Implement datum support and add make for ex-5.52

This commit is contained in:
2021-06-12 10:51:50 -04:00
parent bcabdd3212
commit 15057b52d4
7 changed files with 114 additions and 41 deletions

View File

@@ -74,9 +74,11 @@
;;;simple expressions
(define (compile-self-evaluating exp target linkage)
(end-with-linkage linkage
(make-instruction-sequence '() (list target)
`((" " ,target " " = " " ,exp ";")))))
(cond ((number? exp)
(end-with-linkage linkage
(make-instruction-sequence '() (list target)
`((" " ,target " = const_int(" ,exp ");")))))
(else (error "SELF-EVAL -- unsupported type" exp))))
(define (compile-quoted exp target linkage)
(end-with-linkage linkage
@@ -222,25 +224,29 @@
(append-instruction-sequences
(car operand-codes)
(make-instruction-sequence '(val) '(argl)
'((" " argl " = " list (val) ";"))))))
'((" argl[0] = val;"))))))
(if (null? (cdr operand-codes))
code-to-get-last-arg
(preserving '(env)
code-to-get-last-arg
(code-to-get-rest-args
(cdr operand-codes))))))))
1
(cdr operand-codes))))))))
(define (code-to-get-rest-args operand-codes)
(define (code-to-get-rest-args index operand-codes)
(let ((code-for-next-arg
(preserving '(argl)
(car operand-codes)
(make-instruction-sequence '(val argl) '(argl)
'((" " argl " " = " " cons "(" val ", " argl ");"))))))
`((" argl[" ,index "] = val;"))))))
(if (null? (cdr operand-codes))
code-for-next-arg
(append-instruction-sequences
code-for-next-arg
(make-instruction-sequence
'() '() `((" argl[" ,(+ index 1) "] = NULL;"))))
(preserving '(env)
code-for-next-arg
(code-to-get-rest-args (cdr operand-codes))))))
(code-to-get-rest-args (+ index 1) (cdr operand-codes))))))
;;;applying procedures
@@ -263,7 +269,7 @@
(end-with-linkage linkage
(make-instruction-sequence '(proc argl)
(list target)
`((" val = proc(argl);"))))))
`((" val = (*proc->primitive_procedure)((void**) argl);"))))))
(make-instruction-sequence '() '() `((,after-call ":")))))))
;;;applying compiled procedures