From 4e074b282a8236dcc3599f76ce85d7e52a24d408 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Mon, 7 Nov 2016 22:36:40 +0000 Subject: Adapted more examples to be standalone --- squeen.icl | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) (limited to 'squeen.icl') diff --git a/squeen.icl b/squeen.icl index cd67c16..205bffd 100644 --- a/squeen.icl +++ b/squeen.icl @@ -19,7 +19,84 @@ programmer that are only 40% slower than this solution (lqueen.icl). */ -import StdEnv +(&&) infixr 3 :: !Bool Bool -> Bool +(&&) a b + = code { + push_b 0 + jmp_false l1 + pop_b 1 + jsr_eval 0 + pushB_a 0 + pop_a 1 + .d 0 1 b + rtn + :l1 + pop_a 1 + .d 0 1 b + rtn + } + +(||) infixr 2 :: !Bool Bool -> Bool +(||) a b + = code { + push_b 0 + jmp_true l2 + pop_b 1 + jsr_eval 0 + pushB_a 0 + pop_a 1 + .d 0 1 b + rtn + :l2 + pop_a 1 + .d 0 1 b + rtn + } + +not :: !Bool -> Bool +not True = False +not False = True + +(<) infix 4 :: !Int !Int -> Bool +(<) a b = code inline { + ltI +} + +(>) a b :== b < a + +(+) infixl 6 :: !Int !Int -> Int +(+) a b = code inline { + addI +} + +inc :: !Int -> Int +inc a = a + 1 + +(-) infixl 6 :: !Int !Int -> Int +(-) a b = code inline { + subI +} + + +(==) infix 4 :: !Int !Int -> Bool +(==) a b = code inline { + eqI +} + +(<>) infix 4 :: !Int !Int -> Bool +(<>) a b = not (a == b) + +length :: [a] -> Int +length xs = len 0 xs +where + len :: Int [a] -> Int + len i [] = i + len i [_:xs] = len (i+1) xs + +hd :: [a] -> a +hd [x:xs] = x + +//import StdEnv BoardSize :== 8 // The size of the chessboard. -- cgit v1.2.3