Advertisement
NovaYoshi

FALSE in MUF

Dec 3rd, 2018
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 KB | None | 0 0
  1. $include $lib/case
  2.  
  3. lvar code (user program)
  4. lvar d_stack (data stack)
  5. lvar pc (program counter)
  6. lvar output (output string)
  7. lvar ram (variables)
  8. lvar temp
  9.  
  10. : dpush (data stack push)
  11. d_stack @ array_appenditem d_stack !
  12. ;
  13. : dpop (data stack pop)
  14. d_stack @ dup array_last pop array_getitem
  15. d_stack @ dup array_last pop array_delitem d_stack !
  16. ;
  17. : nextchar
  18. code @ pc @ 1 midstr
  19. pc ++
  20. ;
  21. : goback
  22. pc --
  23. ;
  24. : isdigit?
  25. ctoi dup 48 >= swap 57 <= and
  26. ;
  27. : run
  28. begin
  29. ( get a character )
  30. nextchar
  31.  
  32. case
  33. ctoi dup 97 >= swap 122 <= and when goback nextchar ctoi 97 - dpush end (variable references)
  34. isdigit? when
  35. goback
  36. 0
  37. begin
  38. nextchar dup
  39. isdigit? not if
  40. break
  41. then
  42. ctoi 48 - swap 10 * +
  43. repeat
  44. goback pop dpush
  45. end
  46. "'" strcmp not when nextchar ctoi dpush end
  47. "+" strcmp not when dpop dpop + dpush end
  48. "*" strcmp not when dpop dpop * dpush end
  49. "&" strcmp not when dpop dpop bitand dpush end
  50. "|" strcmp not when dpop dpop bitor dpush end
  51. "^" strcmp not when dpop dpop bitxor dpush end (extension: xor)
  52. "_" strcmp not when 0 dpop - dpush end
  53. "-" strcmp not when dpop dpop swap - dpush end
  54. "/" strcmp not when dpop dpop swap / dpush end
  55. "M" strcmp not when dpop dpop swap % dpush end (extension: modulo)
  56. ">" strcmp not when 0 dpop dpop swap > - dpush end
  57. "<" strcmp not when 0 dpop dpop swap < - dpush end
  58. "=" strcmp not when 0 dpop dpop swap = - dpush end
  59. "$" strcmp not when dpop dup dpush dpush end
  60. "V" strcmp not when dpop dpop dup dpush swap dpush dpush end (extension: over)
  61. "%" strcmp not when dpop end
  62. "\\" strcmp not when dpop dpop swap dpush dpush end
  63. "." strcmp not when output @ dpop intostr strcat output ! end
  64. "," strcmp not when output @ dpop itoc strcat output ! end
  65. ":" strcmp not when dpop temp ! dpop ram @ temp @ array_setitem ram ! end
  66. ";" strcmp not when ram @ dpop array_getitem dpush end
  67. "!" strcmp not when pc @ dpop pc ! run pc ! end
  68. "?" strcmp not when pc @ dpop pc ! dpop if run then pc ! end
  69. "T" strcmp not when pc @ dpop pc ! dpop temp ! dpop if temp @ pc ! then run pc ! end (extension: if/else)
  70. "O" strcmp not when d_stack @ dup array_count dpop - -- array_getitem dpush end (pick)
  71. "#" strcmp not when
  72. pc @ dpop dpop
  73. begin
  74. dup pc ! run
  75. dpop not if break then
  76. over pc ! run
  77. repeat
  78. pop pop pc !
  79. end
  80. "[" strcmp not when
  81. pc @ dpush (push start of lambda)
  82. 1 temp !
  83. begin
  84. nextchar dup
  85. "[" strcmp not if temp ++ then
  86. "]" strcmp not if temp -- then
  87. temp @ 0 =
  88. until
  89. end
  90. "]" strcmp not when 99999 pc ! end ("break" didn't work)
  91. "@" strcmp not when dpop dpop dpop -3 rotate dpush dpush dpush end
  92. "{" strcmp not when begin nextchar "}" strcmp not until end
  93. "\"" strcmp not when
  94. begin
  95. nextchar dup
  96. "\"" strcmp not if
  97. break
  98. then
  99. output @ swap strcat output !
  100. repeat
  101. pop
  102. end
  103. "~" strcmp not when 0 dpop - -- dpush end
  104. endcase
  105.  
  106. pc @ code @ strlen >
  107. until
  108. ;
  109. : main
  110. code !
  111. { }list d_stack !
  112. { 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 }list ram !
  113. 1 pc !
  114. "" output !
  115.  
  116. run
  117.  
  118. me @ "FALSE: " output @ strcat notify
  119. ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement