Lhogho
0.0.028
|
Go to the source code of this file.
Macros | |
#define | SRC_EXT_COUNT (sizeof source_extensions)/(sizeof source_extensions[0]) |
#define | SRC_EXT (source_extensions[i]) |
#define | BUF_SIZE 1024 |
#define | RETURN_NO_CHECK(INSTR) |
#define | RETURN_NO_CHECK_EL(INSTR) |
#define | RETURN_CHECK(INSTR) |
Functions | |
atom_t | compile_expr (context_t *ctx, atom_t lisp, int mode) |
compiles expression or constant More... | |
atom_t | compile_block (context_t *ctx, atom_t lisp, int mode) |
compiles block of statements More... | |
atom_t | compile_if (context_t *ctx, atom_t source, int mode) |
compiles IF statement More... | |
atom_t | compile_repeat (context_t *ctx, atom_t source) |
compiles REPEAT statement More... | |
atom_t | compile_while (context_t *ctx, atom_t source, int is_while, int is_do) |
compiles WHILE statement More... | |
atom_t | compile_forever (context_t *ctx, atom_t source) |
compiles FOREVER statement More... | |
atom_t | compile_catch (context_t *ctx, atom_t source, int mode) |
compiles CATCH statement More... | |
atom_t | compile_tag (context_t *ctx, atom_t source) |
compiles TAG statement More... | |
atom_t | compile_goto (context_t *ctx, atom_t source, atom_t var) |
compiles GOTO statement More... | |
atom_t | compile_iftest (context_t *ctx, atom_t source, int criteria) |
atom_t | compile_for (context_t *ctx, atom_t source) |
compiles FOR statement More... | |
void | init_compiler (outter_t outter, inner_t inner, inner_eof_t inner_eof) |
initializes the compiler More... | |
void | finit_compiler () |
finalizes the compiler More... | |
int | compile_from_options () |
compiles according to options More... | |
atom_t | compile_to_file () |
compiles into executable file More... | |
atom_t | instruction_list (atom_t data) |
ensured that input is a list in brackets More... | |
int | run_function (atom_t function) |
runs the compiled code of a function More... | |
int | run_source (chars_t source) |
compiles and runs source code More... | |
atom_t | compile_function (atom_t func, int mode, int is_macro) |
compiles a function More... | |
atom_t | compile_external_function (atom_t func) |
compiles an external function More... | |
atom_t | compile_internal_function (atom_t func, int static_link) |
compiles an internal function More... | |
int | is_constant (atom_t lisp) |
determines whether lisp is a constant More... | |
int | is_reference (atom_t lisp) |
determines whether lisp is a reference More... | |
atom_t | compile_lisp_const (context_t *ctx, atom_t lisp) |
compiles constant More... | |
atom_t | compile_local (context_t *ctx, atom_t source, int *processed) |
compiles LOCAL statement More... | |
atom_t | compile_make (context_t *ctx, atom_t source, int is_name, int *processed) |
compiles MAKE statement More... | |
atom_t | compile_output (context_t *ctx, atom_t source) |
compiles OUTPUT statement More... | |
atom_t | compile_maybeoutput (context_t *ctx, atom_t source) |
compiles MAYBEOUTPUT statement More... | |
atom_t | compile_stop (context_t *ctx, atom_t source) |
compiles STOP statement More... | |
atom_t | compile_test (context_t *ctx, atom_t source, int criteria) |
compiles IFTRUE and IFFALSE statements More... | |
atom_t | compile_lisp_reference (context_t *ctx, atom_t source) |
compiles reference More... | |
Variables | |
int | running_compiled_code |
indicate whether generated code is currently running More... | |
int | compiling_code |
indicate whether source code is currently compiling More... | |
char * | source_extensions [] = { ".lgo", ".log", ".lg", ".logo", ".lho", ".lhogho" } |
#define SRC_EXT_COUNT (sizeof source_extensions)/(sizeof source_extensions[0]) |
Definition at line 142 of file compiler.c.
#define SRC_EXT (source_extensions[i]) |
Definition at line 143 of file compiler.c.
#define BUF_SIZE 1024 |
#define RETURN_NO_CHECK_EL | ( | INSTR) |
ctx | compilation context |
lisp | statement to compile |
mode | compilation mode (COMPILE_AS_FUNC/COMPILE_AS_PROC) |
Compiles a single expression or constant. If needed calls itself recursively to process nested expressions. Expression result is in the stack.
Depending on mode
the result is checked with rt_cmdchk(), rt_funchk() or rt_exprchk().
If the result of compile_expr
is empty list, then the expression is a constant which is left in the stack. The caller may want to pop it in EAX register.
Definition at line 1829 of file compiler.c.
ctx | compilation context |
lisp | statements to compile |
mode | compilation mode (COMPILE_AS_macro) |
Compiles a block of expressions. If mode
is COMPILE_AS_UNKNOWN
then the number of expressions determines how to compile. If the number is >1, then compile as procedure.
Definition at line 2163 of file compiler.c.
ctx | compilation context |
source | IF's source |
mode | compilation mode (COMPILE_AS_... macro) |
Compiles an if
statement. The generated code depends on the parameters - whether they are constants or expressions. At the end of execution of generated code the result of if
should be in the stack (the result is either error atom or unbound atom).
Definition at line 1235 of file compiler.c.
ctx | compilation context |
source | REPEAT's source |
Compiles a repeat
statement. The generated code depends on the first parameter of repeat
- if it is a constant, then a shorter code is generated. If it is an expression, then the code should contain instructions for calculating the number of repetitions.
At the end of execution of generated code the result of repeat
should be in the stack (the result is either error atom or unbound atom).
Definition at line 1359 of file compiler.c.
ctx | compilation context |
source | WHILE's source |
is_while | while=1, until=0 |
is_do | do.while/do.until=1, while/until=0 |
Compiles a while
or a until
statement. If the value of is_while
is !0, then generated code is for while. If it is 0, then the code is for repeat. If is_do
is 1, then parameters must be swapped as in do.while
and do.until
.
Definition at line 1580 of file compiler.c.
ctx | compilation context |
source | FOREVER's source |
Compiles a forever
statement.
Definition at line 1419 of file compiler.c.
ctx | compilation context |
source | CATCH's source |
mode | compilation mode (COMPILE_AS_... macro) |
Compiles a catch
statement. The generated code executes the commands and catches forced exits. If they are caused by a throw
with the same tag, then the exits are masked.
Definition at line 1304 of file compiler.c.
ctx | compilation context |
source | TAG's source |
Compiles a tag
statement. Creates a new variable of type VAR_TYPE_TAG.
Definition at line 1670 of file compiler.c.
ctx | compilation context |
source | GOTO's source |
var | GOTO's var atom |
Compiles a goto
statement. Creates code which searches in real-time for tag named as the input and makes jump to it.
If the input is a constant word, then find taget address at compile-time.
Definition at line 1715 of file compiler.c.
ctx | compilation context |
source | FOR's source |
Compiles a for
statement.
Definition at line 1444 of file compiler.c.
void init_compiler | ( | outter_t | outter, |
inner_t | inner, | ||
inner_eof_t | inner_eof | ||
) |
outter | outter function to use by dump and dumpln |
inner | inner function to use for text input |
inner_eof | inner_eof function to test eof of text input |
Initializes the compiler and all other modules
Definition at line 169 of file compiler.c.
void finit_compiler | ( | ) |
int compile_from_options | ( | ) |
Compiles according to the compiler's options. In case of error dumps the error message and returns non-zero value.
Definition at line 242 of file compiler.c.
atom_t compile_to_file | ( | ) |
Compiles current source into executable file. The name of the file is based on the name of the external source. EXE
extension is used for Windows systems. For Linux no extension is used. The generated file has read-write-execute user permisions.
If the option_make_executable_compiler is set, then the compiled file acts like a compiler in respect to its inputs.
If the option_make_executable is set, then the compiled file acts as a standalone file and does not use any of the Lhogho options.
Definition at line 341 of file compiler.c.
Ensures that CAR(data) is an instruction list. If it is is a list, then do nothing and return it. Otherwise replace it with [(RUN CAR(data))]
Definition at line 458 of file compiler.c.
int run_function | ( | atom_t | function) |
Runs the compiled code of a function. Assumes the function is already compiled without error. If error occurs during execution the error is dumped on the output stream and its code is returned.
Definition at line 480 of file compiler.c.
int run_source | ( | chars_t | source) |
Compiles source code as if it is the main program. No variables are cleared before or after the compilation. Then runs the compiled code.
Definition at line 550 of file compiler.c.
func | function to compile |
mode | compilation mode (COMPILE_AS_ macros) |
is_macro | macro mode |
Compiles the body of a function. If the function is not parsed or a syntax tree is not generated then parse and treeify it first.
If is_macro
is false, then the epilogue of the function releases all local variables - created at compile or at runtime.
If is_macro
is true, then the epilogue of the function calls a function to process the locals. This function would typically save the locals in the parent variable.
Definition at line 608 of file compiler.c.
func | function to compile |
Compiles the trampoline of an external function.
Definition at line 744 of file compiler.c.
func | function to compile |
static_link | static link from the current frame |
Compiles the trampoline of an internal function.
Definition at line 810 of file compiler.c.
int is_constant | ( | atom_t | lisp) |
lisp | statement to check |
Lisps which are expressions (i.e. they are in parentheses) are not constants. References to variables like ':a' are not constants. Everything else is considered constants.
Definition at line 885 of file compiler.c.
int is_reference | ( | atom_t | lisp) |
lisp | statement to check |
References are words which start with colon, like ':a'.
Definition at line 954 of file compiler.c.
ctx | compilation context |
lisp | constant to compile |
Compiles a single constant.
Definition at line 993 of file compiler.c.
ctx | compilation context |
source | LOCAL's source |
processed | 1 if the statement is processed |
Compiles a LOCAL statement. Actually does not compile but process the LOCAL's source by removing all constant-words. Such parameters should already be processed by the treefier. If all parameters are removed, then the whole LOCAL statement is ignored. Otherwise the modified source is processed as ordinary user-defined function.
Definition at line 1035 of file compiler.c.
ctx | compilation context |
source | MAKE's source |
is_name | MAKE=0, NAME=1 |
processed | 1 if the statement is processed |
Compiles a MAKE statement. The generated code depends on the parameters - whether they are constants or expressions. At the end of execution of generated code the result of MAKE should be in the stack (the result is either error atom or unbound atom).
Some MAKE statements cannot be processed - e.g. those in which the name of the variable is an expression. In such cases processed
is set to 0.
Definition at line 1088 of file compiler.c.
ctx | compilation context |
source | OUTPUT's source |
Compiles an OUTPUT statement.
Definition at line 1164 of file compiler.c.
ctx | compilation context |
source | MAYBEOUTPUT's source |
Compiles an MAYBEOUTPUT statement.
Definition at line 1187 of file compiler.c.
ctx | compilation context |
source | STOP's source |
Compiles a STOP statement.
Definition at line 1211 of file compiler.c.
ctx | compilation context |
source | IFTRUE's or IFFALSE's source |
criteria | IFTRUE=1, IFFALSE=0 |
Compiles a iftrue
or a iffalse
statement. If the value of criteria
is 1, then generated code is for iftrue
. If it is 0, then the code is for iffalse
.
Definition at line 1640 of file compiler.c.
ctx | compilation context |
source | reference source |
Compiles a reference to variable's value - :a.
Definition at line 1771 of file compiler.c.
int running_compiled_code |
Definition at line 138 of file compiler.c.
int compiling_code |
Definition at line 139 of file compiler.c.
char* source_extensions[] = { ".lgo", ".log", ".lg", ".logo", ".lho", ".lhogho" } |
Definition at line 141 of file compiler.c.