Only emit funcall macros that are used by the generated code

This commit is contained in:
Justin Ethier 2015-04-01 15:11:19 -04:00
parent b946e75a02
commit 503770a899
2 changed files with 12 additions and 11 deletions

4
TODO
View file

@ -1,9 +1,5 @@
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
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.

View file

@ -87,15 +87,17 @@
return 0;}")
;;; 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)
(cond
((not (number? arity))
(error `(Non-numeric number of arguments received ,arity)))
((> arity *c-call-max-args*)
(error "Only support up to 128 arguments. Received: " arity))
(else
(if (> arity *c-call-arity*)
(set! *c-call-arity* arity)))))
(vector-set! *c-call-arity* arity #t))))
(define (emit-c-macros)
(c-macro-declare-globals)
@ -103,10 +105,13 @@
(emit-c-arity-macros 0))
(define (emit-c-arity-macros arity)
(when (<= arity *c-call-arity*)
(emit (c-macro-funcall arity))
(emit (c-macro-return-funcall arity))
(emit (c-macro-return-check arity))
(when (<= arity *c-call-max-args*)
(cond
((or (= arity 1) (= arity 2)
(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))))
(define (c-macro-return-funcall num-args)