mirror of
https://github.com/CPunch/Cosmo.git
synced 2024-11-21 15:00:06 +00:00
implemented jump table dispatch
- currently only enabled on supported platforms (GNU C Compiler + Clang) - when enabled, sped up examples/fibtest.cosmo by about 20% (avg of 11.179s prior and 8.799 after) NOTE: malicious dumps can trivially cause crashes now by having junk function chunks
This commit is contained in:
parent
7bca6927a9
commit
2b3825d258
@ -64,7 +64,7 @@ typedef enum
|
||||
OP_FALSE,
|
||||
OP_NIL,
|
||||
|
||||
OP_RETURN
|
||||
OP_RETURN,
|
||||
} COPCODE; // there can be a max of 256 instructions
|
||||
|
||||
#endif
|
||||
|
10
src/cosmo.h
10
src/cosmo.h
@ -14,7 +14,15 @@
|
||||
performance, however this will produce undefined behavior as you reach the stack limit (and may
|
||||
cause a seg fault!). It is recommended to keep this enabled.
|
||||
*/
|
||||
#define SAFE_STACK
|
||||
// #define SAFE_STACK
|
||||
|
||||
/*
|
||||
NAN_BOXXED:
|
||||
if undefined, the interpreter will use a tagged union to store values. This is the default.
|
||||
Note that even though the sizeof(CValue) is 8 bytes for NAN_BOXXED (as opposed to 16 bytes for
|
||||
the tagged union) no performance benefits were measured. I recommend keeping this undefined for
|
||||
now.
|
||||
*/
|
||||
// #define NAN_BOXXED
|
||||
|
||||
// forward declare *most* stuff so our headers are cleaner
|
||||
|
13
src/cvm.h
13
src/cvm.h
@ -8,6 +8,19 @@
|
||||
|
||||
// #define VM_DEBUG
|
||||
|
||||
/*
|
||||
if we're using GNUC or clang, we can use computed gotos which speeds up
|
||||
cosmoV_execute by about 20% from benchmarking. of course, if you know
|
||||
your compiler supports computed gotos, you can define VM_JUMPTABLE
|
||||
|
||||
BTW: be weary of maliciously crafted cosmo dumps!! it's very easy to crash
|
||||
cosmo with this enabled and reading invalid opcodes due to us just using the
|
||||
opcode as an index into the jump table
|
||||
*/
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
# define VM_JUMPTABLE
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
COSMOVM_OK,
|
||||
|
Loading…
Reference in New Issue
Block a user