github.com/nevalang/neva@v0.23.1-0.20240507185603-7696a9bb8dda/internal/runtime/ir/ir.go (about)

     1  package ir
     2  
     3  // Program represents the main structure containing ports, connections, and funcs.
     4  type Program struct {
     5  	Ports       []PortInfo   `json:"ports,omitempty"`
     6  	Connections []Connection `json:"connections,omitempty"`
     7  	Funcs       []FuncCall   `json:"funcs,omitempty"`
     8  }
     9  
    10  // PortInfo contains information about each port.
    11  type PortInfo struct {
    12  	PortAddr PortAddr `json:"port_addr,omitempty"`
    13  	BufSize  uint32   `json:"buf_size,omitempty"`
    14  }
    15  
    16  // PortAddr represents the address of a port.
    17  type PortAddr struct {
    18  	Path string `json:"path,omitempty"`
    19  	Port string `json:"port,omitempty"`
    20  	Idx  uint32 `json:"index,omitempty"`
    21  }
    22  
    23  // Connection represents connections between ports.
    24  type Connection struct {
    25  	SenderSide    PortAddr                 `json:"sender_side,omitempty"`
    26  	ReceiverSides []ReceiverConnectionSide `json:"receiver_sides,omitempty"`
    27  }
    28  
    29  // ReceiverConnectionSide represents the receiver side of a connection.
    30  type ReceiverConnectionSide struct {
    31  	PortAddr PortAddr `json:"port_addr,omitempty"`
    32  }
    33  
    34  // FuncCall represents a function within the program.
    35  type FuncCall struct {
    36  	Ref string `json:"ref,omitempty"`
    37  	IO  FuncIO `json:"io,omitempty"`
    38  	Msg *Msg   `json:"msg,omitempty"`
    39  }
    40  
    41  // FuncIO represents the input/output ports of a function.
    42  type FuncIO struct {
    43  	In  []PortAddr `json:"in,omitempty"`  // Must be ordered by path -> port -> idx
    44  	Out []PortAddr `json:"out,omitempty"` // Must be ordered by path -> port -> idx
    45  }
    46  
    47  // Msg represents a message.
    48  type Msg struct {
    49  	Type  MsgType        `json:"-"`
    50  	Bool  bool           `json:"bool,omitempty"`
    51  	Int   int64          `json:"int,omitempty"`
    52  	Float float64        `json:"float,omitempty"`
    53  	Str   string         `json:"str,omitempty"`
    54  	List  []Msg          `json:"list,omitempty"`
    55  	Map   map[string]Msg `json:"map,omitempty"`
    56  }
    57  
    58  // MsgType is an enumeration of message types.
    59  type MsgType int32
    60  
    61  const (
    62  	MsgTypeUnspecified MsgType = 0
    63  	MsgTypeBool        MsgType = 1
    64  	MsgTypeInt         MsgType = 2
    65  	MsgTypeFloat       MsgType = 3
    66  	MsgTypeString      MsgType = 4
    67  	MsgTypeList        MsgType = 5
    68  	MsgTypeMap         MsgType = 6
    69  )