Simplified file structure
This commit is contained in:
parent
cacee7260a
commit
a466281307
219 changed files with 453 additions and 457 deletions
46
src/core/Compare.go
Normal file
46
src/core/Compare.go
Normal 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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue