Got past temporary variable deallocation bug. Now working on functions.
This commit is contained in:
@@ -5,6 +5,24 @@
|
||||
*/
|
||||
#include "runtime.h"
|
||||
|
||||
struct subroutine *callStack=nullptr;
|
||||
|
||||
subroutine::subroutine(enum STATES r)
|
||||
{
|
||||
this->ret=r;
|
||||
this->called=callStack;
|
||||
}
|
||||
|
||||
enum STATES subroutine::close()
|
||||
{
|
||||
if (callStack==nullptr) return STACK_UNDERFLOW_ERROR;
|
||||
enum STATES r=callStack->ret;
|
||||
struct subroutine *l=callStack->called;
|
||||
delete callStack;
|
||||
callStack=l;
|
||||
return r;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
unsigned int ret=run();
|
||||
|
||||
@@ -14,9 +14,24 @@ enum STATES:unsigned int
|
||||
{
|
||||
EXIT,
|
||||
UNDEFINED_STATE_ERROR,
|
||||
STACK_UNDERFLOW_ERROR,
|
||||
START
|
||||
};
|
||||
|
||||
class subroutine
|
||||
{
|
||||
struct subroutine *called;
|
||||
enum STATES ret;
|
||||
|
||||
public:
|
||||
static enum STATES close();
|
||||
subroutine(enum STATES r);
|
||||
virtual ~subroutine()
|
||||
{}
|
||||
};
|
||||
|
||||
extern struct subroutine *callStack;
|
||||
|
||||
/* function prototype */
|
||||
unsigned int run();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user