示例#1
0
文件: ast.py 项目: saner/jspy
    def eval(self, context):
        # for for(var exp1, cond, exp2)
        if self.declarations is not None:
          for declaration in self.declarations:
              declaration.eval(context)

        # for for(exp1, cond, exp2)
        if self.start_expression is not None:
            ref = self.start_expression.eval(context)
            js.get_value(ref)

        result_value = js.EMPTY
        while True:
            if self.condition is not None:
              condition_value = js.get_value(self.condition.eval(context))
              if not condition_value:
                  return js.Completion(js.NORMAL, result_value, js.EMPTY)
            stmt = self.statement.eval(context)
            if stmt.value is not js.EMPTY:
                result_value = stmt.value
            if stmt.type is js.BREAK:
                return js.Completion(js.NORMAL, result_value, js.EMPTY)
            if js.is_abrupt(stmt) and stmt.type is not js.CONTINUE:
                return stmt
            if self.count_expression is not None:
              count_expression_ref = self.count_expression.eval(context)
              js.get_value(count_expression_ref)
示例#2
0
 def eval(self, context):
     f = js.get_value(self.obj.eval(context))
     s = None
     if (not (self.scope == None)):
         s = js.get_value(self.scope.eval(context))
     return f.call(None, [
         js.get_value(argument.eval(context))
         for argument in self.argumentss
     ],
                   scope=s)
示例#3
0
 def eval(self, context):
     ref = self.reference.eval(context)
     value = js.get_value(self.expression.eval(context))
     if self.op == '=':
         js.put_value(ref, value)
         return value
     else:
         new_value = perform_binary_op(self.op[:-1], js.get_value(ref),
                                       value)
         js.put_value(ref, new_value)
         return new_value
示例#4
0
文件: ast.py 项目: mstepniowski/jspy
 def eval(self, context):
     ref = self.reference.eval(context)
     value = js.get_value(self.expression.eval(context))
     if self.op == '=':
         js.put_value(ref, value)
         return value
     else:
         new_value = perform_binary_op(self.op[:-1],
                                       js.get_value(ref),
                                       value)
         js.put_value(ref, new_value)
         return new_value
示例#5
0
 def eval(self, context):
     left = js.get_value(self.left_expression.eval(context))
     right = js.get_value(self.right_expression.eval(context))
     if self.op == '*':
         return left * right
     elif self.op == '/':
         return left / right
     elif self.op == '%':
         return left % right
     elif self.op == '+':
         return left + right
     elif self.op == '-':
         return left - right
     elif self.op == '<<':
         return left << right
     elif self.op == '>>':
         return left >> right
     elif self.op == '<':
         return left < right
     elif self.op == '<=':
         return left <= right
     elif self.op == '>':
         return left > right
     elif self.op == '>=':
         return left >= right
     elif self.op == 'instanceof':
         # TODO
         return False
     elif self.op == 'in':
         # TODO
         return False
     elif self.op == '==':
         return left == right
     elif self.op == '!=':
         return left != right
     elif self.op == '===':
         return left == right
     elif self.op == '!==':
         return left != right
     elif self.op == '&':
         return left & right
     elif self.op == '^':
         return left ^ right
     elif self.op == '|':
         return left | right
     elif self.op == '&&':
         return left and right
     elif self.op == '||':
         return left or right
     else:
         raise SyntaxError('Unknown binary operand: %r' % self.op)
示例#6
0
文件: ast.py 项目: mstepniowski/jspy
 def eval(self, context):
     left = js.get_value(self.left_expression.eval(context))
     right = js.get_value(self.right_expression.eval(context))
     if self.op == '*':
         return left * right
     elif self.op == '/':
         return left / right
     elif self.op == '%':
         return left % right
     elif self.op == '+':
         return left + right
     elif self.op == '-':
         return left - right
     elif self.op == '<<':
         return left << right
     elif self.op == '>>':
         return left >> right
     elif self.op == '<':
         return left < right
     elif self.op == '<=':
         return left <= right
     elif self.op == '>':
         return left > right
     elif self.op == '>=':
         return left >= right
     elif self.op == 'instanceof':
         # TODO
         return False
     elif self.op == 'in':
         # TODO
         return False
     elif self.op == '==':
         return left == right
     elif self.op == '!=':
         return left != right
     elif self.op == '===':
         return left == right
     elif self.op == '!==':
         return left != right
     elif self.op == '&':
         return left & right
     elif self.op == '^':
         return left ^ right
     elif self.op == '|':
         return left | right
     elif self.op == '&&':
         return left and right
     elif self.op == '||':
         return left or right
     else:
         raise SyntaxError('Unknown binary operand: %r' % self.op)
