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-05-30 19:08:33 +0400
committerIan Johnson <ian.johnson@appliedlanguage.com>2013-06-03 16:37:26 +0400
commit5d7d222f39875c2247e799fb06a6693ce7ed5463 (patch)
tree796cb7160dea2b23fb9e26900d7b1266bc8eaf4e
parent4e51345cd6b405551ba327d91a7d905e204587b1 (diff)
Values are supported on the LHS of a wire mapping expression.
-rw-r--r--examples/debug_stubbing/parallel_component.pcl24
-rw-r--r--examples/debug_stubbing/sequential_component.pcl23
-rw-r--r--examples/debug_stubbing/stub_components.pcl35
-rw-r--r--src/pclc/parser/pcl_parser.py8
-rw-r--r--src/pclc/visitors/executor_visitor.py34
-rw-r--r--src/pclc/visitors/first_pass_resolver_visitor.py6
-rw-r--r--src/pclc/visitors/third_pass_resolver_visitor.py7
7 files changed, 117 insertions, 20 deletions
diff --git a/examples/debug_stubbing/parallel_component.pcl b/examples/debug_stubbing/parallel_component.pcl
new file mode 100644
index 0000000..7572fac
--- /dev/null
+++ b/examples/debug_stubbing/parallel_component.pcl
@@ -0,0 +1,24 @@
+#
+# Copyright Capita Translation and Interpreting 2013
+#
+# This file is part of Pipeline Creation Language (PCL).
+#
+# Pipeline Creation Language (PCL) is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Pipeline Creation Language (PCL) is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Pipeline Creation Language (PCL). If not, see <http://www.gnu.org/licenses/>.
+#
+component parallel_component
+ inputs (a, b), (c, d)
+ output (e, f), (g, h)
+ as
+ wire (a -> _, b -> _, 2.718 -> e, "Hello \"World\"" -> f),
+ (c -> _, d -> _, 6.674e-11 -> g, "Goodbye \"World\"" -> h)
diff --git a/examples/debug_stubbing/sequential_component.pcl b/examples/debug_stubbing/sequential_component.pcl
new file mode 100644
index 0000000..95b8238
--- /dev/null
+++ b/examples/debug_stubbing/sequential_component.pcl
@@ -0,0 +1,23 @@
+#
+# Copyright Capita Translation and Interpreting 2013
+#
+# This file is part of Pipeline Creation Language (PCL).
+#
+# Pipeline Creation Language (PCL) is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Pipeline Creation Language (PCL) is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Pipeline Creation Language (PCL). If not, see <http://www.gnu.org/licenses/>.
+#
+component sequential_component
+ inputs a, b
+ output c, d
+ as
+ wire a -> _, b -> _, True -> c, False -> d
diff --git a/examples/debug_stubbing/stub_components.pcl b/examples/debug_stubbing/stub_components.pcl
new file mode 100644
index 0000000..3900da9
--- /dev/null
+++ b/examples/debug_stubbing/stub_components.pcl
@@ -0,0 +1,35 @@
+#
+# Copyright Capita Translation and Interpreting 2013
+#
+# This file is part of Pipeline Creation Language (PCL).
+#
+# Pipeline Creation Language (PCL) is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Pipeline Creation Language (PCL) is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Pipeline Creation Language (PCL). If not, see <http://www.gnu.org/licenses/>.
+#
+import parallel_component as parallel
+import sequential_component as sequential
+
+component stub_component
+ inputs a
+ output a, seq_c, seq_d, para_e, para_f, para_h, para_h
+ declare
+ para := new parallel
+ seq := new sequential
+ as
+ wire a -> a &&&
+ ((wire a -> a, a -> b >>> seq) &&&
+ (split >>> wire (a -> a, a -> b), (a -> c, a -> d) >>> para >>> merge top[e] -> para_e, top[f] -> para_f,
+ bottom[g] -> para_g, bottom[h] -> para_h)) >>>
+ merge top[a] -> a,
+ bottom[seq_c] -> seq_c, bottom[seq_d] -> seq_d,
+ bottom[para_e] -> para_e, bottom[para_f] -> para_f, bottom[para_g] -> para_g, bottom[para_h] -> para_h
diff --git a/src/pclc/parser/pcl_parser.py b/src/pclc/parser/pcl_parser.py
index 68d245c..3c12c38 100644
--- a/src/pclc/parser/pcl_parser.py
+++ b/src/pclc/parser/pcl_parser.py
@@ -269,8 +269,12 @@ def p_wire_mappings(p):
p[0] = [p[1]]
def p_wire_mapping(p):
- '''wire_mapping : identifier_or_qual_identifier MAPS_TO identifier_or_qual_identifier'''
- p[0] = Mapping(p.parser.filename, p[1].lineno, p[1], p[3])
+ '''wire_mapping : identifier_or_qual_identifier MAPS_TO identifier_or_qual_identifier
+ | literal MAPS_TO identifier_or_qual_identifier'''
+ if isinstance(p[1], Literal):
+ p[0] = LiteralMapping(p.parser.filename, p[1].lineno, p[1], p[3])
+ else:
+ p[0] = Mapping(p.parser.filename, p[1].lineno, p[1], p[3])
def p_conditional_expression(p):
'''conditional_expression : or_conditional_expression'''
diff --git a/src/pclc/visitors/executor_visitor.py b/src/pclc/visitors/executor_visitor.py
index 27ac5a2..b37fe74 100644
--- a/src/pclc/visitors/executor_visitor.py
+++ b/src/pclc/visitors/executor_visitor.py
@@ -68,7 +68,7 @@ class ExecutorVisitor(object):
"# This file was automatically generated by PCLc on\n" \
"# %(datetime)s.\n" \
"#\n" \
- "from pypeline.helpers.parallel_helpers import cons_function_component, cons_wire, cons_dictionary_wire, cons_split_wire, cons_unsplit_wire, cons_if_component\n" \
+ "from pypeline.helpers.parallel_helpers import cons_function_component, cons_wire, cons_split_wire, cons_unsplit_wire, cons_if_component\n" \
"from pypeline.core.arrows.kleisli_arrow import KleisliArrow\n" \
"from pypeline.core.arrows.kleisli_arrow_choice import KleisliArrowChoice\n" \
"from pypeline.core.types.either import Left, Right\n" \
@@ -332,24 +332,28 @@ class ExecutorVisitor(object):
@multimethod(WireExpression)
def visit(self, wire_expr):
- self.__write_line("%s = cons_dictionary_wire({%s})" % \
+ dict_repr = ["'%s' : %s" % (m.to,
+ "a['%s']" % (m.from_) if isinstance(m, Mapping) \
+ else (m.literal.value.__repr__() if isinstance(m.literal.value, str) else m.literal)) \
+ for m in wire_expr.mapping \
+ if str(m.to) != '_']
+ self.__write_line("%s = cons_wire(lambda a, s: {%s})" % \
(self.__get_temp_var(wire_expr),
- ", ".join(["'%s' : '%s'" % \
- (m.from_, m.to) \
- for m in wire_expr.mapping \
- if str(m.to) != '_'])))
+ ", ".join(dict_repr)))
@multimethod(WireTupleExpression)
def visit(self, wire_tuple_expr):
- wire_fn = "lambda t, s: ({%s}, {%s})" % \
- (", ".join(["'%s' : t[0]['%s']" % \
- (m.to, m.from_) \
- for m in wire_tuple_expr.top_mapping \
- if str(m.to) != '_']), \
- ", ".join(["'%s' : t[1]['%s']" % \
- (m.to, m.from_) \
- for m in wire_tuple_expr.bottom_mapping \
- if str(m.to) != '_']))
+ top_dict_repr = ["'%s' : %s" % (m.to,
+ "t[0]['%s']" % (m.from_) if isinstance(m, Mapping) \
+ else (m.literal.value.__repr__() if isinstance(m.literal.value, str) else m.literal)) \
+ for m in wire_tuple_expr.top_mapping \
+ if str(m.to) != '_']
+ bottom_dict_repr = ["'%s' : %s" % (m.to,
+ "t[1]['%s']" % (m.from_) if isinstance(m, Mapping) \
+ else (m.literal.value.__repr__() if isinstance(m.literal.value, str) else m.literal)) \
+ for m in wire_tuple_expr.bottom_mapping \
+ if str(m.to) != '_']
+ wire_fn = "lambda t, s: ({%s}, {%s})" % (", ".join(top_dict_repr), ", ".join(bottom_dict_repr))
self.__write_line("%s = cons_wire(%s)" % \
(self.__get_temp_var(wire_tuple_expr),
wire_fn))
diff --git a/src/pclc/visitors/first_pass_resolver_visitor.py b/src/pclc/visitors/first_pass_resolver_visitor.py
index 7548574..c5bbe33 100644
--- a/src/pclc/visitors/first_pass_resolver_visitor.py
+++ b/src/pclc/visitors/first_pass_resolver_visitor.py
@@ -526,7 +526,7 @@ class FirstPassResolverVisitor(ResolverVisitor):
@multimethod(WireExpression)
@resolve_expression_once
def visit(self, wire_expr):
- inputs = [m.from_ for m in wire_expr.mapping]
+ inputs = [m.from_ for m in wire_expr.mapping if isinstance(m, Mapping)]
outputs = [m.to for m in wire_expr.mapping if str(m.to) != '_']
# Catch duplicates
@@ -553,9 +553,9 @@ class FirstPassResolverVisitor(ResolverVisitor):
@multimethod(WireTupleExpression)
@resolve_expression_once
def visit(self, wire_tuple_expr):
- top_inputs = [m.from_ for m in wire_tuple_expr.top_mapping]
+ top_inputs = [m.from_ for m in wire_tuple_expr.top_mapping if isinstance(m, Mapping)]
top_outputs = [m.to for m in wire_tuple_expr.top_mapping if m.to.identifier != '_']
- bottom_inputs = [m.from_ for m in wire_tuple_expr.bottom_mapping]
+ bottom_inputs = [m.from_ for m in wire_tuple_expr.bottom_mapping if isinstance(m, Mapping)]
bottom_outputs = [m.to for m in wire_tuple_expr.bottom_mapping if m.to.identifier != '_']
# Catch duplicates
diff --git a/src/pclc/visitors/third_pass_resolver_visitor.py b/src/pclc/visitors/third_pass_resolver_visitor.py
index b6f2a02..d9dd165 100644
--- a/src/pclc/visitors/third_pass_resolver_visitor.py
+++ b/src/pclc/visitors/third_pass_resolver_visitor.py
@@ -46,6 +46,13 @@ type_formatting_fn = lambda c: "(%s), (%s)" % (", ".join([i.identifier for i in
if isinstance(c, tuple) \
else ", ".join([i.identifier for i in c])
+def type_formatting_fn(c):
+ print c
+ print len(c)
+ return "(%s), (%s)" % (", ".join([i.identifier for i in c[0]]), \
+ ", ".join([i.identifier for i in c[1]])) \
+ if isinstance(c, tuple) \
+ else ", ".join([i.identifier for i in c])
@multimethodclass
class ThirdPassResolverVisitor(SecondPassResolverVisitor):