Ejemplo n.º 1
0
def repl(prompt=u'haiku> '):
  "A read-eval-print loop for haiku."
  canonical   = CanonicalExpressionPickler()
  simple      = SimpleExpressionPickler()
  interpreter = BaseInterpreter(pickler=simple, environment=globalEnvironment)

  while True:
    try:
      expression = interpreter.read(raw_input(prompt))
    except EOFError:
      sys.stdout.write('\n'); return 0
    except KeyboardInterrupt:
      sys.stdout.write('\n'); continue
    except Exception, e:
      traceback.print_exc();  continue

    try:
      result = interpreter.evaluate(expression)
      print u"INPUT:  %s" % canonical.dumps(*expression).encode('string_escape')
      print u"DEBUG:  %s" % Unicode(expression)
      print u"RESULT: %s" % Unicode(result)
      print u"OUTPUT: %s" % simple.dumps(result)[1:-1]
    except Exception, e:
      traceback.print_exc(); continue
Ejemplo n.º 2
0
from haiku.pickle import CanonicalExpressionPickler
from haiku.types import *
__all__ = []

# ===----------------------------------------------------------------------===

pickler = CanonicalExpressionPickler()

_pickle, _unpickle = map(Symbol,
'pickle   unpickle'.split())

pickle = Procedure(
  params      = Tuple([(1, AlphaCompatible)]),
  defaults    = Tuple(),
  ellipsis    = False,
  environment = builtinEnvironment,
  body        = lambda eval_,env:pickler.dumps(env[1]),
)

unpickle = Procedure(
  params      = Tuple([(1, SymbolCompatible)]),
  defaults    = Tuple(),
  ellipsis    = False,
  environment = builtinEnvironment,
  body        = lambda eval_,env:pickler.loads(env[1]),
)

# ===----------------------------------------------------------------------===
# End of File
# ===----------------------------------------------------------------------===