Commit ce030bd4 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 0ba3696b
...@@ -362,13 +362,9 @@ import ( ...@@ -362,13 +362,9 @@ import (
specAnnotation.parse(typespec.Doc) specAnnotation.parse(typespec.Doc)
// remember enum types // remember enum types
// FIXME separate dedicated first pass to extract enums first
if specAnnotation.enum { if specAnnotation.enum {
//typ := typeInfo.Types[typespec.Type].Type
typ := typeInfo.Defs[typespec.Name].Type() typ := typeInfo.Defs[typespec.Name].Type()
// XXX verify typ is basic int XXX or byte?
enumRegistry[typ]= enumSerial enumRegistry[typ]= enumSerial
//fmt.Printf("// enum %s #%d\n", typeName(typ), enumSerial)
enumSerial++ enumSerial++
} }
...@@ -400,7 +396,7 @@ import ( ...@@ -400,7 +396,7 @@ import (
buf.WriteString(generateCodecCode(typespec, &encoderN{})) buf.WriteString(generateCodecCode(typespec, &encoderN{}))
buf.WriteString(generateCodecCode(typespec, &decoderN{})) buf.WriteString(generateCodecCode(typespec, &decoderN{}))
// XXX keep all M routines separate from N for code locality // TODO keep all M routines separate from N for code locality ?
buf.WriteString(generateCodecCode(typespec, &sizerM{})) buf.WriteString(generateCodecCode(typespec, &sizerM{}))
buf.WriteString(generateCodecCode(typespec, &encoderM{})) buf.WriteString(generateCodecCode(typespec, &encoderM{}))
buf.WriteString(generateCodecCode(typespec, &decoderM{})) buf.WriteString(generateCodecCode(typespec, &decoderM{}))
...@@ -429,12 +425,9 @@ import ( ...@@ -429,12 +425,9 @@ import (
// format & output generated code // format & output generated code
code, err := format.Source(buf.Bytes()) code, err := format.Source(buf.Bytes())
//code = buf.Bytes()
if true {
if err != nil { if err != nil {
panic(err) // should not happen panic(err) // should not happen
} }
}
_, err = os.Stdout.Write(code) _, err = os.Stdout.Write(code)
if err != nil { if err != nil {
...@@ -560,12 +553,10 @@ type CodeGenerator interface { ...@@ -560,12 +553,10 @@ type CodeGenerator interface {
// mem.Buf // mem.Buf
genBuf(path string) genBuf(path string)
/* // // generate code for a custom type which implements its own
// generate code for a custom type which implements its own // // encoding/decoding via implementing neo.customCodecN interface.
// encoding/decoding via implementing neo.customCodecN interface. // // XXX move out of common interface?
// XXX move out of common interface? // genCustomN(path string)
genCustomN(path string)
*/
// get generated code. // get generated code.
generatedCode() string generatedCode() string
...@@ -940,7 +931,6 @@ func (d *decoderCommon) generatedCode() string { ...@@ -940,7 +931,6 @@ func (d *decoderCommon) generatedCode() string {
code.Write(d.bufDone.Bytes()) code.Write(d.bufDone.Bytes())
// epilogue // epilogue
// XXX M: return `n + (len0 - len(data))` without nread updates after every decode
retexpr := fmt.Sprintf("%v", d.nread) retexpr := fmt.Sprintf("%v", d.nread)
if d.varUsed["nread"] { if d.varUsed["nread"] {
// casting nread to int is ok even on 32 bit arches: // casting nread to int is ok even on 32 bit arches:
...@@ -1003,7 +993,7 @@ func (d *decoderN) genBasic(assignto string, typ *types.Basic, userType types.Ty ...@@ -1003,7 +993,7 @@ func (d *decoderN) genBasic(assignto string, typ *types.Basic, userType types.Ty
d.overflow.Add(basic.wireSize) d.overflow.Add(basic.wireSize)
} }
// M: XXX // M: emit code to size/encode/decode basic fixed type
func (s *sizerM) genBasic(path string, typ *types.Basic, userType types.Type) { func (s *sizerM) genBasic(path string, typ *types.Basic, userType types.Type) {
// upath casts path into basic type if needed // upath casts path into basic type if needed
// e.g. p.x -> int32(p.x) if p.x is custom type with underlying int32 // e.g. p.x -> int32(p.x) if p.x is custom type with underlying int32
...@@ -1039,10 +1029,10 @@ func (s *sizerM) genBasic(path string, typ *types.Basic, userType types.Type) { ...@@ -1039,10 +1029,10 @@ func (s *sizerM) genBasic(path string, typ *types.Basic, userType types.Type) {
case types.Float64: s.size.Add(1+8) // mfloat64 + <value64> case types.Float64: s.size.Add(1+8) // mfloat64 + <value64>
} }
} }
func (e *encoderM) genBasic(path string, typ *types.Basic, userType types.Type) { func (e *encoderM) genBasic(path string, typ *types.Basic, userType types.Type) {
// upath casts path into basic type if needed // upath casts path into basic type if needed
// e.g. p.x -> int32(p.x) if p.x is custom type with underlying int32 // e.g. p.x -> int32(p.x) if p.x is custom type with underlying int32
// XXX dup?
upath := path upath := path
if userType.Underlying() != userType { if userType.Underlying() != userType {
upath = fmt.Sprintf("%s(%s)", typ.Name(), upath) upath = fmt.Sprintf("%s(%s)", typ.Name(), upath)
......
Markdown is supported
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