~rabbits/fractran

cb1a768721ab694fbe03ca0369c62d2b86f50aee — neauoire 9 months ago 8680f6d
Added step counter
3 files changed, 32 insertions(+), 6 deletions(-)

M build.sh
M fractran
M fractran.c
M build.sh => build.sh +25 -3
@@ 7,10 7,10 @@ clang-format -i fractran.c
rm ./fractran

# debug(slow)
cc -std=c89 -DDEBUG -Wall -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined fractran.c -o fractran
# cc -std=c89 -DDEBUG -Wall -Wpedantic -Wshadow -Wextra -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Wvla -g -Og -fsanitize=address -fsanitize=undefined fractran.c -o fractran

# build(fast)
# cc fractran.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -o fractran
cc fractran.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -o fractran

# Size
echo "Size: $(du -sk ./fractran)"


@@ 23,8 23,21 @@ then
fi

# run
echo "========== ADDER PROGRAM =========="
echo "========== ADDER OPERATOR ========="
echo "144 3/2" | ./fractran
echo "Expected: 729"

echo "========= SUBTRACT OPERATOR ======="
echo "254803968 1/6" | ./fractran
echo "Expected: 32768"

echo "============ MIN PROGRAM =========="
echo "69984 5/6 1/3 1/2" | ./fractran
echo "Expected: 3125"

echo "============ MAX PROGRAM =========="
echo "69984 5/6 5/2 5/3" | ./fractran
echo "Expected: 78125"

echo "====== MULTIPLICATION PROGRAM ====="
echo "36 385/13 13/21 1/7 3/11 7/2 1/3" | ./fractran


@@ 34,3 47,12 @@ echo "6" | ./fractran

echo "=========== INVALID QUERY ========="
echo "" | ./fractran

echo "============= NAND GATE ==========="
echo "0 1/42 5/14 5/21 5/7" | ./fractran
echo "2 1/42 5/14 5/21 5/7" | ./fractran
echo "3 1/42 5/14 5/21 5/7" | ./fractran
echo "6 1/42 5/14 5/21 5/7" | ./fractran


echo "16 2/1" | ./fractran
\ No newline at end of file

M fractran => fractran +0 -0
M fractran.c => fractran.c +7 -3
@@ 64,8 64,8 @@ printstate(Machine *m)
void
run(Machine *m)
{
	int i = 0;
	while(i < m->len) {
	int i = 0, steps = 0;
	while(i < m->len && m->acc.num) {
		Fraction res, *f = &m->program[i++];
		res = Frac(m->acc.num * f->num, m->acc.den * f->den);
		printf("%u × %u/%u = %u/%u \n",


@@ 79,6 79,11 @@ run(Machine *m)
			printstate(m);
			i = 0;
		}
		steps++;
	}
	if(steps) {
		printstate(m);
		printf("Completed in %d steps.\n", steps);
	}
}



@@ 114,6 119,5 @@ main(void)
	}
	printstate(&m);
	run(&m);
	printstate(&m);
	return 0;
}