-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
258 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package analyzer | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/nevalang/neva/internal/compiler/src" | ||
ts "github.com/nevalang/neva/pkg/typesystem" | ||
) | ||
|
||
func (a Analyzer) analyzeComponent(comp src.Component, prog src.Program) (src.Component, error) { | ||
resolvedInterface, err := a.analyzeInterface(comp.Interface) | ||
if err != nil { | ||
return src.Component{}, fmt.Errorf("analyze interface: %w", err) | ||
} | ||
|
||
if err := a.analyzeComponentNodes(comp.Nodes, prog); err != nil { | ||
return src.Component{}, fmt.Errorf("analyze component nodes: %w", err) | ||
} | ||
|
||
normalizedNetwork, err := a.analyzeComponentNet(comp.Net, resolvedInterface, comp.Nodes) | ||
if err != nil { | ||
return src.Component{}, fmt.Errorf("analyze component network: %w", err) | ||
} | ||
|
||
return src.Component{ | ||
Interface: resolvedInterface, | ||
Nodes: comp.Nodes, | ||
Net: normalizedNetwork, | ||
}, nil | ||
} | ||
|
||
func (a Analyzer) analyzeComponentNodes(nodes map[string]src.Node, prog src.Program) error { | ||
for _, node := range nodes { | ||
if err := a.analyzeComponentNode(node, prog); err != nil { | ||
return fmt.Errorf("analyze node: %w", err) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
var ( | ||
ErrNodeEntity = fmt.Errorf("node entity is not a component or interface") | ||
ErrNodeTypeArgsCountMismatch = errors.New("node type args count mismatch") | ||
) | ||
|
||
func (a Analyzer) analyzeComponentNode(node src.Node, prog src.Program) error { | ||
entity, err := prog.Entity(node.EntityRef) | ||
if err != nil { | ||
return fmt.Errorf("entity: %w", err) | ||
} | ||
|
||
if entity.Kind != src.ComponentEntity && entity.Kind != src.InterfaceEntity { | ||
return fmt.Errorf("%w: %v", ErrNodeEntity, entity.Kind) | ||
} | ||
|
||
var compInterface src.Interface | ||
if entity.Kind == src.ComponentEntity { | ||
compInterface = entity.Component.Interface | ||
} else { | ||
compInterface = entity.Interface | ||
} | ||
|
||
if len(node.TypeArgs) != len(compInterface.TypeParams) { | ||
return fmt.Errorf( | ||
"%w: want %v, got %v", | ||
ErrNodeTypeArgsCountMismatch, compInterface.TypeParams, node.TypeArgs, | ||
) | ||
} | ||
|
||
resolvedArgs := make([]ts.Expr, 0, len(node.TypeArgs)) | ||
for _, arg := range node.TypeArgs { | ||
resolvedArg, err := a.analyzeTypeExpr(arg) | ||
if err != nil { | ||
return fmt.Errorf("analyze type expr: %w", err) | ||
} | ||
resolvedArgs = append(resolvedArgs, resolvedArg) | ||
} | ||
|
||
// check that args are compatible with type params | ||
// this can be done by creating | ||
|
||
return nil | ||
} | ||
|
||
func (a Analyzer) analyzeComponentNet( | ||
net []src.Connection, | ||
compInterface src.Interface, | ||
nodes map[string]src.Node, | ||
) ([]src.Connection, error) { | ||
return net, nil // TODO | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package analyzer | ||
|
||
import ( | ||
"fmt" | ||
|
||
ts "github.com/nevalang/neva/pkg/typesystem" | ||
) | ||
|
||
func (a Analyzer) analyzeTypeDef(def ts.Def) (ts.Def, error) { | ||
resolvedDef, err := a.resolver.ResolveDef(def, nil) | ||
if err != nil { | ||
return ts.Def{}, fmt.Errorf("resolve def: %w", err) | ||
} | ||
return resolvedDef, nil | ||
} | ||
|
||
func (a Analyzer) analyzeTypeExpr(expr ts.Expr) (ts.Expr, error) { | ||
resolvedExpr, err := a.resolver.ResolveExpr(expr, nil) | ||
if err != nil { | ||
return ts.Expr{}, fmt.Errorf("resolve expr: %w", err) | ||
} | ||
return resolvedExpr, nil | ||
} | ||
|
||
func (a Analyzer) analyzeTypeParams(params []ts.Param) ([]ts.Param, error) { | ||
resolvedParams, _, err := a.resolver.ResolveParams(params, nil) | ||
if err != nil { | ||
return nil, fmt.Errorf("resolve params: %w", err) | ||
} | ||
return resolvedParams, nil | ||
} |
Oops, something went wrong.