Fixed tons of bugs, started working on conditions

This commit is contained in:
Ryan Ward 2020-11-17 00:10:41 -05:00
parent b602823646
commit ea05df4529
18 changed files with 379 additions and 146 deletions

View File

@ -4,20 +4,31 @@
//#include "utils.h"
#include <iostream>
#include "value.h"
#include <chrono>
using namespace dms;
using namespace utils;
//typedef void(*FNPTR)();
using namespace std::chrono;
value invokeTest(void* self, dms_state* state, dms_args* args) {
utils::print(args->args[0].getPrintable());
return "I work!";
}
value print(void* self, dms_state* state, dms_args* args) {
for (size_t i = 0; i < args->size()-1; i++)
std::cout << args->args[i].getPrintable() << '\t';
std::cout << std::endl;
return value();
}
int main()
{
/*milliseconds ms = duration_cast<milliseconds>(
system_clock::now().time_since_epoch()
);
utils::print(ms.count());*/
LineParser parser = LineParser("test.dms");
dms_state* state = parser.Parse();
state->invoker.registerFunction("invokeTest", invokeTest);
state->invoker.registerFunction("print", print);
state->dump();
state->run();

View File

@ -169,6 +169,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="character.h" />
<ClInclude Include="comparisons.h" />
<ClInclude Include="dms_list.h" />
<ClInclude Include="enviroment.h" />
<ClInclude Include="Handlers.h" />

View File

@ -140,5 +140,8 @@
<ClInclude Include="dms_list.h">
<Filter>Source Files\DMS</Filter>
</ClInclude>
<ClInclude Include="comparisons.h">
<Filter>Header Files\DMS</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -24,7 +24,7 @@ namespace dms {
return funcs[str](self, state, args);
}
state->push_error(errors::error{ errors::non_existing_function, utils::concat("Attempt to call '",str,"' a nil value!") });
return nullptr;
return value(datatypes::error);
}
std::unordered_map<std::string, value (*)(void*, dms_state*, dms_args*)> Invoker::Export() {
return funcs;

View File

@ -14,6 +14,7 @@
#include "token.h"
#include "utils.h"
#include "errors.h"
#include "comparisons.h"
namespace dms {
struct tokenstream {
@ -76,6 +77,8 @@ namespace dms {
bool match_process_standard(tokenstream* stream, value& v); // All types that are matchable are handled here!
bool match_process_index(tokenstream* stream,value& v, bool leftside = false);
bool match_process_return(tokenstream* stream);
bool match_process_condition(tokenstream* stream, value& v);
bool match_process_if(tokenstream* stream);
// Build
void buildGoto(std::string g, bool v = false);

View File

@ -5,43 +5,53 @@ using namespace dms::utils;
namespace dms {
bool LineParser::match_process_standard(tokenstream* stream, value& v) {
if (match_process_expression(stream, v)) {
match_process_condition(stream,v);
return true;
}
else if (match_process_function(stream, v)) {
match_process_condition(stream, v);
return true;
}
else if (match_process_list(stream, v)) {
match_process_condition(stream, v);
return true;
}
else if (match_process_index(stream, v)) {
match_process_condition(stream, v);
return true;
}
else if (stream->match(tokens::True)) {
v.set(buildBool(true));
v.set(true);
stream->next();
match_process_condition(stream, v);
return true;
}
else if (stream->match(tokens::False)) {
v.set(buildBool(false));
v.set(false);
stream->next();
match_process_condition(stream, v);
return true;
}
else if (stream->match(tokens::number)) {
v.set(std::stod(stream->next().name));
match_process_condition(stream, v);
return true;
}
else if (stream->match(tokens::string)) {
v.set(buildString(stream->next().name));
match_process_condition(stream, v);
return true;
}
else if (stream->match(tokens::name)) {
v.set(buildString(stream->next().name));
v.type = datatypes::variable;
match_process_condition(stream, v);
return true;
}
else if (stream->match(tokens::nil)) {
stream->next();
v.set();
match_process_condition(stream, v);
return true;
}
else if (stream->match(tokens::bracketo, tokens::name, tokens::bracketc)) {
@ -50,6 +60,7 @@ namespace dms {
v.set(buildString(stream->next().name));
v.type = datatypes::block;
stream->next();
match_process_condition(stream, v);
return true;
}
else if (stream->match(tokens::newline)) {
@ -57,6 +68,76 @@ namespace dms {
}
return false;
}
bool LineParser::match_process_condition(tokenstream* stream, value& v) {
// This has taken way too long, but there exists only a few places where this needs to be interjected
// The reference to v needs some work if we have a comparison!
// First we need to get a copy of v store it somewhere do the comparision and convert v into a variable that points to the output of the comparison
comp cmp;
// We only need to see if one of these conditions are true
//==
if (stream->match(tokens::equal,tokens::equal)) {
cmp = comp::eq;
stream->next();
stream->next();
}
//<=
else if (stream->match(tokens::anglebracketO, tokens::equal)) {
cmp = comp::lteq;
stream->next();
stream->next();
}
//>=
else if (stream->match(tokens::anglebracketC, tokens::equal)) {
cmp = comp::gteq;
stream->next();
stream->next();
}
//!=
else if (stream->match(tokens::exclamation, tokens::equal)) {
cmp = comp::nteq;
stream->next();
stream->next();
}
//<
else if (stream->match(tokens::anglebracketO)) {
cmp = comp::lt;
stream->next();
}
//>
else if (stream->match(tokens::anglebracketC)) {
cmp = comp::gt;
stream->next();
}
else {
return false;
}
// So if all is good we continue here
value right = value(datatypes::variable);
value left = v;
value var = value(datatypes::variable);
// COMP cmp out v1 v2
if (match_process_standard(stream,right)) {
v.set(buildString(var.s->getValue()));
v.type = datatypes::variable;
cmd* c = new cmd;
c->opcode = codes::COMP;
c->args.push(value((double)cmp));
c->args.push(var);
c->args.push(left);
c->args.push(right);
current_chunk->addCmd(c);
return true;
}
else {
badSymbol(stream);
return false;
}
}
//Covers if, elseif, else
bool LineParser::match_process_if(tokenstream* stream) {
return false;
}
bool LineParser::match_process_list(tokenstream* stream, value& v) {
if (stream->match(tokens::cbracketo)) {
token start = stream->peek();
@ -557,7 +638,7 @@ namespace dms {
if (tempstream.match(tokens::seperator)) {
// We have a seperator for function arguments
tempstream.next(); // Consume it
}
}
else if (match_process_standard(&tempstream, tempval)) {
c->args.push(tempval);
}

View File

@ -231,6 +231,14 @@ namespace dms {
doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer);
t_vec.push_back(token{ tokens::ampersand,codes::NOOP,"&",line });
}
else if (data == '>') {
doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer);
t_vec.push_back(token{ tokens::anglebracketC,codes::NOOP,">",line });
}
else if (data == '>') {
doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer);
t_vec.push_back(token{ tokens::anglebracketO,codes::NOOP,"<",line });
}
else if (data == '\t') {
doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer);
t_vec.push_back(token{ tokens::tab,codes::NOOP,"\t",line });
@ -377,6 +385,10 @@ namespace dms {
flagcmd = new cmd;
}
else if (code == codes::ENTR && tok == tokens::name) {
if (state->entry != "$undefined") {
state->push_error(errors::error{ errors::unknown ,utils::concat("Entrypoint already defined as '",state->entry,"'. Trying to redefine as '",temp[0].name,"' is not allowed!"), true,stream->last().line_num,current_chunk });
return;
}
state->entry = temp[0].name;
flagcmd->opcode = code;
flagcmd->args.push(value(temp[0].name));
@ -411,6 +423,7 @@ namespace dms {
}
else {
state->push_error(errors::error{ errors::badtoken,concat("Expected <FLAG IDENTIFIER> got: ", current, temp[0]),true,line,current_chunk });
return;
}
}
// Default block
@ -470,6 +483,8 @@ namespace dms {
std::stringstream str;
str << "Unexpected symbol: " << tokens[i];
state->push_error(errors::error{ errors::badtoken,str.str(),true,line,current_chunk });
return;
}
}
// If all went well the 'args' now has all of tha params for the method we will be working with
@ -479,6 +494,8 @@ namespace dms {
else {
str << "'function' keyword expected got " << b;
state->push_error(errors::error{ errors::badtoken, str.str(),true,line,current_chunk });
return;
}
}
// Control Handle all controls here

View File

@ -18,7 +18,7 @@ namespace dms {
if (has("nickname")) {
return values["nickname"].getPrintable();
}
if (seen && has("fname") && has("lname")) {
if (seen && has("fname") && has("lname") && fullname) {
return utils::concat(values["fname"].getPrintable()," ", values["lname"].getPrintable());
}
else if (seen && has("fname")) {

11
DMS/comparisons.h Normal file
View File

@ -0,0 +1,11 @@
#pragma once
namespace dms {
enum comp {
eq,
gteq,
lteq,
nteq,
lt,
gt
};
}

View File

@ -2,7 +2,7 @@
#include "Handlers.h"
namespace dms {
void dms_state::init() {
if (init_init)
if (init_init || stop)
return;
init_init = true;
cmd* c = new cmd;
@ -37,6 +37,9 @@ namespace dms {
void dms_state::pushMem() {
mem_stack.push(memory());
}
void dms_state::pushMem(memory &mem) {
mem_stack.push(mem);
}
void dms_state::popMem() {
mem_stack.pop();
}

View File

@ -12,11 +12,13 @@
#include "memory.h"
#include <stack>
#include "dms_list.h"
#include "comparisons.h"
namespace dms {
struct Handler;
value blockInvoke(void*, dms_state*, dms_args*);
struct dms_state
{
friend class LineParser;
Handler* handler = nullptr;
bool hasFirst = false;
Invoker invoker;
@ -74,6 +76,7 @@ namespace dms {
private:
// From what I gathered
//std::mutex memory_mutex;
void pushMem(memory&);
bool stop = false;
bool init_init = false;
void init(chunk* chunk, size_t &pos,size_t &max, std::vector<cmd*>& cmds);

View File

@ -11,20 +11,6 @@ namespace dms {
void dms_state::setHandler(Handler* hand) {
this->handler = hand;
}
void checkCharacter(character* cc,std::string index, datatypes type) {
value val = cc->get(index);
// If a type mismatch is present, overwrite them with the defaults
if (val.type!=type) {
if (type == datatypes::string)
cc->values[index] = value("");
else if (type == datatypes::boolean) {
cc->values[index] = value(false);
}
else if (type == datatypes::number) {
cc->values[index] = value(0);
}
}
}
enviroment* dms_state::getEnvironment(std::string env) {
if (environments.count(env)) {
return environments[env];
@ -46,6 +32,20 @@ namespace dms {
}
return nullptr;
}
void checkCharacter(character* cha, std::string index, datatypes type) {
auto val = cha->values[index];
// If a type mismatch is present, overwrite them with the defaults
if (val.type != type) {
if (type == datatypes::string)
cha->values[index] = value("");
else if (type == datatypes::boolean) {
cha->values[index] = value(false);
}
else if (type == datatypes::number) {
cha->values[index] = value(0);
}
}
}
character* dms_state::getCharacter(std::string cha) {
if (characters.count(cha)) {
characters[cha]->seen = true;
@ -53,12 +53,13 @@ namespace dms {
}
else {
if (blockExists(cha)) {
pushMem();
character* cc = new character;
cc->fullname = isEnabled("fullname");
cc->set("fname", cha);
/*cc->set("fname", cha);
cc->set("lname", "");
cc->set("unknown", "Unknown");
cc->set("known", false);
cc->set("known", false);*/
if (isEnabled("omniscient")) {
cc->seen = true;
}
@ -66,20 +67,25 @@ namespace dms {
cc->seen = false;
}
if (run(cha,&cc->values)) {
cc->values = *getMem();
checkCharacter(cc, "fname",datatypes::string);
checkCharacter(cc, "lname", datatypes::string);
if (cc->get("fname") == value("")) {
cc->set("fname",value(cha));
}
checkCharacter(cc, "unknown", datatypes::string);
checkCharacter(cc, "known", datatypes::boolean);
if (cc->get("known").b == true) {
if (cc->get("known").b) {
cc->seen = true;
}
}
else {
popMem();
return nullptr;
}
characters.insert_or_assign(cha, cc);
// Call Character event!
handler->OnSpeakerCreated(this,cc);
popMem();
return cc;
}
else {
@ -108,6 +114,8 @@ namespace dms {
return true;
}
bool dms_state::run() {
if (stop)
return false;
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;
@ -226,6 +234,8 @@ namespace dms {
else if (environmentExists(obj)) {
ret = getEnvironment(obj)->Invoke(funcname, this, &args);
}
if (ret.type == datatypes::error)
return false;
if (assn.type != datatypes::nil) {
assign(assn, ret);
}
@ -248,6 +258,8 @@ namespace dms {
else {
ret = invoker.Invoke(funcname, this, &args);
}
if (ret.type == datatypes::error)
return false;
if (assn.type != datatypes::nil) {
assign(assn, ret);
}
@ -385,9 +397,43 @@ namespace dms {
list.e->pushValue(c->args.args[1]);
}
break;
case COMP:
{
comp cmp = (comp)c->args.args[0].n;
value assn = c->args.args[1];
value left = c->args.args[2].resolve(this);
value right = c->args.args[3].resolve(this);
switch (cmp) {
case comp::eq: {
assign(assn, value(left == right));
break;
}
case comp::gt: {
assign(assn, value(left > right));
break;
}
case comp::gteq: {
assign(assn, value(left >= right));
break;
}
case comp::lt: {
assign(assn, value(left < right));
break;
}
case comp::lteq: {
assign(assn, value(left <= right));
break;
}
case comp::nteq: {
assign(assn, value(left != right));
break;
}
}
}
break;
case HALT:
//wait();
sleep(700);
//sleep(700);
std::cout << std::endl;
break;
case WAIT:

Binary file not shown.

View File

@ -10,26 +10,28 @@ Line <3> name omniscient
Line <3> newline
Line <3> newline
Line <4> flag
Line <4> name forwardlabels
Line <4> name fullname
Line <4> newline
Line <4> newline
Line <5> flag
Line <5> name savestate
Line <5> newline
Line <5> name forwardlabels
Line <5> newline
Line <6> flag
Line <6> name savestate
Line <6> newline
Line <6> newline
Line <7> newline
Line <8> flag
Line <8> string loadtest.dms
Line <8> newline
Line <8> newline
Line <9> flag
Line <9> number 0.2
Line <9> string loadtest.dms
Line <9> newline
Line <9> newline
Line <10> flag
Line <10> name extendedDefine
Line <10> number 0.2
Line <10> newline
Line <10> newline
Line <11> flag
Line <11> name extendedDefine
Line <11> newline
Line <11> newline
Line <12> bracketo [
@ -44,98 +46,112 @@ Line <13> newline
Line <13> newline
Line <14> name Bob
Line <14> colon :
Line <14> string Hi `Ryan`, I'm good.
Line <14> string Hi `Ryan`, I'm good, I'm Bob by the way.
Line <14> newline
Line <14> newline
Line <15> name a
Line <15> equal =
Line <15> number 1000
Line <15> name Ryan
Line <15> colon :
Line <15> string Oh so your name is `Bob`, nice to meet you!
Line <15> newline
Line <15> newline
Line <16> name imp
Line <16> name a
Line <16> equal =
Line <16> string this
Line <16> number 1000
Line <16> newline
Line <16> newline
Line <17> name test
Line <17> name imp
Line <17> equal =
Line <17> name invokeTest
Line <17> parao (
Line <17> string Running external code!
Line <17> parac )
Line <17> string this
Line <17> newline
Line <17> newline
Line <17> newline
Line <18> string Loop Test... `test`
Line <18> name print
Line <18> parao (
Line <18> string Hello
Line <18> seperator ,
Line <18> number 122
Line <18> equal =
Line <18> equal =
Line <18> number 123
Line <18> parac )
Line <18> newline
Line <18> newline
Line <19> control
Line <19> string Pick one
Line <19> cbracketo {
Line <19> name test
Line <19> equal =
Line <19> name invokeTest
Line <19> parao (
Line <19> string Running external code!
Line <19> parac )
Line <19> newline
Line <19> newline
Line <20> string this
Line <20> gotoo
Line <20> name imp
Line <19> newline
Line <20> string Loop Test... `test`
Line <20> newline
Line <20> newline
Line <21> string that
Line <21> gotoo
Line <21> parao (
Line <21> string that
Line <21> parac )
Line <21> control
Line <21> string Pick one
Line <21> cbracketo {
Line <21> newline
Line <21> newline
Line <22> cbracketc }
Line <22> string this
Line <22> gotoo
Line <22> name imp
Line <22> newline
Line <22> newline
Line <23> label this
Line <23> string that
Line <23> gotoo
Line <23> parao (
Line <23> string that
Line <23> parac )
Line <23> newline
Line <23> newline
Line <24> string At "this"
Line <24> cbracketc }
Line <24> newline
Line <24> newline
Line <25> gotoo
Line <25> parao (
Line <25> string loop
Line <25> parac )
Line <25> flag
Line <25> name test
Line <25> newline
Line <25> newline
Line <26> label that
Line <26> label this
Line <26> newline
Line <26> newline
Line <27> string At "that"
Line <27> string At "this"
Line <27> newline
Line <27> newline
Line <28> label loop
Line <28> gotoo
Line <28> string loop
Line <28> newline
Line <28> newline
Line <29> name a
Line <29> equal =
Line <29> name a
Line <29> plus +
Line <29> number 1
Line <29> label that
Line <29> newline
Line <29> newline
Line <30> string a = `a`
Line <30> string At "that"
Line <30> newline
Line <30> newline
Line <31> gotoo
Line <31> parao (
Line <31> string loop
Line <31> parac )
Line <31> label loop
Line <31> newline
Line <31> newline
Line <32> name a
Line <32> equal =
Line <32> name a
Line <32> plus +
Line <32> number 1
Line <32> newline
Line <32> newline
Line <33> string a = `a`
Line <33> newline
Line <33> newline
Line <34> gotoo
Line <34> parao (
Line <34> string loop
Line <34> parac )
Line <34> newline
Line <34> newline
Line <35> newline
Line <35> newline
Line <36> newline
Line <36> newline
Line <37> newline
Line <37> newline
Line <38> newline
Line <38> newline
Line <39> newline
Line <39> newline
@ -145,83 +161,89 @@ Line <41> newline
Line <42> newline
Line <43> newline
Line <43> newline
Line <44> bracketo [
Line <44> name Bob
Line <44> colon :
Line <44> name char
Line <44> bracketc ]
Line <44> newline
Line <44> newline
Line <45> newline
Line <45> newline
Line <46> newline
Line <47> newline
Line <48> name unknown
Line <48> equal =
Line <48> string Some Random Guy
Line <47> newline
Line <48> bracketo [
Line <48> name Bob
Line <48> colon :
Line <48> name char
Line <48> bracketc ]
Line <48> newline
Line <48> newline
Line <49> name age
Line <49> equal =
Line <49> number 0.24
Line <49> newline
Line <49> newline
Line <50> name money
Line <50> equal =
Line <50> number 100
Line <50> newline
Line <50> newline
Line <51> name excited
Line <51> colon :
Line <51> string path/to/file
Line <51> newline
Line <51> newline
Line <52> name unknown
Line <52> equal =
Line <52> string Some Random Guy
Line <52> newline
Line <52> newline
Line <53> bracketo [
Line <53> name test1
Line <53> colon :
Line <53> name function
Line <53> parao (
Line <53> parac )
Line <53> bracketc ]
Line <53> name age
Line <53> equal =
Line <53> number 0.24
Line <53> newline
Line <53> newline
Line <54> string Inside a function!
Line <54> name money
Line <54> equal =
Line <54> number 100
Line <54> newline
Line <54> newline
Line <55> name excited
Line <55> colon :
Line <55> string path/to/file
Line <55> newline
Line <55> newline
Line <56> newline
Line <56> newline
Line <57> bracketo [
Line <57> name test1
Line <57> colon :
Line <57> name function
Line <57> parao (
Line <57> parac )
Line <57> bracketc ]
Line <57> newline
Line <57> newline
Line <58> bracketo [
Line <58> name newblock
Line <58> colon :
Line <58> name function
Line <58> parao (
Line <58> name a
Line <58> seperator ,
Line <58> name b
Line <58> seperator ,
Line <58> name c
Line <58> parac )
Line <58> bracketc ]
Line <58> string Inside a function!
Line <58> newline
Line <58> newline
Line <59> string Func Arguments: a = `a`, b = `b`, c = `c`
Line <59> newline
Line <59> newline
Line <60> string Time to return
Line <60> newline
Line <60> newline
Line <61> ret
Line <61> name a
Line <61> plus +
Line <61> name b
Line <61> plus +
Line <61> name c
Line <61> newline
Line <61> newline
Line <61> eof
Line <62> bracketo [
Line <62> name newblock
Line <62> colon :
Line <62> name function
Line <62> parao (
Line <62> name a
Line <62> seperator ,
Line <62> name b
Line <62> seperator ,
Line <62> name c
Line <62> parac )
Line <62> bracketc ]
Line <62> newline
Line <62> newline
Line <63> string Func Arguments: a = `a`, b = `b`, c = `c`
Line <63> newline
Line <63> newline
Line <64> string Time to return
Line <64> newline
Line <64> newline
Line <65> ret
Line <65> name a
Line <65> plus +
Line <65> name b
Line <65> plus +
Line <65> name c
Line <65> newline
Line <65> newline
Line <65> eof
Line <1> newline
Line <1> newline
Line <1> bracketo [

View File

@ -1,6 +1,7 @@
entry main // Will either start the first block seen or the block supplied by you!
//enable warnings
disable omniscient
enable fullname
enable forwardlabels // Do most of your labels exist ahead?
enable savestate
//enable leaking
@ -8,18 +9,20 @@ enable savestate
loadfile "loadtest.dms"
version 0.2
using extendedDefine
[main]
Ryan: "Hello `Bob`, how are you doing?"
Bob: "Hi `Ryan`, I'm good."
Bob: "Hi `Ryan`, I'm good, I'm Bob by the way."
Ryan: "Oh so your name is `Bob`, nice to meet you!"
a = 1000
imp = "this"
print("Hello",122==123)
test = invokeTest("Running external code!");
"Loop Test... `test`"
choice "Pick one" {
"this" goto imp
"that" goto ("that")
}
enable test
::this::
"At \"this\""
goto "loop"
@ -31,16 +34,16 @@ using extendedDefine
goto ("loop")
if (this==that) this()|that()
// if (this==that) this()|that()
if(this == that){
// if(this == that){
} else if (that > this) {
// } elseif (that > this) {
} else {
// } else {
}
// }
[Bob:char]
//fname = "Bob"

View File

@ -50,6 +50,8 @@ namespace dms::tokens {
ampersand,
nil,
pipe,
anglebracketO,
anglebracketC,
};//stream, t_vec, line, isNum, buffer
struct token {
tokentype type = noop;
@ -121,7 +123,9 @@ namespace dms::tokens {
"dollar",
"ampersand",
"nil",
"pipe"
"pipe",
"anglebracketO",
"anglebracketC",
};
out << "Line <" << c.line_num << "> " << tokenlist[c.type] << " \t\t " << c.name;
return out;

View File

@ -52,7 +52,7 @@ namespace dms {
s = buildString(other.s->val);
break;
case datatypes::boolean:
b = buildBool(other.b);
b = other.b;
break;
case datatypes::custom:
// Handle this later
@ -200,6 +200,30 @@ namespace dms {
bool operator!=(const value& lhs, const value& rhs) {
return !(lhs.getPrintable() == rhs.getPrintable());
}
bool operator>(const value& lhs, const value& rhs) {
if (lhs.type == datatypes::number && rhs.type == datatypes::number) {
return lhs.n > rhs.n;
}
return false;
}
bool operator<(const value& lhs, const value& rhs) {
if (lhs.type == datatypes::number && rhs.type == datatypes::number) {
return lhs.n < rhs.n;
}
return false;
}
bool operator>=(const value& lhs, const value& rhs) {
if (lhs.type == datatypes::number && rhs.type == datatypes::number) {
return lhs.n >= rhs.n;
}
return false;
}
bool operator<=(const value& lhs, const value& rhs) {
if (lhs.type == datatypes::number && rhs.type == datatypes::number) {
return lhs.n <= rhs.n;
}
return false;
}
value value::resolve(dms_state* state) {
if (type == datatypes::variable && (*this)!=(*state->getMem())[getPrintable()]) {
return (*state->getMem())[getPrintable()].resolve(state);
@ -364,9 +388,6 @@ namespace dms {
dms_string* dms_str = new dms_string{ newstr.str() };
return dms_str;
}
dms_boolean* buildBool(bool b) {
return new dms_boolean{b};
}
std::string value::toString() const {
std::stringstream temp;
temp << this;

View File

@ -51,7 +51,6 @@ namespace dms {
value* self;
};
dms_string* buildString(std::string str);
dms_boolean* buildBool(bool b);
struct value {
public:
datatypes type = datatypes::nil;
@ -75,11 +74,16 @@ namespace dms {
value& operator=(value& other);
value& operator=(const value& other);
friend bool operator==(const value& lhs, const value& rhs);
friend bool operator!=(const value& lhs, const value& rhs);
friend bool operator>(const value& lhs, const value& rhs);
friend bool operator<(const value& lhs, const value& rhs);
friend bool operator>=(const value& lhs, const value& rhs);
friend bool operator<=(const value& lhs, const value& rhs);
friend value operator+(const value& lhs, const value& rhs);
friend value operator-(const value& lhs, const value& rhs);
friend value operator/(const value& lhs, const value& rhs);
friend value operator*(const value& lhs, const value& rhs);
friend bool operator!=(const value& lhs, const value& rhs);
value resolve(dms_state*);
void nuke();
void set(value*);