cps
This commit is contained in:
Binary file not shown.
@@ -1,4 +0,0 @@
|
||||
;;; -*- mode:scheme -*-
|
||||
|
||||
(let ((x0 (prim:write "wawa"))) x0)
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
.data
|
||||
.balign 8
|
||||
.1:
|
||||
.ascii "wawa"
|
||||
/* end data */
|
||||
|
||||
.text
|
||||
.globl main
|
||||
main:
|
||||
pushq %rbp
|
||||
movq %rsp, %rbp
|
||||
movl $4, %esi
|
||||
leaq .1(%rip), %rdi
|
||||
callq scm_from_utf8_string
|
||||
movq %rax, %rdi
|
||||
callq scm_write
|
||||
leave
|
||||
ret
|
||||
.type main, @function
|
||||
.size main, .-main
|
||||
/* end function main */
|
||||
|
||||
.section .note.GNU-stack,"",@progbits
|
||||
@@ -1 +0,0 @@
|
||||
(prim:write "wawa")
|
||||
@@ -1,10 +0,0 @@
|
||||
|
||||
data $.1 =
|
||||
{b "wawa"}
|
||||
export
|
||||
function w $main () {
|
||||
@start
|
||||
%.2 =l call $scm_from_utf8_string (l $.1, l 4)
|
||||
%x0 =l call $scm_write (l %.2)
|
||||
ret %x0
|
||||
}
|
||||
Binary file not shown.
@@ -1,4 +0,0 @@
|
||||
;;; -*- mode:scheme -*-
|
||||
|
||||
(let ((x0 (prim:cons 4 5)) (x1 (prim:write x0))) x1)
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
.text
|
||||
.globl main
|
||||
main:
|
||||
pushq %rbp
|
||||
movq %rsp, %rbp
|
||||
movl $16, %edi
|
||||
callq GC_malloc
|
||||
movq %rax, %rdi
|
||||
movq $18, (%rdi)
|
||||
movq $22, 8(%rdi)
|
||||
callq scm_write
|
||||
leave
|
||||
ret
|
||||
.type main, @function
|
||||
.size main, .-main
|
||||
/* end function main */
|
||||
|
||||
.section .note.GNU-stack,"",@progbits
|
||||
@@ -1 +0,0 @@
|
||||
(prim:write (prim:cons 4 5))
|
||||
@@ -1,10 +0,0 @@
|
||||
export
|
||||
function w $main () {
|
||||
@start
|
||||
%x0 =l call $GC_malloc (l 16)
|
||||
%.2 =l add %x0, 8
|
||||
storel 18, %x0
|
||||
storel 22, %.2
|
||||
%x1 =l call $scm_write (l %x0)
|
||||
ret %x1
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
(define (adder x)
|
||||
(lambda (y)
|
||||
(+ x y)))
|
||||
|
||||
((adder 3) 4)
|
||||
|
||||
|
||||
|
||||
(define (adder x)
|
||||
(list (lambda (self y)
|
||||
(+ (nth self 1) y))
|
||||
x))
|
||||
|
||||
(let ((closure (adder 3)))
|
||||
((nth closure 0) closure 4))
|
||||
@@ -1,70 +0,0 @@
|
||||
.text
|
||||
zerop:
|
||||
pushq %rbp
|
||||
movq %rsp, %rbp
|
||||
cmpl $0, %edi
|
||||
jnz .Lbb2
|
||||
movl $1, %eax
|
||||
jmp .Lbb3
|
||||
.Lbb2:
|
||||
movl $0, %eax
|
||||
.Lbb3:
|
||||
leave
|
||||
ret
|
||||
.type zerop, @function
|
||||
.size zerop, .-zerop
|
||||
/* end function zerop */
|
||||
|
||||
.text
|
||||
factorial:
|
||||
pushq %rbp
|
||||
movq %rsp, %rbp
|
||||
subq $8, %rsp
|
||||
pushq %rbx
|
||||
movq %rdi, %rbx
|
||||
callq zerop
|
||||
movq %rbx, %rdi
|
||||
cmpl $0, %eax
|
||||
jnz .Lbb6
|
||||
movq %rdi, %rbx
|
||||
subq $1, %rdi
|
||||
callq factorial
|
||||
movq %rbx, %rdi
|
||||
imulq %rdi, %rax
|
||||
jmp .Lbb7
|
||||
.Lbb6:
|
||||
movl $1, %eax
|
||||
.Lbb7:
|
||||
popq %rbx
|
||||
leave
|
||||
ret
|
||||
.type factorial, @function
|
||||
.size factorial, .-factorial
|
||||
/* end function factorial */
|
||||
|
||||
.data
|
||||
.balign 8
|
||||
fstr:
|
||||
.ascii "fac 3 = %d\n"
|
||||
.byte 0
|
||||
/* end data */
|
||||
|
||||
.text
|
||||
.globl main
|
||||
main:
|
||||
pushq %rbp
|
||||
movq %rsp, %rbp
|
||||
movl $3, %edi
|
||||
callq factorial
|
||||
movq %rax, %rsi
|
||||
leaq fstr(%rip), %rdi
|
||||
movl $0, %eax
|
||||
callq printf
|
||||
movl $0, %eax
|
||||
leave
|
||||
ret
|
||||
.type main, @function
|
||||
.size main, .-main
|
||||
/* end function main */
|
||||
|
||||
.section .note.GNU-stack,"",@progbits
|
||||
@@ -1,16 +0,0 @@
|
||||
(define (factorial n)
|
||||
(if (zero? n)
|
||||
1
|
||||
(* n (factorial (- n 1)))))
|
||||
|
||||
|
||||
;;; ANF
|
||||
|
||||
(define (factorial n)
|
||||
(let ((r₁ (zero? n)))
|
||||
(if r₁
|
||||
1
|
||||
(let ((r₂ (- n 1))
|
||||
(r₃ (factorial r₂))
|
||||
(r₄ (* n r₃)))
|
||||
r₄))))
|
||||
@@ -1,30 +0,0 @@
|
||||
function l $zerop (l %n) {
|
||||
@start
|
||||
jnz %n, @b1, @b2
|
||||
@b1
|
||||
ret 0
|
||||
@b2
|
||||
ret 1
|
||||
}
|
||||
|
||||
function l $factorial (l %n) {
|
||||
@start
|
||||
%r1 =l call $zerop (l %n)
|
||||
jnz %r1, @b1, @b2
|
||||
@b1
|
||||
ret 1
|
||||
@b2
|
||||
%r2 =l sub %n, 1
|
||||
%r3 =l call $factorial (l %r2)
|
||||
%r4 =l mul %n, %r3
|
||||
ret %r4
|
||||
}
|
||||
|
||||
data $fstr = { b "fac 3 = %d\n", b 0 }
|
||||
|
||||
export function w $main () {
|
||||
@start
|
||||
%r =l call $factorial (l 3)
|
||||
call $printf (l $fstr, ..., l %r)
|
||||
ret 0
|
||||
}
|
||||
Binary file not shown.
@@ -1,4 +0,0 @@
|
||||
;;; -*- mode:scheme -*-
|
||||
|
||||
(let ((x0 (prim:write "안녕하세요"))) x0)
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
.data
|
||||
.balign 8
|
||||
.1:
|
||||
.ascii "\354\225\210\353\205\225\355\225\230\354\204\270\354\232\224"
|
||||
/* end data */
|
||||
|
||||
.text
|
||||
.globl main
|
||||
main:
|
||||
pushq %rbp
|
||||
movq %rsp, %rbp
|
||||
movl $15, %esi
|
||||
leaq .1(%rip), %rdi
|
||||
callq scm_from_utf8_string
|
||||
movq %rax, %rdi
|
||||
callq scm_write
|
||||
leave
|
||||
ret
|
||||
.type main, @function
|
||||
.size main, .-main
|
||||
/* end function main */
|
||||
|
||||
.section .note.GNU-stack,"",@progbits
|
||||
@@ -1 +0,0 @@
|
||||
(prim:write "안녕하세요")
|
||||
@@ -1,10 +0,0 @@
|
||||
|
||||
data $.1 =
|
||||
{b "\354\225\210\353\205\225\355\225\230\354\204\270\354\232\224"}
|
||||
export
|
||||
function w $main () {
|
||||
@start
|
||||
%.2 =l call $scm_from_utf8_string (l $.1, l 15)
|
||||
%x0 =l call $scm_write (l %.2)
|
||||
ret %x0
|
||||
}
|
||||
Reference in New Issue
Block a user