Nife version Beta
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

181 lines
3.1 KiB

  1. /* Copyright (C) 2011-2014 Patrick H. E. Foubet - S.E.R.I.A.N.E.
  2. This program is free software: you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation, either version 3 of the License, or any
  5. later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program. If not, see <http://www.gnu.org/licenses/>
  12. *******************************************************************/
  13. /* stackL.c */
  14. #include "conf.h"
  15. #include <stdio.h>
  16. #include "nife.h"
  17. #include "mth.h"
  18. #include "err.h"
  19. #include "stackL.h"
  20. void IF_stackL_clear(void)
  21. {
  22. _MODIF_i_StackL_(0);
  23. }
  24. void putBool(bool B)
  25. {
  26. int i;
  27. i=i_StackL;
  28. stackL[i++] = B;
  29. _MODIF_i_StackL_(i);
  30. if (i == LSTACKL) stopErr("putBool",NULL);
  31. }
  32. void IF_dupL(void)
  33. {
  34. int i;
  35. i=i_StackL;
  36. if (i) {
  37. putBool(stackL[i-1]);
  38. } else messErr(5);
  39. }
  40. void IF_swapL(void)
  41. {
  42. bool B;
  43. int i;
  44. i=i_StackL;
  45. if (i > 1) {
  46. B = stackL[i-1];
  47. stackL[i-1] = stackL[i-2];
  48. stackL[i-2] = B;
  49. } else messErr(20);
  50. }
  51. void IF_andL(void)
  52. {
  53. bool B;
  54. int i;
  55. i=i_StackL;
  56. if (i > 1) {
  57. B = stackL[i-1] & stackL[i-2];
  58. stackL[i-2] = B;
  59. i--;
  60. _MODIF_i_StackL_(i);
  61. } else messErr(20);
  62. }
  63. void IF_orL(void)
  64. {
  65. bool B;
  66. int i;
  67. i=i_StackL;
  68. if (i > 1) {
  69. B = stackL[i-1] | stackL[i-2];
  70. stackL[i-2] = B;
  71. i--;
  72. _MODIF_i_StackL_(i);
  73. } else messErr(20);
  74. }
  75. void IF_xorL(void)
  76. {
  77. bool B;
  78. int i;
  79. i=i_StackL;
  80. if (i> 1) {
  81. if (stackL[i-1] == stackL[i-2]) B=FALSE;
  82. else B = TRUE;
  83. stackL[i-2] = B;
  84. i--;
  85. _MODIF_i_StackL_(i);
  86. } else messErr(20);
  87. }
  88. void IF_overL(void)
  89. {
  90. int i;
  91. i=i_StackL;
  92. if (i > 1) {
  93. putBool(stackL[i-2]);
  94. } else messErr(20);
  95. }
  96. bool getBool(void)
  97. {
  98. int i;
  99. i=i_StackL;
  100. if (i) {
  101. i--;
  102. _MODIF_i_StackL_(i);
  103. return(stackL[i]);
  104. } else messErr(5);
  105. return -1;
  106. }
  107. void IF_typeL(void)
  108. {
  109. int i;
  110. i=i_StackL;
  111. if (i) {
  112. i--;
  113. _MODIF_i_StackL_(i);
  114. if(stackL[i]) printf("true\n");
  115. else printf("false\n");
  116. } else messErr(5);
  117. }
  118. void negBool(void)
  119. {
  120. int i;
  121. i=i_StackL;
  122. if (i) {
  123. i--;
  124. if(stackL[i]) stackL[i]= FALSE;
  125. else stackL[i]= TRUE;
  126. } else messErr(5);
  127. }
  128. void IF_true(void)
  129. {
  130. putBool(TRUE);
  131. }
  132. void IF_false(void)
  133. {
  134. putBool(FALSE);
  135. }
  136. void IF_dropL(void)
  137. {
  138. getBool();
  139. }
  140. void IF_show_stackL(void)
  141. {
  142. int i,j=0,I;
  143. char s;
  144. I=i_StackL;
  145. for(i=I-1;i>=0;i--) {
  146. if (stackL[i]) printf(" TRUE");
  147. else printf(" FALSE");
  148. if (j==0) printf(" <- top");
  149. printf("\n");
  150. j++;
  151. if (j==NBLIG) break;
  152. }
  153. if (i>0) {
  154. if (i==1) s=' ';
  155. else s='s';
  156. printf(" ... and %d other%c boolean%c !\n",I-NBLIG,s,s);
  157. } else printf("<end of logical stack>\n");
  158. }