Re: SWITCH question
- Posted by jimcbrown (admin) Jan 06, 2018
- 1808 views
Some of the other switch failures seem to come from be_execute.c around line 2030 - specifically when the call to thread() is executed.
Does it still crash if you define INT_CODES? (Look at Makefile.gnu and add -DINT_CODES to EOSFLAGS). By specifying to build the interpreter with INT_CODES you can skip over all this assembly/goto stuff. With INT_CODES, the IL codes are instead processed one at a time, more slowly ... by a big switch statement.
Now we are deep into the land of assembly language. Should we abandon all hope?
I know exactly what this is. Basically, we convert the IL codes into a set of memory addresses, and then we use a goto to jump to the code that handles a particular IL instruction.
thread() is defined on line 803:
#define thread() do { __asm { JMP [pc] } } while(0)
Incidently, this is the wrong one. This definition is only used when compiling against MSVC on Windoze.
This is the one used on Unix/MinGW:
#if defined(EUNIX) || defined(EMINGW) // these GNU-based compilers support dynamic labels, // so threading is much easier #define thread() goto *((void *)*pc) #define thread2() {pc += 2; goto *((void *)*pc);} #define thread4() {pc += 4; goto *((void *)*pc);} #define thread5() {pc += 5; goto *((void *)*pc);} #define inc3pc() pc += 3 #define BREAK goto *((void *)*pc) #endif