예제 #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
파일: tests.py 프로젝트: pombredanne/jspy-1
 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
파일: tests.py 프로젝트: pombredanne/jspy-1
 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])