Skip to content

Commit

Permalink
refactor: ContextThreadLocal execution environment
Browse files Browse the repository at this point in the history
  • Loading branch information
4e6 committed Oct 8, 2024
1 parent 4d29bfa commit c5b3c0c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ public final class EnsoLanguage extends TruffleLanguage<EnsoContext> {
private static final LanguageReference<EnsoLanguage> REFERENCE =
LanguageReference.create(EnsoLanguage.class);

private final ContextThreadLocal<ExecutionEnvironment[]> threadExecutionEnvironment =
locals.createContextThreadLocal(
(ctx, thread) -> new ExecutionEnvironment[] { ctx.getGlobalExecutionEnvironment() });
private final ContextThreadLocal<ExecutionEnvironment[]> executionEnvironment =
locals.createContextThreadLocal((ctx, thread) -> new ExecutionEnvironment[1]);

public static EnsoLanguage get(Node node) {
return REFERENCE.get(node);
Expand Down Expand Up @@ -377,11 +376,11 @@ protected Object getLanguageView(EnsoContext context, Object value) {
return null;
}

public ExecutionEnvironment getThreadExecutionEnvironment() {
return threadExecutionEnvironment.get()[0];
public ExecutionEnvironment getExecutionEnvironment() {
return executionEnvironment.get()[0];
}

public void setExecutionEnvironment(ExecutionEnvironment executionEnvironment) {
threadExecutionEnvironment.get()[0] = executionEnvironment;
this.executionEnvironment.get()[0] = executionEnvironment;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,8 @@ public ExecutionEnvironment getGlobalExecutionEnvironment() {
}

public ExecutionEnvironment getExecutionEnvironment() {
return language.getThreadExecutionEnvironment();
ExecutionEnvironment env = language.getExecutionEnvironment();
return env == null ? getGlobalExecutionEnvironment() : env;
}

/** Set the runtime execution environment of this context. */
Expand Down

0 comments on commit c5b3c0c

Please sign in to comment.