Update readme and work on SCM to C translator
This commit is contained in:
@@ -82,53 +82,58 @@
|
||||
; 3628800
|
||||
; #magic
|
||||
|
||||
(display "\nex-5.51\n")
|
||||
(display "\nex-5.51 - Scheme Interpreter in Rust\n")
|
||||
|
||||
; I have implemented a crude Scheme interpreter in Rust:
|
||||
; https://git.felixm.de/felixm/schemers
|
||||
|
||||
(display "[ok]\n")
|
||||
|
||||
(display "\nex-5.52\n")
|
||||
(display "\nex-5.52 - Scheme to C Translator\n")
|
||||
|
||||
(load "shared/scm2c-compiler")
|
||||
(load "shared/scm2c/translator")
|
||||
|
||||
; My goal is to compile to C. Not to compile the metacircular evaluator.
|
||||
; My goal is to create proof of concept. Not to compile the metacircular
|
||||
; evaluator.
|
||||
|
||||
(define c-preamble '(
|
||||
"#include <stdio.h>"
|
||||
"#include \"scm_support.h\""
|
||||
""
|
||||
"int main() {"
|
||||
" int val;"
|
||||
" int *argl;"
|
||||
" void *cont, *entry, *proc, *env;"
|
||||
""
|
||||
))
|
||||
|
||||
(define c-epilog '(
|
||||
" printf(\"%u\\n\", val);"
|
||||
"}"
|
||||
))
|
||||
|
||||
(define (compile-to-file code)
|
||||
(define (compile-to-file file-name code)
|
||||
(define (write-list-to-line xs port)
|
||||
(cond
|
||||
((null? xs) '())
|
||||
((pair? xs) (display (car xs) port)
|
||||
(write-list-to-line (cdr xs) port))
|
||||
(else (display xs port))))
|
||||
|
||||
(define (write-list-to-port xs port)
|
||||
(if (null? xs) '()
|
||||
(begin (write-list-to-line (car xs) port)
|
||||
(display "\n" port)
|
||||
(write-list-to-port (cdr xs) port))))
|
||||
(let ((port (open-output-file "main.c"))
|
||||
(let ((port (open-output-file file-name))
|
||||
(stmts (statements (compile code 'val 'next))))
|
||||
(write-list-to-port c-preamble port)
|
||||
(write-list-to-port stmts port)
|
||||
(write-list-to-port c-epilog port)
|
||||
(display "[cc ") (display file-name)
|
||||
(display "]") (newline)
|
||||
(close-output-port port)))
|
||||
|
||||
(compile-to-file '(+ 1 1))
|
||||
(compile-to-file "shared/scm2c/main.c" '(+ 1 1))
|
||||
|
||||
; write assembly to file for debug purposes
|
||||
|
||||
|
||||
Reference in New Issue
Block a user