Skip to content

Commit 4dc2402

Browse files
committed
[GR-15297] Reintroduce Truffle::MAIN for interop code.
PullRequest: truffleruby/808
2 parents 59fb511 + af68d97 commit 4dc2402

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

spec/truffle/interop/import_spec.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. This
2+
# code is released under a tri EPL/GPL/LGPL license. You can use it,
3+
# redistribute it and/or modify it under the terms of the:
4+
#
5+
# Eclipse Public License version 1.0, or
6+
# GNU General Public License version 2, or
7+
# GNU Lesser General Public License version 2.1.
8+
9+
require_relative '../../ruby/spec_helper'
10+
11+
guard -> { Truffle::Interop.polyglot_access? } do
12+
describe "Truffle::Interop.import" do
13+
14+
it "imports an object" do
15+
object = Object.new
16+
Truffle::Interop.export :imports_an_object, object
17+
Truffle::Interop.import(:imports_an_object).should == object
18+
end
19+
20+
it "raises NameError if not found" do
21+
-> {
22+
Truffle::Interop.import(:not_registered_export_test)
23+
}.should raise_error(NameError, "import 'not_registered_export_test' not found")
24+
end
25+
26+
end
27+
end

src/main/java/org/truffleruby/RubyLanguage.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,12 @@ protected Object findExportedSymbol(RubyContext context, String symbolName, bool
145145
return null;
146146
}
147147

148-
return context.send(context.getCoreLibrary().getTruffleInteropModule(), "lookup_symbol", context.getSymbolTable().getSymbol(symbolName));
148+
Object implicit = context.send(context.getCoreLibrary().getTruffleInteropModule(), "lookup_symbol", context.getSymbolTable().getSymbol(symbolName));
149+
if (implicit == NotProvided.INSTANCE) {
150+
return null;
151+
} else {
152+
return implicit;
153+
}
149154
}
150155

151156
@SuppressWarnings("deprecation")

src/main/ruby/core/truffle/interop.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
# GNU General Public License version 2, or
99
# GNU Lesser General Public License version 2.1.
1010

11-
module Truffle
11+
# Used by Truffle::Interop.lookup_symbol
12+
Truffle::Interop::MAIN = self
1213

14+
module Truffle
1315
module Interop
1416

1517
def self.import_method(name)
@@ -111,7 +113,7 @@ def self.lookup_symbol(name)
111113
elsif Truffle::SymbolOperations.is_constant?(name) && Object.const_defined?(name)
112114
Object.const_get(name)
113115
else
114-
nil
116+
undefined
115117
end
116118
end
117119

0 commit comments

Comments
 (0)