Skip to content

Instantly share code, notes, and snippets.

@AlexCouch
Last active March 27, 2020 07:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexCouch/7f188052f64512a75f76424c579c2133 to your computer and use it in GitHub Desktop.
Save AlexCouch/7f188052f64512a75f76424c579c2133 to your computer and use it in GitHub Desktop.
//Initialize the core bytecode engine. The result is the built engine object that can then be used by the IO Apps
val HIREngine = BytecodeEngine.init{
configureBytecode{
//Configure a chunk of bytecode called "identifier" which will instruct the engine how to construct this chunk.
//The order to which you call these factory methods dictates the exact order and mechanism the engine will construct the chunk
//This chunk can then be referenced by the IO Apps, for constructing a certain chunk from a certain input at a certain time
//Or for deserializing, converting, or "lowering" by the output apps.
createChunk("identifier"){
createOpcode(0x11){
this.name = "IDENTIFIER"
this.description = "This denotes an identifier and the engine should read in a null-terminated string after reading this byte"
}
//Include the StringWriter plugin which will tell the engine to read in a string following the read of the previous opcode 0x11
include{
//Configure the StringReader plugin
plugin(StringWriter){
onCatch{ it ->
//`it` is the exception that was caught during string writing
ErrorManager.createErrorMessage(it)
}
}
}
}
//Create a chunk called "global_variable". It is the opcode 0x35, followed by an "identifier" chunk, followed by an "expression" chunk.
createChunk("global_variable"){
createOpcode(0x35){
this.name = "GLOBAL_VAR"
this.description = "This denotes the start of a global variable and should be treated as such"
}
include{
chunk("identifier")
}
include{
chunk("expression")
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment