Skip to content

Commit

Permalink
Implement usort_enter_scope Hint
Browse files Browse the repository at this point in the history
  • Loading branch information
pefontana committed Sep 19, 2023
1 parent cc5fc5f commit 36a071c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/hints/hint_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ func (p *CairoVmHintProcessor) ExecuteHint(vm *vm.VirtualMachine, hintData *any,
return memcpy_enter_scope(data.Ids, vm, execScopes)
case VM_ENTER_SCOPE:
return vm_enter_scope(execScopes)
case USORT_ENTER_SCOPE:
return usort_enter_scope(execScopes)
default:
return errors.Errorf("Unknown Hint: %s", data.Code)
}
Expand Down
27 changes: 27 additions & 0 deletions pkg/hints/usort_hints.go
Original file line number Diff line number Diff line change
@@ -1 +1,28 @@
package hints

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

// Implements hint:
// %{ vm_enter_scope(dict(__usort_max_size = globals().get('__usort_max_size'))) %}
func usort_enter_scope(executionScopes *types.ExecutionScopes) error {
usort_max_size, err := executionScopes.Get("usort_max_size")

usort_max_size_felt := usort_max_size.(lambdaworks.Felt)

if err != nil {
return err
}

if usort_max_size == nil {
executionScopes.EnterScope(make(map[string]interface{}))
}

scope := make(map[string]interface{})
scope["usort_max_size"] = usort_max_size_felt
executionScopes.EnterScope(scope)

return nil
}

0 comments on commit 36a071c

Please sign in to comment.