.
authorMart Lubbers <mart@martlubbers.net>
Thu, 26 May 2016 13:25:33 +0000 (15:25 +0200)
committerMart Lubbers <mart@martlubbers.net>
Thu, 26 May 2016 13:25:33 +0000 (15:25 +0200)
examples/test.spl
gen.icl
test.bak [new file with mode: 0644]

index 2428d67..6917e84 100644 (file)
@@ -1,4 +1,84 @@
+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 [];
+       } else {
+               return f(l.hd) : map(f, l.tl);
+       }
+}
+
+plus(x, y){
+       return x + y;
+}
+
+ap(f, x){
+       return f(x);
+}
+
 main(){
-       var b = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
-       return;
+       [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);
+
+       
+
 }
diff --git a/gen.icl b/gen.icl
index e92954c..f72f7f3 100644 (file)
--- a/gen.icl
+++ b/gen.icl
@@ -283,11 +283,15 @@ instance g Expr where
                                ,Instr "ldh" [Lit 0] "Get function number"
                                ,Instr "str" [Raw "R5"] ""
                                ,Instr "bsr" [L "1func"] ""
-                               ,Instr "ldr" [Raw "MP"] ""
-                               ,Instr "ldc" [Lit t] ""
-                               ,Instr "add" [] ""
-                               ,Instr "str" [Raw "SP"] ""
                                ,Instr "ldr" [Raw "RR"] ""
+       //                      ,Instr "ldl" [Lit t] ""
+       //                      ,Instr "ldh" [Lit $ 1] ""
+       //                      ,Instr "neg" [] ""
+       //                      ,Instr "ldr" [Raw "SP"] ""
+       //                      ,Instr "add" [] ""
+       //                      ,Instr "ldc" [Lit arity] ""
+       //                      ,Instr "sub" [] ""
+       //                      ,Instr "str" [Raw "SP"] ""
                                ]
                        )
                Nothing = liftT (Left $ Error "Undefined function!!!")
@@ -303,7 +307,7 @@ instance g Stmt where
         fresh >>= \elseLabel->
         fresh >>= \endLabel->
         g cond >>|
-        tell [Instr "brf" [L elseLabel] "branch else"] >>|
+       tell [Instr "brf" [L elseLabel] "branch else"] >>|
         mapM_ g th >>|
         tell [Instr "bra" [L endLabel] "branch end if"] >>|
         tell [Lab elseLabel] >>|
@@ -368,7 +372,7 @@ instance g FunDecl where
 
 annote :: Int String -> Gen ()
 annote pos key = 
-    tell [Instr "annote" [Raw "MP", Lit pos, Lit pos, Raw "green", Raw key] ""]
+    tell [Instr "annote" [Raw "MP", Lit pos, Lit pos, Raw "black", Raw key] ""]
 
 class print a :: a -> [String]
 
diff --git a/test.bak b/test.bak
new file mode 100644 (file)
index 0000000..5b35be9
--- /dev/null
+++ b/test.bak
@@ -0,0 +1,134 @@
+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(']');
+}
+
+map(f, l){
+       if(isEmpty(l)){
+               return [];
+       } else {
+               return f(l.hd) : map(f, l.tl);
+       }
+}
+
+plus(x, y){
+       return x + y;
+}
+
+main(){
+       //Int
+       Int i1 = 0;
+       Int i2 = 125123;
+       Int i3 = -1;
+
+       //Int expressions
+       Int i4 = i1 + i2 - i3 * i3 / i3;
+
+       //Char
+       Char c1 = ' ';
+       Char c2 = 'a';
+       Char c3 = '\'';
+
+       //Lijsten
+       [Int] l1 = 1 : 2 : 3 : 4 : [];
+       [Int] l2 = 5 : l1;
+
+       printIntList(map(plus(1), l2));
+//     print(i1);
+//     print("should give: 0\n");
+//     print(i2);
+//     print("should give: 125123\n");
+//     print(i3);
+//     print("should give: -1\n");
+//     print(i4);
+//     print("should give: 125124\n");
+//
+//     print(c2);
+//     print(" should be a\n");
+//     print(c1);
+//     print(" should be literal space\n");
+//     print(c3);
+//     print(" should be '\n");
+//     printIntList(l1);
+//     print("\n");
+//     printIntListR(l2);
+
+//     printIntList(add1List(l2));
+}
+       
+//     
+//     
+//     //Bool
+//     Bool b1 = True;
+//     Bool b2 = False;
+//
+//     //Simple lists
+//     [Int] sl1 = [];
+//     [Int] sl2 = 1 : sl1;
+//     [Int] sl3 = 1 : sl2;
+//
+//     //Strings
+//     [Char] s1 = "hallo";
+//     [Char] s2 = "ha\tllo";
+//     [Char] s3 = "";
+//     
+//     //Tuples
+//     (Int, Int) t1 = (42, 0);
+//     (Int, Char) t2 = (42, ' ');
+//     (Bool, Char) t3 = (True, ' ');
+//     ([Char], Char) t4 = ("hi", ' ');
+//     ([Char], (Int, Int)) t5 = ("hi", (42, 0));
+//     
+//     //Lists
+//     [[Char]] l1 = ("hallo") : ("ik") : ("ben") : ("pim") : [];
+//     [Int] l2 = 1 : 2 : 3 : 4 : 5 : [];
+//     [(Int, Int)] l3 = (1, 2) : (2, 3) : (3, 4) : [];
+//}