changed how characters/envs are loaded. Implemented dynamic reading. Todo indexing

This commit is contained in:
Ryan Ward 2020-10-05 19:11:20 -04:00
parent 35c0b390ab
commit 7134755649
24 changed files with 377 additions and 248 deletions

5
.editorconfig Normal file
View File

@ -0,0 +1,5 @@
# Rules in this file were initially inferred by Visual Studio IntelliCode from the F:\VSCWorkspace\DMS codebase based on best match to current usage at 10/3/2020
# You can modify the rules from these initially generated values to suit your own policies
# You can learn more about editorconfig here: https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference
[*.cs]

View File

@ -1,11 +1,29 @@
#include "dms.h" #include "dms.h"
#include <windows.h>
#include <iostream> #include <iostream>
using namespace dms; using namespace dms;
typedef void(*FNPTR)();
int main() int main()
{ {
/*HINSTANCE hInst = LoadLibrary(L"C:\\Users\\rayam\\Desktop\\test.dll");
if (!hInst) {
std::cout << "\nCould not load the library!";
return EXIT_FAILURE;
}
FNPTR fn = (FNPTR)GetProcAddress(hInst, "_init");
if (!fn) {
std::cout << "\nCould not load function from library!";
return EXIT_FAILURE;
}
fn();*/
LineParser parser = LineParser("test.dms"); LineParser parser = LineParser("test.dms");
dms_state* state = parser.Parse(); dms_state* state = parser.Parse();
state->dump(); state->dump();
state->run(); state->run();
utils::print("Exitcode: ",state->exitcode); utils::print("Exitcode: ",state->exitcode);
} }

View File

@ -134,6 +134,7 @@
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard> <LanguageStandard>stdcpp17</LanguageStandard>
<Optimization>MaxSpeed</Optimization>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
@ -144,6 +145,7 @@
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="character.cpp" /> <ClCompile Include="character.cpp" />
<ClCompile Include="dms_custom.cpp" />
<ClCompile Include="enviroment.cpp" /> <ClCompile Include="enviroment.cpp" />
<ClCompile Include="Handlers.cpp" /> <ClCompile Include="Handlers.cpp" />
<ClCompile Include="chunk.cpp" /> <ClCompile Include="chunk.cpp" />

View File

@ -81,6 +81,9 @@
<ClCompile Include="enviroment.cpp"> <ClCompile Include="enviroment.cpp">
<Filter>Source Files\DMS\blocks</Filter> <Filter>Source Files\DMS\blocks</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="dms_custom.cpp">
<Filter>Source Files\DMS</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="value.h"> <ClInclude Include="value.h">

View File

@ -35,10 +35,12 @@ namespace dms {
} }
// Simple one conn event // Simple one conn event
bool Handler::OnEnviromentCreated(dms_state* state, enviroment* env) const {
return true;
}
bool Handler::OnSpeakerCreated(dms_state* state, character* chara) const { bool Handler::OnSpeakerCreated(dms_state* state, character* chara) const {
return true; return true;
} }
bool Handler::OnStateInit(dms_state* state) const { bool Handler::OnStateInit(dms_state* state) const {
return true; return true;
} }

View File

@ -10,9 +10,9 @@ namespace dms {
virtual bool handleSpeaker(dms_state* state, character* chara) const; virtual bool handleSpeaker(dms_state* state, character* chara) const;
virtual bool handleMessageDisplay(dms_state* state, std::string msg) const; virtual bool handleMessageDisplay(dms_state* state, std::string msg) const;
virtual bool handleMessageAppend(dms_state* state, std::string msg) const; virtual bool handleMessageAppend(dms_state* state, std::string msg) const;
//virtual bool manageMessage(dms_state* state, value* msg) const;
// Simple Events: only one connector! // Simple Events: only one connector!
virtual bool OnEnviromentCreated(dms_state* state, enviroment* env) const;
virtual bool OnSpeakerCreated(dms_state* state, character* chara) const; virtual bool OnSpeakerCreated(dms_state* state, character* chara) const;
virtual bool OnStateInit(dms_state* state) const; virtual bool OnStateInit(dms_state* state) const;
}; };

View File

