Posted to tcl by gps at Tue Mar 31 06:01:48 GMT 2009view raw

  1. Have you seen those 1960's era demos with the inventor of the mouse?
  2.  
  3. I was thinking it would be useful to be able to have layers of code in some hypertext format, somewhat like MOL.
  4.  
  5. For instance, this factorial code generates a lot of assembly code (which follows), and I was thinking it would be useful to be able to zoom using hypertext or something like it.
  6.  
  7. It might go something like toplevel-command -> implementation commands -> assembly language.
  8.  
  9. How could I structure the source code to enable this?
  10.  
  11. Do any of you know how they did that in NLS?
  12.  
  13. extern puti
  14. extern putn
  15. extern ok
  16. extern failed
  17. extern putstr
  18.  
  19. : factorial
  20. declare n
  21. *n ->
  22. n 1 <=
  23. if 1 return
  24. else n 1 - factorial n * return
  25. then
  26. ;;
  27.  
  28. : run
  29. declare r1
  30. declare r2
  31. declare r3
  32.  
  33. 3 factorial *r1 ->
  34. 4 factorial *r2 ->
  35. 5 factorial *r3 ->
  36.  
  37. 3 puti " = " putstr r1 puti putn
  38. 4 puti " = " putstr r2 puti putn
  39. 5 puti " = " putstr r3 puti putn
  40.  
  41. r1 6 = if ok else failed then putn
  42. r2 24 = if ok else failed then putn
  43. r3 120 = if ok else failed then putn
  44.  
  45. 0
  46. ;;
  47.  
  48.  
  49. .globl factorial
  50. factorial:
  51. pushl %ebp
  52. movl %esp,%ebp
  53. /*declare begin*/
  54. subl $4,%esp
  55. /*declare end*/
  56. /*push-local begin*/
  57. subl $4,%edi
  58. leal -4(%ebp),%ecx
  59. movl %ecx,(%edi)
  60. /*push-local end*/
  61. /*op-> begin*/
  62. movl (%edi),%eax
  63. addl $4,%edi
  64. movl (%edi),%ecx
  65. movl %ecx,(%eax)
  66. addl $4,%edi
  67. /*op-> end*/
  68. /*push-local begin*/
  69. subl $4,%edi
  70. movl -4(%ebp),%ecx
  71. movl %ecx,(%edi)
  72. /*push-local end*/
  73. /*push-value begin*/
  74. subl $4,%edi
  75. movl $1,(%edi)
  76. /*push-value end*/
  77. /* op-<= begin */
  78. /*op-cmp2 begin*/
  79. movl (%edi),%eax
  80. addl $4,%edi
  81. movl (%edi),%ecx
  82. addl $4,%edi
  83. cmpl %eax,%ecx
  84. /*op-cmp2 end*/
  85. movl $0,%esi
  86. movl $-1,%edx
  87. cmovle %edx,%esi
  88. subl $4,%edi
  89. movl %esi,(%edi)
  90. /* op-<= end */
  91. /*op-if begin*/
  92. mov (%edi),%eax
  93. addl $4,%edi
  94. cmpl $0,%eax
  95. je ___else_2
  96. /*op-if end*/
  97. /*push-value begin*/
  98. subl $4,%edi
  99. movl $1,(%edi)
  100. /*push-value end*/
  101. /*op-return begin*/
  102. leave
  103. ret
  104. /*op-return end*/
  105. /* op-else begin */
  106. jmp ___then_1
  107. ___else_2:
  108. /* op-else end */
  109. /*push-local begin*/
  110. subl $4,%edi
  111. movl -4(%ebp),%ecx
  112. movl %ecx,(%edi)
  113. /*push-local end*/
  114. /*push-value begin*/
  115. subl $4,%edi
  116. movl $1,(%edi)
  117. /*push-value end*/
  118. /*op- begin*/
  119. movl (%edi),%eax
  120. addl $4,%edi
  121. subl %eax,(%edi)
  122. /*op- end*/
  123. /*op-extern-call begin*/
  124. call factorial
  125. /*op-extern-call end*/
  126. /*push-local begin*/
  127. subl $4,%edi
  128. movl -4(%ebp),%ecx
  129. movl %ecx,(%edi)
  130. /*push-local end*/
  131. /*op-* begin*/
  132. movl (%edi),%eax
  133. xorl %edx,%edx
  134. addl $4,%edi
  135. movl (%edi),%ebx
  136. imul %ebx
  137. movl %eax,(%edi)
  138. /*op-* end*/
  139. /*op-return begin*/
  140. leave
  141. ret
  142. /*op-return end*/
  143. /*op-then begin*/
  144. ___then_1:
  145. /*op-then end*/
  146. leave
  147. ret
  148. .globl run
  149. run:
  150. pushl %ebp
  151. movl %esp,%ebp
  152. /*declare begin*/
  153. subl $4,%esp
  154. /*declare end*/
  155. /*declare begin*/
  156. subl $4,%esp
  157. /*declare end*/
  158. /*declare begin*/
  159. subl $4,%esp
  160. /*declare end*/
  161. /*push-value begin*/
  162. subl $4,%edi
  163. movl $3,(%edi)
  164. /*push-value end*/
  165. /*op-extern-call begin*/
  166. call factorial
  167. /*op-extern-call end*/
  168. /*push-local begin*/
  169. subl $4,%edi
  170. leal -4(%ebp),%ecx
  171. movl %ecx,(%edi)
  172. /*push-local end*/
  173. /*op-> begin*/
  174. movl (%edi),%eax
  175. addl $4,%edi
  176. movl (%edi),%ecx
  177. movl %ecx,(%eax)
  178. addl $4,%edi
  179. /*op-> end*/
  180. /*push-value begin*/
  181. subl $4,%edi
  182. movl $4,(%edi)
  183. /*push-value end*/
  184. /*op-extern-call begin*/
  185. call factorial
  186. /*op-extern-call end*/
  187. /*push-local begin*/
  188. subl $4,%edi
  189. leal -8(%ebp),%ecx
  190. movl %ecx,(%edi)
  191. /*push-local end*/
  192. /*op-> begin*/
  193. movl (%edi),%eax
  194. addl $4,%edi
  195. movl (%edi),%ecx
  196. movl %ecx,(%eax)
  197. addl $4,%edi
  198. /*op-> end*/
  199. /*push-value begin*/
  200. subl $4,%edi
  201. movl $5,(%edi)
  202. /*push-value end*/
  203. /*op-extern-call begin*/
  204. call factorial
  205. /*op-extern-call end*/
  206. /*push-local begin*/
  207. subl $4,%edi
  208. leal -12(%ebp),%ecx
  209. movl %ecx,(%edi)
  210. /*push-local end*/
  211. /*op-> begin*/
  212. movl (%edi),%eax
  213. addl $4,%edi
  214. movl (%edi),%ecx
  215. movl %ecx,(%eax)
  216. addl $4,%edi
  217. /*op-> end*/
  218. /*push-value begin*/
  219. subl $4,%edi
  220. movl $3,(%edi)
  221. /*push-value end*/
  222. /*op-extern-call begin*/
  223. call puti
  224. /*op-extern-call end*/
  225. .section .rodata
  226. .align 4
  227. ___quote_3: .long 3
  228. .byte 0x20, 0x3d, 0x20
  229. .text
  230. subl $4,%edi
  231. movl $___quote_3,(%edi)
  232. /*op-extern-call begin*/
  233. call putstr
  234. /*op-extern-call end*/
  235. /*push-local begin*/
  236. subl $4,%edi
  237. movl -4(%ebp),%ecx
  238. movl %ecx,(%edi)
  239. /*push-local end*/
  240. /*op-extern-call begin*/
  241. call puti
  242. /*op-extern-call end*/
  243. /*op-extern-call begin*/
  244. call putn
  245. /*op-extern-call end*/
  246. /*push-value begin*/
  247. subl $4,%edi
  248. movl $4,(%edi)
  249. /*push-value end*/
  250. /*op-extern-call begin*/
  251. call puti
  252. /*op-extern-call end*/
  253. .section .rodata
  254. .align 4
  255. ___quote_4: .long 3
  256. .byte 0x20, 0x3d, 0x20
  257. .text
  258. subl $4,%edi
  259. movl $___quote_4,(%edi)
  260. /*op-extern-call begin*/
  261. call putstr
  262. /*op-extern-call end*/
  263. /*push-local begin*/
  264. subl $4,%edi
  265. movl -8(%ebp),%ecx
  266. movl %ecx,(%edi)
  267. /*push-local end*/
  268. /*op-extern-call begin*/
  269. call puti
  270. /*op-extern-call end*/
  271. /*op-extern-call begin*/
  272. call putn
  273. /*op-extern-call end*/
  274. /*push-value begin*/
  275. subl $4,%edi
  276. movl $5,(%edi)
  277. /*push-value end*/
  278. /*op-extern-call begin*/
  279. call puti
  280. /*op-extern-call end*/
  281. .section .rodata
  282. .align 4
  283. ___quote_5: .long 3
  284. .byte 0x20, 0x3d, 0x20
  285. .text
  286. subl $4,%edi
  287. movl $___quote_5,(%edi)
  288. /*op-extern-call begin*/
  289. call putstr
  290. /*op-extern-call end*/
  291. /*push-local begin*/
  292. subl $4,%edi
  293. movl -12(%ebp),%ecx
  294. movl %ecx,(%edi)
  295. /*push-local end*/
  296. /*op-extern-call begin*/
  297. call puti
  298. /*op-extern-call end*/
  299. /*op-extern-call begin*/
  300. call putn
  301. /*op-extern-call end*/
  302. /*push-local begin*/
  303. subl $4,%edi
  304. movl -4(%ebp),%ecx
  305. movl %ecx,(%edi)
  306. /*push-local end*/
  307. /*push-value begin*/
  308. subl $4,%edi
  309. movl $6,(%edi)
  310. /*push-value end*/
  311. /* op-= begin */
  312. /*op-cmp2 begin*/
  313. movl (%edi),%eax
  314. addl $4,%edi
  315. movl (%edi),%ecx
  316. addl $4,%edi
  317. cmpl %eax,%ecx
  318. /*op-cmp2 end*/
  319. movl $0,%eax
  320. movl $-1,%ecx
  321. cmove %ecx,%eax
  322. subl $4,%edi
  323. movl %eax,(%edi)
  324. /* op-= end */
  325. /*op-if begin*/
  326. mov (%edi),%eax
  327. addl $4,%edi
  328. cmpl $0,%eax
  329. je ___else_7
  330. /*op-if end*/
  331. /*op-extern-call begin*/
  332. call ok
  333. /*op-extern-call end*/
  334. /* op-else begin */
  335. jmp ___then_6
  336. ___else_7:
  337. /* op-else end */
  338. /*op-extern-call begin*/
  339. call failed
  340. /*op-extern-call end*/
  341. /*op-then begin*/
  342. ___then_6:
  343. /*op-then end*/
  344. /*op-extern-call begin*/
  345. call putn
  346. /*op-extern-call end*/
  347. /*push-local begin*/
  348. subl $4,%edi
  349. movl -8(%ebp),%ecx
  350. movl %ecx,(%edi)
  351. /*push-local end*/
  352. /*push-value begin*/
  353. subl $4,%edi
  354. movl $24,(%edi)
  355. /*push-value end*/
  356. /* op-= begin */
  357. /*op-cmp2 begin*/
  358. movl (%edi),%eax
  359. addl $4,%edi
  360. movl (%edi),%ecx
  361. addl $4,%edi
  362. cmpl %eax,%ecx
  363. /*op-cmp2 end*/
  364. movl $0,%eax
  365. movl $-1,%ecx
  366. cmove %ecx,%eax
  367. subl $4,%edi
  368. movl %eax,(%edi)
  369. /* op-= end */
  370. /*op-if begin*/
  371. mov (%edi),%eax
  372. addl $4,%edi
  373. cmpl $0,%eax
  374. je ___else_9
  375. /*op-if end*/
  376. /*op-extern-call begin*/
  377. call ok
  378. /*op-extern-call end*/
  379. /* op-else begin */
  380. jmp ___then_8
  381. ___else_9:
  382. /* op-else end */
  383. /*op-extern-call begin*/
  384. call failed
  385. /*op-extern-call end*/
  386. /*op-then begin*/
  387. ___then_8:
  388. /*op-then end*/
  389. /*op-extern-call begin*/
  390. call putn
  391. /*op-extern-call end*/
  392. /*push-local begin*/
  393. subl $4,%edi
  394. movl -12(%ebp),%ecx
  395. movl %ecx,(%edi)
  396. /*push-local end*/
  397. /*push-value begin*/
  398. subl $4,%edi
  399. movl $120,(%edi)
  400. /*push-value end*/
  401. /* op-= begin */
  402. /*op-cmp2 begin*/
  403. movl (%edi),%eax
  404. addl $4,%edi
  405. movl (%edi),%ecx
  406. addl $4,%edi
  407. cmpl %eax,%ecx
  408. /*op-cmp2 end*/
  409. movl $0,%eax
  410. movl $-1,%ecx
  411. cmove %ecx,%eax
  412. subl $4,%edi
  413. movl %eax,(%edi)
  414. /* op-= end */
  415. /*op-if begin*/
  416. mov (%edi),%eax
  417. addl $4,%edi
  418. cmpl $0,%eax
  419. je ___else_11
  420. /*op-if end*/
  421. /*op-extern-call begin*/
  422. call ok
  423. /*op-extern-call end*/
  424. /* op-else begin */
  425. jmp ___then_10
  426. ___else_11:
  427. /* op-else end */
  428. /*op-extern-call begin*/
  429. call failed
  430. /*op-extern-call end*/
  431. /*op-then begin*/
  432. ___then_10:
  433. /*op-then end*/
  434. /*op-extern-call begin*/
  435. call putn
  436. /*op-extern-call end*/
  437. /*push-value begin*/
  438. subl $4,%edi
  439. movl $0,(%edi)
  440. /*push-value end*/
  441. leave
  442. ret
  443.  
  444.  
  445.