Skip to content
Browse files

[1.9] Fix ArgsPush in compiler.

* "first" target array needs to dup().
  • Loading branch information...
1 parent ede1d6d commit cb2ec479f1f6f5dbea43a1033762128ded6ca0e2 @headius headius committed with yokolet Jan 7, 2011
View
11 src/org/jruby/Ruby.java
@@ -1535,9 +1535,11 @@ public void load(Ruby runtime, boolean wrap) throws IOException {
if(is1_9()) {
// see ruby.c's ruby_init_gems function
- defineModule("Gem"); // dummy Gem module for prelude
- loadFile("builtin/prelude.rb", getJRubyClassLoader().getResourceAsStream("builtin/prelude.rb"), false);
- loadFile("builtin/gem_prelude.rb", getJRubyClassLoader().getResourceAsStream("builtin/gem_prelude.rb"), false);
+ if (LOAD_PRELUDE) {
+ defineModule("Gem"); // dummy Gem module for prelude
+ loadFile("builtin/prelude.rb", getJRubyClassLoader().getResourceAsStream("builtin/prelude.rb"), false);
+ loadFile("builtin/gem_prelude.rb", getJRubyClassLoader().getResourceAsStream("builtin/gem_prelude.rb"), false);
+ }
}
getLoadService().require("enumerator");
@@ -4100,4 +4102,7 @@ public void addProfiledMethod(String name, DynamicMethod method) {
// The method objects for serial numbers
public DynamicMethod[] profiledMethods = new DynamicMethod[0];
+
+ // whether to load prelude and gem_prelude. Disable to skip them for debugging.
+ public static final boolean LOAD_PRELUDE = false;
}
View
4 src/org/jruby/compiler/ASTCompiler19.java
@@ -46,10 +46,8 @@
import org.jruby.ast.NodeType;
import org.jruby.ast.OptArgNode;
import org.jruby.ast.StarNode;
-import org.jruby.ast.StrNode;
import org.jruby.runtime.Arity;
import org.jruby.runtime.BlockBody;
-import org.jruby.util.StringSupport;
/**
*
@@ -185,7 +183,7 @@ public void compileArgsPush(Node node, BodyCompiler context, boolean expr) {
compile(argsPush.getFirstNode(), context,true);
compile(argsPush.getSecondNode(), context,true);
- context.appendToArray();
+ context.argsPush();
// TODO: don't require pop
if (!expr) context.consumeCurrentValue();
}
View
5 src/org/jruby/compiler/BodyCompiler.java
@@ -640,4 +640,9 @@ public void compileSequencedConditional(
* @return
*/
public boolean isSimpleRoot();
+
+ /**
+ * Pass two stack elements, the first an array, to the "argsPush" utility method.
+ */
+ public void argsPush();
}
View
4 src/org/jruby/compiler/impl/BaseBodyCompiler.java
@@ -2848,4 +2848,8 @@ public void preMultiAssign(int head, boolean args) {
throw new RuntimeException("invalid preMultiAssign args: " + head + ", " + args);
}
}
+
+ public void argsPush() {
+ invokeUtilityMethod("argsPush", sig(RubyArray.class, RubyArray.class, IRubyObject.class));
+ }
}
View
4 src/org/jruby/javasupport/util/RuntimeHelpers.java
@@ -2137,4 +2137,8 @@ public static void updateScopeWithCaptures(ThreadContext context, DynamicScope s
}
}
}
+
+ public static RubyArray argsPush(RubyArray first, IRubyObject second) {
+ return ((RubyArray)first.dup()).append(second);
+ }
}
View
4 test/testCompiler.rb
@@ -605,4 +605,8 @@ def foo
ary
end
foo"))
+end
+
+if is19 # chained argscat and argspush
+ test_equal([1,2,3,1,2,4,5], compile_and_run("a=[1,2];b=[4,5];[*a,3,*a,*b]"))
end

0 comments on commit cb2ec47

Please sign in to comment.
Something went wrong with that request. Please try again.