Reworked a lot of stuff, need to fix what I broke

This commit is contained in:
Ryan Ward 2020-12-11 00:18:56 -05:00
parent b8b446143e
commit 993b9e9b4d
14 changed files with 135 additions and 132 deletions

View File

@ -5,7 +5,7 @@
#include <iostream>
#include "value.h"
#include "enviroment.h"
#include "sterilizer.h"
#include "wrapper.h"
//#include <chrono>
using namespace dms;
//typedef void(*FNPTR)();
@ -36,6 +36,9 @@ value type(void* self, dms_state* state, dms_args* args) {
//}
int main()
{
// TODO fix disp cmd to handle the standard
/*milliseconds ms = duration_cast<milliseconds>(
system_clock::now().time_since_epoch()
);

View File

@ -189,10 +189,10 @@
<ClInclude Include="errors.h" />
<ClInclude Include="dms.h" />
<ClInclude Include="LineParser.h" />
<ClInclude Include="sterilizer.h" />
<ClInclude Include="token.h" />
<ClInclude Include="utils.h" />
<ClInclude Include="value.h" />
<ClInclude Include="wrapper.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets" />

View File

@ -149,7 +149,7 @@
<ClInclude Include="comparisons.h">
<Filter>Header Files\DMS</Filter>
</ClInclude>
<ClInclude Include="sterilizer.h">
<ClInclude Include="wrapper.h">
<Filter>Header Files\DMS\C-API</Filter>
</ClInclude>
</ItemGroup>

View File

@ -17,7 +17,7 @@ namespace dms {
}
value dms_custom::Index(value data) {
state->push_error(errors::error{ errors::unknown,"Attempting to index a non enviroment!" });
return nullptr;
return value();
}
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!" });
@ -25,30 +25,30 @@ namespace dms {
}
value dms_custom::Call(dms_args* args) {
state->push_error(errors::error{ errors::unknown,"Attempting to call a non function value!" });
return nullptr;
return value();
}
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;
return value();
}
value dms_custom::SUB(value left, value right) {
state->push_error(errors::error{ errors::unknown,"Attempting to subtract a non number value!" });
return nullptr;
return value();
}
value dms_custom::MUL(value left, value right) {
state->push_error(errors::error{ errors::unknown,"Attempting to multiply a non number value!" });
return nullptr;
return value();
}
value dms_custom::DIV(value left, value right) {
state->push_error(errors::error{ errors::unknown,"Attempting to divide a non number value!" });
return nullptr;
return value();
}
value dms_custom::POW(value left, value right) {
state->push_error(errors::error{ errors::unknown,"Attempting to raise a non number value!" });
return nullptr;
return value();
}
value dms_custom::EQUAL(value left, value right) {
return value(left.getPrintable() == right.getPrintable());

View File

@ -160,6 +160,8 @@ namespace dms {
push_error(errors::error{ errors::unknown ,val.s });
return false;
}
if(val.state==nullptr)
val.state = this;
(*getMem())[var.getPrintable()] = val;
return true;
}

View File

@ -545,9 +545,12 @@ namespace dms {
return false;
break;
case DISP:
//FIX STRING STER
if (!handler->handleMessageDisplay(this, c->args.args[0].s))
return false;
{
//FIX STRING STER
value disp = c->args.args[0].resolve(this).getPrintable();
if (!handler->handleMessageDisplay(this, c->args.args[0].s))
return false;
}
break;
case ASGN:
if(!assign(c->args.args[0], c->args.args[1])) {

Binary file not shown.

View File

@ -39,131 +39,112 @@ Line <12> name main
Line <12> bracketc ]
Line <12> newline
Line <12> newline
Line <13> name num
Line <13> equal =
Line <13> number 30.0
Line <13> name Ryan
Line <13> colon :
Line <13> string I am good
Line <13> newline
Line <13> newline
Line <14> name io
Line <14> dot .
Line <14> name print
Line <14> parao (
Line <14> string !
Line <14> name John
Line <14> colon :
Line <14> string Hi
Line <14> plus +
Line <14> name num
Line <14> name Ryan
Line <14> plus +
Line <14> string =
Line <14> plus +
Line <14> name fact
Line <14> parao (
Line <14> name num
Line <14> parac )
Line <14> parac )
Line <14> string how are you?
Line <14> newline
Line <14> newline
Line <15> newline
Line <15> newline
Line <16> bracketo [
Line <16> name fact
Line <16> colon :
Line <16> name function
Line <16> parao (
Line <16> name n
Line <16> parac )
Line <16> bracketc ]
Line <16> newline
Line <16> newline
Line <17> name if
Line <17> parao (
Line <17> name n
Line <17> equal =
Line <17> equal =
Line <17> number 1
Line <17> parac )
Line <17> newline
Line <17> newline
Line <18> ret
Line <18> number 1
Line <18> bracketo [
Line <18> name John
Line <18> colon :
Line <18> name char
Line <18> bracketc ]
Line <18> newline
Line <18> newline
Line <19> name else
Line <19> name lname
Line <19> equal =
Line <19> string Johnson
Line <19> newline
Line <19> newline
Line <20> ret
Line <20> name n
Line <20> multiply *
Line <20> name fact
Line <20> parao (
Line <20> name n
Line <20> minus -
Line <20> number 1
Line <20> parac )
Line <20> name age
Line <20> equal =
Line <20> number 16
Line <20> newline
Line <20> newline
Line <21> name money
Line <21> equal =
Line <21> number 100000
Line <21> newline
Line <21> newline
Line <22> bracketo [
Line <22> name this
Line <22> colon :
Line <22> name function
Line <22> parao (
Line <22> parac )
Line <22> bracketc ]
Line <22> name known
Line <22> equal =
Line <22> true true
Line <22> newline
Line <22> newline
Line <23> name print
Line <23> parao (
Line <23> string This
Line <23> parac )
Line <23> newline
Line <23> newline
Line <24> bracketo [
Line <24> name Ryan
Line <24> colon :
Line <24> name char
Line <24> bracketc ]
Line <24> newline
Line <24> newline
Line <25> bracketo [
Line <25> name that
Line <25> colon :
Line <25> name function
Line <25> parao (
Line <25> parac )
Line <25> bracketc ]
Line <25> name lname
Line <25> equal =
Line <25> string Ward
Line <25> newline
Line <25> newline
Line <26> name print
Line <26> parao (
Line <26> string That
Line <26> parac )
Line <26> name age
Line <26> equal =
Line <26> number 24
Line <26> newline
Line <26> newline
Line <27> name known
Line <27> equal =
Line <27> true true
Line <27> newline
Line <27> newline
Line <28> bracketo [
Line <28> name Bob
Line <28> colon :
Line <28> name char
Line <28> bracketc ]
Line <28> name money
Line <28> equal =
Line <28> number 0
Line <28> newline
Line <28> newline
Line <29> newline
Line <29> newline
Line <30> bracketo [
Line <30> name Bob
Line <30> colon :
Line <30> name char
Line <30> bracketc ]
Line <30> newline
Line <30> newline
Line <31> newline
Line <32> name unknown
Line <32> equal =
Line <32> string Some Random Guy
Line <32> newline
Line <32> newline
Line <33> name age
Line <33> equal =
Line <33> number 0.24
Line <33> newline
Line <33> newline
Line <34> name money
Line <34> name unknown
Line <34> equal =
Line <34> number 100
Line <34> string Some Random Guy
Line <34> newline
Line <34> newline
Line <35> name excited
Line <35> colon :
Line <35> string path/to/file
Line <35> name age
Line <35> equal =
Line <35> number 24
Line <35> newline
Line <35> newline
Line <35> eof
Line <36> name money
Line <36> equal =
Line <36> number 100
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> eof

View File

@ -1,21 +0,0 @@
#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
};
}

View File

@ -10,26 +10,28 @@ enable debugging
version 0.2
using extendedDefine
[main]
num = 30.0
io.print("!"+num+" = " + fact(num))
[fact:function(n)]
if(n==1)
return 1
else
return n * fact(n-1)
[this:function()]
print("This")
Ryan: "I am good"
John: "Hi " + Ryan + " how are you?"
[that:function()]
print("That")
[John:char]
lname = "Johnson"
age = 16
money = 100000
known = true
[Ryan:char]
lname = "Ward"
age = 24
known = true
money = 0
[Bob:char]
//fname = "Bob"
//known = true // defaults to false
//lname = "Johnson" // defaults to ""
unknown = "Some Random Guy"
age = .24
age = 24
money = 100
excited: "path/to/file"

View File

@ -350,6 +350,9 @@ namespace dms {
}
return *this;
}
value value::resolve() {
return resolve(state);
}
void dms_args::push(value val) {
args.push_back(val);
}
@ -389,6 +392,10 @@ namespace dms {
return "custom";
}
else if (type == block) {
if (state->characterExists(s)) {
auto cha = state->getCharacter(s);
return cha->getName();
}
return s;
}
else if (type == datatypes::variable) {

View File

@ -42,6 +42,7 @@ namespace dms {
std::string s;
dms_list* e = nullptr;
dms_custom* c = nullptr;
dms_state* state = nullptr;
value();
value(datatypes);
value(char const*,datatypes);
@ -71,6 +72,7 @@ namespace dms {
friend value operator/(const value& lhs, const value& rhs);
friend value operator*(const value& lhs, const value& rhs);
value resolve(dms_state*);
value resolve();
void nuke();
void set(value);
void set(std::string str);

23
DMS/wrapper.h Normal file
View File

@ -0,0 +1,23 @@
#pragma once
#include "enviroment.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
const char* s; // Contains the string part.
uint64_t i; // The int portion of the code
double n;
};
void s_value_setInt(s_value& sv, int n) { sv.type = int64; sv.i = n; } // Define value as an int
void s_value_setDouble(s_value& sv, double d) { sv.type = number; sv.n = d; } // Define value as a double
void s_value_setString(s_value& sv, const char* str) { sv.type = string; sv.s = str; } // Define value as a string
void s_value_setBlock(s_value& sv, const char* str) { sv.type = block; sv.s = str; } // Define value as a block
void s_value_setVariable(s_value& sv, const char* str) { sv.type = variable; sv.s = str; } // Define value as a variable
void s_value_setNil(s_value& sv) { sv.type = nil; } // Define value as nil
struct s_enviroment {
};
}

View File

@ -9,3 +9,4 @@ The Dialogue Management Script's goal is to provide a nice and simple way to hav
- [ ] Finish implementing custom datatype
- [ ] Speed up interperter
- [ ] Finish C API for code
- [ ] Extend beginning features