Skip to content

Commit 86a11cb

Browse files
jaekwonomarsy
authored andcommitted
tests and cleanup
1 parent 5c9cfc2 commit 86a11cb

File tree

3 files changed

+93
-7
lines changed

3 files changed

+93
-7
lines changed

gnovm/pkg/gnolang/realm.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ func (rlm *Realm) processNewEscapedMarks(store Store, start int) int {
645645
// (ancestors) must be marked as dirty to update the
646646
// hash tree.
647647
func (rlm *Realm) markDirtyAncestors(store Store) {
648-
markAncestorsOne := func(oo Object) {
648+
markAncestors := func(oo Object) {
649649
for {
650650
if pv, ok := oo.(*PackageValue); ok {
651651
if debugRealm {
@@ -682,12 +682,12 @@ func (rlm *Realm) markDirtyAncestors(store Store) {
682682
break // no more owners.
683683
} else if po.GetIsNewReal() {
684684
// already will be marked
685-
// via call to markAncestorsOne
685+
// via call to markAncestors
686686
// via .created.
687687
break
688688
} else if po.GetIsDirty() {
689689
// already will be marked
690-
// via call to markAncestorsOne
690+
// via call to markAncestors
691691
// via .updated.
692692
break
693693
} else if po.GetIsDeleted() {
@@ -706,14 +706,14 @@ func (rlm *Realm) markDirtyAncestors(store Store) {
706706
// to .updated without affecting iteration.
707707
for _, oo := range rlm.updated {
708708
if !oo.GetIsDeleted() {
709-
markAncestorsOne(oo)
709+
markAncestors(oo)
710710
}
711711
}
712712
// NOTE: must happen after iterating over rlm.updated
713713
// for the same reason.
714714
for _, oo := range rlm.created {
715715
if !oo.GetIsDeleted() {
716-
markAncestorsOne(oo)
716+
markAncestors(oo)
717717
}
718718
}
719719
}
@@ -829,6 +829,7 @@ func (rlm *Realm) saveObject(store Store, oo Object) {
829829
oo.SetIsEscaped(true)
830830
// XXX anything else to do?
831831
}
832+
832833
// set object to store.
833834
// NOTE: also sets the hash to object.
834835
rlm.sumDiff += store.SetObject(oo)

gnovm/tests/files/struct63f.gno

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// PKGPATH: gno.land/r/main
2+
package main
3+
4+
type A struct {
5+
b *B
6+
}
7+
8+
type B struct {
9+
c *C
10+
}
11+
12+
type C struct {
13+
d *D
14+
}
15+
16+
type D struct {
17+
e int
18+
}
19+
20+
var x = A{b: &B{c: &C{d: &D{e: 1}}}}
21+
22+
func init() {
23+
println("init() START")
24+
// variant of struct63.gno
25+
// x.b.c = C{d: D{e: 2}}
26+
x.b.c = &C{d: nil} // Is realm.go "created" C{}.
27+
x.b.c.d = &D{e: 2} // *Not* realm.go "updated" because C{} is unreal...
28+
// however it *will* get saved recursively due to "created".
29+
// If new-real or dirty any new objects in subcomponents are separately
30+
// marked "created" there, not here.
31+
println("init() END")
32+
}
33+
34+
func main() {
35+
println("main() START")
36+
println(x.b.c.d.e)
37+
println("main() END")
38+
}
39+
40+
// Output:
41+
// init() START
42+
// init() END
43+
// main() START
44+
// 2
45+
// main() END

tm2/pkg/colors/colors.go

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const (
3939

4040
// color the string s with color 'color'
4141
// unless s is already colored
42-
func treat(s string, color string) string {
42+
func treat(color string, s string) string {
4343
if len(s) > 2 && s[:2] == "\x1b[" {
4444
return s
4545
}
@@ -50,7 +50,7 @@ func treatAll(color string, args ...any) string {
5050
parts := make([]string, len(args))
5151

5252
for i, arg := range args {
53-
parts[i] = treat(fmt.Sprintf("%v", arg), color)
53+
parts[i] = treat(color, fmt.Sprintf("%v", arg))
5454
}
5555

5656
return strings.Join(parts, "")
@@ -60,14 +60,26 @@ func None(args ...any) string {
6060
return treatAll(ANSIReset, args...)
6161
}
6262

63+
func Nonef(format string, args ...any) string {
64+
return treat(ANSIReset, fmt.Sprintf(format, args...))
65+
}
66+
6367
func Black(args ...any) string {
6468
return treatAll(ANSIFgBlack, args...)
6569
}
6670

71+
func Blackf(format string, args ...any) string {
72+
return treat(ANSIFgBlack, fmt.Sprintf(format, args...))
73+
}
74+
6775
func Red(args ...any) string {
6876
return treatAll(ANSIFgRed, args...)
6977
}
7078

79+
func Redf(format string, args ...any) string {
80+
return treat(ANSIFgRed, fmt.Sprintf(format, args...))
81+
}
82+
7183
func RedBg(args ...any) string {
7284
return treatAll(ANSIBgRed, args...)
7385
}
@@ -76,30 +88,58 @@ func Green(args ...any) string {
7688
return treatAll(ANSIFgGreen, args...)
7789
}
7890

91+
func Greenf(format string, args ...any) string {
92+
return treat(ANSIFgGreen, fmt.Sprintf(format, args...))
93+
}
94+
7995
func Yellow(args ...any) string {
8096
return treatAll(ANSIFgYellow, args...)
8197
}
8298

99+
func Yellowf(format string, args ...any) string {
100+
return treat(ANSIFgYellow, fmt.Sprintf(format, args...))
101+
}
102+
83103
func Blue(args ...any) string {
84104
return treatAll(ANSIFgBlue, args...)
85105
}
86106

107+
func Bluef(format string, args ...any) string {
108+
return treat(ANSIFgBlue, fmt.Sprintf(format, args...))
109+
}
110+
87111
func Magenta(args ...any) string {
88112
return treatAll(ANSIFgMagenta, args...)
89113
}
90114

115+
func Magentaf(format string, args ...any) string {
116+
return treat(ANSIFgMagenta, fmt.Sprintf(format, args...))
117+
}
118+
91119
func Cyan(args ...any) string {
92120
return treatAll(ANSIFgCyan, args...)
93121
}
94122

123+
func Cyanf(format string, args ...any) string {
124+
return treat(ANSIFgCyan, fmt.Sprintf(format, args...))
125+
}
126+
95127
func White(args ...any) string {
96128
return treatAll(ANSIFgWhite, args...)
97129
}
98130

131+
func Whitef(format string, args ...any) string {
132+
return treat(ANSIFgWhite, fmt.Sprintf(format, args...))
133+
}
134+
99135
func Gray(args ...any) string {
100136
return treatAll(ANSIFgGray, args...)
101137
}
102138

139+
func Grayf(format string, args ...any) string {
140+
return treat(ANSIFgGray, fmt.Sprintf(format, args...))
141+
}
142+
103143
// result may be 4 ASNSII chars longer than they should be to denote the
104144
// elipses (...), and one for a trailing hex nibble in case the last byte is
105145
// non-ascii.

0 commit comments

Comments
 (0)