JunoAlgebra.mesa
Written July, 1982 by Donna M. Auguste and Greg Nelson
Edited September 7, 1982 10:58 pm
Edited September 8, 1982 10:59 pm
Last Edited by: Gnelson, October 11, 1983 4:15 pm
Last Edited by: Stolfi, June 13, 1984 10:02:21 am PDT

This module is concerned with the interpretation of Juno symbolic expressions. It defines the semantics of the Juno language.

DIRECTORY

JunoStorage USING [Point, Coords],
JunoGraphics USING[Color],
JunoParseUnparse USING [Se],
Rope USING [ROPE];

JunoAlgebra: DEFINITIONS =

BEGIN OPEN Stor: JunoStorage, Parser: JunoParseUnparse, Gr: JunoGraphics;

- - - - SYMBOLIC EXPRESSIONS

Se: TYPE = Parser.Se; -- Symbolic Expression. Either:

ATOM (variable, operator, or function name)
REF REAL, REF INT
ROPE
LIST OF Se of the form (operator arg) or (operator arg arg)

- - - - VALUES

Value: TYPE = REF ANY; -- the result of evaluating a Symbolic Expression. Either:

REF REAL, REF INT
ROPE
Point (see JunoStorage)
LIST OF Value

ValueList: TYPE = LIST OF Value;

- - - - IMPORTED TYPES

Point: TYPE = Stor.Point;

Coords: TYPE = Stor.Coords;

- - - - ALISTS

AList: TYPE = LIST OF REF ANY; -- Association list.

Of the form (atom value atom value ... atom value)

GetDef: PROC [name: ATOM, alist: AList] RETURNS [value: Value];
Returns NIL if not found.

AddDef: PROC [name: ATOM, value: Value, alist: AList]
RETURNS [newAlist: AList];
Prepends name-value pair to the alist. Gets storage from pool if available.

- - - - EXPRESSION EVALUATION

The global (procedure) A-List:

The global or procedure AList (that maps procedure names into symbolic expresions) is an implicit paramter of Eval, Apply and its relatives. It is maintained by the JunoProcViewer module.

The contents of the global a-list reflect what the parser found in the proc viewers during the most recent call to JunoProcViewer.ParseAll. Any edits since then will not be noticed by the evaluator. Ergo, JunoTop should call ParseAll frequently, e.g. before every refresh and before each additional "call procedure" command from the user.

Comand mode vs. eval mode:

The cmd flag in Eval and Apply specifies that the given Se should be interpreted as an executable command, rather than a value -returning expression.

If cmd = false, an atomic expr is looked up in the varable alist, and the result returned without further evaluations. If cmd=FALSE, atomic exprs are looked up in the proc file alist; the result must be a parameterless lambda, that is evaluated again (In juno, a call to a parameterless procedure Foo is written ``Foo'' instead of "Foo()").

Some operations (like print and draw) are allowed only if cmd=TRUE; conversely, others (such as unary minus) are allowed only when cmd=FALSE. Note that function arguments are always evaluated with cmd=FALSE, and the left part of "A; B" is always evaluated with cmd=TRUE.

Eval: PROC [expr: Se, alist: AList, cmd: BOOLFALSE] RETURNS [value: Value];
Evaluates expr using the given alist for variables, and the current proc file for functions.

Apply: PROC[op: Se, args: ValueList, cmd: BOOLFALSE] RETURNS [value: Value];
Applies the given operation to the given arguments.
Both op and args are assumed to be evaluated; op is NOT looked up in the proc file.
The op may be a lambda expression: (lambda (comma <parm> ...) <body>).

EvalError: SIGNAL [what: Rope.ROPE] RETURNS [value: Value];
Raised by Eval and Apply on run-time errors.

- - - - PROCEDURE CALL

Call: PROC[func: ATOM, args: ValueList];
Similar to Apply, but evaluates op first (i.e., uses op if intrinsic function, else uses its current definition obtained from proc file). The args are assumed to be already evaluated.

- - - - MISCELLANEA

EvalColor: PROC[expr: Se, alist: AList] RETURNS [color: Gr.Color];
The expr must be either a reserved color atom ($black, $red, $lightyellow, etc), or must evaluate to a real number (gray level, 0= white, 1=black), or to a list of up to three numbers, giving [red, green, blue].

END.