-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rkt
40 lines (34 loc) · 1.47 KB
/
main.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#lang racket
(require "lexer.rkt")
(require "compiler.rkt")
(define (time thunk)
(define start (current-inexact-milliseconds))
(define result (thunk))
(values result (- (current-inexact-milliseconds) start)))
(define (pipeline ast)
(lower-op-assign
(parse-L1 ast)))
(define (compile fname)
(define-values (cst cst-time)
(call-with-input-file fname
(lambda (ip)
(define-values (tokens token-time) (time (lambda () (tokenizer-thunk ip))))
(printf "tokenization time: ~a milliseconds ~n" token-time)
(time (lambda () (parse tokens))))))
(printf "cst parse time: ~a milliseconds ~n" cst-time)
(define-values (ast ast-time) (time (lambda () (new-cst->ast cst))))
(printf "cst -> ast took: ~a milliseconds ~n" ast-time)
(define-values (lua-ast pipeline-time) (time (lambda () (pipeline ast))))
(printf "hl-ast -> lua ast took: ~a milliseconds ~n" pipeline-time)
(define-values (lua-code lua-time) (time (lambda () (generate-code lua-ast))))
(printf "codegen took: ~a milliseconds ~n" lua-time)
lua-code)
(define (compile-path path show?)
(printf "compiling: ~a ~n" path)
(define-values (example-code example-time) (time (lambda () (compile path))))
(printf "total time: ~a milliseconds to compile ~n ~n" example-time)
(when show? (printf "~a~n" example-code)))
(compile-path "examples/timecop.lua" #f)
(compile-path "examples/escapes.lua" #t)
(compile-path "examples/multilinecomments.lua" #t)
(compile-path "examples/test.lua" #t)