add file trace to parser, refactor, fix inner type
This commit is contained in:
parent
bcf0978b68
commit
c8660a6471
10 changed files with 131 additions and 51 deletions
|
|
@ -393,6 +393,18 @@ func (c *Compiler) compile(tree Node) error {
|
|||
return c.error(fmt.Sprintf("wrong argument count: function of signature %s got %d, requires %d", f, len(n.args), len(f.In)), n)
|
||||
}
|
||||
|
||||
var innerType TypeSignature
|
||||
if a, ok := n.source.(*AccessNode); ok {
|
||||
isig, err := c.deduceSignature(a.source)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if isig.Type() == TypeList {
|
||||
innerType = isig.(*ListSignature).Contents
|
||||
}
|
||||
}
|
||||
|
||||
for i, arg := range n.args {
|
||||
sig, err := c.deduceSignature(arg)
|
||||
if err != nil {
|
||||
|
|
@ -400,7 +412,11 @@ func (c *Compiler) compile(tree Node) error {
|
|||
}
|
||||
|
||||
// check that arg type is as required
|
||||
if !f.In[i].Matches(sig) {
|
||||
fin := f.In[i]
|
||||
if fin.Type() == TypeInner && innerType != nil {
|
||||
fin = innerType
|
||||
}
|
||||
if !fin.Matches(sig) {
|
||||
return c.error(fmt.Sprintf("argument #%d does not have expected type signature: got %s, requires %s", i, sig, f.In[i]), arg)
|
||||
}
|
||||
|
||||
|
|
@ -598,7 +614,7 @@ func (c *Compiler) deduceSignature(tree Node) (TypeSignature, error) {
|
|||
n := tree.(*ListNode)
|
||||
|
||||
contents := n.content
|
||||
// check for contents type
|
||||
// check for content type
|
||||
for _, v := range n.items {
|
||||
sig, err := c.deduceSignature(v)
|
||||
if err != nil {
|
||||
|
|
@ -761,7 +777,7 @@ func (c *Compiler) deduceSignature(tree Node) (TypeSignature, error) {
|
|||
|
||||
if f.Out.Type() == TypeInner {
|
||||
if innerType == nil {
|
||||
return nil, c.error(fmt.Sprintf("function source (%s) has no inner type", sig), n.source)
|
||||
return nil, c.error(fmt.Sprintf("function source (%s) has no inner type (@ output)", sig), n.source)
|
||||
}
|
||||
|
||||
return innerType, nil
|
||||
|
|
@ -1204,7 +1220,7 @@ func (c *Compiler) error(msg string, causer Node) CompilerError {
|
|||
msg,
|
||||
causer,
|
||||
c.source,
|
||||
c.fileStack.items[0:c.fileStack.Current],
|
||||
c.fileStack.Slice(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1223,7 +1239,7 @@ func (c *Compiler) resolveImport(path string) error {
|
|||
// stop recursive imports
|
||||
for i := c.fileStack.Current - 1; i >= 0; i-- {
|
||||
if c.resolver.IsSame(path, c.fileStack.items[i]) {
|
||||
return errors.New("recursive imports")
|
||||
return errors.New("recursive import")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1238,7 +1254,7 @@ func (c *Compiler) resolveImport(path string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
parser := NewParser(src, tokens)
|
||||
parser := NewParser(src, append(c.fileStack.Slice(), path), tokens)
|
||||
p, err := parser.Parse(path)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue