"Slot into the meta-stack pointed by sp + 1."
'(comp-slot-n (1+ (comp-sp))))
-(defun comp-push-call (src-slot)
- "Push call SRC-SLOT into frame."
- (cl-assert src-slot)
- (cl-incf (comp-sp))
+(defun comp-emit-call (call)
+ "Emit CALL."
+ (cl-assert call)
(setf (comp-slot)
(make-comp-mvar :slot (comp-sp)
- :type (alist-get (cadr src-slot)
+ :type (alist-get (cadr call)
comp-known-ret-types)))
- (push (list 'set (comp-slot) src-slot) comp-limple))
+ (push (list 'set (comp-slot) call) comp-limple))
+
+(defun comp-push-call (call)
+ "Push call CALL into frame."
+ (cl-incf (comp-sp))
+ (comp-emit-call call))
(defun comp-push-slot-n (n)
"Push slot number N into frame."
:constant val))
(push (list 'setimm (comp-slot) val) comp-limple))
-(defun comp-push-block (bblock)
+(defun comp-emit-block (bblock)
"Push basic block BBLOCK."
(push bblock (comp-func-blocks comp-func))
;; Every new block we are forced to wipe out all the frame.
(defun comp-limplify-listn (n)
"Limplify list N."
- (comp-pop 1)
- (comp-push-call `(call Fcons ,(comp-slot-next)
+ (comp-emit-call `(call Fcons ,(comp-slot)
,(make-comp-mvar :const-vld t
:constant nil)))
(dotimes (_ (1- n))
- (comp-pop 2)
- (comp-push-call `(call Fcons
- ,(comp-slot-next)
- ,(comp-slot-n (+ 2 (comp-sp)))))))
+ (comp-pop 1)
+ (comp-emit-call `(call Fcons
+ ,(comp-slot)
+ ,(comp-slot-n (1+ (comp-sp)))))))
(defun comp-limplify-lap-inst (inst)
"Limplify LAP instruction INST accumulating in `comp-limple'."
:const-vld t
:constant (cadr inst)))))
;; ('byte-varset
- ;; (comp-push-call `(call Fsymbol_value ,(cadr inst))))
+ ;; (comp-emit-call `(call Fsymbol_value ,(cadr inst))))
('byte-constant
(comp-push-const (cadr inst)))
('byte-stack-ref
(comp-push-slot-n (- (comp-sp) (cdr inst))))
('byte-plus
- (comp-pop 2)
- (comp-push-call `(callref Fplus 2 ,(comp-sp))))
- ('byte-car
(comp-pop 1)
- (comp-push-call `(call Fcar ,(comp-slot))))
- ('byte-cdr
+ (comp-emit-call `(callref Fplus 2 ,(comp-sp))))
+ ('byte-cons
(comp-pop 1)
- (comp-push-call `(call Fcdr ,(comp-slot))))
+ (comp-emit-call `(call Fcons ,(comp-slot) ,(comp-slot-next))))
+ ('byte-car
+ (comp-emit-call `(call Fcar ,(comp-slot))))
+ ('byte-cdr
+ (comp-emit-call `(call Fcdr ,(comp-slot))))
('byte-car-safe
- (comp-pop 1)
- (comp-push-call `(call Fcar_safe ,(comp-slot))))
+ (comp-emit-call `(call Fcar_safe ,(comp-slot))))
('byte-cdr-safe
- (comp-pop 1)
- (comp-push-call `(call Fcdr_safe ,(comp-slot))))
+ (comp-emit-call `(call Fcdr_safe ,(comp-slot))))
('byte-list1
(comp-limplify-listn 1))
('byte-list2
:frame (comp-limple-frame-new-frame frame-size)))
(comp-limple ()))
;; Prologue
- (comp-push-block 'entry)
+ (comp-emit-block 'entry)
(comp-emit-annotation (concat "Lisp function: "
(symbol-name (comp-func-symbol-name func))))
(cl-loop for i below (comp-args-mandatory (comp-func-args func))
(push `(setpar ,(comp-slot) ,i) comp-limple)))
(push '(jump body) comp-limple)
;; Body
- (comp-push-block 'body)
+ (comp-emit-block 'body)
(mapc #'comp-limplify-lap-inst (comp-func-ir func))
(setf (comp-func-ir func) (reverse comp-limple))
;; Prologue block must be first
(should (= (comp-tests-cdr-safe-f '(1 . 2)) 2))
(should (null (comp-tests-cdr-safe-f 'a))))
-;; (ert-deftest comp-tests-cons-car-cdr ()
-;; "Testing cons car cdr."
-;; (defun comp-tests-cons-car-f ()
-;; (car (cons 1 2)))
-;; (native-compile #'comp-tests-cons-car-f)
+(ert-deftest comp-tests-cons-car-cdr ()
+ "Testing cons car cdr."
+ (defun comp-tests-cons-car-f ()
+ (car (cons 1 2)))
+ (native-compile #'comp-tests-cons-car-f)
-;; (defun comp-tests-cons-cdr-f (x)
-;; (cdr (cons 'foo x)))
-;; (native-compile #'comp-tests-cons-cdr-f)
+ (defun comp-tests-cons-cdr-f (x)
+ (cdr (cons 'foo x)))
+ (native-compile #'comp-tests-cons-cdr-f)
-;; (should (= (comp-tests-cons-car-f) 1))
-;; (should (= (comp-tests-cons-cdr-f 3) 3)))
+ (should (= (comp-tests-cons-car-f) 1))
+ (should (= (comp-tests-cons-cdr-f 3) 3)))
;; (ert-deftest comp-tests-varset ()
;; "Testing varset."