on master help sign in
Support externally defined primitives
fc02362Edwin Brady
CHANGELOG+10
@@ -1,5 +1,15 @@
1New in 0.9.18:
1New in 0.9.18:
2--------------
2--------------
3+* Strings are now UTF8 encoded in the default back end
4+* Some reorganisation of primitives:
5+ + Buffer and BitVector primitives have been removed (they were not
6+ tested sufficiently, and lack a maintainer)
7+ + Float has been renamed 'Double' (Float is defined in the Prelude for
8+ compatibility)
9+ + Externally defined primitives and operations now supported with
10+ '%extern' directive, allowing back ends to define their own special
11+ purpose primitives
12+ + Ptr and ManagedPtr have been removed and replaced with external primitives
3* Syntax rules no longer perform variable capture. Users of effects will
13* Syntax rules no longer perform variable capture. Users of effects will
4 need to explicitly name results in dependent effect signatures instead
14 need to explicitly name results in dependent effect signatures instead
5 of using the default name "result".
15 of using the default name "result".
libs/prelude/Builtins.idr+20
@@ -154,3 +154,23 @@ really_believe_me x = prim__believe_me _ _ x
154Float : Type
154Float : Type
155Float = Double
155Float = Double
156
156
157+-- Pointers as external primitive; there's no literals for these, so no
158+-- need for them to be part of the compiler.
159+
160+abstract data Ptr : Type
161+abstract data ManagedPtr : Type
162+
163+%extern prim__readFile : prim__WorldType -> Ptr -> String
164+%extern prim__writeFile : prim__WorldType -> Ptr -> String -> Int
165+%extern prim__readString : prim__WorldType -> String
166+%extern prim__writeString : prim__WorldType -> String -> Int
167+
168+%extern prim__vm : Ptr
169+%extern prim__stdin : Ptr
170+%extern prim__stdout : Ptr
171+%extern prim__stderr : Ptr
172+
173+%extern prim__null : Ptr
174+%extern prim__registerPtr : Ptr -> Int -> ManagedPtr
175+
176+
src/IRTS/CodegenC.hs+28−19
@@ -451,16 +451,6 @@ doOp v (LIntStr (ITFixed _)) [x] = v ++ "idris_castBitsStr(vm, " ++ creg x ++ ")
451doOp v LFloatStr [x] = v ++ "idris_castFloatStr(vm, " ++ creg x ++ ")"
451doOp v LFloatStr [x] = v ++ "idris_castFloatStr(vm, " ++ creg x ++ ")"
452doOp v LStrFloat [x] = v ++ "idris_castStrFloat(vm, " ++ creg x ++ ")"
452doOp v LStrFloat [x] = v ++ "idris_castStrFloat(vm, " ++ creg x ++ ")"
453
453
454−doOp v LReadStr [_] = v ++ "idris_readStr(vm, stdin)"
455−doOp v LWriteStr [_,s] = v ++ "MKINT((i_int)(idris_writeStr(stdout"
456− ++ ",GETSTR("
457− ++ creg s ++ "))))"
458−
459−doOp v LReadFile [_,x] = v ++ "idris_readStr(vm, GETPTR(" ++ creg x ++ "))"
460−doOp v LWriteFile [_,x,s] = v ++ "MKINT((i_int)(idris_writeStr(GETPTR(" ++ creg x
461− ++ "),GETSTR("
462− ++ creg s ++ "))))"
463−
464doOp v (LSLt (ATInt (ITFixed ty))) [x, y] = bitOp v "SLt" ty [x, y]
454doOp v (LSLt (ATInt (ITFixed ty))) [x, y] = bitOp v "SLt" ty [x, y]
465doOp v (LSLe (ATInt (ITFixed ty))) [x, y] = bitOp v "SLte" ty [x, y]
455doOp v (LSLe (ATInt (ITFixed ty))) [x, y] = bitOp v "SLte" ty [x, y]
466doOp v (LEq (ATInt (ITFixed ty))) [x, y] = bitOp v "Eq" ty [x, y]
456doOp v (LEq (ATInt (ITFixed ty))) [x, y] = bitOp v "Eq" ty [x, y]
@@ -552,16 +542,8 @@ doOp v LStrIndex [x, y] = v ++ "idris_strIndex(vm, " ++ creg x ++ "," ++ creg y
552doOp v LStrRev [x] = v ++ "idris_strRev(vm, " ++ creg x ++ ")"
542doOp v LStrRev [x] = v ++ "idris_strRev(vm, " ++ creg x ++ ")"
553doOp v LStrLen [x] = v ++ "idris_strlen(vm, " ++ creg x ++ ")"
543doOp v LStrLen [x] = v ++ "idris_strlen(vm, " ++ creg x ++ ")"
554
544
555−doOp v LStdIn [] = v ++ "MKPTR(vm, stdin)"
556−doOp v LStdOut [] = v ++ "MKPTR(vm, stdout)"
557−doOp v LStdErr [] = v ++ "MKPTR(vm, stderr)"
558−
559doOp v LFork [x] = v ++ "MKPTR(vm, vmThread(vm, " ++ cname (sMN 0 "EVAL") ++ ", " ++ creg x ++ "))"
545doOp v LFork [x] = v ++ "MKPTR(vm, vmThread(vm, " ++ cname (sMN 0 "EVAL") ++ ", " ++ creg x ++ "))"
560doOp v LPar [x] = v ++ creg x -- "MKPTR(vm, vmThread(vm, " ++ cname (MN 0 "EVAL") ++ ", " ++ creg x ++ "))"
546doOp v LPar [x] = v ++ creg x -- "MKPTR(vm, vmThread(vm, " ++ cname (MN 0 "EVAL") ++ ", " ++ creg x ++ "))"
561−doOp v LVMPtr [] = v ++ "MKPTR(vm, vm)"
562−doOp v LNullPtr [] = v ++ "MKPTR(vm, NULL)"
563−doOp v LRegisterPtr [p, i] = v ++ "MKMPTR(vm, GETPTR(" ++ creg p ++
564− "), GETINT(" ++ creg i ++ "))"
565doOp v (LChInt ITNative) args = v ++ creg (last args)
547doOp v (LChInt ITNative) args = v ++ creg (last args)
566doOp v (LChInt ITChar) args = doOp v (LChInt ITNative) args
548doOp v (LChInt ITChar) args = doOp v (LChInt ITNative) args
567doOp v (LIntCh ITNative) args = v ++ creg (last args)
549doOp v (LIntCh ITNative) args = v ++ creg (last args)
@@ -569,7 +551,34 @@ doOp v (LIntCh ITChar) args = doOp v (LIntCh ITNative) args
569
551
570doOp v LSystemInfo [x] = v ++ "idris_systemInfo(vm, " ++ creg x ++ ")"
552doOp v LSystemInfo [x] = v ++ "idris_systemInfo(vm, " ++ creg x ++ ")"
571doOp v LNoOp args = v ++ creg (last args)
553doOp v LNoOp args = v ++ creg (last args)
554+
555+-- Pointer primitives (declared as %extern in Builtins.idr)
556+doOp v (LExternal rs) [_]
557+ | rs == sUN "prim__readString" = v ++ "idris_readStr(vm, stdin)"
558+doOp v (LExternal ws) [_,s]
559+ | ws == sUN "prim__writeString"
560+ = v ++ "MKINT((i_int)(idris_writeStr(stdout"
561+ ++ ",GETSTR("
562+ ++ creg s ++ "))))"
563+
564+doOp v (LExternal rf) [_,x]
565+ | rf == sUN "prim__readFile"
566+ = v ++ "idris_readStr(vm, GETPTR(" ++ creg x ++ "))"
567+doOp v (LExternal wf) [_,x,s]
568+ | wf == sUN "prim__writeFile"
569+ = v ++ "MKINT((i_int)(idris_writeStr(GETPTR(" ++ creg x
570+ ++ "),GETSTR("
571+ ++ creg s ++ "))))"
572+doOp v (LExternal vm) [] | vm == sUN "prim__vm" = v ++ "MKPTR(vm, vm)"
573+doOp v (LExternal si) [] | si == sUN "prim__stdin" = v ++ "MKPTR(vm, stdin)"
574+doOp v (LExternal so) [] | so == sUN "prim__stdout" = v ++ "MKPTR(vm, stdout)"
575+doOp v (LExternal se) [] | se == sUN "prim__stderr" = v ++ "MKPTR(vm, stderr)"
576+
577+doOp v (LExternal nul) [] | nul == sUN "prim__null" = v ++ "MKPTR(vm, NULL)"
578+doOp v (LExternal rp) [p, i] | rp == sUN "prim__registerPtr"
579+ = v ++ "MKMPTR(vm, GETPTR(" ++ creg p ++ "), GETINT(" ++ creg i ++ "))"
580+
572−doOp _ op args = error "doOp of (" ++ show op ++ ") not implemented, arguments (" ++ show args ++ ")"
581+doOp _ op args = error $ "doOp not implemented (" ++ show (op, args) ++ ")"
573
582
574flUnOp :: String -> String -> String
583flUnOp :: String -> String -> String
575flUnOp name val = "MKFLOAT(vm, " ++ name ++ "(GETFLOAT(" ++ val ++ ")))"
584flUnOp name val = "MKFLOAT(vm, " ++ name ++ "(GETFLOAT(" ++ val ++ ")))"
src/IRTS/CodegenJavaScript.hs+4−2
@@ -680,7 +680,8 @@ jsOP _ reg op args = JSAssign (translateReg reg) jsOP'
680 jsOP'
680 jsOP'
681 | LNoOp <- op = translateReg (last args)
681 | LNoOp <- op = translateReg (last args)
682
682
683− | LWriteStr <- op,
683+ | (LExternal ws) <- op,
684+ ws == sUN "prim__writeString",
684 (_:str:_) <- args = JSAssign (translateReg reg)
685 (_:str:_) <- args = JSAssign (translateReg reg)
685 (JSApp (JSIdent "i$putStr") [translateReg str])
686 (JSApp (JSIdent "i$putStr") [translateReg str])
686
687
@@ -1269,7 +1270,8 @@ jsOP _ reg op args = JSAssign (translateReg reg) jsOP'
1269
1270
1270 | LSystemInfo <- op
1271 | LSystemInfo <- op
1271 , (arg:_) <- args = jsCall "i$systemInfo" [translateReg arg]
1272 , (arg:_) <- args = jsCall "i$systemInfo" [translateReg arg]
1272− | LNullPtr <- op
1273+ | LExternal nul <- op
1274+ , nul == sUN "prim__null"
1273 , (_) <- args = JSNull
1275 , (_) <- args = JSNull
1274 | otherwise = JSError $ "Not implemented: " ++ show op
1276 | otherwise = JSError $ "Not implemented: " ++ show op
1275 where
1277 where
src/IRTS/Compiler.hs+14−3
@@ -185,7 +185,7 @@ isCon _ = False
185build :: (Name, Def) -> Idris (Name, LDecl)
185build :: (Name, Def) -> Idris (Name, LDecl)
186build (n, d)
186build (n, d)
187 = do i <- getIState
187 = do i <- getIState
188− case lookup n (idris_scprims i) of
188+ case getPrim n i of
189 Just (ar, op) ->
189 Just (ar, op) ->
190 let args = map (\x -> sMN x "op") [0..] in
190 let args = map (\x -> sMN x "op") [0..] in
191 return (n, (LFun [] n (take ar args)
191 return (n, (LFun [] n (take ar args)
@@ -193,6 +193,12 @@ build (n, d)
193 _ -> do def <- mkLDecl n d
193 _ -> do def <- mkLDecl n d
194 logLvl 3 $ "Compiled " ++ show n ++ " =\n\t" ++ show def
194 logLvl 3 $ "Compiled " ++ show n ++ " =\n\t" ++ show def
195 return (n, def)
195 return (n, def)
196+ where getPrim n i
197+ | Just (ar, op) <- lookup n (idris_scprims i)
198+ = Just (ar, op)
199+ | Just ar <- lookup n (S.toList (idris_externs i))
200+ = Just (ar, LExternal n)
201+ getPrim n i = Nothing
196
202
197declArgs args inl n (LLam xs x) = declArgs (args ++ xs) inl n x
203declArgs args inl n (LLam xs x) = declArgs (args ++ xs) inl n x
198declArgs args inl n x = LFun (if inl then [Inline] else []) n args x
204declArgs args inl n x = LFun (if inl then [Inline] else []) n args x
@@ -225,7 +231,9 @@ data VarInfo = VI
225type Vars = M.Map Name VarInfo
231type Vars = M.Map Name VarInfo
226
232
227irTerm :: Vars -> [Name] -> Term -> Idris LExp
233irTerm :: Vars -> [Name] -> Term -> Idris LExp
228−irTerm vs env tm@(App f a) = case unApply tm of
234+irTerm vs env tm@(App f a) = do
235+ ist <- getIState
236+ case unApply tm of
229 (P _ (UN m) _, args)
237 (P _ (UN m) _, args)
230 | m == txt "mkForeignPrim"
238 | m == txt "mkForeignPrim"
231 -> doForeign vs env (reverse (drop 4 args)) -- drop implicits
239 -> doForeign vs env (reverse (drop 4 args)) -- drop implicits
@@ -359,9 +367,12 @@ irTerm vs env tm@(App f a) = case unApply tm of
359 -- type constructor
367 -- type constructor
360 (P (TCon t a) n _, args) -> return LNothing
368 (P (TCon t a) n _, args) -> return LNothing
361
369
370+ -- an external name applied to arguments
371+ (P _ n _, args) | S.member (n, length args) (idris_externs ist) -> do
372+ LOp (LExternal n) <$> mapM (irTerm vs env) args
373+
362 -- a name applied to arguments
374 -- a name applied to arguments
363 (P _ n _, args) -> do
375 (P _ n _, args) -> do
364− ist <- getIState
365 case lookup n (idris_scprims ist) of
376 case lookup n (idris_scprims ist) of
366 -- if it's a primitive that is already saturated,
377 -- if it's a primitive that is already saturated,
367 -- compile to the corresponding op here already to save work
378 -- compile to the corresponding op here already to save work
src/IRTS/Lang.hs+1−5
@@ -69,14 +69,12 @@ data PrimFn = LPlus ArithTy | LMinus ArithTy | LTimes ArithTy
69 | LStrConcat | LStrLt | LStrEq | LStrLen
69 | LStrConcat | LStrLt | LStrEq | LStrLen
70 | LIntFloat IntTy | LFloatInt IntTy | LIntStr IntTy | LStrInt IntTy
70 | LIntFloat IntTy | LFloatInt IntTy | LIntStr IntTy | LStrInt IntTy
71 | LFloatStr | LStrFloat | LChInt IntTy | LIntCh IntTy
71 | LFloatStr | LStrFloat | LChInt IntTy | LIntCh IntTy
72− | LReadStr | LWriteStr | LReadFile | LWriteFile
73 | LBitCast ArithTy ArithTy -- Only for values of equal width
72 | LBitCast ArithTy ArithTy -- Only for values of equal width
74
73
75 | LFExp | LFLog | LFSin | LFCos | LFTan | LFASin | LFACos | LFATan
74 | LFExp | LFLog | LFSin | LFCos | LFTan | LFASin | LFACos | LFATan
76 | LFSqrt | LFFloor | LFCeil | LFNegate
75 | LFSqrt | LFFloor | LFCeil | LFNegate
77
76
78 | LStrHead | LStrTail | LStrCons | LStrIndex | LStrRev
77 | LStrHead | LStrTail | LStrCons | LStrIndex | LStrRev
79− | LStdIn | LStdOut | LStdErr
80
78
81 -- system info
79 -- system info
82 | LSystemInfo
80 | LSystemInfo
@@ -84,9 +82,7 @@ data PrimFn = LPlus ArithTy | LMinus ArithTy | LTimes ArithTy
84 | LFork
82 | LFork
85 | LPar -- evaluate argument anywhere, possibly on another
83 | LPar -- evaluate argument anywhere, possibly on another
86 -- core or another machine. 'id' is a valid implementation
84 -- core or another machine. 'id' is a valid implementation
87− | LVMPtr
85+ | LExternal Name
88− | LNullPtr
89− | LRegisterPtr
90 | LNoOp
86 | LNoOp
91 deriving (Show, Eq)
87 deriving (Show, Eq)
92
88
src/Idris/AbsSyntax.hs+3−3
@@ -1013,13 +1013,13 @@ expandParamsD rhsonly ist dec ps ns (PTy doc argdocs syn fc o n ty)
1013 PTy doc argdocs syn fc o (dec n) (piBindp expl_param ps (expandParams dec ps ns [] ty))
1013 PTy doc argdocs syn fc o (dec n) (piBindp expl_param ps (expandParams dec ps ns [] ty))
1014 else --trace (show (n, expandParams dec ps ns ty)) $
1014 else --trace (show (n, expandParams dec ps ns ty)) $
1015 PTy doc argdocs syn fc o n (expandParams dec ps ns [] ty)
1015 PTy doc argdocs syn fc o n (expandParams dec ps ns [] ty)
1016−expandParamsD rhsonly ist dec ps ns (PPostulate doc syn fc o n ty)
1016+expandParamsD rhsonly ist dec ps ns (PPostulate e doc syn fc o n ty)
1017 = if n `elem` ns && (not rhsonly)
1017 = if n `elem` ns && (not rhsonly)
1018 then -- trace (show (n, expandParams dec ps ns ty)) $
1018 then -- trace (show (n, expandParams dec ps ns ty)) $
1019− PPostulate doc syn fc o (dec n) (piBind ps
1019+ PPostulate e doc syn fc o (dec n) (piBind ps
1020 (expandParams dec ps ns [] ty))
1020 (expandParams dec ps ns [] ty))
1021 else --trace (show (n, expandParams dec ps ns ty)) $
1021 else --trace (show (n, expandParams dec ps ns ty)) $
1022− PPostulate doc syn fc o n (expandParams dec ps ns [] ty)
1022+ PPostulate e doc syn fc o n (expandParams dec ps ns [] ty)
1023expandParamsD rhsonly ist dec ps ns (PClauses fc opts n cs)
1023expandParamsD rhsonly ist dec ps ns (PClauses fc opts n cs)
1024 = let n' = if n `elem` ns then dec n else n in
1024 = let n' = if n `elem` ns then dec n else n in
1025 PClauses fc opts n' (map expandParamsC cs)
1025 PClauses fc opts n' (map expandParamsC cs)
src/Idris/AbsSyntaxTree.hs+8−5
@@ -226,6 +226,7 @@ data IState = IState {
226 module_aliases :: M.Map [T.Text] [T.Text],
226 module_aliases :: M.Map [T.Text] [T.Text],
227 idris_consolewidth :: ConsoleWidth, -- ^ How many chars wide is the console?
227 idris_consolewidth :: ConsoleWidth, -- ^ How many chars wide is the console?
228 idris_postulates :: S.Set Name,
228 idris_postulates :: S.Set Name,
229+ idris_externs :: S.Set (Name, Int),
229 idris_erasureUsed :: [(Name, Int)], -- ^ Function/constructor name, argument position is used
230 idris_erasureUsed :: [(Name, Int)], -- ^ Function/constructor name, argument position is used
230 idris_whocalls :: Maybe (M.Map Name [Name]),
231 idris_whocalls :: Maybe (M.Map Name [Name]),
231 idris_callswho :: Maybe (M.Map Name [Name]),
232 idris_callswho :: Maybe (M.Map Name [Name]),
@@ -300,6 +301,7 @@ data IBCWrite = IBCFix FixDecl
300 | IBCErrorHandler Name
301 | IBCErrorHandler Name
301 | IBCFunctionErrorHandler Name Name Name
302 | IBCFunctionErrorHandler Name Name Name
302 | IBCPostulate Name
303 | IBCPostulate Name
304+ | IBCExtern (Name, Int)
303 | IBCTotCheckErr FC String
305 | IBCTotCheckErr FC String
304 | IBCParsedRegion FC
306 | IBCParsedRegion FC
305 | IBCModDocs Name -- ^ The name is the special name used to track module docs
307 | IBCModDocs Name -- ^ The name is the special name used to track module docs
@@ -317,7 +319,7 @@ idrisInit = IState initContext S.empty []
317 [] [] [] defaultOpts 6 [] [] [] [] emptySyntaxRules [] [] [] [] [] [] []
319 [] [] [] defaultOpts 6 [] [] [] [] emptySyntaxRules [] [] [] [] [] [] []
318 [] [] Nothing [] Nothing [] [] Nothing Nothing [] Hidden False [] Nothing [] []
320 [] [] Nothing [] Nothing [] [] Nothing Nothing [] Hidden False [] Nothing [] []
319 (RawOutput stdout) True defaultTheme [] (0, emptyContext) emptyContext M.empty
321 (RawOutput stdout) True defaultTheme [] (0, emptyContext) emptyContext M.empty
320− AutomaticWidth S.empty [] Nothing Nothing [] [] M.empty []
322+ AutomaticWidth S.empty S.empty [] Nothing Nothing [] [] M.empty []
321
323
322-- | The monad for the main REPL - reading and processing files and updating
324-- | The monad for the main REPL - reading and processing files and updating
323-- global state (hence the IO inner monad).
325-- global state (hence the IO inner monad).
@@ -594,7 +596,8 @@ type ProvideWhat = ProvideWhat' PTerm
594data PDecl' t
596data PDecl' t
595 = PFix FC Fixity [String] -- ^ Fixity declaration
597 = PFix FC Fixity [String] -- ^ Fixity declaration
596 | PTy (Docstring (Either Err PTerm)) [(Name, Docstring (Either Err PTerm))] SyntaxInfo FC FnOpts Name t -- ^ Type declaration
598 | PTy (Docstring (Either Err PTerm)) [(Name, Docstring (Either Err PTerm))] SyntaxInfo FC FnOpts Name t -- ^ Type declaration
599+ | PPostulate Bool -- external def if true
597− | PPostulate (Docstring (Either Err PTerm)) SyntaxInfo FC FnOpts Name t -- ^ Postulate
600+ (Docstring (Either Err PTerm)) SyntaxInfo FC FnOpts Name t -- ^ Postulate
598 | PClauses FC FnOpts Name [PClause' t] -- ^ Pattern clause
601 | PClauses FC FnOpts Name [PClause' t] -- ^ Pattern clause
599 | PCAF FC Name t -- ^ Top level constant
602 | PCAF FC Name t -- ^ Top level constant
600 | PData (Docstring (Either Err PTerm)) [(Name, Docstring (Either Err PTerm))] SyntaxInfo FC DataOpts (PData' t) -- ^ Data declaration.
603 | PData (Docstring (Either Err PTerm)) [(Name, Docstring (Either Err PTerm))] SyntaxInfo FC DataOpts (PData' t) -- ^ Data declaration.
@@ -694,7 +697,7 @@ type PClause = PClause' PTerm
694declared :: PDecl -> [Name]
697declared :: PDecl -> [Name]
695declared (PFix _ _ _) = []
698declared (PFix _ _ _) = []
696declared (PTy _ _ _ _ _ n t) = [n]
699declared (PTy _ _ _ _ _ n t) = [n]
697−declared (PPostulate _ _ _ _ n t) = [n]
700+declared (PPostulate _ _ _ _ _ n t) = [n]
698declared (PClauses _ _ n _) = [] -- not a declaration
701declared (PClauses _ _ n _) = [] -- not a declaration
699declared (PCAF _ n _) = [n]
702declared (PCAF _ n _) = [n]
700declared (PData _ _ _ _ _ (PDatadecl n _ ts)) = n : map fstt ts
703declared (PData _ _ _ _ _ (PDatadecl n _ ts)) = n : map fstt ts
@@ -714,7 +717,7 @@ declared (PDirective _) = []
714tldeclared :: PDecl -> [Name]
717tldeclared :: PDecl -> [Name]
715tldeclared (PFix _ _ _) = []
718tldeclared (PFix _ _ _) = []
716tldeclared (PTy _ _ _ _ _ n t) = [n]
719tldeclared (PTy _ _ _ _ _ n t) = [n]
717−tldeclared (PPostulate _ _ _ _ n t) = [n]
720+tldeclared (PPostulate _ _ _ _ _ n t) = [n]
718tldeclared (PClauses _ _ n _) = [] -- not a declaration
721tldeclared (PClauses _ _ n _) = [] -- not a declaration
719tldeclared (PRecord _ _ _ n _ _ _ c _) = [n, c]
722tldeclared (PRecord _ _ _ n _ _ _ c _) = [n, c]
720tldeclared (PData _ _ _ _ _ (PDatadecl n _ ts)) = n : map fstt ts
723tldeclared (PData _ _ _ _ _ (PDatadecl n _ ts)) = n : map fstt ts
@@ -729,7 +732,7 @@ tldeclared _ = []
729defined :: PDecl -> [Name]
732defined :: PDecl -> [Name]
730defined (PFix _ _ _) = []
733defined (PFix _ _ _) = []
731defined (PTy _ _ _ _ _ n t) = []
734defined (PTy _ _ _ _ _ n t) = []
732−defined (PPostulate _ _ _ _ n t) = []
735+defined (PPostulate _ _ _ _ _ n t) = []
733defined (PClauses _ _ n _) = [n] -- not a declaration
736defined (PClauses _ _ n _) = [n] -- not a declaration
734defined (PCAF _ n _) = [n]
737defined (PCAF _ n _) = [n]
735defined (PData _ _ _ _ _ (PDatadecl n _ ts)) = n : map fstt ts
738defined (PData _ _ _ _ _ (PDatadecl n _ ts)) = n : map fstt ts
src/Idris/Core/Execute.hs+39−30
@@ -251,6 +251,9 @@ execApp env ctxt c@(EP (TCon _ arity) n _) args =
251 let restArgs = drop arity args
251 let restArgs = drop arity args
252 execApp env ctxt (mkEApp c args') restArgs
252 execApp env ctxt (mkEApp c args') restArgs
253
253
254+execApp env ctxt f@(EP _ n _) args
255+ | Just (res, rest) <- getOp n args = do r <- res
256+ execApp env ctxt r rest
254execApp env ctxt f@(EP _ n _) args =
257execApp env ctxt f@(EP _ n _) args =
255 do let val = lookupDef n ctxt
258 do let val = lookupDef n ctxt
256 case val of
259 case val of
@@ -260,9 +263,9 @@ execApp env ctxt f@(EP _ n _) args =
260 if length args >= arity
263 if length args >= arity
261 then let args' = take arity args in
264 then let args' = take arity args in
262 case getOp n args' of
265 case getOp n args' of
263− Just res -> do r <- res
266+ Just (res, []) -> do r <- res
264− execApp env ctxt r (drop arity args)
267+ execApp env ctxt r (drop arity args)
265− Nothing -> return (mkEApp f args)
268+ _ -> return (mkEApp f args)
266 else return (mkEApp f args)
269 else return (mkEApp f args)
267 [CaseOp _ _ _ _ _ (CaseDefs _ ([], STerm tm) _ _)] -> -- nullary fun
270 [CaseOp _ _ _ _ _ (CaseDefs _ ([], STerm tm) _ _)] -> -- nullary fun
268 do rhs <- doExec env ctxt tm
271 do rhs <- doExec env ctxt tm
@@ -418,41 +421,47 @@ upio = sUN "unsafePerformPrimIO"
418delay = sUN "Delay"
421delay = sUN "Delay"
419force = sUN "Force"
422force = sUN "Force"
420
423
421−-- | Look up primitive operations in the global table and transform them into ExecVal functions
424+-- | Look up primitive operations in the global table and transform
425+-- them into ExecVal functions
422−getOp :: Name -> [ExecVal] -> Maybe (Exec ExecVal)
426+getOp :: Name -> [ExecVal] -> Maybe (Exec ExecVal, [ExecVal])
423−getOp fn [_, _, x] | fn == pbm = Just (return x)
427+getOp fn (_ : _ : x : xs) | fn == pbm = Just (return x, xs)
424−getOp fn [_, EConstant (Str n)]
428+getOp fn (_ : EConstant (Str n) : xs)
425 | fn == pws =
429 | fn == pws =
426− Just $ do execIO $ putStr n
430+ Just (do execIO $ putStr n
427− return (EConstant (I 0))
431+ return (EConstant (I 0)), xs)
428−getOp fn [_]
432+getOp fn (_:xs)
429 | fn == prs =
433 | fn == prs =
430− Just $ do line <- execIO getLine
434+ Just (do line <- execIO getLine
431− return (EConstant (Str line))
435+ return (EConstant (Str line)), xs)
432−getOp fn [_, EP _ fn' _, EConstant (Str n)]
436+getOp fn (_ : EP _ fn' _ : EConstant (Str n) : xs)
433 | fn == pwf && fn' == pstdout =
437 | fn == pwf && fn' == pstdout =
434− Just $ do execIO $ putStr n
438+ Just (do execIO $ putStr n
435− return (EConstant (I 0))
439+ return (EConstant (I 0)), xs)
436−getOp fn [_, EP _ fn' _]
440+getOp fn (_ : EP _ fn' _ : xs)
437 | fn == prf && fn' == pstdin =
441 | fn == prf && fn' == pstdin =
438− Just $ do line <- execIO getLine
442+ Just (do line <- execIO getLine
439− return (EConstant (Str line))
443+ return (EConstant (Str line)), xs)
440−getOp fn [_, EHandle h, EConstant (Str n)]
444+getOp fn (_ : EHandle h : EConstant (Str n) : xs)
441 | fn == pwf =
445 | fn == pwf =
442− Just $ do execIO $ hPutStr h n
446+ Just (do execIO $ hPutStr h n
443− return (EConstant (I 0))
447+ return (EConstant (I 0)), xs)
444−getOp fn [_, EHandle h]
448+getOp fn (_ : EHandle h : xs)
445 | fn == prf =
449 | fn == prf =
446− Just $ do contents <- execIO $ hGetLine h
450+ Just (do contents <- execIO $ hGetLine h
447− return (EConstant (Str (contents ++ "\n")))
451+ return (EConstant (Str (contents ++ "\n"))), xs)
448−getOp fn [_, arg]
452+getOp fn (_ : arg : xs)
449 | fn == prf =
453 | fn == prf =
450− Just $ execFail (Msg "Can't use prim__readFile on a raw pointer in the executor.")
454+ Just $ (execFail (Msg "Can't use prim__readFile on a raw pointer in the executor."), xs)
451−getOp n args = getPrim n primitives >>= flip applyPrim args
455+getOp n args = do (arity, prim) <- getPrim n primitives
456+ if (length args >= arity)
457+ then do res <- applyPrim prim (take arity args)
458+ Just (res, drop arity args)
459+ else Nothing
452− where getPrim :: Name -> [Prim] -> Maybe ([ExecVal] -> Maybe ExecVal)
460+ where getPrim :: Name -> [Prim] -> Maybe (Int, [ExecVal] -> Maybe ExecVal)
453 getPrim n [] = Nothing
461 getPrim n [] = Nothing
454− getPrim n ((Prim pn _ arity def _ _) : prims) | n == pn = Just $ execPrim def
462+ getPrim n ((Prim pn _ arity def _ _) : prims)
463+ | n == pn = Just (arity, execPrim def)
455− | otherwise = getPrim n prims
464+ | otherwise = getPrim n prims
456
465
457 execPrim :: ([Const] -> Maybe Const) -> [ExecVal] -> Maybe ExecVal
466 execPrim :: ([Const] -> Maybe Const) -> [ExecVal] -> Maybe ExecVal
458 execPrim f args = EConstant <$> (mapM getConst args >>= f)
467 execPrim f args = EConstant <$> (mapM getConst args >>= f)
src/Idris/DeepSeq.hs+2−2
@@ -132,9 +132,9 @@ instance (NFData t) => NFData (PDecl' t) where
132 = rnf x1 `seq`
132 = rnf x1 `seq`
133 rnf x2 `seq`
133 rnf x2 `seq`
134 rnf x3 `seq` rnf x4 `seq` rnf x5 `seq` rnf x6 `seq` rnf x7 `seq` ()
134 rnf x3 `seq` rnf x4 `seq` rnf x5 `seq` rnf x6 `seq` rnf x7 `seq` ()
135− rnf (PPostulate x1 x2 x3 x4 x5 x6)
135+ rnf (PPostulate x1 x2 x3 x4 x5 x6 x7)
136 = rnf x1 `seq`
136 = rnf x1 `seq`
137− rnf x2 `seq` rnf x3 `seq` rnf x4 `seq` rnf x5 `seq` rnf x6 `seq` ()
137+ rnf x2 `seq` rnf x3 `seq` rnf x4 `seq` rnf x5 `seq` rnf x6 `seq` rnf x7 `seq` ()
138 rnf (PClauses x1 x2 x3 x4)
138 rnf (PClauses x1 x2 x3 x4)
139 = rnf x1 `seq` rnf x2 `seq` rnf x3 `seq` rnf x4 `seq` ()
139 = rnf x1 `seq` rnf x2 `seq` rnf x3 `seq` rnf x4 `seq` ()
140 rnf (PCAF x1 x2 x3) = rnf x1 `seq` rnf x2 `seq` rnf x3 `seq` ()
140 rnf (PCAF x1 x2 x3) = rnf x1 `seq` rnf x2 `seq` rnf x3 `seq` ()
src/Idris/Elab/Type.hs+16−1
@@ -1,5 +1,6 @@
1{-# LANGUAGE PatternGuards #-}
1{-# LANGUAGE PatternGuards #-}
2−module Idris.Elab.Type (buildType, elabType, elabType', elabPostulate) where
2+module Idris.Elab.Type (buildType, elabType, elabType',
3+ elabPostulate, elabExtern) where
3
4
4import Idris.AbsSyntax
5import Idris.AbsSyntax
5import Idris.ASTUtils
6import Idris.ASTUtils
@@ -229,5 +230,19 @@ elabPostulate info syn doc fc opts n ty = do
229 -- remove it from the deferred definitions list
230 -- remove it from the deferred definitions list
230 solveDeferred n
231 solveDeferred n
231
232
233+elabExtern :: ElabInfo -> SyntaxInfo -> Docstring (Either Err PTerm) ->
234+ FC -> FnOpts -> Name -> PTerm -> Idris ()
235+elabExtern info syn doc fc opts n ty = do
236+ cty <- elabType info syn doc [] fc opts n ty
237+ ist <- getIState
238+ let arity = length (getArgTys (normalise (tt_ctxt ist) [] cty))
239+
240+ putIState . (\ist -> ist{ idris_externs = S.insert (n, arity) (idris_externs ist) }) =<< getIState
241+ updateContext (addOperator n cty arity (\x -> Nothing))
242+ addIBC (IBCExtern (n, arity))
243+
244+ -- remove it from the deferred definitions list
245+ solveDeferred n
246+
232
247
233
248
src/Idris/ElabDecls.hs+4−2
@@ -160,10 +160,12 @@ elabDecl' what info (PTy doc argdocs s f o n ty)
160 = do iLOG $ "Elaborating type decl " ++ show n ++ show o
160 = do iLOG $ "Elaborating type decl " ++ show n ++ show o
161 elabType info s doc argdocs f o n ty
161 elabType info s doc argdocs f o n ty
162 return ()
162 return ()
163−elabDecl' what info (PPostulate doc s f o n ty)
163+elabDecl' what info (PPostulate b doc s f o n ty)
164 | what /= EDefns
164 | what /= EDefns
165 = do iLOG $ "Elaborating postulate " ++ show n ++ show o
165 = do iLOG $ "Elaborating postulate " ++ show n ++ show o
166+ if b
167+ then elabExtern info s doc f o n ty
166− elabPostulate info s doc f o n ty
168+ else elabPostulate info s doc f o n ty
167elabDecl' what info (PData doc argDocs s f co d)
169elabDecl' what info (PData doc argDocs s f co d)
168 | what /= ETypes
170 | what /= ETypes
169 = do iLOG $ "Elaborating " ++ show (d_name d)
171 = do iLOG $ "Elaborating " ++ show (d_name d)
src/Idris/Erasure.hs+9−4
@@ -77,9 +77,10 @@ performUsageAnalysis roots = do
77 cg <- idris_callgraph <$> getIState
77 cg <- idris_callgraph <$> getIState
78 opt <- idris_optimisation <$> getIState
78 opt <- idris_optimisation <$> getIState
79 used <- idris_erasureUsed <$> getIState
79 used <- idris_erasureUsed <$> getIState
80+ externs <- idris_externs <$> getIState
80
81
81 -- Build the dependency graph.
82 -- Build the dependency graph.
82− let depMap = buildDepMap ci used ctx main
83+ let depMap = buildDepMap ci used (S.toList externs) ctx main
83
84
84 -- Search for reachable nodes in the graph.
85 -- Search for reachable nodes in the graph.
85 let (residDeps, (reachableNames, minUse)) = minimalUsage depMap
86 let (residDeps, (reachableNames, minUse)) = minimalUsage depMap
@@ -174,9 +175,10 @@ forwardChain deps
174
175
175-- Build the dependency graph,
176-- Build the dependency graph,
176-- starting the depth-first search from a list of Names.
177-- starting the depth-first search from a list of Names.
177−buildDepMap :: Ctxt ClassInfo -> [(Name, Int)] -> Context -> [Name] -> Deps
178+buildDepMap :: Ctxt ClassInfo -> [(Name, Int)] -> [(Name, Int)] ->
179+ Context -> [Name] -> Deps
178−buildDepMap ci used ctx startNames = addPostulates used $
180+buildDepMap ci used externs ctx startNames
179− dfs S.empty M.empty startNames
181+ = addPostulates used $ dfs S.empty M.empty startNames
180 where
182 where
181 -- mark the result of Main.main as used with the empty assumption
183 -- mark the result of Main.main as used with the empty assumption
182 addPostulates :: [(Name, Int)] -> Deps -> Deps
184 addPostulates :: [(Name, Int)] -> Deps -> Deps
@@ -226,6 +228,9 @@ buildDepMap ci used ctx startNames = addPostulates used $
226 -- in general, all other primitives use all their arguments
228 -- in general, all other primitives use all their arguments
227 , [(n, Arg i) | (n,arity) <- usedPrims, i <- [0..arity-1]]
229 , [(n, Arg i) | (n,arity) <- usedPrims, i <- [0..arity-1]]
228
230
231+ -- %externs are assumed to use all their arguments
232+ , [(n, Arg i) | (n,arity) <- externs, i <- [0..arity-1]]
233+
229 -- mkForeign* functions are special-cased below
234 -- mkForeign* functions are special-cased below
230 ]
235 ]
231 ]
236 ]
src/Idris/IBC.hs+18−6
@@ -37,7 +37,7 @@ import Codec.Compression.Zlib (compress)
37import Util.Zlib (decompressEither)
37import Util.Zlib (decompressEither)
38
38
39ibcVersion :: Word8
39ibcVersion :: Word8
40−ibcVersion = 101
40+ibcVersion = 102
41
41
42data IBCFile = IBCFile { ver :: Word8,
42data IBCFile = IBCFile { ver :: Word8,
43 sourcefile :: FilePath,
43 sourcefile :: FilePath,
@@ -79,6 +79,7 @@ data IBCFile = IBCFile { ver :: Word8,
79 ibc_metavars :: ![(Name, (Maybe Name, Int, Bool))],
79 ibc_metavars :: ![(Name, (Maybe Name, Int, Bool))],
80 ibc_patdefs :: ![(Name, ([([Name], Term, Term)], [PTerm]))],
80 ibc_patdefs :: ![(Name, ([([Name], Term, Term)], [PTerm]))],
81 ibc_postulates :: ![Name],
81 ibc_postulates :: ![Name],
82+ ibc_externs :: ![(Name, Int)],
82 ibc_parsedSpan :: !(Maybe FC),
83 ibc_parsedSpan :: !(Maybe FC),
83 ibc_usage :: ![(Name, Int)],
84 ibc_usage :: ![(Name, Int)],
84 ibc_exports :: ![Name]
85 ibc_exports :: ![Name]
@@ -89,7 +90,7 @@ deriving instance Binary IBCFile
89!-}
90!-}
90
91
91initIBC :: IBCFile
92initIBC :: IBCFile
92−initIBC = IBCFile ibcVersion "" [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] Nothing [] []
93+initIBC = IBCFile ibcVersion "" [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] Nothing [] []
93
94
94loadIBC :: Bool -- ^ True = reexport, False = make everything private
95loadIBC :: Bool -- ^ True = reexport, False = make everything private
95 -> FilePath -> Idris ()
96 -> FilePath -> Idris ()
@@ -228,6 +229,7 @@ ibc i (IBCMetavar n) f =
228 Nothing -> return f
229 Nothing -> return f
229 Just t -> return f { ibc_metavars = (n, t) : ibc_metavars f }
230 Just t -> return f { ibc_metavars = (n, t) : ibc_metavars f }
230ibc i (IBCPostulate n) f = return f { ibc_postulates = n : ibc_postulates f }
231ibc i (IBCPostulate n) f = return f { ibc_postulates = n : ibc_postulates f }
232+ibc i (IBCExtern n) f = return f { ibc_externs = n : ibc_externs f }
231ibc i (IBCTotCheckErr fc err) f = return f { ibc_totcheckfail = (fc, err) : ibc_totcheckfail f }
233ibc i (IBCTotCheckErr fc err) f = return f { ibc_totcheckfail = (fc, err) : ibc_totcheckfail f }
232ibc i (IBCParsedRegion fc) f = return f { ibc_parsedSpan = Just fc }
234ibc i (IBCParsedRegion fc) f = return f { ibc_parsedSpan = Just fc }
233ibc i (IBCModDocs n) f = case lookupCtxtExact n (idris_moduledocs i) of
235ibc i (IBCModDocs n) f = case lookupCtxtExact n (idris_moduledocs i) of
@@ -290,6 +292,7 @@ process reexp i fn
290 pFunctionErrorHandlers $ force (ibc_function_errorhandlers i)
292 pFunctionErrorHandlers $ force (ibc_function_errorhandlers i)
291 pMetavars $ force (ibc_metavars i)
293 pMetavars $ force (ibc_metavars i)
292 pPostulates $ force (ibc_postulates i)
294 pPostulates $ force (ibc_postulates i)
295+ pExterns $ force (ibc_externs i)
293 pParsedSpan $ force (ibc_parsedSpan i)
296 pParsedSpan $ force (ibc_parsedSpan i)
294 pUsage $ force (ibc_usage i)
297 pUsage $ force (ibc_usage i)
295 pExports $ force (ibc_exports i)
298 pExports $ force (ibc_exports i)
@@ -306,6 +309,11 @@ pPostulates ns = do
306 i <- getIState
309 i <- getIState
307 putIState i{ idris_postulates = idris_postulates i `S.union` S.fromList ns }
310 putIState i{ idris_postulates = idris_postulates i `S.union` S.fromList ns }
308
311
312+pExterns :: [(Name, Int)] -> Idris ()
313+pExterns ns = do
314+ i <- getIState
315+ putIState i{ idris_externs = idris_externs i `S.union` S.fromList ns }
316+
309pParsedSpan :: Maybe FC -> Idris ()
317pParsedSpan :: Maybe FC -> Idris ()
310pParsedSpan fc = do ist <- getIState
318pParsedSpan fc = do ist <- getIState
311 putIState ist { idris_parsedSpan = fc }
319 putIState ist { idris_parsedSpan = fc }
@@ -934,7 +942,7 @@ instance Binary MetaInformation where
934 _ -> error "Corrupted binary data for MetaInformation"
942 _ -> error "Corrupted binary data for MetaInformation"
935
943
936instance Binary IBCFile where
944instance Binary IBCFile where
937− put x@(IBCFile x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43)
945+ put x@(IBCFile x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43 x44)
938 = {-# SCC "putIBCFile" #-}
946 = {-# SCC "putIBCFile" #-}
939 do put x1
947 do put x1
940 put x2
948 put x2
@@ -979,6 +987,7 @@ instance Binary IBCFile where
979 put x41
987 put x41
980 put x42
988 put x42
981 put x43
989 put x43
990+ put x44
982
991
983 get
992 get
984 = do x1 <- get
993 = do x1 <- get
@@ -1025,7 +1034,8 @@ instance Binary IBCFile where
1025 x41 <- get
1034 x41 <- get
1026 x42 <- get
1035 x42 <- get
1027 x43 <- get
1036 x43 <- get
1037+ x44 <- get
1028− return (IBCFile x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43)
1038+ return (IBCFile x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42 x43 x44)
1029 else return (initIBC { ver = x1 })
1039 else return (initIBC { ver = x1 })
1030
1040
1031instance Binary DataOpt where
1041instance Binary DataOpt where
@@ -1271,7 +1281,7 @@ instance (Binary t) => Binary (PDecl' t) where
1271 PMutual x1 x2 -> do putWord8 11
1281 PMutual x1 x2 -> do putWord8 11
1272 put x1
1282 put x1
1273 put x2
1283 put x2
1274− PPostulate x1 x2 x3 x4 x5 x6
1284+ PPostulate x1 x2 x3 x4 x5 x6 x7
1275 -> do putWord8 12
1285 -> do putWord8 12
1276 put x1
1286 put x1
1277 put x2
1287 put x2
@@ -1279,6 +1289,7 @@ instance (Binary t) => Binary (PDecl' t) where
1279 put x4
1289 put x4
1280 put x5
1290 put x5
1281 put x6
1291 put x6
1292+ put x7
1282 PSyntax x1 x2 -> do putWord8 13
1293 PSyntax x1 x2 -> do putWord8 13
1283 put x1
1294 put x1
1284 put x2
1295 put x2
@@ -1376,7 +1387,8 @@ instance (Binary t) => Binary (PDecl' t) where
1376 x4 <- get
1387 x4 <- get
1377 x5 <- get
1388 x5 <- get
1378 x6 <- get
1389 x6 <- get
1390+ x7 <- get
1379− return (PPostulate x1 x2 x3 x4 x5 x6)
1391+ return (PPostulate x1 x2 x3 x4 x5 x6 x7)
1380 13 -> do x1 <- get
1392 13 -> do x1 <- get
1381 x2 <- get
1393 x2 <- get
1382 return (PSyntax x1 x2)
1394 return (PSyntax x1 x2)
src/Idris/ParseExpr.hs+2−7
@@ -1158,19 +1158,14 @@ constants =
1158 , ("Char", AType (ATInt ITChar))
1158 , ("Char", AType (ATInt ITChar))
1159 , ("Double", AType ATFloat)
1159 , ("Double", AType ATFloat)
1160 , ("String", StrType)
1160 , ("String", StrType)
1161− , ("Ptr", PtrType)
1161+-- , ("Ptr", PtrType)
1162− , ("ManagedPtr", ManagedPtrType)
1162+-- , ("ManagedPtr", ManagedPtrType)
1163 , ("prim__WorldType", WorldType)
1163 , ("prim__WorldType", WorldType)
1164 , ("prim__TheWorld", TheWorld)
1164 , ("prim__TheWorld", TheWorld)
1165−-- , ("prim__UnsafeBuffer", BufferType)
1166 , ("Bits8", AType (ATInt (ITFixed IT8)))
1165 , ("Bits8", AType (ATInt (ITFixed IT8)))
1167 , ("Bits16", AType (ATInt (ITFixed IT16)))
1166 , ("Bits16", AType (ATInt (ITFixed IT16)))
1168 , ("Bits32", AType (ATInt (ITFixed IT32)))
1167 , ("Bits32", AType (ATInt (ITFixed IT32)))
1169 , ("Bits64", AType (ATInt (ITFixed IT64)))
1168 , ("Bits64", AType (ATInt (ITFixed IT64)))
1170−-- , ("Bits8x16", AType (ATInt (ITVec IT8 16)))
1171−-- , ("Bits16x8", AType (ATInt (ITVec IT16 8)))
1172−-- , ("Bits32x4", AType (ATInt (ITVec IT32 4)))
1173−-- , ("Bits64x2", AType (ATInt (ITVec IT64 2)))
1174 ]
1169 ]
1175
1170
1176constant :: IdrisParser Idris.Core.TT.Const
1171constant :: IdrisParser Idris.Core.TT.Const
src/Idris/Parser.hs+7−5
@@ -500,10 +500,11 @@ Postulate ::=
500@
500@
501-}
501-}
502postulate :: SyntaxInfo -> IdrisParser PDecl
502postulate :: SyntaxInfo -> IdrisParser PDecl
503+postulate syn = do (doc, ext)
503−postulate syn = do doc <- try $ do (doc, _) <- docstring syn
504+ <- try $ do (doc, _) <- docstring syn
504 pushIndent
505 pushIndent
505− reserved "postulate"
506+ ext <- ppostDecl
506− return doc
507+ return (doc, ext)
507 ist <- get
508 ist <- get
508 let initOpts = if default_total ist
509 let initOpts = if default_total ist
509 then [TotalFn]
510 then [TotalFn]
@@ -518,9 +519,10 @@ postulate syn = do doc <- try $ do (doc, _) <- docstring syn
518 fc <- getFC
519 fc <- getFC
519 terminator
520 terminator
520 addAcc n acc
521 addAcc n acc
521− return (PPostulate doc syn fc opts' n ty)
522+ return (PPostulate ext doc syn fc opts' n ty)
522 <?> "postulate"
523 <?> "postulate"
523−
524+ where ppostDecl = do reserved "postulate"; return False
525+ <|> do lchar '%'; reserved "extern"; return True
524{- | Parses a using declaration
526{- | Parses a using declaration
525
527
526@
528@
src/Idris/Primitives.hs+23−23
@@ -167,29 +167,29 @@ primitives =
167 Prim (sUN "prim__strRev") (ty [StrType] StrType) 1 (p_strRev)
167 Prim (sUN "prim__strRev") (ty [StrType] StrType) 1 (p_strRev)
168 (1, LStrRev) total,
168 (1, LStrRev) total,
169
169
170− Prim (sUN "prim__readFile") (ty [WorldType,PtrType] StrType) 2 (p_cantreduce)
170+-- Prim (sUN "prim__readFile") (ty [WorldType,PtrType] StrType) 2 (p_cantreduce)
171− (2, LReadFile) total, -- total is okay, because we have 'WorldType'
171+-- (2, LReadFile) total, -- total is okay, because we have 'WorldType'
172− Prim (sUN "prim__writeFile") (ty [WorldType,PtrType,StrType] (AType (ATInt ITNative))) 3 (p_cantreduce)
172+-- Prim (sUN "prim__writeFile") (ty [WorldType,PtrType,StrType] (AType (ATInt ITNative))) 3 (p_cantreduce)
173− (3, LWriteFile) total,
173+-- (3, LWriteFile) total,
174− Prim (sUN "prim__readString") (ty [WorldType] StrType) 1 (p_cantreduce)
174+-- Prim (sUN "prim__readString") (ty [WorldType] StrType) 1 (p_cantreduce)
175− (1, LReadStr) total, -- total is okay, because we have 'WorldType'
175+-- (1, LReadStr) total, -- total is okay, because we have 'WorldType'
176− Prim (sUN "prim__writeString") (ty [WorldType,StrType] (AType (ATInt ITNative))) 2 (p_cantreduce)
176+-- Prim (sUN "prim__writeString") (ty [WorldType,StrType] (AType (ATInt ITNative))) 2 (p_cantreduce)
177− (2, LWriteStr) total,
177+-- (2, LWriteStr) total,
178−
178+--
179− Prim (sUN "prim__vm") (ty [] PtrType) 0 (p_cantreduce)
179+-- Prim (sUN "prim__vm") (ty [] PtrType) 0 (p_cantreduce)
180− (0, LVMPtr) total,
180+-- (0, LVMPtr) total,
181− -- Streams
181+-- -- Streams
182− Prim (sUN "prim__stdin") (ty [] PtrType) 0 (p_cantreduce)
182+-- Prim (sUN "prim__stdin") (ty [] PtrType) 0 (p_cantreduce)
183− (0, LStdIn) total,
183+-- (0, LStdIn) total,
184− Prim (sUN "prim__stdout") (ty [] PtrType) 0 (p_cantreduce)
184+-- Prim (sUN "prim__stdout") (ty [] PtrType) 0 (p_cantreduce)
185− (0, LStdOut) total,
185+-- (0, LStdOut) total,
186− Prim (sUN "prim__stderr") (ty [] PtrType) 0 (p_cantreduce)
186+-- Prim (sUN "prim__stderr") (ty [] PtrType) 0 (p_cantreduce)
187− (0, LStdErr) total,
187+-- (0, LStdErr) total,
188− Prim (sUN "prim__null") (ty [] PtrType) 0 (p_cantreduce)
188+-- Prim (sUN "prim__null") (ty [] PtrType) 0 (p_cantreduce)
189− (0, LNullPtr) total,
189+-- (0, LNullPtr) total,
190− -- Managed pointer registration
190+-- -- Managed pointer registration
191− Prim (sUN "prim__registerPtr") (ty [PtrType, AType (ATInt ITNative)] ManagedPtrType) 2 (p_cantreduce)
191+-- Prim (sUN "prim__registerPtr") (ty [PtrType, AType (ATInt ITNative)] ManagedPtrType) 2 (p_cantreduce)
192− (2, LRegisterPtr) total,
192+-- (2, LRegisterPtr) total,
193 Prim (sUN "prim__systemInfo") (ty [AType (ATInt ITNative)] StrType) 1 (p_cantreduce)
193 Prim (sUN "prim__systemInfo") (ty [AType (ATInt ITNative)] StrType) 1 (p_cantreduce)
194 (1, LSystemInfo) total
194 (1, LSystemInfo) total
195 ] ++ concatMap intOps [ITFixed IT8, ITFixed IT16, ITFixed IT32, ITFixed IT64, ITBig, ITNative, ITChar]
195 ] ++ concatMap intOps [ITFixed IT8, ITFixed IT16, ITFixed IT32, ITFixed IT64, ITBig, ITNative, ITChar]