aboutsummaryrefslogtreecommitdiffstats
path: root/csc/ir2.csc
diff options
context:
space:
mode:
authorRose Hogenson <rhogenson@posteo.net>2022-08-01 19:35:19 -0700
committerRose Hogenson <rhogenson@posteo.net>2022-08-01 19:35:19 -0700
commitacc561366f3fe6ec0377103f52ef0f7e923711c9 (patch)
treed7a19cfbad78a69ebea71b27302e708c0655863d /csc/ir2.csc
parent99ce19a8053a93457885f32ec54c1c5b7c1961c1 (diff)
downloadchromatopelma-acc561366f3fe6ec0377103f52ef0f7e923711c9.tar.zst
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.
Diffstat (limited to 'csc/ir2.csc')
-rw-r--r--csc/ir2.csc217
1 files changed, 0 insertions, 217 deletions
diff --git a/csc/ir2.csc b/csc/ir2.csc
deleted file mode 100644
index 888437f..0000000
--- a/csc/ir2.csc
+++ /dev/null
@@ -1,217 +0,0 @@
-(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 <variable>.
-
-
- ; A function argument or local variable.
- (define-match-record-type <variable>
- (make-variable gensym)
- variable?
- %variable
- (gensym variable-gensym))
-
-
- ; The globals array. This will eventually be stored in register 0.
- (define-match-record-type <globals>
- (make-globals)
- globals?
- %globals)
-
-
- ; A global instance of <globals>.
- ; 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 <label>
- (make-label gensym)
- label?
- %label
- (gensym label-gensym))
-
-
- ; CPS expressions:
- ; CPS expressions are similar to IR1 expressions,
- ; but constrained not to have any subexpressions except atoms.
- ; And they take a continuation.
-
-
- ; A primitive encodes one of a number of primitive operations.
- ; Each operation takes a number of arguments,
- ; and binds some number of result variables.
- ; The known primitives are listed below, along with their arity.
- ; - alloc: size -> result
- ; - peek: pointer * offset -> result
- ; - poke: word * pointer * offset -> ()
- ; - exit: code -> ()
- (define-match-record-type <primitive>
- (make-primitive operation arguments results continuation)
- primitive?
- %primitive
- (operation primitive-operation)
- (arguments primitive-arguments)
- (results primitive-results)
- (continuation primitive-continuation))
-
-
- ; Branches depending on the given atom.
- ; If it is true, continue with continuation true.
- ; If false, continue with continuation false.
- (define-match-record-type <branch>
- (make-branch atom true false)
- branch?
- %branch
- (atom branch-atom)
- (true branch-true)
- (false branch-false))
-
-
- ; Applies a procedure to a list of arguments. Apply does not take a
- ; continuation. Instead the continuation will be passed as the first
- ; argument to the function.
- (define-match-record-type <apply>
- (make-apply procedure arguments)
- apply?
- %apply
- (procedure apply-procedure)
- (arguments apply-arguments))
-
-
- ; The tail continuation. Used for the exit point of library init functions,
- ; and the end of a program.
- (define-match-record-type <tail>
- (make-tail)
- tail?
- %tail)
-
-
- (define *tail* (make-tail))
-
-
- ; A procedure. All closures are allocated in a fix expression. A closure
- ; does not take a continuation. Instead, the procedure will accept the
- ; continuation as an argument.
- (define-match-record-type <closure>
- (make-closure name arguments body)
- closure?
- %closure
- (name closure-name)
- (arguments closure-arguments)
- (body closure-body))
-
-
- ; Defines a list of mutually recursive procedures.
- ; Functions is a list of closures, and body is an expression.
- (define-match-record-type <fix>
- (make-fix functions body)
- fix?
- %fix
- (functions fix-functions)
- (body fix-body))))