From c5fcc7d0f5c3f2f596f4d02d5e84283efce7eb52 Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Tue, 21 Jun 2022 20:14:25 -0700 Subject: More progress on CPS. --- csc/ir2.csc | 100 ++++++++++++++++++++---------------------------------------- 1 file changed, 33 insertions(+), 67 deletions(-) (limited to 'csc/ir2.csc') diff --git a/csc/ir2.csc b/csc/ir2.csc index 46dbad1..708d7b1 100644 --- a/csc/ir2.csc +++ b/csc/ir2.csc @@ -1,74 +1,30 @@ (define-library (csc ir2) (export - lambda-body - lambda-case-alternate - lambda-case-arguments - lambda-case-body - lambda-case-gensyms - lambda-case-rest - lambda-case? - make-lambda-case + atom-continuation + atom-expression + atom? + ir2=? + make-atom + make-tail + tail? ; Re-exports from IR1. - call-arguments - call-procedure - call? constant-expression constant? - if-alternate - if-consequent - if-test - if? - lambda? - make-call - make-constant - make-if - make-lambda - make-sequence - make-toplevel-define - make-toplevel-ref - make-void - sequence-head - sequence-tail - sequence? - toplevel-define-expression - toplevel-define-name - toplevel-define? - toplevel-ref-name - toplevel-ref? - void?) + make-constant) (import (scheme base) (only (csc ir1) - call-arguments - call-procedure - call? - constant-expression constant? - if-alternate - if-consequent - if-test - if? - lambda-body - lambda? - make-call - make-constant - make-if - make-lambda - make-sequence - make-toplevel-define - make-void - sequence-head - sequence-tail - sequence? - toplevel-define-expression - toplevel-define-name - toplevel-define? - void?)) + ir1=? + make-constant)) (begin ; This library defines the intermediate representation IR2. ; It's CPS time bitch. + ; CPS expressions. + + ; An atom consists of an ir1 expression and a continuation. (define-record-type (make-atom expression continuation) @@ -77,17 +33,27 @@ (continuation atom-continuation)) - ; - (define-record-type - (make-variable k var + ; CPS continuations. + + + ; tail is the tail continuation. + (define-record-type + (make-tail) + tail?) - ; idx - ; Reference to a variable by index in the closure. - (define-record-type - (make-closure-ref idx) - closure-ref? - (idx closure-ref-index)) + (define (ir2=?-sametype x y) + (cond + ((and (atom? x) (atom? y)) + (and (ir1=? (atom-expression x) (atom-expression y)) + (ir2=? (atom-continuation x) (atom-continuation y)))) + ((and (tail? x) (tail? y)) #t) + (else #f))) - ; arguments rest + (define (ir2=? x y) + (cond + ((ir2=?-sametype x y) #t) + ((and (ir2=?-sametype x x) (ir2=?-sametype y y)) + #f) + (else (error "One or more arguments has a type unknown to ir2=?" x y)))))) -- cgit v1.3.1