From 20e59359edae3d88b65c08523607050401e38693 Mon Sep 17 00:00:00 2001 From: Marion Date: Fri, 06 Sep 2013 09:47:52 +0000 Subject: new special return type for the 'box' block --- (limited to 'TurtleArt/tatype.py') diff --git a/TurtleArt/tatype.py b/TurtleArt/tatype.py index cf7bb03..346eb23 100644 --- a/TurtleArt/tatype.py +++ b/TurtleArt/tatype.py @@ -63,6 +63,7 @@ class TypeDisjunction(tuple,Type): TYPE_OBJECT = Type('object', 0) TYPE_BOOL = Type('bool', 5) +TYPE_BOX = Type('box', 8) # special type for the unknown content of a box TYPE_CHAR = Type('char', 1) TYPE_COLOR = Type('color', 2) TYPE_FLOAT = Type('float', 3) @@ -115,9 +116,7 @@ def get_type(x): return (get_type(value)[0], True) elif isinstance(x, ast.Subscript): if x.value == BOX_AST: - return (TypeDisjunction((TYPE_OBJECT, TYPE_STRING, TYPE_NUMBER, - TYPE_FLOAT, TYPE_INT, TYPE_NUMERIC_STRING, TYPE_CHAR, - TYPE_COLOR)), True) + return (TYPE_BOX, True) elif isinstance(x, ast.Call): if isinstance(x.func, ast.Name): if x.func.id == 'float': @@ -172,6 +171,11 @@ TYPE_CONVERTERS = { # The relation describing the type hierarchy must be transitive, i.e. # converting A -> C must yield the same result as converting A -> B -> C. # TYPE_OBJECT is the supertype of everything. + TYPE_BOX: { + TYPE_FLOAT: float, + TYPE_INT: int, + TYPE_NUMBER: float, + TYPE_STRING: str}, TYPE_CHAR: { TYPE_INT: ord, TYPE_STRING: identity}, -- cgit v0.9.1