mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-24 20:45:06 +02:00
Less verbose CPS debug printing
This commit is contained in:
parent
df0f325c00
commit
e705824a6d
2 changed files with 40 additions and 4 deletions
|
@ -405,23 +405,23 @@
|
||||||
;; No need for call/cc yet
|
;; No need for call/cc yet
|
||||||
(set! input-program cps))))
|
(set! input-program cps))))
|
||||||
(trace:info "---------------- after CPS:")
|
(trace:info "---------------- after CPS:")
|
||||||
(trace:info input-program) ;pretty-print
|
(trace:info (ast:ast->pp-sexp input-program))
|
||||||
|
|
||||||
(when (> *optimization-level* 0)
|
(when (> *optimization-level* 0)
|
||||||
(set! input-program
|
(set! input-program
|
||||||
(optimize-cps input-program))
|
(optimize-cps input-program))
|
||||||
(trace:info "---------------- after cps optimizations (1):")
|
(trace:info "---------------- after cps optimizations (1):")
|
||||||
(trace:info input-program)
|
(trace:info (ast:ast->pp-sexp input-program))
|
||||||
|
|
||||||
(set! input-program
|
(set! input-program
|
||||||
(optimize-cps input-program))
|
(optimize-cps input-program))
|
||||||
(trace:info "---------------- after cps optimizations (2):")
|
(trace:info "---------------- after cps optimizations (2):")
|
||||||
(trace:info input-program)
|
(trace:info (ast:ast->pp-sexp input-program))
|
||||||
|
|
||||||
(set! input-program
|
(set! input-program
|
||||||
(optimize-cps input-program))
|
(optimize-cps input-program))
|
||||||
(trace:info "---------------- after cps optimizations (3):")
|
(trace:info "---------------- after cps optimizations (3):")
|
||||||
(trace:info input-program)
|
(trace:info (ast:ast->pp-sexp input-program))
|
||||||
)
|
)
|
||||||
|
|
||||||
(set! input-program
|
(set! input-program
|
||||||
|
|
|
@ -24,12 +24,15 @@
|
||||||
ast:lambda-has-cont
|
ast:lambda-has-cont
|
||||||
ast:set-lambda-has-cont!
|
ast:set-lambda-has-cont!
|
||||||
ast:get-next-lambda-id!
|
ast:get-next-lambda-id!
|
||||||
|
ast:ast->pp-sexp
|
||||||
)
|
)
|
||||||
(begin
|
(begin
|
||||||
(define *lambda-id* 0)
|
(define *lambda-id* 0)
|
||||||
|
|
||||||
(define (ast:get-next-lambda-id!)
|
(define (ast:get-next-lambda-id!)
|
||||||
(set! *lambda-id* (+ 1 *lambda-id*))
|
(set! *lambda-id* (+ 1 *lambda-id*))
|
||||||
*lambda-id*)
|
*lambda-id*)
|
||||||
|
|
||||||
(define-record-type <lambda-ast>
|
(define-record-type <lambda-ast>
|
||||||
(ast:%make-lambda id args body has-cont)
|
(ast:%make-lambda id args body has-cont)
|
||||||
ast:lambda?
|
ast:lambda?
|
||||||
|
@ -38,8 +41,41 @@
|
||||||
(body ast:lambda-body ast:set-lambda-body!)
|
(body ast:lambda-body ast:set-lambda-body!)
|
||||||
(has-cont ast:lambda-has-cont ast:set-lambda-has-cont!)
|
(has-cont ast:lambda-has-cont ast:set-lambda-has-cont!)
|
||||||
)
|
)
|
||||||
|
|
||||||
(define (ast:make-lambda args body . opts)
|
(define (ast:make-lambda args body . opts)
|
||||||
(let ((has-cont (if (pair? opts) (car opts) #f)))
|
(let ((has-cont (if (pair? opts) (car opts) #f)))
|
||||||
(set! *lambda-id* (+ 1 *lambda-id*))
|
(set! *lambda-id* (+ 1 *lambda-id*))
|
||||||
(ast:%make-lambda *lambda-id* args body has-cont)))
|
(ast:%make-lambda *lambda-id* args body has-cont)))
|
||||||
|
|
||||||
|
;; Transform a SEXP in AST form to one that prints more cleanly
|
||||||
|
(define (ast:ast->pp-sexp exp)
|
||||||
|
(cond
|
||||||
|
((ast:lambda? exp)
|
||||||
|
(let* ((id (ast:lambda-id exp))
|
||||||
|
(has-cont (ast:lambda-has-cont exp))
|
||||||
|
(sym (string->symbol
|
||||||
|
(string-append
|
||||||
|
"lambda-"
|
||||||
|
(number->string id)
|
||||||
|
(if has-cont "-cont" ""))))
|
||||||
|
)
|
||||||
|
`(,sym ,(ast:lambda-args exp)
|
||||||
|
,@(map ast:ast->pp-sexp (ast:lambda-body exp))))
|
||||||
|
)
|
||||||
|
((quote? exp) exp)
|
||||||
|
((const? exp) exp)
|
||||||
|
((ref? exp) exp)
|
||||||
|
((define? exp)
|
||||||
|
`(define ,(define->var exp)
|
||||||
|
,@(ast:ast->pp-sexp (define->exp exp))))
|
||||||
|
((set!? exp)
|
||||||
|
`(set! ,(set!->var exp)
|
||||||
|
,(ast:ast->pp-sexp (set!->exp exp))))
|
||||||
|
((if? exp)
|
||||||
|
`(if ,(ast:ast->pp-sexp (if->condition exp))
|
||||||
|
,(ast:ast->pp-sexp (if->then exp))
|
||||||
|
,(ast:ast->pp-sexp (if->else exp))))
|
||||||
|
((app? exp)
|
||||||
|
(map ast:ast->pp-sexp exp))
|
||||||
|
(else exp)))
|
||||||
))
|
))
|
||||||
|
|
Loading…
Add table
Reference in a new issue