Added quotes and added an interpreter for scheme on the ir
This commit is contained in:
@@ -139,7 +139,7 @@
|
|||||||
;; | (set-then! <var> <aexp> <cexp>)
|
;; | (set-then! <var> <aexp> <cexp>)
|
||||||
;; | (letrec ((<var> <aexp>)) <cexp>)
|
;; | (letrec ((<var> <aexp>)) <cexp>)
|
||||||
;; <aexp> ::= (lambda (<var> ...) exp)
|
;; <aexp> ::= (lambda (<var> ...) exp)
|
||||||
;; | <num> | <var> | #t | #f
|
;; | <num> | <var> | #t | #f | (quote <exp>)
|
||||||
;;
|
;;
|
||||||
;; We choose a hybrid transformation based on https://matt.might.net/articles/cps-conversion/
|
;; We choose a hybrid transformation based on https://matt.might.net/articles/cps-conversion/
|
||||||
;; Admittedly this is a little black magic to me, but it's useful
|
;; Admittedly this is a little black magic to me, but it's useful
|
||||||
@@ -170,6 +170,7 @@
|
|||||||
;; T-c takes a symbolic continuation, and uses it to construct CPS
|
;; T-c takes a symbolic continuation, and uses it to construct CPS
|
||||||
;; (expr * aexp) -> cexp
|
;; (expr * aexp) -> cexp
|
||||||
(match expr
|
(match expr
|
||||||
|
[ ('quote e) `(,c ,expr)]
|
||||||
[`(lambda . ,_) `(,c ,(M expr))]
|
[`(lambda . ,_) `(,c ,(M expr))]
|
||||||
[ (? atomic?) `(,c ,(M expr))]
|
[ (? atomic?) `(,c ,(M expr))]
|
||||||
[ ('letrec ([v e]) body)
|
[ ('letrec ([v e]) body)
|
||||||
@@ -202,6 +203,7 @@
|
|||||||
;; As an invariant, T-k cannot nest a T-c call directly
|
;; As an invariant, T-k cannot nest a T-c call directly
|
||||||
;; (expr * (aexp -> cexp) -> cexp)
|
;; (expr * (aexp -> cexp) -> cexp)
|
||||||
(match expr
|
(match expr
|
||||||
|
[ ('quote e) (k expr)]
|
||||||
[`(lambda . ,_) (k (M expr))]
|
[`(lambda . ,_) (k (M expr))]
|
||||||
[(? atomic?) (k (M expr))]
|
[(? atomic?) (k (M expr))]
|
||||||
[('letrec ([v e]) body)
|
[('letrec ([v e]) body)
|
||||||
@@ -252,6 +254,14 @@
|
|||||||
(match-lambda*
|
(match-lambda*
|
||||||
[(args ... k) (k (apply x args))])
|
[(args ... k) (k (apply x args))])
|
||||||
x))
|
x))
|
||||||
|
|
||||||
|
(define (ir-interpreter)
|
||||||
|
(display "> ")
|
||||||
|
(let ([prgm (read)])
|
||||||
|
(display "$$ = ")
|
||||||
|
(primitive-eval `(display (call/cc (lambda (ktail) ,(ir-convert prgm)))))
|
||||||
|
(newline))
|
||||||
|
(ir-interpreter))
|
||||||
;; Compilation
|
;; Compilation
|
||||||
|
|
||||||
(define (meaning e r)
|
(define (meaning e r)
|
||||||
|
|||||||
Reference in New Issue
Block a user