diff --git a/src/vm.ts b/src/vm.ts index 1958809..197b6ab 100644 --- a/src/vm.ts +++ b/src/vm.ts @@ -401,9 +401,8 @@ export class VM { const key = this.stack.pop()! namedPairs.unshift({ key: toString(key), value }) } - for (const pair of namedPairs) { + for (const pair of namedPairs) namedArgs.set(pair.key, pair.value) - } // Pop positional arguments from stack const positionalArgs: Value[] = [] diff --git a/tests/functions.test.ts b/tests/functions.test.ts index 83c832d..fc35e78 100644 --- a/tests/functions.test.ts +++ b/tests/functions.test.ts @@ -376,6 +376,29 @@ test("CALL - named args with defaults on fixed params", async () => { expect(result).toEqual({ type: 'number', value: 5 }) }) +test("CALL - fixed params can be named", async () => { + const bytecode = toBytecode(` + MAKE_FUNCTION (a b) .func_0 + STORE minus + TRY_LOAD minus + PUSH 200 + PUSH 'a' + PUSH 900 + PUSH 1 + PUSH 1 + CALL + HALT + .func_0: + TRY_LOAD a + TRY_LOAD b + SUB + RETURN + `) + + const result = await run(bytecode) + expect(result).toEqual(toValue(700)) +}) + test("TRY_CALL - calls function if found", async () => { const bytecode = toBytecode([ ["MAKE_FUNCTION", [], ".body"],