今話題のAmberをビルドしてみた

# Amberとは

アセンブリで作られた言語処理系だそうです。

https://speakerdeck.com/nineties/bootstrap
https://github.com/nineties/amber

# OSXでビルドしてみる

```
git clone https://github.com/nineties/amber
cd amber
make
```

ビルド結果

``` 
cd rowl0; /Applications/Xcode.app/Contents/Developer/usr/bin/make
as main.s -o main.o --32
FATAL:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../libexec/as/x86_64/as: I don't understand '-' flag!
make[1]: *** [main.o] Error 1
make: *** [all] Error 2
```

asの実行部分でこけました。
asの仕様がOSXとLinuxで違うのかな・・・？(詳しくないので後回し)

# Linux (CentOS 7.0)でビルドしてみる

```
git clone https://github.com/nineties/amber
cd amber
make
```

もりもりっとビルド処理が走ります。

以下、ビルドログ

```
cd rowl0; make
make[1]: ディレクトリ `/vagrant/,/amber/rowl0' に入ります
as main.s -o main.o --32
as lib.s -o lib.o --32
as lex.s -o lex.o --32
as compile.s -o compile.o --32
as codegen.s -o codegen.o --32
ld main.o lib.o lex.o compile.o codegen.o -o rlc --nostdlib -m elf_i386 --entry=_main
make[1]: ディレクトリ `/vagrant/,/amber/rowl0' から出ます
cd amber; make
make[1]: ディレクトリ `/vagrant/,/amber/amber' に入ります
make[1]: Warning: File `../rowl0/rlc' has modification time 5.3 s in the future
../rowl0/rlc < startup.rl > startup.s
as startup.s -o startup.o --32
../rowl0/rlc < stddef.rl > stddef.s
../rowl0/rlc < code.rl > code.s
../rowl0/rlc < main.rl > main.s
as main.s -o main.o --32
as stddef.s -o stddef.o --32
../rowl0/rlc < stdlib.rl > stdlib.s
as stdlib.s -o stdlib.o --32
../rowl0/rlc < alloc.rl > alloc.s
as alloc.s -o alloc.o --32
../rowl0/rlc < rowllib.rl > rowllib.s
as rowllib.s -o rowllib.o --32
../rowl0/rlc < builtin.rl > builtin.s
as builtin.s -o builtin.o --32
../rowl0/rlc < pprint.rl > pprint.s
as pprint.s -o pprint.o --32
../rowl0/rlc < token.rl > token.s
../rowl0/rlc < lex.rl > lex.s
as lex.s -o lex.o --32
../rowl0/rlc < parse.rl > parse.s
as parse.s -o parse.o --32
../rowl0/rlc < eval.rl > eval.s
as eval.s -o eval.o --32
ld startup.o main.o stddef.o stdlib.o alloc.o rowllib.o builtin.o pprint.o lex.o parse.o eval.o -o rlci --nostdlib -m elf_i386 --entry=_start
./rlci vm-main.rlc > vm-main.s
as vm-main.s -o vm-main.o --32
./rlci vm-eval.rlc > vm-eval.s
# of VM instructions = 186
as vm-eval.s -o vm-eval.o --32
./rlci vm-gc.rlc > vm-gc.s
as vm-gc.s -o vm-gc.o --32
./rlci vm-load.rlc > vm-load.s
as vm-load.s -o vm-load.o --32
./rlci vm-prim-util.rlc > vm-prim-util.s
as vm-prim-util.s -o vm-prim-util.o --32
./rlci vm-prim-sys.rlc > vm-prim-sys.s
as vm-prim-sys.s -o vm-prim-sys.o --32
./rlci vm-prim-io.rlc > vm-prim-io.s
as vm-prim-io.s -o vm-prim-io.o --32
./rlci vm-prim-string.rlc > vm-prim-string.s
as vm-prim-string.s -o vm-prim-string.o --32
./rlci vm-prim-vector.rlc > vm-prim-vector.s
as vm-prim-vector.s -o vm-prim-vector.o --32
./rlci vm-prim-tuple.rlc > vm-prim-tuple.s
as vm-prim-tuple.s -o vm-prim-tuple.o --32
./rlci vm-prim-idtable.rlc > vm-prim-idtable.s
as vm-prim-idtable.s -o vm-prim-idtable.o --32
./rlci vm-prim-wrtable.rlc > vm-prim-wrtable.s
as vm-prim-wrtable.s -o vm-prim-wrtable.o --32
./rlci vm-prim-random.rlc > vm-prim-random.s
as vm-prim-random.s -o vm-prim-random.o --32
ld vm-main.o vm-eval.o vm-gc.o vm-load.o vm-prim-util.o vm-prim-sys.o vm-prim-io.o vm-prim-string.o vm-prim-vector.o vm-prim-tuple.o vm-prim-idtable.o vm-prim-wrtable.o vm-prim-random.o -o rlvm --nostdlib -m elf_i386 --entry=_start
./rlci linker.rlc > linker
./rlci disasm.rlc > disasm
./rlci amber-util.rlc > amber-util.rlo
./rlci amber-node.rlc > amber-node.rlo
./rlci amber-error.rlc > amber-error.rlo
./rlci amber-symtable.rlc > amber-symtable.rlo
./rlci amber-assemble.rlc > amber-assemble.rlo
./rlci amber-compile.rlc > amber-compile.rlo
./rlci amber-object.rlc > amber-object.rlo
./rlci amber-packrat.rlc > amber-packrat.rlo
./rlci amber-types.rlc > amber-types.rlo
./rlci amber-string.rlc > amber-string.rlo
./rlci amber-pprint.rlc > amber-pprint.rlo
./rlci amber-base.rlc > amber-base.rlo
./rlci amber-numeric.rlc > amber-numeric.rlo
./rlci amber-float.rlc > amber-float.rlo
./rlci amber-math.rlc > amber-math.rlo
./rlci amber-tuple.rlc > amber-tuple.rlo
./rlci amber-table.rlc > amber-table.rlo
./rlci amber-array.rlc > amber-array.rlo
./rlci amber-interp.rlc > amber-interp.rlo
./rlci amber-main.rlc > amber-main.rlo
./rlci amber-matching.rlc > amber-matching.rlo
./rlci amber-function.rlc > amber-function.rlo
./rlci amber-symbol.rlc > amber-symbol.rlo
./rlci amber-random.rlc > amber-random.rlo
./rlci amber-list.rlc > amber-list.rlo
./rlci amber-io.rlc > amber-io.rlo
./rlci amber-encoding.rlc > amber-encoding.rlo
            ./rlci amber-sys.rlc > amber-sys.rlo
./rlci amber-gc.rlc > amber-gc.rlo
./rlci startup.rlc > startup.rlo
./rlvm linker amber-main.rlo amber-util.rlo amber-interp.rlo amber-node.rlo amber-error.rlo amber-object.rlo amber-symtable.rlo amber-assemble.rlo amber-compile.rlo amber-matching.rlo amber-packrat.rlo amber-base.rlo amber-function.rlo amber-symbol.rlo amber-numeric.rlo amber-float.rlo amber-math.rlo amber-random.rlo amber-string.rlo amber-list.rlo amber-tuple.rlo amber-array.rlo amber-table.rlo amber-io.rlo amber-pprint.rlo amber-encoding.rlo amber-sys.rlo amber-gc.rlo -o amberi
make[1]: 警告:  時刻のずれを検出. 不完全なビルド結果になるかもしれません.
rm vm-prim-random.s vm-prim-util.s vm-load.s vm-prim-vector.s vm-eval.s vm-prim-io.s vm-prim-idtable.s vm-prim-sys.s vm-prim-tuple.s vm-prim-wrtable.s vm-prim-string.s vm-gc.s vm-main.s
make[1]: ディレクトリ `/vagrant/,/amber/amber' から出ます
```


待つこと約10分、ビルドが成功しました！

インストール

```
sudo make instal
```

## 実行してみる

```
$ amber
amber:1> puts(1234)
1234
amber:2> puts(1+1)
2
amber:6> puts(1*2*3*4)
24
```

動きました！！