📝 add logs

This commit is contained in:
ValKmjolnir 2024-10-28 00:51:56 +08:00
parent 826c0857a7
commit d7fe5f3631
4 changed files with 29 additions and 4 deletions

2
.gitattributes vendored
View File

@ -1 +1 @@
*.colgm linguist-language=Nasal
*.colgm linguist-language=Rust

View File

@ -90,8 +90,14 @@ impl report {
self->filename.clear();
self->filename.append_i8_vec(filename);
var another = str::new();
io::stdout().out("read into report::another\n");
readfile_into_string(filename, another);
io::stdout().out("\n");
var source = str::new();
io::stdout().out("read into report::source\n");
readfile_into_string(filename, source);
io::stdout().out("\n");
var tmp = str::new();
for (var pos = 0 => u64; pos < source->size; pos += 1 => u64) {

View File

@ -896,7 +896,9 @@ impl lexer {
self->err->load_file_source(filename);
var src = str::new();
io::stdout().out("read into lexer::scan::src\n");
readfile_into_string(filename, src);
io::stdout().out("\n");
self->pos = 0 => u64;
self->line = 0;
@ -950,6 +952,7 @@ impl lexer {
src->delete();
free(src => i8*);
io::stdout().out("delete lexer::scan::src\n");
}
pub func dump(self) {

View File

@ -14,12 +14,14 @@ pub enum flag {
}
pub func readfile_into_string(filename: i8*, dst: str*) -> i64 {
io::stdout().out("remained info size: ")
.out_i64(dst->size => i64).out("\n");
var fd = open(filename, (flag::O_RDONLY => i32) | (flag::O_BINARY => i32));
if (fd < (0 => i32)) {
return fd => i64;
}
var buff = malloc(1024 => u64);
var buff = [i8; 1024];
var readcount = read(fd, buff, 1023);
for (var index = 0; index < readcount; index += 1) {
@ -33,8 +35,9 @@ pub func readfile_into_string(filename: i8*, dst: str*) -> i64 {
}
}
io::stdout().out("load into 0x").out_hex(dst->c_str => i64)
.out(", size ").out_i64(dst->size => i64).out("\n");
close(fd);
free(buff);
return 0;
}
@ -82,12 +85,24 @@ impl io {
return self[0];
}
var buff = [i8; 128];
var buff = [i8; 256];
itoa(info, buff, 10);
write(self->fd, buff, strlen(buff));
return self[0];
}
pub func out_hex(self, info: i64) -> io {
// do nothing if is stdin
if (self->fd == 0 => i32) {
return self[0];
}
var buff = [i8; 256];
itoa(info, buff, 16);
write(self->fd, buff, strlen(buff));
return self[0];
}
pub func endln(self) {
if (self->fd != (0 => i32)) {
write(self->fd, "\n", 1);
@ -95,6 +110,7 @@ impl io {
}
}
// ANSI escape sequence color
impl io {
pub func red(self) -> io {
self->out("\e[91;1m");