From acc561366f3fe6ec0377103f52ef0f7e923711c9 Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Mon, 1 Aug 2022 19:35:19 -0700 Subject: Modify the project structure. Now the lib directory contains what will eventually end up on the user's /usr/lib/csc. When I write make install, it will copy all of the .csc files from lib into the destination lib directory. This means I can start working on the standard library in lib/scheme. --- lib/csc/ir2.csc | 217 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 217 insertions(+) create mode 100644 lib/csc/ir2.csc (limited to 'lib/csc/ir2.csc') diff --git a/lib/csc/ir2.csc b/lib/csc/ir2.csc new file mode 100644 index 0000000..888437f --- /dev/null +++ b/lib/csc/ir2.csc @@ -0,0 +1,217 @@ +(define-library (csc ir2) + (export + %apply + %branch + %closure + %fix + %globals + %label + %primitive + %tail + %variable + *globals* + *tail* + apply-arguments + apply-procedure + apply? + branch-atom + branch-false + branch-true + branch? + call-closure-args + call-closure-closure + call-closure? + closure-arguments + closure-body + closure-name + closure-rest + closure? + fix-body + fix-functions + fix? + globals? + label-gensym + label? + make-apply + make-branch + make-call-closure + make-closure + make-fix + make-label + make-primitive + make-variable + primitive-arguments + primitive-continuation + primitive-operation + primitive-results + primitive? + tail? + variable-gensym + variable? + + ; Re-exports from IR1. + %constant + %library-ref + constant-expression + constant? + lexical-ref-gensym + lexical-ref-name + lexical-ref? + lexical-set-expression + lexical-set-ref + lexical-set? + library-ref-library + library-ref-name + library-ref? + make-constant + make-lexical-ref + make-lexical-set + make-library-ref) + (import (scheme base) + (only (csc ir1) + %constant + %library-ref + constant-expression + constant? + lexical-ref-gensym + lexical-ref-name + lexical-ref? + lexical-set-expression + lexical-set-ref + lexical-set? + library-ref-library + library-ref-name + library-ref? + make-constant + make-lexical-ref + make-lexical-set + make-library-ref) + (only (csc list) all) + (only (csc loop) + loop + return) + (only (csc match) + define-match-record-type + match)) + (begin + ; This library defines the intermediate representation IR2. + ; It's CPS time bitch. + + ; CPS atom: + ; An atom is a value that can be computed immediately without + ; any subexpressions. + ; Atoms consist of + ; - constant, + ; - lexical-ref, + ; - library-ref, + ; - or globals. + ; After closure conversion, there are no more lexical refs. + ; Each lexical ref will be converted to a . + + + ; A function argument or local variable. + (define-match-record-type + (make-variable gensym) + variable? + %variable + (gensym variable-gensym)) + + + ; The globals array. This will eventually be stored in register 0. + (define-match-record-type + (make-globals) + globals? + %globals) + + + ; A global instance of . + ; Considered equal to calling (make-globals). + (define *globals* (make-globals)) + + + ; A label, used for function names and will compile to a constant. + (define-match-record-type