cmp: cleanup: use with-c1form-env in applicable places

c2expr, t2expr, t3function all uses the macro now. That yields gives better
introspection environment and more regular handling.

Additionally bind a new variable *CURRENT-C1FORM*.
This commit is contained in:
Daniel Kochmański 2023-12-11 18:39:44 +01:00
parent c69963f47c
commit 63ca129a79
4 changed files with 32 additions and 30 deletions

View file

@ -14,7 +14,9 @@
(let* ((name (c1form-name form))
(args (c1form-args form))
(dispatch (gethash name *c2-dispatch-table*)))
(apply dispatch form args))))
(if dispatch
(apply dispatch form args)
(cmperr "Unhandled C2FORM found at the:~%~4I~A" form)))))
(defun c2expr* (form)
;; C2EXPR* compiles the giving expression in a context in which

View file

@ -35,14 +35,13 @@
(defun t2expr (form)
(check-type form c1form)
(ext:if-let ((def (gethash (c1form-name form) *t2-dispatch-table*)))
(let ((*compile-file-truename* (c1form-file form))
(*compile-file-position* (c1form-file-position form))
(*current-toplevel-form* (c1form-form form))
(*current-form* (c1form-form form))
(*cmp-env* (c1form-env form)))
(apply def form (c1form-args form)))
(cmperr "Unhandled T2FORM found at the toplevel:~%~4I~A" form)))
(with-c1form-env (form form)
(let* ((name (c1form-name form))
(args (c1form-args form))
(dispatch (gethash name *t2-dispatch-table*)))
(if dispatch
(apply dispatch form args)
(cmperr "Unhandled T2FORM found at the toplevel:~%~4I~A" form)))))
(defun t2compiler-let (c1form symbols values body)
(declare (ignore c1form))
@ -314,27 +313,26 @@
(when *compile-print*
(ext:when-let ((name (or (fun-name fun) (fun-description fun))))
(format t "~&;;; Emitting code for ~s.~%" name)))
(let* ((lambda-expr (fun-lambda fun))
(*cmp-env* (c1form-env lambda-expr))
(*tail-recursion-info* fun)
(*tail-recursion-mark* nil))
(with-bir-env (:env (fun-env fun)
:level (fun-lexical-levels fun)
:volatile (c1form-volatile* lambda-expr))
(t3function-declaration fun)
(wt-nl-open-brace)
(let ((body (t3function-body fun)))
(wt-function-locals (fun-closure fun))
(wt-nl "const cl_env_ptr cl_env_copy = ecl_process_env();")
(when (eq (fun-closure fun) 'CLOSURE)
(wt-nl "cl_object " *volatile* "env0 = cl_env_copy->function->cclosure.env;"))
(wt-nl "cl_object " *volatile* "value0;")
(when (policy-check-stack-overflow)
(wt-nl "ecl_cs_check(cl_env_copy,value0);"))
(when (eq (fun-closure fun) 'CLOSURE)
(t3function-closure-scan fun))
(write-sequence body *compiler-output1*)
(wt-nl-close-many-braces 0)))))
(with-c1form-env (lambda-expr (fun-lambda fun))
(let ((*tail-recursion-info* fun)
(*tail-recursion-mark* nil))
(with-bir-env (:env (fun-env fun)
:level (fun-lexical-levels fun)
:volatile (c1form-volatile* lambda-expr))
(t3function-declaration fun)
(wt-nl-open-brace)
(let ((body (t3function-body fun)))
(wt-function-locals (fun-closure fun))
(wt-nl "const cl_env_ptr cl_env_copy = ecl_process_env();")
(when (eq (fun-closure fun) 'CLOSURE)
(wt-nl "cl_object " *volatile* "env0 = cl_env_copy->function->cclosure.env;"))
(wt-nl "cl_object " *volatile* "value0;")
(when (policy-check-stack-overflow)
(wt-nl "ecl_cs_check(cl_env_copy,value0);"))
(when (eq (fun-closure fun) 'CLOSURE)
(t3function-closure-scan fun))
(write-sequence body *compiler-output1*)
(wt-nl-close-many-braces 0))))))
(defun t3function-body (fun)
(let ((string (make-array 2048 :element-type 'character

View file

@ -178,6 +178,7 @@
(defmacro with-c1form-env ((form value) &rest body)
`(let* ((,form ,value)
(*current-c1form* ,form)
(*compile-file-truename* (c1form-file ,form))
(*compile-file-position* (c1form-file-position ,form))
(*current-toplevel-form* (c1form-toplevel-form ,form))

View file

@ -24,6 +24,7 @@
;;; Variables and constants for error handling
;;;
(defvar *current-form* '|compiler preprocess|)
(defvar *current-c1form*)
(defvar *current-toplevel-form* '|compiler preprocess|)
(defvar *compile-file-position* -1)
(defvar *active-protection* nil)