Skip to content

Commit

Permalink
assert() + Panic() + Trap() revamp for standardized debug build
Browse files Browse the repository at this point in the history
  • Loading branch information
hostilefork committed Jul 7, 2015
1 parent 11f0db3 commit f12ba40
Show file tree
Hide file tree
Showing 85 changed files with 1,071 additions and 938 deletions.
1 change: 1 addition & 0 deletions src/boot/errors.r
Expand Up @@ -227,6 +227,7 @@ User: [
Internal: [
code: 900
type: "internal error"
misc: [{miscellaneous error (add specific case to errors.r)}]
bad-path: [{bad path:} arg1]
not-here: [arg1 {not supported on your system}]
no-memory: {not enough memory}
Expand Down
3 changes: 1 addition & 2 deletions src/core/a-constants.c
Expand Up @@ -42,11 +42,10 @@ const REBYTE * Str_Stack_Misaligned = {
BP("!! Stack misaligned: %d")
};

const REBYTE * const Crash_Msgs[] = {
const REBYTE * const Panic_Msgs[] = {
BP"REBOL System Error",
BP"boot failure",
BP"internal problem",
BP"assertion failed",
BP"invalid datatype %d",
BP"unspecific",
BP"\n\nProgram terminated abnormally.\nThis should never happen.\nPlease contact www.REBOL.com with details."
Expand Down
2 changes: 1 addition & 1 deletion src/core/a-lib.c
Expand Up @@ -948,7 +948,7 @@ RL_API int RL_Set_Field(REBSER *obj, u32 word, RXIARG val, int type)
{
REBVAL value = {0};
if (!(word = Find_Word_Index(obj, word, FALSE))) return 0;
if (VAL_PROTECTED(FRM_WORDS(obj)+word)) return 0; // Trap1(RE_LOCKED_WORD, word);
if (VAL_PROTECTED(FRM_WORDS(obj)+word)) return 0; // Trap1_DEAD_END(RE_LOCKED_WORD, word);
RXI_To_Value(FRM_VALUES(obj)+word, val, type);
return type;
}
Expand Down
38 changes: 22 additions & 16 deletions src/core/b-init.c
Expand Up @@ -95,15 +95,15 @@ extern const REBYTE Str_Banner[];
printf("%d %s\n", sizeof(REBALL), "all");
#endif

ASSERT(VAL_TYPE(&val) == 123, RP_REBVAL_ALIGNMENT);
if (VAL_TYPE(&val) != 123) Panic(RP_REBVAL_ALIGNMENT);
if (sizeof(void *) == 8) {
ASSERT(sizeof(REBVAL) == 32, RP_REBVAL_ALIGNMENT);
ASSERT1(sizeof(REBGOB) == 84, RP_BAD_SIZE);
if (sizeof(REBVAL) != 32) Panic(RP_REBVAL_ALIGNMENT);
if (sizeof(REBGOB) != 84) Panic(RP_BAD_SIZE);
} else {
ASSERT(sizeof(REBVAL) == 16, RP_REBVAL_ALIGNMENT);
ASSERT1(sizeof(REBGOB) == 64, RP_BAD_SIZE);
if (sizeof(REBVAL) != 16) Panic(RP_REBVAL_ALIGNMENT);
if (sizeof(REBGOB) != 64) Panic(RP_BAD_SIZE);
}
ASSERT1(sizeof(REBDAT) == 4, RP_BAD_SIZE);
if (sizeof(REBDAT) != 4) Panic(RP_BAD_SIZE);
}


Expand Down Expand Up @@ -173,7 +173,7 @@ extern const REBYTE Str_Banner[];

textlen = Bytes_To_REBCNT(Native_Specs);
text = Decompress(&spec, 0, -1, textlen, 0);
if (!text || (STR_LEN(text) != textlen)) Crash(RP_BOOT_DATA);
if (!text || (STR_LEN(text) != textlen)) Panic(RP_BOOT_DATA);
boot = Scan_Source(STR_HEAD(text), textlen);
//Dump_Block_Raw(boot, 0, 2);
Free_Series(text);
Expand All @@ -183,8 +183,10 @@ extern const REBYTE Str_Banner[];

Boot_Block = (BOOT_BLK *)VAL_BLK(BLK_HEAD(boot));

ASSERT(VAL_TAIL(&Boot_Block->types) == REB_MAX, RP_BAD_BOOT_TYPE_BLOCK);
ASSERT(VAL_WORD_SYM(VAL_BLK(&Boot_Block->types)) == SYM_END_TYPE, RP_BAD_END_TYPE_WORD);
if (VAL_TAIL(&Boot_Block->types) != REB_MAX)
Panic(RP_BAD_BOOT_TYPE_BLOCK);
if (VAL_WORD_SYM(VAL_BLK(&Boot_Block->types)) != SYM_END_TYPE)
Panic(RP_BAD_END_TYPE_WORD);

// Create low-level string pointers (used by RS_ constants):
{
Expand All @@ -200,9 +202,12 @@ extern const REBYTE Str_Banner[];
}
}

ASSERT(!strcmp("end!", Get_Sym_Name(SYM_END_TYPE)), RP_BAD_END_CANON_WORD);
ASSERT(!strcmp("true", Get_Sym_Name(SYM_TRUE)), RP_BAD_TRUE_CANON_WORD);
ASSERT(!strcmp("line", BOOT_STR(RS_SCAN,1)), RP_BAD_BOOT_STRING);
if (strcmp("end!", Get_Sym_Name(SYM_END_TYPE)) != 0)
Panic(RP_BAD_END_CANON_WORD);
if (strcmp("true", Get_Sym_Name(SYM_TRUE)) != 0)
Panic(RP_BAD_TRUE_CANON_WORD);
if (strcmp("line", BOOT_STR(RS_SCAN,1)) != 0)
Panic(RP_BAD_BOOT_STRING);
}


Expand Down Expand Up @@ -314,7 +319,7 @@ extern const REBYTE Str_Banner[];
{
if ((Native_Limit == 0 && *Native_Functions) || (Native_Count < Native_Limit))
Make_Native(ds, VAL_SERIES(D_ARG(1)), *Native_Functions++, REB_NATIVE);
else Trap0(RE_MAX_NATIVES);
else Trap_DEAD_END(RE_MAX_NATIVES);
Native_Count++;
return R_RET;
}
Expand All @@ -327,7 +332,7 @@ extern const REBYTE Str_Banner[];
***********************************************************************/
{
Action_Count++;
if (Action_Count >= A_MAX_ACTION) Crash(RP_ACTION_OVERFLOW);
if (Action_Count >= A_MAX_ACTION) Panic_DEAD_END(RP_ACTION_OVERFLOW);
Make_Native(ds, VAL_SERIES(D_ARG(1)), (REBFUN)(REBUPT)Action_Count, REB_ACTION);
return R_RET;
}
Expand Down Expand Up @@ -366,7 +371,7 @@ extern const REBYTE Str_Banner[];
val = Append_Frame(Lib_Context, word, 0);
// Find the related function:
func = Find_Word_Value(Lib_Context, VAL_WORD_SYM(word+1));
if (!func) Crash(9912);
if (!func) Panic(RP_MISC);
*val = *func;
VAL_SET(val, REB_OP);
VAL_SET_EXT(val, VAL_TYPE(func));
Expand All @@ -391,7 +396,8 @@ extern const REBYTE Str_Banner[];
// Construct the first native, which is the NATIVE function creator itself:
// native: native [spec [block!]]
word = VAL_BLK_SKIP(&Boot_Block->booters, 1);
ASSERT2(IS_SET_WORD(word) && VAL_WORD_SYM(word) == SYM_NATIVE, RE_NATIVE_BOOT);
if (!IS_SET_WORD(word) || VAL_WORD_SYM(word) != SYM_NATIVE)
Panic(RE_NATIVE_BOOT);
//val = BLK_SKIP(Sys_Context, SYS_CTX_NATIVE);
val = Append_Frame(Lib_Context, word, 0);
Make_Native(val, VAL_SERIES(word+2), Native_Functions[0], REB_NATIVE);
Expand Down

0 comments on commit f12ba40

Please sign in to comment.