Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Forth in Node
Search
Zoom.Quiet
September 03, 2013
Programming
2
190
Forth in Node
[符式協會:4759] Node.js hosts umbilical FORTH
Zoom.Quiet
September 03, 2013
Tweet
Share
More Decks by Zoom.Quiet
See All by Zoom.Quiet
PyCon2014China-Zhuhai-high performance
zoomquiet
0
180
PyCon2014China-Zhuhai-meta programming
zoomquiet
1
160
PyCon2014China-Zhuhai-bpm.py
zoomquiet
0
130
PyCon2014China-Zhuhai-luna kv db
zoomquiet
0
110
PyCon2014China-Zhuhai-seed studio
zoomquiet
0
120
PyCon2014China-Zhuhai-Docker Registry Build By Python
zoomquiet
0
150
PyCon2014China-Zhuhai-jeff
zoomquiet
0
110
PyCon2014China-Zhuhai-pythonic front-end
zoomquiet
0
150
DevFest2014-Zhuhai-Polymer
zoomquiet
0
450
Other Decks in Programming
See All in Programming
Understanding Apache Lucene - More than just full-text search
spinscale
0
120
技術検証結果の整理と解析をAIに任せよう!
keisukeikeda
0
120
Go 1.26でのsliceのメモリアロケーション最適化 / Go 1.26 リリースパーティ #go126party
mazrean
1
410
コーディングルールの鮮度を保ちたい / keep-fresh-go-internal-conventions
handlename
0
210
Codexに役割を持たせる 他のAIエージェントと組み合わせる実務Tips
o8n
4
1.3k
クライアントワークでSREをするということ。あるいは事業会社におけるSREと同じこと・違うこと
nnaka2992
1
340
仕様漏れ実装漏れをなくすトレーサビリティAI基盤のご紹介
orgachem
PRO
4
1.2k
Claude Codeログ基盤の構築
giginet
PRO
7
3.4k
AIに任せる範囲を安全に広げるためにやっていること
fukucheee
0
140
AI時代のシステム設計:ドメインモデルで変更しやすさを守る設計戦略
masuda220
PRO
5
1k
AI Assistants for Your Angular Solutions
manfredsteyer
PRO
0
140
CS教育のDX AIによる育成の効率化
niftycorp
PRO
0
140
Featured
See All Featured
Making the Leap to Tech Lead
cromwellryan
135
9.8k
Imperfection Machines: The Place of Print at Facebook
scottboms
269
14k
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.2k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
550
We Are The Robots
honzajavorek
0
200
Into the Great Unknown - MozCon
thekraken
40
2.3k
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
110
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
1.9k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8k
AI: The stuff that nobody shows you
jnunemaker
PRO
3
450
A Soul's Torment
seathinner
5
2.5k
Skip the Path - Find Your Career Trail
mkilby
1
80
Transcript
Node.js to host Umbilical FORTH 吳政昌 動程科技 2013/08/31
想一想 如何為遠在火星的好奇號開發程式?
臍帶式開發環境 • 整個開發環境分成 Host 端和 Target 端 • 開發工具在 Host
端。 • 透過通訊功能以及簡單的幾個指令,開發、測 試並執行 Target 端上的軟體。 • 經典:A 3-INSTRUCTION FORTH http://utoh. org/3ins4th.html • 只需要三個指令:XC@, XC!, XCALL • Host 和 Target 端都是 FORTH 系統
舊愛:FORTH,1984 • 裝置端,很適合用於控制設備 • 2-Stack Virtual machine • Operating system
• Scripting language • Cooperative multitasking • Asynchrounous programming • 於被用於 Open firmware (Mac), Actionscript • 一個人就可以理解、掌握
新歡:Javascript, Node.js, 2013 • 雲端 • Asynchronous programming • 目前受
Google, Microsoft, Oracle 支持 • 內建於 Google Drive, Window 8, Java 8 • 從網頁端下凡至伺服端的仙女:Node.js • 延續下凡的趨勢:愛死拼腦(Espruino), Javascript for Things
趨勢:從裝置端到雲端
運算的雲、製造的雲 • 雲就是霧茫茫看不清楚, 為數眾多的意思。 • Javascript 不真的適合最 後的一里路:裝置端。 • 最後一里是
C 或是專用 語言(如 PLC) 的天下。 • 兩端需要溝通。
解決方案:新歡舊愛,執其兩端 • umbilical jxForth
開發步驟 步驟二:建立臍帶式 Forth 開發環境 使用工具:node.js, objdump, EventEmitter, VT100 步驟一:產生 jxForth
映象。 使用工具:gcc, gas, node.js, PEG.js
步驟一:產生 jxForth 映象 • 撰寫 core.f,這是一個 FORTH 程式。 • 以
PEG.js 對 core.f 進行語法解析後,產生 core.S 以及 words.json 檔。 • 以 gcc 編譯及連結 main.c 及 core.S,得到 jxForth 映象。
PEG.js • Parsing expression gramma • 2004 by Bryan Ford
• Parsed in linear time • 不需要 tokenization step • Cannot be ambiguous • 最大的優勢:語言支援(C,C++,Java, Javascript, Python,Ruby,Lua,...) • 很適合用來開發領域語言(DSL)
建立臍帶式開發環境 1. 使用 objdump -t 及 words.json 建立 Target的 字典。
2. 以 <指令位址> x 方式要求 Target 執行指令。 3. Target 回傳的字串中,以 <host></host> 標記 的部份是下給 host 執行的指令。 4. 指令 sync。 5. 指令 dp!。
定義新指令 • TARGET 字典有變更時,DP 必須同步。
Host 和 Target 同步 • 事件:words.ready • 事件:sync • 當發生事件
words.ready 後,代表字典備妥, node.js 可以開使進入 repl。 (read-eval-print- loop) • 每執行一行(使用者按 Enter),將此行解譯送 給 target ,要求 target 於完成後執行 sync,等 待 sync 事件。 • 當發生 sync 事件時,再執行一次 repl。
Line Editor • REPL 迴圈需要一個 line editor。 • Node.js 的
readline 不好用。 • Line Editor 是什麼? • var editor = new EventEmitter(); • Editor 將標準輸入設為 Raw mode,並且監聽 input 的 data 事件,以便讀取每個按鍵。 • Editor 會發出 ^C, ^D, backspace, enter 事 件。 • Editor 監聽自己的 ^C,^D,backspace,enter 事 件,並執行預設的行為。
VT100 • 使用以下三個 VT100 的 control sequence。 • var vt100_backward
= '\x1B[D'; • var vt100_erase_end_of_line = '\x1B[K'; • var bell = '\x07';
結論 • 秀一下。 • 程式在 http://projects.mapacode. tw/jxforth/doc/trunk/doc/wiki/index.wiki • 歡迎提問!