From 9665eda348e3e2fa8ac32fdc26d1c0b0eb65b432 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 6 Feb 2012 21:06:13 -0700 Subject: exists() and delete() are now operators. --- src/astnode.cpp | 2 ++ src/astnode.h | 2 ++ src/functiondelete.cpp | 20 -------------------- src/functiondelete.h | 16 ---------------- src/functionexists.cpp | 19 ------------------- src/functionexists.h | 16 ---------------- src/game.cpp | 4 ---- src/gamebuilder.cpp | 3 +++ src/gamestate.cpp | 17 +++++++++++++++++ src/parser.l | 2 ++ src/parser.y | 4 ++++ 11 files changed, 30 insertions(+), 75 deletions(-) delete mode 100644 src/functiondelete.cpp delete mode 100644 src/functiondelete.h delete mode 100644 src/functionexists.cpp delete mode 100644 src/functionexists.h 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 ) case AstNode::tIndex: return f << "tIndex"; case AstNode::tPop: return f << "tPop"; case AstNode::tDeref: return f << "tDeref"; + case AstNode::tExists: return f << "tExists"; + case AstNode::tDelete: return f << "tDelete"; case AstNode::tLeafLiteral: return f << "!tLeafLiteral!"; 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: tIndex = 0x0100001A, tPop = 0x0100001B, tDeref = 0x0100001C, + tExists = 0x0100001D, + tDelete = 0x0100001E, tLeafLiteral = 0x02000000, 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 @@ -#include "functiondelete.h" - -#include "gamestate.h" - -FunctionDelete::FunctionDelete() -{ -} - -FunctionDelete::~FunctionDelete() -{ -} - -void FunctionDelete::call( class GameState &gState ) -{ - Variable v = gState.pop(); - VariableRef r = v.getVariableRef(); - gState.delVariable( r.sName, r.sid ); - gState.push( Variable( Variable::tNull ) ); -} - 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 @@ -#ifndef FUNCTION_DELETE_H -#define FUNCTION_DELETE_H - -#include "function.h" - -class FunctionDelete : public Function -{ -public: - FunctionDelete(); - virtual ~FunctionDelete(); - - virtual Bu::String getName() const { return "delete"; } - virtual void call( class GameState &gState ); -}; - -#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 @@ -#include "functionexists.h" - -#include "gamestate.h" - -FunctionExists::FunctionExists() -{ -} - -FunctionExists::~FunctionExists() -{ -} - -void FunctionExists::call( class GameState &gState ) -{ - Variable v = gState.pop(); - VariableRef r = v.getVariableRef(); - gState.push( Variable( gState.hasVariable( r.sName, r.sid ) ) ); -} - 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 @@ -#ifndef FUNCTION_EXISTS_H -#define FUNCTION_EXISTS_H - -#include "function.h" - -class FunctionExists : public Function -{ -public: - FunctionExists(); - virtual ~FunctionExists(); - - virtual Bu::String getName() const { return "exists"; } - virtual void call( class GameState &gState ); -}; - -#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 @@ #include "game.h" #include "functiondisplay.h" -#include "functionexists.h" -#include "functiondelete.h" #include "functionexit.h" #include "functionrandom.h" #include "functioninteger.h" @@ -16,8 +14,6 @@ Game::Game() { hGlobalParam.insert("start", Variable::newSituationName("start") ); addFunction( new FunctionDisplay() ); - addFunction( new FunctionExists() ); - addFunction( new FunctionDelete() ); addFunction( new FunctionExit() ); addFunction( new FunctionRandom() ); 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 ) case AstNode::tNot: case AstNode::tNegate: case AstNode::tSwap: + case AstNode::tDeref: + case AstNode::tExists: + case AstNode::tDelete: break; 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 ) push( popDeref() ); break; + case AstNode::tExists: + { + Variable v = pop(); + VariableRef r = v.getVariableRef(); + push( Variable( hasVariable( r.sName, r.sid ) ) ); + } + break; + + case AstNode::tDelete: + { + Variable v = pop(); + VariableRef r = v.getVariableRef(); + delVariable( r.sName, r.sid ); + push( Variable( Variable::tNull ) ); + } + break; + // tLeafLiteral case AstNode::tVarName: 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; } or { return tokOr; } return { return tokReturn; } ignore { return tokIgnore; } +exists { return tokExists; } +delete { return tokDelete; } true { yylval->bValue = true; return tokBool; } 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 %token tokMinusAssign %token tokTimesAssign %token tokDivideAssign +%token tokExists +%token tokDelete %token tokSituationName %token tokIdent %token tokGoto @@ -234,6 +236,8 @@ literal: tokInt { bld.addLiteral( Variable( $1 ) ); } ; expr: literal + | tokExists '(' varRef ')' { bld.addNode( AstNode::tExists ); } + | tokDelete '(' varRef ')' { bld.addNode( AstNode::tDelete ); } | tokIdent '(' funcCallParams ')' { bld.addFuncCall( *($1) ); } | varRef | varRef '=' expr { bld.addNode( AstNode::tStore ); } -- cgit v1.2.3