Add macro support v0.11.0
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 4 Oct 2023 14:14:33 +0000 (10:14 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 6 Oct 2023 15:55:00 +0000 (11:55 -0400)
commit320644e2c5cf8803f15aca71763f28b66071b166
tree91c80f2ecf46725b5577d02d9d535b86fcf1124c
parent261c5ecfc67f0cb56a39f27a6d70542ac2d6a2cf
Add macro support

This patch makes Normand support macro definitions and macro expansions.

The macro system doesn't support recursion, and to expand a given macro
by name, it needs to be already defined.

A macro definition may only exist at the root level, not within a group
(including not within a repetition, condition, or other macro definition
which all have implicit groups). The form is:

    !macro name(a, b, c)
        ...
    !end

Parameters are optional, but you always need the parentheses after the
macro name.

Parameter names must be unique for a given macro definition.

A parameter becomes a variable for the items of the macro group.

A macro expansion has the form:

    m:name(1, 2, 3)

Again, you always need the parentheses.

To expand a macro, its definition needs to exist completely before (no
recursion).

A parameter value is one of:

* A constant integer.
* A variable/label name.
* An expression between `{` and `}`.

The initial state of a macro expansion is:

Current offset:
    Copied

Current byte order:
    Copied

Variables:
    Parameter values (using parameter names)

Labels:
    None

The final state, after handling a macro expansion, is:

Current offset:
    Incremented by the size of the generated macro expansion data,
    _not_ its final current offset.

Current byte order:
    The one before the expansion.

Variables:
    The ones before the expansion.

Labels:
    The ones before the expansion.

Change-Id: I493c89009d7f7ce61b22f04e70881b253429c3b8
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
80 files changed:
README.adoc
normand/normand.py
pyproject.toml
tests/fail-cond-blk-empty-expr.nt
tests/fail-fl-int-32b-out-of-range-neg.nt
tests/fail-fl-int-32b-out-of-range-pos.nt
tests/fail-fl-int-8b-out-of-range-neg.nt
tests/fail-fl-int-8b-out-of-range-pos.nt
tests/fail-label-missing-suffix.nt
tests/fail-macro-def-dup-param.nt [new file with mode: 0644]
tests/fail-macro-def-dup.nt [new file with mode: 0644]
tests/fail-macro-def-in-cond.nt [new file with mode: 0644]
tests/fail-macro-def-in-group.nt [new file with mode: 0644]
tests/fail-macro-def-in-macro.nt [new file with mode: 0644]
tests/fail-macro-def-in-rep.nt [new file with mode: 0644]
tests/fail-macro-def-inval-name.nt [new file with mode: 0644]
tests/fail-macro-def-inval-param-name.nt [new file with mode: 0644]
tests/fail-macro-def-missing-comma.nt [new file with mode: 0644]
tests/fail-macro-def-missing-end-paren.nt [new file with mode: 0644]
tests/fail-macro-def-missing-end.nt [new file with mode: 0644]
tests/fail-macro-def-no-name.nt [new file with mode: 0644]
tests/fail-macro-def-no-paren.nt [new file with mode: 0644]
tests/fail-macro-exp-inval-param-float.nt [new file with mode: 0644]
tests/fail-macro-exp-inval-param-str.nt [new file with mode: 0644]
tests/fail-macro-exp-missing-colon.nt [new file with mode: 0644]
tests/fail-macro-exp-missing-name.nt [new file with mode: 0644]
tests/fail-macro-exp-missing-paren.nt [new file with mode: 0644]
tests/fail-macro-exp-missing-suffix.nt [new file with mode: 0644]
tests/fail-macro-exp-param-count-mismatch.nt [new file with mode: 0644]
tests/fail-offset-missing-suffix.nt
tests/fail-rep-blk-empty-expr.nt
tests/fail-rep-post-empty-expr.nt
tests/fail-rep-post-unreachable-label-2.nt
tests/fail-rep-post-unreachable-label-3.nt [deleted file]
tests/fail-uleb128-unreachable-label-2.nt
tests/fail-uleb128-unreachable-label-3.nt [deleted file]
tests/fail-var-empty-expr.nt
tests/fail-var-unreachable-label-1.nt [new file with mode: 0644]
tests/fail-var-unreachable-label-2.nt [new file with mode: 0644]
tests/pass-bmp.nt
tests/pass-cond-blk-expr-var-1.nt [deleted file]
tests/pass-cond-blk-expr-var-2.nt [deleted file]
tests/pass-cond-blk-expr-var.nt [new file with mode: 0644]
tests/pass-macro-def-dup-label.nt [new file with mode: 0644]
tests/pass-macro-def-five-params.nt [new file with mode: 0644]
tests/pass-macro-def-no-items.nt [new file with mode: 0644]
tests/pass-macro-def-no-params.nt [new file with mode: 0644]
tests/pass-macro-def-one-param.nt [new file with mode: 0644]
tests/pass-macro-def-same-label.nt [new file with mode: 0644]
tests/pass-macro-def-spaces.nt [new file with mode: 0644]
tests/pass-macro-def-var-dup-label.nt [new file with mode: 0644]
tests/pass-macro-exp-cond.nt [new file with mode: 0644]
tests/pass-macro-exp-final-state-bo.nt [new file with mode: 0644]
tests/pass-macro-exp-final-state-labels.nt [new file with mode: 0644]
tests/pass-macro-exp-final-state-offset.nt [new file with mode: 0644]
tests/pass-macro-exp-final-state-vars.nt [new file with mode: 0644]
tests/pass-macro-exp-fl-num.nt [new file with mode: 0644]
tests/pass-macro-exp-init-state-bo.nt [new file with mode: 0644]
tests/pass-macro-exp-init-state-offset.nt [new file with mode: 0644]
tests/pass-macro-exp-nest.nt [new file with mode: 0644]
tests/pass-macro-exp-no-params.nt [new file with mode: 0644]
tests/pass-macro-exp-one-param.nt [new file with mode: 0644]
tests/pass-macro-exp-rep.nt [new file with mode: 0644]
tests/pass-macro-exp-three-params.nt [new file with mode: 0644]
tests/pass-macro-exp-var.nt [new file with mode: 0644]
tests/pass-readme-intro-macro.nt [new file with mode: 0644]
tests/pass-readme-learn-macro-def-1.nt [new file with mode: 0644]
tests/pass-readme-learn-macro-def-2.nt [new file with mode: 0644]
tests/pass-readme-learn-macro-exp-1.nt [new file with mode: 0644]
tests/pass-readme-learn-macro-exp-2.nt [new file with mode: 0644]
tests/pass-rep-blk-expr-var-1.nt [deleted file]
tests/pass-rep-blk-expr-var-2.nt [deleted file]
tests/pass-rep-blk-expr-var.nt [new file with mode: 0644]
tests/pass-rep-post-expr-var-1.nt [deleted file]
tests/pass-rep-post-expr-var-2.nt [deleted file]
tests/pass-rep-post-expr-var.nt [new file with mode: 0644]
tests/pass-uleb128-expr-var-1.nt [deleted file]
tests/pass-uleb128-expr-var-2.nt [deleted file]
tests/pass-uleb128-expr-var.nt [new file with mode: 0644]
tests/pass-var-label.nt [new file with mode: 0644]
This page took 0.029383 seconds and 4 git commands to generate.