Skip to content

Commit

Permalink
Merge branch 'master' into truffle-head
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Dec 24, 2014
2 parents 03a8a55 + ecee892 commit f3e944c
Show file tree
Hide file tree
Showing 29 changed files with 553 additions and 181 deletions.
2 changes: 1 addition & 1 deletion core/pom.rb
Expand Up @@ -53,7 +53,7 @@
jar 'org.jruby.joni:joni:2.1.5'
jar 'org.jruby.extras:bytelist:1.0.12'
jar 'org.jruby.jcodings:jcodings:1.0.12'
jar 'org.jruby:dirgra:0.1'
jar 'org.jruby:dirgra:0.2'

jar 'com.headius:invokebinder:1.5'
jar 'com.headius:options:1.1'
Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Expand Up @@ -147,7 +147,7 @@
<dependency>
<groupId>org.jruby</groupId>
<artifactId>dirgra</artifactId>
<version>0.1</version>
<version>0.2</version>
</dependency>
<dependency>
<groupId>com.headius</groupId>
Expand Down
16 changes: 6 additions & 10 deletions core/src/main/java/org/jruby/RubyProcess.java
Expand Up @@ -113,7 +113,7 @@ public static RubyModule createProcessModule(Ruby runtime) {
public static final String CLOCK_UNIT_FLOAT_MILLISECOND = "float_millisecond";
public static final String CLOCK_UNIT_FLOAT_SECOND = "float_second";
public static final String CLOCK_UNIT_HERTZ = "hertz";

@JRubyClass(name="Process::Status")
public static class RubyStatus extends RubyObject {
private final long status;
Expand Down Expand Up @@ -573,16 +573,12 @@ public static IRubyObject exit_bang(IRubyObject recv, IRubyObject[] args) {

@JRubyMethod(name = "groups", module = true, visibility = PRIVATE)
public static IRubyObject groups(IRubyObject recv) {
if(Platform.IS_WINDOWS) {
throw recv.getRuntime().newNotImplementedError("groups() function is unimplemented on this machine");
} else {
long[] groups = (new com.sun.security.auth.module.UnixSystem()).getGroups();
RubyArray ary = RubyArray.newArray(recv.getRuntime(), groups.length);
for(int i = 0; i < groups.length; i++) {
ary.push(RubyFixnum.newFixnum(recv.getRuntime(), groups[i]));
}
return ary;
long[] groups = Platform.getPlatform().getGroups(recv);
RubyArray ary = RubyArray.newArray(recv.getRuntime(), groups.length);
for(int i = 0; i < groups.length; i++) {
ary.push(RubyFixnum.newFixnum(recv.getRuntime(), groups[i]));
}
return ary;
}

@JRubyMethod(name = "setrlimit", rest = true, module = true, visibility = PRIVATE)
Expand Down
85 changes: 0 additions & 85 deletions core/src/main/java/org/jruby/RubyRegexp.java
Expand Up @@ -1965,91 +1965,6 @@ public static IRubyObject match_last(IRubyObject match) {
return nth_match(i, match);
}

static RubyString regsub(RubyString str, RubyString src, Matcher matcher, Encoding enc) {
Region regs = matcher.getRegion();

int no = -1;
ByteList bs = str.getByteList();
int p = bs.getBegin();
int s = p;
int end = p + bs.getRealSize();
byte[]bytes = bs.getUnsafeBytes();

ByteList srcbs = src.getByteList();

ByteList val = null;

while (s < end) {
int ss = s;
int c = bytes[s] & 0xff;
int l = enc.length(bytes, s++, end);
if (l != 1) {
s += l - 1;
continue;
}
if (c != '\\' || s == end) continue;
if (val == null) val = new ByteList(ss - p);

val.append(bytes, p, ss - p);
c = bytes[s++] & 0xff;
p = s;

switch (c) {
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
no = c - '0';
break;
case '&':
no = 0;
break;
case '`':
val.append( srcbs.getUnsafeBytes(), srcbs.getBegin(), matcher.getBegin());
continue;
case '\'':
val.append(srcbs.getUnsafeBytes(), srcbs.getBegin() + matcher.getEnd(), srcbs.getRealSize() - matcher.getEnd());
continue;
case '+':
if (regs == null) {
if (matcher.getBegin() == -1) {
no = 0;
continue;
}
} else {
no = regs.numRegs - 1;
while (regs.beg[no] == -1 && no > 0) no--;
if (no == 0) continue;
}
break;
case '\\':
val.append(bytes, s - 1, 1);
continue;
default:
val.append(bytes, s - 2, 2);
continue;
}

if (regs != null) {
if (no >= 0) {
if (no >= regs.numRegs || regs.beg[no] == -1) continue;
val.append(srcbs.getUnsafeBytes(), srcbs.getBegin() + regs.beg[no], regs.end[no] - regs.beg[no]);
}
} else {
if (no != 0 || matcher.getBegin() == -1) continue;
val.append(srcbs.getUnsafeBytes(), srcbs.getBegin() + matcher.getBegin(), matcher.getEnd() - matcher.getBegin());
}
}

if (p < end) {
if (val == null) {
return RubyString.newString(str.getRuntime(), bs.makeShared(p - bs.getBegin(), end - p));
} else {
val.append(bytes, p, end - p);
}
}
if (val == null) return str;
return RubyString.newString(str.getRuntime(), val);
}

// MRI: ASCGET macro from rb_reg_regsub
private static final int ASCGET(boolean acompat, byte[] sBytes, int s, int e, int[] cl, Encoding strEnc) {
if (acompat) {
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ir/operands/Array.java
Expand Up @@ -20,7 +20,7 @@ public class Array extends Operand {

// SSS FIXME: Do we create a special-case for zero-length arrays?
public Array() {
this(new Operand[0]);
this(EMPTY_ARRAY);
}

public Array(List<Operand> elts) {
Expand All @@ -30,7 +30,7 @@ public Array(List<Operand> elts) {
public Array(Operand[] elts) {
super(OperandType.ARRAY);

this.elts = elts == null ? new Operand[0] : elts;
this.elts = elts == null ? EMPTY_ARRAY : elts;
}

public boolean isBlank() {
Expand Down
7 changes: 3 additions & 4 deletions core/src/main/java/org/jruby/ir/operands/AsString.java
Expand Up @@ -16,19 +16,18 @@ public class AsString extends Operand {
public AsString(Operand source) {
super(OperandType.AS_STRING);

if (source == null) source = new StringLiteral("");
this.source = source;
this.source = source == null ? StringLiteral.EMPTY_STRING : source;
}

@Override
public Object retrieve(ThreadContext context, IRubyObject self, StaticScope currScope, DynamicScope currDynScope, Object[] temp) {
return ((IRubyObject)source.retrieve(context, self, currScope, currDynScope, temp)).asString();
return ((IRubyObject) source.retrieve(context, self, currScope, currDynScope, temp)).asString();
}

@Override
public Operand getSimplifiedOperand(Map<Operand, Operand> valueMap, boolean force) {
Operand newSource = source.getSimplifiedOperand(valueMap, force);
return (newSource == source) ? this : new AsString(newSource);
return newSource == source ? this : new AsString(newSource);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ir/operands/Complex.java
Expand Up @@ -9,7 +9,7 @@
* Represents a Complex literal.
*/
public class Complex extends ImmutableLiteral {
private ImmutableLiteral number;
private final ImmutableLiteral number;

public Complex(ImmutableLiteral number) {
super(OperandType.COMPLEX);
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/java/org/jruby/ir/operands/DynamicSymbol.java
Expand Up @@ -35,7 +35,9 @@ public void addUsedVariables(List<Variable> l) {
}

public Operand cloneForInlining(CloneInfo ii) {
return new DynamicSymbol(symbolName.cloneForInlining(ii));
Operand clonedSymbolName = symbolName.cloneForInlining(ii);

return clonedSymbolName == symbolName ? this : new DynamicSymbol(clonedSymbolName);
}

@Override
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/org/jruby/ir/operands/StringLiteral.java
Expand Up @@ -22,6 +22,8 @@
* This is not like a Java string.
*/
public class StringLiteral extends Operand {
public static final StringLiteral EMPTY_STRING = new StringLiteral("");

// SSS FIXME: Pick one of bytelist or string, or add internal conversion methods to convert to the default representation

final public ByteList bytelist;
Expand Down
18 changes: 2 additions & 16 deletions core/src/main/java/org/jruby/ir/representations/BasicBlock.java
Expand Up @@ -21,7 +21,6 @@ public class BasicBlock implements ExplicitVertexID, Comparable {
private Label label; // All basic blocks have a starting label
private List<Instr> instrs; // List of non-label instructions
private boolean isRescueEntry; // Is this basic block entry of a rescue?
private Instr[] instrsArray;

public BasicBlock(CFG cfg, Label label) {
this.label = label;
Expand All @@ -30,21 +29,19 @@ public BasicBlock(CFG cfg, Label label) {
isRescueEntry = false;

assert label != null : "label is null";
assert cfg != null : "cfg is null";

initInstrs();
}

private void initInstrs() {
instrs = new ArrayList<Instr>();
instrs = new ArrayList<>();
if (RubyInstanceConfig.IR_COMPILER_DEBUG || RubyInstanceConfig.IR_VISUALIZER) {
IRManager irManager = cfg.getScope().getManager();
InstructionsListener listener = irManager.getInstructionsListener();
if (listener != null) {
instrs = new InstructionsListenerDecorator(instrs, listener);
}
}
instrsArray = null;
}

@Override
Expand Down Expand Up @@ -79,7 +76,6 @@ public boolean isRescueEntry() {

public void replaceInstrs(List<Instr> instrs) {
this.instrs = instrs;
this.instrsArray = null;
}

public void addInstr(Instr i) {
Expand All @@ -94,23 +90,13 @@ public List<Instr> getInstrs() {
return instrs;
}

public int instrCount() {
return instrs.size();
}

public Instr[] getInstrsArray() {
if (instrsArray == null) instrsArray = instrs.toArray(new Instr[instrs.size()]);

return instrsArray;
}

public Instr getLastInstr() {
int n = instrs.size();
return (n == 0) ? null : instrs.get(n-1);
}

public boolean removeInstr(Instr i) {
return i == null? false : instrs.remove(i);
return i != null && instrs.remove(i);
}

public boolean isEmpty() {
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/java/org/jruby/ir/runtime/IRRuntimeHelpers.java
Expand Up @@ -28,6 +28,7 @@
import org.jruby.parser.StaticScope;
import org.jruby.runtime.*;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.callsite.FunctionalCachingCallSite;
import org.jruby.util.ByteList;
import org.jruby.util.DefinedMessage;
import org.jruby.util.RegexpOptions;
Expand Down Expand Up @@ -1292,4 +1293,9 @@ public static RaiseException newRequiredKeywordArgumentError(ThreadContext conte
public static void pushExitBlock(ThreadContext context, Block blk) {
context.runtime.pushExitBlock(context.runtime.newProc(Block.Type.LAMBDA, blk));
}

@JIT
public static FunctionalCachingCallSite newFunctionalCachingCallSite(String name) {
return new FunctionalCachingCallSite(name);
}
}
18 changes: 18 additions & 0 deletions core/src/main/java/org/jruby/ir/targets/IRBytecodeAdapter.java
Expand Up @@ -275,6 +275,24 @@ public org.objectweb.asm.Label newLabel() {
*/
public abstract void invokeOther(String name, int arity, boolean hasClosure);

/**
* Invoke a fixnum-receiving method on an object other than self.
*
* Stack required: context, self, receiver (fixnum will be handled separately)
*
* @param name name of the method to invoke
*/
public abstract void invokeOtherOneFixnum(String name, long fixnum);

/**
* Invoke a float-receiving method on an object other than self.
*
* Stack required: context, self, receiver (float will be handled separately)
*
* @param name name of the method to invoke
*/
public abstract void invokeOtherOneFloat(String name, double flote);


/**
* Invoke a method on self.
Expand Down

0 comments on commit f3e944c

Please sign in to comment.