From 519f9c3b940f4dbdde6ecf7861db9102ed43b8eb Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 12 Jan 2025 22:10:24 +0000 Subject: Compile native function declarations into Shid --- .../ShidCodeGenNativeFunctionDeclarationTests.java | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/test/java/org/shedlang/compiler/shid/ShidCodeGenNativeFunctionDeclarationTests.java (limited to 'src/test/java') diff --git a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenNativeFunctionDeclarationTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenNativeFunctionDeclarationTests.java new file mode 100644 index 00000000..90304a57 --- /dev/null +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenNativeFunctionDeclarationTests.java @@ -0,0 +1,30 @@ +package org.shedlang.compiler.shid; + +import org.junit.jupiter.api.Test; +import org.shedlang.compiler.ast.typed.TypedNativeFunctionDeclarationNode; +import org.shedlang.compiler.shid.instructions.ShidDeclareNativeFunction; + +import static org.shedlang.compiler.shid.instructions.ShidMatchers.isShidLocalStore; +import static org.zwobble.precisely.AssertThat.assertThat; +import static org.zwobble.precisely.Matchers.*; + +public class ShidCodeGenNativeFunctionDeclarationTests { + @Test + public void nativeFunctionIsCompiledToDeclareNativeFunctionInstruction() { + var node = TypedNativeFunctionDeclarationNode.builder() + .withName("f") + .build(); + var context = ShidCodeGen.Context.EMPTY + .addShedVal("f"); + + var result = ShidCodeGen.compileNamespaceStatement(node, context); + + assertThat(result.instructions(), isSequence( + instanceOf( + ShidDeclareNativeFunction.class, + has("name", x -> x.name(), equalTo("f")) + ), + isShidLocalStore("f__0") + )); + } +} -- cgit v1.2.3