From 5ada5cc8c2df8f73fe235f81ed43b6ab44beb743 Mon Sep 17 00:00:00 2001 From: jed Date: Sat, 15 Sep 2012 21:17:50 -0700 Subject: [PATCH] . --- src/Interpreter.cpp | 4 +- src/Operation.h | 96 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 1 deletion(-) diff --git a/src/Interpreter.cpp b/src/Interpreter.cpp index c97b8780c9..dabbb692d1 100644 --- a/src/Interpreter.cpp +++ b/src/Interpreter.cpp @@ -21,7 +21,7 @@ Interpreter::Interpreter() mBlockJump=0; mFunctionTable.resize(NUM_OF_OPS); - /* + mFunctionTable[INT_OP]=new IntOp(); mFunctionTable[FLOAT_OP]=new FloatOp(); mFunctionTable[UINT160_OP]=new Uint160Op(); @@ -47,6 +47,7 @@ Interpreter::Interpreter() mFunctionTable[BLOCK_OP]=new SubOp(); mFunctionTable[BLOCK_END_OP]=new SubOp(); mFunctionTable[SEND_XNS_OP]=new SendXNSOp(); + /* mFunctionTable[SEND_OP]=new SendOp(); mFunctionTable[REMOVE_CONTRACT_OP]=new SubOp(); mFunctionTable[FEE_OP]=new SubOp(); @@ -70,6 +71,7 @@ Interpreter::Interpreter() mFunctionTable[GET_ACCEPTOR_ID_OP]=new GetAcceptorIDOp(); mFunctionTable[GET_CONTRACT_ID_OP]=new GetContractIDOp(); */ + } Data::pointer Interpreter::popStack() diff --git a/src/Operation.h b/src/Operation.h index 9fca2498c4..09f023f6a2 100644 --- a/src/Operation.h +++ b/src/Operation.h @@ -100,6 +100,102 @@ public: } }; +class MulOp : public Operation +{ +public: + bool work(Interpreter* interpreter) + { + Data::pointer data1=interpreter->popStack(); + Data::pointer data2=interpreter->popStack(); + if( (data1->isInt32() || data1->isFloat()) && + (data2->isInt32() || data2->isFloat()) ) + { + if(data1->isFloat() || data2->isFloat()) interpreter->pushStack(Data::pointer(new FloatData(data1->getFloat()*data2->getFloat()))); + else interpreter->pushStack(Data::pointer(new IntData(data1->getInt()*data2->getInt()))); + return(true); + }else + { + return(false); + } + } +}; + +class DivOp : public Operation +{ +public: + bool work(Interpreter* interpreter) + { + Data::pointer data1=interpreter->popStack(); + Data::pointer data2=interpreter->popStack(); + if( (data1->isInt32() || data1->isFloat()) && + (data2->isInt32() || data2->isFloat()) ) + { + if(data1->isFloat() || data2->isFloat()) interpreter->pushStack(Data::pointer(new FloatData(data1->getFloat()/data2->getFloat()))); + else interpreter->pushStack(Data::pointer(new IntData(data1->getInt()/data2->getInt()))); + return(true); + }else + { + return(false); + } + } +}; + +class GtrOp : public Operation +{ +public: + bool work(Interpreter* interpreter) + { + Data::pointer data1=interpreter->popStack(); + Data::pointer data2=interpreter->popStack(); + if( (data1->isInt32() || data1->isFloat()) && + (data2->isInt32() || data2->isFloat()) ) + { + interpreter->pushStack(Data::pointer(new BoolData(data1->getFloat()>data2->getFloat()))); + return(true); + }else + { + return(false); + } + } +}; + +class LessOp : public Operation +{ +public: + bool work(Interpreter* interpreter) + { + Data::pointer data1=interpreter->popStack(); + Data::pointer data2=interpreter->popStack(); + if( (data1->isInt32() || data1->isFloat()) && + (data2->isInt32() || data2->isFloat()) ) + { + interpreter->pushStack(Data::pointer(new FloatData(data1->getFloat()getFloat()))); + return(true); + }else + { + return(false); + } + } +}; + +class ModOp : public Operation +{ +public: + bool work(Interpreter* interpreter) + { + Data::pointer data1=interpreter->popStack(); + Data::pointer data2=interpreter->popStack(); + if( data1->isInt32() && data2->isInt32() ) + { + interpreter->pushStack(Data::pointer(new IntData(data1->getInt()%data2->getInt()))); + return(true); + }else + { + return(false); + } + } +}; + class StartBlockOp : public Operation {