ideas, ideas.

This commit is contained in:
Paul Tagliamonte 2013-03-05 18:39:34 -05:00
parent 4a78498133
commit 0638cfa187
7 changed files with 34 additions and 6 deletions

View File

@ -22,6 +22,7 @@ from hy.errors import HyError
from hy.models.expression import HyExpression from hy.models.expression import HyExpression
from hy.models.symbol import HySymbol from hy.models.symbol import HySymbol
from hy.models.integer import HyInteger
from hy.models.string import HyString from hy.models.string import HyString
import ast import ast
@ -175,6 +176,12 @@ class HyASTCompiler(object):
self.returnable = ret_status self.returnable = ret_status
return ret return ret
@builds(HyInteger)
def compile_number(self, number):
return ast.Num(n=number,
lineno=number.start_line,
col_offset=number.start_column)
@builds(HySymbol) @builds(HySymbol)
def compile_symbol(self, symbol): def compile_symbol(self, symbol):
return ast.Name(id=str(symbol), ctx=ast.Load(), return ast.Name(id=str(symbol), ctx=ast.Load(),

View File

@ -87,12 +87,14 @@ class Machine(object):
if self.submachine: if self.submachine:
self.submachine.process([char]) self.submachine.process([char])
if type(self.submachine.state) == Idle: if type(self.submachine.state) == Idle:
if len(self.submachine.nodes) != 1: if len(self.submachine.nodes) > 1:
raise LexException("Funky Submachine stuff") raise LexException("Funky Submachine stuff")
result = self.submachine.nodes[0]
nodes = self.submachine.nodes
self.submachine = None self.submachine = None
if result:
self.state.nodes.append(result) if len(nodes) > 0:
self.state.nodes.append(nodes[0])
continue continue
new = self.state.process(char) new = self.state.process(char)

View File

@ -120,7 +120,10 @@ class Expression(State):
def exit(self): def exit(self):
self.commit() self.commit()
self.result = HyExpression(self.nodes) if self.nodes != []:
self.result = HyExpression(self.nodes)
else:
self.result = None
def process(self, char): def process(self, char):
""" """

View File

@ -0,0 +1,4 @@
#
import hy
from .native_tests.math import *

View File

View File

@ -0,0 +1,5 @@
; copyright ..
(def test_basic_math (fn ()
(assert (+ 2 2) 4)))

7
tox.ini Normal file
View File

@ -0,0 +1,7 @@
[tox]
envlist = py27,pypy,py32
[testenv]
commands = nosetests
deps =
nose
setuptools