./index.html ../index.html

Modula-3に挑戦した時の記録

Delphiよりも以前のObject Pascalプラス、コルーチンとか構造化例外とか、なModula-3。 同じ方向性を持つ言語としては、全ての面でAdaが上回ってるんじゃないか、という恐れもあり…。 まあやるだけやってみます。 どっちかといえば、インストールに挑戦する色が…。

SRC Modula-3

SRC Modula-3のインストール手順です。 正規の方法はWin95時代のもので既に時代遅れになっており、試行錯誤しました。

boot-NT386.tar.gz

...\boot-NT386\m3build\templates\NT386の中を、手順通りに書き変えておきます…はいいのですが、VC++4と現在のVC++は構成が違います。 ...\boot-NT386\m3build\templates\NT386を、環境によっても異なるでしょうが、とにかく使えるように書き換えねばなりません。

INSTALL_ROOT = "c:\\progra~1\\modula-3\\"
SDK_ROOT     = "c:\\progra~1\\MIFD68~1\\"
VC_ROOT      = "c:\\progra~1\\MICROS~3.NET\\Vc7\\"

"MSVC_ROOT"を検索して、SDK_ROOTかVC_ROOTの適切な方に置換。 あと、LINKへ代入してる行の"-ignore:505"オプションですが、これがエラーを引き起こすので削除。

それからまず、(VC++製品版を持ってないから)nmakeが無いのでquake(必要なツール)がビルドできません。 ...\boot-NT386\quake\NT386 にて以下のバッチファイルを実行してください。

cl -c -nologo -DMSDOS  -I. -I..\src -DTARGET_NT386  ..\src\parser.c
cl -c -nologo -DMSDOS  -I. -I..\src -DTARGET_NT386  ..\src\lexical.c
cl -c -nologo -DMSDOS  -I. -I..\src -DTARGET_NT386  ..\src\array.c
cl -c -nologo -DMSDOS  -I. -I..\src -DTARGET_NT386  ..\src\atom.c
cl -c -nologo -DMSDOS  -I. -I..\src -DTARGET_NT386  ..\src\hash.c
cl -c -nologo -DMSDOS  -I. -I..\src -DTARGET_NT386  ..\src\builtin.c
cl -c -nologo -DMSDOS  -I. -I..\src -DTARGET_NT386  ..\src\code.c
cl -c -nologo -DMSDOS  -I. -I..\src -DTARGET_NT386  ..\src\dict.c
cl -c -nologo -DMSDOS  -I. -I..\src -DTARGET_NT386  ..\src\execute.c
cl -c -nologo -DMSDOS  -I. -I..\src -DTARGET_NT386  ..\src\fileio.c
cl -c -nologo -DMSDOS  -I. -I..\src -DTARGET_NT386  ..\src\iostack.c
cl -c -nologo -DMSDOS  -I. -I..\src -DTARGET_NT386  ..\src\list.c
cl -c -nologo -DMSDOS  -I. -I..\src -DTARGET_NT386  ..\src\name.c
cl -c -nologo -DMSDOS  -I. -I..\src -DTARGET_NT386  ..\src\operator.c
cl -c -nologo -DMSDOS  -I. -I..\src -DTARGET_NT386  ..\src\path.c
cl -c -nologo -DMSDOS  -I. -I..\src -DTARGET_NT386  ..\src\quake.c
cl -c -nologo -DMSDOS  -I. -I..\src -DTARGET_NT386  ..\src\table.c
cl -c -nologo -DMSDOS  -I. -I..\src -DTARGET_NT386  ..\src\stack.c
cl -c -nologo -DMSDOS  -I. -I..\src -DTARGET_NT386  ..\src\strng.c
cl -c -nologo -DMSDOS  -I. -I..\src -DTARGET_NT386  ..\src\utils.c
cl -nologo -DMSDOS  -I. -I..\src -DTARGET_NT386 (改行しない)
  parser.obj lexical.obj array.obj atom.obj hash.obj (改行しない)
  builtin.obj code.obj dict.obj execute.obj fileio.obj (改行しない)
  iostack.obj list.obj name.obj operator.obj path.obj (改行しない)
  quake.obj table.obj stack.obj strng.obj utils.obj -MD -o quake.exe

