amend.cfg

part of shnell – a source to source compiler enhancement tool

© Jens Gustedt, 2017-2019

the list of valid shnell extensions

This file list all shnell extensions that are accepted. They are usually invoked by a pragma inside the C source. For example a pragma

#pragma CMOD amend do I = 5
...
#pragma CMOD done

would unroll the code between the two pragma 5 times and replace the occurence of ${I} by the current number. (See regVar for meta-variables.)

Corresponding scripts are run as they are listed here. Arguments to the directive are passed through the environment variable CMOD_EXTENSION_ARGUMENTS, but are better handled through the arguments module.

The identifier for an extension must follow the same rules as for C identifiers and should generally not be reserved.

Simple directives for demonstrative purposes

the simplest “extension”, copy the source over, ignore all the arguments

copy=cat

copy the source over and echo all arguments of the directive to stderr

hello = ${EXEDIR}/hello.sh

comment all the source in the directive

comment=sed s+^+//+

ignore all the source in the directive

ignore = ${EXEDIR}/ignore.sh

an invalid extension because there remains a $

invalid = EXEDIR/hello

Unrolling

specialize code for a list of values that an identifier takes

specialize = ${EXEDIR}/specialize.sh

specialize code for a list of ranges of values that an identifier takes

ranges = ${EXEDIR}/ranges.sh

foreach code for a list of values

foreach = ${EXEDIR}/foreach.sh

do loop for a specified number of values

do = ${EXEDIR}/do.sh

Binding

evaluate an expression

let = ${EXEDIR}/let.sh

bind variables to values

bind = ${EXEDIR}/bind.sh

Meta directives to organize shnell dialects

add short cuts to avoid the amend meta directive

dialect = ${EXEDIR}/dialect.sh

re-valuate a whole source blob

eval = ${EXEDIR}/evaluation.sh

load text snippets from files load = ${EXEDIR}/load.sh

generate mangled names, experimental

module = ${EXEDIR}/module.sh

generate internal names, experimental

intern = ${EXEDIR}/intern.sh

import names from other modules, experimental

using = ${EXEDIR}/using.sh

create shortcut for module name, experimental

rename = ${EXEDIR}/rename.sh

Targeted source replacement

factor all decimal integers, toy

factor = ${EXEDIR}/factor.sh

compute simple constant expressions, semi-toy

compute = ${EXEDIR}/compute.sh

compute expressions by using the POSIX bc tool

bc = ${EXEDIR}/bc.sh

Environment and configuration

add POSIX configuration variables

getconf = ${EXEDIR}/getconf.sh

evaluate environment variables

env = ${EXEDIR}/env.sh

obtain the bytes of the git hash of the source file

gitID = ${EXEDIR}/gitID.sh

C language specific tools

add enum configuration variables

enum = ${EXEDIR}/enum.sh

Implement C and C++ attributes by translating them to compiler specifics

attribute = ${EXEDIR}/attribute.sh

Put all code onto a single physical line, use this to construct #define

oneline = ${EXEDIR}/oneline.sh

Put all code onto a single logical line, use this to construct #define

logicalline = ${EXEDIR}/logicalline.sh

Trade: simple naming naming enforcement for im- and export

The TRADE dialect and the trade commandline interface use export and implicit directives to ensure that each TU /exports/ properly named identifiers and is able to import from other TU by simple implicit naming conventions.

introduce prefix naming conventions

export = ${EXEDIR}/export.sh

make names private, can only be used with export

private = ${EXEDIR}/private.sh

introduce short names for other TU, can only be used with export

alias = ${EXEDIR}/alias.sh

import headers from other TU implicitly

implicit = ${EXEDIR}/implicit.sh

introduce short names for legacy TU, can only be used with implicit

legacy = ${EXEDIR}/legacy.sh

establich startup handlers, can only be used with implicit

startup = ${EXEDIR}/startup.sh

establish atexit handlers, can only be used with implicit

atexit = ${EXEDIR}/atexit.sh

establish local handlers, can only be used with implicit

local = ${EXEDIR}/local.sh

Other directives

bring generic selection to C++

generic_selection = ${EXEDIR}/generic_selection.sh

translate C++ lambda to gcc’s nested functions

lambda = ${EXEDIR}/lambda.sh

normalize C code such that all control constructs use compound statements

normalize = ${EXEDIR}/normalize.sh

define a holdback for a lambda expression

holdback = ${EXEDIR}/holdback.sh

tentatively define a preprocessor macro

define = ${EXEDIR}/define.sh

run the depending code through the C preprocessor

preprocess = ${EXEDIR}/preprocess.sh

run the depending code through the C preprocessor

preprocess = ${EXEDIR}/preprocess.sh