diff options
| -rw-r--r-- | ast.h | 2 | ||||
| -rw-r--r-- | builtins/files.c | 22 | ||||
| -rw-r--r-- | builtins/util.c | 6 | ||||
| -rw-r--r-- | builtins/util.h | 1 | ||||
| -rw-r--r-- | parse.c | 2 | ||||
| -rw-r--r-- | repl.c | 2 | ||||
| -rw-r--r-- | tomo.c | 2 | ||||
| -rw-r--r-- | typecheck.c | 4 |
8 files changed, 17 insertions, 24 deletions
@@ -16,7 +16,7 @@ .tag=ast_tag, .__data.ast_tag={__VA_ARGS__})) #define FakeAST(ast_tag, ...) (new(ast_t, .tag=ast_tag, .__data.ast_tag={__VA_ARGS__})) #define WrapAST(ast, ast_tag, ...) (new(ast_t, .file=(ast)->file, .start=(ast)->start, .end=(ast)->end, .tag=ast_tag, .__data.ast_tag={__VA_ARGS__})) -#define TextAST(ast, _str) WrapAST(ast, TextLiteral, .str=heap_str(_str)) +#define TextAST(ast, _str) WrapAST(ast, TextLiteral, .str=GC_strdup(_str)) struct binding_s; typedef struct type_ast_s type_ast_t; diff --git a/builtins/files.c b/builtins/files.c index 6c833469..70c76484 100644 --- a/builtins/files.c +++ b/builtins/files.c @@ -28,36 +28,36 @@ public char *resolve_path(const char *path, const char *relative_to, const char char buf[PATH_MAX] = {0}; if (streq(path, "~") || strncmp(path, "~/", 2) == 0) { char *resolved = realpath(heap_strf("%s%s", getenv("HOME"), path+1), buf); - if (resolved) return heap_str(resolved); + if (resolved) return GC_strdup(resolved); } else if (streq(path, ".") || strncmp(path, "./", 2) == 0) { - char *relative_dir = dirname(heap_str(relative_to)); + char *relative_dir = dirname(GC_strdup(relative_to)); char *resolved = realpath(heap_strf("%s/%s", relative_dir, path), buf); - if (resolved) return heap_str(resolved); + if (resolved) return GC_strdup(resolved); } else if (path[0] == '/') { // Absolute path: char *resolved = realpath(path, buf); - if (resolved) return heap_str(resolved); + if (resolved) return GC_strdup(resolved); } else { // Relative path: - char *relative_dir = dirname(heap_str(relative_to)); + char *relative_dir = dirname(GC_strdup(relative_to)); if (!system_path) system_path = "."; - char *copy = heap_str(system_path); + char *copy = GC_strdup(system_path); for (char *dir, *pos = copy; (dir = strsep(&pos, ":")); ) { if (dir[0] == '/') { char *resolved = realpath(heap_strf("%s/%s", dir, path), buf); - if (resolved) return heap_str(resolved); + if (resolved) return GC_strdup(resolved); } else if (dir[0] == '~' && (dir[1] == '\0' || dir[1] == '/')) { char *resolved = realpath(heap_strf("%s%s/%s", getenv("HOME"), dir+1, path), buf); - if (resolved) return heap_str(resolved); + if (resolved) return GC_strdup(resolved); } else if (streq(dir, ".") || strncmp(dir, "./", 2) == 0) { char *resolved = realpath(heap_strf("%s/%s", relative_dir, path), buf); - if (resolved) return heap_str(resolved); + if (resolved) return GC_strdup(resolved); } else if (streq(dir, ".") || streq(dir, "..") || strncmp(dir, "./", 2) == 0 || strncmp(dir, "../", 3) == 0) { char *resolved = realpath(heap_strf("%s/%s/%s", relative_dir, dir, path), buf); - if (resolved) return heap_str(resolved); + if (resolved) return GC_strdup(resolved); } else { char *resolved = realpath(heap_strf("%s/%s", dir, path), buf); - if (resolved) return heap_str(resolved); + if (resolved) return GC_strdup(resolved); } } } diff --git a/builtins/util.c b/builtins/util.c index 598ab259..d4f3cd31 100644 --- a/builtins/util.c +++ b/builtins/util.c @@ -11,12 +11,6 @@ public bool USE_COLOR; -public char *heap_str(const char *str) -{ - if (!str) return NULL; - return GC_strndup(str, strlen(str)); -} - public char *heap_strf(const char *fmt, ...) { va_list args; diff --git a/builtins/util.h b/builtins/util.h index 08de9779..bc0a5828 100644 --- a/builtins/util.h +++ b/builtins/util.h @@ -25,7 +25,6 @@ extern bool USE_COLOR; -char *heap_str(const char *str); char *heap_strf(const char *fmt, ...); CORD CORD_asprintf(CORD fmt, ...); #define CORD_appendf(cord, fmt, ...) CORD_sprintf(cord, "%r" fmt, *(cord) __VA_OPT__(,) __VA_ARGS__) @@ -156,7 +156,7 @@ const char *unescape(const char **out) { assert(*escape == '\\'); if (unescapes[(int)escape[1]]) { *endpos = escape + 2; - return heap_str(unescapes[(int)escape[1]]); + return GC_strdup(unescapes[(int)escape[1]]); } else if (escape[1] == 'U' && escape[2]) { char *endptr = NULL; long codepoint = strtol(escape+2, &endptr, 16); @@ -50,7 +50,7 @@ void repl(void) || starts_with(line, "func") || starts_with(line, "struct") || starts_with(line, "lang")) { printf("\x1b[33;1m..\x1b[m "); fflush(stdout); - code = heap_str(line); + code = GC_strdup(line); while ((len=getline(&line, &buf_size, stdin)) >= 0) { if (len == 1) break; code = heap_strf("%s%s", code, line); @@ -192,7 +192,7 @@ int main(int argc, char *argv[]) // For shared objects, link up all the object files into one .so file: if (mode == MODE_COMPILE_SHARED_OBJ) { - char *libname_id = heap_str(libname); + char *libname_id = GC_strdup(libname); for (char *p = libname_id; *p; p++) { if (!isalnum(*p) && *p != '_' && *p != '$') *p = '_'; diff --git a/typecheck.c b/typecheck.c index 52af8371..49ebe582 100644 --- a/typecheck.c +++ b/typecheck.c @@ -130,7 +130,7 @@ static env_t *load_module(env_t *env, ast_t *module_ast) env_t *module_env = fresh_scope(env); Table$str_set(env->imports, libname, module_env); - char *libname_id = heap_str(libname); + char *libname_id = GC_strdup(libname); for (char *c = libname_id; *c; c++) { if (!isalnum(*c) && *c != '_') *c = '_'; @@ -147,7 +147,7 @@ static env_t *load_module(env_t *env, ast_t *module_ast) ast_t *ast = parse_file(tm_path, NULL); if (!ast) errx(1, "Could not compile file %s", tm_path); env_t *module_file_env = fresh_scope(module_env); - char *file_prefix = heap_str(file_base_name(line)); + char *file_prefix = GC_strdup(file_base_name(line)); for (char *p = file_prefix; *p; p++) { if (!isalnum(*p) && *p != '_' && *p != '$') *p = '_'; |
