1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2026-05-27 21:17:10 +02:00

Dumped the old implementation. Started with a more simple approach.

This commit is contained in:
Sandu Liviu Catalin
2016-02-21 00:25:00 +02:00
parent 96ded94026
commit 06e598acfb
293 changed files with 37439 additions and 92564 deletions
+55 -12
View File
@@ -157,7 +157,7 @@ public:
void MoveIfCurrentTargetIsLocal() {
SQInteger trg = _fs->TopTarget();
if(_fs->IsLocal(trg)) {
trg = _fs->PopTarget(); //no pops the target and move it
trg = _fs->PopTarget(); //pops the target and moves it
_fs->AddInstruction(_OP_MOVE, _fs->PushTarget(), trg);
}
}
@@ -338,6 +338,7 @@ public:
_fs->PushTarget(p1);
//EmitCompArithLocal(tok, p1, p1, p2);
_fs->AddInstruction(ChooseArithOpByToken(tok),p1, p2, p1, 0);
_fs->SnoozeOpt();
}
break;
case OBJECT:
@@ -356,7 +357,9 @@ public:
SQInteger tmp = _fs->PushTarget();
_fs->AddInstruction(_OP_GETOUTER, tmp, pos);
_fs->AddInstruction(ChooseArithOpByToken(tok), tmp, val, tmp, 0);
_fs->AddInstruction(_OP_SETOUTER, tmp, pos, tmp);
_fs->PopTarget();
_fs->PopTarget();
_fs->AddInstruction(_OP_SETOUTER, _fs->PushTarget(), pos, tmp);
}
break;
}
@@ -656,6 +659,7 @@ public:
case EXPR: Error(_SC("can't '++' or '--' an expression")); break;
case OBJECT:
case BASE:
if(_es.donot_get == true) { Error(_SC("can't '++' or '--' an expression")); break; } //mmh dor this make sense?
Emit2ArgsOP(_OP_PINC, diff);
break;
case LOCAL: {
@@ -706,7 +710,7 @@ public:
}
SQInteger Factor()
{
_es.etype = EXPR;
//_es.etype = EXPR;
switch(_token)
{
case TK_STRING_LITERAL:
@@ -864,6 +868,7 @@ public:
case TK___FILE__: _fs->AddInstruction(_OP_LOAD, _fs->PushTarget(), _fs->GetConstant(_sourcename)); Lex(); break;
default: Error(_SC("expression expected"));
}
_es.etype = EXPR;
return -1;
}
void EmitLoadConstInt(SQInteger value,SQInteger target)
@@ -871,7 +876,7 @@ public:
if(target < 0) {
target = _fs->PushTarget();
}
if((value & (~((SQInteger)0xFFFFFFFF))) == 0) { //does it fit in 32 bits?
if(value <= INT_MAX && value > INT_MIN) { //does it fit in 32 bits?
_fs->AddInstruction(_OP_LOADINT, target,value);
}
else {
@@ -900,8 +905,13 @@ public:
{
switch(_token) {
case _SC('='): case _SC('('): case TK_NEWSLOT: case TK_MODEQ: case TK_MULEQ:
case TK_DIVEQ: case TK_MINUSEQ: case TK_PLUSEQ: case TK_PLUSPLUS: case TK_MINUSMINUS:
case TK_DIVEQ: case TK_MINUSEQ: case TK_PLUSEQ:
return false;
case TK_PLUSPLUS: case TK_MINUSMINUS:
if (!IsEndOfStatement()) {
return false;
}
break;
}
return (!_es.donot_get || ( _es.donot_get && (_token == _SC('.') || _token == _SC('['))));
}
@@ -1017,6 +1027,28 @@ public:
if(_token == _SC(',')) Lex(); else break;
} while(1);
}
void IfBlock()
{
if (_token == _SC('{'))
{
BEGIN_SCOPE();
Lex();
Statements();
Expect(_SC('}'));
if (true) {
END_SCOPE();
}
else {
END_SCOPE_NO_CLOSE();
}
}
else {
//BEGIN_SCOPE();
Statement();
if (_lex._prevtoken != _SC('}') && _lex._prevtoken != _SC(';')) OptionalSemicolon();
//END_SCOPE();
}
}
void IfStatement()
{
SQInteger jmppos;
@@ -1024,22 +1056,33 @@ public:
Lex(); Expect(_SC('(')); CommaExpr(); Expect(_SC(')'));
_fs->AddInstruction(_OP_JZ, _fs->PopTarget());
SQInteger jnepos = _fs->GetCurrentPos();
BEGIN_SCOPE();
Statement();
IfBlock();
//
if(_token != _SC('}') && _token != TK_ELSE) OptionalSemicolon();
/*static int n = 0;
if (_token != _SC('}') && _token != TK_ELSE) {
printf("IF %d-----------------------!!!!!!!!!\n", n);
if (n == 5)
{
printf("asd");
}
n++;
//OptionalSemicolon();
}*/
END_SCOPE();
SQInteger endifblock = _fs->GetCurrentPos();
if(_token == TK_ELSE){
haselse = true;
BEGIN_SCOPE();
//BEGIN_SCOPE();
_fs->AddInstruction(_OP_JMP);
jmppos = _fs->GetCurrentPos();
Lex();
Statement(); if(_lex._prevtoken != _SC('}')) OptionalSemicolon();
END_SCOPE();
//Statement(); if(_lex._prevtoken != _SC('}')) OptionalSemicolon();
IfBlock();
//END_SCOPE();
_fs->SetIntructionParam(jmppos, 1, _fs->GetCurrentPos() - jmppos);
}
_fs->SetIntructionParam(jnepos, 1, endifblock - jnepos + (haselse?1:0));