Posted to tcl by gps at Tue Mar 31 06:01:48 GMT 2009view raw
- Have you seen those 1960's era demos with the inventor of the mouse?
- I was thinking it would be useful to be able to have layers of code in some hypertext format, somewhat like MOL.
- 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.
- It might go something like toplevel-command -> implementation commands -> assembly language.
- How could I structure the source code to enable this?
- Do any of you know how they did that in NLS?
- extern puti
- extern putn
- extern ok
- extern failed
- extern putstr
- : factorial
- declare n
- *n ->
- n 1 <=
- if 1 return
- else n 1 - factorial n * return
- then
- ;;
- : run
- declare r1
- declare r2
- declare r3
- 3 factorial *r1 ->
- 4 factorial *r2 ->
- 5 factorial *r3 ->
- 3 puti " = " putstr r1 puti putn
- 4 puti " = " putstr r2 puti putn
- 5 puti " = " putstr r3 puti putn
- r1 6 = if ok else failed then putn
- r2 24 = if ok else failed then putn
- r3 120 = if ok else failed then putn
- 0
- ;;
- .globl factorial
- factorial:
- pushl %ebp
- movl %esp,%ebp
- /*declare begin*/
- subl $4,%esp
- /*declare end*/
- /*push-local begin*/
- subl $4,%edi
- leal -4(%ebp),%ecx
- movl %ecx,(%edi)
- /*push-local end*/
- /*op-> begin*/
- movl (%edi),%eax
- addl $4,%edi
- movl (%edi),%ecx
- movl %ecx,(%eax)
- addl $4,%edi
- /*op-> end*/
- /*push-local begin*/
- subl $4,%edi
- movl -4(%ebp),%ecx
- movl %ecx,(%edi)
- /*push-local end*/
- /*push-value begin*/
- subl $4,%edi
- movl $1,(%edi)
- /*push-value end*/
- /* op-<= begin */
- /*op-cmp2 begin*/
- movl (%edi),%eax
- addl $4,%edi
- movl (%edi),%ecx
- addl $4,%edi
- cmpl %eax,%ecx
- /*op-cmp2 end*/
- movl $0,%esi
- movl $-1,%edx
- cmovle %edx,%esi
- subl $4,%edi
- movl %esi,(%edi)
- /* op-<= end */
- /*op-if begin*/
- mov (%edi),%eax
- addl $4,%edi
- cmpl $0,%eax
- je ___else_2
- /*op-if end*/
- /*push-value begin*/
- subl $4,%edi
- movl $1,(%edi)
- /*push-value end*/
- /*op-return begin*/
- leave
- ret
- /*op-return end*/
- /* op-else begin */
- jmp ___then_1
- ___else_2:
- /* op-else end */
- /*push-local begin*/
- subl $4,%edi
- movl -4(%ebp),%ecx
- movl %ecx,(%edi)
- /*push-local end*/
- /*push-value begin*/
- subl $4,%edi
- movl $1,(%edi)
- /*push-value end*/
- /*op- begin*/
- movl (%edi),%eax
- addl $4,%edi
- subl %eax,(%edi)
- /*op- end*/
- /*op-extern-call begin*/
- call factorial
- /*op-extern-call end*/
- /*push-local begin*/
- subl $4,%edi
- movl -4(%ebp),%ecx
- movl %ecx,(%edi)
- /*push-local end*/
- /*op-* begin*/
- movl (%edi),%eax
- xorl %edx,%edx
- addl $4,%edi
- movl (%edi),%ebx
- imul %ebx
- movl %eax,(%edi)
- /*op-* end*/
- /*op-return begin*/
- leave
- ret
- /*op-return end*/
- /*op-then begin*/
- ___then_1:
- /*op-then end*/
- leave
- ret
- .globl run
- run:
- pushl %ebp
- movl %esp,%ebp
- /*declare begin*/
- subl $4,%esp
- /*declare end*/
- /*declare begin*/
- subl $4,%esp
- /*declare end*/
- /*declare begin*/
- subl $4,%esp
- /*declare end*/
- /*push-value begin*/
- subl $4,%edi
- movl $3,(%edi)
- /*push-value end*/
- /*op-extern-call begin*/
- call factorial
- /*op-extern-call end*/
- /*push-local begin*/
- subl $4,%edi
- leal -4(%ebp),%ecx
- movl %ecx,(%edi)
- /*push-local end*/
- /*op-> begin*/
- movl (%edi),%eax
- addl $4,%edi
- movl (%edi),%ecx
- movl %ecx,(%eax)
- addl $4,%edi
- /*op-> end*/
- /*push-value begin*/
- subl $4,%edi
- movl $4,(%edi)
- /*push-value end*/
- /*op-extern-call begin*/
- call factorial
- /*op-extern-call end*/
- /*push-local begin*/
- subl $4,%edi
- leal -8(%ebp),%ecx
- movl %ecx,(%edi)
- /*push-local end*/
- /*op-> begin*/
- movl (%edi),%eax
- addl $4,%edi
- movl (%edi),%ecx
- movl %ecx,(%eax)
- addl $4,%edi
- /*op-> end*/
- /*push-value begin*/
- subl $4,%edi
- movl $5,(%edi)
- /*push-value end*/
- /*op-extern-call begin*/
- call factorial
- /*op-extern-call end*/
- /*push-local begin*/
- subl $4,%edi
- leal -12(%ebp),%ecx
- movl %ecx,(%edi)
- /*push-local end*/
- /*op-> begin*/
- movl (%edi),%eax
- addl $4,%edi
- movl (%edi),%ecx
- movl %ecx,(%eax)
- addl $4,%edi
- /*op-> end*/
- /*push-value begin*/
- subl $4,%edi
- movl $3,(%edi)
- /*push-value end*/
- /*op-extern-call begin*/
- call puti
- /*op-extern-call end*/
- .section .rodata
- .align 4
- ___quote_3: .long 3
- .byte 0x20, 0x3d, 0x20
- .text
- subl $4,%edi
- movl $___quote_3,(%edi)
- /*op-extern-call begin*/
- call putstr
- /*op-extern-call end*/
- /*push-local begin*/
- subl $4,%edi
- movl -4(%ebp),%ecx
- movl %ecx,(%edi)
- /*push-local end*/
- /*op-extern-call begin*/
- call puti
- /*op-extern-call end*/
- /*op-extern-call begin*/
- call putn
- /*op-extern-call end*/
- /*push-value begin*/
- subl $4,%edi
- movl $4,(%edi)
- /*push-value end*/
- /*op-extern-call begin*/
- call puti
- /*op-extern-call end*/
- .section .rodata
- .align 4
- ___quote_4: .long 3
- .byte 0x20, 0x3d, 0x20
- .text
- subl $4,%edi
- movl $___quote_4,(%edi)
- /*op-extern-call begin*/
- call putstr
- /*op-extern-call end*/
- /*push-local begin*/
- subl $4,%edi
- movl -8(%ebp),%ecx
- movl %ecx,(%edi)
- /*push-local end*/
- /*op-extern-call begin*/
- call puti
- /*op-extern-call end*/
- /*op-extern-call begin*/
- call putn
- /*op-extern-call end*/
- /*push-value begin*/
- subl $4,%edi
- movl $5,(%edi)
- /*push-value end*/
- /*op-extern-call begin*/
- call puti
- /*op-extern-call end*/
- .section .rodata
- .align 4
- ___quote_5: .long 3
- .byte 0x20, 0x3d, 0x20
- .text
- subl $4,%edi
- movl $___quote_5,(%edi)
- /*op-extern-call begin*/
- call putstr
- /*op-extern-call end*/
- /*push-local begin*/
- subl $4,%edi
- movl -12(%ebp),%ecx
- movl %ecx,(%edi)
- /*push-local end*/
- /*op-extern-call begin*/
- call puti
- /*op-extern-call end*/
- /*op-extern-call begin*/
- call putn
- /*op-extern-call end*/
- /*push-local begin*/
- subl $4,%edi
- movl -4(%ebp),%ecx
- movl %ecx,(%edi)
- /*push-local end*/
- /*push-value begin*/
- subl $4,%edi
- movl $6,(%edi)
- /*push-value end*/
- /* op-= begin */
- /*op-cmp2 begin*/
- movl (%edi),%eax
- addl $4,%edi
- movl (%edi),%ecx
- addl $4,%edi
- cmpl %eax,%ecx
- /*op-cmp2 end*/
- movl $0,%eax
- movl $-1,%ecx
- cmove %ecx,%eax
- subl $4,%edi
- movl %eax,(%edi)
- /* op-= end */
- /*op-if begin*/
- mov (%edi),%eax
- addl $4,%edi
- cmpl $0,%eax
- je ___else_7
- /*op-if end*/
- /*op-extern-call begin*/
- call ok
- /*op-extern-call end*/
- /* op-else begin */
- jmp ___then_6
- ___else_7:
- /* op-else end */
- /*op-extern-call begin*/
- call failed
- /*op-extern-call end*/
- /*op-then begin*/
- ___then_6:
- /*op-then end*/
- /*op-extern-call begin*/
- call putn
- /*op-extern-call end*/
- /*push-local begin*/
- subl $4,%edi
- movl -8(%ebp),%ecx
- movl %ecx,(%edi)
- /*push-local end*/
- /*push-value begin*/
- subl $4,%edi
- movl $24,(%edi)
- /*push-value end*/
- /* op-= begin */
- /*op-cmp2 begin*/
- movl (%edi),%eax
- addl $4,%edi
- movl (%edi),%ecx
- addl $4,%edi
- cmpl %eax,%ecx
- /*op-cmp2 end*/
- movl $0,%eax
- movl $-1,%ecx
- cmove %ecx,%eax
- subl $4,%edi
- movl %eax,(%edi)
- /* op-= end */
- /*op-if begin*/
- mov (%edi),%eax
- addl $4,%edi
- cmpl $0,%eax
- je ___else_9
- /*op-if end*/
- /*op-extern-call begin*/
- call ok
- /*op-extern-call end*/
- /* op-else begin */
- jmp ___then_8
- ___else_9:
- /* op-else end */
- /*op-extern-call begin*/
- call failed
- /*op-extern-call end*/
- /*op-then begin*/
- ___then_8:
- /*op-then end*/
- /*op-extern-call begin*/
- call putn
- /*op-extern-call end*/
- /*push-local begin*/
- subl $4,%edi
- movl -12(%ebp),%ecx
- movl %ecx,(%edi)
- /*push-local end*/
- /*push-value begin*/
- subl $4,%edi
- movl $120,(%edi)
- /*push-value end*/
- /* op-= begin */
- /*op-cmp2 begin*/
- movl (%edi),%eax
- addl $4,%edi
- movl (%edi),%ecx
- addl $4,%edi
- cmpl %eax,%ecx
- /*op-cmp2 end*/
- movl $0,%eax
- movl $-1,%ecx
- cmove %ecx,%eax
- subl $4,%edi
- movl %eax,(%edi)
- /* op-= end */
- /*op-if begin*/
- mov (%edi),%eax
- addl $4,%edi
- cmpl $0,%eax
- je ___else_11
- /*op-if end*/
- /*op-extern-call begin*/
- call ok
- /*op-extern-call end*/
- /* op-else begin */
- jmp ___then_10
- ___else_11:
- /* op-else end */
- /*op-extern-call begin*/
- call failed
- /*op-extern-call end*/
- /*op-then begin*/
- ___then_10:
- /*op-then end*/
- /*op-extern-call begin*/
- call putn
- /*op-extern-call end*/
- /*push-value begin*/
- subl $4,%edi
- movl $0,(%edi)
- /*push-value end*/
- leave
- ret