Lhogho  0.0.027
Asm

Asm module contains functions and definitions for generating machine code. Actually the module is responsible for pseudo-machine code, which is then converted to real processor-specific machine code.

Platform specific modules:

Executable File Structure

The Lhogho compiler creates executables files in a lazy manner - i.e. instead of building entorely new file it makes a compy of itself and attaches the source. When this file is executes it will extract the source from itself, compile it in-memory, and execute it.

executable_structure.png
Structure of executable file

The executable file contains four segments. The first one is an exact copy of the compiler which generated the executable file. The second segment is an exact copy of the source program. The next segment is 4-byte integer containing the size of the source in bytes. This valus is used to extract the source from the compiler program. The last segment is a 4-byte magic integer number. It indicates the existence of source in the compiler program.

Running compiled files

Then a compiled file is run, actually the embedded Lhogho compiler in it is run. The compiler itself does not know that it is compiled program, so it inspects itself. If the last 4 bytes contain the magic number, then it assumes there is also source included in it. Then Lhogho extracts the source and compiles it.

Because a compiled program contains the complete compiler, it can also be used as a compiler. Thus compiling another source will generate a file with two sources.

executable_chain_structure.png
Multiple sources

When such a program is run it will extract sources from bottom to top, but will execute them from top to bottom.

Imagine we have three test programs test1.lgo, test2.lgo and test3.lgo. if we execute these commands:

lhogho -x test1.lgo
test1 -x test2.lgo
test2 -x test3.lgo

we will generate executable files test1, test2 and test3. When the third executable file test3 is run it will execute the code from all three *.lgo programs.

In-memory compilation

By default Lhogho compiles logo sources into mem atoms. Each compiled routine has its own mem block. Routines descriptors contain pointer to the mem block and to the actual code.

compile_memory1.png
In-memory compilation of user functions

For primitives there is no memory block, but the ADDRESS field points directly to the implementation of the primitive, which is a part of the compiler.

compile_memory2.png
In-memory compilation of primitives

[ HOME | INDEX | ATOMS | VARS | REFERENCE ]
Lhogho Developer's Documentation
Tue Feb 7 2012