From 281b1bdd8a472d5162b2d469563b4abbcc6dcf14 Mon Sep 17 00:00:00 2001 From: Emil Valeev Date: Sun, 13 Aug 2023 16:38:38 +0300 Subject: [PATCH] fix(llrgen): simplify example and kinda fix all --- cmd/interpreter/main.go | 10 +--------- internal/interpreter/transformer.go | 10 +++++----- internal/llrgen/llrgen.go | 28 +++++++++------------------- internal/runtime/program.go | 4 ++-- internal/runtime/runtime.go | 8 +++++--- 5 files changed, 22 insertions(+), 38 deletions(-) diff --git a/cmd/interpreter/main.go b/cmd/interpreter/main.go index e85b857e..1fbc56af 100644 --- a/cmd/interpreter/main.go +++ b/cmd/interpreter/main.go @@ -28,16 +28,8 @@ interfaces { components { Main(start) (exit) { - nodes { - abs IReader - concrete = io.Reader() - } net { - in.start -> abs.in.v - abs.out.v -> { - concrete.in.v - } - concrete.out.v -> out.code + in.start -> out.exit } } } diff --git a/internal/interpreter/transformer.go b/internal/interpreter/transformer.go index eb746d1d..98bc060c 100644 --- a/internal/interpreter/transformer.go +++ b/internal/interpreter/transformer.go @@ -14,7 +14,7 @@ func (t transformer) Transform(ctx context.Context, ll shared.LLProgram) (runtim for addr, buf := range ll.Ports { rPorts[runtime.PortAddr{ Path: addr.Path, - Name: addr.Port, + Port: addr.Port, Idx: addr.Idx, }] = make(chan runtime.Msg, buf) } @@ -23,7 +23,7 @@ func (t transformer) Transform(ctx context.Context, ll shared.LLProgram) (runtim for _, conn := range ll.Net { senderAddr := runtime.PortAddr{ Path: conn.SenderSide.Path, - Name: conn.SenderSide.Port, + Port: conn.SenderSide.Port, Idx: conn.SenderSide.Idx, } @@ -43,7 +43,7 @@ func (t transformer) Transform(ctx context.Context, ll shared.LLProgram) (runtim for _, rcvr := range conn.ReceiverSides { receiverPortAddr := runtime.PortAddr{ Path: rcvr.PortAddr.Path, - Name: rcvr.PortAddr.Port, + Port: rcvr.PortAddr.Port, Idx: rcvr.PortAddr.Idx, } @@ -73,7 +73,7 @@ func (t transformer) Transform(ctx context.Context, ll shared.LLProgram) (runtim for _, addr := range f.IO.In { rPort := rPorts[runtime.PortAddr{ Path: addr.Path, - Name: addr.Port, + Port: addr.Port, Idx: addr.Idx, }] rIOIn[addr.Port] = append(rIOIn[addr.Port], rPort) @@ -83,7 +83,7 @@ func (t transformer) Transform(ctx context.Context, ll shared.LLProgram) (runtim for _, addr := range f.IO.Out { rPort := rPorts[runtime.PortAddr{ Path: addr.Path, - Name: addr.Port, + Port: addr.Port, Idx: addr.Idx, }] rIOOut[addr.Port] = append(rIOOut[addr.Port], rPort) diff --git a/internal/llrgen/llrgen.go b/internal/llrgen/llrgen.go index 1f52f079..d2f93d9f 100644 --- a/internal/llrgen/llrgen.go +++ b/internal/llrgen/llrgen.go @@ -155,14 +155,14 @@ func (g Generator) insertConnectionsAndReturnIOUsage( nodesIOUsage[senderPortAddr.Node].out[senderPortAddr.Port]++ // fixme why we assume that? senderSide := shared.LLPortAddr{ - Path: nodeCtx.path, - Port: conn.SenderSide.PortAddr.Node, + Path: nodeCtx.path + "/" + conn.SenderSide.PortAddr.Node, + Port: conn.SenderSide.PortAddr.Port, Idx: conn.SenderSide.PortAddr.Idx, } receiverSides := make([]shared.LLReceiverConnectionSide, 0, len(conn.ReceiverSides)) for _, receiverSide := range conn.ReceiverSides { - irSide := g.mapReceiverConnectionSide(nodeCtx.path, receiverSide, "in") + irSide := g.mapReceiverConnectionSide(nodeCtx.path, receiverSide) receiverSides = append(receiverSides, irSide) // we can have same receiver for different senders and we don't want to count it twice @@ -250,23 +250,13 @@ type handleSenderSideResult struct { } // mapReceiverConnectionSide maps compiler connection side to ir connection side 1-1 just making the port addr's path absolute -func (g Generator) mapReceiverConnectionSide(nodeCtxPath string, side shared.ReceiverConnectionSide, pathPostfix string) shared.LLReceiverConnectionSide { +func (g Generator) mapReceiverConnectionSide(nodeCtxPath string, side shared.ReceiverConnectionSide) shared.LLReceiverConnectionSide { return shared.LLReceiverConnectionSide{ - PortAddr: g.portAddr(nodeCtxPath, side, pathPostfix), + PortAddr: shared.LLPortAddr{ + Path: nodeCtxPath + "/" + side.PortAddr.Node, + Port: side.PortAddr.Port, + Idx: side.PortAddr.Idx, + }, Selectors: side.Selectors, } } - -func (Generator) portAddr(nodeCtxPath string, side shared.ReceiverConnectionSide, pathPostfix string) shared.LLPortAddr { - addr := shared.LLPortAddr{ - Path: nodeCtxPath, - Port: side.PortAddr.Port, - Idx: side.PortAddr.Idx, - } - - if side.PortAddr.Node != "in" && side.PortAddr.Node != "out" { - addr.Path += "/" + pathPostfix - } - - return addr -} diff --git a/internal/runtime/program.go b/internal/runtime/program.go index c5ee9fad..6c530c01 100644 --- a/internal/runtime/program.go +++ b/internal/runtime/program.go @@ -13,7 +13,7 @@ type Program struct { type PortAddr struct { Path string // Path is needed to distinguish ports with the same name - Name string // Separate name field is needed for functions + Port string // Separate port field is needed for functions Idx uint8 } @@ -22,7 +22,7 @@ func (p PortAddr) String() string { if p.Path != "" { s += p.Path + "." } - return s + fmt.Sprintf("%s[%d]", p.Name, p.Idx) + return s + fmt.Sprintf("%s[%d]", p.Port, p.Idx) } type Ports map[PortAddr]chan Msg diff --git a/internal/runtime/runtime.go b/internal/runtime/runtime.go index 432bb5d4..c3fcc3f2 100644 --- a/internal/runtime/runtime.go +++ b/internal/runtime/runtime.go @@ -43,12 +43,12 @@ var ( func (r Runtime) Run(ctx context.Context, prog Program) (code int, err error) { // FirstByName is not how this supposed to be working! There could be more "start" and "exit" ports! - startPort := prog.Ports[PortAddr{Path: "main/in", Name: "start"}] + startPort := prog.Ports[PortAddr{Path: "main/in", Port: "start"}] if startPort == nil { return 0, ErrStartPortNotFound } - exitPort := prog.Ports[PortAddr{Path: "main/in", Name: "start"}] + exitPort := prog.Ports[PortAddr{Path: "main/in", Port: "start"}] if exitPort == nil { return 0, ErrExitPortNotFound } @@ -70,7 +70,9 @@ func (r Runtime) Run(ctx context.Context, prog Program) (code int, err error) { return nil }) - go func() { startPort <- nil }() + go func() { // kick + startPort <- emptyMsg{} + }() var exitCode int go func() {