Make Operands an array
This commit is contained in:
@@ -70,30 +70,21 @@ func assembleInstruction(in instruction) (*vm.Instruction, error) {
|
||||
return nil, fmt.Errorf("Incorrect number of operands: expected %d, found %d\n", len(pattern), len(operands))
|
||||
}
|
||||
|
||||
if len(operands) >= 1 {
|
||||
op1, err := assembleOperand(operands[0], pattern[0])
|
||||
for i, t := range pattern {
|
||||
op, err := assembleOperand(operands[i], t)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "In first operand")
|
||||
}
|
||||
|
||||
instr.Operand1 = op1
|
||||
}
|
||||
|
||||
if len(operands) >= 2 {
|
||||
op2, err := assembleOperand(operands[1], pattern[1])
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "In second operand")
|
||||
}
|
||||
|
||||
instr.Operand2 = op2
|
||||
instr.Operands[i] = op
|
||||
}
|
||||
|
||||
return instr, nil
|
||||
}
|
||||
|
||||
func assembleOperand(op string, t operandType) (vm.Operand, error) {
|
||||
func assembleOperand(op string, t operandType) (*vm.Operand, error) {
|
||||
op = strings.ToLower(op)
|
||||
ret := vm.Operand{}
|
||||
ret := &vm.Operand{}
|
||||
numStr := ""
|
||||
|
||||
switch {
|
||||
|
||||
Reference in New Issue
Block a user