/
Ruby.java
2520 lines (2095 loc) · 85.8 KB
/
Ruby.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
**** BEGIN LICENSE BLOCK *****
* Version: CPL 1.0/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Common Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.eclipse.org/legal/cpl-v10.html
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* Copyright (C) 2001 Chad Fowler <chadfowler@chadfowler.com>
* Copyright (C) 2001 Alan Moore <alan_moore@gmx.net>
* Copyright (C) 2001-2002 Benoit Cerrina <b.cerrina@wanadoo.fr>
* Copyright (C) 2001-2004 Jan Arne Petersen <jpetersen@uni-bonn.de>
* Copyright (C) 2002-2004 Anders Bengtsson <ndrsbngtssn@yahoo.se>
* Copyright (C) 2004 Thomas E Enebo <enebo@acm.org>
* Copyright (C) 2004-2005 Charles O Nutter <headius@headius.com>
* Copyright (C) 2004 Stefan Matthias Aust <sma@3plus4.de>
* Copyright (C) 2006 Miguel Covarrubias <mlcovarrubias@gmail.com>
* Copyright (C) 2006 Michael Studman <codehaus@michaelstudman.com>
* Copyright (C) 2006 Ola Bini <ola@ologix.com>
* Copyright (C) 2007 Nick Sieger <nicksieger@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the CPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the CPL, the GPL or the LGPL.
***** END LICENSE BLOCK *****/
package org.jruby;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Stack;
import java.util.WeakHashMap;
import org.jruby.ast.Node;
import org.jruby.ast.executable.RubiniusRunner;
import org.jruby.ast.executable.Script;
import org.jruby.ast.executable.YARVCompiledRunner;
import org.jruby.common.RubyWarnings;
import org.jruby.compiler.ASTCompiler;
import org.jruby.compiler.ASTInspector;
import org.jruby.compiler.NotCompilableException;
import org.jruby.compiler.impl.StandardASMCompiler;
import org.jruby.compiler.yarv.StandardYARVCompiler;
import org.jruby.evaluator.ASTInterpreter;
import org.jruby.exceptions.JumpException;
import org.jruby.exceptions.RaiseException;
import org.jruby.ext.JavaBasedPOSIX;
import org.jruby.ext.LateLoadingLibrary;
import org.jruby.ext.POSIX;
import org.jruby.ext.POSIXFunctionMapper;
import org.jruby.ext.socket.RubySocket;
import org.jruby.internal.runtime.GlobalVariables;
import org.jruby.internal.runtime.ThreadService;
import org.jruby.internal.runtime.ValueAccessor;
import org.jruby.javasupport.Java;
import org.jruby.javasupport.JavaSupport;
import org.jruby.libraries.RbConfigLibrary;
import org.jruby.parser.Parser;
import org.jruby.parser.ParserConfiguration;
import org.jruby.regexp.RegexpFactory;
import org.jruby.runtime.Block;
import org.jruby.runtime.CacheMap;
import org.jruby.runtime.CallbackFactory;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.EventHook;
import org.jruby.runtime.GlobalVariable;
import org.jruby.runtime.IAccessor;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.ObjectSpace;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.load.Library;
import org.jruby.runtime.load.LoadService;
import org.jruby.util.ByteList;
import org.jruby.util.IOHandler;
import org.jruby.util.IOInputStream;
import org.jruby.util.IOOutputStream;
import org.jruby.util.JRubyClassLoader;
import org.jruby.util.KCode;
import org.jruby.util.MethodCache;
import org.jruby.util.NormalizedFile;
import org.jruby.runtime.Binding;
import com.sun.jna.Native;
/**
* The jruby runtime.
*/
public final class Ruby {
private static String[] BUILTIN_LIBRARIES = {"fcntl", "yaml", "yaml/syck", "jsignal" };
private CacheMap cacheMap = new CacheMap();
private MethodCache methodCache = new MethodCache();
private ThreadService threadService;
private Hashtable<Object, Object> runtimeInformation;
private static POSIX posix = loadPosix();
private int stackTraces = 0;
private ObjectSpace objectSpace = new ObjectSpace();
public final RubyFixnum[] fixnumCache = new RubyFixnum[256];
private final RubySymbol.SymbolTable symbolTable = new RubySymbol.SymbolTable(this);
private Hashtable<Integer, WeakReference<IOHandler>> ioHandlers = new Hashtable<Integer, WeakReference<IOHandler>>();
private long randomSeed = 0;
private long randomSeedSequence = 0;
private Random random = new Random();
private ArrayList<EventHook> eventHooks = new ArrayList<EventHook>();
private boolean hasEventHooks;
private boolean globalAbortOnExceptionEnabled = false;
private boolean doNotReverseLookupEnabled = false;
private final boolean objectSpaceEnabled;
private long globalState = 1;
/** safe-level:
0 - strings from streams/environment/ARGV are tainted (default)
1 - no dangerous operation by tainted value
2 - process/file operations prohibited
3 - all generated objects are tainted
4 - no global (non-tainted) variable modification/no direct output
*/
private int safeLevel = 0;
// Default classes/objects
private IRubyObject undef;
private RubyClass objectClass;
private RubyClass moduleClass;
private RubyClass classClass;
private RubyModule kernelModule;
private RubyClass nilClass;
private RubyClass trueClass;
private RubyClass falseClass;
private RubyModule comparableModule;
private RubyClass numericClass;
private RubyClass floatClass;
private RubyClass integerClass;
private RubyClass fixnumClass;
private RubyModule enumerableModule;
private RubyClass arrayClass;
private RubyClass hashClass;
private RubyClass rangeClass;
private RubyClass stringClass;
private RubyClass symbolClass;
private RubyNil nilObject;
private RubyBoolean trueObject;
private RubyBoolean falseObject;
private RubyClass procClass;
private RubyClass bindingClass;
private RubyClass methodClass;
private RubyClass unboundMethodClass;
private RubyClass matchDataClass;
private RubyClass regexpClass;
private RubyClass timeClass;
private RubyModule mathModule;
private RubyModule marshalModule;
private RubyClass bignumClass;
private RubyClass dirClass;
private RubyClass fileClass;
private RubyClass fileStatClass;
private RubyModule fileTestModule;
private RubyClass statClass;
private RubyClass ioClass;
private RubyClass threadClass;
private RubyClass threadGroupClass;
private RubyClass continuationClass;
private RubyClass structClass;
private IRubyObject tmsStruct;
private RubyModule gcModule;
private RubyModule objectSpaceModule;
private RubyModule processModule;
private RubyClass procStatusClass;
private RubyModule procUIDModule;
private RubyModule procGIDModule;
private RubyModule precisionModule;
private RubyClass exceptionClass;
private RubyClass systemCallError = null;
private RubyModule errnoModule = null;
private IRubyObject topSelf;
// record separator var, to speed up io ops that use it
private GlobalVariable recordSeparatorVar;
// former java.lang.System concepts now internalized for MVM
private String currentDirectory;
private long startTime = System.currentTimeMillis();
private RubyInstanceConfig config;
private InputStream in;
private PrintStream out;
private PrintStream err;
private IRubyObject verbose;
private IRubyObject debug;
// Java support
private JavaSupport javaSupport;
public static final JRubyClassLoader defaultJRubyClassLoader = new JRubyClassLoader(Thread.currentThread().getContextClassLoader());
private JRubyClassLoader jrubyClassLoader;
private static boolean securityRestricted = false;
private Parser parser = new Parser(this);
private LoadService loadService;
private GlobalVariables globalVariables = new GlobalVariables(this);
private RubyWarnings warnings = new RubyWarnings(this);
// Contains a list of all blocks (as Procs) that should be called when
// the runtime environment exits.
private Stack<RubyProc> atExitBlocks = new Stack<RubyProc>();
private Profile profile;
private String jrubyHome;
private KCode kcode = KCode.NONE;
public int symbolLastId = 128;
public int moduleLastId = 0;
private Object respondToMethod;
private RegexpFactory regexpFactory;
/**
* A list of finalizers, weakly referenced, to be executed on tearDown
*/
private Map<Finalizable, Object> finalizers;
private String[] argv;
/**
* Create and initialize a new JRuby Runtime.
*/
private Ruby(RubyInstanceConfig config) {
this.config = config;
this.threadService = new ThreadService(this);
if(config.isSamplingEnabled()) {
org.jruby.util.SimpleSampler.registerThreadContext(threadService.getCurrentContext());
}
this.in = config.getInput();
this.out = config.getOutput();
this.err = config.getError();
this.objectSpaceEnabled = config.isObjectSpaceEnabled();
this.profile = config.getProfile();
this.currentDirectory = config.getCurrentDirectory();
this.jrubyClassLoader = config.getJRubyClassLoader();
this.argv = config.getArgv();
}
/**
* @deprecated use #newInstance()
*/
public static Ruby getDefaultInstance() {
return newInstance();
}
/**
* Returns a default instance of the JRuby runtime.
*
* @return the JRuby runtime
*/
public static Ruby newInstance() {
return newInstance(new RubyInstanceConfig());
}
/**
* Returns a default instance of the JRuby runtime configured as provided.
*
* @param config the instance configuration
* @return the JRuby runtime
*/
public static Ruby newInstance(RubyInstanceConfig config) {
Ruby ruby = new Ruby(config);
ruby.init();
return ruby;
}
/**
* Returns a default instance of the JRuby runtime configured with the given input, output and error streams.
*
* @param in the custom input stream
* @param out the custom output stream
* @param err the custom error stream
* @return the JRuby runtime
*/
public static Ruby newInstance(InputStream in, PrintStream out, PrintStream err) {
RubyInstanceConfig config = new RubyInstanceConfig();
config.setInput(in);
config.setOutput(out);
config.setError(err);
return newInstance(config);
}
public IRubyObject evalFile(InputStream in, String name) {
return eval(parseFile(in, name, getCurrentContext().getCurrentScope()));
}
/**
* Evaluates a script and returns a RubyObject.
*/
public IRubyObject evalScriptlet(String script) {
return eval(parseEval(script, "<script>", getCurrentContext().getCurrentScope(), 0));
}
public IRubyObject eval(Node node) {
try {
ThreadContext tc = getCurrentContext();
return ASTInterpreter.eval(this, tc, node, tc.getFrameSelf(), Block.NULL_BLOCK);
} catch (JumpException.ReturnJump rj) {
throw newLocalJumpError("return", (IRubyObject)rj.getValue(), "unexpected return");
} catch (JumpException.BreakJump bj) {
throw newLocalJumpError("break", (IRubyObject)bj.getValue(), "unexpected break");
} catch (JumpException.RedoJump rj) {
throw newLocalJumpError("redo", (IRubyObject)rj.getValue(), "unexpected redo");
}
}
/**
* This differs from the other methods in that it accepts a string-based script and
* parses and runs it as though it were loaded at a command-line. This is the preferred
* way to start up a new script when calling directly into the Ruby object (which is
* generally *dis*couraged.
*
* @param script The contents of the script to run as a normal, root script
* @return The last value of the script
*/
public IRubyObject executeScript(String script, String filename) {
byte[] bytes;
try {
bytes = script.getBytes(KCode.NONE.getKCode());
} catch (UnsupportedEncodingException e) {
bytes = script.getBytes();
}
Node node = parseInline(new ByteArrayInputStream(bytes), filename, null);
getCurrentContext().getCurrentFrame().setPosition(node.getPosition());
return runNormally(node, false);
}
public void runFromMain(InputStream in, String filename) {
if(config.isYARVEnabled()) {
new YARVCompiledRunner(this, in, filename).run();
} else if(config.isRubiniusEnabled()) {
new RubiniusRunner(this, in, filename).run();
} else {
Node scriptNode;
if (config.isInlineScript()) {
scriptNode = parseInline(in, filename, getCurrentContext().getCurrentScope());
} else {
scriptNode = parseFile(in, filename, getCurrentContext().getCurrentScope());
}
getCurrentContext().getCurrentFrame().setPosition(scriptNode.getPosition());
if (config.isAssumePrinting() || config.isAssumeLoop()) {
runWithGetsLoop(scriptNode, config.isAssumePrinting(), config.isProcessLineEnds(),
config.isSplit(), config.isYARVCompileEnabled());
} else {
runNormally(scriptNode, config.isYARVCompileEnabled());
}
}
}
public IRubyObject runWithGetsLoop(Node scriptNode, boolean printing, boolean processLineEnds, boolean split, boolean yarvCompile) {
ThreadContext context = getCurrentContext();
Script script = null;
YARVCompiledRunner runner = null;
boolean compile = getInstanceConfig().getCompileMode().shouldPrecompileCLI();
if (compile || !yarvCompile) {
script = tryCompile(scriptNode);
if (compile && script == null) {
// terminate; tryCompile will have printed out an error and we're done
return getNil();
}
} else if (yarvCompile) {
runner = tryCompileYarv(scriptNode);
}
if (processLineEnds) {
getGlobalVariables().set("$\\", getGlobalVariables().get("$/"));
}
while (RubyKernel.gets(getTopSelf(), IRubyObject.NULL_ARRAY).isTrue()) {
loop: while (true) { // Used for the 'redo' command
try {
if (processLineEnds) {
getGlobalVariables().get("$_").callMethod(context, "chop!");
}
if (split) {
getGlobalVariables().set("$F", getGlobalVariables().get("$_").callMethod(context, "split"));
}
if (script != null) {
runScript(script);
} else if (runner != null) {
runYarv(runner);
} else {
runInterpreter(scriptNode);
}
if (printing) RubyKernel.print(getKernel(), new IRubyObject[] {getGlobalVariables().get("$_")});
break loop;
} catch (JumpException.RedoJump rj) {
// do nothing, this iteration restarts
} catch (JumpException.NextJump nj) {
// recheck condition
break loop;
} catch (JumpException.BreakJump bj) {
// end loop
return (IRubyObject) bj.getValue();
}
}
}
return getNil();
}
public IRubyObject runNormally(Node scriptNode, boolean yarvCompile) {
Script script = null;
YARVCompiledRunner runner = null;
boolean compile = getInstanceConfig().getCompileMode().shouldPrecompileCLI();
boolean forceCompile = getInstanceConfig().getCompileMode().shouldPrecompileAll();
if (compile) {
script = tryCompile(scriptNode);
if (forceCompile && script == null) {
System.err.println("Error, could not compile; pass -J-Djruby.jit.logging.verbose=true for more details");
return getNil();
}
} else if (yarvCompile) {
runner = tryCompileYarv(scriptNode);
}
if (script != null) {
return runScript(script);
} else if (runner != null) {
return runYarv(runner);
} else {
return runInterpreter(scriptNode);
}
}
private Script tryCompile(Node node) {
Script script = null;
try {
String filename = node.getPosition().getFile();
String classname;
if (filename.equals("-e")) {
classname = "__dash_e__";
} else {
classname = filename.replace('\\', '/').replaceAll(".rb", "");
}
// remove leading / or ./ from classname, since it will muck up the dotted name
if (classname.startsWith("/")) classname = classname.substring(1);
if (classname.startsWith("./")) classname = classname.substring(2);
ASTInspector inspector = new ASTInspector();
inspector.inspect(node);
StandardASMCompiler compiler = new StandardASMCompiler(classname, filename);
ASTCompiler.compileRoot(node, compiler, inspector);
script = (Script)compiler.loadClass(this.getJRubyClassLoader()).newInstance();
if (config.isJitLogging()) {
System.err.println("compiled: " + node.getPosition().getFile());
}
} catch (NotCompilableException nce) {
if (config.isJitLoggingVerbose()) {
System.err.println("Error -- Not compileable: " + nce.getMessage());
}
} catch (ClassNotFoundException e) {
if (config.isJitLoggingVerbose()) {
System.err.println("Error -- Not compileable: " + e.getMessage());
}
} catch (InstantiationException e) {
if (config.isJitLoggingVerbose()) {
System.err.println("Error -- Not compileable: " + e.getMessage());
}
} catch (IllegalAccessException e) {
if (config.isJitLoggingVerbose()) {
System.err.println("Error -- Not compileable: " + e.getMessage());
}
} catch (Throwable t) {
if (config.isJitLoggingVerbose()) {
System.err.println("coult not compile: " + node.getPosition().getFile() + " because of: \"" + t.getMessage() + "\"");
}
}
return script;
}
private YARVCompiledRunner tryCompileYarv(Node node) {
try {
StandardYARVCompiler compiler = new StandardYARVCompiler(this);
ASTCompiler.getYARVCompiler().compile(node, compiler);
org.jruby.lexer.yacc.ISourcePosition p = node.getPosition();
if(p == null && node instanceof org.jruby.ast.RootNode) {
p = ((org.jruby.ast.RootNode)node).getBodyNode().getPosition();
}
return new YARVCompiledRunner(this,compiler.getInstructionSequence("<main>",p.getFile(),"toplevel"));
} catch (NotCompilableException nce) {
System.err.println("Error -- Not compileable: " + nce.getMessage());
return null;
} catch (JumpException.ReturnJump rj) {
return null;
}
}
private IRubyObject runScript(Script script) {
ThreadContext context = getCurrentContext();
try {
return script.load(getCurrentContext(), context.getFrameSelf(), IRubyObject.NULL_ARRAY, Block.NULL_BLOCK);
} catch (JumpException.ReturnJump rj) {
return (IRubyObject) rj.getValue();
}
}
private IRubyObject runYarv(YARVCompiledRunner runner) {
try {
return runner.run();
} catch (JumpException.ReturnJump rj) {
return (IRubyObject) rj.getValue();
}
}
private IRubyObject runInterpreter(Node scriptNode) {
ThreadContext context = getCurrentContext();
try {
return ASTInterpreter.eval(this, context, scriptNode, getTopSelf(), Block.NULL_BLOCK);
} catch (JumpException.ReturnJump rj) {
return (IRubyObject) rj.getValue();
}
}
Object getRespondToMethod() {
return respondToMethod;
}
void setRespondToMethod(Object rtm) {
this.respondToMethod = rtm;
}
public IRubyObject getUndef() {
return undef;
}
public RubyClass getObject() {
return objectClass;
}
public RubyClass getModule() {
return moduleClass;
}
public RubyClass getClassClass() {
return classClass;
}
public RubyModule getKernel() {
return kernelModule;
}
void setKernel(RubyModule kernelModule) {
this.kernelModule = kernelModule;
}
public RubyModule getComparable() {
return comparableModule;
}
void setComparable(RubyModule comparableModule) {
this.comparableModule = comparableModule;
}
public RubyClass getNumeric() {
return numericClass;
}
void setNumeric(RubyClass numericClass) {
this.numericClass = numericClass;
}
public RubyClass getFloat() {
return floatClass;
}
void setFloat(RubyClass floatClass) {
this.floatClass = floatClass;
}
public RubyClass getInteger() {
return integerClass;
}
void setInteger(RubyClass integerClass) {
this.integerClass = integerClass;
}
public RubyClass getFixnum() {
return fixnumClass;
}
void setFixnum(RubyClass fixnumClass) {
this.fixnumClass = fixnumClass;
}
public RubyModule getEnumerable() {
return enumerableModule;
}
void setEnumerable(RubyModule enumerableModule) {
this.enumerableModule = enumerableModule;
}
public RubyClass getString() {
return stringClass;
}
void setString(RubyClass stringClass) {
this.stringClass = stringClass;
}
public RubyClass getSymbol() {
return symbolClass;
}
void setSymbol(RubyClass symbolClass) {
this.symbolClass = symbolClass;
}
public RubyClass getArray() {
return arrayClass;
}
void setArray(RubyClass arrayClass) {
this.arrayClass = arrayClass;
}
public RubyClass getHash() {
return hashClass;
}
void setHash(RubyClass hashClass) {
this.hashClass = hashClass;
}
public RubyClass getRange() {
return rangeClass;
}
void setRange(RubyClass rangeClass) {
this.rangeClass = rangeClass;
}
/** Returns the "true" instance from the instance pool.
* @return The "true" instance.
*/
public RubyBoolean getTrue() {
return trueObject;
}
/** Returns the "false" instance from the instance pool.
* @return The "false" instance.
*/
public RubyBoolean getFalse() {
return falseObject;
}
/** Returns the "nil" singleton instance.
* @return "nil"
*/
public IRubyObject getNil() {
return nilObject;
}
public RubyClass getNilClass() {
return nilClass;
}
void setNilClass(RubyClass nilClass) {
this.nilClass = nilClass;
}
public RubyClass getTrueClass() {
return trueClass;
}
void setTrueClass(RubyClass trueClass) {
this.trueClass = trueClass;
}
public RubyClass getFalseClass() {
return falseClass;
}
void setFalseClass(RubyClass falseClass) {
this.falseClass = falseClass;
}
public RubyClass getProc() {
return procClass;
}
void setProc(RubyClass procClass) {
this.procClass = procClass;
}
public RubyClass getBinding() {
return bindingClass;
}
void setBinding(RubyClass bindingClass) {
this.bindingClass = bindingClass;
}
public RubyClass getMethod() {
return methodClass;
}
void setMethod(RubyClass methodClass) {
this.methodClass = methodClass;
}
public RubyClass getUnboundMethod() {
return unboundMethodClass;
}
void setUnboundMethod(RubyClass unboundMethodClass) {
this.unboundMethodClass = unboundMethodClass;
}
public RubyClass getMatchData() {
return matchDataClass;
}
void setMatchData(RubyClass matchDataClass) {
this.matchDataClass = matchDataClass;
}
public RubyClass getRegexp() {
return regexpClass;
}
void setRegexp(RubyClass regexpClass) {
this.regexpClass = regexpClass;
}
public RubyClass getTime() {
return timeClass;
}
void setTime(RubyClass timeClass) {
this.timeClass = timeClass;
}
public RubyModule getMath() {
return mathModule;
}
void setMath(RubyModule mathModule) {
this.mathModule = mathModule;
}
public RubyModule getMarshal() {
return marshalModule;
}
void setMarshal(RubyModule marshalModule) {
this.marshalModule = marshalModule;
}
public RubyClass getBignum() {
return bignumClass;
}
void setBignum(RubyClass bignumClass) {
this.bignumClass = bignumClass;
}
public RubyClass getDir() {
return dirClass;
}
void setDir(RubyClass dirClass) {
this.dirClass = dirClass;
}
public RubyClass getFile() {
return fileClass;
}
void setFile(RubyClass fileClass) {
this.fileClass = fileClass;
}
public RubyClass getFileStat() {
return fileStatClass;
}
void setFileStat(RubyClass fileStatClass) {
this.fileStatClass = fileStatClass;
}
public RubyModule getFileTest() {
return fileTestModule;
}
void setFileTest(RubyModule fileTestModule) {
this.fileTestModule = fileTestModule;
}
public RubyClass getStat() {
return statClass;
}
void setStat(RubyClass statClass) {
this.statClass = statClass;
}
public RubyClass getIO() {
return ioClass;
}
void setIO(RubyClass ioClass) {
this.ioClass = ioClass;
}
public RubyClass getThread() {
return threadClass;
}
void setThread(RubyClass threadClass) {
this.threadClass = threadClass;
}
public RubyClass getThreadGroup() {
return threadGroupClass;
}
void setThreadGroup(RubyClass threadGroupClass) {
this.threadGroupClass = threadGroupClass;
}
public RubyClass getContinuation() {
return continuationClass;
}
void setContinuation(RubyClass continuationClass) {
this.continuationClass = continuationClass;
}
public RubyClass getStructClass() {
return structClass;
}
void setStructClass(RubyClass structClass) {
this.structClass = structClass;
}
public IRubyObject getTmsStruct() {
return tmsStruct;
}
void setTmsStruct(RubyClass tmsStruct) {
this.tmsStruct = tmsStruct;
}
public RubyModule getGC() {
return gcModule;
}
void setGC(RubyModule gcModule) {
this.gcModule = gcModule;
}
public RubyModule getObjectSpaceModule() {
return objectSpaceModule;
}
void setObjectSpaceModule(RubyModule objectSpaceModule) {
this.objectSpaceModule = objectSpaceModule;
}
public RubyModule getProcess() {
return processModule;
}
void setProcess(RubyModule processModule) {
this.processModule = processModule;
}
public RubyClass getProcStatus() {
return procStatusClass;
}
void setProcStatus(RubyClass procStatusClass) {
this.procStatusClass = procStatusClass;
}
public RubyModule getProcUID() {
return procUIDModule;
}
void setProcUID(RubyModule procUIDModule) {
this.procUIDModule = procUIDModule;
}
public RubyModule getProcGID() {
return procGIDModule;
}
void setProcGID(RubyModule procGIDModule) {
this.procGIDModule = procGIDModule;
}
public RubyModule getPrecision() {
return precisionModule;
}
void setPrecision(RubyModule precisionModule) {
this.precisionModule = precisionModule;
}
public RubyClass getException() {
return exceptionClass;
}
void setException(RubyClass exceptionClass) {
this.exceptionClass = exceptionClass;
}
public RubyModule getModule(String name) {
return (RubyModule) objectClass.getConstantAt(name);
}
/**
*
* @param internedName the name of the module; <em>must</em> be an interned String!
* @return
*/
public RubyModule fastGetModule(String internedName) {
return (RubyModule) objectClass.fastGetConstantAt(internedName);
}
/** Returns a class from the instance pool.
*
* @param name The name of the class.
* @return The class.
*/
public RubyClass getClass(String name) {
return objectClass.getClass(name);
}
/**
*
* @param internedName the name of the class; <em>must</em> be an interned String!
* @return
*/
public RubyClass fastGetClass(String internedName) {
return objectClass.fastGetClass(internedName);
}
/** rb_define_class
*
*/
public RubyClass defineClass(String name, RubyClass superClass, ObjectAllocator allocator) {
IRubyObject classObj = objectClass.getConstantAt(name);
if (classObj != null) {
if (!(classObj instanceof RubyClass)) throw newTypeError(name + " is not a class");
RubyClass klazz = (RubyClass)classObj;
if (klazz.getSuperClass().getRealClass() != superClass) throw newNameError(name + " is already defined", name);
return klazz;
}
if (superClass == null) {
warnings.warn("no super class for `" + name + "', Object assumed");
superClass = objectClass;
}
return RubyClass.newClass(this, superClass, name, allocator, objectClass, false);