Indexing fixed, expressions fixed. Changes to characters

This commit is contained in:
Ryan Ward 2020-12-12 00:49:14 -05:00
parent 993b9e9b4d
commit f9c236857b
13 changed files with 213 additions and 102 deletions

View File

@ -46,10 +46,11 @@ int main()
enviroment* envio = new enviroment; enviroment* envio = new enviroment;
LineParser parser = LineParser("test.dms"); LineParser parser = LineParser("test.dms");
dms_state* state = parser.Parse(); dms_state* state = parser.Parse();
state->dump();
envio->registerFunction("print", print); envio->registerFunction("print", print);
state->invoker.registerFunction("print", print); state->invoker.registerFunction("print", print);
state->injectEnv("io",envio); state->injectEnv("io",envio);
state->dump();
state->run(); state->run();

View File

@ -93,6 +93,7 @@ namespace dms {
bool match_process_for(tokenstream* stream); bool match_process_for(tokenstream* stream);
bool match_process_number(tokenstream* stream, value& v); bool match_process_number(tokenstream* stream, value& v);
bool match_process_asm(tokenstream* stream); bool match_process_asm(tokenstream* stream);
bool match_process_1afunc(tokenstream* stream, value& v);
// Build // Build
void buildGoto(std::string g, bool v = false); void buildGoto(std::string g, bool v = false);

View File

@ -73,6 +73,10 @@ namespace dms {
} }
return true; return true;
} }
if (match_process_1afunc(stream, v)) {
match_process_condition(stream, v);
return true;
}
if (match_process_expression(stream, v)) { if (match_process_expression(stream, v)) {
match_process_condition(stream,v); match_process_condition(stream,v);
return true; return true;
@ -330,8 +334,46 @@ namespace dms {
} }
return false; return false;
} }
bool LineParser::match_process_1afunc(tokenstream* stream, value& v ) {
if (stream->match(tokens::name,tokens::string) || stream->match(tokens::name,tokens::number) || stream->match(tokens::name,tokens::minus)) {
cmd* c = new cmd;
c->opcode = codes::FUNC;
c->args.push(value(stream->next().name,variable));
c->args.push(v);
value num;
if (stream->match(tokens::string)) {
c->args.push(value(stream->next().name));
} else if (match_process_number(stream,num)) {
c->args.push(num);
}
current_chunk->addCmd(c);
return true;
}
return false;
}
bool LineParser::match_process_disp(tokenstream* stream) { bool LineParser::match_process_disp(tokenstream* stream) {
if ((isBlock(bt_block) || isBlock(bt_method)) && stream->match(tokens::newline, tokens::string, tokens::newline)) { if (stream->match(tokens::name,tokens::colon)) {
std::string name = stream->next().name;
stream->next();
cmd* c = new cmd;
c->opcode = codes::SSPK;
c->args.push(value(name, datatypes::variable));
current_chunk->addCmd(c);
value msg(variable);
if (match_process_standard(stream, msg)) {
c = new cmd;
c->opcode = codes::DISP;
c->args.push(msg);
current_chunk->addCmd(c); // Add the cmd to the current chunk
current_chunk->addCmd(new cmd{ codes::HALT });
}
else {
badSymbol(stream);
return false;
}
return true;
}
else if ((isBlock(bt_block) || isBlock(bt_method)) && stream->match(tokens::newline, tokens::string, tokens::newline)) {
stream->next(); // Standard consumption stream->next(); // Standard consumption
cmd* c = new cmd; cmd* c = new cmd;
c->opcode = codes::DISP; c->opcode = codes::DISP;
@ -874,6 +916,8 @@ namespace dms {
c->args.push(v); c->args.push(v);
c->args.push(value(name,datatypes::block)); c->args.push(value(name,datatypes::block));
c->args.push(tempval); c->args.push(tempval);
current_chunk->addCmd(c);
return true;
} }
else if (nlcount) { else if (nlcount) {
state->push_error(errors::error{ errors::badtoken,concat("Unexpected symbol '",tempstream.last().toString(),"' Expected ']' to close list (line: ",tempstream.last().line_num,") Indexing must be done on one line?"),true,tempstream.last().line_num,current_chunk }); state->push_error(errors::error{ errors::badtoken,concat("Unexpected symbol '",tempstream.last().toString(),"' Expected ']' to close list (line: ",tempstream.last().line_num,") Indexing must be done on one line?"),true,tempstream.last().line_num,current_chunk });
@ -888,9 +932,6 @@ namespace dms {
return false; return false;
} }
} }
current_chunk->addCmd(c);
return true;
} }
return false; return false;
} }
@ -1171,8 +1212,6 @@ namespace dms {
o = codes::CHOI; o = codes::CHOI;
else if (cmd == "blck") else if (cmd == "blck")
o = codes::BLCK; o = codes::BLCK;
else if (cmd == "fore")
o = codes::FORE;
else if (cmd == "whle") else if (cmd == "whle")
o = codes::WHLE; o = codes::WHLE;
else if (cmd == "func") else if (cmd == "func")
@ -1578,6 +1617,19 @@ namespace dms {
return false; return false;
} }
} }
else if (stream->match(tokens::name, tokens::bracketo)) {
value tmpvalue = value(datatypes::variable);
if (match_process_index(stream, tmpvalue)) {
if (left.isNil())
left = tmpvalue;
else if (right.isNil())
right = tmpvalue;
else {
badSymbol(stream);
return false;
}
}
}
else if (stream->match(tokens::name)) { else if (stream->match(tokens::name)) {
// We tested functions already! So if that fails and we have a name then... we have a variable lets handle this! // We tested functions already! So if that fails and we have a name then... we have a variable lets handle this!
if (left.isNil()) if (left.isNil())

View File

@ -519,6 +519,7 @@ namespace dms {
manageCount(match_process_wait(stream), count, current_count); manageCount(match_process_wait(stream), count, current_count);
//utils::print("[jump]"); //utils::print("[jump]");
manageCount(match_process_jump(stream), count, current_count); manageCount(match_process_jump(stream), count, current_count);
manageCount(match_process_1afunc(stream, nil),count,current_count);
manageCount(match_process_asm(stream), count, current_count); manageCount(match_process_asm(stream), count, current_count);
if (count != 0 && current_count == count) { if (count != 0 && current_count == count) {
return true; // We got what we came for, we exit and consume no more! return true; // We got what we came for, we exit and consume no more!

View File

@ -2,7 +2,7 @@
#include "utils.h" #include "utils.h"
namespace dms { namespace dms {
value character_setName(void* self, dms_state* state, dms_args* args) { value character_setName(void* self, dms_state* state, dms_args* args) {
if(utils::typeassert(*args, datatypes::string)) { if(args->args[0].type == datatypes::string){
character* me = (character*)self; character* me = (character*)self;
me->set("fname", args->args[0]); me->set("fname", args->args[0]);
} }

View File

@ -14,7 +14,7 @@ const std::string dms::codes::list[] = {
"LABL", "LABL",
"CHOI", "CHOI",
"BLCK", "BLCK",
"FORE", "CHAR",
"WHLE", "WHLE",
"FUNC", "FUNC",
"IFFF", "IFFF",

View File

@ -15,8 +15,8 @@ namespace dms::codes {
ASGN, // Done ASGN, // Done
LABL, // Done LABL, // Done
CHOI, // Done CHOI, // Done
BLCK, BLCK, //
FORE, CHAR, // Done
WHLE, WHLE,
FUNC, // Done FUNC, // Done
IFFF, // Done IFFF, // Done

View File

@ -43,6 +43,12 @@ namespace dms {
c->args.push(value(key, datatypes::variable)); c->args.push(value(key, datatypes::variable));
c->args.push(value(key, datatypes::block)); c->args.push(value(key, datatypes::block));
chunks["$INIT"]->addCmd(c); chunks["$INIT"]->addCmd(c);
if (val->type == bt_character) {
c = new cmd;
c->opcode = codes::CHAR;
c->args.push(value(key));
chunks["$INIT"]->addCmd(c);
}
c = new cmd; c = new cmd;
} }
else if (val->type == bt_method) { else if (val->type == bt_method) {
@ -141,7 +147,7 @@ namespace dms {
bool dms_state::injectEnv(std::string name, enviroment* env) bool dms_state::injectEnv(std::string name, enviroment* env)
{ {
std::string ename = std::string("$ENV_") + name; std::string ename = name;
assign(value(name, datatypes::variable), value(ename, datatypes::block)); assign(value(name, datatypes::variable), value(ename, datatypes::block));
environments.insert_or_assign(ename, env); environments.insert_or_assign(ename, env);
chunk* c = new chunk; chunk* c = new chunk;
@ -160,8 +166,8 @@ namespace dms {
push_error(errors::error{ errors::unknown ,val.s }); push_error(errors::error{ errors::unknown ,val.s });
return false; return false;
} }
if(val.state==nullptr)
val.state = this; val.state = this;
var.state = this;
(*getMem())[var.getPrintable()] = val; (*getMem())[var.getPrintable()] = val;
return true; return true;
} }

View File

@ -254,7 +254,7 @@ namespace dms {
break; break;
case OFUN: case OFUN:
{ {
std::string obj = c->args.args[0].resolve(this).getPrintable(); std::string obj = c->args.args[0].getPrintable();
if (obj=="nil") { if (obj=="nil") {
obj = c->args.args[0].getPrintable(); obj = c->args.args[0].getPrintable();
} }
@ -410,13 +410,13 @@ namespace dms {
value assn = c->args.args[0]; value assn = c->args.args[0];
value env = c->args.args[1]; value env = c->args.args[1];
value indx = c->args.args[2].resolve(this); value indx = c->args.args[2].resolve(this);
if (env.type == datatypes::block && blockExists(env.getPrintable())) { // If this is a block let's handle this if (env.type == datatypes::block && blockExists(env.s)) { // If this is a block let's handle this
enviroment* e = nullptr; enviroment* e = nullptr;
if (environments.count(env.getPrintable())) { if (environments.count(env.s)) {
e = environments[env.getPrintable()]; e = environments[env.s];
} }
else if (characters.count(env.getPrintable())) { else if (characters.count(env.s)) {
e = characters[env.getPrintable()]; e = characters[env.s];
} }
if(!assign( assn, e->values[indx.getPrintable()])) { if(!assign( assn, e->values[indx.getPrintable()])) {
return false; return false;
@ -540,15 +540,18 @@ namespace dms {
} }
break; break;
case APND: case APND:
//FIX STRING STER if (!handler->handleMessageAppend(this, c->args.args[0].resolve(this).getPrintable()))
if (!handler->handleMessageAppend(this, c->args.args[0].s))
return false; return false;
break; break;
case CHAR:
{
std::string cha = c->args.args[0].s;
getCharacter(cha);
break;
}
case DISP: case DISP:
{ {
//FIX STRING STER if (!handler->handleMessageDisplay(this, c->args.args[0].resolve(this).getPrintable()))
value disp = c->args.args[0].resolve(this).getPrintable();
if (!handler->handleMessageDisplay(this, c->args.args[0].s))
return false; return false;
} }
break; break;

Binary file not shown.

View File

@ -21,9 +21,6 @@ Line <6> name savestate
Line <6> newline Line <6> newline
Line <6> newline Line <6> newline
Line <7> newline Line <7> newline
Line <8> flag
Line <8> name debugging
Line <8> newline
Line <8> newline Line <8> newline
Line <9> newline Line <9> newline
Line <10> flag Line <10> flag
@ -41,110 +38,149 @@ Line <12> newline
Line <12> newline Line <12> newline
Line <13> name Ryan Line <13> name Ryan
Line <13> colon : Line <13> colon :
Line <13> string I am good Line <13> string Hello Mr.
Line <13> plus +
Line <13> name Bob
Line <13> bracketo [
Line <13> string lname
Line <13> bracketc ]
Line <13> plus +
Line <13> string ! How are you doing?
Line <13> newline Line <13> newline
Line <13> newline Line <13> newline
Line <14> name John Line <14> name Bob
Line <14> colon : Line <14> dot .
Line <14> string Hi Line <14> name setName
Line <14> plus + Line <14> parao (
Line <14> name Ryan Line <14> string Rob
Line <14> plus + Line <14> parac )
Line <14> string how are you?
Line <14> newline Line <14> newline
Line <14> newline Line <14> newline
Line <15> name Ryan
Line <15> colon :
Line <15> string Hello
Line <15> plus +
Line <15> name Bob
Line <15> plus +
Line <15> string ! How are you doing?
Line <15> newline Line <15> newline
Line <15> newline Line <15> newline
Line <16> newline Line <16> newline
Line <16> newline
Line <17> newline Line <17> newline
Line <17> newline Line <17> newline
Line <18> bracketo [
Line <18> name John
Line <18> colon :
Line <18> name char
Line <18> bracketc ]
Line <18> newline Line <18> newline
Line <18> newline
Line <19> name lname
Line <19> equal =
Line <19> string Johnson
Line <19> newline Line <19> newline
Line <19> newline
Line <20> name age
Line <20> equal =
Line <20> number 16
Line <20> newline Line <20> newline
Line <20> newline
Line <21> name money
Line <21> equal =
Line <21> number 100000
Line <21> newline Line <21> newline
Line <21> newline
Line <22> name known
Line <22> equal =
Line <22> true true
Line <22> newline Line <22> newline
Line <22> newline Line <22> newline
Line <23> bracketo [
Line <23> name test
Line <23> colon :
Line <23> name function
Line <23> parao (
Line <23> name n
Line <23> parac )
Line <23> bracketc ]
Line <23> newline Line <23> newline
Line <23> newline Line <23> newline
Line <24> bracketo [ Line <24> ret
Line <24> name Ryan Line <24> name n
Line <24> colon : Line <24> plus +
Line <24> name char Line <24> number 1
Line <24> bracketc ]
Line <24> newline Line <24> newline
Line <24> newline Line <24> newline
Line <25> name lname
Line <25> equal =
Line <25> string Ward
Line <25> newline Line <25> newline
Line <25> newline Line <25> newline
Line <26> name age Line <26> bracketo [
Line <26> equal = Line <26> name Ryan
Line <26> number 24 Line <26> colon :
Line <26> name char
Line <26> bracketc ]
Line <26> newline Line <26> newline
Line <26> newline Line <26> newline
Line <27> name known Line <27> name lname
Line <27> equal = Line <27> equal =
Line <27> true true Line <27> string Ward
Line <27> newline Line <27> newline
Line <27> newline Line <27> newline
Line <28> name money Line <28> name age
Line <28> equal = Line <28> equal =
Line <28> number 0 Line <28> number 24
Line <28> newline Line <28> newline
Line <28> newline Line <28> newline
Line <29> name known
Line <29> equal =
Line <29> true true
Line <29> newline Line <29> newline
Line <29> newline Line <29> newline
Line <30> bracketo [ Line <30> name money
Line <30> name Bob Line <30> equal =
Line <30> colon : Line <30> number 0
Line <30> name char
Line <30> bracketc ]
Line <30> newline Line <30> newline
Line <30> newline Line <30> newline
Line <31> newline Line <31> newline
Line <31> newline
Line <32> bracketo [
Line <32> name John
Line <32> colon :
Line <32> name char
Line <32> bracketc ]
Line <32> newline Line <32> newline
Line <32> newline
Line <33> name lname
Line <33> equal =
Line <33> string Johnson
Line <33> newline Line <33> newline
Line <34> name unknown Line <33> newline
Line <34> name age
Line <34> equal = Line <34> equal =
Line <34> string Some Random Guy Line <34> number 16
Line <34> newline Line <34> newline
Line <34> newline Line <34> newline
Line <35> name age Line <35> name money
Line <35> equal = Line <35> equal =
Line <35> number 24 Line <35> number 100000
Line <35> newline Line <35> newline
Line <35> newline Line <35> newline
Line <36> name money Line <36> name known
Line <36> equal = Line <36> equal =
Line <36> number 100 Line <36> true true
Line <36> newline Line <36> newline
Line <36> newline Line <36> newline
Line <37> name excited
Line <37> colon :
Line <37> string path/to/file
Line <37> newline Line <37> newline
Line <37> newline Line <37> newline
Line <37> eof Line <38> bracketo [
Line <38> name Bob
Line <38> colon :
Line <38> name char
Line <38> bracketc ]
Line <38> newline
Line <38> newline
Line <39> newline
Line <40> newline
Line <41> name lname
Line <41> equal =
Line <41> string Johnson
Line <41> newline
Line <42> name unknown
Line <42> equal =
Line <42> string Some Random Guy
Line <42> newline
Line <42> newline
Line <43> name age
Line <43> equal =
Line <43> number 24
Line <43> newline
Line <43> newline
Line <44> name money
Line <44> equal =
Line <44> number 100
Line <44> newline
Line <44> newline
Line <45> name excited
Line <45> colon :
Line <45> string path/to/file
Line <45> newline
Line <45> newline
Line <45> eof

View File

@ -1,25 +1,27 @@
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 fullname disable fullname
enable forwardlabels // Do most of your labels exist ahead? enable forwardlabels // Do most of your labels exist ahead?
enable savestate enable savestate
//enable leaking //enable leaking
enable debugging //enable debugging
//loadfile "loadtest.dms" //loadfile "loadtest.dms"
version 0.2 version 0.2
using extendedDefine using extendedDefine
[main] [main]
Ryan: "I am good" Ryan: "Hello Mr. " + Bob["lname"] + "! How are you doing?"
John: "Hi " + Ryan + " how are you?" Bob.setName("Rob")
Ryan: "Hello " + Bob + "! How are you doing?"
//io.print(test 122 + 7)
// Ryan: "I am good"
// John: "Hi " + Ryan + " how are you?"
// sqrt 144 + 10
// speed
[test:function(n)]
[John:char] return n + 1
lname = "Johnson"
age = 16
money = 100000
known = true
[Ryan:char] [Ryan:char]
lname = "Ward" lname = "Ward"
@ -27,10 +29,16 @@ using extendedDefine
known = true known = true
money = 0 money = 0
[John:char]
lname = "Johnson"
age = 16
money = 100000
known = true
[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 Random Guy" unknown = "Some Random Guy"
age = 24 age = 24
money = 100 money = 100

View File

@ -55,6 +55,7 @@ namespace dms {
value::value(const value& other) { value::value(const value& other) {
if (this != &other) { if (this != &other) {
type = other.type; type = other.type;
state = other.state;
switch (other.type) { switch (other.type) {
case datatypes::block: case datatypes::block:
s = other.s; s = other.s;
@ -97,6 +98,7 @@ namespace dms {
if (this != &other) { if (this != &other) {
nuke(); // Delete it all nuke(); // Delete it all
type = other.type; type = other.type;
state = other.state;
switch (other.type) { switch (other.type) {
case datatypes::block: case datatypes::block:
s = other.s; s = other.s;
@ -145,6 +147,7 @@ namespace dms {
if (this != &other) { if (this != &other) {
nuke(); nuke();
type = other.type; type = other.type;
state = other.state;
switch (other.type) { switch (other.type) {
case datatypes::block: case datatypes::block:
s = other.s; s = other.s;
@ -344,9 +347,9 @@ namespace dms {
} }
return false; return false;
} }
value value::resolve(dms_state* state) { value value::resolve(dms_state* _state) {
if (type == datatypes::variable && (*this)!=(*state->getMem())[getPrintable()]) { if (type == datatypes::variable && (*this)!=(*_state->getMem())[s]) {
return (*state->getMem())[getPrintable()].resolve(state); return (*_state->getMem())[s].resolve(_state);
} }
return *this; return *this;
} }