SPARC で JavaScript エンジン iv/lv5 を動かす(動きました).


漢なら地上最速で ECMA262 5.1 full support した仕様に忠実な JavaScript エンジンである iv/lv5 を SPARC で動かして, 宇宙線の多い日も安心快適な JavaScript ライフを送りたいですね!

## ビルドする.

テスト用? に cmake configure 中に sunspider とかダウンロードするのを消します.

```
#include(ExternalProject)
```

g++-4.8.1(sparc64-unknown-linux-gnu) が available とします(C++11 対応)

```
$ g++-4.8.1 -v
…
Target: sparc64-unknown-linux-gnu
…
Thread model: posix
gcc version 4.8.1 (GCC) 
```


`CMAKE_CXX_COMPILER=g++-4.8.1` での指定だと cmake の configure に失敗するので, 環境変数でコンパイラを指定して cmake を invoke します.

```
$ export CC=gcc-4.8.1
$ export CXX=g++-4.8.1
$ cmake  -H. -Brelease -DCMAKE_BUILD_TYPE=Release
$ make -C release lv5

…
[100%] Building CXX object iv/lv5/CMakeFiles/lv5.dir/main.cc.o
Linking CXX executable lv5




liblv5.a(misc.c.o): In function `GC_do_blocking_inner':
misc.c:(.text+0x34): undefined reference to `GC_save_regs_in_stack'
liblv5.a(misc.c.o): In function `GC_clear_stack':
misc.c:(.text+0x30c): undefined reference to `GC_clear_stack_inner'
collect2: error: ld returned 1 exit status
```

ぐぬぬ… libgc 周りでエラーが出てしまいました…

## パッチを当てる.

SPARC ビルド時に libgc のソースに一部ファイル欠けがあったので追加します.

https://github.com/Constellation/iv/issues/99

パッチを当ててビルドすると無事 lv5 が出来ました!

## 実行する.


```
$ ./lv5 
> 1+3
4
> print("bora")
bora
undefined
> print
function print() { "[native code]" }
> 1.3+4.5 
5.8
> Math.random()
0.34344955306509606
```

Super cool!


## ユニットテストを走らせる.

```
$ ./iv_unit_tests
…
[----------] Global test environment tear-down
[==========] 130 tests from 42 test cases ran. (3903 ms total)
[  PASSED  ] 113 tests.
[  FAILED  ] 17 tests, listed below:
[  FAILED  ] SipHashCase.test_spec_streaming
[  FAILED  ] SipHashCase.test_spec_one_pass
[  FAILED  ] SipHashCase.test_empty_string
[  FAILED  ] SipHashCase.test_one_byte
[  FAILED  ] SipHashCase.test_six_bytes
[  FAILED  ] SipHashCase.test_seven_bytes
[  FAILED  ] SipHashCase.test_eight_bytes
[  FAILED  ] SipHashCase.test_one_mio_zero_bytes
[  FAILED  ] SipHashCase.test_reference_vectors
[  FAILED  ] SipHashCase.test_24_spec
[  FAILED  ] SipHashCase.test_24_empty_string
[  FAILED  ] SipHashCase.test_24_one_byte
[  FAILED  ] SipHashCase.test_24_six_bytes
[  FAILED  ] SipHashCase.test_24_seven_bytes
[  FAILED  ] ShipHashCase.test_24_eight_bytes
[  FAILED  ] ShipHashCase.test_24_one_mio_zero_bytes
[  FAILED  ] ShipHashCase.test_24_reference_vectors

17 FAILED TESTS
```

ハッシュ関数周り以外は動いていそうです!

lv5 の unit tester も動かします.

```
$ ./lv5_unit_tests 
Running main() from gtest_main.cc
[==========] Running 10 tests from 5 test cases.
[----------] Global test environment set-up.
[----------] 1 test from SuiteCase
[ RUN      ] SuiteCase.RailgunPassTest
lv5 can't open "iv/lv5/test/suite/resources/jasmine.js": No such file or directory
...
Value of: core::io::ReadFile(filename, &res)
  Actual: false
Expected: true
iv/lv5/test/suite/resources/jasmine.js
lv5 can't open "iv/lv5/test/suite/resources/ConsoleReporter.js": No such file or directory
...
Value of: core::io::ReadFile(filename, &res)
  Actual: false
Expected: true
iv/lv5/test/suite/resources/ConsoleReporter.js
lv5 can't open "iv/lv5/test/suite/resources/driver.js": No such file or directory
...
Value of: core::io::ReadFile(filename, &res)
  Actual: false
Expected: true
iv/lv5/test/suite/resources/driver.js
[  FAILED  ] SuiteCase.RailgunPassTest (7 ms)
[----------] 1 test from SuiteCase (7 ms total)

[----------] 6 tests from RadioCoreCase
[ RUN      ] RadioCoreCase.MainTest
[       OK ] RadioCoreCase.MainTest (0 ms)
[ RUN      ] RadioCoreCase.BlockAddrTest
[       OK ] RadioCoreCase.BlockAddrTest (0 ms)
[ RUN      ] RadioCoreCase.ColoringWhiteTest
[       OK ] RadioCoreCase.ColoringWhiteTest (0 ms)
[ RUN      ] RadioCoreCase.ColoringBlackTest
[       OK ] RadioCoreCase.ColoringBlackTest (0 ms)
[ RUN      ] RadioCoreCase.ColoringScopedTest
[       OK ] RadioCoreCase.ColoringScopedTest (1 ms)
[ RUN      ] RadioCoreCase.ColoringScopedEscapeTest
[       OK ] RadioCoreCase.ColoringScopedEscapeTest (0 ms)
[----------] 6 tests from RadioCoreCase (2 ms total)

[----------] 1 test from RadioArenaCase
[ RUN      ] RadioArenaCase.ArenaBlocksTest
[       OK ] RadioArenaCase.ArenaBlocksTest (0 ms)
[----------] 1 test from RadioArenaCase (0 ms total)

[----------] 1 test from JSValCase
[ RUN      ] JSValCase.NaNTest
[       OK ] JSValCase.NaNTest (0 ms)
[----------] 1 test from JSValCase (0 ms total)

[----------] 1 test from FpuCase
[ RUN      ] FpuCase.FpuTest
[       OK ] FpuCase.FpuTest (0 ms)
[----------] 1 test from FpuCase (0 ms total)

[----------] Global test environment tear-down
[==========] 10 tests from 5 test cases ran. (10 ms total)
[  PASSED  ] 9 tests.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] SuiteCase.RailgunPassTest

 1 FAILED TEST
```

最初にテスト用の JS コードをダウンロードしないようにしたのが原因でしょうか, SuiteCase.RailgunPassTest は fail してしまいましたが, それ以外はうまく動いているようです!

Happy JavaScript coding on SPARC!

## TODO

* `iv` という名前が激しく検索しづらいのでなにか別名を考えてあげたい.
* エンディアンの問題は無いか?(SPARC は big endian)
* クロスコンパイルにもチャレンジする(target=SPARC, host=x86)
  * ネイティブ環境だと, リンクに激しく時間がかかるので…