Implemented register to register instructions
This commit is contained in:
@ -142,13 +142,18 @@ func (f *Function) CompileVariableDefinition(expr *expression.Expression) error
|
||||
return err
|
||||
}
|
||||
|
||||
// All expressions are returned to the memory pool.
|
||||
// To avoid losing variable values, we will detach it from the expression.
|
||||
expr.RemoveChild(value)
|
||||
reg, exists := f.CPU.FindFree()
|
||||
|
||||
if !exists {
|
||||
panic("no free registers")
|
||||
}
|
||||
|
||||
f.ExpressionToRegister(value, reg)
|
||||
f.CPU.Use(reg)
|
||||
|
||||
f.Variables[name] = &Variable{
|
||||
Name: name,
|
||||
Value: value,
|
||||
Name: name,
|
||||
Register: reg,
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -197,7 +202,8 @@ func (f *Function) TokenToRegister(t token.Token, register cpu.Register) error {
|
||||
return errors.New(&errors.UnknownIdentifier{Name: name}, f.File, t.Position)
|
||||
}
|
||||
|
||||
return f.ExpressionToRegister(variable.Value, register)
|
||||
f.Assembler.MoveRegisterRegister(register, variable.Register)
|
||||
return nil
|
||||
|
||||
case token.Number:
|
||||
value := t.Text()
|
||||
|
Reference in New Issue
Block a user