@@ -48,7 +48,7 @@ codegenC' :: [(Name, SDecl)] ->
4848 [String] -> -- extra object files
4949 [String] -> -- extra compiler flags (libraries)
5050 [String] -> -- extra compiler flags (anything)
51− [ExportIFace] ->
51+ [ExportIFace] ->
5252 Bool -> -- interfaces too (so make a .o instead)
5353 DbgLevel ->
5454 IO ()
@@ -153,7 +153,7 @@ showCStr s = '"' : foldr ((++) . showChar) "\"" s
153153 headHex h (length bytes) : map toHex bytes
154154 where
155155 split acc 0 = acc
156− split acc x = let xbits = x .&. 0x3f
156+ split acc x = let xbits = x .&. 0x3f
157157 xrest = shiftR x 6 in
158158 split (xbits : acc) xrest
159159
@@ -185,7 +185,7 @@ bcc i (ASSIGNCONST l c)
185185 -- if it's a type constant, we won't use it, but equally it shouldn't
186186 -- report an error. These might creep into generated for various reasons
187187 -- (especially if erasure is disabled).
188− mkConst c | isTypeConst c = "MKINT(42424242)"
188+ mkConst c | isTypeConst c = "MKINT(42424242)"
189189 mkConst c = error $ "mkConst of (" ++ show c ++ ") not implemented"
190190
191191bcc i (UPDATE l r) = indent i ++ creg l ++ " = " ++ creg r ++ ";\n"
@@ -328,7 +328,7 @@ bcc i (ERROR str) = indent i ++ "fprintf(stderr, " ++ show str ++ "); fprintf(st
328328
329329-- Deconstruct the Foreign type in the defunctionalised expression and build
330330-- a foreign type description for c_irts and irts_c
331−toAType (FCon i)
331+toAType (FCon i)
332332 | i == sUN "C_IntChar" = ATInt ITChar
333333 | i == sUN "C_IntNative" = ATInt ITNative
334334 | i == sUN "C_IntBits8" = ATInt (ITFixed IT8)
@@ -337,15 +337,15 @@ toAType (FCon i)
337337 | i == sUN "C_IntBits64" = ATInt (ITFixed IT64)
338338toAType t = error (show t ++ " not defined in toAType")
339339
340−toFType (FCon c)
340+toFType (FCon c)
341341 | c == sUN "C_Str" = FString
342342 | c == sUN "C_Float" = FArith ATFloat
343343 | c == sUN "C_Ptr" = FPtr
344344 | c == sUN "C_MPtr" = FManagedPtr
345345 | c == sUN "C_Unit" = FUnit
346−toFType (FApp c [_,ity])
346+toFType (FApp c [_,ity])
347347 | c == sUN "C_IntT" = FArith (toAType ity)
348−toFType (FApp c [_])
348+toFType (FApp c [_])
349349 | c == sUN "C_Any" = FAny
350350toFType t = FAny
351351
@@ -551,7 +551,7 @@ doOp v LStrLt [l,r] = v ++ "idris_strlt(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
551551doOp v LStrEq [l,r] = v ++ "idris_streq(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
552552
553553doOp v LReadStr [_] = v ++ "idris_readStr(vm, stdin)"
554−doOp v LWriteStr [_,s]
554+doOp v LWriteStr [_,s]
555555 = v ++ "MKINT((i_int)(idris_writeStr(stdout"
556556 ++ ",GETSTR("
557557 ++ creg s ++ "))))"
@@ -577,10 +577,10 @@ doOp v LSystemInfo [x] = v ++ "idris_systemInfo(vm, " ++ creg x ++ ")"
577577doOp v LNoOp args = v ++ creg (last args)
578578
579579-- Pointer primitives (declared as %extern in Builtins.idr)
580−doOp v (LExternal rf) [_,x]
580+doOp v (LExternal rf) [_,x]
581581 | rf == sUN "prim__readFile"
582582 = v ++ "idris_readStr(vm, GETPTR(" ++ creg x ++ "))"
583−doOp v (LExternal wf) [_,x,s]
583+doOp v (LExternal wf) [_,x,s]
584584 | wf == sUN "prim__writeFile"
585585 = v ++ "MKINT((i_int)(idris_writeStr(GETPTR(" ++ creg x
586586 ++ "),GETSTR("
@@ -591,15 +591,32 @@ doOp v (LExternal so) [] | so == sUN "prim__stdout" = v ++ "MKPTR(vm, stdout)"
591591doOp v (LExternal se) [] | se == sUN "prim__stderr" = v ++ "MKPTR(vm, stderr)"
592592
593593doOp v (LExternal nul) [] | nul == sUN "prim__null" = v ++ "MKPTR(vm, NULL)"
594−doOp v (LExternal eqp) [x, y] | eqp == sUN "prim__eqPtr"
594+doOp v (LExternal eqp) [x, y] | eqp == sUN "prim__eqPtr"
595595 = v ++ "MKINT((i_int)(GETPTR(" ++ creg x ++ ") == GETPTR(" ++ creg y ++ ")))"
596−doOp v (LExternal eqp) [x, y] | eqp == sUN "prim__eqManagedPtr"
596+doOp v (LExternal eqp) [x, y] | eqp == sUN "prim__eqManagedPtr"
597597 = v ++ "MKINT((i_int)(GETMPTR(" ++ creg x ++ ") == GETMPTR(" ++ creg y ++ ")))"
598598doOp v (LExternal rp) [p, i] | rp == sUN "prim__registerPtr"
599599 = v ++ "MKMPTR(vm, GETPTR(" ++ creg p ++ "), GETINT(" ++ creg i ++ "))"
600−
600+doOp v (LExternal pk) [_, p, o] | pk == sUN "prim__peek8"
601+ = v ++ "idris_peekB8(vm," ++ creg p ++ "," ++ creg o ++")"
602+doOp v (LExternal pk) [_, p, o, x] | pk == sUN "prim__poke8"
603+ = v ++ "idris_pokeB8(" ++ creg p ++ "," ++ creg o ++ "," ++ creg x ++ ")"
604+doOp v (LExternal pk) [_, p, o] | pk == sUN "prim__peek16"
605+ = v ++ "idris_peekB16(vm," ++ creg p ++ "," ++ creg o ++")"
606+doOp v (LExternal pk) [_, p, o, x] | pk == sUN "prim__poke16"
607+ = v ++ "idris_pokeB16(" ++ creg p ++ "," ++ creg o ++ "," ++ creg x ++ ")"
608+doOp v (LExternal pk) [_, p, o] | pk == sUN "prim__peek32"
609+ = v ++ "idris_peekB32(vm," ++ creg p ++ "," ++ creg o ++")"
610+doOp v (LExternal pk) [_, p, o, x] | pk == sUN "prim__poke32"
611+ = v ++ "idris_pokeB32(" ++ creg p ++ "," ++ creg o ++ "," ++ creg x ++ ")"
612+doOp v (LExternal pk) [_, p, o] | pk == sUN "prim__peek64"
613+ = v ++ "idris_peekB64(vm," ++ creg p ++ "," ++ creg o ++")"
614+doOp v (LExternal pk) [_, p, o, x] | pk == sUN "prim__poke64"
615+ = v ++ "idris_pokeB64(" ++ creg p ++ "," ++ creg o ++ "," ++ creg x ++ ")"
616+doOp v (LExternal mpt) [p] | mpt == sUN "prim__asPtr" = v ++ "MKPTR(vm, GETMPTR("++ creg p ++"))"
601617doOp _ op args = error $ "doOp not implemented (" ++ show (op, args) ++ ")"
602618
619+
603620flUnOp :: String -> String -> String
604621flUnOp name val = "MKFLOAT(vm, " ++ name ++ "(GETFLOAT(" ++ val ++ ")))"
605622
@@ -610,7 +627,7 @@ flUnOp name val = "MKFLOAT(vm, " ++ name ++ "(GETFLOAT(" ++ val ++ ")))"
610627ifaceC :: Export -> String
611628ifaceC (ExportData n) = "typedef VAL " ++ cdesc n ++ ";\n"
612629ifaceC (ExportFun n cn ret args)
613− = ctype ret ++ " " ++ cdesc cn ++
630+ = ctype ret ++ " " ++ cdesc cn ++
614631 "(VM* vm" ++ showArgs (zip argNames args) ++ ") {\n"
615632 ++ mkBody n (zip argNames args) ret ++ "}\n\n"
616633 where showArgs [] = ""
@@ -623,7 +640,7 @@ mkBody n as t = indent 1 ++ "INITFRAME;\n" ++
623640 indent 1 ++ "RESERVE(" ++ show (max (length as) 3) ++ ");\n" ++
624641 push 0 as ++ call n ++ retval t
625642 where push i [] = ""
626− push i ((n, t) : ts) = indent 1 ++ c_irts (toFType t)
643+ push i ((n, t) : ts) = indent 1 ++ c_irts (toFType t)
627644 ("TOP(" ++ show i ++ ") = ") n
628645 ++ ";\n" ++ push (i + 1) ts
629646
@@ -689,13 +706,10 @@ hdr_guard x = "__" ++ map hchar x
689706hdr_export :: Export -> String
690707hdr_export (ExportData n) = "typedef VAL " ++ cdesc n ++ ";\n"
691708hdr_export (ExportFun n cn ret args)
692− = ctype ret ++ " " ++ cdesc cn ++
709+ = ctype ret ++ " " ++ cdesc cn ++
693710 "(VM* vm" ++ showArgs (zip argNames args) ++ ");\n"
694711 where showArgs [] = ""
695712 showArgs ((n, t) : ts) = ", " ++ ctype t ++ " " ++ n ++
696713 showArgs ts
697714
698715 argNames = zipWith (++) (repeat "arg") (map show [0..])
699−
700−
701−