1
0
forked from Mirror/wren

wren/vm: Uniformize macros to stick to 80 columns. (#756)

uniform macros
This commit is contained in:
Michel Hermier
2020-06-08 21:23:15 +02:00
committed by GitHub
parent 2c2f5936eb
commit 26d0194117
7 changed files with 147 additions and 151 deletions

View File

@ -157,16 +157,14 @@
#include <stdio.h>
#define ASSERT(condition, message) \
do \
{ \
do { \
if (!(condition)) \
{ \
fprintf(stderr, "[%s:%d] Assert failed in %s(): %s\n", \
__FILE__, __LINE__, __func__, message); \
abort(); \
} \
} \
while(0)
} while (false)
// Indicates that we know execution should never reach this point in the
// program. In debug mode, we assert this fact because it's a bug to get here.
@ -176,17 +174,15 @@
// in some cases and also lets it perform some optimizations by assuming the
// code is never reached.
#define UNREACHABLE() \
do \
{ \
do { \
fprintf(stderr, "[%s:%d] This code should not be reached in %s()\n", \
__FILE__, __LINE__, __func__); \
abort(); \
} \
while (0)
} while (false)
#else
#define ASSERT(condition, message) do {} while (0)
#define ASSERT(condition, message) do { } while (false)
// Tell the compiler that this part of the code will never be reached.
#if defined( _MSC_VER )

View File

@ -264,7 +264,7 @@ static void call_fn(WrenVM* vm, Value* args, int numArgs)
{ \
call_fn(vm, args, numArgs); \
return false; \
} \
}
DEF_FN_CALL(0)
DEF_FN_CALL(1)

View File

@ -123,7 +123,7 @@ static int dumpInstruction(WrenVM* vm, ObjFn* fn, int i, int* lastLine)
#define BYTE_INSTRUCTION(name) \
printf("%-16s %5d\n", name, READ_BYTE()); \
break; \
break
switch (code)
{

View File

@ -6,14 +6,14 @@
// Binds a primitive method named [name] (in Wren) implemented using C function
// [fn] to `ObjClass` [cls].
#define PRIMITIVE(cls, name, function) \
{ \
do { \
int symbol = wrenSymbolTableEnsure(vm, \
&vm->methodNames, name, strlen(name)); \
Method method; \
method.type = METHOD_PRIMITIVE; \
method.as.primitive = prim_##function; \
wrenBindMethod(vm, cls, symbol, method); \
}
} while (false)
// Defines a primitive method whose C function name is [name]. This abstracts
// the actual type signature of a primitive function and makes it clear which C
@ -21,7 +21,11 @@
#define DEF_PRIMITIVE(name) \
static bool prim_##name(WrenVM* vm, Value* args)
#define RETURN_VAL(value) do { args[0] = value; return true; } while (0)
#define RETURN_VAL(value) \
do { \
args[0] = value; \
return true; \
} while (false)
#define RETURN_OBJ(obj) RETURN_VAL(OBJ_VAL(obj))
#define RETURN_BOOL(value) RETURN_VAL(BOOL_VAL(value))
@ -34,13 +38,13 @@
do { \
vm->fiber->error = wrenNewStringLength(vm, msg, sizeof(msg) - 1); \
return false; \
} while (0);
} while (false)
#define RETURN_ERROR_FMT(msg, arg) \
do { \
vm->fiber->error = wrenStringFormat(vm, msg, arg); \
return false; \
} while (0);
} while (false)
// Validates that the given [arg] is a function. Returns true if it is. If not,
// reports an error and returns false.

View File

@ -798,35 +798,33 @@ static WrenInterpretResult runInterpreter(WrenVM* vm, register ObjFiber* fiber)
// Use this after a CallFrame has been pushed or popped to refresh the local
// variables.
#define LOAD_FRAME() \
do { \
frame = &fiber->frames[fiber->numFrames - 1]; \
stackStart = frame->stackStart; \
ip = frame->ip; \
fn = frame->closure->fn;
fn = frame->closure->fn; \
} while (false)
// Terminates the current fiber with error string [error]. If another calling
// fiber is willing to catch the error, transfers control to it, otherwise
// exits the interpreter.
#define RUNTIME_ERROR() \
do \
{ \
do { \
STORE_FRAME(); \
runtimeError(vm); \
if (vm->fiber == NULL) return WREN_RESULT_RUNTIME_ERROR; \
fiber = vm->fiber; \
LOAD_FRAME(); \
DISPATCH(); \
} \
while (false)
} while (false)
#if WREN_DEBUG_TRACE_INSTRUCTIONS
// Prints the stack and instruction before each instruction is executed.
#define DEBUG_TRACE_INSTRUCTIONS() \
do \
{ \
do { \
wrenDumpStack(fiber); \
wrenDumpInstruction(vm, fn, (int)(ip - fn->code.data)); \
} \
while (false)
} while (false)
#else
#define DEBUG_TRACE_INSTRUCTIONS() do { } while (false)
#endif
@ -843,12 +841,10 @@ static WrenInterpretResult runInterpreter(WrenVM* vm, register ObjFiber* fiber)
#define CASE_CODE(name) code_##name
#define DISPATCH() \
do \
{ \
do { \
DEBUG_TRACE_INSTRUCTIONS(); \
goto *dispatchTable[instruction = (Code)READ_BYTE()]; \
} \
while (false)
} while (false)
#else