diff options
author | Marion <marion.zepf@gmail.com> | 2013-07-23 09:01:44 (GMT) |
---|---|---|
committer | Marion <marion.zepf@gmail.com> | 2013-07-23 09:01:44 (GMT) |
commit | 1071c82c317933a3251fe0c0c5028afbb5615e73 (patch) | |
tree | 88d2cd2fec8da3c3296681e41faaec13f6ae7b1a /TurtleArt/taprimitive.py | |
parent | 75271bb387a70a047b3258813d55e1e517c5bd44 (diff) |
define some Primitives as not exportable when they are created
Diffstat (limited to 'TurtleArt/taprimitive.py')
-rw-r--r-- | TurtleArt/taprimitive.py | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/TurtleArt/taprimitive.py b/TurtleArt/taprimitive.py index 2bd259e..2719a71 100644 --- a/TurtleArt/taprimitive.py +++ b/TurtleArt/taprimitive.py @@ -30,7 +30,8 @@ class Primitive(object): but that can also be transformed into a Python AST. """ - def __init__(self, func, slot_wrappers=None, call_afterwards=None): + def __init__(self, func, slot_wrappers=None, call_afterwards=None, + export_me=True): """ slot_wrappers -- A dictionary mapping from the index of an argument in the args list to another Primitive that should be wrapped around the actual argument value (e.g., to convert a @@ -40,7 +41,9 @@ class Primitive(object): and last argument number (the latter increased by 1) as a key. call_afterwards -- Code to call after this Primitive has been called (e.g., for updating labels in LogoCode) (not used for creating - AST)""" + AST) + export_me -- True iff this Primitive should be exported to Python + code (the default case) """ self.func = func if slot_wrappers is None: self.slot_wrappers = {} @@ -48,6 +51,7 @@ class Primitive(object): # TODO check for duplicate keys (that appear as number and in a tuple or in several tuples) and for overlapping tuple ranges self.slot_wrappers = slot_wrappers self.call_afterwards = call_afterwards + self.export_me = export_me def __repr__(self): return "Primitive(" + repr(self.func) + ")" @@ -79,16 +83,20 @@ class Primitive(object): args_for_wrapper = runtime_args[start:end] if call_wrappers: wrapper_output = wrapper(*args_for_wrapper) - else: + elif wrapper.export_me: wrapper_output = wrapper.get_ast(*args_for_wrapper) + else: + wrapper_output = args_for_wrapper new_args.append(wrapper_output) i += end - start else: # number -> slot wrapper around one argument if call_wrappers: new_arg = wrapper(arg) - else: + elif wrapper.export_me: new_arg = wrapper.get_ast(arg) + else: + new_arg = arg new_args.append(new_arg) i += 1 @@ -98,8 +106,10 @@ class Primitive(object): if wrapper is not None: if call_wrappers: new_value = wrapper(value) - else: + elif wrapper.export_me: new_value = wrapper.get_ast(value) + else: + new_value = value new_kwargs[key] = new_value else: new_kwargs[key] = value |