generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathOpcodes.h
3699 lines (3683 loc) · 140 KB
/
Opcodes.h
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
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: set ts=8 sw=2 et tw=0 ft=c:
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef vm_Opcodes_h
#define vm_Opcodes_h
#include <stddef.h>
#include <stdint.h>
#include "js/TypeDecls.h"
// clang-format off
/*
* [SMDOC] Bytecode Definitions
*
* SpiderMonkey bytecode instructions.
*
* To use this header, define a macro of the form:
*
* #define MACRO(op, op_snake, token, length, nuses, ndefs, format) ...
*
* Then `FOR_EACH_OPCODE(MACRO)` invokes `MACRO` for every opcode.
*
* Field Description
* ----- -----------
* op UpperCamelCase form of opcode id
* op_snake snake_case form of opcode id
* token Pretty-printer string, or null if ugly
* length Number of bytes including any immediate operands
* nuses Number of stack slots consumed by bytecode, -1 if variadic
* ndefs Number of stack slots produced by bytecode
* format JOF_ flags describing instruction operand layout, etc.
*
* For more about `format`, see the comments on the `JOF_` constants defined in
* BytecodeUtil.h.
*
*
* [SMDOC] Bytecode Invariants
*
* Creating scripts that do not follow the rules can lead to undefined
* behavior. Bytecode has many consumers, not just the interpreter: JITs,
* analyses, the debugger. That's why the rules below apply even to code that
* can't be reached in ordinary execution (such as code after an infinite loop
* or inside an `if (false)` block).
*
* The `code()` of a script must be a packed (not aligned) sequence of valid
* instructions from start to end. Each instruction has a single byte opcode
* followed by a number of operand bytes based on the opcode.
*
* ## Jump instructions
*
* Operands named `offset`, `forwardOffset`, or `defaultOffset` are jump
* offsets, the distance in bytes from the start of the current instruction to
* the start of another instruction in the same script. Operands named
* `forwardOffset` or `defaultOffset` must be positive.
*
* Forward jumps must jump to a `JSOp::JumpTarget` instruction. Backward jumps,
* indicated by negative offsets, must jump to a `JSOp::LoopHead` instruction.
* Jump offsets can't be zero.
*
* Needless to say, scripts must not contain overlapping instruction sequences
* (in the sense of <https://en.wikipedia.org/wiki/Overlapping_gene>).
*
* A script's `trynotes` and `scopeNotes` impose further constraints. Each try
* note and each scope note marks a region of the bytecode where some invariant
* holds, or some cleanup behavior is needed--that there's a for-in iterator in
* a particular stack slot, for instance, which must be closed on error. All
* paths into the span must establish that invariant. In practice, this means
* other code never jumps into the span: the only way in is to execute the
* bytecode instruction that sets up the invariant (in our example,
* `JSOp::Iter`).
*
* If a script's `trynotes` (see "Try Notes" in JSScript.h) contain a
* `JSTRY_CATCH` or `JSTRY_FINALLY` span, there must be a `JSOp::Try`
* instruction immediately before the span and a `JSOp::JumpTarget immediately
* after it. Instructions must not jump to this `JSOp::JumpTarget`. (The VM puts
* us there on exception.) Furthermore, the instruction sequence immediately
* following a `JSTRY_CATCH` span must read `JumpTarget; Exception` or, in
* non-function scripts, `JumpTarget; Undefined; SetRval; Exception`. (These
* instructions run with an exception pending; other instructions aren't
* designed to handle that.)
*
* Unreachable instructions are allowed, but they have to follow all the rules.
*
* Control must not reach the end of a script. (Currently, the last instruction
* is always JSOp::RetRval.)
*
* ## Other operands
*
* Operands named `nameIndex` or `atomIndex` (which appear on instructions that
* have `JOF_ATOM` in the `format` field) must be valid indexes into
* `script->atoms()`.
*
* Operands named `argc` (`JOF_ARGC`) are argument counts for call
* instructions. `argc` must be small enough that the instruction's nuses is <=
* the current stack depth (see "Stack depth" below).
*
* Operands named `argno` (`JOF_QARG`) refer to an argument of the current
* function. `argno` must be in the range `0..script->function()->nargs()`.
* Instructions with these operands must appear only in function scripts.
*
* Operands named `localno` (`JOF_LOCAL`) refer to a local variable stored in
* the stack frame. `localno` must be in the range `0..script->nfixed()`.
*
* Operands named `resumeIndex` (`JOF_RESUMEINDEX`) refer to a resume point in
* the current script. `resumeIndex` must be a valid index into
* `script->resumeOffsets()`.
*
* Operands named `hops` and `slot` (`JOF_ENVCOORD`) refer a slot in an
* `EnvironmentObject`. At run time, they must point to a fixed slot in an
* object on the current environment chain. See `EnvironmentCoordinates`.
*
* Operands with the following names must be valid indexes into
* `script->gcthings()`, and the pointer in the vector must point to the right
* type of thing:
*
* - `objectIndex` (`JOF_OBJECT`): `PlainObject*` or `ArrayObject*`
* - `baseobjIndex` (`JOF_OBJECT`): `PlainObject*`
* - `funcIndex` (`JOF_OBJECT`): `JSFunction*`
* - `regexpIndex` (`JOF_REGEXP`): `RegExpObject*`
* - `shapeIndex` (`JOF_SHAPE`): `Shape*`
* - `scopeIndex` (`JOF_SCOPE`): `Scope*`
* - `lexicalScopeIndex` (`JOF_SCOPE`): `LexicalScope*`
* - `classBodyScopeIndex` (`JOF_SCOPE`): `ClassBodyScope*`
* - `withScopeIndex` (`JOF_SCOPE`): `WithScope*`
* - `bigIntIndex` (`JOF_BIGINT`): `BigInt*`
*
* Operands named `icIndex` (`JOF_ICINDEX`) must be exactly the number of
* preceding instructions in the script that have the JOF_IC flag.
* (Rationale: Each JOF_IC instruction has a unique entry in
* `script->jitScript()->icEntries()`. At run time, in the bytecode
* interpreter, we have to find that entry. We could store the IC index as an
* operand to each JOF_IC instruction, but it's more memory-efficient to use a
* counter and reset the counter to `icIndex` after each jump.)
*
* ## Stack depth
*
* Each instruction has a compile-time stack depth, the number of values on the
* interpreter stack just before executing the instruction. It isn't explicitly
* present in the bytecode itself, but (for reachable instructions, anyway)
* it's a function of the bytecode.
*
* - The first instruction has stack depth 0.
*
* - Each successor of an instruction X has a stack depth equal to
*
* X's stack depth - `js::StackUses(X)` + `js::StackDefs(X)`
*
* except for `JSOp::Case` (below).
*
* X's "successors" are: the next instruction in the script, if
* `js::FlowsIntoNext(op)` is true for X's opcode; one or more
* `JSOp::JumpTarget`s elsewhere, if X is a forward jump or
* `JSOp::TableSwitch`; and/or a `JSOp::LoopHead` if it's a backward jump.
*
* - `JSOp::Case` is a special case because its stack behavior is eccentric.
* The formula above is correct for the next instruction. The jump target
* has a stack depth that is 1 less.
*
* - The `JSOp::JumpTarget` instruction immediately following a `JSTRY_CATCH`
* or `JSTRY_FINALLY` span has the same stack depth as the `JSOp::Try`
* instruction that precedes the span.
*
* Every instruction covered by the `JSTRY_CATCH` or `JSTRY_FINALLY` span
* must have a stack depth >= that value, so that error recovery is
* guaranteed to find enough values on the stack to resume there.
*
* - `script->nslots() - script->nfixed()` must be >= the maximum stack
* depth of any instruction in `script`. (The stack frame must be big
* enough to run the code.)
*
* `BytecodeParser::parse()` computes stack depths for every reachable
* instruction in a script.
*
* ## Scopes and environments
*
* As with stack depth, each instruction has a static scope, which is a
* compile-time characterization of the eventual run-time environment chain
* when that instruction executes. Just as every instruction has a stack budget
* (nuses/ndefs), every instruction either pushes a scope, pops a scope, or
* neither. The same successor relation applies as above.
*
* Every scope used in a script is stored in the `JSScript::gcthings()` vector.
* They can be accessed using `getScope(index)` if you know what `index` to
* pass.
*
* The scope of every instruction (that's reachable via the successor relation)
* is given in two independent ways: by the bytecode itself and by the scope
* notes. The two sources must agree.
*
* ## Further rules
*
* All reachable instructions must be reachable without taking any backward
* edges.
*
* Instructions with the `JOF_CHECKSLOPPY` flag must not be used in strict mode
* code. `JOF_CHECKSTRICT` instructions must not be used in nonstrict code.
*
* Many instructions have their own additional rules. These are documented on
* the various opcodes below (look for the word "must").
*/
// clang-format on
// clang-format off
/*
* SpiderMonkey bytecode categorization (as used in generated documentation):
*
* [Index]
* [Constants]
* [Compound primitives]
* Record literals
* Tuple literals
* [Expressions]
* Unary operators
* Binary operators
* Conversions
* Other expressions
* [Objects]
* Creating objects
* Defining properties
* Accessing properties
* Super
* Enumeration
* Iteration
* SetPrototype
* Array literals
* RegExp literals
* Built-in objects
* [Functions]
* Creating functions
* Creating constructors
* Calls
* Generators and async functions
* [Control flow]
* Jump targets
* Jumps
* Return
* Exceptions
* [Variables and scopes]
* Initialization
* Looking up bindings
* Getting binding values
* Setting binding values
* Entering and leaving environments
* Creating and deleting bindings
* Function environment setup
* [Stack operations]
* [Other]
*/
// clang-format on
// clang-format off
#define FOR_EACH_OPCODE(MACRO) \
/*
* Push `undefined`.
*
* Category: Constants
* Operands:
* Stack: => undefined
*/ \
MACRO(Undefined, undefined, "", 1, 0, 1, JOF_BYTE) \
/*
* Push `null`.
*
* Category: Constants
* Operands:
* Stack: => null
*/ \
MACRO(Null, null, "null", 1, 0, 1, JOF_BYTE) \
/*
* Push a boolean constant.
*
* Category: Constants
* Operands:
* Stack: => true/false
*/ \
MACRO(False, false_, "false", 1, 0, 1, JOF_BYTE) \
MACRO(True, true_, "true", 1, 0, 1, JOF_BYTE) \
/*
* Push the `int32_t` immediate operand as an `Int32Value`.
*
* `JSOp::Zero`, `JSOp::One`, `JSOp::Int8`, `JSOp::Uint16`, and `JSOp::Uint24`
* are all compact encodings for `JSOp::Int32`.
*
* Category: Constants
* Operands: int32_t val
* Stack: => val
*/ \
MACRO(Int32, int32, NULL, 5, 0, 1, JOF_INT32) \
/*
* Push the number `0`.
*
* Category: Constants
* Operands:
* Stack: => 0
*/ \
MACRO(Zero, zero, "0", 1, 0, 1, JOF_BYTE) \
/*
* Push the number `1`.
*
* Category: Constants
* Operands:
* Stack: => 1
*/ \
MACRO(One, one, "1", 1, 0, 1, JOF_BYTE) \
/*
* Push the `int8_t` immediate operand as an `Int32Value`.
*
* Category: Constants
* Operands: int8_t val
* Stack: => val
*/ \
MACRO(Int8, int8, NULL, 2, 0, 1, JOF_INT8) \
/*
* Push the `uint16_t` immediate operand as an `Int32Value`.
*
* Category: Constants
* Operands: uint16_t val
* Stack: => val
*/ \
MACRO(Uint16, uint16, NULL, 3, 0, 1, JOF_UINT16) \
/*
* Push the `uint24_t` immediate operand as an `Int32Value`.
*
* Category: Constants
* Operands: uint24_t val
* Stack: => val
*/ \
MACRO(Uint24, uint24, NULL, 4, 0, 1, JOF_UINT24) \
/*
* Push the 64-bit floating-point immediate operand as a `DoubleValue`.
*
* If the operand is a NaN, it must be the canonical NaN (see
* `JS::detail::CanonicalizeNaN`).
*
* Category: Constants
* Operands: double val
* Stack: => val
*/ \
MACRO(Double, double_, NULL, 9, 0, 1, JOF_DOUBLE) \
/*
* Push the BigInt constant `script->getBigInt(bigIntIndex)`.
*
* Category: Constants
* Operands: uint32_t bigIntIndex
* Stack: => bigint
*/ \
MACRO(BigInt, big_int, NULL, 5, 0, 1, JOF_BIGINT) \
/*
* Push the string constant `script->getAtom(atomIndex)`.
*
* Category: Constants
* Operands: uint32_t atomIndex
* Stack: => string
*/ \
MACRO(String, string, NULL, 5, 0, 1, JOF_STRING) \
/*
* Push a well-known symbol.
*
* `symbol` must be in range for `JS::SymbolCode`.
*
* Category: Constants
* Operands: uint8_t symbol (the JS::SymbolCode of the symbol to use)
* Stack: => symbol
*/ \
MACRO(Symbol, symbol, NULL, 2, 0, 1, JOF_UINT8) \
/*
* Pop the top value on the stack, discard it, and push `undefined`.
*
* Implements: [The `void` operator][1], step 3.
*
* [1]: https://tc39.es/ecma262/#sec-void-operator
*
* Category: Expressions
* Type: Unary operators
* Operands:
* Stack: val => undefined
*/ \
MACRO(Void, void_, NULL, 1, 1, 1, JOF_BYTE) \
/*
* [The `typeof` operator][1].
*
* Infallible. The result is always a string that depends on the [type][2]
* of `val`.
*
* `JSOp::Typeof` and `JSOp::TypeofExpr` are the same except
* that--amazingly--`JSOp::Typeof` affects the behavior of an immediately
* *preceding* `JSOp::GetName` or `JSOp::GetGName` instruction! This is how
* we implement [`typeof`][1] step 2, making `typeof nonExistingVariable`
* return `"undefined"` instead of throwing a ReferenceError.
*
* In a global scope:
*
* - `typeof x` compiles to `GetGName "x"; Typeof`.
* - `typeof (0, x)` compiles to `GetGName "x"; TypeofExpr`.
*
* Emitting the same bytecode for these two expressions would be a bug.
* Per spec, the latter throws a ReferenceError if `x` doesn't exist.
*
* [1]: https://tc39.es/ecma262/#sec-typeof-operator
* [2]: https://tc39.es/ecma262/#sec-ecmascript-language-types
*
* Category: Expressions
* Type: Unary operators
* Operands:
* Stack: val => (typeof val)
*/ \
MACRO(Typeof, typeof_, NULL, 1, 1, 1, JOF_BYTE|JOF_IC) \
MACRO(TypeofExpr, typeof_expr, NULL, 1, 1, 1, JOF_BYTE|JOF_IC) \
/*
* [The unary `+` operator][1].
*
* `+val` doesn't do any actual math. It just calls [ToNumber][2](val).
*
* The conversion can call `.toString()`/`.valueOf()` methods and can
* throw. The result on success is always a Number. (Per spec, unary `-`
* supports BigInts, but unary `+` does not.)
*
* [1]: https://tc39.es/ecma262/#sec-unary-plus-operator
* [2]: https://tc39.es/ecma262/#sec-tonumber
*
* Category: Expressions
* Type: Unary operators
* Operands:
* Stack: val => (+val)
*/ \
MACRO(Pos, pos, "+ ", 1, 1, 1, JOF_BYTE|JOF_IC) \
/*
* [The unary `-` operator][1].
*
* Convert `val` to a numeric value, then push `-val`. The conversion can
* call `.toString()`/`.valueOf()` methods and can throw. The result on
* success is always numeric.
*
* [1]: https://tc39.es/ecma262/#sec-unary-minus-operator
*
* Category: Expressions
* Type: Unary operators
* Operands:
* Stack: val => (-val)
*/ \
MACRO(Neg, neg, "- ", 1, 1, 1, JOF_BYTE|JOF_IC) \
/*
* [The bitwise NOT operator][1] (`~`).
*
* `val` is converted to an integer, then bitwise negated. The conversion
* can call `.toString()`/`.valueOf()` methods and can throw. The result on
* success is always an Int32 or BigInt value.
*
* [1]: https://tc39.es/ecma262/#sec-bitwise-not-operator
*
* Category: Expressions
* Type: Unary operators
* Operands:
* Stack: val => (~val)
*/ \
MACRO(BitNot, bit_not, "~", 1, 1, 1, JOF_BYTE|JOF_IC) \
/*
* [The logical NOT operator][1] (`!`).
*
* `val` is first converted with [ToBoolean][2], then logically
* negated. The result is always a boolean value. This does not call
* user-defined methods and can't throw.
*
* [1]: https://tc39.es/ecma262/#sec-logical-not-operator
* [2]: https://tc39.es/ecma262/#sec-toboolean
*
* Category: Expressions
* Type: Unary operators
* Operands:
* Stack: val => (!val)
*/ \
MACRO(Not, not_, "!", 1, 1, 1, JOF_BYTE|JOF_IC) \
/*
* [Binary bitwise operations][1] (`|`, `^`, `&`).
*
* The arguments are converted to integers first. The conversion can call
* `.toString()`/`.valueOf()` methods and can throw. The result on success
* is always an Int32 or BigInt Value.
*
* [1]: https://tc39.es/ecma262/#sec-binary-bitwise-operators
*
* Category: Expressions
* Type: Binary operators
* Operands:
* Stack: lval, rval => (lval OP rval)
*/ \
MACRO(BitOr, bit_or, "|", 1, 2, 1, JOF_BYTE|JOF_IC) \
MACRO(BitXor, bit_xor, "^", 1, 2, 1, JOF_BYTE|JOF_IC) \
MACRO(BitAnd, bit_and, "&", 1, 2, 1, JOF_BYTE|JOF_IC) \
/*
* Loose equality operators (`==` and `!=`).
*
* Pop two values, compare them, and push the boolean result. The
* comparison may perform conversions that call `.toString()`/`.valueOf()`
* methods and can throw.
*
* Implements: [Abstract Equality Comparison][1].
*
* [1]: https://tc39.es/ecma262/#sec-abstract-equality-comparison
*
* Category: Expressions
* Type: Binary operators
* Operands:
* Stack: lval, rval => (lval OP rval)
*/ \
MACRO(Eq, eq, "==", 1, 2, 1, JOF_BYTE|JOF_IC) \
MACRO(Ne, ne, "!=", 1, 2, 1, JOF_BYTE|JOF_IC) \
/*
* Strict equality operators (`===` and `!==`).
*
* Pop two values, check whether they're equal, and push the boolean
* result. This does not call user-defined methods and can't throw
* (except possibly due to OOM while flattening a string).
*
* Implements: [Strict Equality Comparison][1].
*
* [1]: https://tc39.es/ecma262/#sec-strict-equality-comparison
*
* Category: Expressions
* Type: Binary operators
* Operands:
* Stack: lval, rval => (lval OP rval)
*/ \
MACRO(StrictEq, strict_eq, "===", 1, 2, 1, JOF_BYTE|JOF_IC) \
MACRO(StrictNe, strict_ne, "!==", 1, 2, 1, JOF_BYTE|JOF_IC) \
/*
* Relative operators (`<`, `>`, `<=`, `>=`).
*
* Pop two values, compare them, and push the boolean result. The
* comparison may perform conversions that call `.toString()`/`.valueOf()`
* methods and can throw.
*
* Implements: [Relational Operators: Evaluation][1].
*
* [1]: https://tc39.es/ecma262/#sec-relational-operators-runtime-semantics-evaluation
*
* Category: Expressions
* Type: Binary operators
* Operands:
* Stack: lval, rval => (lval OP rval)
*/ \
MACRO(Lt, lt, "<", 1, 2, 1, JOF_BYTE|JOF_IC) \
MACRO(Gt, gt, ">", 1, 2, 1, JOF_BYTE|JOF_IC) \
MACRO(Le, le, "<=", 1, 2, 1, JOF_BYTE|JOF_IC) \
MACRO(Ge, ge, ">=", 1, 2, 1, JOF_BYTE|JOF_IC) \
/*
* [The `instanceof` operator][1].
*
* This throws a `TypeError` if `target` is not an object. It calls
* `target[Symbol.hasInstance](value)` if the method exists. On success,
* the result is always a boolean value.
*
* [1]: https://tc39.es/ecma262/#sec-instanceofoperator
*
* Category: Expressions
* Type: Binary operators
* Operands:
* Stack: value, target => (value instanceof target)
*/ \
MACRO(Instanceof, instanceof, "instanceof", 1, 2, 1, JOF_BYTE|JOF_IC) \
/*
* [The `in` operator][1].
*
* Push `true` if `obj` has a property with the key `id`. Otherwise push `false`.
*
* This throws a `TypeError` if `obj` is not an object. This can fire
* proxy hooks and can throw. On success, the result is always a boolean
* value.
*
* [1]: https://tc39.es/ecma262/#sec-relational-operators-runtime-semantics-evaluation
*
* Category: Expressions
* Type: Binary operators
* Operands:
* Stack: id, obj => (id in obj)
*/ \
MACRO(In, in_, "in", 1, 2, 1, JOF_BYTE|JOF_IC) \
/*
* [Bitwise shift operators][1] (`<<`, `>>`, `>>>`).
*
* Pop two values, convert them to integers, perform a bitwise shift, and
* push the result.
*
* Conversion can call `.toString()`/`.valueOf()` methods and can throw.
* The result on success is always an Int32 or BigInt Value.
*
* [1]: https://tc39.es/ecma262/#sec-bitwise-shift-operators
*
* Category: Expressions
* Type: Binary operators
* Operands:
* Stack: lval, rval => (lval OP rval)
*/ \
MACRO(Lsh, lsh, "<<", 1, 2, 1, JOF_BYTE|JOF_IC) \
MACRO(Rsh, rsh, ">>", 1, 2, 1, JOF_BYTE|JOF_IC) \
MACRO(Ursh, ursh, ">>>", 1, 2, 1, JOF_BYTE|JOF_IC) \
/*
* [The binary `+` operator][1].
*
* Pop two values, convert them to primitive values, add them, and push the
* result. If both values are numeric, add them; if either is a
* string, do string concatenation instead.
*
* The conversion can call `.toString()`/`.valueOf()` methods and can throw.
*
* [1]: https://tc39.es/ecma262/#sec-addition-operator-plus-runtime-semantics-evaluation
*
* Category: Expressions
* Type: Binary operators
* Operands:
* Stack: lval, rval => (lval + rval)
*/ \
MACRO(Add, add, "+", 1, 2, 1, JOF_BYTE|JOF_IC) \
/*
* [The binary `-` operator][1].
*
* Pop two values, convert them to numeric values, subtract the top value
* from the other one, and push the result.
*
* The conversion can call `.toString()`/`.valueOf()` methods and can
* throw. On success, the result is always numeric.
*
* [1]: https://tc39.es/ecma262/#sec-subtraction-operator-minus-runtime-semantics-evaluation
*
* Category: Expressions
* Type: Binary operators
* Operands:
* Stack: lval, rval => (lval - rval)
*/ \
MACRO(Sub, sub, "-", 1, 2, 1, JOF_BYTE|JOF_IC) \
/*
* Add or subtract 1.
*
* `val` must already be a numeric value, such as the result of
* `JSOp::ToNumeric`.
*
* Implements: [The `++` and `--` operators][1], step 3 of each algorithm.
*
* [1]: https://tc39.es/ecma262/#sec-postfix-increment-operator
*
* Category: Expressions
* Type: Binary operators
* Operands:
* Stack: val => (val +/- 1)
*/ \
MACRO(Inc, inc, NULL, 1, 1, 1, JOF_BYTE|JOF_IC) \
MACRO(Dec, dec, NULL, 1, 1, 1, JOF_BYTE|JOF_IC) \
/*
* [The multiplicative operators][1] (`*`, `/`, `%`).
*
* Pop two values, convert them to numeric values, do math, and push the
* result.
*
* The conversion can call `.toString()`/`.valueOf()` methods and can
* throw. On success, the result is always numeric.
*
* [1]: https://tc39.es/ecma262/#sec-multiplicative-operators-runtime-semantics-evaluation
*
* Category: Expressions
* Type: Binary operators
* Operands:
* Stack: lval, rval => (lval OP rval)
*/ \
MACRO(Mul, mul, "*", 1, 2, 1, JOF_BYTE|JOF_IC) \
MACRO(Div, div, "/", 1, 2, 1, JOF_BYTE|JOF_IC) \
MACRO(Mod, mod, "%", 1, 2, 1, JOF_BYTE|JOF_IC) \
/*
* [The exponentiation operator][1] (`**`).
*
* Pop two values, convert them to numeric values, do exponentiation, and
* push the result. The top value is the exponent.
*
* The conversion can call `.toString()`/`.valueOf()` methods and can
* throw. This throws a RangeError if both values are BigInts and the
* exponent is negative.
*
* [1]: https://tc39.es/ecma262/#sec-exp-operator
*
* Category: Expressions
* Type: Binary operators
* Operands:
* Stack: lval, rval => (lval ** rval)
*/ \
MACRO(Pow, pow, "**", 1, 2, 1, JOF_BYTE|JOF_IC) \
/*
* No-op instruction for bytecode decompiler to hint that the previous
* binary operator is compound assignment.
*
* Category: Expressions
* Type: Other expressions
* Operands:
* Stack:
*/ \
MACRO(NopIsAssignOp, nop_is_assign_op, NULL, 1, 0, 0, JOF_BYTE) \
/*
* Convert a value to a property key.
*
* Implements: [ToPropertyKey][1], except that if the result would be the
* string representation of some integer in the range 0..2^31, we push the
* corresponding Int32 value instead. This is because the spec insists that
* array indices are strings, whereas for us they are integers.
*
* This is used for code like `++obj[index]`, which must do both a
* `JSOp::GetElem` and a `JSOp::SetElem` with the same property key. Both
* instructions would convert `index` to a property key for us, but the
* spec says to convert it only once.
*
* The conversion can call `.toString()`/`.valueOf()` methods and can
* throw.
*
* [1]: https://tc39.es/ecma262/#sec-topropertykey
*
* Category: Expressions
* Type: Conversions
* Operands:
* Stack: propertyNameValue => propertyKey
*/ \
MACRO(ToPropertyKey, to_property_key, NULL, 1, 1, 1, JOF_BYTE|JOF_IC) \
/*
* Convert a value to a numeric value (a Number or BigInt).
*
* Implements: [ToNumeric][1](val).
*
* Note: This is used to implement [`++` and `--`][2]. Surprisingly, it's
* not possible to get the right behavior using `JSOp::Add` and `JSOp::Sub`
* alone. For one thing, `JSOp::Add` sometimes does string concatenation,
* while `++` always does numeric addition. More fundamentally, the result
* of evaluating `x--` is ToNumeric(old value of `x`), a value that the
* sequence `GetLocal "x"; One; Sub; SetLocal "x"` does not give us.
*
* [1]: https://tc39.es/ecma262/#sec-tonumeric
* [2]: https://tc39.es/ecma262/#sec-postfix-increment-operator
*
* Category: Expressions
* Type: Conversions
* Operands:
* Stack: val => ToNumeric(val)
*/ \
MACRO(ToNumeric, to_numeric, NULL, 1, 1, 1, JOF_BYTE|JOF_IC) \
/*
* Convert a value to a string.
*
* Implements: [ToString][1](val).
*
* Note: This is used in code for template literals, like `${x}${y}`. Each
* substituted value must be converted using ToString. `JSOp::Add` by itself
* would do a slightly wrong kind of conversion (hint="number" rather than
* hint="string").
*
* [1]: https://tc39.es/ecma262/#sec-tostring
*
* Category: Expressions
* Type: Conversions
* Stack: val => ToString(val)
*/ \
MACRO(ToString, to_string, NULL, 1, 1, 1, JOF_BYTE) \
/*
* Test whether the value on top of the stack is `NullValue` or
* `UndefinedValue` and push the boolean result.
*
* Category: Expressions
* Type: Other expressions
* Operands:
* Stack: val => val, IsNullOrUndefined(val)
*/ \
MACRO(IsNullOrUndefined, is_null_or_undefined, NULL, 1, 1, 2, JOF_BYTE) \
/*
* Push the global `this` value. Not to be confused with the `globalThis`
* property on the global.
*
* This must be used only in scopes where `this` refers to the global
* `this`.
*
* Category: Expressions
* Type: Other expressions
* Operands:
* Stack: => this
*/ \
MACRO(GlobalThis, global_this, NULL, 1, 0, 1, JOF_BYTE) \
/*
* Push the global `this` value for non-syntactic scope. Not to be confused
* with the `globalThis` property on the global.
*
* This must be used only in scopes where `this` refers to the global
* `this`.
*
* Category: Expressions
* Type: Other expressions
* Operands:
* Stack: => this
*/ \
MACRO(NonSyntacticGlobalThis, non_syntactic_global_this, NULL, 1, 0, 1, JOF_BYTE) \
/*
* Push the value of `new.target`.
*
* The result is a constructor or `undefined`.
*
* This must be used only in non-arrow function scripts.
*
* Implements: [GetNewTarget][1].
*
* [1]: https://tc39.es/ecma262/#sec-getnewtarget
*
* Category: Expressions
* Type: Other expressions
* Operands:
* Stack: => new.target
*/ \
MACRO(NewTarget, new_target, NULL, 1, 0, 1, JOF_BYTE) \
/*
* Dynamic import of the module specified by the string value on the top of
* the stack.
*
* Implements: [Import Calls][1].
*
* [1]: https://tc39.es/ecma262/#sec-import-calls
*
* Category: Expressions
* Type: Other expressions
* Operands:
* Stack: moduleId, options => promise
*/ \
MACRO(DynamicImport, dynamic_import, NULL, 1, 2, 1, JOF_BYTE) \
/*
* Push the `import.meta` object.
*
* This must be used only in module code.
*
* Category: Expressions
* Type: Other expressions
* Operands:
* Stack: => import.meta
*/ \
MACRO(ImportMeta, import_meta, NULL, 1, 0, 1, JOF_BYTE) \
/*
* Create and push a new object with no properties.
*
* Category: Objects
* Type: Creating objects
* Operands:
* Stack: => obj
*/ \
MACRO(NewInit, new_init, NULL, 1, 0, 1, JOF_BYTE|JOF_IC) \
/*
* Create and push a new object of a predetermined shape.
*
* The new object has the shape `script->getShape(shapeIndex)`.
* Subsequent `InitProp` instructions must fill in all slots of the new
* object before it is used in any other way.
*
* Category: Objects
* Type: Creating objects
* Operands: uint32_t shapeIndex
* Stack: => obj
*/ \
MACRO(NewObject, new_object, NULL, 5, 0, 1, JOF_SHAPE|JOF_IC) \
/*
* Push a preconstructed object.
*
* Going one step further than `JSOp::NewObject`, this instruction doesn't
* just reuse the shape--it actually pushes the preconstructed object
* `script->getObject(objectIndex)` right onto the stack. The object must
* be a singleton `PlainObject` or `ArrayObject`.
*
* The spec requires that an *ObjectLiteral* or *ArrayLiteral* creates a
* new object every time it's evaluated, so this instruction must not be
* used anywhere it might be executed more than once.
*
* This may only be used in non-function run-once scripts. Care also must
* be taken to not emit in loops or other constructs where it could run
* more than once.
*
* Category: Objects
* Type: Creating objects
* Operands: uint32_t objectIndex
* Stack: => obj
*/ \
MACRO(Object, object, NULL, 5, 0, 1, JOF_OBJECT) \
/*
* Create and push a new ordinary object with the provided [[Prototype]].
*
* This is used to create the `.prototype` object for derived classes.
*
* Category: Objects
* Type: Creating objects
* Operands:
* Stack: proto => obj
*/ \
MACRO(ObjWithProto, obj_with_proto, NULL, 1, 1, 1, JOF_BYTE) \
/*
* Define a data property on an object.
*
* `obj` must be an object.
*
* Implements: [CreateDataPropertyOrThrow][1] as used in
* [PropertyDefinitionEvaluation][2] of regular and shorthand
* *PropertyDefinition*s.
*
* [1]: https://tc39.es/ecma262/#sec-createdatapropertyorthrow
* [2]: https://tc39.es/ecma262/#sec-object-initializer-runtime-semantics-propertydefinitionevaluation
*
* Category: Objects
* Type: Defining properties
* Operands: uint32_t nameIndex
* Stack: obj, val => obj
*/ \
MACRO(InitProp, init_prop, NULL, 5, 2, 1, JOF_ATOM|JOF_PROP|JOF_PROPINIT|JOF_IC) \
/*
* Like `JSOp::InitProp`, but define a non-enumerable property.
*
* This is used to define class methods.
*
* Implements: [PropertyDefinitionEvaluation][1] for methods, steps 3 and
* 4, when *enumerable* is false.
*
* [1]: https://tc39.es/ecma262/#sec-method-definitions-runtime-semantics-propertydefinitionevaluation
*
* Category: Objects
* Type: Defining properties
* Operands: uint32_t nameIndex
* Stack: obj, val => obj
*/ \
MACRO(InitHiddenProp, init_hidden_prop, NULL, 5, 2, 1, JOF_ATOM|JOF_PROP|JOF_PROPINIT|JOF_IC) \
/*
* Like `JSOp::InitProp`, but define a non-enumerable, non-writable,
* non-configurable property.
*
* This is used to define the `.prototype` property on classes.
*
* Implements: [MakeConstructor][1], step 8, when *writablePrototype* is
* false.
*
* [1]: https://tc39.es/ecma262/#sec-makeconstructor
*
* Category: Objects
* Type: Defining properties
* Operands: uint32_t nameIndex
* Stack: obj, val => obj
*/ \
MACRO(InitLockedProp, init_locked_prop, NULL, 5, 2, 1, JOF_ATOM|JOF_PROP|JOF_PROPINIT|JOF_IC) \
/*
* Define a data property on `obj` with property key `id` and value `val`.
*
* `obj` must be an object.
*
* Implements: [CreateDataPropertyOrThrow][1]. This instruction is used for
* object literals like `{0: val}` and `{[id]: val}`, and methods like
* `*[Symbol.iterator]() {}`.
*
* `JSOp::InitHiddenElem` is the same but defines a non-enumerable property,
* for class methods.
* `JSOp::InitLockedElem` is the same but defines a non-enumerable, non-writable, non-configurable property,
* for private class methods.
*
* [1]: https://tc39.es/ecma262/#sec-createdatapropertyorthrow
*
* Category: Objects
* Type: Defining properties
* Operands:
* Stack: obj, id, val => obj
*/ \
MACRO(InitElem, init_elem, NULL, 1, 3, 1, JOF_BYTE|JOF_ELEM|JOF_PROPINIT|JOF_IC) \
MACRO(InitHiddenElem, init_hidden_elem, NULL, 1, 3, 1, JOF_BYTE|JOF_ELEM|JOF_PROPINIT|JOF_IC) \
MACRO(InitLockedElem, init_locked_elem, NULL, 1, 3, 1, JOF_BYTE|JOF_ELEM|JOF_PROPINIT|JOF_IC) \
/*
* Define an accessor property on `obj` with the given `getter`.
* `nameIndex` gives the property name.
*
* `obj` must be an object and `getter` must be a function.
*
* `JSOp::InitHiddenPropGetter` is the same but defines a non-enumerable
* property, for getters in classes.
*
* Category: Objects
* Type: Defining properties
* Operands: uint32_t nameIndex
* Stack: obj, getter => obj
*/ \
MACRO(InitPropGetter, init_prop_getter, NULL, 5, 2, 1, JOF_ATOM|JOF_PROP|JOF_PROPINIT) \
MACRO(InitHiddenPropGetter, init_hidden_prop_getter, NULL, 5, 2, 1, JOF_ATOM|JOF_PROP|JOF_PROPINIT) \
/*
* Define an accessor property on `obj` with property key `id` and the given `getter`.
*
* This is used to implement getters like `get [id]() {}` or `get 0() {}`.
*
* `obj` must be an object and `getter` must be a function.
*
* `JSOp::InitHiddenElemGetter` is the same but defines a non-enumerable
* property, for getters in classes.
*
* Category: Objects
* Type: Defining properties
* Operands:
* Stack: obj, id, getter => obj
*/ \