basic records support

This commit is contained in:
Neemek 2026-08-17 17:08:24 +02:00 committed by Neemek
parent 19011e67da
commit ff11d7e0ed
Signed by: neemek
GPG key ID: 84FFE4D7D40AB25E
11 changed files with 522 additions and 138 deletions

View file

@ -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:
}