globals (halfway, NONFUNCTIONAL!)
# ====== Legal notices
#
-# Copyright 2014, 2015, 2016 Jacques de Hooge, GEATEC engineering, www.geatec.com
+# Copyright 2014, 2015, 2016, 2017 Jacques de Hooge, GEATEC engineering, www.geatec.com
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -980,7 +980,19 @@ class Generator (ast.NodeVisitor):
if type (target) == ast.Subscript: # Only non-overloaded LHS index can be left to visit_Subscript
if type (target.slice) == ast.Index: # Always overloaded
- if type (target.slice.value) == ast.Tuple:
+ if self.isCall (node.targets [0] .value, 'globals'):
+ # Create assignments on the fly and visit it
+ # Note that the RHS may be quite complex, e.g. a Python list comprehension
+ self.visit (ast.Assign (
+ targets = [ast.Name (
+ id = self.nextTemp ('temp'),
+ ctx = ast.Store
+ )],
+ value = value
+ ))
+ self.emit (';\neval (\'{} = {{}}\'.format ({}))\n', node.targets [0] .slice.value.id, self.getTemp ('temp'))
+ self.prevTemp ('temp')
+ elif type (target.slice.value) == ast.Tuple:
self.visit (target.value)
self.emit ('.__setitem__ (') # Free function tries .__setitem__ (overload) and [] (native)
self.stripTuple = True
@@ -2353,7 +2365,11 @@ class Generator (ast.NodeVisitor):
# LHS slice and overloaded LHS index are dealth with directy in visit_Assign, since the RHS is needed for them also
def visit_Subscript (self, node):
if type (node.slice) == ast.Index:
- if type (node.slice.value) == ast.Tuple: # Always overloaded, it must be an RHS index
+ if self.isCall (node.value, 'globals'):
+ self.emit ('eval (')
+ self.visit (node.slice.value)
+ self.emit (')')
+ elif type (node.slice.value) == ast.Tuple: # Always overloaded, it must be an RHS index
self.visit (node.value)
self.emit ('.__getitem__ (')
self.stripTuple = True
