This repository has been archived by the owner on Feb 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 93
/
opcode.go
807 lines (641 loc) · 28.1 KB
/
opcode.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
// Copyright 2017 Istio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package il
// Opcode is the type for the opcodes in the il.
type Opcode uint32
// OpcodeArg represents the type of the arguments that opcodes have.
type OpcodeArg int
// opcodeInfo holds metadata about an opcode.
type opcodeInfo struct {
// The human-readable name of the opcode.
name string
// The string keyword matching this opcode.
keyword string
// The set of arguments that is expected by this opcode.
args []OpcodeArg
}
const (
// Halt stops the VM with an error.
Halt Opcode = 0
// Nop does nothing.
Nop Opcode = 1
// Err raises an error.
Err Opcode = 2
// Errz pops a boolean value from stack and check its value. if the value is false, then it
// raises an error.
Errz Opcode = 3
// Errnz pops a boolean value from stack and check its value. if the value is true, then it
// raises an error.
Errnz Opcode = 4
// PopS pops a string from the stack.
PopS Opcode = 10
// PopB pops a bool from the stack.
PopB Opcode = 11
// PopI pops an integer from the stack.
PopI Opcode = 12
// PopD pops a double from the stack.
PopD Opcode = 13
// DupS pops a string value from the stack and pushes it back into the stack twice.
DupS Opcode = 14
// DupB pops a boolean value from the stack and pushes it back into the stack twice.
DupB Opcode = 15
// DupI pops an integer value from the stack and pushes it back into the stack twice.
DupI Opcode = 16
// DupD pops a double value from the stack and pushes it back into the stack twice.
DupD Opcode = 17
// RLoadS pops a string from the stack and stores in the target register.
RLoadS Opcode = 20
// RLoadB pops a bool from the stack and stores in the target register.
RLoadB Opcode = 21
// RLoadI pops an integer from the stack and stores in the target register.
RLoadI Opcode = 22
// RLoadD pops a double from the stack and stores in the target register.
RLoadD Opcode = 23
// ALoadS loads its string argument into the target register.
ALoadS Opcode = 30
// ALoadB loads its boolean argument into the target register.
ALoadB Opcode = 31
// ALoadI loads its integer argument into the target register.
ALoadI Opcode = 32
// ALoadD loads its double argument into the target register.
ALoadD Opcode = 33
// APushS pushes its string argument to the stack.
APushS Opcode = 40
// APushB pushes its boolean argument to the stack.
APushB Opcode = 41
// APushI pushes its integer argument to the stack.
APushI Opcode = 42
// APushD pushes its double argument to the stack.
APushD Opcode = 43
// RPushS reads a string value from the target register and pushes it into stack.
RPushS Opcode = 50
// RPushB reads a boolean value from the target register and pushes it into stack.
RPushB Opcode = 51
// RPushI reads an integer value from the target register and pushes it into stack.
RPushI Opcode = 52
// RPushD reads a double value from the target register and pushes it into stack.
RPushD Opcode = 53
// EqS pops two string values from the stack and compare for equality. If the strings are
// equal then it pushes 1 into the stack, otherwise it pushes 0.
EqS Opcode = 60
// EqB pops two bool values from the stack and compare for equality. If equal, then it
// pushes 1 into the stack, otherwise it pushes 0.
EqB Opcode = 61
// EqI pops two integer values from the stack and compare for equality. If equal, then it
// pushes 1 into the stack, otherwise it pushes 0.
EqI Opcode = 62
// EqD pops two double values from the stack and compare for equality. If equal, then it
// pushes 1 into the stack, otherwise it pushes 0.
EqD Opcode = 63
// AEqS pops a string value from the stack and compare it against its argument for equality.
// If equal, then it pushes 1 into the stack, otherwise it pushes 0.
AEqS Opcode = 70
// AEqB pops a bool value from the stack and compare it against its argument for equality.
// If equal, then it pushes 1 into the stack, otherwise it pushes 0.
AEqB Opcode = 71
// AEqI pops an integer value from the stack and compare it against its argument for equality
// If equal, then it pushes 1 into the stack, otherwise it pushes 0.
AEqI Opcode = 72
// AEqD pops a double value from the stack and compare it against its argument for equality
// If equal, then it pushes 1 into the stack, otherwise it pushes 0.
AEqD Opcode = 73
// Xor pops two boolean values from the stack, performs logical exclusive-or, then pushes the
// result back into stack.
Xor Opcode = 80
// And pops two boolean values from the stack, performs logical and, then pushes the
// result back into stack.
And Opcode = 81
// Or pops two boolean values from the stack, performs logical or, then pushes the
// result back into stack.
Or Opcode = 82
// AXor pops a boolean value from the stack and performs logical exclusive-or with its
// argument, then pushes the result back into stack.
AXor Opcode = 83
// AAnd pops a boolean value from the stack and performs logical and with its
// argument, then pushes the result back into stack.
AAnd Opcode = 84
// AOr pops a boolean value from the stack and performs logical or with its
// argument, then pushes the result back into stack.
AOr Opcode = 85
// Not pops a boolean value from the stack and performs logical not,
// then pushes the result back into stack.
Not Opcode = 86
// ResolveS lookups up a string attribute value in the bag, with the given name.
// If successful, pushes the resolved string into stack, otherwise raises error.
ResolveS Opcode = 90
// ResolveB lookups up a bool attribute value in the bag, with the given name.
// If successful, pushes the resolved bool into stack, otherwise raises error.
ResolveB Opcode = 91
// ResolveI lookups up an integer attribute value in the bag, with the given name.
// If successful, pushes the resolved integer into stack, otherwise raises error.
ResolveI Opcode = 92
// ResolveD lookups up a double attribute value in the bag, with the given name.
// If successful, pushes the resolved double into stack, otherwise raises error.
ResolveD Opcode = 93
// ResolveF lookups up a interface{} attribute value in the bag, with the given name.
// If successful, pushes the resolved interface{} into stack, otherwise raises error.
ResolveF Opcode = 94
// TResolveS lookups up a string attribute value in the bag, with the given name.
// If successful, pushes the resolved string value, then 1 into the stack,
// otherwise pushes 0.
TResolveS Opcode = 100
// TResolveB lookups up a bool attribute value in the bag, with the given name.
// If successful, pushes the resolved bool value, then 1 into the stack,
// otherwise pushes 0.
TResolveB Opcode = 101
// TResolveI lookups up an integer attribute value in the bag, with the given name.
// If successful, pushes the resolved integer value, then 1 into the stack,
// otherwise pushes 0.
TResolveI Opcode = 102
// TResolveD lookups up a double attribute value in the bag, with the given name.
// If successful, pushes the resolved double value, then 1 into the stack,
// otherwise pushes 0.
TResolveD Opcode = 103
// TResolveF lookups up a interface{} attribute value in the bag, with the given name.
// If successful, pushes the resolved interface{} value, then 1 into the stack,
// otherwise pushes 0.
TResolveF Opcode = 104
// AddI pops two integer values from the stack, adds their value and pushes the result
// back into stack. The operation follows Go's integer addition semantics.
AddI Opcode = 110
// AddD pops two double values from the stack, adds their value and pushes the result
// back into stack. The operation follows Go's float addition semantics.
AddD Opcode = 111
// SubI pops two integer values from the stack, and subtracts the second popped value
// from the first one, then pushes the result back into stack.
// The operation follows Go's integer subtraction semantics.
SubI Opcode = 112
// SubD pops two double values from the stack, and subtracts the second popped value
// from the first one, then pushes the result back into stack.
// The operation follows Go's float subtraction semantics.
SubD Opcode = 113
// AAddI pops an integer value from the stack, adds the popped value and its argument,
// and pushes the result back into stack. The operation follows Go's integer addition
// semantics.
AAddI Opcode = 114
// AAddD pops a double value from the stack, adds the popped value and its argument,
// and pushes the result back into stack. The operation follows Go's double addition
// semantics.
AAddD Opcode = 115
// ASubI pops an integer value from the stack, subtracts its argument from the popped value,
// then pushes the result back into stack. The operation follows Go's integer subtraction
// semantics.
ASubI Opcode = 116
// ASubD pops a double value from the stack, subtracts its argument from the popped value,
// then pushes the result back into stack. The operation follows Go's double subtraction
// semantics.
ASubD Opcode = 117
// Jmp jumps to the given instruction address.
Jmp Opcode = 200
// Jz pops a bool value from the stack. If the value is zero, then jumps to the given
// instruction address.
Jz Opcode = 201
// Jnz pops a bool value from the stack. If the value is not 0, then jumps to the given
// instruction address.
Jnz Opcode = 202
// Call invokes the target function.
Call Opcode = 203
// Ret returns from the current function.
Ret Opcode = 204
// Lookup pops a string, then a stringmap from the stack and perform a lookup on the stringmap
// using the string as the name. If a value is found, then the value is pushed into the
// stack. Otherwise raises an error.
Lookup Opcode = 210
// TLookup pops a string, then a stringmap from the stack and perform a lookup on the stringmap
// using the string as the name. If a value is found, then the value is pushed into the
// stack, then 1. Otherwise 0 is pushed to into the stack.
TLookup Opcode = 211
// ALookup pops a stringmap from the stack and perform a lookup on the stringmap using the string
// parameter as the name. If a value is found, then the value is pushed into the stack
// Otherwise raises an error.
ALookup Opcode = 212
// NLookup pops a string, then a stringmap from the stack and perform a lookup on the stringmap
// using the string as the name. If a value is found, then the value is pushed into the
// stack. Otherwise empty string is pushed onto the stack.
NLookup Opcode = 213
// ANLookup pops a stringmap from the stack and perform a lookup on the stringmap using the string
// parameter as the name. If a value is found, then the value is pushed into the stack
// Otherwise empty string is pushed onto the stack.
ANLookup Opcode = 214
)
const (
// OpcodeArgRegister represents an argument that references a register.
OpcodeArgRegister OpcodeArg = 0
// OpcodeArgString represents an argument that is a string.
OpcodeArgString OpcodeArg = 1
// OpcodeArgInt represents an argument that is an integer.
OpcodeArgInt OpcodeArg = 2
// OpcodeArgDouble represents an argument that is a double.
OpcodeArgDouble OpcodeArg = 3
// OpcodeArgBool represents an argument that is a boolean.
OpcodeArgBool OpcodeArg = 4
// OpcodeArgFunction represents an argument that is a function.
OpcodeArgFunction OpcodeArg = 5
// OpcodeArgAddress represents an argument that is an address.
OpcodeArgAddress OpcodeArg = 6
)
var argSizes = map[OpcodeArg]uint32{
OpcodeArgRegister: 1,
OpcodeArgString: 1,
OpcodeArgBool: 1,
OpcodeArgFunction: 1,
OpcodeArgAddress: 1,
OpcodeArgDouble: 2,
OpcodeArgInt: 2,
}
var opCodeInfos = map[Opcode]opcodeInfo{
// Halt stops the VM with an error.
Halt: {name: "Halt", keyword: "halt"},
// Nop does nothing.
Nop: {name: "Nop", keyword: "nop"},
// Err raises an error.
Err: {name: "Err", keyword: "err", args: []OpcodeArg{
// Text of the error.
OpcodeArgString,
}},
// Errz pops a boolean value from stack and check its value. if the value is false, then it
// raises an error.
Errz: {name: "Errz", keyword: "errz", args: []OpcodeArg{
// Text of the error message.
OpcodeArgString,
}},
// Errnz pops a boolean value from stack and check its value. if the value is true, then it
// raises an error.
Errnz: {name: "Errnz", keyword: "errnz", args: []OpcodeArg{
// Text of the error message.
OpcodeArgString,
}},
// PopS pops a string from the stack.
PopS: {name: "PopS", keyword: "pop_s"},
// PopB pops a bool from the stack.
PopB: {name: "PopB", keyword: "pop_b"},
// PopI pops an integer from the stack.
PopI: {name: "PopI", keyword: "pop_i"},
// PopD pops a double from the stack.
PopD: {name: "PopD", keyword: "pop_d"},
// DupS pops a string value from the stack and pushes it back into the stack twice.
DupS: {name: "DupS", keyword: "dup_s"},
// DupB pops a boolean value from the stack and pushes it back into the stack twice.
DupB: {name: "DupB", keyword: "dup_b"},
// DupI pops an integer value from the stack and pushes it back into the stack twice.
DupI: {name: "DupI", keyword: "dup_i"},
// DupD pops a double value from the stack and pushes it back into the stack twice.
DupD: {name: "DupD", keyword: "dup_d"},
// RLoadS pops a string from the stack and stores in the target register.
RLoadS: {name: "RLoadS", keyword: "rload_s", args: []OpcodeArg{
// The target register.
OpcodeArgRegister,
}},
// RLoadB pops a bool from the stack and stores in the target register.
RLoadB: {name: "RLoadB", keyword: "rload_b", args: []OpcodeArg{
// The target register.
OpcodeArgRegister,
}},
// RLoadI pops an integer from the stack and stores in the target register.
RLoadI: {name: "RLoadI", keyword: "rload_i", args: []OpcodeArg{
// The target register.
OpcodeArgRegister,
}},
// RLoadD pops a double from the stack and stores in the target register.
RLoadD: {name: "RLoadD", keyword: "rload_d", args: []OpcodeArg{
// The target register.
OpcodeArgRegister,
}},
// ALoadS loads its string argument into the target register.
ALoadS: {name: "ALoadS", keyword: "aload_s", args: []OpcodeArg{
// The target register.
OpcodeArgRegister,
// The string to load.
OpcodeArgString,
}},
// ALoadB loads its boolean argument into the target register.
ALoadB: {name: "ALoadB", keyword: "aload_b", args: []OpcodeArg{
// The target register.
OpcodeArgRegister,
// The bool to load.
OpcodeArgBool,
}},
// ALoadI loads its integer argument into the target register.
ALoadI: {name: "ALoadI", keyword: "aload_i", args: []OpcodeArg{
// The target register.
OpcodeArgRegister,
// The integer to load.
OpcodeArgInt,
}},
// ALoadD loads its double argument into the target register.
ALoadD: {name: "ALoadD", keyword: "aload_d", args: []OpcodeArg{
// The target register.
OpcodeArgRegister,
// The double to load.
OpcodeArgDouble,
}},
// APushS pushes its string argument to the stack.
APushS: {name: "APushS", keyword: "apush_s", args: []OpcodeArg{
// The string to push.
OpcodeArgString,
}},
// APushB pushes its boolean argument to the stack.
APushB: {name: "APushB", keyword: "apush_b", args: []OpcodeArg{
// The boolean to push.
OpcodeArgBool,
}},
// APushI pushes its integer argument to the stack.
APushI: {name: "APushI", keyword: "apush_i", args: []OpcodeArg{
// The integer to push.
OpcodeArgInt,
}},
// APushD pushes its double argument to the stack.
APushD: {name: "APushD", keyword: "apush_d", args: []OpcodeArg{
// The double to push.
OpcodeArgDouble,
}},
// RPushS reads a string value from the target register and pushes it into stack.
RPushS: {name: "RPushS", keyword: "rpush_s", args: []OpcodeArg{
// The target register.
OpcodeArgRegister,
}},
// RPushB reads a boolean value from the target register and pushes it into stack.
RPushB: {name: "RPushB", keyword: "rpush_b", args: []OpcodeArg{
// The target register.
OpcodeArgRegister,
}},
// RPushI reads an integer value from the target register and pushes it into stack.
RPushI: {name: "RPushI", keyword: "rpush_i", args: []OpcodeArg{
// The target register.
OpcodeArgRegister,
}},
// RPushD reads a double value from the target register and pushes it into stack.
RPushD: {name: "RPushD", keyword: "rpush_d", args: []OpcodeArg{
// The target register.
OpcodeArgRegister,
}},
// EqS pops two string values from the stack and compare for equality. If the strings are
// equal then it pushes 1 into the stack, otherwise it pushes 0.
EqS: {name: "EqS", keyword: "eq_s"},
// EqB pops two bool values from the stack and compare for equality. If the bools are
// equal then it pushes 1 into the stack, otherwise it pushes 0.
EqB: {name: "EqB", keyword: "eq_b"},
// EqI pops two integer values from the stack and compare for equality. If the integers are
// equal then it pushes 1 into the stack, otherwise it pushes 0.
EqI: {name: "EqI", keyword: "eq_i"},
// EqD pops two double values from the stack and compare for equality. If the doubles are
// equal then it pushes 1 into the stack, otherwise it pushes 0.
EqD: {name: "EqD", keyword: "eq_d"},
// AEqS pops a string value from the stack and compare it against its argument for equality.
// If equal, then it pushes 1 into the stack, otherwise it pushes 0.
AEqS: {name: "AEqS", keyword: "aeq_s", args: []OpcodeArg{
// The string value for comparison.
OpcodeArgString,
}},
// AEqB pops a bool value from the stack and compare it against its argument for equality.
// If equal, then it pushes 1 into the stack, otherwise it pushes 0.
AEqB: {name: "AEqB", keyword: "aeq_b", args: []OpcodeArg{
// The bool value for comparison.
OpcodeArgBool,
}},
// AEqI pops an integer value from the stack and compare it against its argument for equality.
// If equal, then it pushes 1 into the stack, otherwise it pushes 0.
AEqI: {name: "AEqI", keyword: "aeq_i", args: []OpcodeArg{
// The integer value for comparison.
OpcodeArgInt,
}},
// AEqD pops a double value from the stack and compare it against its argument for equality.
// If equal, then it pushes 1 into the stack, otherwise it pushes 0.
AEqD: {name: "AEqD", keyword: "aeq_d", args: []OpcodeArg{
// The double value for comparison.
OpcodeArgDouble,
}},
// Xor pops two boolean values from the stack, performs logical exclusive-or, then pushes the
// result back into stack.
Xor: {name: "Xor", keyword: "xor"},
// And pops two boolean values from the stack, performs logical and, then pushes the
// result back into stack.
And: {name: "And", keyword: "and"},
// Or pops two boolean values from the stack, performs logical or, then pushes the
// result back into stack.
Or: {name: "Or", keyword: "or"},
// AXor pops a boolean value from the stack and performs logical exclusive-or with its
// argument, then pushes the result back into stack.
AXor: {name: "AXor", keyword: "axor", args: []OpcodeArg{
// The boolean value to xor.
OpcodeArgBool,
}},
// AAnd pops a boolean value from the stack and performs logical and with its
// argument, then pushes the result back into stack.
AAnd: {name: "AAnd", keyword: "aand", args: []OpcodeArg{
// The boolean value to and.
OpcodeArgBool,
}},
// AOr pops a boolean value from the stack and performs logical or with its
// argument, then pushes the result back into stack.
AOr: {name: "AOr", keyword: "aor", args: []OpcodeArg{
// The boolean value to or.
OpcodeArgBool,
}},
// Not pops a boolean value from the stack and performs logical not,
// then pushes the result back into stack.
Not: {name: "Not", keyword: "not"},
// ResolveS lookups up a string attribute value in the bag, with the given name.
// If successful, pushes the resolved string into stack, otherwise raises error.
ResolveS: {name: "ResolveS", keyword: "resolve_s", args: []OpcodeArg{
// The name of the attribute.
OpcodeArgString,
}},
// ResolveB lookups up a bool attribute value in the bag, with the given name.
// If successful, pushes the resolved bool into stack, otherwise raises error.
ResolveB: {name: "ResolveB", keyword: "resolve_b", args: []OpcodeArg{
// The name of the attribute.
OpcodeArgString,
}},
// ResolveI lookups up an integer attribute value in the bag, with the given name.
// If successful, pushes the resolved integer into stack, otherwise raises error.
ResolveI: {name: "ResolveI", keyword: "resolve_i", args: []OpcodeArg{
// The name of the attribute.
OpcodeArgString,
}},
// ResolveD lookups up a double attribute value in the bag, with the given name.
// If successful, pushes the resolved double into stack, otherwise raises error.
ResolveD: {name: "ResolveD", keyword: "resolve_d", args: []OpcodeArg{
// The name of the attribute.
OpcodeArgString,
}},
// ResolveF lookups up an interface attribute value in the bag, with the given name.
// If successful, pushes the resolved interface{} into stack, otherwise raises error.
ResolveF: {name: "ResolveF", keyword: "resolve_f", args: []OpcodeArg{
// The name of the attribute.
OpcodeArgString,
}},
// TResolveS lookups up a string attribute value in the bag, with the given name.
// If successful, pushes the resolved string value, then 1 into the stack,
// otherwise pushes 0.
TResolveS: {name: "TResolveS", keyword: "tresolve_s", args: []OpcodeArg{
// The name of the attribute.
OpcodeArgString,
}},
// TResolveB lookups up a ool attribute value in the bag, with the given name.
// If successful, pushes the resolved bool value, then 1 into the stack,
// otherwise pushes 0.
TResolveB: {name: "TResolveB", keyword: "tresolve_b", args: []OpcodeArg{
// The name of the attribute.
OpcodeArgString,
}},
// TResolveI lookups up an integer attribute value in the bag, with the given name.
// If successful, pushes the resolved integer value, then 1 into the stack,
// otherwise pushes 0.
TResolveI: {name: "TResolveI", keyword: "tresolve_i", args: []OpcodeArg{
// The name of the attribute.
OpcodeArgString,
}},
// TResolveD lookups up a double attribute value in the bag, with the given name.
// If successful, pushes the resolved double value, then 1 into the stack,
// otherwise pushes 0.
TResolveD: {name: "TResolveD", keyword: "tresolve_d", args: []OpcodeArg{
// The name of the attribute.
OpcodeArgString,
}},
// TResolveF lookups up a interface{} attribute value in the bag, with the given name.
// If successful, pushes the resolved interface{] value, then 1 into the stack,
// otherwise pushes 0.
TResolveF: {name: "TResolveF", keyword: "tresolve_f", args: []OpcodeArg{
// The name of the attribute.
OpcodeArgString,
}},
// AddI pops two integer values from the stack, adds their value and pushes the result
// back into stack. The operation follows Go's integer addition semantics.
AddI: {name: "AddI", keyword: "add_i"},
// AddD pops two double values from the stack, adds their value and pushes the result
// back into stack. The operation follows Go's float addition semantics.
AddD: {name: "AddD", keyword: "add_d"},
// SubI pops two integer values from the stack, and subtracts the second popped value
// from the first one, then pushes the result back into stack.
// The operation follows Go's integer subtraction semantics.
SubI: {name: "SubI", keyword: "sub_i"},
// SubD pops two double values from the stack, and subtracts the second popped value
// from the first one, then pushes the result back into stack.
// The operation follows Go's float subtraction semantics.
SubD: {name: "SubD", keyword: "sub_d"},
// AAddI pops an integer value from the stack, adds the popped value and its argument,
// and pushes the result back into stack. The operation follows Go's integer addition
// semantics.
AAddI: {name: "AAddI", keyword: "aadd_i", args: []OpcodeArg{
// Value to add
OpcodeArgInt,
}},
// AAddD pops a double value from the stack, adds the popped value and its argument,
// and pushes the result back into stack. The operation follows Go's double addition
// semantics.
AAddD: {name: "AAddD", keyword: "aadd_d", args: []OpcodeArg{
// Value to add
OpcodeArgDouble,
}},
// ASubI pops an integer value from the stack, subtracts its argument from the popped value,
// then pushes the result back into stack. The operation follows Go's integer subtraction
// semantics.
ASubI: {name: "ASubI", keyword: "asub_i", args: []OpcodeArg{
// Value to subtract
OpcodeArgInt,
}},
// ASubD pops a double value from the stack, subtracts its argument from the popped value,
// then pushes the result back into stack. The operation follows Go's double subtraction
// semantics.
ASubD: {name: "ASubD", keyword: "asub_d", args: []OpcodeArg{
// Value to subtract
OpcodeArgDouble,
}},
// Jmp jumps to the given instruction address.
Jmp: {name: "Jmp", keyword: "jmp", args: []OpcodeArg{
// The address to jump to.
OpcodeArgAddress,
}},
// Jz pops a bool value from the stack. If the value is 0, then jumps to the given
// instruction address.
Jz: {name: "Jz", keyword: "jz", args: []OpcodeArg{
// The address to jump to.
OpcodeArgAddress,
}},
// Jnz pops a bool value from the stack. If the value is not 0, then jumps to the given
// instruction address.
Jnz: {name: "Jnz", keyword: "jnz", args: []OpcodeArg{
// The address to jump to.
OpcodeArgAddress,
}},
// Call invokes the target function.
Call: {name: "Call", keyword: "call", args: []OpcodeArg{
// The name of the target function.
OpcodeArgFunction,
}},
// Ret returns from the current function.
Ret: {name: "Ret", keyword: "ret"},
// Lookup pops a string, then a stringmap from the stack and perform a lookup on the stringmap
// using the string as the name. If a value is found, then the value is pushed into the
// stack. Otherwise raises an error.
Lookup: {name: "Lookup", keyword: "lookup"},
// NLookup pops a string, then a stringmap from the stack and perform a lookup on the stringmap
// using the string as the name. If a value is found, then the value is pushed into the
// stack. Otherwise empty string is pushed ono the stack.
NLookup: {name: "NLookup", keyword: "nlookup"},
// TLookup pops a string, then a stringmap from the stack and perform a lookup on the stringmap
// using the string as the name. If a value is found, then the value is pushed into the
// stack, then 1. Otherwise 0 is pushed to into the stack.
TLookup: {name: "TLookup", keyword: "tlookup"},
// ALookup pops a stringmap from the stack and perform a lookup on the stringmap using the string
// parameter as the name. If a value is found, then the value is pushed into the stack
// Otherwise raises an error.
ALookup: {name: "ALookup", keyword: "alookup", args: []OpcodeArg{
// The name of the attribute.
OpcodeArgString,
}},
// ANLookup pops a stringmap from the stack and perform a lookup on the stringmap using the string
// parameter as the name. If a value is found, then the value is pushed into the stack
// Otherwise empty string is pushed onto the stack.
ANLookup: {name: "ANLookup", keyword: "anlookup", args: []OpcodeArg{
// The name of the attribute.
OpcodeArgString,
}},
}
var opcodesByKeyword = func() map[string]Opcode {
r := make(map[string]Opcode)
for o, i := range opCodeInfos {
r[i.keyword] = o
}
return r
}()
// GetOpcode finds and returns the opcode that matches the keyword text that is supplied.
func GetOpcode(text string) (Opcode, bool) {
o, f := opcodesByKeyword[text]
return o, f
}
func (o Opcode) String() string {
return opCodeInfos[o].name
}
// Size returns the total size the instruction and its arguments occupy, in uint32s.
func (o Opcode) Size() uint32 {
var s uint32 = 1
for _, a := range opCodeInfos[o].args {
s += a.Size()
}
return s
}
// Keyword returns the keyword corresponding to the opcode.
func (o Opcode) Keyword() string {
return opCodeInfos[o].keyword
}
// Args return the metadata about the arguments to the opcode.
func (o Opcode) Args() []OpcodeArg {
return opCodeInfos[o].args
}
// Size returns the number of uint32 byte codes that the argument occupies.
func (o OpcodeArg) Size() uint32 {
return argSizes[o]
}