Fixes that should enable MSVC to build the core interpreter
This commit is contained in:
parent
c530cf20fd
commit
bc3024881f
@ -198,8 +198,8 @@ static int isJumpTarget(KrkCodeObject * func, size_t startPoint) {
|
||||
size_t offset = 0;
|
||||
|
||||
#define SIMPLE(opc) case opc: size = 1; break;
|
||||
#define CONSTANT(opc,more) case opc: { size_t constant __attribute__((unused)) = chunk->code[offset + 1]; size = 2; more; break; } \
|
||||
case opc ## _LONG: { size_t constant __attribute__((unused)) = (chunk->code[offset + 1] << 16) | \
|
||||
#define CONSTANT(opc,more) case opc: { size_t constant _unused = chunk->code[offset + 1]; size = 2; more; break; } \
|
||||
case opc ## _LONG: { size_t constant _unused = (chunk->code[offset + 1] << 16) | \
|
||||
(chunk->code[offset + 2] << 8) | (chunk->code[offset + 3]); size = 4; more; break; }
|
||||
#define OPERANDB(opc,more) case opc: { size = 2; more; break; }
|
||||
#define OPERAND(opc,more) OPERANDB(opc,more) \
|
||||
|
@ -32,3 +32,17 @@ typedef int64_t krk_integer_type;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) && !defined(__clang__)
|
||||
#define KRK_NO_DOCUMENTATION 1
|
||||
#define KRK_NO_GC_TRACING 1
|
||||
#define KRK_NO_CALLGRIND 1
|
||||
typedef intptr_t ssize_t;
|
||||
#pragma warning(disable : 4146) /* unary minus on unsigned */
|
||||
#pragma warning(disable : 4996) /* sterror */
|
||||
#pragma warning(disable : 4267) /* conversions to smaller types... */
|
||||
#pragma warning(disable : 4244) /* conversions to smaller types... */
|
||||
#include <math.h>
|
||||
#define __builtin_floor floor
|
||||
#define __builtin_unreachable abort
|
||||
#define __builtin_expect(cond,expected) (cond)
|
||||
#endif
|
||||
|
@ -33,6 +33,30 @@
|
||||
#define _noexport
|
||||
#endif
|
||||
|
||||
#if __has_attribute(unused)
|
||||
# define _unused __attribute__((unused))
|
||||
#else
|
||||
# define _unused
|
||||
#endif
|
||||
|
||||
#if __has_attribute(hot)
|
||||
# define _hot __attribute__((hot))
|
||||
#else
|
||||
# define _hot
|
||||
#endif
|
||||
|
||||
#if __has_attribute(cold)
|
||||
# define _cold __attribute__((cold))
|
||||
#else
|
||||
# define _cold
|
||||
#endif
|
||||
|
||||
#if __has_attribute(nonnull)
|
||||
# define _nonnull __attribute__((nonnull))
|
||||
#else
|
||||
# define _nonnull
|
||||
#endif
|
||||
|
||||
#define ADD_BASE_CLASS(obj, name, baseClass) krk_makeClass(vm.builtins, &obj, name, baseClass)
|
||||
|
||||
#define ATTRIBUTE_NOT_ASSIGNABLE() do { if (unlikely(argc != 1)) return krk_runtimeError(vm.exceptions->attributeError, "'%T' object has no attribute '%s'", \
|
||||
@ -70,7 +94,7 @@
|
||||
#define CHECK_ARG(i, type, ctype, name) \
|
||||
if (unlikely(argc < (i+1))) return NOT_ENOUGH_ARGS(name); \
|
||||
if (unlikely(!IS_ ## type (argv[i]))) return TYPE_ERROR(type,argv[i]); \
|
||||
ctype name __attribute__((unused)) = AS_ ## type (argv[i])
|
||||
ctype name _unused = AS_ ## type (argv[i])
|
||||
|
||||
#define FUNC_NAME(klass, name) _ ## klass ## _ ## name
|
||||
#define FUNC_SIG(klass, name) _noexport KrkValue FUNC_NAME(klass,name) (int argc, const KrkValue argv[], int hasKw)
|
||||
|
@ -153,8 +153,8 @@ KRK_Method(dict,__len__) {
|
||||
|
||||
KRK_Method(dict,__contains__) {
|
||||
METHOD_TAKES_EXACTLY(1);
|
||||
KrkValue _unused;
|
||||
return BOOLEAN_VAL(krk_tableGet(&self->entries, argv[1], &_unused));
|
||||
KrkValue v;
|
||||
return BOOLEAN_VAL(krk_tableGet(&self->entries, argv[1], &v));
|
||||
}
|
||||
|
||||
KRK_Method(dict,capacity) {
|
||||
|
@ -521,7 +521,7 @@ KRK_Method(listiterator,__init__) {
|
||||
}
|
||||
|
||||
FUNC_SIG(listiterator,__call__) {
|
||||
static __attribute__ ((unused)) const char* _method_name = "__call__";
|
||||
static _unused const char* _method_name = "__call__";
|
||||
if (unlikely((argc != 1))) goto _bad;
|
||||
if (unlikely(!IS_OBJECT(argv[0]))) goto _bad;
|
||||
if (unlikely(AS_INSTANCE(argv[0])->_class != vm.baseClasses->listiteratorClass)) goto _bad;
|
||||
|
@ -63,8 +63,8 @@ KRK_Method(set,__init__) {
|
||||
|
||||
KRK_Method(set,__contains__) {
|
||||
METHOD_TAKES_EXACTLY(1);
|
||||
KrkValue _unused;
|
||||
return BOOLEAN_VAL(krk_tableGet(&self->entries, argv[1], &_unused));
|
||||
KrkValue v;
|
||||
return BOOLEAN_VAL(krk_tableGet(&self->entries, argv[1], &v));
|
||||
}
|
||||
|
||||
KRK_Method(set,__repr__) {
|
||||
@ -198,11 +198,11 @@ KRK_Method(set,__eq__) {
|
||||
if (self->entries.count != them->entries.count)
|
||||
return BOOLEAN_VAL(0);
|
||||
|
||||
KrkValue _unused;
|
||||
KrkValue v;
|
||||
|
||||
for (unsigned int i = 0; i < self->entries.capacity; ++i) {
|
||||
if (IS_KWARGS(self->entries.entries[i].key)) continue;
|
||||
if (!krk_tableGet(&them->entries, self->entries.entries[i].key, &_unused)) return BOOLEAN_VAL(0);
|
||||
if (!krk_tableGet(&them->entries, self->entries.entries[i].key, &v)) return BOOLEAN_VAL(0);
|
||||
}
|
||||
|
||||
return BOOLEAN_VAL(1);
|
||||
@ -216,10 +216,10 @@ KRK_Method(set,__lt__) {
|
||||
struct Set * them = AS_set(argv[1]);
|
||||
if (self->entries.count == them->entries.count)
|
||||
return BOOLEAN_VAL(0);
|
||||
KrkValue _unused;
|
||||
KrkValue v;
|
||||
for (unsigned int i = 0; i < self->entries.capacity; ++i) {
|
||||
if (IS_KWARGS(self->entries.entries[i].key)) continue;
|
||||
if (!krk_tableGet(&them->entries, self->entries.entries[i].key, &_unused)) return BOOLEAN_VAL(0);
|
||||
if (!krk_tableGet(&them->entries, self->entries.entries[i].key, &v)) return BOOLEAN_VAL(0);
|
||||
}
|
||||
return BOOLEAN_VAL(1);
|
||||
}
|
||||
@ -230,10 +230,10 @@ KRK_Method(set,__le__) {
|
||||
if (!IS_set(argv[1]))
|
||||
return NOTIMPL_VAL();
|
||||
struct Set * them = AS_set(argv[1]);
|
||||
KrkValue _unused;
|
||||
KrkValue v;
|
||||
for (unsigned int i = 0; i < self->entries.capacity; ++i) {
|
||||
if (IS_KWARGS(self->entries.entries[i].key)) continue;
|
||||
if (!krk_tableGet(&them->entries, self->entries.entries[i].key, &_unused)) return BOOLEAN_VAL(0);
|
||||
if (!krk_tableGet(&them->entries, self->entries.entries[i].key, &v)) return BOOLEAN_VAL(0);
|
||||
}
|
||||
return BOOLEAN_VAL(1);
|
||||
}
|
||||
@ -246,10 +246,10 @@ KRK_Method(set,__gt__) {
|
||||
struct Set * them = AS_set(argv[1]);
|
||||
if (self->entries.count == them->entries.count)
|
||||
return BOOLEAN_VAL(0);
|
||||
KrkValue _unused;
|
||||
KrkValue v;
|
||||
for (unsigned int i = 0; i < them->entries.capacity; ++i) {
|
||||
if (IS_KWARGS(them->entries.entries[i].key)) continue;
|
||||
if (!krk_tableGet(&self->entries, them->entries.entries[i].key, &_unused)) return BOOLEAN_VAL(0);
|
||||
if (!krk_tableGet(&self->entries, them->entries.entries[i].key, &v)) return BOOLEAN_VAL(0);
|
||||
}
|
||||
return BOOLEAN_VAL(1);
|
||||
}
|
||||
@ -259,10 +259,10 @@ KRK_Method(set,__ge__) {
|
||||
if (!IS_set(argv[1]))
|
||||
return NOTIMPL_VAL();
|
||||
struct Set * them = AS_set(argv[1]);
|
||||
KrkValue _unused;
|
||||
KrkValue v;
|
||||
for (unsigned int i = 0; i < them->entries.capacity; ++i) {
|
||||
if (IS_KWARGS(them->entries.entries[i].key)) continue;
|
||||
if (!krk_tableGet(&self->entries, them->entries.entries[i].key, &_unused)) return BOOLEAN_VAL(0);
|
||||
if (!krk_tableGet(&self->entries, them->entries.entries[i].key, &v)) return BOOLEAN_VAL(0);
|
||||
}
|
||||
return BOOLEAN_VAL(1);
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
* @param arg The value passed that failed the type check.
|
||||
* @param argName Name of the argument. If NULL or zero-length, argument name is not included in the description.
|
||||
*/
|
||||
__attribute__((cold))
|
||||
_cold
|
||||
static void raise_TypeError(const char * method_name, const char * expected, KrkValue arg, const char * argName) {
|
||||
krk_runtimeError(vm.exceptions->typeError,
|
||||
"%s()%s%s expects %s, not '%T'",
|
||||
@ -37,7 +37,7 @@ static void raise_TypeError(const char * method_name, const char * expected, Krk
|
||||
* @param method_name Original method name passed to krk_parseArgs.
|
||||
* @param fmt Pointer to somewhere in the format string up to the colon.
|
||||
*/
|
||||
__attribute__((cold))
|
||||
_cold
|
||||
static const char * methodName(const char * method_name, const char * fmt) {
|
||||
const char * maybeColon = strchr(fmt, ':');
|
||||
return maybeColon ? maybeColon + 1 : method_name;
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <kuroko/kuroko.h>
|
||||
#include <kuroko/scanner.h>
|
||||
|
||||
KrkScanner krk_initScanner(const char * src) {
|
||||
|
@ -23,6 +23,10 @@
|
||||
# define KRK_BUILD_COMPILER "GCC " __VERSION__
|
||||
#elif (defined(__clang__))
|
||||
# define KRK_BUILD_COMPILER "clang " __clang_version__
|
||||
#elif (defined(_MSC_VER) && !defined(__clang__))
|
||||
# define KRK_ARG_STR(str) #str
|
||||
# define KRK_ARG_LOL(s) KRK_ARG_STR(s)
|
||||
# define KRK_BUILD_COMPILER "msvc " KRK_ARG_LOL(_MSC_FULL_VER)
|
||||
#else
|
||||
# define KRK_BUILD_COMPILER ""
|
||||
#endif
|
||||
|
@ -105,7 +105,7 @@ KrkTableEntry * krk_findEntryExact(KrkTableEntry * entries, size_t capacity, Krk
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __TINYC__
|
||||
#if defined(__TINYC__) || (defined(_MSC_VER) && !defined(__clang__))
|
||||
int __builtin_clz(unsigned int x) {
|
||||
int i = 31;
|
||||
while (!(x & (1 << i)) && i >= 0) i--;
|
||||
|
@ -99,7 +99,7 @@ static inline int _krk_diff_type_equivalence(uint16_t val_a, uint16_t val_b, Krk
|
||||
return _krk_method_equivalence(a,b);
|
||||
}
|
||||
|
||||
__attribute__((hot))
|
||||
_hot
|
||||
int krk_valuesSameOrEqual(KrkValue a, KrkValue b) {
|
||||
if (a == b) return 1;
|
||||
uint16_t val_a = KRK_VAL_TYPE(a);
|
||||
@ -109,7 +109,7 @@ int krk_valuesSameOrEqual(KrkValue a, KrkValue b) {
|
||||
: _krk_diff_type_equivalence(val_a, val_b, a, b);
|
||||
}
|
||||
|
||||
__attribute__((hot))
|
||||
_hot
|
||||
int krk_valuesEqual(KrkValue a, KrkValue b) {
|
||||
uint16_t val_a = KRK_VAL_TYPE(a);
|
||||
uint16_t val_b = KRK_VAL_TYPE(b);
|
||||
|
9
src/vm.c
9
src/vm.c
@ -2,7 +2,6 @@
|
||||
#include <limits.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
@ -224,7 +223,7 @@ KrkClass * krk_makeClass(KrkInstance * module, KrkClass ** _class, const char *
|
||||
*
|
||||
* For a class built by managed code, called by type.__new__
|
||||
*/
|
||||
__attribute__((nonnull))
|
||||
_nonnull
|
||||
void krk_finalizeClass(KrkClass * _class) {
|
||||
KrkValue tmp;
|
||||
|
||||
@ -258,8 +257,8 @@ void krk_finalizeClass(KrkClass * _class) {
|
||||
if (_class->base && _class->_eq != _class->base->_eq) {
|
||||
if (_class->_hash == _class->base->_hash) {
|
||||
_class->_hash = NULL;
|
||||
KrkValue _unused;
|
||||
if (!krk_tableGet_fast(&_class->methods, AS_STRING(vm.specialMethodNames[METHOD_HASH]), &_unused)) {
|
||||
KrkValue v;
|
||||
if (!krk_tableGet_fast(&_class->methods, AS_STRING(vm.specialMethodNames[METHOD_HASH]), &v)) {
|
||||
krk_tableSet(&_class->methods, OBJECT_VAL(vm.specialMethodNames[METHOD_HASH]), NONE_VAL());
|
||||
}
|
||||
}
|
||||
@ -2146,7 +2145,7 @@ _resumeHook: (void)0;
|
||||
unsigned int OPERAND = 0;
|
||||
|
||||
/* Only GCC lets us put these on empty statements; just hope clang doesn't start complaining */
|
||||
#ifndef __clang__
|
||||
#if defined(__GNUC__) && !defined(__clang__)
|
||||
# define FALLTHROUGH __attribute__((fallthrough));
|
||||
#else
|
||||
# define FALLTHROUGH
|
||||
|
Loading…
Reference in New Issue
Block a user