feat: add expand-compiled (#1310)

This commit is contained in:
Veit Heller 2021-09-17 05:57:50 +02:00 committed by GitHub
parent 5a449b0919
commit e307654521
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -986,6 +986,18 @@ commandC ctx xobj = do
liftIO (putStr c)
pure (newCtx, dynamicNil)
-- | This function will return the compiled AST.
commandExpandCompiled :: UnaryCommandCallback
commandExpandCompiled ctx xobj = do
(newCtx, result) <- expandAll (evalDynamic ResolveLocal) ctx xobj
case result of
Left err -> pure (newCtx, Left err)
Right expanded -> do
(_, annotated) <- annotateWithinContext newCtx expanded
case annotated of
Left err -> pure $ evalError newCtx (show err) (xobjInfo xobj)
Right (annXObj, _) -> pure (newCtx, Right annXObj)
-- | Helper function for commandC
printC :: XObj -> String
printC xobj =

View File

@ -256,6 +256,7 @@ dynamicModule =
f "not" commandNot "negates its boolean argument." "(not false) ; => true",
f "c" commandC "prints the C code emitted for a binding." "(c '(+ 2 3)) ; => int _3 = Int__PLUS_(2, 3);",
f "expand" commandExpand "expands a macro and prints the result." "(expand '(when true 1)) ; => (if true 1 ())",
f "expand-compiled" commandExpandCompiled "expands and desugars the code." "(expand-compiled '(+ 2 3)) ; => (Int.+ 2 3)",
f "system-include" commandAddSystemInclude "adds a system include, i.e. a C `#include` with angle brackets (`<>`)." "(system-include \"stdint.h\")",
f "relative-include" commandAddRelativeInclude "adds a relative include, i.e. a C `include` with quotes. It also prepends the current directory." "(relative-include \"myheader.h\")",
f "read-file" commandReadFile "reads a file into a string." "(read-file \"myfile.txt\")",