summaryrefslogtreecommitdiff
path: root/src/pim
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-09-21 20:21:03 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-09-21 20:21:03 (GMT)
commit644c1307124dffd13268445d0aebaed13a090c78 (patch)
treee0d1ba738b7adbb484ba6d1fb3ae094e0c94b610 /src/pim
parent939a04d3c77bf9aa8d54e912f5e12817de51756c (diff)
downloadpowder-644c1307124dffd13268445d0aebaed13a090c78.zip
powder-644c1307124dffd13268445d0aebaed13a090c78.tar.gz
Set properties with integer.property
Diffstat (limited to 'src/pim')
-rw-r--r--src/pim/Generator.cpp11
-rw-r--r--src/pim/Generator.h7
-rw-r--r--src/pim/Machine.cpp9
-rw-r--r--src/pim/Machine.h1
-rw-r--r--src/pim/Opcodes.inl2
-rw-r--r--src/pim/Parser.cpp83
-rw-r--r--src/pim/Scanner.cpp5
-rw-r--r--src/pim/Token.cpp1
-rw-r--r--src/pim/Token.h1
9 files changed, 65 insertions, 55 deletions
diff --git a/src/pim/Generator.cpp b/src/pim/Generator.cpp
index b2ea84c..8228c1c 100644
--- a/src/pim/Generator.cpp
+++ b/src/pim/Generator.cpp
@@ -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()
{
diff --git a/src/pim/Generator.h b/src/pim/Generator.h
index 0121c13..0287339 100644
--- a/src/pim/Generator.h
+++ b/src/pim/Generator.h
@@ -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();
diff --git a/src/pim/Machine.cpp b/src/pim/Machine.cpp
index 4c07514..a112363 100644
--- a/src/pim/Machine.cpp
+++ b/src/pim/Machine.cpp
@@ -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;
diff --git a/src/pim/Machine.h b/src/pim/Machine.h
index dcaef92..a40dd51 100644
--- a/src/pim/Machine.h
+++ b/src/pim/Machine.h
@@ -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
diff --git a/src/pim/Opcodes.inl b/src/pim/Opcodes.inl
index 3c18da5..4b28294 100644
--- a/src/pim/Opcodes.inl
+++ b/src/pim/Opcodes.inl
@@ -15,6 +15,8 @@ OPDEF(Transform)
OPDEF(Get)
OPDEF(Position)
OPDEF(Kill)
+OPDEF(LoadProperty)
+OPDEF(StoreProperty)
OPDEF(JumpEqual)
OPDEF(JumpNotEqual)
OPDEF(JumpGreater)
diff --git a/src/pim/Parser.cpp b/src/pim/Parser.cpp
index 75af21d..378a252 100644
--- a/src/pim/Parser.cpp
+++ b/src/pim/Parser.cpp
@@ -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;
}
diff --git a/src/pim/Scanner.cpp b/src/pim/Scanner.cpp
index 32e64d0..7aba994 100644
--- a/src/pim/Scanner.cpp
+++ b/src/pim/Scanner.cpp
@@ -160,6 +160,11 @@ namespace pim
nextCharacter();
return Token(Token::CommaSymbol, ",", cLine);
}
+ else if(cChar == '.')
+ {
+ nextCharacter();
+ return Token(Token::DotSymbol, ".", cLine);
+ }
else
{
nextCharacter();
diff --git a/src/pim/Token.cpp b/src/pim/Token.cpp
index 2db451e..1741af0 100644
--- a/src/pim/Token.cpp
+++ b/src/pim/Token.cpp
@@ -41,6 +41,7 @@ namespace pim
"get",
"IDENTIFIER",
",",
+ ".",
"INVALID SYMBOL"
};
}
diff --git a/src/pim/Token.h b/src/pim/Token.h
index 6a80f49..42e0bc2 100644
--- a/src/pim/Token.h
+++ b/src/pim/Token.h
@@ -56,6 +56,7 @@ namespace pim
Identifier,
CommaSymbol,
+ DotSymbol,
InvalidSymbol,