Open4

Ribbon: 自分で自分をコンパイルする

okuokuokuoku

上手くいかない

readerのテストがエラーになる。ただし他のテストは正常。

$ ./proto ~/repos/yuni/tests/lib/miniread0.sps > self.txt
-> Trying "/home/oku/repos/yuniribbit-proto/runtime/yunitest/mini.sls" -> Trying "/home/oku/repos/yuniribbit-proto/yunitest/mini.sls" -> Trying "/home/oku/repos/yuni/external/yunitest/mini.sls" -> Trying "/home/oku/repos/yuni/lib/yunitest/mini.sls" Error:
  0: "a"
  1: "unknown char literal"
Aborted (core dumped)

string-length の結果がおかしい。。?

https://github.com/okuoku/yuni/blob/ebc80255da77db64848657e7c0d838222074f0f2/lib/yuni/miniread/reader.sls#L81-L96

"a"(= 1 (string-length s)) が成立するはずなので、 error に行くのはおかしい。

... そもそも、 Trying... の出力の末尾には改行が入るはずなのに改行が入っていない。

$ ./proto ~/repos/yuni/tests/lib/miniread0.sps > base.txt
-> Trying "/home/oku/repos/yuniribbit-proto/runtime/yunitest/mini.sls"
-> Trying "/home/oku/repos/yuniribbit-proto/yunitest/mini.sls"
-> Trying "/home/oku/repos/yuni/external/yunitest/mini.sls"
-> Trying "/home/oku/repos/yuni/lib/yunitest/mini.sls"
okuokuokuoku

シリアライズがおかしい

改行を出力する newline 手続きは

https://github.com/okuoku/yuni/blob/ebc80255da77db64848657e7c0d838222074f0f2/lib-r7c/r7c-io/port/objects.sls#L72-L75

のように実装されている。つまり、文字リテラルがおかしい。。?

(import (yuni scheme)
        (yuni io drypack))


(let ((p (open-output-bytevector)))
 (drypack-put p #\newline)
 (write (get-output-bytevector p)))

(exit 0)

これが

#u8(5 4 4 1 0 0 0 0 0 0 0)

本来は:

#u8(5 4 4 1 0 0 0 0 0 0 10)

となる。はず。確かに、

(write (char->integer #\newline))

とすると 0 が出力される。。つまり、readerが正しく文字リテラルを読めていない = Ribbonでコンパイル後のreaderをシリアライズすると壊れる と考えられる。今まではGaucheでシリアライズしたことしかない。

okuokuokuoku

定数テーブルから値が脱落している

シリアライズされた結果を比較してみると、ライブラリ (r7c-io writer datum) をGaucheでコンパイルした場合

       () 1 0 3 2 5 4 6 #\space " . " #f 8 7 "\\a" "\\b" 9 "\\t"
       10 "\\n" 13 "\\d" 34 "\\\"" 92
       "\\\\" "()" "#<eof-object>" "#t" "#f" quote #\'
       quasiquote #\` unquote #\, unquote-splicing #\@ "Unexpected" #\( #\)
       #\# #\u #\8 #\" #\\ "#<procedure>" "#<port>" "#<unknown>" -2 #t

となっているものが、Ribbonでは、

       () 1 0 3 2 5 4 6 #\space " . " #f 8 7 "\\a" "\\b" 9 "\\t"
       "\\n" "\\d" "\\\"" 
       "\\\\" "()" "#<eof-object>" "#t" "#f" quote #\'
       quasiquote #\`unquote #\, unquote-splicing #\@ "Unexpected" #\( #\)
       #\# #\u #\8 #\" #\\ "#<procedure>" "#<port>" "#<unknown>" -2 #t

のように、数値 10 13 34 92 が抜けている。

該当するコードは:

https://github.com/okuoku/yuni/blob/ebc80255da77db64848657e7c0d838222074f0f2/lib-r7c/r7c-io/writer/datum.sls#L50-L59

... これ 16進数値リテラルが正常に読めてない な。。

https://github.com/okuoku/ribbon/commit/834962fbe39654da2af996fc257ced2d639e2b65

実装した。真面目なnumber readerを書かないといけないけどサボっている。。

https://github.com/okuoku/yuni/commit/68c7d918892ce8cf104ce940df4300e1d1e7f6de

よもやテストされていないとは。。

https://github.com/okuoku/yuniribbit-proto/commit/49b92731baee928e0048d17ff1b72f47f1252fdb

今回のような比較ができるように、どの処理系で出力してもシリアライズ結果が一致するようにした。 hashtable-keyshashtable-entries の出力順は順不同(unordered)なので、最悪実行のたびに結果が違ってしまう可能性がある。