Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Anders Blomdell
LabComm
Commits
eccd4e90
Commit
eccd4e90
authored
May 13, 2015
by
Sven Gestegård Robertz
Browse files
Passes tests for files without intentions
parent
be3a4abc
Changes
5
Hide whitespace changes
Inline
Side-by-side
examples/user_types/Decoder.java
View file @
eccd4e90
...
...
@@ -34,12 +34,12 @@ public class Decoder
theSecondInt
.
register
(
decoder
,
this
);
intAndRef
.
register
(
decoder
,
this
);
doavoid
.
registerSampleRef
(
decoder
);
this
.
tdp
=
TypeDefParser
.
registerTypeDefParser
(
decoder
);
//
this.tdp = TypeDefParser.registerTypeDefParser(decoder);
// TypeDef.register(decoder, this);
// TypeBinding.register(decoder, this);
tdp
.
addListener
(
this
);
//
tdp.addListener(this);
try
{
System
.
out
.
println
(
"Running decoder."
);
...
...
examples/user_types/test.lc
View file @
eccd4e90
typedef struct {
(foo:bar)
int val;
int val;
} coord;
typedef int anInt;
typedef void avoid;
sample
(function:trigger)(foo:bar)
avoid doavoid;
sample avoid doavoid;
sample
(a:b) "a struct with an int and a ref"
struct {
(c:d)(e:f)
int x;
sample struct {
int x;
sample reference;
} intAndRef;
...
...
lib/java/se/lth/control/labcomm2014/DecoderChannel.java
View file @
eccd4e90
...
...
@@ -23,7 +23,7 @@ public class DecoderChannel implements Decoder {
byte
[]
signature
=
new
byte
[
signature_length
];
ReadBytes
(
signature
,
signature_length
);
def_registry
.
add
(
index
,
name
,
signature
);
}
}
private
void
processSampleRef
()
throws
IOException
{
int
index
=
decodePacked32
();
...
...
@@ -32,17 +32,17 @@ public class DecoderChannel implements Decoder {
byte
[]
signature
=
new
byte
[
signature_length
];
ReadBytes
(
signature
,
signature_length
);
ref_registry
.
add
(
index
,
name
,
signature
);
}
}
private
void
processTypeDef
(
int
len
)
throws
IOException
{
try
{
processSample
(
Constant
.
TYPE_DEF
);
}
catch
(
Exception
ex
)
{
int
idx
=
decodePacked32
();
String
name
=
decodeString
();
String
name
=
decodeString
();
int
siglen
=
decodePacked32
();
for
(
int
i
=
0
;
i
<
siglen
;
i
++)
{
byte
b
=
decodeByte
();
byte
b
=
decodeByte
();
}
}
}
...
...
@@ -52,14 +52,14 @@ public class DecoderChannel implements Decoder {
processSample
(
Constant
.
TYPE_BINDING
);
}
catch
(
Exception
ex
)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
decodeByte
();
decodeByte
();
}
}
}
}
private
void
processPragma
(
int
len
)
throws
IOException
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
decodeByte
();
decodeByte
();
}
}
...
...
@@ -84,7 +84,7 @@ public class DecoderChannel implements Decoder {
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
}
}
}
public
void
runOne
()
throws
Exception
{
boolean
done
=
false
;
...
...
@@ -129,7 +129,7 @@ public class DecoderChannel implements Decoder {
}
}
public
void
register
(
SampleDispatcher
dispatcher
,
public
void
register
(
SampleDispatcher
dispatcher
,
SampleHandler
handler
)
throws
IOException
{
def_registry
.
add
(
dispatcher
,
handler
);
}
...
...
@@ -158,7 +158,7 @@ public class DecoderChannel implements Decoder {
public
byte
decodeByte
()
throws
IOException
{
return
in
.
readByte
();
}
public
short
decodeShort
()
throws
IOException
{
return
in
.
readShort
();
}
...
...
@@ -215,17 +215,17 @@ public class DecoderChannel implements Decoder {
}
}
/* Package visible methods for use from TypeDefParser */
String
getSampleName
(
int
idx
)
{
DecoderRegistry
.
Entry
e
=
def_registry
.
get
(
idx
);
return
e
.
getName
();
DecoderRegistry
.
Entry
e
=
def_registry
.
get
(
idx
);
return
e
.
getName
();
}
byte
[]
getSampleSignature
(
int
idx
)
{
DecoderRegistry
.
Entry
e
=
def_registry
.
get
(
idx
);
return
e
.
getSignature
();
DecoderRegistry
.
Entry
e
=
def_registry
.
get
(
idx
);
return
e
.
getSignature
();
}
}
lib/java/se/lth/control/labcomm2014/TypeDefParser.java
View file @
eccd4e90
...
...
@@ -22,7 +22,7 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler {
private
int
sampleIndex
;
private
Decoder
decoder
;
private
byte
[]
dummy
=
new
byte
[
0
];
public
String
toString
()
{
return
"self"
;}
public
String
toString
()
{
return
"self"
;}
public
String
getName
()
{
if
(
decoder
instanceof
DecoderChannel
)
{
DecoderChannel
dc
=
(
DecoderChannel
)
decoder
;
...
...
@@ -30,7 +30,7 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler {
}
else
{
return
"self"
;
}
}
}
public
int
getIndex
()
{
return
0
;}
public
byte
[]
getSignature
()
{
if
(
decoder
instanceof
DecoderChannel
)
{
...
...
@@ -142,7 +142,7 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler {
result
.
add
(
sd
.
getType
());
result
.
add
(
new
NameSymbol
(
sd
.
getName
()));
Iterator
<
ParsedTypeDef
>
di
=
sd
.
getDepIterator
();
Iterator
<
ParsedTypeDef
>
di
=
sd
.
getDepIterator
();
while
(
di
.
hasNext
())
{
ParsedTypeDef
d
=
di
.
next
();
result
.
add
(
new
TypeSymbol
());
...
...
@@ -164,7 +164,7 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler {
return
sb
.
toString
();
}
/* An interface for using Visitor pattern to traverse
/* An interface for using Visitor pattern to traverse
* ParsedTypeDefs
*/
public
interface
ParsedSymbolVisitor
{
...
...
@@ -209,7 +209,7 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler {
this
.
name
=
name
;
}
public
String
toString
()
{
public
String
toString
()
{
return
name
;
}
public
void
accept
(
ParsedSymbolVisitor
v
){
...
...
@@ -226,7 +226,7 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler {
// v.visit(this);
// }
//
// public String toString() {
// public String toString() {
// return "sample";}
// }
...
...
@@ -272,7 +272,7 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler {
this
.
name
=
"sample"
;
break
;
default
:
this
.
name
=
"??? unknown tag 0x"
+
Integer
.
toHexString
(
tag
);
this
.
name
=
"??? unknown tag 0x"
+
Integer
.
toHexString
(
tag
);
}
}
...
...
@@ -280,7 +280,7 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler {
v
.
visit
(
this
);
}
public
String
toString
()
{
public
String
toString
()
{
return
name
;}
}
...
...
@@ -311,7 +311,7 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler {
sb
.
append
(
"struct {\n"
);
for
(
ParsedField
f
:
fields
)
{
sb
.
append
(
f
.
toString
());
sb
.
append
(
";\n"
);
sb
.
append
(
";\n"
);
}
sb
.
append
(
"}"
);
return
sb
.
toString
();
...
...
@@ -457,7 +457,7 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler {
type
.
accept
(
v
);
}
}
public
class
ParsedSampleDef
extends
ParsedTypeDef
{
private
HashSet
<
ParsedTypeDef
>
deps
;
...
...
@@ -480,7 +480,7 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler {
Iterator
<
ParsedTypeDef
>
getDepIterator
()
{
return
deps
.
iterator
();
}
}
}
private
class
ParserState
{
...
...
@@ -504,12 +504,12 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler {
this
();
pushType
(
typeIdx
);
}
ParserState
(
TypeDef
td
)
{
this
();
pushType
(
td
);
}
ParserState
(
byte
sig
[])
{
this
();
bis
=
new
ByteArrayInputStream
(
sig
);
...
...
@@ -524,7 +524,7 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler {
void
pushType
(
int
typeIdx
)
{
if
(
typeIdx
>=
0x40
&&
!
typeStack
.
contains
(
typeIdx
))
{
typeStack
.
push
(
typeDefs
.
get
(
typeIdx
));
}
}
}
void
popType
()
{
...
...
@@ -569,6 +569,12 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler {
return
(
int
)
(
res
&
0xffffffff
);
}
void
skipBytes
(
int
len
)
throws
IOException
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
in
.
readByte
();
}
}
}
public
ParsedSampleDef
parseSignature
(
TypeDef
td
)
throws
IOException
{
...
...
@@ -586,19 +592,19 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler {
System
.
out
.
println
(
"EOF: self_binding"
);
}
return
result
;
}
}
private
ArrayType
parseArray
(
ParserState
in
)
throws
IOException
{
int
numIdx
=
in
.
decodePacked32
();
int
idx
[]
=
new
int
[
numIdx
];
for
(
int
i
=
0
;
i
<
numIdx
;
i
++){
idx
[
i
]
=
in
.
decodePacked32
();
idx
[
i
]
=
in
.
decodePacked32
();
}
int
type
=
in
.
decodePacked32
();
ParsedType
elementType
=
lookupType
(
type
,
in
);
ParsedType
elementType
=
lookupType
(
type
,
in
);
ArrayType
result
=
new
ArrayType
(
idx
,
elementType
);
for
(
int
i
=
0
;
i
<
numIdx
;
i
++){
idx
[
i
]
=
in
.
decodePacked32
();
idx
[
i
]
=
in
.
decodePacked32
();
}
return
result
;
}
...
...
@@ -625,7 +631,7 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler {
in
.
pushType
(
tag
);
// sampleRefs are sent as primitive types, see above
// } else if(tag == Constant.SAMPLE) {
// result = new SampleRefType();
// result = new SampleRefType();
}
else
{
result
=
new
PrimitiveType
(
tag
);
}
...
...
@@ -642,6 +648,13 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler {
return
result
;
}
private
ParsedType
parseType
(
ParserState
in
)
throws
IOException
{
String
intentions
=
in
.
decodeString
();
if
(
intentions
.
length
()>
0
)
{
System
.
out
.
println
(
"parseType intentions ("
+
intentions
);
}
else
{
System
.
out
.
println
(
"no intentions"
);
}
int
tag
=
in
.
decodePacked32
();
ParsedType
result
=
null
;
switch
(
tag
)
{
...
...
@@ -657,7 +670,7 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler {
default
:
result
=
lookupType
(
tag
,
in
);
break
;
}
}
return
result
;
}
}
lib/python/labcomm2014/LabComm.py
View file @
eccd4e90
...
...
@@ -88,7 +88,7 @@
# | user data
# | ...
# +----+--
#
#
#
# LabComm2006 packets has the following layout
#
...
...
@@ -122,7 +122,7 @@
# | user data
# | ...
# +----+--
#
#
#?? | field1 name
#?? | (length + UTF8)...
...
...
@@ -160,12 +160,12 @@
#?? | fieldN data |
#?? | ... |
#?? +----+----+----+----+
#
#
# type numbers and lengths do not have a fixed lenght, but are packed into
# sequences of 7 bit chunks, represented in bytes with the high bit meaning
#
#
# type numbers and lengths do not have a fixed lenght, but are packed into
# sequences of 7 bit chunks, represented in bytes with the high bit meaning
# that more data is to come.
import
types
import
struct
as
packer
...
...
@@ -175,8 +175,8 @@ DEFAULT_VERSION = "LabComm2014"
i_VERSION
=
0x01
i_SAMPLE_DEF
=
0x02
i_SAMPLE_REF
=
0x03
i_TYPE_DEF
=
0x04
i_TYPE_BINDING
=
0x05
i_TYPE_DEF
=
0x04
i_TYPE_BINDING
=
0x05
i_PRAGMA
=
0x3f
i_USER
=
0x40
# ..0xffffffff
...
...
@@ -184,7 +184,7 @@ i_USER = 0x40 # ..0xffffffff
i_ARRAY
=
0x10
i_STRUCT
=
0x11
i_BOOLEAN
=
0x20
i_BOOLEAN
=
0x20
i_BYTE
=
0x21
i_SHORT
=
0x22
i_INTEGER
=
0x23
...
...
@@ -237,7 +237,7 @@ class primitive(type_decl):
def
__ne__
(
self
,
other
):
return
not
self
.
__eq__
(
other
)
def
__hash__
(
self
):
return
hash
(
self
.
__class__
)
...
...
@@ -247,7 +247,7 @@ class BOOLEAN(primitive):
def
encode
(
self
,
encoder
,
value
):
return
encoder
.
encode_boolean
(
value
)
def
decode
(
self
,
decoder
,
obj
=
None
):
return
decoder
.
decode_boolean
()
...
...
@@ -263,10 +263,10 @@ class BYTE(primitive):
def
encode
(
self
,
encoder
,
value
):
return
encoder
.
encode_byte
(
value
)
def
decode
(
self
,
decoder
,
obj
=
None
):
return
decoder
.
decode_byte
()
def
new_instance
(
self
):
return
0
...
...
@@ -279,10 +279,10 @@ class SHORT(primitive):
def
encode
(
self
,
encoder
,
value
):
return
encoder
.
encode_short
(
value
)
def
decode
(
self
,
decoder
,
obj
=
None
):
return
decoder
.
decode_short
()
def
new_instance
(
self
):
return
0
...
...
@@ -295,10 +295,10 @@ class INTEGER(primitive):
def
encode
(
self
,
encoder
,
value
):
return
encoder
.
encode_int
(
value
)
def
decode
(
self
,
decoder
,
obj
=
None
):
return
decoder
.
decode_int
()
def
new_instance
(
self
):
return
0
...
...
@@ -311,10 +311,10 @@ class LONG(primitive):
def
encode
(
self
,
encoder
,
value
):
return
encoder
.
encode_long
(
value
)
def
decode
(
self
,
decoder
,
obj
=
None
):
return
decoder
.
decode_long
()
def
new_instance
(
self
):
return
long
(
0
)
...
...
@@ -327,10 +327,10 @@ class FLOAT(primitive):
def
encode
(
self
,
encoder
,
value
):
return
encoder
.
encode_float
(
value
)
def
decode
(
self
,
decoder
,
obj
=
None
):
return
decoder
.
decode_float
()
def
new_instance
(
self
):
return
0.0
...
...
@@ -343,10 +343,10 @@ class DOUBLE(primitive):
def
encode
(
self
,
encoder
,
value
):
return
encoder
.
encode_double
(
value
)
def
decode
(
self
,
decoder
,
obj
=
None
):
return
decoder
.
decode_double
()
def
new_instance
(
self
):
return
0.0
...
...
@@ -359,10 +359,10 @@ class STRING(primitive):
def
encode
(
self
,
encoder
,
value
):
return
encoder
.
encode_string
(
value
)
def
decode
(
self
,
decoder
,
obj
=
None
):
return
decoder
.
decode_string
()
def
new_instance
(
self
):
return
""
...
...
@@ -379,7 +379,7 @@ class SAMPLE(primitive):
# Probably trying to encode a sample class, grab signature
value
=
value
.
signature
return
encoder
.
encode_int
(
encoder
.
ref_to_index
.
get
(
value
,
0
))
def
decode
(
self
,
decoder
,
obj
=
None
):
return
decoder
.
decode_ref
()
...
...
@@ -403,6 +403,7 @@ class sampledef_or_sampleref_or_typedef(type_decl):
e1
.
encode_type
(
self
.
get_index
(
encoder
))
e1
.
encode_string
(
self
.
name
)
with
length_encoder
(
e1
)
as
e2
:
self
.
encode_empty_intentions
(
e2
)
self
.
decl
.
encode_decl
(
e2
)
def
encode
(
self
,
encoder
,
value
):
...
...
@@ -413,6 +414,7 @@ class sampledef_or_sampleref_or_typedef(type_decl):
name
=
decoder
.
decode_string
()
if
usePacketLength
(
decoder
.
version
):
length
=
decoder
.
decode_packed32
()
self
.
decode_intentions
(
decoder
)
decl
=
decoder
.
decode_decl
()
result
=
self
.
__class__
.
__new__
(
self
.
__class__
)
result
.
__init__
(
name
=
name
,
decl
=
decl
)
...
...
@@ -428,16 +430,16 @@ class sampledef_or_sampleref_or_typedef(type_decl):
return
self
.
decl
.
new_instance
()
def
__eq__
(
self
,
other
):
return
(
self
.
__class__
==
other
.
__class__
and
return
(
self
.
__class__
==
other
.
__class__
and
self
.
name
==
other
.
name
and
self
.
decl
==
other
.
decl
)
def
__ne__
(
self
,
other
):
return
not
self
.
__eq__
(
other
)
def
__hash__
(
self
):
return
hash
(
self
.
__class__
)
^
hash
(
self
.
name
)
^
hash
(
self
.
decl
)
def
__repr__
(
self
):
return
"%s('%s', %s)"
%
(
self
.
type_name
,
self
.
name
,
self
.
decl
)
...
...
@@ -453,12 +455,17 @@ class sample_def(sampledef_or_sampleref_or_typedef):
def
rename
(
self
,
name
):
return
sample_def
(
name
=
name
,
decl
=
self
.
decl
)
def
decode_intentions
(
self
,
d
):
return
d
.
decode_string
()
def
encode_empty_intentions
(
self
,
e
):
e
.
encode_empty_intentions
()
class
sample_ref
(
sampledef_or_sampleref_or_typedef
):
type_index
=
i_SAMPLE_REF
type_name
=
'sample_ref'
def
__init__
(
self
,
name
=
None
,
decl
=
None
,
sample
=
None
):
self
.
name
=
name
self
.
decl
=
decl
...
...
@@ -467,6 +474,12 @@ class sample_ref(sampledef_or_sampleref_or_typedef):
else
:
self
.
sample
=
sample
def
decode_intentions
(
self
,
d
):
return
d
.
decode_string
()
def
encode_empty_intentions
(
self
,
e
):
e
.
encode_empty_intentions
()
def
get_index
(
self
,
encoder
):
return
encoder
.
ref_to_index
[
self
.
sample
]
...
...
@@ -477,6 +490,12 @@ class typedef(sampledef_or_sampleref_or_typedef):
type_index
=
i_TYPE_DEF
type_name
=
'typedef'
def
decode_intentions
(
self
,
d
):
pass
def
encode_empty_intentions
(
self
,
e
):
pass
def
encode_decl
(
self
,
encoder
):
self
.
decl
.
encode_decl
(
encoder
)
...
...
@@ -487,18 +506,18 @@ class array(type_decl):
def
__init__
(
self
,
indices
,
decl
):
self
.
indices
=
tuple
(
indices
)
self
.
decl
=
decl
def
__eq__
(
self
,
other
):
return
(
self
.
__class__
==
other
.
__class__
and
return
(
self
.
__class__
==
other
.
__class__
and
self
.
indices
==
other
.
indices
and
self
.
decl
==
other
.
decl
)
def
__ne__
(
self
,
other
):
return
not
self
.
__eq__
(
other
)
def
__hash__
(
self
):
return
hash
(
self
.
__class__
)
^
hash
(
self
.
indices
)
^
hash
(
self
.
decl
)
def
encode_decl
(
self
,
encoder
):
encoder
.
encode_type
(
i_ARRAY
)
encoder
.
encode_packed32
(
len
(
self
.
indices
))
...
...
@@ -526,7 +545,7 @@ class array(type_decl):
pass
except
TypeError
:
pass
return
shape
return
shape
def
shape
(
self
,
l
):
shape
=
self
.
min_max_shape
(
l
,
0
,
[])
...
...
@@ -537,7 +556,7 @@ class array(type_decl):
result
.
append
(
low
)
return
result
def
encode_indices
(
self
,
encoder
,
value
):
depth
=
len
(
self
.
indices
)
shape
=
self
.
shape
(
value
)
...
...
@@ -558,7 +577,7 @@ class array(type_decl):
self
.
encode_value
(
encoder
,
e
,
depth
-
1
)
else
:
self
.
decl
.
encode
(
encoder
,
value
)
def
encode
(
self
,
encoder
,
value
):
depth
=
self
.
encode_indices
(
encoder
,
value
)
self
.
encode_value
(
encoder
,
value
,
depth
)
...
...
@@ -597,7 +616,7 @@ class array(type_decl):
for
i
in
range
(
indices
[
0
]):
result
.
append
(
self
.
new_instance_value
(
indices
[
1
:]))
return
result
def
new_instance
(
self
):
indices
=
[]
for
i
in
self
.
indices
:
...
...
@@ -605,19 +624,19 @@ class array(type_decl):
i
=
decoder
.
decode_packed32
()
indices
.
append
(
i
)
return
self
.
new_instance_value
(
indices
)
def
__repr__
(
self
):
return
"labcomm.array(%s,
\n
%s)"
%
(
self
.
indices
,
indent
(
4
,
self
.
decl
.
__repr__
()))