Exemple #1
0
def func_range(a, b, step=1):
    if not (compare_type(a, INTEGER_TYPE) and compare_type(b, INTEGER_TYPE)) \
            and compare_type(step, INTEGER_TYPE):

        return AILRuntimeError('a and b must be an integer!')

    va = unpack_ailobj(a)
    vb = unpack_ailobj(b)
    vs = unpack_ailobj(step)

    if va > vb:
        return convert_to_array([])
    return convert_to_array(list(range(va, vb, vs)))
Exemple #2
0
def throw_error(msg, etype=None):
    now_f = MAIN_INTERPRETER_STATE.frame_stack[-1]
    where = now_f.code.name

    msg = unpack_ailobj(msg)
    if type is not None:
        etype = unpack_ailobj(etype)

    if not (type(msg) == type(etype) == str):
        return AILRuntimeError('throw() needs 1 or 2 string as arguments.')

    erro = AILRuntimeError(msg, etype, now_f)

    MAIN_INTERPRETER_STATE.err_stack.append(make_err_struct_object(
        erro, where))
Exemple #3
0
def func_int(obj):
    v = objs.unpack_ailobj(obj)

    try:
        return int(v)
    except Exception as e:
        return AILRuntimeError(str(e), 'PythonError')
Exemple #4
0
def _open(fp, mode):
    fp = unpack_ailobj(fp)
    mode = unpack_ailobj(mode)

    if not (type(fp) == type(mode) == str):
        return AILRuntimeError('open() needs 2 string as argument')

    try:
        iobuf = open(fp, mode)
    except FileNotFoundError:
        return null
    except OSError as e:
        return AILRuntimeError(str(e), 'OSError')
    except Exception as e:
        return AILRuntimeError(str(e), 'RuntimeError')

    return _convert_to_iobuffer(iobuf)
Exemple #5
0
def print_all_error(exit=False, exit_code=1):
    es = MAIN_INTERPRETER_STATE.err_stack[::-1]

    for e in es:
        eo = convert_to_pyobj(e)
        print(unpack_ailobj(eo.__this_to_string)(e))

    if exit:
        sys.exit(exit_code)
Exemple #6
0
def _sys_exit(_, code):
    if not compare_type(code, INTEGER_TYPE):
        return AILRuntimeError('exit() needs an integer.')

    c = unpack_ailobj(code)

    import sys
    try:
        sys.exit(c)
    except Exception as e:
        return AILRuntimeError(str(e), 'PythonError')
Exemple #7
0
def _peek(this, size):
    this = convert_to_pyobj(this)
    size = unpack_ailobj(size)

    if type(size) != int:
        return AILRuntimeError('iobuffer.peek() needs an integer.')

    try:
        return this.__this___buffer.peek(size)
    except Exception as e:
        return AILRuntimeError(str(e), 'PythonError')
Exemple #8
0
def _write(this, string):
    this = convert_to_pyobj(this)
    string = unpack_ailobj(string)
    buf = this.__this___buffer

    if type(string) != str:
        return AILRuntimeError('iobuffer.write() needs a string.')

    try:
        if not buf.writable():
            return AILRuntimeError('not writeable', 'OSError')

        return buf.write(string)
    except Exception as e:
        return AILRuntimeError(str(e), 'PythonError')
Exemple #9
0
def _read(this, size):
    this = convert_to_pyobj(this)
    size = unpack_ailobj(size)
    buf = this.__this___buffer

    if type(size) != int:
        return AILRuntimeError('iobuffer.read() needs an integer.')

    try:
        if not buf.readable():
            return AILRuntimeError('not readable', 'OSError')

        return buf.read(size)
    except Exception as e:
        return AILRuntimeError(str(e), 'PythonError')