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

Expose Relocatable fields + add NewMaybeRelocatableRelocatable #9

Merged
merged 6 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
6 changes: 3 additions & 3 deletions pkg/vm/memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand All @@ -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")
}

Expand Down
11 changes: 8 additions & 3 deletions pkg/vm/memory/relocatable.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -35,3 +35,8 @@ type MaybeRelocatable struct {
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}
}
Loading