셀프호스팅에 손대기 전의 강제 함수다. 아픈 자리를 전부 건드린다: R4 아래의 토큰 구조체, 태그드 유니온, 진단 출력, 유닛 경계. 토큰은 자기가 나온 글자를 담지 않는다. R4 가 대여를 집합 저장소에서 막으므로, 어디서 시작해 얼마나 긴지를 적고 소스는 옆에서 같이 다닌다. 위치도 &mut usize 로 옆에서 다닌다 -- 슬라이스와 함께 구조체에 들어갈 수 없기 때문이다. 이것이 R11 이 말하는 모양이고, 쓸 수 있다. first keyword unit @1 / number 42 @3 / text "hi" @3 / arrow -> @5 keyword 6 name 7 number 1 text 1 punct 15 / total 30 길에서 고친 것: - binding.Type.Variant 가 안 풀렸다. 유닛 경계 이름 조회가 심볼만 보고 타입을 보지 않았다. - 문자열 const 전역이 빈 슬라이스로 나갔다. 포인터는 링커만 아는 수라서 바이트에 구멍을 두고 링커가 채우게 한다. - exec.py 가 OUTPUT 마커를 여러 개 적어도 마지막 하나만 검사했다. 고치자마자 readfile 의 낡은 기대가 드러났다. run.py 217/217, exec.py 27/27.
38 lines
1.2 KiB
Plaintext
38 lines
1.2 KiB
Plaintext
// EXIT:0
|
|
// OUTPUT:read 27 bytes
|
|
// OUTPUT:first line: // EXIT:0
|
|
unit readfile;
|
|
import std.io;
|
|
|
|
// Reads its own source and reports the first line. A program that can open a
|
|
// file is a program that can be a compiler.
|
|
|
|
fn main() -> i32 {
|
|
var path: [64]u8 = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
|
|
let n: usize = io.to_cstr(path[..], "fec/tests/exec/readfile.fe");
|
|
let handle: i32 = io.open_read(path[0..n]) catch |e| {
|
|
@print("cannot open\n");
|
|
return 1;
|
|
};
|
|
var buf: [64]u8 = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
|
|
let got: usize = io.read(handle, buf[..]) catch |e| {
|
|
io.close(handle);
|
|
return 2;
|
|
};
|
|
io.close(handle);
|
|
@print("read {} bytes\n", n);
|
|
var stop: usize = 0;
|
|
while stop < got {
|
|
if buf[stop] == 10 { break; }
|
|
stop = stop + 1;
|
|
}
|
|
@print("first line: {}\n", buf[0..stop]);
|
|
return 0;
|
|
}
|