所有網頁 圖片 影片 地圖 新聞 網誌搜尋 Gmail 更多 »
最近造訪的群組 | 說明 | 登入
Google 網上論壇首頁
群組資訊
成員: 100
語言: 中文 (繁體)
群組類別:
藝術文化
科技學術
電腦資訊
更多群組資訊 »
Studying forth meta compiling (大家來Wiki)    
2008/10/21 
08:31 

我現在有心花點時間來理解 forth 的 meta compiling. 想像中,就是把用 forth 開發好的東西抽出有用到的 words 變成固定用途、瘦身版的 executable。 我反正要寫筆記的,時代不一樣了,網路已經很穩,服務又好,筆記應該要 wiki 才對。Here it is ..... let's go .......


15:31 

找到了! 

c:\FPC\HLP\CHAPTER7.TXT  : 

We can build batch files this way.  As you can see, many types of
commands could be given to F- PC on the command line.  Here are the
contents of the FMETA.BAT:

        F-PC  -  FLOAD  META86

This single line batch file meta-compiles the F-PC kernel file and
creates the KERNEL.COM file. A similar batch file EXTEND.BAT is provided
to extend the the kernel into a full featured F-PC system.  There are a
number of batch files in the F-PC system and they are good examples of
how to call F-PC to perform various tasks in the DOS environment and then
return automatically to DOS.  It is a valuable tool for building
customized applications.
 

15:37

Execute  C:\FPC\> F-PC  -  FLOAD  META86  on Vista DOS box got an divide overflow error. Use Bochs virtual machine with a smaller HDD to try again ... (Google Groups 的「檔案」功能怎麼好差勁! 放個 ~.gif 檔貼圖問題重重,只好先把圖片暫存到 Google Sites 轉貼過來才 ok !)


16:28

Office "D:\Learnings\Bochs\image\FPC run.bat"

改用 Bochs 虛擬環境, HDD 設小一點, 不要超過當年的上限 512MB 輕易 OK 了。 一下子就產生了一個 kernel.com file size 35964 bytes (I use FPC 3.6). 試著執行剛剛學會的 F-PC command line 

 

c:\FPC> kernel - 1 2 3 4 5 .s bye

 [5]      2       3       4       5  Leaving..
c:\FPC>

 

It works fine.  

 

剛剛在 compile 好 kernel.com 之後, 畫面上有句話,要我在 DOS 下執行 extend 。 不知是幹啥的? 做了再說 . . .

 

C:\FPC>extend

C:\FPC>KERNEL - FLOAD F-PC.SEQ  save-exe f-pc.exe .s bye
Loading the extensions to KERNEL.COM, with all HEADERS PRESENT.
.............................................
.........................................

Elapsed time   =  00:00:05.99
Total lines compiled  = 12971
Compiled lines/minute = 129830

  CODE    LIST   HEAD   TOTAL  bytes used
 33714   95440  42547  171701
 Stack Empty.  Leaving..
C:\FPC>

What happened?
Wow !  It generated a "f-pc.exe   171856 bytes"  in a very short time (In Bochs VM besides). Try to run it. I see the F-PC greeting screen as usual, but the date time become NOW,  wa ha ha  好玩好玩 !

 

17:29

下面這段話值得銘記在心。他是來幫我呢?還是來嚇倒我呢? 

c:\FPC\HLP\CHAPTER9.TXT  

Meta compilation the is the darkest art in Forth.  Do not be fooled by the
above simple discussions to think that meta compilation can be practiced
easily.  You have to understand F-PC completely to made modifications in
the kernel files to rebuild a Forth to your own liking.  Only Tom Zimmer
is entrusted to make modification to F-PC.  Nevertheless, you have all
the source code and the tools to roll your own Forth in F-PC.

17:55

再往下看 c:\FPC\HLP\CHAPTER9.TXT , 發現 f-pc 有完備的 target executable 產生方式。 Meta compiling , Turnkey system, Fsave。 我認為日常寫自己的應用程式三者都不必用到,用 F-PC 的 command line 拉你的 ~.seq 進來,然後指定要執行的 word , bye 即可。

 

21:31

Compile 出 kernel.com 是我最感興趣的。 該 kernel.com 真的很精簡, 'words' 它不認得,不知道它 supports 那些 words ? 我看了一下 kernel.com 的 source c:\FPC\SRC\META86.SEQ 目前還看不懂。

 

試用 fsave command 很有趣。 寫一個 new word 


    : hi  cr ." Hello World !! " cr ;

    fsave hi

    bye


這樣就得到一個 hi.exe 了,執行  hi - hi bye 就印出了 " Hello world !! " 。 寫程式這麼簡單還真是平生未見! 我前面已經 trace 過「空殼子 eforth」, 猜也猜得到 F-PC 應該有這樣的能力。親手真的實驗出來了,還是覺得很驚奇。

 

21:39

許願:

fsave 很爽,可是 hi.exe 172KB 太肥了,想到裡面還拖帶著根本用不著的 SED 很不甘心。我希望能掌握 meta compiling 的應用能力就好,如此可以弄出個量身訂做的 F-PC,只含我會用到的必要 words,程式寫好 fsave 一下就 ok,那真是太美了。 話說回來,即使用 172kb 的 f-pc 也可以滿意了,現成的呀!

 

 

2008/12/10
22:38
下面這段 F-PC v3.6 裡面所附的說明書 chapter 4 (c:\FPC\HLP\CHAPTER4.TXT ) 裡的文字正是我要找的東西 ... target compiler :

  It only compiles what is needed in the application and discards Forth words which are not used by the application.
 
Tom Zimmer  當年是打算要對這個 Target COMpiler 收費的。時至今日,早就免費奉送了。

blabla
Title
paragraph
blabla
Title
paragraph
blabla
Title
paragraph
blabla
Title
paragraph
blabla
版本: 
建立群組 - Google 網上論壇 - Google 首頁 - 服務條款 - 隱私權政策
©2009 Google