2001-09-20 04:02:59 +04:00
|
|
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
1998-03-28 05:44:41 +03:00
|
|
|
*
|
2001-09-20 04:02:59 +04:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
1999-09-29 03:12:09 +04:00
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
2001-09-20 04:02:59 +04:00
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1998-03-28 05:44:41 +03:00
|
|
|
*
|
1999-09-29 03:12:09 +04:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
2001-09-20 04:02:59 +04:00
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
1999-09-29 03:12:09 +04:00
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1998-03-28 05:44:41 +03:00
|
|
|
*
|
2001-09-20 04:02:59 +04:00
|
|
|
* The Original Code is Mozilla Communicator client code, released
|
|
|
|
* March 31, 1998.
|
1999-09-29 03:12:09 +04:00
|
|
|
*
|
2001-09-20 04:02:59 +04:00
|
|
|
* The Initial Developer of the Original Code is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-09-29 03:12:09 +04:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
2001-09-20 04:02:59 +04:00
|
|
|
* Contributor(s):
|
1999-09-29 03:12:09 +04:00
|
|
|
*
|
2001-09-20 04:02:59 +04:00
|
|
|
* Alternatively, the contents of this file may be used under the
|
|
|
|
* terms of the GNU Public License (the "GPL"), in which case the
|
|
|
|
* provisions of the GPL are applicable instead of those above.
|
|
|
|
* If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of the GPL and not to allow others to use your
|
|
|
|
* version of this file under the NPL, indicate your decision by
|
|
|
|
* deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this
|
|
|
|
* file under either the NPL or the GPL.
|
|
|
|
*/
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
#ifndef jsemit_h___
|
|
|
|
#define jsemit_h___
|
|
|
|
/*
|
|
|
|
* JS bytecode generation.
|
|
|
|
*/
|
1998-06-10 03:04:48 +04:00
|
|
|
|
|
|
|
#include "jsstddef.h"
|
1998-10-14 14:22:38 +04:00
|
|
|
#include "jstypes.h"
|
1998-03-28 05:44:41 +03:00
|
|
|
#include "jsatom.h"
|
|
|
|
#include "jsopcode.h"
|
|
|
|
#include "jsprvtd.h"
|
|
|
|
#include "jspubtd.h"
|
|
|
|
|
1998-10-14 14:22:38 +04:00
|
|
|
JS_BEGIN_EXTERN_C
|
1998-03-28 05:44:41 +03:00
|
|
|
|
1998-04-24 04:31:11 +04:00
|
|
|
typedef enum JSStmtType {
|
1998-03-28 05:44:41 +03:00
|
|
|
STMT_BLOCK = 0, /* compound statement: { s1[;... sN] } */
|
1999-11-17 07:13:05 +03:00
|
|
|
STMT_LABEL = 1, /* labeled statement: L: s */
|
1998-03-28 05:44:41 +03:00
|
|
|
STMT_IF = 2, /* if (then) statement */
|
1999-11-17 07:13:05 +03:00
|
|
|
STMT_ELSE = 3, /* else clause of if statement */
|
1998-03-28 05:44:41 +03:00
|
|
|
STMT_SWITCH = 4, /* switch statement */
|
|
|
|
STMT_WITH = 5, /* with statement */
|
1999-11-17 07:13:05 +03:00
|
|
|
STMT_TRY = 6, /* try statement */
|
|
|
|
STMT_CATCH = 7, /* catch block */
|
|
|
|
STMT_FINALLY = 8, /* finally statement */
|
1998-04-24 04:31:11 +04:00
|
|
|
STMT_DO_LOOP = 9, /* do/while loop statement */
|
|
|
|
STMT_FOR_LOOP = 10, /* for loop statement */
|
|
|
|
STMT_FOR_IN_LOOP = 11, /* for/in loop statement */
|
|
|
|
STMT_WHILE_LOOP = 12 /* while loop statement */
|
|
|
|
} JSStmtType;
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
#define STMT_IS_LOOP(stmt) ((stmt)->type >= STMT_DO_LOOP)
|
|
|
|
|
1998-04-24 04:31:11 +04:00
|
|
|
typedef struct JSStmtInfo JSStmtInfo;
|
1998-03-28 05:44:41 +03:00
|
|
|
|
1998-04-24 04:31:11 +04:00
|
|
|
struct JSStmtInfo {
|
|
|
|
JSStmtType type; /* statement type */
|
|
|
|
ptrdiff_t top; /* offset of loop top from cg base */
|
|
|
|
ptrdiff_t update; /* loop update offset (top if none) */
|
|
|
|
ptrdiff_t breaks; /* offset of last break in loop */
|
|
|
|
ptrdiff_t continues; /* offset of last continue in loop */
|
2000-04-15 03:27:09 +04:00
|
|
|
ptrdiff_t gosub; /* offset of last GOSUB for this finally */
|
|
|
|
ptrdiff_t catchJump; /* offset of last end-of-catch jump */
|
2000-01-18 14:06:05 +03:00
|
|
|
JSAtom *label; /* name of LABEL or CATCH var */
|
1998-04-24 04:31:11 +04:00
|
|
|
JSStmtInfo *down; /* info for enclosing statement */
|
1998-03-28 05:44:41 +03:00
|
|
|
};
|
|
|
|
|
2000-04-15 03:27:09 +04:00
|
|
|
#define SET_STATEMENT_TOP(stmt, top) \
|
|
|
|
((stmt)->top = (stmt)->update = (top), (stmt)->breaks = \
|
|
|
|
(stmt)->continues = (stmt)->catchJump = (stmt)->gosub = (-1))
|
1998-03-28 05:44:41 +03:00
|
|
|
|
1998-04-24 04:31:11 +04:00
|
|
|
struct JSTreeContext { /* tree context for semantic checks */
|
|
|
|
uint32 flags; /* statement state flags, see below */
|
|
|
|
uint32 tryCount; /* total count of try statements parsed */
|
|
|
|
JSStmtInfo *topStmt; /* top of statement info stack */
|
2000-01-18 14:06:05 +03:00
|
|
|
JSAtomList decls; /* function, const, and var declarations */
|
2001-01-27 11:00:45 +03:00
|
|
|
JSParseNode *nodeList; /* list of recyclable parse-node structs */
|
1998-04-24 04:31:11 +04:00
|
|
|
};
|
|
|
|
|
2001-02-24 06:00:56 +03:00
|
|
|
#define TCF_COMPILING 0x01 /* generating bytecode; this tc is a cg */
|
|
|
|
#define TCF_IN_FUNCTION 0x02 /* parsing inside function body */
|
|
|
|
#define TCF_RETURN_EXPR 0x04 /* function has 'return expr;' */
|
|
|
|
#define TCF_RETURN_VOID 0x08 /* function has 'return;' */
|
|
|
|
#define TCF_IN_FOR_INIT 0x10 /* parsing init expr of for; exclude 'in' */
|
|
|
|
#define TCF_FUN_CLOSURE_VS_VAR 0x20 /* function and var with same name */
|
|
|
|
#define TCF_FUN_USES_NONLOCALS 0x40 /* function refers to non-local names */
|
|
|
|
#define TCF_FUN_HEAVYWEIGHT 0x80 /* function needs Call object per call */
|
|
|
|
#define TCF_FUN_FLAGS 0xE0 /* flags to propagate from FunctionBody */
|
1998-04-24 04:31:11 +04:00
|
|
|
|
1999-11-17 07:13:05 +03:00
|
|
|
#define TREE_CONTEXT_INIT(tc) \
|
2001-01-27 11:00:45 +03:00
|
|
|
((tc)->flags = 0, (tc)->tryCount = 0, (tc)->topStmt = NULL, \
|
|
|
|
ATOM_LIST_INIT(&(tc)->decls), (tc)->nodeList = NULL)
|
1999-11-12 09:03:40 +03:00
|
|
|
|
2001-01-27 11:00:45 +03:00
|
|
|
#define TREE_CONTEXT_FINISH(tc) \
|
1999-11-12 09:03:40 +03:00
|
|
|
((void)0)
|
1998-04-24 04:31:11 +04:00
|
|
|
|
1998-03-28 05:44:41 +03:00
|
|
|
struct JSCodeGenerator {
|
2001-01-27 11:00:45 +03:00
|
|
|
JSTreeContext treeContext; /* base state: statement info stack, etc. */
|
1998-04-24 04:31:11 +04:00
|
|
|
void *codeMark; /* low watermark in cx->codePool */
|
1999-11-12 09:03:40 +03:00
|
|
|
void *noteMark; /* low watermark in cx->notePool */
|
1998-04-24 04:31:11 +04:00
|
|
|
void *tempMark; /* low watermark in cx->tempPool */
|
1999-11-12 09:03:40 +03:00
|
|
|
struct {
|
|
|
|
jsbytecode *base; /* base of JS bytecode vector */
|
|
|
|
jsbytecode *limit; /* one byte beyond end of bytecode */
|
|
|
|
jsbytecode *next; /* pointer to next free bytecode */
|
|
|
|
} prolog, main, *current;
|
1998-10-14 14:22:38 +04:00
|
|
|
const char *filename; /* null or weak link to source filename */
|
|
|
|
uintN firstLine; /* first line, for js_NewScriptFromCG */
|
|
|
|
uintN currentLine; /* line number for tree-based srcnote gen */
|
|
|
|
JSPrincipals *principals; /* principals for constant folding eval */
|
1998-04-24 04:31:11 +04:00
|
|
|
JSAtomList atomList; /* literals indexed for mapping */
|
1999-11-17 07:13:05 +03:00
|
|
|
intN stackDepth; /* current stack depth in script frame */
|
1998-04-24 04:31:11 +04:00
|
|
|
uintN maxStackDepth; /* maximum stack depth so far */
|
|
|
|
jssrcnote *notes; /* source notes, see below */
|
|
|
|
uintN noteCount; /* number of source notes so far */
|
2001-01-27 11:00:45 +03:00
|
|
|
uintN noteMask; /* growth increment for notes */
|
1998-04-24 04:31:11 +04:00
|
|
|
ptrdiff_t lastNoteOffset; /* code offset for last source note */
|
1998-10-14 14:22:38 +04:00
|
|
|
JSTryNote *tryBase; /* first exception handling note */
|
|
|
|
JSTryNote *tryNext; /* next available note */
|
|
|
|
size_t tryNoteSpace; /* # of bytes allocated at tryBase */
|
1998-03-28 05:44:41 +03:00
|
|
|
};
|
|
|
|
|
1999-11-12 09:03:40 +03:00
|
|
|
#define CG_BASE(cg) ((cg)->current->base)
|
|
|
|
#define CG_LIMIT(cg) ((cg)->current->limit)
|
|
|
|
#define CG_NEXT(cg) ((cg)->current->next)
|
|
|
|
#define CG_CODE(cg,offset) (CG_BASE(cg) + (offset))
|
|
|
|
#define CG_OFFSET(cg) PTRDIFF(CG_NEXT(cg), CG_BASE(cg), jsbytecode)
|
|
|
|
|
|
|
|
#define CG_PROLOG_BASE(cg) ((cg)->prolog.base)
|
|
|
|
#define CG_PROLOG_LIMIT(cg) ((cg)->prolog.limit)
|
|
|
|
#define CG_PROLOG_NEXT(cg) ((cg)->prolog.next)
|
|
|
|
#define CG_PROLOG_CODE(cg,poff) (CG_PROLOG_BASE(cg) + (poff))
|
|
|
|
#define CG_PROLOG_OFFSET(cg) PTRDIFF(CG_PROLOG_NEXT(cg), CG_PROLOG_BASE(cg),\
|
|
|
|
jsbytecode)
|
|
|
|
|
|
|
|
#define CG_SWITCH_TO_MAIN(cg) ((cg)->current = &(cg)->main)
|
|
|
|
#define CG_SWITCH_TO_PROLOG(cg) ((cg)->current = &(cg)->prolog)
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
/*
|
1999-11-12 09:03:40 +03:00
|
|
|
* Initialize cg to allocate bytecode space from cx->codePool, source note
|
|
|
|
* space from cx->notePool, and all other arena-allocated temporaries from
|
|
|
|
* cx->tempPool. Return true on success. Report an error and return false
|
|
|
|
* if the initial code segment can't be allocated.
|
1998-03-28 05:44:41 +03:00
|
|
|
*/
|
|
|
|
extern JS_FRIEND_API(JSBool)
|
1998-04-24 04:31:11 +04:00
|
|
|
js_InitCodeGenerator(JSContext *cx, JSCodeGenerator *cg,
|
|
|
|
const char *filename, uintN lineno,
|
|
|
|
JSPrincipals *principals);
|
|
|
|
|
|
|
|
/*
|
1999-11-12 09:03:40 +03:00
|
|
|
* Release cx->codePool, cx->notePool, and cx->tempPool to marks set by
|
|
|
|
* js_InitCodeGenerator. Note that cgs are magic: they own the arena pool
|
|
|
|
* "tops-of-stack" space above their codeMark, noteMark, and tempMark points.
|
|
|
|
* This means you cannot alloc from tempPool and save the pointer beyond the
|
|
|
|
* next JS_FinishCodeGenerator.
|
1998-04-24 04:31:11 +04:00
|
|
|
*/
|
|
|
|
extern JS_FRIEND_API(void)
|
1998-10-14 14:22:38 +04:00
|
|
|
js_FinishCodeGenerator(JSContext *cx, JSCodeGenerator *cg);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Emit one bytecode.
|
|
|
|
*/
|
|
|
|
extern ptrdiff_t
|
|
|
|
js_Emit1(JSContext *cx, JSCodeGenerator *cg, JSOp op);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Emit two bytecodes, an opcode (op) with a byte of immediate operand (op1).
|
|
|
|
*/
|
|
|
|
extern ptrdiff_t
|
|
|
|
js_Emit2(JSContext *cx, JSCodeGenerator *cg, JSOp op, jsbytecode op1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Emit three bytecodes, an opcode with two bytes of immediate operands.
|
|
|
|
*/
|
|
|
|
extern ptrdiff_t
|
|
|
|
js_Emit3(JSContext *cx, JSCodeGenerator *cg, JSOp op, jsbytecode op1,
|
|
|
|
jsbytecode op2);
|
|
|
|
|
1998-04-24 04:31:11 +04:00
|
|
|
/*
|
|
|
|
* Emit (1 + extra) bytecodes, for N bytes of op and its immediate operand.
|
|
|
|
*/
|
|
|
|
extern ptrdiff_t
|
|
|
|
js_EmitN(JSContext *cx, JSCodeGenerator *cg, JSOp op, size_t extra);
|
|
|
|
|
1998-03-28 05:44:41 +03:00
|
|
|
/*
|
|
|
|
* Unsafe macro to call js_SetJumpOffset and return false if it does.
|
|
|
|
*/
|
|
|
|
#define CHECK_AND_SET_JUMP_OFFSET(cx,cg,pc,off) \
|
1998-10-14 14:22:38 +04:00
|
|
|
JS_BEGIN_MACRO \
|
1998-03-28 05:44:41 +03:00
|
|
|
if (!js_SetJumpOffset(cx, cg, pc, off)) \
|
|
|
|
return JS_FALSE; \
|
1998-10-14 14:22:38 +04:00
|
|
|
JS_END_MACRO
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
#define CHECK_AND_SET_JUMP_OFFSET_AT(cx,cg,off) \
|
|
|
|
CHECK_AND_SET_JUMP_OFFSET(cx, cg, CG_CODE(cg,off), CG_OFFSET(cg) - (off))
|
|
|
|
|
|
|
|
extern JSBool
|
|
|
|
js_SetJumpOffset(JSContext *cx, JSCodeGenerator *cg, jsbytecode *pc,
|
|
|
|
ptrdiff_t off);
|
|
|
|
|
2000-02-04 05:01:49 +03:00
|
|
|
/* Test whether we're in a with statement. */
|
|
|
|
extern JSBool
|
|
|
|
js_InWithStatement(JSTreeContext *tc);
|
|
|
|
|
|
|
|
/* Test whether we're in a catch block with exception named by atom. */
|
|
|
|
extern JSBool
|
|
|
|
js_InCatchBlock(JSTreeContext *tc, JSAtom *atom);
|
|
|
|
|
1998-03-28 05:44:41 +03:00
|
|
|
/*
|
1998-04-24 04:31:11 +04:00
|
|
|
* Push the C-stack-allocated struct at stmt onto the stmtInfo stack.
|
1998-03-28 05:44:41 +03:00
|
|
|
*/
|
|
|
|
extern void
|
1998-04-24 04:31:11 +04:00
|
|
|
js_PushStatement(JSTreeContext *tc, JSStmtInfo *stmt, JSStmtType type,
|
|
|
|
ptrdiff_t top);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
/*
|
1998-04-24 04:31:11 +04:00
|
|
|
* Emit a break instruction, recording it for backpatching.
|
1998-03-28 05:44:41 +03:00
|
|
|
*/
|
1998-04-24 04:31:11 +04:00
|
|
|
extern ptrdiff_t
|
|
|
|
js_EmitBreak(JSContext *cx, JSCodeGenerator *cg, JSStmtInfo *stmt,
|
|
|
|
JSAtomListElement *label);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
/*
|
1998-04-24 04:31:11 +04:00
|
|
|
* Emit a continue instruction, recording it for backpatching.
|
1998-03-28 05:44:41 +03:00
|
|
|
*/
|
|
|
|
extern ptrdiff_t
|
1998-04-24 04:31:11 +04:00
|
|
|
js_EmitContinue(JSContext *cx, JSCodeGenerator *cg, JSStmtInfo *stmt,
|
|
|
|
JSAtomListElement *label);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
/*
|
1998-04-24 04:31:11 +04:00
|
|
|
* Pop tc->topStmt. If the top JSStmtInfo struct is not stack-allocated, it
|
|
|
|
* is up to the caller to free it.
|
1998-03-28 05:44:41 +03:00
|
|
|
*/
|
|
|
|
extern void
|
1998-04-24 04:31:11 +04:00
|
|
|
js_PopStatement(JSTreeContext *tc);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
/*
|
1998-04-24 04:31:11 +04:00
|
|
|
* Like js_PopStatement(&cg->treeContext), also patch breaks and continues.
|
|
|
|
* May fail if a jump offset overflows.
|
1998-03-28 05:44:41 +03:00
|
|
|
*/
|
1998-04-24 04:31:11 +04:00
|
|
|
extern JSBool
|
|
|
|
js_PopStatementCG(JSContext *cx, JSCodeGenerator *cg);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
/*
|
1998-04-24 04:31:11 +04:00
|
|
|
* Emit code into cg for the tree rooted at pn.
|
1998-03-28 05:44:41 +03:00
|
|
|
*/
|
1998-04-24 04:31:11 +04:00
|
|
|
extern JSBool
|
|
|
|
js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
/*
|
1998-04-24 04:31:11 +04:00
|
|
|
* Emit code into cg for the tree rooted at body, then create a persistent
|
|
|
|
* script for fun from cg.
|
1998-03-28 05:44:41 +03:00
|
|
|
*/
|
|
|
|
extern JSBool
|
1998-04-24 04:31:11 +04:00
|
|
|
js_EmitFunctionBody(JSContext *cx, JSCodeGenerator *cg, JSParseNode *body,
|
|
|
|
JSFunction *fun);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Source notes generated along with bytecode for decompiling and debugging.
|
|
|
|
* A source note is a uint8 with 5 bits of type and 3 of offset from the pc of
|
|
|
|
* the previous note. If 3 bits of offset aren't enough, extended delta notes
|
2000-09-01 22:42:22 +04:00
|
|
|
* (SRC_XDELTA) consisting of 2 set high order bits followed by 6 offset bits
|
1998-03-28 05:44:41 +03:00
|
|
|
* are emitted before the next note. Some notes have operand offsets encoded
|
1998-10-14 14:22:38 +04:00
|
|
|
* immediately after them, in note bytes or byte-triples.
|
1998-03-28 05:44:41 +03:00
|
|
|
*
|
1999-11-12 09:03:40 +03:00
|
|
|
* Source Note Extended Delta
|
|
|
|
* +7-6-5-4-3+2-1-0+ +7-6-5+4-3-2-1-0+
|
2000-09-01 22:42:22 +04:00
|
|
|
* |note-type|delta| |1 1| ext-delta |
|
|
|
|
* +---------+-----+ +---+-----------+
|
1999-11-12 09:03:40 +03:00
|
|
|
*
|
1998-03-28 05:44:41 +03:00
|
|
|
* At most one "gettable" note (i.e., a note of type other than SRC_NEWLINE,
|
|
|
|
* SRC_SETLINE, and SRC_XDELTA) applies to a given bytecode.
|
|
|
|
*
|
|
|
|
* NB: the js_SrcNoteName and js_SrcNoteArity arrays in jsemit.c are indexed
|
|
|
|
* by this enum, so their initializers need to match the order here.
|
|
|
|
*/
|
|
|
|
typedef enum JSSrcNoteType {
|
|
|
|
SRC_NULL = 0, /* terminates a note vector */
|
|
|
|
SRC_IF = 1, /* JSOP_IFEQ bytecode is from an if-then */
|
|
|
|
SRC_IF_ELSE = 2, /* JSOP_IFEQ bytecode is from an if-then-else */
|
|
|
|
SRC_WHILE = 3, /* JSOP_IFEQ is from a while loop */
|
|
|
|
SRC_FOR = 4, /* JSOP_NOP or JSOP_POP in for loop head */
|
1998-10-14 14:22:38 +04:00
|
|
|
SRC_CONTINUE = 5, /* JSOP_GOTO is a continue, not a break;
|
|
|
|
also used on JSOP_ENDINIT if extra comma
|
|
|
|
at end of array literal: [1,2,,] */
|
1999-11-12 09:03:40 +03:00
|
|
|
SRC_VAR = 6, /* JSOP_NAME/SETNAME/FORNAME in a var decl */
|
1998-10-14 14:22:38 +04:00
|
|
|
SRC_PCDELTA = 7, /* offset from comma-operator to next POP,
|
|
|
|
or from CONDSWITCH to first CASE opcode */
|
1998-03-28 05:44:41 +03:00
|
|
|
SRC_ASSIGNOP = 8, /* += or another assign-op follows */
|
|
|
|
SRC_COND = 9, /* JSOP_IFEQ is from conditional ?: operator */
|
2000-06-08 10:46:18 +04:00
|
|
|
SRC_RESERVED0 = 10, /* reserved for future use */
|
1998-07-31 04:07:22 +04:00
|
|
|
SRC_HIDDEN = 11, /* opcode shouldn't be decompiled */
|
1998-03-28 05:44:41 +03:00
|
|
|
SRC_PCBASE = 12, /* offset of first obj.prop.subprop bytecode */
|
|
|
|
SRC_LABEL = 13, /* JSOP_NOP for label: with atomid immediate */
|
|
|
|
SRC_LABELBRACE = 14, /* JSOP_NOP for label: {...} begin brace */
|
|
|
|
SRC_ENDBRACE = 15, /* JSOP_NOP for label: {...} end brace */
|
|
|
|
SRC_BREAK2LABEL = 16, /* JSOP_GOTO for 'break label' with atomid */
|
|
|
|
SRC_CONT2LABEL = 17, /* JSOP_GOTO for 'continue label' with atomid */
|
1998-10-14 14:22:38 +04:00
|
|
|
SRC_SWITCH = 18, /* JSOP_*SWITCH with offset to end of switch,
|
|
|
|
2nd off to first JSOP_CASE if condswitch */
|
1998-04-24 04:31:11 +04:00
|
|
|
SRC_FUNCDEF = 19, /* JSOP_NOP for function f() with atomid */
|
2000-09-01 22:42:22 +04:00
|
|
|
SRC_CATCH = 20, /* catch block has guard */
|
|
|
|
SRC_CONST = 21, /* JSOP_SETCONST in a const decl */
|
|
|
|
SRC_NEWLINE = 22, /* bytecode follows a source newline */
|
|
|
|
SRC_SETLINE = 23, /* a file-absolute source line number note */
|
|
|
|
SRC_XDELTA = 24 /* 24-31 are for extended delta notes */
|
1998-03-28 05:44:41 +03:00
|
|
|
} JSSrcNoteType;
|
|
|
|
|
|
|
|
#define SN_TYPE_BITS 5
|
|
|
|
#define SN_DELTA_BITS 3
|
2000-09-01 22:42:22 +04:00
|
|
|
#define SN_XDELTA_BITS 6
|
1998-10-14 14:22:38 +04:00
|
|
|
#define SN_TYPE_MASK (JS_BITMASK(SN_TYPE_BITS) << SN_DELTA_BITS)
|
|
|
|
#define SN_DELTA_MASK ((ptrdiff_t)JS_BITMASK(SN_DELTA_BITS))
|
|
|
|
#define SN_XDELTA_MASK ((ptrdiff_t)JS_BITMASK(SN_XDELTA_BITS))
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
#define SN_MAKE_NOTE(sn,t,d) (*(sn) = (jssrcnote) \
|
|
|
|
(((t) << SN_DELTA_BITS) \
|
|
|
|
| ((d) & SN_DELTA_MASK)))
|
|
|
|
#define SN_MAKE_XDELTA(sn,d) (*(sn) = (jssrcnote) \
|
|
|
|
((SRC_XDELTA << SN_DELTA_BITS) \
|
|
|
|
| ((d) & SN_XDELTA_MASK)))
|
|
|
|
|
|
|
|
#define SN_IS_XDELTA(sn) ((*(sn) >> SN_DELTA_BITS) >= SRC_XDELTA)
|
|
|
|
#define SN_TYPE(sn) (SN_IS_XDELTA(sn) ? SRC_XDELTA \
|
|
|
|
: *(sn) >> SN_DELTA_BITS)
|
|
|
|
#define SN_SET_TYPE(sn,type) SN_MAKE_NOTE(sn, type, SN_DELTA(sn))
|
|
|
|
#define SN_IS_GETTABLE(sn) (SN_TYPE(sn) < SRC_NEWLINE)
|
|
|
|
|
|
|
|
#define SN_DELTA(sn) ((ptrdiff_t)(SN_IS_XDELTA(sn) \
|
|
|
|
? *(sn) & SN_XDELTA_MASK \
|
|
|
|
: *(sn) & SN_DELTA_MASK))
|
|
|
|
#define SN_SET_DELTA(sn,delta) (SN_IS_XDELTA(sn) \
|
|
|
|
? SN_MAKE_XDELTA(sn, delta) \
|
|
|
|
: SN_MAKE_NOTE(sn, SN_TYPE(sn), delta))
|
|
|
|
|
1998-10-14 14:22:38 +04:00
|
|
|
#define SN_DELTA_LIMIT ((ptrdiff_t)JS_BIT(SN_DELTA_BITS))
|
|
|
|
#define SN_XDELTA_LIMIT ((ptrdiff_t)JS_BIT(SN_XDELTA_BITS))
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Offset fields follow certain notes and are frequency-encoded: an offset in
|
1998-07-31 04:07:22 +04:00
|
|
|
* [0,0x7f] consumes one byte, an offset in [0x80,0x7fffff] takes three, and
|
|
|
|
* the high bit of the first byte is set.
|
1998-03-28 05:44:41 +03:00
|
|
|
*/
|
1998-07-31 04:07:22 +04:00
|
|
|
#define SN_3BYTE_OFFSET_FLAG 0x80
|
|
|
|
#define SN_3BYTE_OFFSET_MASK 0x7f
|
1998-03-28 05:44:41 +03:00
|
|
|
|
1998-04-24 04:31:11 +04:00
|
|
|
extern JS_FRIEND_DATA(const char *) js_SrcNoteName[];
|
1999-11-12 09:03:40 +03:00
|
|
|
extern JS_FRIEND_DATA(uint8) js_SrcNoteArity[];
|
|
|
|
extern JS_FRIEND_API(uintN) js_SrcNoteLength(jssrcnote *sn);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
#define SN_LENGTH(sn) ((js_SrcNoteArity[SN_TYPE(sn)] == 0) ? 1 \
|
|
|
|
: js_SrcNoteLength(sn))
|
|
|
|
#define SN_NEXT(sn) ((sn) + SN_LENGTH(sn))
|
|
|
|
|
|
|
|
/* A source note array is terminated by an all-zero element. */
|
|
|
|
#define SN_MAKE_TERMINATOR(sn) (*(sn) = SRC_NULL)
|
|
|
|
#define SN_IS_TERMINATOR(sn) (*(sn) == SRC_NULL)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Append a new source note of the given type (and therefore size) to cg's
|
|
|
|
* notes dynamic array, updating cg->noteCount. Return the new note's index
|
|
|
|
* within the array pointed at by cg->notes. Return -1 if out of memory.
|
|
|
|
*/
|
|
|
|
extern intN
|
|
|
|
js_NewSrcNote(JSContext *cx, JSCodeGenerator *cg, JSSrcNoteType type);
|
|
|
|
|
|
|
|
extern intN
|
|
|
|
js_NewSrcNote2(JSContext *cx, JSCodeGenerator *cg, JSSrcNoteType type,
|
|
|
|
ptrdiff_t offset);
|
|
|
|
|
|
|
|
extern intN
|
|
|
|
js_NewSrcNote3(JSContext *cx, JSCodeGenerator *cg, JSSrcNoteType type,
|
|
|
|
ptrdiff_t offset1, ptrdiff_t offset2);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get and set the offset operand identified by which (0 for the first, etc.).
|
|
|
|
*/
|
1998-04-24 04:31:11 +04:00
|
|
|
extern JS_FRIEND_API(ptrdiff_t)
|
1998-03-28 05:44:41 +03:00
|
|
|
js_GetSrcNoteOffset(jssrcnote *sn, uintN which);
|
|
|
|
|
|
|
|
extern JSBool
|
|
|
|
js_SetSrcNoteOffset(JSContext *cx, JSCodeGenerator *cg, uintN index,
|
|
|
|
uintN which, ptrdiff_t offset);
|
|
|
|
|
|
|
|
/*
|
1999-11-12 09:03:40 +03:00
|
|
|
* Finish taking source notes in cx's notePool by copying them to new
|
1998-04-24 04:31:11 +04:00
|
|
|
* stable store allocated via JS_malloc. Return null on malloc failure,
|
|
|
|
* which means this function reported an error.
|
|
|
|
*/
|
1998-10-14 14:22:38 +04:00
|
|
|
extern jssrcnote *
|
1998-04-24 04:31:11 +04:00
|
|
|
js_FinishTakingSrcNotes(JSContext *cx, JSCodeGenerator *cg);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate cg->treeContext.tryCount notes (plus one for the end sentinel)
|
1998-10-14 14:22:38 +04:00
|
|
|
* from cx->tempPool and set up cg->tryBase/tryNext for exactly tryCount
|
|
|
|
* js_NewTryNote calls. The storage is freed by js_FinishCodeGenerator.
|
1998-03-28 05:44:41 +03:00
|
|
|
*/
|
|
|
|
extern JSBool
|
1998-04-24 04:31:11 +04:00
|
|
|
js_AllocTryNotes(JSContext *cx, JSCodeGenerator *cg);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
/*
|
1998-04-24 04:31:11 +04:00
|
|
|
* Grab the next trynote slot in cg, filling it in appropriately.
|
1998-03-28 05:44:41 +03:00
|
|
|
*/
|
1998-10-14 14:22:38 +04:00
|
|
|
extern JSTryNote *
|
1998-04-24 04:31:11 +04:00
|
|
|
js_NewTryNote(JSContext *cx, JSCodeGenerator *cg, ptrdiff_t start,
|
1998-07-31 04:07:22 +04:00
|
|
|
ptrdiff_t end, ptrdiff_t catchStart);
|
1998-04-24 04:31:11 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Finish generating exception information, and copy it to JS_malloc
|
|
|
|
* storage.
|
|
|
|
*/
|
1998-10-14 14:22:38 +04:00
|
|
|
extern JSBool
|
1998-04-24 04:31:11 +04:00
|
|
|
js_FinishTakingTryNotes(JSContext *cx, JSCodeGenerator *cg, JSTryNote **tryp);
|
1998-03-28 05:44:41 +03:00
|
|
|
|
1998-10-14 14:22:38 +04:00
|
|
|
JS_END_EXTERN_C
|
1998-03-28 05:44:41 +03:00
|
|
|
|
|
|
|
#endif /* jsemit_h___ */
|