Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(gnovm): remove TRANS_BREAK from transcriber #3626

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 25 additions & 85 deletions gnovm/pkg/gnolang/transcribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
const (
TRANS_CONTINUE TransCtrl = iota
TRANS_SKIP
TRANS_BREAK
TRANS_EXIT
)

Expand Down Expand Up @@ -101,7 +100,7 @@
TRANS_IMPORT_PATH
TRANS_CONST_TYPE
TRANS_CONST_VALUE
TRANS_VAR_NAME // XXX stringer
TRANS_VAR_NAME
TRANS_VAR_TYPE
TRANS_VAR_VALUE
TRANS_TYPE_TYPE
Expand All @@ -113,8 +112,6 @@
// - TRANS_SKIP to break out of the
// ENTER,CHILDS1,[BLOCK,CHILDS2]?,LEAVE sequence for that node,
// i.e. skipping (the rest of) it;
// - TRANS_BREAK to break out of looping in CHILDS1 or CHILDS2,
// but still perform TRANS_LEAVE.
// - TRANS_EXIT to stop traversing altogether.
//
// Do not mutate ns.
Expand Down Expand Up @@ -168,9 +165,7 @@
}
for idx := range cnn.Args {
cnn.Args[idx] = transcribe(t, nns, TRANS_CALL_ARG, idx, cnn.Args[idx], &c).(Expr)
if isBreak(c) {
break
} else if isStopOrSkip(nc, c) {
if isStopOrSkip(nc, c) {
return
}
}
Expand Down Expand Up @@ -248,16 +243,12 @@
k, v := kvx.Key, kvx.Value
if k != nil {
k = transcribe(t, nns, TRANS_COMPOSITE_KEY, idx, k, &c).(Expr)
if isBreak(c) {
break
} else if isStopOrSkip(nc, c) {
if isStopOrSkip(nc, c) {
return
}
}
v = transcribe(t, nns, TRANS_COMPOSITE_VALUE, idx, v, &c).(Expr)
if isBreak(c) {
break
} else if isStopOrSkip(nc, c) {
if isStopOrSkip(nc, c) {
return
}
cnn.Elts[idx] = KeyValueExpr{Key: k, Value: v}
Expand All @@ -269,9 +260,7 @@
}
for idx := range cnn.HeapCaptures {
cnn.HeapCaptures[idx] = *(transcribe(t, nns, TRANS_FUNCLIT_HEAP_CAPTURE, idx, &cnn.HeapCaptures[idx], &c).(*NameExpr))
if isBreak(c) {
break
} else if isStopOrSkip(nc, c) {
if isStopOrSkip(nc, c) {
return
}
}
Expand All @@ -285,9 +274,7 @@
// iterate over Body; its length can change if a statement is decomposed.
for idx := 0; idx < len(cnn.Body); idx++ {
cnn.Body[idx] = transcribe(t, nns, TRANS_FUNCLIT_BODY, idx, cnn.Body[idx], &c).(Stmt)
if isBreak(c) {
break
} else if isStopOrSkip(nc, c) {
if isStopOrSkip(nc, c) {
return
}
}
Expand Down Expand Up @@ -321,9 +308,7 @@
case *InterfaceTypeExpr:
for idx := range cnn.Methods {
cnn.Methods[idx] = *transcribe(t, nns, TRANS_INTERFACETYPE_METHOD, idx, &cnn.Methods[idx], &c).(*FieldTypeExpr)
if isBreak(c) {
break
} else if isStopOrSkip(nc, c) {
if isStopOrSkip(nc, c) {
return
}
}
Expand All @@ -341,9 +326,7 @@
}
for idx := range cnn.Results {
cnn.Results[idx] = *transcribe(t, nns, TRANS_FUNCTYPE_RESULT, idx, &cnn.Results[idx], &c).(*FieldTypeExpr)
if isBreak(c) {
break
} else if isStopOrSkip(nc, c) {
if isStopOrSkip(nc, c) {
return
}
}
Expand All @@ -359,9 +342,7 @@
case *StructTypeExpr:
for idx := range cnn.Fields {
cnn.Fields[idx] = *transcribe(t, nns, TRANS_STRUCTTYPE_FIELD, idx, &cnn.Fields[idx], &c).(*FieldTypeExpr)
if isBreak(c) {
break
} else if isStopOrSkip(nc, c) {
if isStopOrSkip(nc, c) {
return
}
}
Expand All @@ -373,17 +354,13 @@
case *AssignStmt:
for idx := range cnn.Lhs {
cnn.Lhs[idx] = transcribe(t, nns, TRANS_ASSIGN_LHS, idx, cnn.Lhs[idx], &c).(Expr)
if isBreak(c) {
break
} else if isStopOrSkip(nc, c) {
if isStopOrSkip(nc, c) {
return
}
}
for idx := range cnn.Rhs {
cnn.Rhs[idx] = transcribe(t, nns, TRANS_ASSIGN_RHS, idx, cnn.Rhs[idx], &c).(Expr)
if isBreak(c) {
break
} else if isStopOrSkip(nc, c) {
if isStopOrSkip(nc, c) {
return
}
}
Expand All @@ -398,9 +375,7 @@
// iterate over Body; its length can change if a statement is decomposed.
for idx := 0; idx < len(cnn.Body); idx++ {
cnn.Body[idx] = transcribe(t, nns, TRANS_BLOCK_BODY, idx, cnn.Body[idx], &c).(Stmt)
if isBreak(c) {
break
} else if isStopOrSkip(nc, c) {
if isStopOrSkip(nc, c) {
return
}
}
Expand All @@ -409,9 +384,7 @@
// iterate over Body; its length can change if a statement is decomposed.
for idx := 0; idx < len(cnn.Body); idx++ {
cnn.Body[idx] = transcribe(t, nns, TRANS_DECL_BODY, idx, cnn.Body[idx], &c).(SimpleDeclStmt)
if isBreak(c) {
break
} else if isStopOrSkip(nc, c) {
if isStopOrSkip(nc, c) {
return
}
}
Expand Down Expand Up @@ -455,9 +428,7 @@
// iterate over Body; its length can change if a statement is decomposed.
for idx := 0; idx < len(cnn.Body); idx++ {
cnn.Body[idx] = transcribe(t, nns, TRANS_FOR_BODY, idx, cnn.Body[idx], &c).(Stmt)
if isBreak(c) {
break
} else if isStopOrSkip(nc, c) {
if isStopOrSkip(nc, c) {
return
}
}
Expand Down Expand Up @@ -506,9 +477,7 @@
// iterate over Body; its length can change if a statement is decomposed.
for idx := 0; idx < len(cnn.Body); idx++ {
cnn.Body[idx] = transcribe(t, nns, TRANS_IF_CASE_BODY, idx, cnn.Body[idx], &c).(Stmt)
if isBreak(c) {
break
} else if isStopOrSkip(nc, c) {
if isStopOrSkip(nc, c) {
return
}
}
Expand Down Expand Up @@ -544,18 +513,14 @@
// iterate over Body; its length can change if a statement is decomposed.
for idx := 0; idx < len(cnn.Body); idx++ {
cnn.Body[idx] = transcribe(t, nns, TRANS_RANGE_BODY, idx, cnn.Body[idx], &c).(Stmt)
if isBreak(c) {
break
} else if isStopOrSkip(nc, c) {
if isStopOrSkip(nc, c) {
return
}
}
case *ReturnStmt:
for idx := range cnn.Results {
cnn.Results[idx] = transcribe(t, nns, TRANS_RETURN_RESULT, idx, cnn.Results[idx], &c).(Expr)
if isBreak(c) {
break
} else if isStopOrSkip(nc, c) {
if isStopOrSkip(nc, c) {
return
}
}
Expand All @@ -564,9 +529,7 @@
case *SelectStmt:
for idx := range cnn.Cases {
cnn.Cases[idx] = *transcribe(t, nns, TRANS_SELECT_CASE, idx, &cnn.Cases[idx], &c).(*SelectCaseStmt)
if isBreak(c) {
break
} else if isStopOrSkip(nc, c) {
if isStopOrSkip(nc, c) {

Check warning on line 532 in gnovm/pkg/gnolang/transcribe.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/transcribe.go#L532

Added line #L532 was not covered by tests
return
}
}
Expand All @@ -585,9 +548,7 @@
// iterate over Body; its length can change if a statement is decomposed.
for idx := 0; idx < len(cnn.Body); idx++ {
cnn.Body[idx] = transcribe(t, nns, TRANS_SELECTCASE_BODY, idx, cnn.Body[idx], &c).(Stmt)
if isBreak(c) {
break
} else if isStopOrSkip(nc, c) {
if isStopOrSkip(nc, c) {

Check warning on line 551 in gnovm/pkg/gnolang/transcribe.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/transcribe.go#L551

Added line #L551 was not covered by tests
return
}
}
Expand Down Expand Up @@ -632,9 +593,7 @@
}
for idx := range cnn.Clauses {
cnn.Clauses[idx] = *transcribe(t, nns, TRANS_SWITCH_CASE, idx, &cnn.Clauses[idx], &c).(*SwitchClauseStmt)
if isBreak(c) {
break
} else if isStopOrSkip(nc, c) {
if isStopOrSkip(nc, c) {
return
}
}
Expand All @@ -652,18 +611,14 @@
}
for idx := range cnn.Cases {
cnn.Cases[idx] = transcribe(t, nns, TRANS_SWITCHCASE_CASE, idx, cnn.Cases[idx], &c).(Expr)
if isBreak(c) {
break
} else if isStopOrSkip(nc, c) {
if isStopOrSkip(nc, c) {
return
}
}
// iterate over Body; its length can change if a statement is decomposed.
for idx := 0; idx < len(cnn.Body); idx++ {
cnn.Body[idx] = transcribe(t, nns, TRANS_SWITCHCASE_BODY, idx, cnn.Body[idx], &c).(Stmt)
if isBreak(c) {
break
} else if isStopOrSkip(nc, c) {
if isStopOrSkip(nc, c) {
return
}
}
Expand All @@ -688,9 +643,7 @@
// iterate over Body; its length can change if a statement is decomposed.
for idx := 0; idx < len(cnn.Body); idx++ {
cnn.Body[idx] = transcribe(t, nns, TRANS_FUNC_BODY, idx, cnn.Body[idx], &c).(Stmt)
if isBreak(c) {
break
} else if isStopOrSkip(nc, c) {
if isStopOrSkip(nc, c) {
return
}
}
Expand All @@ -709,9 +662,7 @@
}
for idx := range cnn.Values {
cnn.Values[idx] = transcribe(t, nns, TRANS_VAR_VALUE, idx, cnn.Values[idx], &c).(Expr)
if isBreak(c) {
break
} else if isStopOrSkip(nc, c) {
if isStopOrSkip(nc, c) {
return
}
}
Expand All @@ -730,9 +681,7 @@
}
for idx := range cnn.Decls {
cnn.Decls[idx] = transcribe(t, nns, TRANS_FILE_BODY, idx, cnn.Decls[idx], &c).(Decl)
if isBreak(c) {
break
} else if isStopOrSkip(nc, c) {
if isStopOrSkip(nc, c) {
return
}
}
Expand Down Expand Up @@ -768,12 +717,3 @@
panic("should not happen")
}
}

// returns true if transcribe() should break (a loop).
func isBreak(nc TransCtrl) (brek bool) {
if nc == TRANS_BREAK {
return true
} else {
return false
}
}
7 changes: 3 additions & 4 deletions gnovm/pkg/gnolang/transctrl_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gnovm/tests/stdlibs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ available when testing gno code in `_test.gno` and `_filetest.gno` files.
Re-declarations of functions already existing override the definitions of the
normal stdlibs directory.

Adding imports that don't exist in the corresponding normal stdlib is undefined behavior
Adding imports that don't exist in the corresponding normal stdlib is undefined behavior
Loading