Login
7 branches 0 tags
Ben (Win10) Fixed msys2/clang64 4f7d498 4 years ago 201 Commits
nujel / binlib / io.nuj
[def help [let*
        [defun iter [l]
                [cond [[nil? l] #t]
                      [#t [display [describe [car l]]] [newline] [iter [cdr l]]
                ]]
        ]

        [λ [i]
                "Describe 10 functions at offset 1"
                [def off [* [int i] 10]]
                [iter [map cat [symbol-table off 10]]]
                [display [cat "Help page " [int i] " of " [/ [symbol-count] 10]]]
                [newline]
                #t
        ]
]]

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

[defun file/eval [path]
        "Evaluate a Nujel source file in the current context"
        [def source [cons 'do [read [file/read path]]]]
        [apply root-closure [cons [compile [cons 'do source]]]]
]

[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"]