evaluation

evaluation

part of shnell – a source to source compiler enhancement tool

© Jens Gustedt, 2017

Evaluate the depending code fragment with protected directives

several times.

This allows to use constructs such as ${N} also as arguments to subsequent directives.

In it simplest form, something like

#pragma CMOD amend eval HERE

will first replace the HERE in occurences such as

#pragma HERE amend ...

with CMOD and then call the expansion procedure with input the modified program part, again.

Several identifiers in the line for eval have the code fragment processed as often as there are such “labels”, last is inner most.

Per default the following directives have shortcuts for amend:

CMOD_AMENDS="${CMOD_AMEND:=
bind
do
env
eval
foreach
let
}"

So the following line, where a variable N currently has the value 4,

#pragma HERE do I = ${N}

is then replaced by

#pragma CMOD amend do I = 4

The directives that can appear instead of the above can be changed by defining the environment variable CMOD_AMEND to a list of directives that should have shortcuts. If an element in the list is of the form NEW=OLD the

#pragma HERE NEW

directive resolves to

#pragma CMOD amend OLD

in the depending source snippet.

If only NEW is given,

#pragma HERE NEW

resolves to

#pragma CMOD amend NEW.

A particular directive can be switched off by leaving OLD empty, that is by only giving NEW=. After that

#pragma HERE NEW

is ivalid. Thus, by addition of amend= and/or insert= to the list all other directives can be disabled for HERE.

Coding and configuration

The following code is needed to enable the sh-module framework.

SRC="$_" . "${0%%/${0##*/}}/import.sh"

Imports

The following sh-modules are imported:

Details

Declared functions

evaluation: Evaluate the source code for the tags received on the commandline