diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-09-11 13:56:39 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-09-11 13:56:39 -0400 |
| commit | 75fbaa79bc88abe8868cb4508e9ab9390cb7b329 (patch) | |
| tree | c9a66af84908aa6ce188344ffa7d962a88ba95f2 | |
| parent | b0b23acf887bec28b5ef8d0dfe448c4228ee0eb3 (diff) | |
Rename closure_t -> Closure_t for consistency
| -rw-r--r-- | builtins/array.c | 18 | ||||
| -rw-r--r-- | builtins/array.h | 14 | ||||
| -rw-r--r-- | builtins/datatypes.h | 2 | ||||
| -rw-r--r-- | builtins/functions.h | 2 | ||||
| -rw-r--r-- | builtins/optionals.c | 2 | ||||
| -rw-r--r-- | builtins/optionals.h | 2 | ||||
| -rw-r--r-- | builtins/path.c | 4 | ||||
| -rw-r--r-- | builtins/path.h | 2 | ||||
| -rw-r--r-- | builtins/table.c | 2 | ||||
| -rw-r--r-- | builtins/text.c | 2 | ||||
| -rw-r--r-- | builtins/text.h | 2 | ||||
| -rw-r--r-- | builtins/thread.c | 2 | ||||
| -rw-r--r-- | builtins/thread.h | 2 | ||||
| -rw-r--r-- | compile.c | 18 |
14 files changed, 37 insertions, 37 deletions
diff --git a/builtins/array.c b/builtins/array.c index c9064eed..72e1c790 100644 --- a/builtins/array.c +++ b/builtins/array.c @@ -231,7 +231,7 @@ public Int_t Array$find(Array_t arr, void *item, const TypeInfo *type) return NULL_INT; } -public Int_t Array$first(Array_t arr, closure_t predicate) +public Int_t Array$first(Array_t arr, Closure_t predicate) { bool (*is_good)(void*, void*) = (void*)predicate.fn; for (int64_t i = 0; i < arr.length; i++) { @@ -241,7 +241,7 @@ public Int_t Array$first(Array_t arr, closure_t predicate) return NULL_INT; } -public void Array$sort(Array_t *arr, closure_t comparison, int64_t padded_item_size) +public void Array$sort(Array_t *arr, Closure_t comparison, int64_t padded_item_size) { if (arr->data_refcount != 0 || (int64_t)arr->stride != padded_item_size) Array$compact(arr, padded_item_size); @@ -249,7 +249,7 @@ public void Array$sort(Array_t *arr, closure_t comparison, int64_t padded_item_s qsort_r(arr->data, (size_t)arr->length, (size_t)padded_item_size, comparison.fn, comparison.userdata); } -public Array_t Array$sorted(Array_t arr, closure_t comparison, int64_t padded_item_size) +public Array_t Array$sorted(Array_t arr, Closure_t comparison, int64_t padded_item_size) { Array$compact(&arr, padded_item_size); qsort_r(arr.data, (size_t)arr.length, (size_t)padded_item_size, comparison.fn, comparison.userdata); @@ -578,7 +578,7 @@ public uint64_t Array$hash(const Array_t *arr, const TypeInfo *type) } #pragma GCC diagnostic ignored "-Wstack-protector" -static void siftdown(Array_t *heap, int64_t startpos, int64_t pos, closure_t comparison, int64_t padded_item_size) +static void siftdown(Array_t *heap, int64_t startpos, int64_t pos, Closure_t comparison, int64_t padded_item_size) { assert(pos > 0 && pos < heap->length); char newitem[padded_item_size]; @@ -596,7 +596,7 @@ static void siftdown(Array_t *heap, int64_t startpos, int64_t pos, closure_t com memcpy(heap->data + heap->stride*pos, newitem, (size_t)(padded_item_size)); } -static void siftup(Array_t *heap, int64_t pos, closure_t comparison, int64_t padded_item_size) +static void siftup(Array_t *heap, int64_t pos, Closure_t comparison, int64_t padded_item_size) { int64_t endpos = heap->length; int64_t startpos = pos; @@ -626,7 +626,7 @@ static void siftup(Array_t *heap, int64_t pos, closure_t comparison, int64_t pad siftdown(heap, startpos, pos, comparison, padded_item_size); } -public void Array$heap_push(Array_t *heap, const void *item, closure_t comparison, int64_t padded_item_size) +public void Array$heap_push(Array_t *heap, const void *item, Closure_t comparison, int64_t padded_item_size) { Array$insert(heap, item, I(0), padded_item_size); @@ -637,7 +637,7 @@ public void Array$heap_push(Array_t *heap, const void *item, closure_t compariso } } -public void Array$heap_pop(Array_t *heap, closure_t comparison, int64_t padded_item_size) +public void Array$heap_pop(Array_t *heap, Closure_t comparison, int64_t padded_item_size) { if (heap->length == 0) fail("Attempt to pop from an empty array"); @@ -656,7 +656,7 @@ public void Array$heap_pop(Array_t *heap, closure_t comparison, int64_t padded_i } } -public void Array$heapify(Array_t *heap, closure_t comparison, int64_t padded_item_size) +public void Array$heapify(Array_t *heap, Closure_t comparison, int64_t padded_item_size) { if (heap->data_refcount != 0) Array$compact(heap, padded_item_size); @@ -670,7 +670,7 @@ public void Array$heapify(Array_t *heap, closure_t comparison, int64_t padded_it ARRAY_DECREF(*heap); } -public Int_t Array$binary_search(Array_t array, void *target, closure_t comparison) +public Int_t Array$binary_search(Array_t array, void *target, Closure_t comparison) { typedef int32_t (*cmp_fn_t)(void*, void*, void*); int64_t lo = 0, hi = array.length-1; diff --git a/builtins/array.h b/builtins/array.h index 9a3e7bda..91272f9c 100644 --- a/builtins/array.h +++ b/builtins/array.h @@ -69,9 +69,9 @@ void Array$remove_item(Array_t *arr, void *item, Int_t max_removals, const TypeI #define Array$remove_item_value(arr, item_expr, max, type) ({ __typeof(item_expr) item = item_expr; Array$remove_item(arr, &item, max, type); }) Int_t Array$find(Array_t arr, void *item, const TypeInfo *type); #define Array$find_value(arr, item_expr, type) ({ __typeof(item_expr) item = item_expr; Array$find(arr, &item, type); }) -Int_t Array$first(Array_t arr, closure_t predicate); -void Array$sort(Array_t *arr, closure_t comparison, int64_t padded_item_size); -Array_t Array$sorted(Array_t arr, closure_t comparison, int64_t padded_item_size); +Int_t Array$first(Array_t arr, Closure_t predicate); +void Array$sort(Array_t *arr, Closure_t comparison, int64_t padded_item_size); +Array_t Array$sorted(Array_t arr, Closure_t comparison, int64_t padded_item_size); void Array$shuffle(Array_t *arr, int64_t padded_item_size); Array_t Array$shuffled(Array_t arr, int64_t padded_item_size); void *Array$random(Array_t arr); @@ -91,14 +91,14 @@ PUREFUNC uint64_t Array$hash(const Array_t *arr, const TypeInfo *type); PUREFUNC int32_t Array$compare(const Array_t *x, const Array_t *y, const TypeInfo *type); PUREFUNC bool Array$equal(const Array_t *x, const Array_t *y, const TypeInfo *type); Text_t Array$as_text(const Array_t *arr, bool colorize, const TypeInfo *type); -void Array$heapify(Array_t *heap, closure_t comparison, int64_t padded_item_size); -void Array$heap_push(Array_t *heap, const void *item, closure_t comparison, int64_t padded_item_size); +void Array$heapify(Array_t *heap, Closure_t comparison, int64_t padded_item_size); +void Array$heap_push(Array_t *heap, const void *item, Closure_t comparison, int64_t padded_item_size); #define Array$heap_push_value(heap, _value, comparison, padded_item_size) ({ __typeof(_value) value = _value; Array$heap_push(heap, &value, comparison, padded_item_size); }) -void Array$heap_pop(Array_t *heap, closure_t comparison, int64_t padded_item_size); +void Array$heap_pop(Array_t *heap, Closure_t comparison, int64_t padded_item_size); #define Array$heap_pop_value(heap, comparison, padded_item_size, type) \ ({ Array_t *_heap = heap; if (_heap->length == 0) fail("Attempt to pop from an empty array"); \ type value = *(type*)_heap->data; Array$heap_pop(_heap, comparison, padded_item_size); value; }) -Int_t Array$binary_search(Array_t array, void *target, closure_t comparison); +Int_t Array$binary_search(Array_t array, void *target, Closure_t comparison); #define Array$binary_search_value(array, target, comparison) \ ({ __typeof(target) _target = target; Array$binary_search(array, &_target, comparison); }) diff --git a/builtins/datatypes.h b/builtins/datatypes.h index aa7670b7..c08d92dd 100644 --- a/builtins/datatypes.h +++ b/builtins/datatypes.h @@ -58,7 +58,7 @@ typedef struct table_s { typedef struct { void *fn, *userdata; -} closure_t; +} Closure_t; typedef struct Range_s { Int_t first, last, step; diff --git a/builtins/functions.h b/builtins/functions.h index f258a20d..550676b4 100644 --- a/builtins/functions.h +++ b/builtins/functions.h @@ -30,7 +30,7 @@ PUREFUNC int32_t generic_compare(const void *x, const void *y, const TypeInfo *t PUREFUNC bool generic_equal(const void *x, const void *y, const TypeInfo *type); Text_t generic_as_text(const void *obj, bool colorize, const TypeInfo *type); int generic_print(const void *obj, bool colorize, const TypeInfo *type); -closure_t spawn(closure_t fn); +Closure_t spawn(Closure_t fn); bool pop_flag(char **argv, int *i, const char *flag, Text_t *result); void print_stack_trace(FILE *out, int start, int stop); diff --git a/builtins/optionals.c b/builtins/optionals.c index b38883fb..065d535a 100644 --- a/builtins/optionals.c +++ b/builtins/optionals.c @@ -11,7 +11,7 @@ public const Array_t NULL_ARRAY = {.length=-1}; public const Bool_t NULL_BOOL = -1; public const Int_t NULL_INT = {.small=0}; public const Table_t NULL_TABLE = {.entries.length=-1}; -public const closure_t NULL_CLOSURE = {.fn=NULL}; +public const Closure_t NULL_CLOSURE = {.fn=NULL}; public const Text_t NULL_TEXT = {.length=-1}; static inline bool is_null(const void *obj, const TypeInfo *non_optional_type) diff --git a/builtins/optionals.h b/builtins/optionals.h index a0b9b0e0..a6ff5c72 100644 --- a/builtins/optionals.h +++ b/builtins/optionals.h @@ -17,7 +17,7 @@ extern const Bool_t NULL_BOOL; extern const Table_t NULL_TABLE; extern const Array_t NULL_ARRAY; extern const Int_t NULL_INT; -extern const closure_t NULL_CLOSURE; +extern const Closure_t NULL_CLOSURE; extern const Text_t NULL_TEXT; Text_t Optional$as_text(const void *obj, bool colorize, const TypeInfo *type); diff --git a/builtins/path.c b/builtins/path.c index 096cbdd0..ab032927 100644 --- a/builtins/path.c +++ b/builtins/path.c @@ -456,7 +456,7 @@ static NextLine_t _next_line(FILE **f) return NextLine$tagged$Next(line_text); } -public closure_t Path$by_line(Path_t path) +public Closure_t Path$by_line(Path_t path) { path = Path$_expand_home(path); @@ -467,7 +467,7 @@ public closure_t Path$by_line(Path_t path) FILE **wrapper = GC_MALLOC(sizeof(FILE*)); *wrapper = f; GC_register_finalizer(wrapper, (void*)_line_reader_cleanup, NULL, NULL, NULL); - return (closure_t){.fn=(void*)_next_line, .userdata=wrapper}; + return (Closure_t){.fn=(void*)_next_line, .userdata=wrapper}; } public const TypeInfo Path$info = { diff --git a/builtins/path.h b/builtins/path.h index dd42af85..64a1d72d 100644 --- a/builtins/path.h +++ b/builtins/path.h @@ -39,7 +39,7 @@ Text_t Path$write_unique(Path_t path, Text_t text); Path_t Path$parent(Path_t path); Text_t Path$base_name(Path_t path); Text_t Path$extension(Path_t path, bool full); -closure_t Path$by_line(Path_t path); +Closure_t Path$by_line(Path_t path); #define Path$hash Text$hash #define Path$compare Text$compare diff --git a/builtins/table.c b/builtins/table.c index cd87c897..c8a73fdf 100644 --- a/builtins/table.c +++ b/builtins/table.c @@ -388,7 +388,7 @@ public void Table$clear(Table_t *t) public Table_t Table$sorted(Table_t t, const TypeInfo *type) { - closure_t cmp = (closure_t){.fn=generic_compare, .userdata=(void*)type->TableInfo.key}; + Closure_t cmp = (Closure_t){.fn=generic_compare, .userdata=(void*)type->TableInfo.key}; Array_t entries = Array$sorted(t.entries, cmp, (int64_t)entry_size(type)); return Table$from_entries(entries, type); } diff --git a/builtins/text.c b/builtins/text.c index be00667c..3902863b 100644 --- a/builtins/text.c +++ b/builtins/text.c @@ -2051,7 +2051,7 @@ public Text_t Text$trim(Text_t text, Pattern_t pattern, bool trim_left, bool tri return Text$slice(text, I(first+1), I(last+1)); } -public Text_t Text$map(Text_t text, Pattern_t pattern, closure_t fn) +public Text_t Text$map(Text_t text, Pattern_t pattern, Closure_t fn) { Text_t ret = {.length=0}; diff --git a/builtins/text.h b/builtins/text.h index e35c193f..2e58ad60 100644 --- a/builtins/text.h +++ b/builtins/text.h @@ -56,7 +56,7 @@ Text_t Text$from_codepoint_names(Array_t codepoint_names); Text_t Text$from_bytes(Array_t bytes); Array_t Text$lines(Text_t text); Text_t Text$join(Text_t glue, Array_t pieces); -Text_t Text$map(Text_t text, Pattern_t pattern, closure_t fn); +Text_t Text$map(Text_t text, Pattern_t pattern, Closure_t fn); Text_t Text$repeat(Text_t text, Int_t count); extern const TypeInfo Text$info; diff --git a/builtins/thread.c b/builtins/thread.c index b9193787..b842da94 100644 --- a/builtins/thread.c +++ b/builtins/thread.c @@ -16,7 +16,7 @@ #include "types.h" #include "util.h" -public pthread_t *Thread$new(closure_t fn) +public pthread_t *Thread$new(Closure_t fn) { pthread_t *thread = new(pthread_t); pthread_create(thread, NULL, fn.fn, fn.userdata); diff --git a/builtins/thread.h b/builtins/thread.h index 2956dda6..2e3298cb 100644 --- a/builtins/thread.h +++ b/builtins/thread.h @@ -10,7 +10,7 @@ #include "types.h" #include "util.h" -pthread_t *Thread$new(closure_t fn); +pthread_t *Thread$new(Closure_t fn); void Thread$cancel(pthread_t *thread); void Thread$join(pthread_t *thread); void Thread$detach(pthread_t *thread); @@ -91,7 +91,7 @@ static bool promote(env_t *env, CORD *code, type_t *actual, type_t *needed) return true; if (needed->tag == ClosureType && actual->tag == FunctionType) { - *code = CORD_all("((closure_t){", *code, ", NULL})"); + *code = CORD_all("((Closure_t){", *code, ", NULL})"); return true; } @@ -207,7 +207,7 @@ CORD compile_type(type_t *t) } return CORD_all(code, ")"); } - case ClosureType: return "closure_t"; + case ClosureType: return "Closure_t"; case PointerType: return CORD_cat(compile_type(Match(t, PointerType)->pointed), "*"); case StructType: { if (t == THREAD_TYPE) @@ -2388,7 +2388,7 @@ CORD compile(env_t *env, ast_t *ast) body = CORD_all(body, compile_statement(body_scope, FakeAST(Return)), "\n"); env->code->funcs = CORD_all(env->code->funcs, code, " {\n", body, "\n}\n"); - return CORD_all("((closure_t){", name, ", ", userdata, "})"); + return CORD_all("((Closure_t){", name, ", ", userdata, "})"); } case MethodCall: { auto call = Match(ast, MethodCall); @@ -2457,7 +2457,7 @@ CORD compile(env_t *env, ast_t *ast) arg_t *arg_spec = new(arg_t, .name="by", .type=Type(ClosureType, .fn=fn_t)); comparison = compile_arguments(env, ast, arg_spec, call->args); } else { - comparison = CORD_all("((closure_t){.fn=generic_compare, .userdata=(void*)", compile_type_info(env, item_t), "})"); + comparison = CORD_all("((Closure_t){.fn=generic_compare, .userdata=(void*)", compile_type_info(env, item_t), "})"); } return CORD_all("Array$", call->name, "(", self, ", ", comparison, ", ", padded_item_size, ")"); } else if (streq(call->name, "heapify")) { @@ -2470,7 +2470,7 @@ CORD compile(env_t *env, ast_t *ast) arg_t *arg_spec = new(arg_t, .name="by", .type=Type(ClosureType, .fn=fn_t)); comparison = compile_arguments(env, ast, arg_spec, call->args); } else { - comparison = CORD_all("((closure_t){.fn=generic_compare, .userdata=(void*)", compile_type_info(env, item_t), "})"); + comparison = CORD_all("((Closure_t){.fn=generic_compare, .userdata=(void*)", compile_type_info(env, item_t), "})"); } return CORD_all("Array$heapify(", self, ", ", comparison, ", ", padded_item_size, ")"); } else if (streq(call->name, "heap_push")) { @@ -2479,7 +2479,7 @@ CORD compile(env_t *env, ast_t *ast) type_t *fn_t = Type(FunctionType, .args=new(arg_t, .name="x", .type=item_ptr, .next=new(arg_t, .name="y", .type=item_ptr)), .ret=Type(IntType, .bits=TYPE_IBITS32)); ast_t *default_cmp = FakeAST(InlineCCode, - .code=CORD_all("((closure_t){.fn=generic_compare, .userdata=(void*)", + .code=CORD_all("((Closure_t){.fn=generic_compare, .userdata=(void*)", compile_type_info(env, item_t), "})"), .type=NewTypeAST(NULL, NULL, NULL, FunctionTypeAST)); arg_t *arg_spec = new(arg_t, .name="item", .type=item_t, @@ -2492,7 +2492,7 @@ CORD compile(env_t *env, ast_t *ast) type_t *fn_t = Type(FunctionType, .args=new(arg_t, .name="x", .type=item_ptr, .next=new(arg_t, .name="y", .type=item_ptr)), .ret=Type(IntType, .bits=TYPE_IBITS32)); ast_t *default_cmp = FakeAST(InlineCCode, - .code=CORD_all("((closure_t){.fn=generic_compare, .userdata=(void*)", + .code=CORD_all("((Closure_t){.fn=generic_compare, .userdata=(void*)", compile_type_info(env, item_t), "})"), .type=NewTypeAST(NULL, NULL, NULL, FunctionTypeAST)); arg_t *arg_spec = new(arg_t, .name="by", .type=Type(ClosureType, .fn=fn_t), .default_val=default_cmp); @@ -2504,7 +2504,7 @@ CORD compile(env_t *env, ast_t *ast) type_t *fn_t = Type(FunctionType, .args=new(arg_t, .name="x", .type=item_ptr, .next=new(arg_t, .name="y", .type=item_ptr)), .ret=Type(IntType, .bits=TYPE_IBITS32)); ast_t *default_cmp = FakeAST(InlineCCode, - .code=CORD_all("((closure_t){.fn=generic_compare, .userdata=(void*)", + .code=CORD_all("((Closure_t){.fn=generic_compare, .userdata=(void*)", compile_type_info(env, item_t), "})"), .type=NewTypeAST(NULL, NULL, NULL, FunctionTypeAST)); arg_t *arg_spec = new(arg_t, .name="target", .type=item_t, @@ -2796,7 +2796,7 @@ CORD compile(env_t *env, ast_t *ast) if (call->fn->tag == Var) { return CORD_all("((", fn_type_code, ")", closure, ".fn)(", arg_code, closure, ".userdata)"); } else { - return CORD_all("({ closure_t closure = ", closure, "; ((", fn_type_code, ")closure.fn)(", + return CORD_all("({ Closure_t closure = ", closure, "; ((", fn_type_code, ")closure.fn)(", arg_code, "closure.userdata); })"); } } else { |
