示例#1
0
文件: user.py 项目: parastoo-62/pie
    def _get_return_value(self, frame):
        if not frame.stack:
            return space.null()

        return_value = frame.stack.pop()
        if self.return_type == self.VALUE:
            return_value = return_value.deref()

        return return_value
示例#2
0
 def GET_INDEX(self, value):
     name = self.frame.pop_name()
     w_array = self.frame.get_variable(name, self.context)
     w_index = self.frame.stack.pop()
     try:
         w_value = w_array.get(w_index)
     except KeyError:
         w_value = space.undefined()
     except IllegalOffsetType:
         #TODO: add illegal offset type message print
         w_value = space.null()
     self.frame.stack.append(w_value)
示例#3
0
 def test_get_type_conversion_other(self):
     array = space.array([space.int(0), space.int(1),
                          space.int(1), space.int(2),
                          space.int(-1), space.int(3)])
     value = array.get(space.float(1.5)).deref()
     self.assertTrue(value.equal(space.int(2)).is_true())
     value = array.get(space.bool(True)).deref()
     self.assertTrue(value.equal(space.int(2)).is_true())
     value = array.get(space.bool(False)).deref()
     self.assertTrue(value.equal(space.int(1)).is_true())
     with self.assertRaises(KeyError):
         value = array.get(space.null())
     with self.assertRaises(IllegalOffsetType):
         value = array.get(space.array())
示例#4
0
文件: user.py 项目: parastoo-62/pie
    def _get_frame(self, context, stack_values):
        frame = Frame()
        for index, argument in enumerate(self.arguments):
            argument_name, argument_type, default = argument
            try:
                value = stack_values[index]

                if argument_type == self.REFERENCE:
                    if not isinstance(value, W_Variable):
                        NonVariablePassedByReference(context).handle()
                        frame.variables[argument_name] = space.variable(space.null())
                    else:
                        frame.variables[argument_name] = value
                else:
                    frame.set_variable(argument_name, value.deref())

            except IndexError:
                if default is None:
                    MissingArgument(context, index + 1, self).handle()
                    frame.variables[argument_name] = space.variable(space.null())
                else:
                    frame.variables[argument_name] = space.variable(default)

        return frame
示例#5
0
 def test_array_creation_null_string_branch(self):
     raw = [space.string("test"), space.int(1),
            space.string("08"), space.int(2),
            space.string("99"), space.int(3),
            space.null(), space.int(4),
            space.string("-5"), space.int(5),
            space.string("-09"), space.int(7)]
     actual = space.array(raw)
     expected = {space.string("test"): space.int(1),
                 space.string("08"): space.int(2),
                 space.string('99'): space.int(3), space.string(""): space.int(4),
                 space.string('-5'): space.int(5),
                 space.string("-09"): space.int(7)}
     for key, value in expected.iteritems():
         self.assertTrue(actual.get(key).deref().equal(value).is_true())
示例#6
0
    def CALL_FUNCTION(self, arguments_number):
        function_name = self.frame.pop_name()
        if function_name not in self.context.functions:
            UndefinedFunction(self.context, function_name).handle()
            self.frame.stack.append(space.null())
            return

        parameters = []
        for _ in range(arguments_number):
            parameters.insert(0, self.frame.stack.pop())

        function = self.context.functions[function_name]
        w_return_value = function.call(self.context, parameters)

        self.frame.stack.append(w_return_value)
示例#7
0
    def interpret(self, context, frame):
        if not self.bytecode:
            try:
                self.bytecode = compiling.compile_source(self)
            except PieError as e:
                e.context = context
                e.handle()
                return space.bool(False)
        Interpreter(self.bytecode, context, frame).interpret()

        # TODO: as debug_trace function appear, a test for
        # this path should appear too
        if frame.stack:
            return frame.stack.pop()
        else:
            return space.null()
示例#8
0
文件: nodes.py 项目: parastoo-62/pie
 def get_compiled_value(self):
     return space.null()
示例#9
0
文件: frame.py 项目: parastoo-62/pie
 def get_variable(self, name, context):
     try:
         return self.variables[name]
     except KeyError:
         UndefinedVariable(context, name).handle()
         return space.null()
示例#10
0
 def CAST_TO_UNSET(self, value):
     self.frame.stack.pop()  # Don't need to keep value
     self.frame.stack.append(space.null())