From d91979adb9dc6eaa96f37ac0af337fed1aed08af Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Thu, 8 Dec 2022 11:43:37 +0200 Subject: Use Integer instead of Int in ASTInteger --- examples/fibo.milch | 2 +- src/Builtins.hs | 8 +++++--- src/Utils.hs | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/examples/fibo.milch b/examples/fibo.milch index f6a14a8..160ecdf 100644 --- a/examples/fibo.milch +++ b/examples/fibo.milch @@ -4,4 +4,4 @@ 1 1 _ (+ (fibo (- n 1)) (fibo (- n 2)))))) -(fibo 50) +(fibo 300) diff --git a/src/Builtins.hs b/src/Builtins.hs index 079195f..e87cb09 100644 --- a/src/Builtins.hs +++ b/src/Builtins.hs @@ -207,10 +207,12 @@ builtinTail = (name, makeNonsenseAST $ ASTFunction Pure fn1) where builtinSubstr :: (String, AST) builtinSubstr = (name, makeNonsenseAST $ ASTFunction Pure fn1) where name = "substr" - fn1 ast1@AST { an = ASTInteger at } = + fn1 ast1@AST { an = ASTInteger atInteger } = return $ makeNonsenseAST $ ASTFunction Pure $ fn2 where - fn2 ast2@AST { an = ASTInteger len } = + fn2 ast2@AST { an = ASTInteger lenInteger } = return $ makeNonsenseAST $ ASTFunction Pure $ fn3 where + len = fromIntegral lenInteger :: Int + at = fromIntegral atInteger :: Int fn3 AST { an = ASTString str } = return $ makeNonsenseAST $ ASTString $ drop at .> take len $ str fn3 ast3 = throwL (astPos ast3) $ argError3 name ast1 ast2 ast3 @@ -258,7 +260,7 @@ builtinLen :: (String, AST) builtinLen = (name, makeNonsenseAST $ ASTFunction Pure fn1) where name = "len" fn1 AST { an = ASTString str } = - return $ makeNonsenseAST $ ASTInteger $ length str + return $ makeNonsenseAST $ ASTInteger $ fromIntegral $ length str fn1 ast1 = throwL (astPos ast1) $ argError1 name ast1 builtinFatal :: (String, AST) diff --git a/src/Utils.hs b/src/Utils.hs index e4b2333..0f0654c 100644 --- a/src/Utils.hs +++ b/src/Utils.hs @@ -124,7 +124,7 @@ type LFunction = AST -> LContext AST type LRecord = M.Map String AST data ASTNode - = ASTInteger Int + = ASTInteger Integer | ASTDouble Double | ASTSymbol String | ASTBoolean Bool -- cgit v1.3