Thread safety for status updates, periodically minify
This commit is contained in:
@@ -3,3 +3,13 @@ package vm
|
||||
type Function struct {
|
||||
Instructions []*Instruction
|
||||
}
|
||||
|
||||
func (fnc *Function) Copy() *Function {
|
||||
ret := &Function{}
|
||||
|
||||
for _, instr := range fnc.Instructions {
|
||||
ret.Instructions = append(ret.Instructions, instr.Copy())
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
@@ -7,3 +7,15 @@ type Instruction struct {
|
||||
|
||||
opHandler opHandler `struc:"skip"`
|
||||
}
|
||||
|
||||
func (instr *Instruction) Copy() *Instruction {
|
||||
ret := &Instruction{
|
||||
OpCode: instr.OpCode,
|
||||
}
|
||||
|
||||
for i, opr := range instr.Operands {
|
||||
ret.Operands[i] = opr.Copy()
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
@@ -13,3 +13,14 @@ type Operand struct {
|
||||
Reserved [3]byte
|
||||
Value uint64
|
||||
}
|
||||
|
||||
func (opr *Operand) Copy() *Operand {
|
||||
if opr == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &Operand{
|
||||
Type: opr.Type,
|
||||
Value: opr.Value,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,3 +6,17 @@ type Program struct {
|
||||
InstructionLimit uint64
|
||||
Functions []*Function
|
||||
}
|
||||
|
||||
func (prog *Program) Copy() *Program {
|
||||
ret := &Program{
|
||||
GlobalMemorySize: prog.GlobalMemorySize,
|
||||
FunctionMemorySize: prog.FunctionMemorySize,
|
||||
InstructionLimit: prog.InstructionLimit,
|
||||
}
|
||||
|
||||
for _, fnc := range prog.Functions {
|
||||
ret.Functions = append(ret.Functions, fnc.Copy())
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user