This section gives some technical informations about QScheme.
The classical scheme works in a loop, the famous REPL, which stands for ``Read,
Eval, Print Loop''. My scheme mostly conforms to this. In order to achieve
speed and flexibility, the REPL has been slightly changed.
The compile phase transforms the list given by the read procedure into an intermediate code (icode) representation. This code is stored in a standard array and can be manipulated with the standard scheme procedures.The icode is describe hereafter.
The optimizer transforms the icode generated by the compiler, mainly to implement tail recursion.
The assembler transforms the icode to a code which can be executed by the virtual machine. The vmcode is an internal code. It cannot be changed from scheme. It only can be printed for debugging purpose, see the disasm function.
With this design, the compiler and the optimizer can be written in scheme itself.
The compiler takes a list as input and generates an icode array. Input list is typically delivered by the read function.
When compilers encounters a symbol which is bound to a macro, the macro code is evaluated and the result of this evaluation replaces the original form.
After compilation, the icode array contains assembly instructions. See table 2.
|
The optimizer transforms the icode. The main optimizations are:
The assembler transforms the intermediate code to real virtual machine code. During this transformation, the ``nop'' generated during optimization are ignored and the labels are mapped to true address.
The compiler/assembler is implemented in the asm.c source file. There you can find the complete list of opcodes.
The execute and the read function can be found in the s.c file. It's not really a good place but it's so now.