From d39cf84965dffd11cab440f5a4efa1b16932ba73 Mon Sep 17 00:00:00 2001 From: Lizzy Hunt Date: Wed, 28 Feb 2024 13:41:53 -0700 Subject: [PATCH] branching --- src/interpreter/builtins.ts | 120 ++++++- src/interpreter/denotable.ts | 1 + src/interpreter/interpreter.ts | 44 ++- src/parser/grammar.pegjs | 6 + src/parser/parser.ts | 624 +++++++++++++++++++-------------- test/interpreter.spec.ts | 7 + test/programs/branching.cps | 10 + test/programs/index.ts | 3 + test/signature_match.spec.ts | 4 - 9 files changed, 544 insertions(+), 275 deletions(-) create mode 100644 test/programs/branching.cps diff --git a/src/interpreter/builtins.ts b/src/interpreter/builtins.ts index 200131f..bc666e9 100644 --- a/src/interpreter/builtins.ts +++ b/src/interpreter/builtins.ts @@ -28,6 +28,117 @@ const addUnaryIntegerOperationsTo = (env: Environment) => { return env; }; +const addNumberComparisonOperationsTo = (env: Environment) => { + const comparisonOperationsSignatures: DenotableFunctionSignature[] = [ + { + arguments: [ + ['real', 'int'], + ['real', 'int'], + ], + return: 'bool', + }, + ]; + + for (const { name, fn } of [ + { name: '<=', fn: (a: number, b: number) => (a <= b ? 1 : 0) }, + { name: '<', fn: (a: number, b: number) => (a < b ? 1 : 0) }, + { name: '>', fn: (a: number, b: number) => (a > b ? 1 : 0) }, + { name: '>=', fn: (a: number, b: number) => (a >= b ? 1 : 0) }, + ]) { + env.set(name, { + type: 'function', + value: { + signatures: comparisonOperationsSignatures, + body: ({ value: a }: Denotable, { value: b }: Denotable) => + fn(a as number, b as number), + }, + }); + } + + return env; +}; + +const addEqualityOperationsTo = (env: Environment) => { + const equalityOperationSignatures: DenotableFunctionSignature[] = [ + { + arguments: ['int', 'int'], + return: 'bool', + }, + { + arguments: ['real', 'real'], + return: 'bool', + }, + { + arguments: ['bool', 'bool'], + return: 'bool', + }, + { + arguments: ['string', 'string'], + return: 'bool', + }, + ]; + + for (const { name, fn } of [ + { + name: '==', + fn: (a: number | string, b: number | string) => (a === b ? 1 : 0), + }, + { + name: '!=', + fn: (a: number | string, b: number | string) => (a !== b ? 1 : 0), + }, + ]) { + env.set(name, { + type: 'function', + value: { + signatures: equalityOperationSignatures, + body: ({ value: a }: Denotable, { value: b }: Denotable) => + fn(a as number | string, b as number | string), + }, + }); + } + + return env; +}; + +const addBooleanAlgebraOperationsTo = (env: Environment) => { + const binaryBooleanOps: DenotableFunctionSignature[] = [ + { + arguments: ['bool', 'bool'], + return: 'bool', + }, + ]; + + for (const { name, fn } of [ + { name: '||', fn: (a: number, b: number) => (a === 1 || b === 1 ? 1 : 0) }, + { name: '&&', fn: (a: number, b: number) => (a === 1 && b === 1 ? 1 : 0) }, + ]) { + env.set(name, { + type: 'function', + value: { + signatures: binaryBooleanOps, + body: ({ value: a }: Denotable, { value: b }: Denotable) => + fn(a as number, b as number), + }, + }); + } + + env.set('!', { + type: 'function', + value: { + signatures: [ + { + arguments: ['bool'], + return: 'bool', + }, + ], + body: ({ value }: Denotable) => (value === 1 ? 0 : 1), + }, + }); + + return env; +}; + const addBinaryIntegerOperationsTo = (env: Environment) => { const binaryIntegerOperationSignatures: DenotableFunctionSignature[] = [ { @@ -42,12 +153,6 @@ const addBinaryIntegerOperationsTo = (env: Environment) => { { name: '<<', fn: (a: number, b: number) => a << b }, { name: '|', fn: (a: number, b: number) => a | b }, { name: '^', fn: (a: number, b: number) => a ^ b }, - { name: '&&', fn: (a: number, b: number) => (a && b ? 1 : 0) }, - { name: '<=', fn: (a: number, b: number) => (a <= b ? 1 : 0) }, - { name: '<', fn: (a: number, b: number) => (a < b ? 1 : 0) }, - { name: '>', fn: (a: number, b: number) => (a > b ? 1 : 0) }, - { name: '>=', fn: (a: number, b: number) => (a >= b ? 1 : 0) }, - { name: '||', fn: (a: number, b: number) => (a || b ? 1 : 0) }, ]) { env.set(name, { type: 'function', @@ -102,5 +207,8 @@ export const putBuiltinsOnEnvironemtn = (env: Environment) => { addBinaryArithmeticOperationsTo, addBinaryIntegerOperationsTo, addUnaryIntegerOperationsTo, + addNumberComparisonOperationsTo, + addBooleanAlgebraOperationsTo, + addEqualityOperationsTo, ].reduce((acc, builtinsAdder) => builtinsAdder(acc), env); }; diff --git a/src/interpreter/denotable.ts b/src/interpreter/denotable.ts index 65aee86..bb520f8 100644 --- a/src/interpreter/denotable.ts +++ b/src/interpreter/denotable.ts @@ -21,6 +21,7 @@ export type DenotableType = | 'null' | 'int' | 'real' + | 'bool' | 'string' | 'bytearray' | 'function' diff --git a/src/interpreter/interpreter.ts b/src/interpreter/interpreter.ts index ebd605c..94e263c 100644 --- a/src/interpreter/interpreter.ts +++ b/src/interpreter/interpreter.ts @@ -29,7 +29,6 @@ const evaluateValue = ( return { type: 'int', value: value.int }; } if ('name' in value) { - logger.debug(`Evaluating variable: ${value.name}`); return env.get(value.name); } @@ -42,10 +41,6 @@ const evaluatePrimitiveOperation = ( logger: TracingLogger, ) => { const { opr, operands, resultBindings, continuations } = primitiveOperation; - if (operands.length !== 2) { - throw new BadArgumentError('Primitive operations must have 2 operands'); - } - const operandValues = operands.map(operand => evaluateValue(operand, env, logger.createChild('evaluteValue')), ); @@ -56,15 +51,46 @@ const evaluatePrimitiveOperation = ( continuationEnvironment.set(name, result); } - // return the result of the last continuation - return continuations.reduce((_, continuation, i) => { - const childLogger = logger.createChild(`continuation[${i}]`); + if (result.type === 'bool') { + if (continuations.length > 2) { + throw new BadArgumentError( + `Expected <= 2 continuations for boolean result, got ${continuations.length}`, + ); + } + if (continuations.length !== 2) { + logger.warn( + `Expected 2 continuations for boolean result, got ContinuationLength=(${continuations.length})`, + ); + } + + const [trueContinuation, falseContinuation] = continuations; + const childLogger = logger.createChild('continuation[true]'); + const continuation = result.value ? trueContinuation : falseContinuation; return evaluteContinuationExpression( continuation, continuationEnvironment, childLogger, ); - }, result); + } + + if (continuations.length > 1) { + throw new BadArgumentError( + `Expected <= 1 continuations for non-boolean result, got ${continuations.length}`, + ); + } else if (continuations.length === 0) { + logger.warn( + `!! Expected 1 continuation in continuation list... implicitly returning result but PLEASE NOTE this is technically undefined behavior !!`, + ); + return result; + } + + const [continuation] = continuations; + const childLogger = logger.createChild('continuation'); + return evaluteContinuationExpression( + continuation, + continuationEnvironment, + childLogger, + ); }; const evaluteContinuationExpression = ( diff --git a/src/parser/grammar.pegjs b/src/parser/grammar.pegjs index 66facc5..e237af9 100644 --- a/src/parser/grammar.pegjs +++ b/src/parser/grammar.pegjs @@ -223,6 +223,7 @@ Value / LabelStatement / IntStatement / RealStatement + / BoolStatement / StringStatement VarStatement = VAR _ ident:Identifier { return ident; } @@ -233,6 +234,8 @@ IntStatement = INT _ int:Integer { return int; } RealStatement = REAL _ real:Real { return real; } +BoolStatement = BOOL _ bool:Integer { return bool; } + StringStatement = STRING _ string:QuotedString { return string; } AccessStatement @@ -286,6 +289,7 @@ ComparisonOperation / ">" / "<" / "||" + / "&&" Integer = digits:("-"? [0-9]+) !"." { return { int: parseInt(digits.join(''), 10) }; } @@ -317,6 +321,8 @@ INT = "INT" REAL = "REAL" +BOOL = "BOOL" + STRING = "STRING" APP = "APP" diff --git a/src/parser/parser.ts b/src/parser/parser.ts index 802488f..500a763 100644 --- a/src/parser/parser.ts +++ b/src/parser/parser.ts @@ -310,39 +310,41 @@ function peg$parse(input, options) { var peg$c6 = ">="; var peg$c7 = "!="; var peg$c8 = "||"; - var peg$c9 = "-"; - var peg$c10 = "."; - var peg$c11 = "'"; - var peg$c12 = "\""; - var peg$c13 = "OFFSET"; - var peg$c14 = "OFFp"; - var peg$c15 = "SELp"; - var peg$c16 = "VAR"; - var peg$c17 = "INT"; - var peg$c18 = "REAL"; - var peg$c19 = "STRING"; - var peg$c20 = "APP"; - var peg$c21 = "RECORD"; - var peg$c22 = "SELECT"; - var peg$c23 = "FIX"; - var peg$c24 = "SWITCH"; - var peg$c25 = "PRIMOP"; - var peg$c26 = "LABEL"; - var peg$c27 = "store"; - var peg$c28 = "update"; - var peg$c29 = "makeref"; - var peg$c30 = "makerefunboxed"; - var peg$c31 = "unboxedupdate"; - var peg$c32 = "subscript"; - var peg$c33 = "boxed"; - var peg$c34 = "_"; - var peg$c35 = "["; - var peg$c36 = "]"; - var peg$c37 = ","; - var peg$c38 = "="; - var peg$c39 = "("; - var peg$c40 = ")"; - var peg$c41 = "\r\n"; + var peg$c9 = "&&"; + var peg$c10 = "-"; + var peg$c11 = "."; + var peg$c12 = "'"; + var peg$c13 = "\""; + var peg$c14 = "OFFSET"; + var peg$c15 = "OFFp"; + var peg$c16 = "SELp"; + var peg$c17 = "VAR"; + var peg$c18 = "INT"; + var peg$c19 = "REAL"; + var peg$c20 = "BOOL"; + var peg$c21 = "STRING"; + var peg$c22 = "APP"; + var peg$c23 = "RECORD"; + var peg$c24 = "SELECT"; + var peg$c25 = "FIX"; + var peg$c26 = "SWITCH"; + var peg$c27 = "PRIMOP"; + var peg$c28 = "LABEL"; + var peg$c29 = "store"; + var peg$c30 = "update"; + var peg$c31 = "makeref"; + var peg$c32 = "makerefunboxed"; + var peg$c33 = "unboxedupdate"; + var peg$c34 = "subscript"; + var peg$c35 = "boxed"; + var peg$c36 = "_"; + var peg$c37 = "["; + var peg$c38 = "]"; + var peg$c39 = ","; + var peg$c40 = "="; + var peg$c41 = "("; + var peg$c42 = ")"; + var peg$c43 = "\r\n"; var peg$r0 = /^[A-Za-z]/; var peg$r1 = /^[0-9A-Z_a-z]/; @@ -368,43 +370,45 @@ function peg$parse(input, options) { var peg$e11 = peg$literalExpectation("!=", false); var peg$e12 = peg$classExpectation(["!", "<", ">"], false, false); var peg$e13 = peg$literalExpectation("||", false); - var peg$e14 = peg$literalExpectation("-", false); - var peg$e15 = peg$classExpectation([["0", "9"]], false, false); - var peg$e16 = peg$literalExpectation(".", false); - var peg$e17 = peg$literalExpectation("'", false); - var peg$e18 = peg$classExpectation(["'"], true, false); - var peg$e19 = peg$literalExpectation("\"", false); - var peg$e20 = peg$classExpectation(["\""], true, false); - var peg$e21 = peg$literalExpectation("OFFSET", false); - var peg$e22 = peg$literalExpectation("OFFp", false); - var peg$e23 = peg$literalExpectation("SELp", false); - var peg$e24 = peg$literalExpectation("VAR", false); - var peg$e25 = peg$literalExpectation("INT", false); - var peg$e26 = peg$literalExpectation("REAL", false); - var peg$e27 = peg$literalExpectation("STRING", false); - var peg$e28 = peg$literalExpectation("APP", false); - var peg$e29 = peg$literalExpectation("RECORD", false); - var peg$e30 = peg$literalExpectation("SELECT", false); - var peg$e31 = peg$literalExpectation("FIX", false); - var peg$e32 = peg$literalExpectation("SWITCH", false); - var peg$e33 = peg$literalExpectation("PRIMOP", false); - var peg$e34 = peg$literalExpectation("LABEL", false); - var peg$e35 = peg$literalExpectation("store", false); - var peg$e36 = peg$literalExpectation("update", false); - var peg$e37 = peg$literalExpectation("makeref", false); - var peg$e38 = peg$literalExpectation("makerefunboxed", false); - var peg$e39 = peg$literalExpectation("unboxedupdate", false); - var peg$e40 = peg$literalExpectation("subscript", false); - var peg$e41 = peg$literalExpectation("boxed", false); - var peg$e42 = peg$literalExpectation("_", false); - var peg$e43 = peg$literalExpectation("[", false); - var peg$e44 = peg$literalExpectation("]", false); - var peg$e45 = peg$literalExpectation(",", false); - var peg$e46 = peg$literalExpectation("=", false); - var peg$e47 = peg$literalExpectation("(", false); - var peg$e48 = peg$literalExpectation(")", false); - var peg$e49 = peg$classExpectation([["\t", "\n"], " "], false, false); - var peg$e50 = peg$literalExpectation("\r\n", false); + var peg$e14 = peg$literalExpectation("&&", false); + var peg$e15 = peg$literalExpectation("-", false); + var peg$e16 = peg$classExpectation([["0", "9"]], false, false); + var peg$e17 = peg$literalExpectation(".", false); + var peg$e18 = peg$literalExpectation("'", false); + var peg$e19 = peg$classExpectation(["'"], true, false); + var peg$e20 = peg$literalExpectation("\"", false); + var peg$e21 = peg$classExpectation(["\""], true, false); + var peg$e22 = peg$literalExpectation("OFFSET", false); + var peg$e23 = peg$literalExpectation("OFFp", false); + var peg$e24 = peg$literalExpectation("SELp", false); + var peg$e25 = peg$literalExpectation("VAR", false); + var peg$e26 = peg$literalExpectation("INT", false); + var peg$e27 = peg$literalExpectation("REAL", false); + var peg$e28 = peg$literalExpectation("BOOL", false); + var peg$e29 = peg$literalExpectation("STRING", false); + var peg$e30 = peg$literalExpectation("APP", false); + var peg$e31 = peg$literalExpectation("RECORD", false); + var peg$e32 = peg$literalExpectation("SELECT", false); + var peg$e33 = peg$literalExpectation("FIX", false); + var peg$e34 = peg$literalExpectation("SWITCH", false); + var peg$e35 = peg$literalExpectation("PRIMOP", false); + var peg$e36 = peg$literalExpectation("LABEL", false); + var peg$e37 = peg$literalExpectation("store", false); + var peg$e38 = peg$literalExpectation("update", false); + var peg$e39 = peg$literalExpectation("makeref", false); + var peg$e40 = peg$literalExpectation("makerefunboxed", false); + var peg$e41 = peg$literalExpectation("unboxedupdate", false); + var peg$e42 = peg$literalExpectation("subscript", false); + var peg$e43 = peg$literalExpectation("boxed", false); + var peg$e44 = peg$literalExpectation("_", false); + var peg$e45 = peg$literalExpectation("[", false); + var peg$e46 = peg$literalExpectation("]", false); + var peg$e47 = peg$literalExpectation(",", false); + var peg$e48 = peg$literalExpectation("=", false); + var peg$e49 = peg$literalExpectation("(", false); + var peg$e50 = peg$literalExpectation(")", false); + var peg$e51 = peg$classExpectation([["\t", "\n"], " "], false, false); + var peg$e52 = peg$literalExpectation("\r\n", false); // @ts-ignore var peg$f0 = function(exprs) { @@ -507,30 +511,33 @@ function peg$parse(input, options) { var peg$f17 = function(real) {// @ts-ignore return real; };// @ts-ignore - var peg$f18 = function(string) {// @ts-ignore - return string; };// @ts-ignore + var peg$f18 = function(bool) {// @ts-ignore + return bool; };// @ts-ignore - var peg$f19 = function(offset) {// @ts-ignore - return offset; };// @ts-ignore + var peg$f19 = function(string) {// @ts-ignore + return string; };// @ts-ignore var peg$f20 = function(offset) {// @ts-ignore return offset; };// @ts-ignore - var peg$f21 = function(name) { + var peg$f21 = function(offset) {// @ts-ignore + return offset; };// @ts-ignore + + var peg$f22 = function(name) { // @ts-ignore return { name: name[0] + name[1].join('') }; };// @ts-ignore - var peg$f22 = function(digits) {// @ts-ignore + var peg$f23 = function(digits) {// @ts-ignore return { int: parseInt(digits.join(''), 10) }; };// @ts-ignore - var peg$f23 = function(content) {// @ts-ignore - return content.join(''); };// @ts-ignore - var peg$f24 = function(content) {// @ts-ignore return content.join(''); };// @ts-ignore - var peg$f25 = function(value) { + var peg$f25 = function(content) {// @ts-ignore + return content.join(''); };// @ts-ignore + + var peg$f26 = function(value) { // @ts-ignore return { real: parseFloat( // @ts-ignore @@ -2991,7 +2998,12 @@ peg$parseValue() { // @ts-ignore if (s0 === peg$FAILED) { // @ts-ignore - s0 = peg$parseStringStatement(); + s0 = peg$parseBoolStatement(); +// @ts-ignore + if (s0 === peg$FAILED) { +// @ts-ignore + s0 = peg$parseStringStatement(); + } } } } @@ -3201,6 +3213,56 @@ peg$parseRealStatement() { return s0; } +// @ts-ignore + function // @ts-ignore +peg$parseBoolStatement() { +// @ts-ignore + var s0, s1, s2, s3; + +// @ts-ignore + s0 = peg$currPos; +// @ts-ignore + s1 = peg$parseBOOL(); +// @ts-ignore + if (s1 !== peg$FAILED) { +// @ts-ignore + s2 = peg$parse_(); +// @ts-ignore + if (s2 !== peg$FAILED) { +// @ts-ignore + s3 = peg$parseInteger(); +// @ts-ignore + if (s3 !== peg$FAILED) { +// @ts-ignore + peg$savedPos = s0; +// @ts-ignore + s0 = peg$f18(s3); +// @ts-ignore + } else { +// @ts-ignore + peg$currPos = s0; +// @ts-ignore + s0 = peg$FAILED; + } +// @ts-ignore + } else { +// @ts-ignore + peg$currPos = s0; +// @ts-ignore + s0 = peg$FAILED; + } +// @ts-ignore + } else { +// @ts-ignore + peg$currPos = s0; +// @ts-ignore + s0 = peg$FAILED; + } + +// @ts-ignore + return s0; + } + // @ts-ignore function // @ts-ignore peg$parseStringStatement() { @@ -3224,7 +3286,7 @@ peg$parseStringStatement() { // @ts-ignore peg$savedPos = s0; // @ts-ignore - s0 = peg$f18(s3); + s0 = peg$f19(s3); // @ts-ignore } else { // @ts-ignore @@ -3292,7 +3354,7 @@ peg$parseOffsetStatement() { // @ts-ignore peg$savedPos = s0; // @ts-ignore - s0 = peg$f19(s3); + s0 = peg$f20(s3); // @ts-ignore } else { // @ts-ignore @@ -3342,7 +3404,7 @@ peg$parseSelectStatement() { // @ts-ignore peg$savedPos = s0; // @ts-ignore - s0 = peg$f20(s3); + s0 = peg$f21(s3); // @ts-ignore } else { // @ts-ignore @@ -3443,7 +3505,7 @@ peg$parseIdentifier() { // @ts-ignore peg$savedPos = s0; // @ts-ignore - s1 = peg$f21(s1); + s1 = peg$f22(s1); } // @ts-ignore s0 = s1; @@ -3729,6 +3791,22 @@ peg$parseComparisonOperation() { // @ts-ignore if (peg$silentFails === 0) { peg$fail(peg$e13); } } +// @ts-ignore + if (s0 === peg$FAILED) { +// @ts-ignore + if (input.substr(peg$currPos, 2) === peg$c9) { +// @ts-ignore + s0 = peg$c9; +// @ts-ignore + peg$currPos += 2; +// @ts-ignore + } else { +// @ts-ignore + s0 = peg$FAILED; +// @ts-ignore + if (peg$silentFails === 0) { peg$fail(peg$e14); } + } + } } } } @@ -3752,7 +3830,7 @@ peg$parseInteger() { // @ts-ignore if (input.charCodeAt(peg$currPos) === 45) { // @ts-ignore - s2 = peg$c9; + s2 = peg$c10; // @ts-ignore peg$currPos++; // @ts-ignore @@ -3760,7 +3838,7 @@ peg$parseInteger() { // @ts-ignore s2 = peg$FAILED; // @ts-ignore - if (peg$silentFails === 0) { peg$fail(peg$e14); } + if (peg$silentFails === 0) { peg$fail(peg$e15); } } // @ts-ignore if (s2 === peg$FAILED) { @@ -3780,7 +3858,7 @@ peg$parseInteger() { // @ts-ignore s4 = peg$FAILED; // @ts-ignore - if (peg$silentFails === 0) { peg$fail(peg$e15); } + if (peg$silentFails === 0) { peg$fail(peg$e16); } } // @ts-ignore if (s4 !== peg$FAILED) { @@ -3799,7 +3877,7 @@ peg$parseInteger() { // @ts-ignore s4 = peg$FAILED; // @ts-ignore - if (peg$silentFails === 0) { peg$fail(peg$e15); } + if (peg$silentFails === 0) { peg$fail(peg$e16); } } } // @ts-ignore @@ -3829,7 +3907,7 @@ peg$parseInteger() { // @ts-ignore if (input.charCodeAt(peg$currPos) === 46) { // @ts-ignore - s3 = peg$c10; + s3 = peg$c11; // @ts-ignore peg$currPos++; // @ts-ignore @@ -3837,7 +3915,7 @@ peg$parseInteger() { // @ts-ignore s3 = peg$FAILED; // @ts-ignore - if (peg$silentFails === 0) { peg$fail(peg$e16); } + if (peg$silentFails === 0) { peg$fail(peg$e17); } } // @ts-ignore peg$silentFails--; @@ -3857,7 +3935,7 @@ peg$parseInteger() { // @ts-ignore peg$savedPos = s0; // @ts-ignore - s0 = peg$f22(s1); + s0 = peg$f23(s1); // @ts-ignore } else { // @ts-ignore @@ -3888,7 +3966,7 @@ peg$parseQuotedString() { // @ts-ignore if (input.charCodeAt(peg$currPos) === 39) { // @ts-ignore - s1 = peg$c11; + s1 = peg$c12; // @ts-ignore peg$currPos++; // @ts-ignore @@ -3896,7 +3974,7 @@ peg$parseQuotedString() { // @ts-ignore s1 = peg$FAILED; // @ts-ignore - if (peg$silentFails === 0) { peg$fail(peg$e17); } + if (peg$silentFails === 0) { peg$fail(peg$e18); } } // @ts-ignore if (s1 !== peg$FAILED) { @@ -3913,7 +3991,7 @@ peg$parseQuotedString() { // @ts-ignore s3 = peg$FAILED; // @ts-ignore - if (peg$silentFails === 0) { peg$fail(peg$e18); } + if (peg$silentFails === 0) { peg$fail(peg$e19); } } // @ts-ignore while (s3 !== peg$FAILED) { @@ -3930,13 +4008,13 @@ peg$parseQuotedString() { // @ts-ignore s3 = peg$FAILED; // @ts-ignore - if (peg$silentFails === 0) { peg$fail(peg$e18); } + if (peg$silentFails === 0) { peg$fail(peg$e19); } } } // @ts-ignore if (input.charCodeAt(peg$currPos) === 39) { // @ts-ignore - s3 = peg$c11; + s3 = peg$c12; // @ts-ignore peg$currPos++; // @ts-ignore @@ -3944,14 +4022,14 @@ peg$parseQuotedString() { // @ts-ignore s3 = peg$FAILED; // @ts-ignore - if (peg$silentFails === 0) { peg$fail(peg$e17); } + if (peg$silentFails === 0) { peg$fail(peg$e18); } } // @ts-ignore if (s3 !== peg$FAILED) { // @ts-ignore peg$savedPos = s0; // @ts-ignore - s0 = peg$f23(s2); + s0 = peg$f24(s2); // @ts-ignore } else { // @ts-ignore @@ -3973,7 +4051,7 @@ peg$parseQuotedString() { // @ts-ignore if (input.charCodeAt(peg$currPos) === 34) { // @ts-ignore - s1 = peg$c12; + s1 = peg$c13; // @ts-ignore peg$currPos++; // @ts-ignore @@ -3981,7 +4059,7 @@ peg$parseQuotedString() { // @ts-ignore s1 = peg$FAILED; // @ts-ignore - if (peg$silentFails === 0) { peg$fail(peg$e19); } + if (peg$silentFails === 0) { peg$fail(peg$e20); } } // @ts-ignore if (s1 !== peg$FAILED) { @@ -3998,7 +4076,7 @@ peg$parseQuotedString() { // @ts-ignore s3 = peg$FAILED; // @ts-ignore - if (peg$silentFails === 0) { peg$fail(peg$e20); } + if (peg$silentFails === 0) { peg$fail(peg$e21); } } // @ts-ignore while (s3 !== peg$FAILED) { @@ -4015,13 +4093,13 @@ peg$parseQuotedString() { // @ts-ignore s3 = peg$FAILED; // @ts-ignore - if (peg$silentFails === 0) { peg$fail(peg$e20); } + if (peg$silentFails === 0) { peg$fail(peg$e21); } } } // @ts-ignore if (input.charCodeAt(peg$currPos) === 34) { // @ts-ignore - s3 = peg$c12; + s3 = peg$c13; // @ts-ignore peg$currPos++; // @ts-ignore @@ -4029,14 +4107,14 @@ peg$parseQuotedString() { // @ts-ignore s3 = peg$FAILED; // @ts-ignore - if (peg$silentFails === 0) { peg$fail(peg$e19); } + if (peg$silentFails === 0) { peg$fail(peg$e20); } } // @ts-ignore if (s3 !== peg$FAILED) { // @ts-ignore peg$savedPos = s0; // @ts-ignore - s0 = peg$f24(s2); + s0 = peg$f25(s2); // @ts-ignore } else { // @ts-ignore @@ -4070,7 +4148,7 @@ peg$parseReal() { // @ts-ignore if (input.charCodeAt(peg$currPos) === 45) { // @ts-ignore - s2 = peg$c9; + s2 = peg$c10; // @ts-ignore peg$currPos++; // @ts-ignore @@ -4078,7 +4156,7 @@ peg$parseReal() { // @ts-ignore s2 = peg$FAILED; // @ts-ignore - if (peg$silentFails === 0) { peg$fail(peg$e14); } + if (peg$silentFails === 0) { peg$fail(peg$e15); } } // @ts-ignore if (s2 === peg$FAILED) { @@ -4098,7 +4176,7 @@ peg$parseReal() { // @ts-ignore s4 = peg$FAILED; // @ts-ignore - if (peg$silentFails === 0) { peg$fail(peg$e15); } + if (peg$silentFails === 0) { peg$fail(peg$e16); } } // @ts-ignore if (s4 !== peg$FAILED) { @@ -4117,7 +4195,7 @@ peg$parseReal() { // @ts-ignore s4 = peg$FAILED; // @ts-ignore - if (peg$silentFails === 0) { peg$fail(peg$e15); } + if (peg$silentFails === 0) { peg$fail(peg$e16); } } } // @ts-ignore @@ -4132,7 +4210,7 @@ peg$parseReal() { // @ts-ignore if (input.charCodeAt(peg$currPos) === 46) { // @ts-ignore - s5 = peg$c10; + s5 = peg$c11; // @ts-ignore peg$currPos++; // @ts-ignore @@ -4140,7 +4218,7 @@ peg$parseReal() { // @ts-ignore s5 = peg$FAILED; // @ts-ignore - if (peg$silentFails === 0) { peg$fail(peg$e16); } + if (peg$silentFails === 0) { peg$fail(peg$e17); } } // @ts-ignore if (s5 !== peg$FAILED) { @@ -4157,7 +4235,7 @@ peg$parseReal() { // @ts-ignore s7 = peg$FAILED; // @ts-ignore - if (peg$silentFails === 0) { peg$fail(peg$e15); } + if (peg$silentFails === 0) { peg$fail(peg$e16); } } // @ts-ignore if (s7 !== peg$FAILED) { @@ -4176,7 +4254,7 @@ peg$parseReal() { // @ts-ignore s7 = peg$FAILED; // @ts-ignore - if (peg$silentFails === 0) { peg$fail(peg$e15); } + if (peg$silentFails === 0) { peg$fail(peg$e16); } } } // @ts-ignore @@ -4225,7 +4303,7 @@ peg$parseReal() { // @ts-ignore peg$savedPos = s0; // @ts-ignore - s1 = peg$f25(s1); + s1 = peg$f26(s1); } // @ts-ignore s0 = s1; @@ -4264,35 +4342,11 @@ peg$parseOFFSET() { var s0; // @ts-ignore - if (input.substr(peg$currPos, 6) === peg$c13) { -// @ts-ignore - s0 = peg$c13; -// @ts-ignore - peg$currPos += 6; -// @ts-ignore - } else { -// @ts-ignore - s0 = peg$FAILED; -// @ts-ignore - if (peg$silentFails === 0) { peg$fail(peg$e21); } - } - -// @ts-ignore - return s0; - } - -// @ts-ignore - function // @ts-ignore -peg$parseOFFP() { -// @ts-ignore - var s0; - -// @ts-ignore - if (input.substr(peg$currPos, 4) === peg$c14) { + if (input.substr(peg$currPos, 6) === peg$c14) { // @ts-ignore s0 = peg$c14; // @ts-ignore - peg$currPos += 4; + peg$currPos += 6; // @ts-ignore } else { // @ts-ignore @@ -4307,7 +4361,7 @@ peg$parseOFFP() { // @ts-ignore function // @ts-ignore -peg$parseSELP() { +peg$parseOFFP() { // @ts-ignore var s0; @@ -4331,16 +4385,16 @@ peg$parseSELP() { // @ts-ignore function // @ts-ignore -peg$parseVAR() { +peg$parseSELP() { // @ts-ignore var s0; // @ts-ignore - if (input.substr(peg$currPos, 3) === peg$c16) { + if (input.substr(peg$currPos, 4) === peg$c16) { // @ts-ignore s0 = peg$c16; // @ts-ignore - peg$currPos += 3; + peg$currPos += 4; // @ts-ignore } else { // @ts-ignore @@ -4355,7 +4409,7 @@ peg$parseVAR() { // @ts-ignore function // @ts-ignore -peg$parseINT() { +peg$parseVAR() { // @ts-ignore var s0; @@ -4379,16 +4433,16 @@ peg$parseINT() { // @ts-ignore function // @ts-ignore -peg$parseREAL() { +peg$parseINT() { // @ts-ignore var s0; // @ts-ignore - if (input.substr(peg$currPos, 4) === peg$c18) { + if (input.substr(peg$currPos, 3) === peg$c18) { // @ts-ignore s0 = peg$c18; // @ts-ignore - peg$currPos += 4; + peg$currPos += 3; // @ts-ignore } else { // @ts-ignore @@ -4403,16 +4457,16 @@ peg$parseREAL() { // @ts-ignore function // @ts-ignore -peg$parseSTRING() { +peg$parseREAL() { // @ts-ignore var s0; // @ts-ignore - if (input.substr(peg$currPos, 6) === peg$c19) { + if (input.substr(peg$currPos, 4) === peg$c19) { // @ts-ignore s0 = peg$c19; // @ts-ignore - peg$currPos += 6; + peg$currPos += 4; // @ts-ignore } else { // @ts-ignore @@ -4427,16 +4481,16 @@ peg$parseSTRING() { // @ts-ignore function // @ts-ignore -peg$parseAPP() { +peg$parseBOOL() { // @ts-ignore var s0; // @ts-ignore - if (input.substr(peg$currPos, 3) === peg$c20) { + if (input.substr(peg$currPos, 4) === peg$c20) { // @ts-ignore s0 = peg$c20; // @ts-ignore - peg$currPos += 3; + peg$currPos += 4; // @ts-ignore } else { // @ts-ignore @@ -4451,7 +4505,7 @@ peg$parseAPP() { // @ts-ignore function // @ts-ignore -peg$parseRECORD() { +peg$parseSTRING() { // @ts-ignore var s0; @@ -4475,16 +4529,16 @@ peg$parseRECORD() { // @ts-ignore function // @ts-ignore -peg$parseSELECT() { +peg$parseAPP() { // @ts-ignore var s0; // @ts-ignore - if (input.substr(peg$currPos, 6) === peg$c22) { + if (input.substr(peg$currPos, 3) === peg$c22) { // @ts-ignore s0 = peg$c22; // @ts-ignore - peg$currPos += 6; + peg$currPos += 3; // @ts-ignore } else { // @ts-ignore @@ -4499,16 +4553,16 @@ peg$parseSELECT() { // @ts-ignore function // @ts-ignore -peg$parseFIX() { +peg$parseRECORD() { // @ts-ignore var s0; // @ts-ignore - if (input.substr(peg$currPos, 3) === peg$c23) { + if (input.substr(peg$currPos, 6) === peg$c23) { // @ts-ignore s0 = peg$c23; // @ts-ignore - peg$currPos += 3; + peg$currPos += 6; // @ts-ignore } else { // @ts-ignore @@ -4523,7 +4577,7 @@ peg$parseFIX() { // @ts-ignore function // @ts-ignore -peg$parseSWITCH() { +peg$parseSELECT() { // @ts-ignore var s0; @@ -4547,16 +4601,16 @@ peg$parseSWITCH() { // @ts-ignore function // @ts-ignore -peg$parsePRIMOP() { +peg$parseFIX() { // @ts-ignore var s0; // @ts-ignore - if (input.substr(peg$currPos, 6) === peg$c25) { + if (input.substr(peg$currPos, 3) === peg$c25) { // @ts-ignore s0 = peg$c25; // @ts-ignore - peg$currPos += 6; + peg$currPos += 3; // @ts-ignore } else { // @ts-ignore @@ -4571,16 +4625,16 @@ peg$parsePRIMOP() { // @ts-ignore function // @ts-ignore -peg$parseLABEL() { +peg$parseSWITCH() { // @ts-ignore var s0; // @ts-ignore - if (input.substr(peg$currPos, 5) === peg$c26) { + if (input.substr(peg$currPos, 6) === peg$c26) { // @ts-ignore s0 = peg$c26; // @ts-ignore - peg$currPos += 5; + peg$currPos += 6; // @ts-ignore } else { // @ts-ignore @@ -4595,16 +4649,16 @@ peg$parseLABEL() { // @ts-ignore function // @ts-ignore -peg$parseSTORE() { +peg$parsePRIMOP() { // @ts-ignore var s0; // @ts-ignore - if (input.substr(peg$currPos, 5) === peg$c27) { + if (input.substr(peg$currPos, 6) === peg$c27) { // @ts-ignore s0 = peg$c27; // @ts-ignore - peg$currPos += 5; + peg$currPos += 6; // @ts-ignore } else { // @ts-ignore @@ -4619,16 +4673,16 @@ peg$parseSTORE() { // @ts-ignore function // @ts-ignore -peg$parseUPDATE() { +peg$parseLABEL() { // @ts-ignore var s0; // @ts-ignore - if (input.substr(peg$currPos, 6) === peg$c28) { + if (input.substr(peg$currPos, 5) === peg$c28) { // @ts-ignore s0 = peg$c28; // @ts-ignore - peg$currPos += 6; + peg$currPos += 5; // @ts-ignore } else { // @ts-ignore @@ -4643,16 +4697,16 @@ peg$parseUPDATE() { // @ts-ignore function // @ts-ignore -peg$parseMAKEREF() { +peg$parseSTORE() { // @ts-ignore var s0; // @ts-ignore - if (input.substr(peg$currPos, 7) === peg$c29) { + if (input.substr(peg$currPos, 5) === peg$c29) { // @ts-ignore s0 = peg$c29; // @ts-ignore - peg$currPos += 7; + peg$currPos += 5; // @ts-ignore } else { // @ts-ignore @@ -4667,16 +4721,16 @@ peg$parseMAKEREF() { // @ts-ignore function // @ts-ignore -peg$parseMAKEREFUNBOXED() { +peg$parseUPDATE() { // @ts-ignore var s0; // @ts-ignore - if (input.substr(peg$currPos, 14) === peg$c30) { + if (input.substr(peg$currPos, 6) === peg$c30) { // @ts-ignore s0 = peg$c30; // @ts-ignore - peg$currPos += 14; + peg$currPos += 6; // @ts-ignore } else { // @ts-ignore @@ -4691,16 +4745,16 @@ peg$parseMAKEREFUNBOXED() { // @ts-ignore function // @ts-ignore -peg$parseUNBOXED_UPDATE() { +peg$parseMAKEREF() { // @ts-ignore var s0; // @ts-ignore - if (input.substr(peg$currPos, 13) === peg$c31) { + if (input.substr(peg$currPos, 7) === peg$c31) { // @ts-ignore s0 = peg$c31; // @ts-ignore - peg$currPos += 13; + peg$currPos += 7; // @ts-ignore } else { // @ts-ignore @@ -4715,16 +4769,16 @@ peg$parseUNBOXED_UPDATE() { // @ts-ignore function // @ts-ignore -peg$parseSUBSCRIPT() { +peg$parseMAKEREFUNBOXED() { // @ts-ignore var s0; // @ts-ignore - if (input.substr(peg$currPos, 9) === peg$c32) { + if (input.substr(peg$currPos, 14) === peg$c32) { // @ts-ignore s0 = peg$c32; // @ts-ignore - peg$currPos += 9; + peg$currPos += 14; // @ts-ignore } else { // @ts-ignore @@ -4737,6 +4791,54 @@ peg$parseSUBSCRIPT() { return s0; } +// @ts-ignore + function // @ts-ignore +peg$parseUNBOXED_UPDATE() { +// @ts-ignore + var s0; + +// @ts-ignore + if (input.substr(peg$currPos, 13) === peg$c33) { +// @ts-ignore + s0 = peg$c33; +// @ts-ignore + peg$currPos += 13; +// @ts-ignore + } else { +// @ts-ignore + s0 = peg$FAILED; +// @ts-ignore + if (peg$silentFails === 0) { peg$fail(peg$e41); } + } + +// @ts-ignore + return s0; + } + +// @ts-ignore + function // @ts-ignore +peg$parseSUBSCRIPT() { +// @ts-ignore + var s0; + +// @ts-ignore + if (input.substr(peg$currPos, 9) === peg$c34) { +// @ts-ignore + s0 = peg$c34; +// @ts-ignore + peg$currPos += 9; +// @ts-ignore + } else { +// @ts-ignore + s0 = peg$FAILED; +// @ts-ignore + if (peg$silentFails === 0) { peg$fail(peg$e42); } + } + +// @ts-ignore + return s0; + } + // @ts-ignore function // @ts-ignore peg$parseBOXED() { @@ -4744,9 +4846,9 @@ peg$parseBOXED() { var s0; // @ts-ignore - if (input.substr(peg$currPos, 5) === peg$c33) { + if (input.substr(peg$currPos, 5) === peg$c35) { // @ts-ignore - s0 = peg$c33; + s0 = peg$c35; // @ts-ignore peg$currPos += 5; // @ts-ignore @@ -4754,7 +4856,7 @@ peg$parseBOXED() { // @ts-ignore s0 = peg$FAILED; // @ts-ignore - if (peg$silentFails === 0) { peg$fail(peg$e41); } + if (peg$silentFails === 0) { peg$fail(peg$e43); } } // @ts-ignore @@ -4794,7 +4896,7 @@ peg$parseSAFE_SYMBOL() { // @ts-ignore if (input.charCodeAt(peg$currPos) === 95) { // @ts-ignore - s0 = peg$c34; + s0 = peg$c36; // @ts-ignore peg$currPos++; // @ts-ignore @@ -4802,7 +4904,7 @@ peg$parseSAFE_SYMBOL() { // @ts-ignore s0 = peg$FAILED; // @ts-ignore - if (peg$silentFails === 0) { peg$fail(peg$e42); } + if (peg$silentFails === 0) { peg$fail(peg$e44); } } // @ts-ignore @@ -4826,7 +4928,7 @@ peg$parseDIGIT() { // @ts-ignore s0 = peg$FAILED; // @ts-ignore - if (peg$silentFails === 0) { peg$fail(peg$e15); } + if (peg$silentFails === 0) { peg$fail(peg$e16); } } // @ts-ignore @@ -4841,54 +4943,6 @@ peg$parseLBRACKET() { // @ts-ignore if (input.charCodeAt(peg$currPos) === 91) { -// @ts-ignore - s0 = peg$c35; -// @ts-ignore - peg$currPos++; -// @ts-ignore - } else { -// @ts-ignore - s0 = peg$FAILED; -// @ts-ignore - if (peg$silentFails === 0) { peg$fail(peg$e43); } - } - -// @ts-ignore - return s0; - } - -// @ts-ignore - function // @ts-ignore -peg$parseRBRACKET() { -// @ts-ignore - var s0; - -// @ts-ignore - if (input.charCodeAt(peg$currPos) === 93) { -// @ts-ignore - s0 = peg$c36; -// @ts-ignore - peg$currPos++; -// @ts-ignore - } else { -// @ts-ignore - s0 = peg$FAILED; -// @ts-ignore - if (peg$silentFails === 0) { peg$fail(peg$e44); } - } - -// @ts-ignore - return s0; - } - -// @ts-ignore - function // @ts-ignore -peg$parseCOMMA() { -// @ts-ignore - var s0; - -// @ts-ignore - if (input.charCodeAt(peg$currPos) === 44) { // @ts-ignore s0 = peg$c37; // @ts-ignore @@ -4907,12 +4961,12 @@ peg$parseCOMMA() { // @ts-ignore function // @ts-ignore -peg$parseEQUALS() { +peg$parseRBRACKET() { // @ts-ignore var s0; // @ts-ignore - if (input.charCodeAt(peg$currPos) === 61) { + if (input.charCodeAt(peg$currPos) === 93) { // @ts-ignore s0 = peg$c38; // @ts-ignore @@ -4931,12 +4985,12 @@ peg$parseEQUALS() { // @ts-ignore function // @ts-ignore -peg$parseLPAREN() { +peg$parseCOMMA() { // @ts-ignore var s0; // @ts-ignore - if (input.charCodeAt(peg$currPos) === 40) { + if (input.charCodeAt(peg$currPos) === 44) { // @ts-ignore s0 = peg$c39; // @ts-ignore @@ -4955,12 +5009,12 @@ peg$parseLPAREN() { // @ts-ignore function // @ts-ignore -peg$parseRPAREN() { +peg$parseEQUALS() { // @ts-ignore var s0; // @ts-ignore - if (input.charCodeAt(peg$currPos) === 41) { + if (input.charCodeAt(peg$currPos) === 61) { // @ts-ignore s0 = peg$c40; // @ts-ignore @@ -4977,6 +5031,54 @@ peg$parseRPAREN() { return s0; } +// @ts-ignore + function // @ts-ignore +peg$parseLPAREN() { +// @ts-ignore + var s0; + +// @ts-ignore + if (input.charCodeAt(peg$currPos) === 40) { +// @ts-ignore + s0 = peg$c41; +// @ts-ignore + peg$currPos++; +// @ts-ignore + } else { +// @ts-ignore + s0 = peg$FAILED; +// @ts-ignore + if (peg$silentFails === 0) { peg$fail(peg$e49); } + } + +// @ts-ignore + return s0; + } + +// @ts-ignore + function // @ts-ignore +peg$parseRPAREN() { +// @ts-ignore + var s0; + +// @ts-ignore + if (input.charCodeAt(peg$currPos) === 41) { +// @ts-ignore + s0 = peg$c42; +// @ts-ignore + peg$currPos++; +// @ts-ignore + } else { +// @ts-ignore + s0 = peg$FAILED; +// @ts-ignore + if (peg$silentFails === 0) { peg$fail(peg$e50); } + } + +// @ts-ignore + return s0; + } + // @ts-ignore function // @ts-ignore peg$parse_() { @@ -4996,14 +5098,14 @@ peg$parse_() { // @ts-ignore s1 = peg$FAILED; // @ts-ignore - if (peg$silentFails === 0) { peg$fail(peg$e49); } + if (peg$silentFails === 0) { peg$fail(peg$e51); } } // @ts-ignore if (s1 === peg$FAILED) { // @ts-ignore - if (input.substr(peg$currPos, 2) === peg$c41) { + if (input.substr(peg$currPos, 2) === peg$c43) { // @ts-ignore - s1 = peg$c41; + s1 = peg$c43; // @ts-ignore peg$currPos += 2; // @ts-ignore @@ -5011,7 +5113,7 @@ peg$parse_() { // @ts-ignore s1 = peg$FAILED; // @ts-ignore - if (peg$silentFails === 0) { peg$fail(peg$e50); } + if (peg$silentFails === 0) { peg$fail(peg$e52); } } } // @ts-ignore @@ -5031,14 +5133,14 @@ peg$parse_() { // @ts-ignore s1 = peg$FAILED; // @ts-ignore - if (peg$silentFails === 0) { peg$fail(peg$e49); } + if (peg$silentFails === 0) { peg$fail(peg$e51); } } // @ts-ignore if (s1 === peg$FAILED) { // @ts-ignore - if (input.substr(peg$currPos, 2) === peg$c41) { + if (input.substr(peg$currPos, 2) === peg$c43) { // @ts-ignore - s1 = peg$c41; + s1 = peg$c43; // @ts-ignore peg$currPos += 2; // @ts-ignore @@ -5046,7 +5148,7 @@ peg$parse_() { // @ts-ignore s1 = peg$FAILED; // @ts-ignore - if (peg$silentFails === 0) { peg$fail(peg$e50); } + if (peg$silentFails === 0) { peg$fail(peg$e52); } } } } @@ -5282,11 +5384,13 @@ export type Value = | LabelStatement | IntStatement | RealStatement + | BoolStatement | StringStatement; export type VarStatement = Identifier; export type LabelStatement = Identifier; export type IntStatement = Integer; export type RealStatement = Real; +export type BoolStatement = Integer; export type StringStatement = QuotedString; export type AccessStatement = OffsetStatement | SelectStatement; export type OffsetStatement = Integer; @@ -5307,7 +5411,14 @@ export type StoreOperation = | SUBSCRIPT; export type ArithmeticOperation = string | "**" | "%"; export type BitOperation = ">>" | "<<" | string; -export type ComparisonOperation = "==" | "<=" | ">=" | "!=" | string | "||"; +export type ComparisonOperation = + | "==" + | "<=" + | ">=" + | "!=" + | string + | "||" + | "&&"; export type Integer = { int: number }; export type QuotedString = string; export type Real = { real: number }; @@ -5318,6 +5429,7 @@ export type SELP = "SELp"; export type VAR = "VAR"; export type INT = "INT"; export type REAL = "REAL"; +export type BOOL = "BOOL"; export type STRING = "STRING"; export type APP = "APP"; export type RECORD = "RECORD"; diff --git a/test/interpreter.spec.ts b/test/interpreter.spec.ts index fa74ef0..49b741e 100644 --- a/test/interpreter.spec.ts +++ b/test/interpreter.spec.ts @@ -18,6 +18,13 @@ test('Add (1 real) and (3 int) -> result => (real 1 - result) = -3 done with cor expect(result).toEqual({ type: 'real', value: -3 }); }); +test('Branching', async () => { + const ast = peggyParse(await TestPrograms.Branching); + + const result = await evaluate(ast, testingLogger); + expect(result).toEqual({ type: 'real', value: 2 }); +}); + /* test('String equality', async () => { const ast = peggyParse(await TestPrograms.StringEquality); diff --git a/test/programs/branching.cps b/test/programs/branching.cps new file mode 100644 index 0000000..f73704c --- /dev/null +++ b/test/programs/branching.cps @@ -0,0 +1,10 @@ +PRIMOP(>=, [REAL 0, REAL 1], [resultFalse], [ + PRIMOP(+, [REAL 2, REAL 4], [result], []), + PRIMOP(<=, [INT 1, REAL 1], [resultTrue], [ + PRIMOP(&&, [VAR resultTrue, VAR resultFalse], [fin], [ + PRIMOP(-, [REAL 1, REAL 1], [result], []), + PRIMOP(+, [REAL 1, REAL 1], [twoWhenFinIsFalse], []) + ]), + PRIMOP(-, [REAL 1, REAL 1], [result], []) + ]) +]) \ No newline at end of file diff --git a/test/programs/index.ts b/test/programs/index.ts index c8f3c85..864169f 100644 --- a/test/programs/index.ts +++ b/test/programs/index.ts @@ -7,6 +7,9 @@ export namespace TestPrograms { export const PrimopScope = Bun.file( join(import.meta.dir + '/primop-scope.cps'), ).text(); + export const Branching = Bun.file( + join(import.meta.dir + '/branching.cps'), + ).text(); export const StringEquality = Bun.file( join(import.meta.dir + '/string-equal.cps'), ).text(); diff --git a/test/signature_match.spec.ts b/test/signature_match.spec.ts index 10be880..02b8c89 100644 --- a/test/signature_match.spec.ts +++ b/test/signature_match.spec.ts @@ -1,13 +1,9 @@ import { expect, test } from 'bun:test'; -import { TestPrograms } from './programs'; -import { peggyParse } from '@/parser'; import { - evaluate, type DenotableFunctionSignature, denotableTypesEquivalent, matchSignature, } from '@/interpreter'; -import { testingLogger } from './logger'; test('simple denotable types are equivalent', () => { expect(denotableTypesEquivalent('int', 'int')).toBe(true);