Skip to content

Commit

Permalink
feat: add symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
siyul-park committed Nov 25, 2023
1 parent 6a297ef commit 1556b52
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 103 deletions.
46 changes: 20 additions & 26 deletions pkg/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,12 @@ type (

// Loader loads scheme.Spec into symbol.Table.
Loader struct {
scheme *scheme.Scheme
table *symbol.Table
remote *storage.Storage
local *storage.Storage
referenced map[ulid.ULID]links
undefined map[ulid.ULID]links
mu sync.RWMutex
scheme *scheme.Scheme
table *symbol.Table
remote *storage.Storage
local *storage.Storage
mu sync.RWMutex
}

links map[string][]scheme.PortLocation
)

// New returns a new Loader.
Expand All @@ -50,12 +46,10 @@ func New(ctx context.Context, config Config) (*Loader, error) {
}

return &Loader{
scheme: scheme,
table: table,
remote: remote,
local: local,
referenced: make(map[ulid.ULID]links),
undefined: make(map[ulid.ULID]links),
scheme: scheme,
table: table,
remote: remote,
local: local,
}, nil
}

Expand Down Expand Up @@ -102,11 +96,9 @@ func (ld *Loader) loadOne(ctx context.Context, filter *storage.Filter) (node.Nod
}

if remote != nil {
if local != nil {
if reflect.DeepEqual(remote, local) {
if n, ok := ld.table.Lookup(remote.GetID()); ok {
return n, nil
}
if reflect.DeepEqual(remote, local) {
if n, ok := ld.table.Lookup(remote.GetID()); ok {
return n, nil

Check failure on line 101 in pkg/loader/loader.go

View workflow job for this annotation

GitHub Actions / Check ubuntu-20.04 @ Go 1.21

cannot use n (variable of type *symbol.Symbol) as node.Node value in return statement: *symbol.Symbol does not implement node.Node (missing method Close)
}
}
} else {
Expand All @@ -117,6 +109,8 @@ func (ld *Loader) loadOne(ctx context.Context, filter *storage.Filter) (node.Nod
return nil, nil
}

// load child

if n, err := ld.scheme.Decode(remote); err != nil {
return nil, err
} else {
Expand Down Expand Up @@ -173,15 +167,15 @@ func (ld *Loader) loadMany(ctx context.Context, filter *storage.Filter) ([]node.
var nodes []node.Node
for id, remote := range idToRemote {
local := idToLocal[id]
if local != nil {
if reflect.DeepEqual(remote, local) {
if n, ok := ld.table.Lookup(id); ok {
nodes = append(nodes, n)
continue
}
if reflect.DeepEqual(remote, local) {
if n, ok := ld.table.Lookup(id); ok {
nodes = append(nodes, n)

Check failure on line 172 in pkg/loader/loader.go

View workflow job for this annotation

GitHub Actions / Check ubuntu-20.04 @ Go 1.21

cannot use n (variable of type *symbol.Symbol) as node.Node value in argument to append: *symbol.Symbol does not implement node.Node (missing method Close)
continue
}
}

// load child

if n, err := ld.scheme.Decode(remote); err != nil {
return nil, err
} else {
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/networkx/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestAddToHooks(t *testing.T) {
})

hk.Load(n)

errChan := make(chan error)

err = n.WaitForListen(errChan)
Expand Down
34 changes: 34 additions & 0 deletions pkg/symbol/symbo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package symbol

import (
"github.com/oklog/ulid/v2"
"github.com/siyul-park/uniflow/pkg/node"
"github.com/siyul-park/uniflow/pkg/scheme"
)

type (
Symbol struct {
Node node.Node
Spec scheme.Spec
}
)

func (s *Symbol) ID() ulid.ULID {
return s.Spec.GetID()
}

func (s *Symbol) Kind() string {
return s.Spec.GetKind()
}

func (s *Symbol) Namespace() string {
return s.Spec.GetNamespace()
}

func (s *Symbol) Name() string {
return s.Spec.GetName()
}

func (s *Symbol) Links() map[string][]scheme.PortLocation {
return s.Spec.GetLinks()
}
Loading

0 comments on commit 1556b52

Please sign in to comment.