ideas, ideas.
This commit is contained in:
parent
4a78498133
commit
0638cfa187
@ -22,6 +22,7 @@ from hy.errors import HyError
|
||||
|
||||
from hy.models.expression import HyExpression
|
||||
from hy.models.symbol import HySymbol
|
||||
from hy.models.integer import HyInteger
|
||||
from hy.models.string import HyString
|
||||
|
||||
import ast
|
||||
@ -84,7 +85,7 @@ class HyASTCompiler(object):
|
||||
@builds("/")
|
||||
@builds("*")
|
||||
def compile_maths_expression(self, expression):
|
||||
# operator = Mod | Pow | LShift | RShift | BitOr |
|
||||
# operator = Mod | Pow | LShift | RShift | BitOr |
|
||||
# BitXor | BitAnd | FloorDiv
|
||||
# (to implement list) XXX
|
||||
|
||||
@ -175,6 +176,12 @@ class HyASTCompiler(object):
|
||||
self.returnable = ret_status
|
||||
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)
|
||||
def compile_symbol(self, symbol):
|
||||
return ast.Name(id=str(symbol), ctx=ast.Load(),
|
||||
|
@ -87,12 +87,14 @@ class Machine(object):
|
||||
if self.submachine:
|
||||
self.submachine.process([char])
|
||||
if type(self.submachine.state) == Idle:
|
||||
if len(self.submachine.nodes) != 1:
|
||||
if len(self.submachine.nodes) > 1:
|
||||
raise LexException("Funky Submachine stuff")
|
||||
result = self.submachine.nodes[0]
|
||||
|
||||
nodes = self.submachine.nodes
|
||||
self.submachine = None
|
||||
if result:
|
||||
self.state.nodes.append(result)
|
||||
|
||||
if len(nodes) > 0:
|
||||
self.state.nodes.append(nodes[0])
|
||||
continue
|
||||
|
||||
new = self.state.process(char)
|
||||
|
@ -120,7 +120,10 @@ class Expression(State):
|
||||
|
||||
def exit(self):
|
||||
self.commit()
|
||||
self.result = HyExpression(self.nodes)
|
||||
if self.nodes != []:
|
||||
self.result = HyExpression(self.nodes)
|
||||
else:
|
||||
self.result = None
|
||||
|
||||
def process(self, char):
|
||||
"""
|
||||
|
@ -0,0 +1,4 @@
|
||||
#
|
||||
|
||||
import hy
|
||||
from .native_tests.math import *
|
0
tests/native_tests/__init__.hy
Normal file
0
tests/native_tests/__init__.hy
Normal file
5
tests/native_tests/math.hy
Normal file
5
tests/native_tests/math.hy
Normal file
@ -0,0 +1,5 @@
|
||||
; copyright ..
|
||||
|
||||
|
||||
(def test_basic_math (fn ()
|
||||
(assert (+ 2 2) 4)))
|
Loading…
Reference in New Issue
Block a user