@ -74,6 +74,7 @@ namespace dms {
bool match_process_list(tokenstream* stream, value* v = nullptr); bool match_process_list(tokenstream* stream, value* v = nullptr);
bool match_process_wait(tokenstream* stream); bool match_process_wait(tokenstream* stream);
bool match_process_standard(tokenstream* stream, value* v = nullptr); // All types that are matchable are handled here! bool match_process_standard(tokenstream* stream, value* v = nullptr); // All types that are matchable are handled here!
bool match_process_index(tokenstream* stream,value* v = nullptr);
// Build // Build

View File

@ -547,7 +547,15 @@ namespace dms {
} }
return false; return false;
} }
bool LineParser::match_process_index(tokenstream* stream, value* v) {
if (stream->match(tokens::name,tokens::bracketo)) {
// Todo implement this
}
return false;
}
bool LineParser::match_process_jump(tokenstream* stream) { bool LineParser::match_process_jump(tokenstream* stream) {
if (current_chunk->type == blocktype::bt_character || current_chunk->type == blocktype::bt_env)
return false;
if (stream->match(tokens::jump, tokens::name) || stream->match(tokens::jump, tokens::string)) { if (stream->match(tokens::jump, tokens::name) || stream->match(tokens::jump, tokens::string)) {
cmd* c = new cmd; cmd* c = new cmd;
c->opcode = codes::JUMP; c->opcode = codes::JUMP;

View File

@ -240,12 +240,12 @@ namespace dms {
return true; return true;
} }
else if (bk_name == "$END") { else if (bk_name == "$END") {
cmd* c = new cmd; /*cmd* c = new cmd;
c->opcode = codes::JUMP; c->opcode = codes::JUMP;
c->args.push(buildValue("$END")); c->args.push(buildValue("$END"));
current_chunk->addCmd(c); current_chunk->addCmd(c);
state->push_chunk(current_chunk->name, current_chunk); state->push_chunk(current_chunk->name, current_chunk);
current_chunk = state->chunks["$END"]; current_chunk = state->chunks["$END"];*/
return true; return true;
} }
else { else {

Binary file not shown.

View File

@ -2,17 +2,20 @@
#include "utils.h" #include "utils.h"
namespace dms { namespace dms {
std::string character::getName() { std::string character::getName() {
if (values.count("nickname")) { if (has("nickname")) {
return values["nickname"]->getPrintable(); return values["nickname"]->getPrintable();
} }
if (seen && values.count("lname")) { if (seen && has("fname") && has("lname")) {
return utils::concat(values["fname"]->getPrintable()," ", values["lname"]->getPrintable()); return utils::concat(values["fname"]->getPrintable()," ", values["lname"]->getPrintable());
} }
else if (seen) { else if (seen && has("fname")) {
return utils::concat(values["fname"]->getPrintable()); return utils::concat(values["fname"]->getPrintable());
} }
else { else if (!seen && has("unknown")) {
return values["unknown"]->getPrintable(); return values["unknown"]->getPrintable();
} }
else {
return "unknown";
}
} }
} }

61
DMS/dms_custom.cpp Normal file
View File

@ -0,0 +1,61 @@
#include "value.h"
#include "utils.h"
//Implement the defaults
namespace dms {
// These are pointers to other data that should not be deleted.
const value* perNIL = new value;
void dms_custom::_del() {
state = nullptr;
self = nullptr;
}
void dms_custom::_set(value* v) {
self = v;
}
void dms_custom::Init(dms_state* state) {
this->state = state;
}
value* dms_custom::Index(value* data) {
state->push_error(errors::error{ errors::unknown,"Attempting to index a non enviroment!" });
return nullptr;
}
bool dms_custom::NewIndex(value* var, value* val) {
state->push_error(errors::error{ errors::unknown,"Attempting to create a new index on a non enviroment!" });
return false;
}
value* dms_custom::Call(dms_args* args) {
state->push_error(errors::error{errors::unknown,"Attempting to call a non function value!"});
return nullptr;
}
value* dms_custom::ToString() {
return buildValue(utils::concat("Custom: ",this));
}
value* dms_custom::ADD(value* left, value* right) {
state->push_error(errors::error{ errors::unknown,"Attempting to add a non number value!" });
return nullptr;
}
value* dms_custom::SUB(value* left, value* right) {
state->push_error(errors::error{ errors::unknown,"Attempting to subtract a non number value!" });
return nullptr;
}
value* dms_custom::MUL(value* left, value* right) {
state->push_error(errors::error{ errors::unknown,"Attempting to multiply a non number value!" });
return nullptr;
}
value* dms_custom::DIV(value* left, value* right) {
state->push_error(errors::error{ errors::unknown,"Attempting to divide a non number value!" });
return nullptr;
}
value* dms_custom::POW(value* left, value* right) {
state->push_error(errors::error{ errors::unknown,"Attempting to raise a non number value!" });
return nullptr;
}
value* dms_custom::EQUAL(value* left, value* right) {
return buildValue(left->getPrintable() == right->getPrintable());
}
value* dms_custom::LESS_THAN(value* left, value* right) {
return buildValue(left->getPrintable() < right->getPrintable());
}
value* dms_custom::LESS_THAN_EQUAL(value* left, value* right) {
return buildValue(left->getPrintable() <= right->getPrintable());
}
}

View File

@ -7,7 +7,7 @@ namespace dms {
init_init = true; init_init = true;
cmd* c = new cmd; cmd* c = new cmd;
for (const auto& [key, val] : chunks) { for (const auto& [key, val] : chunks) {
if (val->type == blocktype::bt_character) { if (val->type == blocktype::bt_character || val->type == blocktype::bt_env) {
value* v = buildVariable(); value* v = buildVariable();
v->set(buildString(key)); v->set(buildString(key));
v->type = datatypes::block; v->type = datatypes::block;
@ -36,6 +36,7 @@ namespace dms {
enables.insert_or_assign("warnings",false); // enables.insert_or_assign("warnings",false); //
enables.insert_or_assign("statesave",true); // Allows you to save state enables.insert_or_assign("statesave",true); // Allows you to save state
enables.insert_or_assign("omniscient",false); // Allows you to know who's who when you first meet them enables.insert_or_assign("omniscient",false); // Allows you to know who's who when you first meet them
enables.insert_or_assign("fullname", true);
chunk* c = new chunk; chunk* c = new chunk;
c->name = "$END"; c->name = "$END";
c->type = blocktype::bt_block; c->type = blocktype::bt_block;
@ -92,20 +93,20 @@ namespace dms {
return false; return false;
} }
bool dms_state::assign(value* var, value* val) { bool dms_state::assign(std::unordered_map<std::string, value*>* mem, value* var, value* val) {
if (memory.count(var->s->getValue()) == 0) { if (mem->count(var->s->getValue()) == 0) {
memory.insert_or_assign(var->s->getValue(), val); mem->insert_or_assign(var->s->getValue(), val);
return true; return true;
} }
else { else {
value* temp = memory[var->s->getValue()]; value* temp = (*mem)[var->s->getValue()];
if (temp->type != datatypes::variable) { if (temp->type != datatypes::variable) {
temp->set(); // Set the removed value to nil temp->set(); // Set the removed value to nil
garbage.push_back(memory[var->s->getValue()]); garbage.push_back((*mem)[var->s->getValue()]);
} }
else else
utils::print("> so we have a variable"); // This print should be a reminder for me to do something about this. 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; (*mem)[var->s->getValue()] = val;
} }
} }
void dms_state::dump(bool print) { void dms_state::dump(bool print) {

View File

@ -1,16 +1,12 @@
#pragma once #pragma once
#include "errors.h"
#include "chunk.h"
#include "dms_exceptions.h"
#include <fstream> #include <fstream>
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <map>
#include <unordered_map> #include <unordered_map>
// Threading Stuff
#include <thread> #include "errors.h"
#include <mutex> #include "chunk.h"
#include <chrono> #include "dms_exceptions.h"
#include "Character.h" #include "Character.h"
#include "enviroment.h" #include "enviroment.h"
namespace dms { namespace dms {
@ -21,12 +17,12 @@ namespace dms {
bool hasFirst = false; bool hasFirst = false;
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::unordered_map<std::string, chunk*> chunks;
std::map<std::string, character*> characters; std::unordered_map<std::string, character*> characters;
std::map<std::string, enviroment*> enviroments; std::unordered_map<std::string, enviroment*> enviroments;
std::map<std::string, size_t> labels; std::unordered_map<std::string, size_t> labels;
std::string entry = "$undefined"; std::string entry = "$undefined";
std::map<std::string, bool> enables; std::unordered_map<std::string, bool> enables;
std::size_t cur_line=0; std::size_t cur_line=0;
int exitcode = 0; int exitcode = 0;
const double Iversion = 1.0; const double Iversion = 1.0;
@ -53,12 +49,13 @@ namespace dms {
character* getCharacter(std::string c); character* getCharacter(std::string c);
enviroment* getEnviroment(std::string c); enviroment* getEnviroment(std::string c);
bool assign(value* var, value* val); bool assign(std::unordered_map<std::string, value*>* mem,value* var, value* val);
size_t seek(std::string label,std::vector<cmd*> cmds ,codes::op code, size_t pos); size_t seek(std::string label,std::vector<cmd*> cmds ,codes::op code, size_t pos);
bool characterExists(std::string bk_name); bool characterExists(std::string bk_name);
bool blockExists(std::string bk_name); bool blockExists(std::string bk_name);
bool typeAssert(value* val, datatypes type); bool typeAssert(value* val, datatypes type);
bool run(); bool run();
bool run(std::string ent,std::unordered_map<std::string, value*>* mem);
// This is called once and once only. Dynamically loading code is not a thing! // This is called once and once only. Dynamically loading code is not a thing!
void init(); void init();

View File

@ -11,77 +11,68 @@ namespace dms {
void dms_state::setHandler(Handler* hand) { void dms_state::setHandler(Handler* hand) {
this->handler = hand; this->handler = hand;
} }
enviroment* dms_state::getEnviroment(std::string c) { void checkCharacter(character* cc,std::string index, datatypes type) {
value* val = cc->get(index);
if (val==nullptr) {
if (type == datatypes::string)
cc->values[index] = buildValue("");
else if (type == datatypes::boolean) {
cc->values[index] = buildValue(false);
}
}
else if (val != nullptr) {
if (val->type != type) {
cc->values.erase(index);
}
}
}
enviroment* dms_state::getEnviroment(std::string env) {
if (enviroments.count(env)) {
return enviroments[env];
}
else {
if (blockExists(env)) {
enviroment* e = new enviroment;
if (!run(env, &e->values)) {
return nullptr;
}
enviroments.insert_or_assign(env, e);
handler->OnEnviromentCreated(this, e);
return e;
}
else {
push_error(errors::error{ errors::non_existing_block ,utils::concat("Attempted to index a non existing enviroment block!") });
return nullptr;
}
}
return nullptr; return nullptr;
} }
character* dms_state::getCharacter(std::string cha) { character* dms_state::getCharacter(std::string cha) {
if (characters.count(cha)) { if (characters.count(cha)) {
characters[cha]->seen = true;
return characters[cha]; return characters[cha];
} }
else { else {
if (blockExists(cha)) { if (blockExists(cha)) {
character* cc = new character; character* cc = new character;
cc->values.insert_or_assign("fname", buildValue(cha)); cc->set("fname", buildValue(cha));
cc->values.insert_or_assign("lname", buildValue("")); cc->set("lname", buildValue(""));
codes::op code; cc->set("unknown", buildValue("Unknown"));
cmd* c = nullptr; cc->set("known", buildValue(false));
bool halt = false;
size_t pos = 0;
size_t max = 0;
std::vector<cmd*> cmds;
init(chunks[cha], pos, max, cmds);
if (isEnabled("omniscient")) { if (isEnabled("omniscient")) {
cc->seen = true; cc->seen = true;
} }
else { else {
cc->seen = false; cc->seen = false;
} }
while (true) { if (run(cha,&cc->values)) {
c = cmds[pos++]; checkCharacter(cc, "fname",datatypes::string);
code = c->opcode; checkCharacter(cc, "lname", datatypes::string);
checkCharacter(cc, "unknown", datatypes::string);
switch (code) checkCharacter(cc, "known", datatypes::boolean);
{
// Handle flags here
case STAT:
if(c->args.args[0]->type == datatypes::variable && c->args.args[1]->type == datatypes::string)
cc->paths.insert_or_assign(c->args.args[0]->s->getValue(), c->args.args[1]->s->getValue());
else
push_error(errors::error{ errors::invalid_type ,utils::concat("Expected variable: string! Got: ",datatype[c->args.args[0]->type],": ",datatype[c->args.args[1]->type]) });
break;
case ASGN:
if (c->args.args[0]->s->getValue() == "fname") {
if(!typeAssert(c->args.args[1],datatypes::string))
return nullptr;
cc->values.insert_or_assign("fname", c->args.args[1]);
}
else if (c->args.args[0]->s->getValue() == "lname") {
if (!typeAssert(c->args.args[1], datatypes::string))
return nullptr;
cc->values.insert_or_assign("lname", c->args.args[1]);
}
else if (c->args.args[0]->s->getValue() == "unknown") {
if (!typeAssert(c->args.args[1], datatypes::string))
return nullptr;
cc->values.insert_or_assign("unknown", c->args.args[1]);
}
else if (c->args.args[0]->s->getValue() == "known") {
if (!typeAssert(c->args.args[1], datatypes::boolean))
return nullptr;
cc->seen = c->args.args[1]->b->getValue();
} }
else { else {
cc->values.insert_or_assign(c->args.args[0]->s->getValue(), c->args.args[1]); return nullptr;
}
break;
default:
break;
}
if (pos == max) {
// How did we get here? The end of a block?
break;
}
} }
characters.insert_or_assign(cha, cc); characters.insert_or_assign(cha, cc);
// Call Character event! // Call Character event!
@ -114,17 +105,20 @@ namespace dms {
return true; return true;
} }
bool dms_state::run() { bool dms_state::run() {
if (chunks[entry] == NULL) {
push_error(errors::error{ errors::non_existing_block ,utils::concat("Attempted to Jump to a non existing block [",entry,"]") });
return false;
}
return run("$INIT",&memory);
}
bool dms_state::run(std::string ent, std::unordered_map<std::string, value*>* mem) {
codes::op code; codes::op code;
cmd* c = nullptr; cmd* c = nullptr;
bool halt = false; bool halt = false;
size_t pos=0; size_t pos=0;
size_t max = 0; size_t max = 0;
std::vector<cmd*> cmds; std::vector<cmd*> cmds;
if (chunks[entry] == NULL) { init(chunks[ent],pos,max,cmds);
push_error(errors::error{errors::non_existing_block ,utils::concat("Attempted to Jump to a non existing block [",entry,"]")});
return false;
}
init(chunks["$INIT"],pos,max,cmds);
//TODO: parse the cmds and do stuff //TODO: parse the cmds and do stuff
// If this is running in a thread then stop will force this loop to stop // If this is running in a thread then stop will force this loop to stop
@ -182,22 +176,22 @@ namespace dms {
env->hpart.insert_or_assign("$size", c->args.args[1]); env->hpart.insert_or_assign("$size", c->args.args[1]);
value* val = new value; value* val = new value;
val->set(env); val->set(env);
assign(c->args.args[0], val); assign(mem,c->args.args[0], val);
} }
break; break;
case INST: case INST:
{ {
value* list = memory[c->args.args[0]->s->getValue()]; value* list = (*mem)[c->args.args[0]->s->getValue()];
list->e->pushValue(c->args.args[1]); list->e->pushValue(c->args.args[1]);
} }
break; break;
case HALT: case HALT:
//wait(); //wait();
std::this_thread::sleep_for(std::chrono::milliseconds(700)); sleep(700);
std::cout << std::endl; std::cout << std::endl;
break; break;
case WAIT: case WAIT:
std::this_thread::sleep_for(std::chrono::milliseconds((int)(c->args.args[0]->n->getValue()*1000))); sleep((int)(c->args.args[0]->n->getValue()*1000));
break; break;
case DSPD: case DSPD:
if (speaker == nullptr) { if (speaker == nullptr) {
@ -229,7 +223,7 @@ namespace dms {
return false; return false;
break; break;
case ASGN: case ASGN:
assign(c->args.args[0], c->args.args[1]); assign(mem,c->args.args[0], c->args.args[1]);
break; break;
case LINE: case LINE:
cur_line = c->args.args[0]->n->getValue(); cur_line = c->args.args[0]->n->getValue();
@ -243,7 +237,7 @@ namespace dms {
std::string prompt = c->args.args[0]->s->getValue(); std::string prompt = c->args.args[0]->s->getValue();
std::string fn = c->args.args[1]->s->getValue(); std::string fn = c->args.args[1]->s->getValue();
for (size_t i = 2; i < c->args.args.size(); i++) for (size_t i = 2; i < c->args.args.size(); i++)
args.push_back(c->args.args[i]->resolve(memory)->s->getValue()); args.push_back(c->args.args[i]->resolve(*mem)->s->getValue());
size_t npos = handler->handleChoice(this, prompt, args); size_t npos = handler->handleChoice(this, prompt, args);
size_t nnpos = seek(concat("CHOI_", fn, "_", npos),cmds,LABL,npos); size_t nnpos = seek(concat("CHOI_", fn, "_", npos),cmds,LABL,npos);
if (!nnpos) { if (!nnpos) {
@ -257,8 +251,8 @@ namespace dms {
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, *mem, datatypes::string)) {
std::string block = c->args.args[0]->resolve(memory)->s->getValue(); std::string block = c->args.args[0]->resolve(*mem)->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; return false;
@ -272,7 +266,7 @@ namespace dms {
} }
} }
else { else {
datatypes set = c->args.args[0]->resolve(memory)->type; datatypes set = c->args.args[0]->resolve(*mem)->type;
push_error(errors::error{ errors::invalid_arguments, utils::concat("String expected got ",datatype[set]), true,ln }); push_error(errors::error{ errors::invalid_arguments, utils::concat("String expected got ",datatype[set]), true,ln });
return false; return false;
} }

Binary file not shown.

View File

@ -17,267 +17,264 @@ Line <5> flag
Line <5> name savestate Line <5> name savestate
Line <5> newline Line <5> newline
Line <5> newline Line <5> newline
Line <6> flag
Line <6> name fullname
Line <6> newline
Line <6> newline Line <6> newline
Line <7> newline Line <7> newline
Line <8> flag
Line <8> string loadtest.dms
Line <8> newline
Line <8> newline Line <8> newline
Line <9> flag Line <9> flag
Line <9> number 0.2 Line <9> string loadtest.dms
Line <9> newline Line <9> newline
Line <9> newline Line <9> newline
Line <10> flag Line <10> flag
Line <10> name extendedDefine Line <10> number 0.2
Line <10> newline Line <10> newline
Line <10> newline Line <10> newline
Line <11> flag
Line <11> name extendedDefine
Line <11> newline Line <11> newline
Line <11> newline Line <11> newline
Line <12> bracketo [
Line <12> name main
Line <12> bracketc ]
Line <12> newline Line <12> newline
Line <12> newline Line <12> newline
Line <13> string why Line <13> bracketo [
Line <13> name main
Line <13> bracketc ]
Line <13> newline Line <13> newline
Line <13> newline Line <13> newline
Line <14> name Bob Line <14> string why
Line <14> colon :
Line <14> cbracketo {
Line <14> newline Line <14> newline
Line <14> newline Line <14> newline
Line <15> name speed Line <15> name Bob
Line <15> number 50 Line <15> colon :
Line <15> cbracketo {
Line <15> newline Line <15> newline
Line <15> newline Line <15> newline
Line <16> name excited Line <16> name speed
Line <16> colon : Line <16> number 50
Line <16> string Hello Mr. `Ryan:lname`,
Line <16> newline Line <16> newline
Line <16> newline Line <16> newline
Line <17> string how are you doing? Line <17> name excited
Line <17> colon :
Line <17> string Hello Mr. `Ryan:lname`,
Line <17> newline Line <17> newline
Line <17> newline Line <17> newline
Line <18> cbracketc } Line <18> string how are `inv:slot2` you doing?
Line <18> newline Line <18> newline
Line <18> newline Line <18> newline
Line <19> cbracketc }
Line <19> newline Line <19> newline
Line <19> newline Line <19> newline
Line <20> newline Line <20> newline
Line <20> newline
Line <21> newline Line <21> newline
Line <21> newline
Line <22> name Ryan
Line <22> colon :
Line <22> cbracketo {
Line <22> newline Line <22> newline
Line <22> newline Line <22> newline
Line <23> string Hey `Bob`, I'm good how are you?
Line <23> newline Line <23> newline
Line <23> newline
Line <24> cbracketc }
Line <24> newline Line <24> newline
Line <24> newline
Line <25> name Ryan
Line <25> colon :
Line <25> cbracketo {
Line <25> newline Line <25> newline
Line <25> newline Line <25> newline
Line <26> string Waiting ... Line <26> string Hey `Bob`, I'm good how are you?
Line <26> newline Line <26> newline
Line <26> newline Line <26> newline
Line <27> cbracketc }
Line <27> newline Line <27> newline
Line <27> newline
Line <28> exit
Line <28> number 1
Line <28> newline Line <28> newline
Line <28> newline Line <28> newline
Line <29> string Waiting ...
Line <29> newline Line <29> newline
Line <29> newline Line <29> newline
Line <30> name Bob
Line <30> colon :
Line <30> cbracketo {
Line <30> newline Line <30> newline
Line <30> newline Line <30> newline
Line <31> string I am great thanks! I want to show you that I can count! Line <31> name Bob
Line <31> colon :
Line <31> cbracketo {
Line <31> newline Line <31> newline
Line <31> newline Line <31> newline
Line <32> name wait Line <32> string I am great thanks! I want to show you that I can count!
Line <32> number 1
Line <32> newline Line <32> newline
Line <32> newline Line <32> newline
Line <33> string 1 Line <33> name wait
Line <33> number 0.1
Line <33> newline Line <33> newline
Line <33> newline Line <33> newline
Line <34> name wait Line <34> string 1
Line <34> number 1
Line <34> newline Line <34> newline
Line <34> newline Line <34> newline
Line <35> string 2 Line <35> name wait
Line <35> number 0.1
Line <35> newline Line <35> newline
Line <35> newline Line <35> newline
Line <36> name wait Line <36> string 2
Line <36> number 1
Line <36> newline Line <36> newline
Line <36> newline Line <36> newline
Line <37> string 3 Line <37> name wait
Line <37> number 0.1
Line <37> newline Line <37> newline
Line <37> newline Line <37> newline
Line <38> name wait Line <38> string 3
Line <38> number 1
Line <38> newline Line <38> newline
Line <38> newline Line <38> newline
Line <39> string 4 Line <39> name wait
Line <39> number 0.1
Line <39> newline Line <39> newline
Line <39> newline Line <39> newline
Line <40> name wait Line <40> string 4
Line <40> number 1
Line <40> newline
Line <40> newline
Line <41> string 5
Line <40> newline
Line <40> newline
Line <41> name wait
Line <41> number 0.1
Line <41> newline Line <41> newline
Line <41> newline Line <41> newline
Line <42> cbracketc } Line <42> string 5
Line <42> newline Line <42> newline
Line <42> newline Line <42> newline
Line <43> cbracketc }
Line <43> newline Line <43> newline
Line <43> newline Line <43> newline
Line <44> control
Line <44> string What do you want to do?
Line <44> cbracketo {
Line <44> newline Line <44> newline
Line <44> newline Line <44> newline
Line <45> string option 1 Line <45> control
Line <45> name test2 Line <45> string What do you want to do?
Line <45> parao (
Line <45> string testing
Line <45> seperator ,
Line <45> cbracketo { Line <45> cbracketo {
Line <45> number 1
Line <45> seperator ,
Line <45> number 2
Line <45> seperator ,
Line <45> number 3
Line <45> cbracketc }
Line <45> parac )
Line <45> newline Line <45> newline
Line <45> newline Line <45> newline
Line <46> string option 2 Line <46> string option 1
Line <46> jump Line <46> name test2
Line <46> string test Line <46> parao (
Line <46> string testing
Line <46> seperator ,
Line <46> cbracketo {
Line <46> number 1
Line <46> seperator ,
Line <46> number 2
Line <46> seperator ,
Line <46> number 3
Line <46> cbracketc }
Line <46> parac )
Line <46> newline Line <46> newline
Line <46> newline Line <46> newline
Line <47> string option 3 Line <47> string option 2
Line <47> jump Line <47> jump
Line <47> name there Line <47> string test
Line <47> newline Line <47> newline
Line <47> newline Line <47> newline
Line <48> string option 4 Line <48> string option 3
Line <48> gotoo Line <48> jump
Line <48> string o3 Line <48> name there
Line <48> newline Line <48> newline
Line <48> newline Line <48> newline
Line <49> string option 5 Line <49> string option 4
Line <49> gotoo Line <49> gotoo
Line <49> name here Line <49> string o3
Line <49> newline Line <49> newline
Line <49> newline Line <49> newline
Line <50> string option 6 Line <50> string option 5
Line <50> name test Line <50> gotoo
Line <50> parao ( Line <50> name here
Line <50> string here
Line <50> parac )
Line <50> newline Line <50> newline
Line <50> newline Line <50> newline
Line <51> cbracketc } Line <51> string option 6
Line <51> name test
Line <51> parao (
Line <51> string here
Line <51> parac )
Line <51> newline Line <51> newline
Line <51> newline Line <51> newline
Line <52> cbracketc }
Line <52> newline Line <52> newline
Line <52> newline Line <52> newline
Line <53> bracketo [
Line <53> name test
Line <53> bracketc ]
Line <53> newline Line <53> newline
Line <53> newline Line <53> newline
Line <54> name Ryan Line <54> bracketo [
Line <54> colon : Line <54> name test
Line <54> string We are here now! Line <54> bracketc ]
Line <54> newline Line <54> newline
Line <54> newline Line <54> newline
Line <55> pipe | Line <55> name Ryan
Line <55> string This continues from the last message! Line <55> colon :
Line <55> string We are here now!
Line <55> newline Line <55> newline
Line <55> newline Line <55> newline
Line <56> pipe | Line <56> pipe |
Line <56> string Keeps code readable. This does not cause a new line! Line <56> string This continues from the last message!
Line <56> newline Line <56> newline
Line <56> newline Line <56> newline
Line <57> name Ryan Line <57> pipe |
Line <57> colon : Line <57> string Keeps code readable. This does not cause a new line!
Line <57> string This does trigger a new line tho!
Line <57> newline Line <57> newline
Line <57> newline Line <57> newline
Line <58> string This also will cause a new line! Line <58> name Ryan
Line <58> colon :
Line <58> string This does trigger a new line tho!
Line <58> newline Line <58> newline
Line <58> newline Line <58> newline
Line <59> string This also will cause a new line!
Line <59> newline Line <59> newline
Line <59> newline Line <59> newline
Line <60> bracketo [
Line <60> name Bob
Line <60> colon :
Line <60> name char
Line <60> bracketc ]
Line <60> newline Line <60> newline
Line <60> newline Line <60> newline
Line <61> name fname Line <61> bracketo [
Line <61> equal = Line <61> name Bob
Line <61> string Bob Line <61> colon :
Line <61> name char
Line <61> bracketc ]
Line <61> newline Line <61> newline
Line <61> newline Line <61> newline
Line <62> newline Line <62> newline
Line <63> newline Line <63> newline
Line <64> name unknown
Line <64> equal =
Line <64> string Some Rando
Line <64> newline Line <64> newline
Line <64> newline Line <65> name unknown
Line <65> name age
Line <65> equal = Line <65> equal =
Line <65> number 0.24 Line <65> string Some Rando
Line <65> newline Line <65> newline
Line <65> newline Line <65> newline
Line <66> name money Line <66> name age
Line <66> equal = Line <66> equal =
Line <66> number 100 Line <66> number 0.24
Line <66> newline Line <66> newline
Line <66> newline Line <66> newline
Line <67> name excited Line <67> name money
Line <67> colon : Line <67> equal =
Line <67> string path/to/file Line <67> number 100
Line <67> newline Line <67> newline
Line <67> newline Line <67> newline
Line <68> name excited
Line <68> colon :
Line <68> string path/to/file
Line <68> newline Line <68> newline
Line <68> newline Line <68> newline
Line <69> bracketo [
Line <69> name newblock
Line <69> colon :
Line <69> name function
Line <69> parao (
Line <69> parac )
Line <69> bracketc ]
Line <69> newline Line <69> newline
Line <69> newline Line <69> newline
Line <70> string Test #2 Line <70> bracketo [
Line <70> name newblock
Line <70> colon :
Line <70> name function
Line <70> parao (
Line <70> parac )
Line <70> bracketc ]
Line <70> newline Line <70> newline
Line <70> newline Line <70> newline
Line <71> string Does it parse this part properly? Line <71> string Test #2
Line <71> newline Line <71> newline
Line <71> newline Line <71> newline
Line <72> string huh Line <72> string Does it parse this part properly?
Line <72> newline Line <72> newline
Line <72> newline Line <72> newline
Line <72> eof Line <73> string huh
Line <73> newline
Line <73> newline
Line <73> eof
Line <1> newline Line <1> newline
Line <1> newline Line <1> newline
Line <1> flag Line <1> flag
@ -397,7 +394,7 @@ Line <23> newline
Line <24> newline Line <24> newline
Line <24> newline Line <24> newline
Line <25> bracketo [ Line <25> bracketo [
Line <25> name inventory Line <25> name inv
Line <25> colon : Line <25> colon :
Line <25> name env Line <25> name env
Line <25> bracketc ] Line <25> bracketc ]

View File

@ -22,7 +22,7 @@ disable hello
g = false g = false
return d return d
[inventory:env] [inv:env]
slot1 = "S1" slot1 = "S1"
slot2 = "S2" slot2 = "S2"
slot3 = "S3" slot3 = "S3"

BIN
DMS/test.dll Normal file

Binary file not shown.

View File

@ -3,6 +3,7 @@ entry main // Will either start the first block seen or the block supplied by yo
disable omniscient disable omniscient
enable forseelabels enable forseelabels
enable savestate enable savestate
disable fullname
//enable leaking //enable leaking
//enable debugging //enable debugging
loadfile "loadtest.dms" loadfile "loadtest.dms"
@ -14,9 +15,11 @@ using extendedDefine
Bob: { Bob: {
speed 50 speed 50
excited: "Hello Mr. `Ryan:lname`, " excited: "Hello Mr. `Ryan:lname`, "
"how are you doing?" "how are `inv:slot2` you doing?"
} }
//test = Bob[here]
//Ryan:setNickname(Bob,"Bobby") // Not yet implemeted! //Ryan:setNickname(Bob,"Bobby") // Not yet implemeted!
Ryan: { Ryan: {
@ -25,19 +28,17 @@ using extendedDefine
"Waiting ..." "Waiting ..."
exit 1
Bob: { Bob: {
"I am great thanks! I want to show you that I can count!\n" "I am great thanks! I want to show you that I can count!\n"
wait 1 wait .1
"1\n" "1\n"
wait 1 wait .1
"2\n" "2\n"
wait 1 wait .1
"3\n" "3\n"
wait 1 wait .1
"4\n" "4\n"
wait 1 wait .1
"5\n" "5\n"
} }
@ -58,7 +59,7 @@ using extendedDefine
"This also will cause a new line!" "This also will cause a new line!"
[Bob:char] [Bob:char]
fname = "Bob" //fname = "Bob"
//known = true // defaults to false //known = true // defaults to false
//lname = "Johnson" // defaults to "" //lname = "Johnson" // defaults to ""
unknown = "Some Rando" unknown = "Some Rando"

View File

@ -1,5 +1,10 @@
#include "utils.h" #include "utils.h"
namespace dms::utils { namespace dms::utils {
void sleep(unsigned int mseconds)
{
clock_t goal = mseconds + clock();
while (goal > clock());
}
bool isalphanum(std::string str) { bool isalphanum(std::string str) {
for (size_t i = 0; i < str.size(); i++) { for (size_t i = 0; i < str.size(); i++) {
if (!isalnum(str[i]) && str[i]!='_') if (!isalnum(str[i]) && str[i]!='_')

View File

@ -7,6 +7,7 @@
#include "value.h" #include "value.h"
#include <unordered_map> #include <unordered_map>
#include "dms_state.h" #include "dms_state.h"
#include <time.h>
namespace dms::utils { namespace dms::utils {
template<class... Args> template<class... Args>
void print(Args... args) { void print(Args... args) {
@ -22,6 +23,7 @@ namespace dms::utils {
(str << ... << args); (str << ... << args);
return str.str(); return str.str();
} }
void sleep(unsigned int mseconds);
std::string random_string(size_t length); std::string random_string(size_t length);
bool typeassert(dms_args args, datatypes t1=nil, datatypes t2 = nil, datatypes t3 = nil, datatypes t4 = nil, datatypes t5 = nil, datatypes t6 = nil, datatypes t7 = nil, datatypes t8 = nil, datatypes t9 = nil, datatypes t10 = nil, datatypes t11 = nil, datatypes t12 = nil); //Type asserting is mostly an internal thing for build in methods. It's not needed for dms code! bool typeassert(dms_args args, datatypes t1=nil, datatypes t2 = nil, datatypes t3 = nil, datatypes t4 = nil, datatypes t5 = nil, datatypes t6 = nil, datatypes t7 = nil, datatypes t8 = nil, datatypes t9 = nil, datatypes t10 = nil, datatypes t11 = nil, datatypes t12 = nil); //Type asserting is mostly an internal thing for build in methods. It's not needed for dms code!
bool typeassert(dms_state* state, dms_args args, datatypes t1 = nil, datatypes t2 = nil, datatypes t3 = nil, datatypes t4 = nil, datatypes t5 = nil, datatypes t6 = nil, datatypes t7 = nil, datatypes t8 = nil, datatypes t9 = nil, datatypes t10 = nil, datatypes t11 = nil, datatypes t12 = nil); bool typeassert(dms_state* state, dms_args args, datatypes t1 = nil, datatypes t2 = nil, datatypes t3 = nil, datatypes t4 = nil, datatypes t5 = nil, datatypes t6 = nil, datatypes t7 = nil, datatypes t8 = nil, datatypes t9 = nil, datatypes t10 = nil, datatypes t11 = nil, datatypes t12 = nil);

View File

@ -1,8 +1,7 @@
#include "value.h" #include "value.h"
#include "utils.h" #include "dms_state.h"
#include "string"
namespace dms { namespace dms {
const std::string datatype[] = { "nil", "number", "boolean", "env", "string", "custom", "variable", "block" }; const std::string datatype[] = { "escape","nil", "number", "boolean", "env", "string", "custom", "variable", "block" };
std::vector<value*> _VALUES; std::vector<value*> _VALUES;
value::value() { value::value() {
_VALUES.push_back(this); // Used for the interperter! In the end everything is a value _VALUES.push_back(this); // Used for the interperter! In the end everything is a value
@ -39,7 +38,7 @@ namespace dms {
if (state->memory.count(lookup)) { if (state->memory.count(lookup)) {
value* v = state->memory[lookup]; value* v = state->memory[lookup];
if (v->type == datatypes::block) { if (v->type == datatypes::block) {
if (state->getCharacter(v->s->getValue())!=nullptr) { if ((state->chunks.count(v->s->getValue()) && state->chunks[v->s->getValue()]->type == blocktype::bt_character) && state->getCharacter(v->s->getValue())!=nullptr) {
character* cha = state->getCharacter(v->s->getValue()); character* cha = state->getCharacter(v->s->getValue());
if (cha->values.count(index)) { if (cha->values.count(index)) {
temp << cha->values[index]->getPrintable(); temp << cha->values[index]->getPrintable();
@ -48,6 +47,15 @@ namespace dms {
temp << cha->getName(); temp << cha->getName();
} }
} }
else if ((state->chunks.count(v->s->getValue()) && state->chunks[v->s->getValue()]->type == blocktype::bt_env) && state->getEnviroment(v->s->getValue()) != nullptr) {
enviroment* env = state->getEnviroment(v->s->getValue());
if (env->values.count(index)) {
temp << env->values[index]->getPrintable();
}
else {
temp << env;
}
}
else { else {
temp << "nil"; temp << "nil";
} }
@ -175,10 +183,13 @@ namespace dms {
value* buildValue() { value* buildValue() {
return new value; return new value;
} }
value* buildNil() {
return new value;
}
size_t count = 0; size_t count = 0;
value* buildVariable() { value* buildVariable() {
count++; count++;
std::string val = utils::concat("$",count); std::string val = "$"+count;
return buildVariable(val); return buildVariable(val);
} }
value* buildBlock(std::string str) { value* buildBlock(std::string str) {
@ -214,6 +225,8 @@ namespace dms {
return val; return val;
} }
void value::nuke() { void value::nuke() {
if (type == datatypes::custom)
c->_del();
delete[] s; delete[] s;
delete[] b; delete[] b;
delete[] n; delete[] n;
@ -249,6 +262,12 @@ namespace dms {
e = en; e = en;
type = env; type = env;
} }
void dms::value::set(dms_custom* cus) {
nuke();
c = cus;
c->_set(this);
type = custom;
}
void value::set() { void value::set() {
nuke(); nuke();
type = nil; type = nil;

View File

@ -10,7 +10,7 @@ namespace dms {
struct value; struct value;
struct dms_args; struct dms_args;
extern const std::string datatype[]; extern const std::string datatype[];
enum datatypes { escape, nil, number, boolean, env, string, custom, variable, block }; enum datatypes { escape, nil, number, boolean, env, string, custom, variable, block, error };
struct dms_number { struct dms_number {
double val; double val;
double getValue() { return val; } double getValue() { return val; }
@ -42,6 +42,10 @@ namespace dms {
}; };
// Custom data that you can work with by overriding this code // Custom data that you can work with by overriding this code
struct dms_custom { struct dms_custom {
void Init(dms_state* state);
void _set(value* v);
void _del();
virtual value* Index(value* data); virtual value* Index(value* data);
virtual bool NewIndex(value* var, value* val); virtual bool NewIndex(value* var, value* val);
virtual value* Call(dms_args* args); virtual value* Call(dms_args* args);
@ -53,12 +57,16 @@ namespace dms {
virtual value* POW(value* left, value* right); virtual value* POW(value* left, value* right);
virtual value* EQUAL(value* left, value* right); virtual value* EQUAL(value* left, value* right);
virtual value* LESS_THAN(value* left, value* right); virtual value* LESS_THAN(value* left, value* right);
virtual value* GREATER_THAN(value* left, value* right); virtual value* LESS_THAN_EQUAL(value* left, value* right);
private:
dms_state* state=nullptr;
value* self;
}; };
dms_string* buildString(std::string str); dms_string* buildString(std::string str);
dms_boolean* buildBool(bool b); dms_boolean* buildBool(bool b);
dms_number* buildNumber(double num); dms_number* buildNumber(double num);
struct value { struct value {
public:
datatypes type = nil; datatypes type = nil;
dms_boolean* b = nullptr; dms_boolean* b = nullptr;
dms_number* n = nullptr; dms_number* n = nullptr;
@ -72,6 +80,7 @@ namespace dms {
void set(dms_boolean* bo); void set(dms_boolean* bo);
void set(dms_number* num); void set(dms_number* num);
void set(dms_env* en); void set(dms_env* en);
void set(dms_custom* cus);
void set(); void set();
bool typeMatch(const value* o) const; bool typeMatch(const value* o) const;
std::string getPrintable() const; std::string getPrintable() const;
@ -108,6 +117,7 @@ namespace dms {
}; };
}; };
value* buildValue(); value* buildValue();
value* buildNil();
value* buildVariable(std::string str); value* buildVariable(std::string str);
value* buildVariable(); value* buildVariable();
value* buildValue(std::string str); value* buildValue(std::string str);