Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
petar-dambovaliev committed Aug 14, 2024
1 parent d5742ae commit 17e97e9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
3 changes: 2 additions & 1 deletion gnovm/pkg/gnolang/alloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ func (alloc *Allocator) NewSliceFromData(data []byte) *SliceValue {
func (alloc *Allocator) NewStruct(fields []TypedValue) *StructValue {
alloc.AllocateStruct()
return &StructValue{
Fields: fields,
Fields: fields,
NotAddressible: true,
}
}

Expand Down
11 changes: 9 additions & 2 deletions gnovm/pkg/gnolang/op_expressions.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ func (m *Machine) doOpSelector() {
m.Printf("-v[S] %v\n", xv)
m.Printf("+v[S] %v\n", res)
}

if xv.NotAddressable {
panic(fmt.Sprintf("expr not addressable: %+v\n", xv))
}

*xv = res // reuse as result
}

Expand Down Expand Up @@ -758,9 +763,11 @@ func (m *Machine) doOpStructLit() {
// construct and push value.
m.PopValue() // baseOf() is st
sv := m.Alloc.NewStruct(fs)

m.PushValue(TypedValue{
T: xt,
V: sv,
T: xt,
V: sv,
NotAddressable: sv.NotAddressible,
})
}

Expand Down
8 changes: 6 additions & 2 deletions gnovm/pkg/gnolang/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,8 @@ func (sv *SliceValue) GetPointerAtIndexInt2(store Store, ii int, et Type) Pointe

type StructValue struct {
ObjectInfo
Fields []TypedValue
Fields []TypedValue
NotAddressible bool
}

// TODO handle unexported fields in debug, and also ensure in the preprocessor.
Expand Down Expand Up @@ -519,7 +520,10 @@ func (sv *StructValue) Copy(alloc *Allocator) *StructValue {
fields[i] = field.Copy(alloc)
}

return alloc.NewStruct(fields)
strct := alloc.NewStruct(fields)

strct.NotAddressible = sv.NotAddressible
return strct
}

// ----------------------------------------
Expand Down

0 comments on commit 17e97e9

Please sign in to comment.