From 3d725845c08fe0897ade3bcd6b86c654ab8d5228 Mon Sep 17 00:00:00 2001 From: Marion Date: Thu, 12 Sep 2013 23:52:40 +0000 Subject: make Media objects exportable --- (limited to 'TurtleArt/tatype.py') 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: -- cgit v0.9.1