Skip to content

Commit

Permalink
Silly forwards to builtins
Browse files Browse the repository at this point in the history
  • Loading branch information
dlorch committed Nov 23, 2015
1 parent 06dae0c commit cc7ef86
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions pycep/analyzer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import ast

def parse(source):
# TODO: implement
node = ast.parse(source, mode='exec')
return node
10 changes: 8 additions & 2 deletions pycep/interpreter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import __builtin__
import pycep.analyzer

def execfile(filename):
def eval(expression):
node = pycep.analyzer.parse(expression)
# TODO: implement
return __builtin__.execfile(filename)
return __builtin__.eval(compile(node, '<string>', mode='exec'))

def execfile(filename):
program = "".join(open(filename).readlines())
return eval(program)
2 changes: 1 addition & 1 deletion pycep/tests/test_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
SAMPLE_PROGRAMS = path.abspath(path.join(path.dirname(__file__), "programs"))

class TestInterpreter(unittest.TestCase):

def test_helloworld(self):
filename = path.join(SAMPLE_PROGRAMS, "helloworld.py")
self.assertEquals(pycep.interpreter.execfile(filename), execfile(filename))

0 comments on commit cc7ef86

Please sign in to comment.