Use UDAs for Op disassembly
This commit is contained in:
parent
8717d37445
commit
2cd7a44bc7
2 changed files with 18 additions and 12 deletions
|
|
@ -10,22 +10,28 @@ struct OpColour{
|
|||
string r, g, b;
|
||||
}
|
||||
|
||||
enum OpConst;
|
||||
enum OpStack;
|
||||
enum OpJump;
|
||||
|
||||
enum OpCode : ubyte{
|
||||
@(OpColour("200", "200", "100")) Constant,
|
||||
@OpConst @(OpColour("200", "200", "100")) Constant,
|
||||
|
||||
@(OpColour("255", "200", "100")) Nil,
|
||||
@(OpColour("255", "200", "100")) True,
|
||||
@(OpColour("255", "200", "100")) False,
|
||||
|
||||
@(OpColour("000", "200", "100")) Pop,
|
||||
@(OpColour("060", "200", "150")) GetLocal,
|
||||
@(OpColour("000", "200", "150")) GetGlobal,
|
||||
@(OpColour("000", "200", "150")) DefineGlobal,
|
||||
@(OpColour("060", "200", "150")) SetLocal,
|
||||
@(OpColour("000", "200", "150")) SetGlobal,
|
||||
@OpStack @(OpColour("060", "200", "150")) GetLocal,
|
||||
@OpStack @(OpColour("060", "200", "150")) SetLocal,
|
||||
|
||||
@(OpColour("000", "255", "000")) Jump,
|
||||
@(OpColour("000", "200", "000")) JumpIfFalse,
|
||||
@(OpColour("010", "255", "000")) Loop,
|
||||
@OpConst @(OpColour("000", "200", "150")) GetGlobal,
|
||||
@OpConst @(OpColour("000", "200", "150")) DefineGlobal,
|
||||
@OpConst @(OpColour("000", "200", "150")) SetGlobal,
|
||||
|
||||
@OpJump @(OpColour("000", "255", "000")) Jump,
|
||||
@OpJump @(OpColour("000", "200", "000")) JumpIfFalse,
|
||||
@OpJump @(OpColour("010", "255", "000")) Loop,
|
||||
|
||||
@(OpColour("255", "100", "100")) Equal,
|
||||
@(OpColour("255", "100", "100")) Greater,
|
||||
|
|
|
|||
|
|
@ -68,11 +68,11 @@ long disassembleInstruction(Chunk* chunk, long offset){
|
|||
printf(colour!(" %02x ", Colour.Black).ptr, instruction);
|
||||
switch(instruction){
|
||||
static foreach(e; EnumMembers!OpCode){
|
||||
static if(e == OpCode.Constant || e == OpCode.DefineGlobal || e == OpCode.GetGlobal || e == OpCode.SetGlobal){
|
||||
static if(hasUDA!(e, OpConst)){
|
||||
case e: return constantInstruction!(e)(e.stringof, chunk, offset);
|
||||
} else static if(e == OpCode.GetLocal || e == OpCode.SetLocal){
|
||||
} else static if(hasUDA!(e, OpStack)){
|
||||
case e: return stackIndexInstruction!e(e.stringof, chunk, offset);
|
||||
} else static if(e == OpCode.Jump || e == OpCode.JumpIfFalse || e == OpCode.Loop){
|
||||
} else static if(hasUDA!(e, OpJump)){
|
||||
case e: return jumpInstruction!e(e.stringof, e == OpCode.Loop ? -1 : 1, chunk, offset);
|
||||
} else {
|
||||
case e: return simpleInstruction!e(e.stringof, offset);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue