From e7848681147696a1b4e7717458cf40bc3d69c207 Mon Sep 17 00:00:00 2001 From: Anders Blomdell <anders.blomdell@control.lth.se> Date: Tue, 3 Mar 2015 16:32:06 +0100 Subject: [PATCH] More cleanups --- compiler/2006/CS_CodeGen.jrag | 2 +- compiler/2006/LabComm.java | 24 -- compiler/2006/Python_CodeGen.jrag | 29 +- compiler/2006/RAPID_CodeGen.jrag | 367 ------------------ compiler/2014/Python_CodeGen.jrag | 231 ----------- examples/duck_typing/duck_typing.py | 6 +- lib/RAPID/LabComm.sys | 317 --------------- lib/RAPID/README | 104 ----- lib/c/2006/labcomm2006.c | 2 +- lib/c/2006/labcomm2006_decoder.c | 20 +- lib/c/2006/labcomm2006_encoder.c | 6 +- lib/c/2006/labcomm2006_private.h | 14 +- .../test/test_labcomm_basic_type_encoding.c | 12 - .../se/lth/control/labcomm2006/Constant.cs | 2 +- .../se/lth/control/labcomm2006/Decoder.cs | 2 +- .../lth/control/labcomm2006/DecoderChannel.cs | 2 +- .../control/labcomm2006/DecoderRegistry.cs | 2 +- .../se/lth/control/labcomm2006/Encoder.cs | 2 +- .../lth/control/labcomm2006/EncoderChannel.cs | 2 +- .../control/labcomm2006/EncoderRegistry.cs | 2 +- .../se/lth/control/labcomm2006/Sample.cs | 2 +- .../control/labcomm2006/SampleDispatcher.cs | 2 +- .../lth/control/labcomm2006/SampleHandler.cs | 2 +- .../se/lth/control/labcomm2006/Decoder.java | 1 - .../control/labcomm2006/DecoderChannel.java | 27 +- .../se/lth/control/labcomm2006/Encoder.java | 2 +- .../control/labcomm2006/EncoderChannel.java | 8 +- lib/python/labcomm/__init__.py | 31 -- .../{labcomm => labcomm2006}/LabComm.py | 32 +- .../{labcomm => labcomm2006}/StreamReader.py | 2 - .../{labcomm => labcomm2006}/StreamWriter.py | 2 - lib/python/labcomm2006/__init__.py | 27 ++ packaging/make_srpm | 25 +- test/relay_gen_cs.py | 2 +- test/test_encoder_decoder.py | 34 +- tools/lc2csv.py | 2 +- 36 files changed, 134 insertions(+), 1215 deletions(-) delete mode 100644 compiler/2006/RAPID_CodeGen.jrag delete mode 100644 compiler/2014/Python_CodeGen.jrag delete mode 100644 lib/RAPID/LabComm.sys delete mode 100644 lib/RAPID/README delete mode 100644 lib/python/labcomm/__init__.py rename lib/python/{labcomm => labcomm2006}/LabComm.py (96%) rename lib/python/{labcomm => labcomm2006}/StreamReader.py (95%) rename lib/python/{labcomm => labcomm2006}/StreamWriter.py (95%) create mode 100644 lib/python/labcomm2006/__init__.py diff --git a/compiler/2006/CS_CodeGen.jrag b/compiler/2006/CS_CodeGen.jrag index 800e054..6499c0e 100644 --- a/compiler/2006/CS_CodeGen.jrag +++ b/compiler/2006/CS_CodeGen.jrag @@ -206,7 +206,7 @@ aspect CS_CodeGen { env.indent(); } env.println("using System;"); - env.println("using se.lth.control.labcomm;"); + env.println("using se.lth.control.labcomm2006;"); for (int i = 0; i < getNumDecl(); i++) { Decl d = getDecl(i); try { diff --git a/compiler/2006/LabComm.java b/compiler/2006/LabComm.java index 8ec9d1e..6a51ce3 100644 --- a/compiler/2006/LabComm.java +++ b/compiler/2006/LabComm.java @@ -30,8 +30,6 @@ public class LabComm { println("[ Python options ]"); println(" -P Generates Python code in FILE.py"); println(" --python=PFILE Generates Python code in PFILE"); - println("[ RAPID options ]"); - println(" --rapid Generates RAPID code in FILE.sys"); println("[ Misc options ]"); println(" --pretty=PFILE Pretty prints to PFILE"); println(" --typeinfo=TIFILE Generates typeinfo in TIFILE"); @@ -68,7 +66,6 @@ public class LabComm { } private static void genCS(Program p, String csName, String csNamespace) { -// throw new Error("C# generation currently disabled"); try { p.CS_gen(csName, csNamespace); } catch (IOException e) { @@ -100,14 +97,6 @@ public class LabComm { } } - private static void genRAPID(Program p, String filename, String prefix) { - try { - p.RAPID_gen(filename, prefix); - } catch (IOException e) { - System.err.println("IOException: " + filename + " " + e); - } - } - /** Helper class to contain command line options and their associated behaviour **/ @@ -127,7 +116,6 @@ public class LabComm { String pythonFile = null; String prettyFile = null; String typeinfoFile = null; - String rapidFile = null; String fileName = null; Opts(String[] args) { @@ -208,8 +196,6 @@ public class LabComm { prettyFile = args[i].substring(9); } else if (args[i].startsWith("--typeinfo=")) { typeinfoFile = args[i].substring(11); - } else if (args[i].equals("--rapid")) { - rapidFile = coreName + ".sys"; } else if (i == args.length - 1) { fileName = args[i]; } else { @@ -302,15 +288,6 @@ public class LabComm { return wroteFile; } - boolean generateRAPID(Program ast) { - boolean wroteFile = false; - if (rapidFile != null) { - printStatus("RAPID: " , rapidFile); - genRAPID(ast, rapidFile, coreName); - wroteFile = true; - } - return wroteFile; - } boolean generatePrettyPrint(Program ast) { boolean wroteFile = false; if (prettyFile != null) { @@ -371,7 +348,6 @@ public class LabComm { fileWritten |= opts.generateCS(ast); fileWritten |= opts.generateJava(ast); fileWritten |= opts.generatePython(ast); - fileWritten |= opts.generateRAPID(ast); fileWritten |= opts.generatePrettyPrint(ast); fileWritten |= opts.generateTypeinfo(ast); diff --git a/compiler/2006/Python_CodeGen.jrag b/compiler/2006/Python_CodeGen.jrag index 9d68bd3..6589b63 100644 --- a/compiler/2006/Python_CodeGen.jrag +++ b/compiler/2006/Python_CodeGen.jrag @@ -77,8 +77,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 labcomm2006"); env.println(); Python_genTypes(env); env.println("sample = tuple(["); @@ -112,7 +111,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 = labcomm2006.sample('" + getName() + "', "); env.indent(); getType().Python_genSignature(env); env.unindent(); @@ -133,20 +132,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("labcomm2006.BOOLEAN()"); } break; + case LABCOMM_BYTE: { env.print("labcomm2006.BYTE()"); } break; + case LABCOMM_SHORT: { env.print("labcomm2006.SHORT()"); } break; + case LABCOMM_INT: { env.print("labcomm2006.INTEGER()"); } break; + case LABCOMM_LONG: { env.print("labcomm2006.LONG()"); } break; + case LABCOMM_FLOAT: { env.print("labcomm2006.FLOAT()"); } break; + case LABCOMM_DOUBLE: { env.print("labcomm2006.DOUBLE()"); } break; + case LABCOMM_STRING: { env.print("labcomm2006.STRING()"); } break; + case LABCOMM_SAMPLE: { env.print("labcomm2006.SAMPLE()"); } break; } } public void ArrayType.Python_genSignature(Python_env env) { - env.print("labcomm.array(["); + env.print("labcomm2006.array(["); for (int i = 0 ; i < getNumExp() ; i++) { if (i > 0) { env.print(", "); } env.print(getExp(i).Python_getValue()); @@ -159,7 +158,7 @@ aspect PythonTypes { } public void StructType.Python_genSignature(Python_env env) { - env.println("labcomm.struct(["); + env.println("labcomm2006.struct(["); env.indent(); for (int i = 0 ; i < getNumField() ; i++) { if (i > 0) { env.println(","); } @@ -170,7 +169,7 @@ aspect PythonTypes { } public void VoidType.Python_genSignature(Python_env env) { - env.println("labcomm.struct([])"); + env.println("labcomm2006.struct([])"); } public void Field.Python_genSignature(Python_env env) { diff --git a/compiler/2006/RAPID_CodeGen.jrag b/compiler/2006/RAPID_CodeGen.jrag deleted file mode 100644 index a2029b7..0000000 --- a/compiler/2006/RAPID_CodeGen.jrag +++ /dev/null @@ -1,367 +0,0 @@ - -aspect RAPID_env { - public class RAPID_env { - private String prefix; - private StringBuilder types; - private StringBuilder constants; - private StringBuilder procedures; - private PrintStream ps; - - public RAPID_env(PrintStream ps, String prefix) - { - this.types = new StringBuilder(); - this.constants = new StringBuilder(); - this.procedures = new StringBuilder(); - this.prefix = prefix; - this.ps = ps; - } - - public String prefix() { return this.prefix; } - - public String addRecord(String name, java.util.List<String> components) - { - String recordName = this.prefix + "_" + name; - types.append("\tRECORD " + recordName); - types.append("\n"); - for (String c : components) { - types.append("\t\t" + c + "\n"); - } - types.append("\tENDRECORD"); - types.append("\n\n"); - return recordName; - } - - public void addConstant(String type, String name, String value) { - this.constants.append("\tLOCAL CONST " + type + " " + name + - " := " + value + ";\n"); - } - - public void addProc(String name, java.util.List<String> params, - java.util.List<String> stmts) - { - this.procedures.append("\tLOCAL PROC " + name + "("); - for (int i = 0; i < params.size(); i++) { - this.procedures.append(params.get(i)); - if (i < params.size() - 1) { - this.procedures.append(", "); - } - } - this.procedures.append(")\n"); - for (String stmt : stmts) { - this.procedures.append("\t\t" + stmt + "\n"); - } - this.procedures.append("\tERROR\n\t\tRAISE ;\n\tENDPROC\n\n"); - } - - public void flush() - { - ps.println("MODULE " + prefix() + "(SYSMODULE)"); - ps.println(); - ps.print(types.toString()); - ps.println(); - ps.println("\tLOCAL CONST string prefix:=\"" + this.prefix + "\";"); - ps.print(constants.toString()); - ps.println(); - ps.print(procedures.toString()); - ps.println(); - ps.print("ENDMODULE"); - } - } -} - -aspect RAPID_CodeGen { - - public void ASTNode.RAPID_gen(RAPID_env env) { - throw new UnsupportedOperationException(); - } - - public void Program.RAPID_gen(String file, String prefix) - throws IOException - { - PrintStream ps = new PrintStream(new FileOutputStream(new File(file))); - RAPID_env env = new RAPID_env(ps, prefix); - RAPID_gen(env); - } - - public void Program.RAPID_gen(RAPID_env env) - { - for (int i = 0; i < getNumDecl(); i++) { - getDecl(i).RAPID_gen(env); - } - env.flush(); - } - - public void Decl.RAPID_gen(RAPID_env env) { - throw new UnsupportedOperationException("RAPID code generation (currently) does not support "+getClass().getSimpleName()); - } - - public void TypeDecl.RAPID_gen(RAPID_env env) { - System.out.println("***WARNING! TypeDecl.RapidGen(.) a NOP after sig reorganization."); - System.out.println(" (Tell a developer to) remove this warning when tested"); - } - - public void Decl.RAPID_emitFlatSignature(RAPID_env env, String sig_len_name, String sig_name) { - System.out.println("***WARNING! Code not tested after reorganization of signatures."); - System.out.println(" (Tell a developer to) remove this warning when tested"); - SignatureList sig = flatSignature(2006); - StringBuilder sb = new StringBuilder(); - sb.append("["); - byte[] d = null; - int sig_len = 0; - for (int i = 0; i < sig.size(); i++) { - d = sig.getData(i, 2006); - for (int j = 0; d != null && j < d.length; j++) { - sb.append(d[j] + ","); - sig_len++; - } - } - sb.delete(sb.length() - 1, sb.length()); - sb.append("]"); - env.addConstant("num", sig_len_name, "" + sig_len); - env.addConstant("byte", sig_name + "{" + sig_len_name + "}", - sb.toString()); - } - - public void SampleDecl.RAPID_gen(RAPID_env env) { - // Add type declarations - String fullName = getType().RAPID_AddType(env, getName()); - // Add signature constants - String sig_len_name = "signature_len_" + getName(); - String sig_name = "signature_" + getName(); - - RAPID_emitFlatSignature(env, sig_len_name, sig_name); - - // Add decode procedures - ArrayList<String> params = new ArrayList<String>(); - ArrayList<String> stmts = new ArrayList<String>(); - params.add("VAR LabComm_Decoder_Sample s"); - params.add("string handler"); - stmts.add("s.prefix := prefix;"); - stmts.add("s.name := \"" + getName() + "\";"); - stmts.add("s.handler := handler;"); - env.addProc("Dec_Reg_" + getName(), params, stmts); - - params.clear(); - stmts.clear(); - params.add("VAR LabComm_Decoder_Sample s"); - params.add("VAR rawbytes sig"); - params.add("num user_id"); - stmts.add("VAR byte tmp_sig{" + sig_len_name + "};"); - stmts.add("IF RawBytesLen(sig)<>" + sig_len_name + " THEN"); - stmts.add("\tRETURN;"); - stmts.add("ENDIF"); - stmts.add("FOR i FROM 1 TO " + sig_len_name + " DO"); - stmts.add("\tUnpackRawBytes sig, i, tmp_sig{i}, \\Hex1;"); - stmts.add("ENDFOR"); - stmts.add("IF tmp_sig<>" + sig_name + " THEN"); - stmts.add("\tRETURN;"); - stmts.add("ENDIF"); - stmts.add("s.user_id := user_id;"); - env.addProc("Reg_If_Signature_Of_" + getName(), params, stmts); - - params.clear(); - stmts.clear(); - params.add("VAR Decoder d"); - params.add("VAR LabComm_Stream st"); - params.add("VAR LabComm_Decoder_Sample s"); - stmts.add("VAR " + fullName + " tmp;"); - getType().RAPID_AddDecodeInstr(env, stmts, "tmp", "st"); - stmts.add("% s.handler % tmp;"); - env.addProc("Decode_And_Handle_" + getName(), params, stmts); - - params.clear(); - stmts.clear(); - params.add("VAR Encoder e"); - params.add("VAR LabComm_Stream st"); - params.add("VAR LabComm_Encoder_Sample s"); - stmts.add("s.prefix := prefix;"); - stmts.add("s.name := \"" + getName() + "\";"); - stmts.add("Encoder_Register_Sample e, st, s;"); - env.addProc("Enc_Reg_" + getName(), params, stmts); - - params.clear(); - stmts.clear(); - params.add("VAR Encoder e"); - params.add("VAR LabComm_Stream s"); - stmts.add("VAR rawbytes buffer;"); - stmts.add("FOR i FROM 1 TO " + sig_len_name + " DO"); - stmts.add("\tPackRawBytes " + sig_name + - "{i}, buffer, \\Network, i, \\Hex1;"); - stmts.add("ENDFOR"); - stmts.add("SocketSend s.soc, \\RawData:=buffer, \\NoOfBytes:=" + - sig_len_name + ";"); - env.addProc("Encode_Signature_" + getName(), params, stmts); - - params.clear(); - stmts.clear(); - params.add("VAR Encoder e"); - params.add("VAR LabComm_Stream st"); - params.add("VAR LabComm_Encoder_Sample s"); - params.add("VAR " + fullName + " val"); - stmts.add("Encode_Packed st, s.user_id;"); - getType().RAPID_AddEncodeInstr(env, stmts, "val", "st"); - env.addProc("Encode_" + getName(), params, stmts); - } - - public String Type.RAPID_AddType(RAPID_env env, String name) { - throw new UnsupportedOperationException("RAPID code generation does (currently) not support "+getClass().getSimpleName()); - } - - public String StructType.RAPID_AddType(RAPID_env env, String name) { - ArrayList<String> components = new ArrayList<String>(); - for (int i = 0; i < getNumField(); i++) { - Field f = getField(i); - components.add( - f.getType().RAPID_AddType(env, name + "_" + f.getName()) + - " " + f.getName() + ";"); - } - String typeName = env.addRecord(name, components); - return typeName; - } - - public String FixedArrayType.RAPID_AddType(RAPID_env env, String name) { - String typeName = getType().RAPID_AddType(env, name + "_e"); - if (getNumExp() > 1) { - throw new UnsupportedOperationException("RAPID generation only (currently) supports one-dimensional arrays"); - } - ArrayList<String> components = new ArrayList<String>(); - for (int i = 1; i <= getExp(0).RAPID_getValue(); i++) { - components.add(typeName + " e" + i + ";"); - } - String completeName = env.addRecord("list_" + name, components); - return completeName; - } - - public String PrimType.RAPID_AddType(RAPID_env env, String name) { - if (getToken() == LABCOMM_SHORT || - getToken() == LABCOMM_FLOAT || - getToken() == LABCOMM_INT) { - return "num"; - } else if (getToken() == LABCOMM_LONG) { - return "dnum"; - } else if (getToken() == LABCOMM_STRING) { - return "string"; - } else if (getToken() == LABCOMM_BOOLEAN) { - return "bool"; - } else if (getToken() == LABCOMM_BYTE) { - return "byte"; - } - throw new UnsupportedOperationException("RAPID code generation does not (currently) support "+getName()); - } - - public void Type.RAPID_AddDecodeInstr(RAPID_env env, - java.util.List<String> instrs, - String var_name, String stream_name) { - throw new UnsupportedOperationException("RAPID code generation does not (currently) support "+getClass().getSimpleName()); - } - - public void StructType.RAPID_AddDecodeInstr(RAPID_env env, - java.util.List<String> instrs, - String var_name, String stream_name) { - for (int i = 0; i < getNumField(); i++) { - getField(i).getType().RAPID_AddDecodeInstr(env, instrs, - var_name + "." + getField(i).getName(), stream_name); - } - } - - public void FixedArrayType.RAPID_AddDecodeInstr(RAPID_env env, - java.util.List<String> instrs, - String var_name, String stream_name) { - for (int i = 1; i <= getExp(0).RAPID_getValue(); i++) { - getType().RAPID_AddDecodeInstr(env, instrs, - var_name + ".e" + i, stream_name); - } - } - - public void PrimType.RAPID_AddDecodeInstr(RAPID_env env, - java.util.List<String> instrs, - String var_name, String stream_name) { - switch(getToken()) { - case LABCOMM_BYTE: - instrs.add("Decode_Byte " + stream_name + "," + var_name + ";"); - break; - case LABCOMM_BOOLEAN: - instrs.add("Decode_Bool " + stream_name + "," + var_name + ";"); - break; - case LABCOMM_SHORT: - instrs.add("Decode_Short " + stream_name + "," + var_name + ";"); - break; - case LABCOMM_INT: - instrs.add("Decode_Int " + stream_name + "," + var_name + ";"); - break; - case LABCOMM_LONG: - instrs.add("Decode_Long " + stream_name + "," + var_name + ";"); - break; - case LABCOMM_FLOAT: - instrs.add("Decode_Float " + stream_name + "," + var_name + ";"); - break; - case LABCOMM_STRING: - instrs.add("Decode_String " + stream_name + "," + var_name + ";"); - break; - default: - throw new UnsupportedOperationException("RAPID code generation does not (currently) support "+getName()); - } - } - - public void Type.RAPID_AddEncodeInstr(RAPID_env env, - java.util.List<String> instrs, - String var_name, String stream_name) { - throw new UnsupportedOperationException("RAPID code generation does not (currently) support "+getClass().getSimpleName()); - } - - public void StructType.RAPID_AddEncodeInstr(RAPID_env env, - java.util.List<String> instrs, - String var_name, String stream_name) { - for (int i = 0; i < getNumField(); i++) { - getField(i).getType().RAPID_AddEncodeInstr(env, instrs, - var_name + "." + getField(i).getName(), stream_name); - } - } - - public void FixedArrayType.RAPID_AddEncodeInstr(RAPID_env env, - java.util.List<String> instrs, - String var_name, String stream_name) { - for (int i = 1; i <= getExp(0).RAPID_getValue(); i++) { - getType().RAPID_AddEncodeInstr(env, instrs, - var_name + ".e" + i, stream_name); - } - } - - public void PrimType.RAPID_AddEncodeInstr(RAPID_env env, - java.util.List<String> instrs, - String var_name, String stream_name) { - switch(getToken()) { - case LABCOMM_BYTE: - instrs.add("Encode_Byte " + stream_name + "," + var_name + ";"); - break; - case LABCOMM_BOOLEAN: - instrs.add("Encode_Bool " + stream_name + "," + var_name + ";"); - break; - case LABCOMM_SHORT: - instrs.add("Encode_Short " + stream_name + "," + var_name + ";"); - break; - case LABCOMM_INT: - instrs.add("Encode_Int " + stream_name + "," + var_name + ";"); - break; - case LABCOMM_LONG: - instrs.add("Encode_Long " + stream_name + "," + var_name + ";"); - break; - case LABCOMM_FLOAT: - instrs.add("Encode_Float " + stream_name + "," + var_name + ";"); - break; - case LABCOMM_STRING: - instrs.add("Encode_String " + stream_name + "," + var_name + ";"); - break; - default: - throw new UnsupportedOperationException("RAPID code generation does not (currently) support "+getName()); - } - } - - public int Exp.RAPID_getValue() { - throw new UnsupportedOperationException("RAPID code generation does not (currently) support "+getClass().getSimpleName()); - } - - public int IntegerLiteral.RAPID_getValue() { - return Integer.parseInt(getValue()); - } -} diff --git a/compiler/2014/Python_CodeGen.jrag b/compiler/2014/Python_CodeGen.jrag deleted file mode 100644 index 68b9b95..0000000 --- a/compiler/2014/Python_CodeGen.jrag +++ /dev/null @@ -1,231 +0,0 @@ -aspect Python_CodeGenEnv { - - // Environment wrapper for Python code generation - // handles qualid nesting, indentation, file writing and - // prefix propagation - - public class Python_env { - - final private class Python_printer { - - private boolean newline = true; - private PrintStream out; - - public Python_printer(PrintStream out) { - this.out = out; - } - - public void print(Python_env env, String s) { - if (newline) { - newline = false; - for (int i = 0 ; i < env.indent ; i++) { - out.print(" "); - } - } - out.print(s); - } - - public void println(Python_env env, String s) { - print(env, s); - out.println(); - newline = true; - } - - public void println(Python_env env) { - out.println(); - newline = true; - } - - } - - private int indent; - private Python_printer printer; - - public Python_env(PrintStream out) { - this.indent = 0; - this.printer = new Python_printer(out); - } - - public void indent() { - indent++; - } - - public void unindent() { - indent--; - } - - public void print(String s) { - printer.print(this, s); - } - - public void println(String s) { - printer.println(this, s); - } - - public void println() { - printer.println(this); - } - - } - -} - -aspect Python_CodeGen { - - public void Program.Python_gen(PrintStream out, String baseName, int version) { - // Remove when Blomdell has verified that it is OK to ignore version - // when generating python code. - System.err.println("*** Warning! Python_gen ignores version: "+version); - Python_env env = new Python_env(out); - env.println("#!/usr/bin/python"); - env.println("# Auto generated " + baseName); - env.println(); - env.println("import labcomm"); - env.println("import StringIO"); - env.println(); - Python_genTypes(env); - env.println("typedef = tuple(["); - env.indent(); - for (int i = 0 ; i < getNumDecl() ; i++) { - getDecl(i).Python_genTypedefListEntry(env); - } - env.unindent(); - env.println("])"); - env.println("sample = tuple(["); - env.indent(); - for (int i = 0 ; i < getNumDecl() ; i++) { - getDecl(i).Python_genSampleListEntry(env); - } - env.unindent(); - env.println("])"); - } - -} - -aspect PythonTypes { - - public void Program.Python_genTypes(Python_env env) { - for (int i = 0 ; i < getNumDecl() ; i++) { - getDecl(i).Python_genSignature(env); - } - } - - public void Decl.Python_genSignature(Python_env env) { - throw new Error(this.getClass().getName() + - ".Python_genSignature(Python_env env)" + - " not declared"); - } - - public void TypeDecl.Python_genSignature(Python_env env) { - env.println("class " + getName() + "(object):"); - env.indent(); - env.println("signature = labcomm.typedef('" + getName() + "',"); - env.indent(); - getType().Python_genSignature(env); - env.unindent(); - env.println(")"); - env.unindent(); - env.println(); - } - - public void SampleDecl.Python_genSignature(Python_env env) { - env.println("class " + getName() + "(object):"); - env.indent(); - env.println("signature = labcomm.sample('" + getName() + "', "); - env.indent(); - getType().Python_genSignature(env); - env.unindent(); - env.println(")"); - env.unindent(); - env.println(); - } - - public void UserType.Python_genSignature(Python_env env) { - env.println(getName() + ".signature"); - // lookupType(getName()).getType().Python_genSignature(env); - } - - public void Type.Python_genSignature(Python_env env) { - throw new Error(this.getClass().getName() + - ".Python_genSignature(Python_env env)" + - " not declared"); - } - - 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; - } - } - - public void ArrayType.Python_genSignature(Python_env env) { - env.print("labcomm.array(["); - for (int i = 0 ; i < getNumExp() ; i++) { - if (i > 0) { env.print(", "); } - env.print(getExp(i).Python_getValue()); - } - env.println("],"); - env.indent(); - getType().Python_genSignature(env); - env.print(")"); - env.unindent(); - } - - public void StructType.Python_genSignature(Python_env env) { - env.println("labcomm.struct(["); - env.indent(); - for (int i = 0 ; i < getNumField() ; i++) { - if (i > 0) { env.println(","); } - getField(i).Python_genSignature(env); - } - env.print("])"); - env.unindent(); - } - - public void VoidType.Python_genSignature(Python_env env) { - env.println("labcomm.struct([])"); - } - - public void Field.Python_genSignature(Python_env env) { - env.print("('" + getName() + "', "); - getType().Python_genSignature(env); - env.print(")"); - } - - public void Decl.Python_genTypedefListEntry(Python_env env) { - } - - public void TypeDecl.Python_genTypedefListEntry(Python_env env) { - env.println(getName() + ","); - } - - public void Decl.Python_genSampleListEntry(Python_env env) { - } - - public void SampleDecl.Python_genSampleListEntry(Python_env env) { - env.println(getName()+ ","); - } - - public String Exp.Python_getValue() { - throw new Error(this.getClass().getName() + - ".Python_getValue()" + - " not declared"); - } - - public String IntegerLiteral.Python_getValue() { - return getValue(); - } - - public String VariableSize.Python_getValue() { - return "0"; - } - -} - diff --git a/examples/duck_typing/duck_typing.py b/examples/duck_typing/duck_typing.py index 3138e47..c49f334 100755 --- a/examples/duck_typing/duck_typing.py +++ b/examples/duck_typing/duck_typing.py @@ -1,6 +1,6 @@ #!/usr/bin/python -import labcomm +import labcomm2006 import animal import StringIO @@ -10,7 +10,7 @@ class Animal: if __name__ == '__main__': buf = StringIO.StringIO() - encoder = labcomm.Encoder(labcomm.StreamWriter(buf)) + encoder = labcomm2006.Encoder(labcomm2006.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 = labcomm2006.Decoder(labcomm2006.StreamReader(buf)) try: while True: value,decl = decoder.decode() diff --git a/lib/RAPID/LabComm.sys b/lib/RAPID/LabComm.sys deleted file mode 100644 index 8d31dce..0000000 --- a/lib/RAPID/LabComm.sys +++ /dev/null @@ -1,317 +0,0 @@ -MODULE LabComm(SYSMODULE) - - RECORD LabComm_Stream - socketdev soc; - ENDRECORD - - RECORD LabComm_Decoder_Sample - string prefix; - string name; - num user_id; - string handler; - ENDRECORD - - RECORD LabComm_Encoder_Sample - string prefix; - string name; - num user_id; - ENDRECORD - - RECORD Decoder - num user_id; - ENDRECORD - - RECORD Encoder - num next_user_id; - ENDRECORD - - ! LabComm constants - CONST string LabCommVersion := "LabComm2013"; - CONST num SAMPLE_DECL:=2; - CONST num SAMPLE_DATA:=64; - - CONST num STRUCT_TYPE := 17; - CONST num ARRAY_TYPE := 16; - CONST num BYTE_TYPE := 37; - CONST num BOOL_TYPE := 37; - CONST num SHORT_TYPE := 34; - CONST num INT_TYPE := 37; - CONST num LONG_TYPE := 37; - CONST num FLOAT_TYPE := 37; - - ! Error declarations - CONST errnum INCORRECT_LABCOMM_VERSION := 50; - CONST errnum UNKNOWN_PACKET_TYPE := 51; - CONST errnum UNKNOWN_SAMPLE_TYPE := 52; - CONST errnum INCORRECT_SAMPLE_SIGNATURE := 53; - CONST errnum SAMPLE_TYPE_NOT_REGISTERED := 54; - CONST errnum IMPLEMENTATION_LIMIT_REACHED := 55; - - PROC Decode_Packed(VAR LabComm_Stream s, VAR num v, \ VAR rawbytes collect) - VAR rawbytes buffer; - SocketReceive s.soc,\RawData:=buffer,\ReadNoOfBytes:=1; - UnpackRawBytes buffer,\Network,1,v,\IntX:=USINT; - IF Present(collect) THEN - CopyRawBytes buffer, 1, collect, (RawBytesLen(collect)+1); - ENDIF - ERROR - RAISE ; - ENDPROC - - PROC Encode_Packed(VAR LabComm_Stream s, num v) - VAR rawbytes buffer; - PackRawBytes v,buffer,\Network,1,\IntX:=USINT; - SocketSend s.soc,\RawData:=buffer,\NoOfBytes:=1; - ERROR - RAISE ; - ENDPROC - - PROC Decode_Boolean(VAR LabComm_Stream s, VAR bool v, \ VAR rawbytes collect) - VAR rawbytes buffer; - VAR num tmp; - SocketReceive s.soc,\RawData:=buffer,\ReadNoOfBytes:=1; - UnpackRawBytes buffer,\Network,1,tmp,\IntX:=USINT; - IF tmp = 0 THEN - v := FALSE; - ELSE - v := TRUE; - ENDIF - IF Present(collect) THEN - CopyRawBytes buffer, 1, collect, (RawBytesLen(collect)+1); - ENDIF - ERROR - RAISE ; - ENDPROC - - PROC Encode_Boolean(VAR LabComm_Stream s, bool v) - VAR rawbytes buffer; - VAR num tmp; - IF v THEN - tmp := 1; - ELSE - tmp := 0; - ENDIF - PackRawBytes tmp,buffer,\Network,1,\IntX:=USINT; - SocketSend s.soc,\RawData:=buffer,\NoOfBytes:=1; - ERROR - RAISE ; - ENDPROC - - PROC Decode_Byte(VAR LabComm_Stream s, VAR byte v, \ VAR rawbytes collect) - VAR rawbytes buffer; - SocketReceive s.soc,\RawData:=buffer,\ReadNoOfBytes:=1; - UnpackRawBytes buffer,\Network,1,v,\Hex1; - IF Present(collect) THEN - CopyRawBytes buffer, 1, collect, (RawBytesLen(collect)+1); - ENDIF - ERROR - RAISE ; - ENDPROC - - PROC Encode_Byte(VAR LabComm_Stream s, byte v) - VAR rawbytes buffer; - PackRawBytes v,buffer,\Network,1,\Hex1; - SocketSend s.soc,\RawData:=buffer,\NoOfBytes:=1; - ERROR - RAISE ; - ENDPROC - - PROC Decode_Short(VAR LabComm_Stream s,VAR num v, \ VAR rawbytes collect) - VAR rawbytes buffer; - SocketReceive s.soc,\RawData:=buffer,\ReadNoOfBytes:=2; - UnpackRawBytes buffer,\Network,1,v,\IntX:=INT; - IF Present(collect) THEN - CopyRawBytes buffer, 1, collect, (RawBytesLen(collect)+1); - ENDIF - ERROR - RAISE ; - ENDPROC - - PROC Encode_Short(VAR LabComm_Stream s, num v) - VAR rawbytes buffer; - PackRawBytes v, buffer, \Network, 1, \IntX:=INT; - SocketSend s.soc, \RawData:=buffer, \NoOfBytes:=2; - ERROR - RAISE ; - ENDPROC - - PROC Decode_Integer(VAR LabComm_Stream s, VAR num v, \ VAR rawbytes collect) - VAR rawbytes buffer; - SocketReceive s.soc,\RawData:=buffer,\ReadNoOfBytes:=4; - UnpackRawBytes buffer,\Network,1,v,\IntX:=DINT; - IF Present(collect) THEN - CopyRawBytes buffer, 1, collect, (RawBytesLen(collect)+1); - ENDIF - ERROR - RAISE ; - ENDPROC - - PROC Encode_Integer(VAR LabComm_Stream s, num v) - VAR rawbytes buffer; - PackRawBytes v,buffer,\Network,1,\IntX:=DINT; - SocketSend s.soc,\RawData:=buffer,\NoOfBytes:=4; - ERROR - RAISE ; - ENDPROC - - PROC Decode_Long(VAR LabComm_Stream s, VAR dnum v, \ VAR rawbytes collect) - VAR rawbytes buffer; - SocketReceive s.soc,\RawData:=buffer,\ReadNoOfBytes:=8; - UnpackRawBytes buffer,\Network,1,v,\IntX:=LINT; - IF Present(collect) THEN - CopyRawBytes buffer, 1, collect, (RawBytesLen(collect)+1); - ENDIF - ERROR - RAISE ; - ENDPROC - - PROC Encode_Long(VAR LabComm_Stream s, dnum v) - VAR rawbytes buffer; - PackRawBytes v,buffer,\Network,1,\IntX:=LINT; - SocketSend s.soc,\RawData:=buffer,\NoOfBytes:=8; - ERROR - RAISE ; - ENDPROC - - PROC Decode_Float(VAR LabComm_Stream s,VAR num v, \ VAR rawbytes collect) - VAR rawbytes buffer; - SocketReceive s.soc,\RawData:=buffer,\ReadNoOfBytes:=4; - UnpackRawBytes buffer,\Network,1,v,\Float4; - IF Present(collect) THEN - CopyRawBytes buffer, 1, collect, (RawBytesLen(collect)+1); - ENDIF - ERROR - RAISE ; - ENDPROC - - PROC Encode_Float(VAR LabComm_Stream s, num v) - VAR rawbytes buffer; - PackRawBytes v, buffer,\Network,1,\Float4; - SocketSend s.soc,\RawData:=buffer,\NoOfBytes:=4; - ERROR - RAISE ; - ENDPROC - - PROC Decode_String(VAR LabComm_Stream st,VAR string s, \ VAR rawbytes collect) - VAR rawbytes buffer; - VAR num length; - IF Present(collect) THEN - Decode_Packed st, length, \collect:=collect; - ELSE - Decode_Packed st, length; - ENDIF - SocketReceive st.soc,\Str:=s,\ReadNoOfBytes:=length; - IF Present(collect) THEN - PackRawBytes s, collect, (RawBytesLen(collect)+1), \ASCII; - ENDIF - ERROR - RAISE ; - ENDPROC - - PROC Encode_String(VAR LabComm_Stream st, string s) - VAR rawbytes buffer; - VAR num length; - length := StrLen(s); - Encode_Packed st, length; - SocketSend st.soc,\Str:=s,\NoOfBytes:=length; - ERROR - RAISE ; - ENDPROC - - PROC Encoder_Register_Sample(VAR Encoder e, VAR LabComm_Stream st, VAR LabComm_Encoder_Sample s) - s.user_id := e.next_user_id; - e.next_user_id := e.next_user_id + 1; - Encode_Packed st, SAMPLE_DECL; - Encode_Packed st, s.user_id; - Encode_String st, s.name; - % s.prefix + ":Encode_Signature_" + s.name % e, st; - ERROR - RAISE ; - ENDPROC - - PROC Collect_Array(VAR LabComm_Stream s, VAR rawbytes sig) - VAR num num_dim; - VAR num dims; - Decode_Packed s, num_dim, \collect:=sig; - FOR i FROM 1 TO num_dim DO - Decode_Packed s, dims, \collect:=sig; - ENDFOR - Collect_Signature s, sig; - ERROR - RAISE ; - ENDPROC - - PROC Collect_Struct(VAR LabComm_Stream s, VAR rawbytes sig) - VAR num num_elements; - VAR string tmp; - Decode_Packed s, num_elements, \collect:=sig; - FOR i FROM 1 TO num_elements DO - Decode_String s, tmp, \collect:=sig; - Collect_Signature s, sig; - ENDFOR - ERROR - RAISE ; - ENDPROC - - PROC Collect_Signature(VAR LabComm_Stream s, VAR rawbytes sig) - VAR num type_id; - Decode_Packed s, type_id, \collect:=sig; - TEST type_id - CASE STRUCT_TYPE: - Collect_Struct s, sig; - CASE ARRAY_TYPE: - Collect_Array s, sig; - CASE BYTE_TYPE, BOOL_TYPE, SHORT_TYPE, INT_TYPE, LONG_TYPE, SHORT_TYPE: - DEFAULT: - RAISE IMPLEMENTATION_LIMIT_REACHED; - ENDTEST - ERROR - RAISE ; - ENDPROC - - PROC Decode_One(VAR Decoder d, VAR LabComm_Stream s, VAR LabComm_Decoder_Sample samples{*}) - VAR rawbytes buffer; - VAR num packet_type; - VAR num user_id; - VAR string type_name; - Decode_Packed s, packet_type; - WHILE packet_type = SAMPLE_DECL DO - Decode_Packed s, user_id; - Decode_String s, type_name; - Collect_Signature s, buffer; - FOR i FROM 1 TO Dim(samples, 1) DO - % samples{i}.prefix + ":Reg_If_Signature_Of_" + samples{i}.name % samples{i}, buffer, user_id; - ENDFOR - Decode_Packed s, packet_type; - ENDWHILE - IF packet_type >= SAMPLE_DATA THEN - FOR i FROM 1 TO Dim(samples, 1) DO - IF samples{i}.user_id = packet_type THEN - % samples{i}.prefix + ":Decode_And_Handle_" + samples{i}.name % d, s, samples{i}; - ENDIF - ENDFOR - RETURN ; - ENDIF - RAISE UNKNOWN_PACKET_TYPE; - ERROR - RAISE ; - ENDPROC - - PROC Init_Decoder(VAR Decoder d, VAR LabComm_Stream s) - VAR string version; - Decode_String s,version; - IF version<>LabCommVersion THEN - RAISE INCORRECT_LABCOMM_VERSION; - ENDIF - ERROR - RAISE ; - ENDPROC - - PROC Init_Encoder(VAR Encoder e, VAR LabComm_Stream s) - Encode_String s, LabCommVersion; - e.next_user_id := SAMPLE_DATA; - ERROR - RAISE ; - ENDPROC - -ENDMODULE \ No newline at end of file diff --git a/lib/RAPID/README b/lib/RAPID/README deleted file mode 100644 index e59711f..0000000 --- a/lib/RAPID/README +++ /dev/null @@ -1,104 +0,0 @@ -The implementation of LabComm in RAPID - -Limitations of this implementation: - - The type double is not available due to limitations in RAPID. There is a - non-integer type with 64 bits but there is not marshalling utilities for it. - - Variable sized arrays is not available. There is no dynamic allocation, - possible solution is a max-size array (1024) and a integervalue denoting the - size. - - A RECORD (struct) cannot contain an array, but fixed size arrays are - available both in structs and stand alone. The current implementation creates - a RECORD with one member for each index in the array. Not an omptimal - solution, the alternativ would be a seperate variable. - - Decoding and encoding is done directly from a TCP socket. - - Every generated procedure is namespaced by declaring them LOCAL to the - generated module. They must be called by using runtime binding of procedure - names ( % proc_name % arg1, arg2, ...;). The generated types are not - declared local. - -Usage: - -# Declare a stream, LabComm_Stream: - $ VAR LabComm_Stream st; -This contains a socketdev wich must be created and connected or instatiated -through an accept. - $ SocketCreate st.soc; - $ SocketConnect st.soc, "127.0.0.1", 55555; -or - $ SocketAccept server_socket, st.soc; - -# Initiate Encoder and/or Decoder with the stream: - $ VAR Decoder d; - $ Init_Decoder d, st; - - $ VAR Encoder e; - $ Init_Encoder e, st; -This will read/write the version of LabComm to ensure compatibility, current -version is "LabComm2014". - -# Initiate the labcomm samples: -LabComm trusts the application to manage each sample. It requests the samples, -as a list, when performing decoding or encoding. -This is done through the generated code which implies the procedures are LOCAL -and must be called with runtime bindings. -When initiating a decoder sample the name of the callback procedure to receive -such samples is suplied as a string. - $ PROC handle_samplename(prefix_samplename val) - $ ... - $ ENDPROC - $ VAR LabComm_Decoder_Sample ds{1}; - $ % prefix:Dec_Reg_samplename % ds{1}, "handle_samplename"; -NOTE: The callback must be of type procedure and not function. Functions cannot -be called with runtime bindings. - -When initiating an encoder sample the stream must be supplied to let the -encoder send the sample signature. - $ VAR LabComm_Encoder_Sample es{1}; - $ % prefix:Enc_Reg_samplename % e, st, es{1}; - -# Encode and/or decode samples: - $ Decode_One d, st, ds; -It returns as soon as any sample is decoded. The decoded sample is supplied as -argument to the callback procedure registered with the corresponding sample. - $ VAR prefix_samplename val; - $ <init val> - $ % prefix:Encode_samplename % e, st, es{1}, val; - -# Complete example: - -## LabComm definition: -example.lc >> -sample struct { - short sum; - short terms[2]; -} foo; -<< EOF - -## RAPID CODE -PROC handle_foo(example_foo val) - IF val.sum = val.terms.e1 + val.terms.e2 THEN - TPWrite "Verification successfull!"; - ELSE - TPWrite "Verification failed!"; - ENDIF -ENDPROC - - -PROC main() - VAR Decoder d; - VAR Encoder e; - VAR LabComm_Stream st; - VAR LabComm_Encoder_Sample es{1}; - VAR LabComm_Decoder_Sample ds{1}; - VAR example_foo val := [2,[1,1]]; - SocketCreate st.soc; - SocketConnect st.soc, "127.0.0.1", 55555; - Init_Decoder d, st; - Init_Encoder e, st; - % "example:Enc_Reg_foo" % e, st, es{1}; - % "example:Dec_Reg_foo" % ds{1}, "handle_foo"; - % "example:Encode_foo" % e, st, es{1}, val; - Decode_One d, st, ds; - SocketClose st.soc; -ENDPROC - diff --git a/lib/c/2006/labcomm2006.c b/lib/c/2006/labcomm2006.c index badfe47..0f46cec 100644 --- a/lib/c/2006/labcomm2006.c +++ b/lib/c/2006/labcomm2006.c @@ -262,6 +262,6 @@ int labcomm2006_internal_sizeof(const struct labcomm2006_signature *signature, void *v) { int length = signature->encoded_size(v); - return (labcomm2006_size_packed32(signature->index) + + return (labcomm2006_size_int(signature->index) + length); } diff --git a/lib/c/2006/labcomm2006_decoder.c b/lib/c/2006/labcomm2006_decoder.c index 2ae181d..5a77d8e 100644 --- a/lib/c/2006/labcomm2006_decoder.c +++ b/lib/c/2006/labcomm2006_decoder.c @@ -87,23 +87,23 @@ static int collect_flat_signature( { int result, type; - type = labcomm2006_read_packed32(decoder->reader); + type = labcomm2006_read_int(decoder->reader); result = decoder->reader->error; if (result < 0) { goto out; } if (type >= LABCOMM_USER) { decoder->on_error(LABCOMM2006_ERROR_UNIMPLEMENTED_FUNC, 3, "Implement %s ... (1) for type 0x%x\n", __FUNCTION__, type); } else { - labcomm2006_write_packed32(writer, type); + labcomm2006_write_int(writer, type); switch (type) { case LABCOMM_ARRAY: { int dimensions, i; - dimensions = labcomm2006_read_packed32(decoder->reader); - labcomm2006_write_packed32(writer, dimensions); + dimensions = labcomm2006_read_int(decoder->reader); + labcomm2006_write_int(writer, dimensions); for (i = 0 ; i < dimensions ; i++) { - int n = labcomm2006_read_packed32(decoder->reader); - labcomm2006_write_packed32(writer, n); + int n = labcomm2006_read_int(decoder->reader); + labcomm2006_write_int(writer, n); } result = collect_flat_signature(decoder, writer); if (result < 0) { goto out; } @@ -111,8 +111,8 @@ static int collect_flat_signature( case LABCOMM_STRUCT: { int fields, i; - fields = labcomm2006_read_packed32(decoder->reader); - labcomm2006_write_packed32(writer, fields); + fields = labcomm2006_read_int(decoder->reader); + labcomm2006_write_int(writer, fields); for (i = 0 ; i < fields ; i++) { char *name = labcomm2006_read_string(decoder->reader); labcomm2006_write_string(writer, name); @@ -189,7 +189,7 @@ static int decode_typedef_or_sample(struct labcomm2006_decoder *d, int kind) local_index = 0; labcomm2006_writer_alloc(&writer, writer.action_context); labcomm2006_writer_start(&writer, writer.action_context, 0, NULL, NULL); - remote_index = labcomm2006_read_packed32(d->reader); + remote_index = labcomm2006_read_int(d->reader); signature.name = labcomm2006_read_string(d->reader); collect_flat_signature(d, &writer); labcomm2006_writer_end(&writer, writer.action_context); @@ -296,7 +296,7 @@ int labcomm2006_decoder_decode_one(struct labcomm2006_decoder *d) int result, remote_index; reader_alloc(d); - remote_index = labcomm2006_read_packed32(d->reader); + remote_index = labcomm2006_read_int(d->reader); if (d->reader->error < 0) { result = d->reader->error; goto out; diff --git a/lib/c/2006/labcomm2006_encoder.c b/lib/c/2006/labcomm2006_encoder.c index 4eb8eca..9d83a54 100644 --- a/lib/c/2006/labcomm2006_encoder.c +++ b/lib/c/2006/labcomm2006_encoder.c @@ -85,8 +85,8 @@ int labcomm2006_internal_encoder_register( index, signature, NULL); if (err == -EALREADY) { result = 0; goto out; } if (err != 0) { result = err; goto out; } - labcomm2006_write_packed32(e->writer, LABCOMM_SAMPLE); - labcomm2006_write_packed32(e->writer, index); + labcomm2006_write_int(e->writer, LABCOMM_SAMPLE); + labcomm2006_write_int(e->writer, index); labcomm2006_write_string(e->writer, signature->name); for (i = 0 ; i < signature->size ; i++) { if (e->writer->pos >= e->writer->count) { @@ -117,7 +117,7 @@ int labcomm2006_internal_encode( index, signature, value); if (result == -EALREADY) { result = 0; goto no_end; } if (result != 0) { goto out; } - result = labcomm2006_write_packed32(e->writer, index); + result = labcomm2006_write_int(e->writer, index); if (result != 0) { goto out; } result = encode(e->writer, value); out: diff --git a/lib/c/2006/labcomm2006_private.h b/lib/c/2006/labcomm2006_private.h index c3bd51d..7a46165 100644 --- a/lib/c/2006/labcomm2006_private.h +++ b/lib/c/2006/labcomm2006_private.h @@ -231,14 +231,14 @@ LABCOMM_DECODE(float, float) LABCOMM_DECODE(double, double) // compatibility with 2014 version -#define labcomm2006_read_packed32 labcomm2006_read_int +#define labcomm2006_read_int labcomm2006_read_int static inline char *labcomm2006_read_string(struct labcomm2006_reader *r) { char *result = NULL; int length, pos; - length = labcomm2006_read_packed32(r); + length = labcomm2006_read_int(r); result = labcomm2006_memory_alloc(r->memory, 1, length + 1); if (!result) { labcomm2006_on_error_fprintf(LABCOMM2006_ERROR_MEMORY, 4, "%d byte at %s:%d", @@ -392,10 +392,10 @@ LABCOMM_ENCODE(long, long long) LABCOMM_ENCODE(float, float) LABCOMM_ENCODE(double, double) -#define labcomm2006_write_packed32 labcomm2006_write_int +#define labcomm2006_write_int labcomm2006_write_int #if 0 -static inline int labcomm2006_write_packed32(struct labcomm2006_writer *w, +static inline int labcomm2006_write_int(struct labcomm2006_writer *w, unsigned int data) { unsigned char tmp[5]; @@ -421,7 +421,7 @@ static inline int labcomm2006_write_string(struct labcomm2006_writer *w, char *s int length, i, err; length = strlen((char*)s); - err = labcomm2006_write_packed32(w, length); + err = labcomm2006_write_int(w, length); if (err != 0) { return err; } for (i = 0 ; i < length ; i++) { if (w->pos >= w->count) { @@ -435,8 +435,8 @@ static inline int labcomm2006_write_string(struct labcomm2006_writer *w, char *s return 0; } -/* Size of packed32 variable is 4 as we use int*/ -static inline int labcomm2006_size_packed32(unsigned int data) +/* Size of int variable is 4 as we use int*/ +static inline int labcomm2006_size_int(unsigned int data) { return 4; } diff --git a/lib/c/2006/test/test_labcomm_basic_type_encoding.c b/lib/c/2006/test/test_labcomm_basic_type_encoding.c index f6582e2..2a48d3e 100644 --- a/lib/c/2006/test/test_labcomm_basic_type_encoding.c +++ b/lib/c/2006/test/test_labcomm_basic_type_encoding.c @@ -46,8 +46,6 @@ static struct labcomm2006_reader reader = { .pos = 0, }; -typedef uint32_t packed32; - #define TEST_WRITE_READ(type, ltype, format, value, expect_count, expect_bytes) \ { \ type decoded; \ @@ -93,16 +91,6 @@ static void writer_assert(char *type, int main(void) { - TEST_WRITE_READ(packed32, packed32, "%d", 0x00000000, 4, "\x00\x00\x00\x00"); - TEST_WRITE_READ(packed32, packed32, "%d", 0x0000007f, 4, "\x00\x00\x00\x7f"); - TEST_WRITE_READ(packed32, packed32, "%d", 0x00000080, 4, "\x00\x00\x00\x80"); - TEST_WRITE_READ(packed32, packed32, "%d", 0x00003fff, 4, "\x00\x00\x3f\xff"); - TEST_WRITE_READ(packed32, packed32, "%d", 0x00004000, 4, "\x00\x00\x40\x00"); - TEST_WRITE_READ(packed32, packed32, "%d", 0x001fffff, 4, "\x00\x1f\xff\xff"); - TEST_WRITE_READ(packed32, packed32, "%d", 0x00200000, 4, "\x00\x20\x00\x00"); - TEST_WRITE_READ(packed32, packed32, "%d", 0x0fffffff, 4, "\x0f\xff\xff\xff"); - TEST_WRITE_READ(packed32, packed32, "%d", 0x10000000, 4, "\x10\x00\x00\x00"); - TEST_WRITE_READ(packed32, packed32, "%d", 0xffffffff, 4, "\xff\xff\xff\xff"); TEST_WRITE_READ(uint8_t, boolean, "%d", 0, 1, "\x00"); TEST_WRITE_READ(uint8_t, boolean, "%d", 1, 1, "\x01"); TEST_WRITE_READ(uint8_t, byte, "%d", 0, 1, "\x00"); diff --git a/lib/csharp/se/lth/control/labcomm2006/Constant.cs b/lib/csharp/se/lth/control/labcomm2006/Constant.cs index e74678f..01eb7c8 100644 --- a/lib/csharp/se/lth/control/labcomm2006/Constant.cs +++ b/lib/csharp/se/lth/control/labcomm2006/Constant.cs @@ -1,4 +1,4 @@ -namespace se.lth.control.labcomm { +namespace se.lth.control.labcomm2006 { public class Constant { diff --git a/lib/csharp/se/lth/control/labcomm2006/Decoder.cs b/lib/csharp/se/lth/control/labcomm2006/Decoder.cs index 70c8138..007d657 100644 --- a/lib/csharp/se/lth/control/labcomm2006/Decoder.cs +++ b/lib/csharp/se/lth/control/labcomm2006/Decoder.cs @@ -1,6 +1,6 @@ using System; -namespace se.lth.control.labcomm { +namespace se.lth.control.labcomm2006 { public interface Decoder { diff --git a/lib/csharp/se/lth/control/labcomm2006/DecoderChannel.cs b/lib/csharp/se/lth/control/labcomm2006/DecoderChannel.cs index 334742f..1b68cff 100644 --- a/lib/csharp/se/lth/control/labcomm2006/DecoderChannel.cs +++ b/lib/csharp/se/lth/control/labcomm2006/DecoderChannel.cs @@ -1,4 +1,4 @@ -namespace se.lth.control.labcomm { +namespace se.lth.control.labcomm2006 { using System; using System.IO; diff --git a/lib/csharp/se/lth/control/labcomm2006/DecoderRegistry.cs b/lib/csharp/se/lth/control/labcomm2006/DecoderRegistry.cs index 132e37b..078dd83 100644 --- a/lib/csharp/se/lth/control/labcomm2006/DecoderRegistry.cs +++ b/lib/csharp/se/lth/control/labcomm2006/DecoderRegistry.cs @@ -1,4 +1,4 @@ -namespace se.lth.control.labcomm { +namespace se.lth.control.labcomm2006 { using System; using System.Collections.Generic; diff --git a/lib/csharp/se/lth/control/labcomm2006/Encoder.cs b/lib/csharp/se/lth/control/labcomm2006/Encoder.cs index 5fe9d1f..b861add 100644 --- a/lib/csharp/se/lth/control/labcomm2006/Encoder.cs +++ b/lib/csharp/se/lth/control/labcomm2006/Encoder.cs @@ -1,4 +1,4 @@ -namespace se.lth.control.labcomm { +namespace se.lth.control.labcomm2006 { using System; diff --git a/lib/csharp/se/lth/control/labcomm2006/EncoderChannel.cs b/lib/csharp/se/lth/control/labcomm2006/EncoderChannel.cs index 3ef38e0..fa46783 100644 --- a/lib/csharp/se/lth/control/labcomm2006/EncoderChannel.cs +++ b/lib/csharp/se/lth/control/labcomm2006/EncoderChannel.cs @@ -1,4 +1,4 @@ -namespace se.lth.control.labcomm { +namespace se.lth.control.labcomm2006 { using System; using System.IO; diff --git a/lib/csharp/se/lth/control/labcomm2006/EncoderRegistry.cs b/lib/csharp/se/lth/control/labcomm2006/EncoderRegistry.cs index 9c40028..e097f11 100644 --- a/lib/csharp/se/lth/control/labcomm2006/EncoderRegistry.cs +++ b/lib/csharp/se/lth/control/labcomm2006/EncoderRegistry.cs @@ -1,4 +1,4 @@ -namespace se.lth.control.labcomm { +namespace se.lth.control.labcomm2006 { using System; using System.Collections.Generic; diff --git a/lib/csharp/se/lth/control/labcomm2006/Sample.cs b/lib/csharp/se/lth/control/labcomm2006/Sample.cs index c9ea7fd..8f95265 100644 --- a/lib/csharp/se/lth/control/labcomm2006/Sample.cs +++ b/lib/csharp/se/lth/control/labcomm2006/Sample.cs @@ -1,4 +1,4 @@ -namespace se.lth.control.labcomm { +namespace se.lth.control.labcomm2006 { public interface Sample { diff --git a/lib/csharp/se/lth/control/labcomm2006/SampleDispatcher.cs b/lib/csharp/se/lth/control/labcomm2006/SampleDispatcher.cs index 23d39ed..61b89f9 100644 --- a/lib/csharp/se/lth/control/labcomm2006/SampleDispatcher.cs +++ b/lib/csharp/se/lth/control/labcomm2006/SampleDispatcher.cs @@ -1,4 +1,4 @@ -namespace se.lth.control.labcomm { +namespace se.lth.control.labcomm2006 { using System; diff --git a/lib/csharp/se/lth/control/labcomm2006/SampleHandler.cs b/lib/csharp/se/lth/control/labcomm2006/SampleHandler.cs index d30cd26..2730d6f 100644 --- a/lib/csharp/se/lth/control/labcomm2006/SampleHandler.cs +++ b/lib/csharp/se/lth/control/labcomm2006/SampleHandler.cs @@ -1,4 +1,4 @@ -namespace se.lth.control.labcomm { +namespace se.lth.control.labcomm2006 { public interface SampleHandler { } diff --git a/lib/java/se/lth/control/labcomm2006/Decoder.java b/lib/java/se/lth/control/labcomm2006/Decoder.java index 0b442cb..44b98bd 100644 --- a/lib/java/se/lth/control/labcomm2006/Decoder.java +++ b/lib/java/se/lth/control/labcomm2006/Decoder.java @@ -14,6 +14,5 @@ public interface Decoder { public float decodeFloat() throws IOException; public double decodeDouble() throws IOException; public String decodeString() throws IOException; - public int decodePacked32() throws IOException; } diff --git a/lib/java/se/lth/control/labcomm2006/DecoderChannel.java b/lib/java/se/lth/control/labcomm2006/DecoderChannel.java index 34acf50..64e260a 100644 --- a/lib/java/se/lth/control/labcomm2006/DecoderChannel.java +++ b/lib/java/se/lth/control/labcomm2006/DecoderChannel.java @@ -18,10 +18,10 @@ public class DecoderChannel implements Decoder { public void runOne() throws Exception { boolean done = false; while (!done) { - int tag = decodePacked32(); + int tag = decodeInt(); switch (tag) { case Constant.SAMPLE: { - int index = decodePacked32(); + int index = decodeInt(); String name = decodeString(); ByteArrayOutputStream signature = new ByteArrayOutputStream(); collectFlatSignature(new EncoderChannel(signature)); @@ -54,20 +54,20 @@ public class DecoderChannel implements Decoder { } private void collectFlatSignature(Encoder out) throws IOException { - int type = decodePacked32(); - out.encodePacked32(type); + int type = decodeInt(); + out.encodeInt(type); switch (type) { case Constant.ARRAY: { - int dimensions = decodePacked32(); - out.encodePacked32(dimensions); + int dimensions = decodeInt(); + out.encodeInt(dimensions); for (int i = 0 ; i < dimensions ; i++) { - out.encodePacked32(decodePacked32()); + out.encodeInt(decodeInt()); } collectFlatSignature(out); } break; case Constant.STRUCT: { - int fields = decodePacked32(); - out.encodePacked32(fields); + int fields = decodeInt(); + out.encodeInt(fields); for (int i = 0 ; i < fields ; i++) { out.encodeString(decodeString()); collectFlatSignature(out); @@ -125,7 +125,7 @@ public class DecoderChannel implements Decoder { public String decodeString() throws IOException { //in.readShort(); // HACK //return in.readUTF(); - int len = decodePacked32() & 0xffffffff; + int len = decodeInt() & 0xffffffff; byte[] chars = new byte[len]; for(int i=0; i<len; i++) { chars[i] = in.readByte(); @@ -133,12 +133,5 @@ public class DecoderChannel implements Decoder { return new String(chars); } - /** - method for API harmonization with labcomm2014. - Labcomm2006 encodes lengths etc as 32 bit ints. - */ - public int decodePacked32() throws IOException { - return in.readInt(); - } } diff --git a/lib/java/se/lth/control/labcomm2006/Encoder.java b/lib/java/se/lth/control/labcomm2006/Encoder.java index eaf54b2..8c421a9 100644 --- a/lib/java/se/lth/control/labcomm2006/Encoder.java +++ b/lib/java/se/lth/control/labcomm2006/Encoder.java @@ -15,6 +15,6 @@ public interface Encoder { public void encodeFloat(float value) throws IOException; public void encodeDouble(double value) throws IOException; public void encodeString(String value) throws IOException; - public void encodePacked32(long value) throws IOException; + public void encodeInt(long value) throws IOException; } diff --git a/lib/java/se/lth/control/labcomm2006/EncoderChannel.java b/lib/java/se/lth/control/labcomm2006/EncoderChannel.java index b164754..c439738 100644 --- a/lib/java/se/lth/control/labcomm2006/EncoderChannel.java +++ b/lib/java/se/lth/control/labcomm2006/EncoderChannel.java @@ -25,8 +25,8 @@ public class EncoderChannel implements Encoder { public void register(SampleDispatcher dispatcher) throws IOException { int index = registry.add(dispatcher); - encodePacked32(Constant.SAMPLE); - encodePacked32(index); + encodeInt(Constant.SAMPLE); + encodeInt(index); encodeString(dispatcher.getName()); byte[] signature = dispatcher.getSignature(); for (int i = 0 ; i < signature.length ; i++) { @@ -36,7 +36,7 @@ public class EncoderChannel implements Encoder { } public void begin(Class<? extends Sample> c) throws IOException { - encodePacked32(registry.getTag(c)); + encodeInt(registry.getTag(c)); } public void end(Class<? extends Sample> c) throws IOException { @@ -84,7 +84,7 @@ public class EncoderChannel implements Encoder { method for API harmonization with labcomm2014. Labcomm2006 encodes lengths etc as 32 bit ints. */ - public void encodePacked32(long value) throws IOException { + public void encodeInt(long value) throws IOException { if(value > Integer.MAX_VALUE) { throw new IllegalArgumentException("Value too large, must fit in 32 bits"); } diff --git a/lib/python/labcomm/__init__.py b/lib/python/labcomm/__init__.py deleted file mode 100644 index 8bcecac..0000000 --- a/lib/python/labcomm/__init__.py +++ /dev/null @@ -1,31 +0,0 @@ -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 - -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 - -decl_from_signature = labcomm.LabComm.decl_from_signature - -try: - import labcomm.TreeModel - TreeModel = labcomm.TreeModel.TreeModel -except: - pass - diff --git a/lib/python/labcomm/LabComm.py b/lib/python/labcomm2006/LabComm.py similarity index 96% rename from lib/python/labcomm/LabComm.py rename to lib/python/labcomm2006/LabComm.py index 6d096f2..70f3899 100644 --- a/lib/python/labcomm/LabComm.py +++ b/lib/python/labcomm2006/LabComm.py @@ -118,7 +118,7 @@ class length_encoder: def __exit__(self, type, value, traceback): if usePacketLength(self.version): - self.encoder.encode_packed32(len(self.data)) + self.encoder.encode_int(len(self.data)) self.encoder.pack("%ds" % len(self.data), self.data) def indent(i, s): @@ -350,9 +350,9 @@ class array(type_decl): def encode_decl(self, encoder): encoder.encode_type(i_ARRAY) - encoder.encode_packed32(len(self.indices)) + encoder.encode_int(len(self.indices)) for i in self.indices: - encoder.encode_packed32(i) + encoder.encode_int(i) encoder.encode_type_number(self.decl) def min_max_shape(self, l, depth, shape): @@ -395,7 +395,7 @@ class array(type_decl): (shape, self.indices)) for i in range(len(self.indices)): if self.indices[i] == 0: - encoder.encode_packed32(shape[i]) + encoder.encode_int(shape[i]) elif self.indices[i] != shape[i]: raise Exception("Actual dimension %d in %s differs from %s" % (i, shape, self.indices)) @@ -413,10 +413,10 @@ class array(type_decl): self.encode_value(encoder, value, depth) def decode_decl(self, decoder): - n_indices = decoder.decode_packed32() + n_indices = decoder.decode_int() indices = [] for i in range(n_indices): - index = decoder.decode_packed32() + index = decoder.decode_int() indices.append(index) elem_decl = decoder.decode_decl() return array(indices, elem_decl) @@ -434,7 +434,7 @@ class array(type_decl): indices = [] for i in self.indices: if i == 0: - i = decoder.decode_packed32() + i = decoder.decode_int() indices.append(i) return self.decode_value(decoder, indices) @@ -451,7 +451,7 @@ class array(type_decl): indices = [] for i in self.indices: if i == 0: - i = decoder.decode_packed32() + i = decoder.decode_int() indices.append(i) return self.new_instance_value(indices) @@ -475,7 +475,7 @@ class struct(type_decl): def encode_decl(self, encoder): encoder.encode_type(i_STRUCT) - encoder.encode_packed32(len(self.field)) + encoder.encode_int(len(self.field)) for (name, decl) in self.field: encoder.encode_string(name) encoder.encode_type_number(decl) @@ -489,7 +489,7 @@ class struct(type_decl): decl.encode(encoder, getattr(obj, name)) def decode_decl(self, decoder): - n_field = decoder.decode_packed32() + n_field = decoder.decode_int() field = [] for i in range(n_field): name = decoder.decode_string() @@ -644,12 +644,12 @@ class Encoder(Codec): except KeyError: decl.encode_decl(self) - def encode_packed32(self, v): + def encode_int(self, v): v = v & 0xffffffff self.encode_int(v) def encode_type(self, index): - self.encode_packed32(index) + self.encode_int(index) def encode_boolean(self, v): if v: @@ -677,7 +677,7 @@ class Encoder(Codec): def encode_string(self, v): s = v.encode("utf8") - self.encode_packed32(len(s)); + self.encode_int(len(s)); self.pack("%ds" % len(s),s) class Decoder(Codec): @@ -728,11 +728,11 @@ class Decoder(Codec): return result - def decode_packed32(self): + def decode_int(self): return self.decode_int() def decode_type_number(self): - return self.decode_packed32() + return self.decode_int() def decode_boolean(self): return self.unpack("!b") != 0 @@ -756,7 +756,7 @@ class Decoder(Codec): return self.unpack("!d") def decode_string(self): - length = self.decode_packed32() + length = self.decode_int() return self.unpack("!%ds" % length).decode("utf8") def decode_ref(self): diff --git a/lib/python/labcomm/StreamReader.py b/lib/python/labcomm2006/StreamReader.py similarity index 95% rename from lib/python/labcomm/StreamReader.py rename to lib/python/labcomm2006/StreamReader.py index 87e9a59..a32b993 100644 --- a/lib/python/labcomm/StreamReader.py +++ b/lib/python/labcomm2006/StreamReader.py @@ -1,5 +1,3 @@ -import labcomm - class StreamReader: def __init__(self, stream): diff --git a/lib/python/labcomm/StreamWriter.py b/lib/python/labcomm2006/StreamWriter.py similarity index 95% rename from lib/python/labcomm/StreamWriter.py rename to lib/python/labcomm2006/StreamWriter.py index 2fffc98..f72c443 100644 --- a/lib/python/labcomm/StreamWriter.py +++ b/lib/python/labcomm2006/StreamWriter.py @@ -1,5 +1,3 @@ -import labcomm - class StreamWriter: def __init__(self, stream): diff --git a/lib/python/labcomm2006/__init__.py b/lib/python/labcomm2006/__init__.py new file mode 100644 index 0000000..2d1075b --- /dev/null +++ b/lib/python/labcomm2006/__init__.py @@ -0,0 +1,27 @@ +__all__ = [ 'LabComm' ] + +import LabComm + +from StreamReader import StreamReader +from StreamWriter import StreamWriter + +Decoder = LabComm.Decoder +Encoder = LabComm.Encoder + +sample = LabComm.sample_def + +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 + +decl_from_signature = LabComm.decl_from_signature + diff --git a/packaging/make_srpm b/packaging/make_srpm index c5abe53..986cfa1 100755 --- a/packaging/make_srpm +++ b/packaging/make_srpm @@ -2,7 +2,7 @@ spec() { cat << 'EOF' -Name: labcomm +Name: labcomm__SUFFIX__ Version: __VERSION__ Release: 1 Summary: LabComm communication protocol @@ -43,26 +43,17 @@ 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} @@ -71,27 +62,25 @@ 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/labcomm2006.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}/labcomm2006 +install lib/python/labcomm2006/* ${RPM_BUILD_ROOT}/%{python_sitelib}/labcomm2006 %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" \ diff --git a/test/relay_gen_cs.py b/test/relay_gen_cs.py index 3568ea9..9e01063 100755 --- a/test/relay_gen_cs.py +++ b/test/relay_gen_cs.py @@ -30,7 +30,7 @@ if __name__ == '__main__': result.extend(split_match('^[^|]*\|(.*)$', """ |using System; |using System.IO; - |using se.lth.control.labcomm; + |using se.lth.control.labcomm2006; | |public class cs_relay : """)) diff --git a/test/test_encoder_decoder.py b/test/test_encoder_decoder.py index 074330d..9e7574d 100755 --- a/test/test_encoder_decoder.py +++ b/test/test_encoder_decoder.py @@ -3,7 +3,7 @@ import argparse import imp -import labcomm +import labcomm2006 import math import os import re @@ -47,19 +47,19 @@ class Test: pass def generate(self, decl): - if decl.__class__ == labcomm.sample: + if decl.__class__ == labcomm2006.sample: result = [] for values in self.generate(decl.decl): result.append((decl, values)) return result - elif decl.__class__ == labcomm.struct: + elif decl.__class__ == labcomm2006.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(labcomm2006.struct(decl.field[1:])) for v1 in values1: for v2 in values2: v = dict(v2) @@ -67,7 +67,7 @@ class Test: result.append(v) return result - elif decl.__class__ == labcomm.array: + elif decl.__class__ == labcomm2006.array: if len(decl.indices) == 1: values = self.generate(decl.decl) if decl.indices[0] == 0: @@ -75,7 +75,7 @@ class Test: else: lengths = [ decl.indices[0] ] else: - values = self.generate(labcomm.array(decl.indices[1:], + values = self.generate(labcomm2006.array(decl.indices[1:], decl.decl)) if decl.indices[0] == 0: lengths = [1, 2] @@ -90,33 +90,33 @@ class Test: result.append(element) return result - elif decl.__class__ == labcomm.BOOLEAN: + elif decl.__class__ == labcomm2006.BOOLEAN: return [False, True] - elif decl.__class__ == labcomm.BYTE: + elif decl.__class__ == labcomm2006.BYTE: return [0, 127, 128, 255] - elif decl.__class__ == labcomm.SHORT: + elif decl.__class__ == labcomm2006.SHORT: return [-32768, 0, 32767] - elif decl.__class__ == labcomm.INTEGER: + elif decl.__class__ == labcomm2006.INTEGER: return [-2147483648, 0, 2147483647] - elif decl.__class__ == labcomm.LONG: + elif decl.__class__ == labcomm2006.LONG: return [-9223372036854775808, 0, 9223372036854775807] - elif decl.__class__ == labcomm.FLOAT: + elif decl.__class__ == labcomm2006.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__ == labcomm2006.DOUBLE: return [-math.pi, 0.0, math.pi] - elif decl.__class__ == labcomm.STRING: + elif decl.__class__ == labcomm2006.STRING: return ['string', u'sträng' ] - elif decl.__class__ == labcomm.SAMPLE: + elif decl.__class__ == labcomm2006.SAMPLE: return self.signatures print>>sys.stderr, decl @@ -133,7 +133,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 = labcomm2006.Encoder(labcomm2006.StreamWriter(p.stdin)) for signature in self.signatures: encoder.add_decl(signature) pass @@ -173,7 +173,7 @@ class Test: pass def decode(self, f): - decoder = labcomm.Decoder(labcomm.StreamReader(f)) + decoder = labcomm2006.Decoder(labcomm2006.StreamReader(f)) try: while True: value,decl = decoder.decode() diff --git a/tools/lc2csv.py b/tools/lc2csv.py index bebcd69..c2a8ebd 100755 --- a/tools/lc2csv.py +++ b/tools/lc2csv.py @@ -1,7 +1,7 @@ #!/usr/bin/env python import argparse -import labcomm +import labcomm2006 import sys import time -- GitLab