Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
emil14 committed Sep 20, 2023
1 parent 888ac73 commit 447583f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ linters:
- exhaustivestruct
- exhaustruct
- exhaustive
- composites
# - composites
# - testpackage # _test package
# - forbidigo # doesn't allow to use fmt.Println

Expand Down
2 changes: 1 addition & 1 deletion internal/interpreter/transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (t transformer) Transform(ctx context.Context, irprog *ir.Program) (runtime
},
}

rReceivers := make([]runtime.ReceiverConnectionSide, len(conn.ReceiverSides))
rReceivers := make([]runtime.ReceiverConnectionSide, 0, len(conn.ReceiverSides))
for _, rcvr := range conn.ReceiverSides {
receiverPortAddr := runtime.PortAddr{
Path: rcvr.PortAddr.Path,
Expand Down
14 changes: 5 additions & 9 deletions internal/runtime/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,17 @@ type Msg interface {
Int() int64
Float() float64
Str() string
Vec() []Msg
Map() map[string]Msg
}

// Empty

type emptyMsg struct{}

func (emptyMsg) Bool() bool { return false }
func (emptyMsg) Int() int64 { return 0 }
func (emptyMsg) Float() float64 { return 0 }
func (emptyMsg) Str() string { return "" }
func (emptyMsg) Vec() []Msg { return []Msg{} }
func (emptyMsg) Map() map[string]Msg { return map[string]Msg{} }
func (emptyMsg) String() string { return "stringer not implemented" }
func (emptyMsg) Bool() bool { return false }
func (emptyMsg) Int() int64 { return 0 }
func (emptyMsg) Float() float64 { return 0 }
func (emptyMsg) Str() string { return "" }
func (emptyMsg) String() string { return "()" } // stringer

// Int

Expand Down
14 changes: 8 additions & 6 deletions internal/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ 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 "enter" and "exit" ports!
startPort := prog.Ports[PortAddr{Path: "main/in", Port: "enter"}]
if startPort == nil {
enter := prog.Ports[PortAddr{Path: "main/in", Port: "enter"}]
if enter == nil {
return 0, ErrStartPortNotFound
}

exitPort := prog.Ports[PortAddr{Path: "main/in", Port: "enter"}]
if exitPort == nil {
exit := prog.Ports[PortAddr{Path: "main/out", Port: "exit"}]
if exit == nil {
return 0, ErrExitPortNotFound
}

Expand All @@ -73,12 +73,14 @@ func (r Runtime) Run(ctx context.Context, prog Program) (code int, err error) {
})

go func() { // kick
startPort <- emptyMsg{}
enter <- emptyMsg{}
}()

var exitCode int64
go func() {
exitCode, ok = (<-exitPort).Int()
msg := <-exit
fmt.Println(msg)
exitCode = (<-exit).Int()
cancel()
}()

Expand Down

0 comments on commit 447583f

Please sign in to comment.