diff --git a/.gradle/6.7.1/executionHistory/executionHistory.bin b/.gradle/6.7.1/executionHistory/executionHistory.bin index 0f99f48..6fb2f27 100644 Binary files a/.gradle/6.7.1/executionHistory/executionHistory.bin and b/.gradle/6.7.1/executionHistory/executionHistory.bin differ diff --git a/.gradle/6.7.1/executionHistory/executionHistory.lock b/.gradle/6.7.1/executionHistory/executionHistory.lock index 2e0b03c..78cb830 100644 Binary files a/.gradle/6.7.1/executionHistory/executionHistory.lock and b/.gradle/6.7.1/executionHistory/executionHistory.lock differ diff --git a/.gradle/6.7.1/fileHashes/fileHashes.bin b/.gradle/6.7.1/fileHashes/fileHashes.bin index baa3c7b..b3a719e 100644 Binary files a/.gradle/6.7.1/fileHashes/fileHashes.bin and b/.gradle/6.7.1/fileHashes/fileHashes.bin differ diff --git a/.gradle/6.7.1/fileHashes/fileHashes.lock b/.gradle/6.7.1/fileHashes/fileHashes.lock index e4e8c51..2c51f1a 100644 Binary files a/.gradle/6.7.1/fileHashes/fileHashes.lock and b/.gradle/6.7.1/fileHashes/fileHashes.lock differ diff --git a/.gradle/6.7.1/javaCompile/classAnalysis.bin b/.gradle/6.7.1/javaCompile/classAnalysis.bin index 37f6347..0538442 100644 Binary files a/.gradle/6.7.1/javaCompile/classAnalysis.bin and b/.gradle/6.7.1/javaCompile/classAnalysis.bin differ diff --git a/.gradle/6.7.1/javaCompile/javaCompile.lock b/.gradle/6.7.1/javaCompile/javaCompile.lock index 4e5c91f..6ef3bb9 100644 Binary files a/.gradle/6.7.1/javaCompile/javaCompile.lock and b/.gradle/6.7.1/javaCompile/javaCompile.lock differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index a9b4906..d562c1a 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/src/test/java/com/vectron/fcl/FclDasmTest.java b/src/test/java/com/vectron/fcl/FclDasmTest.java new file mode 100644 index 0000000..d010116 --- /dev/null +++ b/src/test/java/com/vectron/fcl/FclDasmTest.java @@ -0,0 +1,115 @@ +package com.vectron.fcl; + +import com.vectron.fcl.Fcl; +import com.vectron.fcl.FclStack; +import com.vectron.fcl.RamTranscript; +import com.vectron.fcl.types.Obj; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.io.FileReader; +import java.io.IOException; + +import static org.junit.Assert.assertEquals; + +public class FclDasmTest { // TODO + private Fcl fcl; + private RamTranscript transcript = new RamTranscript(); + + @Before + public void setUp() throws Exception { + resetForth(); + assertEquals(0, fcl.stackSize()); + assertEquals(0, fcl.rStackSize()); + assertEquals(0, evalPop("psp @").longValue()); + } + + private void resetForth() throws IOException { + fcl = new Fcl(new FclStack(), 524288, transcript); + load("core.forth"); + load("ops.forth"); + load("locals.forth"); + load("quotations.forth"); + load("collections.forth"); + load("http.forth"); + } + + private void load(final String fileName) throws IOException { + FileReader reader = null; + try { + reader = new FileReader(System.getProperty("user.dir") + "/src/main/res/raw/" + fileName); + fcl.eval(reader); + } finally { + if (reader != null) + reader.close(); + } + } + + @Test + public void name() { + eval(": tst1 -> a -> b -> c -> d 12 ;"); + dasm("tst1"); + } + + private void dasm(String word) { + eval("'" + word + "' dasm"); + System.err.println(transcript.content()); + } + + @Test + public void testLocalDisasm() { + eval(": sqe -> a -> b -> c\n" + + " b neg b b * 4 a * c * - sqrt - 2 a * /\n" + + " b neg b b * 4 a * c * - sqrt + 2 a * /\n" + + ";\n"); + dasm("sqe"); + } + + @Test + public void test() { + eval(": find ( n -- n )\n" + + "0 => count -> s\n" + + "1001 1 do\n" + + " i s /mod -> quotient -> remainder \n" + + " remainder 0 = if\n" + + " count inc\n" + + " then\n" + + "loop\n" + + "count @ ;"); + dasm("find"); + } + + @Test + public void testLocalEarlyDisasm() { + eval(": tst -> x -> y\n" + + " x y < if 1 exit then -1 ;\n" + + ";\n"); + dasm("tst"); + } + + @Test + public void testNoLocal() { + eval(": tst\n" + + " < if 1 exit then -1 ;\n"); + dasm("tst"); + } + + @After + public void tearDown() throws Exception { + assertEquals(0, fcl.stackSize()); + assertEquals(0, fcl.rStackSize()); + assertEquals(0, evalPop("psp @").longValue()); + } + + private void eval(String script) { + fcl.eval(script); + } + + private Obj evalPop(String script) { + eval(script); + return fcl.pop(); + } +} +