From 6a0f4f16a939b4f8f6a99bf8035d55af9d6eca44 Mon Sep 17 00:00:00 2001 From: "rginda%netscape.com" Date: Sat, 14 Oct 2000 00:06:42 +0000 Subject: [PATCH] guess what? yep, more icode asm hacking. --- js/js2/Makefile | 14 +++++- js/js2/ica_test.cpp | 34 ++++++++++--- js/js2/icodeasm.cpp | 113 +++++++++++++++++++++++++++++++++++-------- js/js2/icodeasm.h | 2 +- js2/src/Makefile | 14 +++++- js2/src/ica_test.cpp | 34 ++++++++++--- js2/src/icodeasm.cpp | 113 +++++++++++++++++++++++++++++++++++-------- js2/src/icodeasm.h | 2 +- 8 files changed, 270 insertions(+), 56 deletions(-) diff --git a/js/js2/Makefile b/js/js2/Makefile index 5ccf1b9aec97..26413bd1f8bb 100644 --- a/js/js2/Makefile +++ b/js/js2/Makefile @@ -15,6 +15,18 @@ objs = hash.o \ vmtypes.o \ debugger.o +test_objs = hash.o \ + icodegenerator.o \ + interpreter.o \ + jsmath.o \ + jstypes.o \ + numerics.o \ + parser.o \ + utilities.o \ + world.o \ + vmtypes.o \ + debugger.o + gc_path = ../../gc/boehm/ libs = gc.a -lstdc++ -lm @@ -33,7 +45,7 @@ gctest: gc_allocator.o $(CC) -o $@ -ggdb $^ $(libs) ica_test: - $(CC) $(CFLAGS) -o ica_test ica_test.cpp icodeasm.cpp $(LIBS) + $(CC) $(CFLAGS) -o ica_test ica_test.cpp icodeasm.cpp $(test_objs) $(libs) clean: rm -f $(objs) diff --git a/js/js2/ica_test.cpp b/js/js2/ica_test.cpp index a4b141574c55..e96157226f4a 100644 --- a/js/js2/ica_test.cpp +++ b/js/js2/ica_test.cpp @@ -37,15 +37,35 @@ #include "icodeasm.h" int -main (int argc, char **argv) +main (int , char **) { - JavaScript::Debugger::ICodeParser icp; - string str = "true"; - - bool b = false; - icp.ParseBool (str.begin(), str.end(), &b); - fprintf (stderr, "bool parsed as %c\n", b); + JavaScript::ICodeASM::ICodeParser icp; + bool b; + string str; +#define BOOL_TEST(s, expect) \ + { \ + b = false; \ + str = s; \ + icp.ParseBool (str.begin(), str.end(), &b); \ + if (b == expect) \ + fprintf (stderr, "PASS: "); \ + else \ + fprintf (stderr, "FAIL: "); \ + fprintf (stderr, "string %s bool parsed as %i\n", str.c_str(), b); \ + } \ + + BOOL_TEST ("true", true); + BOOL_TEST ("True", true); + BOOL_TEST ("tRue", true); + BOOL_TEST ("TRUE", true); + BOOL_TEST ("True", true); + BOOL_TEST ("false", false); + BOOL_TEST ("False", false); + BOOL_TEST ("fAlSe", false); + BOOL_TEST ("FALSE", false); + BOOL_TEST ("False", false); + return 0; } diff --git a/js/js2/icodeasm.cpp b/js/js2/icodeasm.cpp index 43b1349e7530..53c390260096 100644 --- a/js/js2/icodeasm.cpp +++ b/js/js2/icodeasm.cpp @@ -160,22 +160,21 @@ namespace ICodeASM { ICodeParser::ParseBool (iter begin, iter end, bool *rval) { iter curpos = begin; - string *str = new string(); - if ((curpos != end) && (*curpos == "T" || *curpos == "t")) { - if ((++curpos != end) && (*curpos == "R" || *curpos == "r")) - if ((++curpos != end) && (*curpos == "U" || *curpos == "u")) + if ((curpos != end) && (*curpos == 'T' || *curpos == 't')) { + if ((++curpos != end) && (*curpos == 'R' || *curpos == 'r')) + if ((++curpos != end) && (*curpos == 'U' || *curpos == 'u')) if ((++curpos != end) && - (*curpos == "E" || *curpos == "e")) { + (*curpos == 'E' || *curpos == 'e')) { *rval = true; return ++curpos; } - } else if ((curpos != end) && (*curpos == "F" || *curpos == "f")) { - if ((++curpos != end) && (*curpos == "A" || *curpos == "a")) - if ((++curpos != end) && (*curpos == "L" || *curpos == "l")) - if ((++curpos != end) && (*curpos == "S" || *curpos == "s")) + } else if ((curpos != end) && (*curpos == 'F' || *curpos == 'f')) { + if ((++curpos != end) && (*curpos == 'A' || *curpos == 'a')) + if ((++curpos != end) && (*curpos == 'L' || *curpos == 'l')) + if ((++curpos != end) && (*curpos == 'S' || *curpos == 's')) if ((++curpos != end) && - (*curpos == "E" || *curpos == "e")) { + (*curpos == 'E' || *curpos == 'e')) { *rval = false; return ++curpos; } @@ -312,7 +311,7 @@ namespace ICodeASM { ICodeParser::ParseUInt32 (iter begin, iter end, uint32 *rval) { /* XXX add overflow checking */ - uint32 position = 0; + int32 position = 0; iter curpos; for (curpos = begin; curpos < end; ++curpos) { @@ -329,8 +328,7 @@ namespace ICodeASM { } scan_done: - curpos = begin; - for (; position >= 0; --position) + for (curpos = begin; position >= 0; --position) *rval += (*curpos++ - '0') * static_cast(pow (10, position)); return curpos; @@ -406,7 +404,7 @@ namespace ICodeASM { } scan_done: - if (tl.type = ttUndetermined) { + if (tl.type == ttUndetermined) { tl.type = ttInstruction; tl.end = end; } @@ -419,17 +417,23 @@ namespace ICodeASM { string icode_str(tl.begin, tl.end); for (uint i = 0; i < icodemap_size; ++i) if (cmp_nocase(icode_str, &icodemap[i].name[0], - &icodemap[i].name[0] + strlen(icodemap[i].name) + 1)) + &icodemap[i].name[0] + + strlen(icodemap[i].name) + 1)) return ParseInstruction (i, tl.end, end); - throw ("Unknown ICode " + icode_str); + throw new ICodeParseException ("Unknown ICode " + icode_str); + } else { + throw new ICodeParseException ("Internal error in ParseStatement."); } + } iter - ICodeParser::ParseArgumentListOperand (iter begin, iter end, AnyOperand *o) + ICodeParser::ParseArgumentListOperand (iter begin, iter /*end*/, + AnyOperand */*o*/) { /* XXX this is hard, lets go shopping */ ASSERT ("Not Implemented."); + return begin; } iter @@ -446,7 +450,7 @@ namespace ICodeASM { } iter - ParseBoolOperand (iter begin, iter end, AnyOperand *o) + ICodeParser::ParseBoolOperand (iter begin, iter end, AnyOperand *o) { TokenLocation tl = SeekTokenStart (begin, end); @@ -457,7 +461,15 @@ namespace ICodeASM { } iter - ParseICodeModuleOperand (iter begin, iter end, AnyOperand *o) + ICodeParser::ParseDoubleOperand (iter begin, iter /*end*/, + AnyOperand */*o*/) + { + ASSERT ("Not Implemented."); + return begin; + } + + iter + ICodeParser::ParseICodeModuleOperand (iter begin, iter end, AnyOperand *o) { TokenLocation tl = SeekTokenStart (begin, end); @@ -470,6 +482,69 @@ namespace ICodeASM { return end; } + iter + ICodeParser::ParseJSClassOperand (iter begin, iter /*end*/, + AnyOperand */*o*/) + { + ASSERT ("Not Implemented."); + return begin; + } + + iter + ICodeParser::ParseJSStringOperand (iter begin, iter /*end*/, + AnyOperand */*o*/) + { + ASSERT ("Not Implemented."); + return begin; + } + iter + ICodeParser::ParseJSFunctionOperand (iter begin, iter /*end*/, + AnyOperand */*o*/) + { + ASSERT ("Not Implemented."); + return begin; + } + + iter + ICodeParser::ParseJSTypeOperand (iter begin, iter /*end*/, + AnyOperand */*o*/) + { + ASSERT ("Not Implemented."); + return begin; + } + + iter + ICodeParser::ParseLabelOperand (iter begin, iter /*end*/, + AnyOperand */*o*/) + { + ASSERT ("Not Implemented."); + return begin; + } + + iter + ICodeParser::ParseUInt32Operand (iter begin, iter /*end*/, + AnyOperand */*o*/) + { + ASSERT ("Not Implemented."); + return begin; + } + + iter + ICodeParser::ParseRegisterOperand (iter begin, iter /*end*/, + AnyOperand */*o*/) + { + ASSERT ("Not Implemented."); + return begin; + } + + iter + ICodeParser::ParseStringAtomOperand (iter begin, iter /*end*/, + AnyOperand */*o*/) + { + ASSERT ("Not Implemented."); + return begin; + } + } } diff --git a/js/js2/icodeasm.h b/js/js2/icodeasm.h index d38bf4bf3d46..cde3f37d3d2d 100644 --- a/js/js2/icodeasm.h +++ b/js/js2/icodeasm.h @@ -85,7 +85,7 @@ namespace ICodeASM { double asDouble; uint32 asUInt32; VM::Register asRegister; - bool asBool; + bool asBoolean; VM::ArgumentList *asArgumentList; string *asString; }; diff --git a/js2/src/Makefile b/js2/src/Makefile index 5ccf1b9aec97..26413bd1f8bb 100644 --- a/js2/src/Makefile +++ b/js2/src/Makefile @@ -15,6 +15,18 @@ objs = hash.o \ vmtypes.o \ debugger.o +test_objs = hash.o \ + icodegenerator.o \ + interpreter.o \ + jsmath.o \ + jstypes.o \ + numerics.o \ + parser.o \ + utilities.o \ + world.o \ + vmtypes.o \ + debugger.o + gc_path = ../../gc/boehm/ libs = gc.a -lstdc++ -lm @@ -33,7 +45,7 @@ gctest: gc_allocator.o $(CC) -o $@ -ggdb $^ $(libs) ica_test: - $(CC) $(CFLAGS) -o ica_test ica_test.cpp icodeasm.cpp $(LIBS) + $(CC) $(CFLAGS) -o ica_test ica_test.cpp icodeasm.cpp $(test_objs) $(libs) clean: rm -f $(objs) diff --git a/js2/src/ica_test.cpp b/js2/src/ica_test.cpp index a4b141574c55..e96157226f4a 100644 --- a/js2/src/ica_test.cpp +++ b/js2/src/ica_test.cpp @@ -37,15 +37,35 @@ #include "icodeasm.h" int -main (int argc, char **argv) +main (int , char **) { - JavaScript::Debugger::ICodeParser icp; - string str = "true"; - - bool b = false; - icp.ParseBool (str.begin(), str.end(), &b); - fprintf (stderr, "bool parsed as %c\n", b); + JavaScript::ICodeASM::ICodeParser icp; + bool b; + string str; +#define BOOL_TEST(s, expect) \ + { \ + b = false; \ + str = s; \ + icp.ParseBool (str.begin(), str.end(), &b); \ + if (b == expect) \ + fprintf (stderr, "PASS: "); \ + else \ + fprintf (stderr, "FAIL: "); \ + fprintf (stderr, "string %s bool parsed as %i\n", str.c_str(), b); \ + } \ + + BOOL_TEST ("true", true); + BOOL_TEST ("True", true); + BOOL_TEST ("tRue", true); + BOOL_TEST ("TRUE", true); + BOOL_TEST ("True", true); + BOOL_TEST ("false", false); + BOOL_TEST ("False", false); + BOOL_TEST ("fAlSe", false); + BOOL_TEST ("FALSE", false); + BOOL_TEST ("False", false); + return 0; } diff --git a/js2/src/icodeasm.cpp b/js2/src/icodeasm.cpp index 43b1349e7530..53c390260096 100644 --- a/js2/src/icodeasm.cpp +++ b/js2/src/icodeasm.cpp @@ -160,22 +160,21 @@ namespace ICodeASM { ICodeParser::ParseBool (iter begin, iter end, bool *rval) { iter curpos = begin; - string *str = new string(); - if ((curpos != end) && (*curpos == "T" || *curpos == "t")) { - if ((++curpos != end) && (*curpos == "R" || *curpos == "r")) - if ((++curpos != end) && (*curpos == "U" || *curpos == "u")) + if ((curpos != end) && (*curpos == 'T' || *curpos == 't')) { + if ((++curpos != end) && (*curpos == 'R' || *curpos == 'r')) + if ((++curpos != end) && (*curpos == 'U' || *curpos == 'u')) if ((++curpos != end) && - (*curpos == "E" || *curpos == "e")) { + (*curpos == 'E' || *curpos == 'e')) { *rval = true; return ++curpos; } - } else if ((curpos != end) && (*curpos == "F" || *curpos == "f")) { - if ((++curpos != end) && (*curpos == "A" || *curpos == "a")) - if ((++curpos != end) && (*curpos == "L" || *curpos == "l")) - if ((++curpos != end) && (*curpos == "S" || *curpos == "s")) + } else if ((curpos != end) && (*curpos == 'F' || *curpos == 'f')) { + if ((++curpos != end) && (*curpos == 'A' || *curpos == 'a')) + if ((++curpos != end) && (*curpos == 'L' || *curpos == 'l')) + if ((++curpos != end) && (*curpos == 'S' || *curpos == 's')) if ((++curpos != end) && - (*curpos == "E" || *curpos == "e")) { + (*curpos == 'E' || *curpos == 'e')) { *rval = false; return ++curpos; } @@ -312,7 +311,7 @@ namespace ICodeASM { ICodeParser::ParseUInt32 (iter begin, iter end, uint32 *rval) { /* XXX add overflow checking */ - uint32 position = 0; + int32 position = 0; iter curpos; for (curpos = begin; curpos < end; ++curpos) { @@ -329,8 +328,7 @@ namespace ICodeASM { } scan_done: - curpos = begin; - for (; position >= 0; --position) + for (curpos = begin; position >= 0; --position) *rval += (*curpos++ - '0') * static_cast(pow (10, position)); return curpos; @@ -406,7 +404,7 @@ namespace ICodeASM { } scan_done: - if (tl.type = ttUndetermined) { + if (tl.type == ttUndetermined) { tl.type = ttInstruction; tl.end = end; } @@ -419,17 +417,23 @@ namespace ICodeASM { string icode_str(tl.begin, tl.end); for (uint i = 0; i < icodemap_size; ++i) if (cmp_nocase(icode_str, &icodemap[i].name[0], - &icodemap[i].name[0] + strlen(icodemap[i].name) + 1)) + &icodemap[i].name[0] + + strlen(icodemap[i].name) + 1)) return ParseInstruction (i, tl.end, end); - throw ("Unknown ICode " + icode_str); + throw new ICodeParseException ("Unknown ICode " + icode_str); + } else { + throw new ICodeParseException ("Internal error in ParseStatement."); } + } iter - ICodeParser::ParseArgumentListOperand (iter begin, iter end, AnyOperand *o) + ICodeParser::ParseArgumentListOperand (iter begin, iter /*end*/, + AnyOperand */*o*/) { /* XXX this is hard, lets go shopping */ ASSERT ("Not Implemented."); + return begin; } iter @@ -446,7 +450,7 @@ namespace ICodeASM { } iter - ParseBoolOperand (iter begin, iter end, AnyOperand *o) + ICodeParser::ParseBoolOperand (iter begin, iter end, AnyOperand *o) { TokenLocation tl = SeekTokenStart (begin, end); @@ -457,7 +461,15 @@ namespace ICodeASM { } iter - ParseICodeModuleOperand (iter begin, iter end, AnyOperand *o) + ICodeParser::ParseDoubleOperand (iter begin, iter /*end*/, + AnyOperand */*o*/) + { + ASSERT ("Not Implemented."); + return begin; + } + + iter + ICodeParser::ParseICodeModuleOperand (iter begin, iter end, AnyOperand *o) { TokenLocation tl = SeekTokenStart (begin, end); @@ -470,6 +482,69 @@ namespace ICodeASM { return end; } + iter + ICodeParser::ParseJSClassOperand (iter begin, iter /*end*/, + AnyOperand */*o*/) + { + ASSERT ("Not Implemented."); + return begin; + } + + iter + ICodeParser::ParseJSStringOperand (iter begin, iter /*end*/, + AnyOperand */*o*/) + { + ASSERT ("Not Implemented."); + return begin; + } + iter + ICodeParser::ParseJSFunctionOperand (iter begin, iter /*end*/, + AnyOperand */*o*/) + { + ASSERT ("Not Implemented."); + return begin; + } + + iter + ICodeParser::ParseJSTypeOperand (iter begin, iter /*end*/, + AnyOperand */*o*/) + { + ASSERT ("Not Implemented."); + return begin; + } + + iter + ICodeParser::ParseLabelOperand (iter begin, iter /*end*/, + AnyOperand */*o*/) + { + ASSERT ("Not Implemented."); + return begin; + } + + iter + ICodeParser::ParseUInt32Operand (iter begin, iter /*end*/, + AnyOperand */*o*/) + { + ASSERT ("Not Implemented."); + return begin; + } + + iter + ICodeParser::ParseRegisterOperand (iter begin, iter /*end*/, + AnyOperand */*o*/) + { + ASSERT ("Not Implemented."); + return begin; + } + + iter + ICodeParser::ParseStringAtomOperand (iter begin, iter /*end*/, + AnyOperand */*o*/) + { + ASSERT ("Not Implemented."); + return begin; + } + } } diff --git a/js2/src/icodeasm.h b/js2/src/icodeasm.h index d38bf4bf3d46..cde3f37d3d2d 100644 --- a/js2/src/icodeasm.h +++ b/js2/src/icodeasm.h @@ -85,7 +85,7 @@ namespace ICodeASM { double asDouble; uint32 asUInt32; VM::Register asRegister; - bool asBool; + bool asBoolean; VM::ArgumentList *asArgumentList; string *asString; };