Skip to content

Commit

Permalink
fix(llrgen): simplify example and kinda fix all
Browse files Browse the repository at this point in the history
  • Loading branch information
Emil Valeev committed Aug 13, 2023
1 parent a7552ca commit 281b1bd
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 38 deletions.
10 changes: 1 addition & 9 deletions cmd/interpreter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions internal/interpreter/transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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,
}

Expand All @@ -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,
}

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
28 changes: 9 additions & 19 deletions internal/llrgen/llrgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions internal/runtime/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
Expand Down
8 changes: 5 additions & 3 deletions internal/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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() {
Expand Down

0 comments on commit 281b1bd

Please sign in to comment.