Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/TurtleArt/tatype.py
diff options
context:
space:
mode:
authorMarion <marion.zepf@gmail.com>2013-09-01 14:39:06 (GMT)
committer Marion <marion.zepf@gmail.com>2013-09-01 14:39:06 (GMT)
commit5bb8683e7489c240e81f90b9555d7ada47008dfa (patch)
treec589c370659bb9d9bd780ba30498977b8648aa16 /TurtleArt/tatype.py
parent5c263c8e288a0de6702fa5d910cd1c9d928e63cd (diff)
remove types 'positive', 'negative', and 'zero'
- These fine value-dependent distinctions should be made at runtime, not during type checking. - Fix a small bug in the algorithm to find a converter given two types.
Diffstat (limited to 'TurtleArt/tatype.py')
-rw-r--r--TurtleArt/tatype.py43
1 files changed, 13 insertions, 30 deletions
diff --git a/TurtleArt/tatype.py b/TurtleArt/tatype.py
index 3fa7a83..14f1c9e 100644
--- a/TurtleArt/tatype.py
+++ b/TurtleArt/tatype.py
@@ -57,12 +57,10 @@ TYPE_CHAR = Type('char', 1)
TYPE_COLOR = Type('color', 2)
TYPE_FLOAT = Type('float', 3)
TYPE_INT = Type('int', 4)
-TYPE_NEGATIVE = Type('negative', 5)
-TYPE_NUMBER = Type('number', 6)
+TYPE_NUMBER = Type('number', 6) # shortcut to avoid a TypeDisjunction between
+# TYPE_FLOAT and TYPE_INT
TYPE_NUMERIC_STRING = Type('numeric string', 7)
-TYPE_POSITIVE = Type('positive', 8)
TYPE_STRING = Type('string', 9)
-TYPE_ZERO = Type('zero', 10)
# TODO add list types
@@ -71,13 +69,10 @@ def get_type(x):
and a boolean indicating whether x is an AST. If the type cannot be
determined, return TYPE_OBJECT as the type. """
# non-AST types
- if isinstance(x, (float, int, long)):
- if x > 0:
- return (TYPE_POSITIVE, False)
- elif x == 0:
- return (TYPE_ZERO, False)
- else:
- return (TYPE_NEGATIVE, False)
+ if isinstance(x, (int, long)):
+ return (TYPE_INT, False)
+ elif isinstance(x, float):
+ return (TYPE_FLOAT, False)
elif isinstance(x, basestring):
if len(x) == 1:
return (TYPE_CHAR, False)
@@ -107,8 +102,10 @@ def get_type(x):
return (get_type(value)[0], True)
elif isinstance(x, ast.Call):
if isinstance(x.func, ast.Name):
- if x.func.id in ('float', 'int'):
- return (x.func.__name__, True)
+ if x.func.id == 'float':
+ return (TYPE_FLOAT, True)
+ if x.func.id == 'int':
+ return (TYPE_INT, True)
elif x.func.id in ('repr', 'str', 'unicode'):
return (TYPE_STRING, True)
@@ -140,7 +137,6 @@ TYPE_CONVERTERS = {
# converting A -> C must yield the same result as converting A -> B -> C.
# TYPE_OBJECT is the supertype of everything.
TYPE_CHAR: {
- TYPE_POSITIVE: ord, # ignore the zero byte, chr(0)
TYPE_STRING: identity},
TYPE_COLOR: {
TYPE_FLOAT: float,
@@ -155,26 +151,13 @@ TYPE_CONVERTERS = {
TYPE_FLOAT: float,
TYPE_NUMBER: identity,
TYPE_STRING: str},
- TYPE_NEGATIVE: {
- TYPE_FLOAT: float,
- TYPE_INT: int,
- TYPE_NUMBER: identity,
- TYPE_STRING: str},
TYPE_NUMBER: {
- TYPE_STRING: str},
- TYPE_NUMERIC_STRING: {
- TYPE_FLOAT: float,
- TYPE_STRING: identity},
- TYPE_POSITIVE: {
TYPE_FLOAT: float,
TYPE_INT: int,
- TYPE_NUMBER: identity,
TYPE_STRING: str},
- TYPE_ZERO: {
+ TYPE_NUMERIC_STRING: {
TYPE_FLOAT: float,
- TYPE_INT: int,
- TYPE_NUMBER: identity,
- TYPE_STRING: str}
+ TYPE_STRING: identity}
}
@@ -251,7 +234,7 @@ def get_converter(old_type, new_type):
# form the transitive closure of all types that old_type can be
# converted to, and look for new_type there
backtrace = converters_from_old.copy()
- new_backtrace = backtrace
+ new_backtrace = backtrace.copy()
break_all = False
while True:
newest_backtrace = {}