-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Lia is a programming language that is compiled to Ases. It's a very low abstraction of the Ases, which is why the language imitates the Assembly syntax. Think Ases like the machine code and Lia like Assembly.
This project is for learning purposes, I promise to make a serious language before my death. :)
You have to install the Lia and the Ases in your system, to install Ases:
$ git clone https://github.com/Silva97/Ases
$ cd Ases
$ make
$ sudo make install
And the Lia is the same way:
$ git clone https://github.com/Silva97/Lia
$ cd Lia
$ make
$ sudo make install
The simplest usage is:
$ lia source.lia -o output
$ ./output
For see help about usage of the compiler, run lia -h
in the terminal.
If you want to learn how to program in Lia (why you want it???), here is the place.
First I recommend you to install the syntax highlight of the Lia language, you can see the files in the syntaxes folder.
Ases is a register machine that has 12 general-purpose registers, that as named from 'A' to 'L'. The register DP (Data Pointer) is used as a pointer to the memory data, and the register "stack" (it's not a real stack) is indirectly used to hold data to operations. This is a very simple example that gets the value of the 'A' register and set 'B' (b = a
):
Ab
All instructions in Ases is just one character. The name of the register in uppercase gets your value and sets "stack" to it, the name of the register in lowercase gets the value of the "stack" and sets the register.
In Lia you can use general-purpose registers like ra
, rb
.. rl
. The data pointer is referred to as dp
and "stack" as ss
.
[import "lia"]
mov rb, ra
This instruction is compiled to the same previous Ases code.
In the Ases the data memory is used with the DP register. To store a value in the memory, is used the !
instruction, and =
is used to gets the value in the memory. You can use >
and <
to increments and decrements the data pointer respectively.
But in Lia this memory system has been converted to a (real) stack. You can push and pop values from the stack, like in:
[import "lia"]
set ra, 55
push ra
push 23
pop ra
pop rb
The final result of this code is the ra
register with value 23 and rb
with 55. The push in the Lia is !>
in Ases, and the pop is <=
. The data pointer after a push is pointing to a free memory space, you can use this space if you want, but don't forget that use of the stack overwrites this value. The instruction load
gets the value pointed by dp
, and the instruction store
sets it:
[import "lia"]
set ra, 23
store ra
mov ra, rc
add ra, rd
# Do anything here
load ra
You can import the module var
to allocate a stack frame in the stack of the Lia and use this space to local variables. Simplest example:
[import "lia", "var"]
alloc 5
setvar 0, 'x' # var0 = 'x'
movvar 1, ra # var1 = ra
getvar rb, 1 # rb = var1
free 5
In the Ases the communication is just an input of data and output, don't have files or any other method to access the "external world". Functions in Ases is just instructions 0
.. 9
that do complex operations. The 0 function gets the input and sets the ss
, and 1 function output the character in ss
register. You can use these functions in Lia with the func
instruction:
[import "lia"]
func 0
inc ss # Increments ss, like in C: ss++;
func 1
But it's not the best method, the lia
module defines commands to do it in a best way:
[import "lia"]
in ra
inc ra
out ra
iout '\n'
out
gets a register operand, and iout
an immediate operand. The immediate operand can be a literal number or a literal character.
The "meta-instructions" is a pretty name to the instructions processed by the compiler but did not an instruction that is executed in runtime. The meta-import
is used to import a module in the source code, you can insert the name of the default modules or the relative path to a module you wrote. You can import more than one module, separating each by comma, like example:
[import "lia", "var", "modules/mymodule"]
A module file should have a .lia
extension. For example the "lia" module has the filename "lia.lia".
Note: The meta-instructions is processed before the generation of the code.
A meta-instruction syntax is different for each instruction, but this starts with [
and end with ]
. You can insert break lines inside a meta-instruction. Like in:
[
import "lia",
"var"
]
The instructions are the builtin instructions of the Lia language, and commands are the module-defined commands by the meta-new
instruction. func
, push
, store
and say
are examples of instructions. And in
, mov
, add
are commands.
The syntax of a instruction is variable but all the commands have the same syntax, a maximum of three operands of type: Register, immediate, procedure name, or string.
You can use a command referring to your name and passing arguments separated by a comma, like that:
command argument1, argument2, argument3