|
| 1 | + |
| 2 | +| MNEMONIC | Bytecode | Stack In | Stack Out | Description | |
| 3 | +|----------|-----------|----------------------------------------|----------------|---------------------------------------------| |
| 4 | +| n/a | 0x00 | | | Null string terminator | |
| 5 | +| push | 0x01 | object id | object id | Pushes an object into stack | |
| 6 | +| ipush | 0x02 | variable id | variable value | Push an integer into stack | |
| 7 | +| swap | 0x03 | a, b | b, a | Swaps the top 2 values on the stack | |
| 8 | +| call | 0x04 | arg n, arg n-1 ... arg 0, method ID | return value | Call library function | |
| 9 | +| [] | 0x05 | | | RESERVED, see 0x2A | |
| 10 | +| ret | 0x06 | | | Return void to caller | |
| 11 | +| iret | 0x07 | return value | return value | Return value after call, return to caller | |
| 12 | +| magic | 0x08 | | | BREAKPOINT | |
| 13 | +| error | 0x09 | error code | all cleared | Activates command block to print exception. | |
| 14 | +| n/a | 0x0A-0x19 | | | RESERVED FOR LIBRARY AND REFERENCES | |
| 15 | +| _raw | 0x2A | arg n, arg n-1 ... arg 0 | | Insert raw Minecraft comamnd* | |
| 16 | +| irv | 0x2B | variable type id, variable name hashed | | Register a new empty variable | |
| 17 | +| ro | 0x2C | target object id, source object id | | Registers a new object | |
| 18 | +| ipop | 0x2D | variable id | | Pops integer from stack into variable | |
| 19 | +| pop | 0x2E | target object id, source object id | | Pops object from stack into another object | |
| 20 | +| spush | 0x2F | variable id | variable value | Push a string into string register | |
| 21 | +| lpush | 0x30 | variable id | variable value | Push a long into stack | |
| 22 | +| bpush | 0x31 | variable id | variable value | Push a boolean into stack | |
| 23 | +| spop | 0x32 | variable id | | Pops string from register** into variable | |
| 24 | +| lpop | 0x33 | variable id | | Pops long from stack into variable | |
| 25 | +| bpop | 0x34 | variable id | | Pops boolean from stack into variable | |
| 26 | +| lods | 0x35 | | | Loads string into register | |
| 27 | +| lodl | 0x36 | | | Loads long into register | |
| 28 | +| lodb | 0x37 | | | Loads boolean into register | |
| 29 | +| lodi | 0x38 | | | Loads integer into register | |
| 30 | +| pops | 0x39 | | value | Loads register into stack | |
| 31 | +| popl | 0x3A | | value | Loads register into stack | |
| 32 | +| popb | 0x3B | | value | Loads register into stack | |
| 33 | +| popi | 0x3C | | value | Loads register into stack | |
| 34 | + |
| 35 | +For opcode 0x2A* |
| 36 | + - Note that the string stored in the stack must be null terminated with 0x0000 (yes, that's 4 bytes) |
| 37 | + - Note if there is 0x05 following the the null termination, then it signals a reference to an argument. The 0x05 is then followed by the argument id |
| 38 | + - The argument is structured like an object |
| 39 | + |
| 40 | +** String register differs from regular registers |
| 41 | + |
| 42 | +Stack and registers are abstract. Stack and registers can only hold up to 64 bits of data. |
| 43 | + |
| 44 | +How it all operates: |
| 45 | +Roslyn Parser ->[References]-> OPCODES ->[Library]-> Command Blocks |
| 46 | + |
| 47 | +A [Reference] contains all the variable structures. It contains all the system-required method names hashed, ther corresponding IDs |
| 48 | +and their structures. This will be written in CBIL, and compiled to the same bytecode above. |
| 49 | +A [Library] contains all the code linked to the system-required methods. The names of each method should match that of the [Reference]. This will be |
| 50 | +written in CBIL, and compiled to the bytecode above. |
| 51 | +A [structure] is something to define the structure a variable/object that will be stored in the stack. Think of classes. |
| 52 | + |
| 53 | +A variable will be stored in a variable dictionary with the id and it's corresponding type and hashed name. |
| 54 | +An object will be stored in an object dictionary with the id and it's corresponding type and hashed name. |
| 55 | + |
| 56 | +| MNEMONIC | Bytecode | Stack In | Stack Out | Description | |
| 57 | +|---------------------------|----------|----------|-----------|----------------------------------------------| |
| 58 | +| cmp | 0x0A | a, b | flag *** | Compare 2 values | |
| 59 | +| je | 0x0B | flag*** | | Jump to function if equal | |
| 60 | +| jne | 0x0C | flag*** | | Jump to function if not equal | |
| 61 | +| jb | 0x0D | flag*** | | Jump to function if less than | |
| 62 | +| jbe | 0x0E | flag*** | | Jump to function if less than or equal to | |
| 63 | +| ja | 0x0F | flag*** | | Jump to function if greater than | |
| 64 | +| jae | 0x10 | flag*** | | Jump to function if greater than or equal to | |
| 65 | +| [name] [class id] [flags] | 0x11 | | | Defines a function | |
| 66 | +| class [name]: | 0x12 | | | Defines a class (object) | |
| 67 | +| namespace [name] | 0x13 | | | Defines a namespace | |
| 68 | + |
| 69 | +All methods + variables in a class would be names [namespace].[class].[name] to give each class an unique id name. When referencing a method of an object, |
| 70 | +the return type of the method will be automatically be looked up, along with the namespace it is under. |
| 71 | + |
| 72 | +Example CBIL script: |
| 73 | +``` csharp |
| 74 | +// User script |
| 75 | +using CBIL; |
| 76 | +namespace ExampleScript |
| 77 | +{ |
| 78 | + class Example |
| 79 | + { |
| 80 | + string exampleString = "Hello World"; |
| 81 | + void main() |
| 82 | + { |
| 83 | + printLn(exampleString); |
| 84 | + } |
| 85 | + } |
| 86 | +} |
| 87 | +// Library script |
| 88 | +namespace CBIL |
| 89 | +{ |
| 90 | + class Print |
| 91 | + { |
| 92 | + public static void printLn(string input) |
| 93 | + { |
| 94 | + _volatile_("say @a \"{s:0}\"", input); |
| 95 | + } |
| 96 | + } |
| 97 | +} |
| 98 | +``` |
| 99 | + |
| 100 | +Bytecode Mnemonics: |
| 101 | +``` assembly |
| 102 | +namespace ExampleScript: |
| 103 | +class ExampleScript.Example: |
| 104 | + irv 0x5 ExampleScript.Example.exampleString |
| 105 | + lods "Hello World" |
| 106 | + spop ExampleScript.Example.exampleString |
| 107 | + ExampleScript.Example.Main void private: |
| 108 | + spush ExampleScript.Example.exampleString |
| 109 | + call CBIL.Print.printLN |
| 110 | +
|
| 111 | +namespace CBIL: |
| 112 | +class CBIL.Print: |
| 113 | + CBIL.Print.printLN void public static: |
| 114 | + irv 0x5 CBIL.Print.printLN.s |
| 115 | + spop CBIL.Print.printLN.s |
| 116 | + _raw "say @a \"" [CBIL.Print.printLN.s] "\" |
| 117 | + ret |
| 118 | +``` |
0 commit comments