Пример #1
0
def test_signatures():
   a = mopen('blaze.mod')
   print "Module".center(80, '=')
   print a.show()
Пример #2
0
def test_adhoc():
    a = mopen('blaze.mod')

    ty = ('Array', [('t', 'int')])
    over = a.resolve_adhoc('add', ty)
Пример #3
0
    '__lt__': fail_implicit('<'),
    '__ge__': fail_implicit('>='),
    '__le__': fail_implicit('<='),
    '__eq__': fail_implicit('=='),
    '__ne__': fail_implicit('!='),
}

implicit_unops = {
    '__nonzero__': partial(fail_implicit, 'not'),
}

#------------------------------------------------------------------------
# Prelude
#------------------------------------------------------------------------

core = mopen('blaze.mod')

pysorts = {
    'int': 'int',
    'float': 'float',
    'complex': 'complex',
    'index': 'tuple',
    'bool': 'bool',
    'any': 'object',
}


def build_bound_meth(ctx, name, sig):
    def method(self, *args, **kw):
        # since we're bound splice the domain at the
        # first domain element
Пример #4
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('module', nargs='?', help='Module')
    parser.add_argument('--noprelude', action='store_true', help='Include prelude')
    parser.add_argument('--ddump-mod', action='store_true', help='Dump module tree')
    args = parser.parse_args()

    mod = None

    if args.module:
        mod = mopen(args.module)
    else:
        print 'No module specified?'
        sys.exit(0)

    if not args.noprelude:
        pass

    readline.parse_and_bind("tab: complete")
    readline.set_completer(partial(completer, mod))

    while True:
        try:
            line = raw_input('>> ').strip()
        except EOFError:
            break

        #-----------------------------------------------
        if line.startswith(':show') or line.startswith(':s'):
            try:
                rr = mod[line[1:].strip()]
                print rr
            except KeyError:
                print "No such rule or strategy '%s'" % line[1:]

        #-----------------------------------------------
        elif line.startswith(':type') or line.startswith(':t'):
            pass

        elif line.startswith(':reload') or line.startswith(':r'):
            print "Reloading".center(80, '=')
            mod = mopen(args.module)

        #-----------------------------------------------
        elif line.startswith(':let'):
            pass

        #-----------------------------------------------
        elif line.startswith(':load'):
            pass

        #-----------------------------------------------
        elif line.startswith(':browse'):
            pass

        #-----------------------------------------------
        elif line.startswith(':help'):
            print help
            pass

        #-----------------------------------------------
        elif line.startswith(':bound'):
            head = line.split()[1]
            cls = mod.resolve_bound(head)

            for name, sig in cls:
                print '\t', name, '::', sig

        elif line.startswith(':adhoc'):
            fn = line.split()[1]

            try:
                cls = mod.anon_refs[fn]

                for name, sig in cls:
                    print '\t', name, '::', sig
            except KeyError:
                print 'No definition'

        else:
            pass
Пример #5
0
implicit_binops = {
    "__gt__": fail_implicit(">"),
    "__lt__": fail_implicit("<"),
    "__ge__": fail_implicit(">="),
    "__le__": fail_implicit("<="),
    "__eq__": fail_implicit("=="),
    "__ne__": fail_implicit("!="),
}

implicit_unops = {"__nonzero__": partial(fail_implicit, "not")}

# ------------------------------------------------------------------------
# Prelude
# ------------------------------------------------------------------------

core = mopen("blaze.mod")

pysorts = {"int": "int", "float": "float", "complex": "complex", "index": "tuple", "bool": "bool", "any": "object"}


def build_bound_meth(ctx, name, sig):
    def method(self, *args, **kw):
        # since we're bound splice the domain at the
        # first domain element
        adom, bdom = sig.dom[0], sig.dom[1:]
        saturated = len(bdom) == len(args)

        # resolve the codomain of the signature it terms
        # of the proxy _ty variables
        if saturated:
            outsig = instantiate(ctx, sig)
Пример #6
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('module', nargs='?', help='Module')
    parser.add_argument('--noprelude',
                        action='store_true',
                        help='Include prelude')
    parser.add_argument('--ddump-mod',
                        action='store_true',
                        help='Dump module tree')
    args = parser.parse_args()

    mod = None

    if args.module:
        mod = mopen(args.module)
    else:
        print 'No module specified?'
        sys.exit(0)

    if not args.noprelude:
        pass

    readline.parse_and_bind("tab: complete")
    readline.set_completer(partial(completer, mod))

    while True:
        try:
            line = raw_input('>> ').strip()
        except EOFError:
            break

        #-----------------------------------------------
        if line.startswith(':show') or line.startswith(':s'):
            try:
                rr = mod[line[1:].strip()]
                print rr
            except KeyError:
                print "No such rule or strategy '%s'" % line[1:]

        #-----------------------------------------------
        elif line.startswith(':type') or line.startswith(':t'):
            pass

        elif line.startswith(':reload') or line.startswith(':r'):
            print "Reloading".center(80, '=')
            mod = mopen(args.module)

        #-----------------------------------------------
        elif line.startswith(':let'):
            pass

        #-----------------------------------------------
        elif line.startswith(':load'):
            pass

        #-----------------------------------------------
        elif line.startswith(':browse'):
            pass

        #-----------------------------------------------
        elif line.startswith(':help'):
            print help
            pass

        #-----------------------------------------------
        elif line.startswith(':bound'):
            head = line.split()[1]
            cls = mod.resolve_bound(head)

            for name, sig in cls:
                print '\t', name, '::', sig

        elif line.startswith(':adhoc'):
            fn = line.split()[1]

            try:
                cls = mod.anon_refs[fn]

                for name, sig in cls:
                    print '\t', name, '::', sig
            except KeyError:
                print 'No definition'

        else:
            pass
Пример #7
0
    '__lt__' : fail_implicit('<'),
    '__ge__' : fail_implicit('>='),
    '__le__' : fail_implicit('<='),
    '__eq__' : fail_implicit('=='),
    '__ne__' : fail_implicit('!='),
}

implicit_unops = {
    '__nonzero__' : partial(fail_implicit, 'not'),
}

#------------------------------------------------------------------------
# Prelude
#------------------------------------------------------------------------

core = mopen('blaze.mod')

pysorts = {
    'int'     : 'int',
    'float'   : 'float',
    'complex' : 'complex',
    'index'   : 'tuple',
    'bool'    : 'bool',
    'any'     : 'object',
}

def build_bound_meth(ctx, name, sig):
    def method(self, *args, **kw):
        # since we're bound splice the domain at the
        # first domain element
        adom, bdom = sig.dom[0], sig.dom[1:]