quake.exeができたので、それからm3boot.batを実行すれば、だいたいなんとか…?

すくいきれないものを、拾っていきます。 m3core。libへの引数を記述してあるはずのqk2というファイルが存在しません。

...\boot-NT386\m3core\NT386>lib -out:m3core.lib *.mo *.io *.obj

…いいのかこんなんで。 libm3も同様、ファイル名はm3.lib。 m3middleも同様、m3middle.lib。 m3frontも同様、m3front.lib。 m3linkerも同様、m3link.lib。

その状態で再度m3boot.batを実行すると、m3.exeなんとか完成。

m3ship.batは、成功します。 って所定の位置(INSTALL_ROOT)にファイルをコピーしてるだけですが。

m3.tar.gz

boot-NT386.tar.gzだけですと、実行ファイルだけでRTLすら無いので、こっちも必要です。 手順に従うなら、c:\progra~1\modula-3\binにパスを通してからm3.tar.gzを展開した位置でm3build.exeを実行するだけです。

時々ファイルコピーに失敗してそこで止まります。 何もせずまたm3buildを実行すると再開されました。 …よーするに、あれだ。lib.exeを、偽物*1使ってるから、同期が取れてないのでしょうな。手抜きでWinExecだし。

終わったら、それぞれのアーカイブを展開したディレクトリは消していいようです。 それにしても、トータルでファイル数三千強、90MBを超えてます。 元が合計10Mいかない.tar.gzとは思えません。 最終的なイメージを.7zで連結圧縮かけてみたら、縮む縮む18MBに…。

Critical Mass Modula-3

SRC Modula-3のインストールを成功させた翌日、Critical Mass Modula-3というのが生きていて今でも更新されているのを発見しました。 (本家サイトからはリンク切れだった)

ソースからのビルドにはCYGWINが必要なようですが、インストーラ付きバイナリが配布されてるので素直にそれを使っておけばいいでしょう。 それから、Win32用のリンカが用意できてないとかでMSのlink.exeが必要*2ですが、.NET SDKにあるので問題なし。 というかすぐ上でもSRC Modula-3のビルドで使ってますし。

インストーラはCUIですが妙に親切です。 全部何も入れずにENTERでもOKでしょう。 僕はインストール先にc:\progra~1\cm3と答えましたが。

Thank you for using Critical Mass CM3.  This program
will configure and install the system.

cminstall_root is set to E:\Area\cm
If this is not correct, please restart the installer with
-root 

The installer will ask you some questions about the locations of programs
and libraries. Usually it will display a default inside [], which can be
accepted with .
If the installer has found several choices, you may cycle through them
with `+' or `.' for the next and `-' for the previous one.
You may of course also enter a completely different value.


Where would you like the system installed? [c:\cm3] c:\progra~1\cm3
What should be the default text editor for new Reactor users?
checking for executable pfe32.exe... not found
checking for executable pfe.exe... not found
checking for executable vi.exe... not found
checking for executable emacs.bat... not found
registry lookup by extension for .txt... found 
checking for executable notepad.exe... found 
checking for executable notepad.exe in directory C:\WINDOWS... not found
checking for notepad.exe at value of environment variable windir... found 
checking for notepad.exe at value of environment variable winbootdir... not foun
d
checking for executable write.exe... found 
checking for executable writepad.exe... not found

1: C:\progra~1\accessories\sakura\sakura.exe
2: C:\WINNT\SYSTEM32\notepad.exe
3: C:\WINNT\notepad.exe
4: C:\WINNT\SYSTEM32\write.exe
What should be the default text editor for new Reactor users? 
   [C:\progra~1\accessories\sakura\sakura.exe](1 of 4) 

