Commit 70df32f9 authored by Anders Blomdell's avatar Anders Blomdell
Browse files

Renamed python library to labcomm2014

parent 1f17be8a
......@@ -80,8 +80,7 @@ aspect Python_CodeGen {
env.println("#!/usr/bin/python");
env.println("# Auto generated " + baseName);
env.println();
env.println("import labcomm");
env.println("import StringIO");
env.println("import labcomm2014");
env.println();
Python_genTypes(env);
env.println("typedef = tuple([");
......@@ -119,7 +118,7 @@ aspect PythonTypes {
public void TypeDecl.Python_genSignature(Python_env env) {
env.println("class " + getName() + "(object):");
env.indent();
env.println("signature = labcomm.typedef('" + getName() + "',");
env.println("signature = labcomm2014.typedef('" + getName() + "',");
env.indent();
getType().Python_genSignature(env);
env.unindent();
......@@ -131,7 +130,7 @@ aspect PythonTypes {
public void SampleDecl.Python_genSignature(Python_env env) {
env.println("class " + getName() + "(object):");
env.indent();
env.println("signature = labcomm.sample('" + getName() + "', ");
env.println("signature = labcomm2014.sample('" + getName() + "', ");
env.indent();
getType().Python_genSignature(env);
env.unindent();
......@@ -153,20 +152,20 @@ aspect PythonTypes {
public void PrimType.Python_genSignature(Python_env env) {
switch (getToken()) {
case LABCOMM_BOOLEAN: { env.print("labcomm.BOOLEAN()"); } break;
case LABCOMM_BYTE: { env.print("labcomm.BYTE()"); } break;
case LABCOMM_SHORT: { env.print("labcomm.SHORT()"); } break;
case LABCOMM_INT: { env.print("labcomm.INTEGER()"); } break;
case LABCOMM_LONG: { env.print("labcomm.LONG()"); } break;
case LABCOMM_FLOAT: { env.print("labcomm.FLOAT()"); } break;
case LABCOMM_DOUBLE: { env.print("labcomm.DOUBLE()"); } break;
case LABCOMM_STRING: { env.print("labcomm.STRING()"); } break;
case LABCOMM_SAMPLE: { env.print("labcomm.SAMPLE()"); } break;
case LABCOMM_BOOLEAN: { env.print("labcomm2014.BOOLEAN()"); } break;
case LABCOMM_BYTE: { env.print("labcomm2014.BYTE()"); } break;
case LABCOMM_SHORT: { env.print("labcomm2014.SHORT()"); } break;
case LABCOMM_INT: { env.print("labcomm2014.INTEGER()"); } break;
case LABCOMM_LONG: { env.print("labcomm2014.LONG()"); } break;
case LABCOMM_FLOAT: { env.print("labcomm2014.FLOAT()"); } break;
case LABCOMM_DOUBLE: { env.print("labcomm2014.DOUBLE()"); } break;
case LABCOMM_STRING: { env.print("labcomm2014.STRING()"); } break;
case LABCOMM_SAMPLE: { env.print("labcomm2014.SAMPLE()"); } break;
}
}
public void ArrayType.Python_genSignature(Python_env env) {
env.print("labcomm.array([");
env.print("labcomm2014.array([");
for (int i = 0 ; i < getNumExp() ; i++) {
if (i > 0) { env.print(", "); }
env.print(getExp(i).Python_getValue());
......@@ -179,7 +178,7 @@ aspect PythonTypes {
}
public void StructType.Python_genSignature(Python_env env) {
env.println("labcomm.struct([");
env.println("labcomm2014.struct([");
env.indent();
for (int i = 0 ; i < getNumField() ; i++) {
if (i > 0) { env.println(","); }
......@@ -190,7 +189,7 @@ aspect PythonTypes {
}
public void VoidType.Python_genSignature(Python_env env) {
env.println("labcomm.struct([])");
env.println("labcomm2014.struct([])");
}
public void Field.Python_genSignature(Python_env env) {
......
#!/usr/bin/python
import labcomm
import labcomm2014
import animal
import StringIO
......@@ -10,7 +10,7 @@ class Animal:
if __name__ == '__main__':
buf = StringIO.StringIO()
encoder = labcomm.Encoder(labcomm.StreamWriter(buf))
encoder = labcomm2014.Encoder(labcomm2014.StreamWriter(buf))
encoder.add_decl(animal.cow.signature)
encoder.add_decl(animal.dog.signature)
encoder.add_decl(animal.duck.signature)
......@@ -22,7 +22,7 @@ if __name__ == '__main__':
theAnimal.says = 'Quack'
encoder.encode(theAnimal, animal.duck.signature)
buf.seek(0)
decoder = labcomm.Decoder(labcomm.StreamReader(buf))
decoder = labcomm2014.Decoder(labcomm2014.StreamReader(buf))
try:
while True:
value,decl = decoder.decode()
......
#!/usr/bin/python
import labcomm
import labcomm2014
import sys
import simple
if __name__ == '__main__':
version = sys.argv[2] if len(sys.argv) == 3 else "LabComm2014"
encoder = labcomm.Encoder(labcomm.StreamWriter(open(sys.argv[1], 'w')), version)
encoder = labcomm2014.Encoder(labcomm2014.StreamWriter(open(sys.argv[1], 'w')), version)
encoder.add_decl(simple.theTwoInts.signature)
encoder.add_decl(simple.IntString.signature)
foo = simple.theTwoInts()
......
......@@ -5,9 +5,9 @@ import sys
import socket
import rwsocket
if not any('labcomm' in p for p in sys.path):
if not any('labcomm2014' in p for p in sys.path):
sys.path.append('../../lib/python')
import labcomm
import labcomm2014
if __name__ == "__main__":
......@@ -19,7 +19,7 @@ if __name__ == "__main__":
sock.connect(addr)
print "Connected!"
d = labcomm.Decoder(labcomm.StreamReader(sock))
d = labcomm2014.Decoder(labcomm2014.StreamReader(sock))
while True:
try:
......
#!/usr/bin/python
import labcomm
import labcomm2014
import sys
import test
if __name__ == '__main__':
version = sys.argv[2] if len(sys.argv) == 3 else "LabComm2014"
encoder = labcomm.Encoder(labcomm.StreamWriter(open(sys.argv[1], 'w')), version)
encoder = labcomm2014.Encoder(labcomm2014.StreamWriter(open(sys.argv[1], 'w')), version)
encoder.add_decl(test.twoLines.signature)
tl = dict(
l1=dict(
......
#!/usr/bin/python
import labcomm
import labcomm2014
import sys
if __name__ == "__main__":
version = sys.argv[2] if len(sys.argv) == 3 else "LabComm2014"
d = labcomm.Decoder(labcomm.StreamReader(open(sys.argv[1])), version)
d = labcomm2014.Decoder(labcomm2014.StreamReader(open(sys.argv[1])), version)
while True:
try:
......
import labcomm.LabComm
from labcomm.StreamReader import StreamReader
from labcomm.StreamWriter import StreamWriter
Decoder = labcomm.LabComm.Decoder
Encoder = labcomm.LabComm.Encoder
sample = labcomm.LabComm.sample_def
sample_def = labcomm.LabComm.sample_def
sample_ref = labcomm.LabComm.sample_ref
typedef = labcomm.LabComm.typedef
array = labcomm.LabComm.array
struct = labcomm.LabComm.struct
primitive = labcomm.LabComm.primitive
BOOLEAN = labcomm.LabComm.BOOLEAN
BYTE = labcomm.LabComm.BYTE
SHORT = labcomm.LabComm.SHORT
INTEGER = labcomm.LabComm.INTEGER
LONG = labcomm.LabComm.LONG
FLOAT = labcomm.LabComm.FLOAT
DOUBLE = labcomm.LabComm.DOUBLE
STRING = labcomm.LabComm.STRING
SAMPLE = labcomm.LabComm.SAMPLE
decl_from_signature = labcomm.LabComm.decl_from_signature
try:
import labcomm.TreeModel
TreeModel = labcomm.TreeModel.TreeModel
except:
pass
import labcomm
class StreamReader:
def __init__(self, stream):
......
import labcomm
class StreamWriter:
def __init__(self, stream):
......
__all__ = [ 'LabComm' ]
import LabComm
from StreamReader import StreamReader
from StreamWriter import StreamWriter
Decoder = LabComm.Decoder
Encoder = LabComm.Encoder
sample = LabComm.sample_def
sample_def = LabComm.sample_def
sample_ref = LabComm.sample_ref
typedef = LabComm.typedef
array = LabComm.array
struct = LabComm.struct
primitive = LabComm.primitive
BOOLEAN = LabComm.BOOLEAN
BYTE = LabComm.BYTE
SHORT = LabComm.SHORT
INTEGER = LabComm.INTEGER
LONG = LabComm.LONG
FLOAT = LabComm.FLOAT
DOUBLE = LabComm.DOUBLE
STRING = LabComm.STRING
SAMPLE = LabComm.SAMPLE
decl_from_signature = LabComm.decl_from_signature
......@@ -2,7 +2,7 @@
spec() {
cat << 'EOF'
Name: labcomm
Name: labcomm__SUFFIX__
Version: __VERSION__
Release: 1
Summary: LabComm communication protocol
......@@ -40,58 +40,47 @@ make
# C
#
install -d ${RPM_BUILD_ROOT}/%{_libdir}
install lib/c/liblabcomm2006.a ${RPM_BUILD_ROOT}/%{_libdir}/
install lib/c/liblabcomm2006.so.1 ${RPM_BUILD_ROOT}/%{_libdir}/liblabcomm2006.so.__VERSION__
ln -s liblabcomm2006.so.__VERSION__ ${RPM_BUILD_ROOT}/%{_libdir}/liblabcomm2006.so
install lib/c/liblabcomm2014.a ${RPM_BUILD_ROOT}/%{_libdir}/
install lib/c/liblabcomm2014.so.1 ${RPM_BUILD_ROOT}/%{_libdir}/liblabcomm2014.so.__VERSION__
ln -s liblabcomm2014.so.__VERSION__ ${RPM_BUILD_ROOT}/%{_libdir}/liblabcomm2014.so
install -d ${RPM_BUILD_ROOT}/%{_includedir}/labcomm
install lib/c/2014/*h ${RPM_BUILD_ROOT}/%{_includedir}/labcomm
install -d ${RPM_BUILD_ROOT}/%{_includedir}/labcomm2006
install lib/c/2006/*h ${RPM_BUILD_ROOT}/%{_includedir}/labcomm
#
# java
#
install -d ${RPM_BUILD_ROOT}/usr/lib
install -m u=r,g=r,o=r compiler/labcomm2014_compiler.jar ${RPM_BUILD_ROOT}/usr/lib
install -m u=r,g=r,o=r compiler/labcomm2006_compiler.jar ${RPM_BUILD_ROOT}/usr/lib
install -m u=r,g=r,o=r lib/java/labcomm2014.jar ${RPM_BUILD_ROOT}/usr/lib
install -m u=r,g=r,o=r lib/java/labcomm2006.jar ${RPM_BUILD_ROOT}/usr/lib
install -d ${RPM_BUILD_ROOT}/%{_bindir}
install -m u=rx,g=rx,o=rx \
compiler/labcomm2014 ${RPM_BUILD_ROOT}/%{_bindir}/labcomm2014
install -m u=rx,g=rx,o=rx \
compiler/labcomm2006 ${RPM_BUILD_ROOT}/%{_bindir}/labcomm2006
ls -l ${RPM_BUILD_ROOT}/%{_bindir}
#
# C#
#
install -d ${RPM_BUILD_ROOT}/usr/lib
install -m u=r,g=r,o=r lib/csharp/labcomm.dll ${RPM_BUILD_ROOT}/usr/lib
install -m u=r,g=r,o=r lib/csharp/labcomm2014.dll ${RPM_BUILD_ROOT}/usr/lib
#
# Python
#
install -d ${RPM_BUILD_ROOT}/%{python_sitelib}/labcomm
install lib/python/labcomm/* ${RPM_BUILD_ROOT}/%{python_sitelib}/labcomm
install -d ${RPM_BUILD_ROOT}/%{python_sitelib}/labcomm2014
install lib/python/labcomm/* ${RPM_BUILD_ROOT}/%{python_sitelib}/labcomm2014
%files
%defattr (-, root, root)
%exclude /usr/lib/debug
%exclude /usr/lib/labcomm2014_compiler.jar
%exclude /usr/lib/labcomm2006_compiler.jar
/usr/lib/*
%{_libdir}/*
%files devel
%defattr (-, root, root)
/usr/lib/labcomm2014_compiler.jar
/usr/lib/labcomm2006_compiler.jar
%{_includedir}/*
%{_includedir}/labcomm/*
%{_bindir}/*
EOF
......@@ -108,10 +97,12 @@ rm -rf rpmbuild/SOURCES/*
# Create spec and .tar.gz
DESCRIBE=$(git describe | sed -e 's/^v\(.*\)/\1/')
VERSION=$(echo ${DESCRIBE} | sed -e 's/-/./g')
SUFFIX=$(echo ${DESCRIBE} | sed -e 's/^\([^.]*\)[.].*$/\1/g')
VERSION=$(echo ${DESCRIBE} | sed -e 's/^[^.]*[.]\(.*\)/\1/g;s/-/./g')
COMMIT=$(git rev-parse HEAD)
(
spec | \
sed -e "s/__SUFFIX__/${SUFFIX}/g" | \
sed -e "s/__VERSION__/${VERSION}/g" | \
sed -e "s/__DESCRIBE__/${DESCRIBE}/g" | \
sed -e "s/__COMMIT__/${COMMIT}/g" \
......
......@@ -3,7 +3,7 @@
import argparse
import imp
import labcomm
import labcomm2014
import math
import os
import re
......@@ -47,25 +47,25 @@ class Test:
pass
def generate(self, decl):
if decl.__class__ == labcomm.sample:
if decl.__class__ == labcomm2014.sample:
result = []
for values in self.generate(decl.decl):
result.append((decl, values))
return result
elif decl.__class__ == labcomm.typedef:
elif decl.__class__ == labcomm2014.typedef:
result = []
for values in self.generate(decl.decl):
result.append(values)
return result
elif decl.__class__ == labcomm.struct:
elif decl.__class__ == labcomm2014.struct:
result = []
if len(decl.field) == 0:
result.append({})
else:
values1 = self.generate(decl.field[0][1])
values2 = self.generate(labcomm.struct(decl.field[1:]))
values2 = self.generate(labcomm2014.struct(decl.field[1:]))
for v1 in values1:
for v2 in values2:
v = dict(v2)
......@@ -73,7 +73,7 @@ class Test:
result.append(v)
return result
elif decl.__class__ == labcomm.array:
elif decl.__class__ == labcomm2014.array:
if len(decl.indices) == 1:
values = self.generate(decl.decl)
if decl.indices[0] == 0:
......@@ -81,7 +81,7 @@ class Test:
else:
lengths = [ decl.indices[0] ]
else:
values = self.generate(labcomm.array(decl.indices[1:],
values = self.generate(labcomm2014.array(decl.indices[1:],
decl.decl))
if decl.indices[0] == 0:
lengths = [1, 2]
......@@ -96,33 +96,33 @@ class Test:
result.append(element)
return result
elif decl.__class__ == labcomm.BOOLEAN:
elif decl.__class__ == labcomm2014.BOOLEAN:
return [False, True]
elif decl.__class__ == labcomm.BYTE:
elif decl.__class__ == labcomm2014.BYTE:
return [0, 127, 128, 255]
elif decl.__class__ == labcomm.SHORT:
elif decl.__class__ == labcomm2014.SHORT:
return [-32768, 0, 32767]
elif decl.__class__ == labcomm.INTEGER:
elif decl.__class__ == labcomm2014.INTEGER:
return [-2147483648, 0, 2147483647]
elif decl.__class__ == labcomm.LONG:
elif decl.__class__ == labcomm2014.LONG:
return [-9223372036854775808, 0, 9223372036854775807]
elif decl.__class__ == labcomm.FLOAT:
elif decl.__class__ == labcomm2014.FLOAT:
def tofloat(v):
return struct.unpack('f', struct.pack('f', v))[0]
return [tofloat(-math.pi), 0.0, tofloat(math.pi)]
elif decl.__class__ == labcomm.DOUBLE:
elif decl.__class__ == labcomm2014.DOUBLE:
return [-math.pi, 0.0, math.pi]
elif decl.__class__ == labcomm.STRING:
elif decl.__class__ == labcomm2014.STRING:
return ['string', u'sträng' ]
elif decl.__class__ == labcomm.SAMPLE:
elif decl.__class__ == labcomm2014.SAMPLE:
return self.signatures
print>>sys.stderr, decl
......@@ -130,19 +130,19 @@ class Test:
def uses_refs(self, decls):
for decl in decls:
if decl.__class__ == labcomm.sample:
if decl.__class__ == labcomm2014.sample:
if self.uses_refs([ decl.decl ]):
return True
elif decl.__class__ == labcomm.struct:
elif decl.__class__ == labcomm2014.struct:
if self.uses_refs([ d for n,d in decl.field ]):
return True
elif decl.__class__ == labcomm.array:
elif decl.__class__ == labcomm2014.array:
if self.uses_refs([ decl.decl ]):
return True
elif decl.__class__ == labcomm.SAMPLE:
elif decl.__class__ == labcomm2014.SAMPLE:
return True
return False
......@@ -159,7 +159,7 @@ class Test:
self.next = threading.Condition()
decoder = threading.Thread(target=self.decode, args=(p.stdout,))
decoder.start()
encoder = labcomm.Encoder(labcomm.StreamWriter(p.stdin))
encoder = labcomm2014.Encoder(labcomm2014.StreamWriter(p.stdin))
for signature in self.signatures:
encoder.add_decl(signature)
pass
......@@ -202,7 +202,7 @@ class Test:
pass
def decode(self, f):
decoder = labcomm.Decoder(labcomm.StreamReader(f))
decoder = labcomm2014.Decoder(labcomm2014.StreamReader(f))
try:
while True:
value,decl = decoder.decode()
......
#!/usr/bin/env python
import argparse
import labcomm
import labcomm2014
import sys
import time
......@@ -41,67 +41,67 @@ class FollowingReader(Reader):
def flatten(sample, _type):
if isinstance(_type, labcomm.sample):
if isinstance(_type, labcomm2014.sample):
flatten(sample, _type.decl)
elif isinstance(_type, labcomm.array):
elif isinstance(_type, labcomm2014.array):
for e in sample:
flatten(e, _type.decl)
elif isinstance(_type, labcomm.struct):
elif isinstance(_type, labcomm2014.struct):
for name, decl in _type.field:
flatten(sample[name], decl)
elif isinstance(_type, labcomm.BOOLEAN):
elif isinstance(_type, labcomm2014.BOOLEAN):
print "%d," % sample,
elif isinstance(_type, labcomm.STRING):
elif isinstance(_type, labcomm2014.STRING):
print "\"%s\"," % sample,
elif isinstance(_type, labcomm.primitive):
elif isinstance(_type, labcomm2014.primitive):
print "%s," % sample,
else:
raise Exception("Unhandled type. " + str(type(type_)) + " " + str(type_))
def flatten_labels(_type, prefix=""):
if isinstance(_type, labcomm.sample):
if isinstance(_type, labcomm2014.sample):
flatten_labels(_type.decl, _type.name)
elif isinstance(_type, labcomm.array):
elif isinstance(_type, labcomm2014.array):
if len(_type.indices) != 1:
raise Exception("Fix multidimensional arrays")
if len(_type.indices) == 0:
raise Exception("We dont't handle dynamical sizes yet %s" % _type)
for i in range(0, _type.indices[0]):
flatten_labels(_type.decl, prefix + "[%d]" % i)
elif isinstance(_type, labcomm.struct):
elif isinstance(_type, labcomm2014.struct):
for name, decl in _type.field:
flatten_labels(decl,
prefix + "." + name)
elif isinstance(_type, labcomm.primitive):
elif isinstance(_type, labcomm2014.primitive):
print '"%s",' % prefix,
else:
raise Exception("Unhandled type. " + str(type(type_)) + " " + str(type_))
def default(type_):
if isinstance(type_, labcomm.sample):
if isinstance(type_, labcomm2014.sample):
return default(type_.decl)
elif isinstance(type_, labcomm.array):
elif isinstance(type_, labcomm2014.array):
if len(type_.indices) != 1:
raise Exception("Fix multidimensional arrays")
if len(type_.indices) == 0:
raise Exception("We dont't handle dynamical sizes yet %s" % type_)
for i in range(0, type_.indices[0]):
return [default(type_.decl) for _ in range(type_.indices[0])]
elif isinstance(type_, labcomm.struct):
elif isinstance(type_, labcomm2014.struct):
return {name: default(decl) for name, decl in type_.field}
elif isinstance(type_, labcomm.STRING):
elif isinstance(type_, labcomm2014.STRING):
return ''
elif isinstance(type_, labcomm.BOOLEAN):
elif isinstance(type_, labcomm2014.BOOLEAN):
return False
elif (isinstance(type_, labcomm.FLOAT) or
isinstance(type_, labcomm.DOUBLE)):
elif (isinstance(type_, labcomm2014.FLOAT) or
isinstance(type_, labcomm2014.DOUBLE)):
return float('NaN')
elif (isinstance(type_, labcomm.BYTE) or
isinstance(type_, labcomm.SHORT) or
isinstance(type_, labcomm.INTEGER) or
isinstance(type_, labcomm.LONG)):
elif (isinstance(type_, labcomm2014.BYTE) or
isinstance(type_, labcomm2014.SHORT) or
isinstance(type_, labcomm2014.INTEGER) or
isinstance(type_, labcomm2014.LONG)):
return 0
else:
raise Exception("Unhandled type. " + str(type(type_)) + " " + str(type_))
......@@ -156,7 +156,7 @@ def main(main_args):
reader = FollowingReader(file_, args.interval, args.timeout)
else:
reader = Reader(file_)
d = labcomm.Decoder(reader)
d = labcomm2014.Decoder(reader)
while True:
try:
o, t = d.decode()
......
......@@ -4,11 +4,11 @@ import sys
import imp
import subprocess
import os
import labcomm
import labcomm2014
TRANSLATE={
labcomm.SHORT() : 'short',
labcomm.DOUBLE() : 'double'
labcomm2014.SHORT() : 'short',
labcomm2014.DOUBLE() : 'double'
}
def compile_lc(lc):
......@@ -22,46 +22,46 @@ def compile_lc(lc):
return (lc_import.typedef, lc_import.sample)
def gen_binding(decl, lc_prefix, prefix, suffix):
if isinstance(decl, labcomm.sample):
if isinstance(decl.decl, labcomm.typedef):
if isinstance(decl, labcomm2014.sample):
if isinstance(decl.decl, labcomm2014.typedef):
print "%(n1)s = coder.cstructname(%(n1)s, '%(lc)s_%(n2)s')" % dict(
n1=decl.name, n2=decl.decl.name, lc=lc_prefix)
else:
print "%(n1)s = coder.cstructname(%(n1)s, '%(lc)s_%(n2)s')" % dict(
n1=decl.name, n2=decl.name, lc=lc_prefix)
gen_binding(decl.decl, lc_prefix, '%s.' % decl.name, suffix)
elif isinstance(decl, labcomm.typedef):
elif