on master help sign in
Overdid the external primitives

ReadStr and WriteStr should stay internal, for ease of bootstrapping new back ends (and they don't use Ptr anyway)

commit9d7c50a7bd5aa58d4b18d5be111b717d7077b7a2 authorEdwin Brady <ecb10@st-andrews.ac.uk> dateSun 29 Mar 2015, 16:50 (12 years ago) parent5433d22
4 files changed+12−33
libs/prelude/Builtins.idr−2 src/IRTS/CodegenC.hs+7−8 src/IRTS/Lang.hs+1 src/Idris/Primitives.hs+4−23
libs/prelude/Builtins.idr−2
@@ -162,8 +162,6 @@ abstract data ManagedPtr : Type
162162
163163%extern prim__readFile : prim__WorldType -> Ptr -> String
164164%extern prim__writeFile : prim__WorldType -> Ptr -> String -> Int
165−%extern prim__readString : prim__WorldType -> String
166−%extern prim__writeString : prim__WorldType -> String -> Int
167165
168166%extern prim__vm : Ptr
169167%extern prim__stdin : Ptr
src/IRTS/CodegenC.hs+7−8
@@ -529,6 +529,13 @@ doOp v LStrConcat [l,r] = v ++ "idris_concat(vm, " ++ creg l ++ ", " ++ creg r +
529529doOp v LStrLt [l,r] = v ++ "idris_strlt(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
530530doOp v LStrEq [l,r] = v ++ "idris_streq(vm, " ++ creg l ++ ", " ++ creg r ++ ")"
531531
532+doOp v LReadStr [_] = v ++ "idris_readStr(vm, stdin)"
533+doOp v LWriteStr [_,s]
534+ = v ++ "MKINT((i_int)(idris_writeStr(stdout"
535+ ++ ",GETSTR("
536+ ++ creg s ++ "))))"
537+
538+
532539-- String functions which need to know we're UTF8
533540doOp v LStrHead [x] = v ++ "idris_strHead(vm, " ++ creg x ++ ")"
534541doOp v LStrTail [x] = v ++ "idris_strTail(vm, " ++ creg x ++ ")"
@@ -548,14 +555,6 @@ doOp v LSystemInfo [x] = v ++ "idris_systemInfo(vm, " ++ creg x ++ ")"
548555doOp v LNoOp args = v ++ creg (last args)
549556
550557-- Pointer primitives (declared as %extern in Builtins.idr)
551−doOp v (LExternal rs) [_]
552− | rs == sUN "prim__readString" = v ++ "idris_readStr(vm, stdin)"
553−doOp v (LExternal ws) [_,s]
554− | ws == sUN "prim__writeString"
555− = v ++ "MKINT((i_int)(idris_writeStr(stdout"
556− ++ ",GETSTR("
557− ++ creg s ++ "))))"
558−
559558doOp v (LExternal rf) [_,x]
560559 | rf == sUN "prim__readFile"
561560 = v ++ "idris_readStr(vm, GETPTR(" ++ creg x ++ "))"
src/IRTS/Lang.hs+1
@@ -75,6 +75,7 @@ data PrimFn = LPlus ArithTy | LMinus ArithTy | LTimes ArithTy
7575 | LFSqrt | LFFloor | LFCeil | LFNegate
7676
7777 | LStrHead | LStrTail | LStrCons | LStrIndex | LStrRev
78+ | LReadStr | LWriteStr
7879
7980 -- system info
8081 | LSystemInfo
src/Idris/Primitives.hs+4−23
@@ -166,29 +166,10 @@ primitives =
166166 Prim (sUN "prim__strRev") (ty [StrType] StrType) 1 (p_strRev)
167167 (1, LStrRev) total,
168168
169−-- Prim (sUN "prim__readFile") (ty [WorldType,PtrType] StrType) 2 (p_cantreduce)
170−-- (2, LReadFile) total, -- total is okay, because we have 'WorldType'
171−-- Prim (sUN "prim__writeFile") (ty [WorldType,PtrType,StrType] (AType (ATInt ITNative))) 3 (p_cantreduce)
172−-- (3, LWriteFile) total,
173−-- Prim (sUN "prim__readString") (ty [WorldType] StrType) 1 (p_cantreduce)
174−-- (1, LReadStr) total, -- total is okay, because we have 'WorldType'
175−-- Prim (sUN "prim__writeString") (ty [WorldType,StrType] (AType (ATInt ITNative))) 2 (p_cantreduce)
176−-- (2, LWriteStr) total,
177−--
178−-- Prim (sUN "prim__vm") (ty [] PtrType) 0 (p_cantreduce)
179−-- (0, LVMPtr) total,
180−-- -- Streams
181−-- Prim (sUN "prim__stdin") (ty [] PtrType) 0 (p_cantreduce)
182−-- (0, LStdIn) total,
183−-- Prim (sUN "prim__stdout") (ty [] PtrType) 0 (p_cantreduce)
184−-- (0, LStdOut) total,
185−-- Prim (sUN "prim__stderr") (ty [] PtrType) 0 (p_cantreduce)
186−-- (0, LStdErr) total,
187−-- Prim (sUN "prim__null") (ty [] PtrType) 0 (p_cantreduce)
188−-- (0, LNullPtr) total,
189−-- -- Managed pointer registration
190−-- Prim (sUN "prim__registerPtr") (ty [PtrType, AType (ATInt ITNative)] ManagedPtrType) 2 (p_cantreduce)
191−-- (2, LRegisterPtr) total,
169+ Prim (sUN "prim__readString") (ty [WorldType] StrType) 1 (p_cantreduce)
170+ (1, LReadStr) total, -- total is okay, because we have 'WorldType'
171+ Prim (sUN "prim__writeString") (ty [WorldType,StrType] (AType (ATInt ITNative))) 2 (p_cantreduce)
172+ (2, LWriteStr) total,
192173 Prim (sUN "prim__systemInfo") (ty [AType (ATInt ITNative)] StrType) 1 (p_cantreduce)
193174 (1, LSystemInfo) total
194175 ] ++ concatMap intOps [ITFixed IT8, ITFixed IT16, ITFixed IT32, ITFixed IT64, ITBig, ITNative, ITChar]