Reorganisation of cpp and header files
parent
e011fd66a6
commit
e5089f9b31
|
@ -35,7 +35,7 @@ include_directories("${PROJECT_BINARY_DIR}")
|
|||
set(PROJECT_SRC
|
||||
src/main.cpp
|
||||
src/canvas.cpp
|
||||
src/cursor.cpp
|
||||
src/thread.cpp
|
||||
src/rufunge.cpp
|
||||
)
|
||||
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
#pragma once
|
||||
#include "canvas.hpp"
|
||||
#include "subroutine.hpp"
|
||||
#include <iostream>
|
||||
#include <assert.h>
|
||||
|
||||
enum EDIR {
|
||||
RIGHT,
|
||||
|
@ -73,94 +70,3 @@ public:
|
|||
return (it == operators.end()) ? -1 : it->second;
|
||||
}
|
||||
};
|
||||
|
||||
enum ETHREAD_STATE
|
||||
{
|
||||
ETS_DEAD,
|
||||
ETS_READY,
|
||||
ETS_STRING,
|
||||
ETS_NUMBER
|
||||
};
|
||||
|
||||
class VM;
|
||||
class Thread
|
||||
{
|
||||
public:
|
||||
Cursor *cursor;
|
||||
std::stack<Cursor*> link;
|
||||
std::stack<char> stack;
|
||||
ETHREAD_STATE state = ETS_READY;
|
||||
|
||||
inline void setDir(EDIR dir)
|
||||
{
|
||||
assert(cursor);
|
||||
cursor->dir = dir;
|
||||
}
|
||||
|
||||
inline void move() {
|
||||
assert(cursor);
|
||||
cursor->move();
|
||||
}
|
||||
inline void turnLeft() {
|
||||
assert(cursor);
|
||||
cursor->turnLeft();
|
||||
}
|
||||
inline void turnRight() {
|
||||
assert(cursor);
|
||||
cursor->turnRight();
|
||||
}
|
||||
inline char getChar() {
|
||||
assert(cursor);
|
||||
return cursor->getChar();
|
||||
}
|
||||
|
||||
/// Exits the current cursor and loads the next from the stack
|
||||
///
|
||||
/// @return true on cursors remaining
|
||||
bool popCursor() {
|
||||
delete cursor;
|
||||
cursor = NULL;
|
||||
|
||||
if (link.empty()) {
|
||||
std::cerr << "Popped cursor, end-of-LS" << std::endl;
|
||||
state = ETS_DEAD;
|
||||
return false;
|
||||
} else {
|
||||
cursor = link.top();
|
||||
link.pop();
|
||||
std::cerr << "Popped cursor, " << link.size()
|
||||
<< " remaining in LS" << std::endl;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void pushCursor(Cursor *nc) {
|
||||
if (cursor) {
|
||||
link.push(cursor);
|
||||
}
|
||||
cursor = nc;
|
||||
state = ETS_READY;
|
||||
std::cerr << "Pushed cursor!" << std::endl;
|
||||
}
|
||||
|
||||
char pop() {
|
||||
char retval = 0;
|
||||
if (!stack.empty()) {
|
||||
retval = stack.top();
|
||||
stack.pop();
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
inline void push(char v) {
|
||||
stack.push(v);
|
||||
}
|
||||
|
||||
Thread(Canvas *c)
|
||||
{
|
||||
std::cerr << "Created new thread!" << std::endl;
|
||||
cursor = new Cursor();
|
||||
cursor->canvas = c;
|
||||
}
|
||||
|
||||
void step(VM *vm, std::map<int, Subroutine*> &srman);
|
||||
};
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#pragma once
|
||||
#include "cursor.hpp"
|
||||
#include "thread.hpp"
|
||||
|
||||
class VM
|
||||
{
|
||||
|
|
|
@ -1,4 +1,48 @@
|
|||
#include "cursor.hpp"
|
||||
#include "thread.hpp"
|
||||
|
||||
Thread::Thread(Canvas *c)
|
||||
{
|
||||
std::cerr << "Created new thread!" << std::endl;
|
||||
cursor = new Cursor();
|
||||
cursor->canvas = c;
|
||||
}
|
||||
|
||||
bool Thread::popCursor() {
|
||||
delete cursor;
|
||||
cursor = NULL;
|
||||
|
||||
if (link.empty()) {
|
||||
std::cerr << "Popped cursor, end-of-LS" << std::endl;
|
||||
state = ETS_DEAD;
|
||||
return false;
|
||||
} else {
|
||||
cursor = link.top();
|
||||
link.pop();
|
||||
std::cerr << "Popped cursor, " << link.size()
|
||||
<< " remaining in LS" << std::endl;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void Thread::pushCursor(Cursor *nc) {
|
||||
if (cursor) {
|
||||
link.push(cursor);
|
||||
}
|
||||
cursor = nc;
|
||||
state = ETS_READY;
|
||||
std::cerr << "Pushed cursor!" << std::endl;
|
||||
}
|
||||
|
||||
char Thread::pop() {
|
||||
if (stack.empty()) {
|
||||
return 0;
|
||||
} else {
|
||||
char retval = 0;
|
||||
retval = stack.top();
|
||||
stack.pop();
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
|
||||
void Thread::step(VM *vm, std::map<int, Subroutine*> &srman)
|
||||
{
|
|
@ -0,0 +1,64 @@
|
|||
#pragma once
|
||||
#include "cursor.hpp"
|
||||
#include "subroutine.hpp"
|
||||
#include <iostream>
|
||||
#include <assert.h>
|
||||
|
||||
enum ETHREAD_STATE
|
||||
{
|
||||
ETS_DEAD,
|
||||
ETS_READY,
|
||||
ETS_STRING,
|
||||
ETS_NUMBER
|
||||
};
|
||||
|
||||
class VM;
|
||||
class Thread
|
||||
{
|
||||
public:
|
||||
Cursor *cursor;
|
||||
std::stack<Cursor*> link;
|
||||
std::stack<char> stack;
|
||||
ETHREAD_STATE state = ETS_READY;
|
||||
|
||||
Thread(Canvas *c);
|
||||
|
||||
inline void setDir(EDIR dir)
|
||||
{
|
||||
assert(cursor);
|
||||
cursor->dir = dir;
|
||||
}
|
||||
|
||||
inline void move() {
|
||||
assert(cursor);
|
||||
cursor->move();
|
||||
}
|
||||
inline void turnLeft() {
|
||||
assert(cursor);
|
||||
cursor->turnLeft();
|
||||
}
|
||||
inline void turnRight() {
|
||||
assert(cursor);
|
||||
cursor->turnRight();
|
||||
}
|
||||
inline char getChar() {
|
||||
assert(cursor);
|
||||
return cursor->getChar();
|
||||
}
|
||||
|
||||
/// Exits the current cursor and loads the next from the stack
|
||||
///
|
||||
/// @return true on cursors remaining
|
||||
bool popCursor();
|
||||
|
||||
void pushCursor(Cursor *nc);
|
||||
|
||||
char pop();
|
||||
|
||||
inline void push(char v) {
|
||||
stack.push(v);
|
||||
}
|
||||
|
||||
|
||||
void step(VM *vm, std::map<int, Subroutine*> &srman);
|
||||
};
|
Loading…
Reference in New Issue