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/linker.csc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'csc/linker.csc') diff --git a/csc/linker.csc b/csc/linker.csc index 238fbc5..dc738b7 100644 --- a/csc/linker.csc +++ b/csc/linker.csc @@ -29,6 +29,8 @@ unless (symbol=? op 'label) collect (cons op (loop for arg in args collect (match arg + (('label 'init) + (list 'const (lookup label-map -1))) (('label x) (list 'const (lookup label-map x))) (_ arg)))))) @@ -39,9 +41,12 @@ for i from offset with m = (make-map compare-numbers) do (match op + (('label 'init) + (set! m (insert m -1 i)) + (set! i (- i 1))) ; Labels will be removed later. (('label id) (set! m (insert m id i)) - (set! i (- i 1)))) ; Labels will be removed later. + (set! i (- i 1)))) finally (return m))) @@ -71,8 +76,11 @@ (translate-globals (loop for prog in programs for off = 0 then (+ off (length converted-prog)) - for converted-prog = (translate-labels - prog - (make-label-map off prog)) + for converted-prog = (let ((prog-prelude (cons + (list 'jmp '(label init)) + prog))) + (translate-labels + prog-prelude + (make-label-map off prog-prelude))) append converted-prog) environment)))) -- cgit v1.3.1