Login
7 branches 0 tags
Ben (Win10) Some compiler fixes 3ff3a21 3 years ago 563 Commits
nujel / bootstrap / binlib.no
[do [def test-context "Nujel Bootstrap"] [def help [fn* help [i] "Describe 10 functions at offset 1" #{
10s i
08i 1 v int?
0Bo 7
24
09o 16
10s i
08i 1 v int
0Fs i
0D
10s off
02i 10
08i 2 v symbol-table
10s string
08i 2 v map
25v anonymous v [l] v "" v #{
10s l
08i 1 v describe
0Es desc
0D
10s l
05v " "
10s desc
08i 3 v cat
08i 1 v println
01
}
08i 2 v for-each
0D
08i 0 v symbol-count
02i 10
08i 2 v /
0Es sc
0D
05v "Help page "
10s i
05v " of "
10s sc
08i 4 v cat
08i 1 v println
01
}]] [def file/compile [fn* file/compile [path no-write environment] "Compile a Nujel source file into optimized object code" #{
23s do
10s path
08i 1 v file/read
08i 1 v read
08i 2 v cons
0Es source
0D
10s source
10s environment
08i 2 v compile/forms
0Es object-code
0D
10s no-write
0Bo 7
24
09o 49
10s object-code
0Bo 15
10s object-code
08i 1 v str/write
09o 7
05v ""
10s path
08i 1 v path/without-extension
05v ".no"
08i 2 v cat
08i 2 v file/write
0D
10s object-code
01
}]] [def file/eval [fn* file/eval [path environment] "Evaluate a Nujel source file in the current context" #{
10s environment
0Bo 7
24
09o 11
10s root-closure
0Fs environment
0D
23s do
10s path
08i 1 v file/read
08i 1 v read
08i 2 v cons
0Es source
0D
10s source
10s environment
08i 2 v compile/forms
01
}]] [def file/eval/bytecode [fn* file/eval/bytecode [path] "Evaluate a Nujel source file in the current context" #{
23s do
10s path
08i 1 v file/read
08i 1 v read
08i 2 v cons
0Es source
0D
10s source
08i 1 v compile
08i 1 v bytecompile
08i 1 v assemble
0Es bc
0D
10s disassemble/raw
10s bc
1Ai 1
0D
10s bc
08i 1 v bytecode-eval
01
}]] [def eval/forked [fn* eval/forked [nujel-binary raw-expr] "Evaluate @EXPR in a separate process running NUJEL-BINARY" #{
05v "[print [str/write "
10s raw-expr
08i 1 v str/write
08i 2 v cat
0Es expr
0D
10s expr
08i 1 v file/temp
0Es tmp-path
0D
10s nujel-binary
05v " "
10s tmp-path
08i 3 v cat
0Es command
0D
10s command
08i 1 v popen
0Es res
0D
10s tmp-path
08i 1 v file/remove
0D
10s res
08i 1 v car
10s res
08i 1 v cdr
08i 2 v cons
01
}]] [def file/file? [fn* file/file? [filename] "" #{
10s filename
08i 1 v file/stat
05v :regular-file?
08i 2 v ref
01
}]] [def file/dir? [fn* file/dir? [filename] "" #{
10s filename
08i 1 v file/stat
05v :directory?
08i 2 v ref
01
}]] [def directory/read-relative [fn* directory/read-relative [path] "" #{
10s path
08i 1 v directory/read
25v anonymous v [a] v "" v #{
10s path
05v "/"
10s a
08i 3 v cat
01
}
08i 2 v map
01
}]] [def directory/read-recursive [fn* directory/read-recursive [path] "" #{
10s path
08i 1 v directory/read-relative
25v anonymous v [A] v "" v #{
10s A
08i 1 v file/dir?
0Bo 15
10s A
08i 1 v directory/read-recursive
09o 7
10s A
01
}
08i 2 v map
08i 1 v flatten
01
}]]][do [def repl/executable-name "nujel"] [def repl/parse-args/bytecode-eval-n #f] [def repl/parse-args/eval-next #f] [def repl/parse-args/run-repl #t] [def repl/options [tree/new #nil]] [def repl/option-map [tree/new #nil]] [def repl/exception-handler [fn* repl/exception-handler [error] "" #{
10s error
08i 1 v display/error
01
}]] [def repl/history #nil] [def repl/prompt [fn* repl/prompt [] "> " #{
05v "> "
01
}]] [def repl/wasm [fn* repl/wasm [line] "Evaluate LINE in the wasm context" #{
10s repl/exception-handler
18o 61
10s line
08i 1 v read
0Es raw
0D
23s do
10s raw
08i 2 v cons
08i 1 v compile
08i 1 v list
0Es cexpr
0D
10s root-closure
10s cexpr
08i 2 v apply
09o 8
1Ai 1
09o 5
27
0D
01
}]] [def repl/readline [fn* repl/readline [ctx] "" #{
08i 0 v repl/prompt
08i 1 v readline
0Es line
0D
10s line
08i 1 v nil?
0Bo 23
05v "Bye!\r\n"
08i 1 v display
0D
02i 0
08i 1 v exit
09o 4
24
0D
10s line
08i 1 v read
0Es raw
0D
23s do
10s raw
08i 2 v cons
0Es expr
0D
10s expr
08i 1 v compile
08i 1 v cons
0Es cexpr
0D
10s ctx
10s cexpr
08i 2 v apply
0Es result
0D
10s line
10s repl/history
08i 2 v cons
0Fs repl/history
0D
10s result
08i 1 v nil?
0Bo 10
05v ""
09o 12
10s result
08i 1 v str/write
08i 1 v cat
08i 1 v println
01
}]] [def repl [fn* repl [] "" #{
02i 0
1B
1C
05v #t
0Bo 33
0D
10s repl/exception-handler
18o 15
10s root-closure
08i 1 v repl/readline
09o 8
1Ai 1
09o 5
27
0D
09o -35
01
}]] [def repl/print-help [fn* repl/print-help [] "" #{
05v "Nujel"
08i 1 v ansi-rainbow
05v " - A Lisp dialect for games.\n"
08i 2 v cat
08i 1 v println
0D
05v "Usage:"
08i 1 v ansi-green
05v " nujel [options] [command_string | file]"
08i 2 v cat
08i 1 v println
0D
05v "\nLow-level options - for work on the runtime itself"
08i 1 v cat
08i 1 v println
0D
05v "  "
05v "n"
08i 1 v ansi-yellow
05v " - do not load the standard library"
08i 3 v cat
08i 1 v println
0D
05v "  "
05v "v"
08i 1 v ansi-yellow
05v " - be verbose"
08i 3 v cat
08i 1 v println
0D
05v "  "
05v "r"
08i 1 v ansi-yellow
05v " - eval following file without compilation/expansion"
08i 3 v cat
08i 1 v println
0D
05v "\nHigh-level options - for working with/on Nujel code"
08i 1 v cat
08i 1 v println
0D
05v "  "
05v "b"
08i 1 v ansi-blue
05v " - eval following file using the bytecode interpreter"
08i 3 v cat
08i 1 v println
0D
05v "  "
05v "x"
08i 1 v ansi-blue
05v " - Run the expression following this argument directly"
08i 3 v cat
08i 1 v println
0D
05v "  "
05v "h"
08i 1 v ansi-blue
05v " - Print this help screen"
08i 3 v cat
08i 1 v println
0D
05v "\nLong options - for working with/on Nujel code"
08i 1 v cat
08i 1 v println
0D
05v "  "
05v "no-color"
08i 1 v ansi-blue
05v " - Disable ANSI color"
08i 3 v cat
08i 1 v println
0D
05v "  "
05v "color   "
08i 1 v ansi-blue
05v " - Enable ANSI color"
08i 3 v cat
08i 1 v println
01
}]] [def repl/run-forked* [fn* repl/run-forked* [expr] "" #{
10s repl/executable-name
05v " -x \""
10s expr
08i 1 v str/write
05v "\""
08i 4 v cat
0Es command
0D
10s command
08i 1 v popen
01
}]] [def repl/run-forked [macro* repl/run-forked [expr] "" #{
23s repl/run-forked*
23s quote
10s expr
08i 2 v list
24
08i 2 v cons
08i 2 v cons
01
}]] [tree/set! repl/option-map 'b [fn* anonymous [option] "" #{
05v #t
0Fs repl/parse-args/bytecode-eval-n
0D
05v #f
0Fs repl/parse-args/run-repl
01
}]] [tree/set! repl/option-map 'h [fn* anonymous [option] "" #{
08i 0 v repl/print-help
0D
05v #f
0Fs repl/parse-args/run-repl
01
}]] [tree/set! repl/option-map 'no-color [fn* anonymous [option] "" #{
05v ""
0Fs ansi/disabled
01
}]] [tree/set! repl/option-map 'color [fn* anonymous [option] "" #{
05v #f
0Fs ansi/disabled
01
}]] [tree/set! repl/option-map 'x [fn* anonymous [option] "" #{
05v #t
0Fs repl/parse-args/eval-next
0D
05v #f
0Fs repl/parse-args/run-repl
01
}]] [tree/set! repl/option-map :default [fn* anonymous [option] "" #{
10s repl/options
10s option
05v #t
08i 3 v tree/set!
01
}]] [def repl/parse-option [fn* repl/parse-option [option] "" #{
10s repl/option-map
10s option
08i 2 v ref
0C
0Ao 26
0D
10s repl/option-map
05v :default
08i 2 v ref
0C
0Ao 8
0D
05v #f
10s option
1Ai 1
01
}]] [def repl/parse-options [fn* repl/parse-options [options] "" #{
10s options
02i 0
08i 2 v char-at
02i 45
20
0Bo 27
10s options
02i 1
08i 2 v cut
08i 1 v string->keyword
08i 1 v repl/parse-option
09o 34
10s options
05v ""
08i 2 v split
10s str->sym
08i 2 v map
10s repl/parse-option
08i 2 v for-each
01
}]] [def repl/parse-arg [fn* repl/parse-arg [arg] "" #{
10s repl/parse-args/bytecode-eval-n
0Bo 41
10s display/error
18o 15
10s arg
08i 1 v file/eval/bytecode
09o 8
1Ai 1
09o 5
27
0D
0D
05v #f
0Fs repl/parse-args/bytecode-eval-n
09o 158
10s repl/parse-args/eval-next
0Bo 69
10s display/error
18o 43
10s root-closure
23s do
10s arg
08i 1 v read
08i 2 v cons
08i 1 v compile
08i 1 v cons
08i 2 v apply
09o 8
1Ai 1
09o 5
27
0D
0D
05v #f
0Fs repl/parse-args/eval-next
09o 85
10s arg
02i 0
08i 2 v char-at
02i 45
20
0Bo 22
10s arg
02i 1
08i 2 v string/cut
08i 1 v repl/parse-options
09o 49
05v #t
0Bo 41
10s display/error
18o 15
10s arg
08i 1 v file/eval
09o 8
1Ai 1
09o 5
27
0D
0D
05v #f
0Fs repl/parse-args/run-repl
09o 4
24
01
}]] [def repl/parse-args [fn* repl/parse-args [args] "" #{
10s args
0Bo 35
10s args
08i 1 v car
08i 1 v repl/parse-arg
0D
10s args
08i 1 v cdr
08i 1 v repl/parse-args
09o 7
10s repl/parse-args/run-repl
01
}]] [def repl/init/wasm [fn* repl/init/wasm [args] "" #{
05v "Nujel"
08i 1 v ansi-rainbow
05v " heißt euch willkommen!"
08i 2 v cat
08i 1 v println
01
}]] [def repl/init/bin [fn* repl/init/bin [args] "" #{
10s repl/exception-handler
18o 46
10s args
08i 1 v car
0Fs repl/executable-name
0D
10s args
08i 1 v cdr
08i 1 v repl/parse-args
0Bo 11
08i 0 v repl
09o 4
24
09o 8
1Ai 1
09o 5
27
0D
01
}]] [def repl/init [fn* repl/init args "" #{
10s System/Architecture
23s wasm
20
0Bo 15
10s args
08i 1 v repl/init/wasm
09o 12
10s args
08i 1 v repl/init/bin
01
}]]]