More Related Content
PPTX
PDF
PPTX
PDF
PPTX
PDF
120414 foss4g nagoya_presentation2 PDF
PPTX
Viewers also liked
PPTX
PDF
PPTX
Analog Devices の IP コアを使う PDF
How to Make Awesome SlideShares: Tips & Tricks PPTX
PDF
Getting Started With SlideShare PPTX
Synthesijer で作るFORTH仮想マシン PDF
Continuation Passing Style and Macros in Clojure - Jan 2012 PPTX
PPTX
Similar to 20周遅れ
PDF
PDF
PDF
Adding simpl GVN path into GHC PPTX
MISRA-C2012とISO/IEC 9899:2011 at OSCNagoya2013 PPT
PPT
PPT
PPTX
PDF
PDF
PPT
PDF
PDF
PPT
KEY
サイボウズ・ラボユース 最終成果報告会プレゼンテーション PDF
PPTX
Ocaml lecture slides 01 at axsh PDF
PPTX
PPT
Parsing Left Recursive PEG More from ryos36
PPTX
Stellaris を使った組み込みアプリ開発ガイド PPTX
PPTX
研究者のための Python による FPGA 入門 PPTX
PPTX
PPTX
Polyphony: Python ではじめる FPGA PDF
PPTX
PPTX
PPTX
PPTX
PPTX
PPTX
Recently uploaded
PPTX
JavaScript/TypeScript実力強化書 2章のアップデート Forkwell Library PDF
20251122_OWASPNagoya_takei_ITU-T,X.1060,security PDF
最高峰のストレージとバックアップ:ARTESCA+Veeam:統合型ソフトウェア PDF
N2WS Backup & Recovery と Veeam Backup for AWS PDF
Veeam&WasabiでトリプルV: クラウドへのランサムウエア対策の決定コンビ PDF
Gluesync:RDBMS、NoSQL,データレイク間のリアルタイム・データレプリケーション 20周遅れ
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
mini-scheme → CPS
•再帰を使った階乗の例
(:fix ((fact (n)
(:if (:= n 0)
1
(:* n (fact (:- n 1))))))
(fact 10))
(:FIXH
((FACT (|sym1| N)
(:FIXS ((|sym2| (|sym3|) (:APP |sym1| (|sym3|))))
(:= (N 0) NIL
((:APP |sym2| (1))
(:- (N 1) (|sym7|)
((:FIXS
((|sym5| (|sym6|) (:* (N |sym6|) (|sym4|) ((:APP |sym2|
(|sym4|))))))
(:APP FACT (|sym5| |sym7|))))))))))
(:FIXS ((|sym8| (|sym9|) (:APP EXIT (|sym9|)))) (:APP FACT
(|sym8| 10))))
- 8.
CPS → CPS(η-Reduction)
•再帰を使った階乗の例
(:FIXH
((FACT (|sym1| N)
(:FIXS ((|sym2| (|sym3|) (:APP |sym1| (|sym3|))))
(:= (N 0) NIL
((:APP |sym2| (1))
(:- (N 1) (|sym7|)
((:FIXS
((|sym5| (|sym6|) (:* (N |sym6|) (|sym4|) ((:APP |sym2|
(|sym4|))))))
(:APP FACT (|sym5| |sym7|))))))))))
(:FIXS ((|sym8| (|sym9|) (:APP EXIT (|sym9|)))) (:APP FACT
(|sym8| 10))))
(:FIXH
((FACT (|sym1| N)
(:= (N 0) NIL
((:APP |sym1| (1))
(:- (N 1) (|sym7|)
((:FIXS
((|sym5| (|sym6|) (:* (N |sym6|) (|sym4|) ((:APP |sym1|
(|sym4|))))))
(:APP FACT (|sym5| |sym7|)))))))))
(:APP FACT (EXIT 10)))
- 9.
CPS→ VM
• 再帰を使った階乗の例
(:FIXH
((FACT(|sym1| N)
(:= (N 0) NIL
((:APP |sym1| (1))
(:- (N 1) (|sym7|)
((:FIXS
((|sym5| (|sym6|) (:* (N |sym6|) (|sym4|) ((:APP |sym1|
(|sym4|))))))
(:APP FACT (|sym5| |sym7|)))))))))
(:APP FACT (EXIT 10)))
((:JUMP (:LABEL |:MAIN|)) MAIN (:CONST (:LABEL |:MAIN|)) EXIT
(:CONST (:LABEL |:EXIT|)) |:EXIT| (:HALT :R1) |:MAIN|
(:JUMP (:LABEL |:label0|)) (:LIVE-REG 0 (1 1 1 0 0 0 0 0 0 0)) |:FACT|
(:= :R2 0) (:CONDITIONAL-JUMP (:LABEL |:label1|)) (:- :R2 1 :R9)
(:JUMP (:LABEL |:label2|)) (:LIVE-REG 0 (1 1 0 0 0 0 0 0 0 0)) |:sym5|
(:RECORD-REF :R0 2 :R9) (:RECORD-REF :R0 1 :R8) (:POP 3) (:* :R8 :R1 :R1)
(:RECORD-REF :R9 0 :R8) (:MOVE :R9 :R0) (:JUMP :R8) |:label2|
(:STACK (:HEAP-LIST (:LABEL |:sym5|) :R2 :R1) :R1) (:RECORD-REF :R0 0 :R8)
(:MOVE :R9 :R2) (:JUMP :R8) |:label1| (:RECORD-REF :R1 0 :R9)
(:MOVE :R1 :R0)
(:MOVEI 1 :R1) (:JUMP :R9) |:label0|
(:HEAP (:HEAP-LIST (:LABEL |:FACT|)) :R9) (:RECORD-REF :R9 0 :R8)
(:MOVE :R9 :R0) (:MOVEI (:ADDRESS EXIT) :R1) (:MOVEI 10 :R2) (:JUMP :R8))
- 10.
VM も作った
• vmgen(gforth)でつくった VM (抜粋)
stack definitions:
E stack data-stack sp Cell
E s" Operand" single inst-stream type-prefix operand
E s" Imm" single inst-stream type-prefix imm
E s" Cell" single data-stack type-prefix s
----------------------------------------------------------------
add ( operand -- )
regs[operand.r2] = regs[operand.r0] + regs[operand.r1];
addi8 ( operand -- )
regs[operand.r2] = regs[operand.r0] + operand.r1;
addi32 ( operand imm32 -- )
regs[operand.r2] = regs[operand.r0] + imm32;
----------------------------------------------------------------
sub ( operand -- )
regs[operand.r2] = regs[operand.r0] - regs[operand.r1];
subi8 ( operand -- )
regs[operand.r2] = regs[operand.r0] - operand.r1;
- 11.
- 12.
- 13.
- 14.