Merge branch 'master' into powerpc

Conflicts:

	makefile
	src/assembler.h
	src/compile.cpp
	src/compiler.cpp
	src/compiler.h
	src/finder.cpp
This commit is contained in:
Joel Dice
2008-11-11 08:20:49 -07:00
parent 2304a656cf
commit c80eb51c17
47 changed files with 1508 additions and 282 deletions

View File

@ -24,6 +24,13 @@ public class ByteArrayOutputStream extends OutputStream {
this(0);
}
public void reset() {
chain = null;
length = 0;
buffer = null;
position = 0;
}
public int size() {
return length;
}

View File

@ -0,0 +1,72 @@
/* Copyright (c) 2008, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
package java.io;
public class RandomAccessFile {
private long peer;
private long length;
private long position = 0;
public RandomAccessFile(String name, String mode)
throws FileNotFoundException
{
if (! mode.equals("r")) throw new IllegalArgumentException();
long[] result = new long[2];
open(name, result);
peer = result[0];
length = result[1];
}
private static native void open(String name, long[] result)
throws FileNotFoundException;
public long length() throws IOException {
return length;
}
public long getFilePointer() throws IOException {
return position;
}
public void seek(long position) throws IOException {
if (position < 0 || position > length) throw new IOException();
this.position = position;
}
public void readFully(byte[] buffer, int offset, int length)
throws IOException
{
if (peer == 0) throw new IOException();
if (length == 0) return;
if (position + length > this.length) throw new EOFException();
if (offset < 0 || offset + length > buffer.length)
throw new ArrayIndexOutOfBoundsException();
copy(peer, position, buffer, offset, length);
}
private static native void copy(long peer, long position, byte[] buffer,
int offset, int length);
public void close() throws IOException {
if (peer != 0) {
close(peer);
peer = 0;
}
}
private static native void close(long peer);
}

View File

@ -219,6 +219,25 @@ public final class Class <T> {
}
}
public Constructor getDeclaredConstructor(Class ... parameterTypes)
throws NoSuchMethodException
{
Constructor c = null;
Constructor[] constructors = getDeclaredConstructors();
for (int i = 0; i < constructors.length; ++i) {
if (match(parameterTypes, constructors[i].getParameterTypes())) {
c = constructors[i];
}
}
if (c == null) {
throw new NoSuchMethodException();
} else {
return c;
}
}
private int countConstructors(boolean publicOnly) {
int count = 0;
if (methodTable != null) {

View File

@ -30,6 +30,10 @@ public final class Integer extends Number implements Comparable<Integer> {
return new Integer(value);
}
public static Integer valueOf(String value) {
return valueOf(parseInt(value));
}
public boolean equals(Object o) {
return o instanceof Integer && ((Integer) o).value == value;
}

View File

@ -75,6 +75,8 @@ public class Runtime {
public native long totalMemory();
public static native void dumpHeap(String outputFile);
private static class MyProcess extends Process {
private long pid;
private final int in;

View File

@ -74,7 +74,15 @@ public class StringBuffer implements CharSequence {
sb.append(b, 0, b.length);
return this;
}
public synchronized int indexOf(String s) {
return sb.indexOf(s);
}
public synchronized int indexOf(String s, int fromIndex) {
return sb.indexOf(s, fromIndex);
}
public synchronized StringBuffer insert(int i, String s) {
sb.insert(i, s);
return this;
@ -85,6 +93,11 @@ public class StringBuffer implements CharSequence {
return this;
}
public synchronized StringBuffer insert(int i, int v) {
sb.insert(i, v);
return this;
}
public synchronized StringBuffer delete(int start, int end) {
sb.delete(start, end);
return this;
@ -112,6 +125,10 @@ public class StringBuffer implements CharSequence {
sb.setLength(v);
}
public synchronized void setCharAt(int index, char ch) {
sb.setCharAt(index, ch);
}
public synchronized void getChars(int srcOffset, int srcLength, char[] dst,
int dstOffset)
{

View File

@ -154,6 +154,10 @@ public class StringBuilder implements CharSequence {
return insert(i, new String(new char[] { c }, 0, 1, false));
}
public StringBuilder insert(int i, int v) {
return insert(i, String.valueOf(v));
}
public StringBuilder delete(int start, int end) {
if (start >= end) {
return this;
@ -322,4 +326,10 @@ public class StringBuilder implements CharSequence {
public CharSequence subSequence(int start, int end) {
return substring(start, end);
}
public void setCharAt(int index, char ch) {
if(index < 0 || index >= length) throw new IndexOutOfBoundsException();
deleteCharAt(index);
insert(index, ch);
}
}

View File

@ -111,8 +111,8 @@ public class Method<T> extends AccessibleObject implements Member {
}
}
public static native Object invoke(Method method, Object instance,
Object ... arguments)
private static native Object invoke(Method method, Object instance,
Object ... arguments)
throws InvocationTargetException, IllegalAccessException;
public Class getReturnType() {

View File

@ -45,6 +45,12 @@ public abstract class Calendar {
fields[field] = value;
}
public void set(int year, int month, int date) {
set(YEAR, year);
set(MONTH, month);
set(DAY_OF_MONTH, date);
}
public void setTime(Date date) {
time = date.getTime();
}

View File

@ -11,7 +11,7 @@
package java.util;
public class Locale {
public static final Locale ENGLISH = new Locale("en");
public static final Locale ENGLISH = new Locale("en", "us");
private final String language;
private final String country;

View File

@ -23,4 +23,8 @@ public class PropertyResourceBundle extends ResourceBundle {
public Object handleGetObject(String key) {
return map.get(key);
}
public Enumeration<String> getKeys() {
return map.keys();
}
}

View File

@ -58,6 +58,21 @@ public class Random {
return next(32);
}
public void nextBytes(byte[] bytes) {
final int length = bytes.length;
for (int i = 0; i < length;) {
int r = nextInt();
for (int j = Math.min(length - i, 4); j > 0; --j) {
bytes[i++] = (byte) r;
r >>= 8;
}
}
}
public long nextLong() {
return ((long) next(32) << 32) + next(32);
}
public double nextDouble() {
return (((long) next(26) << 27) + next(27)) / (double) (1L << 53);
}

View File

@ -118,4 +118,6 @@ public abstract class ResourceBundle {
}
protected abstract Object handleGetObject(String key);
public abstract Enumeration<String> getKeys();
}

View File

@ -12,7 +12,7 @@ package java.util;
public class Stack<T> extends Vector<T> {
public boolean empty() {
return size() != 0;
return size() == 0;
}
public T peek() {

View File

@ -61,8 +61,8 @@ public class Vector<T> implements List<T> {
return list.set(index, value);
}
public T setElementAt(T value, int index) {
return set(index, value);
public void setElementAt(T value, int index) {
set(index, value);
}
public T elementAt(int index) {

View File

@ -0,0 +1,16 @@
/* Copyright (c) 2008, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
package java.util.zip;
public abstract class ZipEntry {
public abstract String getName();
public abstract int getCompressedSize();
}

View File

@ -0,0 +1,313 @@
/* Copyright (c) 2008, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
package java.util.zip;
import java.io.File;
import java.io.RandomAccessFile;
import java.io.InputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Map;
import java.util.HashMap;
public class ZipFile {
private final RandomAccessFile file;
private final Window window;
private final Map<String,Integer> index = new HashMap();
public ZipFile(String name) throws IOException {
file = new RandomAccessFile(name, "r");
window = new Window(file, 4096);
int fileLength = (int) file.length();
int pointer = fileLength - 22;
byte[] magic = new byte[] { 0x50, 0x4B, 0x05, 0x06 };
while (pointer > 0) {
if (equal(window.data, window.seek(pointer, magic.length),
magic, 0, magic.length))
{
pointer = directoryOffset(window, pointer);
magic = new byte[] { 0x50, 0x4B, 0x01, 0x02 };
while (pointer < fileLength) {
if (equal(window.data, window.seek(pointer, magic.length),
magic, 0, magic.length))
{
index.put(entryName(window, pointer), pointer);
pointer = entryEnd(window, pointer);
} else {
pointer = fileLength;
}
}
pointer = 0;
} else {
-- pointer;
}
}
}
public ZipFile(File file) throws IOException {
this(file.getAbsolutePath());
}
public int size() {
return index.size();
}
public Enumeration<ZipEntry> entries() {
return new MyEnumeration(window, index.values().iterator());
}
public ZipEntry getEntry(String name) {
Integer pointer = index.get(name);
return (pointer == null ? null : new MyZipEntry(window, pointer));
}
public InputStream getInputStream(ZipEntry entry) throws IOException {
int pointer = ((MyZipEntry) entry).pointer;
int method = compressionMethod(window, pointer);
int size = compressedSize(window, pointer);
InputStream in = new MyInputStream(file, fileData(window, pointer), size);
final int Stored = 0;
final int Deflated = 8;
switch (method) {
case Stored:
return in;
case Deflated:
return new InflaterInputStream(in, new Inflater(true));
default:
throw new IOException();
}
}
private static boolean equal(byte[] a, int aOffset, byte[] b, int bOffset,
int size)
{
for (int i = 0; i < size; ++i) {
if (a[aOffset + i] != b[bOffset + i]) return false;
}
return true;
}
private static int get2(Window w, int p) throws IOException {
int offset = w.seek(p, 2);
return
((w.data[offset + 1] & 0xFF) << 8) |
((w.data[offset ] & 0xFF) );
}
private static int get4(Window w, int p) throws IOException {
int offset = w.seek(p, 4);
return
((w.data[offset + 3] & 0xFF) << 24) |
((w.data[offset + 2] & 0xFF) << 16) |
((w.data[offset + 1] & 0xFF) << 8) |
((w.data[offset ] & 0xFF) );
}
private static int directoryOffset(Window w, int p) throws IOException {
return get4(w, p + 16);
}
private static int entryNameLength(Window w, int p) throws IOException {
return get2(w, p + 28);
}
private static String entryName(Window w, int p) throws IOException {
int length = entryNameLength(w, p);
return new String(w.data, w.seek(p + 46, length), length);
}
private static int compressionMethod(Window w, int p) throws IOException {
return get2(w, p + 10);
}
private static int compressedSize(Window w, int p) throws IOException {
return get4(w, p + 20);
}
private static int fileNameLength(Window w, int p) throws IOException {
return get2(w, p + 28);
}
private static int extraFieldLength(Window w, int p) throws IOException {
return get2(w, p + 30);
}
private static int commentFieldLength(Window w, int p) throws IOException {
return get2(w, p + 32);
}
private static int entryEnd(Window w, int p) throws IOException {
final int HeaderSize = 46;
return p + HeaderSize
+ fileNameLength(w, p)
+ extraFieldLength(w, p)
+ commentFieldLength(w, p);
}
private static int fileData(Window w, int p) throws IOException {
int localHeader = localHeader(w, p);
final int LocalHeaderSize = 30;
return localHeader
+ LocalHeaderSize
+ localFileNameLength(w, localHeader)
+ localExtraFieldLength(w, localHeader);
}
private static int localHeader(Window w, int p) throws IOException {
return get4(w, p + 42);
}
private static int localFileNameLength(Window w, int p) throws IOException {
return get2(w, p + 26);
}
private static int localExtraFieldLength(Window w, int p)
throws IOException
{
return get2(w, p + 28);
}
public void close() throws IOException {
file.close();
}
private static class Window {
private final RandomAccessFile file;
public final byte[] data;
public int start;
public int length;
public Window(RandomAccessFile file, int size) {
this.file = file;
data = new byte[size];
}
public int seek(int start, int length) throws IOException {
int fileLength = (int) file.length();
if (length > data.length) {
throw new IllegalArgumentException
("length " + length + " greater than buffer length " + data.length);
}
if (start < 0) {
throw new IllegalArgumentException("negative start " + start);
}
if (start + length > fileLength) {
throw new IllegalArgumentException
("end " + (start + length) + " greater than file length " +
fileLength);
}
if (start < this.start || start + length > this.start + this.length) {
this.length = Math.min(data.length, fileLength);
this.start = start - ((this.length - length) / 2);
if (this.start < 0) {
this.start = 0;
} else if (this.start + this.length > fileLength) {
this.start = fileLength - this.length;
}
file.seek(this.start);
file.readFully(data, 0, this.length);
}
return start - this.start;
}
}
private static class MyZipEntry extends ZipEntry {
public final Window window;
public final int pointer;
public MyZipEntry(Window window, int pointer) {
this.window = window;
this.pointer = pointer;
}
public String getName() {
try {
return entryName(window, pointer);
} catch (IOException e) {
return null;
}
}
public int getCompressedSize() {
try {
return compressedSize(window, pointer);
} catch (IOException e) {
return 0;
}
}
}
private static class MyEnumeration implements Enumeration<ZipEntry> {
private final Window window;
private final Iterator<Integer> iterator;
public MyEnumeration(Window window, Iterator<Integer> iterator) {
this.window = window;
this.iterator = iterator;
}
public boolean hasMoreElements() {
return iterator.hasNext();
}
public ZipEntry nextElement() {
return new MyZipEntry(window, iterator.next());
}
}
private static class MyInputStream extends InputStream {
private RandomAccessFile file;
private int offset;
private int length;
public MyInputStream(RandomAccessFile file, int start, int length) {
this.file = file;
this.offset = start;
this.length = length;
}
public int read() throws IOException {
byte[] b = new byte[1];
int c = read(b);
return (c == -1 ? -1 : b[0] & 0xFF);
}
public int read(byte[] b, int offset, int length) throws IOException {
if (this.length == 0) return -1;
if (length > this.length) length = this.length;
file.seek(this.offset);
file.readFully(b, offset, length);
this.offset += length;
this.length -= length;
return length;
}
public void close() throws IOException {
file = null;
}
}
}