diff options
| author | Rose Hogenson <rhogenson@posteo.net> | 2022-07-22 12:02:25 -0700 |
|---|---|---|
| committer | Rose Hogenson <rhogenson@posteo.net> | 2022-07-22 12:02:25 -0700 |
| commit | 555519b85ded4a8fefd9c217e6acfb529ac67432 (patch) | |
| tree | 1b030258c276b15427cb3a214b484eaa7d8f9eb5 /csc/ir2.csc | |
| parent | 7c46c091746544a0069dc3d1bde969a79a7c2409 (diff) | |
| download | chromatopelma-555519b85ded4a8fefd9c217e6acfb529ac67432.tar.zst | |
Handle global variables.
Global variables will be stored in an array which is kept in register 0.
The linker will later translate each library-ref into an integer, which
is used as an index into the globals table.
This design makes implementing eval quite straightforward, the eval
bytecode will accept a globals table and a bytevector of bytecode, save
the current set of registers, set register 0 to the new globals table,
and begin executing the given bytecode. When eval is finished, it will
restore the saved registers and return to the previous instruction
pointer. In this way, calling eval can create a call stack.
We could think about implementing function calls with eval, and it's
cool that it would work, but the CPS transformation mostly makes this
irrelevant. It's interesting to think about implementing an interpreter,
where a function call would simply eval the function's bytecode, and the
function call stack would be handled automatically.
Diffstat (limited to 'csc/ir2.csc')
| -rw-r--r-- | csc/ir2.csc | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/csc/ir2.csc b/csc/ir2.csc index 331aa4c..30fb5a3 100644 --- a/csc/ir2.csc +++ b/csc/ir2.csc @@ -4,8 +4,10 @@ %branch %closure %fix + %globals %primitive %variable + *globals* apply-arguments apply-procedure apply? @@ -27,6 +29,7 @@ fix-body fix-functions fix? + globals? kargs-expression kargs-refs kargs? @@ -101,10 +104,10 @@ ; Atoms consist of ; - constant, ; - lexical-ref, - ; - or library-ref + ; - library-ref, + ; - or globals. ; After closure conversion, there are no more lexical refs. - ; Each lexical ref will be converted to one of the following - ; data types. + ; Each lexical ref will be converted to a <variable>. ; A function argument or local variable. @@ -115,6 +118,18 @@ (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)) + + ; CPS expressions: ; CPS expressions are similar to IR1 expressions, ; but constrained not to have any subexpressions except atoms. |
