From: Mart Lubbers Date: Tue, 24 May 2016 13:05:46 +0000 (+0200) Subject: ding' X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=0487063d65ed490d5e00f8aa40e351c1dd039fbd;p=cc1516.git ding' git pu --- diff --git a/examples/high.spl b/examples/high.spl index 233dc4c..1445e6f 100644 --- a/examples/high.spl +++ b/examples/high.spl @@ -6,5 +6,6 @@ main (){ var a = plus(); var b = plus(1); var c = plus(1, 2); + var d = plus(1, 2, 3); // d(3, 4); } diff --git a/gen.icl b/gen.icl index f464013..2828798 100644 --- a/gen.icl +++ b/gen.icl @@ -109,7 +109,6 @@ programContext x = [Lab "1func" ,Lab "read" ] -//helper functions for the gen monad getAdressbook :: Gen Addressbook getAdressbook = gets fst @@ -178,23 +177,26 @@ instance g Expr where ,Instr "ldc" [Lit 0] "" ,Instr "sth" [] ""] g (FunExpr _ k es fs) = getAdressbook >>= \ab->case 'Map'.get k ab of + //Identifier points to function Just (LAB l arity fn) = if (arity <> (length es)) ( tell - [Instr "ldc" [Lit fn] "" + [Instr "ldc" [Lit fn] "Store function number" ,Instr "sth" [] "" - ,Instr "ldc" [Lit $ length es] "" + ,Instr "ldc" [Lit $ length es] "Store arity" ,Instr "sth" [] "" ,Instr "ajs" [Lit -1] ""] >>| mapM_ g es >>| if (isEmpty es) (pure ()) (tell - [Instr "stmh" [Lit $ length es] "" + [Instr "stmh" [Lit $ length es] "Store arguments" ,Instr "ajs" [Lit -1] ""])) ( mapM_ g es >>| jump "bsr" k - >>| mapM_ (const $ tell [Instr "ajs" [Lit -1] ""]) es //clean up args - >>| tell [Instr "ldr" [Raw "RR"] ""]) - Nothing = liftT (Left $ Error "Undefined function!!!") + >>| tell + [Instr "ajs" [Lit $ ~(length es)] "Clean arguments" + ,Instr "ldr" [Raw "RR"] ""]) + //Identifier points to variable, thus higher order function Just (ADDR t) = liftT (Left $ Error "FunExpr to addr") + Nothing = liftT (Left $ Error "Undefined function!!!") jump :: String String -> Gen () jump instr k = getAdressbook >>= \ab->case 'Map'.get k ab of