Skip to content

Commit

Permalink
avoid recursive file load.
Browse files Browse the repository at this point in the history
  • Loading branch information
ichiban committed Oct 4, 2024
1 parent 03d3d3d commit c33bef0
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions engine/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,16 @@ func (vm *VM) ensureLoaded(ctx context.Context, file Term, env *Env) error {
if _, ok := vm.loaded[f]; ok {
return nil
}
defer func() {
vm.loaded[f] = struct{}{}
}()

return vm.Compile(ctx, string(b))
// It's too early to say it's fully loaded. Yet this avoids recursive load of the same file.
vm.loaded[f] = struct{}{}

if err := vm.Compile(ctx, string(b)); err != nil {
delete(vm.loaded, f) // It wasn't fully loaded after all.
return err
}

return nil
}

func (vm *VM) open(file Term, env *Env) (string, []byte, error) {
Expand Down

0 comments on commit c33bef0

Please sign in to comment.