Skip to content

Commit

Permalink
Added stubs for all the core Python types.
Browse files Browse the repository at this point in the history
  • Loading branch information
freakboy3742 committed Sep 25, 2015
1 parent c07daf0 commit ff282a1
Show file tree
Hide file tree
Showing 34 changed files with 164 additions and 37 deletions.
31 changes: 26 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ ALL_FILES=\
python/org/python/Callable.class \
python/org/python/Function.class \
python/org/python/InstanceMethod.class \
python/org/python/Iterator.class \
python/org/python/Range.class \
python/org/python/Iterable.class \
python/org/python/StaticMethod.class \
python/org/python/Constructor.class \
python/org/python/exceptions/ArithmeticError.class \
Expand Down Expand Up @@ -62,7 +61,6 @@ ALL_FILES=\
python/org/python/exceptions/TimeoutError.java \
python/org/python/exceptions/TypeError.class \
python/org/python/exceptions/UnboundLocalError.class \
python/org/python/exceptions/UnboundLocalErrorNameError.java \
python/org/python/exceptions/UnicodeDecodeError.class \
python/org/python/exceptions/UnicodeEncodeError.class \
python/org/python/exceptions/UnicodeError.class \
Expand All @@ -71,8 +69,31 @@ ALL_FILES=\
python/org/python/exceptions/UserWarning.java \
python/org/python/exceptions/ValueError.class \
python/org/python/exceptions/Warning.java \
python/org/python/exceptions/ZeroDivisionError.class

python/org/python/exceptions/ZeroDivisionError.class \
python/org/python/types/Bool.class \
python/org/python/types/ByteArray.class \
python/org/python/types/Bytes.class \
python/org/python/types/Class.class \
python/org/python/types/Complex.class \
python/org/python/types/ContextManager.class \
python/org/python/types/Dict.class \
python/org/python/types/DictView.class \
python/org/python/types/Ellipsis.class \
python/org/python/types/Float.class \
python/org/python/types/FrozenSet.class \
python/org/python/types/Function.class \
python/org/python/types/Int.class \
python/org/python/types/List.class \
python/org/python/types/MemoryView.class \
python/org/python/types/Method.class \
python/org/python/types/Module.class \
python/org/python/types/NotImplemented.class \
python/org/python/types/Null.class \
python/org/python/types/Range.class \
python/org/python/types/Set.class \
python/org/python/types/Str.class \
python/org/python/types/Tuple.class \
python/org/python/types/Type.class \

.PHONY: all clean

