예제 #1
0
파일: test_add.py 프로젝트: Delaunay/Kiwi
def main():
    import sys
    sys.stderr = sys.stdout

    ctx = make_scope()
    builder = AstBuilder(ctx)

    function_test_add(builder, ctx)
예제 #2
0
파일: test_trace.py 프로젝트: Delaunay/Kiwi
def main():
    import sys
    sys.stderr = sys.stdout

    from kiwi.print import to_string
    from kiwi.builder import AstBuilder
    from kiwi.builtin import make_scope

    ctx = make_scope()
    builder = AstBuilder(ctx)
    float_type = builder.reference('Float')

    # Make the Add Function
    fun = builder.function()
    fun.args([('x', None), ('y', None)])
    fun.return_type = None

    body = fun.unary_operator(
        fun.reference('return'),
        fun.binary_operator(fun.reference('+'), fun.reference('x'),
                            fun.reference('y')))

    fun.body(body)

    fun = fun.make()
    builder.bind('add', fun)
    # Done

    # Make a Call to `add`
    add_fun = builder.reference('add')
    two = builder.call(
        add_fun, [builder.value(1, float_type),
                  builder.value(2, float_type)])
    # Done

    # ctx.dump()

    print('-' * 80)
    no_types = to_string(fun, ctx)

    print('-' * 80)
    result = type_trace(two, ctx)
    #result = type_trace(fun, ctx)

    print('-' * 80)
    fun_str = to_string(fun, ctx)
    print('-' * 80)
    print('   User Input: ', no_types)
    print('Deduced Types: ', fun_str)
    print('       Result: ', result[1])
예제 #3
0
def main():
    import sys
    sys.stderr = sys.stdout
    from kiwi.print import to_string
    from kiwi.type.deduce import type_deduce

    ctx = make_scope()
    builder = AstBuilder(ctx)
    fun = function_test_add_def(builder)

    type_deduce(fun, ctx)

    print(to_string(fun, ctx))
    print(to_string(fun, ctx))
    print(to_string(fun.type, ctx))
예제 #4
0
def main():
    import sys
    sys.stderr = sys.stdout

    from kiwi.print import to_string
    from kiwi.builder import AstBuilder
    from kiwi.builtin import make_scope
    from kiwi.test_add import function_test_add_def

    ctx = make_scope()
    builder = AstBuilder(ctx)

    float_type = builder.reference('Float')

    bind = function_test_add_def(builder, return_bind=True)

    two = builder.call(
        bind.expr,
        [builder.value(1, float_type),
         builder.value(2, float_type)])

    original = to_string(bind)

    print('-' * 80)
    type_trace(two, ctx)
    print('-' * 80)
    new = to_string(bind)
    print('-' * 80)
    ftype = to_string(bind.expr.type)

    print('-' * 80)
    print(original)
    print('\nAfter Inference:')
    print('-----------------')
    print(new)
    print()
    print('Fun Type: {}'.format(ftype))
    print('-' * 80)

    module = ir.Module(name='test')
    r = llvm_codegen(module, ctx, bind)

    print('-' * 80)
    print(r)
    print('-' * 80)
    print(module)
    print('-' * 80)
예제 #5
0
from kiwi.expressions import *
from kiwi.builder import AstBuilder
from kiwi.builtin import make_scope
from kiwi.interpreter import keval
from kiwi.type.trace import type_trace
from kiwi.codegen.ir import llvm_codegen

from kiwi.print import to_string
from llvmlite import ir

ctx = make_scope()
builder = AstBuilder(ctx)

ftype = builder.reference('Float')
itype = builder.reference('Int')


def make_var(builder, name, type_name) -> Expression:
    variable_fun = builder.reference('variable')
    symbol_type = builder.reference('Symbol')

    return builder.call(
        variable_fun,
        [builder.value(name, symbol_type),
         builder.reference(type_name)])


def union_test_make(builder: AstBuilder):
    union_fun = builder.reference('union')
    return builder.call(
        union_fun,