diff options
| author | Rose Hogenson <rhogenson@posteo.net> | 2022-07-26 18:29:40 -0700 |
|---|---|---|
| committer | Rose Hogenson <rhogenson@posteo.net> | 2022-07-26 18:29:40 -0700 |
| commit | b8ed2e52cd7decd56b195df5363fcc0f17cc3805 (patch) | |
| tree | 1c650ce05c82ebaf21f3a8b5a259781c2c24843b /csc/linker.csc | |
| parent | a8b7dc2c48f29de2aff5786beedcbe5bc0f3ac50 (diff) | |
| download | chromatopelma-b8ed2e52cd7decd56b195df5363fcc0f17cc3805.tar.zst | |
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.
Diffstat (limited to 'csc/linker.csc')
| -rw-r--r-- | csc/linker.csc | 16 |
1 files changed, 12 insertions, 4 deletions
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)))) |
