DavidKinder / Git

Fast Glulx interpreter, originally written by Iain Merrick.
MIT License
46 stars 13 forks source link

Git doesn't work when compiled with Visual C++ #10

Closed DavidKinder closed 3 years ago

DavidKinder commented 3 years ago

Visual C++ doesn't support GCC's label-as-value extension, so Git can only be compiled with Visual C++ without direct threading. The code mostly seems to work, but for some games (e.g. Alabaster) halts at some point with a "bad opcode" error. Need to investigate whether this is a problem with Git or with Visual C++.

DavidKinder commented 3 years ago

The problem seems to occur when Git hits a "do_recompile" instruction.

DavidKinder commented 3 years ago

This looks to be a subtle problem with Visual C++. The problematic line is in terp.c:

pc = compile (READ_PC);

READ_PC is a preprocessor definition, expanding it out gives (with a little simplification):

pc = compile (*pc++);

The C99 specification says that there is a sequence point before a function is called, after all arguments have been evaluated, so pc should be incremented before the compile() call, but Visual C++ does it after the function call and after pc has been assigned to.

Since pc doesn't need incrementing in this case, the problem can be avoided with slightly simpler code:

pc = compile (*pc);
DavidKinder commented 3 years ago

Fixed by 20a7bb24a448d0f0607477862424009e00f1fdac