From 4ccd6607639bda725cefef2d5a663fe808f9feda Mon Sep 17 00:00:00 2001 From: Taylor Date: Wed, 15 Jan 2025 13:02:27 -0600 Subject: [PATCH] a fully working interpreter? --- src/Push.hs | 1 - src/Tests.hs | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/Tests.hs diff --git a/src/Push.hs b/src/Push.hs index 32e1db1..5ec0881 100644 --- a/src/Push.hs +++ b/src/Push.hs @@ -52,7 +52,6 @@ intAdd (State es (i : is) fs bs ss ps) = State es ((i + head is) : drop 1 is) fs -- let result = sum (take 2 (int state)) -- dropped = drop 2 (int state) -- in updateIntStack (result : dropped) state - -- For safety, pattern match on [] and i:is or check for <2 long list after take 2? -- Optionally, split this off into independent functions diff --git a/src/Tests.hs b/src/Tests.hs new file mode 100644 index 0000000..24ae1d3 --- /dev/null +++ b/src/Tests.hs @@ -0,0 +1,21 @@ +module Tests where + +import Push + +exampleState = + State + { exec = [IntGene 5, FloatGene 3.4, BoolGene True, StringGene "hi"], + int = [1, 2, 3], + float = [1.2, 1.7], + bool = [True, False], + string = ["Hello", "Push"], + parameter = [IntGene 1, StringGene "Hi", BoolGene True, FloatGene 1.3] + } + +-- intAdd +testResult1 = [3, 3] == int (intAdd exampleState) + +loaded = loadProgarm [IntGene 6, IntGene 6, StateFunc intAdd] emptyState + +-- interpretExec +testResult2 = [12] == int (interpretExec loaded)