mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-12 23:37:38 +02:00
Only emit funcall macros that are used by the generated code
This commit is contained in:
parent
b946e75a02
commit
503770a899
2 changed files with 12 additions and 11 deletions
4
TODO
4
TODO
|
@ -1,9 +1,5 @@
|
||||||
Working TODO list:
|
Working TODO list:
|
||||||
|
|
||||||
- Only emit funcall* / return_funcall* definitions for cases that are actually used.
|
|
||||||
IE, do not emit funcall9 just because funcall10 is required
|
|
||||||
|
|
||||||
|
|
||||||
- Error handling
|
- Error handling
|
||||||
need to perform much more error handling of input code. one of the biggest is to report if a function is passed the wrong number of arguments, as this will result in segfauls, bad transport errors, etc downstream if it is allowed.
|
need to perform much more error handling of input code. one of the biggest is to report if a function is passed the wrong number of arguments, as this will result in segfauls, bad transport errors, etc downstream if it is allowed.
|
||||||
|
|
||||||
|
|
19
cgen.scm
19
cgen.scm
|
@ -87,15 +87,17 @@
|
||||||
return 0;}")
|
return 0;}")
|
||||||
|
|
||||||
;;; Auto-generation of C macros
|
;;; Auto-generation of C macros
|
||||||
(define *c-call-arity* 5)
|
(define *c-call-max-args* 128)
|
||||||
|
(define *c-call-arity* (make-vector (+ 1 *c-call-max-args*) #f))
|
||||||
|
|
||||||
(define (set-c-call-arity! arity)
|
(define (set-c-call-arity! arity)
|
||||||
(cond
|
(cond
|
||||||
((not (number? arity))
|
((not (number? arity))
|
||||||
(error `(Non-numeric number of arguments received ,arity)))
|
(error `(Non-numeric number of arguments received ,arity)))
|
||||||
|
((> arity *c-call-max-args*)
|
||||||
|
(error "Only support up to 128 arguments. Received: " arity))
|
||||||
(else
|
(else
|
||||||
(if (> arity *c-call-arity*)
|
(vector-set! *c-call-arity* arity #t))))
|
||||||
(set! *c-call-arity* arity)))))
|
|
||||||
|
|
||||||
(define (emit-c-macros)
|
(define (emit-c-macros)
|
||||||
(c-macro-declare-globals)
|
(c-macro-declare-globals)
|
||||||
|
@ -103,10 +105,13 @@
|
||||||
(emit-c-arity-macros 0))
|
(emit-c-arity-macros 0))
|
||||||
|
|
||||||
(define (emit-c-arity-macros arity)
|
(define (emit-c-arity-macros arity)
|
||||||
(when (<= arity *c-call-arity*)
|
(when (<= arity *c-call-max-args*)
|
||||||
(emit (c-macro-funcall arity))
|
(cond
|
||||||
(emit (c-macro-return-funcall arity))
|
((or (= arity 1) (= arity 2)
|
||||||
(emit (c-macro-return-check arity))
|
(vector-ref *c-call-arity* arity))
|
||||||
|
(emit (c-macro-funcall arity))
|
||||||
|
(emit (c-macro-return-funcall arity))
|
||||||
|
(emit (c-macro-return-check arity))))
|
||||||
(emit-c-arity-macros (+ arity 1))))
|
(emit-c-arity-macros (+ arity 1))))
|
||||||
|
|
||||||
(define (c-macro-return-funcall num-args)
|
(define (c-macro-return-funcall num-args)
|
||||||
|
|
Loading…
Add table
Reference in a new issue