aboutsummaryrefslogtreecommitdiffstats
path: root/lib/csc/ir1.csc
diff options
context:
space:
mode:
authorRose Hogenson <rhogenson@posteo.net>2023-05-01 07:56:42 -0700
committerRose Hogenson <rhogenson@posteo.net>2023-05-01 07:56:42 -0700
commita89d6c82e981fec7d6e4c975e083d2b9e04467ad (patch)
treed5445ceb797473dd45ac006c337d990e5dd6f0d4 /lib/csc/ir1.csc
parent112ce5291da35e54c38c4ff1d7a2408a64a98e71 (diff)
downloadchromatopelma-a89d6c82e981fec7d6e4c975e083d2b9e04467ad.tar.zst
Rewrite most of the compiler.
This represents a major step back in terms of functionality, and amount of code. The latter I think constitutes a major win. Next steps are to reimplement syntax-rules, call/cc, and call-with-values.
Diffstat (limited to 'lib/csc/ir1.csc')
-rw-r--r--lib/csc/ir1.csc216
1 files changed, 0 insertions, 216 deletions
diff --git a/lib/csc/ir1.csc b/lib/csc/ir1.csc
deleted file mode 100644
index c88123e..0000000
--- a/lib/csc/ir1.csc
+++ /dev/null
@@ -1,216 +0,0 @@
-(define-library (csc ir1)
- (export
- %call
- %call-builtin
- %constant
- %define-syntax
- %if
- %lambda
- %letrec
- %lexical-ref
- %lexical-set
- %library-define
- %library-ref
- %sequence
- call-arguments
- call-builtin-arguments
- call-builtin-operation
- call-builtin?
- call-procedure
- call?
- constant-expression
- constant?
- define-syntax-name
- define-syntax-transformer
- define-syntax?
- if-alternate
- if-consequent
- if-test
- if?
- lambda-arguments
- lambda-body
- lambda?
- letrec-expression
- letrec-gensyms
- letrec-in-order?
- letrec-names
- letrec-values
- letrec?
- lexical-ref-gensym
- lexical-ref-name
- lexical-ref?
- lexical-set-expression
- lexical-set-ref
- lexical-set?
- library-define-expression
- library-define-ref
- library-define?
- library-ref-library
- library-ref-name
- library-ref?
- make-call
- make-call-builtin
- make-constant
- make-define-syntax
- make-if
- make-lambda
- make-letrec
- make-lexical-ref
- make-lexical-set
- make-library-define
- make-library-ref
- make-sequence
- sequence-head
- sequence-tail
- sequence?)
- (import (scheme base)
- (only (csc list)
- all)
- (only (csc loop) loop return)
- (only (csc match)
- define-match-record-type))
- (begin
- ; This library defines the intermediate representation IR1. An expression
- ; in IR1 has one of the following forms (plagiarized from Guile's
- ; Tree-IL).
-
-
- ; <constant> expression
- ; Constant is used to include literal constants in scheme code.
- (define-match-record-type <constant>
- (make-constant expression)
- constant?
- %constant
- (expression constant-expression))
-
-
- ; <lexical-ref> name gensym
- ; A reference to a lexically-bound variable. The name is the original name
- ; of the variable in the source program. gensym is a unique identifier for
- ; this variable.
- (define-match-record-type <lexical-ref>
- (make-lexical-ref name gensym)
- lexical-ref?
- %lexical-ref
- (name lexical-ref-name)
- (gensym lexical-ref-gensym))
-
-
- ; <library-ref> name
- ; A free reference to a variable in a library. If the library is 'main,
- ; then it is a top-level global variable.
- (define-match-record-type <library-ref>
- (make-library-ref name library)
- library-ref?
- %library-ref
- (name library-ref-name)
- (library library-ref-library))
-
-
- ; <lexical-set> name gensym expression
- ; Sets a lexically-bound variable.
- (define-match-record-type <lexical-set>
- (make-lexical-set ref expression)
- lexical-set?
- %lexical-set
- (ref lexical-set-ref)
- (expression lexical-set-expression))
-
-
- ; <library-define> name expression
- ; Defines a new variable in the current library.
- (define-match-record-type <library-define>
- (make-library-define ref expression)
- library-define?
- %library-define
- (ref library-define-ref)
- (expression library-define-expression))
-
-
- ; <define-syntax> name transformer
- ; Defines a new macro in the current environment. name is the name of the
- ; macro. transformer is a macro transformer.
- (define-match-record-type <define-syntax>
- (make-define-syntax name transformer)
- define-syntax?
- %define-syntax
- (name define-syntax-name)
- (transformer define-syntax-transformer))
-
-
- ; <if> test consequent alternate
- ; A conditional.
- (define-match-record-type <if>
- (make-if test consequent alternate)
- if?
- %if
- (test if-test)
- (consequent if-consequent)
- (alternate if-alternate))
-
-
- ; <call> procedure arguments
- ; A procedure call. The procedure and arguments are evaluated in an
- ; unspecified order, and the resulting procedure is passed the
- ; resulting arguments.
- (define-match-record-type <call>
- (make-call procedure arguments)
- call?
- %call
- (procedure call-procedure)
- (arguments call-arguments))
-
-
- ; <call-builtin> operation arguments
- ; Executes the given builtin operation on the arguments. The known builtin
- ; operations are listed below. Each operation can return a value, or not.
- ; - alloc: size -> result
- ; - peek: pointer * offset -> result
- ; - poke: word * pointer * offset -> ()
- ; - lt: int * int -> bool
- ; - eq: obj * obj -> bool
- ; - call-with-current-continuation: proc -> result
- ; - call-with-values: producer * consumer -> result
- ; - apply: proc * args -> result
- (define-match-record-type <call-builtin>
- (make-call-builtin operation arguments)
- call-builtin?
- %call-builtin
- (operation call-builtin-operation)
- (arguments call-builtin-arguments))
-
-
- ; <sequence> head tail
- ; Evaluate head, ignoring any result. Then tail is evaluated.
- (define-match-record-type <sequence>
- (make-sequence head tail)
- sequence?
- %sequence
- (head sequence-head)
- (tail sequence-tail))
-
-
- ; <lambda> body
- ; A closure. Arguments is a lexical-ref.
- (define-match-record-type <lambda>
- (make-lambda arguments body)
- lambda?
- %lambda
- (arguments lambda-arguments)
- (body lambda-body))
-
-
- ; <letrec> in-order? names gensyms values expression
- ; Lexical binding, like Scheme's letrec, or letrec* if in-order? is true.
- ; names are the original binding names, gensyms are gensyms corresponding
- ; to the names, and values are IR1 expressions for the values. expression
- ; is a single IR1 expression.
- (define-match-record-type <letrec>
- (make-letrec in-order? names gensyms values expression)
- letrec?
- %letrec
- (in-order? letrec-in-order?)
- (names letrec-names)
- (gensyms letrec-gensyms)
- (values letrec-values)
- (expression letrec-expression))))