The tool network

The function that creates the interpreter tool network must create an instance of the tool class defined above. It must include the tool in a standard Typol tool network then add other network components specific to the Exp environment to send and receive signals.

In order to include the tool in the standard network, we need to define an stnode class, then create an instance to encapsulate the tool. We define the following stnode class so that evaluation may be triggered by the signal interpret:


   (st-declare Exp-interpreter 
               ;;Input signals
               (interpret) 
               ;;Output signals
               ())

Now we may create the interpreter tool network:


;;;;;;;;;;;;;;
;;Tool network creation
;;;;;;;;;;;;;;
(setq #:sys-package:colon '#:Exp:interpreter)

(de :create (ctview)
    (lets ((ctedit (send 'object ctview))
           (tool (:tool:create ctedit))
           (network (ty-tool-create-std-network tool
                                                'Exp-interpreter 
                                                ':callback))
           )
        ...))

The specified callback package ':callback determines what functions are called when an input signal arrives. So far, the only callback signal is interpret, so the callback function invoked will be ':callback:interpret.

Now that we have created the standard tool network and the interpreter is capable of receiving the interpret signal, we need to add an encapsulated button to the network capable of emitting that signal to start evaluation. In the following, we add a button whose title is Eval Exp and who emits the signal interpret when activated:


(de :create (ctview)
    (lets ((ctedit (send 'object ctview))
           (tool (:tool:create ctedit))
           (network (ty-tool-create-std-network tool
                                                'Exp-interpreter 
                                                ':callback))
           )
       (:create-decoration ctview network)
       ))

(de :create-decoration (ctview network)
    ;;Use the convenience function of Exp.ll
    (#:Exp-environment:handle-button network "Eval Exp" 'interpret))

We still must define the callback function triggered by the interpret signal. In this function, the tool must call the Typol program with the correct initial values: a source tree and an optional environmen tree. A tool calls a Typol program with the the generic function ty-run. This function's arguments are a tool, a program name (as generated by the export predicate), a debug flag, and initial values.


;;Later we will set this value by resources.
;;When true, this variable causes the interpreter
;;to be executed in debug mode.
(defvar :debug ())

(de :callback:interpret (stnode port)
    (lets ((tool (st-object stnode))
           (root (:tool:get-source tool))
           (env  (:tool:get-initial-env tool))
           )
      ;;If no environment tree memorized by tool,
      ;;call appropriate Typol predicate.
      (if env
          (ty-run tool '#:eval_exp:full_eval_exp :debug root env)
          (ty-run tool '#:eval_exp:init_eval_exp :debug root)
          )))


Tutorial