-
Notifications
You must be signed in to change notification settings - Fork 0
2 Meta instructions
The meta-instructions in Lia start at [
character and stops with ]
. Each instruction has a different syntax and will be processed by the compiler in a different way. You can insert break lines inside meta-instructions to be more readable.
All meta-instructions is interpreted at compile-time.
[import "mod1", "mod2", "mod3" ...]
The import
meta-instruction is used to import the content of one or more modules, the module file must have the .lia
extension. The Lia compiler will search the module in the default path, defined paths by command line, and the local path respectively.
So, if you have a module in "modules/mymodule.lia", then you can use:
[import "modules/mymodule"]
If you don't want to specify the folder, you can set this folder to search by modules using -I option to the compiler.
$ lia example.lia -I modules -o output
You can specify various paths to search by modules using various -I options.
The $
will be replaced by the target name, you can import modules to different targets if you put it inside a folder with the target name and use the $
, like that:
[import "$/lia"]
# Import "ases/lia.lia" if target is 'ases'.
[require "mod1", "mod2", "mod3" ...]
The require
usage is the same as import
, but this declares the dependency of a determined module instead import it. If at the moment of the interpretation of this instruction anyone of specified modules not be imported yet, an error will be printed by the compiler.
[new command = "ases code"]
Definition of commands is the main part of the Lia language, you can write a new command receiving at maximum three operands that be compiled to Ases code. The simplest example is the mov
instruction defined in the lia
module:
[new mov x:r y:r = "Yx"]
mov ra, rb # Compiles to: "Ba"
You can optionally put a sequence of maximum three operands, specifying the name of one character and the type. Valid types are r
for register, i
for immediate value (character or number), p
for procedure name, and s
for string.
For registers operands, you can refer to your name using uppercase to gets your value, and refer using lowercase to sets it. It's the same way of the use of registers in Ases language.
Refer to an immediate operand gets your value, and refer a string prints it in the output, and refer to a procedure calls it.
Note: Any valid register name in Ases language is an invalid name to an operand.
Note 2: Redeclare a command overwrites it.
[action name]
Runs a determined action.
Name | Action |
---|---|
stop | Stops the interpretation of the module |
[if CONDITION then !action]
[if CONDITION then
mov ra, rb
set rc, 5
# ...
]
Conditional runs an action or expand a piece of code. The CONDITION
follows the grammar:
CONDITION: TOKEN == TOKEN
| TOKEN != TOKEN
| not CONDITION
| TOKEN
;
Token can be a macro name with a variant with no token list. Example:
[if TARGET == "ases" then
say "Compiled to Ases language\n"
]