From 5dfbf8ec179e65387bb27ea65b49f3e47ac26be9 Mon Sep 17 00:00:00 2001 From: "K. Lange" Date: Mon, 8 Mar 2021 16:36:12 +0900 Subject: [PATCH] Various cleanups --- src/builtins.c | 4 ++-- src/obj_base.c | 1 + src/os.c | 6 +++--- src/threads.c | 12 ++++++------ test/day5.krk | 20 -------------------- test/testGeneratorExpressions.krk | 14 ++++---------- 6 files changed, 16 insertions(+), 41 deletions(-) diff --git a/src/builtins.c b/src/builtins.c index 7734698..ddd46f9 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -5,8 +5,8 @@ #include "util.h" #include "debug.h" -KrkClass * Helper; -KrkClass * LicenseReader; +static KrkClass * Helper; +static KrkClass * LicenseReader; KrkValue krk_dirObject(int argc, KrkValue argv[], int hasKw) { if (argc != 1) return krk_runtimeError(vm.exceptions->argumentError, "wrong number of arguments or bad type, got %d\n", argc); diff --git a/src/obj_base.c b/src/obj_base.c index 0c97240..7c9dfdf 100644 --- a/src/obj_base.c +++ b/src/obj_base.c @@ -59,6 +59,7 @@ static KrkValue _class_to_str(int argc, KrkValue argv[], int hasKw) { return OBJECT_VAL(out); } +_noexport void _createAndBind_type(void) { ADD_BASE_CLASS(vm.baseClasses->typeClass, "type", vm.baseClasses->objectClass); krk_defineNative(&vm.baseClasses->typeClass->methods, ":__base__", krk_baseOfClass); diff --git a/src/os.c b/src/os.c index 6bed6b4..38a145b 100644 --- a/src/os.c +++ b/src/os.c @@ -21,8 +21,8 @@ /* Did you know this is actually specified to not exist in a header? */ extern char ** environ; -KrkClass * OSError = NULL; -KrkClass * stat_result = NULL; +static KrkClass * OSError = NULL; +static KrkClass * stat_result = NULL; #define DO_KEY(key) krk_attachNamedObject(AS_DICT(result), #key, (KrkObj*)krk_copyString(buf. key, strlen(buf .key))) #define S_KEY(key,val) krk_attachNamedObject(AS_DICT(result), #key, (KrkObj*)val); @@ -89,7 +89,7 @@ KRK_FUNC(uname,{ }) #endif -KrkClass * environClass; +static KrkClass * environClass; KrkValue krk_os_setenviron(int argc, KrkValue argv[], int hasKw) { if (argc < 3 || !krk_isInstanceOf(argv[0], environClass) || diff --git a/src/threads.c b/src/threads.c index 3eea1e8..368241d 100644 --- a/src/threads.c +++ b/src/threads.c @@ -17,8 +17,9 @@ #define gettid() -1 #endif -KrkClass * ThreadError; -KrkClass * Thread; +static KrkClass * ThreadError; +static KrkClass * Thread; + /** * @brief Object representation of a system thread. * @extends KrkInstance @@ -38,7 +39,8 @@ struct Thread { unsigned int alive:1; }; -KrkClass * Lock; +static KrkClass * Lock; + /** * @brief Simple atomic structure for waiting. * @extends KrkInstance @@ -192,8 +194,6 @@ KRK_METHOD(Lock,__exit__,{ pthread_mutex_unlock(&self->mutex); }) -KrkInstance * threadsModule; - _noexport void _createAndBind_threadsMod(void) { /** @@ -201,7 +201,7 @@ void _createAndBind_threadsMod(void) { * * Methods for dealing with threads. */ - threadsModule = krk_newInstance(vm.baseClasses->moduleClass); + KrkInstance * threadsModule = krk_newInstance(vm.baseClasses->moduleClass); krk_attachNamedObject(&vm.modules, "threading", (KrkObj*)threadsModule); krk_attachNamedObject(&threadsModule->fields, "__name__", (KrkObj*)S("threading")); diff --git a/test/day5.krk b/test/day5.krk index 34d700e..7e971d7 100644 --- a/test/day5.krk +++ b/test/day5.krk @@ -49,26 +49,6 @@ for l in lines: let i = seat_id(l) taken[i] = 1 -def min(iter): - let l # Silly way to get the first value of an iterable that doesn't do [] - for v in iter: - l = v - break - for v in iter: - if v < l: - l = v - return l - -def max(iter): - let l # Silly way to get the first value of an iterable that doesn't do [] - for v in iter: - l = v - break - for v in iter: - if v > l: - l = v - return l - print("---") for i in range(min(taken.keys()), max(taken.keys())): if (i - 1) in taken and (i + 1) in taken and i not in taken: diff --git a/test/testGeneratorExpressions.krk b/test/testGeneratorExpressions.krk index 3ce1b7e..1124171 100644 --- a/test/testGeneratorExpressions.krk +++ b/test/testGeneratorExpressions.krk @@ -1,21 +1,15 @@ -def _sum(iterable): - let total = 0 - for i in iterable: - total += i - return total - -print(_sum([x * x for x in range(10)])) -print(_sum((x * x for x in range(10)))) +print(sum([x * x for x in range(10)])) +print(sum((x * x for x in range(10)))) print('generator object' in str((x * x for x in range(10)))) # Should be directly usable as function argument -print(_sum(x * x for x in range(10))) +print(sum(x * x for x in range(10))) import dis # Should have a compile error: try: - dis.build('_sum(x * x for x in range(10), 2, 3)') + dis.build('sum(x * x for x in range(10), 2, 3)') except SyntaxError as e: print('parenthesized' in str(e))