~rabbits/fractran

e616603a5ad26de6f823700a3a8b36867beda4e5 — neauoire 2 months ago cb1a768 main
Minor cleanup
5 files changed, 66 insertions(+), 13 deletions(-)

A .clang-format
A .gitignore
M build.sh
D fractran
M fractran.c
A .clang-format => .clang-format +19 -0
@@ 0,0 1,19 @@
AlignAfterOpenBracket: DontAlign
AlignEscapedNewlines: DontAlign
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: TopLevel
BinPackArguments: false
BinPackParameters: false
BreakBeforeBraces: WebKit
IndentCaseLabels: false
TabWidth: 4
IndentWidth: 4
ContinuationIndentWidth: 4
UseTab: ForContinuationAndIndentation
ColumnLimit: 0
ReflowComments: false
SortIncludes: false
SpaceBeforeParens: false
\ No newline at end of file

A .gitignore => .gitignore +7 -0
@@ 0,0 1,7 @@
.DS*
*jpg~
*png~
*gif~
*.chr
*.bmp
fractran
\ No newline at end of file

M build.sh => build.sh +34 -7
@@ 48,11 48,38 @@ 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 "============= AND GATE ==========="
echo "7 5/42 1/21 1/14 1/7" | ./fractran
echo "14 5/42 1/21 1/14 1/7" | ./fractran
echo "21 5/42 1/21 1/14 1/7" | ./fractran
echo "42 5/42 1/21 1/14 1/7" | ./fractran

echo "============= OR GATE ==========="
echo "7 5/42 5/21 5/14 1/7" | ./fractran
echo "14 5/42 5/21 5/14 1/7" | ./fractran
echo "21 5/42 5/21 5/14 1/7" | ./fractran
echo "42 5/42 5/21 5/14 1/7" | ./fractran

echo "============= XOR GATE ==========="
echo "7 1/42 5/21 5/14 1/7" | ./fractran
echo "14 1/42 5/21 5/14 1/7" | ./fractran
echo "21 1/42 5/21 5/14 1/7" | ./fractran
echo "42 1/42 5/21 5/14 1/7" | ./fractran

echo "16 2/1" | ./fractran
\ No newline at end of file
echo "============= NAND GATE ==========="
echo "7 1/42 5/21 5/14 5/7" | ./fractran
echo "14 1/42 5/21 5/14 5/7" | ./fractran
echo "21 1/42 5/21 5/14 5/7" | ./fractran
echo "42 1/42 5/21 5/14 5/7" | ./fractran

echo "============= NOR GATE ==========="
echo "7 1/42 1/21 1/14 5/7" | ./fractran
echo "14 1/42 1/21 1/14 5/7" | ./fractran
echo "21 1/42 1/21 1/14 5/7" | ./fractran
echo "42 1/42 1/21 1/14 5/7" | ./fractran

echo "============= XNOR GATE ==========="
echo "7 5/42 1/21 1/14 5/7" | ./fractran
echo "14 5/42 1/21 1/14 5/7" | ./fractran
echo "21 5/42 1/21 1/14 5/7" | ./fractran
echo "42 5/42 1/21 1/14 5/7" | ./fractran

D fractran => fractran +0 -0
M fractran.c => fractran.c +6 -6
@@ 20,7 20,7 @@ typedef struct Machine {
	Fraction acc, program[256];
} Machine;

int
static int
gcd(int a, int b)
{
	if(b == 0)


@@ 28,7 28,7 @@ gcd(int a, int b)
	return gcd(b, a % b);
}

Fraction
static Fraction
Frac(unsigned int num, unsigned int den)
{
	Fraction f;


@@ 38,7 38,7 @@ Frac(unsigned int num, unsigned int den)
	return f;
}

void
static void
printstate(Machine *m)
{
	unsigned int fac = 2, num = m->acc.num;


@@ 61,7 61,7 @@ printstate(Machine *m)
	putchar('\n');
}

void
static void
run(Machine *m)
{
	int i = 0, steps = 0;


@@ 87,7 87,7 @@ run(Machine *m)
	}
}

void
static void
push(Machine *m, char *w)
{
	Fraction f;


@@ 100,7 100,7 @@ push(Machine *m, char *w)
		m->program[m->len++] = f;
}

Machine m;
static Machine m;

int
main(void)