std: 표준 라이브러리가 컴파일러 옆에서 해석되고 호출된다
std 는 예약된 이름이고 프로그램이 아니라 컴파일러와 함께 있으므로 자기 루트를 갖는다 (--std=). 본문 없는 선언은 링커가 찾을 것 -- 런타임이나 C 라이브러리 -- 이므로 IR 에 extern 으로 나간다. 런타임에 write/alloc/free/exit 를 넣었다. 이것이 표준 라이브러리가 스스로 말할 수 없는 전부이고 나머지는 Ferro 로 쓴다. @trap @unreachable @size_of @align_of @line 을 내린다. 링크 이름에서 점과 괄호를 걸렀다. 유닛 경로에는 점이 있고 제네릭 인스턴스에는 괄호가 있는데 어셈블러가 받지 않는다.
This commit is contained in:
+11
-4
@@ -1,5 +1,12 @@
|
||||
unit core;
|
||||
unit std.core;
|
||||
|
||||
pub error Error { Invalid = 1, Io = 2, }
|
||||
pub fn panic(msg: str, file: str, line: u32) { }
|
||||
pub fn assert(ok: bool) { }
|
||||
// The default error set is open: `error.Name` names a member of it without
|
||||
// declaring one, and the build assigns the codes (SPEC 4.6).
|
||||
|
||||
pub fn assert(ok: bool) -> void {
|
||||
if not ok { @trap(); }
|
||||
}
|
||||
|
||||
pub fn min(a: i32, b: i32) -> i32 { if a < b { return a; } return b; }
|
||||
pub fn max(a: i32, b: i32) -> i32 { if a > b { return a; } return b; }
|
||||
pub fn abs(v: i32) -> i32 { if v < 0 { return 0 - v; } return v; }
|
||||
|
||||
+24
-2
@@ -1,2 +1,24 @@
|
||||
unit sys;
|
||||
pub fn exit(code: u16);
|
||||
unit std.sys;
|
||||
|
||||
// The few things the language cannot say for itself. The runtime provides
|
||||
// them; everything else in the standard library is written in Ferro.
|
||||
extern "c" fn fe_rt_write(handle: i32, bytes: *u8, len: usize) -> i32;
|
||||
extern "c" fn fe_rt_alloc(n: usize) -> *u8;
|
||||
extern "c" fn fe_rt_free(p: *u8);
|
||||
extern "c" fn fe_rt_exit(code: i32);
|
||||
|
||||
pub fn exit(code: i32) -> void {
|
||||
unsafe { fe_rt_exit(code); }
|
||||
}
|
||||
|
||||
pub fn raw_write(handle: i32, bytes: *u8, len: usize) -> i32 {
|
||||
unsafe { return fe_rt_write(handle, bytes, len); }
|
||||
}
|
||||
|
||||
pub fn raw_alloc(n: usize) -> *u8 {
|
||||
unsafe { return fe_rt_alloc(n); }
|
||||
}
|
||||
|
||||
pub fn raw_free(p: *u8) -> void {
|
||||
unsafe { fe_rt_free(p); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user