Expand Down
8 changes: 4 additions & 4 deletions python/org/Python.java
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ public static org.python.Object iter(
if (args.length < 1) {
throw new org.python.exceptions.TypeError("len() expects at least argument, got " + args.length);
} else if (args.length == 1) {
if (args[0] instanceof org.python.Iterator) {
if (args[0] instanceof org.python.Iterable) {
return args[0];
} else {
return args[0].__iter__();
Expand Down Expand Up @@ -1047,11 +1047,11 @@ public static org.python.Object range(
org.python.Object [] args,
java.util.Hashtable<java.lang.String, org.python.Object> kwargs) {
if (args.length == 1) {
return new org.python.Range(args[0]);
return new org.python.types.Range(args[0]);
} else if (args.length == 2) {
return new org.python.Range(args[0], args[1]);
return new org.python.types.Range(args[0], args[1]);
} else if (args.length == 3) {
return new org.python.Range(args[0], args[1], args[2]);
return new org.python.types.Range(args[0], args[1], args[2]);
} else if (args.length == 0) {
throw new org.python.exceptions.TypeError("range expected 1 arguments, got " + args.length);
} else {
Expand Down
7 changes: 7 additions & 0 deletions python/org/python/Iterable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.python;


public interface Iterable {
public org.python.Object __iter__();
public org.python.Object __next__();
}
6 changes: 0 additions & 6 deletions python/org/python/Iterator.java

This file was deleted.

2 changes: 1 addition & 1 deletion python/org/python/Object.java
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,8 @@ public org.python.Object __iter__() {
} else if (this.type == java.util.Set.class) {
} else if (this.type == org.python.Object.class) {
} else if (this.type == java.util.ArrayList.class) {
return org.python.JavaIterator(((java.util.ArrayList<>)this.value).iterator());
}
return null;
}

public org.python.Object __reversed__() {
Expand Down
4 changes: 0 additions & 4 deletions python/org/python/exceptions/UnboundLocalError.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package org.python.exceptions;

public class UnboundLocalError extends org.python.exceptions.NameError {
public UnboundLocalError() {
super();
}

public UnboundLocalError(String msg) {
super(msg);
}
Expand Down
11 changes: 0 additions & 11 deletions python/org/python/exceptions/UnboundLocalErrorNameError.java

This file was deleted.

5 changes: 5 additions & 0 deletions python/org/python/types/Bool.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.python.types;

public class Bool extends org.python.Object {

}
5 changes: 5 additions & 0 deletions python/org/python/types/ByteArray.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.python.types;

public class ByteArray extends org.python.Object {

}
5 changes: 5 additions & 0 deletions python/org/python/types/Bytes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.python.types;

public class Bytes extends org.python.Object {

}
5 changes: 5 additions & 0 deletions python/org/python/types/Class.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.python.types;

public class Class extends org.python.Object {

}
5 changes: 5 additions & 0 deletions python/org/python/types/Complex.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.python.types;

public class Complex extends org.python.Object {

}
5 changes: 5 additions & 0 deletions python/org/python/types/ContextManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.python.types;

public class ContextManager extends org.python.Object {

}
5 changes: 5 additions & 0 deletions python/org/python/types/Dict.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.python.types;

public class Dict extends org.python.Object {

}
5 changes: 5 additions & 0 deletions python/org/python/types/DictView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.python.types;

public class DictView extends org.python.Object {

}
5 changes: 5 additions & 0 deletions python/org/python/types/Ellipsis.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.python.types;

public class Ellipsis extends org.python.Object {

}
5 changes: 5 additions & 0 deletions python/org/python/types/Float.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.python.types;

public class Float extends org.python.Object {

}
5 changes: 5 additions & 0 deletions python/org/python/types/FrozenSet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.python.types;

public class FrozenSet extends org.python.Object {

}
5 changes: 5 additions & 0 deletions python/org/python/types/Function.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.python.types;

public class Function extends org.python.Object {

}
5 changes: 5 additions & 0 deletions python/org/python/types/Int.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.python.types;

public class Int extends org.python.Object {

}
5 changes: 5 additions & 0 deletions python/org/python/types/List.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.python.types;

public class List extends org.python.Object {

}
5 changes: 5 additions & 0 deletions python/org/python/types/MemoryView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.python.types;

public class MemoryView extends org.python.Object {

}
5 changes: 5 additions & 0 deletions python/org/python/types/Method.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.python.types;

public class Method extends org.python.Object {

}
5 changes: 5 additions & 0 deletions python/org/python/types/Module.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.python.types;

public class Module extends org.python.Object {

}
5 changes: 5 additions & 0 deletions python/org/python/types/NotImplemented.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.python.types;

public class NotImplemented extends org.python.Object {

}
5 changes: 5 additions & 0 deletions python/org/python/types/Null.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.python.types;

public class Null extends org.python.Object {

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.python;
package org.python.types;


public class Range extends org.python.Object implements org.python.Iterator {
public class Range extends org.python.Object implements org.python.Iterable {
private long index;

private long stop;
Expand Down Expand Up @@ -42,11 +42,16 @@ public Range(org.python.Object start, org.python.Object stop, org.python.Object
value = attrs;
}

public org.python.Object __iter__() {
return this;
}

public org.python.Object __next__() {
if (this.index >= this.stop) {
throw new org.python.exceptions.StopIteration();
}
this.index += this.step;
return new org.python.Object(this.index);
}

}
5 changes: 5 additions & 0 deletions python/org/python/types/Set.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.python.types;

public class Set extends org.python.Object {

}
5 changes: 5 additions & 0 deletions python/org/python/types/Str.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.python.types;

public class Str extends org.python.Object {

}
5 changes: 5 additions & 0 deletions python/org/python/types/Tuple.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.python.types;

public class Tuple extends org.python.Object {

}
5 changes: 5 additions & 0 deletions python/org/python/types/Type.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.python.types;

public class Type extends org.python.Object {

}
4 changes: 2 additions & 2 deletions tests/test_for.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ def test_for_over_range(self):
103: <DUP>
104: <INVOKESPECIAL java/util/Hashtable.<init> ()V>
107: <INVOKESTATIC org/Python.iter ([Lorg/python/Object;Ljava/util/Hashtable;)Lorg/python/Object;>
110: <CHECKCAST <Class org/python/Iterator>>
110: <CHECKCAST <Class org/python/Iterable>>
113: <DUP>
114: <INVOKEINTERFACE org/python/Iterator.__next__ ()Lorg/python/Object;>
114: <INVOKEINTERFACE org/python/Iterable.__next__ ()Lorg/python/Object;>
119: <GOTO 6>
122: <GOTO 13>
125: <ASTORE_2>
Expand Down
2 changes: 1 addition & 1 deletion voc/python/opcodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,7 @@ def convert(self, context, arguments):
'([Lorg/python/Object;Ljava/util/Hashtable;)Lorg/python/Object;'
),

JavaOpcodes.CHECKCAST('org/python/Iterator'),
JavaOpcodes.CHECKCAST('org/python/Iterable'),
)


Expand Down
2 changes: 1 addition & 1 deletion voc/python/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ def transpile(self, context):
loop,
opcodes.TRY(),
JavaOpcodes.DUP(),
JavaOpcodes.INVOKEINTERFACE('org/python/Iterator', '__next__', '()Lorg/python/Object;', 0),
JavaOpcodes.INVOKEINTERFACE('org/python/Iterable', '__next__', '()Lorg/python/Object;', 0),
opcodes.CATCH('org/python/exceptions/StopIteration'),
opcodes.jump(JavaOpcodes.GOTO(0), context, loop, opcodes.Opcode.NEXT),
opcodes.END_TRY(),
Expand Down

0 comments on commit ff282a1

Please sign in to comment.