Login
7 branches 0 tags
Ben (Win10) Added nreverse and a faster map 08c07d7 4 years ago 268 Commits
nujel / binlib / io.nuj
[defun help [i]
       "Describe 10 functions at offset 1"
       [def off [* [int i] 10]]
       [for-each [\ [l] [println [cat l " " [describe l]]]]
                 [map cat [symbol-table off 10]]]
       [println [cat "Help page " [int i] " of " [/ [symbol-count] 10]]]
       #t
]

[defun file/compile [path no-write environment]
        "Compile a Nujel source file into optimized object code"
        [def source [cons 'do [read [file/read path]]]]
        [def object-code [compile/forms source environment]]
        [when-not no-write [file/write [cat [path/without-extension path] ".no"] [str/write object-code]]]
        object-code
]

[defun file/eval [path environment]
       "Evaluate a Nujel source file in the current context"
       [when-not environmnet [set! environment root-closure]]
       [def source [cons 'do [read [file/read path]]]]
       [compile/forms [cons 'do source] environment]
]

[defun eval/forked [nujel-binary raw-expr]
        "Evaluate @EXPR in a separate process running NUJEL-BINARY"
        [def expr [cat "[print [str/write " [str/write raw-expr]] "]] "]
        [def tmp-path [file/temp expr]]

        [def command [cat nujel-binary " " tmp-path]]
        [def res [popen command]]
        [file/remove tmp-path]
        [cons [car res] [cdr res]]
]
[def test-context "Nujel Standalone"]