Choices rewritten, lists being worked on
This commit is contained in:
parent
9dc8a90ecd
commit
c6f9707d79
@ -7,6 +7,7 @@ namespace dms {
|
|||||||
std::string fname = "";
|
std::string fname = "";
|
||||||
std::string lname = "";
|
std::string lname = "";
|
||||||
bool seen = false;
|
bool seen = false;
|
||||||
|
double spd = 100;
|
||||||
std::unordered_map<std::string, std::string> paths;
|
std::unordered_map<std::string, std::string> paths;
|
||||||
std::unordered_map<std::string, value*> values;
|
std::unordered_map<std::string, value*> values;
|
||||||
};
|
};
|
||||||
|
|||||||
20
DMS/DMS.cpp
20
DMS/DMS.cpp
@ -4,16 +4,14 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
using namespace dms;
|
using namespace dms;
|
||||||
// You can use your own choice handler!
|
// You can use your own choice handler!
|
||||||
class myChoi : public choiceHandler {
|
class myHandler : public Handler {
|
||||||
uint8_t manageChoice(dms_state* state, dms_args choices) const override {
|
uint8_t manageChoice(dms_state* state, std::string prompt, std::vector<std::string> args) const override {
|
||||||
uint8_t count = choices.args.size();
|
std::string pos;
|
||||||
uint8_t pos;
|
for (size_t i = 0; i < args.size(); i++)
|
||||||
std::string prompt = choices.args[0]->s->getValue();
|
std::cout << i << ": " << args[i] << std::endl;
|
||||||
for (size_t i = 1; i < count; i++)
|
std::cout << prompt << " ";
|
||||||
std::cout << i << ": " << choices.args[i]->s->getValue() << std::endl;
|
|
||||||
std::cout << prompt;
|
|
||||||
std::cin >> pos;
|
std::cin >> pos;
|
||||||
return pos;
|
return std::stoi(pos) - 1;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
int main()
|
int main()
|
||||||
@ -21,12 +19,12 @@ int main()
|
|||||||
LineParser parser = LineParser("test.dms");
|
LineParser parser = LineParser("test.dms");
|
||||||
dms_state* state = parser.Parse();
|
dms_state* state = parser.Parse();
|
||||||
try {
|
try {
|
||||||
//state->setChoiceHandler(new myChoi);
|
//state->setHandler(new myHandler);
|
||||||
}
|
}
|
||||||
catch (std::exception& e) {
|
catch (std::exception& e) {
|
||||||
std::cout << e.what() << '\n';
|
std::cout << e.what() << '\n';
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
//state->dump();
|
state->dump();
|
||||||
state->run();
|
state->run();
|
||||||
}
|
}
|
||||||
@ -1,13 +1,21 @@
|
|||||||
#include "Handlers.h"
|
#include "Handlers.h"
|
||||||
namespace dms {
|
namespace dms {
|
||||||
uint8_t choiceHandler::manageChoice(dms_state* state, dms_args choices) const {
|
uint8_t Handler::manageChoice(dms_state* state, std::string prompt, std::vector<std::string> args) const {
|
||||||
uint8_t count = choices.args.size();
|
|
||||||
std::string pos;
|
std::string pos;
|
||||||
std::string prompt = choices.args[0]->s->getValue();
|
for (size_t i = 0; i < args.size(); i++)
|
||||||
for (size_t i = 1; i < count; i++)
|
std::cout << i+1 << ": " << args[i] << std::endl;
|
||||||
std::cout << i << ": " << choices.args[i]->s->getValue() << std::endl;
|
|
||||||
std::cout << prompt << " ";
|
std::cout << prompt << " ";
|
||||||
std::cin >> pos;
|
std::cin >> pos;
|
||||||
return std::stoi(pos)-1;
|
try {
|
||||||
|
if (std::stoi(pos) > 0 && std::stoi(pos) < args.size())
|
||||||
|
return std::stoi(pos) - 1;
|
||||||
|
else
|
||||||
|
throw exceptions::InvalidChoice();
|
||||||
|
}
|
||||||
|
catch (std::exception e) {
|
||||||
|
std::cout << "Invalid Choice!" << std::endl;
|
||||||
|
return manageChoice(state,prompt,args);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,10 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "value.h"
|
#include "value.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "Character.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
namespace dms {
|
namespace dms {
|
||||||
struct choiceHandler
|
struct Handler
|
||||||
{
|
{
|
||||||
virtual uint8_t manageChoice(dms_state* state, dms_args choices) const;
|
virtual uint8_t manageChoice(dms_state* state, std::string prompt, std::vector<std::string> args) const;
|
||||||
|
//virtual bool manageSpeaker(dms_state* state, character* chara) const;
|
||||||
|
//virtual bool manageMessage(dms_state* state, value* msg) const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -94,6 +94,7 @@ namespace dms {
|
|||||||
bool isBlock(blocktype bk_type);
|
bool isBlock(blocktype bk_type);
|
||||||
void tolower(std::string &str);
|
void tolower(std::string &str);
|
||||||
void tokenizer(dms_state* state, std::vector<tokens::token> &tok);
|
void tokenizer(dms_state* state, std::vector<tokens::token> &tok);
|
||||||
|
void debugInvoker(tokenstream* stream);
|
||||||
public:
|
public:
|
||||||
//Refer to streams.cpp for the match_process_CMD code.
|
//Refer to streams.cpp for the match_process_CMD code.
|
||||||
dms_state* Parse();
|
dms_state* Parse();
|
||||||
|
|||||||
@ -72,6 +72,7 @@ namespace dms {
|
|||||||
current_chunk->addCmd(c);
|
current_chunk->addCmd(c);
|
||||||
bool ready = true;
|
bool ready = true;
|
||||||
while (tempstream.peek().type != tokens::none) {
|
while (tempstream.peek().type != tokens::none) {
|
||||||
|
debugInvoker(stream);
|
||||||
if (tempstream.match(tokens::cbracketc)) {
|
if (tempstream.match(tokens::cbracketc)) {
|
||||||
ready = true;
|
ready = true;
|
||||||
c = new cmd;
|
c = new cmd;
|
||||||
@ -184,6 +185,7 @@ namespace dms {
|
|||||||
stream->next();
|
stream->next();
|
||||||
stream->next();
|
stream->next();
|
||||||
while (stream->peek().type != tokens::cbracketc) {
|
while (stream->peek().type != tokens::cbracketc) {
|
||||||
|
debugInvoker(stream);
|
||||||
if (stream->match(tokens::name)) {
|
if (stream->match(tokens::name)) {
|
||||||
std::string mode = stream->next().name;
|
std::string mode = stream->next().name;
|
||||||
if (mode == "speed") {
|
if (mode == "speed") {
|
||||||
@ -302,9 +304,12 @@ namespace dms {
|
|||||||
std::string option;
|
std::string option;
|
||||||
cmd* c = new cmd;
|
cmd* c = new cmd;
|
||||||
// Create a unique label name by using the line number
|
// Create a unique label name by using the line number
|
||||||
std::string choicelabel = concat("$CHOI_END_", stream->peek().line_num);
|
int CHOI_ID = 0;
|
||||||
|
std::string choi_str = concat("CHOI_", fn);
|
||||||
|
std::string choicelabel = concat("$CHOI_END_", choi_str,"_", stream->peek().line_num);
|
||||||
c->opcode = codes::CHOI;
|
c->opcode = codes::CHOI;
|
||||||
c->args.push(buildValue(prompt));
|
c->args.push(buildValue(prompt));
|
||||||
|
c->args.push(buildValue(fn));
|
||||||
current_chunk->addCmd(c); // We will keep a reference to this and add to it as we go through the list
|
current_chunk->addCmd(c); // We will keep a reference to this and add to it as we go through the list
|
||||||
bool start = false;
|
bool start = false;
|
||||||
bool hasfunc = false;
|
bool hasfunc = false;
|
||||||
@ -340,6 +345,10 @@ namespace dms {
|
|||||||
If we are provided with a number greater than 3 then we can push an execption.
|
If we are provided with a number greater than 3 then we can push an execption.
|
||||||
*/
|
*/
|
||||||
while (!stream->match(tokens::cbracketc)) {
|
while (!stream->match(tokens::cbracketc)) {
|
||||||
|
debugInvoker(stream);
|
||||||
|
if (start && !stream->match(tokens::newline)) {
|
||||||
|
buildLabel(concat(choi_str,"_", CHOI_ID++));
|
||||||
|
}
|
||||||
if (stream->match(tokens::cbracketo) && !start) {
|
if (stream->match(tokens::cbracketo) && !start) {
|
||||||
start = true;
|
start = true;
|
||||||
stream->next();
|
stream->next();
|
||||||
@ -357,15 +366,9 @@ namespace dms {
|
|||||||
hasfunc = true;
|
hasfunc = true;
|
||||||
buildGoto(choicelabel);
|
buildGoto(choicelabel);
|
||||||
}
|
}
|
||||||
else if (match_process_goto(stream)) {
|
else if (match_process_goto(stream)) {}
|
||||||
buildNoop(); // Add noop to post-goto command
|
else if (match_process_jump(stream)) {}
|
||||||
}
|
else if (match_process_exit(stream)) {}
|
||||||
else if (match_process_jump(stream)) {
|
|
||||||
buildNoop(); // Add noop to post-jump command
|
|
||||||
}
|
|
||||||
else if (match_process_exit(stream)) {
|
|
||||||
buildNoop(); // Add noop to post-exit command
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Last Match
|
// Last Match
|
||||||
else if (stream->match(tokens::newline)) {
|
else if (stream->match(tokens::newline)) {
|
||||||
@ -459,6 +462,7 @@ namespace dms {
|
|||||||
value* ref = buildVariable();
|
value* ref = buildVariable();
|
||||||
// This part we add values to the opcodes for the bytecode FUNC val a1 a2 a3 ... an
|
// This part we add values to the opcodes for the bytecode FUNC val a1 a2 a3 ... an
|
||||||
while (tempstream.peek().type != tokens::none) { // End of stream
|
while (tempstream.peek().type != tokens::none) { // End of stream
|
||||||
|
debugInvoker(stream);
|
||||||
tempval = buildVariable();
|
tempval = buildVariable();
|
||||||
tok = tempstream.peek();
|
tok = tempstream.peek();
|
||||||
if (tempstream.match(tokens::seperator)) {
|
if (tempstream.match(tokens::seperator)) {
|
||||||
@ -600,6 +604,7 @@ namespace dms {
|
|||||||
size_t loops = 0;
|
size_t loops = 0;
|
||||||
bool hasOP = false;
|
bool hasOP = false;
|
||||||
while (stream->peek().type != tokens::none) {
|
while (stream->peek().type != tokens::none) {
|
||||||
|
debugInvoker(stream);
|
||||||
if (stream->match(tokens::parao)) {
|
if (stream->match(tokens::parao)) {
|
||||||
tokenstream temp;
|
tokenstream temp;
|
||||||
temp.init(&(stream->next(tokens::parao, tokens::parac))); // Balanced match!
|
temp.init(&(stream->next(tokens::parao, tokens::parac))); // Balanced match!
|
||||||
|
|||||||
@ -35,7 +35,7 @@ namespace dms {
|
|||||||
rawdata << line << ";\n";
|
rawdata << line << ";\n";
|
||||||
}
|
}
|
||||||
myfile.close();
|
myfile.close();
|
||||||
//std::cout << rawdata.str() << std::endl;
|
fn = file;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
std::cout << "Unable to open file";
|
std::cout << "Unable to open file";
|
||||||
@ -331,15 +331,14 @@ namespace dms {
|
|||||||
token current = stream->next();
|
token current = stream->next();
|
||||||
createBlock("$INIT", blocktype::bt_block);
|
createBlock("$INIT", blocktype::bt_block);
|
||||||
cmd* flagcmd = new cmd;
|
cmd* flagcmd = new cmd;
|
||||||
size_t current_line = 0;
|
if (state->isEnabled("debugging")) {
|
||||||
|
cmd* c = new cmd;
|
||||||
|
c->opcode = codes::FILE;
|
||||||
|
c->args.push(buildValue(fn));
|
||||||
|
current_chunk->addCmd(c);
|
||||||
|
}
|
||||||
while (stream->peek().type != tokens::eof) {
|
while (stream->peek().type != tokens::eof) {
|
||||||
if (stream->peek().line_num != current_line) {
|
debugInvoker(stream);
|
||||||
current_line = stream->peek().line_num;
|
|
||||||
cmd* ln = new cmd;
|
|
||||||
ln->opcode = codes::LINE;
|
|
||||||
ln->args.push(buildValue((int)current_line+1));
|
|
||||||
current_chunk->addCmd(ln);
|
|
||||||
}
|
|
||||||
if (current.type == tokens::flag) {
|
if (current.type == tokens::flag) {
|
||||||
temp = stream->next(tokens::newline);
|
temp = stream->next(tokens::newline);
|
||||||
stream->prev(); // Unconsume the newline piece
|
stream->prev(); // Unconsume the newline piece
|
||||||
|
|||||||
@ -215,6 +215,20 @@ namespace dms {
|
|||||||
c->args.push(buildValue(w));
|
c->args.push(buildValue(w));
|
||||||
current_chunk->addCmd(c);
|
current_chunk->addCmd(c);
|
||||||
}
|
}
|
||||||
|
void LineParser::debugInvoker(tokenstream* stream) {
|
||||||
|
if (state->isEnabled("debugging") && stream->peek().type != tokens::newline) {
|
||||||
|
// A very nasty if statement, I won't hide it, this could be made much more readable
|
||||||
|
// This checks if the last cmd is a LINE cmd and if its the same line number as the current one we simply skip it
|
||||||
|
if (current_chunk->cmds.size() >= 2 && current_chunk->cmds[current_chunk->cmds.size() - 1]!=nullptr && current_chunk->cmds[current_chunk->cmds.size() - 1]->opcode==codes::LINE && (size_t)current_chunk->cmds[current_chunk->cmds.size()-1]->args.args[0]->n->getValue()== (size_t)stream->peek().line_num) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int current_line = stream->peek().line_num;
|
||||||
|
cmd* ln = new cmd;
|
||||||
|
ln->opcode = codes::LINE;
|
||||||
|
ln->args.push(buildValue(current_line));
|
||||||
|
current_chunk->addCmd(ln);
|
||||||
|
}
|
||||||
|
}
|
||||||
bool LineParser::createBlock(std::string bk_name, blocktype bk_type) {
|
bool LineParser::createBlock(std::string bk_name, blocktype bk_type) {
|
||||||
if (current_chunk != nullptr) {
|
if (current_chunk != nullptr) {
|
||||||
if (state->chunks.count(bk_name)==0 && bk_name!="$END")
|
if (state->chunks.count(bk_name)==0 && bk_name!="$END")
|
||||||
|
|||||||
@ -45,5 +45,6 @@ const std::string dms::codes::list[] = {
|
|||||||
"MOD",
|
"MOD",
|
||||||
"LIST",
|
"LIST",
|
||||||
"LINE",
|
"LINE",
|
||||||
"HALT"
|
"HALT",
|
||||||
|
"FILE"
|
||||||
};
|
};
|
||||||
@ -48,6 +48,7 @@ namespace dms::codes {
|
|||||||
LIST,
|
LIST,
|
||||||
LINE,
|
LINE,
|
||||||
HALT,
|
HALT,
|
||||||
|
FILE
|
||||||
};
|
};
|
||||||
extern const std::string list[];
|
extern const std::string list[];
|
||||||
static bool isControl(const op code) {
|
static bool isControl(const op code) {
|
||||||
|
|||||||
@ -11,5 +11,10 @@ namespace dms::exceptions {
|
|||||||
return "ChoiceHandler Expected got ???";
|
return "ChoiceHandler Expected got ???";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
struct InvalidChoice : public std::exception {
|
||||||
|
const char* what() const throw () {
|
||||||
|
return "Invalid Choice!";
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,7 @@ namespace dms {
|
|||||||
cc->args.push(buildValue(0));
|
cc->args.push(buildValue(0));
|
||||||
c->addCmd(cc);
|
c->addCmd(cc);
|
||||||
push_chunk("$END", c);
|
push_chunk("$END", c);
|
||||||
setChoiceHandler(new choiceHandler); // Use the default implementation
|
setHandler(new Handler); // Use the default implementation
|
||||||
}
|
}
|
||||||
bool dms_state::characterExists(std::string bk_name) {
|
bool dms_state::characterExists(std::string bk_name) {
|
||||||
return (chunks.count(bk_name) && chunks[bk_name]->type == blocktype::bt_character);
|
return (chunks.count(bk_name) && chunks[bk_name]->type == blocktype::bt_character);
|
||||||
@ -49,6 +49,22 @@ namespace dms {
|
|||||||
}
|
}
|
||||||
outputFile.close();
|
outputFile.close();
|
||||||
}
|
}
|
||||||
|
bool dms_state::assign(value* var, value* val) {
|
||||||
|
if (memory.count(var->s->getValue()) == 0) {
|
||||||
|
memory.insert_or_assign(var->s->getValue(), val);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
value* temp = memory[var->s->getValue()];
|
||||||
|
if (temp->type != datatypes::variable) {
|
||||||
|
temp->set(); // Set the removed value to nil
|
||||||
|
garbage.push_back(memory[var->s->getValue()]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
utils::print("> so we have a variable"); // This print should be a reminder for me to do something about this.
|
||||||
|
memory[var->s->getValue()] = val;
|
||||||
|
}
|
||||||
|
}
|
||||||
void dms_state::dump() {
|
void dms_state::dump() {
|
||||||
std::cout << "Number of chunks: " << chunks.size() << std::endl;
|
std::cout << "Number of chunks: " << chunks.size() << std::endl;
|
||||||
std::ofstream outputFile("dump.bin");
|
std::ofstream outputFile("dump.bin");
|
||||||
@ -62,7 +78,12 @@ namespace dms {
|
|||||||
chunks.insert_or_assign(s, c);
|
chunks.insert_or_assign(s, c);
|
||||||
}
|
}
|
||||||
void dms_state::push_error(errors::error err) {
|
void dms_state::push_error(errors::error err) {
|
||||||
std::cout << err.err_msg << " On Line <" << err.linenum << ">" << std::endl;
|
if (isEnabled("debugging")) {
|
||||||
|
std::cout << err.err_msg << " On Line <" << cur_line << ">" << std::endl;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
std::cout << err.err_msg << std::endl;
|
||||||
|
}
|
||||||
this->err = err;
|
this->err = err;
|
||||||
if (err.crash)
|
if (err.crash)
|
||||||
stop = true;
|
stop = true;
|
||||||
|
|||||||
@ -15,13 +15,15 @@
|
|||||||
namespace dms {
|
namespace dms {
|
||||||
struct dms_state
|
struct dms_state
|
||||||
{
|
{
|
||||||
void* choi = nullptr;
|
void* handler = nullptr;
|
||||||
std::unordered_map<std::string, value*> memory;
|
std::unordered_map<std::string, value*> memory;
|
||||||
std::vector<value*> garbage;
|
std::vector<value*> garbage;
|
||||||
std::map<std::string, chunk*> chunks;
|
std::map<std::string, chunk*> chunks;
|
||||||
std::map<std::string, character*> characters;
|
std::map<std::string, character*> characters;
|
||||||
|
std::map<std::string, size_t> labels;
|
||||||
std::string entry = "$undefined";
|
std::string entry = "$undefined";
|
||||||
std::map<std::string, bool> enables;
|
std::map<std::string, bool> enables;
|
||||||
|
std::size_t cur_line=0;
|
||||||
const double Iversion = 1.0;
|
const double Iversion = 1.0;
|
||||||
double Cversion; // The version of
|
double Cversion; // The version of
|
||||||
errors::error err;
|
errors::error err;
|
||||||
@ -38,9 +40,11 @@ namespace dms {
|
|||||||
void enable(std::string flag);
|
void enable(std::string flag);
|
||||||
void disable(std::string flag);
|
void disable(std::string flag);
|
||||||
bool isEnabled(std::string flag);
|
bool isEnabled(std::string flag);
|
||||||
void setChoiceHandler(void* choi);
|
void setHandler(void* hand);
|
||||||
|
|
||||||
// Gets or creates a character
|
// Gets or creates a character
|
||||||
|
bool assign(value* var, value* val);
|
||||||
|
size_t seek(std::string label,std::vector<cmd*> cmds ,codes::op code, size_t pos);
|
||||||
character* getCharacter(std::string c);
|
character* getCharacter(std::string c);
|
||||||
bool characterExists(std::string bk_name);
|
bool characterExists(std::string bk_name);
|
||||||
bool blockExists(std::string bk_name);
|
bool blockExists(std::string bk_name);
|
||||||
|
|||||||
@ -7,8 +7,8 @@ using namespace dms::exceptions;
|
|||||||
using namespace dms::codes;
|
using namespace dms::codes;
|
||||||
namespace dms {
|
namespace dms {
|
||||||
// This is a pointer to a choicehandler! dms_state and utils have codepedencies, so I have to do this.
|
// This is a pointer to a choicehandler! dms_state and utils have codepedencies, so I have to do this.
|
||||||
void dms_state::setChoiceHandler(void* choi) {
|
void dms_state::setHandler(void* hand) {
|
||||||
this->choi = choi;
|
this->handler = hand;
|
||||||
}
|
}
|
||||||
character* dms_state::getCharacter(std::string cha) {
|
character* dms_state::getCharacter(std::string cha) {
|
||||||
if (characters.count(cha)) {
|
if (characters.count(cha)) {
|
||||||
@ -61,12 +61,19 @@ namespace dms {
|
|||||||
return cc;
|
return cc;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
push_error(errors::error{ errors::non_existing_block ,utils::concat("Attempted to index a non existing character!") });
|
push_error(errors::error{ errors::non_existing_block ,utils::concat("Attempted to index a non existing character block!") });
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
size_t dms_state::seek(std::string label, std::vector<cmd*> cmds, codes::op code, size_t pos) {
|
||||||
|
for (size_t i = pos; i < cmds.size(); i++) {
|
||||||
|
if (cmds[i]->opcode == code && cmds[i]->args.args[0]->s->getValue() == label)
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
void dms_state::init(chunk* chunk, size_t& pos, size_t& max, std::vector<cmd*>& cmds) {
|
void dms_state::init(chunk* chunk, size_t& pos, size_t& max, std::vector<cmd*>& cmds) {
|
||||||
pos = 0;
|
pos = 0;
|
||||||
max = chunk->cmds.size();
|
max = chunk->cmds.size();
|
||||||
@ -86,7 +93,7 @@ namespace dms {
|
|||||||
size_t max = 0;
|
size_t max = 0;
|
||||||
std::vector<cmd*> cmds;
|
std::vector<cmd*> cmds;
|
||||||
if (chunks[entry] == NULL) {
|
if (chunks[entry] == NULL) {
|
||||||
push_error(errors::error{errors::non_existing_block ,utils::concat("Attempted to Jump to a non existing block <",entry,">")});
|
push_error(errors::error{errors::non_existing_block ,utils::concat("Attempted to Jump to a non existing block [",entry,"]")});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
init(chunks["$INIT"],pos,max,cmds);
|
init(chunks["$INIT"],pos,max,cmds);
|
||||||
@ -99,8 +106,8 @@ namespace dms {
|
|||||||
while (!stop || !halt) {
|
while (!stop || !halt) {
|
||||||
c = cmds[pos++];
|
c = cmds[pos++];
|
||||||
code = c->opcode;
|
code = c->opcode;
|
||||||
//utils::print("> ",*c);
|
//print("\n(",pos,")> ",*c);
|
||||||
//utils::wait();
|
//wait();
|
||||||
switch (code)
|
switch (code)
|
||||||
{
|
{
|
||||||
// Handle flags here
|
// Handle flags here
|
||||||
@ -124,8 +131,33 @@ namespace dms {
|
|||||||
// How we add modules into the code. This is the code that actually loads that data!
|
// How we add modules into the code. This is the code that actually loads that data!
|
||||||
break;
|
break;
|
||||||
// Flags handled
|
// Flags handled
|
||||||
|
case LIST:
|
||||||
|
//We need to create an enviroment value then set that
|
||||||
|
{
|
||||||
|
dms_env* env = new dms_env;
|
||||||
|
env->hpart.insert_or_assign("$size", c->args.args[1]);
|
||||||
|
value* val = new value;
|
||||||
|
val->set(env);
|
||||||
|
assign(c->args.args[0], val);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case INST:
|
||||||
|
{
|
||||||
|
value* list = memory[c->args.args[0]->s->getValue()];
|
||||||
|
list->e->pushValue(c->args.args[1]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case HALT:
|
case HALT:
|
||||||
wait();
|
//wait();
|
||||||
|
break;
|
||||||
|
case DSPD:
|
||||||
|
if (speaker == nullptr) {
|
||||||
|
push_error(errors::error{ errors::unknown ,utils::concat("A call to set speaker speed, but a speaker has not been defined!") });
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
speaker->spd = c->args.args[0]->n->getValue();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case SSPK:
|
case SSPK:
|
||||||
if (characterExists(c->args.args[0]->s->getValue())){
|
if (characterExists(c->args.args[0]->s->getValue())){
|
||||||
@ -145,36 +177,46 @@ namespace dms {
|
|||||||
utils::write(c->args.args[0]->s->getValue());
|
utils::write(c->args.args[0]->s->getValue());
|
||||||
break;
|
break;
|
||||||
case ASGN:
|
case ASGN:
|
||||||
if (memory.count(c->args.args[0]->s->getValue()) == 0) {
|
assign(c->args.args[0], c->args.args[1]);
|
||||||
memory.insert_or_assign(c->args.args[0]->s->getValue(), c->args.args[1]);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
value* temp = memory[c->args.args[0]->s->getValue()];
|
|
||||||
if (temp->type != datatypes::variable) {
|
|
||||||
temp->set(); // Set the removed value to nil
|
|
||||||
garbage.push_back(memory[c->args.args[0]->s->getValue()]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
print("> so we have a variable");
|
|
||||||
memory[c->args.args[0]->s->getValue()] = c->args.args[1];
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case LINE:
|
case LINE:
|
||||||
ln = c->args.args[0]->n->getValue();
|
cur_line = c->args.args[0]->n->getValue();
|
||||||
break;
|
break;
|
||||||
case NOOP:
|
case NOOP:
|
||||||
break;
|
break;
|
||||||
case CHOI:
|
case CHOI:
|
||||||
//Because we are using void* we must cast our pointers
|
//Because we are using void* we must cast our pointers
|
||||||
//The implementation of this however should mean that you only ever have to deal with one "ChoiceHandler. One annoying void*"
|
//The implementation of this however should mean that you only ever have to deal with one "ChoiceHandler. One annoying void*"
|
||||||
pos += 2* (*(choiceHandler*)choi).manageChoice(this, c->args);
|
{
|
||||||
|
std::vector<std::string> args;
|
||||||
|
std::string prompt = c->args.args[0]->s->getValue();
|
||||||
|
std::string fn = c->args.args[1]->s->getValue();
|
||||||
|
for (size_t i = 2; i < c->args.args.size(); i++)
|
||||||
|
args.push_back(c->args.args[i]->resolve(memory)->s->getValue());
|
||||||
|
size_t npos = (*(Handler*)handler).manageChoice(this, prompt, args);
|
||||||
|
print("CHOI_", fn, "_", npos);
|
||||||
|
size_t nnpos = seek(concat("CHOI_", fn, "_", npos),cmds,LABL,npos);
|
||||||
|
if (!nnpos) {
|
||||||
|
push_error(errors::error{ errors::choice_unknown ,utils::concat("Unknown choice!") });
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
print(nnpos);
|
||||||
|
pos = nnpos;
|
||||||
|
wait();
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case JUMP:
|
case JUMP:
|
||||||
// Value assert resolves the data so a variable must eventually equal a string
|
// Value assert resolves the data so a variable must eventually equal a string
|
||||||
if (utils::valueassert(c->args, memory, datatypes::string)) {
|
if (utils::valueassert(c->args, memory, datatypes::string)) {
|
||||||
std::string block = c->args.args[0]->resolve(memory)->s->getValue();
|
std::string block = c->args.args[0]->resolve(memory)->s->getValue();
|
||||||
if (chunks[block] == NULL) {
|
if (chunks[block] == NULL) {
|
||||||
push_error(errors::error{ errors::non_existing_block ,utils::concat("Attempted to Jump to a non existing block <",block,">") });
|
push_error(errors::error{ errors::non_existing_block ,utils::concat("Attempted to Jump to a non existing block [",block,"]") });
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if (chunks[block]->type != bt_block) {
|
||||||
|
push_error(errors::error{ errors::non_existing_block ,utils::concat("Attempted to Jump to a non standard block [",block,"] type: ",getBlockType(chunks[block]->type))});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
BIN
DMS/dump.bin
BIN
DMS/dump.bin
Binary file not shown.
203
DMS/dump.txt
203
DMS/dump.txt
@ -12,185 +12,206 @@ Line <3> flag
|
|||||||
Line <3> name omniscient
|
Line <3> name omniscient
|
||||||
Line <3> newline
|
Line <3> newline
|
||||||
Line <3> newline
|
Line <3> newline
|
||||||
|
Line <4> flag
|
||||||
|
Line <4> name forseelabels
|
||||||
|
Line <4> newline
|
||||||
Line <4> newline
|
Line <4> newline
|
||||||
Line <5> flag
|
|
||||||
Line <5> name debugging
|
|
||||||
Line <5> newline
|
Line <5> newline
|
||||||
Line <5> newline
|
|
||||||
Line <6> flag
|
|
||||||
Line <6> string loadtest.dms
|
|
||||||
Line <6> newline
|
|
||||||
Line <6> newline
|
Line <6> newline
|
||||||
Line <7> flag
|
Line <7> flag
|
||||||
Line <7> number 1.2
|
Line <7> string loadtest.dms
|
||||||
Line <7> newline
|
Line <7> newline
|
||||||
Line <7> newline
|
Line <7> newline
|
||||||
Line <8> flag
|
Line <8> flag
|
||||||
Line <8> name extendedDefine
|
Line <8> number 1.2
|
||||||
Line <8> newline
|
Line <8> newline
|
||||||
Line <8> newline
|
Line <8> newline
|
||||||
|
Line <9> flag
|
||||||
|
Line <9> name extendedDefine
|
||||||
Line <9> newline
|
Line <9> newline
|
||||||
Line <9> newline
|
Line <9> newline
|
||||||
Line <10> bracketo [
|
|
||||||
Line <10> name main
|
|
||||||
Line <10> bracketc ]
|
|
||||||
Line <10> newline
|
Line <10> newline
|
||||||
Line <10> newline
|
Line <10> newline
|
||||||
Line <11> string Testing
|
Line <11> bracketo [
|
||||||
|
Line <11> name main
|
||||||
|
Line <11> bracketc ]
|
||||||
Line <11> newline
|
Line <11> newline
|
||||||
Line <11> newline
|
Line <11> newline
|
||||||
Line <12> name Bob
|
Line <12> string why
|
||||||
Line <12> colon :
|
|
||||||
Line <12> cbracketo {
|
|
||||||
Line <12> newline
|
Line <12> newline
|
||||||
Line <12> newline
|
Line <12> newline
|
||||||
Line <13> name speed
|
Line <13> name works
|
||||||
Line <13> number 50
|
Line <13> equal =
|
||||||
|
Line <13> true true
|
||||||
Line <13> newline
|
Line <13> newline
|
||||||
Line <13> newline
|
Line <13> newline
|
||||||
Line <14> name excited
|
Line <14> jump
|
||||||
Line <14> colon :
|
Line <14> name Bob
|
||||||
Line <14> string Hello Ryan!
|
|
||||||
Line <14> newline
|
Line <14> newline
|
||||||
Line <14> newline
|
Line <14> newline
|
||||||
Line <15> name wait
|
Line <15> string Testing
|
||||||
Line <15> number 200
|
|
||||||
Line <15> newline
|
Line <15> newline
|
||||||
Line <15> newline
|
Line <15> newline
|
||||||
Line <16> string How are you doing?
|
Line <16> name Bob
|
||||||
|
Line <16> colon :
|
||||||
|
Line <16> cbracketo {
|
||||||
Line <16> newline
|
Line <16> newline
|
||||||
Line <16> newline
|
Line <16> newline
|
||||||
Line <17> cbracketc }
|
Line <17> name speed
|
||||||
|
Line <17> number 50
|
||||||
Line <17> newline
|
Line <17> newline
|
||||||
Line <17> newline
|
Line <17> newline
|
||||||
|
Line <18> name excited
|
||||||
|
Line <18> colon :
|
||||||
|
Line <18> string Hello Ryan!
|
||||||
Line <18> newline
|
Line <18> newline
|
||||||
Line <18> newline
|
Line <18> newline
|
||||||
Line <19> name Ryan
|
Line <19> name wait
|
||||||
Line <19> colon :
|
Line <19> number 200
|
||||||
Line <19> cbracketo {
|
|
||||||
Line <19> newline
|
Line <19> newline
|
||||||
Line <19> newline
|
Line <19> newline
|
||||||
Line <20> string Hey Bob I'm good how are you?
|
Line <20> string How are you doing?
|
||||||
Line <20> newline
|
Line <20> newline
|
||||||
Line <20> newline
|
Line <20> newline
|
||||||
Line <21> cbracketc }
|
Line <21> cbracketc }
|
||||||
Line <21> newline
|
Line <21> newline
|
||||||
Line <21> newline
|
Line <21> newline
|
||||||
Line <22> name Bob
|
|
||||||
Line <22> colon :
|
|
||||||
Line <22> string Testing...
|
|
||||||
Line <22> newline
|
Line <22> newline
|
||||||
Line <22> newline
|
Line <22> newline
|
||||||
|
Line <23> name Ryan
|
||||||
|
Line <23> colon :
|
||||||
|
Line <23> cbracketo {
|
||||||
Line <23> newline
|
Line <23> newline
|
||||||
Line <23> newline
|
Line <23> newline
|
||||||
Line <24> control
|
Line <24> string Hey Bob I'm good how are you?
|
||||||
Line <24> string What do you want to do?
|
|
||||||
Line <24> cbracketo {
|
|
||||||
Line <24> newline
|
Line <24> newline
|
||||||
Line <24> newline
|
Line <24> newline
|
||||||
Line <25> string option 1
|
Line <25> cbracketc }
|
||||||
Line <25> name test2
|
|
||||||
Line <25> parao (
|
|
||||||
Line <25> string testing
|
|
||||||
Line <25> parac )
|
|
||||||
Line <25> newline
|
Line <25> newline
|
||||||
Line <25> newline
|
Line <25> newline
|
||||||
Line <26> string option 2
|
Line <26> name Bob
|
||||||
Line <26> jump
|
Line <26> colon :
|
||||||
Line <26> string test
|
Line <26> string Testing...
|
||||||
Line <26> newline
|
Line <26> newline
|
||||||
Line <26> newline
|
Line <26> newline
|
||||||
Line <27> string option 3
|
|
||||||
Line <27> jump
|
|
||||||
Line <27> name there
|
|
||||||
Line <27> newline
|
Line <27> newline
|
||||||
Line <27> newline
|
Line <27> newline
|
||||||
Line <28> string option 4
|
Line <28> control
|
||||||
Line <28> gotoo
|
Line <28> string What do you want to do?
|
||||||
Line <28> string o3
|
Line <28> cbracketo {
|
||||||
Line <28> newline
|
Line <28> newline
|
||||||
Line <28> newline
|
Line <28> newline
|
||||||
Line <29> string option 5
|
Line <29> string option 1
|
||||||
Line <29> gotoo
|
Line <29> name test2
|
||||||
Line <29> name here
|
Line <29> parao (
|
||||||
|
Line <29> string testing
|
||||||
|
Line <29> seperator ,
|
||||||
|
Line <29> cbracketo {
|
||||||
|
Line <29> number 1
|
||||||
|
Line <29> seperator ,
|
||||||
|
Line <29> number 2
|
||||||
|
Line <29> seperator ,
|
||||||
|
Line <29> number 3
|
||||||
|
Line <29> cbracketc }
|
||||||
|
Line <29> parac )
|
||||||
Line <29> newline
|
Line <29> newline
|
||||||
Line <29> newline
|
Line <29> newline
|
||||||
Line <30> string option 6
|
Line <30> string option 2
|
||||||
Line <30> name test
|
Line <30> jump
|
||||||
Line <30> parao (
|
Line <30> string test
|
||||||
Line <30> string here
|
|
||||||
Line <30> parac )
|
|
||||||
Line <30> newline
|
Line <30> newline
|
||||||
Line <30> newline
|
Line <30> newline
|
||||||
Line <31> cbracketc }
|
Line <31> string option 3
|
||||||
|
Line <31> jump
|
||||||
|
Line <31> name there
|
||||||
Line <31> newline
|
Line <31> newline
|
||||||
Line <31> newline
|
Line <31> newline
|
||||||
|
Line <32> string option 4
|
||||||
|
Line <32> gotoo
|
||||||
|
Line <32> string o3
|
||||||
Line <32> newline
|
Line <32> newline
|
||||||
Line <32> newline
|
Line <32> newline
|
||||||
Line <33> bracketo [
|
Line <33> string option 5
|
||||||
Line <33> name test
|
Line <33> gotoo
|
||||||
Line <33> bracketc ]
|
Line <33> name here
|
||||||
Line <33> newline
|
Line <33> newline
|
||||||
Line <33> newline
|
Line <33> newline
|
||||||
Line <34> name Ryan
|
Line <34> string option 6
|
||||||
Line <34> colon :
|
Line <34> name test
|
||||||
Line <34> string We are here now!
|
Line <34> parao (
|
||||||
|
Line <34> string here
|
||||||
|
Line <34> parac )
|
||||||
Line <34> newline
|
Line <34> newline
|
||||||
Line <34> newline
|
Line <34> newline
|
||||||
Line <35> string hehe
|
Line <35> cbracketc }
|
||||||
Line <35> newline
|
Line <35> newline
|
||||||
Line <35> newline
|
Line <35> newline
|
||||||
Line <36> newline
|
Line <36> newline
|
||||||
Line <36> newline
|
Line <36> newline
|
||||||
Line <37> bracketo [
|
Line <37> bracketo [
|
||||||
Line <37> name Bob
|
Line <37> name test
|
||||||
Line <37> colon :
|
|
||||||
Line <37> name char
|
|
||||||
Line <37> bracketc ]
|
Line <37> bracketc ]
|
||||||
Line <37> newline
|
Line <37> newline
|
||||||
Line <37> newline
|
Line <37> newline
|
||||||
Line <38> name fname
|
Line <38> name Ryan
|
||||||
Line <38> equal =
|
Line <38> colon :
|
||||||
Line <38> string Bob
|
Line <38> string We are here now!
|
||||||
Line <38> newline
|
Line <38> newline
|
||||||
Line <38> newline
|
Line <38> newline
|
||||||
|
Line <39> string hehe
|
||||||
|
Line <39> newline
|
||||||
Line <39> newline
|
Line <39> newline
|
||||||
Line <40> name age
|
|
||||||
Line <40> equal =
|
|
||||||
Line <40> number .24
|
|
||||||
Line <40> newline
|
Line <40> newline
|
||||||
Line <40> newline
|
Line <40> newline
|
||||||
Line <41> name money
|
Line <41> bracketo [
|
||||||
Line <41> equal =
|
Line <41> name Bob
|
||||||
Line <41> number 100
|
Line <41> colon :
|
||||||
|
Line <41> name char
|
||||||
|
Line <41> bracketc ]
|
||||||
Line <41> newline
|
Line <41> newline
|
||||||
Line <41> newline
|
Line <41> newline
|
||||||
Line <42> name excited
|
Line <42> name fname
|
||||||
Line <42> colon :
|
Line <42> equal =
|
||||||
Line <42> string path/to/file
|
Line <42> string Bob
|
||||||
Line <42> newline
|
Line <42> newline
|
||||||
Line <42> newline
|
Line <42> newline
|
||||||
Line <43> newline
|
Line <43> newline
|
||||||
Line <43> newline
|
Line <44> name age
|
||||||
Line <44> bracketo [
|
Line <44> equal =
|
||||||
Line <44> name newblock
|
Line <44> number 0.24
|
||||||
Line <44> colon :
|
|
||||||
Line <44> name function
|
|
||||||
Line <44> parao (
|
|
||||||
Line <44> parac )
|
|
||||||
Line <44> bracketc ]
|
|
||||||
Line <44> newline
|
Line <44> newline
|
||||||
Line <44> newline
|
Line <44> newline
|
||||||
Line <45> string Test #2
|
Line <45> name money
|
||||||
|
Line <45> equal =
|
||||||
|
Line <45> number 100
|
||||||
Line <45> newline
|
Line <45> newline
|
||||||
Line <45> newline
|
Line <45> newline
|
||||||
Line <46> string Does it parse this part properly?
|
Line <46> name excited
|
||||||
|
Line <46> colon :
|
||||||
|
Line <46> string path/to/file
|
||||||
Line <46> newline
|
Line <46> newline
|
||||||
Line <46> newline
|
Line <46> newline
|
||||||
Line <47> string huh
|
|
||||||
Line <47> newline
|
Line <47> newline
|
||||||
Line <47> newline
|
Line <47> newline
|
||||||
Line <47> eof
|
Line <48> bracketo [
|
||||||
|
Line <48> name newblock
|
||||||
|
Line <48> colon :
|
||||||
|
Line <48> name function
|
||||||
|
Line <48> parao (
|
||||||
|
Line <48> parac )
|
||||||
|
Line <48> bracketc ]
|
||||||
|
Line <48> newline
|
||||||
|
Line <48> newline
|
||||||
|
Line <49> string Test #2
|
||||||
|
Line <49> newline
|
||||||
|
Line <49> newline
|
||||||
|
Line <50> string Does it parse this part properly?
|
||||||
|
Line <50> newline
|
||||||
|
Line <50> newline
|
||||||
|
Line <51> string huh
|
||||||
|
Line <51> newline
|
||||||
|
Line <51> newline
|
||||||
|
Line <51> eof
|
||||||
Line <1> newline
|
Line <1> newline
|
||||||
Line <1> newline
|
Line <1> newline
|
||||||
Line <1> bracketo [
|
Line <1> bracketo [
|
||||||
|
|||||||
@ -1,13 +1,17 @@
|
|||||||
entry main // Will either start the first block seen or the block supplied by you!
|
entry main // Will either start the first block seen or the block supplied by you!
|
||||||
enable warnings
|
enable warnings
|
||||||
disable omniscient
|
disable omniscient
|
||||||
|
enable forseelabels
|
||||||
//enable leaking
|
//enable leaking
|
||||||
enable debugging
|
//enable debugging
|
||||||
loadfile "loadtest.dms"
|
loadfile "loadtest.dms"
|
||||||
version 1.2
|
version 1.2
|
||||||
using extendedDefine
|
using extendedDefine
|
||||||
|
|
||||||
[main]
|
[main]
|
||||||
|
"why"
|
||||||
|
works = true
|
||||||
|
jump Bob
|
||||||
"Testing"
|
"Testing"
|
||||||
Bob: {
|
Bob: {
|
||||||
speed 50
|
speed 50
|
||||||
@ -22,7 +26,7 @@ using extendedDefine
|
|||||||
Bob: "Testing..."
|
Bob: "Testing..."
|
||||||
|
|
||||||
choice "What do you want to do?" {
|
choice "What do you want to do?" {
|
||||||
"option 1" test2("testing")
|
"option 1" test2("testing",{1,2,3})
|
||||||
"option 2" jump "test"
|
"option 2" jump "test"
|
||||||
"option 3" jump there
|
"option 3" jump there
|
||||||
"option 4" goto "o3"
|
"option 4" goto "o3"
|
||||||
|
|||||||
@ -133,32 +133,17 @@ namespace dms {
|
|||||||
return temp.str();
|
return temp.str();
|
||||||
}
|
}
|
||||||
void dms_env::pushValue(value* val) {
|
void dms_env::pushValue(value* val) {
|
||||||
double count = 0;
|
ipart.push_back(val);
|
||||||
while (ipart[count++]->type != nil) {}
|
|
||||||
ipart.insert_or_assign(count-1, val);
|
|
||||||
}
|
}
|
||||||
void dms_env::pushValue(value* ind, value* val) {
|
void dms_env::pushValue(value* ind, value* val) {
|
||||||
if (ind->type == number) {
|
if (val->type == nil) {
|
||||||
size_t size = ipart.size();
|
hpart[ind->toString()]->nuke();
|
||||||
if (val->type == nil) {
|
hpart.erase(ind->toString());
|
||||||
ipart[ind->n->val]->nuke();
|
count--;
|
||||||
ipart.erase(ind->n->val);
|
}
|
||||||
count--;
|
else {
|
||||||
}
|
hpart.insert_or_assign(ind->toString(), val);
|
||||||
else {
|
count++;
|
||||||
ipart.insert_or_assign(ind->n->val, val);
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (val->type == nil) {
|
|
||||||
hpart[ind->toString()]->nuke();
|
|
||||||
hpart.erase(ind->toString());
|
|
||||||
count--;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
hpart.insert_or_assign(ind->toString(), val);
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
value* dms_env::getValue(value* ind) {
|
value* dms_env::getValue(value* ind) {
|
||||||
|
|||||||
@ -137,7 +137,7 @@ namespace dms {
|
|||||||
struct dms_env
|
struct dms_env
|
||||||
{
|
{
|
||||||
std::unordered_map<std::string, value*> hpart;
|
std::unordered_map<std::string, value*> hpart;
|
||||||
std::unordered_map<double, value*> ipart;
|
std::vector<value*> ipart;
|
||||||
void pushValue(value* val);
|
void pushValue(value* val);
|
||||||
void pushValue(value* ind, value* val);
|
void pushValue(value* ind, value* val);
|
||||||
value* getValue(value* val);
|
value* getValue(value* val);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user