Commit 1a5a8580 authored by Anders Blomdell's avatar Anders Blomdell
Browse files

Typedefs for python

parent 9b70aa01
...@@ -84,13 +84,13 @@ aspect Python_CodeGen { ...@@ -84,13 +84,13 @@ aspect Python_CodeGen {
env.println("import StringIO"); env.println("import StringIO");
env.println(); env.println();
Python_genTypes(env); Python_genTypes(env);
//env.println("typedef = ["); env.println("typedef = tuple([");
//env.indent(); env.indent();
//for (int i = 0 ; i < getNumDecl() ; i++) { for (int i = 0 ; i < getNumDecl() ; i++) {
// getDecl(i).Python_genTypedefListEntry(env); getDecl(i).Python_genTypedefListEntry(env);
//} }
//env.unindent(); env.unindent();
//env.println("]"); env.println("])");
env.println("sample = tuple(["); env.println("sample = tuple([");
env.indent(); env.indent();
for (int i = 0 ; i < getNumDecl() ; i++) { for (int i = 0 ; i < getNumDecl() ; i++) {
...@@ -117,7 +117,6 @@ aspect PythonTypes { ...@@ -117,7 +117,6 @@ aspect PythonTypes {
} }
public void TypeDecl.Python_genSignature(Python_env env) { public void TypeDecl.Python_genSignature(Python_env env) {
/*
env.println("class " + getName() + "(object):"); env.println("class " + getName() + "(object):");
env.indent(); env.indent();
env.println("signature = labcomm.typedef('" + getName() + "',"); env.println("signature = labcomm.typedef('" + getName() + "',");
...@@ -127,7 +126,6 @@ aspect PythonTypes { ...@@ -127,7 +126,6 @@ aspect PythonTypes {
env.println(")"); env.println(")");
env.unindent(); env.unindent();
env.println(); env.println();
*/
} }
public void SampleDecl.Python_genSignature(Python_env env) { public void SampleDecl.Python_genSignature(Python_env env) {
...@@ -143,7 +141,8 @@ aspect PythonTypes { ...@@ -143,7 +141,8 @@ aspect PythonTypes {
} }
public void UserType.Python_genSignature(Python_env env) { 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) { public void Type.Python_genSignature(Python_env env) {
...@@ -204,7 +203,7 @@ aspect PythonTypes { ...@@ -204,7 +203,7 @@ aspect PythonTypes {
} }
public void TypeDecl.Python_genTypedefListEntry(Python_env env) { public void TypeDecl.Python_genTypedefListEntry(Python_env env) {
env.println("('" + getName() + "', " + getName() + ".signature),"); env.println(getName() + ",");
} }
public void Decl.Python_genSampleListEntry(Python_env env) { public void Decl.Python_genSampleListEntry(Python_env env) {
......
...@@ -389,7 +389,7 @@ class SAMPLE(primitive): ...@@ -389,7 +389,7 @@ class SAMPLE(primitive):
# #
# Aggregate types # Aggregate types
# #
class sample_def_or_ref(type_decl): class sampledef_or_sampleref_or_typedef(type_decl):
def __init__(self, name=None, decl=None): def __init__(self, name=None, decl=None):
self.name = name self.name = name
self.decl = decl self.decl = decl
...@@ -402,8 +402,8 @@ class sample_def_or_ref(type_decl): ...@@ -402,8 +402,8 @@ class sample_def_or_ref(type_decl):
with length_encoder(e1) as e2: with length_encoder(e1) as e2:
self.decl.encode_decl(e2) self.decl.encode_decl(e2)
def encode(self, encoder, object): def encode(self, encoder, value):
self.decl.encode(encoder, object) self.decl.encode(encoder, value)
def decode_decl(self, decoder): def decode_decl(self, decoder):
index = decoder.decode_type_number() index = decoder.decode_type_number()
...@@ -438,7 +438,7 @@ class sample_def_or_ref(type_decl): ...@@ -438,7 +438,7 @@ class sample_def_or_ref(type_decl):
def __repr__(self): def __repr__(self):
return "%s('%s', %s)" % (self.type_name, self.name, self.decl) return "%s('%s', %s)" % (self.type_name, self.name, self.decl)
class sample_def(sample_def_or_ref): class sample_def(sampledef_or_sampleref_or_typedef):
type_index = i_SAMPLE_DEF type_index = i_SAMPLE_DEF
type_name = 'sample' type_name = 'sample'
...@@ -448,7 +448,7 @@ class sample_def(sample_def_or_ref): ...@@ -448,7 +448,7 @@ class sample_def(sample_def_or_ref):
def add_index(self, decoder, index, decl): def add_index(self, decoder, index, decl):
decoder.add_decl(decl, index) decoder.add_decl(decl, index)
class sample_ref(sample_def_or_ref): class sample_ref(sampledef_or_sampleref_or_typedef):
type_index = i_SAMPLE_REF type_index = i_SAMPLE_REF
type_name = 'sample_ref' type_name = 'sample_ref'
...@@ -466,6 +466,16 @@ class sample_ref(sample_def_or_ref): ...@@ -466,6 +466,16 @@ class sample_ref(sample_def_or_ref):
def add_index(self, decoder, index, decl): def add_index(self, decoder, index, decl):
decoder.add_ref(decl, index) 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): class array(type_decl):
def __init__(self, indices, decl): def __init__(self, indices, decl):
self.indices = tuple(indices) self.indices = tuple(indices)
......
...@@ -9,6 +9,7 @@ Encoder = labcomm.LabComm.Encoder ...@@ -9,6 +9,7 @@ Encoder = labcomm.LabComm.Encoder
sample = labcomm.LabComm.sample_def sample = labcomm.LabComm.sample_def
sample_def = labcomm.LabComm.sample_def sample_def = labcomm.LabComm.sample_def
sample_ref = labcomm.LabComm.sample_ref sample_ref = labcomm.LabComm.sample_ref
typedef = labcomm.LabComm.typedef
array = labcomm.LabComm.array array = labcomm.LabComm.array
struct = labcomm.LabComm.struct struct = labcomm.LabComm.struct
......
...@@ -53,6 +53,12 @@ class Test: ...@@ -53,6 +53,12 @@ class Test:
result.append((decl, values)) result.append((decl, values))
return result 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: elif decl.__class__ == labcomm.struct:
result = [] result = []
if len(decl.field) == 0: if len(decl.field) == 0:
...@@ -164,7 +170,6 @@ class Test: ...@@ -164,7 +170,6 @@ class Test:
print>>sys.stderr, "Checking", signature.name, print>>sys.stderr, "Checking", signature.name,
for decl,value in self.generate(signature): for decl,value in self.generate(signature):
sys.stderr.write('.') sys.stderr.write('.')
#print name,decl,value,value.__class__
self.next.acquire() self.next.acquire()
self.received_value = None self.received_value = None
self.received_decl = None self.received_decl = None
...@@ -176,7 +181,7 @@ class Test: ...@@ -176,7 +181,7 @@ class Test:
self.failed = True self.failed = True
elif value != self.received_value: elif value != self.received_value:
print>>sys.stderr, "Coding error" 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, "Got: ", self.received_value
print>>sys.stderr, " ", self.received_decl print>>sys.stderr, " ", self.received_decl
print>>sys.stderr, "Expected:", value print>>sys.stderr, "Expected:", value
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment