From: Mart Lubbers Date: Thu, 2 Jun 2016 08:00:04 +0000 (+0200) Subject: ding X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=8d676a148fcdb56253c65e547e103086d0f852ff;p=cc1516.git ding --- diff --git a/examples/higher.spl b/examples/higher.spl index 61413c1..1df4a80 100644 --- a/examples/higher.spl +++ b/examples/higher.spl @@ -34,14 +34,22 @@ // } //} -plus(x, y){ +plus3(x, y, z){ return x + y; } +plus(x, y){ + return x+y; +} + apply(f, x){ return f(x); } +ap2(f, g, x){ + return f(g(x)); +} + main(){ // print("faculty of 5 is: ", foldr(\x y->x*y, 1, intList(5))); // print("sum of 1..5 is: ", foldr(\x y->x+y, 0, intList(5))); @@ -49,32 +57,8 @@ main(){ // print("sum of 0..12 but only the evens: ", // foldr(\x y->x+y, 0, filter(\x->x%2 == 0, intList(12)))); - var a = plus(3); - var b = apply(a); - var c = apply(b); - var d = apply(c); - var e = apply(d); - var f = apply(e); - var g = apply(f); - var h = apply(g); - var i = apply(h); - var j = apply(i); - var k = apply(j); - var l = apply(k); - var m = apply(l); - var n = apply(m); - var o = apply(n); - var p = apply(o); - var q = apply(p); - var r = apply(q); - var s = apply(r); - var t = apply(s); - var u = apply(t); - var v = apply(u); - var w = apply(v); - var x = apply(w); - var y = apply(x); - var z = apply(y); - - print("3+5=", z(5)); + var a = plus3; + var b = a(1); + var c = b(2); + var d = c(3); } diff --git a/examples/printparse.spl b/examples/printparse.spl index 1712b73..607610f 100644 --- a/examples/printparse.spl +++ b/examples/printparse.spl @@ -76,8 +76,13 @@ printInt(x) { print(l); } +printBool(b) :: Bool -> Void { + print(b); +} + main(){ var num = "-1234"; printList(printInt, [32, 4, strToInt(num)]); +// printList(printBool, [True, False, True, True]); } diff --git a/gen.icl b/gen.icl index 9f515c9..0707984 100644 --- a/gen.icl +++ b/gen.icl @@ -187,16 +187,19 @@ funnyStuff k es fs = getAdressbook >>= \ab->case 'Map'.get k ab of //Identifier points to function Just (LAB l arity fn) = if (arity <> (length es)) //Function is not complete - ( tell + ( mapM_ g es + >>| tell [Instr "ldc" [Lit fn] "Store function number" ,Instr "sth" [] "" + ,Instr "str" [Raw "R7"] "" ,Instr "ldc" [Lit $ length es] "Store arity" ,Instr "sth" [] "" - ,Instr "ajs" [Lit -1] ""] - >>| mapM_ g es + ,Instr "ajs" [Lit -1] "" + ] >>| if (isEmpty es) (pure ()) (tell [Instr "stmh" [Lit $ length es] "Store arguments" - ,Instr "ajs" [Lit -1] ""])) + ,Instr "ajs" [Lit -1] "" + ,Instr "ldr" [Raw "R7"] ""])) //Function is complete ( mapM_ g es >>| getAdressbook >>= \ab->(case 'Map'.get k ab of