hoi'
authorMart Lubbers <mart@martlubbers.net>
Thu, 26 May 2016 14:19:18 +0000 (16:19 +0200)
committerMart Lubbers <mart@martlubbers.net>
Thu, 26 May 2016 14:19:18 +0000 (16:19 +0200)
git psu

examples/test.spl
gen.icl

index 6917e84..bb74407 100644 (file)
@@ -1,56 +1,3 @@
-digitToChar(x){
-       x = x % 10;
-       if(x == 0){ return '0'; }
-       else { if(x == 1){ return '1'; }
-       else { if(x == 2){ return '2'; }
-       else { if(x == 3){ return '3'; }
-       else { if(x == 4){ return '4'; }
-       else { if(x == 5){ return '5'; }
-       else { if(x == 6){ return '6'; }
-       else { if(x == 7){ return '7'; }
-       else { if(x == 8){ return '8'; }
-       else { return '9'; }}}}}}}}}
-}
-
-printInt (i){
-       if(i > 0){
-               print(digitToChar(i));
-               printInt(i/10);
-       }
-}
-
-printIntList (l){
-       print('[');
-       if(!isEmpty(l)){
-               printInt(l.hd);
-               l = l.tl;
-       }
-       while(!isEmpty(l)){
-               print(',');
-               printInt(l.hd);
-               l = l.tl;
-       }
-       print(']');
-}
-
-printIntListRP(l){
-       if(!isEmpty(l)){
-               print(',');
-               printInt(l.hd);
-               printIntListRP(l.tl);
-       }
-}
-
-printIntListR(l){
-       print('[');
-       if(!isEmpty(l)){
-               printInt(l.hd);
-               l = l.tl;
-       }
-       printIntListRP(l);
-       print("]\n");
-}
-
 map(f, l){
        if(isEmpty(l)){
                return [];
@@ -63,22 +10,16 @@ plus(x, y){
        return x + y;
 }
 
-ap(f, x){
-       return f(x);
+foldr(f, acc, l){
+       if(isEmpty(l)){
+               return acc;
+       } else {
+               return foldr(f, f(acc, l.hd), l.tl);
+       }
 }
 
 main(){
-       [Int] l1 = 1 : 2 : [];
-       var fun = plus(1);
-       
-//     var b = ap(fun, 3);
-       var res1 = map(fun, l1);
-//     var res2 = map(fun, res1);
-       
-//     printIntListR(l1);
-//     printIntListR(res1);
-//     printIntListR(res2);
-
-       
-
+       [Int] l1 = 1 : 2 : 3 : 4 : 5 : [];
+       var c = foldr(plus, 0, l1);
+       var d = map(plus(1), l1);
 }
diff --git a/gen.icl b/gen.icl
index f72f7f3..a0333a2 100644 (file)
--- a/gen.icl
+++ b/gen.icl
@@ -282,8 +282,20 @@ instance g Expr where
                                [Instr "ldl" [Lit t] ""
                                ,Instr "ldh" [Lit 0] "Get function number"
                                ,Instr "str" [Raw "R5"] ""
-                               ,Instr "bsr" [L "1func"] ""
+                               ,Instr "bsr" [L "1func"] "HIGHER ORDER END"
+                               ,Instr "ldl" [Lit t] ""
+                               ,Instr "ldh" [Lit 1] ""
+                               ,Instr "neg" [] ""
+                               ,Instr "ldr" [Raw "SP"] ""
+                               ,Instr "add" [] ""
+                               ,Instr "ldc" [Lit $ length es + 1] ""
+                               ,Instr "sub" [] ""
+                               ,Instr "str" [Raw "SP"] ""
                                ,Instr "ldr" [Raw "RR"] ""
+                               //RR is nu goed
+//                             ,Instr "ajs" [Lit $ ~ (length es)] ""
+//                             ,Instr "ldl" [Lit t] ""
+//                             ,Instr "ldr" [Raw "RR"] "END OF HIGHERORDERFUNCALL"
        //                      ,Instr "ldl" [Lit t] ""
        //                      ,Instr "ldh" [Lit $ 1] ""
        //                      ,Instr "neg" [] ""