comp-known-ret-types))))
(comp-emit (list 'set (comp-slot) call)))
+(defmacro comp-emit-set-call-subr (subr-name &optional c-fun-name)
+ "Emit a call for SUBR-NAME using C-FUN-NAME.
+If C-FUN-NAME is nil will be guessed from SUBR-NAME."
+ (let* ((arity (subr-arity (symbol-function subr-name)))
+ (minarg (car arity))
+ (maxarg (cdr arity)))
+ (unless c-fun-name
+ (setq c-fun-name
+ (intern (concat "F"
+ (replace-regexp-in-string
+ "-" "_"
+ (symbol-name subr-name))))))
+ (if (eq maxarg 'many)
+ (progn
+ (cl-assert (= minarg 0))
+ `(error "To be implemented"))
+ (cl-assert (= minarg maxarg))
+ `(let ((c-fun-name ',c-fun-name)
+ (slots (cl-loop for i from 0 below ,maxarg
+ collect (comp-slot-n (+ i (comp-sp))))))
+ (comp-emit-set-call `(call ,c-fun-name ,@slots))))))
+
(defun comp-copy-slot-n (n)
"Set current slot with slot number N as source."
(let ((src-slot (comp-slot-n n)))
"Emit annotation STR."
(comp-emit `(comment ,str)))
-(defun comp-set-const (val)
+(defun comp-emit-set-const (val)
"Set constant VAL to current slot."
(setf (comp-slot) (make-comp-mvar :slot (comp-sp)
:const-vld t
name))))
(defmacro comp-op-case (&rest cases)
- "Expand CASES into the corresponding pcase."
+ "Expand CASES into the corresponding pcase.
+This is responsible for generating the proper stack adjustment when known."
(declare (debug (body))
(indent defun))
`(pcase op
(byte-memq)
(byte-not)
(byte-car
- (comp-emit-set-call `(call Fcar ,(comp-slot))))
+ (comp-emit-set-call-subr car))
(byte-cdr
- (comp-emit-set-call `(call Fcdr ,(comp-slot))))
+ (comp-emit-set-call-subr cdr))
(byte-cons
- (comp-emit-set-call `(call Fcons ,(comp-slot) ,(comp-slot-next))))
+ (comp-emit-set-call-subr cons))
(byte-list1
(comp-limplify-listn 1))
(byte-list2
(byte-list4
(comp-limplify-listn 4))
(byte-length
- (comp-emit-set-call `(call Flength ,(comp-slot))))
+ (comp-emit-set-call-subr length))
(byte-aref
- (comp-emit-set-call `(call Faref
- ,(comp-slot)
- ,(comp-slot-next))))
+ (comp-emit-set-call-subr aref))
(byte-aset
- (comp-emit-set-call `(call Faset
- ,(comp-slot)
- ,(comp-slot-next)
- ,(comp-slot-n (+ 2 (comp-sp))))))
+ (comp-emit-set-call-subr aset))
(byte-symbol-value
- (comp-emit-set-call `(call Fsymbol_value ,(comp-slot))))
+ (comp-emit-set-call-subr symbol-value))
(byte-symbol-function)
(byte-set)
(byte-fset)
(byte-discardN)
(byte-switch)
(byte-constant
- (comp-set-const arg)))))
+ (comp-emit-set-const arg)))))
(defun comp-limplify (func)
"Given FUNC compute its LIMPLE ir."