Skip to content

Commit 22b204b

Browse files
committed
Implement rb_keyword_given_p()
1 parent afb570f commit 22b204b

File tree

7 files changed

+37
-34
lines changed

7 files changed

+37
-34
lines changed

lib/cext/ABI_check.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4
1+
5

src/main/c/cext/call.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ VALUE rb_call_super(int args_count, const VALUE *args) {
7575
}
7676

7777
int rb_keyword_given_p(void) {
78-
return 0; // TODO
78+
return polyglot_as_boolean(RUBY_CEXT_INVOKE_NO_WRAP("rb_keyword_given_p")) ? RB_PASS_KEYWORDS : RB_NO_KEYWORDS;
7979
}
8080

8181
int rb_block_given_p(void) {

src/main/java/org/truffleruby/cext/CExtNodes.java

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,12 @@ public abstract static class CallWithCExtLockAndFrameNode extends PrimitiveArray
145145

146146
@Specialization
147147
protected Object callWithCExtLockAndFrame(
148-
Object receiver, RubyArray argsArray, Object specialVariables, Object block) {
148+
VirtualFrame frame, Object receiver, RubyArray argsArray, Object specialVariables, Object block) {
149149
final ExtensionCallStack extensionStack = getLanguage()
150150
.getCurrentThread()
151151
.getCurrentFiber().extensionCallStack;
152-
extensionStack.push(specialVariables, block);
152+
final boolean keywordsGiven = RubyArguments.getDescriptor(frame) instanceof KeywordArgumentsDescriptor;
153+
extensionStack.push(keywordsGiven, specialVariables, block);
153154
try {
154155
return callCextNode.execute(receiver, argsArray);
155156
} finally {
@@ -746,6 +747,14 @@ protected RubyString trStrCapaResize(RubyString string, int newCapacity,
746747

747748
}
748749

750+
@CoreMethod(names = "rb_keyword_given_p", onSingleton = true)
751+
public abstract static class RbKeywordGivenNode extends CoreMethodArrayArgumentsNode {
752+
753+
@Specialization
754+
protected boolean keywordGiven() {
755+
return getLanguage().getCurrentThread().getCurrentFiber().extensionCallStack.areKeywordsGiven();
756+
}
757+
}
749758

750759
@CoreMethod(names = "rb_block_proc", onSingleton = true)
751760
public abstract static class BlockProcNode extends CoreMethodArrayArgumentsNode {
@@ -1669,26 +1678,6 @@ protected Object createMarker(RubyDynamicObject object, RubyProc marker) {
16691678

16701679
}
16711680

1672-
@CoreMethod(names = "push_extension_call_frame", onSingleton = true, required = 1)
1673-
public abstract static class PushPreservingFrame extends CoreMethodArrayArgumentsNode {
1674-
1675-
@Specialization
1676-
protected Object pushFrame(Object variables, RubyProc block) {
1677-
getLanguage().getCurrentThread().getCurrentFiber().extensionCallStack.push(variables, block);
1678-
return nil;
1679-
}
1680-
}
1681-
1682-
@CoreMethod(names = "pop_extension_call_frame", onSingleton = true, required = 0)
1683-
public abstract static class PopPreservingFrame extends CoreMethodArrayArgumentsNode {
1684-
1685-
@Specialization
1686-
protected Object popFrame() {
1687-
getLanguage().getCurrentThread().getCurrentFiber().extensionCallStack.pop();
1688-
return nil;
1689-
}
1690-
}
1691-
16921681
@CoreMethod(names = "rb_thread_check_ints", onSingleton = true, required = 0)
16931682
public abstract static class CheckThreadInterrupt extends CoreMethodArrayArgumentsNode {
16941683

src/main/java/org/truffleruby/core/FinalizationService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ protected void processReference(RubyContext context, RubyLanguage language,
9696
protected void processReferenceInternal(RubyContext context, RubyLanguage language,
9797
FinalizerReference finalizerReference) {
9898
final ExtensionCallStack stack = language.getCurrentThread().getCurrentFiber().extensionCallStack;
99-
stack.push(stack.getSpecialVariables(), stack.getBlock());
99+
stack.push(stack.areKeywordsGiven(), stack.getSpecialVariables(), stack.getBlock());
100100
try {
101101
while (!context.isFinalizing()) {
102102
final Finalizer finalizer;

src/main/java/org/truffleruby/core/MarkingService.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ protected void processReference(RubyContext context, RubyLanguage language, Proc
8787
@TruffleBoundary
8888
public void runAllMarkers(RubyContext context, RubyLanguage language) {
8989
final ExtensionCallStack stack = language.getCurrentThread().getCurrentFiber().extensionCallStack;
90-
stack.push(stack.getSpecialVariables(), stack.getBlock());
90+
stack.push(stack.areKeywordsGiven(), stack.getSpecialVariables(), stack.getBlock());
9191
try {
9292
// TODO (eregon, 15 Sept 2020): there seems to be no synchronization here while walking the list of
9393
// markingService, and concurrent mutations seem to be possible.
@@ -112,23 +112,31 @@ public void runAllMarkers(RubyContext context, RubyLanguage language) {
112112
private final UnsizedQueue keptObjectQueue = new UnsizedQueue();
113113

114114
protected static class ExtensionCallStackEntry {
115+
115116
protected final ExtensionCallStackEntry previous;
116117
protected final ArrayList<Object> preservedObjects = new ArrayList<>();
117-
protected final Object block;
118+
protected final boolean keywordsGiven;
118119
protected Object specialVariables;
120+
protected final Object block;
119121

120-
protected ExtensionCallStackEntry(ExtensionCallStackEntry previous, Object specialVariables, Object block) {
122+
protected ExtensionCallStackEntry(
123+
ExtensionCallStackEntry previous,
124+
boolean keywordsGiven,
125+
Object specialVariables,
126+
Object block) {
121127
this.previous = previous;
122-
this.block = block;
128+
this.keywordsGiven = keywordsGiven;
123129
this.specialVariables = specialVariables;
130+
this.block = block;
124131
}
125132
}
126133

127134
public static class ExtensionCallStack {
135+
128136
protected ExtensionCallStackEntry current;
129137

130138
public ExtensionCallStack(Object specialVariables, Object block) {
131-
current = new ExtensionCallStackEntry(null, specialVariables, block);
139+
current = new ExtensionCallStackEntry(null, false, specialVariables, block);
132140
}
133141

134142
public ArrayList<Object> getKeptObjects() {
@@ -141,8 +149,12 @@ public void pop() {
141149
current = current.previous;
142150
}
143151

144-
public void push(Object specialVariables, Object block) {
145-
current = new ExtensionCallStackEntry(current, specialVariables, block);
152+
public void push(boolean keywordsGiven, Object specialVariables, Object block) {
153+
current = new ExtensionCallStackEntry(current, keywordsGiven, specialVariables, block);
154+
}
155+
156+
public boolean areKeywordsGiven() {
157+
return current.keywordsGiven;
146158
}
147159

148160
public Object getSpecialVariables() {

src/main/java/org/truffleruby/language/loader/FeatureLoader.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
import com.oracle.truffle.api.source.Source;
6262
import com.oracle.truffle.api.source.SourceSection;
6363

64+
import static org.truffleruby.language.RubyBaseNode.nil;
65+
6466
public class FeatureLoader {
6567

6668
private final RubyContext context;
@@ -449,7 +451,7 @@ public void ensureCExtImplementationLoaded(String feature, RequireNode requireNo
449451
final Object initFunction = findFunctionInLibrary(library, "rb_tr_init", rubyLibPath);
450452

451453
final InteropLibrary interop = InteropLibrary.getFactory().getUncached();
452-
language.getCurrentThread().getCurrentFiber().extensionCallStack.push(Nil.INSTANCE, Nil.INSTANCE);
454+
language.getCurrentThread().getCurrentFiber().extensionCallStack.push(false, nil, nil);
453455
try {
454456
// rb_tr_init(Truffle::CExt)
455457
interop.execute(initFunction, truffleCExt);

src/main/java/org/truffleruby/language/loader/RequireNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ private void requireCExtension(String feature, String expandedPath, Node current
283283

284284
requireMetric("before-execute-" + feature);
285285
ValueWrapperManager.allocateNewBlock(getContext(), getLanguage());
286-
getLanguage().getCurrentThread().getCurrentFiber().extensionCallStack.push(nil, nil);
286+
getLanguage().getCurrentThread().getCurrentFiber().extensionCallStack.push(false, nil, nil);
287287
try {
288288
InteropNodes
289289
.execute(

0 commit comments

Comments
 (0)