Skip to content

Commit

Permalink
Merge pull request #334 from ichiban/avoid-recursive-load
Browse files Browse the repository at this point in the history
avoid recursive file load.
  • Loading branch information
ichiban authored Oct 13, 2024
2 parents 3223b40 + c33bef0 commit 8449bdf
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 8449bdf

Please sign in to comment.