def execute(self, context): ast = self.ast # If self.ast is not an SL2 screen, run it using renpy.display.screen.use_screen. if ast is None: self.execute_use_screen(context) return # Otherwise, run it directly. ctx = SLContext(context) try: if self.args: args, kwargs = self.args.evaluate(context.scope) else: args = [ ] kwargs = { } except: if not context.predicting: raise args = [ ] kwargs = { } if ast.parameters is not None: scope = ast.parameters.apply(args, kwargs, ignore_errors=context.predicting) else: if args: raise Exception("Screen {} does not take positional arguments. ({} given)".format(self.target, len(args))) scope = context.scope.copy() scope.update(kwargs) scope["_scope"] = scope ctx.scope = scope # Use a call-site specific cache. (Otherwise, two uses of the same screen would # be sharing cache locations. cache = context.cache.get(self.serial, None) if cache is None: context.cache[self.serial] = cache = { } ctx.cache = cache # Run the child screen. ast.execute(ctx)
@addToClass(ast.OpNode) def execute(self): args = [c.execute() for c in self.children] if len(args) == 1: args.insert(0, 0) return reduce(ops[self.op], args) @addToClass(ast.AssignNode) def execute(self): vars[self.children[0].tok] = self.children[1].execute() @addToClass(ast.PrintNode) def execute(self): print(self.children[0].execute()) @addToClass(ast.WhileNode) def execute(self): while (self.children[0].execute()): self.children[1].execute() if __name__ == "__main__": prog = open(sys.argv[1]).read() ast = parse(prog) ast.execute()
def execute(self, context): ast = self.ast # If self.ast is not an SL2 screen, run it using renpy.display.screen.use_screen. if ast is None: self.execute_use_screen(context) return # Otherwise, run the use statement directly. # Figure out the cache to use. # True if we want to force-mark this as an update. update = False if (not context.predicting) and self.id: # If we have an id, look it up in the current screen's use_cache. current_screen = renpy.display.screen.current_screen() use_id = (self.target, eval(self.id, context.globals, context.scope)) cache = current_screen.use_cache.get(use_id, None) if cache is not None: update = True else: if cache is None: cache = context.cache.get(self.serial, None) if cache is None: cache = {} context.cache[self.serial] = cache current_screen.use_cache[use_id] = cache else: # Otherwise, look up the cache based on the statement's location. cache = context.cache.get(self.serial, None) if cache is None: context.cache[self.serial] = cache = {} # Evaluate the arguments. try: if self.args: args, kwargs = self.args.evaluate(context.scope) else: args = [] kwargs = {} except: if not context.predicting: raise args = [] kwargs = {} # Apply the arguments to the parameters (if present) or to the scope of the used screen. if ast.parameters is not None: new_scope = ast.parameters.apply(args, kwargs, ignore_errors=context.predicting) scope = cache.get("scope", None) if scope is None: scope = cache["scope"] = new_scope else: scope.update(new_scope) else: if args: raise Exception( "Screen {} does not take positional arguments. ({} given)". format(self.target, len(args))) scope = context.scope.copy() scope.update(kwargs) scope["_scope"] = scope # Run the child screen. ctx = SLContext(context) ctx.scope = scope ctx.cache = cache if update: ctx.updating = True ast.execute(ctx)
def execute(self, context): ast = self.ast # If self.ast is not an SL2 screen, run it using renpy.display.screen.use_screen. if ast is None: self.execute_use_screen(context) return # Otherwise, run the use statement directly. # Figure out the cache to use. # True if we want to force-mark this as an update. update = False if (not context.predicting) and self.id: # If we have an id, look it up in the current screen's use_cache. current_screen = renpy.display.screen.current_screen() use_id = (self.target, eval(self.id, context.globals, context.scope)) cache = current_screen.use_cache.get(use_id, None) if cache is not None: update = True else: if cache is None: cache = context.cache.get(self.serial, None) if cache is None: cache = { } context.cache[self.serial] = cache current_screen.use_cache[use_id] = cache else: # Otherwise, look up the cache based on the statement's location. cache = context.cache.get(self.serial, None) if cache is None: context.cache[self.serial] = cache = { } # Evaluate the arguments. try: if self.args: args, kwargs = self.args.evaluate(context.scope) else: args = [ ] kwargs = { } except: if not context.predicting: raise args = [ ] kwargs = { } # Apply the arguments to the parameters (if present) or to the scope of the used screen. if ast.parameters is not None: new_scope = ast.parameters.apply(args, kwargs, ignore_errors=context.predicting) scope = cache.get("scope", None) if scope is None: scope = cache["scope"] = new_scope else: scope.update(new_scope) else: if args: raise Exception("Screen {} does not take positional arguments. ({} given)".format(self.target, len(args))) scope = context.scope.copy() scope.update(kwargs) scope["_scope"] = scope # Run the child screen. ctx = SLContext(context) ctx.scope = scope ctx.cache = cache if update: ctx.updating = True ast.execute(ctx)