Skip to content

Commit b7832f4

Browse files
committed
Add basic test for YARP
1 parent f39ef4d commit b7832f4

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

spec/truffle/yarp_spec.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# truffleruby_primitives: true
2+
3+
# Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved. This
4+
# code is released under a tri EPL/GPL/LGPL license. You can use it,
5+
# redistribute it and/or modify it under the terms of the:
6+
#
7+
# Eclipse Public License version 2.0, or
8+
# GNU General Public License version 2, or
9+
# GNU Lesser General Public License version 2.1.
10+
11+
require_relative '../ruby/spec_helper'
12+
13+
# Similar tests as in https://github.com/ruby/yarp/blob/main/.github/workflows/truffleruby.yml
14+
describe "YARP" do
15+
it "can parse core files" do
16+
root = File.expand_path("../..", __dir__)
17+
Dir.glob("#{root}/src/main/ruby/truffleruby/**/*.rb") do |file|
18+
Truffle::Debug.yarp_parse(File.read(file)).should.include?("Node")
19+
end
20+
end
21+
22+
it "can execute simple code" do
23+
-> {
24+
-> {
25+
Truffle::Debug.yarp_execute("p 1+2").should == 3
26+
}.should output_to_fd(/^YARP AST:.+Truffle AST:/m, STDERR)
27+
}.should output("3\n")
28+
end
29+
end

src/main/java/org/truffleruby/debug/TruffleDebugNodes.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,15 +298,19 @@ protected Object parse(Object code,
298298

299299
@CoreMethod(names = "yarp_execute", onSingleton = true, required = 1)
300300
public abstract static class YARPExecuteNode extends CoreMethodArrayArgumentsNode {
301-
@TruffleBoundary
302301
@Specialization(guards = "strings.isRubyString(code)", limit = "1")
303-
protected Object yarpExecute(Object code,
302+
protected Object yarpExecute(VirtualFrame frame, Object code,
304303
@Cached RubyStringLibrary strings,
305304
@Cached TruffleString.CopyToByteArrayNode copyToByteArrayNode) {
306305
var tstring = strings.getTString(code);
307306
var tencoding = strings.getTEncoding(code);
308307
var source = copyToByteArrayNode.execute(tstring, tencoding);
309308

309+
return doExecute(source, RubyArguments.getMethod(frame));
310+
}
311+
312+
@TruffleBoundary
313+
private Object doExecute(byte[] source, InternalMethod method) {
310314
byte[] serialized = yarpSerialize(getLanguage(), source);
311315

312316
var ast = Loader.load(source, serialized);
@@ -320,7 +324,7 @@ protected Object yarpExecute(Object code,
320324
return truffleAST.getCallTarget().call(RubyArguments.pack(
321325
null,
322326
null,
323-
null,
327+
method,
324328
DeclarationContext.topLevel(getContext()),
325329
null,
326330
coreLibrary().mainObject,

0 commit comments

Comments
 (0)