Skip to content

Commit

Permalink
Earlier debug initialisation, and remove an ancient check for a bug I…
Browse files Browse the repository at this point in the history
… now understand (namely variables being assigned to address 0 when they only exist in a single compiler pass).
  • Loading branch information
Alex Cole committed Oct 16, 2023
1 parent 27c12e2 commit 28c1f02
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 99 deletions.
96 changes: 2 additions & 94 deletions YSI_Core/y_core/y_debug_impl.inc
Original file line number Diff line number Diff line change
Expand Up @@ -700,74 +700,6 @@ stock Debug_PrintArray(arr[], size = sizeof (arr))
return str;
}

/*-------------------------------------------------------------------------*//**
* <library>y_debug</library>
* <remarks>
* Does some strange mangling of <c>YSI_FILTERSCRIPT</c> because at one point
* I found a compiler bug where the first automata in the script could
* conflict with the first variable in the script. I don't know what
* triggered it, and it has never shown up since I messed about with this file
* to try mangle some things. Never the less, if it ever happens again this
* code might detect it. Actually, that's less likely now, since that
* variable is now very unlikely to be the first in the script ever.
* </remarks>
*//*------------------------------------------------------------------------**/

public OnCodeInit()
{
Debug_SetState();
new
s = 0;
// Test the ADDRESS of the variable, not the value.
#emit CONST.pri @_
#emit STOR.S.pri s
if (s)
{
//goto Debug_OnCodeInit_no_fault();
#if defined Debug_OnCodeInit
return Debug_OnCodeInit();
#else
return 1;
#endif
}
Debug_Fatal("@_ == 0");
while (s != 10000000) ++s;
#emit CONST.pri 0
#emit SCTRL __cip
return 1;
}

#undef OnCodeInit
#define OnCodeInit Debug_OnCodeInit
#if defined Debug_OnCodeInit
forward Debug_OnCodeInit();
#endif

/*-------------------------------------------------------------------------*//**
* <library>y_debug</library>
* <transition keep="true" target="ysi_debug : on" source="ysi_debug : "/>
* <remarks>
* Mostly exists to define the full range of <c>ysi_debug</c> states.
* </remarks>
*//*------------------------------------------------------------------------**/

static stock Debug_SetState() <ysi_debug : off>
{
}

/*-------------------------------------------------------------------------*//**
* <library>y_debug</library>
* <transition keep="true" target="ysi_debug : on" source="ysi_debug : "/>
* <remarks>
* Mostly exists to define the full range of <c>ysi_debug</c> states.
* </remarks>
*//*------------------------------------------------------------------------**/

static stock Debug_SetState() <>
{
state ysi_debug : on;
}

/*-------------------------------------------------------------------------*//**
* <library>y_debug</library>
* <transition keep="true" target="ysi_debug : on" source="ysi_debug : "/>
Expand Down Expand Up @@ -801,44 +733,20 @@ stock bool:Debug_GetState() <>
* </remarks>
*//*------------------------------------------------------------------------**/

stock bool:Debug_Enable() <ysi_debug : off>
stock bool:Debug_Enable()
{
state ysi_debug : on;
return true;
}

/*-------------------------------------------------------------------------*//**
* <library>y_debug</library>
* <remarks>
* Turn on level 0 prints.
* </remarks>
*//*------------------------------------------------------------------------**/

stock bool:Debug_Enable() <>
{
return false;
}

/*-------------------------------------------------------------------------*//**
* <library>y_debug</library>
* <remarks>
* Turn off level 0 prints.
* </remarks>
*//*------------------------------------------------------------------------**/

stock bool:Debug_Disable() <ysi_debug : off>
{
return false;
}

/*-------------------------------------------------------------------------*//**
* <library>y_debug</library>
* <remarks>
* Turn off level 0 prints.
* </remarks>
*//*------------------------------------------------------------------------**/

stock bool:Debug_Disable() <>
stock bool:Debug_Disable()
{
state ysi_debug : off;
return true;
Expand Down
14 changes: 10 additions & 4 deletions YSI_Core/y_core/y_scriptinit_impl.inc
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ static stock const
*/
YSI_gscPostInitFile[] = "post-init";

native Debug_PrintF__(const fmat[], arg) = printf;
native ScriptInit_PrintF__(const fmat[], arg) = printf;

static stock
/**
Expand Down Expand Up @@ -1023,7 +1023,7 @@ stock Server_PrintIntroMessage(...)
#emit ADD
#emit LOAD.I
#emit STOR.S.pri a
Debug_PrintF__(YSI_gsc38, a);
ScriptInit_PrintF__(YSI_gsc38, a);
}
// Footer.
YSI_Print__(YSI_gscSpacer);
Expand Down Expand Up @@ -1078,7 +1078,7 @@ stock Server_PrintIntroPart(...)
#emit ADD
#emit LOAD.I
#emit STOR.S.pri a
Debug_PrintF__(YSI_gsc38, a);
ScriptInit_PrintF__(YSI_gsc38, a);
}
}

Expand Down Expand Up @@ -1235,6 +1235,7 @@ stock Server_GetLongCallDefault()

static bool:ScriptInit_CallOnCodeInit(bool:jit, bool:fs)
{
Debug_Enable();
#if defined _DEBUG
#if _DEBUG > 0
new preHeap, postHeap;
Expand All @@ -1244,7 +1245,9 @@ static bool:ScriptInit_CallOnCodeInit(bool:jit, bool:fs)
{
#if _YSI_SAFE_STARTUP
#if __debug <= 0
YSI_PrintF__("YSI v%02d.%02d.%04d", YSI_VERSION_MAJOR, YSI_VERSION_MINOR, YSI_VERSION_BUILD);
printf("A");
Debug_Info("Version: %02d.%02d.%04d", YSI_VERSION_MAJOR, YSI_VERSION_MINOR, YSI_VERSION_BUILD);
printf("B");
#endif
#else
YSI_PrintF__("Unsafe YSI signed by: %s", YSI_gcUnsafeStartupContract);
Expand Down Expand Up @@ -2151,6 +2154,9 @@ stock bool:Server_UpgradeCrashDetect()
return false;
}

// Don't let anyone else call this function.
#define ScriptInit_PrintF__ ScriptInit_PrintF

#if __COMPILER___EMIT_U
#endinput
#endif
Expand Down
2 changes: 1 addition & 1 deletion YSI_Core/y_master/y_master_once.inc
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ public OnYSIInit()
new
masters = getproperty(8, YSIM_MASTER) | getproperty(5, YSI_FIXES_gscSingleProperty);
@_ = Cell_GetLowestEmpty(masters);
Debug_Info("YSI Script ID: %d", @_);
Debug_Info("Script ID: %d", @_);
setproperty(8, YSIM_MASTER, masters | Master_ID());
Debug_Code1{if (!Master_ID()) Debug_Error("MasterID not assigned");}
#if !defined YSI_NO_MASTER
Expand Down

0 comments on commit 28c1f02

Please sign in to comment.