@@ -59,14 +59,18 @@ func Debug() *VM {
59
59
func (vm * VM ) Run (program * Program , env any ) (_ any , err error ) {
60
60
defer func () {
61
61
if r := recover (); r != nil {
62
+ var location file.Location
63
+ if vm .ip - 1 < len (program .locations ) {
64
+ location = program .locations [vm .ip - 1 ]
65
+ }
62
66
f := & file.Error {
63
- Location : program . Locations [ vm . ip - 1 ] ,
67
+ Location : location ,
64
68
Message : fmt .Sprintf ("%v" , r ),
65
69
}
66
70
if err , ok := r .(error ); ok {
67
71
f .Wrap (err )
68
72
}
69
- err = f .Bind (program .Source )
73
+ err = f .Bind (program .source )
70
74
}
71
75
}()
72
76
@@ -108,10 +112,10 @@ func (vm *VM) Run(program *Program, env any) (_ any, err error) {
108
112
vm .pop ()
109
113
110
114
case OpStore :
111
- program .Variables [arg ] = vm .pop ()
115
+ program .variables [arg ] = vm .pop ()
112
116
113
117
case OpLoadVar :
114
- vm .push (program .Variables [arg ])
118
+ vm .push (program .variables [arg ])
115
119
116
120
case OpLoadConst :
117
121
vm .push (runtime .Fetch (env , program .Constants [arg ]))
@@ -126,7 +130,7 @@ func (vm *VM) Run(program *Program, env any) (_ any, err error) {
126
130
vm .push (runtime .FetchMethod (env , program .Constants [arg ].(* runtime.Method )))
127
131
128
132
case OpLoadFunc :
129
- vm .push (program .Functions [arg ])
133
+ vm .push (program .functions [arg ])
130
134
131
135
case OpFetch :
132
136
b := vm .pop ()
@@ -332,15 +336,15 @@ func (vm *VM) Run(program *Program, env any) (_ any, err error) {
332
336
vm .push (out [0 ].Interface ())
333
337
334
338
case OpCall0 :
335
- out , err := program .Functions [arg ]()
339
+ out , err := program .functions [arg ]()
336
340
if err != nil {
337
341
panic (err )
338
342
}
339
343
vm .push (out )
340
344
341
345
case OpCall1 :
342
346
a := vm .pop ()
343
- out , err := program.Functions [arg ](a )
347
+ out , err := program.functions [arg ](a )
344
348
if err != nil {
345
349
panic (err )
346
350
}
@@ -349,7 +353,7 @@ func (vm *VM) Run(program *Program, env any) (_ any, err error) {
349
353
case OpCall2 :
350
354
b := vm .pop ()
351
355
a := vm .pop ()
352
- out , err := program .Functions [arg ](a , b )
356
+ out , err := program .functions [arg ](a , b )
353
357
if err != nil {
354
358
panic (err )
355
359
}
@@ -359,7 +363,7 @@ func (vm *VM) Run(program *Program, env any) (_ any, err error) {
359
363
c := vm .pop ()
360
364
b := vm .pop ()
361
365
a := vm .pop ()
362
- out , err := program .Functions [arg ](a , b , c )
366
+ out , err := program .functions [arg ](a , b , c )
363
367
if err != nil {
364
368
panic (err )
365
369
}
0 commit comments