diff options
| author | Lam Wei Lun <weilun.lam@gmail.com> | 2026-01-21 02:47:13 +0800 |
|---|---|---|
| committer | Lam Wei Lun <weilun.lam@gmail.com> | 2026-01-21 02:47:13 +0800 |
| commit | 14463b3961c03eac5c4f2fa493a354bc866bf6c2 (patch) | |
| tree | 50cac4e039b312be91af80c2092fbc2361e2b49d /src/parser | |
| parent | 451e6b1fff77bccedccdb745e4ee56cbeef31b79 (diff) | |
| parent | 6165c437410052fa177fc1245c176ec6709a9da7 (diff) | |
Upstream main
Diffstat (limited to 'src/parser')
| -rw-r--r-- | src/parser/parser_core.c | 6 | ||||
| -rw-r--r-- | src/parser/parser_stmt.c | 31 |
2 files changed, 25 insertions, 12 deletions
diff --git a/src/parser/parser_core.c b/src/parser/parser_core.c index 3c2805c..464c905 100644 --- a/src/parser/parser_core.c +++ b/src/parser/parser_core.c @@ -622,6 +622,12 @@ static ASTNode *generate_derive_impls(ParserContext *ctx, ASTNode *strct, char * sprintf(code, "impl %s { fn to_string(self) -> char* { return \"%s { ... }\"; } }", name, name); } + else if (0 == strcmp(trait, "Copy")) + { + // Marker trait for Copy/Move semantics + code = xmalloc(1024); + sprintf(code, "impl Copy for %s {}", name); + } if (code) { diff --git a/src/parser/parser_stmt.c b/src/parser/parser_stmt.c index c5efe8a..a8c8df5 100644 --- a/src/parser/parser_stmt.c +++ b/src/parser/parser_stmt.c @@ -4269,30 +4269,37 @@ ASTNode *parse_import(ParserContext *ctx, Lexer *l) strncpy(fn, t.start + 1, ln); fn[ln] = 0; - // Resolve relative paths (if starts with ./ or ../ + // Resolve paths relative to current file char resolved_path[1024]; - if (fn[0] == '.' && (fn[1] == '/' || (fn[1] == '.' && fn[2] == '/'))) + int is_explicit_relative = (fn[0] == '.' && (fn[1] == '/' || (fn[1] == '.' && fn[2] == '/'))); + + // Try to resolve relative to current file if not absolute + if (fn[0] != '/') { - // Relative import - resolve relative to current file char *current_dir = xstrdup(g_current_filename); char *last_slash = strrchr(current_dir, '/'); if (last_slash) { *last_slash = 0; // Truncate to directory + + // Handle explicit relative differently? + // Existing logic enforced it. Let's try to verify existence first. + + // Construct candidate path const char *leaf = fn; - if (leaf[0] == '.' && leaf[1] == '/') + // Clean up ./ prefix for cleaner path construction if we want + // but keeping it is fine too, /path/to/./file works. + + snprintf(resolved_path, sizeof(resolved_path), "%s/%s", current_dir, leaf); + + // If it's an explicit relative path, OR if the file exists at this relative location + if (is_explicit_relative || access(resolved_path, R_OK) == 0) { - leaf += 2; + free(fn); + fn = xstrdup(resolved_path); } - snprintf(resolved_path, sizeof(resolved_path), "%s/%s", current_dir, leaf); - } - else - { - snprintf(resolved_path, sizeof(resolved_path), "%s", fn); } free(current_dir); - free(fn); - fn = xstrdup(resolved_path); } // Check if file exists, if not try system-wide paths |
