Skip to content

Commit 958d616

Browse files
committed
extract call environment preparation
1 parent 5e68861 commit 958d616

3 files changed

Lines changed: 21 additions & 10 deletions

File tree

docs/architecture.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Key files:
2727
- `vibes/execution_call_capabilities.go` (call-time capability binding and contract registration)
2828
- `vibes/execution_call_globals.go` (strict global validation and call-time global binding)
2929
- `vibes/execution_call_classes.go` (call-time class body initialization in class-local scope)
30+
- `vibes/execution_call_env.go` (call env prep: argument rebind/bind and memory validation)
3031
- `vibes/execution_function_args.go` (function argument/default/type/ivar binding helpers)
3132
- `vibes/execution_calls.go` (callable dispatch + function invocation)
3233
- `vibes/execution_call_expr.go` (call expression target/args/kwargs/block evaluation)

vibes/execution_call_env.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package vibes
2+
3+
func prepareCallEnvForFunction(exec *Execution, root *Env, rebinder *callFunctionRebinder, fn *ScriptFunction, args []Value, keywords map[string]Value) (*Env, error) {
4+
callEnv := newEnv(root)
5+
callArgs := rebinder.rebindValues(args)
6+
callKeywords := rebinder.rebindKeywords(keywords)
7+
if err := exec.bindFunctionArgs(fn, callEnv, callArgs, callKeywords, fn.Pos); err != nil {
8+
return nil, err
9+
}
10+
exec.pushEnv(callEnv)
11+
if err := exec.checkMemory(); err != nil {
12+
exec.popEnv()
13+
return nil, err
14+
}
15+
exec.popEnv()
16+
17+
return callEnv, nil
18+
}

vibes/execution_script.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,10 @@ func (s *Script) Call(ctx context.Context, name string, args []Value, opts CallO
5353
return NewNil(), err
5454
}
5555

56-
callEnv := newEnv(root)
57-
callArgs := rebinder.rebindValues(args)
58-
callKeywords := rebinder.rebindKeywords(opts.Keywords)
59-
if err := exec.bindFunctionArgs(fn, callEnv, callArgs, callKeywords, fn.Pos); err != nil {
60-
return NewNil(), err
61-
}
62-
exec.pushEnv(callEnv)
63-
if err := exec.checkMemory(); err != nil {
64-
exec.popEnv()
56+
callEnv, err := prepareCallEnvForFunction(exec, root, rebinder, fn, args, opts.Keywords)
57+
if err != nil {
6558
return NewNil(), err
6659
}
67-
exec.popEnv()
6860

6961
if err := exec.pushFrame(fn.Name, fn.Pos); err != nil {
7062
return NewNil(), err

0 commit comments

Comments
 (0)