(optimize compiled-statements) -> statement
Optimize is the second (optional, but highly recommended) step when converting human-readable code to machine-readable code. It is preceded by compile, and followed by assemble.
The example follows what was begun in compile.
>> (define testprog (read-lisp-file "lib/mosc.ms")) :: ((import "lib/compile") (import "lib/optimize") (define (...) (...) (...) (...) (...) (...)) (export mosc)) >> (set! testprog (compile testprog)) :: #f >> (optimize testprog) :: ((usen 0 0) (ldc "lib/lib") (ldc 1) (ldg import) (call) (drop) (ldc "lib/compile") (ldc 1) (ldg import) (call) (drop) (ldc "lib/assemble") (ldc 1) (ldg import) (call) (drop) (ldc "lib/optimize") (ldc 1) (ldg import) (call) (drop) (ldc "lib/freeze") (ldc 1) (ldg import) (call) (drop) (ldf lambda-6) (stg mosc) (ldu) (retn) lambda-6 (usen 1 4) (ldc #f) (stb 0 1) (ldc #f) (stb 0 2) (ldb 0 0) (ldc ".ms") (ldc 2) (ldg string-ends-with?) (call) (jf false-8) (ldb 0 0) (stb 0 1) (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-7) false-8 (ldb 0 0) (ldc ".scm") (ldc 2) (ldg string-ends-with?) (call) (jf false-10) (ldb 0 0) (stb 0 1) (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-9) false-10 (ldb 0 0) (ldc ".ms") (ldc 2) (ldg string-append) (call) (stb 0 1) (ldu) done-9 done-7 (drop) (ldb 0 0) (ldc ".mo") (ldc 2) (ldg string-append) (call) (stb 0 2) (ldb 0 1) (ldc 1) (ldg read-lisp-file) (call) (stb 0 3) (ldb 0 3) (ldc 1) (ldg compile) (call) (stb 0 3) (ldb 0 3) (ldc 1) (ldg optimize) (call) (stb 0 3) (ldb 0 3) (ldc 1) (ldg assemble) (call) (stb 0 3) (ldb 0 3) (ldc 1) (ldg freeze) (call) (stb 0 3) (ldb 0 2) (ldc 1) (ldg open-output-file) (call) (stb 0 2) (ldb 0 3) (ldb 0 2) (ldc 2) (ldg write-data) (call) (drop) (ldb 0 2) (ldc 1) (ldg close-output-port) >(tail))