[xruby commit] r2327 - trunk/src/com/xruby/runtime/builtin

1 view
Skip to first unread message

codesite...@google.com

unread,
Jul 1, 2008, 10:32:58 PM7/1/08
to xruby-...@googlegroups.com
Author: xue.yong.zhi
Date: Tue Jul 1 19:32:45 2008
New Revision: 2327

Modified:
trunk/src/com/xruby/runtime/builtin/RubyKernelModule.java

Log:
display filename of eval() for easier debugging


Modified: trunk/src/com/xruby/runtime/builtin/RubyKernelModule.java
==============================================================================
--- trunk/src/com/xruby/runtime/builtin/RubyKernelModule.java (original)
+++ trunk/src/com/xruby/runtime/builtin/RubyKernelModule.java Tue Jul
1 19:32:45 2008
@@ -29,7 +29,7 @@
public static RubyValue opEqual(RubyValue receiver, RubyValue arg) {
return ObjectFactory.createBoolean(receiver == arg);
}
-
+
@RubyLevelMethod(name="===")
public static RubyValue objEqual(RubyValue receiver, RubyValue arg) {
if (receiver == arg) {
@@ -39,30 +39,30 @@
return ObjectFactory.createBoolean(result);
}
}
-
+
@RubyLevelMethod(name="class")
public static RubyValue objRubyClass(RubyValue receiver) {
RubyClass klass = receiver.getRubyClass();
return klass != null ? klass.getRealClass() : RubyConstant.QNIL;
}
-
+
// FIXME: Kernel_clone should be revised.
@RubyLevelMethod(name="clone", alias="dup")
public static RubyValue objClone(RubyValue receiver) {
return (RubyValue) receiver.clone();
}
-
+
@RubyLevelMethod(name="to_s")
public static RubyValue anyObjToS(RubyValue receiver) {
String className = receiver.getRubyClass().getName();
return ObjectFactory.createString("#<" + className + ":0x" +
Integer.toHexString(receiver.hashCode()) + "x>");
}
-
+
@RubyLevelMethod(name="inspect")
public static RubyValue objInsepct(RubyValue receiver) {
return ObjectFactory.createString(receiver.inspect());
}
-
+
@RubyLevelMethod(name="methods")
public static RubyValue objMethods(RubyValue receiver) {
RubyArray a = new RubyArray();
@@ -70,17 +70,17 @@
klass.collectClassMethodNames(a, RubyMethod.ALL);
return a;
}
-
+
@RubyLevelMethod(name="singleton_methods")
public static RubyValue objSingletonMethods(RubyValue receiver) {
return objSingletonMethod(receiver, true);
}
-
- @RubyLevelMethod(name="singleton_methods")
+
+ @RubyLevelMethod(name="singleton_methods")
public static RubyValue objSingletonMethods(RubyValue receiver,
RubyValue arg) {
return objSingletonMethod(receiver, arg.isTrue());
}
-
+
private static RubyValue objSingletonMethod(RubyValue receiver,
boolean all) {
RubyArray a = new RubyArray();
if(receiver.getRubyClass().isSingleton()) {
@@ -97,7 +97,7 @@
}
return a;
}
-
+
// FIXME:This method should be module.
@RubyLevelMethod(name="raise", alias="fail")
public static RubyValue raise(RubyValue value, RubyArray args) {
@@ -129,14 +129,14 @@

throw new RubyException(e);
}
-
+
@RubyLevelMethod(name="exit", module=true)
public static RubyValue exit(RubyValue receiver) {
// TODO should raise SystemExit exception and call at_exit blocks
System.exit(0);
return RubyConstant.QNIL;
}
-
+
@RubyLevelMethod(name="exit", module=true)
public static RubyValue exit(RubyValue receiver, RubyValue arg) {
// TODO should raise SystemExit exception and call at_exit blocks
@@ -151,7 +151,7 @@
System.exit(status);
return RubyConstant.QNIL;
}
-
+
@RubyLevelMethod(name="loop", module=true)
public static RubyValue loop(RubyValue receiver, RubyArray args,
RubyBlock block) {
if (null == block) {
@@ -165,29 +165,29 @@
}
}
}
-
+
@RubyLevelMethod(name="kind_of?", alias="is_a?")
public static RubyValue kindOf(RubyValue receiver, RubyValue arg) {
return ObjectFactory.createBoolean(RubyAPI.isKindOf(arg, receiver));
}
-
+
@RubyLevelMethod(name="instance_of?")
public static RubyValue instanceOf(RubyValue receiver, RubyValue arg) {
return
ObjectFactory.createBoolean(receiver.getRubyClass().getRealClass() == arg);
}
-
+
@RubyLevelMethod(name="respond_to?")
public static RubyValue respond_to(RubyValue receiver, RubyArray
args) {
if (null == args || args.size() < 1) {
int actual_argc = (null == args ) ? 0 : args.size();
throw new
RubyException(RubyRuntime.ArgumentErrorClass, "in `respond_to': wrong
number of arguments (" + actual_argc + " for 1)");
}
-
+
boolean include_private = (RubyConstant.QTRUE == args.get(1));
RubyID mid = RubyID.intern(args.get(0).toStr());
return ObjectFactory.createBoolean(hasMethod(receiver, mid, include_private));
}
-
+
private static boolean hasMethod(RubyValue receiver, RubyID mid,
boolean include_private) {
if (include_private) {
return (null != receiver.findMethod(mid));
@@ -195,31 +195,31 @@
return (null != receiver.findPublicMethod(mid));
}
}
-
+
@RubyLevelMethod(name="send", alias="__send__")
public static RubyValue send(RubyValue receiver, RubyBlock block) {
throw new RubyException(RubyRuntime.ArgumentErrorClass, "no method
name given");
}
-
+
@RubyLevelMethod(name="send", alias="__send__")
public static RubyValue send(RubyValue receiver, RubyValue value,
RubyBlock block) {
RubyID mid = RubyID.intern(value.toStr());
return RubyAPI.callNoArgMethod(receiver, block, mid);
}
-
+
@RubyLevelMethod(name="send", alias="__send__")
public static RubyValue send(RubyValue receiver, RubyValue arg0,
RubyValue arg1, RubyBlock block) {
RubyID mid = RubyID.intern(arg0.toStr());
return RubyAPI.callOneArgMethod(receiver, arg1, block, mid);
}
-
+
@RubyLevelMethod(name="send", alias="__send__")
public static RubyValue send(RubyValue receiver, RubyArray args,
RubyBlock block) {
RubyValue method_name = args.delete_at(0);
RubyID mid = RubyID.intern(method_name.toStr());
return RubyAPI.callMethod(receiver, args, block, mid);
}
-
+
@RubyLevelMethod(name="instance_eval")
public static RubyValue instanceEval(RubyValue receiver, RubyArray
args, RubyBlock block) {
if (null == args && null == block) {
@@ -238,7 +238,7 @@
return block.invoke(receiver);
}
}
-
+
private static RubyValue eval(String evalText) {
RubyCompiler compiler = new RubyCompiler();
try {
@@ -255,7 +255,7 @@
throw new RubyException(e.toString());
}
}
-
+
public static RubyValue eval(String evalText, RubyBinding binding) {
RubyCompiler compiler = new RubyCompiler();
try {
@@ -284,21 +284,21 @@
return p.invoke();
}
} catch (RecognitionException e) {
- throw new RubyException(RubyRuntime.SyntaxErrorClass, e.toString());
+ throw new RubyException(RubyRuntime.SyntaxErrorClass,
file_name + " " + e.toString());
} catch (TokenStreamException e) {
- throw new RubyException(RubyRuntime.SyntaxErrorClass, e.toString());
+ throw new RubyException(RubyRuntime.SyntaxErrorClass,
file_name + " " + e.toString());
} catch (InstantiationException e) {
throw new RubyException(e.toString());
} catch (IllegalAccessException e) {
throw new RubyException(e.toString());
}
}
-
+
@RubyLevelMethod(name="eval", module=true)
public static RubyValue eval(RubyValue receiver, RubyValue arg) {
return eval(arg.toStr());
}
-
+
@RubyLevelMethod(name="eval", module=true)
public static RubyValue eval(RubyValue receiver, RubyValue arg0,
RubyValue arg1) {
if (arg1 instanceof RubyBinding) {
@@ -322,7 +322,7 @@

return eval(args.get(0).toStr(), binding, file_name);
}
-
+
@RubyLevelMethod(name="method")
public static RubyValue objMethod(RubyValue receiver, RubyValue arg) {
String method_name = arg.toStr();
@@ -333,7 +333,7 @@
}
return ObjectFactory.createMethod(receiver, method_name, m);
}
-
+
@RubyLevelMethod(name="public_methods")
public static RubyValue publicMethods(RubyValue receiver) {
RubyArray a = new RubyArray();
@@ -341,22 +341,22 @@
klass.collectClassMethodNames(a, RubyMethod.PUBLIC);
return a;
}
-
+
@RubyLevelMethod(name="caller", module=true)
public static RubyValue call(RubyValue receiver) {
return new RubyArray();//FIXME use a try/catch to get stacktrace
}
-
+
@RubyLevelMethod(name="caller", module=true)
public static RubyValue call(RubyValue receiver, RubyValue arg) {
return new RubyArray();//FIXME use a try/catch to get stacktrace
}
-
+
@RubyLevelMethod(name="throw", module=true)
public static RubyValue throwMethod(RubyValue receiver) {
throw new RubyException(RubyRuntime.ArgumentErrorClass, "in
`throw': wrong number of arguments (0 for 1)");
}
-
+
@RubyLevelMethod(name="throw", module=true)
public static RubyValue throwMethod(RubyValue receiver, RubyArray
args) {
RubyExceptionValue e;
@@ -374,7 +374,7 @@
}
throw new RubyException(e);
}
-
+
@RubyLevelMethod(name="catch", module=true)
public static RubyValue catchMethod(RubyValue receiver, RubyValue
arg, RubyBlock block) {
if (!(arg instanceof RubySymbol)) {
@@ -396,7 +396,7 @@

return RubyConstant.QNIL;
}
-
+
@RubyLevelMethod(name="untrace_var", module=true)
public static RubyValue untrace_var(RubyValue receiver, RubyArray
args, RubyBlock block) {
if (null == args || args.size() < 1) {
@@ -419,7 +419,7 @@

return RubyConstant.QNIL;
}
-
+
@RubyLevelMethod(name="trace_var", module=true)
public static RubyValue trace_var(RubyValue receiver, RubyArray args,
RubyBlock block) {
if (null == args || args.size() < 1) {
@@ -444,54 +444,54 @@

return RubyConstant.QNIL;
}
-
+
@RubyLevelMethod(name="block_given?", alias="iterator?", module=true)
public static RubyValue blockGivenP(RubyValue receiver, RubyBlock
block) {
return ObjectFactory.createBoolean(null != block);
}
-
+
@RubyLevelMethod(name="Float", module=true)
public static RubyFloat toFloat(RubyValue receiver, RubyValue arg) {
- return arg.toRubyFloat();
+ return arg.toRubyFloat();
}
-
+
@RubyLevelMethod(name="Integer", module=true)
public static RubyInteger toInteger(RubyValue receiver, RubyValue
arg) {
- return arg.toRubyInteger();
+ return arg.toRubyInteger();
}
-
+
@RubyLevelMethod(name="puts", module=true)
public static RubyValue puts(RubyValue receiver) {
return RubyIO.STDOUT.puts();
}
-
+
@RubyLevelMethod(name="puts", module=true)
public static RubyValue puts(RubyValue receiver, RubyArray args) {
return RubyIO.STDOUT.puts(args);
}
-
+
@RubyLevelMethod(name="print", module=true)
public static RubyValue print(RubyValue receiver) {
return RubyIO.STDOUT.print();
}
-
+
@RubyLevelMethod(name="print", module=true)
public static RubyValue print(RubyValue receiver, RubyValue arg) {
return RubyIO.STDOUT.print(arg);
}
-
+
@RubyLevelMethod(name="print", module=true)
public static RubyValue print(RubyValue receiver, RubyArray args) {
return RubyIO.STDOUT.print(args);
}
-
+
@RubyLevelMethod(name="printf", module=true)
public static RubyValue printf(RubyValue receiver, RubyArray args) {
String fmt = args.get(0).toStr();
System.out.printf(fmt, RubyKernelModule.buildFormatArg(args, 1));
return RubyConstant.QNIL;
}
-
+
@RubyLevelMethod(name="sprintf", module=true)
public static RubyValue sprintf(RubyValue receiver, RubyArray
args) {
String fmt = args.get(0).toStr();
@@ -502,12 +502,12 @@
ps.close();
return ObjectFactory.createString(baos.toString());
}
-
+
@RubyLevelMethod(name="p", module=true)
public static RubyValue p(RubyValue receiver) {
return RubyConstant.QNIL;
}
-
+
@RubyLevelMethod(name="p", module=true)
public static RubyValue p(RubyValue receiver, RubyValue arg) {
RubyValue str = RubyAPI.callNoArgMethod(arg, null, RubyID.inspectID);
@@ -516,7 +516,7 @@
System.out.print(value.toString());
return RubyConstant.QNIL;
}
-
+
@RubyLevelMethod(name="p", module=true)
public static RubyValue p(RubyValue receiver, RubyArray args) {
for (RubyValue arg : args) {
@@ -529,7 +529,7 @@
}

private static BufferedReader in_ = new BufferedReader(new InputStreamReader(System.in));
-
+
@RubyLevelMethod(name="gets", module=true)
public static RubyValue gets(RubyValue receiver) {
String s = null;
@@ -540,7 +540,7 @@
GlobalVariables.set((null == s ? RubyConstant.QNIL : ObjectFactory.createString(s)), "$_");
return GlobalVariables.get("$_");
}
-
+
@RubyLevelMethod(name="object_id", alias={"__id__", "hash"})
public static RubyValue objectId(RubyValue receiver) {
//Object.hashCode() javadoc:
@@ -548,18 +548,18 @@
//by class Object does return distinct integers for distinct objects.
return ObjectFactory.createFixnum(receiver.hashCode());
}
-
+
@RubyLevelMethod(name="extend")
public static RubyValue extend(RubyValue receiver) {
throw new RubyException(RubyRuntime.ArgumentErrorClass, "wrong
number of arguments (0 for 1)");
}
-
+
@RubyLevelMethod(name="extend")
public static RubyValue extend(RubyValue receiver, RubyValue arg) {
RubyAPI.callPublicOneArgMethod(arg, receiver, null, RubyID.extendObjectID);
return receiver;
}
-
+
@RubyLevelMethod(name="extend")
public static RubyValue extend(RubyValue receiver, RubyArray args) {
for (RubyValue v : args) {
@@ -568,7 +568,7 @@

return receiver;
}
-
+
@RubyLevelMethod(name="freeze")
public static RubyValue freeze(RubyValue receiver) {
receiver.freeze();
@@ -590,7 +590,7 @@
public static RubyValue tainted(RubyValue receiver) {
return ObjectFactory.createBoolean(receiver.tainted());
}
-
+
@RubyLevelMethod(name="method_missing", module=true)
public static RubyValue methodMissing(RubyValue receiver,
RubyArray args) {
RubySymbol method_name = (RubySymbol)args.get(0);
@@ -598,7 +598,7 @@
klass = (klass != null) ? klass.getRealClass() : null;
throw new
RubyException(RubyRuntime.NoMethodErrorClass, "undefined method '" +
method_name.toString() + "' for " + klass.getName());
}
-
+
@RubyLevelMethod(name="sleep", module=true)
public static RubyValue sleep(RubyValue receiver, RubyValue arg) {
long milliseconds = RubyTypesUtil.convertToJavaLong(arg)*1000;
@@ -609,7 +609,7 @@
long endTime = System.currentTimeMillis();
return ObjectFactory.createFixnum((int)Math.round((endTime-startTime)/1000.0));
}
-
+
private static Pattern packagePattern = Pattern.compile("\\.");

@RubyLevelMethod(name="require_java", alias="import", module=true)
@@ -631,7 +631,7 @@
RubyRuntime.setJavaSupported(true);
return RubyConstant.QTRUE;
}
-
+
@RubyLevelMethod(name="__load_with_reflection__", module=true)
public static RubyValue loadWithReflection(RubyValue receiver,
RubyValue arg, RubyBlock block) {
String required_file = arg.toStr();
@@ -646,7 +646,7 @@
if (a.include(arg) == RubyConstant.QFALSE) {
a.push(arg);
}
-
+
p.invoke();
return RubyConstant.QTRUE;
} catch (ClassNotFoundException e) {
@@ -657,19 +657,19 @@
return RubyConstant.QFALSE;
}
}
-
+
@RubyLevelMethod(name="binding", module=true)
public static RubyValue binding(RubyValue receiver, RubyArray
args) {
//compiler will do the magic and insert Binding object
return args.get(0);
}
-
+
@RubyLevelMethod(name="lambda", alias="proc", module=true)
public static RubyValue lambda(RubyValue receiver, RubyBlock
block) {
block.setCreatedByLambda();
return ObjectFactory.createProc(block);
}
-
+
@RubyLevelMethod(name="at_exit", module=true)
public static RubyValue atExit(RubyValue receiver, RubyBlock
block) {
if (null == block) {
@@ -679,7 +679,7 @@
AtExitBlocks.registerBlock(block);
return ObjectFactory.createProc(block);
}
-
+
@RubyLevelMethod(name="gsub", module=true)
public static RubyValue gsub(RubyValue receiver, RubyArray args,
RubyBlock block) {
if (!(GlobalVariables.get("$_") instanceof RubyString)) {
@@ -689,7 +689,7 @@
RubyValue r =
((RubyString)GlobalVariables.get("$_")).gsub_danger(args, block);
return GlobalVariables.set(r, "$_");
}
-
+
@RubyLevelMethod(name="gsub!", module=true)
public static RubyValue gsubBang(RubyValue receiver, RubyArray
args, RubyBlock block) {
if (!(GlobalVariables.get("$_") instanceof RubyString)) {
@@ -702,7 +702,7 @@
}
return r;
}
-
+
@RubyLevelMethod(name="sub", module=true)
public static RubyValue sub(RubyValue receiver, RubyArray args,
RubyBlock block) {
if (!(GlobalVariables.get("$_") instanceof RubyString)) {

Reply all
Reply to author
Forward
0 new messages