Various cleanups
This commit is contained in:
parent
90f4c75127
commit
5dfbf8ec17
@ -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);
|
||||
|
@ -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);
|
||||
|
6
src/os.c
6
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) ||
|
||||
|
@ -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"));
|
||||
|
@ -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:
|
||||
|
@ -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))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user