Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/TurtleArt/tatype.py
diff options
context:
space:
mode:
Diffstat (limited to 'TurtleArt/tatype.py')
-rw-r--r--TurtleArt/tatype.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/TurtleArt/tatype.py b/TurtleArt/tatype.py
index 3a14fbf..1402014 100644
--- a/TurtleArt/tatype.py
+++ b/TurtleArt/tatype.py
@@ -23,6 +23,7 @@
import ast
from gettext import gettext as _
+from tablock import Media
from taconstants import (Color, CONSTANTS)
from tautils import debug_output
@@ -74,11 +75,11 @@ TYPE_CHAR = Type('TYPE_CHAR', 1)
TYPE_COLOR = Type('TYPE_COLOR', 2)
TYPE_FLOAT = Type('TYPE_FLOAT', 3)
TYPE_INT = Type('TYPE_INT', 4)
+TYPE_MEDIA = Type('TYPE_MEDIA', 10)
TYPE_NUMBER = Type('TYPE_NUMBER', 6) # shortcut to avoid a TypeDisjunction
# between TYPE_FLOAT and TYPE_INT
TYPE_NUMERIC_STRING = Type('TYPE_NUMERIC_STRING', 7)
TYPE_STRING = Type('TYPE_STRING', 9)
-# TODO add list types
BOX_AST = ast.Name(id='BOX', ctx=ast.Load)
@@ -104,6 +105,8 @@ def get_type(x):
return (TYPE_NUMERIC_STRING, False)
elif isinstance(x, Color):
return (TYPE_COLOR, False)
+ elif isinstance(x, Media):
+ return (TYPE_MEDIA, False)
elif hasattr(x, "return_type"):
return (x.return_type, False)
@@ -133,6 +136,10 @@ def get_type(x):
return (TYPE_CHAR, True)
elif x.func.id in ('repr', 'str', 'unicode'):
return (TYPE_STRING, True)
+ elif x.func.id == 'Color':
+ return (TYPE_COLOR, True)
+ elif x.func.id == 'Media':
+ return (TYPE_MEDIA, True)
# unary operands never change the type of their argument
elif isinstance(x, ast.UnaryOp):
if issubclass(x.op, ast.Not):
@@ -146,9 +153,9 @@ def get_type(x):
# other binary operators
elif isinstance(x, ast.BinOp):
type_left = get_type(x.left)[0]
- if type_left == TYPE_STRING:
- return (TYPE_STRING, True)
type_right = get_type(x.right)[0]
+ if type_left == TYPE_STRING or type_right == TYPE_STRING:
+ return (TYPE_STRING, True)
if type_left == type_right == TYPE_INT:
return (TYPE_INT, True)
else: