aboutsummaryrefslogtreecommitdiff
path: root/nexgb/xgbgen/go_event.go
diff options
context:
space:
mode:
authorAndrew Gallant (Ocelot) <Andrew.Gallant@tufts.edu>2012-04-30 16:18:17 -0400
committerAndrew Gallant (Ocelot) <Andrew.Gallant@tufts.edu>2012-04-30 16:18:17 -0400
commit73154769b3eba60fe48a7c08882e8e64b1545e3f (patch)
tree3fe7c2a1f9ae1d22931b4673901d8ea340192d57 /nexgb/xgbgen/go_event.go
parent2a2d8653b3a7918dfb00dcca8937b0e878279c70 (diff)
downloadhaven-73154769b3eba60fe48a7c08882e8e64b1545e3f.tar.gz
haven-73154769b3eba60fe48a7c08882e8e64b1545e3f.tar.xz
haven-73154769b3eba60fe48a7c08882e8e64b1545e3f.zip
splitting up go specific code. too much for one file IMO. more progress. almost done with structs.
Diffstat (limited to 'nexgb/xgbgen/go_event.go')
-rw-r--r--nexgb/xgbgen/go_event.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/nexgb/xgbgen/go_event.go b/nexgb/xgbgen/go_event.go
new file mode 100644
index 0000000..d91fd7a
--- /dev/null
+++ b/nexgb/xgbgen/go_event.go
@@ -0,0 +1,38 @@
+package main
+
+// Event types
+func (e *Event) Define(c *Context) {
+ c.Putln("// Event definition %s (%d)", e.SrcName(), e.Number)
+}
+
+func (e *Event) Read(c *Context, prefix string) {
+ c.Putln("// Event read %s", e.SrcName())
+}
+
+func (e *Event) Write(c *Context, prefix string) {
+ c.Putln("// Event write %s", e.SrcName())
+}
+
+// EventCopy types
+func (e *EventCopy) Define(c *Context) {
+ c.Putln("// EventCopy definition %s (%d)", e.SrcName(), e.Number)
+ c.Putln("")
+ c.Putln("const %s = %d", e.SrcName(), e.Number)
+ c.Putln("")
+ c.Putln("type %s %s", e.EvType(), e.Old.(*Event).EvType())
+ c.Putln("")
+ c.Putln("func New%s(buf []byte) %s {", e.SrcName(), e.EvType())
+ c.Putln("return (%s)(New%s(buf))", e.EvType(), e.Old.SrcName())
+ c.Putln("}")
+ c.Putln("")
+ c.Putln("func (ev %s) ImplementsEvent() { }", e.EvType())
+ c.Putln("")
+ c.Putln("func (ev %s) Bytes() []byte {", e.EvType())
+ c.Putln("return (%s)(ev).Bytes()", e.Old.(*Event).EvType())
+ c.Putln("}")
+ c.Putln("")
+ c.Putln("func init() {")
+ c.Putln("newEventFuncs[%d] = New%s", e.Number, e.SrcName())
+ c.Putln("}")
+ c.Putln("")
+}