diff options
author | David Thompson <dthompson@vistahigherlearning.com> | 2022-08-10 18:49:33 -0400 |
---|---|---|
committer | David Thompson <dthompson@vistahigherlearning.com> | 2022-08-10 18:50:10 -0400 |
commit | 9f65c417b7575eab5ebd2733a817a0f0e954c4d9 (patch) | |
tree | 8343f16a11a92a8eefb35095bf5cfbdf7cf44997 /compiler.scm | |
parent | c441f8f092cd5da5b09e3e4e826141d915189ab5 (diff) |
Step 2: Immediate Constants
Diffstat (limited to 'compiler.scm')
-rw-r--r-- | compiler.scm | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/compiler.scm b/compiler.scm index 1285ac6..919be4c 100644 --- a/compiler.scm +++ b/compiler.scm @@ -5,6 +5,23 @@ (newline)) (define (compile-program x) + (define fixnum-shift 2) + (define fixnum-tag 0) + (define char-shift 8) + (define char-tag 15) + (define boolean-shift 7) + (define boolean-tag 31) + (define empty-list 47) ;; #b00101111 + (define (immediate-rep x) + (cond + ((integer? x) + (ash x fixnum-shift)) + ((char? x) + (logior (ash (char->integer x) char-shift) char-tag)) + ((boolean? x) + (logior (ash (if x 1 0) boolean-shift) boolean-tag)) + ((null? x) + empty-list))) (with-output-to-file "scheme_entry.S" (lambda () (display ".text @@ -13,5 +30,5 @@ .type scheme_entry, @function scheme_entry: ") - (emit "movl $~a, %eax" x) + (emit "movl $~a, %eax" (immediate-rep x)) (emit "ret")))) |