Skip to content

Commit 44e9a9e

Browse files
committed
extract class body initialization from script call
1 parent e9b6365 commit 44e9a9e

3 files changed

Lines changed: 23 additions & 14 deletions

File tree

docs/architecture.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Key files:
2424
- `vibes/execution_script.go` (script call surface and call-time orchestration)
2525
- `vibes/execution_script_helpers.go` (compiled script lookup/order/ownership and call-time cloning helpers)
2626
- `vibes/execution_call_capabilities.go` (call-time capability binding and contract registration)
27+
- `vibes/execution_call_classes.go` (call-time class body initialization in class-local scope)
2728
- `vibes/execution_function_args.go` (function argument/default/type/ivar binding helpers)
2829
- `vibes/execution_calls.go` (callable dispatch + function invocation)
2930
- `vibes/execution_call_expr.go` (call expression target/args/kwargs/block evaluation)

vibes/execution_call_classes.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package vibes
2+
3+
func initializeClassBodiesForCall(exec *Execution, root *Env, callClasses map[string]*ClassDef) error {
4+
for name, classDef := range callClasses {
5+
if len(classDef.Body) == 0 {
6+
continue
7+
}
8+
classVal, _ := root.Get(name)
9+
env := newEnv(root)
10+
env.Define("self", classVal)
11+
exec.pushReceiver(classVal)
12+
_, _, err := exec.evalStatements(classDef.Body, env)
13+
exec.popReceiver()
14+
if err != nil {
15+
return err
16+
}
17+
}
18+
19+
return nil
20+
}

vibes/execution_script.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,8 @@ func (s *Script) Call(ctx context.Context, name string, args []Value, opts CallO
7575
return NewNil(), err
7676
}
7777

78-
// initialize class bodies (class vars)
79-
for name, classDef := range callClasses {
80-
if len(classDef.Body) == 0 {
81-
continue
82-
}
83-
classVal, _ := root.Get(name)
84-
env := newEnv(root)
85-
env.Define("self", classVal)
86-
exec.pushReceiver(classVal)
87-
_, _, err := exec.evalStatements(classDef.Body, env)
88-
exec.popReceiver()
89-
if err != nil {
90-
return NewNil(), err
91-
}
78+
if err := initializeClassBodiesForCall(exec, root, callClasses); err != nil {
79+
return NewNil(), err
9280
}
9381

9482
callEnv := newEnv(root)

0 commit comments

Comments
 (0)