Various cleanups

This commit is contained in:
K. Lange 2021-03-08 16:36:12 +09:00
parent 90f4c75127
commit 5dfbf8ec17
6 changed files with 16 additions and 41 deletions

View File

@ -5,8 +5,8 @@
#include "util.h" #include "util.h"
#include "debug.h" #include "debug.h"
KrkClass * Helper; static KrkClass * Helper;
KrkClass * LicenseReader; static KrkClass * LicenseReader;
KrkValue krk_dirObject(int argc, KrkValue argv[], int hasKw) { 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); if (argc != 1) return krk_runtimeError(vm.exceptions->argumentError, "wrong number of arguments or bad type, got %d\n", argc);

View File

@ -59,6 +59,7 @@ static KrkValue _class_to_str(int argc, KrkValue argv[], int hasKw) {
return OBJECT_VAL(out); return OBJECT_VAL(out);
} }
_noexport
void _createAndBind_type(void) { void _createAndBind_type(void) {
ADD_BASE_CLASS(vm.baseClasses->typeClass, "type", vm.baseClasses->objectClass); ADD_BASE_CLASS(vm.baseClasses->typeClass, "type", vm.baseClasses->objectClass);
krk_defineNative(&vm.baseClasses->typeClass->methods, ":__base__", krk_baseOfClass); krk_defineNative(&vm.baseClasses->typeClass->methods, ":__base__", krk_baseOfClass);

View File

@ -21,8 +21,8 @@
/* Did you know this is actually specified to not exist in a header? */ /* Did you know this is actually specified to not exist in a header? */
extern char ** environ; extern char ** environ;
KrkClass * OSError = NULL; static KrkClass * OSError = NULL;
KrkClass * stat_result = 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 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); #define S_KEY(key,val) krk_attachNamedObject(AS_DICT(result), #key, (KrkObj*)val);
@ -89,7 +89,7 @@ KRK_FUNC(uname,{
}) })
#endif #endif
KrkClass * environClass; static KrkClass * environClass;
KrkValue krk_os_setenviron(int argc, KrkValue argv[], int hasKw) { KrkValue krk_os_setenviron(int argc, KrkValue argv[], int hasKw) {
if (argc < 3 || !krk_isInstanceOf(argv[0], environClass) || if (argc < 3 || !krk_isInstanceOf(argv[0], environClass) ||

View File

@ -17,8 +17,9 @@
#define gettid() -1 #define gettid() -1
#endif #endif
KrkClass * ThreadError; static KrkClass * ThreadError;
KrkClass * Thread; static KrkClass * Thread;
/** /**
* @brief Object representation of a system thread. * @brief Object representation of a system thread.
* @extends KrkInstance * @extends KrkInstance
@ -38,7 +39,8 @@ struct Thread {
unsigned int alive:1; unsigned int alive:1;
}; };
KrkClass * Lock; static KrkClass * Lock;
/** /**
* @brief Simple atomic structure for waiting. * @brief Simple atomic structure for waiting.
* @extends KrkInstance * @extends KrkInstance
@ -192,8 +194,6 @@ KRK_METHOD(Lock,__exit__,{
pthread_mutex_unlock(&self->mutex); pthread_mutex_unlock(&self->mutex);
}) })
KrkInstance * threadsModule;
_noexport _noexport
void _createAndBind_threadsMod(void) { void _createAndBind_threadsMod(void) {
/** /**
@ -201,7 +201,7 @@ void _createAndBind_threadsMod(void) {
* *
* Methods for dealing with threads. * 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(&vm.modules, "threading", (KrkObj*)threadsModule);
krk_attachNamedObject(&threadsModule->fields, "__name__", (KrkObj*)S("threading")); krk_attachNamedObject(&threadsModule->fields, "__name__", (KrkObj*)S("threading"));

View File

@ -49,26 +49,6 @@ for l in lines:
let i = seat_id(l) let i = seat_id(l)
taken[i] = 1 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("---") print("---")
for i in range(min(taken.keys()), max(taken.keys())): 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: if (i - 1) in taken and (i + 1) in taken and i not in taken:

View File

@ -1,21 +1,15 @@
def _sum(iterable): print(sum([x * x for x in range(10)]))
let total = 0 print(sum((x * x for x in range(10))))
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('generator object' in str((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 # 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 import dis
# Should have a compile error: # Should have a compile error:
try: 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: except SyntaxError as e:
print('parenthesized' in str(e)) print('parenthesized' in str(e))