mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2025-02-07 15:31:02 +00:00
- fixed issues with Dehacked's ad-hoc script code generation
* The functions had no prototype and caused crashes. * even after creating a prototype it didn't work because CreateAnonymousFunction was set up incorrectly for the case where a known return type was given.
This commit is contained in:
parent
48c2f6451e
commit
fc341c901f
2 changed files with 16 additions and 5 deletions
|
@ -707,8 +707,11 @@ static void CreatePlaySoundFunc(FunctionCallEmitter &emitters, int value1, int v
|
||||||
// misc1 = state, misc2 = probability
|
// misc1 = state, misc2 = probability
|
||||||
static void CreateRandomJumpFunc(FunctionCallEmitter &emitters, int value1, int value2)
|
static void CreateRandomJumpFunc(FunctionCallEmitter &emitters, int value1, int value2)
|
||||||
{ // A_Jump
|
{ // A_Jump
|
||||||
|
auto symlabel = StateLabels.AddPointer(FindState(value1));
|
||||||
|
|
||||||
emitters.AddParameterIntConst(value2); // maxchance
|
emitters.AddParameterIntConst(value2); // maxchance
|
||||||
emitters.AddParameterPointerConst(FindState(value1)); // jumpto
|
emitters.AddParameterIntConst(symlabel); // jumpto
|
||||||
|
emitters.AddReturn(REGT_POINTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
// misc1 = Boom linedef type, misc2 = sector tag
|
// misc1 = Boom linedef type, misc2 = sector tag
|
||||||
|
@ -765,6 +768,8 @@ void SetDehParams(FState *state, int codepointer)
|
||||||
int value2 = state->GetMisc2();
|
int value2 = state->GetMisc2();
|
||||||
if (!(value1|value2)) return;
|
if (!(value1|value2)) return;
|
||||||
|
|
||||||
|
bool returnsState = codepointer == 6;
|
||||||
|
|
||||||
// Fakey fake script position thingamajig. Because NULL cannot be used instead.
|
// Fakey fake script position thingamajig. Because NULL cannot be used instead.
|
||||||
// Even if the lump was parsed by an FScanner, there would hardly be a way to
|
// Even if the lump was parsed by an FScanner, there would hardly be a way to
|
||||||
// identify which line is troublesome.
|
// identify which line is troublesome.
|
||||||
|
@ -783,6 +788,7 @@ void SetDehParams(FState *state, int codepointer)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int numargs = sym->GetImplicitArgs();
|
int numargs = sym->GetImplicitArgs();
|
||||||
|
auto funcsym = CreateAnonymousFunction(RUNTIME_CLASS(AActor)->VMType, returnsState? (PType*)TypeState : TypeVoid, numargs==3? SUF_ACTOR|SUF_WEAPON : SUF_ACTOR);
|
||||||
VMFunctionBuilder buildit(numargs);
|
VMFunctionBuilder buildit(numargs);
|
||||||
// Allocate registers used to pass parameters in.
|
// Allocate registers used to pass parameters in.
|
||||||
// self, stateowner, state (all are pointers)
|
// self, stateowner, state (all are pointers)
|
||||||
|
@ -795,10 +801,15 @@ void SetDehParams(FState *state, int codepointer)
|
||||||
}
|
}
|
||||||
// Emit code for action parameters.
|
// Emit code for action parameters.
|
||||||
MBFCodePointerFactories[codepointer](emitters, value1, value2);
|
MBFCodePointerFactories[codepointer](emitters, value1, value2);
|
||||||
emitters.EmitCall(&buildit);
|
auto where = emitters.EmitCall(&buildit);
|
||||||
buildit.Emit(OP_RET, RET_FINAL, REGT_NIL, 0);
|
if (!returnsState) buildit.Emit(OP_RET, RET_FINAL, REGT_NIL, 0);
|
||||||
|
else buildit.Emit(OP_RET, RET_FINAL, EncodeRegType(where), where.RegNum);
|
||||||
|
where.Free(&buildit);
|
||||||
|
|
||||||
// Attach it to the state.
|
// Attach it to the state.
|
||||||
VMScriptFunction *sfunc = new VMScriptFunction;
|
VMScriptFunction *sfunc = new VMScriptFunction;
|
||||||
|
funcsym->Variants[0].Implementation = sfunc;
|
||||||
|
sfunc->Proto = funcsym->Variants[0].Proto;
|
||||||
sfunc->RegTypes = regts; // These functions are built after running the script compiler so they don't get this info.
|
sfunc->RegTypes = regts; // These functions are built after running the script compiler so they don't get this info.
|
||||||
buildit.MakeFunction(sfunc);
|
buildit.MakeFunction(sfunc);
|
||||||
sfunc->NumArgs = numargs;
|
sfunc->NumArgs = numargs;
|
||||||
|
|
|
@ -221,7 +221,7 @@ void SetImplicitArgs(TArray<PType *> *args, TArray<uint32_t> *argflags, TArray<F
|
||||||
|
|
||||||
PFunction *CreateAnonymousFunction(PContainerType *containingclass, PType *returntype, int flags)
|
PFunction *CreateAnonymousFunction(PContainerType *containingclass, PType *returntype, int flags)
|
||||||
{
|
{
|
||||||
TArray<PType *> rets(1);
|
TArray<PType *> rets;
|
||||||
TArray<PType *> args;
|
TArray<PType *> args;
|
||||||
TArray<uint32_t> argflags;
|
TArray<uint32_t> argflags;
|
||||||
TArray<FName> argnames;
|
TArray<FName> argnames;
|
||||||
|
@ -233,7 +233,7 @@ PFunction *CreateAnonymousFunction(PContainerType *containingclass, PType *retur
|
||||||
// (just give them VARF_Play, whatever)
|
// (just give them VARF_Play, whatever)
|
||||||
fflags |= VARF_Play;
|
fflags |= VARF_Play;
|
||||||
|
|
||||||
rets[0] = returntype != nullptr? returntype : TypeError; // Use TypeError as placeholder if we do not know the return type yet.
|
if (returntype) rets.Push(returntype);
|
||||||
SetImplicitArgs(&args, &argflags, &argnames, containingclass, fflags, flags);
|
SetImplicitArgs(&args, &argflags, &argnames, containingclass, fflags, flags);
|
||||||
|
|
||||||
PFunction *sym = Create<PFunction>(containingclass, NAME_None); // anonymous functions do not have names.
|
PFunction *sym = Create<PFunction>(containingclass, NAME_None); // anonymous functions do not have names.
|
||||||
|
|
Loading…
Reference in a new issue