Skip to content

Commit

Permalink
Implemented rb_frame_method_and_id internal API.
Browse files Browse the repository at this point in the history
This commit implements rb_frame_method_and_id internal API, that is
needed by the rice gem. The corresponding changeset represents a first
but hopefully significant step to get torch.rb working on Truffleruby.
  • Loading branch information
mtortonesi committed Dec 27, 2023
1 parent 26f8683 commit 55f0659
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/c/cext/call.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,7 @@ VALUE rb_eval_cmd_kw(VALUE cmd, VALUE args, int kw_splat) {
return RUBY_CEXT_INVOKE("rb_eval_string", cmd);
}
}

int rb_frame_method_id_and_class(ID *idp, VALUE *klassp) {
return RUBY_CEXT_INVOKE("rb_frame_method_id_and_class", idp, klassp);
}
31 changes: 31 additions & 0 deletions src/main/java/org/truffleruby/cext/CExtNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -2071,4 +2071,35 @@ RubyArray zlibGetCRCTable() {
}
}

@CoreMethod(names = "rb_frame_method_and_id", onSingleton = true, required = 2)
public abstract static class FrameMethodAndId extends CoreMethodArrayArgumentsNode {

@Specialization
boolean frameMethodAndId(Object frameMethod, Object frameId) {
final Frame callingMethodFrame = findCallingMethodFrame();
frameMethod = RubyArguments.getMethod(callingMethodFrame);
frameId = System.identityHashCode(RubyArguments.tryGetSelf(callingMethodFrame));
return true;
}

@TruffleBoundary
private static Frame findCallingMethodFrame() {
return Truffle.getRuntime().iterateFrames(frameInstance -> {
final Frame frame = frameInstance.getFrame(FrameAccess.READ_ONLY);

final InternalMethod method = RubyArguments.tryGetMethod(frame);

if (method == null) {
return null;
} else if (method.getName().equals(/* Truffle::CExt. */ "rb_frame_method_and_id") ||
method.getName().equals(/* Truffle::Interop */ "execute_without_conversion")) {
// TODO CS 11-Mar-17 must have a more precise check to skip these methods
return null;
} else {
return frame;
}
});
}
}

}

0 comments on commit 55f0659

Please sign in to comment.