Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Forth in Node
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Zoom.Quiet
September 03, 2013
Programming
220
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Forth in Node
[符式協會:4759] Node.js hosts umbilical FORTH
Zoom.Quiet
September 03, 2013
Transcript
17 slides
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 • 歡迎提問!
More Decks by Zoom.Quiet
See All by Zoom.Quiet
PyCon2014China-Zhuhai-high performance
zoomquiet
0
220
PyCon2014China-Zhuhai-meta programming
zoomquiet
1
190
PyCon2014China-Zhuhai-bpm.py
zoomquiet
0
170
PyCon2014China-Zhuhai-luna kv db
zoomquiet
0
170
PyCon2014China-Zhuhai-seed studio
zoomquiet
0
170
PyCon2014China-Zhuhai-Docker Registry Build By Python
zoomquiet
0
180
PyCon2014China-Zhuhai-jeff
zoomquiet
0
170
PyCon2014China-Zhuhai-pythonic front-end
zoomquiet
0
230
DevFest2014-Zhuhai-Polymer
zoomquiet
0
510
Other Decks in Programming
See All in Programming
エラーチャンネルのボールを拾い続けて鍛えるエンジニアの地力 / phpcon-niigata2026
meihei3
1
530
Apache Airflow Introduction
leew
1
100
例外からRich Errorsまで Kotlinエラーハンドリングの進化を読み解く
shiita0903
0
250
止まらない比較を止める — 余帰納法で無限ストリームを比べる
tarao
0
220
React Native経験者が Flutterを30⽇間触って驚いたこと
3saito
0
210
どうしても Eloquent でリポジトリパターンをやりたいんだ #phpcon_niigata / phpcon-niigata-2026
shogogg
0
710
LLM 101
dalinaum
0
560
Claude Codeのおかげでやりたいことがやれるようになったんだよォー!
sms_tech
0
190
マルチプロダクトSaaSの アプリ一覧を速くする——複数プロダクトにまたがる「権限行脚」を減らすまで #techramen26conf
mktakuya
1
260
JavaScriptはシングルバイナリの夢を見るか / Does JavaScript Dream of a Single Binary?
ssssota
1
1.1k
エージェントの管理もエージェントに – herdr-core と自作バックログで作る司令塔 –
nearme_tech
PRO
2
170
はじめてのPLATEAU
nokonoko1203
1
680
Featured
See All Featured
So, you think you're a good person
axbom
PRO
2
2.3k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
1k
Writing Fast Ruby
sferik
630
63k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
870
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
850
Agile that works and the tools we love
rasmusluckow
331
22k
Art, The Web, and Tiny UX
lynnandtonic
304
22k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
68
61k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.8k
A Soul's Torment
seathinner
9
4k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
580
Being A Developer After 40
akosma
PRO
92
590k