From 3f2e9cd3326aed82d9f30b2223737b25933fed01 Mon Sep 17 00:00:00 2001
From: Sven Gestegard Robertz <sven.robertz@cs.lth.se>
Date: Mon, 25 May 2015 17:59:59 +0200
Subject: [PATCH] First implementation of intention encoding in python

---
 compiler/2014/Python_CodeGen.jrag |  6 +++++-
 examples/user_types/Makefile      | 30 ++++++++++++++----------------
 lib/python/labcomm2014/LabComm.py |  3 ++-
 3 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/compiler/2014/Python_CodeGen.jrag b/compiler/2014/Python_CodeGen.jrag
index 11fa07e..d29b584 100644
--- a/compiler/2014/Python_CodeGen.jrag
+++ b/compiler/2014/Python_CodeGen.jrag
@@ -151,7 +151,11 @@ aspect PythonTypes {
   }
 
   public void TypeInstance.Python_genIntentions(Python_env env) {
-    env.print("{'':'"+getName()+"'}");
+    env.print("{'':'"+getName()+"'");
+    for(Intention i : sortedIntentions()) {
+        env.print(", '"+i.getKey()+"':'"+new String(i.getValue())+"'");
+    }
+    env.print("}");
   }
 
   public void TypeInstance.Python_genTypedef(Python_env env) {
diff --git a/examples/user_types/Makefile b/examples/user_types/Makefile
index 50700bb..e1ab9a2 100644
--- a/examples/user_types/Makefile
+++ b/examples/user_types/Makefile
@@ -96,12 +96,11 @@ run:
 	@echo "************ running python encoder: *****************"
 	@PYTHONPATH=${LCDIR}/lib/python:${GENDIR} ./example_encoder.py encoded_data_p LabComm2014
 
-	@echo "WARNING! python encoded data only decoded by python decoder,  pending intention implementation"
-#	@echo "************ running Java  decoder: *****************"
-#	@java -cp .:${LCDIR}/lib/java/labcomm2014.jar:${GENDIR} Decoder encoded_data_p
-#
-#	@echo "************ running C decoder: *****************"
-#	@LD_LIBRARY_PATH=${LCDIR}/lib/c/ ./example_decoder encoded_data_p
+	@echo "************ running Java  decoder: *****************"
+	@java -cp .:${LCDIR}/lib/java/labcomm2014.jar:${GENDIR} Decoder encoded_data_p
+
+	@echo "************ running C decoder: *****************"
+	@LD_LIBRARY_PATH=${LCDIR}/lib/c/ ./example_decoder encoded_data_p
 
 	@echo "************ running python decoder (from wiki_example):"
 	PYTHONPATH=${LCDIR}/lib/python ../wiki_example/example_decoder.py encoded_data_p LabComm2014
@@ -145,16 +144,15 @@ runwcs: build ExampleEncoder.exe ExampleDecoder.exe
 	@echo "************ running python encoder: *****************"
 	@PYTHONPATH=${LCDIR}/lib/python:${GENDIR} ./example_encoder.py encoded_data_p LabComm2014
 
-	@echo "WARNING! python encoded data only decoded by python decoder,  pending intention implementation"
-#	@echo "************ running Java  decoder: *****************"
-#	@java -cp .:${LCDIR}/lib/java/labcomm2014.jar:${GENDIR} Decoder encoded_data_p
-#
-#	@echo "************ running C decoder: *****************"
-#	@LD_LIBRARY_PATH=${LCDIR}/lib/c/ ./example_decoder encoded_data_p
-#
-#	@echo "************ running C# decoder: *****************"
-#	@mono ./ExampleDecoder.exe encoded_data_p
-#
+	@echo "************ running Java  decoder: *****************"
+	@java -cp .:${LCDIR}/lib/java/labcomm2014.jar:${GENDIR} Decoder encoded_data_p
+
+	@echo "************ running C decoder: *****************"
+	@LD_LIBRARY_PATH=${LCDIR}/lib/c/ ./example_decoder encoded_data_p
+
+	@echo "************ running C# decoder: *****************"
+	@mono ./ExampleDecoder.exe encoded_data_p
+
 	@echo "************ running python decoder (from wiki_example):"
 	PYTHONPATH=${LCDIR}/lib/python ../wiki_example/example_decoder.py encoded_data_p LabComm2014
 
diff --git a/lib/python/labcomm2014/LabComm.py b/lib/python/labcomm2014/LabComm.py
index f2acdd9..982c917 100644
--- a/lib/python/labcomm2014/LabComm.py
+++ b/lib/python/labcomm2014/LabComm.py
@@ -893,8 +893,9 @@ class Encoder(Codec):
         keys.sort();
         self.encode_packed32(len(intentions))
         for k in keys:
+            v = intentions[k]
             self.encode_string(k)
-            self.encode_string(intentions[k])
+            self.encode_string(v)
 
 class Decoder(Codec):
     def __init__(self, reader, version=DEFAULT_VERSION):
-- 
GitLab