aboutsummaryrefslogtreecommitdiffstats
path: root/csc/codegen.csc
diff options
context:
space:
mode:
Diffstat (limited to 'csc/codegen.csc')
-rw-r--r--csc/codegen.csc9
1 files changed, 6 insertions, 3 deletions
diff --git a/csc/codegen.csc b/csc/codegen.csc
index 1fd7099..7712427 100644
--- a/csc/codegen.csc
+++ b/csc/codegen.csc
@@ -207,6 +207,9 @@
(if (label? proc)
(list 'jmp (list 'label proc-temp))
(list 'jmp (list 'local proc-temp))))))
+ ((% %tail)
+ (list
+ (list 'jmp (list 'label 0))))
(_ (error "Unexpected form in ir2->bytecode expr"))))
@@ -225,7 +228,7 @@
; Converts an IR2 program into bytecode.
(define (ir2->ir3 expr)
(define label-map (make-map compare-labels))
- (define next-label-id 0)
+ (define next-label-id 1) ; start at 1 because label 0 is used for tail.
(define (translate-label x)
(or (lookup label-map x #f)
(let ((id next-label-id))
@@ -248,9 +251,9 @@
(set! locals-map (insert locals-map x local-count))
local-count)))))
(append
+ (ir2->bytecode (fix-body expr) (make-locals-map '()))
(loop for func in (fix-functions expr)
collect (list 'label (translate-label (closure-name func)))
append (ir2->bytecode (closure-body func) (make-locals-map (closure-arguments func))))
(list
- (list 'label 'init))
- (ir2->bytecode (fix-body expr) (make-locals-map '()))))))
+ (list 'label 0))))))