Beispiel #1
0
def Module(name,directives_star):
    assert(isinstance(name,Interpreter.InAtom))
    assert(isinstance(directives_star,Interpreter.InAtom))

    Utils.testSymbol(name,'Module')

    directives = Utils.argStarAsList(directives_star)

    c_type = Interpreter.Symbol('Type')
    c_define = Interpreter.Symbol('Define')
    c_import = Interpreter.Symbol('Import')
    c_export = Interpreter.Symbol('Export')

    defines = {}
    imports = {}
    exports = []

    for directive in directives:
        t = directive.get(c_type)

        if t == c_define:
            defines[directive.get(Interpreter.Symbol('Name')).value] = directive.get(Interpreter.Symbol('Value'))
        elif t == c_import:
            imports[directive.get(Interpreter.Symbol('Module'))] = \
                (directive.get(Interpreter.Symbol('As')).value,
                 map(lambda x: x.value,Utils.argStarAsList(directive.get(Interpreter.Symbol('Names')))))
        elif t == c_export:
            exports.extend(map(lambda x: x.value,Utils.argStarAsList(directive.get(Interpreter.Symbol('Names')))))
        else:
            raise Exception('Invalid module directive type!')

    return Application.Module(name.value,defines,imports,exports)
Beispiel #2
0
def buildArray(l):
    assert (isinstance(l, list))
    assert (all(map(lambda x: isinstance(x, Interpreter.InAtom), l)))

    kvs = [(Interpreter.Symbol('Length'), Interpreter.Number(len(l)))]

    for i in range(0, len(l)):
        kvs.append((Interpreter.Number(float(i)), l[i]))

    return Interpreter.Dict(kvs)
Beispiel #3
0
def argStarAsList(arg_star):
    assert (isinstance(arg_star, Interpreter.Dict))

    length = arg_star.get(Interpreter.Symbol('Length'))
    assert (length)
    new_ls = []

    for i in range(0, length.value):
        new_item = arg_star.get(Interpreter.Number(i))
        assert (new_item)
        new_ls.append(new_item)

    return new_ls
Beispiel #4
0
def Type(x):
    assert(isinstance(x,Interpreter.InAtom))

    if Utils.isBoolean(x):
        return Interpreter.Symbol('Boolean')
    if Utils.isNumber(x):
        return Interpreter.Symbol('Number')
    if Utils.isSymbol(x):
        return Interpreter.Symbol('Symbol')
    if Utils.isString(x):
        return Interpreter.Symbol('String')
    if Utils.isFunc(x):
        return Interpreter.Symbol('Func')
    if Utils.isDict(x):
        return Interpreter.Symbol('Dict')

    raise Exception('Critical Error: Invalid control path!')