This commit is contained in:
rogerl%netscape.com 2002-08-02 22:32:17 +00:00
Родитель 5df846cc5a
Коммит a66178a89d
5 изменённых файлов: 174 добавлений и 58 удалений

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

@ -99,7 +99,7 @@ const bool showTokens = false;
MetaData::GlobalObject glob(world);
MetaData::Environment env(new MetaData::SystemFrame(), &glob);
MetaData::JS2Metadata metadata(world);
MetaData::JS2Metadata *metadata;
static int readEvalPrint(FILE *in)
@ -139,11 +139,11 @@ static int readEvalPrint(FILE *in)
stdOut << '\n';
}
metadata.setCurrentParser(&p); // for error reporting
metadata->setCurrentParser(&p); // for error reporting
MetaData::Context cxt;
metadata.ValidateStmtList(&cxt, &env, parsedStatements);
metadata.EvalStmtList(&env, MetaData::JS2Metadata::RunPhase, parsedStatements);
metadata->ValidateStmtList(&cxt, &env, parsedStatements);
metadata->EvalStmtList(&env, MetaData::JS2Metadata::RunPhase, parsedStatements);
}
clear(buffer);
@ -211,6 +211,9 @@ int main(int argc, char **argv)
stdOut << "Welcome to Epimetheus.\n";
#endif
metadata = new MetaData::JS2Metadata(world);
try {
bool doInteractive = true;
int result = 0;

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

@ -69,31 +69,99 @@ namespace JavaScript {
namespace MetaData {
JSRuntime *gJavaScriptRuntime;
JSContext *gJavaScriptContext;
JSObject *gJavaScriptGlobalObject;
JSClass gJavaScriptGlobalClass = { "MyClass", 0, JS_PropertyStub, JS_PropertyStub,
JSRuntime *gMonkeyRuntime;
JSContext *gMonkeyContext;
JSObject *gMonkeyGlobalObject;
JSClass gMonkeyGlobalClass = { "MyClass", 0, JS_PropertyStub, JS_PropertyStub,
JS_PropertyStub, JS_PropertyStub, JS_EnumerateStub,
JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub };
JSClass gMonkeyLexicalReferenceClass = { "LexicalReference", 0, JS_PropertyStub, JS_PropertyStub,
JS_PropertyStub, JS_PropertyStub, JS_EnumerateStub,
JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub };
static JSBool
LexicalReference_constructor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
ASSERT(argc == 3);
ASSERT(JSVAL_IS_STRING(argv[0]));
ASSERT(JSVAL_IS_BOOLEAN(argv[1]));
ASSERT(JSVAL_IS_NULL(argv[2]) || JSVAL_IS_OBJECT(argv[2]));
JSString *str = JSVAL_TO_STRING(argv[0]);
if (!str)
return JS_FALSE;
if (!JS_SetProperty(cx, obj, "name", argv[0]))
return JS_FALSE;
return JS_TRUE;
}
static JSBool
readReference(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
// for this reference, use the
return JS_TRUE;
}
static JSBool
writeReference(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
return JS_TRUE;
}
JSFunctionSpec jsfLexicalReference [] =
{
{ "readReference", readReference, 0, 0, 0 },
{ "writeReference", writeReference, 0, 0, 0 },
{ 0 }
};
JSFunctionSpec jsfGlobal [] =
{
{ 0 }
};
void MonkeyError(JSContext *cx, const char *message, JSErrorReport *report)
{
throw message;
}
void JS2Metadata::initializeMonkey( )
{
gJavaScriptRuntime = JS_NewRuntime( 1000000L );
if (gJavaScriptRuntime) {
gJavaScriptContext = JS_NewContext( gJavaScriptRuntime, 8192 );
if (gJavaScriptContext) {
gJavaScriptGlobalObject = JS_NewObject(gJavaScriptContext, &gJavaScriptGlobalClass, NULL, NULL);
if (gJavaScriptGlobalObject)
JS_SetGlobalObject(gJavaScriptContext, gJavaScriptGlobalObject);
}
}
gMonkeyRuntime = JS_NewRuntime( 1000000L );
if (!gMonkeyRuntime)
throw "Monkey start failure";
gMonkeyContext = JS_NewContext( gMonkeyRuntime, 8192 );
if (!gMonkeyContext)
throw "Monkey start failure";
gMonkeyGlobalObject = JS_NewObject(gMonkeyContext, &gMonkeyGlobalClass, NULL, NULL);
if (!gMonkeyGlobalObject)
throw "Monkey start failure";
JS_SetErrorReporter(gMonkeyContext, MonkeyError);
JS_InitStandardClasses(gMonkeyContext, gMonkeyGlobalObject);
JS_InitClass(gMonkeyContext, gMonkeyGlobalObject, NULL,
&gMonkeyLexicalReferenceClass, LexicalReference_constructor, 0,
NULL, jsfLexicalReference,
NULL, NULL);
JS_DefineFunctions(gMonkeyContext, gMonkeyGlobalObject, jsfGlobal);
}
jsval JS2Metadata::execute(String *str)
{
jsval retval;
JS_EvaluateUCScript(gJavaScriptContext, gJavaScriptGlobalObject, str->c_str(), str->length(), "file", 1, &retval);
JS_EvaluateUCScript(gMonkeyContext, gMonkeyGlobalObject, str->c_str(), str->length(), "file", 1, &retval);
return retval;
}

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

@ -44,6 +44,7 @@
#include "js2metadata.h"
#include "numerics.h"
@ -404,6 +405,14 @@ namespace MetaData {
void JS2Metadata::ValidateExpression(Context *cxt, Environment *env, ExprNode *p)
{
switch (p->getKind()) {
case ExprNode::assignment:
case ExprNode::add:
{
BinaryExprNode *b = checked_cast<BinaryExprNode *>(p);
ValidateExpression(cxt, env, b->op1);
ValidateExpression(cxt, env, b->op2);
}
break;
case ExprNode::identifier:
{
IdentifierExprNode *i = checked_cast<IdentifierExprNode *>(p);
@ -428,42 +437,57 @@ namespace MetaData {
*/
jsval JS2Metadata::EvalExpression(Environment *env, Phase phase, ExprNode *p)
{
String s = EvalExprNode(env, phase, p);
return execute(&s);
String s;
EvalExprNode(env, phase, p, s);
try {
return execute(&s);
}
catch (const char *err) {
reportError(Exception::internalError, err, p->pos);
return JSVAL_VOID;
}
}
String JS2Metadata::EvalExprNode(Environment *env, Phase phase, ExprNode *p)
const String numberToString(float64 &number)
{
char buf[dtosStandardBufferSize];
const char *chrp = doubleToStr(buf, dtosStandardBufferSize, number, dtosStandard, 0);
return JavaScript::String(widenCString(chrp));
}
bool JS2Metadata::EvalExprNode(Environment *env, Phase phase, ExprNode *p, String &s)
{
bool returningRef = false;
switch (p->getKind()) {
case ExprNode::index:
{
}
break;
/*
pause
char*
[FullPostfixExpression .PostfixExpressionOrSuper [no line break] ++] do
if phase = compile then throw compileExpressionError end if;
r: OBJORREFOPTIONALLIMIT .Eval[PostfixExpressionOrSuper](env, phase);
a: OBJOPTIONALLIMIT .readRefWithLimit(r, phase);
b: OBJECT .unaryDispatch(incrementTable, null, a, ARGUMENTLIST <<<<positional: [], named: {} >>>, phase);
writeReference(r, b, phase);
return getObject(a);
*/
case ExprNode::assignment:
{
if (phase == CompilePhase) reportError(Exception::compileExpressionError, "Inappropriate compile time expression", p->pos);
BinaryExprNode *b = checked_cast<BinaryExprNode *>(p);
if (EvalExprNode(env, phase, b->op1, s)) {
String r;
s += ".writeReference(";
if (EvalExprNode(env, phase, b->op2, r))
s += r + ".readReference())";
else
s += r + ")";
}
else
ASSERT(false); // shouldn't this have been checked by validate?
}
break;
case ExprNode::add:
{
BinaryExprNode *b = checked_cast<BinaryExprNode *>(p);
s = EvalExprNode(b->op1);
if (EvalExprNode(env, phase, b->op1, s))
s += ".readReference()";
s += " + ";
s += EvalExprNode(b->op2);
if (EvalExprNode(env, phase, b->op2, s))
s += ".readReference()";
}
break;
@ -471,32 +495,52 @@ namespace MetaData {
{
if (phase == CompilePhase) reportError(Exception::compileExpressionError, "Inappropriate compile time expression", p->pos);
UnaryExprNode *u = checked_cast<UnaryExprNode *>(p);
s = EvalExprNode(env, phase, u->op);
s += "++";
// rather than inserting "(r = , a = readRef(), r.writeRef(a + 1), a)" with
// all the attendant performance overhead and temp. handling issues.
s += ".postIncrement()";
returningRef = true;
}
break;
case ExprNode::number:
{
s += numberToString(checked_cast<NumberExprNode *>(p)->value);
}
break;
case ExprNode::identifier:
{
IdentifierExprNode *i = checked_cast<IdentifierExprNode *>(p);
Multiname *mn = new Multiname();
for (NamespaceListIterator nli = i->cxt->openNamespaces.begin(), end = i->cxt->openNamespaces.end();
(nli != end); nli++)
mn->push_back(new QualifiedName(*nli, i->name));
return OBJECT_TO_JSVAL(new LexicalReference(mn, env, i->cxt->strict));
s += "new LexicalReference(\"" + i->name + "\", ";
s += (i->cxt->strict) ? "true, " : "false, ";
NamespaceListIterator nli = i->cxt->openNamespaces.begin(), end = i->cxt->openNamespaces.end();
if (nli != end) {
s += "new Multiname(";
while (true) {
s += (*nli)->name;
nli++;
if (nli != end)
s += ", ";
else
break;
}
s += ")";
}
else
s += "null";
s += ")";
returningRef = true;
}
break;
case ExprNode::boolean:
if (checked_cast<BooleanExprNode *>(p)->value)
return JSVAL_TRUE;
s += "true";
else
return JSVAL_FALSE;
s += "false";
break;
default:
NOT_REACHED("Not Yet Implemented");
}
return JSVAL_VOID;
return returningRef;
}
void JS2Metadata::ValidateTypeExpression(ExprNode *e)
@ -614,7 +658,7 @@ namespace MetaData {
* with the argument value. [This is intended to be widened into a more complete
* argument handling scheme].
*/
void JS2Metadata::reportError(Exception::Kind kind, char *message, size_t pos, const char *arg)
void JS2Metadata::reportError(Exception::Kind kind, const char *message, size_t pos, const char *arg)
{
const char16 *lineBegin;
const char16 *lineEnd;
@ -633,7 +677,7 @@ namespace MetaData {
inline char narrow(char16 ch) { return char(ch); }
// Accepts a String as the error argument and converts to char *
void JS2Metadata::reportError(Exception::Kind kind, char *message, size_t pos, const String& name)
void JS2Metadata::reportError(Exception::Kind kind, const char *message, size_t pos, const String& name)
{
std::string str(name.length(), char());
std::transform(name.begin(), name.end(), str.begin(), narrow);

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

@ -449,12 +449,13 @@ public:
void ValidateAttributeExpression(Context *cxt, Environment *env, ExprNode *p);
jsval EvalExpression(Environment *env, Phase phase, ExprNode *p);
bool EvalExprNode(Environment *env, Phase phase, ExprNode *p, String &s);
Attribute *EvalAttributeExpression(Environment *env, Phase phase, ExprNode *p);
jsval EvalStmtList(Environment *env, Phase phase, StmtNode *p);
jsval EvalStmt(Environment *env, Phase phase, StmtNode *p);
void reportError(Exception::Kind kind, char *message, size_t pos, const char *arg = NULL);
void reportError(Exception::Kind kind, char *message, size_t pos, const String& name);
void reportError(Exception::Kind kind, const char *message, size_t pos, const char *arg = NULL);
void reportError(Exception::Kind kind, const char *message, size_t pos, const String& name);
void initializeMonkey();

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

@ -50,7 +50,7 @@ BSC32=bscmake.exe
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib js32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib js32.lib /nologo /subsystem:console /machine:I386 /libpath:"..\..\..\..\js\src\release"
!ELSEIF "$(CFG)" == "Epimetheus - Win32 Debug"