Skip to content

Commit

Permalink
Execution functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsc2 committed Jul 31, 2023
1 parent ed3ae71 commit 1301f2a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
5 changes: 3 additions & 2 deletions pkg/vm/memory/memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"reflect"
"testing"

"github.com/lambdaclass/cairo-vm.go/pkg/lambdaworks"
"github.com/lambdaclass/cairo-vm.go/pkg/vm/memory"
)

Expand All @@ -15,7 +16,7 @@ func TestMemoryInsert(t *testing.T) {
// Instantiate the address where we want to insert and the value.
// We will insert the value Int(5) in segment 1, offset 0
key := memory.NewRelocatable(1, 0)
val := memory.NewMaybeRelocatableInt(5)
val := memory.NewMaybeRelocatableInt(lambdaworks.From(5))

// Make the insertion
err := mem.Insert(key, val)
Expand Down Expand Up @@ -43,7 +44,7 @@ func TestMemoryInsertWithHoles(t *testing.T) {
// Instantiate the address where we want to insert and the value.
// We will insert the MaybeRelocatable Int(7) in segment 1, offset 2
key := memory.NewRelocatable(1, 2)
val := memory.NewMaybeRelocatableInt(7)
val := memory.NewMaybeRelocatableInt(lambdaworks.From(7))

// Make the insertion
err := mem.Insert(key, val)
Expand Down
8 changes: 6 additions & 2 deletions pkg/vm/memory/relocatable.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package memory

import (
"github.com/lambdaclass/cairo-vm.go/pkg/lambdaworks"
)

// Relocatable in the Cairo VM represents an address
// in some memory segment. When the VM finishes running,
// these values are replaced by real memory addresses,
Expand Down Expand Up @@ -31,7 +35,7 @@ func (r *Relocatable) into_indexes() (uint, uint) {
type Int struct {
// FIXME: Here we should use Lambdaworks felt, just mocking
// this for now.
felt uint
felt lambdaworks.Felt
}

// MaybeRelocatable is the type of the memory cells in the Cairo
Expand All @@ -43,7 +47,7 @@ type MaybeRelocatable struct {
}

// Creates a new MaybeRelocatable with an Int inner value
func NewMaybeRelocatableInt(felt uint) *MaybeRelocatable {
func NewMaybeRelocatableInt(felt lambdaworks.Felt) *MaybeRelocatable {
return &MaybeRelocatable{inner: Int{felt}}
}

Expand Down
24 changes: 23 additions & 1 deletion pkg/vm/vm_core.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package vm

import "github.com/lambdaclass/cairo-vm.go/pkg/vm/memory"
import (
"fmt"
"github.com/lambdaclass/cairo-vm.go/pkg/vm/memory"
)

// VirtualMachine represents the Cairo VM.
// Runs Cairo assembly and produces an execution trace.
Expand All @@ -9,3 +12,22 @@ type VirtualMachine struct {
currentStep uint
segments memory.MemorySegmentManager
}

type Operands struct {
dst memory.MaybeRelocatable
res memory.MaybeRelocatable
op0 memory.MaybeRelocatable
op1 memory.MaybeRelocatable
}

type OperandsAddresses struct {
dst_addr memory.Relocatable
op0_addr memory.Relocatable
op1_addr memory.Relocatable
}

func (vm VirtualMachine) compute_operands(instruction Instruction) {}

func (vm VirtualMachine) run_instrucion(instruction Instruction) {
fmt.Println("hello from instruction")
}

0 comments on commit 1301f2a

Please sign in to comment.