opcodes.red 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. s!:opcodelist := '(
  2. LOADLOC % general opcode to load from the stack
  3. LOADLOC0 LOADLOC1 LOADLOC2 LOADLOC3 % specific offsets
  4. LOADLOC4 LOADLOC5 LOADLOC6 LOADLOC7
  5. LOADLOC8 LOADLOC9 LOADLOC10 LOADLOC11
  6. % combinations to load two values (especially common cases)
  7. LOC0LOC1 LOC1LOC2 LOC2LOC3
  8. LOC1LOC0 LOC2LOC1 LOC3LOC2
  9. VNIL % load the value NIL
  10. LOADLIT % load a literal from the literal vector
  11. LOADLIT1 LOADLIT2 LOADLIT3 % specific offsets
  12. LOADLIT4 LOADLIT5 LOADLIT6 LOADLIT7
  13. LOADFREE % load value of a free (FLUID/SPECIAL) variable
  14. LOADFREE1 LOADFREE2 LOADFREE3 % specific offsets
  15. LOADFREE4
  16. STORELOC % Store onto stack
  17. STORELOC0 STORELOC1 STORELOC2 STORELOC3 % specific offsets
  18. STORELOC4 STORELOC5 STORELOC6 STORELOC7
  19. STOREFREE % Set value of FLUID/SPECIAL variable
  20. STOREFREE1 STOREFREE2 STOREFREE3
  21. LOADLEX % access to non-local lexical variables (for Common Lisp)
  22. STORELEX
  23. CLOSURE
  24. % Code to access local variables and also take CAR or CDR
  25. CARLOC0 CARLOC1 CARLOC2 CARLOC3
  26. CARLOC4 CARLOC5 CARLOC6 CARLOC7
  27. CARLOC8 CARLOC9 CARLOC10 CARLOC11
  28. CDRLOC0 CDRLOC1 CDRLOC2 CDRLOC3
  29. CDRLOC4 CDRLOC5
  30. CAARLOC0 CAARLOC1 CAARLOC2 CAARLOC3
  31. % Function call support
  32. CALL0 CALL1 CALL2 CALL2R CALL3 CALLN
  33. CALL0_0 CALL0_1 CALL0_2 CALL0_3
  34. CALL1_0 CALL1_1 CALL1_2 CALL1_3 CALL1_4 CALL1_5
  35. CALL2_0 CALL2_1 CALL2_2 CALL2_3 CALL2_4
  36. BUILTIN0 BUILTIN1 BUILTIN2 BUILTIN2R BUILTIN3
  37. APPLY1 APPLY2 APPLY3 APPLY4
  38. JCALL JCALLN
  39. % Branches. The main collection come in variants with long or short
  40. % offsets and with the branch to go fowards or backwards.
  41. JUMP JUMP_B JUMP_L JUMP_BL
  42. JUMPNIL JUMPNIL_B JUMPNIL_L JUMPNIL_BL
  43. JUMPT JUMPT_B JUMPT_L JUMPT_BL
  44. JUMPATOM JUMPATOM_B JUMPATOM_L JUMPATOM_BL
  45. JUMPNATOM JUMPNATOM_B JUMPNATOM_L JUMPNATOM_BL
  46. JUMPEQ JUMPEQ_B JUMPEQ_L JUMPEQ_BL
  47. JUMPNE JUMPNE_B JUMPNE_L JUMPNE_BL
  48. JUMPEQUAL JUMPEQUAL_B JUMPEQUAL_L JUMPEQUAL_BL
  49. JUMPNEQUAL JUMPNEQUAL_B JUMPNEQUAL_L JUMPNEQUAL_BL
  50. % The following jumps go forwards only, and by only short offsets. They
  51. % are provided to support a collection of common special cases
  52. % (a) test local variables for NIL or TRUE
  53. JUMPL0NIL JUMPL0T JUMPL1NIL JUMPL1T
  54. JUMPL2NIL JUMPL2T JUMPL3NIL JUMPL3T
  55. JUMPL4NIL JUMPL4T
  56. % (b) store in a local variable and test for NIL or TRUE
  57. JUMPST0NIL JUMPST0T JUMPST1NIL JUMPST1T
  58. JUMPST2NIL JUMPST2T
  59. % (c) test if local variable is atomic or not
  60. JUMPL0ATOM JUMPL0NATOM JUMPL1ATOM JUMPL1NATOM
  61. JUMPL2ATOM JUMPL2NATOM JUMPL3ATOM JUMPL3NATOM
  62. % (d) test free variable for NIL or TRUE
  63. JUMPFREE1NIL JUMPFREE1T JUMPFREE2NIL JUMPFREE2T
  64. JUMPFREE3NIL JUMPFREE3T JUMPFREE4NIL JUMPFREE4T
  65. JUMPFREENIL JUMPFREET
  66. % (e) test for equality (EQ) against literal value
  67. JUMPLIT1EQ JUMPLIT1NE JUMPLIT2EQ JUMPLIT2NE
  68. JUMPLIT3EQ JUMPLIT3NE JUMPLIT4EQ JUMPLIT4NE
  69. JUMPLITEQ JUMPLITNE
  70. % (f) call built-in one-arg function and use that as a predicate
  71. JUMPB1NIL JUMPB1T JUMPB2NIL JUMPB2T
  72. % (g) flagp with a literal tag
  73. JUMPFLAGP JUMPNFLAGP
  74. % (h) EQCAR test against literal
  75. JUMPEQCAR JUMPNEQCAR
  76. % CATCH needs something that behaves a bit like a (general) jump.
  77. CATCH CATCH_B CATCH_L CATCH_BL
  78. % After a CATCH the stack (etc) needs restoring
  79. UNCATCH THROW PROTECT UNPROTECT
  80. PVBIND PVRESTORE % PROGV support
  81. FREEBIND FREERSTR % Bind/restore FLUID/SPECIAL variables
  82. % Exiting from a procedure, optionally popping the stack a bit
  83. EXIT NILEXIT LOC0EXIT LOC1EXIT LOC2EXIT
  84. % General stack management
  85. PUSH PUSHNIL PUSHNIL2 PUSHNIL3 PUSHNILS
  86. POP LOSE LOSE2 LOSE3 LOSES
  87. % Exchange A and B registers
  88. SWOP
  89. % Various especially havily used Lisp functions
  90. EQ EQCAR EQUAL NUMBERP
  91. CAR CDR CAAR CADR CDAR CDDR
  92. CONS NCONS XCONS ACONS LENGTH
  93. LIST2 LIST2STAR LIST3
  94. PLUS2 ADD1 DIFFERENCE SUB1 TIMES2
  95. GREATERP LESSP
  96. FLAGP GET LITGET
  97. GETV QGETV QGETVN
  98. % Support for over-large stack-frames (LOADLOC/STORELOC + lexical access)
  99. BIGSTACK
  100. % Support for CALLs where the literal vector has become huge
  101. BIGCALL
  102. % An integer-based SWITCH or CASE statement has special support
  103. ICASE
  104. % Speed-up support for compiled GET and FLAGP when tag is important
  105. FASTGET
  106. % Opcodes that have not yet been allocated.
  107. SPARE1
  108. SPARE2
  109. )$
  110. if demo!-mode() then <<
  111. p := s!:opcodelist;
  112. for j := 0:254 do <<
  113. n := random!-number(256-j);
  114. q := p;
  115. for k := 1:n do q := cdr q;
  116. w := car p; rplaca(p, car q); rplaca(q, w);
  117. p := cdr p >> >>;
  118. end;