예제 #1
0
파일: prelude.py 프로젝트: overminder/YASI
 def call(self, args_w):
     if len(args_w) <= 1:
         return w_boolean(True)
     w_lhs = args_w[0]
     for i in xrange(1, len(args_w)):
         w_rhs = args_w[i]
         if w_lhs.to_int() > w_rhs.to_int():
             w_lhs = w_rhs
         else:
             return w_boolean(False)
     return w_boolean(True)
예제 #2
0
파일: prelude.py 프로젝트: overminder/YASI
 def call(self, args_w):
     if len(args_w) <= 1:
         return w_boolean(True)
     w_lhs = args_w[0]
     for i in xrange(1, len(args_w)):
         w_rhs = args_w[i]
         if w_lhs.to_int() > w_rhs.to_int():
             w_lhs = w_rhs
         else:
             return w_boolean(False)
     return w_boolean(True)
예제 #3
0
def dump_bytecode_function(w_func):
    assert isinstance(w_func, W_BytecodeFunction)
    fields_w = [None] * 9
    fields_w[0] = symbol('BYTECODE-FUNCTION')
    fields_w[1] = list_to_pair([symbol('NAME'), symbol(w_func.name)])
    #
    code_w = [None] * len(w_func.code)
    for i in xrange(len(code_w)):
        code_w[i] = W_Integer(ord(w_func.code[i]))
    w_code = list_to_pair(code_w)
    fields_w[2] = list_to_pair([symbol('CODE'), w_code])
    fields_w[3] = list_to_pair([symbol('NB-ARGS'), W_Integer(w_func.nb_args),
                                w_boolean(w_func.has_vararg)])
    fields_w[4] = list_to_pair([symbol('NB-LOCALS'),
                                W_Integer(w_func.nb_locals)])
    upval_descrs_w = [None] * (len(w_func.upval_descrs) >> 1)
    i = 0
    while i < len(w_func.upval_descrs):
        c0, c1 = w_func.upval_descrs[i], w_func.upval_descrs[i + 1]
        upval_descrs_w[i >> 1] = list_to_pair([W_Integer(ord(c0)),
                                               W_Integer(ord(c1))])
        i += 2
    #
    w_upval_descrs = list_to_pair(upval_descrs_w[:])
    fields_w[5] = list_to_pair([symbol('UPVAL-DESCRS'), w_upval_descrs])
    w_consts = list_to_pair(w_func.consts_w[:])
    fields_w[6] = list_to_pair([symbol('CONSTS'), w_consts])
    w_names = list_to_pair(w_func.names_w[:])
    fields_w[7] = list_to_pair([symbol('NAMES'), w_names])
    functions_w = [dump_bytecode_function(w_function)
                   for w_function in w_func.functions_w]
    w_functions = list_to_pair(functions_w[:])
    fields_w[8] = list_to_pair([symbol('FUNCTIONS'), w_functions])
    return list_to_pair(fields_w)
예제 #4
0
파일: ffi.py 프로젝트: overminder/YASI
 def call(self, args_w):
     assert len(args_w) == len(self.argtypes_w)
     argchain = ArgChain()
     buffers = []
     for i in xrange(len(args_w)):
         w_arg = args_w[i]
         assert isinstance(w_arg, self.argtypes_w[i])
         if isinstance(w_arg, W_Integer):
             argchain.arg(w_arg.ival)
         elif isinstance(w_arg, W_Symbol):
             sval = w_arg.sval
             assert sval is not None
             charp = rffi.str2charp(sval)
             buffers.append(charp)
             argchain.arg(charp)
         elif isinstance(w_arg, W_String):
             sval = w_arg.content()
             assert sval is not None
             charp = rffi.str2charp(sval)
             buffers.append(charp)
             argchain.arg(charp)
         elif isinstance(w_arg, W_Boolean):
             argchain.arg(w_arg.to_bool())
         else:
             assert 0, 'unsupported argument type'
     res = self.funcptr.call(argchain, rffi.LONG) # annotate type to LONG
     for charp in buffers:
         rffi.free_charp(charp)
     #
     if self.w_restype is W_Integer:
         w_retval = W_Integer(rffi.cast(rffi.LONG, res))
     elif self.w_restype is W_Boolean:
         w_retval = w_boolean(rffi.cast(rffi.LONG, res))
     elif self.w_restype is W_Symbol:
         # XXX who delete the returned pointer?
         w_retval = symbol(rffi.charp2str(rffi.cast(rffi.CCHARP, res)))
     elif self.w_restype is W_String:
         w_retval = W_String(rffi.charp2str(rffi.cast(rffi.CCHARP, res)))
     elif self.w_restype is W_Unspecified:
         w_retval = w_unspec
     else:
         assert 0, 'unsupported result type'
     return w_retval
예제 #5
0
def dump_bytecode_function(w_func):
    assert isinstance(w_func, W_BytecodeFunction)
    fields_w = [None] * 9
    fields_w[0] = symbol('BYTECODE-FUNCTION')
    fields_w[1] = list_to_pair([symbol('NAME'), symbol(w_func.name)])
    #
    code_w = [None] * len(w_func.code)
    for i in xrange(len(code_w)):
        code_w[i] = W_Integer(ord(w_func.code[i]))
    w_code = list_to_pair(code_w)
    fields_w[2] = list_to_pair([symbol('CODE'), w_code])
    fields_w[3] = list_to_pair([
        symbol('NB-ARGS'),
        W_Integer(w_func.nb_args),
        w_boolean(w_func.has_vararg)
    ])
    fields_w[4] = list_to_pair(
        [symbol('NB-LOCALS'), W_Integer(w_func.nb_locals)])
    upval_descrs_w = [None] * (len(w_func.upval_descrs) >> 1)
    i = 0
    while i < len(w_func.upval_descrs):
        c0, c1 = w_func.upval_descrs[i], w_func.upval_descrs[i + 1]
        upval_descrs_w[i >> 1] = list_to_pair(
            [W_Integer(ord(c0)), W_Integer(ord(c1))])
        i += 2
    #
    w_upval_descrs = list_to_pair(upval_descrs_w[:])
    fields_w[5] = list_to_pair([symbol('UPVAL-DESCRS'), w_upval_descrs])
    w_consts = list_to_pair(w_func.consts_w[:])
    fields_w[6] = list_to_pair([symbol('CONSTS'), w_consts])
    w_names = list_to_pair(w_func.names_w[:])
    fields_w[7] = list_to_pair([symbol('NAMES'), w_names])
    functions_w = [
        dump_bytecode_function(w_function) for w_function in w_func.functions_w
    ]
    w_functions = list_to_pair(functions_w[:])
    fields_w[8] = list_to_pair([symbol('FUNCTIONS'), w_functions])
    return list_to_pair(fields_w)
예제 #6
0
파일: prelude.py 프로젝트: overminder/YASI
 def call(self, args_w):
     assert len(args_w) == 1
     w_arg, = args_w
     return w_boolean(isinstance(w_arg, W_Boolean))
예제 #7
0
파일: prelude.py 프로젝트: overminder/YASI
 def call(self, args_w):
     assert len(args_w) == 1
     w_arg, = args_w
     return w_boolean(w_arg.is_null())
예제 #8
0
파일: prelude.py 프로젝트: overminder/YASI
 def call(self, args_w):
     assert len(args_w) == 1
     w_arg, = args_w
     return w_boolean(isinstance(w_arg, W_Boolean))
예제 #9
0
파일: prelude.py 프로젝트: overminder/YASI
 def call(self, args_w):
     assert len(args_w) == 1
     w_arg, = args_w
     return w_boolean(w_arg.is_null())