示例#7
0
 def eval(self, expression, context=None):
     if context is None:
         context = js.ExecutionContext({})
     if not isinstance(context, js.ExecutionContext):
         context = js.ExecutionContext(context)
     expression_ast = self.parser.parse(expression)
     return js.get_value(expression_ast.eval(context))
示例#8
0
 def eval(self, stmt, context=None):
     if context is None:
         context = js.ExecutionContext({})
     if not isinstance(context, js.ExecutionContext):
         context = js.ExecutionContext(context)
     stmt_ast = self.parser.parse(stmt)
     return js.get_value(stmt_ast.eval(context))
示例#9
0
 def eval(self, expression, context=None):
     if context is None:
         context = js.ExecutionContext({})
     if not isinstance(context, js.ExecutionContext):
         context = js.ExecutionContext(context)
     expression_ast = self.parser.parse(expression)
     return js.get_value(expression_ast.eval(context))
示例#10
0
 def eval(self, stmt, context=None):
     if context is None:
         context = js.ExecutionContext({})
     if not isinstance(context, js.ExecutionContext):
         context = js.ExecutionContext(context)
     stmt_ast = self.parser.parse(stmt)
     return js.get_value(stmt_ast.eval(context))
示例#11
0
 def eval(self, context):
     if self.expression is None:
         return js.Completion(js.RETURN, js.UNDEFINED, js.EMPTY)
     else:
         return js.Completion(js.RETURN,
                              js.get_value(self.expression.eval(context)),
                              js.EMPTY)
示例#12
0
文件: ast.py 项目: mstepniowski/jspy
 def eval(self, context):
     if self.expression is None:
         return js.Completion(js.RETURN, js.UNDEFINED, js.EMPTY)
     else:
         return js.Completion(js.RETURN,
                              js.get_value(self.expression.eval(context)),
                              js.EMPTY)
示例#13
0
文件: ast.py 项目: mstepniowski/jspy
 def eval(self, context):
     result_value = js.EMPTY
     while True:
         condition_value = js.get_value(self.condition.eval(context))
         if not condition_value:
             return js.Completion(js.NORMAL, result_value, js.EMPTY)
         stmt = self.statement.eval(context)
         if stmt.value is not js.EMPTY:
             result_value = stmt.value
         if stmt.type is js.BREAK:
             return js.Completion(js.NORMAL, result_value, js.EMPTY)
         elif js.is_abrupt(stmt) and stmt.type is not js.CONTINUE:
             return stmt
示例#14
0
 def eval(self, context):
     result_value = js.EMPTY
     while True:
         condition_value = js.get_value(self.condition.eval(context))
         if not condition_value:
             return js.Completion(js.NORMAL, result_value, js.EMPTY)
         stmt = self.statement.eval(context)
         if stmt.value is not js.EMPTY:
             result_value = stmt.value
         if stmt.type is js.BREAK:
             return js.Completion(js.NORMAL, result_value, js.EMPTY)
         elif js.is_abrupt(stmt) and stmt.type is not js.CONTINUE:
             return stmt
示例#15
0
 def eval(self, context):
     cntx = js.ExecutionContext(dict(), parent=context)
     result_value = js.EMPTY
     firstst = self.first.eval(cntx)
     while True:
         condition_value = js.get_value(self.condition.eval(cntx))
         #print("COND",condition_value)
         if not condition_value:
             return js.Completion(js.NORMAL, result_value, js.EMPTY)
         stmt = self.statement.eval(cntx)
         if stmt.value is not js.EMPTY:
             result_value = stmt.value
         if stmt.type is js.BREAK:
             return js.Completion(js.NORMAL, result_value, js.EMPTY)
         elif js.is_abrupt(stmt) and stmt.type is not js.CONTINUE:
             return stmt
         nextst = self.then.eval(cntx)
示例#16
0
    def eval(self, context):
        expr = self.expression.eval(context)
        value = js.get_value(expr)

        if self.op == 'delete':
            # TODO
            return True
        elif self.op == 'void':
            return js.UNDEFINED
        elif self.op == 'typeof':
            # TODO
            return 'object'
        elif self.op == '++':
            new_value = value + 1
            js.put_value(expr, new_value)
            return new_value
        elif self.op == '--':
            new_value = value - 1
            js.put_value(expr, new_value)
            return new_value
        elif self.op == 'postfix++':
            old_value = value
            js.put_value(expr, old_value + 1)
            return old_value
        elif self.op == 'postfix--':
            old_value = value
            js.put_value(expr, old_value - 1)
            return old_value
        elif self.op == '+':
            return +value
        elif self.op == '-':
            return -value
        elif self.op == '~':
            return ~value
        elif self.op == '!':
            return not value
        else:
            raise SyntaxError('Unknown unary operand: %s' % self.op)
