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
Sven Gestegård Robertz
LabComm
Commits
1a5a8580
Commit
1a5a8580
authored
Feb 26, 2015
by
Anders Blomdell
Browse files
Typedefs for python
parent
9b70aa01
Changes
4
Hide whitespace changes
Inline
Side-by-side
compiler/2014/Python_CodeGen.jrag
View file @
1a5a8580
...
...
@@ -84,13 +84,13 @@ aspect Python_CodeGen {
env.println("import StringIO");
env.println();
Python_genTypes(env);
//
env.println("typedef = [");
//
env.indent();
//
for (int i = 0 ; i < getNumDecl() ; i++) {
//
getDecl(i).Python_genTypedefListEntry(env);
//
}
//
env.unindent();
//
env.println("]");
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++) {
...
...
@@ -117,7 +117,6 @@ aspect PythonTypes {
}
public void TypeDecl.Python_genSignature(Python_env env) {
/*
env.println("class " + getName() + "(object):");
env.indent();
env.println("signature = labcomm.typedef('" + getName() + "',");
...
...
@@ -127,7 +126,6 @@ aspect PythonTypes {
env.println(")");
env.unindent();
env.println();
*/
}
public void SampleDecl.Python_genSignature(Python_env env) {
...
...
@@ -143,7 +141,8 @@ aspect PythonTypes {
}
public void UserType.Python_genSignature(Python_env env) {
lookupType(getName()).getType().Python_genSignature(env);
env.println(getName() + ".signature");
// lookupType(getName()).getType().Python_genSignature(env);
}
public void Type.Python_genSignature(Python_env env) {
...
...
@@ -204,7 +203,7 @@ aspect PythonTypes {
}
public void TypeDecl.Python_genTypedefListEntry(Python_env env) {
env.println(
"('" +
getName() + "
', " + getName() + ".signature)
,");
env.println(getName() + ",");
}
public void Decl.Python_genSampleListEntry(Python_env env) {
...
...
lib/python/labcomm/LabComm.py
View file @
1a5a8580
...
...
@@ -389,7 +389,7 @@ class SAMPLE(primitive):
#
# Aggregate types
#
class
sample
_
def_or_
r
ef
(
type_decl
):
class
sampledef_or_
sampleref_or_typed
ef
(
type_decl
):
def
__init__
(
self
,
name
=
None
,
decl
=
None
):
self
.
name
=
name
self
.
decl
=
decl
...
...
@@ -402,8 +402,8 @@ class sample_def_or_ref(type_decl):
with
length_encoder
(
e1
)
as
e2
:
self
.
decl
.
encode_decl
(
e2
)
def
encode
(
self
,
encoder
,
object
):
self
.
decl
.
encode
(
encoder
,
object
)
def
encode
(
self
,
encoder
,
value
):
self
.
decl
.
encode
(
encoder
,
value
)
def
decode_decl
(
self
,
decoder
):
index
=
decoder
.
decode_type_number
()
...
...
@@ -438,7 +438,7 @@ class sample_def_or_ref(type_decl):
def
__repr__
(
self
):
return
"%s('%s', %s)"
%
(
self
.
type_name
,
self
.
name
,
self
.
decl
)
class
sample_def
(
sample
_
def_or_
r
ef
):
class
sample_def
(
sampledef_or_
sampleref_or_typed
ef
):
type_index
=
i_SAMPLE_DEF
type_name
=
'sample'
...
...
@@ -448,7 +448,7 @@ class sample_def(sample_def_or_ref):
def
add_index
(
self
,
decoder
,
index
,
decl
):
decoder
.
add_decl
(
decl
,
index
)
class
sample_ref
(
sample
_
def_or_
r
ef
):
class
sample_ref
(
sampledef_or_
sampleref_or_typed
ef
):
type_index
=
i_SAMPLE_REF
type_name
=
'sample_ref'
...
...
@@ -466,6 +466,16 @@ class sample_ref(sample_def_or_ref):
def
add_index
(
self
,
decoder
,
index
,
decl
):
decoder
.
add_ref
(
decl
,
index
)
class
typedef
(
sampledef_or_sampleref_or_typedef
):
type_index
=
i_TYPE_DEF
type_name
=
'typedef'
def
encode_decl
(
self
,
encoder
):
self
.
decl
.
encode_decl
(
encoder
)
def
encode
(
self
,
encoder
,
value
):
self
.
decl
.
encode
(
encoder
,
value
)
class
array
(
type_decl
):
def
__init__
(
self
,
indices
,
decl
):
self
.
indices
=
tuple
(
indices
)
...
...
lib/python/labcomm/__init__.py
View file @
1a5a8580
...
...
@@ -9,6 +9,7 @@ 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
...
...
test/test_encoder_decoder.py
View file @
1a5a8580
...
...
@@ -53,6 +53,12 @@ class Test:
result
.
append
((
decl
,
values
))
return
result
elif
decl
.
__class__
==
labcomm
.
typedef
:
result
=
[]
for
values
in
self
.
generate
(
decl
.
decl
):
result
.
append
(
values
)
return
result
elif
decl
.
__class__
==
labcomm
.
struct
:
result
=
[]
if
len
(
decl
.
field
)
==
0
:
...
...
@@ -164,7 +170,6 @@ class Test:
print
>>
sys
.
stderr
,
"Checking"
,
signature
.
name
,
for
decl
,
value
in
self
.
generate
(
signature
):
sys
.
stderr
.
write
(
'.'
)
#print name,decl,value,value.__class__
self
.
next
.
acquire
()
self
.
received_value
=
None
self
.
received_decl
=
None
...
...
@@ -176,7 +181,7 @@ class Test:
self
.
failed
=
True
elif
value
!=
self
.
received_value
:
print
>>
sys
.
stderr
,
"Coding error"
print
>>
sys
.
stderr
,
value
==
self
.
received_value
print
>>
sys
.
stderr
,
value
==
self
.
received_value
print
>>
sys
.
stderr
,
"Got: "
,
self
.
received_value
print
>>
sys
.
stderr
,
" "
,
self
.
received_decl
print
>>
sys
.
stderr
,
"Expected:"
,
value
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment