forked from Mirror/wren
Make do blocks in macros consistent with the rest of the code
This commit is contained in:
@ -157,7 +157,8 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#define ASSERT(condition, message) \
|
#define ASSERT(condition, message) \
|
||||||
do { \
|
do \
|
||||||
|
{ \
|
||||||
if (!(condition)) \
|
if (!(condition)) \
|
||||||
{ \
|
{ \
|
||||||
fprintf(stderr, "[%s:%d] Assert failed in %s(): %s\n", \
|
fprintf(stderr, "[%s:%d] Assert failed in %s(): %s\n", \
|
||||||
@ -174,7 +175,8 @@
|
|||||||
// in some cases and also lets it perform some optimizations by assuming the
|
// in some cases and also lets it perform some optimizations by assuming the
|
||||||
// code is never reached.
|
// code is never reached.
|
||||||
#define UNREACHABLE() \
|
#define UNREACHABLE() \
|
||||||
do { \
|
do \
|
||||||
|
{ \
|
||||||
fprintf(stderr, "[%s:%d] This code should not be reached in %s()\n", \
|
fprintf(stderr, "[%s:%d] This code should not be reached in %s()\n", \
|
||||||
__FILE__, __LINE__, __func__); \
|
__FILE__, __LINE__, __func__); \
|
||||||
abort(); \
|
abort(); \
|
||||||
|
|||||||
@ -6,7 +6,8 @@
|
|||||||
// Binds a primitive method named [name] (in Wren) implemented using C function
|
// Binds a primitive method named [name] (in Wren) implemented using C function
|
||||||
// [fn] to `ObjClass` [cls].
|
// [fn] to `ObjClass` [cls].
|
||||||
#define PRIMITIVE(cls, name, function) \
|
#define PRIMITIVE(cls, name, function) \
|
||||||
do { \
|
do \
|
||||||
|
{ \
|
||||||
int symbol = wrenSymbolTableEnsure(vm, \
|
int symbol = wrenSymbolTableEnsure(vm, \
|
||||||
&vm->methodNames, name, strlen(name)); \
|
&vm->methodNames, name, strlen(name)); \
|
||||||
Method method; \
|
Method method; \
|
||||||
@ -22,7 +23,8 @@
|
|||||||
static bool prim_##name(WrenVM* vm, Value* args)
|
static bool prim_##name(WrenVM* vm, Value* args)
|
||||||
|
|
||||||
#define RETURN_VAL(value) \
|
#define RETURN_VAL(value) \
|
||||||
do { \
|
do \
|
||||||
|
{ \
|
||||||
args[0] = value; \
|
args[0] = value; \
|
||||||
return true; \
|
return true; \
|
||||||
} while (false)
|
} while (false)
|
||||||
@ -35,13 +37,15 @@
|
|||||||
#define RETURN_TRUE RETURN_VAL(TRUE_VAL)
|
#define RETURN_TRUE RETURN_VAL(TRUE_VAL)
|
||||||
|
|
||||||
#define RETURN_ERROR(msg) \
|
#define RETURN_ERROR(msg) \
|
||||||
do { \
|
do \
|
||||||
|
{ \
|
||||||
vm->fiber->error = wrenNewStringLength(vm, msg, sizeof(msg) - 1); \
|
vm->fiber->error = wrenNewStringLength(vm, msg, sizeof(msg) - 1); \
|
||||||
return false; \
|
return false; \
|
||||||
} while (false)
|
} while (false)
|
||||||
|
|
||||||
#define RETURN_ERROR_FMT(msg, arg) \
|
#define RETURN_ERROR_FMT(msg, arg) \
|
||||||
do { \
|
do \
|
||||||
|
{ \
|
||||||
vm->fiber->error = wrenStringFormat(vm, msg, arg); \
|
vm->fiber->error = wrenStringFormat(vm, msg, arg); \
|
||||||
return false; \
|
return false; \
|
||||||
} while (false)
|
} while (false)
|
||||||
@ -49,6 +53,7 @@
|
|||||||
// Validates that the given [arg] is a function. Returns true if it is. If not,
|
// Validates that the given [arg] is a function. Returns true if it is. If not,
|
||||||
// reports an error and returns false.
|
// reports an error and returns false.
|
||||||
bool validateFn(WrenVM* vm, Value arg, const char* argName);
|
bool validateFn(WrenVM* vm, Value arg, const char* argName);
|
||||||
|
bool validateFn(WrenVM* vm, Value arg, const char* argName);
|
||||||
|
|
||||||
// Validates that the given [arg] is a Num. Returns true if it is. If not,
|
// Validates that the given [arg] is a Num. Returns true if it is. If not,
|
||||||
// reports an error and returns false.
|
// reports an error and returns false.
|
||||||
|
|||||||
@ -798,7 +798,8 @@ static WrenInterpretResult runInterpreter(WrenVM* vm, register ObjFiber* fiber)
|
|||||||
// Use this after a CallFrame has been pushed or popped to refresh the local
|
// Use this after a CallFrame has been pushed or popped to refresh the local
|
||||||
// variables.
|
// variables.
|
||||||
#define LOAD_FRAME() \
|
#define LOAD_FRAME() \
|
||||||
do { \
|
do \
|
||||||
|
{ \
|
||||||
frame = &fiber->frames[fiber->numFrames - 1]; \
|
frame = &fiber->frames[fiber->numFrames - 1]; \
|
||||||
stackStart = frame->stackStart; \
|
stackStart = frame->stackStart; \
|
||||||
ip = frame->ip; \
|
ip = frame->ip; \
|
||||||
@ -809,7 +810,8 @@ static WrenInterpretResult runInterpreter(WrenVM* vm, register ObjFiber* fiber)
|
|||||||
// fiber is willing to catch the error, transfers control to it, otherwise
|
// fiber is willing to catch the error, transfers control to it, otherwise
|
||||||
// exits the interpreter.
|
// exits the interpreter.
|
||||||
#define RUNTIME_ERROR() \
|
#define RUNTIME_ERROR() \
|
||||||
do { \
|
do \
|
||||||
|
{ \
|
||||||
STORE_FRAME(); \
|
STORE_FRAME(); \
|
||||||
runtimeError(vm); \
|
runtimeError(vm); \
|
||||||
if (vm->fiber == NULL) return WREN_RESULT_RUNTIME_ERROR; \
|
if (vm->fiber == NULL) return WREN_RESULT_RUNTIME_ERROR; \
|
||||||
@ -821,7 +823,8 @@ static WrenInterpretResult runInterpreter(WrenVM* vm, register ObjFiber* fiber)
|
|||||||
#if WREN_DEBUG_TRACE_INSTRUCTIONS
|
#if WREN_DEBUG_TRACE_INSTRUCTIONS
|
||||||
// Prints the stack and instruction before each instruction is executed.
|
// Prints the stack and instruction before each instruction is executed.
|
||||||
#define DEBUG_TRACE_INSTRUCTIONS() \
|
#define DEBUG_TRACE_INSTRUCTIONS() \
|
||||||
do { \
|
do \
|
||||||
|
{ \
|
||||||
wrenDumpStack(fiber); \
|
wrenDumpStack(fiber); \
|
||||||
wrenDumpInstruction(vm, fn, (int)(ip - fn->code.data)); \
|
wrenDumpInstruction(vm, fn, (int)(ip - fn->code.data)); \
|
||||||
} while (false)
|
} while (false)
|
||||||
@ -841,7 +844,8 @@ static WrenInterpretResult runInterpreter(WrenVM* vm, register ObjFiber* fiber)
|
|||||||
#define CASE_CODE(name) code_##name
|
#define CASE_CODE(name) code_##name
|
||||||
|
|
||||||
#define DISPATCH() \
|
#define DISPATCH() \
|
||||||
do { \
|
do \
|
||||||
|
{ \
|
||||||
DEBUG_TRACE_INSTRUCTIONS(); \
|
DEBUG_TRACE_INSTRUCTIONS(); \
|
||||||
goto *dispatchTable[instruction = (Code)READ_BYTE()]; \
|
goto *dispatchTable[instruction = (Code)READ_BYTE()]; \
|
||||||
} while (false)
|
} while (false)
|
||||||
|
|||||||
Reference in New Issue
Block a user