Skip to content

Commit

Permalink
use BoolType as result in checkOrConvertType
Browse files Browse the repository at this point in the history
  • Loading branch information
thehowl committed Dec 10, 2024
1 parent 1fb863e commit f83eaa3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
35 changes: 18 additions & 17 deletions gnovm/pkg/gnolang/op_binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,6 @@ func (m *Machine) doOpLand() {
lv.SetBool(lv.GetBool() && rv.GetBool())
}

// setMaybeUntypedBool sets lv to b; it will be untyped if both lv and rv are
// untyped; otherwise, it will be a typed bool.
func setMaybeUntypedBool(lv, rv *TypedValue, b bool) {
tp := BoolType
if isUntyped(lv.T) && isUntyped(rv.T) {
tp = UntypedBoolType
}
lv.T, lv.V = tp, nil
lv.SetBool(b)
}

func (m *Machine) doOpEql() {
m.PopExpr()

Expand All @@ -93,7 +82,9 @@ func (m *Machine) doOpEql() {
}
// set result in lv.
res := isEql(m.Store, lv, rv)
setMaybeUntypedBool(lv, rv, res)
lv.T = UntypedBoolType
lv.V = nil
lv.SetBool(res)
}

func (m *Machine) doOpNeq() {
Expand All @@ -108,7 +99,9 @@ func (m *Machine) doOpNeq() {

// set result in lv.
res := !isEql(m.Store, lv, rv)
setMaybeUntypedBool(lv, rv, res)
lv.T = UntypedBoolType
lv.V = nil
lv.SetBool(res)
}

func (m *Machine) doOpLss() {
Expand All @@ -123,7 +116,9 @@ func (m *Machine) doOpLss() {

// set the result in lv.
res := isLss(lv, rv)
setMaybeUntypedBool(lv, rv, res)
lv.T = UntypedBoolType
lv.V = nil
lv.SetBool(res)
}

func (m *Machine) doOpLeq() {
Expand All @@ -138,7 +133,9 @@ func (m *Machine) doOpLeq() {

// set the result in lv.
res := isLeq(lv, rv)
setMaybeUntypedBool(lv, rv, res)
lv.T = UntypedBoolType
lv.V = nil
lv.SetBool(res)
}

func (m *Machine) doOpGtr() {
Expand All @@ -153,7 +150,9 @@ func (m *Machine) doOpGtr() {

// set the result in lv.
res := isGtr(lv, rv)
setMaybeUntypedBool(lv, rv, res)
lv.T = UntypedBoolType
lv.V = nil
lv.SetBool(res)
}

func (m *Machine) doOpGeq() {
Expand All @@ -168,7 +167,9 @@ func (m *Machine) doOpGeq() {

// set the result in lv.
res := isGeq(lv, rv)
setMaybeUntypedBool(lv, rv, res)
lv.T = UntypedBoolType
lv.V = nil
lv.SetBool(res)
}

func (m *Machine) doOpAdd() {
Expand Down
1 change: 1 addition & 0 deletions gnovm/pkg/gnolang/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -3564,6 +3564,7 @@ func checkOrConvertType(store Store, last BlockNode, x *Expr, t Type, autoNative
checkOrConvertType(store, last, &bx.Left, rt, autoNative)
checkOrConvertType(store, last, &bx.Right, rt, autoNative)
}
t = BoolType
default:
// do nothing
}
Expand Down

0 comments on commit f83eaa3

Please sign in to comment.