Skip to content

Commit 6225cf7

Browse files
committed
extract function invocation checks from script call
1 parent 958d616 commit 6225cf7

3 files changed

Lines changed: 26 additions & 16 deletions

File tree

docs/architecture.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Key files:
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)
3030
- `vibes/execution_call_env.go` (call env prep: argument rebind/bind and memory validation)
31+
- `vibes/execution_call_invoke.go` (function frame execution, return type validation, memory checks)
3132
- `vibes/execution_function_args.go` (function argument/default/type/ivar binding helpers)
3233
- `vibes/execution_calls.go` (callable dispatch + function invocation)
3334
- `vibes/execution_call_expr.go` (call expression target/args/kwargs/block evaluation)

vibes/execution_call_invoke.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package vibes
2+
3+
func executeFunctionForCall(exec *Execution, fn *ScriptFunction, callEnv *Env) (Value, error) {
4+
if err := exec.pushFrame(fn.Name, fn.Pos); err != nil {
5+
return NewNil(), err
6+
}
7+
val, returned, err := exec.evalStatements(fn.Body, callEnv)
8+
exec.popFrame()
9+
if err != nil {
10+
return NewNil(), err
11+
}
12+
if fn.ReturnTy != nil {
13+
if err := checkValueType(val, fn.ReturnTy); err != nil {
14+
return NewNil(), exec.errorAt(fn.Pos, "%s", formatReturnTypeMismatch(fn.Name, err))
15+
}
16+
}
17+
if err := exec.checkMemoryWith(val); err != nil {
18+
return NewNil(), err
19+
}
20+
if returned {
21+
return val, nil
22+
}
23+
return val, nil
24+
}

vibes/execution_script.go

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,9 @@ func (s *Script) Call(ctx context.Context, name string, args []Value, opts CallO
5858
return NewNil(), err
5959
}
6060

61-
if err := exec.pushFrame(fn.Name, fn.Pos); err != nil {
62-
return NewNil(), err
63-
}
64-
val, returned, err := exec.evalStatements(fn.Body, callEnv)
65-
exec.popFrame()
61+
val, err := executeFunctionForCall(exec, fn, callEnv)
6662
if err != nil {
6763
return NewNil(), err
6864
}
69-
if fn.ReturnTy != nil {
70-
if err := checkValueType(val, fn.ReturnTy); err != nil {
71-
return NewNil(), exec.errorAt(fn.Pos, "%s", formatReturnTypeMismatch(fn.Name, err))
72-
}
73-
}
74-
if err := exec.checkMemoryWith(val); err != nil {
75-
return NewNil(), err
76-
}
77-
if returned {
78-
return val, nil
79-
}
8065
return val, nil
8166
}

0 commit comments

Comments
 (0)