Implemented register to register instructions

This commit is contained in:
2024-06-23 20:26:53 +02:00
parent 31845dbc48
commit 4fc1935183
11 changed files with 171 additions and 16 deletions

View File

@ -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()