NAME

gen_inline.pl

SYNOPSIS

%perl languages/tcl/tools/gen_inline.pl lib/builtins/foo.tmt > lib/builtins/foo.pir

DESCRIPTION

Use this script to generate PIR code based on a template describing how the inlined tcl builtin works. Parameters specifying argument types and subcommands can be specified, the build tool takes this and generates the actual compiler for that command.

Many builtins need to use the same type of code, and do the same kind of optimizations. By making the inline'd versions more declarative, this lets us do this work once instead of many times, which should make it easier to inline more builtins accurately.j

Currently support options with no arguments, and the following types of arguments: variable name, integer, channel, list, and string.

Internal notes...

@pir_code internal variable

This is a bit complicated. We are munging a template file into PIR code which in turn is generating more PIR code. We'll call the inner PIR INLINED and the outer PIR CALLER.

@pir_code is an array of array refs. The first is a key, the second is data.

If the Key is INLINE, then this will be concated to the INLINED PIR. Magic is done to expand {pir_variable} elements into the string to support the common idiom of:

pir_code .= "$P"
$S0 = some_var
pir_code .= $S0
pir_code .= "= value\n"

Which can now be written as:

$P{some_var} = value

If the Key is VAR, this represents a variable in the CALLER scope, which will be concated to the INLINED PIR.

If the Key is WRAP, this represents PIR code in the CALLER.

As we process the template, we generate this array. The end result is PIR .sub declaration (CALLER) that in turn contains the inlined PIR which will eventually be compiled (INLINED).

Utility Methods

(min,max) = num_args($template)

Given a template, figure out the minimum and maximum number of args required for this builtin.

BUGS

Doesn't support subcommands. Or anything other than [incr], really.