LS2IL:Hello World

From ismods.com: dedicated to promoting white hat, EULA-compliant Inner Space and LavishScript mods
Jump to: navigation, search

Hello World! as written in LavishScript 2 Intermediate Language and executed with ls2il.exe

; Hello World!
function
.registers 1
RESOLVETYPE 0, "System.Console"
RESOLVESTATICMETHOD 0, register[0], "WriteLine{string}"
FASTCALLSTATICMETHOD register[0], "Hello World!"
endfunction

Note: System.Console is not technically provided by the standard runtime environment, but in this case defined by ls2il.exe

Walkthrough

Let's dissect. The first line is a comment:

; Hello World!

Comments in LS2IL are specified with the ; character, and continue to the end of the line. Multi-line comments do not exist.


The next line begins a function:

function

Functions in LS2IL are defined by 'function' on its own line, and terminated with 'endfunction'.


The next line proposes a property of the function:

.registers 1

Lines starting with . are a property of the function, or the code chunk if not within a function. In this case, we specify the number of registers we need for our instructions. Our example re-uses one register for two purposes.


Next we have our instructions:

RESOLVETYPE 0, "System.Console"

Instructions are documented in the Instruction Reference. In this case, RESOLVETYPE will try to resolve a Type object by name "System.Console", and put it in register[0] (the first operand specifies the destination register number).


RESOLVESTATICMETHOD 0, register[0], "WriteLine{string}"

Here, RESOLVESTATICMETHOD will resolve a Static Method called "WriteLine{string}" from a Type in register[0], and place it in register[0] (the first operand specifies the destination register number).


FASTCALLSTATICMETHOD register[0], "Hello World!"

Here, FASTCALLSTATICMETHOD will execute a Static Method referenced by register[0], passing the string value "Hello World!"


And finally, we terminate the function.

endfunction