mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-12 15:27:36 +02:00
WIP - optionally emit alloca-based prims
This commit is contained in:
parent
b2a981b7e5
commit
be5a5f1c6b
2 changed files with 27 additions and 11 deletions
|
@ -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)))
|
||||
)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue