From a0ea0f7f3136a7b43f6a93e974d3179e6a8ab640 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Thu, 8 Sep 2022 05:42:39 +0100 Subject: [PATCH] More subtle bugfixes --- scripts/rule110.toy | 66 +++++++++++++++++++++++++++++++++++++++++++++ source/compiler.c | 5 ++++ source/literal.c | 2 +- source/parser.c | 2 +- 4 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 scripts/rule110.toy diff --git a/scripts/rule110.toy b/scripts/rule110.toy new file mode 100644 index 0000000..5977122 --- /dev/null +++ b/scripts/rule110.toy @@ -0,0 +1,66 @@ +var size: int const = 100; + +var prev = []; +for (var i = 0; i < size; i++) { + prev.push(false); +} + +prev.set(size - 1, true); + + +fn calc(p, i) { + if (p[i-1] && p[i] && p[i+1]) { + return false; + } + + if (p[i-1] && p[i] && !p[i+1]) { + return true; + } + + if (p[i-1] && !p[i] && p[i+1]) { + return true; + } + + if (p[i-1] && !p[i] && !p[i+1]) { + return false; + } + + if (!p[i-1] && p[i] && p[i+1]) { + return true; + } + + if (!p[i-1] && p[i] && !p[i+1]) { + return true; + } + + if (!p[i-1] && !p[i] && p[i+1]) { + return true; + } + + if (!p[i-1] && !p[i] && !p[i+1]) { + return false; + } +} + + + +for (var iteration = 0; iteration < 100; iteration++) { + var line = [false]; + for (var i = 1; i < size-1; i++) { + line.push(calc(prev, i)); + } + line.push(false); + + var output = ""; + for (var i = 0; i < line.length(); i++) { + if (line[i]) { + output += "*"; + } + else { + output += " "; + } + } + + print output; + prev = line; +} diff --git a/source/compiler.c b/source/compiler.c index 7e14956..2e8c203 100644 --- a/source/compiler.c +++ b/source/compiler.c @@ -327,6 +327,11 @@ static Opcode writeCompilerWithJumps(Compiler* compiler, Node* node, void* break return node->binary.opcode; } + if (ret != OP_EOF && (node->binary.opcode == OP_AND || node->binary.opcode == OP_OR || (node->binary.opcode >= OP_COMPARE_EQUAL && node->binary.opcode <= OP_INVERT))) { + compiler->bytecode[compiler->count++] = (unsigned char)ret; //1 byte + ret = OP_EOF; //untangle in this case + } + compiler->bytecode[compiler->count++] = (unsigned char)node->binary.opcode; //1 byte return ret; diff --git a/source/literal.c b/source/literal.c index de251b0..06b80ac 100644 --- a/source/literal.c +++ b/source/literal.c @@ -69,7 +69,7 @@ void freeLiteral(Literal literal) { bool _isTruthy(Literal x) { if (IS_NULL(x)) { - fprintf(stderr, ERROR "ERROR: Null is neither true nor false" RESET); + fprintf(stderr, ERROR "ERROR: Null is neither true nor false\n" RESET); return false; } diff --git a/source/parser.c b/source/parser.c index d9579c0..11b7f69 100644 --- a/source/parser.c +++ b/source/parser.c @@ -448,7 +448,7 @@ static Opcode unary(Parser* parser, Node** nodeHandle) { else if (parser->previous.type == TOKEN_NOT) { //temp handle to potentially negate values - parsePrecedence(parser, &tmpNode, PREC_TERNARY); //can be a literal + parsePrecedence(parser, &tmpNode, PREC_CALL); //can be a literal //check for inverted booleans if (tmpNode->type == NODE_LITERAL && IS_BOOLEAN(tmpNode->atomic.literal)) {