lcode.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. ** $Id: lcode.h $
  3. ** Code generator for Lua
  4. ** See Copyright Notice in lua.h
  5. */
  6. #ifndef lcode_h
  7. #define lcode_h
  8. #include "llex.h"
  9. #include "lobject.h"
  10. #include "lopcodes.h"
  11. #include "lparser.h"
  12. /*
  13. ** Marks the end of a patch list. It is an invalid value both as an absolute
  14. ** address, and as a list link (would link an element to itself).
  15. */
  16. #define NO_JUMP (-1)
  17. /*
  18. ** grep "ORDER OPR" if you change these enums (ORDER OP)
  19. */
  20. typedef enum BinOpr {
  21. /* arithmetic operators */
  22. OPR_ADD, OPR_SUB, OPR_MUL, OPR_MOD, OPR_POW,
  23. OPR_DIV, OPR_IDIV,
  24. /* bitwise operators */
  25. OPR_BAND, OPR_BOR, OPR_BXOR,
  26. OPR_SHL, OPR_SHR,
  27. /* string operator */
  28. OPR_CONCAT,
  29. /* comparison operators */
  30. OPR_EQ, OPR_LT, OPR_LE,
  31. OPR_NE, OPR_GT, OPR_GE,
  32. /* logical operators */
  33. OPR_AND, OPR_OR,
  34. OPR_NOBINOPR
  35. } BinOpr;
  36. /* true if operation is foldable (that is, it is arithmetic or bitwise) */
  37. #define foldbinop(op) ((op) <= OPR_SHR)
  38. #define luaK_codeABC(fs,o,a,b,c) luaK_codeABCk(fs,o,a,b,c,0)
  39. typedef enum UnOpr { OPR_MINUS, OPR_BNOT, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr;
  40. /* get (pointer to) instruction of given 'expdesc' */
  41. #define getinstruction(fs,e) ((fs)->f->code[(e)->u.info])
  42. #define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET)
  43. #define luaK_jumpto(fs,t) luaK_patchlist(fs, luaK_jump(fs), t)
  44. LUAI_FUNC int luaK_code (FuncState *fs, Instruction i);
  45. LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx);
  46. LUAI_FUNC int luaK_codeAsBx (FuncState *fs, OpCode o, int A, int Bx);
  47. LUAI_FUNC int luaK_codeABCk (FuncState *fs, OpCode o, int A,
  48. int B, int C, int k);
  49. LUAI_FUNC int luaK_isKint (expdesc *e);
  50. LUAI_FUNC int luaK_exp2const (FuncState *fs, const expdesc *e, TValue *v);
  51. LUAI_FUNC void luaK_fixline (FuncState *fs, int line);
  52. LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n);
  53. LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n);
  54. LUAI_FUNC void luaK_checkstack (FuncState *fs, int n);
  55. LUAI_FUNC void luaK_int (FuncState *fs, int reg, lua_Integer n);
  56. LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e);
  57. LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e);
  58. LUAI_FUNC void luaK_exp2anyregup (FuncState *fs, expdesc *e);
  59. LUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e);
  60. LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e);
  61. LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e);
  62. LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key);
  63. LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k);
  64. LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e);
  65. LUAI_FUNC void luaK_goiffalse (FuncState *fs, expdesc *e);
  66. LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e);
  67. LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults);
  68. LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e);
  69. LUAI_FUNC int luaK_jump (FuncState *fs);
  70. LUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret);
  71. LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target);
  72. LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list);
  73. LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2);
  74. LUAI_FUNC int luaK_getlabel (FuncState *fs);
  75. LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v, int line);
  76. LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v);
  77. LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1,
  78. expdesc *v2, int line);
  79. LUAI_FUNC void luaK_settablesize (FuncState *fs, int pc,
  80. int ra, int asize, int hsize);
  81. LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore);
  82. LUAI_FUNC void luaK_finish (FuncState *fs);
  83. LUAI_FUNC l_noret luaK_semerror (LexState *ls, const char *msg);
  84. #endif