Files
wren/src/wren_common.h
T

97 lines
3.6 KiB
C
Raw Normal View History

2013-11-12 08:32:35 -08:00
#ifndef wren_common_h
#define wren_common_h
2013-11-28 08:11:50 -08:00
// This header contains macros and defines used across the entire Wren
// implementation. In particular, it contains "configuration" defines that
// control how Wren works. Some of these are only used while hacking on
// debugging Wren itself.
//
// This header is *not* intended to be included by code outside of Wren itself.
2013-12-14 11:06:54 -08:00
// These flags let you control some details of the interpreter's implementation.
// Usually they trade-off a bit of portability for speed. They default to the
// most efficient behavior.
2013-12-10 16:13:25 -08:00
2013-12-14 23:41:23 -08:00
// If true, then Wren will use a NaN-tagged double for its core value
2013-12-14 11:06:54 -08:00
// representation. Otherwise, it will use a larger more conventional struct.
// The former is significantly faster and more compact. The latter is useful for
// debugging and may be more portable.
//
// Defaults to on.
#ifndef WREN_NAN_TAGGING
2013-12-14 23:41:23 -08:00
#define WREN_NAN_TAGGING true
2013-12-14 11:06:54 -08:00
#endif
2013-11-12 08:32:35 -08:00
2013-12-14 23:41:23 -08:00
// If true, the VM's interpreter loop uses computed gotos. See this for more:
// http://gcc.gnu.org/onlinedocs/gcc-3.1.1/gcc/Labels-as-Values.html
2013-12-14 11:06:54 -08:00
// Enabling this speeds up the main dispatch loop a bit, but requires compiler
// support.
//
// Defaults to on.
#ifndef WREN_COMPUTED_GOTO
2013-12-14 23:41:23 -08:00
#define WREN_COMPUTED_GOTO true
2013-12-14 11:06:54 -08:00
#endif
2013-11-24 21:48:27 -08:00
2013-12-14 11:06:54 -08:00
// These flags are useful for debugging and hacking on Wren itself. They are not
// intended to be used for production code. They default to off.
2013-12-14 23:41:23 -08:00
// Set this to true to stress test the GC. It will perform a collection before
// every allocation. This is useful to ensure that memory is always correctly
// pinned.
#define WREN_DEBUG_GC_STRESS false
2013-12-14 11:06:54 -08:00
2013-12-14 23:41:23 -08:00
// Set this to true to log memory operations as they occur.
#define WREN_TRACE_MEMORY false
2013-12-14 11:06:54 -08:00
2014-01-03 13:17:14 -08:00
// Set this to true to log garbage collections as they occur.
#define WREN_TRACE_GC false
2014-01-06 08:01:04 -08:00
// Set this to true to print out the compiled bytecode of each function.
#define WREN_DUMP_COMPILED_CODE false
2013-12-29 10:06:35 -08:00
// The maximum number of arguments that can be passed to a method. Note that
// this limtation is hardcoded in other places in the VM, in particular, the
// `CODE_CALL_XX` instructions assume a certain maximum number.
#define MAX_PARAMETERS (16)
// The maximum name of a method, not including the signature. This is an
// arbitrary but enforced maximum just so we know how long the method name
// strings need to be in the parser.
#define MAX_METHOD_NAME (64)
// The maximum length of a method signature. This includes the name, and the
// extra spaces added to handle arity, and another byte to terminate the string.
#define MAX_METHOD_SIGNATURE (MAX_METHOD_NAME + MAX_PARAMETERS + 1)
2014-01-15 07:59:10 -08:00
// The maximum number of fields a class can have, including inherited fields.
// This is explicit in the bytecode since `CODE_CLASS` and `CODE_SUBCLASS` take
// a single byte for the number of fields. Note that it's 255 and not 256
// because creating a class takes the *number* of fields, not the *highest
// field index*.
#define MAX_FIELDS (255)
2013-12-14 11:06:54 -08:00
// Assertions are used to validate program invariants. They indicate things the
// program expects to be true about its internal state during execution. If an
// assertion fails, there is a bug in Wren.
//
// Assertions add significant overhead, so are only enabled in debug builds.
2013-11-12 08:32:35 -08:00
#ifdef DEBUG
2013-12-14 11:06:54 -08:00
#define ASSERT(condition, message) \
if (!(condition)) { \
printf("ASSERT FAIL " __FILE__ ":%d - %s\n", __LINE__, message); \
abort(); \
}
2013-11-12 08:32:35 -08:00
#else
2013-12-14 11:06:54 -08:00
#define ASSERT(condition, message) ;
2013-11-12 08:32:35 -08:00
#endif
2013-12-22 20:53:35 -08:00
// Assertion to indicate that the given point in the code should never be
// reached.
#define UNREACHABLE() ASSERT(false, "This line should not be reached.");
2013-11-12 08:32:35 -08:00
#endif