From b8ed2e52cd7decd56b195df5363fcc0f17cc3805 Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Tue, 26 Jul 2022 18:29:40 -0700 Subject: Fix an issue with how the linker combined files. I inserted jump statements into the bytecode at the beginning of each compilation unit, to jump to the init label. The point is that now the bytecode can be executed from start to finish, and assuming the libraries were ordered correctly, it will run the full program. --- csc/codegen-test.csc | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'csc/codegen-test.csc') diff --git a/csc/codegen-test.csc b/csc/codegen-test.csc index 01eda04..03f6b11 100644 --- a/csc/codegen-test.csc +++ b/csc/codegen-test.csc @@ -34,7 +34,8 @@ (test codegen-apply (define p (test-var)) (assert-equal - '((peek (local 1) (local 0) (const 5)) + '((label init) + (peek (local 1) (local 0) (const 5)) (mov (local 2) (local 1)) (mov (local 1) (const 10)) (jmp (local 2))) @@ -47,7 +48,8 @@ (test codegen-call-global (define p (test-var)) (assert-equal - '((peek (local 1) (local 0) (global cons (csc based))) + '((label init) + (peek (local 1) (local 0) (global cons (csc based))) (mov (local 3) (local 1)) (mov (local 1) (const 5)) (mov (local 2) (const ())) @@ -62,11 +64,12 @@ (define f (test-label)) (define ret (test-var)) (assert-equal - '((mov (local 1) (label 0)) - (jmp (label 0)) - (label 0) + '((label 0) (mov (local 2) (local 1)) - (jmp (local 2))) + (jmp (local 2)) + (label init) + (mov (local 1) (label 0)) + (jmp (label 0))) (ir2->ir3 (make-fix (list (make-closure f (list ret) @@ -83,10 +86,7 @@ (define g2 (test-var)) (define g3 (test-var)) (assert-equal - '((mov (local 1) (const 0)) - (mov (local 2) (const 1)) - (jmp (label 0)) - (label 0) + '((label 0) (mov (local 127) (local 1)) (mov (local 1) (local 2)) (mov (local 2) (local 127)) @@ -95,6 +95,10 @@ (label 1) (mov (local 2) (local 1)) (mov (local 1) (local 3)) + (jmp (label 0)) + (label init) + (mov (local 1) (const 0)) + (mov (local 2) (const 1)) (jmp (label 0))) (ir2->ir3 (make-fix @@ -108,7 +112,8 @@ (test codegen-branch (define p (test-var)) (assert-equal - '((peek (local 1) (local 0) (const 1)) + '((label init) + (peek (local 1) (local 0) (const 1)) (jmpif (const #t) (label 0)) (mov (local 2) (local 1)) (mov (local 1) (const 10)) -- cgit v1.3.1