application/octet-stream
•
1.64 KB
•
41 lines
; Nujel - Copyright (C) 2020-2021 - Benjamin Vincent Schulenburg
; This project uses the MIT license, a copy should be included under /LICENSE
[defun help [i]
"Describe 10 functions at offset 1"
[def off [* [int i] 10]]
[for-each [map [symbol-table off 10] cat]
[\ [l] [println [cat l " " [describe l]]]]]
[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"]
[if object-code [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"]
[defun file/file? [filename]
[[file/stat filename] :regular-file?]]
[defun file/dir? [filename]
[[file/stat filename] :directory?]]