示例#17
0
文件: ast.py 项目: mstepniowski/jspy
 def eval(self, context):
     expr = self.expression.eval(context)
     value = js.get_value(expr)
     
     if self.op == 'delete':
         # TODO
         return True
     elif self.op == 'void':
         return js.UNDEFINED
     elif self.op == 'typeof':
         # TODO
         return 'object'
     elif self.op == '++':
         new_value = value + 1
         js.put_value(expr, new_value)
         return new_value
     elif self.op == '--':
         new_value = value - 1
         js.put_value(expr, new_value)
         return new_value
     elif self.op == 'postfix++':
         old_value = value
         js.put_value(expr, old_value + 1)
         return old_value
     elif self.op == 'postfix--':
         old_value = value
         js.put_value(expr, old_value - 1)
         return old_value           
     elif self.op == '+':
         return +value
     elif self.op == '-':
         return -value
     elif self.op == '~':
         return ~value
     elif self.op == '!':
         return not value
     else:
         raise SyntaxError('Unknown unary operand: %s' % self.op)
示例#18
0
 def eval(self, context):
     condition_value = js.get_value(self.condition.eval(context))
     if condition_value:
         return js.get_value(self.true_expression.eval(context))
     else:
         return js.get_value(self.false_expression.eval(context))
示例#19
0
文件: ast.py 项目: mstepniowski/jspy
 def get_item_value(self, item, context):
     return js.get_value(item.eval(context)) if item is not None else js.UNDEFINED
示例#20
0
 def eval(self, context):
     f = js.get_value(self.obj.eval(context))
     return f.call(None, [
         js.get_value(argument.eval(context)) for argument in self.arguments
     ])
示例#21
0
 def eval(self, context):
     base_value = js.get_value(self.obj.eval(context))
     property_name_value = js.get_value(self.key.eval(context))
     return js.Reference(name=property_name_value, base=base_value)
示例#22
0
 def eval(self, context):
     items = dict((name, js.get_value(e.eval(context)))
                  for name, e in self.items.items())
     return js.Object(items=items)
示例#23
0
 def get_item_value(self, item, context):
     return js.get_value(
         item.eval(context)) if item is not None else js.UNDEFINED
示例#24
0
文件: ast.py 项目: mstepniowski/jspy
 def eval(self, context):
     condition_value = js.get_value(self.condition.eval(context))
     if condition_value:
         return self.true_statement.eval(context)
     else:
         return self.false_statement.eval(context)
示例#25
0
文件: ast.py 项目: mstepniowski/jspy
 def eval(self, context):
     items = dict((name, js.get_value(e.eval(context))) for name, e in self.items.items())
     return js.Object(items=items)
示例#26
0
 def eval(self, context):
     return js.Completion(js.NORMAL,
                          js.get_value(self.expression.eval(context)),
                          js.EMPTY)
示例#27
0
文件: ast.py 项目: mstepniowski/jspy
 def eval(self, context):
     condition_value = js.get_value(self.condition.eval(context))
     if condition_value:
         return js.get_value(self.true_expression.eval(context))
     else:
         return js.get_value(self.false_expression.eval(context))
示例#28
0
文件: ast.py 项目: mstepniowski/jspy
 def eval(self, context):
     base_value = js.get_value(self.obj.eval(context))
     property_name_value = js.get_value(self.key.eval(context))
     return js.Reference(name=property_name_value, base=base_value)
示例#29
0
 def eval(self, context):
     ref = self.identifier.eval(context)
     value = js.get_value(self.initialiser.eval(context))
     js.put_value(ref, value)
     return js.Completion(js.NORMAL, ref.name, js.EMPTY)
示例#30
0
文件: ast.py 项目: mstepniowski/jspy
 def eval(self, context):
     f = js.get_value(self.obj.eval(context))
     return f.call(None, [js.get_value(argument.eval(context)) for argument in self.arguments])
示例#31
0
 def eval(self, context):
     condition_value = js.get_value(self.condition.eval(context))
     if condition_value:
         return self.true_statement.eval(context)
     else:
         return self.false_statement.eval(context)
示例#32
0
文件: ast.py 项目: mstepniowski/jspy
 def eval(self, context):
     ref = self.identifier.eval(context)
     value = js.get_value(self.initialiser.eval(context))
     js.put_value(ref, value)
     return js.Completion(js.NORMAL, ref.name, js.EMPTY)
示例#33
0
文件: ast.py 项目: mstepniowski/jspy
 def eval(self, context):
     return js.Completion(js.NORMAL,
                          js.get_value(self.expression.eval(context)),
                          js.EMPTY)
示例#34
0
文件: ast.py 项目: saner/jspy
 def eval(self, context):
     # TODO: Ellision
     return js.Array(items=[js.get_value(item.eval(context)) for item in self.items])