Where should CM3 be installed?
setting INSTALL_ROOT to c:\progra~1\cm3
What directory contains the Microsoft Visual C++ libraries?
registry lookup by extension: file .mdp dir: ..\LIB... not found
checking for directory LIB with environment variable MSDEVDIR... not found
checking for directory C:\MSDEV\LIB... not found
checking for directory C:\MSDEVSTD\LIB... not found
checking for directory D:\MSDEV\LIB... not found
checking for directory D:\MSDEVSTD\LIB... not found
checking for directory E:\MSDEV\LIB... not found
checking for directory E:\MSDEVSTD\LIB... not found
checking for directory C:\MSVS\VC98\LIB... not found
checking for directory D:\MSVS\VC98\LIB... not found
checking for directory E:\MSVS\VC98\LIB... not found
checking for directory ..\LIB with executable cl.exe... found 

1: C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\..\LIB
What directory contains the Microsoft Visual C++ libraries? 
   [C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\..\LIB](1 of 1) 

Warning: CM3 currently cannot handle filenames with white space very well.
The name `C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\..\LIB' has
 been shortened to `C:\PROGRA~1\MICROS~3.NET\Vc7\bin\..\LIB'.
Please try to avoid using spaces in CM3 project filenames.

Please feel free to contact m3-support@elego.de to troubleshoot this problem.


What directory contains the Microsoft Visual C++ executables?
registry lookup by extension: file .mdp dir: ..\BIN... not found
checking for directory BIN with environment variable MSDEVDIR... not found
checking for directory C:\MSDEV\BIN... not found
checking for directory C:\MSDEVSTD\BIN... not found
checking for directory D:\MSDEV\BIN... not found
checking for directory D:\MSDEVSTD\BIN... not found
checking for directory E:\MSDEV\BIN... not found
checking for directory E:\MSDEVSTD\BIN... not found
checking for directory C:\MSVS\VC98\BIN... not found
checking for directory D:\MSVS\VC98\BIN... not found
checking for directory E:\MSVS\VC98\BIN... not found
checking for directory ..\BIN with executable cl.exe... found 

1: C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\..\BIN
What directory contains the Microsoft Visual C++ executables? 
   [C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\..\BIN](1 of 1) 

Warning: CM3 currently cannot handle filenames with white space very well.
The name `C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\..\BIN' has
 been shortened to `C:\PROGRA~1\MICROS~3.NET\Vc7\bin\..\BIN'.
Please try to avoid using spaces in CM3 project filenames.

Please feel free to contact m3-support@elego.de to troubleshoot this problem.



Installing CM3 in: c:\progra~1\cm3
This may take a few minutes...

CM3 is now installed.

Before you begin, here's a few reminders:

  1) The CM3 compiler executable is in:
        c:\progra~1\cm3\bin\cm3.exe
     You may need to modify your PATH environment variable to find it.

  2) CM3's shared libraries and any you create and ship are in:
        c:\progra~1\cm3\bin
     As long as that directory is on your PATH, Windows will be able
     to find and use these libraries.

  3) Your system configuration file is:
        c:\progra~1\cm3\bin\cm3.cfg
     At any point in time, you may edit it to modify or update your
     installation.

  4) A copy of this installation dialogue is in:
        c:\progra~1\cm3\Install.log

  5) If you had trouble with this installation or need more assistance,
     please send us a transcript of this installation via e-mail at
     "m3-support@elego.de".

Thank you.

なお、どんなものか見てませんが、構文の独自拡張があるようですので楽しみです。 ってModula-3本来の構文すらなんも知らないのですけど。 独自拡張ってウキウキしませんか? 僕だけ?

付属のライブラリの数は、圧倒的にSRCの方が多いのですが、気分がいいのでこちらを使います。 というわけで、(どうせ最終イメージをアーカイブしてあるし)SRC Modula-3は気分良く削除。

資料探索

