Permalink
Browse files

Inching closer to booting otp. Now at least we get into the driver. N…

…ext step: implement file_read.

erjang.NotImplemented: file_output cmd:15 <<"/sw/lib/erlang/bin//releases/R13B02/start_clean.boot">>
{"init terminating in do_boot",{'cannot get bootfile','/releases/R13B02/start_clean.boot'}}
init terminating in do_boot ()
  • Loading branch information...
1 parent 04370ee commit 2fa973468836536880c046e11edf4ca0f7b294a3 @krestenkrab krestenkrab committed Dec 10, 2009
View
Binary file not shown.
View
Binary file not shown.
@@ -25,7 +25,7 @@
public final EBitString bin;
int bit_pos;
- public int bitsLeft() {
+ public long bitsLeft() {
return bin.bitCount() - bit_pos;
}
@@ -90,18 +90,18 @@ public EInteger bs_get_integer2(int size, int flags) {
}
public EBitString bs_match_string(int bits, EBitString ebs) {
- int size = ebs.bitCount();
+ long size = ebs.bitCount();
// do we have bits enough in the input
if (size > bitsLeft()) {
return null;
}
- int limit = size;
+ long limit = size;
for (int pos = 0; pos < limit; pos += 8) {
- int rest = Math.min(8, limit - pos);
+ int rest = (int) Math.min(8, limit - pos);
int oc1 = 0xff & bin.intBitsAt(pos, rest);
int oc2 = 0xff & ebs.intBitsAt(pos, rest);
@@ -21,6 +21,7 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
+import java.nio.ByteBuffer;
import java.util.zip.Adler32;
import java.util.zip.CRC32;
@@ -30,6 +31,8 @@
public class EBinary extends EBitString {
+ public static final EBinary EMPTY = new EBinary(new byte[0]);
+
public EBinary(byte[] data, int byteOff, int byteLength) {
super(data, byteOff * 8, byteLength * 8);
}
@@ -46,7 +49,7 @@ public EBinary(byte[] bytes) {
@Override
public Type emit_const(MethodVisitor fa) {
- char[] chs = new char[bits / 8];
+ char[] chs = new char[(int) (bits / 8)];
for (int i = 0; i < bits / 8; i++) {
chs[i] = (char) (0xff & octetAt(i));
}
@@ -75,10 +78,11 @@ public EBinary testBinary() {
}
public void updateAdler32(Adler32 a) {
- a.update(data, bitOff / 8, bits / 8);
+ a.update(data, bitOff / 8, (int) (bits / 8));
}
static final int MOD_ADLER = 65521;
+
long adler32() {
return adler32(1);
}
@@ -108,7 +112,7 @@ static long adler32(long adler, int byte_value) {
* @return
*/
public byte[] getByteArray() {
- int octets = bitCount() / 8;
+ int octets = (int) (bitCount() / 8);
byte[] res = new byte[octets];
if ((bitOff % 8) == 0) {
System.arraycopy(data, bitOff / 8, res, 0, octets);
@@ -123,7 +127,7 @@ static long adler32(long adler, int byte_value) {
public long crc() {
CRC32 crc = new CRC32();
- int octets = bitCount() / 8;
+ int octets = (int) (bitCount() / 8);
if ((bitOff % 8) == 0) {
crc.update(data, bitOff / 8, octets);
} else {
@@ -138,7 +142,7 @@ public long crc() {
* @return
*/
public int byteSize() {
- return bitCount() / 8;
+ return (int) (bitCount() / 8);
}
/**
@@ -147,10 +151,33 @@ public int byteSize() {
*/
public void appendTo(OutputStream barr) {
try {
- barr.write(data, bitOff/8, bits/8);
+ barr.write(data, bitOff/8, byteSize());
} catch (IOException e) {
throw new Error(e);
}
}
+ /**
+ * @param barr
+ * @throws IOException
+ */
+ public void writeTo(ByteArrayOutputStream o) {
+ int octets = byteSize();
+ if ((bitOff % 8) == 0) {
+ o.write(data, bitOff / 8, octets);
+ } else {
+ for (int i = 0; i < octets; i++) {
+ o.write( octetAt(i) );
+ }
+ }
+ }
+
+ /**
+ * @param data
+ * @return
+ */
+ public static EBinary make(ByteBuffer data) {
+ return new EBinary(data.array(), data.arrayOffset()+data.position(), data.remaining());
+ }
+
}
@@ -35,7 +35,7 @@
.getInternalName();
protected final byte[] data;
- protected final int bits;
+ protected final long bits;
protected final int bitOff;
public EBitString(byte[] data) {
@@ -60,11 +60,11 @@ int cmp_order() {
@Override
public Type emit_const(MethodVisitor fa) {
- char[] chs = new char[bits / 8 + 1];
+ char[] chs = new char[(int) (bits / 8 + 1)];
for (int pos = 0; pos < bits; pos += 8) {
- int rest = Math.min(8, bits - pos);
+ int rest = (int) (bits-pos > 8 ? 8 : bits-pos);
int oc = 0xff & intBitsAt(pos, rest);
@@ -78,7 +78,7 @@ public Type emit_const(MethodVisitor fa) {
String str = new String(chs);
fa.visitLdcInsn(str);
- fa.visitLdcInsn(new Integer(bits % 8));
+ fa.visitLdcInsn(new Integer((int) (bits % 8)));
fa.visitMethodInsn(Opcodes.INVOKESTATIC, EBITSTRING_NAME, "fromString",
"(Ljava/lang/String;I)L" + EBITSTRING_NAME + ";");
@@ -104,13 +104,13 @@ public boolean equalsExactly(EObject rhs) {
if (bitCount() != ebs.bitCount())
return false;
- int bc1 = bitCount();
- int bc2 = ebs.bitCount();
- int limit = Math.min(bc1, bc2);
+ long bc1 = bitCount();
+ long bc2 = ebs.bitCount();
+ long limit = Math.min(bc1, bc2);
for (int pos = 0; pos < limit; pos += 8) {
- int rest = Math.min(8, limit - pos);
+ int rest = (int) (limit-pos>8 ? 8 : limit-pos);
int oc1 = 0xff & intBitsAt(pos, rest);
int oc2 = 0xff & ebs.intBitsAt(pos, rest);
@@ -126,13 +126,13 @@ public boolean equalsExactly(EObject rhs) {
int compare_same(EObject rhs) {
EBitString ebs = (EBitString) rhs;
- int bc1 = bitCount();
- int bc2 = ebs.bitCount();
- int limit = Math.min(bc1, bc2);
+ long bc1 = bitCount();
+ long bc2 = ebs.bitCount();
+ long limit = Math.min(bc1, bc2);
for (int pos = 0; pos < limit; pos += 8) {
- int rest = Math.min(8, limit - pos);
+ int rest = limit-pos>8 ? 8 : (int)(limit-pos);
int oc1 = 0xff & intBitsAt(pos, rest);
int oc2 = 0xff & ebs.intBitsAt(pos, rest);
@@ -155,7 +155,7 @@ int compare_same(EObject rhs) {
return 1;
}
- public EBitString(byte[] data, int offset, int bits) {
+ public EBitString(byte[] data, int offset, long bits) {
this.data = data;
this.bitOff = offset;
this.bits = bits;
@@ -173,22 +173,22 @@ public int octetAt(int idx) {
return intBitsAt(idx * 8, 8);
}
- public int bitCount() {
+ public long bitCount() {
return bits;
}
public EBitString substring(int bitOff) {
if (bitOff < 0 || bitOff > bitCount()) {
throw new IllegalArgumentException("offset out of range");
}
- return new EBitString(data, bitOff + bitOff, bitCount() - bitOff);
+ return new EBitString(data, this.bitOff + bitOff, bitCount() - bitOff);
}
- public EBitString substring(int bitOff, int len) {
+ public EBitString substring(int bitOff, long len) {
if (bitOff < 0 || bitOff + len > bitCount()) {
throw new IllegalArgumentException("offset out of range");
}
- return new EBitString(data, bitOff + bitOff, len);
+ return new EBitString(data, this.bitOff + bitOff, len);
}
public int bitAt(int bitPos) {
@@ -205,7 +205,7 @@ public int bitAt(int bitPos) {
public int intBitsAt(int bitPos, int bitLength) {
- if (bitOff + bitPos + bitLength > this.bits) {
+ if (bitPos + bitLength > this.bits) {
throw new IllegalArgumentException(
"reading beyond end of BitString");
}
@@ -379,7 +379,7 @@ public String toString() {
sb.append(',');
}
- int lastBitLength = bits - i;
+ int lastBitLength = (int) (bits - i);
sb.append(0xff & intBitsAt(i, lastBitLength));
if (lastBitLength != 8) {
sb.append(':').append(lastBitLength);
@@ -395,7 +395,7 @@ public String toString() {
if (!isBinary())
throw ERT.badarg();
- byte[] result = new byte[bits / 8];
+ byte[] result = new byte[(int) (bits / 8)];
for (int i = 0; i < result.length; i++) {
result[i] = this.byteAt(i * 8);
}
@@ -412,7 +412,7 @@ public boolean collectIOList(List<ByteBuffer> out) {
if (bits != 0) {
if ((bitOff % 8) == 0) {
- out.add(ByteBuffer.wrap(data, bitOff / 8, bits / 8));
+ out.add(ByteBuffer.wrap(data, bitOff / 8, (int) (bits / 8)));
} else {
out.add(ByteBuffer.wrap(toByteArray()));
}
@@ -22,8 +22,6 @@
import java.nio.ByteBuffer;
import java.util.List;
-import erjang.m.erlang.ErlBif;
-
public abstract class ECons extends EObject {
@Override
@@ -26,7 +26,7 @@
*/
public abstract class EHandle extends EObject {
- protected EAtom name;
+ protected EObject name = null;
public EHandle testHandle() { return this; }
@@ -41,7 +41,7 @@ public ELocalHandle testLocalHandle() {
* @see erjang.EHandle#self()
*/
@Override
- ETask<?> task() {
+ EProc task() {
return task;
}
@@ -97,4 +97,22 @@ public int internal_pid_number() {
public String toString() {
return "PID<" + (name==null?"":name) + ":" + task().id + ">";
}
+
+ /* (non-Javadoc)
+ * @see erjang.EPID#process_info()
+ */
+ @Override
+ public EObject process_info() {
+ return task.process_info();
+ }
+
+ /* (non-Javadoc)
+ * @see erjang.EPID#process_info(erjang.EObject)
+ */
+ @Override
+ public EObject process_info(EObject spec) {
+ return task.process_info(spec);
+ }
+
+
}
@@ -62,6 +62,14 @@ public ESeq tail() {
@Override
public String toString() {
+
+ try {
+ EString str = EString.make(this);
+ return str.toString();
+ } catch (ErlangException e) {
+ // ignor e//
+ }
+
StringBuffer sb = new StringBuffer("[");
assert (this instanceof EList);
@@ -99,5 +107,17 @@ public Type emit_const(MethodVisitor fa) {
return type;
}
+ /**
+ * @param messages
+ * @return
+ */
+ public static ESeq make(Object... messages) {
+ ESeq result = ERT.NIL;
+ for (int i = messages.length-1; i >= 0; i--) {
+ result = result.cons((EObject)messages[i]);
+ }
+ return result;
+ }
+
}
@@ -87,11 +87,25 @@ public EObject invoke(EProc proc, EObject[] args)
throws Pausable
{
EFun found = null;
- try {
- ERT.load(fun.module);
- found = EModule.resolve(fun);
- } catch (Throwable ex) {
- System.out.println("unable to load module for "+fun);
+ boolean has_loaded_module =
+ EModule.get_module_info(fun.module).module != null;
+
+ if (!has_loaded_module) {
+ try {
+ ERT.load(fun.module);
+ has_loaded_module = true;
+ } catch (Throwable ex) {
+ System.out.println("unable to load module for "+fun);
+ }
+ }
+
+ if (has_loaded_module)
+ {
+ try {
+ found = EModule.resolve(fun);
+ } catch (Throwable ex) {
+ System.out.println("unable to resolve function "+fun);
+ }
}
if (found == null) {
@@ -31,7 +31,12 @@
public ECons cons(EObject h)
{
- return new EPair(h, this);
+ ESmall sm;
+ if ((sm=h.testSmall()) != null && ((sm.value&0xff)==sm.value)) {
+ return new EBinList((byte) sm.value, this);
+ } else {
+ return new EPair(h, this);
+ }
}
public ERef testReference() {
Oops, something went wrong.

0 comments on commit 2fa9734

Please sign in to comment.