Advertisement
chemoelectric

Output of "vmc m4 < mandel.vm"

Apr 3rd, 2023
466
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.02 KB | Source Code | 0 0
  1. divert(-1)
  2. changecom
  3. define(`newline',`
  4. ')
  5. define(`leftquote',`[')
  6. define(`rightquote',`]')
  7. changequote(`[',`]')
  8. define([print_char],
  9. [ifelse(
  10. $1,0,[*],
  11. $1,1,[*],
  12. $1,2,[*],
  13. $1,3,[*],
  14. $1,4,[*],
  15. $1,5,[*],
  16. $1,6,[*],
  17. $1,7,[*],
  18. $1,8,[*],
  19. $1,9,[*],
  20. $1,10,[newline],
  21. $1,11,[*],
  22. $1,12,[*],
  23. $1,13,[*],
  24. $1,14,[*],
  25. $1,15,[*],
  26. $1,16,[*],
  27. $1,17,[*],
  28. $1,18,[*],
  29. $1,19,[*],
  30. $1,20,[*],
  31. $1,21,[*],
  32. $1,22,[*],
  33. $1,23,[*],
  34. $1,24,[*],
  35. $1,25,[*],
  36. $1,26,[*],
  37. $1,27,[*],
  38. $1,28,[*],
  39. $1,29,[*],
  40. $1,30,[*],
  41. $1,31,[*],
  42. $1,32,[ ],
  43. $1,33,[!],
  44. $1,34,["],
  45. $1,35,[#],
  46. $1,36,[$],
  47. $1,37,[%],
  48. $1,38,[&],
  49. $1,39,['],
  50. $1,40,[(],
  51. $1,41,[)],
  52. $1,42,[*],
  53. $1,43,[+],
  54. $1,44,[,],
  55. $1,45,[-],
  56. $1,46,[.],
  57. $1,47,[/],
  58. $1,48,[0],
  59. $1,49,[1],
  60. $1,50,[2],
  61. $1,51,[3],
  62. $1,52,[4],
  63. $1,53,[5],
  64. $1,54,[6],
  65. $1,55,[7],
  66. $1,56,[8],
  67. $1,57,[9],
  68. $1,58,[:],
  69. $1,59,[;],
  70. $1,60,[<],
  71. $1,61,[=],
  72. $1,62,[>],
  73. $1,63,[?],
  74. $1,64,[@],
  75. $1,65,[A],
  76. $1,66,[B],
  77. $1,67,[C],
  78. $1,68,[D],
  79. $1,69,[E],
  80. $1,70,[F],
  81. $1,71,[G],
  82. $1,72,[H],
  83. $1,73,[I],
  84. $1,74,[J],
  85. $1,75,[K],
  86. $1,76,[L],
  87. $1,77,[M],
  88. $1,78,[N],
  89. $1,79,[O],
  90. $1,80,[P],
  91. $1,81,[Q],
  92. $1,82,[R],
  93. $1,83,[S],
  94. $1,84,[T],
  95. $1,85,[U],
  96. $1,86,[V],
  97. $1,87,[W],
  98. $1,88,[X],
  99. $1,89,[Y],
  100. $1,90,[Z],
  101. $1,91,[changequote([`],['])leftquote`'changequote(`[',`]')],
  102. $1,92,[\],
  103. $1,93,[rightquote],
  104. $1,94,[^],
  105. $1,95,[_],
  106. $1,96,[`],
  107. $1,97,[a],
  108. $1,98,[b],
  109. $1,99,[c],
  110. $1,100,[d],
  111. $1,101,[e],
  112. $1,102,[f],
  113. $1,103,[g],
  114. $1,104,[h],
  115. $1,105,[i],
  116. $1,106,[j],
  117. $1,107,[k],
  118. $1,108,[l],
  119. $1,109,[m],
  120. $1,110,[n],
  121. $1,111,[o],
  122. $1,112,[p],
  123. $1,113,[q],
  124. $1,114,[r],
  125. $1,115,[s],
  126. $1,116,[t],
  127. $1,117,[u],
  128. $1,118,[v],
  129. $1,119,[w],
  130. $1,120,[x],
  131. $1,121,[y],
  132. $1,122,[z],
  133. $1,123,[{],
  134. $1,124,[|],
  135. $1,125,[}],
  136. $1,126,[~],
  137. [*])])
  138. define([stack_1st],[substr([$1],0,index([$1],[:]))])
  139. define([stack_2nd],[stack_1st(stack_drop([$1]))])
  140. define([stack_drop],[substr([$1],eval(index([$1],[:]) [+ 1]))])
  141. define([stack_drop2],[stack_drop(stack_drop([$1]))])
  142. define([stack_not],[eval(stack_1st([$1]) [== 0]):stack_drop([$1])])
  143. define([stack_neg],[eval([-] stack_1st([$1])):stack_drop([$1])])
  144. define([stack_and],[eval(stack_2nd([$1] [!= 0]) [&&] stack_1st([$1] [!= 0])):stack_drop2([$1])])
  145. define([stack_or],[eval(stack_2nd([$1] [!= 0]) [||] stack_1st([$1] [!= 0])):stack_drop2([$1])])
  146. define([stack_lt],[eval(stack_2nd([$1]) [<] stack_1st([$1])):stack_drop2([$1])])
  147. define([stack_le],[eval(stack_2nd([$1]) [<=] stack_1st([$1])):stack_drop2([$1])])
  148. define([stack_gt],[eval(stack_2nd([$1]) [>] stack_1st([$1])):stack_drop2([$1])])
  149. define([stack_ge],[eval(stack_2nd([$1]) [>=] stack_1st([$1])):stack_drop2([$1])])
  150. define([stack_eq],[eval(stack_2nd([$1]) [==] stack_1st([$1])):stack_drop2([$1])])
  151. define([stack_ne],[eval(stack_2nd([$1]) [!=] stack_1st([$1])):stack_drop2([$1])])
  152. define([stack_add],[eval(stack_2nd([$1]) [+] stack_1st([$1])):stack_drop2([$1])])
  153. define([stack_sub],[eval(stack_2nd([$1]) [-] stack_1st([$1])):stack_drop2([$1])])
  154. define([stack_mul],[eval(stack_2nd([$1]) [*] stack_1st([$1])):stack_drop2([$1])])
  155. define([stack_div],[eval(stack_2nd([$1]) [/] stack_1st([$1])):stack_drop2([$1])])
  156. define([stack_mod],[eval(stack_2nd([$1]) [%] stack_1st([$1])):stack_drop2([$1])])
  157. define([prtc_1st],[print_char(stack_1st([$1]))])
  158. define([prti_1st],[stack_1st([$1])])
  159. define([prts_1st],[print_string(stack_1st([$1]))])
  160. define([store],[define([_tmp1],index([$2],[$1:]))[]substr([$2],0,_tmp1)[$1:$3]define([_tmp2],substr([$2],eval(_tmp1 + len([$1]) [+ 1])))substr(_tmp2,index(_tmp2,[:]))])
  161. define([fetch],[define([_tmp],substr([$2],eval(index([$2],[$1:]) [+] len([$1]) [+ 1])))[]substr(_tmp,0,index(_tmp,[:]))])
  162. define([initial_vars],[var0:0:var1:0:var2:0:var3:0:var4:0:var5:0:var6:0:var7:0:var8:0:var9:0:var10:0:var11:0:var12:0:var13:0:var14:0:])
  163. define([kont0],[kont5([420:$1],[$2])])
  164. define([kont5],[kont6(stack_neg([$1]),[$2])])
  165. define([kont6],[kont11(stack_drop([$1]),store([var0],[$2],stack_1st([$1])))])
  166. define([kont11],[kont16([300:$1],[$2])])
  167. define([kont16],[kont21(stack_drop([$1]),store([var1],[$2],stack_1st([$1])))])
  168. define([kont21],[kont26([300:$1],[$2])])
  169. define([kont26],[kont31(stack_drop([$1]),store([var2],[$2],stack_1st([$1])))])
  170. define([kont31],[kont36([300:$1],[$2])])
  171. define([kont36],[kont37(stack_neg([$1]),[$2])])
  172. define([kont37],[kont42(stack_drop([$1]),store([var3],[$2],stack_1st([$1])))])
  173. define([kont42],[kont47([7:$1],[$2])])
  174. define([kont47],[kont52(stack_drop([$1]),store([var4],[$2],stack_1st([$1])))])
  175. define([kont52],[kont57([15:$1],[$2])])
  176. define([kont57],[kont62(stack_drop([$1]),store([var5],[$2],stack_1st([$1])))])
  177. define([kont62],[kont67([200:$1],[$2])])
  178. define([kont67],[kont72(stack_drop([$1]),store([var6],[$2],stack_1st([$1])))])
  179. define([kont72],[kont77(fetch([var2],[$2])[:$1],[$2])])
  180. define([kont77],[kont82(stack_drop([$1]),store([var7],[$2],stack_1st([$1])))])
  181. define([kont82],[kont87(fetch([var7],[$2])[:$1],[$2])])
  182. define([kont87],[kont92(fetch([var3],[$2])[:$1],[$2])])
  183. define([kont92],[kont93(stack_gt([$1]),[$2])])
  184. define([kont93],[ifelse(eval(stack_1st([$1]) [== 0]),1,[kont423(stack_drop([$1]),[$2])],[kont98(stack_drop([$1]),[$2])])])
  185. define([kont98],[kont103(fetch([var0],[$2])[:$1],[$2])])
  186. define([kont103],[kont108(stack_drop([$1]),store([var8],[$2],stack_1st([$1])))])
  187. define([kont108],[kont113(fetch([var8],[$2])[:$1],[$2])])
  188. define([kont113],[kont118(fetch([var1],[$2])[:$1],[$2])])
  189. define([kont118],[kont119(stack_lt([$1]),[$2])])
  190. define([kont119],[ifelse(eval(stack_1st([$1]) [== 0]),1,[kont396(stack_drop([$1]),[$2])],[kont124(stack_drop([$1]),[$2])])])
  191. define([kont124],[kont129([0:$1],[$2])])
  192. define([kont129],[kont134(stack_drop([$1]),store([var9],[$2],stack_1st([$1])))])
  193. define([kont134],[kont139([0:$1],[$2])])
  194. define([kont139],[kont144(stack_drop([$1]),store([var10],[$2],stack_1st([$1])))])
  195. define([kont144],[kont149([32:$1],[$2])])
  196. define([kont149],[kont154(stack_drop([$1]),store([var11],[$2],stack_1st([$1])))])
  197. define([kont154],[kont159([0:$1],[$2])])
  198. define([kont159],[kont164(stack_drop([$1]),store([var12],[$2],stack_1st([$1])))])
  199. define([kont164],[kont169(fetch([var12],[$2])[:$1],[$2])])
  200. define([kont169],[kont174(fetch([var6],[$2])[:$1],[$2])])
  201. define([kont174],[kont175(stack_lt([$1]),[$2])])
  202. define([kont175],[ifelse(eval(stack_1st([$1]) [== 0]),1,[kont369(stack_drop([$1]),[$2])],[kont180(stack_drop([$1]),[$2])])])
  203. define([kont180],[kont185(fetch([var10],[$2])[:$1],[$2])])
  204. define([kont185],[kont190(fetch([var10],[$2])[:$1],[$2])])
  205. define([kont190],[kont191(stack_mul([$1]),[$2])])
  206. define([kont191],[kont196([200:$1],[$2])])
  207. define([kont196],[kont197(stack_div([$1]),[$2])])
  208. define([kont197],[kont202(stack_drop([$1]),store([var13],[$2],stack_1st([$1])))])
  209. define([kont202],[kont207(fetch([var9],[$2])[:$1],[$2])])
  210. define([kont207],[kont212(fetch([var9],[$2])[:$1],[$2])])
  211. define([kont212],[kont213(stack_mul([$1]),[$2])])
  212. define([kont213],[kont218([200:$1],[$2])])
  213. define([kont218],[kont219(stack_div([$1]),[$2])])
  214. define([kont219],[kont224(stack_drop([$1]),store([var14],[$2],stack_1st([$1])))])
  215. define([kont224],[kont229(fetch([var13],[$2])[:$1],[$2])])
  216. define([kont229],[kont234(fetch([var14],[$2])[:$1],[$2])])
  217. define([kont234],[kont235(stack_add([$1]),[$2])])
  218. define([kont235],[kont240([800:$1],[$2])])
  219. define([kont240],[kont241(stack_gt([$1]),[$2])])
  220. define([kont241],[ifelse(eval(stack_1st([$1]) [== 0]),1,[kont298(stack_drop([$1]),[$2])],[kont246(stack_drop([$1]),[$2])])])
  221. define([kont246],[kont251([48:$1],[$2])])
  222. define([kont251],[kont256(fetch([var12],[$2])[:$1],[$2])])
  223. define([kont256],[kont257(stack_add([$1]),[$2])])
  224. define([kont257],[kont262(stack_drop([$1]),store([var11],[$2],stack_1st([$1])))])
  225. define([kont262],[kont267(fetch([var12],[$2])[:$1],[$2])])
  226. define([kont267],[kont272([9:$1],[$2])])
  227. define([kont272],[kont273(stack_gt([$1]),[$2])])
  228. define([kont273],[ifelse(eval(stack_1st([$1]) [== 0]),1,[kont288(stack_drop([$1]),[$2])],[kont278(stack_drop([$1]),[$2])])])
  229. define([kont278],[kont283([64:$1],[$2])])
  230. define([kont283],[kont288(stack_drop([$1]),store([var11],[$2],stack_1st([$1])))])
  231. define([kont288],[kont293(fetch([var6],[$2])[:$1],[$2])])
  232. define([kont293],[kont298(stack_drop([$1]),store([var12],[$2],stack_1st([$1])))])
  233. define([kont298],[kont303(fetch([var10],[$2])[:$1],[$2])])
  234. define([kont303],[kont308(fetch([var9],[$2])[:$1],[$2])])
  235. define([kont308],[kont309(stack_mul([$1]),[$2])])
  236. define([kont309],[kont314([100:$1],[$2])])
  237. define([kont314],[kont315(stack_div([$1]),[$2])])
  238. define([kont315],[kont320(fetch([var7],[$2])[:$1],[$2])])
  239. define([kont320],[kont321(stack_add([$1]),[$2])])
  240. define([kont321],[kont326(stack_drop([$1]),store([var9],[$2],stack_1st([$1])))])
  241. define([kont326],[kont331(fetch([var13],[$2])[:$1],[$2])])
  242. define([kont331],[kont336(fetch([var14],[$2])[:$1],[$2])])
  243. define([kont336],[kont337(stack_sub([$1]),[$2])])
  244. define([kont337],[kont342(fetch([var8],[$2])[:$1],[$2])])
  245. define([kont342],[kont343(stack_add([$1]),[$2])])
  246. define([kont343],[kont348(stack_drop([$1]),store([var10],[$2],stack_1st([$1])))])
  247. define([kont348],[kont353(fetch([var12],[$2])[:$1],[$2])])
  248. define([kont353],[kont358([1:$1],[$2])])
  249. define([kont358],[kont359(stack_add([$1]),[$2])])
  250. define([kont359],[kont364(stack_drop([$1]),store([var12],[$2],stack_1st([$1])))])
  251. define([kont364],[kont164([$1],[$2])])
  252. define([kont369],[kont374(fetch([var11],[$2])[:$1],[$2])])
  253. define([kont374],[prtc_1st([$1])[]kont375(stack_drop([$1]),[$2])])
  254. define([kont375],[kont380(fetch([var8],[$2])[:$1],[$2])])
  255. define([kont380],[kont385(fetch([var4],[$2])[:$1],[$2])])
  256. define([kont385],[kont386(stack_add([$1]),[$2])])
  257. define([kont386],[kont391(stack_drop([$1]),store([var8],[$2],stack_1st([$1])))])
  258. define([kont391],[kont108([$1],[$2])])
  259. define([kont396],[kont401([10:$1],[$2])])
  260. define([kont401],[prtc_1st([$1])[]kont402(stack_drop([$1]),[$2])])
  261. define([kont402],[kont407(fetch([var7],[$2])[:$1],[$2])])
  262. define([kont407],[kont412(fetch([var5],[$2])[:$1],[$2])])
  263. define([kont412],[kont413(stack_sub([$1]),[$2])])
  264. define([kont413],[kont418(stack_drop([$1]),store([var7],[$2],stack_1st([$1])))])
  265. define([kont418],[kont82([$1],[$2])])
  266. define([kont423],[])
  267. divert[]dnl
  268. kont0([stack-bottom],initial_vars)[]dnl
  269.  
Advertisement
Comments
  • chemoelectric
    1 year (edited)
    # text 0.75 KB | 0 0
    1. To run this with "Heirloom Development Tools" m4, or similar legacy m4, you likely have to increase the stack size. "m4 -S 1000 mandel.m4" works for me with Heirloom m4. Also tested with GNU m4 and OpenBSD m4, but written to require no more than the ASCII character set and the POSIX standard for m4.
    2.  
    3. There are no global variables, except that I do not bother with pushdef-popdef for the few temporary variables. The stack is numbers separated by ‘:’. Variables are stored in a manner similar to a Common Lisp plist and so are referenced by name: ‘var0:123:var1:456:var2:789:’
    4.  
    5. I do not play those terribly confusing tricks with commas, as so much m4 code does. This is more like programming in Prolog or a term-rewriting language (such as Pure), I guess.
  • chemoelectric
    1 year (edited)
    # text 0.27 KB | 0 0
    1. ATS/Postiats source code for vmc: https://sourceforge.net/p/chemoelectric/rosettacode-contributions/ci/default/tree/vmc.dats
    2.  
    3. m4 support first appears in the revision tagged ‘vmc-8.0’.
    4.  
    5. vmc takes as input the output of ‘gen’ from the Rosetta Code compiler task suite.
Add Comment
Please, Sign In to add comment
Advertisement