25 lines
704 B
Go
25 lines
704 B
Go
package core
|
|
|
|
import (
|
|
"git.akyoto.dev/cli/q/src/cpu"
|
|
"git.akyoto.dev/cli/q/src/expression"
|
|
"git.akyoto.dev/cli/q/src/token"
|
|
"git.akyoto.dev/cli/q/src/types"
|
|
)
|
|
|
|
// Evaluate evaluates an expression and returns a register that contains the value of the expression.
|
|
func (f *Function) Evaluate(expr *expression.Expression) (types.Type, cpu.Register, bool, error) {
|
|
if expr.Token.Kind == token.Identifier {
|
|
name := expr.Token.Text(f.File.Bytes)
|
|
variable := f.VariableByName(name)
|
|
|
|
if variable.Alive == 1 {
|
|
f.UseVariable(variable)
|
|
return variable.Type, variable.Register, false, nil
|
|
}
|
|
}
|
|
|
|
tmp := f.NewRegister()
|
|
typ, err := f.ExpressionToRegister(expr, tmp)
|
|
return typ, tmp, true, err
|
|
}
|