![]() |
The evaluator of the style rewriter and its coverage | ![]() |
This page describes
src/src/Style/Evaluate/
and compares it with the real evaluator edit_env_rep::exec (
Typeset/Env/env_exec.cpp
), whose semantics are documented in evaluation of primitives.
Opens the stack of sub-computations (memorize_initialize), makes env the current environment std_env, evaluates t, restores the previous environment and returns the top-level memorizer (memorize_finalize). The editor calls it as mem= evaluate (ste, cct).
Atomic trees are returned unchanged and are not memoized. For a compound tree, an evaluate_memorizer keyed on (std_env, t) is created; if it is already known (is_memorized), its result tree is returned and its output environment becomes std_env. Otherwise the evaluation proceeds in a new level of the stack: evaluate_impl (t) computes the result, decorate_ip (t, r) gives the new parts of the result the inverse path of t, and the result tree and the environment after the evaluation are stored in the memorizer. Every call prints Evaluate, Memorized or Computed on the console.
rewrite (tree) (
evaluate_rewrite.cpp
) and the evaluation of inactive markup (
evaluate_inactive.cpp
) are memoized in the same way, with memorizer types MEMORIZE_REWRITE and MEMORIZE_INACTIVE, and print similar traces. Helper functions such as evaluate_string evaluate and then extract an atomic result.
evaluate_impl (
evaluate_main.cpp
) is a large switch on the label of the tree, with the same grouping as edit_env_rep::exec: typesetting primitives with side effects, macro expansion, control flow, boolean, arithmetic, textual and length operations, style and activation commands, and miscellaneous ones. Labels which are not handled fall into the default branch:
built-in labels (below START_EXTENSIONS) are evaluated componentwise: each child is evaluated, the label is kept, and transfer_ip copies the inverse path;
user-defined labels go to evaluate_compound (
evaluate_macro.cpp
), which looks the macro up in the environment and applies it.
Macro application uses substitution rather than argument frames (ALTERNATIVE_MACRO_EXPANSION): the arguments are substituted into the body by expand (tree, assoc_environment), sharing all unchanged subtrees, and the result is evaluated. The details are in the experimental evaluator.
Comparing the case labels of evaluate_impl with those of edit_env_rep::exec (with commented-out code removed), the experimental evaluator handles 126 of the 175 labels of the real one, and no label that the real one does not handle. The 49 missing labels are evaluated componentwise by the default branch: their children are evaluated, but the primitive itself is not executed and stays in the result:
NEW_THEME, COPY_THEME, APPLY_THEME, SELECT_THEME.
ANIM_STATIC, ANIM_DYNAMIC, ANIM_TIME, ANIM_PORTION, MORPH.
MOVE, SHIFT, RESIZE, CLIPPED, and BOX_INFO, FRAME_DIRECT, FRAME_INVERSE (whose cases and implementations are present but commented out, in
evaluate_main.cpp
and
evaluate_misc.cpp
).
All EFF_* labels (EFF_MOVE, EFF_GAUSSIAN, EFF_OVAL, EFF_TURBULENCE, …: 15 labels).
GUIPX_LENGTH, MS_LENGTH, S_LENGTH, and the corner lengths LCORNER_LENGTH, BCORNER_LENGTH, RCORNER_LENGTH, TCORNER_LENGTH.
MINIMUM, MAXIMUM, RGB_COLOR, RGB_ACCESS, FIND_ACCESSIBLE, FIND_FILE_UPWARDS, OCCURS_INSIDE, HAS_BINDING, GET_ATTACHMENT, FILTER_STYLE, VAR_MARK.
Several primitives are dispatched but implemented only approximately, because the information they need belongs to the typesetter:
Treated as assign and value respectively (marked “provisory” in
evaluate_main.cpp:112
, 122).
evaluate_drd_props returns the empty string without doing anything (evaluate_macro.cpp:82-85).
evaluate_par_length, evaluate_paw_length and evaluate_pag_length return fixed values (15cm, 18cm and 23cm), evaluate_gw_length and evaluate_gh_length return 10cm and 6cm, and evaluate_gu_length returns 1cm (
evaluate_length.cpp
); the real computations are left in comments.
evaluate_set_binding and evaluate_get_binding work on two static hash tables local_ref and global_ref of
evaluate_misc.cpp
, which are never connected to the references of the buffer, and set-binding evaluates to the empty string (the comment says the work of concater_rep::typeset_set_binding should be done instead).
Cell formats are not re-evaluated (FIXME in evaluate_table).
rewrite handles extern (calling Scheme), map-args, include (loading the file relative to base-file-name with load_inclusion), with-package and rewrite-inactive; evaluate_rewrite evaluates the rewritten tree. This parallels edit_env_rep::rewrite, described in evaluation of primitives. The with-package branch is one of the places that no longer compiles (see the pitfalls).