diff --git a/src/__tests__/__snapshots__/compiler.test.ts.snap b/src/__tests__/__snapshots__/compiler.test.ts.snap deleted file mode 100644 index 824ecb42..00000000 --- a/src/__tests__/__snapshots__/compiler.test.ts.snap +++ /dev/null @@ -1,32 +0,0 @@ -// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html - -exports[`E2E Compiler Pipeline > Compiler can do tco 1`] = ` -"(module - (type $0 (func (param i32 i32 i32) (result i32))) - (memory $0 1 150) - (export "buffer" (memory $0)) - (export "fib" (func $fib#15065)) - (func $fib#15065 (type $0) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) - (if (result i32) - (local.get $0) - (then - (return_call $fib#15065 - (i32.sub - (local.get $0) - (i32.const 1) - ) - (local.get $2) - (i32.add - (local.get $1) - (local.get $2) - ) - ) - ) - (else - (local.get $1) - ) - ) - ) -) -" -`; diff --git a/src/__tests__/compiler.test.ts b/src/__tests__/compiler.test.ts index 33b27106..9cd0dbfd 100644 --- a/src/__tests__/compiler.test.ts +++ b/src/__tests__/compiler.test.ts @@ -1,8 +1,9 @@ import { e2eVoidText, gcVoidText, tcoText } from "./fixtures/e2e-file.js"; import { compile } from "../compiler.js"; -import { describe, expect, test } from "vitest"; +import { describe, expect, test, vi } from "vitest"; import assert from "node:assert"; import { getWasmFn, getWasmInstance } from "../lib/wasm.js"; +import * as rCallUtil from "../assembler/return-call.js"; describe("E2E Compiler Pipeline", () => { test("Compiler can compile and run a basic void program", async (t) => { @@ -37,8 +38,8 @@ describe("E2E Compiler Pipeline", () => { }); test("Compiler can do tco", async (t) => { - const mod = await compile(tcoText); - mod.optimize(); - t.expect(mod.emitText()).toMatchSnapshot(); + const spy = vi.spyOn(rCallUtil, "returnCall"); + await compile(tcoText); + t.expect(spy).toHaveBeenCalledTimes(1); }); }); diff --git a/src/assembler.ts b/src/assembler.ts index 481c92c9..91b530c2 100644 --- a/src/assembler.ts +++ b/src/assembler.ts @@ -21,6 +21,7 @@ import { HeapTypeRef } from "./lib/binaryen-gc/types.js"; import { getExprType } from "./semantics/resolution/get-expr-type.js"; import { Match, MatchCase } from "./syntax-objects/match.js"; import { initExtensionHelpers } from "./assembler/extension-helpers.js"; +import { returnCall } from "./assembler/return-call.js"; export const assemble = (ast: Expr) => { const mod = new binaryen.Module(); @@ -182,7 +183,7 @@ const compileCall = (opts: CompileExprOpts): number => { const returnType = mapBinaryenType(opts, expr.fn!.returnType!); if (isReturnExpr && id === expr.parentFn?.id) { - return mod.return_call(id, args, returnType); + return returnCall(mod, id, args, returnType); } return mod.call(id, args, returnType); diff --git a/src/assembler/return-call.ts b/src/assembler/return-call.ts new file mode 100644 index 00000000..820402a7 --- /dev/null +++ b/src/assembler/return-call.ts @@ -0,0 +1,11 @@ +import binaryen from "binaryen"; +import { ExpressionRef, TypeRef } from "../lib/binaryen-gc/types.js"; + +export const returnCall = ( + mod: binaryen.Module, + fnId: string, + args: ExpressionRef[], + returnType: TypeRef +) => { + return mod.return_call(fnId, args, returnType); +};