Example #1
0
parser.add_argument('-d', '--debug', type = int, default = 0,
                    help='set debug level')

parser.add_argument('-i', '--interactive', action = 'store_true',
                    help='execute REPL after script completion')

parser.add_argument('-o', '--optimize', type = int, default = 2,
                    help='optimization level')


args = parser.parse_args()

tool.DEBUG = args.debug

console = tool.console(history = '.history')

# command source
if args.filename:
    with open(args.filename) as f:
        source = [ f.read() ]

    if args.interactive:
        source = itertools.chain(source, console)
else:
    source = console


from hm import integer, string, real, boolean, unit, io, ref, lst

if args.codegen:
Example #2
0
def prelude():
    env = Environment()

    env['+'] = sum
    env['='] = lambda args: (lambda first: all(first == a for a in args))(next(args))
    env['-'] = lambda args: next(args) - sum(args)

    env['print'] = lambda args: print(*args)

    return env


# a small lisp repl
def repl(source):

    env = prelude()
    
    import parse
    for expr in parse.loop(source):
        with error.reporting():
            value = eval(env, expr)
            if value is not None:
                print( '::', type(value).__name__, '=', value )


if __name__ == '__main__':
    import tool
    
    repl(tool.console())