Difference between revisions of "LS2IL"
From ismods.com: dedicated to promoting white hat, EULA-compliant Inner Space and LavishScript mods
Line 6: | Line 6: | ||
* IL-definable '''Values''' currently can be: | * IL-definable '''Values''' currently can be: | ||
** null | ** null | ||
− | ** | + | ** signed integer in 8, 16, 32 or 64 bits of bytecode storage, e.g. '''.value i8 -1''' to add an integer -1 stored in 8 bits or simply '''.value -1''' to let the assembler decide |
− | ** | + | ** unsigned integer the same as signed, but e.g. '''.value u8 255''' to add an integer 255 stored in 8 bits or simply '''.value 255''' to let the assembler decide |
+ | ** floating point (32 or 64 bits) | ||
** binary denoted by || and given in hex pairs | ** binary denoted by || and given in hex pairs | ||
** string denoted by "" | ** string denoted by "" | ||
Line 17: | Line 18: | ||
** '''chunkvalue['''#''']''': 0-based Chunk Value | ** '''chunkvalue['''#''']''': 0-based Chunk Value | ||
** '''exception''': Exception currently being handled (hopefully in your exception handler) | ** '''exception''': Exception currently being handled (hopefully in your exception handler) | ||
+ | ** '''field['''#''']: 0-based Field from 'this' object | ||
** '''function''': Function currently being executed | ** '''function''': Function currently being executed | ||
** '''function['''#''']''': 0-based Function from the Chunk | ** '''function['''#''']''': 0-based Function from the Chunk | ||
Line 24: | Line 26: | ||
** '''inputs''': Array of inputs | ** '''inputs''': Array of inputs | ||
** '''registers''': Array of registers | ** '''registers''': Array of registers | ||
+ | ** '''this''': The current object, or 'subject', being manipulated | ||
== Hello World! == | == Hello World! == | ||
Line 30: | Line 33: | ||
.registers 1 | .registers 1 | ||
RESOLVETYPE 0, "System.Console" | RESOLVETYPE 0, "System.Console" | ||
− | RESOLVESTATICMETHOD 0, register[0], " | + | RESOLVESTATICMETHOD 0, register[0], "WriteLine{string}" |
FASTCALLSTATICMETHOD register[0], "Hello World!" | FASTCALLSTATICMETHOD register[0], "Hello World!" | ||
endfunction | endfunction |
Revision as of 13:41, 21 October 2012
LS2IL is the custom IL used the current LavishScript 2 assembler, as built into ls2il.exe with the standard LavishScript 2 execution environment.
Here's the basics:
- The text of a LS2IL file or buffer defines a Chunk of code.
- Chunks have Values (i.e. script-scope data) and Functions.
- IL-definable Values currently can be:
- null
- signed integer in 8, 16, 32 or 64 bits of bytecode storage, e.g. .value i8 -1 to add an integer -1 stored in 8 bits or simply .value -1 to let the assembler decide
- unsigned integer the same as signed, but e.g. .value u8 255 to add an integer 255 stored in 8 bits or simply .value 255 to let the assembler decide
- floating point (32 or 64 bits)
- binary denoted by || and given in hex pairs
- string denoted by ""
- arrays (0-based ordered list of Values) denoted by {}, e.g. {1, 2.0, | 03 |, "4"}
- tables (Values keyed by string) denoted by [key=value], e.g. [ "apples"=2 , "oranges"=3.0 , "ducks"={"all","in","a","row"} ]
- Functions have up to 256 Registers, any number of Values (i.e. static function-scope data), and any number of Instructions. Parameters passed to the function are called Inputs to the Function. Functions in the VM don't return a Value; they will instead do so by modifying the Inputs!
- Instructions have the instruction/opcode and up to 3 Operands.
- Operands are the same as Values but can also be one of the following:
- chunkvalue[#]: 0-based Chunk Value
- exception: Exception currently being handled (hopefully in your exception handler)
- field[#]: 0-based Field from 'this' object
- function: Function currently being executed
- function[#]: 0-based Function from the Chunk
- functionvalue[#]: 0-based Function Value (Value from current Function)
- input[#]: 0-based Input
- register[#]: 0-based Register
- inputs: Array of inputs
- registers: Array of registers
- this: The current object, or 'subject', being manipulated
Hello World!
; Hello World! function .registers 1 RESOLVETYPE 0, "System.Console" RESOLVESTATICMETHOD 0, register[0], "WriteLine{string}" FASTCALLSTATICMETHOD register[0], "Hello World!" endfunction
See LS2IL:Hello World for a walkthrough of this code.