Added Value type
This commit is contained in:
@ -2,26 +2,24 @@ package core
|
||||
|
||||
import (
|
||||
"git.urbach.dev/cli/q/src/ast"
|
||||
"git.urbach.dev/cli/q/src/cpu"
|
||||
"git.urbach.dev/cli/q/src/errors"
|
||||
"git.urbach.dev/cli/q/src/expression"
|
||||
"git.urbach.dev/cli/q/src/token"
|
||||
"git.urbach.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) {
|
||||
func (f *Function) Evaluate(expr *expression.Expression) (Value, bool, error) {
|
||||
if expr.Token.Kind == token.Identifier {
|
||||
name := expr.Token.Text(f.File.Bytes)
|
||||
variable := f.VariableByName(name)
|
||||
|
||||
if variable == nil {
|
||||
return nil, 0, false, errors.New(&errors.UnknownIdentifier{Name: name}, f.File, expr.Token.Position)
|
||||
return Value{}, false, errors.New(&errors.UnknownIdentifier{Name: name}, f.File, expr.Token.Position)
|
||||
}
|
||||
|
||||
if variable.Alive == 1 {
|
||||
f.UseVariable(variable)
|
||||
return variable.Type, variable.Register, false, nil
|
||||
return Value{variable.Type, variable.Register}, false, nil
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,13 +27,13 @@ func (f *Function) Evaluate(expr *expression.Expression) (types.Type, cpu.Regist
|
||||
types, err := f.CompileCall(expr)
|
||||
|
||||
if err != nil {
|
||||
return nil, 0, false, err
|
||||
return Value{}, false, err
|
||||
}
|
||||
|
||||
return types[0], f.CPU.Output[0], false, nil
|
||||
return Value{types[0], f.CPU.Output[0]}, false, nil
|
||||
}
|
||||
|
||||
tmp := f.NewRegister()
|
||||
typ, err := f.ExpressionToRegister(expr, tmp)
|
||||
return typ, tmp, true, err
|
||||
return Value{typ, tmp}, true, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user