diff --git a/src/cmp/cmpbackend-cxx/cmpc-util.lsp b/src/cmp/cmpbackend-cxx/cmpc-util.lsp index e64f3e28a..36dea2ad7 100644 --- a/src/cmp/cmpbackend-cxx/cmpc-util.lsp +++ b/src/cmp/cmpbackend-cxx/cmpc-util.lsp @@ -38,18 +38,19 @@ ;;; *tail-recursion-info* holds NIL, if tail recursion is impossible. ;;; If possible, *tail-recursion-info* holds -;;; ( c1-lambda-form required-arg .... required-arg ), +;;; ( c1-lambda-form required-arg .... required-arg ), ;;; where each required-arg is a var-object. (defvar *tail-recursion-info* nil) +(defvar *tail-recursion-mark* nil) ;;; --cmpexit.lsp-- ;;; ;;; *exit* holds an 'exit', which is ;; LABEL instance or LEAVE. ;;; *unwind-exit* holds a list consisting of: -;; LABEL instance, LEAVE, TAIL-RECURSION-MARK, FRAME, JUMP, BDS-BIND (each -;; pushed for a single special binding), or a LCL (which holds the bind -;; stack pointer used to unbind). +;; LABEL instance, LEAVE, FRAME, JUMP, BDS-BIND (each pushed for a single +;; special binding), or a LCL (which holds the bind stack pointer used to +;; unbind). ;;; (defvar *exit*) diff --git a/src/cmp/cmpbackend-cxx/cmpc-wt.lsp b/src/cmp/cmpbackend-cxx/cmpc-wt.lsp index 3efd1f76d..6a5cc7fdd 100644 --- a/src/cmp/cmpbackend-cxx/cmpc-wt.lsp +++ b/src/cmp/cmpbackend-cxx/cmpc-wt.lsp @@ -110,6 +110,10 @@ ;;; LABELS AND JUMPS ;;; +(defun wt-nl-go (label) + (wt-nl-indent) + (wt-go label)) + (defun wt-go (label) (setf (label-used-p label) t) (wt "goto L" (label-id label) ";")) diff --git a/src/cmp/cmpbackend-cxx/cmppass2-call.lsp b/src/cmp/cmpbackend-cxx/cmppass2-call.lsp index 1736881b5..a95dfa30f 100644 --- a/src/cmp/cmpbackend-cxx/cmppass2-call.lsp +++ b/src/cmp/cmpbackend-cxx/cmppass2-call.lsp @@ -82,7 +82,7 @@ (defun tail-recursion-possible () (dolist (ue *unwind-exit* (baboon :format-control "tail-recursion-possible: should never return.")) - (cond ((eq ue 'TAIL-RECURSION-MARK) + (cond ((eq ue *tail-recursion-mark*) (return t)) ((or (eq ue 'BDS-BIND) (eq ue 'FRAME)) (return nil)) @@ -103,8 +103,7 @@ (let ((*destination* 'TRASH)) ;; We do not provide any C2FORM. (c2psetq nil (cdr *tail-recursion-info*) args))) - (unwind-no-exit 'TAIL-RECURSION-MARK) - (wt-nl "goto TTL;") + (unwind-jump *tail-recursion-mark*) (cmpdebug "Tail-recursive call of ~s was replaced by iteration." (fun-name fun)) t)) diff --git a/src/cmp/cmpbackend-cxx/cmppass2-cont.lsp b/src/cmp/cmpbackend-cxx/cmppass2-cont.lsp index 3fb87f870..bc3eee14b 100644 --- a/src/cmp/cmpbackend-cxx/cmppass2-cont.lsp +++ b/src/cmp/cmpbackend-cxx/cmppass2-cont.lsp @@ -124,12 +124,8 @@ (defun c2go (c1form tag nonlocal) (declare (ignore c1form)) (if nonlocal - (let ((var (tag-var tag))) - (wt-nl "cl_go(" var ",ecl_make_fixnum(" (tag-index tag) "));")) - ;; local go - (progn - (unwind-no-exit* (tag-jump tag)) - (wt-nl) (wt-go (tag-jump tag))))) + (wt-nl "cl_go(" (tag-var tag) ",ecl_make_fixnum(" (tag-index tag) "));") + (unwind-jump (tag-jump tag)))) (defun c2throw (c1form tag val &aux loc) diff --git a/src/cmp/cmpbackend-cxx/cmppass2-eval.lsp b/src/cmp/cmpbackend-cxx/cmppass2-eval.lsp index d28a318fd..eac228551 100644 --- a/src/cmp/cmpbackend-cxx/cmppass2-eval.lsp +++ b/src/cmp/cmpbackend-cxx/cmppass2-eval.lsp @@ -154,43 +154,25 @@ (multiple-value-bind (constantp value) (loc-immediate-value-p loc) (cond ((not constantp) - (cond ((eq (loc-representation-type loc) :bool) - (wt-nl "if (" loc ") {")) - (t - (wt-nl "if ((") - (wt-coerce-loc :object loc) - (wt ")!=ECL_NIL) {"))) - (cond ((unwind-no-exit label) - (incf *opened-c-braces*) - (wt-nl) (wt-go label) - (wt-nl-close-brace)) - (t - (wt " ") (wt-go label) (wt " }")))) - ((null value)) - (t - (unwind-no-exit label) - (wt-nl) (wt-go label))))) + (case (loc-representation-type loc) + (:bool (wt-nl "if (" loc ")")) + (:object (wt-nl "if (" loc "!=ECL_NIL)")) + (otherwise (wt-nl "if ((") (wt-coerce-loc :object loc) (wt ")!=ECL_NIL)"))) + (wt-open-brace) (unwind-jump label) (wt-nl-close-brace)) + ((not (null value)) + (unwind-jump label))))) (defun set-jump-false (loc label) (multiple-value-bind (constantp value) (loc-immediate-value-p loc) (cond ((not constantp) - (cond ((eq (loc-representation-type loc) :bool) - (wt-nl "if (!(" loc ")) {")) - (t - (wt-nl "if (Null(") - (wt-coerce-loc :object loc) - (wt ")) {"))) - (cond ((unwind-no-exit label) - (incf *opened-c-braces*) - (wt-nl) (wt-go label) - (wt-nl-close-brace)) - (t - (wt " ") (wt-go label) (wt " }")))) - (value) - (t - (unwind-no-exit label) - (wt-nl) (wt-go label))))) + (case (loc-representation-type loc) + (:bool (wt-nl "if (!(" loc "))")) + (:object (wt-nl "if (Null(" loc "))")) + (otherwise (wt-nl "if (Null(") (wt-coerce-loc :object loc) (wt "))"))) + (wt-open-brace) (unwind-jump label) (wt-nl-close-brace)) + ((null value) + (unwind-jump label))))) (defun c2mv-prog1 (c1form form body) (wt-nl-open-brace) diff --git a/src/cmp/cmpbackend-cxx/cmppass2-exit.lsp b/src/cmp/cmpbackend-cxx/cmppass2-exit.lsp index 71b966e1b..45112c249 100644 --- a/src/cmp/cmpbackend-cxx/cmppass2-exit.lsp +++ b/src/cmp/cmpbackend-cxx/cmppass2-exit.lsp @@ -37,7 +37,6 @@ ;;; #