NoopでHello World!
今回はデータベースのネタをお休みして、噂のプログラミング言語Noopを試してみました。
- 速報:グーグルが新言語「Noop」を公開。JavaVMで動作 − Blog on Publickey
- JVMで動作する新言語「Noop」- Google開発者らによる新プロジェクト | エンタープライズ | マイコミジャーナル
以下、NoopでHello World!を動かすまでの手順です。
JDKのインストール
NoopはJava VM上で動作するので、まずJava SE Development Kit(JDK)をインストールします。
インストールが済んだら、C:\Program Files\Java\jdk1.6.0_16\binにパスを通しておきます。
TortoiseHgのインストール
NoopはMercurialでバージョン管理されているので、Windows用のクライアントとしてTortoiseHgをインストールします。
Noopソースツリーの取得
コマンドプロンプトから、hgコマンドを用いてNoopのソースツリーを取得します。
C:\>hg clone https://noop.googlecode.com/hg/ noop requesting all changes adding changesets adding manifests adding file changes added 71 changesets with 336 changes to 78 files updating working directory 64 files updated, 0 files merged, 0 files removed, 0 files unresolved
Rubyのインストール
NoopはApache Buildrでビルドするのですが、Apache BuildrはRubyで作られているので先にRubyをインストールします。Windows版のRubyはいくつかありますが、今回はActiveScriptRubyを使用しました。
インストールが済んだら、C:\Program Files\ruby-1.8\binにパスを通しておきます。
Apache Buildrのインストール
RubyのgemコマンドでApache Builderをインストールします。
C:\>gem install buildr ************************************************** Thank you for installing rspec-1.2.2 Please be sure to read History.rdoc and Upgrade.rdoc for useful information about this release. ************************************************** To get started run buildr --help Successfully installed rake-0.8.4 Successfully installed builder-2.1.2 Successfully installed net-ssh-2.0.11 Successfully installed net-sftp-2.0.2 Successfully installed rubyzip-0.9.1 Successfully installed highline-1.5.0 Successfully installed rubyforge-1.0.3 Successfully installed hoe-1.11.0 Successfully installed rjb-1.1.6-x86-mswin32-60 Successfully installed Antwrap-0.7.0 Successfully installed rspec-1.2.2 Successfully installed xml-simple-1.0.12 Successfully installed archive-tar-minitar-0.5.2 Successfully installed buildr-1.3.4 14 gems installed Installing ri documentation for rake-0.8.4... Installing ri documentation for builder-2.1.2... ERROR: While generating documentation for builder-2.1.2 ... MESSAGE: Unhandled special: Special: type=17, text="<!-- HI -->" ... RDOC args: --ri --op C:/Program Files/ruby-1.8/lib/ruby/gems/1.8/doc/builder -2.1.2/ri --title Builder -- Easy XML Building --main README --line-numbers --qu iet lib CHANGES Rakefile README doc/releases/builder-1.2.4.rdoc doc/releases/bui lder-2.0.0.rdoc doc/releases/builder-2.1.1.rdoc --title builder-2.1.2 Documentat ion (continuing with the rest of the installation) Installing ri documentation for net-ssh-2.0.11... Installing ri documentation for net-sftp-2.0.2... Installing ri documentation for rubyzip-0.9.1... Installing ri documentation for highline-1.5.0... Installing ri documentation for rubyforge-1.0.3... Installing ri documentation for hoe-1.11.0... Installing ri documentation for rjb-1.1.6-x86-mswin32-60... Installing ri documentation for Antwrap-0.7.0... Installing ri documentation for rspec-1.2.2... Installing ri documentation for xml-simple-1.0.12... Installing ri documentation for archive-tar-minitar-0.5.2... Installing ri documentation for buildr-1.3.4... Installing RDoc documentation for rake-0.8.4... Installing RDoc documentation for builder-2.1.2... Installing RDoc documentation for net-ssh-2.0.11... Installing RDoc documentation for net-sftp-2.0.2... Installing RDoc documentation for rubyzip-0.9.1... Installing RDoc documentation for highline-1.5.0... Installing RDoc documentation for rubyforge-1.0.3... Installing RDoc documentation for hoe-1.11.0... Installing RDoc documentation for rjb-1.1.6-x86-mswin32-60... Installing RDoc documentation for Antwrap-0.7.0... Installing RDoc documentation for rspec-1.2.2... Could not find main page README.rdoc Could not find main page README.rdoc Could not find main page README.rdoc Could not find main page README.rdoc Installing RDoc documentation for xml-simple-1.0.12... Installing RDoc documentation for archive-tar-minitar-0.5.2... Installing RDoc documentation for buildr-1.3.4...
Scalaのインストール
NoopはScalaで作られているので、Scalaをインストールします。Windows版Scalaのインストールは、ダウンロードしたZIPファイルを展開するだけです。
インストールが済んだら、<インストール先フォルダ>\binにパスを通しておきます。
Noopのビルド
環境変数JAVA_HOMEとSCALA_HOMEを設定し、Apache Builderを用いてNoopをビルドします。ただし、提供されているbuildr.batファイルを使用すると、今回の構成では以下のようなエラーが出てしまうようです。
C:\noop>set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_16 C:\noop>set SCALA_HOME=C:\Scala276 C:\noop>buildr C:/Program Files/ruby-1.8/bin/buildr:19:in `load': no such file to load -- "C:/P rogram Files/ruby-1.8/lib/ruby/gems/1.8/gems/buildr-1.3.4/bin/buildr" (LoadError) from C:/Program Files/ruby-1.8/bin/buildr:19
そのため、rubyコマンドで直接buildrスクリプトを起動します。
C:\noop>ruby "C:\Program Files\ruby-1.8\lib\ruby\gems\1.8\gems\buildr-1.3.4\bin\buildr" (in C:/noop, development) Downloading org.apache.ant:ant:jar:1.7.1 Downloading http://mirrors.ibiblio.org/pub/mirrors/maven2/org/apache/ant/ant/1.7 .1/ant-1.7.1.jar ant-1.7.1.jar: 100% |...........................| 1.3MB/1.3MB Time: 00:00:24 Downloading org.apache.ant:ant:pom:1.7.1 Downloading http://mirrors.ibiblio.org/pub/mirrors/maven2/org/apache/ant/ant/1.7 .1/ant-1.7.1.pom ant-1.7.1.pom: 100% |...........................| 9.5KB/9.5KB Time: 00:00:00 (略) Running tests in noop ScalaTest "noop.grammar.BlockSpec" - should allow a return statement - should allow chained property access on properties - should allow calling a method (略) ScalaTest "noop.grammar.IfSpec" - should parse correctly equality expression on two literals *** FAILED *** (IfSpec.scala:16) org.scalatest.TestFailedException: "(IF 1 == 1)" was not equal to "(IF (EQ 1 1))" (略) ScalaTest "noop.types.StringSpec" - should have a valid class definition parsed from Noop source - should have a native implementation of the length method Run completed. Total number of tests run was: 2 All tests passed. Completed in 1m52.234s
現時点では、いくつか失敗するテストもあるようです。
サンプルプログラムの実行
ビルド結果はtargetフォルダに出力されます。
実はHelloWorldのサンプルは最初から付属しています。早速これを動かしてみましょう。
import noop.Application; import noop.Console; class HelloWorld(Console console) implements Application { Int main(List args) { String s = "Hello World!"; console.println(s); return 0; } }
Noopの実行環境は、現在のところインタプリタのみが提供されているようです。インタプリタを動かすにはclassesフォルダとantlr-runtime-3.1.1.jarにクラスパスを通し、noop.interpreter.InterpreterMainクラスを指定してScalaを起動します。
antlr-runtime-3.1.1.jarはNoopのビルド中にC:\Documents and Settings\<ユーザ名>\.m2\repository\org\antlr\antlr-runtime\3.1.1にダウンロードされているので、それをコピーして使えばOKです。それからHelloWorldプログラムはnoop.Applicationクラスとnoop.Consoleクラスを利用しているのですが、これらのクラス定義はresources\stdlibフォルダに格納されています。そのため起動オプションとして、このフォルダも指定する必要があります。
C:\noop\target>scala noop.interpreter.InterpreterMain Usage: InterpreterMain main-class paths/to/sources ... C:\noop\target>scala noop.interpreter.InterpreterMain HelloWorld resources\helloworld resources\stdlib Hello World!
動きました!
感想
プログラミングは専門外なので何がすごいのかあまり分かっていませんが、最近の開発手法っていろいろあって楽しそうですね。ワクワクします。