When you read a program in a language L into a new ctview or one containing a program in a different language, Centaur calls the function:
({L}:set-environment
if it exists, to install the L environment. Installation involves the creation of tools, tool networks, graphical changes to the ctview, etc.
Similarly, before changing environments in a ctview or killing a ctview, Centaur calls the function:
({L}:clear-environment
so that you may clean up the installed environment.
We define the following functions in contrib/Exp/environment/Exp.ll
The first step towards building the Exp environment is to define the {Exp}:set-environment function. This function should be very simple -just general initialization and then calls to functions that construct each specified tool. Our setup function would thus be:
;;Environment for Exp. (setq #:sys-package:colon '#:Exp-environment) ;;;;;;;;;;;;;;;; ;;Setup ;;;;;;;;;;;;;;;; (de {Exp}:set-environment (ctview) (:initialize-environment ctview) (#:Exp:interpreter:create ctview) ctview )
We will define the function that creates the interpreter shortly. To initialize the ctedit and ctview that contain the Exp program, we:
;;;;;;;;;;;;;;;; ;;Initialization ;;;;;;;;;;;;;;;; (defvar :popup ()) (de :initialize-environment (ctview) (let ((ctedit (send 'object ctview))) ;;Name the ctedit for resources. (#:properties:set-user-property ctedit 'Editor 'Exp) ;;Create a popup and assign it to the current ctedit. (setq :popup ({menu}:create 0 0 'column)) ({ctedit}:popup ctedit :popup) ;;Redraw to take new resources into account. ({ctedit}:redraw ctedit) )) ;;Convenience function used by tools. (de :handle-button (network title sig) (let ((but (create-std-environment-button network title () sig t))) ({menu}:add-button :popup but) ))
The create-std-environment-button function creates a button and adds it to a tool network. When activated, the button emits the specified signal, which is received by an stnode encapsulating the tool. This function only creates the button and inserts it in the network. Our convenience function then adds the button to the popup menu.
Finally, since a ctedit may be reused for programs belonging to a different formalism, we must define a cleanup function to remove the ctedit name, remove the popup menu, and kill all standard tool networks.
;;;;;;;;;;;;;;;; ;;Cleanup ;;;;;;;;;;;;;;;; (de {Exp}:clear-environment (ctview) (let ((ctedit (send 'object ctview))) ;;Clear the ctedit name. (#:properties:reset-properties ctedit) ;;Clear the popup ({ctedit}:popup ctedit ()) ;;Kill all tool networks. (cleanup-std-environment ctview) ))