Skip to content

Commit 4292a3f

Browse files
committed
...
1 parent b0850b2 commit 4292a3f

File tree

13 files changed

+188
-67
lines changed

13 files changed

+188
-67
lines changed

gno.land/pkg/sdk/vm/vm.proto

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ message m_call {
1515
repeated string args = 5;
1616
}
1717

18+
message m_run {
19+
string caller = 1;
20+
string send = 2;
21+
std.MemPackage package = 3;
22+
}
23+
1824
message m_addpkg {
1925
string creator = 1;
2026
std.MemPackage package = 2;
@@ -28,4 +34,8 @@ message InvalidStmtError {
2834
}
2935

3036
message InvalidExprError {
37+
}
38+
39+
message TypeCheckError {
40+
repeated string errors = 1 [json_name = "Errors"];
3141
}

gnovm/pkg/gnolang/debugger_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ func TestRemoteDebug(t *testing.T) {
196196
func TestRemoteError(t *testing.T) {
197197
_, err := evalTest(":xxx", "", debugTarget)
198198
t.Log("err:", err)
199-
if !strings.Contains(err, "tcp/xxx: unknown port") {
199+
if !strings.Contains(err, "tcp/xxx: unknown port") &&
200+
!strings.Contains(err, "tcp/xxx: nodename nor servname provided, or not known") {
200201
t.Error(err)
201202
}
202203
}

gnovm/pkg/gnolang/gnolang.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ message FuncValue {
5858
google.protobuf.Any closure = 5 [json_name = "Closure"];
5959
string file_name = 6 [json_name = "FileName"];
6060
string pkg_path = 7 [json_name = "PkgPath"];
61+
string native_pkg = 8 [json_name = "NativePkg"];
62+
string native_name = 9 [json_name = "NativeName"];
6163
}
6264

6365
message MapValue {

gnovm/pkg/gnolang/op_assign.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (m *Machine) doOpAddAssign() {
5050
rv := m.PopValue() // only one.
5151
lv := m.PopAsPointer(s.Lhs[0])
5252
if debug {
53-
assertSameTypes(lv.TV.T, rv.T)
53+
debugAssertSameTypes(lv.TV.T, rv.T)
5454
}
5555

5656
// XXX HACK (until value persistence impl'd)
@@ -73,7 +73,7 @@ func (m *Machine) doOpSubAssign() {
7373
rv := m.PopValue() // only one.
7474
lv := m.PopAsPointer(s.Lhs[0])
7575
if debug {
76-
assertSameTypes(lv.TV.T, rv.T)
76+
debugAssertSameTypes(lv.TV.T, rv.T)
7777
}
7878

7979
// XXX HACK (until value persistence impl'd)
@@ -96,7 +96,7 @@ func (m *Machine) doOpMulAssign() {
9696
rv := m.PopValue() // only one.
9797
lv := m.PopAsPointer(s.Lhs[0])
9898
if debug {
99-
assertSameTypes(lv.TV.T, rv.T)
99+
debugAssertSameTypes(lv.TV.T, rv.T)
100100
}
101101

102102
// XXX HACK (until value persistence impl'd)
@@ -119,7 +119,7 @@ func (m *Machine) doOpQuoAssign() {
119119
rv := m.PopValue() // only one.
120120
lv := m.PopAsPointer(s.Lhs[0])
121121
if debug {
122-
assertSameTypes(lv.TV.T, rv.T)
122+
debugAssertSameTypes(lv.TV.T, rv.T)
123123
}
124124

125125
// XXX HACK (until value persistence impl'd)
@@ -142,7 +142,7 @@ func (m *Machine) doOpRemAssign() {
142142
rv := m.PopValue() // only one.
143143
lv := m.PopAsPointer(s.Lhs[0])
144144
if debug {
145-
assertSameTypes(lv.TV.T, rv.T)
145+
debugAssertSameTypes(lv.TV.T, rv.T)
146146
}
147147

148148
// XXX HACK (until value persistence impl'd)
@@ -165,7 +165,7 @@ func (m *Machine) doOpBandAssign() {
165165
rv := m.PopValue() // only one.
166166
lv := m.PopAsPointer(s.Lhs[0])
167167
if debug {
168-
assertSameTypes(lv.TV.T, rv.T)
168+
debugAssertSameTypes(lv.TV.T, rv.T)
169169
}
170170

171171
// XXX HACK (until value persistence impl'd)
@@ -188,7 +188,7 @@ func (m *Machine) doOpBandnAssign() {
188188
rv := m.PopValue() // only one.
189189
lv := m.PopAsPointer(s.Lhs[0])
190190
if debug {
191-
assertSameTypes(lv.TV.T, rv.T)
191+
debugAssertSameTypes(lv.TV.T, rv.T)
192192
}
193193

194194
// XXX HACK (until value persistence impl'd)
@@ -211,7 +211,7 @@ func (m *Machine) doOpBorAssign() {
211211
rv := m.PopValue() // only one.
212212
lv := m.PopAsPointer(s.Lhs[0])
213213
if debug {
214-
assertSameTypes(lv.TV.T, rv.T)
214+
debugAssertSameTypes(lv.TV.T, rv.T)
215215
}
216216

217217
// XXX HACK (until value persistence impl'd)
@@ -234,7 +234,7 @@ func (m *Machine) doOpXorAssign() {
234234
rv := m.PopValue() // only one.
235235
lv := m.PopAsPointer(s.Lhs[0])
236236
if debug {
237-
assertSameTypes(lv.TV.T, rv.T)
237+
debugAssertSameTypes(lv.TV.T, rv.T)
238238
}
239239

240240
// XXX HACK (until value persistence impl'd)

gnovm/pkg/gnolang/op_binary.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (m *Machine) doOpLor() {
4545
rv := m.PopValue()
4646
lv := m.PeekValue(1) // also the result
4747
if debug {
48-
assertSameTypes(lv.T, rv.T)
48+
debugAssertSameTypes(lv.T, rv.T)
4949
}
5050

5151
// set result in lv.
@@ -60,7 +60,7 @@ func (m *Machine) doOpLand() {
6060
rv := m.PopValue()
6161
lv := m.PeekValue(1) // also the result
6262
if debug {
63-
assertSameTypes(lv.T, rv.T)
63+
debugAssertSameTypes(lv.T, rv.T)
6464
}
6565

6666
// set result in lv.
@@ -77,7 +77,7 @@ func (m *Machine) doOpEql() {
7777
rv := m.PopValue()
7878
lv := m.PeekValue(1) // also the result
7979
if debug {
80-
assertEqualityTypes(lv.T, rv.T)
80+
debugAssertEqualityTypes(lv.T, rv.T)
8181
}
8282

8383
// set result in lv.
@@ -94,7 +94,7 @@ func (m *Machine) doOpNeq() {
9494
rv := m.PopValue()
9595
lv := m.PeekValue(1) // also the result
9696
if debug {
97-
assertEqualityTypes(lv.T, rv.T)
97+
debugAssertEqualityTypes(lv.T, rv.T)
9898
}
9999

100100
// set result in lv.
@@ -111,7 +111,7 @@ func (m *Machine) doOpLss() {
111111
rv := m.PopValue()
112112
lv := m.PeekValue(1) // also the result
113113
if debug {
114-
assertSameTypes(lv.T, rv.T)
114+
debugAssertSameTypes(lv.T, rv.T)
115115
}
116116

117117
// set the result in lv.
@@ -128,7 +128,7 @@ func (m *Machine) doOpLeq() {
128128
rv := m.PopValue()
129129
lv := m.PeekValue(1) // also the result
130130
if debug {
131-
assertSameTypes(lv.T, rv.T)
131+
debugAssertSameTypes(lv.T, rv.T)
132132
}
133133

134134
// set the result in lv.
@@ -145,7 +145,7 @@ func (m *Machine) doOpGtr() {
145145
rv := m.PopValue()
146146
lv := m.PeekValue(1) // also the result
147147
if debug {
148-
assertSameTypes(lv.T, rv.T)
148+
debugAssertSameTypes(lv.T, rv.T)
149149
}
150150

151151
// set the result in lv.
@@ -162,7 +162,7 @@ func (m *Machine) doOpGeq() {
162162
rv := m.PopValue()
163163
lv := m.PeekValue(1) // also the result
164164
if debug {
165-
assertSameTypes(lv.T, rv.T)
165+
debugAssertSameTypes(lv.T, rv.T)
166166
}
167167

168168
// set the result in lv.
@@ -179,7 +179,7 @@ func (m *Machine) doOpAdd() {
179179
rv := m.PopValue()
180180
lv := m.PeekValue(1) // also result
181181
if debug {
182-
assertSameTypes(lv.T, rv.T)
182+
debugAssertSameTypes(lv.T, rv.T)
183183
}
184184

185185
// add rv to lv.
@@ -193,7 +193,7 @@ func (m *Machine) doOpSub() {
193193
rv := m.PopValue()
194194
lv := m.PeekValue(1) // also result
195195
if debug {
196-
assertSameTypes(lv.T, rv.T)
196+
debugAssertSameTypes(lv.T, rv.T)
197197
}
198198

199199
// sub rv from lv.
@@ -207,7 +207,7 @@ func (m *Machine) doOpBor() {
207207
rv := m.PopValue()
208208
lv := m.PeekValue(1) // also result
209209
if debug {
210-
assertSameTypes(lv.T, rv.T)
210+
debugAssertSameTypes(lv.T, rv.T)
211211
}
212212

213213
// lv | rv
@@ -221,7 +221,7 @@ func (m *Machine) doOpXor() {
221221
rv := m.PopValue()
222222
lv := m.PeekValue(1) // also result
223223
if debug {
224-
assertSameTypes(lv.T, rv.T)
224+
debugAssertSameTypes(lv.T, rv.T)
225225
}
226226

227227
// lv ^ rv
@@ -235,7 +235,7 @@ func (m *Machine) doOpMul() {
235235
rv := m.PopValue()
236236
lv := m.PeekValue(1) // also result
237237
if debug {
238-
assertSameTypes(lv.T, rv.T)
238+
debugAssertSameTypes(lv.T, rv.T)
239239
}
240240

241241
// lv * rv
@@ -249,7 +249,7 @@ func (m *Machine) doOpQuo() {
249249
rv := m.PopValue()
250250
lv := m.PeekValue(1) // also result
251251
if debug {
252-
assertSameTypes(lv.T, rv.T)
252+
debugAssertSameTypes(lv.T, rv.T)
253253
}
254254

255255
// lv / rv
@@ -263,7 +263,7 @@ func (m *Machine) doOpRem() {
263263
rv := m.PopValue()
264264
lv := m.PeekValue(1) // also result
265265
if debug {
266-
assertSameTypes(lv.T, rv.T)
266+
debugAssertSameTypes(lv.T, rv.T)
267267
}
268268

269269
// lv % rv
@@ -309,7 +309,7 @@ func (m *Machine) doOpBand() {
309309
rv := m.PopValue()
310310
lv := m.PeekValue(1) // also result
311311
if debug {
312-
assertSameTypes(lv.T, rv.T)
312+
debugAssertSameTypes(lv.T, rv.T)
313313
}
314314

315315
// lv & rv
@@ -323,7 +323,7 @@ func (m *Machine) doOpBandn() {
323323
rv := m.PopValue()
324324
lv := m.PeekValue(1) // also result
325325
if debug {
326-
assertSameTypes(lv.T, rv.T)
326+
debugAssertSameTypes(lv.T, rv.T)
327327
}
328328

329329
// lv &^ rv

gnovm/pkg/gnolang/op_exec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ func (m *Machine) doOpSwitchClauseCase() {
957957

958958
// eval whether cv == tv.
959959
if debug {
960-
assertEqualityTypes(cv.T, tv.T)
960+
debugAssertEqualityTypes(cv.T, tv.T)
961961
}
962962
match := isEql(m.Store, cv, tv)
963963
if match {

gnovm/pkg/gnolang/preprocess.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,11 @@ func Preprocess(store Store, ctx BlockNode, n Node) Node {
847847
if isUntyped(rt) { // e.g. int(1) + 1<<x
848848
checkOrConvertType(store, last, &n.Right, lt, false)
849849
} else { // both typed, left typed const, right typed non-const
850-
checkOrConvertType(store, last, &n.Left, rt, false) // see eql_0a1a0.gno
850+
if lt.TypeID() != rt.TypeID() {
851+
panic(fmt.Sprintf(
852+
"incompatible types in binary expression: %v %v %v",
853+
lt.TypeID(), n.Op, rt.TypeID()))
854+
}
851855
}
852856
}
853857
} else if ric { // right is const, left is not
@@ -890,7 +894,11 @@ func Preprocess(store Store, ctx BlockNode, n Node) Node {
890894
if isUntyped(lt) {
891895
checkOrConvertType(store, last, &n.Left, rt, false)
892896
} else {
893-
checkOrConvertType(store, last, &n.Right, lt, false)
897+
if lt.TypeID() != rt.TypeID() {
898+
panic(fmt.Sprintf(
899+
"incompatible types in binary expression: %v %v %v",
900+
lt.TypeID(), n.Op, rt.TypeID()))
901+
}
894902
}
895903
}
896904
} else { // ---both not const---
@@ -921,7 +929,7 @@ func Preprocess(store Store, ctx BlockNode, n Node) Node {
921929
}
922930
// check assignable, if pass, convert right to gno first
923931
// XXX, can we just check on native type?
924-
assertAssignableTo(lpt, rpt, false) // both primitive types
932+
assertSame(lpt, rpt, "in binary expression "+n.Op.String()) // both primitive types
925933
rn = Expr(Call(rpt.String(), n.Right))
926934
// checkOrCovertType should happen in future when both sides to be gno'd
927935
} else { // rt not native
@@ -994,10 +1002,14 @@ func Preprocess(store Store, ctx BlockNode, n Node) Node {
9941002
} else if riu { // left typed, right untyped
9951003
checkOrConvertType(store, last, &n.Right, lt, false)
9961004
} else { // both typed, refer to 0a1g.gno
997-
if !shouldSwapOnSpecificity(lt, rt) {
998-
checkOrConvertType(store, last, &n.Left, rt, false)
1005+
if n.Op == EQL || n.Op == NEQ {
1006+
// nothing to do
9991007
} else {
1000-
checkOrConvertType(store, last, &n.Right, lt, false)
1008+
if !shouldSwapOnSpecificity(lt, rt) {
1009+
checkOrConvertType(store, last, &n.Left, rt, false)
1010+
} else {
1011+
checkOrConvertType(store, last, &n.Right, lt, false)
1012+
}
10011013
}
10021014
}
10031015
}

0 commit comments

Comments
 (0)