basic records support
This commit is contained in:
parent
19011e67da
commit
ff11d7e0ed
11 changed files with 522 additions and 138 deletions
|
|
@ -265,6 +265,30 @@ func (c *Compiler) compile(tree Node) (TypeSignature, error) {
|
|||
|
||||
return &TupleSignature{contents}, nil
|
||||
|
||||
case RecordNodeType:
|
||||
n := tree.(*RecordNode)
|
||||
|
||||
c.add(InstructionNewRecord)
|
||||
|
||||
contents := map[string]TypeSignature{}
|
||||
for k, v := range n.entries {
|
||||
t, err := c.compile(v)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
c.add(InstructionSetRecordItem)
|
||||
c.addConstant(&StringValue{
|
||||
k,
|
||||
})
|
||||
|
||||
contents[k] = t
|
||||
}
|
||||
|
||||
return &RecordSignature{
|
||||
contents,
|
||||
}, nil
|
||||
|
||||
case ListNodeType:
|
||||
l := tree.(*ListNode)
|
||||
|
||||
|
|
@ -1196,6 +1220,13 @@ func (c *Compiler) getPropertySignature(source TypeSignature, property string) (
|
|||
return &CompositeSignature{
|
||||
at, bt,
|
||||
}, nil
|
||||
case TypeRecord:
|
||||
prop, ok := sig.(*RecordSignature).Entries[property]
|
||||
if !ok {
|
||||
return nil, errors.New(fmt.Sprintf("cannot record has no property \"%s\"", property))
|
||||
}
|
||||
|
||||
return prop, nil
|
||||
default:
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue