stage1 修复设计问题 实现ir2vm
This commit is contained in:
@@ -147,11 +147,11 @@ static spl_tok_t *peek_next(parser_t *p) {
|
||||
}
|
||||
|
||||
static void parse_error(parser_t *p, spl_tok_t *t, const char *msg) {
|
||||
(void)p;
|
||||
p->failed = 1; /* 出错即停(上层循环以 !p->failed 提前退出) */
|
||||
const char *fn = (t && t->fname) ? t->fname : "<unknown>";
|
||||
usize line = t ? t->line : 0;
|
||||
usize col = t ? t->col : 0;
|
||||
LOG_FATAL("%s:%llu:%llu: error: %s", fn, (unsigned long long)line, (unsigned long long)col,
|
||||
LOG_ERROR("%s:%llu:%llu: error: %s", fn, (unsigned long long)line, (unsigned long long)col,
|
||||
msg);
|
||||
}
|
||||
|
||||
@@ -223,7 +223,7 @@ static spl_ast_node_ref_t wrap_op_expr(parser_t *p, spl_ast_node_ref_t inner, in
|
||||
/* ================================================================
|
||||
* 字面量解 * ================================================================ */
|
||||
|
||||
/* 整数字面量:去下划线后按0 解析x/0o/0b/十进制,忽略 0b 特判*/
|
||||
/* 整数字面量:去下划线后按 0x/0o/0b/十进制解析 */
|
||||
static isize parse_int_literal(const spl_tok_t *t) {
|
||||
char buf[128];
|
||||
usize j = 0;
|
||||
@@ -232,6 +232,11 @@ static isize parse_int_literal(const spl_tok_t *t) {
|
||||
buf[j++] = t->lexeme[i];
|
||||
}
|
||||
buf[j] = 0;
|
||||
/* strtoll base 0 不认 0b/0o 前缀:单独处理 */
|
||||
if (j >= 3 && buf[0] == '0' && (buf[1] == 'b' || buf[1] == 'B'))
|
||||
return (isize)strtoll(buf + 2, NULL, 2);
|
||||
if (j >= 3 && buf[0] == '0' && (buf[1] == 'o' || buf[1] == 'O'))
|
||||
return (isize)strtoll(buf + 2, NULL, 8);
|
||||
return (isize)strtoll(buf, NULL, 0);
|
||||
}
|
||||
|
||||
@@ -637,7 +642,7 @@ static spl_ast_node_ref_vec_t parse_block(parser_t *p) {
|
||||
vec_init(vec);
|
||||
if (!expect(p, TOK_L_BRACE, "expected '{'"))
|
||||
return vec;
|
||||
while (1) {
|
||||
while (!p->failed) {
|
||||
spl_tok_t *t = peek(p);
|
||||
if (!t || t->type == TOK_EOF) {
|
||||
parse_error(p, t, "block missing '}'");
|
||||
@@ -1827,7 +1832,7 @@ void spl_ast_prase(spl_ast_t *ast) {
|
||||
|
||||
spl_ast_node_ref_vec_t members;
|
||||
vec_init(members);
|
||||
while (1) {
|
||||
while (!p.failed) {
|
||||
spl_tok_t *t = peek(&p);
|
||||
if (!t || t->type == TOK_EOF)
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user