Adding in a Hy REPL
This commit is contained in:
parent
8a9ffa05ae
commit
ff37c47c43
27
TODO
27
TODO
@ -9,31 +9,36 @@
|
||||
|
||||
+ Use (def) to imply global foo
|
||||
|
||||
- New Builtins:
|
||||
- New Builtins:
|
||||
+ While
|
||||
|
||||
- New macros:
|
||||
+ Pass
|
||||
|
||||
- New macros:
|
||||
+ loop
|
||||
|
||||
- nREPL type thing:
|
||||
- nREPL type thing:
|
||||
+ SocketIO endpoint
|
||||
+ Socket endpoint
|
||||
+ hyde (hy-dee-e - thanks arno)
|
||||
|
||||
- Builtin type checking (@params(HyExpression, HyList, HyExpression))
|
||||
- Builtin type checking (@params(HyExpression, HyList, HyExpression))
|
||||
|
||||
- Better Exception handling
|
||||
- Better Exception handling
|
||||
+ linenos in the dump
|
||||
+ except IOError as E: # <-- implement
|
||||
|
||||
- Tuples
|
||||
- Tuples
|
||||
|
||||
- List / Dict comprehensions
|
||||
- List / Dict comprehensions
|
||||
|
||||
- var-arity [x y & z]
|
||||
- var-arity [x y & z]
|
||||
|
||||
- car / cdr / first / rest
|
||||
- car / cdr / first / rest
|
||||
|
||||
- hyrepl
|
||||
- hyrepl
|
||||
|
||||
- pyc compiler
|
||||
- pyc compiler
|
||||
|
||||
- core tests (odd? even? true? false?) which
|
||||
build out to a lambda / function / expr
|
||||
|
44
bin/hy
44
bin/hy
@ -1,6 +1,46 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from hy.importer import import_file_to_module
|
||||
import sys
|
||||
import ast
|
||||
import code
|
||||
import readline
|
||||
from hy.lex.states import Idle, LexException
|
||||
from hy.lex.machine import Machine
|
||||
from hy.compiler import hy_compile
|
||||
from hy.core import process
|
||||
|
||||
import_file_to_module("<STDIN>", sys.argv[1])
|
||||
_machine = Machine(Idle, 1, 0)
|
||||
|
||||
|
||||
class HyREPL(code.InteractiveConsole):
|
||||
def runsource(self, source, filename='<input>', symbol='single'):
|
||||
global _machine
|
||||
|
||||
try:
|
||||
_machine.process(source + "\n")
|
||||
except LexException as e:
|
||||
_machine = Machine(Idle, 1, 0)
|
||||
self.showsyntaxerror(filename)
|
||||
return False
|
||||
|
||||
if type(_machine.state) != Idle:
|
||||
_machine = Machine(Idle, 1, 0)
|
||||
return True
|
||||
|
||||
tokens = process(_machine.nodes)
|
||||
|
||||
_machine = Machine(Idle, 1, 0)
|
||||
_ast = hy_compile(tokens, root=ast.Interactive)
|
||||
code = compile(_ast, filename, symbol)
|
||||
|
||||
self.runcode(code)
|
||||
return False
|
||||
|
||||
sys.ps1 = "=> "
|
||||
sys.ps2 = "... "
|
||||
|
||||
hr = HyREPL()
|
||||
hr.interact("""
|
||||
Hi! Welcome to Hy!
|
||||
|
||||
""")
|
||||
|
@ -507,8 +507,11 @@ class HyASTCompiler(object):
|
||||
values=vals)
|
||||
|
||||
|
||||
def hy_compile(tree):
|
||||
def hy_compile(tree, root=None):
|
||||
" Compile a HyObject tree into a Python AST tree. "
|
||||
compiler = HyASTCompiler()
|
||||
ret = ast.Module(body=compiler._mangle_branch(compiler.compile(tree)))
|
||||
tlo = root
|
||||
if root is None:
|
||||
tlo = ast.Module
|
||||
ret = tlo(body=compiler._mangle_branch(compiler.compile(tree)))
|
||||
return ret
|
||||
|
Loading…
Reference in New Issue
Block a user