diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/astnode.cpp | 2 | ||||
-rw-r--r-- | src/astnode.h | 2 | ||||
-rw-r--r-- | src/functiondelete.cpp | 20 | ||||
-rw-r--r-- | src/functiondelete.h | 16 | ||||
-rw-r--r-- | src/functionexists.cpp | 19 | ||||
-rw-r--r-- | src/functionexists.h | 16 | ||||
-rw-r--r-- | src/game.cpp | 4 | ||||
-rw-r--r-- | src/gamebuilder.cpp | 3 | ||||
-rw-r--r-- | src/gamestate.cpp | 17 | ||||
-rw-r--r-- | src/parser.l | 2 | ||||
-rw-r--r-- | src/parser.y | 4 |
11 files changed, 30 insertions, 75 deletions
diff --git a/src/astnode.cpp b/src/astnode.cpp index 9a16f43..54e567d 100644 --- a/src/astnode.cpp +++ b/src/astnode.cpp | |||
@@ -48,6 +48,8 @@ Bu::Formatter &operator<<( Bu::Formatter &f, AstNode::Type t ) | |||
48 | case AstNode::tIndex: return f << "tIndex"; | 48 | case AstNode::tIndex: return f << "tIndex"; |
49 | case AstNode::tPop: return f << "tPop"; | 49 | case AstNode::tPop: return f << "tPop"; |
50 | case AstNode::tDeref: return f << "tDeref"; | 50 | case AstNode::tDeref: return f << "tDeref"; |
51 | case AstNode::tExists: return f << "tExists"; | ||
52 | case AstNode::tDelete: return f << "tDelete"; | ||
51 | 53 | ||
52 | case AstNode::tLeafLiteral: return f << "!tLeafLiteral!"; | 54 | case AstNode::tLeafLiteral: return f << "!tLeafLiteral!"; |
53 | case AstNode::tVarName: return f << "tVarName"; | 55 | case AstNode::tVarName: return f << "tVarName"; |
diff --git a/src/astnode.h b/src/astnode.h index e2629cc..73be338 100644 --- a/src/astnode.h +++ b/src/astnode.h | |||
@@ -38,6 +38,8 @@ public: | |||
38 | tIndex = 0x0100001A, | 38 | tIndex = 0x0100001A, |
39 | tPop = 0x0100001B, | 39 | tPop = 0x0100001B, |
40 | tDeref = 0x0100001C, | 40 | tDeref = 0x0100001C, |
41 | tExists = 0x0100001D, | ||
42 | tDelete = 0x0100001E, | ||
41 | 43 | ||
42 | tLeafLiteral = 0x02000000, | 44 | tLeafLiteral = 0x02000000, |
43 | tVarName = 0x02000001, | 45 | tVarName = 0x02000001, |
diff --git a/src/functiondelete.cpp b/src/functiondelete.cpp deleted file mode 100644 index 070ffd4..0000000 --- a/src/functiondelete.cpp +++ /dev/null | |||
@@ -1,20 +0,0 @@ | |||
1 | #include "functiondelete.h" | ||
2 | |||
3 | #include "gamestate.h" | ||
4 | |||
5 | FunctionDelete::FunctionDelete() | ||
6 | { | ||
7 | } | ||
8 | |||
9 | FunctionDelete::~FunctionDelete() | ||
10 | { | ||
11 | } | ||
12 | |||
13 | void FunctionDelete::call( class GameState &gState ) | ||
14 | { | ||
15 | Variable v = gState.pop(); | ||
16 | VariableRef r = v.getVariableRef(); | ||
17 | gState.delVariable( r.sName, r.sid ); | ||
18 | gState.push( Variable( Variable::tNull ) ); | ||
19 | } | ||
20 | |||
diff --git a/src/functiondelete.h b/src/functiondelete.h deleted file mode 100644 index 3545343..0000000 --- a/src/functiondelete.h +++ /dev/null | |||
@@ -1,16 +0,0 @@ | |||
1 | #ifndef FUNCTION_DELETE_H | ||
2 | #define FUNCTION_DELETE_H | ||
3 | |||
4 | #include "function.h" | ||
5 | |||
6 | class FunctionDelete : public Function | ||
7 | { | ||
8 | public: | ||
9 | FunctionDelete(); | ||
10 | virtual ~FunctionDelete(); | ||
11 | |||
12 | virtual Bu::String getName() const { return "delete"; } | ||
13 | virtual void call( class GameState &gState ); | ||
14 | }; | ||
15 | |||
16 | #endif | ||
diff --git a/src/functionexists.cpp b/src/functionexists.cpp deleted file mode 100644 index 71e03f6..0000000 --- a/src/functionexists.cpp +++ /dev/null | |||
@@ -1,19 +0,0 @@ | |||
1 | #include "functionexists.h" | ||
2 | |||
3 | #include "gamestate.h" | ||
4 | |||
5 | FunctionExists::FunctionExists() | ||
6 | { | ||
7 | } | ||
8 | |||
9 | FunctionExists::~FunctionExists() | ||
10 | { | ||
11 | } | ||
12 | |||
13 | void FunctionExists::call( class GameState &gState ) | ||
14 | { | ||
15 | Variable v = gState.pop(); | ||
16 | VariableRef r = v.getVariableRef(); | ||
17 | gState.push( Variable( gState.hasVariable( r.sName, r.sid ) ) ); | ||
18 | } | ||
19 | |||
diff --git a/src/functionexists.h b/src/functionexists.h deleted file mode 100644 index 5313331..0000000 --- a/src/functionexists.h +++ /dev/null | |||
@@ -1,16 +0,0 @@ | |||
1 | #ifndef FUNCTION_EXISTS_H | ||
2 | #define FUNCTION_EXISTS_H | ||
3 | |||
4 | #include "function.h" | ||
5 | |||
6 | class FunctionExists : public Function | ||
7 | { | ||
8 | public: | ||
9 | FunctionExists(); | ||
10 | virtual ~FunctionExists(); | ||
11 | |||
12 | virtual Bu::String getName() const { return "exists"; } | ||
13 | virtual void call( class GameState &gState ); | ||
14 | }; | ||
15 | |||
16 | #endif | ||
diff --git a/src/game.cpp b/src/game.cpp index 37989bd..753f83b 100644 --- a/src/game.cpp +++ b/src/game.cpp | |||
@@ -1,8 +1,6 @@ | |||
1 | #include "game.h" | 1 | #include "game.h" |
2 | 2 | ||
3 | #include "functiondisplay.h" | 3 | #include "functiondisplay.h" |
4 | #include "functionexists.h" | ||
5 | #include "functiondelete.h" | ||
6 | #include "functionexit.h" | 4 | #include "functionexit.h" |
7 | #include "functionrandom.h" | 5 | #include "functionrandom.h" |
8 | #include "functioninteger.h" | 6 | #include "functioninteger.h" |
@@ -16,8 +14,6 @@ Game::Game() | |||
16 | { | 14 | { |
17 | hGlobalParam.insert("start", Variable::newSituationName("start") ); | 15 | hGlobalParam.insert("start", Variable::newSituationName("start") ); |
18 | addFunction( new FunctionDisplay() ); | 16 | addFunction( new FunctionDisplay() ); |
19 | addFunction( new FunctionExists() ); | ||
20 | addFunction( new FunctionDelete() ); | ||
21 | addFunction( new FunctionExit() ); | 17 | addFunction( new FunctionExit() ); |
22 | addFunction( new FunctionRandom() ); | 18 | addFunction( new FunctionRandom() ); |
23 | addFunction( new FunctionInteger() ); | 19 | addFunction( new FunctionInteger() ); |
diff --git a/src/gamebuilder.cpp b/src/gamebuilder.cpp index 857c348..e8ecf63 100644 --- a/src/gamebuilder.cpp +++ b/src/gamebuilder.cpp | |||
@@ -189,6 +189,9 @@ void GameBuilder::stackMod( AstNode::Type iType ) | |||
189 | case AstNode::tNot: | 189 | case AstNode::tNot: |
190 | case AstNode::tNegate: | 190 | case AstNode::tNegate: |
191 | case AstNode::tSwap: | 191 | case AstNode::tSwap: |
192 | case AstNode::tDeref: | ||
193 | case AstNode::tExists: | ||
194 | case AstNode::tDelete: | ||
192 | break; | 195 | break; |
193 | 196 | ||
194 | case AstNode::tComp: | 197 | case AstNode::tComp: |
diff --git a/src/gamestate.cpp b/src/gamestate.cpp index 7b2d228..041af86 100644 --- a/src/gamestate.cpp +++ b/src/gamestate.cpp | |||
@@ -756,6 +756,23 @@ void GameState::parse( const AstBranch::NodeList &lCode ) | |||
756 | push( popDeref() ); | 756 | push( popDeref() ); |
757 | break; | 757 | break; |
758 | 758 | ||
759 | case AstNode::tExists: | ||
760 | { | ||
761 | Variable v = pop(); | ||
762 | VariableRef r = v.getVariableRef(); | ||
763 | push( Variable( hasVariable( r.sName, r.sid ) ) ); | ||
764 | } | ||
765 | break; | ||
766 | |||
767 | case AstNode::tDelete: | ||
768 | { | ||
769 | Variable v = pop(); | ||
770 | VariableRef r = v.getVariableRef(); | ||
771 | delVariable( r.sName, r.sid ); | ||
772 | push( Variable( Variable::tNull ) ); | ||
773 | } | ||
774 | break; | ||
775 | |||
759 | // tLeafLiteral | 776 | // tLeafLiteral |
760 | case AstNode::tVarName: | 777 | case AstNode::tVarName: |
761 | case AstNode::tLiteral: | 778 | case AstNode::tLiteral: |
diff --git a/src/parser.l b/src/parser.l index 7ceee0a..70704b8 100644 --- a/src/parser.l +++ b/src/parser.l | |||
@@ -51,6 +51,8 @@ and { return tokAnd; } | |||
51 | or { return tokOr; } | 51 | or { return tokOr; } |
52 | return { return tokReturn; } | 52 | return { return tokReturn; } |
53 | ignore { return tokIgnore; } | 53 | ignore { return tokIgnore; } |
54 | exists { return tokExists; } | ||
55 | delete { return tokDelete; } | ||
54 | 56 | ||
55 | true { yylval->bValue = true; return tokBool; } | 57 | true { yylval->bValue = true; return tokBool; } |
56 | false { yylval->bValue = false; return tokBool; } | 58 | false { yylval->bValue = false; return tokBool; } |
diff --git a/src/parser.y b/src/parser.y index 024d61a..c5b86ea 100644 --- a/src/parser.y +++ b/src/parser.y | |||
@@ -69,6 +69,8 @@ void yyerror( YYLTYPE *llocp, yyscan_t yyscanner, GameBuilder &, const char *err | |||
69 | %token tokMinusAssign | 69 | %token tokMinusAssign |
70 | %token tokTimesAssign | 70 | %token tokTimesAssign |
71 | %token tokDivideAssign | 71 | %token tokDivideAssign |
72 | %token tokExists | ||
73 | %token tokDelete | ||
72 | %token <sValue> tokSituationName | 74 | %token <sValue> tokSituationName |
73 | %token <sValue> tokIdent | 75 | %token <sValue> tokIdent |
74 | %token tokGoto | 76 | %token tokGoto |
@@ -234,6 +236,8 @@ literal: tokInt { bld.addLiteral( Variable( $1 ) ); } | |||
234 | ; | 236 | ; |
235 | 237 | ||
236 | expr: literal | 238 | expr: literal |
239 | | tokExists '(' varRef ')' { bld.addNode( AstNode::tExists ); } | ||
240 | | tokDelete '(' varRef ')' { bld.addNode( AstNode::tDelete ); } | ||
237 | | tokIdent '(' funcCallParams ')' { bld.addFuncCall( *($1) ); } | 241 | | tokIdent '(' funcCallParams ')' { bld.addFuncCall( *($1) ); } |
238 | | varRef | 242 | | varRef |
239 | | varRef '=' expr { bld.addNode( AstNode::tStore ); } | 243 | | varRef '=' expr { bld.addNode( AstNode::tStore ); } |