Simplified file structure

This commit is contained in:
Eduard Urbach 2024-08-07 19:39:10 +02:00
parent cacee7260a
commit a466281307
Signed by: eduard
GPG key ID: 49226B848C78F6C8
219 changed files with 453 additions and 457 deletions

46
src/core/Compare.go Normal file
View file

@ -0,0 +1,46 @@
package core
import (
"git.akyoto.dev/cli/q/src/ast"
"git.akyoto.dev/cli/q/src/errors"
"git.akyoto.dev/cli/q/src/expression"
"git.akyoto.dev/cli/q/src/token"
)
// Compare evaluates a boolean expression.
func (f *Function) Compare(comparison *expression.Expression) error {
left := comparison.Children[0]
right := comparison.Children[1]
if left.IsLeaf() && left.Token.Kind == token.Identifier {
name := left.Token.Text(f.File.Bytes)
variable := f.VariableByName(name)
if variable == nil {
return errors.New(&errors.UnknownIdentifier{Name: name}, f.File, left.Token.Position)
}
defer f.UseVariable(variable)
return f.Execute(comparison.Token, variable.Register, right)
}
if ast.IsFunctionCall(left) && right.IsLeaf() {
_, err := f.CompileCall(left)
if err != nil {
return err
}
return f.ExecuteLeaf(comparison.Token, f.CPU.Output[0], right.Token)
}
tmp := f.NewRegister()
_, err := f.ExpressionToRegister(left, tmp)
if err != nil {
return err
}
defer f.FreeRegister(tmp)
return f.Execute(comparison.Token, tmp, right)
}