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: 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.

View file

@ -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)