Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand Down Expand Up @@ -50,14 +50,10 @@ public LetExprNode(

@Override
public Object executeGeneric(VirtualFrame frame) {
if (functionNode == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
functionNode = unresolvedFunctionNode.execute(frame);
callNode = insert(DirectCallNode.create(functionNode.getCallTarget()));
if (isCustomThisScope) {
// deferred until execution time s.t. nodes of inlined type aliases get the right frame slot
customThisSlot = VmUtils.findCustomThisSlot(frame);
}
// Usamos callNode como flag de inicialização para garantir que
// todos os campos dependentes estejam prontos antes de prosseguir.
if (callNode == null) {
initialize(frame);
}

var function =
Expand All @@ -72,4 +68,29 @@ public Object executeGeneric(VirtualFrame frame) {

return callNode.call(function.getThisValue(), function, value);
}

/**
* Inicializa o nó de chamada e resolve a função de forma thread-safe.
*/
private synchronized void initialize(VirtualFrame frame) {
if (callNode != null) {
return;
}

CompilerDirectives.transferToInterpreterAndInvalidate();

// Resolvemos a função primeiro
var resolvedFunction = unresolvedFunctionNode.execute(frame);

if (isCustomThisScope) {
customThisSlot = VmUtils.findCustomThisSlot(frame);
}

// Atribuímos functionNode antes do callNode
this.functionNode = resolvedFunction;

// Inserimos o callNode por último.
// Quando este campo deixar de ser nulo, os outros já estarão visíveis.
this.callNode = insert(DirectCallNode.create(resolvedFunction.getCallTarget()));
}
}
Loading