diff options
author | Marion <marion.zepf@gmail.com> | 2013-09-06 09:47:52 (GMT) |
---|---|---|
committer | Marion <marion.zepf@gmail.com> | 2013-09-06 09:47:52 (GMT) |
commit | 20e59359edae3d88b65c08523607050401e38693 (patch) | |
tree | de057016e33cf3e760921e0ad81a63218d3cbc7f | |
parent | 40990d2845454b87840ff7c854acb1cd86129f05 (diff) |
new special return type for the 'box' block
-rw-r--r-- | TurtleArt/tabasics.py | 12 | ||||
-rw-r--r-- | TurtleArt/tatype.py | 10 |
2 files changed, 13 insertions, 9 deletions
diff --git a/TurtleArt/tabasics.py b/TurtleArt/tabasics.py index fe2bfa1..2943100 100644 --- a/TurtleArt/tabasics.py +++ b/TurtleArt/tabasics.py @@ -108,8 +108,9 @@ from talogo import (primitive_dictionary, logoerror) from tautils import (convert, chr_to_ord, round_int) from taconstants import (Color, CONSTANTS) from taprimitive import (ArgSlot, ConstantArg, or_, Primitive) -from tatype import (TYPE_BOOL, TYPE_CHAR, TYPE_COLOR, TYPE_FLOAT, TYPE_INT, - TYPE_NUMBER, TYPE_NUMERIC_STRING, TYPE_OBJECT, TYPE_STRING) +from tatype import (TYPE_BOOL, TYPE_BOX, TYPE_CHAR, TYPE_COLOR, TYPE_FLOAT, + TYPE_INT, TYPE_NUMBER, TYPE_NUMERIC_STRING, TYPE_OBJECT, + TYPE_STRING) from taturtle import Turtle @@ -1023,7 +1024,7 @@ buttons')) help_string=_('Variable 1 (numeric value)'), value_block=True) self.tw.lc.def_prim('box1', 0, - Primitive(self.tw.lc.prim_get_box, + Primitive(self.tw.lc.prim_get_box, return_type=TYPE_BOX, arg_descs=[ConstantArg('box1')])) palette.add_block('box2', @@ -1035,7 +1036,7 @@ buttons')) help_string=_('Variable 2 (numeric value)'), value_block=True) self.tw.lc.def_prim('box2', 0, - Primitive(self.tw.lc.prim_get_box, + Primitive(self.tw.lc.prim_get_box, return_type=TYPE_BOX, arg_descs=[ConstantArg('box2')])) primitive_dictionary['setbox'] = Primitive(self.tw.lc.prim_set_box, @@ -1052,8 +1053,7 @@ variable')) self.tw.lc.def_prim('storeinbox', 2, primitive_dictionary['setbox']) primitive_dictionary['box'] = Primitive(self.tw.lc.prim_get_box, - return_type=or_(TYPE_OBJECT, TYPE_STRING, TYPE_NUMBER, TYPE_FLOAT, - TYPE_INT, TYPE_NUMERIC_STRING, TYPE_CHAR, TYPE_COLOR), + return_type=TYPE_BOX, arg_descs=[ArgSlot(TYPE_STRING)]) palette.add_block('box', style='number-style-1strarg', 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}, |