stage2 提供词法分析器通过与stage1的差异测试 stage1提供数组到切片的隐式转换

This commit is contained in:
zzy committed 2026-09-18 19:40:10 +08:00
1 parent c30143609a
commit bb9d0a9f18
13 files changed
+1275 -52

No files matched your search

+36
View File
@@ -81,6 +81,39 @@ static void dump_tokens(spl_tok_vec_t toks) {
vec_free(toks);
}
/* 折叠重复分隔符并去掉 "." 路径分量,使同一模块的 import 解析结果唯一。
就地重写,'\' 统一成 '/';保留前导分隔符(绝对路径)。 */
static void normalize_import_path(char *p) {
usize n = strlen(p);
char *out = malloc(n + 1);
if (!out)
return;
char *w = out;
if (p[0] == '/' || p[0] == '\\')
*w++ = '/';
char *r = p;
while (*r) {
while (*r == '/' || *r == '\\')
r++;
if (!*r)
break;
char *seg = r;
while (*r && *r != '/' && *r != '\\')
r++;
usize len = (usize)(r - seg);
if (len == 1 && seg[0] == '.')
continue;
if (w != out && w[-1] != '/')
*w++ = '/';
memcpy(w, seg, len);
w += len;
}
*w = 0;
strcpy(p, out);
free(out);
}
/* 把 import_path 拼接到 importing_file 所在目录。
from_fname 为空时按相对 cwd 处理。绝对路径直接透传。 */
static void resolve_relative(const char *from, const char *path, char *out, usize cap) {
@@ -91,6 +124,7 @@ static void resolve_relative(const char *from, const char *path, char *out, usiz
}
if (path[0] == '/' || path[0] == '\\' || (path[0] && path[1] == ':')) {
snprintf(out, cap, "%s", path);
normalize_import_path(out);
return;
}
const char *last_sep = NULL;
@@ -99,10 +133,12 @@ static void resolve_relative(const char *from, const char *path, char *out, usiz
last_sep = p;
if (!last_sep) {
snprintf(out, cap, "%s", path);
normalize_import_path(out);
return;
}
usize dir_len = (usize)(last_sep - from) + 1;
snprintf(out, cap, "%.*s%s", (int)dir_len, from, path);
normalize_import_path(out);
}
static spl_ast_t *driver_load(void *user, const char *from_fname, const char *path,