21
23
(in-package "COMPILER")
23
25
(defun c1with-stack (forms)
24
(let ((body (c1expr `(progn ,@forms))))
25
(make-c1form* 'WITH-STACK :type (c1form-type body)
26
(let* ((var (pop forms))
27
(body (c1expr `(let ((,var (innermost-stack-frame))) ,@forms))))
28
(make-c1form* 'WITH-STACK
29
:type (c1form-type body)
32
(defvar +ecl-stack-frame-variable+ "_ecl_inner_frame")
28
34
(defun c2with-stack (body)
29
35
(let* ((new-destination (tmp-destination *destination*))
31
(sp (make-lcl-var :rep-type :cl-index)))
32
(wt-nl "{cl_index " sp "=cl_stack_index();")
37
(wt-nl "{ struct ecl_stack_frame _ecl_inner_frame_aux;")
38
(wt-nl *volatile* "cl_object _ecl_inner_frame = (_ecl_inner_frame_aux.narg=0,_ecl_inner_frame_aux.sp=0,_ecl_inner_frame_aux.t=t_frame,(cl_object)&_ecl_inner_frame_aux);")
33
39
(let* ((*destination* new-destination)
34
(*unwind-exit* `((STACK ,sp) ,@*unwind-exit*)))
40
(*unwind-exit* `((STACK ,+ecl-stack-frame-variable+) ,@*unwind-exit*)))
36
(wt-nl "cl_stack_set_index(" sp ");}")
42
(wt-nl "ecl_stack_frame_close(_ecl_inner_frame);}")
37
43
(unwind-exit new-destination)))
45
(defun c1innermost-stack-frame (args)
46
(c1expr `(c-inline () () :object ,+ecl-stack-frame-variable+
47
:one-liner t :side-effects nil)))
39
49
(defun c1stack-push (args)
41
(c-inline ,args (t) :void "cl_stack_push(#0)"
51
(c-inline ,args (t t) :void "ecl_stack_frame_push(#0,#1)"
42
52
:one-liner t :side-effects t)
45
55
(defun c1stack-push-values (args)
46
(make-c1form* 'STACK-PUSH-VALUES :type 'fixnum
47
:args (c1expr (first args))
48
(c1expr `(c-inline () () fixnum "cl_stack_push_values()"
49
:one-liner t :side-effects t))))
56
(let ((frame-var (pop args))
58
(make-c1form* 'STACK-PUSH-VALUES :type '(VALUES)
61
(c1expr `(c-inline (,frame-var) (t) :void "ecl_stack_frame_push_values(#0)"
62
:one-liner t :side-effects t)))))
51
64
(defun c2stack-push-values (form push-statement)
52
65
(let ((*destination* 'VALUES))
54
67
(c2expr push-statement))
56
69
(defun c1stack-pop (args)
57
(let ((action (c1expr `(c-inline ,args (fixnum) :void
58
"cl_stack_pop_values(#0)"
61
(make-c1form* 'STACK-POP :type t :args action)))
63
(defun c2stack-pop (action)
64
(let ((*destination* 'TRASH))
66
(unwind-exit 'VALUES))
68
(defun c1apply-from-stack (args)
69
(c1expr `(c-inline ,args (fixnum t) (values &rest t) "cl_apply_from_stack(#0,#1);"
70
(c1expr `(c-inline ,args (t) (values &rest t)
71
"VALUES(0)=ecl_stack_frame_pop_values(#0);"
72
:one-liner nil :side-effects t)))
74
(defun c1apply-from-stack-frame (args)
75
(c1expr `(c-inline ,args (t t) (values &rest t)
76
"VALUES(0)=ecl_apply_from_stack_frame(#0,#1);"
70
77
:one-liner nil :side-effects t)))
72
79
(put-sysprop 'with-stack 'C1 #'c1with-stack)
73
80
(put-sysprop 'with-stack 'c2 #'c2with-stack)
81
(put-sysprop 'innermost-stack-frame 'C1 #'c1innermost-stack-frame)
74
82
(put-sysprop 'stack-push 'C1 #'c1stack-push)
75
83
(put-sysprop 'stack-push-values 'C1 #'c1stack-push-values)
76
84
(put-sysprop 'stack-push-values 'C2 #'c2stack-push-values)
77
85
(put-sysprop 'stack-pop 'C1 #'c1stack-pop)
78
(put-sysprop 'stack-pop 'C2 #'c2stack-pop)
79
(put-sysprop 'apply-from-stack 'c1 #'c1apply-from-stack)
b'\\ No newline at end of file'
86
(put-sysprop 'si::apply-from-stack-frame 'c1 #'c1apply-from-stack-frame)
b'\\ No newline at end of file'