|Home | About | Partners | Contact Us|
XLR: Extensible Language and Runtime
The bytecode is the interface to the back-end. It is a form of XL0 that contains only low-level instructions in a limited, target-dependent set. For instance, the current C bytecode contains add_int, sub_int, add_float, sub_float, etc.
The early phases prefix bytecode with @ to quickly let it trickle through semantics and other passes of the compiler. So the following XL0 is the kind of bytecode you'd get from the front-end:
@add_int Target, Source1, Source2
then semantics and others mostly ignore it. The last phase of the compiler is going to lookup in the xl.bytecode file, which contains a line like the following (for the C variant of bytecode I currently use):
add_int "$1 = $2 + $3;"
and perform textual replacement, resulting in the following output:
Target = Source1 + Source2;
Some bytecode is generated directly by semantics, and is expected to be present in all targets. These are things like tests, gotos, labels. Some bytecode is ABI-dependent and is emitted in a machine-dependent way by the XL.CODE_GENERATOR.MACHINE module. This includes things like function call conventions, record layout, etc.
Finally, some bytecode represents operations defined by the library using declarations like:
function Add(X: integer; Y : integer) return integer written X+Y is XL.BYTECODE.add_int procedure Copy(out X : integer; Y : integer) written X:=Y is XL.BYTECODE.copy_int
The name is arbitrary here, and it results in a replacement of, say, 3+4 with an @add_int tree. In other words, the semantics of 3+4 is absolutely identical to that of a user-defined written form, except that the target function is defined to be a bytecode, so instead of a function call, we emit the corresponding bytecode.
To see the bytecode output, you can use the following command:
./nxl -parse foo.xl -sem -style bytecode -show
and to expand the bytecode using xl.bytecode as shipped, you use:
./nxl -parse foo.xl -sem -ccode
You can try it with the following test code:
function Add(X: integer; Y : integer) return integer written X+Y is XL.BYTECODE.add_int procedure Copy(out X : integer; Y : integer) written X:=Y is XL.BYTECODE.copy_int procedure Test is X : integer X := 0 X := X + 3