;;;; -*- Mode: Lisp; Syntax: Common-Lisp; indent-tabs-mode: nil; Package: C -*- ;;;; vim: set filetype=lisp tabstop=8 shiftwidth=2 expandtab: ;;;; ;;;; Copyright (c) 1984, Taiichi Yuasa and Masami Hagiya. ;;;; Copyright (c) 1990, Giuseppe Attardi. ;;;; Copyright (c) 2023, Daniel KochmaƄski. ;;;; ;;;; See the file 'LICENSE' for the copyright details. ;;;; ;;;; CMPEXIT Exit manager. ;;;; ;;;; The exit manager has two main operators that unwind the dynamic context: ;;;; ;;;; (UNWIND-EXIT value) carries VALUE to *DESTINATION* and unwinds to *EXIT* ;;;; (UNWIND-JUMP label) unwinds to LABEL ;;;; (UNWIND-COND label) unwinds to LABEL (conditionally) ;;;; (UNWIND-FLEE label) escapes to LABEL (runtime unwind) ;;;; (in-package "COMPILER") (defun unwind-exit (loc) (flet ((unwind-cond-p () (and (consp *destination*) (member (si:cons-car *destination*) '(JUMP-FALSE JUMP-TRUE)))) (unwind-jump-p () (labelp *exit*)) (unwind-exit-p () (eq *exit* 'LEAVE))) (cond ((unwind-cond-p) (unwind-cjump loc)) ((unwind-jump-p) (unwind-label loc)) ((unwind-exit-p) (unwind-leave loc)) (t (baboon-exit-invalid *exit*))))) (defun unwind-jump (exit) (%unwind (label-denv exit) *unwind-exit*) (%goto exit)) (defun unwind-cont (exit) (%unwind (label-denv exit) *unwind-exit*) (%goto exit)) (defun unwind-flee (exit kind) (%escape exit kind)) (defun unwind-cond (exit kind &rest args) (%branch exit *unwind-exit* kind args)) ;;; (defun baboon-exit-not-found (exit) (baboon :format-control "The value of exit~%~A~%is not found in *UNWIND-EXIT*~%~A" :format-arguments (list exit *unwind-exit*))) (defun baboon-exit-invalid (exit) (baboon :format-control "The value of exit~%~A~%is not valid." :format-arguments (list exit))) (defun baboon-unwind-invalid (unwind-to unwind-from) (baboon :format-control "The unwind value~%~A~%is not a tail of the unwind value~%~A" :format-arguments (list unwind-to unwind-from))) (defun baboon-unwind-exit (exit) (baboon :format-control "The value of exit~%~A~%found in *UNWIND-EXIT*~%~A~%is not valid." :format-arguments (list exit *unwind-exit*))) (defun destination-value-matters-p (dest) (declare (si::c-local)) (if (atom dest) (not (eq dest 'TRASH)) (not (member (car dest) '(JUMP-FALSE JUMP-TRUE))))) ;;; UNWIND-EXIT TAGS PURPOSE ;;; ;;; FRAME -> ecl_frs_push() ;;; (STACK frame) -> ecl_stack_frame_open(env, frame, initial_size) ;;; IHS -> ihs push ;;; IHS-ENV -> ihs push ;;; BDS-BIND -> binding of 1 special variable ;;; (LCL n) -> binding stack pointer to Nth local variable ;;; LEAVE -> outermost location ;;; #