Compile

(compile statement) -> statement

Compile is the first step when converting statements from human-readable form to machine-readable form. It is normally followed by optimize, and then by assemble.

For our example, we will use the file "mosc.ms", which you may find in the "lib" subdirectory that came with your MOSVM package. This same file is used with optimize and assemble.

>> (define testprog (read-lisp-file "lib/mosc.ms"))
:: ((import "lib/compile") (import "lib/optimize") (define (...) (...) (...) (...)
(...) (...)) (export mosc))
>> (compile testprog)
:: ((usen 0 0) (ldu) (drop) (ldc "lib/lib") (ldc 1) (ldg import) (call) (drop)
(ldc "lib/compile") (ldc 1) (ldg import) (call) (drop) (ldc "lib/assemble") (ldc1)
(ldg import) (call) (drop) (ldc "lib/optimize") (ldc 1) (ldg import) (call) (drop)
(ldc "lib/freeze") (ldc 1) (ldg import) (call) (drop) (ldf lambda-1) (stgmosc)
(ldu) (retn) lambda-1 (usen 1 4) (ldu) (drop) (ldc #f) (stb 0 1) (ldu) (drop) (ldc #f)
(stb 0 2) (ldu) (drop) (ldb 0 0) (ldc ".ms") (ldc 2) (ldg string-ends-with?) (call)
(jf false-3) (ldu) (drop) (ldb 0 0) (stb 0 1) (ldu) (drop) (ldb 0 0) (ldb 0 0) (ldc 1)
(ldg string-length) (call) (ldc 3) (ldc 2) (ldg -) (call) (ldc 2) (ldg string-head)
(call) (stb 0 0) (ldu) (jmp done-2) false-3 (ldb 0 0) (ldc ".scm") (ldc 2)
(ldg string-ends-with?) (call) (jf false-5) (ldu) (drop)(ldb 0 0) (stb 0 1) (ldu)
(drop) (ldb 0 0) (ldb 0 0) (ldc 1) (ldg string-length) (call) (ldc 4) (ldc 2)
(ldg -) (call) (ldc 2) (ldg string-head) (call) (stb 0 0) (ldu) (jmp done-4)
false-5 (ldu) (drop) (ldb 0 0) (ldc ".ms") (ldc 2) (ldg string-append) (call)
(stb 0 1) (ldu) done-4 done-2 (drop) (ldb 0 0) (ldc ".mo") (ldc 2) (ldg string-append)
(call) (stb 0 2) (ldu) (drop) (ldb 0 1) (ldc 1) (ldg read-lisp-file) (call) (stb 0 3)
(ldu) (drop) (ldb 0 3) (ldc 1) (ldg compile) (call) (stb 0 3) (ldu) (drop) (ldb 0 3)
(ldc 1) (ldg optimize) (call) (stb 0 3) (ldu) (drop) (ldb 0 3) (ldc 1) (ldg assemble)
(call) (stb 0 3) (ldu) (drop) (ldb 03) (ldc 1) (ldg freeze) (call) (stb 0 3) (ldu)
(drop) (ldb 0 2) (ldc 1) (ldg open-output-file) (call) (stb 0 2) (ldu) (drop) (ldb 0 3)
(ldb 0 2) (ldc 2) (ldg write-data) (call) (drop) (ldb 0 2) (ldc 1) (ldg close-output-port)
(call) (retn))
>>