Switching to new parameterslots scheme.

This commit is contained in:
rogerl%netscape.com 2003-06-11 22:04:34 +00:00
Родитель 97fe36ece7
Коммит 0fbd149ac2
17 изменённых файлов: 88 добавлений и 48 удалений

Просмотреть файл

@ -41,14 +41,11 @@
#include <assert.h>
#include <list>
#include <stack>
#include <map>
#include "world.h"
#include "utilities.h"
#include "js2value.h"
#include <map>
#include <algorithm>
#include "strings.h"
#include "reader.h"
#include "parser.h"

Просмотреть файл

@ -29,17 +29,14 @@
#include <algorithm>
#include <assert.h>
#include <list>
#include <stack>
#include <map>
#include "world.h"
#include "strings.h"
#include "utilities.h"
#include "js2value.h"
#include <map>
#include <algorithm>
#include <list>
#include <stack>
#include "reader.h"
#include "parser.h"
#include "js2engine.h"

Просмотреть файл

@ -32,6 +32,12 @@
*/
#include <cstdio>
#include <vector>
#include "systemtypes.h"
#include "js2value.h"
#include "strings.h"
#include "exception.h"
namespace JS = JavaScript;

Просмотреть файл

@ -34,10 +34,6 @@
#ifndef exception_h___
#define exception_h___
#include "systemtypes.h"
#include "js2value.h"
#include "strings.h"
namespace JavaScript
{

Просмотреть файл

@ -67,7 +67,7 @@ namespace MetaData {
js2val JS2Engine::interpret(Phase execPhase, BytecodeContainer *targetbCon, Environment *env)
{
packageFrame = env->getPackageFrame();
jsr(execPhase, targetbCon, sp - execStack, JS2VAL_VOID, env, NULL);
jsr(execPhase, targetbCon, sp - execStack, JS2VAL_VOID, env);
ActivationFrame *f = activationStackTop;
js2val result;
try {
@ -154,6 +154,7 @@ namespace MetaData {
curAct = --activationStackTop;
localFrame = activationStackTop->localFrame;
parameterFrame = activationStackTop->parameterFrame;
parameterSlots = activationStackTop->parameterSlots;
bCon = activationStackTop->bCon;
if (hndlr->mActivation != curAct) {
while (activationStackTop->newEnv->getTopFrame() != activationStackTop->topFrame)
@ -167,6 +168,7 @@ namespace MetaData {
// be at the top, because of postincrement
localFrame = activationStackTop->localFrame;
parameterFrame = activationStackTop->parameterFrame;
parameterSlots = activationStackTop->parameterSlots;
bCon = activationStackTop->bCon;
meta->env = activationStackTop->env;
}
@ -502,6 +504,7 @@ namespace MetaData {
packageFrame(NULL),
parameterFrame(NULL),
localFrame(NULL),
parameterSlots(NULL),
traceInstructions(false)
{
for (int i = 0; i < 256; i++)
@ -1028,7 +1031,7 @@ namespace MetaData {
// Save current engine state (pc, environment top) and
// jump to start of new bytecodeContainer
void JS2Engine::jsr(Phase execPhase, BytecodeContainer *new_bCon, uint32 stackBase, js2val returnVal, Environment *env, ParameterFrame *pFrame)
void JS2Engine::jsr(Phase execPhase, BytecodeContainer *new_bCon, uint32 stackBase, js2val returnVal, Environment *env)
{
if (activationStackTop >= (activationStack + MAX_ACTIVATION_STACK))
meta->reportError(Exception::internalError, "out of activation stack", meta->engine->errorPos());
@ -1042,6 +1045,7 @@ namespace MetaData {
activationStackTop->topFrame = env->getTopFrame(); // remember how big the new env. is supposed to be so that local frames don't accumulate
activationStackTop->localFrame = localFrame;
activationStackTop->parameterFrame = parameterFrame;
activationStackTop->parameterSlots = parameterSlots;
// if (pFrame && pFrame->)
activationStackTop++;
if (new_bCon) {
@ -1073,6 +1077,7 @@ namespace MetaData {
phase = activationStackTop->phase;
localFrame = activationStackTop->localFrame;
parameterFrame = activationStackTop->parameterFrame;
parameterSlots = activationStackTop->parameterSlots;
// reset the env. top
while (activationStackTop->newEnv->getTopFrame() != activationStackTop->topFrame)
activationStackTop->newEnv->removeTopFrame();
@ -1089,6 +1094,7 @@ namespace MetaData {
// and in structures contained in those locations.
void JS2Engine::mark()
{
uint32 i;
if (bCon)
bCon->mark();
for (ActivationFrame *f = activationStack; (f < activationStackTop); f++) {
@ -1103,10 +1109,15 @@ namespace MetaData {
JS2Object::mark(JS2VAL_TO_DOUBLE(nanValue));
JS2Object::mark(JS2VAL_TO_DOUBLE(posInfValue));
JS2Object::mark(JS2VAL_TO_DOUBLE(negInfValue));
for (uint32 i = 0; i < 256; i++) {
for (i = 0; i < 256; i++) {
if (float64Table[i])
JS2Object::mark(float64Table[i]);
}
if (parameterSlots) {
for (i = 0; i < parameterSlots->size(); i++) {
GCMARKVALUE((*parameterSlots)[i]);
}
}
GCMARKVALUE(retval);
}

Просмотреть файл

@ -312,8 +312,9 @@ public:
Frame *topFrame;
NonWithFrame *localFrame;
ParameterFrame *parameterFrame;
ValueList *parameterSlots;
};
void jsr(Phase execPhase, BytecodeContainer *bCon, uint32 stackBase, js2val returnVal, Environment *env, ParameterFrame *pFrame);
void jsr(Phase execPhase, BytecodeContainer *bCon, uint32 stackBase, js2val returnVal, Environment *env);
bool activationStackEmpty() { return (activationStackTop == activationStack); }
void rts();
ActivationFrame *activationStack;
@ -364,6 +365,7 @@ public:
NonWithFrame *packageFrame;
ParameterFrame *parameterFrame;
NonWithFrame *localFrame;
ValueList *parameterSlots;
void pushHandler(uint8 *pc);
void popHandler();

Просмотреть файл

@ -331,10 +331,12 @@ namespace MetaData {
fWrap->env->addFrame(objectType(thisValue));
fWrap->env->addFrame(runtimeFrame);
ParameterFrame *oldPFrame = engine->parameterFrame;
ValueList *oldPSlots = engine->parameterSlots;
try {
savePC = engine->pc;
engine->pc = NULL;
engine->parameterFrame = runtimeFrame;
engine->parameterSlots = runtimeFrame->frameSlots;
result = engine->interpret(RunPhase, bCon, fWrap->env);
}
catch (Exception &x) {
@ -342,12 +344,14 @@ namespace MetaData {
restoreCompilationUnit(oldData);
fWrap->env->setTopFrame(oldTopFrame);
engine->parameterFrame = oldPFrame;
engine->parameterSlots = oldPSlots;
throw x;
}
engine->pc = savePC;
restoreCompilationUnit(oldData);
fWrap->env->setTopFrame(oldTopFrame);
engine->parameterFrame = oldPFrame;
engine->parameterSlots = oldPSlots;
}
}
return result;

Просмотреть файл

@ -3593,7 +3593,7 @@ rescan:
return argv[0];
// need to reset the environment to the one in operation when eval was called so
// that eval code can affect the apppropriate scopes.
meta->engine->jsr(meta->engine->phase, NULL, meta->engine->sp - meta->engine->execStack, JS2VAL_VOID, meta->engine->activationStackTop[-1].env, NULL);
meta->engine->jsr(meta->engine->phase, NULL, meta->engine->sp - meta->engine->execStack, JS2VAL_VOID, meta->engine->activationStackTop[-1].env);
// meta->engine->localFrame = meta->engine->activationStackTop[-1].localFrame;
js2val result = meta->readEvalString(*meta->toString(argv[0]), widenCString("Eval Source"));
meta->engine->rts();
@ -5311,16 +5311,20 @@ XXX see EvalAttributeExpression, where identifiers are being handled for now...
lbe->bindingList.push_back(LocalBindingEntry::NamespaceBinding(meta->publicNamespace, sb));
localBindings.insert(name, lbe);
}
else {
if (argCount > slotCount)
slotCount = argCount;
if (slotCount)
frameSlots = new std::vector<js2val>(slotCount);
}
for (i = 0; (i < argCount); i++) {
if (i < slotCount) {
(*frameSlots)[i] = argBase[i];
}
}
while (i++ < length) {
if (i < slotCount) {
(*frameSlots)[i] = JS2VAL_UNDEFINED;
}
for ( ; (i < slotCount); i++) {
(*frameSlots)[i] = JS2VAL_UNDEFINED;
}
if (plural->buildArguments) {
setLength(meta, argsObj, argCount);

Просмотреть файл

@ -684,8 +684,6 @@ public:
JS2Object *obj;
};
typedef std::vector<js2val> ValueList;
class NonWithFrame : public Frame {
public:

Просмотреть файл

@ -338,8 +338,8 @@
uint16 slotIndex = BytecodeContainer::getShort(pc);
pc += sizeof(short);
a = top();
ASSERT(slotIndex < parameterFrame->frameSlots->size());
(*parameterFrame->frameSlots)[slotIndex] = a;
ASSERT(parameterSlots && slotIndex < parameterSlots->size());
(*parameterSlots)[slotIndex] = a;
}
break;
@ -347,8 +347,9 @@
{
uint16 slotIndex = BytecodeContainer::getShort(pc);
pc += sizeof(short);
ASSERT(slotIndex < parameterFrame->frameSlots->size());
ASSERT(parameterSlots && slotIndex < parameterSlots->size());
// XXX some kind of code here?
push(JS2VAL_TRUE);
}
break;
@ -356,8 +357,8 @@
{
uint16 slotIndex = BytecodeContainer::getShort(pc);
pc += sizeof(short);
ASSERT(slotIndex < parameterFrame->frameSlots->size());
push((*parameterFrame->frameSlots)[slotIndex]);
ASSERT(parameterSlots && slotIndex < parameterSlots->size());
push((*parameterSlots)[slotIndex]);
}
break;
@ -366,8 +367,8 @@
uint16 slotIndex = BytecodeContainer::getShort(pc);
pc += sizeof(short);
push(JS2VAL_NULL);
ASSERT(slotIndex < parameterFrame->frameSlots->size());
push((*parameterFrame->frameSlots)[slotIndex]);
ASSERT(parameterSlots && slotIndex < parameterSlots->size());
push((*parameterSlots)[slotIndex]);
}
break;

Просмотреть файл

@ -1242,10 +1242,10 @@
{
uint16 slotIndex = BytecodeContainer::getShort(pc);
pc += sizeof(short);
ASSERT(slotIndex < parameterFrame->frameSlots->size());
a = (*parameterFrame->frameSlots)[slotIndex];
ASSERT(parameterSlots && slotIndex < parameterSlots->size());
a = (*parameterSlots)[slotIndex];
float64 num = meta->toFloat64(a);
(*parameterFrame->frameSlots)[slotIndex] = allocNumber(num + 1.0);
(*parameterSlots)[slotIndex] = allocNumber(num + 1.0);
pushNumber(num);
}
break;
@ -1253,10 +1253,10 @@
{
uint16 slotIndex = BytecodeContainer::getShort(pc);
pc += sizeof(short);
ASSERT(slotIndex < parameterFrame->frameSlots->size());
a = (*parameterFrame->frameSlots)[slotIndex];
ASSERT(parameterSlots && slotIndex < parameterSlots->size());
a = (*parameterSlots)[slotIndex];
float64 num = meta->toFloat64(a);
(*parameterFrame->frameSlots)[slotIndex] = allocNumber(num - 1.0);
(*parameterSlots)[slotIndex] = allocNumber(num - 1.0);
pushNumber(num);
}
break;
@ -1264,21 +1264,21 @@
{
uint16 slotIndex = BytecodeContainer::getShort(pc);
pc += sizeof(short);
ASSERT(slotIndex < parameterFrame->frameSlots->size());
a = (*parameterFrame->frameSlots)[slotIndex];
ASSERT(parameterSlots && slotIndex < parameterSlots->size());
a = (*parameterSlots)[slotIndex];
float64 num = meta->toFloat64(a);
a = pushNumber(num + 1.0);
(*parameterFrame->frameSlots)[slotIndex] = a;
(*parameterSlots)[slotIndex] = a;
}
break;
case eParameterSlotPreDec:
{
uint16 slotIndex = BytecodeContainer::getShort(pc);
pc += sizeof(short);
ASSERT(slotIndex < parameterFrame->frameSlots->size());
a = (*parameterFrame->frameSlots)[slotIndex];
ASSERT(parameterSlots && slotIndex < parameterSlots->size());
a = (*parameterSlots)[slotIndex];
float64 num = meta->toFloat64(a);
a = pushNumber(num - 1.0);
(*parameterFrame->frameSlots)[slotIndex] = a;
(*parameterSlots)[slotIndex] = a;
}
break;

Просмотреть файл

@ -86,7 +86,8 @@
baseVal = OBJECT_TO_JS2VAL(new (meta) SimpleInstance(meta, protoVal, meta->objectType(protoVal)));
pFrame->thisObject = baseVal;
pFrame->assignArguments(meta, obj, base(argCount), argCount, length);
jsr(phase, fWrap->bCon, base(argCount + 1) - execStack, baseVal, fWrap->env, pFrame);
jsr(phase, fWrap->bCon, base(argCount + 1) - execStack, baseVal, fWrap->env);
parameterSlots = pFrame->frameSlots;
meta->env->addFrame(pFrame);
parameterFrame = pFrame;
pFrame = NULL;
@ -132,7 +133,7 @@ doCall:
push(JS2VAL_UNDEFINED);
argCount++;
}
jsr(phase, NULL, base(argCount + 2) - execStack, JS2VAL_VOID, fWrap->env, NULL);
jsr(phase, NULL, base(argCount + 2) - execStack, JS2VAL_VOID, fWrap->env);
if (fWrap->alien)
a = fWrap->alien(meta, fInst, a, base(argCount), argc);
else
@ -147,7 +148,8 @@ doCall:
pFrame->thisObject = a;
// XXX (use fWrap->compileFrame->signature)
pFrame->assignArguments(meta, fObj, base(argCount), argCount, length);
jsr(phase, fWrap->bCon, base(argCount + 2) - execStack, JS2VAL_VOID, fWrap->env, pFrame);
jsr(phase, fWrap->bCon, base(argCount + 2) - execStack, JS2VAL_VOID, fWrap->env);
parameterSlots = pFrame->frameSlots;
if (fInst->isMethodClosure)
meta->env->addFrame(meta->objectType(a));
meta->env->addFrame(pFrame);
@ -155,7 +157,7 @@ doCall:
pFrame = NULL;
}
else {
jsr(phase, fWrap->bCon, base(argCount + 2) - execStack, JS2VAL_VOID, fWrap->env, pFrame);
jsr(phase, fWrap->bCon, base(argCount + 2) - execStack, JS2VAL_VOID, fWrap->env);
// XXX constructing a parameterFrame only for the purpose of holding the 'this'
// need to find a more efficient way of stashing 'this'
// used to be : "meta->env->addFrame(fWrap->compileFrame->prototype);"

Просмотреть файл

@ -174,6 +174,7 @@ enum Phase { CompilePhase, RunPhase };
typedef uint8 AccessSet;
enum Access { ReadAccess = 0x1, WriteAccess = 0x2, ReadWriteAccess = ReadAccess | WriteAccess};
typedef std::vector<js2val> ValueList;
#endif

Просмотреть файл

@ -31,6 +31,11 @@
* file under either the NPL or the GPL.
*/
#include <vector>
#include "systemtypes.h"
#include "js2value.h"
#include "numerics.h"
#include "lexer.h"

Просмотреть файл

@ -34,6 +34,12 @@
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <vector>
#include "systemtypes.h"
#include "js2value.h"
#include "numerics.h"
#include "parser.h"

Просмотреть файл

@ -31,6 +31,11 @@
* file under either the NPL or the GPL.
*/
#include <vector>
#include "systemtypes.h"
#include "js2value.h"
#include "numerics.h"
#include "parser.h"

Просмотреть файл

@ -32,6 +32,11 @@
*/
#include <algorithm>
#include <vector>
#include "systemtypes.h"
#include "js2value.h"
#include "strings.h"
#include "reader.h"