Rightside implementation of indexing, todo left side

This commit is contained in:
Ryan Ward 2020-10-10 22:41:18 -04:00
parent 6b349615fa
commit 4e092ad8b6
12 changed files with 59 additions and 25 deletions

View File

@ -7,6 +7,7 @@ namespace dms {
struct character : enviroment { struct character : enviroment {
bool seen = false; bool seen = false;
double spd = 100; double spd = 100;
bool fullname = true;
std::unordered_map<std::string, std::string> paths; std::unordered_map<std::string, std::string> paths;
std::string getName(); std::string getName();
}; };

View File

@ -1,5 +1,5 @@
#include "dms.h" #include "dms.h"
#include <windows.h> //#include <windows.h>
#include <iostream> #include <iostream>
using namespace dms; using namespace dms;
typedef void(*FNPTR)(); typedef void(*FNPTR)();

View File

@ -119,6 +119,8 @@
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard> <LanguageStandard>stdcpp17</LanguageStandard>
<Optimization>Disabled</Optimization>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
@ -134,7 +136,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> <Optimization>MinSpace</Optimization>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>

View File

@ -526,8 +526,10 @@ namespace dms {
} }
else if (tempstream.match(tokens::newline)) { else if (tempstream.match(tokens::newline)) {
tempstream.next(); tempstream.next();
//badSymbol(stream); }
//return false; else {
badSymbol(&tempstream);
return false;
} }
} }

View File

@ -46,5 +46,6 @@ const std::string dms::codes::list[] = {
"LIST", "LIST",
"LINE", "LINE",
"HALT", "HALT",
"FILE" "FILE",
"GC"
}; };

View File

@ -48,7 +48,8 @@ namespace dms::codes {
LIST, LIST,
LINE, LINE,
HALT, HALT,
FILE FILE,
GC
}; };
extern const std::string list[]; extern const std::string list[];
static bool isControl(const op code) { static bool isControl(const op code) {

View File

@ -19,7 +19,6 @@ namespace dms {
} }
} }
c->opcode = codes::JUMP; c->opcode = codes::JUMP;
if (entry != "$undefined") if (entry != "$undefined")
c->args.push(buildValue(entry)); c->args.push(buildValue(entry));
@ -107,6 +106,7 @@ namespace dms {
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.
(*mem)[var->s->getValue()] = val; (*mem)[var->s->getValue()] = val;
return true;
} }
} }
void dms_state::dump(bool print) { void dms_state::dump(bool print) {
@ -124,7 +124,10 @@ 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) {
if (isEnabled("debugging")) { if (err.linenum != 0) {
std::cout << err.err_msg << " On Line <" << err.linenum << ">" << std::endl;
}
else if (isEnabled("debugging")) {
std::cout << err.err_msg << " On Line <" << cur_line << ">" << std::endl; std::cout << err.err_msg << " On Line <" << cur_line << ">" << std::endl;
} }
else { else {

View File

@ -55,6 +55,7 @@ namespace dms {
else { else {
if (blockExists(cha)) { if (blockExists(cha)) {
character* cc = new character; character* cc = new character;
cc->fullname = isEnabled("fullname");
cc->set("fname", buildValue(cha)); cc->set("fname", buildValue(cha));
cc->set("lname", buildValue("")); cc->set("lname", buildValue(""));
cc->set("unknown", buildValue("Unknown")); cc->set("unknown", buildValue("Unknown"));
@ -112,6 +113,10 @@ namespace dms {
return run("$INIT",&memory); return run("$INIT",&memory);
} }
bool dms_state::run(std::string ent, std::unordered_map<std::string, value*>* mem) { bool dms_state::run(std::string ent, std::unordered_map<std::string, value*>* mem) {
if (stop) {
exitcode = 1;
return false;
}
codes::op code; codes::op code;
cmd* c = nullptr; cmd* c = nullptr;
bool halt = false; bool halt = false;
@ -169,6 +174,36 @@ namespace dms {
} }
return true; return true;
break; break;
case INDX:
{
value* assn = c->args.args[0];
value* env = c->args.args[1];
value* indx = c->args.args[2]->resolve(*mem);
if (env->type == datatypes::block && blockExists(env->getPrintable())) { // If this is a block let's handle this
enviroment* e = nullptr;
if (enviroments.count(env->getPrintable())) {
e = enviroments[env->getPrintable()];
}
else if (characters.count(env->getPrintable())) {
e = characters[env->getPrintable()];
}
assign(mem, assn, e->values[indx->getPrintable()]);
}
else if (env->type == datatypes::env) {
if (indx->type == datatypes::number) {
assign(mem, assn, env->e->getValue(indx));
}
else {
push_error(errors::error{ errors::invalid_type ,concat("Expected a number value got ",datatype[indx->type]) });
return false;
}
}
else if (env->type == datatypes::custom) {
assign(mem, assn, env->c->Index(indx));
// Call the method within the custom data
}
}
break;
case LIST: case LIST:
//We need to create an enviroment value then set that //We need to create an enviroment value then set that
{ {

Binary file not shown.

View File

@ -71,22 +71,11 @@ Line <21> name test
Line <21> equal = Line <21> equal =
Line <21> name Bob Line <21> name Bob
Line <21> bracketo [ Line <21> bracketo [
Line <21> name a_test Line <21> string fname
Line <21> parao (
Line <21> cbracketo {
Line <21> number 4
Line <21> seperator ,
Line <21> name hi
Line <21> bracketo [
Line <21> string testing
Line <21> bracketc ]
Line <21> seperator ,
Line <21> number 6
Line <21> cbracketc }
Line <21> parac )
Line <21> bracketc ] Line <21> bracketc ]
Line <21> newline Line <21> newline
Line <21> newline Line <21> newline
Line <22> string `Bob`'s First Name is: `test`
Line <22> newline Line <22> newline
Line <22> newline Line <22> newline
Line <23> newline Line <23> newline

View File

@ -18,8 +18,8 @@ using extendedDefine
"how are `inv:slot2` you doing?" "how are `inv:slot2` you doing?"
} }
test = Bob[a_test({4,hi["testing"],6})] test = Bob["fname"]
"`Bob`'s First Name is: `test`"
//Ryan:setNickname(Bob,"Bobby") // Not yet implemeted! //Ryan:setNickname(Bob,"Bobby") // Not yet implemeted!
Ryan: { Ryan: {

View File

@ -11,7 +11,7 @@ namespace dms {
// At the end we actually delete them! // At the end we actually delete them!
} }
value* value::resolve(std::unordered_map<std::string, value*> memory) { value* value::resolve(std::unordered_map<std::string, value*> memory) {
if (type == datatypes::variable) { if (type == datatypes::variable && this!=memory[this->s->getValue()]) {
return memory[s->getValue()]->resolve(memory); // Variable types return the value return memory[s->getValue()]->resolve(memory); // Variable types return the value
} }
return this; return this;
@ -101,7 +101,7 @@ namespace dms {
} }
} }
else { else {
temp << v->getPrintable(); temp << v->resolve(state->memory)->getPrintable();
} }
} }
else { else {