|
12 | 12 | import java.io.IOException;
|
13 | 13 |
|
14 | 14 | import org.truffleruby.Layouts;
|
15 |
| -import org.truffleruby.builtins.CoreModule; |
16 | 15 | import org.truffleruby.builtins.CoreMethod;
|
17 | 16 | import org.truffleruby.builtins.CoreMethodArrayArgumentsNode;
|
18 | 17 | import org.truffleruby.builtins.CoreMethodNode;
|
| 18 | +import org.truffleruby.builtins.CoreModule; |
19 | 19 | import org.truffleruby.builtins.Primitive;
|
20 | 20 | import org.truffleruby.core.cast.BooleanCastWithDefaultNodeGen;
|
21 |
| -import org.truffleruby.core.klass.ClassNodes; |
| 21 | +import org.truffleruby.core.module.ModuleNodes; |
22 | 22 | import org.truffleruby.core.string.StringOperations;
|
23 | 23 | import org.truffleruby.language.RubyNode;
|
24 | 24 | import org.truffleruby.language.RubyRootNode;
|
25 | 25 | import org.truffleruby.language.control.RaiseException;
|
| 26 | +import org.truffleruby.language.dispatch.CallDispatchHeadNode; |
26 | 27 | import org.truffleruby.language.globals.ReadSimpleGlobalVariableNode;
|
27 | 28 | import org.truffleruby.language.globals.WriteSimpleGlobalVariableNode;
|
28 | 29 | import org.truffleruby.language.loader.CodeLoader;
|
@@ -80,40 +81,37 @@ protected boolean load(DynamicObject file, boolean wrap,
|
80 | 81 | throw new RaiseException(getContext(), coreExceptions().loadErrorCannotLoad(feature, this));
|
81 | 82 | }
|
82 | 83 |
|
83 |
| - final DynamicObject wrapClass; |
84 |
| - |
| 84 | + final DynamicObject wrapModule; |
85 | 85 | if (wrap) {
|
86 |
| - wrapClass = ClassNodes.createInitializedRubyClass( |
87 |
| - getContext(), |
88 |
| - null, |
89 |
| - null, |
90 |
| - getContext().getCoreLibrary().getObjectClass(), |
91 |
| - null); |
| 86 | + wrapModule = ModuleNodes |
| 87 | + .createModule(getContext(), null, coreLibrary().getModuleClass(), null, null, this); |
92 | 88 | } else {
|
93 |
| - wrapClass = null; |
| 89 | + wrapModule = null; |
94 | 90 | }
|
95 | 91 |
|
96 | 92 | final RubyRootNode rootNode = getContext()
|
97 | 93 | .getCodeLoader()
|
98 |
| - .parse(source, ParserContext.TOP_LEVEL, null, wrapClass, true, this); |
| 94 | + .parse(source, ParserContext.TOP_LEVEL, null, wrapModule, true, this); |
99 | 95 |
|
| 96 | + final DynamicObject mainObject = getContext().getCoreLibrary().getMainObject(); |
100 | 97 | final DeclarationContext declarationContext;
|
101 |
| - final DynamicObject mainObject; |
| 98 | + final Object self; |
102 | 99 |
|
103 |
| - if (wrapClass == null) { |
| 100 | + if (wrapModule == null) { |
104 | 101 | declarationContext = DeclarationContext.topLevel(getContext());
|
105 |
| - mainObject = getContext().getCoreLibrary().getMainObject(); |
| 102 | + self = mainObject; |
106 | 103 | } else {
|
107 |
| - declarationContext = DeclarationContext.topLevel(wrapClass); |
108 |
| - mainObject = Layouts.CLASS.getInstanceFactory(wrapClass).newInstance(); |
| 104 | + declarationContext = DeclarationContext.topLevel(wrapModule); |
| 105 | + self = CallDispatchHeadNode.getUncached().call(mainObject, "clone"); |
| 106 | + CallDispatchHeadNode.getUncached().call(self, "extend", wrapModule); |
109 | 107 | }
|
110 | 108 |
|
111 | 109 | final CodeLoader.DeferredCall deferredCall = getContext().getCodeLoader().prepareExecute(
|
112 | 110 | ParserContext.TOP_LEVEL,
|
113 | 111 | declarationContext,
|
114 | 112 | rootNode,
|
115 | 113 | null,
|
116 |
| - mainObject); |
| 114 | + self); |
117 | 115 |
|
118 | 116 | deferredCall.call(callNode);
|
119 | 117 |
|
|
0 commit comments