From 67071a176156577c6765618261d629d43e721fa9 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Tue, 13 Nov 2018 18:02:12 -0500 Subject: [PATCH] WIP --- scheme/cyclone/cgen.sld | 14 ++++++++++++-- scheme/cyclone/cps-opt-local-var-redux.scm | 12 +++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/scheme/cyclone/cgen.sld b/scheme/cyclone/cgen.sld index eb5f4bf1..96a38f6b 100644 --- a/scheme/cyclone/cgen.sld +++ b/scheme/cyclone/cgen.sld @@ -1181,6 +1181,13 @@ (c-code "") args))) exps)) + ((equal? 'Cyc-local-set! fun) + (let ((val-exp (c-compile-exp (caddr exp) append-preamble cont ast-id trace cps?))) + (c-code/vars + (string-append (mangle (cadr exp) " = " (c:body val-exp) ";")) + (c:allocs val-exp))) + ;(c-code (string-append (mangle (cadr exp)) " = " (mangle (caddr exp)) ";")) + ) ((equal? 'let fun) (let* ((vars/vals (cadr exp)) (body (caddr exp)) @@ -1192,13 +1199,16 @@ (c-code/vars (let ((cp1-body (c:body cp1))) (string-append cp1-body ";" (c:body cp2))) - (append (list (mangle (car var/val))) (c:allocs cp1) (c:allocs cp2))))) + (append + (list (string-append "object " (mangle (car var/val)) ";")) + (c:allocs cp1) + (c:allocs cp2))))) (c-code "") vars/vals)) (body-exp (c-compile-exp body append-preamble cont ast-id trace cps?)) ) - (trace:error `(JAE DEBUG body ,body ,vars/vals ,exp)) + ;;(trace:error `(JAE DEBUG body ,body ,vars/vals ,exp)) (c:append vexps body-exp) ) ) diff --git a/scheme/cyclone/cps-opt-local-var-redux.scm b/scheme/cyclone/cps-opt-local-var-redux.scm index 88f8d567..dc83e47f 100644 --- a/scheme/cyclone/cps-opt-local-var-redux.scm +++ b/scheme/cyclone/cps-opt-local-var-redux.scm @@ -59,11 +59,13 @@ ;; (car (ast:lambda-body (car exp))) ;; (car (ast:lambda-args (car exp)))))) ;;(newline) -TODO: need to revisit this, may need to replace values with assignments to the "let" variable. -would need to be able to carry that through to cgen and assign properly over there... +;TODO: need to revisit this, may need to replace values with assignments to the "let" variable. +;would need to be able to carry that through to cgen and assign properly over there... (let ((value (lvr:tail-calls->values (car (ast:lambda-body (car exp))) - (car (ast:lambda-args (car exp))))) + (car (ast:lambda-args (car exp))) + (car (ast:lambda-args (cadr exp))) + )) (var (car (ast:lambda-args (cadr exp)))) (body (ast:lambda-body (cadr exp)))) `(let ((,var ,value)) @@ -110,7 +112,7 @@ would need to be able to carry that through to cgen and assign properly over the ;; Local variable reduction helper: ;; Transform all tail calls of sym in the sexp to just the value passed -(define (lvr:tail-calls->values sexp sym) +(define (lvr:tail-calls->values sexp sym assign-sym) (call/cc (lambda (return) (define (scan exp) @@ -134,7 +136,7 @@ would need to be able to carry that through to cgen and assign properly over the ((and (equal? (car exp) sym) (= (length exp) 2) ) - (cadr exp)) + `(Cyc-local-set! ,assign-sym ,(cadr exp))) (else (return #f)))) (else exp)))