Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ianj-als/pcl.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Johnson <ian.johnson@appliedlanguage.com>2013-11-12 15:04:51 +0400
committerIan Johnson <ian.johnson@appliedlanguage.com>2013-11-12 15:04:51 +0400
commit038f4f8fb7e76e339605fb5f6a40cf30eb7548c8 (patch)
treef7e0f8b7376096c9ab865da4197391599d1ce923
parent2ae9ba3bb777d43f83f87d023eacbfb61d245a02 (diff)
Now with all changes. Code generation for let commands now working.
-rw-r--r--src/pclc/parser/command.py5
-rw-r--r--src/pclc/visitors/do_executor_visitor.py39
2 files changed, 28 insertions, 16 deletions
diff --git a/src/pclc/parser/command.py b/src/pclc/parser/command.py
index 3fe1bcc..9fc074b 100644
--- a/src/pclc/parser/command.py
+++ b/src/pclc/parser/command.py
@@ -208,8 +208,9 @@ class LetCommand(Entity, ResolutionSymbols):
binding.accept(visitor)
class LetEnd(Entity):
- def __init__(self, filename, lineno):
+ def __init__(self, filename, lineno, let_command):
Entity.__init__(self, filename, lineno)
+ self.let_command = let_command
def accept(self, visitor):
visitor.visit(self)
@@ -225,7 +226,7 @@ class LetCommand(Entity, ResolutionSymbols):
self.identifier = identifier
self.bindings = LetCommand.LetBindings(filename, bindings[0].lineno, bindings)
self.expression = expression
- self.let_end = LetCommand.LetEnd(filename, expression.lineno)
+ self.let_end = LetCommand.LetEnd(filename, expression.lineno, self)
def accept(self, visitor):
visitor.visit(self)
diff --git a/src/pclc/visitors/do_executor_visitor.py b/src/pclc/visitors/do_executor_visitor.py
index e163209..1e2d345 100644
--- a/src/pclc/visitors/do_executor_visitor.py
+++ b/src/pclc/visitors/do_executor_visitor.py
@@ -49,6 +49,13 @@ class IntermediateRepresentation(object):
def add_child(self, node):
raise NotImplementedError
+ class IRFunctionNode(IRNode):
+ def __init__(self, pt_object, parent):
+ IntermediateRepresentation.IRNode.__init__(self, pt_object, parent)
+
+ def add_child(self, node):
+ pass
+
class IRCommandNode(IRNode):
def __init__(self, pt_object, parent):
IntermediateRepresentation.IRNode.__init__(self, pt_object, parent)
@@ -140,7 +147,9 @@ class IntermediateRepresentation(object):
self.__current_node = node
self.__current_let = node
- def mark_let_end(self):
+ def mark_let_end(self, let_expression_function):
+ node = IntermediateRepresentation.IRFunctionNode(let_expression_function, self.__current_node)
+ self.__current_node.add_child(node)
self.__current_node = self.__current_let.parent
self.__current_let = None
@@ -164,7 +173,19 @@ class IntermediateRepresentation(object):
def __generate_code(self, node, generate_function_call, executor_visitor, is_instrumented):
code = list()
- if isinstance(node, IntermediateRepresentation.IRCommandNode):
+ if isinstance(node, IntermediateRepresentation.IRFunctionNode):
+ # Currently, this is *only* used for let expressions
+ function = node.object
+ scope = function['scope']
+
+ if is_instrumented:
+ code.append(("____instr_command_begin('%s', %d, '%s', a, s)" % (function.filename, function.lineno, function), ""))
+
+ tmp_var = executor_visitor._get_temp_var(function)
+ code.append(("%s = %s" % (tmp_var,
+ generate_function_call(function, scope)), ""))
+ code.append(("return %s" % tmp_var, ""))
+ elif isinstance(node, IntermediateRepresentation.IRCommandNode):
# Command action code generation
command = node.object
scope = command['scope']
@@ -238,7 +259,6 @@ class IntermediateRepresentation(object):
# Let command
let_command = node.object
- code.append(("# LET", ""))
code.append(("def %s(a, s):" % self.__get_function_name(let_command), "+"))
for binding in node.bindings:
@@ -248,16 +268,7 @@ class IntermediateRepresentation(object):
is_instrumented)
code.extend(more_code)
- #more_code = self.__generate_code(node.expression,
- # generate_function_call,
- # executor_visitor,
- # is_instrumented)
- code.append(("%s = %s" % (executor_visitor._get_temp_var(let_command.expression), \
- generate_function_call(let_command.expression,
- let_command.expression['scope'])), ""))
- code.append(("return %s" % executor_visitor._lookup_var(let_command.expression), ""))
-
- code.extend([(None, "-"), (None, "-")])
+ code.append((None, "-"))
if let_command.identifier:
code.append(("%s = %s(a, s)" % (executor_visitor._get_temp_var(let_command.identifier), \
self.__lookup_function_name(let_command)), ""))
@@ -374,7 +385,7 @@ class DoExecutorVisitor(ExecutorVisitor):
@multimethod(LetCommand.LetEnd)
def visit(self, let_end):
- self.__ir.mark_let_end()
+ self.__ir.mark_let_end(let_end.let_command.expression)
@multimethod(AndConditionalExpression)
def visit(self, and_cond_expr):