検索中…ええい、日本人でModula-3を使ってる人はいないのか!? (BSD用にアプリはあるようでそのビルド方法はよく見つかるのですが) …これは…Adaよりも状況が厳しいかも…。

なお、ちょっとした紹介文で、演算子オーバーロードが無いことが書かれてました。 要らないと言えば要らないのですが、少し残念。 おお?genericあるらしい。GCもあるらしい。 以前はGCは無くてもtry..finallyさえあればとか思ってた(だからC++はその点でも却下だった)のですが、最近D言語を弄ってるせいで、GCに対する見方が変わりましたね。 今までAda使う時も真面目にUnchecked_Deallocationしてたのですが、これからはGC任せでサボるかも。 しかし、最初は当然と思ってたのですが、色々見てると、GCと明示的解放の両方ができるAdaみたいなのは逆に珍しいようですね。 普通どっちかだけ。 …GNATだとexe終了時にしかGC走ってくれないのが悲しいですけど。 (ちゃんとデストラクタは呼ばれます)

言語リファレンスは本家でもあるSRCのページから辿れます。 Critical Mass Modula-3の使い方は、Modula-3のチュートリアル含めてCM3 5.1 Documentationに。 このまま検索を続けても何も見つからなければ、ここを頼ることにしましょう。

最初のプログラム

Critical Mass Modula-3のコンパイル方法の説明を読んで…意訳すると、cm3.exeはコンパイラ兼ビルドツールであり、Modula-3はちゃんと依存関係を把握できる言語なのでmakeなんざよりよっぽど賢いぜ、ってところでしょうか。 要するに、Delphiのdcc32.exeがプロジェクトソースからだけでちゃんとusesを辿って必要なものだけ再構築してくれるようなものでしょう。 GNATもgnatmakeというツールが同じことしてくれました。 やっぱこれがまともな言語でありまともなコンパイラというものです。 そもそも依存関係を把握することが不可能なC/C++は論外として、importにより依存関係を把握できるくせに、全部渡さないとリンクでこけるdmd(D言語)って一体…。

で、そのままexampleへ読み進めます。

最初はHello Worldじゃなく1+1にすべきだと思い続けてここでもHello Worldなのですが…。

Main.m3

module Main;
import IO;
begin
  IO.Put("Hello World\n"); 
end Main.
...>cm3 main.m3

Fatal Error: unable to locate configuration file, "cm3.cfg"

…考えるのがめんどくさいのでcm3.cfgをカレントにコピー。 コンパイラのマニュアル読んでいけばどっかに書いてるっしょ。 きちんとシステムのプロパティからPATH通せばおっけーでした。

...>cm3
new source -> compiling main.m3
"..\main.m3", line 1: syntax error: missing INTERFACE or MODULE keyword (module)

"..\main.m3", line 1: unable to find interface ()
"..\main.m3", line 2: warning: file name (main.m3) doesn't match module name ()
2 errors and 1 warning encountered
compilation failed => not building program "prog.exe"
Fatal Error: package build failed

…ぬ、ぬわにぃ!? …ひょっとして、文字ケースセンシティブ?でもって予約語が大文字!?

Main.m3 (正)

MODULE Main;
IMPORT IO;
BEGIN
	IO.Put("Hello World\n"); 
END Main.

…エディタで色分けでもしないとやっとれんなこれは。

リンク時のトラブルとして、やっぱりcm3.cfg中の"-ignore:505"を消さないといけなかったり、winspool.libとcomctl32.libの位置が想定と違ったり、色々ありましたが、prog.lstというファイルにlink.exeが吐いたログが残ってるので原因究明は楽です。

で、prog.exe実行…m3.dllが無い…デフォルトで要ランタイムの設定らしい…。 PATHを通して、おー、動いた。

...>path %PATH%;c:\Progra~1\cm3\bin

...>NT386\prog
Hello World

*1 こちら参照。

*2 "Anybody who would like to volunteer writing a linker for WIN32 in Modula-3 would also be very welcome :-)"…「Win32用にリンカが書けるボランティア募集」だそうです。