- Merge with 4.06 sources: Add another byte to source numbering so that

scripts that start on lines >32K still work.
- Fix is from fur


git-svn-id: svn://10.0.0.236/trunk@4275 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
mlm 1998-06-23 02:32:45 +00:00
parent 3a654f69c4
commit cbb79e399a
2 changed files with 38 additions and 25 deletions

View File

@ -458,8 +458,12 @@ js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn)
delta = lineno - cg->currentLine;
cg->currentLine = lineno;
if (delta) {
/* If delta requires too many SRC_NEWLINE notes, use SRC_SETLINE. */
if (delta >= (uintN)(2 + (lineno > SN_2BYTE_OFFSET_MASK))) {
/*
* Encode any change in the current source line number by using either
* several SRC_NEWLINE notes or one SRC_SETLINE note, whichever
* consumes less space.
*/
if (delta >= (uintN)(2 + ((lineno > SN_3BYTE_OFFSET_MASK) << 1))) {
if (js_NewSrcNote2(cx, cg, SRC_SETLINE, (ptrdiff_t)lineno) < 0)
return JS_FALSE;
} else {
@ -1978,8 +1982,8 @@ js_SrcNoteLength(jssrcnote *sn)
if (!arity)
return 1;
for (base = sn++; --arity >= 0; sn++) {
if (*sn & SN_2BYTE_OFFSET_FLAG)
sn++;
if (*sn & SN_3BYTE_OFFSET_FLAG)
sn +=2 ;
}
return sn - base;
}
@ -1991,11 +1995,11 @@ js_GetSrcNoteOffset(jssrcnote *sn, uintN which)
PR_ASSERT(SN_TYPE(sn) != SRC_XDELTA);
PR_ASSERT(which < js_SrcNoteArity[SN_TYPE(sn)]);
for (sn++; which; sn++, which--) {
if (*sn & SN_2BYTE_OFFSET_FLAG)
sn++;
if (*sn & SN_3BYTE_OFFSET_FLAG)
sn += 2;
}
if (*sn & SN_2BYTE_OFFSET_FLAG)
return (ptrdiff_t)((*sn & SN_2BYTE_OFFSET_MASK) << 8) | sn[1];
if (*sn & SN_3BYTE_OFFSET_FLAG)
return (ptrdiff_t)((((uint32)(*sn & SN_3BYTE_OFFSET_MASK)) << 16) | (sn[1] << 8) | sn[0]);
return (ptrdiff_t)*sn;
}
@ -2006,7 +2010,7 @@ js_SetSrcNoteOffset(JSContext *cx, JSCodeGenerator *cg, uintN index,
jssrcnote *sn;
ptrdiff_t diff;
if ((size_t)offset >= (size_t)(SN_2BYTE_OFFSET_FLAG << 8)) {
if (offset >= (((ptrdiff_t)SN_3BYTE_OFFSET_FLAG) << 16)) {
ReportStatementTooLarge(cx, cg);
return JS_FALSE;
}
@ -2016,26 +2020,35 @@ js_SetSrcNoteOffset(JSContext *cx, JSCodeGenerator *cg, uintN index,
PR_ASSERT(SN_TYPE(sn) != SRC_XDELTA);
PR_ASSERT(which < js_SrcNoteArity[SN_TYPE(sn)]);
for (sn++; which; sn++, which--) {
if (*sn & SN_2BYTE_OFFSET_FLAG)
sn++;
if (*sn & SN_3BYTE_OFFSET_FLAG)
sn += 2;
}
/* See if the new offset requires two bytes. */
if ((uintN)offset > (uintN)SN_2BYTE_OFFSET_MASK) {
/* Maybe this offset was already set to a two-byte value. */
if (!(*sn & SN_2BYTE_OFFSET_FLAG)) {
/* Losing, need to insert another byte for this offset. */
/* See if the new offset requires three bytes. */
if (offset > (ptrdiff_t)SN_3BYTE_OFFSET_MASK) {
/* Maybe this offset was already set to a three-byte value. */
if (!(*sn & SN_3BYTE_OFFSET_FLAG)) {
/* Losing, need to insert another two bytes for this offset. */
index = sn - cg->notes;
if (cg->noteCount++ % SNINCR == 0) {
cg->noteCount += 2;
/*
* Simultaneously test to see if the source note array must grow to
* accomodate either the first or second byte of additional storage
* required by this 3-byte offset.
*/
if ((cg->noteCount - 1) % SNINCR <= 1) {
if (!GrowSrcNotes(cx, cg))
return JS_FALSE;
sn = cg->notes + index;
}
diff = cg->noteCount - (index + 2);
}
diff = cg->noteCount - (index + 3);
PR_ASSERT(diff >= 0);
if (diff > 0)
memmove(sn + 2, sn + 1, diff * sizeof(jssrcnote));
memmove(sn + 3, sn + 1, diff * sizeof(jssrcnote));
}
*sn++ = (jssrcnote)(SN_2BYTE_OFFSET_FLAG | (offset >> 8));
*sn++ = (jssrcnote)(SN_3BYTE_OFFSET_FLAG | (offset >> 16));
*sn++ = (jssrcnote)(offset >> 8);
}
*sn = (jssrcnote)offset;
return JS_TRUE;

View File

@ -295,11 +295,11 @@ typedef enum JSSrcNoteType {
/*
* Offset fields follow certain notes and are frequency-encoded: an offset in
* [0,127] consumes one byte, an offset in [128,32767] takes two, and the high
* bit of the first byte is set.
* [0,0x7f] consumes one byte, an offset in [0x80,0x7fffff] takes three, and
* the high bit of the first byte is set.
*/
#define SN_2BYTE_OFFSET_FLAG 0x80
#define SN_2BYTE_OFFSET_MASK 0x7f
#define SN_3BYTE_OFFSET_FLAG 0x80
#define SN_3BYTE_OFFSET_MASK 0x7f
extern JS_FRIEND_DATA(const char *) js_SrcNoteName[];
extern JS_FRIEND_DATA(uint8) js_SrcNoteArity[];