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
Zoom.Quiet
September 03, 2013
Programming
210
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
More Decks by Zoom.Quiet
See All by Zoom.Quiet
PyCon2014China-Zhuhai-high performance
zoomquiet
0
210
PyCon2014China-Zhuhai-meta programming
zoomquiet
1
180
PyCon2014China-Zhuhai-bpm.py
zoomquiet
0
160
PyCon2014China-Zhuhai-luna kv db
zoomquiet
0
160
PyCon2014China-Zhuhai-seed studio
zoomquiet
0
150
PyCon2014China-Zhuhai-Docker Registry Build By Python
zoomquiet
0
170
PyCon2014China-Zhuhai-jeff
zoomquiet
0
160
PyCon2014China-Zhuhai-pythonic front-end
zoomquiet
0
200
DevFest2014-Zhuhai-Polymer
zoomquiet
0
490
Other Decks in Programming
See All in Programming
C#の現在地 進化の歴史と、AI時代の.NET Everywhere
neuecc
5
4.9k
contenteditable と日本語入力に向き合う
colorful12
0
100
なぜCTOを降りてFDEを選んだのか?〜なぜプロダクト企業がFDEで顧客の現場に踏み込むのか〜
gonta
1
150
カツオ、ご期待ください
suneo3476
0
150
スマートフォンでモールス信号を送受信する 〜スマートフォンのLEDとカメラで作る光通信の設計と実装〜
atsuki_seo
0
230
[ハンズオン]AIへの指示だけで「五目並べ」を作ってみよう
satoshi256kbyte
1
340
ジョジョの世界をXRで再現する
mofurune
0
110
AI Agent時代のリアーキテクチャ戦略と実践
hokaccha
9
5.4k
Findy - エンジニア向け会社紹介/Findy Company Deck
findyinc
6
400k
残高管理から台帳サービスへの進化
artoy
0
140
モバイル交通系ICへのチャージ実例から考える、クロスプラットフォーム開発におけるiOS実機テスト設計とCI運用
yusuga
1
580
Androidだけじゃない、DroidKaigiで広がった私の技術スタック
akkeylab
0
120
Featured
See All Featured
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
320
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
[RailsConf 2023] Rails as a piece of cake
palkan
59
7.1k
Paper Plane
katiecoart
PRO
4
53k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
400
Believing is Seeing
oripsolob
1
240
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Everyday Curiosity
cassininazir
0
340
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
56
3.5k
Bash Introduction
62gerente
615
220k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.2k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
920
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 • 歡迎提問!