From 7dcc83e513e603a7e1baa29696b05f9f3db9307e Mon Sep 17 00:00:00 2001 From: Devyn Cairns Date: Wed, 9 Aug 2023 17:12:24 -0700 Subject: [PATCH] have link return its symbol addresses --- stage2/03-list-util.lsp | 27 ++++++++++++++++----------- stage2/15-link.lsp | 13 +++++++------ stage2/16-awesome.lsp | 5 +++-- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/stage2/03-list-util.lsp b/stage2/03-list-util.lsp index da0db28..1fbaf2b 100644 --- a/stage2/03-list-util.lsp +++ b/stage2/03-list-util.lsp @@ -26,6 +26,10 @@ (proc args scope (eval (eval scope (car args)) (cons map (eval scope (cadr args))))))) +; make a list from args +(define list + (proc args scope (eval-list scope args))) + ; associate two lists into pairs ; if the second list is shorter than the first, remaining pairs will be associated to nil (define assoc @@ -37,14 +41,14 @@ (cons (car (car args)) (car (cadr args))) - (unquote (cons map - (cons (cdr (car args)) - (cons (cdr (cadr args))))))))) + (unquote (list map + (cdr (car args)) + (cdr (cadr args))))))) ; pass evaluated first and second arg to `map` (proc args scope - (unquote (cons map - (cons (eval scope (car args)) - (cons (eval scope (cadr args))))))))) + (unquote (list map + (eval scope (car args)) + (eval scope (cadr args))))))) ; concat two lists (define concat @@ -53,10 +57,11 @@ (if (nil? (car args)) (cadr args) (cons (car (car args)) - (unquote (cons rec - (cons (cdr (car args)) (cons (cadr args)))))))) + (unquote (list rec + (cdr (car args)) + (cadr args)))))) (proc args scope - (unquote (cons rec - (cons (eval scope (car args)) - (cons (eval scope (cadr args))))))))) + (unquote (list rec + (eval scope (car args)) + (eval scope (cadr args))))))) diff --git a/stage2/15-link.lsp b/stage2/15-link.lsp index f22547f..ea38c02 100644 --- a/stage2/15-link.lsp +++ b/stage2/15-link.lsp @@ -31,7 +31,7 @@ ; link a program ; expects multiple named sections with instructions following the name ; symbols defined in context: pc, rel, rel+, all sections -; returns the address and size of the program +; returns the address, size, and sections of the program (define link (proc program scope (let ( @@ -49,9 +49,10 @@ (program-scope (concat ; define rel and rel+ - (assoc - (quote (rel rel+)) - (cons rel (cons rel+ ()))) + (list + (cons (quote rel) rel) + (cons (quote rel+) rel+) + ) (concat section-addrs scope))) (put-instruction (fn (pc instruction-expr) @@ -70,6 +71,6 @@ program-addr ; start pc = base addr program) ; the output of the above should be the end address of the program, - ; but we want to return (addr size) - (cons program-addr (cons program-size ())))))) + ; but we want to return (addr size section-addrs) + (list program-addr program-size section-addrs))))) diff --git a/stage2/16-awesome.lsp b/stage2/16-awesome.lsp index 4434c2a..8d4643e 100644 --- a/stage2/16-awesome.lsp +++ b/stage2/16-awesome.lsp @@ -1,6 +1,6 @@ ; try a simple assembler program (define awesome.str$ (ref "Awesome string!")) -(define awesome$ (car (link +(define awesome.out (link (start ; initialize counter, stack (\addi $sp $sp -0x10) @@ -35,5 +35,6 @@ (\addi $sp $sp 0x10) (\ret) ) -))) +)) +(define awesome$ (car awesome.out)) (call-native awesome$)