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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
170
PyCon2014China-Zhuhai-meta programming
zoomquiet
1
160
PyCon2014China-Zhuhai-bpm.py
zoomquiet
0
130
PyCon2014China-Zhuhai-luna kv db
zoomquiet
0
100
PyCon2014China-Zhuhai-seed studio
zoomquiet
0
120
PyCon2014China-Zhuhai-Docker Registry Build By Python
zoomquiet
0
140
PyCon2014China-Zhuhai-jeff
zoomquiet
0
110
PyCon2014China-Zhuhai-pythonic front-end
zoomquiet
0
140
DevFest2014-Zhuhai-Polymer
zoomquiet
0
440
Other Decks in Programming
See All in Programming
責任感のあるCloudWatchアラームを設計しよう
akihisaikeda
3
160
Rust 製のコードエディタ “Zed” を使ってみた
nearme_tech
PRO
0
140
CSC307 Lecture 05
javiergs
PRO
0
490
生成AIを使ったコードレビューで定性的に品質カバー
chiilog
1
240
コマンドとリード間の連携に対する脅威分析フレームワーク
pandayumi
1
450
Lambda のコードストレージ容量に気をつけましょう
tattwan718
0
110
15年続くIoTサービスのSREエンジニアが挑む分散トレーシング導入
melonps
2
170
FOSDEM 2026: STUNMESH-go: Building P2P WireGuard Mesh Without Self-Hosted Infrastructure
tjjh89017
0
150
AI時代の認知負荷との向き合い方
optfit
0
140
LLM Observabilityによる 対話型音声AIアプリケーションの安定運用
gekko0114
2
420
Package Management Learnings from Homebrew
mikemcquaid
0
200
疑似コードによるプロンプト記述、どのくらい正確に実行される?
kokuyouwind
0
380
Featured
See All Featured
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
62
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
0
140
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
50
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
730
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.6k
AI: The stuff that nobody shows you
jnunemaker
PRO
2
240
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
How Software Deployment tools have changed in the past 20 years
geshan
0
32k
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.3k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
21k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
61k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
120
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 • 歡迎提問!