Skip to content

Instantly share code, notes, and snippets.

@ympbyc
Created April 15, 2017 09:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ympbyc/56b50762520bd8ca875911ee7d713993 to your computer and use it in GitHub Desktop.
Save ympbyc/56b50762520bd8ca875911ee7d713993 to your computer and use it in GitHub Desktop.
rough sketch
(use srfi-1)
(define (mlf-symbol sym)
(string->symbol (string-append "$" (symbol->string sym))))
(define (compile expr)
(cond
[(number? expr) expr]
[(string? expr) (string-append "\"" expr "\"")]
[(symbol? expr) (mlf-symbol expr)]
[(eq? (car expr) 'quote) (cadr expr)]
[(eq? (car expr) '^)
(list 'lambda
(map mlf-symbol (drop-right (cdr expr) 1))
(compile (last expr)))]
[#t (append (list 'apply
(compile (car expr)))
(map compile (cdr expr)))]))
(define (main args)
(print
(list 'module
(list '_ (list 'apply '(global $Pervasives $print_string) (compile (read))))
'(export))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment