eval: add eval primitive

This commit is contained in:
hellerve 2020-03-09 15:50:52 +01:00
parent da32c14197
commit ca5cc8abeb
2 changed files with 11 additions and 2 deletions

View File

@ -98,7 +98,7 @@
(list 'build)
(list 'run)))
(defmacro eval [form]
(defmacro evaluate [form]
(eval-internal form))
(defmacro e [form]
@ -119,7 +119,7 @@
(defndynamic collect-into [xs f]
(list 'quote
(collect-into-internal xs (f) f)))
)
)
(defndynamic cond-internal [xs]
(if (= (length xs) 0)

View File

@ -839,6 +839,14 @@ primitiveDefdynamic _ _ [notName, body] = do
ctx <- get
return (evalError ctx ("`defndynamic` expected a name as first argument, but got " ++ pretty notName) (info notName))
primitiveEval :: Primitive
primitiveEval _ env [val] = do
-- primitives dont evaluate their arguments, so this needs to double-evaluate
arg <- eval env val
case arg of
Left err -> return (Left err)
Right ok -> eval env ok
primitives :: Map.Map SymPath Primitive
primitives = Map.fromList
[ makePrim "quote" 1 "(quote x) ; where x is an actual symbol" (\_ _ [x] -> return (Right x))
@ -858,4 +866,5 @@ primitives = Map.fromList
, makeVarPrim "register" "(register name <signature> <optional: override>)" primitiveRegister
, makeVarPrim "deftype" "(deftype name <members>)" primitiveDeftype
, makePrim "use" 1 "(use MyModule)" primitiveUse
, makePrim "eval" 1 "(evaluate mycode)" primitiveEval
]