epic 0.9 → 0.9.2
raw patch · 10 files changed
+63/−25 lines, 10 filesdep ~basePVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: base
API changes (from Hackage documentation)
- Epic.Epic: tyInt, tyAny, tyUnit, tyPtr, tyString, tyFloat, tyBool, tyChar :: Type
+ Epic.Epic: bigint :: Integer -> Term
+ Epic.Epic: tyInt, tyFloat, tyBool, tyChar, tyBigInt :: Type
+ Epic.Epic: tyString, tyAny, tyUnit, tyPtr :: Type
Files
- Epic/Bytecode.lhs +3/−2
- Epic/CodegenC.lhs +2/−0
- Epic/Epic.lhs +10/−3
- Epic/Scopecheck.lhs +1/−1
- epic.cabal +1/−1
- evm/closure.c +12/−5
- evm/closure.h +4/−4
- evm/libevm.a binary
- evm/stdfuns.c +26/−8
- evm/stdfuns.h +4/−1
Epic/Bytecode.lhs view
@@ -253,7 +253,7 @@ > ecomp lazy tcall (ForeignCall ty fn argtypes) reg vs = do > savetmp <- get_tmp > let (args,types) = unzip argtypes-> (argcode, argregs) <- ecompsEv lazy args vs+> (argcode, argregs) <- ecompsEv (fst lazy, False) args vs > -- let evalcode = if (snd lazy) then [] else map (\x -> EVAL x (snd lazy)) argregs > set_tmp savetmp > return $ argcode ++ [FOREIGN ty reg fn (zip argregs types),@@ -356,7 +356,8 @@ > = do reg' <- new_tmp > (argcode, argregs) <- ecomps lazy args vs > fcode <- ecomp lazy Middle f reg' vs-> return $ fcode ++ argcode ++ [ADDARGS reg reg' argregs]+> return $ fcode ++ argcode ++ [ADDARGS reg reg' argregs] +++> if (not (fst lazy)) then [EVAL reg (snd lazy)] else [] > ccomp (MkInt i) reg = return [INT reg i] > ccomp (MkBigInt i) reg = return [BIGINT reg i]
Epic/CodegenC.lhs view
@@ -75,6 +75,7 @@ > workers _ [] = "" > workers ctxt (decl@(Decl fname ret func@(Bind args locals defn _) _ _):xs) = > -- trace (show fname ++ ": " ++ show defn) $+> "/*\n " ++ show func ++ "\n*/\n" ++ > "void* " ++ quickcall fname ++ "(" ++ showargs args 0 ++ ") {\n" ++ > compileBody (compile ctxt fname func) ++ "\n}\n\n" ++ exportC decl ++ > workers ctxt xs@@ -269,6 +270,7 @@ > cToEpic var TyString = "MKSTR((char*)(" ++ var ++ "))" > cToEpic var TyInt = "MKINT(INTTOEINT(" ++ var ++ "))"+> cToEpic var TyChar = "MKINT(INTTOEINT(" ++ var ++ "))" > cToEpic var TyPtr = "MKPTR(" ++ var ++ ")" > -- cToEpic var TyBigInt = "MKBIGINT((mpz_t*)(" ++ var ++ "))" -- now just a VAL > cToEpic var TyFloat = "MKFLOAT(" ++ var ++ ")"
Epic/Epic.lhs view
@@ -21,10 +21,11 @@ > lazy_, effect_, > foreign_, foreignL_, foreignConst_, foreignConstL_, > let_, letN_, update_, op_,-> str, int, float, char, bool, unit_, (!.), fn, ref, (+>),+> str, int, bigint, float, char, bool, unit_, +> (!.), fn, ref, (+>), > malloc_, > -- * Types-> Type, tyInt, tyChar, tyBool, tyFloat, tyString,+> Type, tyInt, tyBigInt, tyChar, tyBool, tyFloat, tyString, > tyPtr, tyUnit, tyAny, tyC, > -- * Operators > Op, plus_, minus_, times_, divide_, @@ -370,6 +371,10 @@ > int :: Int -> Term > int x = term $ Const (MkInt x) +> -- | Constant big integer+> bigint :: Integer -> Term+> bigint x = term $ Const (MkBigInt x)+ > -- | Constant float > float :: Double -> Term > float x = term $ Const (MkFloat x)@@ -391,10 +396,12 @@ > (+>) :: (EpicExpr c) => c -> Term -> Term > (+>) c k = let_ c (\(x :: Expr) -> k) -> tyInt, tyChar, tyBool, tyFloat, tyString, tyPtr, tyUnit, tyAny :: Type+> tyInt, tyBigInt, tyChar, tyBool, tyFloat :: Type+> tyString, tyPtr, tyUnit, tyAny :: Type > tyC :: String -> Type > tyInt = TyInt+> tyBigInt = TyBigInt > tyChar = TyChar > tyBool = TyBool > tyFloat = TyFloat
Epic/Scopecheck.lhs view
@@ -173,7 +173,7 @@ > v_ise ((n,ty):args) i = let rest = v_ise args (i+1) in > case lookup n rest of > Nothing -> (n,i):rest-> _ -> rest+> Just i' -> (n,i'):rest where dropArg n [] = [] dropArg n ((x,i):xs) | x == n = dropArg n xs
epic.cabal view
@@ -1,5 +1,5 @@ Name: epic-Version: 0.9+Version: 0.9.2 Author: Edwin Brady License: BSD3 License-file: LICENSE
evm/closure.c view
@@ -724,7 +724,7 @@ } fn->fn = (void*)f;- fn->numargs = 2;+ fn->numargs = 3; fn->args = MKARGS(3); fn->args[0] = a1; fn->args[1] = a2;@@ -746,7 +746,7 @@ } fn->fn = (void*)f;- fn->numargs = 2;+ fn->numargs = 4; fn->args = MKARGS(4); fn->args[0] = a1; fn->args[1] = a2;@@ -769,7 +769,7 @@ } fn->fn = (void*)f;- fn->numargs = 2;+ fn->numargs = 5; fn->args = MKARGS(5); fn->args[0] = a1; fn->args[1] = a2;@@ -1084,7 +1084,14 @@ // Since MKSTR is used to build strings from foreign calls, the string // itself will already have been allocated so we just want the closure.- c->info=(void*)x;++// If the foreign call has returned NULL, though, make an empty string.++ if (x == NULL) {+ return MKSTR("");+ } else {+ c->info=(void*)x;+ } EREADY(c); return c; }@@ -1110,7 +1117,7 @@ exit(1); } -void* MKFREE(int x)+void* MKFREE(intptr_t x) { VAL c = MKCLOSURE; SETTY(c, FREEVAR);
evm/closure.h view
@@ -69,9 +69,9 @@ #define MKCLOSURE (Closure*)EMALLOC(sizeof(Closure)) #define MKUNIT (void*)0 -#define INTOP(op,x,y) MKINT((((eint)x)>>1) op (((eint)y)>>1))+#define INTOP(op,x,y) MKINT((eint)((((eint)x)>>1) op (((eint)y)>>1))) #define FLOATOP(op,x,y) MKFLOAT(((GETFLOAT(x)) op (GETFLOAT(y))))-#define FLOATBOP(op,x,y) MKINT(((GETFLOAT(x)) op (GETFLOAT(y))))+#define FLOATBOP(op,x,y) MKINT((eint)(((GETFLOAT(x)) op (GETFLOAT(y))))) #define ADD(x,y) (void*)(((eint)x)+(((eint)y)-1)) #define MULT(x,y) (MKINT((((eint)x)>>1) * (((eint)y)>>1))) #define CHECKEVALUATED(x) if(ISFUN(x) || ISTHUNK(x) \@@ -280,7 +280,7 @@ // vm->roots=rootbase; #define INTTOEINT(x) ((eint)(x))-#define EINTTOINT(x) ((int)(x))+#define EINTTOINT(x) ((intptr_t)(x)) //void* MKINT(int x); mpz_t* NEWBIGINTI(int val);@@ -299,7 +299,7 @@ double GETFLOAT(void* x); //void* GETPTR(void* x); -void* MKFREE(int x);+void* MKFREE(intptr_t x); // Exit with fatal error void ERROR(char* msg);
evm/libevm.a view
binary file changed (57456 → 58152 bytes)
evm/stdfuns.c view
@@ -52,7 +52,16 @@ } // FIXME: Do this properly!-void* freadStr(void* h) {+char* freadStr(void* h) {+ char *buf = NULL;+ if (buf==NULL) { buf = EMALLOC(sizeof(char)*512); } // yeah, right...+ fgets(buf,512,(FILE*)h);+// char *loc = strchr(buf,'\n');+// if (loc) *(loc+1) = '\0'; else buf[0]='\0';+ return buf;+}++void* freadStrAny(void* h) { static char bufin[128]; bufin[0]='\0'; @@ -89,7 +98,11 @@ int strToInt(char* str) {- return strtol(str,NULL,10);+ char* end;+ if (str == NULL) return 0;+ int v = strtol(str,&end,10);++ if (*end != '\0') return 0; else return v; } char* intToStr(int x)@@ -194,12 +207,12 @@ VAL addBig(VAL x, VAL y) { if (ISINT(x) && ISINT(y)) {- int vx = GETINT(x);- int vy = GETINT(y);+ intptr_t vx = GETINT(x);+ intptr_t vy = GETINT(y); if ((vx <= 0 && vy >=0) || (vx >=0 && vy <=0)) { return INTOP(+,x,y); }- int res = vx + vy;+ intptr_t res = vx + vy; if (res >= 1<<30 || res <= -(1 << 30)) { return MKBIGINT(addBigInt(*(NEWBIGINTI(vx)), *(NEWBIGINTI(vy)))); } else {@@ -218,12 +231,12 @@ VAL subBig(VAL x, VAL y) { if (ISINT(x) && ISINT(y)) {- int vx = GETINT(x);- int vy = GETINT(y);+ intptr_t vx = GETINT(x);+ intptr_t vy = GETINT(y); if ((vx <= 0 && vy <=0) || (vx >=0 && vy >=0)) { return INTOP(-,x,y); }- int res = vx - vy;+ intptr_t res = vx - vy; if (res >= 1<<30 || res <= -(1 << 30)) { return MKBIGINT(subBigInt(*(NEWBIGINTI(vx)), *(NEWBIGINTI(vy)))); } else {@@ -363,6 +376,11 @@ mpz_init(*answer); mpz_set_str(*answer, str, 10); return answer;+}++void* intToBigInt(int x)+{+ return MKINT(INTTOEINT(x)); } char* bigIntToStr(mpz_t x)
evm/stdfuns.h view
@@ -32,7 +32,8 @@ void* fileOpen(char* name, char* mode); void fileClose(void* h);-void* freadStr(void* h);+char* freadStr(void* h);+void* freadStrAny(void* h); void fputStr(void* h, char* str); int isNull(void* ptr);@@ -62,6 +63,8 @@ double intToFloat(int x); int floatToInt(double x);++void* intToBigInt(int x); mpz_t* strToBigInt(char* str); char* bigIntToStr(mpz_t x);