Implemented boolean literals
This commit is contained in:
parent
1f0db51a95
commit
bf5110edd4
11 changed files with 69 additions and 13 deletions
|
@ -1,8 +1,11 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"git.urbach.dev/cli/q/src/asm"
|
||||
"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"
|
||||
)
|
||||
|
||||
// CompileCondition inserts code to jump to the start label or end label depending on the truth of the condition.
|
||||
|
@ -62,7 +65,26 @@ func (f *Function) CompileCondition(condition *expression.Expression, successLab
|
|||
|
||||
return err
|
||||
|
||||
default:
|
||||
case token.Call:
|
||||
typ, err := f.CompileCall(condition)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(typ) == 0 {
|
||||
return errors.New(errors.UntypedExpression, f.File, condition.Token.Position)
|
||||
}
|
||||
|
||||
if !types.Is(typ[0], types.Bool) {
|
||||
return errors.New(&errors.TypeMismatch{Encountered: typ[0].Name(), Expected: types.Bool.Name()}, f.File, condition.Token.Position)
|
||||
}
|
||||
|
||||
f.RegisterNumber(asm.COMPARE, f.CPU.Output[0], 0)
|
||||
f.Jump(asm.JE, failLabel)
|
||||
return nil
|
||||
|
||||
case token.Equal, token.NotEqual, token.Greater, token.Less, token.GreaterEqual, token.LessEqual:
|
||||
err := f.Compare(condition)
|
||||
|
||||
if condition.Parent == nil {
|
||||
|
@ -70,5 +92,8 @@ func (f *Function) CompileCondition(condition *expression.Expression, successLab
|
|||
}
|
||||
|
||||
return err
|
||||
|
||||
default:
|
||||
return errors.New(errors.InvalidCondition, f.File, condition.Token.Position)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue