diff --git a/src/ast/types/blocks-and-statements.ts b/src/ast/types/blocks-and-statements.ts index fe5dc7a..c55c9cd 100644 --- a/src/ast/types/blocks-and-statements.ts +++ b/src/ast/types/blocks-and-statements.ts @@ -1,3 +1,4 @@ +import { Closure } from "../../ec-evaluator/types"; import { BaseNode } from "./ast"; import { Identifier, UnannType } from "./classes"; @@ -289,3 +290,13 @@ export interface TernaryExpression extends BaseNode { consequent: Expression; alternate: Expression; } + +export interface MethodDescriptor extends BaseNode { + kind: "Descriptor"; + value: string; + returnType: string; + identifier: string; + formalParameterTypes: string[]; + closure: Closure; + isStatic: boolean; +} \ No newline at end of file diff --git a/src/ec-evaluator/__tests__/arithmetic.test.ts b/src/ec-evaluator/__tests__/arithmetic.test.ts index 62f8828..365ad2c 100644 --- a/src/ec-evaluator/__tests__/arithmetic.test.ts +++ b/src/ec-evaluator/__tests__/arithmetic.test.ts @@ -1,415 +1,431 @@ -import { evaluate } from "../interpreter"; -import { parse } from "../../ast/parser" +import { evaluate } from '../interpreter' +import { parse } from '../../ast/parser' import { ControlStub, StashStub, createContextStub, getControlItemStr, getStashItemStr -} from "./__utils__/utils"; +} from './__utils__/utils' -it("evaluate LocalVariableDeclarationStatement to a basic arithmetic operation correctly", () => { +it('evaluate LocalVariableDeclarationStatement to a basic arithmetic operation correctly', () => { const programStr = ` public class Test { public static void main(String[] args) { int y = 10 % 2; } } - `; + ` - const compilationUnit = parse(programStr); - expect(compilationUnit).toBeTruthy(); + const compilationUnit = parse(programStr) + expect(compilationUnit).toBeTruthy() - const context = createContextStub(); - context.control.push(compilationUnit!); + const context = createContextStub() + context.control.push(compilationUnit!) - const result = evaluate(context); + const result = evaluate(context) const expectedControlTrace = [ - "CompilationUnit", + 'CompilationUnit', - "ExpressionStatement", // Test.main([""]); - "NormalClassDeclaration", // public class Test {...} - "NormalClassDeclaration", // class Object {...} - - "Env", // from NormalClassDeclaration - "ConstructorDeclaration", // Object() {...} + 'ExpressionStatement', // Test.main([""]); + 'NormalClassDeclaration', // public class Test {...} + 'NormalClassDeclaration', // class Object {...} - "Env", // from NormalClassDeclaration - "MethodDeclaration", // public static void main(String[] args) {...} - "ConstructorDeclaration", // Test() {...} + 'Env', // from NormalClassDeclaration + 'ConstructorDeclaration', // Object() {...} - "Pop", - "MethodInvocation", // Test.main([""]) + 'Env', // from NormalClassDeclaration + 'MethodDeclaration', // public static void main(String[] args) {...} + 'ConstructorDeclaration', // Test() {...} - "Invocation", // () - "Literal", // [""] - "ResOverride", - "ExpressionName", // Test - "ResOverload", // main - "ResType", // [""] - "ResType", // Test + 'Pop', + 'MethodInvocation', // Test.main([""]) - "Deref", - "EvalVariable", // Test + 'Invocation', // () + 'Literal', // [""] + 'ResOverride', + 'ExpressionName', // Test + 'ResOverload', // main + 'ResType', // [""] + 'ResType', // Test - "Env", // from Invocation - "Marker", - "Block", // {...} + 'Deref', + 'EvalVariable', // Test - "Env", // from Block - "ReturnStatement", // return; - "LocalVariableDeclarationStatement", // int y = 10 % 2; + 'Env', // from Invocation + 'Marker', + 'Block', // {...} - "ExpressionStatement", // y = 10 % 2; - "LocalVariableDeclarationStatement", // int y; + 'Env', // from Block + 'ReturnStatement', // return; + 'LocalVariableDeclarationStatement', // int y = 10 % 2; - "Pop", - "Assignment", // y = 10 % 2 + 'ExpressionStatement', // y = 10 % 2; + 'LocalVariableDeclarationStatement', // int y; - "Assign", // = - "BinaryExpression", // 10 % 2 - "EvalVariable", // y + 'Pop', + 'Assignment', // y = 10 % 2 - "BinaryOperation", // % - "Literal", // 2 - "Literal", // 10 + 'Assign', // = + 'BinaryExpression', // 10 % 2 + 'EvalVariable', // y - "Reset", // return - "Void", + 'BinaryOperation', // % + 'Literal', // 2 + 'Literal', // 10 - "Reset", // skip Env from Invocation - ]; + 'Reset', // return + 'Void', + + 'Reset' // skip Env from Invocation + ] const expectedStashTrace = [ - "Test", // ResType - "String[]", // ResType - "main", // ResOverload - "Test", // EvalVariable - "Test", // Deref - "main", // ResOverride + 'Test', // ResType + 'String[]', // ResType + 'Descriptor', // ResOverload + 'Test', // EvalVariable + 'Test', // Deref + 'main', // ResOverride `[""]`, // Literal - "y", // EvalVariable - "10", // Literal - "2", // Literal - "0", // BinaryOperation % - "0", // Assign - "Void", // Void - ]; - - expect(result).toEqual(undefined); - expect((context.control as ControlStub).getTrace().map(i => getControlItemStr(i))).toEqual(expectedControlTrace); - expect((context.stash as StashStub).getTrace().map(i => getStashItemStr(i))).toEqual(expectedStashTrace); + 'y', // EvalVariable + '10', // Literal + '2', // Literal + '0', // BinaryOperation % + '0', // Assign + 'Void' // Void + ] + + expect(result).toEqual(undefined) + expect((context.control as ControlStub).getTrace().map(i => getControlItemStr(i))).toEqual( + expectedControlTrace + ) + expect((context.stash as StashStub).getTrace().map(i => getStashItemStr(i))).toEqual( + expectedStashTrace + ) // TODO test env -}); +}) -it("evaluate LocalVariableDeclarationStatement to a complex arithmetic operation correctly", () => { +it('evaluate LocalVariableDeclarationStatement to a complex arithmetic operation correctly', () => { const programStr = ` public class Test { public static void main(String[] args) { int z = 1 + (2 * 3) - 4; } } - `; + ` - const compilationUnit = parse(programStr); - expect(compilationUnit).toBeTruthy(); + const compilationUnit = parse(programStr) + expect(compilationUnit).toBeTruthy() - const context = createContextStub(); - context.control.push(compilationUnit!); + const context = createContextStub() + context.control.push(compilationUnit!) - const result = evaluate(context); + const result = evaluate(context) const expectedControlTrace = [ - "CompilationUnit", + 'CompilationUnit', + + 'ExpressionStatement', // Test.main([""]); + 'NormalClassDeclaration', // public class Test {...} + 'NormalClassDeclaration', // class Object {...} - "ExpressionStatement", // Test.main([""]); - "NormalClassDeclaration", // public class Test {...} - "NormalClassDeclaration", // class Object {...} - - "Env", // from NormalClassDeclaration - "ConstructorDeclaration", // Object() {...} + 'Env', // from NormalClassDeclaration + 'ConstructorDeclaration', // Object() {...} - "Env", // from NormalClassDeclaration - "MethodDeclaration", // public static void main(String[] args) {...} - "ConstructorDeclaration", // Test() {...} + 'Env', // from NormalClassDeclaration + 'MethodDeclaration', // public static void main(String[] args) {...} + 'ConstructorDeclaration', // Test() {...} - "Pop", - "MethodInvocation", // Test.main([""]) + 'Pop', + 'MethodInvocation', // Test.main([""]) - "Invocation", // () - "Literal", // [""] - "ResOverride", - "ExpressionName", // Test - "ResOverload", // main - "ResType", // [""] - "ResType", // Test + 'Invocation', // () + 'Literal', // [""] + 'ResOverride', + 'ExpressionName', // Test + 'ResOverload', // main + 'ResType', // [""] + 'ResType', // Test - "Deref", - "EvalVariable", // Test + 'Deref', + 'EvalVariable', // Test - "Env", // from Invocation - "Marker", - "Block", // {...} + 'Env', // from Invocation + 'Marker', + 'Block', // {...} - "Env", // from Block - "ReturnStatement", // return; - "LocalVariableDeclarationStatement", // int z = 1 + (2 * 3) - 4; + 'Env', // from Block + 'ReturnStatement', // return; + 'LocalVariableDeclarationStatement', // int z = 1 + (2 * 3) - 4; - "ExpressionStatement", // z = 1 + (2 * 3) - 4; - "LocalVariableDeclarationStatement", // int z; + 'ExpressionStatement', // z = 1 + (2 * 3) - 4; + 'LocalVariableDeclarationStatement', // int z; - "Pop", - "Assignment", // z = 1 + (2 * 3) - 4 + 'Pop', + 'Assignment', // z = 1 + (2 * 3) - 4 - "Assign", // = - "BinaryExpression", // 1 + (2 * 3) - 4 - "EvalVariable", // z + 'Assign', // = + 'BinaryExpression', // 1 + (2 * 3) - 4 + 'EvalVariable', // z - "BinaryOperation", // + - "Literal", // 1 - "BinaryExpression", // (2 * 3) - 4 + 'BinaryOperation', // + + 'Literal', // 1 + 'BinaryExpression', // (2 * 3) - 4 - "BinaryOperation", // - - "BinaryExpression", // 2 * 3 - "Literal", // 4 + 'BinaryOperation', // - + 'BinaryExpression', // 2 * 3 + 'Literal', // 4 - "BinaryOperation", // * - "Literal", // 2 - "Literal", // 3 + 'BinaryOperation', // * + 'Literal', // 2 + 'Literal', // 3 - "Reset", // return - "Void", + 'Reset', // return + 'Void', - "Reset", // skip Env from Invocation - ]; + 'Reset' // skip Env from Invocation + ] const expectedStashTrace = [ - "Test", // ResType - "String[]", // ResType - "main", // ResOverload - "Test", // EvalVariable - "Test", // Deref - "main", // ResOverride + 'Test', // ResType + 'String[]', // ResType + 'Descriptor', // ResOverload + 'Test', // EvalVariable + 'Test', // Deref + 'main', // ResOverride `[""]`, // Literal - "z", // EvalVariable - "1", // Literal - "2", // Literal - "3", // Literal - "6", // BinaryOperation * - "7", // BinaryOperation + - "4", // Literal - "3", // BinaryOperation - - "3", // Assign - "Void", // Void - ]; - - expect(result).toEqual(undefined); - expect((context.control as ControlStub).getTrace().map(i => getControlItemStr(i))).toEqual(expectedControlTrace); - expect((context.stash as StashStub).getTrace().map(i => getStashItemStr(i))).toEqual(expectedStashTrace); + 'z', // EvalVariable + '1', // Literal + '2', // Literal + '3', // Literal + '6', // BinaryOperation * + '7', // BinaryOperation + + '4', // Literal + '3', // BinaryOperation - + '3', // Assign + 'Void' // Void + ] + + expect(result).toEqual(undefined) + expect((context.control as ControlStub).getTrace().map(i => getControlItemStr(i))).toEqual( + expectedControlTrace + ) + expect((context.stash as StashStub).getTrace().map(i => getStashItemStr(i))).toEqual( + expectedStashTrace + ) // TODO test env -}); +}) -it("evaluate FieldDeclaration to a basic arithmetic expression without brackets to enforce precedence correctly", () => { +it('evaluate FieldDeclaration to a basic arithmetic expression without brackets to enforce precedence correctly', () => { const programStr = ` public class Test { static int x = 1 + 2 * 3; public static void main(String[] args) {} } - `; + ` - const compilationUnit = parse(programStr); - expect(compilationUnit).toBeTruthy(); + const compilationUnit = parse(programStr) + expect(compilationUnit).toBeTruthy() - const context = createContextStub(); - context.control.push(compilationUnit!); + const context = createContextStub() + context.control.push(compilationUnit!) - const result = evaluate(context); + const result = evaluate(context) const expectedControlTrace = [ - "CompilationUnit", - - "ExpressionStatement", // Test.main([""]); - "NormalClassDeclaration", // public class Test {...} - "NormalClassDeclaration", // class Object {...} - - "Env", // from NormalClassDeclaration - "ConstructorDeclaration", // Object() {...} - - "Env", // from NormalClassDeclaration - "MethodDeclaration", // public static void main(String[] args) {} - "ConstructorDeclaration", // Test() {...} - "FieldDeclaration", // static int x = 1 + 2 * 3; - - "Pop", - "Assign", // = - "BinaryExpression", // 1 + 2 * 3 - "EvalVariable", // x - - "BinaryOperation", // + - "BinaryExpression", // 2 * 3 - "Literal", // 1 - - "BinaryOperation", // * - "Literal", // 3 - "Literal", // 2 - - "Pop", - "MethodInvocation", // Test.main([""]) - - "Invocation", // () - "Literal", // [""] - "ResOverride", - "ExpressionName", // Test - "ResOverload", // main - "ResType", // [""] - "ResType", // Test - - "Deref", - "EvalVariable", // Test - - "Env", // from Invocation - "Marker", - "Block", // {...} - - "Env", // from Block - "ReturnStatement", // return; - - "Reset", // return - "Void", - - "Reset", // skip Env from Invocation - ]; + 'CompilationUnit', + + 'ExpressionStatement', // Test.main([""]); + 'NormalClassDeclaration', // public class Test {...} + 'NormalClassDeclaration', // class Object {...} + + 'Env', // from NormalClassDeclaration + 'ConstructorDeclaration', // Object() {...} + + 'Env', // from NormalClassDeclaration + 'MethodDeclaration', // public static void main(String[] args) {} + 'ConstructorDeclaration', // Test() {...} + 'FieldDeclaration', // static int x = 1 + 2 * 3; + + 'Pop', + 'Assign', // = + 'BinaryExpression', // 1 + 2 * 3 + 'EvalVariable', // x + + 'BinaryOperation', // + + 'BinaryExpression', // 2 * 3 + 'Literal', // 1 + + 'BinaryOperation', // * + 'Literal', // 3 + 'Literal', // 2 + + 'Pop', + 'MethodInvocation', // Test.main([""]) + + 'Invocation', // () + 'Literal', // [""] + 'ResOverride', + 'ExpressionName', // Test + 'ResOverload', // main + 'ResType', // [""] + 'ResType', // Test + + 'Deref', + 'EvalVariable', // Test + + 'Env', // from Invocation + 'Marker', + 'Block', // {...} + + 'Env', // from Block + 'ReturnStatement', // return; + + 'Reset', // return + 'Void', + + 'Reset' // skip Env from Invocation + ] const expectedStashTrace = [ - "x", // EvalVariable - "1", // Literal - "2", // Literal - "3", // Literal - "6", // BinaryOperation * - "7", // BinaryOperation + - "7", // Assign - "Test", // ResType - "String[]", // ResType - "main", // ResOverload - "Test", // EvalVariable - "Test", // Deref - "main", // ResOverride + 'x', // EvalVariable + '1', // Literal + '2', // Literal + '3', // Literal + '6', // BinaryOperation * + '7', // BinaryOperation + + '7', // Assign + 'Test', // ResType + 'String[]', // ResType + 'Descriptor', // ResOverload + 'Test', // EvalVariable + 'Test', // Deref + 'main', // ResOverride `[""]`, // Literal - "Void", // Void - ]; - - expect(result).toEqual(undefined); - expect((context.control as ControlStub).getTrace().map(i => getControlItemStr(i))).toEqual(expectedControlTrace); - expect((context.stash as StashStub).getTrace().map(i => getStashItemStr(i))).toEqual(expectedStashTrace); + 'Void' // Void + ] + + expect(result).toEqual(undefined) + expect((context.control as ControlStub).getTrace().map(i => getControlItemStr(i))).toEqual( + expectedControlTrace + ) + expect((context.stash as StashStub).getTrace().map(i => getStashItemStr(i))).toEqual( + expectedStashTrace + ) // TODO test env -}); +}) -it("evaluate FieldDeclaration to a complex arithmetic expression without brackets to enforce precedence correctly", () => { +it('evaluate FieldDeclaration to a complex arithmetic expression without brackets to enforce precedence correctly', () => { const programStr = ` public class Test { static int x = 2 / 1 - 3 * (5 % 4) + 6; public static void main(String[] args) {} } - `; + ` - const compilationUnit = parse(programStr); - expect(compilationUnit).toBeTruthy(); + const compilationUnit = parse(programStr) + expect(compilationUnit).toBeTruthy() - const context = createContextStub(); - context.control.push(compilationUnit!); + const context = createContextStub() + context.control.push(compilationUnit!) - const result = evaluate(context); + const result = evaluate(context) const expectedControlTrace = [ - "CompilationUnit", - - "ExpressionStatement", // Test.main([""]); - "NormalClassDeclaration", // public class Test {...} - "NormalClassDeclaration", // class Object {...} - - "Env", // from NormalClassDeclaration - "ConstructorDeclaration", // Object() {...} - - "Env", // from NormalClassDeclaration - "MethodDeclaration", // public static void main(String[] args) {} - "ConstructorDeclaration", // Test() {...} - "FieldDeclaration", // static int x = 2 / 1 - 3 * (5 % 4) + 6; - - "Pop", - "Assign", // = - "BinaryExpression", // 2 / 1 - 3 * (5 % 4) + 6 - "EvalVariable", // x - - "BinaryOperation", // + - "Literal", // 6 - "BinaryExpression", // 2 / 1 - 3 * (5 % 4) - - "BinaryOperation", // - - "BinaryExpression", // 3 * (5 % 4) - "BinaryExpression", // 2 / 1 - - "BinaryOperation", // / - "Literal", // 1 - "Literal", // 2 - - "BinaryOperation", // * - "BinaryExpression", // 5 % 4 - "Literal", // 3 - - "BinaryOperation", // % - "Literal", // 4 - "Literal", // 5 - - "Pop", - "MethodInvocation", // Test.main([""]) - - "Invocation", // () - "Literal", // [""] - "ResOverride", - "ExpressionName", // Test - "ResOverload", // main - "ResType", // [""] - "ResType", // Test - - "Deref", - "EvalVariable", // Test - - "Env", // from Invocation - "Marker", - "Block", // {...} - - "Env", // from Block - "ReturnStatement", // return; - - "Reset", // return - "Void", - - "Reset", // skip Env from Invocation - ]; + 'CompilationUnit', + + 'ExpressionStatement', // Test.main([""]); + 'NormalClassDeclaration', // public class Test {...} + 'NormalClassDeclaration', // class Object {...} + + 'Env', // from NormalClassDeclaration + 'ConstructorDeclaration', // Object() {...} + + 'Env', // from NormalClassDeclaration + 'MethodDeclaration', // public static void main(String[] args) {} + 'ConstructorDeclaration', // Test() {...} + 'FieldDeclaration', // static int x = 2 / 1 - 3 * (5 % 4) + 6; + + 'Pop', + 'Assign', // = + 'BinaryExpression', // 2 / 1 - 3 * (5 % 4) + 6 + 'EvalVariable', // x + + 'BinaryOperation', // + + 'Literal', // 6 + 'BinaryExpression', // 2 / 1 - 3 * (5 % 4) + + 'BinaryOperation', // - + 'BinaryExpression', // 3 * (5 % 4) + 'BinaryExpression', // 2 / 1 + + 'BinaryOperation', // / + 'Literal', // 1 + 'Literal', // 2 + + 'BinaryOperation', // * + 'BinaryExpression', // 5 % 4 + 'Literal', // 3 + + 'BinaryOperation', // % + 'Literal', // 4 + 'Literal', // 5 + + 'Pop', + 'MethodInvocation', // Test.main([""]) + + 'Invocation', // () + 'Literal', // [""] + 'ResOverride', + 'ExpressionName', // Test + 'ResOverload', // main + 'ResType', // [""] + 'ResType', // Test + + 'Deref', + 'EvalVariable', // Test + + 'Env', // from Invocation + 'Marker', + 'Block', // {...} + + 'Env', // from Block + 'ReturnStatement', // return; + + 'Reset', // return + 'Void', + + 'Reset' // skip Env from Invocation + ] const expectedStashTrace = [ - "x", // EvalVariable - "2", // Literal - "1", // Literal - "2", // BinaryOperation / - "3", // Literal - "5", // Literal - "4", // Literal - "1", // BinaryOperation % - "3", // BinaryOperation + - "-1", // BinaryOperation - - "6", // Literal - "5", // BinaryOperation + - "5", // Assign - "Test", // ResType - "String[]", // ResType - "main", // ResOverload - "Test", // EvalVariable - "Test", // Deref - "main", // ResOverride + 'x', // EvalVariable + '2', // Literal + '1', // Literal + '2', // BinaryOperation / + '3', // Literal + '5', // Literal + '4', // Literal + '1', // BinaryOperation % + '3', // BinaryOperation + + '-1', // BinaryOperation - + '6', // Literal + '5', // BinaryOperation + + '5', // Assign + 'Test', // ResType + 'String[]', // ResType + 'Descriptor', // ResOverload + 'Test', // EvalVariable + 'Test', // Deref + 'main', // ResOverride `[""]`, // Literal - "Void", // Void - ]; - - expect(result).toEqual(undefined); - expect((context.control as ControlStub).getTrace().map(i => getControlItemStr(i))).toEqual(expectedControlTrace); - expect((context.stash as StashStub).getTrace().map(i => getStashItemStr(i))).toEqual(expectedStashTrace); + 'Void' // Void + ] + + expect(result).toEqual(undefined) + expect((context.control as ControlStub).getTrace().map(i => getControlItemStr(i))).toEqual( + expectedControlTrace + ) + expect((context.stash as StashStub).getTrace().map(i => getStashItemStr(i))).toEqual( + expectedStashTrace + ) // TODO test env -}); +}) diff --git a/src/ec-evaluator/__tests__/class-decl.test.ts b/src/ec-evaluator/__tests__/class-decl.test.ts index 7723f25..0f75a80 100644 --- a/src/ec-evaluator/__tests__/class-decl.test.ts +++ b/src/ec-evaluator/__tests__/class-decl.test.ts @@ -72,7 +72,7 @@ describe("evaluate NormalClassDeclaration correctly", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -156,7 +156,7 @@ describe("evaluate FieldDeclaration correctly", () => { "null", // Assign "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -238,7 +238,7 @@ describe("evaluate FieldDeclaration correctly", () => { "1", // Assign "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -312,7 +312,7 @@ describe("evaluate MethodDeclaration correctly", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -386,7 +386,7 @@ describe("evaluate MethodDeclaration correctly", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -462,7 +462,7 @@ describe("evaluate MethodDeclaration correctly", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride diff --git a/src/ec-evaluator/__tests__/class-instance-creation.test.ts b/src/ec-evaluator/__tests__/class-instance-creation.test.ts index e25a4d4..fa35d2f 100644 --- a/src/ec-evaluator/__tests__/class-instance-creation.test.ts +++ b/src/ec-evaluator/__tests__/class-instance-creation.test.ts @@ -137,7 +137,7 @@ describe("evaluate default constructor", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable, "Test", // Deref "main", // ResOverride @@ -296,7 +296,7 @@ describe("evaluate default constructor", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable, "Test", // Deref "main", // ResOverride @@ -469,7 +469,7 @@ describe("evaluate default constructor", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable, "Test", // Deref "main", // ResOverride @@ -646,7 +646,7 @@ describe("evaluate default constructor", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable, "Test", // Deref "main", // ResOverride @@ -812,7 +812,7 @@ describe("evaluate default constructor", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable, "Test", // Deref "main", // ResOverride diff --git a/src/ec-evaluator/__tests__/constructor-overloading.test.ts b/src/ec-evaluator/__tests__/constructor-overloading.test.ts index ec7d2b9..7e3ee82 100644 --- a/src/ec-evaluator/__tests__/constructor-overloading.test.ts +++ b/src/ec-evaluator/__tests__/constructor-overloading.test.ts @@ -195,7 +195,7 @@ describe("evaluate constructor overloading resolution correctly", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -387,7 +387,7 @@ describe("evaluate constructor overloading resolution correctly", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable, "Test", // Deref "main", // ResOverride @@ -577,7 +577,7 @@ describe("evaluate constructor overloading resolution correctly", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable, "Test", // Deref "main", // ResOverride @@ -791,7 +791,7 @@ describe("evaluate constructor overloading resolution correctly", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable, "Test", // Deref "main", // ResOverride diff --git a/src/ec-evaluator/__tests__/inheritance-instance-field.test.ts b/src/ec-evaluator/__tests__/inheritance-instance-field.test.ts index a4d9563..591e810 100644 --- a/src/ec-evaluator/__tests__/inheritance-instance-field.test.ts +++ b/src/ec-evaluator/__tests__/inheritance-instance-field.test.ts @@ -218,7 +218,7 @@ describe("evaluate instance fields with inheritance", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -247,7 +247,7 @@ describe("evaluate instance fields with inheritance", () => { "Object", // Deref "Object", // Assign "Parent", // ResType - "test", // ResOverload + "Descriptor", // ResOverload "p", // EvalVariable "Object", // Deref "test", // ResOverride @@ -488,7 +488,7 @@ describe("evaluate instance fields with inheritance", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -521,7 +521,7 @@ describe("evaluate instance fields with inheritance", () => { "Object", // Deref "Object", // Assign "Parent", // ResType - "test", // ResOverload + "Descriptor", // ResOverload "p", // EvalVariable "Object", // Deref "test", // ResOverride @@ -718,7 +718,7 @@ describe("evaluate instance fields with inheritance", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -949,7 +949,7 @@ describe("evaluate instance fields with inheritance", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -1184,7 +1184,7 @@ describe("evaluate instance fields with inheritance", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride diff --git a/src/ec-evaluator/__tests__/inheritance-static-field.test.ts b/src/ec-evaluator/__tests__/inheritance-static-field.test.ts index f5befa9..d87df26 100644 --- a/src/ec-evaluator/__tests__/inheritance-static-field.test.ts +++ b/src/ec-evaluator/__tests__/inheritance-static-field.test.ts @@ -103,7 +103,7 @@ describe("evaluate static fields with inheritance", () => { "1", // Assign "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -225,7 +225,7 @@ describe("evaluate static fields with inheritance", () => { "2", // Assign "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -419,7 +419,7 @@ describe("evaluate static fields with inheritance", () => { "1", // Assign "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -642,7 +642,7 @@ describe("evaluate static fields with inheritance", () => { "2", // Assign "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -865,7 +865,7 @@ describe("evaluate static fields with inheritance", () => { "2", // Assign "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride diff --git a/src/ec-evaluator/__tests__/local-var-assignment.test.ts b/src/ec-evaluator/__tests__/local-var-assignment.test.ts index 471d1ea..16d5798 100644 --- a/src/ec-evaluator/__tests__/local-var-assignment.test.ts +++ b/src/ec-evaluator/__tests__/local-var-assignment.test.ts @@ -69,7 +69,7 @@ it("evaluate LocalVariableDeclarationStatement without variableInitializer corre const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -154,7 +154,7 @@ it("evaluate LocalVariableDeclarationStatement with variableInitializer correctl const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -241,7 +241,7 @@ it("evaluate Assignment correctly", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -344,7 +344,7 @@ it("evaluate LocalVariableDeclarationStatement with local variable as variableIn const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride diff --git a/src/ec-evaluator/__tests__/main-mtd.test.ts b/src/ec-evaluator/__tests__/main-mtd.test.ts index 60d9d38..710d2de 100644 --- a/src/ec-evaluator/__tests__/main-mtd.test.ts +++ b/src/ec-evaluator/__tests__/main-mtd.test.ts @@ -107,7 +107,7 @@ describe("evaluate main method correctly", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -313,7 +313,7 @@ describe("evaluate main method correctly", () => { const expectedStashTrace = [ "test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "test", // EvalVariable "test", // Deref "main", // ResOverride @@ -343,7 +343,7 @@ describe("evaluate main method correctly", () => { "Object", // Deref "Object", // Assign "test", // ResType - "test", // ResOverload + "Descriptor", // ResOverload "test", // EvalVariable "Object", // Deref "test", // ResOverride diff --git a/src/ec-evaluator/__tests__/mtd-overloading.test.ts b/src/ec-evaluator/__tests__/mtd-overloading.test.ts index 7345884..734676e 100644 --- a/src/ec-evaluator/__tests__/mtd-overloading.test.ts +++ b/src/ec-evaluator/__tests__/mtd-overloading.test.ts @@ -113,7 +113,7 @@ describe("evaluate method overloading correctly", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -121,7 +121,7 @@ describe("evaluate method overloading correctly", () => { "x", // EvalVariable "Test", // ResType "int", // ResType - "test", // ResOverlaod + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "test", // ResOverride @@ -330,7 +330,7 @@ describe("evaluate method overloading correctly", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -360,7 +360,7 @@ describe("evaluate method overloading correctly", () => { "Object", // Deref "Object", // Assign "Test", // ResType - "Test", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Object", // Deref "Test", // ResOverride @@ -584,7 +584,7 @@ describe("evaluate method overloading correctly", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -614,7 +614,7 @@ describe("evaluate method overloading correctly", () => { "Object", // Assign "Test", // ResType "Test", // ResType - "test", // ResOverload + "Descriptor", // ResOverload "t", // EvalVariable "Object", // Deref "test", // ResOverride @@ -844,7 +844,7 @@ describe("evaluate method overloading correctly", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -874,7 +874,7 @@ describe("evaluate method overloading correctly", () => { "Object", // Assign "Test", // ResType "Test", // ResType - "test", // ResOverload + "Descriptor", // ResOverload "t", // EvalVariable "Object", // Deref "test", // ResOverride @@ -1109,7 +1109,7 @@ describe("evaluate method overloading correctly", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -1140,7 +1140,7 @@ describe("evaluate method overloading correctly", () => { "Test", // ResType "Test", // ResType "Test", // ResType - "test", // ResOverload + "Descriptor", // ResOverload "t", // EvalVariable "Object", // Deref "test", // ResOverride @@ -1305,13 +1305,13 @@ describe("evaluate method overloading correctly", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride `[""]`, // Literal "Test", // ResType - "test", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "test", // ResOverride diff --git a/src/ec-evaluator/__tests__/mtd-overriding.test.ts b/src/ec-evaluator/__tests__/mtd-overriding.test.ts index 9de9854..67c28a3 100644 --- a/src/ec-evaluator/__tests__/mtd-overriding.test.ts +++ b/src/ec-evaluator/__tests__/mtd-overriding.test.ts @@ -213,7 +213,7 @@ describe("evaluate method overriding correctly", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -242,7 +242,7 @@ describe("evaluate method overriding correctly", () => { "Object", // Deref "Object", // Assign "Parent", // ResType - "test", // ResOverload + "Descriptor", // ResOverload "p", // EvalVariable "Object", // Deref "test", // ResOverride @@ -463,7 +463,7 @@ describe("evaluate method overriding correctly", () => { "0", // Assign "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -488,7 +488,7 @@ describe("evaluate method overriding correctly", () => { "Object", // Deref "Object", // Assign "Parent", // ResType - "test", // ResOverload + "Descriptor", // ResOverload "p", // EvalVariable "Object", // Deref "test", // ResOverride @@ -808,7 +808,7 @@ describe("evaluate method overriding correctly", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -861,7 +861,7 @@ describe("evaluate method overriding correctly", () => { "Object", // Assign "Parent", // ResType "Test", // ResType - "test", // ResOverload + "Descriptor", // ResOverload "p", // EvalVariable "Object", // Deref "test", // ResOverride @@ -1184,7 +1184,7 @@ describe("evaluate method overriding correctly", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -1237,7 +1237,7 @@ describe("evaluate method overriding correctly", () => { "Object", // Assign "Parent", // ResType "Test", // ResType - "test", // ResOverload + "Descriptor", // ResOverload "p", // EvalVariable "Object", // Deref "test", // ResOverride diff --git a/src/ec-evaluator/__tests__/qualified-mtd-inv.test.ts b/src/ec-evaluator/__tests__/qualified-mtd-inv.test.ts index d020462..b4ecc18 100644 --- a/src/ec-evaluator/__tests__/qualified-mtd-inv.test.ts +++ b/src/ec-evaluator/__tests__/qualified-mtd-inv.test.ts @@ -96,13 +96,13 @@ describe("evaluate simple qualified MethodInvocation correctly", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride `[""]`, // Literal "Test", // ResType - "test", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "test", // ResOverride @@ -260,7 +260,7 @@ describe("evaluate simple qualified MethodInvocation correctly", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -279,7 +279,7 @@ describe("evaluate simple qualified MethodInvocation correctly", () => { "Object", // Deref "Object", // Assign "Test", // ResType - "test", // ResOverload + "Descriptor", // ResOverload "test", // EvalVariable "Object", // Deref "test", // ResOverride @@ -468,7 +468,7 @@ describe("evaluate simple qualified MethodInvocation correctly", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -487,14 +487,14 @@ describe("evaluate simple qualified MethodInvocation correctly", () => { "Object", // Deref "Object", // Assign "Test", // ResType - "test", // ResOverload + "Descriptor", // ResOverload "test", // EvalVariable "Object", // Deref "test", // ResOverride "Object", "Test", // ResType "int", // ResType - "test", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "test", // ResOverride @@ -663,7 +663,7 @@ describe("evaluate simple qualified MethodInvocation correctly", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -683,7 +683,7 @@ describe("evaluate simple qualified MethodInvocation correctly", () => { "Object", // Assign "x", // EvalVariable "Test", // ResType - "test", // ResOverload + "Descriptor", // ResOverload "test", // EvalVariable "Object", // Deref "test", // ResOverride @@ -936,7 +936,7 @@ describe("evaluate simple qualified MethodInvocation correctly", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -955,7 +955,7 @@ describe("evaluate simple qualified MethodInvocation correctly", () => { "Object", // Deref "Object", // Assign "Test", // ResType - "test", // ResOverload + "Descriptor", // ResOverload "test", // EvalVariable "Object", // Deref "test", // ResOverride @@ -975,7 +975,7 @@ describe("evaluate simple qualified MethodInvocation correctly", () => { "Object", // Assign "Test", // ResType "int", // ResType - "test", // ResOverload + "Descriptor", // ResOverload "test", // EvalVariable "Object", // Deref "test", // ResOverride @@ -1098,14 +1098,14 @@ describe("evaluate complex qualified MethodInvocation correctly", () => { "null", // Assign "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride `[""]`, // Literal "Test", // ResType "Test", // ResTypeCont - "test", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "t", // Res "null", // Deref @@ -1288,7 +1288,7 @@ describe("evaluate complex qualified MethodInvocation correctly", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -1312,7 +1312,7 @@ describe("evaluate complex qualified MethodInvocation correctly", () => { "Object", // Assign "Test", // ResType "AnotherTest", // ResTypeCont - "test", // ResOverload + "Descriptor", // ResOverload "t", // EvalVariable "t", // Res "null", // Deref @@ -1520,7 +1520,7 @@ describe("evaluate complex qualified MethodInvocation correctly", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -1550,7 +1550,7 @@ describe("evaluate complex qualified MethodInvocation correctly", () => { "Object", // Assign "Test", // ResType "Test", // ResTypeCont - "test", // ResOverload + "Descriptor", // ResOverload "t", // EvalVariable "t", // Res "null", // Deref diff --git a/src/ec-evaluator/__tests__/qualified-names-this.test.ts b/src/ec-evaluator/__tests__/qualified-names-this.test.ts index 302ff12..75bf95d 100644 --- a/src/ec-evaluator/__tests__/qualified-names-this.test.ts +++ b/src/ec-evaluator/__tests__/qualified-names-this.test.ts @@ -90,7 +90,7 @@ describe("evaluate simple qualified names correctly", () => { "0", // Assign "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -248,7 +248,7 @@ describe("evaluate simple qualified names correctly", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -370,7 +370,7 @@ describe("evaluate simple qualified names correctly", () => { "0", // Assign "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -535,7 +535,7 @@ describe("evaluate simple qualified names correctly", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -673,7 +673,7 @@ describe("evaluate complex qualified names correctly", () => { "null", // Assign "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride diff --git a/src/ec-evaluator/__tests__/simple-mtd-inv.test.ts b/src/ec-evaluator/__tests__/simple-mtd-inv.test.ts index 9c54370..ac9a389 100644 --- a/src/ec-evaluator/__tests__/simple-mtd-inv.test.ts +++ b/src/ec-evaluator/__tests__/simple-mtd-inv.test.ts @@ -96,13 +96,13 @@ describe("evaluate static MethodInvocation correctly", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride `[""]`, // Literal "Test", // ResType - "test", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "test", // ResOverride @@ -291,7 +291,7 @@ describe("evaluate static MethodInvocation correctly", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -310,14 +310,14 @@ describe("evaluate static MethodInvocation correctly", () => { "Object", // Deref "Object", // Assign "Test", // ResType - "test", // ResOverload + "Descriptor", // ResOverload "test", // EvalVariable "Object", // Deref "test", // ResOverride "Object", "Test", // ResType "int", // ResType - "test", // ResOverload + "Descriptor", // ResOverload "this", // EvalVariable "Object", // Deref "test", // ResOverride @@ -510,7 +510,7 @@ describe("evaluate instance MethodInvocation correctly", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -529,14 +529,14 @@ describe("evaluate instance MethodInvocation correctly", () => { "Object", // Deref "Object", // Assign "Test", // ResType - "test", // ResOverload + "Descriptor", // ResOverload "test", // EvalVariable "Object", // Deref "test", // ResOverride "Object", "Test", // ResType "int", // ResType - "test", // ResOverload + "Descriptor", // ResOverload "this", // EvalVariable "Object", // Deref "test", // ResOverride diff --git a/src/ec-evaluator/__tests__/this-keyword.test.ts b/src/ec-evaluator/__tests__/this-keyword.test.ts index 8683a0f..b9e4e3d 100644 --- a/src/ec-evaluator/__tests__/this-keyword.test.ts +++ b/src/ec-evaluator/__tests__/this-keyword.test.ts @@ -178,7 +178,7 @@ describe("evaluate field access with this keyword correctly", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -201,7 +201,7 @@ describe("evaluate field access with this keyword correctly", () => { "Object", // Deref "Object", // Assign "Test", // ResType - "test", // ResOverload + "Descriptor", // ResOverload "test", // EvalVariable "Object", // Deref "test", // ResOverride @@ -395,7 +395,7 @@ describe("evaluate field access with this keyword correctly", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -418,7 +418,7 @@ describe("evaluate field access with this keyword correctly", () => { "Object", // Deref "Object", // Assign "Test", // ResType - "test", // ResOverload + "Descriptor", // ResOverload "test", // EvalVariable "Object", // Deref "test", // ResOverride @@ -615,7 +615,7 @@ describe("evaluate method invocation with this keyword correctly", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -634,14 +634,14 @@ describe("evaluate method invocation with this keyword correctly", () => { "Object", // Deref "Object", // Assign "Test", // ResType - "test", // ResOverload + "Descriptor", // ResOverload "test", // EvalVariable "Object", // Deref "test", // ResOverride "Object", "Test", // ResType "int", // ResType - "test", // ResOverload + "Descriptor", // ResOverload "this", // EvalVariable "Object", // Deref "test", // ResOverride @@ -837,7 +837,7 @@ describe("evaluate method invocation with this keyword correctly", () => { const expectedStashTrace = [ "Test", // ResType "String[]", // ResType - "main", // ResOverload + "Descriptor", // ResOverload "Test", // EvalVariable "Test", // Deref "main", // ResOverride @@ -856,14 +856,14 @@ describe("evaluate method invocation with this keyword correctly", () => { "Object", // Deref "Object", // Assign "Test", // ResType - "test", // ResOverload + "Descriptor", // ResOverload "test", // EvalVariable "Object", // Deref "test", // ResOverride "Object", "Test", // ResType "int", // ResType - "test", // ResOverload + "Descriptor", // ResOverload "this", // EvalVariable "Object", // Deref "test", // ResOverride diff --git a/src/ec-evaluator/index.ts b/src/ec-evaluator/index.ts index c133dcb..c8ec4a5 100644 --- a/src/ec-evaluator/index.ts +++ b/src/ec-evaluator/index.ts @@ -29,6 +29,7 @@ export const runECEvaluator = ( } catch (e) { // Possible interpreting language error thrown, so conversion to RuntimeError may be required. const error = e.type ? e : new RuntimeError(e.message); + console.log(error); context.errors.push(error); return new Promise((resolve, _) => { resolve({ status: 'error', context } as Error); diff --git a/src/ec-evaluator/interpreter.ts b/src/ec-evaluator/interpreter.ts index 0eeb08e..b55e843 100644 --- a/src/ec-evaluator/interpreter.ts +++ b/src/ec-evaluator/interpreter.ts @@ -1,4 +1,4 @@ -import { cloneDeep } from "lodash"; +import { cloneDeep, } from "lodash"; import { Assignment, @@ -13,6 +13,7 @@ import { LocalVariableDeclarationStatement, LocalVariableType, MethodInvocation, + MethodDescriptor, ReturnStatement, VariableDeclarator, Void, @@ -23,6 +24,7 @@ import { FormalParameter, Identifier, MethodDeclaration, + MethodHeader, NormalClassDeclaration, UnannType, } from "../ast/types/classes"; @@ -773,7 +775,35 @@ const cmdEvaluators: { [type: string]: CmdEvaluator } = { // Method overloading resolution. const classStore: EnvNode = environment.global; const closure: Closure = resOverload(classToSearchIn, command.name, argTypes, classStore); - stash.push(closure); + + if (closure.mtdOrCon.kind == "MethodDeclaration") { + const methodIsStatic: boolean = isStatic(closure.mtdOrCon); + + const header: MethodHeader = (closure.mtdOrCon).methodHeader; + + const params: string[] = header.formalParameterList + .map(fp => fp.unannType); + + const methodDescriptor: MethodDescriptor = methodIsStatic ? { + kind: "Descriptor", + value: `${header.result} ${targetType.type}::${header.identifier}(${params.length === 0 ? "" : params.reduce((x, y) => x + ", " + y)})`, + returnType: header.result, + identifier: header.identifier, + formalParameterTypes: params, + closure: closure, + isStatic: true, + } : { + kind: "Descriptor", + value: `${header.result} ${header.identifier}(${params.length === 0 ? "" : params.reduce((x, y) => x + ", " + y)})`, + returnType: header.result, + identifier: header.identifier, + formalParameterTypes: params, + closure: closure, + isStatic: false, + } + + stash.push(methodDescriptor); + } // Post-processing required if overload resolved method is instance method. if (isInstance(closure.mtdOrCon as MethodDeclaration)) { @@ -793,11 +823,11 @@ const cmdEvaluators: { [type: string]: CmdEvaluator } = { stash: Stash, ) => { const target = stash.pop()!; - const overloadResolvedClosure = stash.pop()! as Closure; + const overloadResolvedClosure = stash.pop()! as MethodDescriptor; - if (isStatic(overloadResolvedClosure.mtdOrCon as MethodDeclaration)) { + if (overloadResolvedClosure.isStatic) { // No method overriding resolution is required if resolved method is a static method. - stash.push(overloadResolvedClosure); + stash.push(overloadResolvedClosure.closure); return; } diff --git a/src/ec-evaluator/types.ts b/src/ec-evaluator/types.ts index 3b7eb17..9368678 100644 --- a/src/ec-evaluator/types.ts +++ b/src/ec-evaluator/types.ts @@ -1,5 +1,5 @@ import { Node } from "../ast/types/ast"; -import { Expression, Literal, Void } from "../ast/types/blocks-and-statements"; +import { Expression, Literal, Void, MethodDescriptor } from "../ast/types/blocks-and-statements"; import { ConstructorDeclaration, FieldDeclaration, @@ -121,7 +121,7 @@ export type Instr = * Components */ export type ControlItem = Node | Instr; -export type StashItem = Primitive | Reference | Value | Void | Type; +export type StashItem = Primitive | Reference | Value | Void | Type | MethodDescriptor; export type Name = string; export type Value = Variable | Closure | Class; diff --git a/src/ec-evaluator/utils.ts b/src/ec-evaluator/utils.ts index ac73751..f8af824 100644 --- a/src/ec-evaluator/utils.ts +++ b/src/ec-evaluator/utils.ts @@ -7,6 +7,7 @@ import { Literal, MethodInvocation, ReturnStatement, + MethodDescriptor, } from "../ast/types/blocks-and-statements"; import { ConstructorDeclaration, @@ -453,11 +454,11 @@ export const resOverload = ( export const resOverride = ( classToSearchIn: Class, - overloadResolvedClosure: Closure, + overloadResolvedMethodDescriptor: MethodDescriptor, ): Closure => { - const overloadResolvedMtd = overloadResolvedClosure.mtdOrCon as MethodDeclaration; - const name = overloadResolvedMtd.methodHeader.identifier; - const overloadResolvedClosureParams = overloadResolvedMtd.methodHeader.formalParameterList; + // const overloadResolvedMtd = overloadResolvedClosure.mtdOrCon as MethodDeclaration; + const name = overloadResolvedMethodDescriptor.identifier; + const overloadResolvedClosureParams = overloadResolvedMethodDescriptor.formalParameterTypes; const closures: Closure[] = []; for (const [closureName, closure] of classToSearchIn.frame.frame.entries()) { @@ -467,7 +468,7 @@ export const resOverride = ( } } - let overrideResolvedClosure = overloadResolvedClosure; + let overrideResolvedClosure = overloadResolvedMethodDescriptor.closure; for (const closure of closures) { const params = (closure.mtdOrCon as MethodDeclaration).methodHeader.formalParameterList; @@ -475,7 +476,7 @@ export const resOverride = ( let match = true; for (let i = 0; i < overloadResolvedClosureParams.length; i++) { - match &&= (params[i].unannType === overloadResolvedClosureParams[i].unannType); + match &&= (params[i].unannType === overloadResolvedClosureParams[i]); if (!match) break; // short circuit }