Help closures
HelpFatalClosure: TYPE = RECORD[proc: HelpFatal, data: REF ← NIL];
HelpFatal:
TYPE =
PROC [data:
REF, head: EvalHead, parent: Tree, msg:
ROPE];
This is called when a non-recoverable error is found.
parent is the offending tree, msg describes what went wrong
HelpWrongTypeClosure: TYPE = RECORD[proc: HelpWrongType, data: REF ← NIL];
HelpWrongType:
TYPE =
PROC
[data: REF, head: EvalHead, parent: Tree, value: TV, target: Type, msg: ROPE]
RETURNS [correct: RopeOrTV];
This is called when the wrong type of TV is found
the client should return the correct TV (which must be OK for the target)
if a ROPE is returned, it replaces msg as the error message
if target = nullType, then the true target may not be known
(this occurs for msg = "not applicable", for example)
if target = CODE[PROC], then some procedure should be returned
HelpIdClosure: TYPE = RECORD[proc: HelpId, data: REF ← NIL];
HelpId:
TYPE =
PROC
[data: REF, head: EvalHead, parent: Tree, id: ROPE, context: Type, target: Type, msg: ROPE]
RETURNS [correct: RopeOrTV];
This is called when the given id is not valid for the context
if the client returns a rope, the lookup will begin again with the new rope
if the client returns a TV, the lookup will return with that TV
if the client returns a fail, that will be the new msg for HelpFatal
if context = nullType, then the context is probably dynamic
(this may occur for msg = "undefined", for example)
if target = nullType, then the true target is not known
HelpSelectorClosure: TYPE = RECORD[proc: HelpSelector, data: REF ← NIL];
HelpSelector:
TYPE =
PROC
[data: REF, head: EvalHead, parent: Tree, id: ROPE, context: TV, target: Type, msg: ROPE]
RETURNS [correct: RopeOrTV];
This is called when the given id is not valid for the context
(note that the context is a TV)
if the client returns a rope, the lookup will begin again with the new rope
if the client returns a TV, the lookup will return with that TV
if the client returns a fail, that will be the new msg for HelpFatal
if target = nullType, then the true target is not known
HelpDefaultClosure: TYPE = RECORD[proc: HelpDefault, data: REF ← NIL];
HelpDefault:
TYPE =
PROC
[data: REF, head: EvalHead, parent: Tree, type: Type, index: CARDINAL, msg: ROPE]
RETURNS [correct: RopeOrTV];
This is called when a default value is not present
if index = 0, then the default is missing for type
if index > 0, then the default is missing for that component of type
the client should return a TV to be used as the default value
the client may also return a new error message
RopeOrTV:
TYPE =
RECORD[
SELECT tag: *
FROM
rope => [rope: ROPE],
tv => [tv: TV],
both => [rope: ROPE, tv: TV],
fail => [fail: ROPE],
ENDCASE
] ← [fail[NIL]];
EvalHead operations
NewEvalHead:
PROC
[context: AMModel.Context,
context # NIL.
AMModel.ContextClass[context]
= one of: world, prog(global frame), interface(ir), proc(local frame)
specials: SymTab.Ref, -- non-NIL
abortClosure: AbortClosure ← [NIL, NIL],
helpFatalClosure: HelpFatalClosure ← [NIL, NIL],
helpWrongTypeClosure: HelpWrongTypeClosure ← [NIL, NIL],
helpIdClosure: HelpIdClosure ← [NIL, NIL],
helpSelectorClosure: HelpSelectorClosure ← [NIL, NIL],
helpDefaultClosure: HelpDefaultClosure ← [NIL, NIL]
]
RETURNS [EvalHead];
returns a new evaluator head
note that most of the help routines are optional
the client can supply special variables for lookup
WorldFromHead: PROC [head: EvalHead] RETURNS [WorldVM.World];