opcodes.red 5.9 KB

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