From 8ccc6ebf0f90a3b1e939d6ef845df7bfd4501f8a Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Thu, 17 Jul 2014 08:16:22 -0700 Subject: 26 - cleanup tests --- mu.arc.t | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 106 insertions(+), 23 deletions(-) (limited to 'mu.arc.t') diff --git a/mu.arc.t b/mu.arc.t index 9c03e5de..86442e3b 100644 --- a/mu.arc.t +++ b/mu.arc.t @@ -1,5 +1,12 @@ (load "mu.arc") +(clear) +(add-fns '((test1 + ((integer 1) <- loadi 1)))) +(run function*!test1) +(if (~iso memory* (obj 1 1)) + (prn "F - 'loadi' writes a literal integer (its lone 'arg' after the instruction name) to a location in memory (an address) specified by its lone 'oarg' or output arg before the arrow")) + (clear) (add-fns '((test1 ((integer 1) <- loadi 1) @@ -7,7 +14,7 @@ ((integer 3) <- add (integer 1) (integer 2))))) (run function*!test1) (if (~iso memory* (obj 1 1 2 3 3 4)) - (prn "F - load and add instructions work")) + (prn "F - 'add' operates on two addresses")) (clear) (add-fns @@ -20,7 +27,7 @@ (run function*!main) ;? (prn memory*) (if (~iso memory* (obj 1 1 2 3 3 4)) - (prn "F - compound functions work")) + (prn "F - calling a user-defined function runs its instructions")) (clear) (add-fns @@ -35,7 +42,7 @@ (run function*!main) ;? (prn memory*) (if (~iso memory* (obj 1 1 2 3 3 4)) - (prn "F - early return works")) + (prn "F - 'reply' stops executing the current function")) ;? (quit) (clear) @@ -56,7 +63,7 @@ (if (~iso memory* (obj 1 1 2 3 3 4 ; add-fn's temporaries 4 1 5 3)) - (prn "F - parameterized compound fn")) + (prn "F - 'arg' accesses in order the operands of the most recent function call (the caller)")) ;? (quit) (clear) @@ -77,7 +84,7 @@ (if (~iso memory* (obj 1 1 2 3 3 4 ; add-fn's temporaries 4 1 5 3)) - (prn "F - arg with index")) + (prn "F - 'arg' with index can access function call arguments out of order")) ;? (quit) (clear) @@ -97,7 +104,7 @@ (if (~iso memory* (obj 1 1 2 3 3 4 ; add-fn's temporaries 4 1 5 3 6 4)) - (prn "F - parameterized compound fn with return value")) + (prn "F - 'reply' can take aguments that are returned, or written back into output args of caller")) (clear) (add-fns @@ -116,7 +123,7 @@ (if (~iso memory* (obj 1 1 2 3 3 4 7 3 ; add-fn's temporaries 4 1 5 3 6 4)) - (prn "F - parameterized compound fn with multiple return values")) + (prn "F - 'reply' permits a function to return multiple values at once")) (clear) (add-fns @@ -127,7 +134,7 @@ (run function*!main) ;? (prn memory*) (if (~iso memory* (obj 1 1 2 3 3 -2)) - (prn "F - sub works")) + (prn "F - 'sub' subtracts the value at one address from the value at another")) (clear) (add-fns @@ -138,7 +145,7 @@ (run function*!main) ;? (prn memory*) (if (~iso memory* (obj 1 2 2 3 3 6)) - (prn "F - mul works")) + (prn "F - 'mul' multiplies like 'add' adds")) (clear) (add-fns @@ -149,7 +156,7 @@ (run function*!main) ;? (prn memory*) (if (~iso memory* (obj 1 8 2 3 3 (/ real.8 3))) - (prn "F - div works")) + (prn "F - 'div' divides like 'add' adds")) (clear) (add-fns @@ -160,7 +167,7 @@ (run function*!main) ;? (prn memory*) (if (~iso memory* (obj 1 8 2 3 3 2 4 2)) - (prn "F - idiv works")) + (prn "F - 'idiv' performs integer division, returning quotient and remainder")) (clear) (add-fns @@ -171,18 +178,18 @@ (run function*!main) ;? (prn memory*) (if (~iso memory* (obj 1 t 2 nil 3 nil)) - (prn "F - and works")) + (prn "F - logical 'and' for booleans")) (clear) (add-fns '((main ((boolean 1) <- loadi 4) - ((boolean 2) <- loadi 4) - ((boolean 3) <- le (boolean 1) (boolean 2))))) + ((boolean 2) <- loadi 3) + ((boolean 3) <- lt (boolean 1) (boolean 2))))) (run function*!main) ;? (prn memory*) -(if (~iso memory* (obj 1 4 2 4 3 t)) - (prn "F - le works")) +(if (~iso memory* (obj 1 4 2 3 3 nil)) + (prn "F - 'lt' is the less-than inequality operator")) (clear) (add-fns @@ -193,7 +200,18 @@ (run function*!main) ;? (prn memory*) (if (~iso memory* (obj 1 4 2 3 3 nil)) - (prn "F - le works - 2")) + (prn "F - 'le' is the <= inequality operator")) + +(clear) +(add-fns + '((main + ((boolean 1) <- loadi 4) + ((boolean 2) <- loadi 4) + ((boolean 3) <- le (boolean 1) (boolean 2))))) +(run function*!main) +;? (prn memory*) +(if (~iso memory* (obj 1 4 2 4 3 t)) + (prn "F - 'le' returns true for equal operands")) (clear) (add-fns @@ -204,7 +222,7 @@ (run function*!main) ;? (prn memory*) (if (~iso memory* (obj 1 4 2 5 3 t)) - (prn "F - le works - 3")) + (prn "F - le is the <= inequality operator - 2")) (clear) (add-fns @@ -216,7 +234,7 @@ (run function*!main) ;? (prn memory*) (if (~iso memory* (obj 1 8)) - (prn "F - jmp works")) + (prn "F - 'jmp' skips some instructions")) (clear) (add-fns @@ -229,7 +247,7 @@ (run function*!main) ;? (prn memory*) (if (~iso memory* (obj 1 8)) - (prn "F - jmp works")) + (prn "F - 'jmp' doesn't skip too many instructions")) (clear) (add-fns @@ -244,7 +262,7 @@ (run function*!main) ;? (prn memory*) (if (~iso memory* (obj 1 1 2 1 3 t)) - (prn "F - jif works")) + (prn "F - 'jif' is a conditional 'jmp'")) (clear) (add-fns @@ -259,7 +277,7 @@ (run function*!main) ;? (prn memory*) (if (~iso memory* (obj 1 1 2 2 3 nil 4 3)) - (prn "F - jif works - 2")) + (prn "F - if 'jif's first arg is false, it doesn't skip any instructions")) (clear) (add-fns @@ -281,4 +299,69 @@ (if (~iso memory* (obj 1 1 2 3 3 4 ; add-fn's temporaries 4 0 5 0 6 nil 7 1 8 3 9 4)) - (prn "F - user-defined function with clauses")) + (prn "F - an example function that checks that its args are integers")) + +(clear) +(add-fns + '((add-fn + ((type 4) <- otype 0) + ((type 5) <- loadi 0) ; type index corresponding to 'integer' + ((boolean 6) <- neq (type 4) (type 5)) + (jif (boolean 6) (offset 4)) + ((integer 7) <- arg) + ((integer 8) <- arg) + ((integer 9) <- add (integer 7) (integer 8)) + (reply (integer 9)) + ((type 5) <- loadi 4) ; second clause: is otype 0 a boolean? + ((boolean 6) <- neq (type 4) (type 5)) + (jif (boolean 6) (offset 6)) + ((boolean 7) <- arg) + ((boolean 8) <- arg) + ((boolean 9) <- or (boolean 7) (boolean 8)) + (reply (boolean 9))) + (main + ((boolean 1) <- loadi t) + ((boolean 2) <- loadi t) + ((boolean 3) <- add-fn (boolean 1) (boolean 2))))) +(run function*!main) +;? (prn memory*) +(if (~iso memory* (obj ; first call to add-fn + 1 t 2 t 3 t + ; add-fn's temporaries + 4 4 5 4 6 nil 7 t 8 t 9 t)) + (prn "F - an example function that can do different things (dispatch) based on the type of its args or oargs")) + +(clear) +(add-fns + '((add-fn + ((type 4) <- otype 0) + ((type 5) <- loadi 0) ; type index corresponding to 'integer' + ((boolean 6) <- neq (type 4) (type 5)) + (jif (boolean 6) (offset 4)) + ((integer 7) <- arg) + ((integer 8) <- arg) + ((integer 9) <- add (integer 7) (integer 8)) + (reply (integer 9)) + ((type 5) <- loadi 4) ; second clause: is otype 0 a boolean? + ((boolean 6) <- neq (type 4) (type 5)) + (jif (boolean 6) (offset 6)) + ((boolean 7) <- arg) + ((boolean 8) <- arg) + ((boolean 9) <- or (boolean 7) (boolean 8)) + (reply (boolean 9))) + (main + ((boolean 1) <- loadi t) + ((boolean 2) <- loadi t) + ((boolean 3) <- add-fn (boolean 1) (boolean 2)) + ((integer 10) <- loadi 3) + ((integer 11) <- loadi 4) + ((integer 12) <- add-fn (integer 10) (integer 11))))) +(run function*!main) +;? (prn memory*) +(if (~iso memory* (obj ; first call to add-fn + 1 t 2 t 3 t + ; second call to add-fn + 10 3 11 4 12 7 + ; temporaries for most recent call to add-fn + 4 0 5 0 6 nil 7 3 8 4 9 7)) + (prn "F - different calls can exercise different clauses of the same function")) -- cgit 1.4.1-2-gfad0