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
|
|
@ -467,6 +467,31 @@ var ListPrototype = map[string]*BuiltinFunctionValue{
|
|||
nil,
|
||||
false,
|
||||
},
|
||||
"put": {
|
||||
"put",
|
||||
&FunctionSignature{
|
||||
[]TypeSignature{
|
||||
&NumberSignature{}, &InnerSignature{},
|
||||
},
|
||||
&NilSignature{},
|
||||
},
|
||||
func(_ *VM, this Value, args []Value) (Value, error) {
|
||||
l := this.(*ListValue)
|
||||
i := int(args[0].(*NumberValue).Number)
|
||||
v := args[1]
|
||||
|
||||
// bounds check
|
||||
if i < 0 || i >= len(l.Items) {
|
||||
return nil, errors.New(fmt.Sprintf("index %x out of range", i))
|
||||
}
|
||||
|
||||
l.Items[i] = v
|
||||
|
||||
return &NilValue{}, nil
|
||||
},
|
||||
nil,
|
||||
false,
|
||||
},
|
||||
"length": {
|
||||
"length",
|
||||
&FunctionSignature{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue