10 FUNC_SIG(list,__init__);
15 return krk_runtimeError(
vm.exceptions->argumentError,
"%s() takes %s %d argument%s (%d given)",
16 "dir",
"exactly", 1,
"", argc);
22 if (IS_INSTANCE(argv[0])) {
25 for (
size_t i = 0; i <
self->fields.capacity; ++i) {
26 if (!IS_KWARGS(self->fields.entries[i].key)) {
28 self->fields.entries[i].key);
31 }
else if (IS_CLOSURE(argv[0])) {
34 for (
size_t i = 0; i <
self->fields.capacity; ++i) {
35 if (!IS_KWARGS(self->fields.entries[i].key)) {
37 self->fields.entries[i].key);
40 }
else if (IS_CLASS(argv[0])) {
41 KrkClass * _class = AS_CLASS(argv[0]);
49 _class = _class->
base;
81 #define IS_object(o) (1)
82 #define AS_object(o) (o)
83 #define CURRENT_CTYPE KrkValue
84 #define CURRENT_NAME self
86 KRK_Method(
object,__dir__) {
90 KRK_Method(
object,__class__) {
93 if (!IS_CLASS(argv[1]))
return krk_runtimeError(
vm.exceptions->typeError,
"'%T' object is not a class", argv[1]);
95 if (AS_CLASS(argv[1])->allocSize !=
sizeof(
KrkInstance))
return krk_runtimeError(
vm.exceptions->typeError,
"'%S' type is not assignable", AS_CLASS(argv[1])->name);
96 AS_INSTANCE(argv[0])->_class = AS_CLASS(argv[1]);
97 current = AS_CLASS(argv[1]);
99 return OBJECT_VAL(current);
102 KRK_Method(
object,__hash__) {
103 if (!IS_OBJECT(
self)) {
106 return INTEGER_VAL(hashed);
108 KrkObj * obj = AS_OBJECT(
self);
109 if (!(obj->
flags & KRK_OBJ_FLAGS_VALID_HASH)) {
110 obj->
hash = (uint32_t)((intptr_t)(obj) >> 3);
111 obj->
flags |= KRK_OBJ_FLAGS_VALID_HASH;
113 return INTEGER_VAL(obj->
hash);
116 KRK_Method(
object,__eq__) {
117 METHOD_TAKES_EXACTLY(1);
119 return NOTIMPL_VAL();
122 KRK_Function(getattr) {
123 FUNCTION_TAKES_AT_LEAST(2);
129 if (argc == 3)
return argv[2];
130 return krk_runtimeError(
vm.exceptions->attributeError,
"'%T' object has no attribute '%S'", argv[0], AS_STRING(argv[1]));
135 KRK_Function(setattr) {
136 FUNCTION_TAKES_EXACTLY(3);
142 return krk_runtimeError(
vm.exceptions->attributeError,
"'%T' object has no attribute '%S'", argv[0], AS_STRING(argv[1]));
147 KRK_Function(hasattr) {
148 FUNCTION_TAKES_AT_LEAST(2);
154 return BOOLEAN_VAL(0);
157 return BOOLEAN_VAL(1);
160 KRK_Function(delattr) {
161 FUNCTION_TAKES_AT_LEAST(2);
166 return krk_runtimeError(
vm.exceptions->attributeError,
"'%T' object has no attribute '%S'", argv[0], AS_STRING(argv[1]));
175 KRK_Method(
object,__setattr__) {
176 METHOD_TAKES_EXACTLY(2);
177 if (!IS_STRING(argv[1]))
return krk_runtimeError(
vm.exceptions->typeError,
"expected str");
179 if (!IS_INSTANCE(argv[0])) {
180 return FUNC_NAME(krk,setattr)(argc,argv,hasKw);
187 KRK_StaticMethod(
object,__new__) {
194 if (!
krk_parseArgs(
"O!*~", (
const char*[]){
"cls"},
vm.baseClasses->typeClass, &_class, &_argc, &_args)) {
200 if (_cls->_new && IS_NATIVE(OBJECT_VAL(_cls->_new)) && _cls->_new != KRK_BASE_CLASS(
object)->_new) {
201 return krk_runtimeError(
vm.exceptions->typeError,
"object.__new__(%S) is not safe, use %S.__new__()", _class->
name, _cls->
name);
206 if (_class->
_init ==
vm.baseClasses->objectClass->_init && (_argc || (hasKw && AS_DICT(argv[argc])->count))) {
213 KRK_Method(
object,__init__) {
217 KRK_StaticMethod(
object,__init_subclass__) {
218 if (!
krk_parseArgs(
".", (
const char*[]){NULL}, NULL))
return NONE_VAL();
236 KRK_Method(
object,__repr__) {
243 KrkString * name = IS_STRING(qualname) ? AS_STRING(qualname) : type->name;
244 int includeModule = !(IS_NONE(module) || (IS_STRING(module) && AS_STRING(module) == S(
"builtins")));
248 if (!krk_pushStringBuilderFormat(&sb,
"<%s%s%s object",
249 includeModule ? AS_CSTRING(module) :
"",
250 includeModule ?
"." :
"",
251 name->
chars))
goto _error;
253 if (IS_OBJECT(
self) && !krk_pushStringBuilderFormat(&sb,
" at %p", (
void*)AS_OBJECT(
self))) {
265 KRK_Method(
object,__str__) {
272 KRK_Method(
object,__format__) {
273 METHOD_TAKES_EXACTLY(1);
274 if (!IS_STRING(argv[1]))
return TYPE_ERROR(str,argv[1]);
275 if (AS_STRING(argv[1])->length != 0)
return krk_runtimeError(
vm.exceptions->typeError,
"Unsupported format string");
286 FUNCTION_TAKES_EXACTLY(1);
288 if (IS_STRING(argv[0]))
return INTEGER_VAL(AS_STRING(argv[0])->codesLength);
289 if (IS_TUPLE(argv[0]))
return INTEGER_VAL(AS_TUPLE(argv[0])->values.count);
292 if (!type->
_len)
return krk_runtimeError(
vm.exceptions->typeError,
"object of type '%T' has no len()", argv[0]);
299 FUNCTION_TAKES_AT_MOST(1);
319 for (
size_t i = 0; i < globals->
used; ++i) {
321 if (IS_KWARGS(entry->key))
continue;
332 FUNCTION_TAKES_EXACTLY(1);
339 #define trySlowMethod(name) do { \
340 KrkClass * type = krk_getType(argv[0]); \
343 if (krk_tableGet(&type->methods, name, &method)) { \
346 return krk_callStack(1); \
353 FUNCTION_TAKES_EXACTLY(1);
354 trySlowMethod(
vm.specialMethodNames[METHOD_ORD]);
355 return TYPE_ERROR(
string of length 1,argv[0]);
359 FUNCTION_TAKES_EXACTLY(1);
360 trySlowMethod(
vm.specialMethodNames[METHOD_CHR]);
361 return TYPE_ERROR(
int,argv[0]);
365 FUNCTION_TAKES_EXACTLY(1);
366 trySlowMethod(
vm.specialMethodNames[METHOD_HEX]);
367 return TYPE_ERROR(
int,argv[0]);
371 FUNCTION_TAKES_EXACTLY(1);
372 trySlowMethod(
vm.specialMethodNames[METHOD_OCT]);
373 return TYPE_ERROR(
int,argv[0]);
377 FUNCTION_TAKES_EXACTLY(1);
378 trySlowMethod(
vm.specialMethodNames[METHOD_BIN]);
379 return TYPE_ERROR(
int,argv[0]);
382 #define KRK_STRING_FAST(string,offset) (uint32_t)\
383 ((string->obj.flags & KRK_OBJ_FLAGS_STRING_MASK) <= (KRK_OBJ_FLAGS_STRING_UCS1) ? ((uint8_t*)string->codes)[offset] : \
384 ((string->obj.flags & KRK_OBJ_FLAGS_STRING_MASK) == (KRK_OBJ_FLAGS_STRING_UCS2) ? ((uint16_t*)string->codes)[offset] : \
385 ((uint32_t*)string->codes)[offset]))
388 if (IS_TUPLE(iterable)) {
389 if (callback(context, AS_TUPLE(iterable)->values.values, AS_TUPLE(iterable)->values.count))
return 1;
390 }
else if (IS_list(iterable)) {
391 if (callback(context, AS_LIST(iterable)->values, AS_LIST(iterable)->count))
return 1;
392 }
else if (IS_dict(iterable)) {
393 for (
size_t i = 0; i < AS_DICT(iterable)->used; ++i) {
394 if (!IS_KWARGS(AS_DICT(iterable)->entries[i].key)) {
395 if (callback(context, &AS_DICT(iterable)->entries[i].key, 1))
return 1;
398 }
else if (IS_STRING(iterable)) {
400 for (
size_t i = 0; i < AS_STRING(iterable)->codesLength; ++i) {
404 if (callback(context, &s, 1)) {
412 if (unlikely(!type->
_iter)) {
440 if (callback(context, &item, 1)) {
457 static int _any_callback(
void * context,
const KrkValue * values,
size_t count) {
459 for (
size_t i = 0; i < count; ++i) {
461 _context->base = BOOLEAN_VAL(1);
469 FUNCTION_TAKES_EXACTLY(1);
475 static int _all_callback(
void * context,
const KrkValue * values,
size_t count) {
477 for (
size_t i = 0; i < count; ++i) {
479 _context->base = BOOLEAN_VAL(0);
487 FUNCTION_TAKES_EXACTLY(1);
493 #define CURRENT_CTYPE KrkInstance *
494 #define CURRENT_NAME self
496 #define IS_map(o) (krk_isInstanceOf(o,KRK_BASE_CLASS(map)))
497 #define AS_map(o) (AS_INSTANCE(o))
498 KRK_Method(map,__init__) {
499 METHOD_TAKES_AT_LEAST(2);
512 for (
int i = 2; i < argc; ++i) {
515 return krk_runtimeError(
vm.exceptions->typeError,
"'%T' object is not iterable", argv[i]);
527 KRK_Method(map,__iter__) {
529 return OBJECT_VAL(
self);
532 KRK_Method(map,__call__) {
541 if (!
krk_tableGet(&self->fields, OBJECT_VAL(S(
"_function")), &
function))
return krk_runtimeError(
vm.exceptions->valueError,
"corrupt map object");
542 if (!
krk_tableGet(&self->fields, OBJECT_VAL(S(
"_iterables")), &iterators) || !IS_TUPLE(iterators))
return krk_runtimeError(
vm.exceptions->valueError,
"corrupt map object");
547 for (
size_t i = 0; i < AS_TUPLE(iterators)->values.count; ++i) {
549 krk_push(AS_TUPLE(iterators)->values.values[i]);
554 for (
size_t j = 0; j < i + 1; ++j)
krk_pop();
556 return OBJECT_VAL(
self);
566 #define IS_zip(o) (krk_isInstanceOf(o,KRK_BASE_CLASS(zip)))
567 #define AS_zip(o) (AS_INSTANCE(o))
568 KRK_Method(zip,__init__) {
569 if (hasKw && AS_DICT(argv[argc])->count)
return krk_runtimeError(
vm.exceptions->typeError,
"%s() takes no keyword arguments",
"zip");
576 for (
int i = 1; i < argc; ++i) {
579 return krk_runtimeError(
vm.exceptions->typeError,
"'%T' object is not iterable", argv[i]);
591 KRK_Method(zip,__iter__) {
593 return OBJECT_VAL(
self);
596 KRK_Method(zip,__call__) {
601 if (!
krk_tableGet(&self->fields, OBJECT_VAL(S(
"_iterables")), &iterators) || !IS_TUPLE(iterators))
return krk_runtimeError(
vm.exceptions->valueError,
"corrupt zip object");
608 for (
size_t i = 0; i < AS_TUPLE(iterators)->values.count; ++i) {
609 krk_push(AS_TUPLE(iterators)->values.values[i]);
613 return OBJECT_VAL(
self);
622 #define IS_filter(o) (krk_isInstanceOf(o,KRK_BASE_CLASS(filter)))
623 #define AS_filter(o) (AS_INSTANCE(o))
624 KRK_Method(filter,__init__) {
625 METHOD_TAKES_EXACTLY(2);
629 return krk_runtimeError(
vm.exceptions->typeError,
"'%T' object is not iterable", argv[2]);
639 KRK_Method(filter,__iter__) {
641 return OBJECT_VAL(
self);
644 KRK_Method(filter,__call__) {
650 if (!
krk_tableGet(&self->fields, OBJECT_VAL(S(
"_function")), &
function))
return krk_runtimeError(
vm.exceptions->valueError,
"corrupt filter object");
651 if (!
krk_tableGet(&self->fields, OBJECT_VAL(S(
"_iterator")), &iterator))
return krk_runtimeError(
vm.exceptions->valueError,
"corrupt filter object");
660 return OBJECT_VAL(
self);
663 if (IS_NONE(
function)) {
684 #define IS_enumerate(o) (krk_isInstanceOf(o,KRK_BASE_CLASS(enumerate)))
685 #define AS_enumerate(o) (AS_INSTANCE(o))
686 KRK_Method(enumerate,__init__) {
689 if (!
krk_parseArgs(
".V|V", (
const char*[]){
"iterable",
"start"}, &iterator, &start))
return NONE_VAL();
696 return krk_runtimeError(
vm.exceptions->typeError,
"'%T' object is not iterable", iterator);
706 KRK_Method(enumerate,__iter__) {
708 return OBJECT_VAL(
self);
712 KRK_Method(enumerate,__call__) {
718 if (!
krk_tableGet(&self->fields, OBJECT_VAL(S(
"_counter")), &counter))
return krk_runtimeError(
vm.exceptions->valueError,
"corrupt enumerate object");
719 if (!
krk_tableGet(&self->fields, OBJECT_VAL(S(
"_iterator")), &iterator))
return krk_runtimeError(
vm.exceptions->valueError,
"corrupt enumerate object");
735 return OBJECT_VAL(
self);
742 krk_push(krk_operator_add(counter, INTEGER_VAL(1)));
750 static int _sum_callback(
void * context,
const KrkValue * values,
size_t count) {
752 for (
size_t i = 0; i < count; ++i) {
753 _context->base = krk_operator_add(_context->base, values[i]);
762 if (!
krk_parseArgs(
"V|$V", (
const char*[]){
"iterable",
"start"}, &iterable, &base))
return NONE_VAL();
768 static int _min_callback(
void * context,
const KrkValue * values,
size_t count) {
770 for (
size_t i = 0; i < count; ++i) {
771 if (IS_KWARGS(_context->base)) _context->base = values[i];
774 if (!IS_BOOLEAN(check))
return 1;
775 else if (AS_BOOLEAN(check) == 1) _context->base = values[i];
782 FUNCTION_TAKES_AT_LEAST(1);
785 if (_min_callback(&context, argv, argc))
return NONE_VAL();
789 if (IS_KWARGS(context.base))
return krk_runtimeError(
vm.exceptions->valueError,
"empty argument to %s()",
"min");
793 static int _max_callback(
void * context,
const KrkValue * values,
size_t count) {
795 for (
size_t i = 0; i < count; ++i) {
796 if (IS_KWARGS(_context->base)) _context->base = values[i];
799 if (!IS_BOOLEAN(check))
return 1;
800 else if (AS_BOOLEAN(check) == 1) _context->base = values[i];
807 FUNCTION_TAKES_AT_LEAST(1);
810 if (_max_callback(&context, argv, argc))
return NONE_VAL();
814 if (IS_KWARGS(context.base))
return krk_runtimeError(
vm.exceptions->valueError,
"empty argument to %s()",
"max");
818 KRK_Function(print) {
828 if (!
krk_parseArgs(
"*z#z#Vp", (
const char*[]){
"sep",
"end",
"file",
"flush"},
830 &sep, &sepLen, &end, &endLen,
836 if (!sep) { sep =
" "; sepLen = 1; }
837 if (!end) { end =
"\n"; endLen = 1; }
839 for (
int i = 0; i < remArgc; ++i) {
842 if (!IS_NONE(file)) {
850 if (!IS_STRING(printable)) {
857 if (!IS_STRING(printable))
return krk_runtimeError(
vm.exceptions->typeError,
"__str__ returned non-string (type %T)", printable);
860 if (!IS_NONE(file)) {
866 if (i + 1 < remArgc) {
873 fwrite(AS_CSTRING(printable), AS_STRING(printable)->length, 1, stdout);
875 if (i + 1 < remArgc) fwrite(sep, sepLen, 1, stdout);
879 if (!IS_NONE(file)) {
892 fwrite(end, endLen, 1, stdout);
893 if (flush) fflush(stdout);
904 KRK_Function(globals) {
905 FUNCTION_TAKES_NONE();
921 KRK_Function(locals) {
922 FUNCTION_TAKES_AT_MOST(1);
927 if (argc > 0 && IS_INTEGER(argv[0])) {
928 if (AS_INTEGER(argv[0]) < 1) {
934 index = AS_INTEGER(argv[0]);
939 size_t offset = frame->
ip - func->
chunk.code;
949 if (func->
obj.
flags & KRK_OBJ_FLAGS_CODEOBJECT_COLLECTS_ARGS) {
955 for (
short int i = 0; i < func->
keywordArgs; ++i) {
961 if (func->
obj.
flags & KRK_OBJ_FLAGS_CODEOBJECT_COLLECTS_KWS) {
980 KRK_Function(isinstance) {
981 FUNCTION_TAKES_EXACTLY(2);
982 if (IS_CLASS(argv[1])) {
984 }
else if (IS_TUPLE(argv[1])) {
985 for (
size_t i = 0; i < AS_TUPLE(argv[1])->values.count; ++i) {
986 if (IS_CLASS(AS_TUPLE(argv[1])->values.values[i]) &&
krk_isInstanceOf(argv[0], AS_CLASS(AS_TUPLE(argv[1])->values.values[i]))) {
987 return BOOLEAN_VAL(1);
990 return BOOLEAN_VAL(0);
992 return TYPE_ERROR(
class or tuple,argv[1]);
996 KRK_Function(issubclass) {
997 FUNCTION_TAKES_EXACTLY(2);
999 if (IS_CLASS(argv[1])) {
1000 return BOOLEAN_VAL(krk_isSubClass(cls, AS_CLASS(argv[1])));
1001 }
else if (IS_TUPLE(argv[1])) {
1002 for (
size_t i = 0; i < AS_TUPLE(argv[1])->values.count; ++i) {
1003 if (IS_CLASS(AS_TUPLE(argv[1])->values.values[i]) && krk_isSubClass(cls, AS_CLASS(AS_TUPLE(argv[1])->values.values[i]))) {
1004 return BOOLEAN_VAL(1);
1007 return BOOLEAN_VAL(0);
1009 return TYPE_ERROR(
class or tuple,argv[1]);
1013 #define IS_module(o) (IS_INSTANCE(o))
1014 #define AS_module(o) (AS_INSTANCE(o))
1016 KRK_Method(module,__repr__) {
1018 krk_tableGet(&self->fields,
vm.specialMethodNames[METHOD_NAME], &name);
1020 if (!IS_STRING(name)) {
1021 return OBJECT_VAL(S(
"<module>"));
1025 krk_tableGet(&self->fields,
vm.specialMethodNames[METHOD_FILE], &file);
1029 if (!krk_pushStringBuilderFormat(&sb,
"<module '%S' ", AS_STRING(name)))
goto _error;
1031 if (IS_STRING(file)) {
1032 if (!krk_pushStringBuilderFormat(&sb,
"from %R>", file))
goto _error;
1034 if (!krk_pushStringBuilderFormat(&sb,
"(built-in)>"))
goto _error;
1043 #define IS_Helper(o) (krk_isInstanceOf(o, KRK_BASE_CLASS(Helper)))
1044 #define AS_Helper(o) (AS_INSTANCE(o))
1045 #define IS_LicenseReader(o) (krk_isInstanceOf(o, KRK_BASE_CLASS(LicenseReader)))
1046 #define AS_LicenseReader(o) (AS_INSTANCE(o))
1048 KRK_Method(Helper,__repr__) {
1049 return OBJECT_VAL(S(
"Type help() for more help, or help(obj) to describe an object."));
1052 KRK_Method(Helper,__call__) {
1053 METHOD_TAKES_AT_MOST(1);
1059 krk_tableGet(&AS_INSTANCE(helpModule)->fields, OBJECT_VAL(S(
"simple")), &callable);
1061 krk_tableGet(&AS_INSTANCE(helpModule)->fields, OBJECT_VAL(S(
"interactive")), &callable);
1064 if (!IS_NONE(callable)) {
1073 KRK_Method(LicenseReader,__repr__) {
1074 return OBJECT_VAL(S(
"Copyright 2020-2022 K. Lange <klange@toaruos.org>. Type `license()` for more information."));
1077 KRK_Method(LicenseReader,__call__) {
1078 METHOD_TAKES_NONE();
1083 krk_tableGet(&AS_INSTANCE(helpModule)->fields, OBJECT_VAL(S(
"__licenseText")), &text);
1085 if (IS_STRING(text)) {
1086 printf(
"%s\n", AS_CSTRING(text));
1093 #define IS_property(o) (krk_isInstanceOf(o,KRK_BASE_CLASS(property)))
1094 #define AS_property(o) (AS_INSTANCE(o))
1102 static void _property_gcscan(
KrkInstance *_self) {
1108 KRK_Method(property,__init__) {
1109 METHOD_TAKES_AT_LEAST(1);
1110 METHOD_TAKES_AT_MOST(2);
1113 ((
struct Property*)
self)->fget = IS_OBJECT(argv[1]) ? AS_OBJECT(argv[1]) : NULL;
1116 if (IS_NATIVE(argv[1])) {
1118 AS_NATIVE(argv[1])->doc ? OBJECT_VAL(
krk_copyString(AS_NATIVE(argv[1])->doc, strlen(AS_NATIVE(argv[1])->doc))) : NONE_VAL());
1119 }
else if (IS_CLOSURE(argv[1])) {
1121 AS_CLOSURE(argv[1])->function->docstring ? OBJECT_VAL(AS_CLOSURE(argv[1])->function->docstring) : NONE_VAL());
1125 if (IS_NATIVE(argv[1])) {
1127 AS_NATIVE(argv[1])->name ? OBJECT_VAL(
krk_copyString(AS_NATIVE(argv[1])->name, strlen(AS_NATIVE(argv[1])->name))) : NONE_VAL());
1128 }
else if (IS_CLOSURE(argv[1])) {
1130 AS_CLOSURE(argv[1])->function->name ? OBJECT_VAL(AS_CLOSURE(argv[1])->function->name) : NONE_VAL());
1135 ((
struct Property*)
self)->fset = IS_OBJECT(argv[2]) ? AS_OBJECT(argv[2]) : NULL;
1141 KRK_Method(property,setter) {
1142 METHOD_TAKES_EXACTLY(1);
1147 KRK_Method(property,__get__) {
1148 METHOD_TAKES_AT_LEAST(1);
1150 if (IS_NONE(argv[1]))
return argv[0];
1160 if (!
krk_tableGet(&self->fields, OBJECT_VAL(S(
"fget")), &fget))
1161 return krk_runtimeError(
vm.exceptions->attributeError,
"'%T' object has no attribute '%s'", argv[0],
"fget");
1168 KRK_Method(property,__set__) {
1169 METHOD_TAKES_EXACTLY(2);
1180 if (
krk_tableGet(&self->fields, OBJECT_VAL(S(
"fset")), &fset)) {
1194 if (
krk_tableGet(&self->fields, OBJECT_VAL(S(
"fget")), &fget)) {
1204 KRK_Method(property,__setattr__) {
1205 METHOD_TAKES_EXACTLY(2);
1206 if (!IS_STRING(argv[1]))
return TYPE_ERROR(str,argv[1]);
1211 krk_tableGet(&self->fields, OBJECT_VAL(S(
"fget")), &fget);
1212 asProp->fget = (IS_CLOSURE(fget) || IS_NATIVE(fget)) ? AS_OBJECT(fget) : NULL;
1215 krk_tableGet(&self->fields, OBJECT_VAL(S(
"fset")), &fset);
1216 asProp->fset = (IS_CLOSURE(fset) || IS_NATIVE(fset)) ? AS_OBJECT(fset) : NULL;
1241 FUNCTION_TAKES_EXACTLY(1);
1242 if (!IS_OBJECT(argv[0]))
return krk_runtimeError(
vm.exceptions->typeError,
"'%T' has no identity", argv[0]);
1243 return INTEGER_VAL((
size_t)AS_OBJECT(argv[0]));
1246 KRK_Function(hash) {
1247 FUNCTION_TAKES_EXACTLY(1);
1250 return INTEGER_VAL(hashed);
1253 KRK_Function(next) {
1254 FUNCTION_TAKES_EXACTLY(1);
1260 FUNCTION_TAKES_EXACTLY(1);
1261 if (IS_INTEGER(argv[0])) {
1262 krk_integer_type i = AS_INTEGER(argv[0]);
1263 return INTEGER_VAL(i >= 0 ? i : -i);
1264 #ifndef KRK_NO_FLOAT
1265 }
else if (IS_FLOATING(argv[0])) {
1266 double i = AS_FLOATING(argv[0]);
1267 return FLOATING_VAL(i >= 0 ? i : -i);
1270 trySlowMethod(
vm.specialMethodNames[METHOD_ABS]);
1271 return krk_runtimeError(
vm.exceptions->typeError,
"bad operand type for 'abs()': '%T'", argv[0]);
1275 KRK_Function(format) {
1276 FUNCTION_TAKES_AT_LEAST(1);
1277 FUNCTION_TAKES_AT_MOST(2);
1281 if (!type->_format) {
1282 return krk_runtimeError(
vm.exceptions->typeError,
"'%T' has no __format__ method", argv[0]);
1286 if (argc < 2)
krk_push(OBJECT_VAL(S(
"")));
1290 if (!IS_STRING(result)) {
1291 return krk_runtimeError(
vm.exceptions->typeError,
"__format__ result was not a string");
1297 #ifndef KRK_STATIC_ONLY
1299 if (module->libHandle) {
1300 krk_dlClose(module->libHandle);
1305 KRK_Function(__build_class__) {
1308 KrkClass * base =
vm.baseClasses->objectClass;
1309 KrkValue metaclass = OBJECT_VAL(
vm.baseClasses->typeClass);
1312 (
const char*[]){
"func",
"name",
"base",
"metaclass"},
1314 vm.baseClasses->strClass, &name,
1315 vm.baseClasses->typeClass, &base,
1320 if (IS_CLASS(metaclass)) {
1322 if (krk_isSubClass(AS_CLASS(metaclass), basemeta)) {
1324 }
else if (krk_isSubClass(basemeta, AS_CLASS(metaclass))) {
1326 metaclass = OBJECT_VAL(basemeta);
1329 "metaclass conflict: %S is not a subclass of %S", AS_CLASS(metaclass)->name, basemeta->
name);
1382 if (IS_CLOSURE(func)) {
1383 if (AS_CLOSURE(func)->upvalueCount && AS_CLOSURE(func)->upvalues[0]->location == -1 && IS_NONE(AS_CLOSURE(func)->upvalues[0]->closed)) {
1384 AS_CLOSURE(func)->upvalues[0]->closed =
krk_peek(0);
1392 #undef CURRENT_CTYPE
1393 #define CURRENT_CTYPE KrkUpvalue *
1394 #define IS_Cell(o) (krk_isObjType((o), KRK_OBJ_UPVALUE))
1395 #define AS_Cell(o) ((KrkUpvalue*)AS_OBJECT(o))
1397 KRK_StaticMethod(Cell,__new__) {
1400 if (!
krk_parseArgs(
"O!|V:Cell", (
const char*[]){
"cls",
"contents"}, KRK_BASE_CLASS(
type), &
_class, &contents)) {
1403 if (
_class != KRK_BASE_CLASS(Cell)) {
1409 return OBJECT_VAL(out);
1412 #define UPVALUE_LOCATION(upvalue) (upvalue->location == -1 ? &upvalue->closed : &upvalue->owner->stack[upvalue->location])
1413 KRK_Method(Cell,__repr__) {
1416 KrkValue contents = *UPVALUE_LOCATION(
self);
1418 if (!krk_pushStringBuilderFormat(&sb,
"<cell at %p: %T object", (
void*)
self, contents))
goto _error;
1419 if (IS_OBJECT(contents)) {
1420 if (!krk_pushStringBuilderFormat(&sb,
" at %p>", (
void*)AS_OBJECT(contents)))
goto _error;
1432 KRK_Method(Cell,cell_contents) {
1434 *UPVALUE_LOCATION(
self) = argv[1];
1436 return *UPVALUE_LOCATION(
self);
1440 void _createAndBind_builtins(
void) {
1442 krk_push(OBJECT_VAL(
vm.baseClasses->objectClass));
1444 KrkClass *
object =
vm.baseClasses->objectClass;
1445 BIND_METHOD(
object,__dir__);
1446 BIND_METHOD(
object,__str__);
1447 BIND_METHOD(
object,__repr__);
1448 BIND_METHOD(
object,__hash__);
1449 BIND_METHOD(
object,__eq__);
1450 BIND_METHOD(
object,__format__);
1451 BIND_STATICMETHOD(
object,__setattr__);
1452 BIND_STATICMETHOD(
object,__new__);
1453 BIND_METHOD(
object,__init__);
1454 BIND_CLASSMETHOD(
object,__init_subclass__);
1457 "@brief Base class for all types.\n\n"
1458 "The @c object base class provides the fallback implementations of methods like "
1459 "@ref object___dir__ \"__dir__\". All object and primitive types eventually inherit from @c object."
1462 vm.baseClasses->moduleClass =
krk_newClass(S(
"module"),
vm.baseClasses->objectClass);
1464 KrkClass * module =
vm.baseClasses->moduleClass;
1470 BIND_METHOD(module,__repr__);
1472 KRK_DOC(module,
"Type of imported modules and packages.");
1483 "@brief Internal module containing built-in functions and classes.\n\n"
1484 "Classes and functions from the @c \\__builtins__ module are generally available from "
1485 "all global namespaces. Built-in names can still be shadowed by module-level globals "
1486 "and function-level locals, so none the names in this module are reserved. When "
1487 "a built-in name has been shadowed, the original can be referenced directly as "
1488 " @c \\__builtins__.name instead.\n\n"
1489 "Built-in names may be bound from several sources. Most come from the core interpreter "
1490 "directly, but some may come from loaded C extension modules or the interpreter binary. "
1491 "Kuroko source modules are also free to append new names to the built-in name space by "
1492 "attaching new properties to the @c \\__builtins__ instance."
1495 KrkClass *
property = ADD_BASE_CLASS(KRK_BASE_CLASS(property),
"property",
object);
1496 property->allocSize =
sizeof(
struct Property);
1497 property->_ongcscan = _property_gcscan;
1498 KRK_DOC(BIND_METHOD(property,__init__),
1499 "@brief Create a property object.\n"
1500 "@arguments fget,[fset]\n\n"
1501 "When a property object is obtained from an instance of the class in which it is defined, "
1502 "the function or method assigned to @p fget is called with the instance as an argument. "
1503 "If @p fset is provided, it will be called with the instance and a value when the property "
1504 "object is assigned to through an instance. For legacy compatibility reasons, a property "
1505 "object's @p fget method may also accept an additional argument to act as a setter if "
1506 "@p fset is not provided, but this functionality may be removed in the future.\n\n"
1507 "The typical use for @c property is as a decorator on methods in a class. See also "
1508 "@ref property_setter \"property.setter\" for the newer Python-style approach to decorating a companion "
1510 BIND_METHOD(property,__get__);
1511 BIND_METHOD(property,__set__);
1512 KRK_DOC(BIND_METHOD(property,setter),
1513 "@brief Assign the setter method of a property object.\n"
1514 "@arguments fset\n\n"
1515 "This should be used as a decorator from an existing property object as follows:\n\n"
1522 " def bar(self, val):\n"
1523 " print('setting bar to',val)\n"
1525 "Be sure to apply the decorator to a function or method with the same name, as this "
1526 "name will be used to assign the property to the class's attribute table; using a "
1527 "different name will create a duplicate alias.");
1531 BIND_PROP(
object,__class__);
1533 KrkClass * Helper = ADD_BASE_CLASS(KRK_BASE_CLASS(Helper),
"Helper",
object);
1535 "@brief Special object that prints a helpeful message.\n\n"
1536 "Object that prints help summary when passed to @ref repr.");
1537 KRK_DOC(BIND_METHOD(Helper,__call__),
1538 "@brief Prints help text.\n"
1539 "@arguments obj=None\n\n"
1540 "Prints the help documentation attached to @p obj or starts the interactive help system by "
1541 "importing the @ref mod_help module.");
1542 BIND_METHOD(Helper,__repr__);
1546 KrkClass * LicenseReader = ADD_BASE_CLASS(KRK_BASE_CLASS(LicenseReader),
"LicenseReader",
object);
1547 KRK_DOC(LicenseReader,
"Special object that prints Kuroko's copyright information when passed to @ref repr");
1548 KRK_DOC(BIND_METHOD(LicenseReader,__call__),
"Print the full license statement.");
1549 BIND_METHOD(LicenseReader,__repr__);
1553 KrkClass * map = ADD_BASE_CLASS(KRK_BASE_CLASS(map),
"map",
object);
1554 KRK_DOC(map,
"Return an iterator that applies a function to a series of iterables");
1555 BIND_METHOD(map,__init__);
1556 BIND_METHOD(map,__iter__);
1557 BIND_METHOD(map,__call__);
1560 KrkClass * zip = ADD_BASE_CLASS(KRK_BASE_CLASS(zip),
"zip",
object);
1562 "@brief Returns an iterator that produces tuples of the nth element of each passed iterable.\n"
1563 "@arguments *iterables\n\n"
1564 "Creates an iterator that returns a tuple of elements from each of @p iterables, until one "
1565 "of @p iterables is exhuasted.");
1566 BIND_METHOD(zip,__init__);
1567 BIND_METHOD(zip,__iter__);
1568 BIND_METHOD(zip,__call__);
1571 KrkClass * filter = ADD_BASE_CLASS(KRK_BASE_CLASS(filter),
"filter",
object);
1572 KRK_DOC(filter,
"Return an iterator that returns only the items from an iterable for which the given function returns true.");
1573 BIND_METHOD(filter,__init__);
1574 BIND_METHOD(filter,__iter__);
1575 BIND_METHOD(filter,__call__);
1578 KrkClass * enumerate = ADD_BASE_CLASS(KRK_BASE_CLASS(enumerate),
"enumerate",
object);
1579 KRK_DOC(enumerate,
"Return an iterator that produces a tuple with a count the iterated values of the passed iteratable.");
1580 BIND_METHOD(enumerate,__init__);
1581 BIND_METHOD(enumerate,__iter__);
1582 BIND_METHOD(enumerate,__call__);
1585 KrkClass * Cell = ADD_BASE_CLASS(KRK_BASE_CLASS(Cell),
"Cell",
object);
1587 Cell->
obj.
flags |= KRK_OBJ_FLAGS_NO_INHERIT;
1588 BIND_STATICMETHOD(Cell,__new__);
1589 BIND_METHOD(Cell,__repr__);
1590 BIND_PROP(Cell,cell_contents);
1593 BUILTIN_FUNCTION(
"isinstance", FUNC_NAME(krk,isinstance),
1594 "@brief Check if an object is an instance of a type.\n"
1595 "@arguments inst, cls\n\n"
1596 "Determine if an object @p inst is an instance of the given class @p cls or one if its subclasses. "
1597 "@p cls may be a single class or a tuple of classes.");
1598 BUILTIN_FUNCTION(
"issubclass", FUNC_NAME(krk,issubclass),
1599 "@brief Check if a class is a subclass of a type.\n"
1600 "@arguments cls, clsinfo\n\n"
1601 "Determine if the class @p cls is a subclass of the class @p clsinfo. @p clsinfo may be a single "
1602 "class or a tuple of classes.");
1603 BUILTIN_FUNCTION(
"globals", FUNC_NAME(krk,globals),
1604 "@brief Update and a return a mapping of names in the global namespace.\n\n"
1605 "Produces a dict mapping all of the names of the current globals namespace to their values. "
1606 "Updating this dict has no meaning, but modifying mutable values within it can affect the global namespace.");
1607 BUILTIN_FUNCTION(
"locals", FUNC_NAME(krk,locals),
1608 "@brief Update and return a mapping of names in the current local scope.\n"
1609 "@arguments callDepth=1\n\n"
1610 "Produces a dict mapping the names of the requested locals scope to their current stack values. "
1611 "If @p callDepth is provided, the locals of an outer call frame will be returned. If the requested "
1612 "call depth is out of range, an exception will be raised.");
1613 BUILTIN_FUNCTION(
"dir", FUNC_NAME(krk,dir),
1614 "@brief Return a list of known property names for a given object.\n"
1615 "@arguments [obj]\n\n"
1616 "Uses various internal methods to collect a list of property names of @p obj, returning "
1617 "that list sorted lexicographically. If no argument is given, the returned list will "
1618 "be the valid global names in the calling scope.");
1619 BUILTIN_FUNCTION(
"len", FUNC_NAME(krk,len),
1620 "@brief Return the length of a given sequence object.\n"
1621 "@arguments seq\n\n"
1622 "Returns the length of the sequence object @p seq, which must implement @c __len__.");
1623 BUILTIN_FUNCTION(
"repr", FUNC_NAME(krk,repr),
1624 "@brief Produce a string representation of the given object.\n"
1625 "@arguments val\n\n"
1626 "Return a string representation of the given object through its @c __repr__ method. "
1627 "@c repr strings should convey all information needed to recreate the object, if this is possible.");
1628 BUILTIN_FUNCTION(
"print", FUNC_NAME(krk,print),
1629 "@brief Print text to the standard output.\n"
1630 "@arguments *args,sep=' ',end='\\n',file=None,flush=False\n\n"
1631 "Prints the string representation of each argument to the standard output. "
1632 "The keyword argument @p sep specifies the string to print between values. "
1633 "The keyword argument @p end specifies the string to print after all of the values have been printed.");
1634 BUILTIN_FUNCTION(
"ord", FUNC_NAME(krk,ord),
1635 "@brief Obtain the ordinal integer value of a codepoint or byte.\n"
1636 "@arguments char\n\n"
1637 "Returns the integer codepoint value of a single-character string @p char.");
1638 BUILTIN_FUNCTION(
"chr", FUNC_NAME(krk,chr),
1639 "@brief Convert an integer codepoint to its string representation.\n"
1640 "@arguments codepoint\n\n"
1641 "Creates a single-codepoint string with the character represented by the integer codepoint @p codepoint.");
1642 BUILTIN_FUNCTION(
"hex", FUNC_NAME(krk,hex),
1643 "@brief Convert an integer value to a hexadecimal string.\n"
1645 "Returns a string representation of @p i in hexadecimal, with a leading @c 0x.");
1646 BUILTIN_FUNCTION(
"oct", FUNC_NAME(krk,oct),
1647 "@brief Convert an integer value to an octal string.\n"
1649 "Returns a string representation of @p i in octal, with a leading @c 0o.");
1650 BUILTIN_FUNCTION(
"any", FUNC_NAME(krk,any),
1651 "@brief Returns True if at least one element in the given iterable is truthy, False otherwise.\n"
1652 "@arguments iterable");
1653 BUILTIN_FUNCTION(
"all", FUNC_NAME(krk,all),
1654 "@brief Returns True if every element in the given iterable is truthy, False otherwise.\n"
1655 "@arguments iterable");
1656 BUILTIN_FUNCTION(
"getattr", FUNC_NAME(krk,getattr),
1657 "@brief Perform attribute lookup on an object using a string.\n"
1658 "@arguments obj,attribute,[default]\n\n"
1659 "Obtains the attributed named @p attribute from the object @p obj, if such an "
1660 "attribute exists. Attribute lookup ordering is complex and includes direct "
1661 "attribute tables of instances, dynamic attributes from classes, and so on. "
1662 "The use of @c getattr is equivalent to a dotted access. If @p attribute refers "
1663 "to a method of @p obj's class, a bound method will be obtained. If @p default "
1664 "is provided then the value supplied will be returned in the case where @p obj "
1665 "does not have an attribute named @p attribute, otherwise an @ref AttributeError "
1667 BUILTIN_FUNCTION(
"setattr", FUNC_NAME(krk,setattr),
1668 "@brief Set an attribute of an object using a string name.\n"
1669 "@arguments obj,attribute,value\n\n"
1670 "Sets the attribute named by @p attribute of the object @p obj to @p value. "
1671 "If @p attribute refers to a @ref property object or other descriptor, the "
1672 "descriptor's @c \\__set__ method will be called. If @p obj is a class, instance, "
1673 "or other type with its own attribute table, then the field will be updated. If "
1674 "@p obj is a type without an attribute table and no class property provides an "
1675 "overriding setter for @p attribute, an @ref AttributeError will be raised.");
1676 BUILTIN_FUNCTION(
"hasattr", FUNC_NAME(krk,hasattr),
1677 "@brief Determines if an object has an attribute.\n"
1678 "@arguments obj,attribute\n\n"
1679 "Uses @ref getattr to determine if @p obj has an attribute named @p attribute.");
1680 BUILTIN_FUNCTION(
"delattr", FUNC_NAME(krk,delattr),
1681 "@brief Delete an attribute by name.\n"
1682 "@arguments obj,attribute\n\n"
1683 "Deletes the attribute @p attribute from @p obj.");
1684 BUILTIN_FUNCTION(
"sum", FUNC_NAME(krk,sum),
1685 "@brief add the elements of an iterable.\n"
1686 "@arguments iterable,start=0\n\n"
1687 "Continuously adds all of the elements from @p iterable to @p start and returns the result "
1688 "when @p iterable has been exhausted.");
1689 BUILTIN_FUNCTION(
"min", FUNC_NAME(krk,min),
1690 "@brief Return the lowest value in an iterable or the passed arguments.\n"
1691 "@arguments iterable");
1692 BUILTIN_FUNCTION(
"max", FUNC_NAME(krk,max),
1693 "@brief Return the highest value in an iterable or the passed arguments.\n"
1694 "@arguments iterable");
1695 BUILTIN_FUNCTION(
"id", FUNC_NAME(krk,
id),
1696 "@brief Returns the identity of an object.\n"
1697 "@arguments val\n\n"
1698 "Returns the internal identity for @p val. Note that not all objects have "
1699 "identities; primitive values such as @c int or @c float do not have identities. "
1700 "Internally, this is the pointer value for a heap object, but this is an implementation detail.");
1701 BUILTIN_FUNCTION(
"hash", FUNC_NAME(krk,hash),
1702 "@brief Returns the hash of a value, used for table indexing.\n"
1703 "@arguments val\n\n"
1704 "If @p val is hashable, its hash value will be calculated if necessary and returned. "
1705 "If @p val is not hashable, @ref TypeError will be raised.");
1706 BUILTIN_FUNCTION(
"bin", FUNC_NAME(krk,bin),
1707 "@brief Convert an integer value to a binary string.\n"
1709 "Produces a string representation of @p i in binary, with a leading @p 0b.");
1710 BUILTIN_FUNCTION(
"next", FUNC_NAME(krk,next),
1711 "@brief Compatibility function. Calls an iterable.\n"
1712 "@arguments iterable");
1713 BUILTIN_FUNCTION(
"abs", FUNC_NAME(krk,abs),
1714 "@brief Obtain the absolute value of a numeric.\n"
1715 "@arguments iterable");
1716 BUILTIN_FUNCTION(
"format", FUNC_NAME(krk,format),
1717 "@brief Format a value for string printing.\n"
1718 "@arguments value[,format_spec]");
1719 BUILTIN_FUNCTION(
"__build_class__", FUNC_NAME(krk,__build_class__),
1720 "@brief Internal function to build a type object.\n"
1721 "@arguments func, name, base=object, metaclass=type");
Functions for debugging bytecode execution.
KrkValue krk_runtimeError(KrkClass *type, const char *fmt,...)
Produce and raise an exception with a formatted message.
Functions for dealing with garbage collection and memory allocation.
void krk_markObject(KrkObj *object)
During a GC scan cycle, mark an object as used.
Represents a managed call state in a VM thread.
KrkObj * _tostr
__str__ Called to produce a string from an instance
KrkCleanupCallback _ongcsweep
C function to call when the garbage collector is discarding an instance of this class.
KrkClass * krk_newClass(KrkString *name, KrkClass *base)
Create a new class object.
KrkObj * _reprer
__repr__ Called to create a reproducible string representation of an instance
KrkString * name
Name of the class.
struct KrkClass * base
Pointer to base class implementation.
KrkObj * _init
__init__ Implicitly called when an instance is created
KrkObj * _len
__len__ Generally called by len() but may be used to determine truthiness
size_t allocSize
Size to allocate when creating instances of this class.
KrkObj * _iter
__iter__ Called by for ... in ..., etc.
KrkTable methods
General attributes table.
KrkObj * _dir
__dir__ Overrides normal behavior for dir()
void krk_finalizeClass(KrkClass *_class)
Finalize a class by collecting pointers to core methods.
struct KrkClass * _class
Metaclass.
KrkCodeObject * function
The codeobject containing the bytecode run when this function is called.
unsigned short potentialPositionals
Precalculated positional arguments for complex argument processing.
KrkChunk chunk
Bytecode data.
KrkValueArray positionalArgNames
Array of names for positional arguments (and *args)
KrkLocalEntry * localNames
Stores the names of local variables used in the function, for debugging.
unsigned short keywordArgs
Arity of keyword (default) arguments.
KrkValueArray keywordArgNames
Array of names for keyword-only arguments (and **kwargs)
size_t localNameCount
Number of entries in localNames.
KrkValue krk_dict_of(int argc, const KrkValue argv[], int hasKw)
Create a dict object.
KrkInstance * krk_newInstance(KrkClass *_class)
Create a new instance of the given class.
KrkValue krk_list_of(int argc, const KrkValue argv[], int hasKw)
Create a list object.
size_t birthday
Instruction offset that this local name became valid on.
KrkString * name
Name of the local.
size_t id
Local ID as used by opcodes; offset from the frame's stack base.
size_t deathday
Instruction offset that this local name becomes invalid on.
Representation of a loaded module.
Managed binding to a C function.
KrkNative * krk_newNative(NativeFn function, const char *name, int type)
Create a native function binding object.
The most basic object type.
uint32_t hash
Cached hash value for table keys.
uint16_t flags
General object flags, mostly related to garbage collection.
uint16_t type
Tag indicating core type.
Immutable sequence of Unicode codepoints.
void * krk_unicodeString(KrkString *string)
Ensure that a codepoint representation of a string is available.
KrkString * krk_copyString(const char *chars, size_t length)
Obtain a string object representation of the given C string.
char * chars
UTF8 canonical data.
One (key,value) pair in a table.
Simple hash table of arbitrary keys to values.
int krk_tableGet(KrkTable *table, KrkValue key, KrkValue *value)
Obtain the value associated with a key in a table.
int krk_tableSet(KrkTable *table, KrkValue key, KrkValue value)
Assign a value to a key in a table.
void krk_attachNamedObject(KrkTable *table, const char name[], KrkObj *obj)
Attach an object to an attribute table.
void krk_attachNamedValue(KrkTable *table, const char name[], KrkValue obj)
Attach a value to an attribute table.
KrkNative * krk_defineNativeProperty(KrkTable *table, const char *name, NativeFn func)
Attach a native dynamic property to an attribute table.
void krk_tableAddAll(KrkTable *from, KrkTable *to)
Add all key-value pairs from 'from' into 'to'.
Immutable sequence of arbitrary values.
KrkValueArray values
Stores the length, capacity, and actual values of the tuple.
KrkTuple * krk_newTuple(size_t length)
Create a new tuple.
Storage for values referenced from nested functions.
KrkValue closed
Heap storage for closed value.
KrkUpvalue * krk_newUpvalue(int slot)
Create an upvalue slot.
void krk_writeValueArray(KrkValueArray *array, KrkValue value)
Add a value to a value array.
Stack reference or primative value.
int krk_isInstanceOf(KrkValue obj, const KrkClass *type)
Determine if a class is an instance or subclass of a given type.
int krk_valuesEqual(KrkValue a, KrkValue b)
Compare two values for equality.
KrkClass * krk_getType(KrkValue value)
Get the class representing a value.
static int krk_valuesSame(KrkValue a, KrkValue b)
Compare two values by identity.
KrkValue krk_valueGetAttribute(KrkValue value, char *name)
Obtain a property of an object by name.
int krk_isFalsey(KrkValue value)
Determine the truth of a value.
int krk_hashValue(KrkValue value, uint32_t *hashOut)
Calculate the hash for a value.
KrkValue krk_set_of(int argc, const KrkValue argv[], int hasKw)
Create a set object.
Inline flexible string array.
Utilities for creating native bindings.
#define krk_parseArgs(f, n,...)
Parse arguments to a function while accepting keyword arguments.
KrkValue krk_discardStringBuilder(struct StringBuilder *sb)
Discard the contents of a string builder.
int krk_unpackIterable(KrkValue iterable, void *context, int callback(void *, const KrkValue *, size_t))
Unpack an iterable.
KrkValue krk_finishStringBuilder(struct StringBuilder *sb)
Finalize a string builder into a string object.
void krk_pushStringBuilder(struct StringBuilder *sb, char c)
Add a character to the end of a string builder.
#define KRK_DOC(thing, text)
Attach documentation to a thing of various types.
Definitions for primitive stack references.
Core API for the bytecode virtual machine.
krk_threadLocal KrkThreadState krk_currentThread
Thread-local VM state.
int krk_getAttribute(KrkString *name)
Implementation of the GET_PROPERTY instruction.
int krk_setAttribute(KrkString *name)
Implementation of the SET_PROPERTY instruction.
KrkValue krk_callStack(int argCount)
Call a callable on the stack with argCount arguments.
#define vm
Convenience macro for namespacing.
int krk_doRecursiveModuleLoad(KrkString *name)
Load a module by a dotted name.
int krk_delAttribute(KrkString *name)
Implementation of the DEL_PROPERTY instruction.
KrkValue krk_operator_lt(KrkValue, KrkValue)
Compare two values, returning True if the left is less than the right.
KrkValue krk_pop(void)
Pop the top of the stack.
KrkValue krk_valueGetAttribute_default(KrkValue value, char *name, KrkValue defaultVal)
See krk_valueGetAttribute.
void krk_swap(int distance)
Swap the top of the stack of the value distance slots down.
KrkValue krk_dirObject(int argc, const KrkValue argv[], int hasKw)
Obtain a list of properties for an object.
void krk_push(KrkValue value)
Push a stack value.
KrkValue krk_callDirect(KrkObj *callable, int argCount)
Call a closure or native function with argCount arguments.
KrkValue krk_instanceSetAttribute_wrapper(KrkValue owner, KrkString *name, KrkValue to)
Set an attribute of an instance object, bypassing __setattr__.
KrkValue krk_peek(int distance)
Peek down from the top of the stack.
KrkValue krk_operator_gt(KrkValue, KrkValue)
Compare to values, returning True if the left is greater than the right.