diff --git a/DMS/DMS.cpp b/DMS/DMS.cpp index cbef133..fdbdd0f 100644 --- a/DMS/DMS.cpp +++ b/DMS/DMS.cpp @@ -5,6 +5,7 @@ #include #include "value.h" #include "enviroment.h" +#include "sterilizer.h" //#include using namespace dms; //typedef void(*FNPTR)(); diff --git a/DMS/DMS.vcxproj b/DMS/DMS.vcxproj index 80d8a29..7290bb1 100644 --- a/DMS/DMS.vcxproj +++ b/DMS/DMS.vcxproj @@ -189,6 +189,7 @@ + diff --git a/DMS/DMS.vcxproj.filters b/DMS/DMS.vcxproj.filters index 0fd0b1f..f215b57 100644 --- a/DMS/DMS.vcxproj.filters +++ b/DMS/DMS.vcxproj.filters @@ -25,6 +25,12 @@ {4c0bb4c5-388c-4f15-abb7-143cb6d6232f} + + {f71964f6-66b3-4d8c-a8da-56d703ad1c2a} + + + {32abbbfd-6359-488c-83be-f61da8fd8f4d} + @@ -143,5 +149,8 @@ Header Files\DMS + + Header Files\DMS\C-API + \ No newline at end of file diff --git a/DMS/dms_custom.cpp b/DMS/dms_custom.cpp index 1c4cbcd..0261106 100644 --- a/DMS/dms_custom.cpp +++ b/DMS/dms_custom.cpp @@ -3,59 +3,61 @@ //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 value(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 value(left.getPrintable() == right.getPrintable()); - } - value dms_custom::LESS_THAN(value left, value right) { - return value(left.getPrintable() < right.getPrintable()); - } - value dms_custom::LESS_THAN_EQUAL(value left, value right) { - return value(left.getPrintable() <= right.getPrintable()); + extern "C" { // Custom data needs to be c ready + 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 value(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 value(left.getPrintable() == right.getPrintable()); + } + value dms_custom::LESS_THAN(value left, value right) { + return value(left.getPrintable() < right.getPrintable()); + } + value dms_custom::LESS_THAN_EQUAL(value left, value right) { + return value(left.getPrintable() <= right.getPrintable()); + } } } \ No newline at end of file diff --git a/DMS/dump.bin b/DMS/dump.bin index e362c2c..247ff62 100644 Binary files a/DMS/dump.bin and b/DMS/dump.bin differ diff --git a/DMS/sterilizer.h b/DMS/sterilizer.h new file mode 100644 index 0000000..b615269 --- /dev/null +++ b/DMS/sterilizer.h @@ -0,0 +1,21 @@ +#pragma once +#include "value.h" +// This file converts the c++ objects into a form that c is happy with +extern "C" { + using namespace dms; + // All structs types in this file will have an s_typename infront of it + // All methods will have an sf_methodname infron of it as well + struct s_value { + datatypes type = nil; // The type of the value + unsigned int slen; // Length of string + const char* s; // Contains the string part. + uint64_t i; // The int portion of the code + double n; + void setInt(int n); // Define value as an int + void setDouble(double n); // Define value as a double + void setString(const char* s); // Define value as a string + void setBlock(const char* s); // Define value as a block + void setVariable(const char* s); // Define value as a variable + void setNil(); // Define value as nil + }; +} \ No newline at end of file diff --git a/DMS/value.cpp b/DMS/value.cpp index 75b87f2..11246a5 100644 --- a/DMS/value.cpp +++ b/DMS/value.cpp @@ -356,123 +356,6 @@ namespace dms { size_t dms_args::size() { return args.size(); } - std::string dms_string::getValue(dms_state* state) { - std::vector _temp; - std::vector _var; - std::vector _ind; - std::stringstream temp; - std::stringstream var; - std::stringstream ind; - bool varStart = false; - bool indStart = false; - for (size_t i = 0; i < val.size(); i++) { - if (indStart && val[i] == '`') { - std::string lookup = var.str(); - std::string index = ind.str(); - var.str(""); - var.clear(); - ind.str(""); - ind.clear(); - varStart = false; - indStart = false; - if (state->getMem()->count(lookup)) { - value v = (*state->getMem())[lookup]; - if (v.type == datatypes::block) { - if (state->getCharacter(v.getPrintable()) != nullptr) { - character* cha = state->getCharacter(v.getPrintable()); - if (cha->values.count(index)) { - temp << cha->values[index].getPrintable(); - } - else { - temp << cha->getName(); - } - } - else if (state->getEnvironment(v.getPrintable())!=nullptr) { - enviroment* env = state->getEnvironment(v.getPrintable()); - if (env->values.count(index)) { - temp << env->values[index].getPrintable(); - } - else { - temp << env; - } - } - else { - temp << "nil"; - } - } - else if (v.resolve(state).type == datatypes::env) { - if(v.resolve(state).e->ipart.size()> std::stoi(index)) - temp << v.resolve(state).e->ipart[std::stoi(index)-(int64_t)1].getPrintable(); - else - temp << "nil"; - } - else { - temp << v.resolve(state).getPrintable(); - } - } - else { - temp << "nil"; - } - } - else if (indStart && val[i] == ':') { - state->push_error(errors::error{ errors::badtoken,"Cannot index more than once in a string injection!" }); - varStart = false; - indStart = false; - var.str(""); - var.clear(); - ind.str(""); - ind.clear(); - return ""; - } - else if (indStart) { - ind << val[i]; - } - else if (val[i] == '`' && !varStart) { - varStart = true; - - } - else if (val[i] == '`' && varStart) { - std::string lookup = var.str(); - var.str(""); - var.clear(); - varStart = false; - if (state->getMem()->count(lookup)) { - value v = (*state->getMem())[lookup]; - if (v.type == datatypes::block) { - if (state->getCharacter(v.s)) { - temp << state->characters[v.s]->getName(); - } - else { - temp << "nil"; - } - } - else { - temp << v.resolve(state).getPrintable(); - } - } - else { - temp << "nil"; - } - } - // A space is not allowed at all - else if (val[i] == ':' && varStart) { - indStart = true; - } - else if (val[i] == ' ' && varStart) { - temp << var.str(); - varStart = false; - var.str(""); - var.clear(); - } - else if (varStart) { - var << val[i]; - } - else { - temp << val[i]; - } - } - return temp.str(); - } std::string value::getPrintable() const { if (type == string) { return s; @@ -608,9 +491,6 @@ namespace dms { nuke(); type = nil; } - std::string dms_string::getValue() { - return val; - } void dms_list::pushValue(value val) { ipart.push_back(val); } @@ -638,16 +518,4 @@ namespace dms { } return str.str(); } - std::ostream& operator << (std::ostream& out, const dms_string& c) { - out << c.val; - return out; - } - std::ostream& operator << (std::ostream& out, const dms_boolean& c) { - out << c.val; - return out; - } - std::ostream& operator << (std::ostream& out, const dms_number& c) { - out << c.val; - return out; - } } \ No newline at end of file diff --git a/DMS/value.h b/DMS/value.h index 8201cdb..564cb8d 100644 --- a/DMS/value.h +++ b/DMS/value.h @@ -12,23 +12,6 @@ namespace dms { struct dms_state; extern const std::string datatype[]; enum datatypes { escape, nil, number, int64, boolean, env, string, custom, variable, block, error }; - struct dms_number { - double val; - double getValue() { return val; } - friend std::ostream& operator << (std::ostream& out, const dms_number& c); - }; - struct dms_boolean { - bool val; - bool getValue() { return val; } - friend std::ostream& operator << (std::ostream& out, const dms_boolean& c); - }; - - struct dms_string { - std::string val; - std::string getValue(); - std::string getValue(dms_state* state); - friend std::ostream& operator << (std::ostream& out, const dms_string& c); - }; // Custom data that you can work with by overriding this code struct dms_custom { void Init(dms_state* state); diff --git a/README.md b/README.md index 5b11a34..51cc5ed 100644 --- a/README.md +++ b/README.md @@ -8,3 +8,4 @@ The Dialogue Management Script's goal is to provide a nice and simple way to hav - [X] ~~Interpert all the bytecode~~ - [ ] Finish implementing custom datatype - [ ] Speed up interperter +- [ ] Finish C API for code