Leopold Toetsch via RT wrote:
Yes, I was planning to do something a bit more thorough, but fixing the immediate segfault was the first challenge.Nick Glencross <[EMAIL PROTECTED]> wrote:
This patch fixes a problem which can occur in this example:
.sub test
.const float a = 12
print a
print_newline
.end
Ah yep.
+ if (t != 'P' && t != val->set)
+ IMCC_fataly(interp, E_TypeError,
+ "const types do not match");
I think, we could be a bit more graceful here for I/N mismatch and set
for the above case the constant val->set to 'N'.
I've looked over the code a bit more now, and see that the value is still stored textually at this point, so setting the type as you've said is pretty simple. It's a shame that strings can be in a number of different formats, and probably quoted, preventing this from working for them too.
Anyhow, here's a new patch for you to review, and perhaps apply...?
Cheers,
Nick
Index: imcc/symreg.c =================================================================== --- imcc/symreg.c (revision 7843) +++ imcc/symreg.c (working copy) @@ -307,6 +307,7 @@ INS(interp, unit, "set_p_pc", "", r, 2, 0, 1); return NULL; } + /* Makes a new identifier constant with value val */ SymReg * mk_const_ident(Interp *interp, @@ -314,6 +315,16 @@ { SymReg *r; + // Forbid assigning a string to anything other than a string const + // for now + if (t != 'S' && val->set == 'S') + IMCC_fataly(interp, E_TypeError, + "bad const initialisation"); + + // Cast value to const type + if (t == 'S' || t == 'I') + val->set = t; + if (global) { if (t == 'P') { IMCC_fataly(interp, E_SyntaxError,