diff --git a/pkg/vm/memory/memory.go b/pkg/vm/memory/memory.go index ea7485a9..15dbc25d 100644 --- a/pkg/vm/memory/memory.go +++ b/pkg/vm/memory/memory.go @@ -20,12 +20,12 @@ func (m *Memory) Insert(addr Relocatable, val *MaybeRelocatable) error { // FIXME: There should be a special handling if the key // segment index is negative. This is an edge // case, so for now let's raise an error. - if addr.segmentIndex < 0 { + if addr.SegmentIndex < 0 { return errors.New("Segment index of key is negative - unimplemented") } // Check that insertions are preformed within the memory bounds - if addr.segmentIndex >= int(m.num_segments) { + if addr.SegmentIndex >= int(m.num_segments) { return errors.New("Error: Inserting into a non allocated segment") } @@ -45,7 +45,7 @@ func (m *Memory) Get(addr Relocatable) (*MaybeRelocatable, error) { // FIXME: There should be a special handling if the key // segment index is negative. This is an edge // case, so for now let's raise an error. - if addr.segmentIndex < 0 { + if addr.SegmentIndex < 0 { return nil, errors.New("Segment index of key is negative - unimplemented") } diff --git a/pkg/vm/memory/relocatable.go b/pkg/vm/memory/relocatable.go index 19d1c8ab..0891dac4 100644 --- a/pkg/vm/memory/relocatable.go +++ b/pkg/vm/memory/relocatable.go @@ -5,8 +5,8 @@ package memory // these values are replaced by real memory addresses, // represented by a field element. type Relocatable struct { - segmentIndex int - offset uint + SegmentIndex int + Offset uint } // Creates a new Relocatable struct with the specified segment index @@ -25,7 +25,7 @@ type Int struct { // MaybeRelocatable is the type of the memory cells in the Cairo // VM. For now, `inner` will hold any type but it should be -// instantiated only with `Relocatable`, `Int` or `nil` types. +// instantiated only with `Relocatable` or `Int` types. // We should analyze better alternatives to this. type MaybeRelocatable struct { inner any @@ -36,6 +36,11 @@ func NewMaybeRelocatableInt(felt uint) *MaybeRelocatable { return &MaybeRelocatable{inner: Int{felt}} } +// Creates a new MaybeRelocatable with a Relocatable inner value +func NewMaybeRelocatableRelocatable(relocatable Relocatable) *MaybeRelocatable { + return &MaybeRelocatable{inner: relocatable} +} + // If m is Int, returns the inner value + true, if not, returns zero + false func (m *MaybeRelocatable) GetInt() (Int, bool) { int, is_type := m.inner.(Int) diff --git a/pkg/vm/memory/segments.go b/pkg/vm/memory/segments.go index d9b4f4d6..d952472a 100644 --- a/pkg/vm/memory/segments.go +++ b/pkg/vm/memory/segments.go @@ -28,7 +28,7 @@ func (m *MemorySegmentManager) LoadData(ptr Relocatable, data *[]MaybeRelocatabl if err != nil { return Relocatable{0, 0}, err } - ptr.offset += 1 + ptr.Offset += 1 } return ptr, nil }