}
main() {
- [Int] x1 = 1 : 2 : [];
- [Int] x2 = 0 : x1;
- [Int] x3 = [];
- //Bool y1 = isEmpty(x2); //gives weird type error, not sure why
- isEmpty(x2);
- return;
+ // [Int] x2 = 0 : x1;
+ // [Int] x3 = [];
+ // (Int, Bool) x4 = (4, True);
+ // //Bool y1 = isEmpty(x2); //gives weird type error, not sure why
+// isEmpty(x2);
+ [Int] x1 = 8 : 2 : [];
+ return x1.hd;
}
BiOr = "or"
BiCons = abort "Shit, Cons, how to deal with this?"
+instance g FieldSelector where
+ g FieldFst = tell [Instr "lda" [Lit 0] "fst"]
+ g FieldSnd = tell [Instr "lda" [Lit 1] "snd"]
+ g FieldHd = tell [Instr "lda" [Lit -1] "hd"]
+ g FieldTl = tell [Instr "lda" [Lit 0] "tl"]
+
instance g Expr where
g (IntExpr _ i) = tell [Instr "ldc" [Lit i] ""]
g (CharExpr _ c) = tell [Instr "ldc" [Lit (toInt c)] ""]
>>| tell [Instr "sth" [] ""]
>>| tell [Instr "ajs" [Lit -1] ""]
g (VarExpr _ (VarDef k fs)) = getAdressbook >>= \ab->case 'Map'.get k ab of
- Nothing = liftT (Left $ Error "PANIC: undefined variable")
- Just (ADDR t) = tell [Instr "ldl" [Lit t] ""]
- Just (LAB t) = liftT (Left $ Error "PANIC: variable and function name clash")
- //load k >>= \instr-> tell [instr] //note: pure is pure for list, i.e. []
+ Just (ADDR t) = tell [Instr "ldl" [Lit t] ""] >>| mapM_ g fs >>| pure ()
+ _ = liftT (Left $ Error "PANIC: variable and function name clash")
g (FunExpr _ k es fs) =
mapM_ g es
>>| jump "bsr" k