diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/parser/parser_expr.c | 2 | ||||
| -rw-r--r-- | src/parser/parser_type.c | 99 | ||||
| -rw-r--r-- | src/parser/parser_utils.c | 48 | ||||
| -rw-r--r-- | src/repl/repl.c | 67 |
4 files changed, 188 insertions, 28 deletions
diff --git a/src/parser/parser_expr.c b/src/parser/parser_expr.c index b451a26..93a50e2 100644 --- a/src/parser/parser_expr.c +++ b/src/parser/parser_expr.c @@ -2855,7 +2855,6 @@ ASTNode *parse_expr_prec(ParserContext *ctx, Lexer *l, Precedence min_prec) call->call.arg_names = has_named ? arg_names : NULL; call->call.arg_count = arg_count; - // FIX: Propagate return type from function type info call->resolved_type = xstrdup("unknown"); if (lhs->type_info && lhs->type_info->kind == TYPE_FUNCTION && lhs->type_info->inner) { @@ -3037,7 +3036,6 @@ ASTNode *parse_expr_prec(ParserContext *ctx, Lexer *l, Precedence min_prec) node->type_info = get_field_type(ctx, lhs->type_info, node->member.field); - // FIX: If not a field, check if it is a method if (!node->type_info && lhs->type_info) { char *struct_name = NULL; diff --git a/src/parser/parser_type.c b/src/parser/parser_type.c index 04a7de9..941c763 100644 --- a/src/parser/parser_type.c +++ b/src/parser/parser_type.c @@ -79,6 +79,39 @@ Type *parse_type_base(ParserContext *ctx, Lexer *l) { resolved_suffix = "uint64_t"; } + // Lowercase aliases + else if (strcmp(suffix, "i8") == 0) + { + resolved_suffix = "int8_t"; + } + else if (strcmp(suffix, "u8") == 0) + { + resolved_suffix = "uint8_t"; + } + else if (strcmp(suffix, "i16") == 0) + { + resolved_suffix = "int16_t"; + } + else if (strcmp(suffix, "u16") == 0) + { + resolved_suffix = "uint16_t"; + } + else if (strcmp(suffix, "i32") == 0) + { + resolved_suffix = "int32_t"; + } + else if (strcmp(suffix, "u32") == 0) + { + resolved_suffix = "uint32_t"; + } + else if (strcmp(suffix, "i64") == 0) + { + resolved_suffix = "int64_t"; + } + else if (strcmp(suffix, "u64") == 0) + { + resolved_suffix = "uint64_t"; + } else if (strcmp(suffix, "usize") == 0) { resolved_suffix = "size_t"; @@ -123,6 +156,11 @@ Type *parse_type_base(ParserContext *ctx, Lexer *l) free(name); return type_new(TYPE_VOID); } + if (strcmp(name, "u0") == 0) + { + free(name); + return type_new(TYPE_VOID); + } if (strcmp(name, "I8") == 0) { free(name); @@ -168,11 +206,21 @@ Type *parse_type_base(ParserContext *ctx, Lexer *l) free(name); return type_new(TYPE_F32); } + if (strcmp(name, "f32") == 0) + { + free(name); + return type_new(TYPE_F32); + } if (strcmp(name, "F64") == 0) { free(name); return type_new(TYPE_F64); } + if (strcmp(name, "f64") == 0) + { + free(name); + return type_new(TYPE_F64); + } if (strcmp(name, "usize") == 0) { free(name); @@ -198,6 +246,56 @@ Type *parse_type_base(ParserContext *ctx, Lexer *l) free(name); return type_new(TYPE_U128); } + if (strcmp(name, "i8") == 0) + { + free(name); + return type_new(TYPE_I8); + } + if (strcmp(name, "u8") == 0) + { + free(name); + return type_new(TYPE_U8); + } + if (strcmp(name, "i16") == 0) + { + free(name); + return type_new(TYPE_I16); + } + if (strcmp(name, "u16") == 0) + { + free(name); + return type_new(TYPE_U16); + } + if (strcmp(name, "i32") == 0) + { + free(name); + return type_new(TYPE_I32); + } + if (strcmp(name, "u32") == 0) + { + free(name); + return type_new(TYPE_U32); + } + if (strcmp(name, "i64") == 0) + { + free(name); + return type_new(TYPE_I64); + } + if (strcmp(name, "u64") == 0) + { + free(name); + return type_new(TYPE_U64); + } + if (strcmp(name, "i128") == 0) + { + free(name); + return type_new(TYPE_I128); + } + if (strcmp(name, "u128") == 0) + { + free(name); + return type_new(TYPE_U128); + } if (strcmp(name, "rune") == 0) { free(name); @@ -300,7 +398,6 @@ Type *parse_type_base(ParserContext *ctx, Lexer *l) zpanic_at(t, "Expected > after generic"); } - // --- INSTANTIATION TRIGGER --- char *arg_str = type_to_string(arg); instantiate_generic(ctx, name, arg_str); diff --git a/src/parser/parser_utils.c b/src/parser/parser_utils.c index ef66104..7733ef7 100644 --- a/src/parser/parser_utils.c +++ b/src/parser/parser_utils.c @@ -1057,10 +1057,18 @@ Type *replace_type_formal(Type *t, const char *p, const char *c, const char *os, { return type_new(TYPE_F32); } + if (strcmp(c, "f32") == 0) + { + return type_new(TYPE_F32); + } if (strcmp(c, "F64") == 0) { return type_new(TYPE_F64); } + if (strcmp(c, "f64") == 0) + { + return type_new(TYPE_F64); + } if (strcmp(c, "usize") == 0) { @@ -1082,6 +1090,46 @@ Type *replace_type_formal(Type *t, const char *p, const char *c, const char *os, { return type_new(TYPE_U128); } + if (strcmp(c, "i8") == 0) + { + return type_new(TYPE_I8); + } + if (strcmp(c, "u8") == 0) + { + return type_new(TYPE_U8); + } + if (strcmp(c, "i16") == 0) + { + return type_new(TYPE_I16); + } + if (strcmp(c, "u16") == 0) + { + return type_new(TYPE_U16); + } + if (strcmp(c, "i32") == 0) + { + return type_new(TYPE_I32); + } + if (strcmp(c, "u32") == 0) + { + return type_new(TYPE_U32); + } + if (strcmp(c, "i64") == 0) + { + return type_new(TYPE_I64); + } + if (strcmp(c, "u64") == 0) + { + return type_new(TYPE_U64); + } + if (strcmp(c, "i128") == 0) + { + return type_new(TYPE_I128); + } + if (strcmp(c, "u128") == 0) + { + return type_new(TYPE_U128); + } if (strcmp(c, "rune") == 0) { diff --git a/src/repl/repl.c b/src/repl/repl.c index c259bff..22fe95d 100644 --- a/src/repl/repl.c +++ b/src/repl/repl.c @@ -1218,9 +1218,8 @@ void run_repl(const char *self_path) child->type == NODE_EXPR_CALL || child->type == NODE_EXPR_MEMBER || child->type == NODE_EXPR_INDEX || child->type == NODE_EXPR_CAST || child->type == NODE_EXPR_SIZEOF || child->type == NODE_EXPR_STRUCT_INIT || - child->type == NODE_EXPR_ARRAY_LITERAL || - child->type == NODE_EXPR_SLICE || child->type == NODE_TERNARY || - child->type == NODE_MATCH) + child->type == NODE_EXPR_ARRAY_LITERAL || child->type == NODE_EXPR_SLICE || + child->type == NODE_TERNARY || child->type == NODE_MATCH) { is_expr = 1; } @@ -1229,21 +1228,30 @@ void run_repl(const char *self_path) if (is_expr) { size_t probesz = 4096; - for(int i=0; i<history_len-1; i++) probesz += strlen(history[i]) + 2; + for (int i = 0; i < history_len - 1; i++) + { + probesz += strlen(history[i]) + 2; + } char *probe_code = malloc(probesz + strlen(last_line) + 512); strcpy(probe_code, ""); - - for (int i = 0; i < history_len - 1; i++) { - if (is_header_line(history[i])) { - strcat(probe_code, history[i]); strcat(probe_code, "\n"); + + for (int i = 0; i < history_len - 1; i++) + { + if (is_header_line(history[i])) + { + strcat(probe_code, history[i]); + strcat(probe_code, "\n"); } } - + strcat(probe_code, "fn main() { _z_suppress_stdout(); "); - - for (int i = 0; i < history_len - 1; i++) { - if (!is_header_line(history[i])) { - strcat(probe_code, history[i]); strcat(probe_code, " "); + + for (int i = 0; i < history_len - 1; i++) + { + if (!is_header_line(history[i])) + { + strcat(probe_code, history[i]); + strcat(probe_code, " "); } } @@ -1255,33 +1263,42 @@ void run_repl(const char *self_path) char p_path[256]; sprintf(p_path, "/tmp/zprep_repl_probe_%d.zc", rand()); FILE *pf = fopen(p_path, "w"); - if (pf) { + if (pf) + { fprintf(pf, "%s", probe_code); fclose(pf); - + char p_cmd[2048]; sprintf(p_cmd, "%s run -q %s 2>&1", self_path, p_path); - + FILE *pp = popen(p_cmd, "r"); int is_void = 0; - if (pp) { + if (pp) + { char buf[1024]; - while(fgets(buf, sizeof(buf), pp)) { - if (strstr(buf, "void") && strstr(buf, "expression")) { + while (fgets(buf, sizeof(buf), pp)) + { + if (strstr(buf, "void") && strstr(buf, "expression")) + { is_void = 1; } } pclose(pp); } - if (!is_void) { - strcat(full_code, "println \"{"); - strcat(full_code, last_line); - strcat(full_code, "}\";"); - } else { + if (!is_void) + { + strcat(full_code, "println \"{"); strcat(full_code, last_line); + strcat(full_code, "}\";"); } - } else { + else + { + strcat(full_code, last_line); + } + } + else + { strcat(full_code, last_line); } free(probe_code); |
