Set properties with integer.property
This commit is contained in:
parent
939a04d3c7
commit
644c130712
@ -257,6 +257,17 @@ namespace pim
|
||||
writeOpcode(Opcode::Kill);
|
||||
}
|
||||
|
||||
void Generator::LoadProperty(std::string property)
|
||||
{
|
||||
writeOpcode(Opcode::LoadProperty);
|
||||
writeConstant(0);
|
||||
}
|
||||
|
||||
void Generator::StoreProperty(std::string property)
|
||||
{
|
||||
writeOpcode(Opcode::StoreProperty);
|
||||
writeConstant(0);
|
||||
}
|
||||
|
||||
void Generator::IntegerToDecimal()
|
||||
{
|
||||
|
@ -36,10 +36,13 @@ namespace pim
|
||||
}
|
||||
~SymbolNotFoundException() throw() {};
|
||||
};
|
||||
class Type
|
||||
{
|
||||
enum { Integer = Token::IntegerSymbol, Decimal = Token::DecimalSymbol };
|
||||
};
|
||||
class Definition
|
||||
{
|
||||
public:
|
||||
enum { Integer = Token::IntegerSymbol, Decimal = Token::DecimalSymbol };
|
||||
std::string Name;
|
||||
int Type;
|
||||
int StackPosition;
|
||||
@ -145,6 +148,8 @@ namespace pim
|
||||
void GetParticle();
|
||||
void GetPosition();
|
||||
void KillParticle();
|
||||
void LoadProperty(std::string property);
|
||||
void StoreProperty(std::string property);
|
||||
|
||||
void IntegerToDecimal();
|
||||
void DecimalToInteger();
|
||||
|
@ -105,6 +105,8 @@ namespace pim
|
||||
case Opcode::Jump:
|
||||
case Opcode::Return:
|
||||
case Opcode::LocalEnter:
|
||||
case Opcode::LoadProperty:
|
||||
case Opcode::StoreProperty:
|
||||
return 4;
|
||||
case Opcode::Discard:
|
||||
case Opcode::Duplicate:
|
||||
@ -214,6 +216,13 @@ namespace pim
|
||||
sim->kill_part(PSPop().Integer);
|
||||
PSPush((Word)0);
|
||||
break;
|
||||
case Opcode::LoadProperty:
|
||||
PSPush(PPROP(PSPop().Integer, argument.Integer));
|
||||
break;
|
||||
case Opcode::StoreProperty:
|
||||
temp1 = PSPop();
|
||||
PPROP(temp1.Integer, argument.Integer) = PSPop();
|
||||
break;
|
||||
case Opcode::JumpEqual:
|
||||
if(PSPop().Integer == PSPop().Integer)
|
||||
programCounter = argument.Integer-1;
|
||||
|
@ -42,6 +42,7 @@ namespace pim
|
||||
#define CSA(argument) (*((Word*)&ram[framePointer-argument]))
|
||||
#define CS() (*((Word*)&ram[callStack]))
|
||||
#define PS() (*((Word*)&ram[programStack]))
|
||||
#define PPROP(index, property) (*((Word*)(&sim->parts[(index)]+property)))
|
||||
|
||||
int programStack; //Points to the item on top of the Program Stack
|
||||
int callStack; //Points to the item on top of the call stack
|
||||
|
@ -15,6 +15,8 @@ OPDEF(Transform)
|
||||
OPDEF(Get)
|
||||
OPDEF(Position)
|
||||
OPDEF(Kill)
|
||||
OPDEF(LoadProperty)
|
||||
OPDEF(StoreProperty)
|
||||
OPDEF(JumpEqual)
|
||||
OPDEF(JumpNotEqual)
|
||||
OPDEF(JumpGreater)
|
||||
|
@ -438,17 +438,26 @@ namespace pim
|
||||
}
|
||||
|
||||
/*
|
||||
<assigment statement> ::= identifier = <expression>
|
||||
<assigment statement> ::= identifier = <expression> | identifier.property = <expression>
|
||||
*/
|
||||
void Parser::assigmentStatement()
|
||||
{
|
||||
std::string variable = token.Source;
|
||||
//generator->PushVariableAddress(token.Source);
|
||||
expect(Token::Identifier);
|
||||
expect(Token::AssignSymbol);
|
||||
expression();
|
||||
//generator->Store();
|
||||
generator->StoreVariable(variable);
|
||||
if(accept(Token::AssignSymbol))
|
||||
{
|
||||
expression();
|
||||
generator->StoreVariable(variable);
|
||||
}
|
||||
else if(accept(Token::DotSymbol))
|
||||
{
|
||||
std::string property = token.Source;
|
||||
expect(Token::Identifier);
|
||||
expect(Token::AssignSymbol);
|
||||
expression();
|
||||
generator->LoadVariable(variable);
|
||||
generator->StoreProperty(property);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -533,56 +542,10 @@ namespace pim
|
||||
}
|
||||
if(doNegate)
|
||||
generator->Negate();
|
||||
/*if(!accept(Token::Identifier))
|
||||
{
|
||||
if(!accept(Token::IntegerConstant))
|
||||
{
|
||||
if(!accept(Token::DecimalConstant))
|
||||
{
|
||||
if(!accept(Token::LeftBracket))
|
||||
{
|
||||
throw ParserExpectException(token, "identifier or constant");
|
||||
}
|
||||
else
|
||||
{
|
||||
expression();
|
||||
expect(Token::RightBracket);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(doNegate)
|
||||
{
|
||||
doNegate = false;
|
||||
generator->Constant("-" + factor);
|
||||
}
|
||||
else
|
||||
generator->Constant(factor);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(doNegate)
|
||||
{
|
||||
doNegate = false;
|
||||
generator->Constant("-" + factor);
|
||||
}
|
||||
else
|
||||
generator->Constant(factor);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
generator->LoadVariable(factor);
|
||||
}
|
||||
if(doNegate)
|
||||
{
|
||||
generator->Negate();
|
||||
}*/
|
||||
}
|
||||
|
||||
/*
|
||||
<variable value> ::= <function call> | identifier | <particle action>
|
||||
<variable value> ::= <function call> | identifier | identifier.property | <particle action>
|
||||
*/
|
||||
void Parser::variableValue()
|
||||
{
|
||||
@ -596,7 +559,17 @@ namespace pim
|
||||
}
|
||||
else
|
||||
{
|
||||
generator->LoadVariable(variable);
|
||||
if(accept(Token::DotSymbol))
|
||||
{
|
||||
std::string property = token.Source;
|
||||
expect(Token::Identifier);
|
||||
generator->LoadVariable(variable);
|
||||
generator->LoadProperty(property);
|
||||
}
|
||||
else
|
||||
{
|
||||
generator->LoadVariable(variable);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -618,8 +591,10 @@ namespace pim
|
||||
}
|
||||
else
|
||||
token = scanner->NextToken();
|
||||
std::cout << "Symbol " << Token::SymbolNames[symbol] << " " << lastToken.Source << std::endl;
|
||||
return true;
|
||||
}
|
||||
std::cout << "Bad Symbol " << Token::SymbolNames[symbol] << " " << token.Source << " (" << token.GetName() << ")" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -160,6 +160,11 @@ namespace pim
|
||||
nextCharacter();
|
||||
return Token(Token::CommaSymbol, ",", cLine);
|
||||
}
|
||||
else if(cChar == '.')
|
||||
{
|
||||
nextCharacter();
|
||||
return Token(Token::DotSymbol, ".", cLine);
|
||||
}
|
||||
else
|
||||
{
|
||||
nextCharacter();
|
||||
|
@ -41,6 +41,7 @@ namespace pim
|
||||
"get",
|
||||
"IDENTIFIER",
|
||||
",",
|
||||
".",
|
||||
"INVALID SYMBOL"
|
||||
};
|
||||
}
|
||||
|
@ -56,6 +56,7 @@ namespace pim
|
||||
Identifier,
|
||||
|
||||
CommaSymbol,
|
||||
DotSymbol,
|
||||
|
||||
InvalidSymbol,
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user