From a4b05fc229c4773db7269fdfdf50fa56a38312b3 Mon Sep 17 00:00:00 2001 From: zeroflag Date: Fri, 25 Jun 2021 14:11:13 +0200 Subject: [PATCH] Dasm test --- .../executionHistory/executionHistory.bin | Bin 60117 -> 80417 bytes .../executionHistory/executionHistory.lock | Bin 17 -> 17 bytes .gradle/6.7.1/fileHashes/fileHashes.bin | Bin 22697 -> 22897 bytes .gradle/6.7.1/fileHashes/fileHashes.lock | Bin 17 -> 17 bytes .gradle/6.7.1/javaCompile/classAnalysis.bin | Bin 176727 -> 177170 bytes .gradle/6.7.1/javaCompile/javaCompile.lock | Bin 17 -> 17 bytes .../buildOutputCleanup.lock | Bin 17 -> 17 bytes .../java/com/vectron/fcl/FclDasmTest.java | 115 ++++++++++++++++++ 8 files changed, 115 insertions(+) create mode 100644 src/test/java/com/vectron/fcl/FclDasmTest.java diff --git a/.gradle/6.7.1/executionHistory/executionHistory.bin b/.gradle/6.7.1/executionHistory/executionHistory.bin index 0f99f48eeca4aeae508bf60aa3248433e746577d..6fb2f27a362109345b8d4a07f45137340adcb227 100644 GIT binary patch delta 1199 zcmcb5m3iS8mI)%VOblQ!--Uret{1}Idy#=bmj%ey-Kh9Ne6pm37SpS%lU*fZnHjkz zZeA*3aLLG+fkA#V5U&Q|*{S*FS*fNOMHNX&i8)ynWqE03X@#c6X~~HY0~xXyHcw^@ zkew{!r?&Zz?|J6U9gE)yGqO$Im@GZ{?hek$v$tIQ#Nq$i!+hoBGt;r2{ST@`2>|$iRFuC!VlM>wI zGtbv5M>-NWs?p4E&-@;iWGsNW96^&m_z4B6y2Gw!Qn2L>9{rIXhk zy+o`-7lA?wk3(fAKRD*6gznf0#U+VJIjPPd-xnm7WM~o@EX3F*xB2Yx9U_?FBXC!J z^PW2eOadp3-u-PT@pmw&`_bgyzUk*=!)E!(7amAVmcP$Ex$eHZfNi9tFw>`9R?Au5 zrM9kJ;xy@Hmq6O=fAbp659fTp^WNd*HU9X?`46fDeY4`#pG8baIa&2nneC@W_v*<7 zhs7rgJ``r+SwGqFiQeRphYJ~ROfGzEIJy6k6e87Sl;q|x3v8FLdKh978C|vHd0O9& z)JTL%URcEIfmBW|ye>ES!ebGj8Op-U0-G7Pyq{q=q37tMK&BQism+Wq`OW>0-ZBbi z+-SKR^}1AX5^Kn;0|{I{jFS(h$O5$sPcC@EwfXpy&5S~gT&KmZ{qI?B&F%c+Nt*K+ z#1zWUJ@=jO>#qzS5gq@%%p3!q0iK zVgb-&4}>NcypoWEd$|G>HkVD(e=Mzv5%I0NHg##C`oqZz1)w+rE9FK~I$59-CawSs z8^fymftM1Fq`LnW^^IaypO2jfV?7g^osf58L03F>8@&Et; diff --git a/.gradle/6.7.1/executionHistory/executionHistory.lock b/.gradle/6.7.1/executionHistory/executionHistory.lock index 2e0b03c7d91bc8173be7a478627d1eecb1a8fdcb..78cb8305251017ad59cb2f74040290e0497e7535 100644 GIT binary patch literal 17 UcmZR6yfo?V&kvR=3=kj-076RzE&u=k literal 17 UcmZR6yfo?V&kvR=3=qH%075+lAOHXW diff --git a/.gradle/6.7.1/fileHashes/fileHashes.bin b/.gradle/6.7.1/fileHashes/fileHashes.bin index baa3c7be11ecb507fab9477f63cd302eca9a8fcd..b3a719eb5ce52020a177e304329fca61100e5dea 100644 GIT binary patch delta 623 zcmZ3vk@4du#tkMCj1iknC0;NId^{d&__gn$D+3rr+}ky5~_XWJtf%E6&iNV5?d%~0DH#2T|Kf`W9&(TMLOf6ngn~_yAFsMx~2oRa96k%B3 z$aPxm+W(&A*4)l7o}@XSK~=}mgXspts{4VL5{{(0{}%OM_uNeyRfqULOdTiwX3mK8 z`n!6w$T9Pm8w`XXIu?Eas;mcMZcs3y1qG}O$25A8R Do~x_t delta 367 zcmeykiE-sd#tkMCj3Jv%C0;NsHkD?c>?`+Sa;SXeP2Mehi}Hx&%wpzr^(IMyhS?9FtWg_m4AdJ&vkSZE`_?$YiAm!?3sO zPxCGNaCyd=wK^4gDXadYs$;(hbOf3cCNVsBQ?6c8?Re_RorTAq-bd9T{uiVJ0JThN A#{d8T diff --git a/.gradle/6.7.1/fileHashes/fileHashes.lock b/.gradle/6.7.1/fileHashes/fileHashes.lock index e4e8c514aa94dfac636406176dccf5b620903190..2c51f1aafccaf866073e1f5cb9ea5febd78dec8b 100644 GIT binary patch literal 17 UcmZQxec!z*arw_<3=pse06#7T!TjTC^PiLEbe8 delta 40 wcmbRAg6sMdu7(!IEllc~j3(PPG?^|kZ5PyGl9XbS`M6P0L3q1KB$IL^03QPkW&i*H diff --git a/.gradle/6.7.1/javaCompile/javaCompile.lock b/.gradle/6.7.1/javaCompile/javaCompile.lock index 4e5c91fd521957dd20ba89490ff1aac77d6e3b74..6ef3bb9e6babad869e1817f8173dddbb5c332a6d 100644 GIT binary patch literal 17 VcmZSfJNlPl)5cq#3}C=i1^_w-1rh)N literal 17 VcmZSfJNlPl)5cq#3}C=i0024x1q=WH diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index a9b49067fb18d193f4b7f503349c0349ae40d3f9..d562c1a6ca0ba2831a81f3382055a4689c7de443 100644 GIT binary patch literal 17 UcmZP;WN)}Evvk)I1_&?!04Wm#z5oCK literal 17 UcmZP;WN)}Evvk)I1_;mq04WOtwg3PC 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(); + } +} +