basic records support
This commit is contained in:
parent
19011e67da
commit
ff11d7e0ed
11 changed files with 522 additions and 138 deletions
20
core/vm.go
20
core/vm.go
|
|
@ -126,7 +126,7 @@ const (
|
|||
// InstructionAppend Append to a list. stack: (... > list > item) => (... > list)
|
||||
InstructionAppend
|
||||
// InstructionFormList Form items on the stack into a list. The 2 bytes after the instructions are the amount of
|
||||
// items to include) The order is reversed compared to on the stack; the top value on the stack is the last in the
|
||||
// items to include. The order is reversed compared to on the stack; the top value on the stack is the last in the
|
||||
// list.
|
||||
InstructionFormList
|
||||
// InstructionConcatLists concatenate lists, producing a new list with the values of both lists. Pops two lists.
|
||||
|
|
@ -139,6 +139,12 @@ const (
|
|||
// being the last item in the tuple.
|
||||
InstructionDestructureTuple
|
||||
|
||||
// InstructionNewRecord Create a new empty record.
|
||||
InstructionNewRecord
|
||||
// InstructionSetRecordItem Set the value of an item in the record, and create it if it does not already exist.
|
||||
// [..., record, item]; the following byte should be the index of a string constant with the name of the property.
|
||||
InstructionSetRecordItem
|
||||
|
||||
// InstructionIndexList index into a list. The lower item is the container, and the top item
|
||||
// is the index. [..., container, index] -> [..., item]
|
||||
InstructionIndexList
|
||||
|
|
@ -1076,6 +1082,18 @@ func (vm *VM) Next() bool {
|
|||
|
||||
vm.Stack.Push(member)
|
||||
|
||||
case InstructionSetRecordItem:
|
||||
i := vm.Stack.Pop()
|
||||
prop := vm.ReadConstant().(*StringValue)
|
||||
r := vm.Stack.Peek().(*RecordValue)
|
||||
|
||||
r.Entries[prop.Text] = i
|
||||
|
||||
case InstructionNewRecord:
|
||||
vm.Stack.Push(&RecordValue{
|
||||
map[string]Value{},
|
||||
})
|
||||
|
||||
case InstructionIndexList:
|
||||
i := vm.Stack.Pop().(*IntegerValue)
|
||||
l := vm.Stack.Pop().(*ListValue)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue