Refactor VM and operators
This commit is contained in:
@@ -35,6 +35,24 @@ func (b *Boolean) Int() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (b *Boolean) LogicalAnd(other Object) (Object, error) {
|
||||
if !AssertTypes(other, BooleanType, IntegerType) {
|
||||
return nil, NewBinaryOpError(b, other, "&&")
|
||||
}
|
||||
return &Boolean{b.Value && other.Bool()}, nil
|
||||
}
|
||||
|
||||
func (b *Boolean) LogicalOr(other Object) (Object, error) {
|
||||
if !AssertTypes(other, BooleanType, IntegerType) {
|
||||
return nil, NewBinaryOpError(b, other, "||")
|
||||
}
|
||||
return &Boolean{b.Value || other.Bool()}, nil
|
||||
}
|
||||
|
||||
func (b *Boolean) LogicalNot() Object {
|
||||
return &Boolean{!b.Value}
|
||||
}
|
||||
|
||||
func (b *Boolean) Compare(other Object) int {
|
||||
if obj, ok := other.(*Boolean); ok {
|
||||
return b.Int() - obj.Int()
|
||||
|
||||
Reference in New Issue
Block a user