diff --git a/scheme/cyclone/cgen.sld b/scheme/cyclone/cgen.sld index 602fccd5..dc90cc38 100644 --- a/scheme/cyclone/cgen.sld +++ b/scheme/cyclone/cgen.sld @@ -649,12 +649,12 @@ (and (> len 0) (equal? end (substring str (- len 1) len))))) -TODO: move this into prim module, integrate with existing function somehow -;;(define (prim->c-func* p use-alloca?) -;; (cond -;; (else -;; (prim->c-func p)))) -TODO: add use-alloca? param to prim:allocates-object? and modify per above +;;TODO: move this into prim module, integrate with existing function somehow +;;;;(define (prim->c-func* p use-alloca?) +;;;; (cond +;;;; (else +;;;; (prim->c-func p)))) +;;TODO: add use-alloca? param to prim:allocates-object? and modify per above ;; c-compile-prim : prim-exp -> string -> string (define (c-compile-prim p cont ast-id) @@ -669,7 +669,7 @@ TODO: add use-alloca? param to prim:allocates-object? and modify per above ((closure)" (cgen:mangle-global p) ")->fn)") - (prim->c-func p))) + (prim->c-func p use-alloca?))) ;; Following closure defs are only used for prim:cont? to ;; create a new closure for the continuation, if needed. ;; @@ -750,7 +750,7 @@ TODO: add use-alloca? param to prim:allocates-object? and modify per above ;; (let ((cv-name (mangle (gensym 'c)))) (c-code/vars - (if (prim:allocates-object? p) + (if (prim:allocates-object? p use-alloca?) cv-name ;; Already a pointer (string-append "&" cv-name)) ;; Point to data (list @@ -966,6 +966,7 @@ TODO: add use-alloca? param to prim:allocates-object? and modify per above (cond ;; Handle recursive calls via iteration, if possible ((and ast-fnc + #f ;; TODO: temporarily disabled (adbf:calls-self? ast-fnc) (self-closure-call? fun (car (adbf:all-params ast-fnc))) ) diff --git a/scheme/cyclone/primitives.sld b/scheme/cyclone/primitives.sld index 1a0319dd..154642c0 100644 --- a/scheme/cyclone/primitives.sld +++ b/scheme/cyclone/primitives.sld @@ -457,7 +457,21 @@ (define (prim-call? exp) (and (list? exp) (prim? (car exp)))) - (define (prim->c-func p) + (define (prim->c-func p use-alloca?) + (cond + (use-alloca? + ;; Special case, when this flag is set the compiler is requesting a + ;; primitive that will allocate data, so any new objects must be + ;; created via alloca or such, and cannot be declared as stack vars. + ;; This is to support C loops in place of recursion. + (cond + ((eq? p 'cons) "alloca_pair") + (else + (_prim->c-func p)))) + (else + (_prim->c-func p)))) + + (define (_prim->c-func p) (cond ((eq? p 'Cyc-global-vars) "Cyc_get_global_variables") ((eq? p 'Cyc-get-cvar) "Cyc_get_cvar") @@ -876,9 +890,10 @@ ;; Does primitive allocate an object? ;; TODO: these are the functions that are defined via macros. This method ;; is obsolete and should be replaced by prim:cont? functions over time. - (define (prim:allocates-object? exp) + (define (prim:allocates-object? exp use-alloca?) (and (prim? exp) - (member exp '()))) + use-alloca? + (member exp '(cons)))) ;; Does the primitive only accept/return immutable objects? ;; This is useful during optimization