Working on optimization and integrations

This commit is contained in:
Ryan Ward 2020-12-24 00:10:23 -05:00
parent f9c236857b
commit 2e298fab80
53 changed files with 1263 additions and 687 deletions

View File

@ -1,6 +1,5 @@
#pragma once #pragma once
#include <string> #include "pch.h"
#include <unordered_map>
#include "value.h" #include "value.h"
#include "enviroment.h" #include "enviroment.h"
namespace dms { namespace dms {

View File

@ -1,11 +1,6 @@
#include "pch.h"
#include "dms.h" #include "dms.h"
#include "memory.h"
#include <windows.h>
#include "utils.h"
#include <iostream>
#include "value.h"
#include "enviroment.h"
#include "wrapper.h"
//#include <chrono> //#include <chrono>
using namespace dms; using namespace dms;
//typedef void(*FNPTR)(); //typedef void(*FNPTR)();
@ -14,26 +9,21 @@ using namespace dms;
// utils::print(args->args[0].getPrintable()); // utils::print(args->args[0].getPrintable());
// return "I work!"; // return "I work!";
//} //}
value print(void* self, dms_state* state, dms_args* args) {
std::string str = "";
for (size_t i = 0; i < args->args.size(); i++) {
str += args->args[i].getPrintable() + "\t";
}
printf((str + "\n").c_str());
return NULL;
}
value type(void* self, dms_state* state, dms_args* args) {
if (args->size() > 0) {
return datatype[args->args[0].type];
}
return "nil";
}
//value concat(void* self, dms_state* state, dms_args* args) { //value concat(void* self, dms_state* state, dms_args* args) {
// std::stringstream str; // std::stringstream str;
// for (size_t i = 0; i < args->size() - 1; i++) // for (size_t i = 0; i < args->size() - 1; i++)
// str << args->args[i].getPrintable(); // str << args->args[i].getPrintable();
// return value(str.str()); // return value(str.str());
//} //}
//void draw(sf::RenderWindow& window) {
// sf::CircleShape shape(60.f);
// shape.setFillColor(sf::Color(150, 50, 250));
//
// // set a 10-pixel wide orange outline
// shape.setOutlineThickness(10.f);
// shape.setOutlineColor(sf::Color(250, 150, 100));
// window.draw(shape);
//}
int main() int main()
{ {
// TODO fix disp cmd to handle the standard // TODO fix disp cmd to handle the standard
@ -43,17 +33,38 @@ int main()
system_clock::now().time_since_epoch() system_clock::now().time_since_epoch()
); );
utils::print(ms.count());*/ utils::print(ms.count());*/
enviroment* envio = new enviroment;
LineParser parser = LineParser("test.dms"); LineParser parser = LineParser("test.dms");
dms_state* state = parser.Parse(); dms_state* state = parser.Parse();
// Load audio stuff
dms::audio::init(state);
state->dump(); state->dump();
envio->registerFunction("print", print);
state->invoker.registerFunction("print", print);
state->injectEnv("io",envio);
state->run(); state->run();
// create the window
//sf::RenderWindow window(sf::VideoMode(800, 600), "My window");
//// run the program as long as the window is open
//while (window.isOpen())
//{
// // check all the window's events that were triggered since the last iteration of the loop
// sf::Event event;
// while (window.pollEvent(event))
// {
// // "close requested" event: we close the window
// if (event.type == sf::Event::Closed)
// window.close();
// }
// // clear the window with black color
// window.clear(sf::Color::Black);
// // draw everything here...
// draw(window);
// // end the current frame
// window.display();
//}
/*HINSTANCE hInst = LoadLibrary(L"C:\\Users\\rayam\\Desktop\\test.dll"); /*HINSTANCE hInst = LoadLibrary(L"C:\\Users\\rayam\\Desktop\\test.dll");
if (!hInst) { if (!hInst) {

View File

@ -89,10 +89,13 @@
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard> <LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalIncludeDirectories>C:\SFML\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>sfml-audio-d.lib;sfml-system-d.lib;openal32.lib;flac.lib;vorbisenc.lib;vorbisfile.lib;vorbis.lib;ogg.lib;winmm.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>C:\SFML\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@ -104,12 +107,15 @@
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard> <LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalIncludeDirectories>C:\SFML\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>C:\SFML\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>sfml-audio.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@ -121,16 +127,19 @@
<LanguageStandard>stdcpp17</LanguageStandard> <LanguageStandard>stdcpp17</LanguageStandard>
<BasicRuntimeChecks>Default</BasicRuntimeChecks> <BasicRuntimeChecks>Default</BasicRuntimeChecks>
<InlineFunctionExpansion>Default</InlineFunctionExpansion> <InlineFunctionExpansion>Default</InlineFunctionExpansion>
<PrecompiledHeader>NotUsing</PrecompiledHeader> <PrecompiledHeader>Use</PrecompiledHeader>
<MultiProcessorCompilation>false</MultiProcessorCompilation> <MultiProcessorCompilation>false</MultiProcessorCompilation>
<LanguageStandard_C>Default</LanguageStandard_C> <LanguageStandard_C>Default</LanguageStandard_C>
<SupportJustMyCode>false</SupportJustMyCode> <SupportJustMyCode>false</SupportJustMyCode>
<AdditionalIncludeDirectories>C:\SFML\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>C:\includes\include;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>C:\SFML\lib;C:\includes\include;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<StackReserveSize>4194304</StackReserveSize> <StackReserveSize>4194304</StackReserveSize>
<AdditionalDependencies>sfml-audio-d.lib;sfml-graphics-d.lib;sfml-window-d.lib;sfml-network-d.lib;sfml-system-d.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@ -143,16 +152,20 @@
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard> <LanguageStandard>stdcpp17</LanguageStandard>
<Optimization>MinSpace</Optimization> <Optimization>MinSpace</Optimization>
<AdditionalIncludeDirectories>C:\SFML\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>C:\SFML\lib;</AdditionalLibraryDirectories>
<AdditionalDependencies>sfml-audio.lib;sfml-graphics.lib;sfml-window.lib;sfml-network.lib;sfml-system.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="character.cpp" /> <ClCompile Include="character.cpp" />
<ClCompile Include="core.cpp" />
<ClCompile Include="dms_custom.cpp" /> <ClCompile Include="dms_custom.cpp" />
<ClCompile Include="enviroment.cpp" /> <ClCompile Include="enviroment.cpp" />
<ClCompile Include="Handlers.cpp" /> <ClCompile Include="Handlers.cpp" />
@ -169,13 +182,19 @@
<ClCompile Include="memory.cpp" /> <ClCompile Include="memory.cpp" />
<ClCompile Include="dms_exceptions.cpp" /> <ClCompile Include="dms_exceptions.cpp" />
<ClCompile Include="LineParserUtils.cpp" /> <ClCompile Include="LineParserUtils.cpp" />
<ClCompile Include="number_utils.cpp" /> <ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
</PrecompiledHeaderFile>
</ClCompile>
<ClCompile Include="sound.cpp" />
<ClCompile Include="utils.cpp" /> <ClCompile Include="utils.cpp" />
<ClCompile Include="value.cpp" /> <ClCompile Include="value.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="character.h" /> <ClInclude Include="character.h" />
<ClInclude Include="comparisons.h" /> <ClInclude Include="comparisons.h" />
<ClInclude Include="core.h" />
<ClInclude Include="dms_list.h" /> <ClInclude Include="dms_list.h" />
<ClInclude Include="enviroment.h" /> <ClInclude Include="enviroment.h" />
<ClInclude Include="Handlers.h" /> <ClInclude Include="Handlers.h" />
@ -189,6 +208,9 @@
<ClInclude Include="errors.h" /> <ClInclude Include="errors.h" />
<ClInclude Include="dms.h" /> <ClInclude Include="dms.h" />
<ClInclude Include="LineParser.h" /> <ClInclude Include="LineParser.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="sound.h" />
<ClInclude Include="s_value.h" />
<ClInclude Include="token.h" /> <ClInclude Include="token.h" />
<ClInclude Include="utils.h" /> <ClInclude Include="utils.h" />
<ClInclude Include="value.h" /> <ClInclude Include="value.h" />

View File

@ -19,18 +19,36 @@
<Filter Include="Source Files\DMS"> <Filter Include="Source Files\DMS">
<UniqueIdentifier>{e3410a7b-6408-4022-b606-2c14cfaac52c}</UniqueIdentifier> <UniqueIdentifier>{e3410a7b-6408-4022-b606-2c14cfaac52c}</UniqueIdentifier>
</Filter> </Filter>
<Filter Include="Header Files\DMS\blocks">
<UniqueIdentifier>{978b41cd-27e4-4b8c-874e-3b6e927b3d4d}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\DMS\blocks">
<UniqueIdentifier>{4c0bb4c5-388c-4f15-abb7-143cb6d6232f}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\DMS\C-API"> <Filter Include="Header Files\DMS\C-API">
<UniqueIdentifier>{f71964f6-66b3-4d8c-a8da-56d703ad1c2a}</UniqueIdentifier> <UniqueIdentifier>{f71964f6-66b3-4d8c-a8da-56d703ad1c2a}</UniqueIdentifier>
</Filter> </Filter>
<Filter Include="Source Files\DMS\C-API"> <Filter Include="Source Files\DMS\C-API">
<UniqueIdentifier>{32abbbfd-6359-488c-83be-f61da8fd8f4d}</UniqueIdentifier> <UniqueIdentifier>{32abbbfd-6359-488c-83be-f61da8fd8f4d}</UniqueIdentifier>
</Filter> </Filter>
<Filter Include="Source Files\DMS\standardMethods">
<UniqueIdentifier>{10d9f698-b08c-40c5-b6b1-e6d903f4b279}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\DMS\standardMethods">
<UniqueIdentifier>{4757b859-2680-4c9a-83e8-be3bf06f192e}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\DMS\parser">
<UniqueIdentifier>{be440a96-7b07-48b3-a84e-64b10775c979}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\DMS\state">
<UniqueIdentifier>{9490aa5b-7d9d-415c-a263-ef1ecd8dd188}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\DMS\objects">
<UniqueIdentifier>{4c0bb4c5-388c-4f15-abb7-143cb6d6232f}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\DMS\objects">
<UniqueIdentifier>{978b41cd-27e4-4b8c-874e-3b6e927b3d4d}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\DMS\platformdep">
<UniqueIdentifier>{39dc0943-16ca-48a6-b04e-04ba994cfb8d}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\DMS\platformdep">
<UniqueIdentifier>{ef57bfaf-35f9-4b3e-8642-7ee96fb82139}</UniqueIdentifier>
</Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="cmd.cpp"> <ClCompile Include="cmd.cpp">
@ -42,9 +60,6 @@
<ClCompile Include="dms_exceptions.cpp"> <ClCompile Include="dms_exceptions.cpp">
<Filter>Source Files\DMS</Filter> <Filter>Source Files\DMS</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="number_utils.cpp">
<Filter>Source Files\DMS</Filter>
</ClCompile>
<ClCompile Include="utils.cpp"> <ClCompile Include="utils.cpp">
<Filter>Source Files\DMS</Filter> <Filter>Source Files\DMS</Filter>
</ClCompile> </ClCompile>
@ -54,43 +69,52 @@
<ClCompile Include="DMS.cpp"> <ClCompile Include="DMS.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="dms_state.cpp">
<Filter>Source Files\DMS</Filter>
</ClCompile>
<ClCompile Include="chunk.cpp"> <ClCompile Include="chunk.cpp">
<Filter>Source Files\DMS</Filter> <Filter>Source Files\DMS</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="LineParserMatchProcess.cpp">
<Filter>Source Files\DMS</Filter>
</ClCompile>
<ClCompile Include="LineParserParse.cpp">
<Filter>Source Files\DMS</Filter>
</ClCompile>
<ClCompile Include="LineParserUtils.cpp">
<Filter>Source Files\DMS</Filter>
</ClCompile>
<ClCompile Include="LineParserBuilds.cpp">
<Filter>Source Files\DMS</Filter>
</ClCompile>
<ClCompile Include="dms_state_interpret.cpp">
<Filter>Source Files\DMS</Filter>
</ClCompile>
<ClCompile Include="Handlers.cpp"> <ClCompile Include="Handlers.cpp">
<Filter>Source Files\DMS</Filter> <Filter>Source Files\DMS</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="character.cpp"> <ClCompile Include="character.cpp">
<Filter>Source Files\DMS\blocks</Filter> <Filter>Source Files\DMS\objects</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="enviroment.cpp"> <ClCompile Include="enviroment.cpp">
<Filter>Source Files\DMS\blocks</Filter> <Filter>Source Files\DMS\objects</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="dms_custom.cpp"> <ClCompile Include="dms_custom.cpp">
<Filter>Source Files\DMS</Filter> <Filter>Source Files\DMS</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="Invoker.cpp"> <ClCompile Include="memory.cpp">
<Filter>Source Files\DMS</Filter> <Filter>Source Files\DMS</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="memory.cpp"> <ClCompile Include="core.cpp">
<Filter>Source Files\DMS\standardMethods</Filter>
</ClCompile>
<ClCompile Include="LineParserBuilds.cpp">
<Filter>Source Files\DMS\parser</Filter>
</ClCompile>
<ClCompile Include="LineParserMatchProcess.cpp">
<Filter>Source Files\DMS\parser</Filter>
</ClCompile>
<ClCompile Include="LineParserParse.cpp">
<Filter>Source Files\DMS\parser</Filter>
</ClCompile>
<ClCompile Include="LineParserUtils.cpp">
<Filter>Source Files\DMS\parser</Filter>
</ClCompile>
<ClCompile Include="dms_state.cpp">
<Filter>Source Files\DMS\state</Filter>
</ClCompile>
<ClCompile Include="dms_state_interpret.cpp">
<Filter>Source Files\DMS\state</Filter>
</ClCompile>
<ClCompile Include="Invoker.cpp">
<Filter>Source Files\DMS\objects</Filter>
</ClCompile>
<ClCompile Include="sound.cpp">
<Filter>Source Files\DMS\standardMethods</Filter>
</ClCompile>
<ClCompile Include="pch.cpp">
<Filter>Source Files\DMS</Filter> <Filter>Source Files\DMS</Filter>
</ClCompile> </ClCompile>
</ItemGroup> </ItemGroup>
@ -132,13 +156,10 @@
<Filter>Header Files\DMS</Filter> <Filter>Header Files\DMS</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="character.h"> <ClInclude Include="character.h">
<Filter>Header Files\DMS\blocks</Filter> <Filter>Header Files\DMS\objects</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="enviroment.h"> <ClInclude Include="enviroment.h">
<Filter>Header Files\DMS\blocks</Filter> <Filter>Header Files\DMS\objects</Filter>
</ClInclude>
<ClInclude Include="Invoker.h">
<Filter>Header Files\DMS</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="memory.h"> <ClInclude Include="memory.h">
<Filter>Header Files\DMS</Filter> <Filter>Header Files\DMS</Filter>
@ -152,5 +173,20 @@
<ClInclude Include="wrapper.h"> <ClInclude Include="wrapper.h">
<Filter>Header Files\DMS\C-API</Filter> <Filter>Header Files\DMS\C-API</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Invoker.h">
<Filter>Header Files\DMS\objects</Filter>
</ClInclude>
<ClInclude Include="core.h">
<Filter>Header Files\DMS\standardMethods</Filter>
</ClInclude>
<ClInclude Include="s_value.h">
<Filter>Header Files\DMS\C-API</Filter>
</ClInclude>
<ClInclude Include="sound.h">
<Filter>Header Files\DMS\standardMethods</Filter>
</ClInclude>
<ClInclude Include="pch.h">
<Filter>Header Files\DMS</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -1,3 +1,4 @@
#include "pch.h"
#include "Handlers.h" #include "Handlers.h"
namespace dms { namespace dms {
uint8_t Handler::handleChoice(dms_state* state, std::string prompt, std::vector<std::string> args) const { uint8_t Handler::handleChoice(dms_state* state, std::string prompt, std::vector<std::string> args) const {

View File

@ -1,8 +1,8 @@
#pragma once #pragma once
#include "pch.h"
#include "value.h" #include "value.h"
#include "utils.h" #include "utils.h"
#include "character.h" #include "character.h"
#include <iostream>
namespace dms { namespace dms {
struct Handler struct Handler
{ {

View File

@ -1,3 +1,4 @@
#include "pch.h"
#include "Invoker.h" #include "Invoker.h"
#include "dms_state.h" #include "dms_state.h"
#include "utils.h" #include "utils.h"
@ -21,11 +22,23 @@ namespace dms {
if(args->size()) if(args->size())
for (int i = 0; i < args->args.size() - 1; i++) for (int i = 0; i < args->args.size() - 1; i++)
args->args[i] = args->args[i].resolve(state); args->args[i] = args->args[i].resolve(state);
return funcs[str](self, state, args); return funcs[str](self, state, args);
} }
state->push_error(errors::error{ errors::non_existing_function, utils::concat("Attempt to call '",str,"' a nil value!") }); state->push_error(errors::error{ errors::non_existing_function, utils::concat("Attempt to call '",str,"' a nil value!") });
return value(datatypes::error); return value(datatypes::error);
} }
value Invoker::Invoke(std::string str,void* ref, dms_state* state, dms_args* args) {
if (funcs.count(str)) {
if (args->size())
for (int i = 0; i < args->args.size() - 1; i++)
args->args[i] = args->args[i].resolve(state);
return funcs[str](ref, state, args);
}
state->push_error(errors::error{ errors::non_existing_function, utils::concat("Attempt to call '",str,"' a nil value!") });
return value(datatypes::error);
}
std::unordered_map<std::string, value (*)(void*, dms_state*, dms_args*)> Invoker::Export() { std::unordered_map<std::string, value (*)(void*, dms_state*, dms_args*)> Invoker::Export() {
return funcs; return funcs;
} }

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "pch.h"
#include "errors.h" #include "errors.h"
#include <unordered_map>
namespace dms { namespace dms {
struct dms_state; struct dms_state;
class Invoker { class Invoker {
@ -12,6 +12,7 @@ namespace dms {
bool registerFunction(std::string str, value (*f)(void*, dms_state*, dms_args*), bool preventoverride); bool registerFunction(std::string str, value (*f)(void*, dms_state*, dms_args*), bool preventoverride);
void _init(void* ref); void _init(void* ref);
value Invoke(std::string str, dms_state* state, dms_args* args); value Invoke(std::string str, dms_state* state, dms_args* args);
value Invoke(std::string str, void* ref, dms_state* state, dms_args* args);
// Exports the methods from an Invoker object // Exports the methods from an Invoker object
std::unordered_map<std::string, value (*)(void*, dms_state*, dms_args*)> Export(); std::unordered_map<std::string, value (*)(void*, dms_state*, dms_args*)> Export();
// Imports methods from another Invoker, this will add and overwrite any method with the same name // Imports methods from another Invoker, this will add and overwrite any method with the same name

View File

@ -1,12 +1,7 @@
#pragma once #pragma once
#include <vector> #include <vector>
#include <fstream> #include <fstream>
#include <string> #include "pch.h"
#include <iostream>
#include <iterator>
#include <stdio.h>
#include <ctype.h>
#include <stack>
#include "codes.h" #include "codes.h"
#include "cmd.h" #include "cmd.h"
#include "dms_state.h" #include "dms_state.h"
@ -94,6 +89,7 @@ namespace dms {
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); bool match_process_1afunc(tokenstream* stream, value& v);
bool match_process_ooxoo(tokenstream* stream, value& v);
// Build // Build
void buildGoto(std::string g, bool v = false); void buildGoto(std::string g, bool v = false);

View File

@ -1,3 +1,4 @@
#include "pch.h"
#include "LineParser.h" #include "LineParser.h"
namespace dms { namespace dms {
void LineParser::buildGoto(std::string g, bool v) { void LineParser::buildGoto(std::string g, bool v) {

View File

@ -1,3 +1,4 @@
#include "pch.h"
#include "LineParser.h" #include "LineParser.h"
using namespace dms::tokens; using namespace dms::tokens;
using namespace dms::utils; using namespace dms::utils;
@ -73,11 +74,15 @@ namespace dms {
} }
return true; return true;
} }
if (match_process_1afunc(stream, v)) { if (match_process_ooxoo(stream,v)) {
match_process_condition(stream, v); match_process_condition(stream, v);
return true; return true;
} }
if (match_process_expression(stream, v)) { else if (match_process_1afunc(stream, v)) {
match_process_condition(stream, v);
return true;
}
else if (match_process_expression(stream, v)) {
match_process_condition(stream,v); match_process_condition(stream,v);
return true; return true;
} }
@ -144,6 +149,21 @@ namespace dms {
} }
return false; return false;
} }
bool LineParser::match_process_ooxoo(tokenstream* stream, value& v) {
if (stream->match(name, plus, plus)) {
}
else if (stream->match(name, minus, minus)) {
}
else if (stream->match(plus, plus, name)) {
}
else if (stream->match(minus, minus, name)) {
}
return false;
}
bool LineParser::match_process_andor(tokenstream* stream, value& v) { bool LineParser::match_process_andor(tokenstream* stream, value& v) {
codes::op code = codes::MUL; codes::op code = codes::MUL;
if (stream->match(tokens::Or)) { if (stream->match(tokens::Or)) {
@ -356,32 +376,58 @@ namespace dms {
std::string name = stream->next().name; std::string name = stream->next().name;
stream->next(); stream->next();
cmd* c = new cmd; cmd* c = new cmd;
if (isBlock(bt_character)) {
c->opcode = codes::STAT;
c->args.push(value(name, datatypes::variable));
}
else {
c->opcode = codes::SSPK; c->opcode = codes::SSPK;
c->args.push(value(name, datatypes::variable)); c->args.push(value(name, datatypes::variable));
}
current_chunk->addCmd(c); current_chunk->addCmd(c);
value msg(variable); value msg(variable);
if (match_process_standard(stream, msg)) { if (stream->match(tokens::cbracketo)) {
if (match_process_scope(stream)) {
return true;
}
else {
badSymbol(stream);
return false;
}
} else if (match_process_standard(stream, msg)) {
if (isBlock(bt_character)) {
c->args.push(value(msg));
}
else {
c = new cmd; c = new cmd;
c->opcode = codes::DISP; c->opcode = codes::DISP;
c->args.push(msg); c->args.push(msg);
current_chunk->addCmd(c); // Add the cmd to the current chunk current_chunk->addCmd(c); // Add the cmd to the current chunk
current_chunk->addCmd(new cmd{ codes::HALT }); current_chunk->addCmd(new cmd{ codes::HALT });
} }
}
else { else {
badSymbol(stream); badSymbol(stream);
return false; return false;
} }
return true; return true;
} }
else if ((isBlock(bt_block) || isBlock(bt_method)) && stream->match(tokens::newline, tokens::string, tokens::newline)) { else if ((isBlock(bt_block) || isBlock(bt_method)) && stream->match(tokens::newline, tokens::string)) {
stream->next(); // Standard consumption stream->next(); // Standard consumption
value temp(variable);
if (match_process_standard(stream, temp)) {
cmd* c = new cmd; cmd* c = new cmd;
c->opcode = codes::DISP; c->opcode = codes::DISP;
c->args.push(value(stream->next().name)); c->args.push(temp);
current_chunk->addCmd(c); // Add the cmd to the current chunk current_chunk->addCmd(c); // Add the cmd to the current chunk
current_chunk->addCmd(new cmd{ codes::HALT }); current_chunk->addCmd(new cmd{ codes::HALT });
return true; return true;
} }
else {
badSymbol(stream);
return false;
}
}
else if ((isBlock(bt_block) || isBlock(bt_method)) && stream->match(tokens::newline,tokens::pipe ,tokens::string, tokens::newline)) { else if ((isBlock(bt_block) || isBlock(bt_method)) && stream->match(tokens::newline,tokens::pipe ,tokens::string, tokens::newline)) {
stream->next(); // Standard consumption stream->next(); // Standard consumption
stream->next(); // pipe consumption stream->next(); // pipe consumption
@ -396,105 +442,6 @@ namespace dms {
current_chunk->addCmd(new cmd{ codes::HALT }); current_chunk->addCmd(new cmd{ codes::HALT });
return true; return true;
} }
else if (isBlock(bt_character) && stream->match(tokens::newline, tokens::name, tokens::colon, tokens::string, tokens::newline)) {
stream->next(); // Standard consumption
std::string name = stream->next().name;
stream->next(); // That colon
std::string msg = stream->next().name;
cmd* c = new cmd;
c->opcode = codes::STAT;
c->args.push(value(name,datatypes::variable));
c->args.push(value(msg));
current_chunk->addCmd(c); // Add the cmd to the current chunk
}
else if ((isBlock(bt_block) || isBlock(bt_method)) && stream->match(tokens::newline, tokens::name, tokens::colon, tokens::string, tokens::newline)) {
// We might have to handle scope here
// Here we match 'Ryan: "This guy said this!"' Note the colon is needed!
stream->next(); // Standard consumption
std::string name = stream->next().name;
stream->next(); // That colon
std::string msg = stream->next().name;
cmd* c = new cmd;
c->opcode = codes::SSPK;
c->args.push(value(name, datatypes::variable));
current_chunk->addCmd(c);
c = new cmd;
c->opcode = codes::DISP;
c->args.push(value(msg));
current_chunk->addCmd(c); // Add the cmd to the current chunk
current_chunk->addCmd(new cmd{ codes::HALT });
return true;
}
else if ((isBlock(bt_block) || isBlock(bt_method)) && stream->match(tokens::name,tokens::colon,tokens::cbracketo)) {
std::string name = stream->next().name;
// Command to set the speaker
cmd* c = new cmd;
c->opcode = codes::SSPK;
c->args.push(value(name,datatypes::variable));
current_chunk->addCmd(c);
stream->next();
stream->next();
while (stream->peek().type != tokens::cbracketc) {
debugInvoker(stream);
if (stream->match(tokens::name)) {
std::string mode = stream->next().name;
if (mode == "speed") {
if (stream->match(tokens::number)) {
buildSpeed(std::stod(stream->next().name));
}
else {
badSymbol(stream);
return false;
}
}
else if (mode == "wait") {
if (stream->match(tokens::number)) {
buildWait(std::stod(stream->next().name));
}
else {
badSymbol(errors::disp_unknown, stream);
}
}
else {
// Assume we have a dact
if (stream->match(tokens::string) || stream->match(tokens::colon,tokens::string)) {
if (stream->match(tokens::colon)) {
stream->next();
}
cmd* c = new cmd;
c->opcode = codes::DACT;
c->args.push(value(mode));
current_chunk->addCmd(c);
// Now build the apnd msg cmd
c = new cmd;
c->opcode = codes::APND;
c->args.push(value(stream->next().name));
current_chunk->addCmd(c);
}
else {
badSymbol(stream);
return false;
}
}
}
else if (stream->match(tokens::string)) {
cmd* c = new cmd;
c->opcode = codes::APND;
c->args.push(value(stream->next().name));
current_chunk->addCmd(c);
}
else if (stream->match(tokens::newline)) {
stream->next();
}
else {
badSymbol(stream);
return false;
}
}
stream->next();
current_chunk->addCmd(new cmd{ codes::HALT });
return true;
}
return false; return false;
} }
bool LineParser::match_process_return(tokenstream* stream) { bool LineParser::match_process_return(tokenstream* stream) {
@ -896,7 +843,24 @@ namespace dms {
return false; return false;
} }
bool LineParser::match_process_index(tokenstream* stream, value& v, bool leftside) { bool LineParser::match_process_index(tokenstream* stream, value& v, bool leftside) {
if (stream->match(tokens::name,tokens::bracketo)) { if (stream->match(tokens::name,tokens::dot,tokens::name)) {
std::string name = stream->next().name;
stream->next();
std::string key = stream->next().name;
cmd* c = new cmd;
if (leftside) {
c->opcode = codes::ASID;
}
else {
c->opcode = codes::INDX;
}
c->args.push(v);
c->args.push(value(name, datatypes::block));
c->args.push(value(key));
current_chunk->addCmd(c);
return true;
}
else if (stream->match(tokens::name,tokens::bracketo)) {
std::string name = stream->next().name; std::string name = stream->next().name;
std::vector<token> toks = stream->next(tokens::bracketo, tokens::bracketc); std::vector<token> toks = stream->next(tokens::bracketo, tokens::bracketc);
toks.pop_back(); // Remove the last element since its a ']' toks.pop_back(); // Remove the last element since its a ']'
@ -1151,11 +1115,11 @@ namespace dms {
temp.push_back(value(ts.next().name)); temp.push_back(value(ts.next().name));
} }
else if (ts.match(tokens::number)) { else if (ts.match(tokens::number)) {
temp.push_back(stov(stream->next().name)); temp.push_back(stov(ts.next().name));
} }
else if (ts.match(tokens::minus,tokens::number)) { else if (ts.match(tokens::minus,tokens::number)) {
ts.next(); ts.next();
temp.push_back(stov(stream->next().name)); temp.push_back(stov(ts.next().name));
} }
else if (ts.match(tokens::True)) { else if (ts.match(tokens::True)) {
temp.push_back(value(true)); temp.push_back(value(true));
@ -1287,6 +1251,8 @@ namespace dms {
} }
} }
if (temp.size() >= 1) { if (temp.size() >= 1) {
if(o == codes::FUNC || o == codes::OFUN)
temp.push_back(escape);
buildCmd(o, temp); buildCmd(o, temp);
} }
return true; return true;
@ -1583,6 +1549,7 @@ namespace dms {
//Function template ^^^ If we encounter an issue the method should push an error, incase it misses something we will! //Function template ^^^ If we encounter an issue the method should push an error, incase it misses something we will!
value tmpvalue = value(datatypes::variable); value tmpvalue = value(datatypes::variable);
if (match_process_function(stream,tmpvalue)) { if (match_process_function(stream,tmpvalue)) {
hasOP = false;
if (left.isNil()) if (left.isNil())
left = tmpvalue; left = tmpvalue;
else if (right.isNil()) else if (right.isNil())
@ -1598,6 +1565,7 @@ namespace dms {
} }
} }
else if (stream->match(tokens::number)) { else if (stream->match(tokens::number)) {
hasOP = false;
if (left.isNil()) if (left.isNil())
left = stov(stream->next().name); left = stov(stream->next().name);
else if (right.isNil()) else if (right.isNil())
@ -1608,6 +1576,7 @@ namespace dms {
} }
} }
else if (stream->match(tokens::string)) { else if (stream->match(tokens::string)) {
hasOP = false;
if (left.isNil()) if (left.isNil())
left = value(stream->next().name,string); left = value(stream->next().name,string);
else if (right.isNil()) else if (right.isNil())
@ -1620,6 +1589,7 @@ namespace dms {
else if (stream->match(tokens::name, tokens::bracketo)) { else if (stream->match(tokens::name, tokens::bracketo)) {
value tmpvalue = value(datatypes::variable); value tmpvalue = value(datatypes::variable);
if (match_process_index(stream, tmpvalue)) { if (match_process_index(stream, tmpvalue)) {
hasOP = false;
if (left.isNil()) if (left.isNil())
left = tmpvalue; left = tmpvalue;
else if (right.isNil()) else if (right.isNil())
@ -1632,6 +1602,7 @@ namespace dms {
} }
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!
hasOP = false;
if (left.isNil()) if (left.isNil())
left = value(stream->next().name,datatypes::variable); left = value(stream->next().name,datatypes::variable);
else if (right.isNil()) else if (right.isNil())
@ -1641,7 +1612,7 @@ namespace dms {
return false; return false;
} }
} }
else if (stream->match(tokens::newline) || stream->match(tokens::parac) || stream->match(tokens::seperator)) { else if ((stream->match(tokens::newline) && !hasOP) || stream->match(tokens::parac) || stream->match(tokens::seperator)) {
if (wv.isNil()) if (wv.isNil())
return stream->restore(lastcmd, current_chunk); // Always return false and restores the position in stream! return stream->restore(lastcmd, current_chunk); // Always return false and restores the position in stream!
cmd* cc = new cmd; cmd* cc = new cmd;

View File

@ -1,3 +1,4 @@
#include "pch.h"
#include "LineParser.h" #include "LineParser.h"
using namespace dms::tokens; using namespace dms::tokens;
using namespace dms::utils; using namespace dms::utils;
@ -239,12 +240,12 @@ namespace dms {
doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer); doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer);
t_vec.push_back(token{ tokens::anglebracketO,codes::NOOP,"<",line }); t_vec.push_back(token{ tokens::anglebracketO,codes::NOOP,"<",line });
} }
else if (data == '\t') { /*else if (data == '\t') {
doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer); doCheck(&stream, &t_vec, line, isNum, hasDec, &buffer);
t_vec.push_back(token{ tokens::tab,codes::NOOP,"\t",line }); t_vec.push_back(token{ tokens::tab,codes::NOOP,"\t",line });
} }*/
if ((data == ' ' || data == '(') && !isStr) { // tokens end with a space if ((data == ' ' || data == '(' || data == '\t') && !isStr) { // tokens end with a space
std::string str = stream.processBuffer(buffer); std::string str = stream.processBuffer(buffer);
tolower(str); tolower(str);
if (str == "enable") { if (str == "enable") {
@ -531,8 +532,8 @@ namespace dms {
if (stream->match(newline) || stream->match(eof)) { if (stream->match(newline) || stream->match(eof)) {
current = stream->next(); current = stream->next();
} }
} }
return true;
} }
void LineParser::_Parse(tokenstream* stream) { void LineParser::_Parse(tokenstream* stream) {
if (stop) return; if (stop) return;

View File

@ -1,5 +1,5 @@
#include "pch.h"
#include "LineParser.h" #include "LineParser.h"
#include <random>
using namespace dms::tokens; using namespace dms::tokens;
using namespace dms::utils; using namespace dms::utils;
namespace dms { namespace dms {
@ -249,6 +249,15 @@ namespace dms {
buffer->clear(); buffer->clear();
hasDec = false; hasDec = false;
} }
else if (str.find('.')!=std::string::npos) {
auto s = utils::split(str, ".");
t_vec->push_back(token{ tokens::name,codes::NOOP,s[0],line });
t_vec->push_back(token{ tokens::dot,codes::NOOP,"dot",line });
t_vec->push_back(token{ tokens::name,codes::NOOP,s[1],line });
buffer->clear();
isNum = false;
hasDec = false;
}
else { else {
t_vec->push_back(token{ tokens::name,codes::ERRO,"Invalid variable name!",line }); t_vec->push_back(token{ tokens::name,codes::ERRO,"Invalid variable name!",line });
} }

5
DMS/Ryan.dms Normal file
View File

@ -0,0 +1,5 @@
filetype char // Define this file as a char, the default makes all all blocks "block"
// This definition allows us to do some cool things, like adding our own methods into the base character object
[setNickname:function(name)]
nickname = name

View File

@ -1,3 +1,4 @@
#include "pch.h"
#include "character.h" #include "character.h"
#include "utils.h" #include "utils.h"
namespace dms { namespace dms {

View File

@ -1,3 +1,4 @@
#include "pch.h"
#include "chunk.h" #include "chunk.h"
namespace dms { namespace dms {
std::string getBlockType(const blocktype b) { std::string getBlockType(const blocktype b) {

View File

@ -1,8 +1,6 @@
#pragma once #pragma once
#include "pch.h"
#include "cmd.h" #include "cmd.h"
#include <string>
#include <vector>
#include <map>
namespace dms { namespace dms {
enum blocktype { enum blocktype {
bt_block, bt_block,

View File

@ -1 +1,2 @@
#include "pch.h"
#include "cmd.h" #include "cmd.h"

View File

@ -1,8 +1,7 @@
#pragma once #pragma once
#include "pch.h"
#include "value.h" #include "value.h"
#include "codes.h" #include "codes.h"
#include <ostream>
#include <vector>
namespace dms { namespace dms {
struct cmd struct cmd
{ {

View File

@ -1,4 +1,5 @@
#pragma once #pragma once
#include "pch.h"
#include "Codes.h" #include "Codes.h"
const std::string dms::codes::list[] = { const std::string dms::codes::list[] = {
"NOOP", "NOOP",

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <vector> #include "pch.h"
#include <string> namespace dms {
namespace dms::codes { namespace codes {
enum op { enum op {
NOOP, // Done NOOP, // Done
ENTR, // Done ENTR, // Done
@ -55,3 +55,4 @@ namespace dms::codes {
}; };
extern const std::string list[]; extern const std::string list[];
} }
}

30
DMS/core.cpp Normal file
View File

@ -0,0 +1,30 @@
#pragma once
#include "pch.h"
#include "core.h"
#include "utils.h"
namespace dms {
namespace core {
value print(void* self, dms_state* state, dms_args* args) {
std::string str = "";
for (size_t i = 0; i < args->args.size(); i++) {
str += args->args[i].getPrintable() + "\t";
}
printf((str + "\n").c_str());
return NULL;
}
value type(void* self, dms_state* state, dms_args* args) {
if (args->size() > 0) {
value temp = args->args[0];
if (temp.type == datatypes::custom && temp.ctype != "")
return temp.ctype;
else
return datatype[args->args[0].type];
}
return "nil";
}
void init(dms_state* state) {
state->invoker.registerFunction("print", print);
state->invoker.registerFunction("type", type);
}
}
}

9
DMS/core.h Normal file
View File

@ -0,0 +1,9 @@
#pragma once
#include "dms_state.h"
namespace dms {
namespace core {
void init(dms_state* state);
value print(void* self, dms_state* state, dms_args* args);
value type(void* self, dms_state* state, dms_args* args);
}
}

View File

@ -14,4 +14,8 @@
#include "Invoker.h" #include "Invoker.h"
#include "memory.h" #include "memory.h"
#include "dms_list.h" #include "dms_list.h"
#include "s_value.h"
#include "wrapper.h"
#include "sound.h"
#include "comparisons.h"

View File

@ -1,3 +1,4 @@
#include "pch.h"
#include "value.h" #include "value.h"
#include "utils.h" #include "utils.h"
//Implement the defaults //Implement the defaults

View File

@ -1 +1,2 @@
#include "pch.h"
#include "dms_exceptions.h" #include "dms_exceptions.h"

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <exception> #include "pch.h"
namespace dms::exceptions { namespace dms {
namespace exceptions {
struct StringBoundsException : public std::exception { struct StringBoundsException : public std::exception {
const char* what() const throw () { const char* what() const throw () {
return "Attempt to sub outside of the bounds of the string!"; return "Attempt to sub outside of the bounds of the string!";
@ -17,4 +18,4 @@ namespace dms::exceptions {
} }
}; };
} }
}

View File

@ -1,5 +1,8 @@
#include "pch.h"
#include "dms_state.h" #include "dms_state.h"
#include "Handlers.h" #include "Handlers.h"
#include "core.h"
#include "sound.h"
namespace dms { namespace dms {
value dms::blockInvoke(void* self, dms_state* state, dms_args* args) { value dms::blockInvoke(void* self, dms_state* state, dms_args* args) {
std::string func = state->call_stack.top(); std::string func = state->call_stack.top();
@ -35,6 +38,7 @@ namespace dms {
void dms_state::init() { void dms_state::init() {
if (init_init || stop) if (init_init || stop)
return; return;
init_init = true; init_init = true;
cmd* c = new cmd; cmd* c = new cmd;
for (const auto& [key, val] : chunks) { for (const auto& [key, val] : chunks) {
@ -65,6 +69,7 @@ namespace dms {
else else
c->args.push(value(chunks.begin()->first)); c->args.push(value(chunks.begin()->first));
chunks["$INIT"]->addCmd(c); chunks["$INIT"]->addCmd(c);
dms::core::init(this);
if (!handler->OnStateInit(this)) if (!handler->OnStateInit(this))
stop = true; stop = true;
} }
@ -72,7 +77,12 @@ namespace dms {
return &mem_stack.top(); return &mem_stack.top();
} }
void dms_state::pushMem() { void dms_state::pushMem() {
mem_stack.push(memory()); memory mem = memory();
if (!mem_stack.empty()) {
mem.parent = getMem();
}
mem_stack.push(mem);
} }
void dms_state::pushMem(memory &mem) { void dms_state::pushMem(memory &mem) {
mem_stack.push(mem); mem_stack.push(mem);
@ -145,6 +155,15 @@ namespace dms {
return false; return false;
} }
bool dms_state::assoiateType(std::string type, Invoker* inv)
{
if(inv_map.count(type)) // Already exists!
return false;
inv_map.insert_or_assign(type,inv); // Create it
return true;
}
bool dms_state::injectEnv(std::string name, enviroment* env) bool dms_state::injectEnv(std::string name, enviroment* env)
{ {
std::string ename = name; std::string ename = name;

View File

@ -1,8 +1,5 @@
#pragma once #pragma once
#include <fstream> #include "pch.h"
#include <string>
#include <iostream>
#include <unordered_map>
#include "Invoker.h" #include "Invoker.h"
#include "errors.h" #include "errors.h"
#include "chunk.h" #include "chunk.h"
@ -10,7 +7,6 @@
#include "Character.h" #include "Character.h"
#include "enviroment.h" #include "enviroment.h"
#include "memory.h" #include "memory.h"
#include <stack>
#include "dms_list.h" #include "dms_list.h"
#include "comparisons.h" #include "comparisons.h"
namespace dms { namespace dms {
@ -30,6 +26,7 @@ namespace dms {
std::unordered_map<std::string, character*> characters; std::unordered_map<std::string, character*> characters;
std::unordered_map<std::string, enviroment*> environments; std::unordered_map<std::string, enviroment*> environments;
std::unordered_map<std::string, size_t> labels; std::unordered_map<std::string, size_t> labels;
std::unordered_map<std::string, Invoker*> inv_map;
std::string entry = "$undefined"; std::string entry = "$undefined";
std::unordered_map<std::string, bool> enables; std::unordered_map<std::string, bool> enables;
std::size_t cur_line=0; std::size_t cur_line=0;
@ -38,6 +35,7 @@ namespace dms {
const double Iversion = 1.0; const double Iversion = 1.0;
double Sversion; // The version of double Sversion; // The version of
errors::error err; errors::error err;
character* speaker = nullptr;
dms_state(); dms_state();
void dump(std::string fn = "dump.bin"); void dump(std::string fn = "dump.bin");
@ -57,6 +55,7 @@ namespace dms {
character* getCharacter(std::string c); character* getCharacter(std::string c);
enviroment* getEnvironment(std::string c); enviroment* getEnvironment(std::string c);
bool assoiateType(std::string type, Invoker* inv);
bool injectEnv(std::string, enviroment*); bool injectEnv(std::string, enviroment*);
bool assign(value var, value val); bool assign(value var, value val);
size_t seek(std::string label,std::vector<cmd*> cmds ,codes::op code, size_t pos); size_t seek(std::string label,std::vector<cmd*> cmds ,codes::op code, size_t pos);
@ -71,6 +70,7 @@ namespace dms {
bool run(); bool run();
bool run(std::string ent,memory* mem); bool run(std::string ent,memory* mem);
bool run(std::string instance); bool run(std::string instance);
bool error(std::string);
// This is called once and once only. Dynamically loading code is not a thing! // This is called once and once only. Dynamically loading code is not a thing!
void init(); void init();
bool hasError(); bool hasError();

View File

@ -1,8 +1,7 @@
#include "pch.h"
#include "dms_state.h" #include "dms_state.h"
#include "utils.h" #include "utils.h"
#include "Handlers.h" #include "Handlers.h"
#include <iostream>
#include <chrono>
using namespace dms::utils; using namespace dms::utils;
using namespace dms::exceptions; using namespace dms::exceptions;
using namespace dms::codes; using namespace dms::codes;
@ -113,6 +112,11 @@ namespace dms {
//Spawn thread and run //Spawn thread and run
return true; return true;
} }
bool dms_state::error(std::string err)
{
push_error(errors::error{ errors::unknown ,err });
return false;
}
bool dms_state::run() { bool dms_state::run() {
if (stop) if (stop)
return false; return false;
@ -138,7 +142,6 @@ namespace dms {
//TODO: parse the cmds and do stuff //TODO: parse the cmds and do stuff
// If this is running in a thread then stop will force this loop to stop // If this is running in a thread then stop will force this loop to stop
size_t ln = 0; size_t ln = 0;
character* speaker = nullptr;
std::string temp; std::string temp;
while (!stop || !halt) { while (!stop || !halt) {
c = cmds[pos++]; c = cmds[pos++];
@ -254,6 +257,29 @@ namespace dms {
break; break;
case OFUN: case OFUN:
{ {
if (c->args.args[0].resolve(this).type == datatypes::custom) {
auto cust = c->args.args[0].resolve(this);
auto fname = c->args.args[1].s;
auto assn = c->args.args[2];
dms_args args;
for (int i = 3; i < c->args.args.size(); i++) {
args.push(c->args.args[i]);
}
if (inv_map.count(cust.ctype)) {
Invoker* inv = inv_map[cust.ctype];
auto ret = inv->Invoke(fname, cust.c, this, &args);
if (assn.type != datatypes::nil) {
if (!assign(assn, ret)) {
return false;
}
}
}
else {
error("Custom object not assoiated with any functions!");
}
}
else {
std::string obj = c->args.args[0].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();
@ -281,6 +307,7 @@ namespace dms {
} }
} }
} }
}
break; break;
case FUNC: case FUNC:
{ {
@ -313,15 +340,15 @@ namespace dms {
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);
value assn = c->args.args[3].resolve(this); value assn = c->args.args[3].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];
} }
e->values[indx.getPrintable()] = assn; e->values[indx.s] = assn;
} }
else if (env.type == datatypes::env) { else if (env.type == datatypes::env) {
if (indx.type == datatypes::number) { if (indx.type == datatypes::number) {
@ -333,7 +360,7 @@ namespace dms {
} }
} }
else if (env.type == datatypes::custom) { else if (env.type == datatypes::custom) {
env.c->NewIndex(indx, assn); //env.c->NewIndex(indx, assn);
//if(!assign( assn, env->c->Index(indx)); //if(!assign( assn, env->c->Index(indx));
// Call the method within the custom data // Call the method within the custom data
} }
@ -434,9 +461,9 @@ namespace dms {
} }
} }
else if (env.type == datatypes::custom) { else if (env.type == datatypes::custom) {
if(!assign( assn, env.c->Index(indx))) { //if(!assign( assn, env.c->Index(indx))) {
return false; // return false;
} //}
// Call the method within the custom data // Call the method within the custom data
} }
} }

Binary file not shown.

View File

@ -23,164 +23,343 @@ Line <6> newline
Line <7> newline Line <7> newline
Line <8> newline Line <8> newline
Line <9> newline Line <9> newline
Line <10> flag
Line <10> number 0.2
Line <10> newline
Line <10> newline Line <10> newline
Line <11> flag Line <11> flag
Line <11> name extendedDefine Line <11> number 0.2
Line <11> newline Line <11> newline
Line <11> newline Line <11> newline
Line <12> bracketo [ Line <12> flag
Line <12> name main Line <12> name extendedDefine
Line <12> bracketc ]
Line <12> newline Line <12> newline
Line <12> newline Line <12> newline
Line <13> name Ryan
Line <13> colon :
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 <14> name music
Line <14> name Bob Line <14> equal =
Line <14> dot . Line <14> name loadMusic
Line <14> name setName
Line <14> parao ( Line <14> parao (
Line <14> string Rob Line <14> string test2.ogg
Line <14> parac ) Line <14> parac )
Line <14> newline Line <14> newline
Line <14> newline Line <14> newline
Line <15> name Ryan Line <15> name music2
Line <15> colon : Line <15> equal =
Line <15> string Hello Line <15> name loadMusic
Line <15> plus + Line <15> parao (
Line <15> name Bob Line <15> string test.ogg
Line <15> plus + Line <15> parac )
Line <15> string ! How are you doing?
Line <15> newline Line <15> newline
Line <15> newline Line <15> newline
Line <16> bracketo [
Line <16> name main
Line <16> bracketc ]
Line <16> newline Line <16> newline
Line <16> newline
Line <17> name a
Line <17> equal =
Line <17> number 10
Line <17> newline Line <17> newline
Line <17> newline Line <17> newline
Line <18> name tester
Line <18> parao (
Line <18> parac )
Line <18> newline Line <18> newline
Line <18> newline
Line <19> name print
Line <19> parao (
Line <19> string a =
Line <19> plus +
Line <19> name a
Line <19> parac )
Line <19> newline
Line <19> newline Line <19> newline
Line <20> newline Line <20> newline
Line <21> newline Line <21> 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 <24> ret
Line <24> name n
Line <24> plus +
Line <24> number 1
Line <24> newline
Line <24> newline Line <24> newline
Line <25> newline Line <25> newline
Line <25> newline
Line <26> bracketo [
Line <26> name Ryan
Line <26> colon :
Line <26> name char
Line <26> bracketc ]
Line <26> newline Line <26> newline
Line <26> newline
Line <27> name lname
Line <27> equal =
Line <27> string Ward
Line <27> newline Line <27> newline
Line <27> newline
Line <28> name age
Line <28> equal =
Line <28> number 24
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 <30> name money
Line <30> equal =
Line <30> number 0
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 <33> newline
Line <34> name age
Line <34> equal =
Line <34> number 16
Line <34> newline Line <34> newline
Line <34> newline
Line <35> name money
Line <35> equal =
Line <35> number 100000
Line <35> newline Line <35> newline
Line <35> newline
Line <36> name known
Line <36> equal =
Line <36> true true
Line <36> newline
Line <36> newline Line <36> newline
Line <37> newline Line <37> newline
Line <37> newline
Line <38> bracketo [
Line <38> name Bob
Line <38> colon :
Line <38> name char
Line <38> bracketc ]
Line <38> newline
Line <38> newline Line <38> newline
Line <39> newline Line <39> newline
Line <40> newline Line <40> newline
Line <41> name lname
Line <41> equal =
Line <41> string Johnson
Line <41> newline Line <41> newline
Line <42> name unknown
Line <42> equal =
Line <42> string Some Random Guy
Line <42> newline Line <42> newline
Line <42> newline
Line <43> name age
Line <43> equal =
Line <43> number 24
Line <43> newline Line <43> newline
Line <43> newline Line <43> newline
Line <44> name money Line <44> bracketo [
Line <44> equal = Line <44> name tester
Line <44> number 100 Line <44> colon :
Line <44> name function
Line <44> parao (
Line <44> parac )
Line <44> bracketc ]
Line <44> newline Line <44> newline
Line <44> newline Line <44> newline
Line <45> name excited Line <45> name print
Line <45> colon : Line <45> parao (
Line <45> string path/to/file Line <45> name a
Line <45> parac )
Line <45> newline Line <45> newline
Line <45> newline Line <45> newline
Line <45> eof Line <46> newline
Line <46> newline
Line <47> bracketo [
Line <47> name SelectSong
Line <47> colon :
Line <47> name function
Line <47> parao (
Line <47> parac )
Line <47> bracketc ]
Line <47> newline
Line <47> newline
Line <48> control
Line <48> string Pick song:
Line <48> cbracketo {
Line <48> newline
Line <48> newline
Line <49> string Music 1
Line <49> cbracketo {
Line <49> newline
Line <49> newline
Line <50> ret
Line <50> name music
Line <50> newline
Line <50> newline
Line <51> cbracketc }
Line <51> newline
Line <51> newline
Line <52> string Music 2
Line <52> cbracketo {
Line <52> newline
Line <52> newline
Line <53> ret
Line <53> name music2
Line <53> newline
Line <53> newline
Line <54> cbracketc }
Line <54> newline
Line <54> newline
Line <55> cbracketc }
Line <55> newline
Line <55> newline
Line <56> newline
Line <56> newline
Line <57> bracketo [
Line <57> name player
Line <57> colon :
Line <57> name function
Line <57> parao (
Line <57> name song
Line <57> parac )
Line <57> bracketc ]
Line <57> newline
Line <57> newline
Line <58> control
Line <58> string What you wanna do?
Line <58> cbracketo {
Line <58> newline
Line <58> newline
Line <59> string play/resume
Line <59> cbracketo {
Line <59> newline
Line <59> newline
Line <60> name song
Line <60> dot dot
Line <60> name play
Line <60> parao (
Line <60> parac )
Line <60> newline
Line <60> newline
Line <61> name player
Line <61> parao (
Line <61> name song
Line <61> parac )
Line <61> newline
Line <61> newline
Line <62> cbracketc }
Line <62> newline
Line <62> newline
Line <63> string pause
Line <63> cbracketo {
Line <63> newline
Line <63> newline
Line <64> name song
Line <64> dot .
Line <64> name pause
Line <64> parao (
Line <64> parac )
Line <64> newline
Line <64> newline
Line <65> name player
Line <65> parao (
Line <65> name song
Line <65> parac )
Line <65> newline
Line <65> newline
Line <66> cbracketc }
Line <66> newline
Line <66> newline
Line <67> string stop
Line <67> cbracketo {
Line <67> newline
Line <67> newline
Line <68> name song
Line <68> dot .
Line <68> name stop
Line <68> parao (
Line <68> parac )
Line <68> newline
Line <68> newline
Line <69> name player
Line <69> parao (
Line <69> name song
Line <69> parac )
Line <69> newline
Line <69> newline
Line <70> cbracketc }
Line <70> newline
Line <70> newline
Line <71> string newSong
Line <71> cbracketo {
Line <71> newline
Line <71> newline
Line <72> name song
Line <72> dot .
Line <72> name stop
Line <72> parao (
Line <72> parac )
Line <72> newline
Line <72> newline
Line <73> name player
Line <73> parao (
Line <73> name song
Line <73> parac )
Line <73> newline
Line <73> newline
Line <74> cbracketc }
Line <74> newline
Line <74> newline
Line <75> string quit
Line <75> exit
Line <75> number 0
Line <75> newline
Line <75> newline
Line <76> cbracketc }
Line <76> newline
Line <76> newline
Line <77> newline
Line <77> newline
Line <78> bracketo [
Line <78> name Ryan
Line <78> colon :
Line <78> name char
Line <78> bracketc ]
Line <78> newline
Line <78> newline
Line <79> name age
Line <79> equal =
Line <79> number 21
Line <79> newline
Line <79> newline
Line <80> name money
Line <80> equal =
Line <80> number 1000
Line <80> newline
Line <80> newline
Line <81> name lname
Line <81> equal =
Line <81> string Ward
Line <81> newline
Line <81> newline
Line <82> name known
Line <82> equal =
Line <82> true true
Line <82> newline
Line <82> newline
Line <83> newline
Line <84> name calm
Line <84> colon :
Line <84> string ./path/to/file
Line <84> newline
Line <84> newline
Line <85> name excited
Line <85> colon :
Line <85> string ./path/to/file
Line <85> newline
Line <85> newline
Line <86> newline
Line <86> newline
Line <87> bracketo [
Line <87> name John
Line <87> colon :
Line <87> name char
Line <87> bracketc ]
Line <87> newline
Line <87> newline
Line <88> name lname
Line <88> equal =
Line <88> string Johnson
Line <88> newline
Line <88> newline
Line <89> name age
Line <89> equal =
Line <89> number 16
Line <89> newline
Line <89> newline
Line <90> name money
Line <90> equal =
Line <90> number 100000
Line <90> newline
Line <90> newline
Line <91> name known
Line <91> equal =
Line <91> true true
Line <91> newline
Line <91> newline
Line <92> newline
Line <92> newline
Line <93> bracketo [
Line <93> name Bob
Line <93> colon :
Line <93> name char
Line <93> bracketc ]
Line <93> newline
Line <93> newline
Line <94> newline
Line <95> newline
Line <96> name lname
Line <96> equal =
Line <96> string Johnson
Line <96> newline
Line <97> name unknown
Line <97> equal =
Line <97> string Some Random Guy
Line <97> newline
Line <97> newline
Line <98> name age
Line <98> equal =
Line <98> number 24
Line <98> newline
Line <98> newline
Line <99> name money
Line <99> equal =
Line <99> number 100
Line <99> newline
Line <99> newline
Line <100> name excited
Line <100> colon :
Line <100> string path/to/file
Line <100> newline
Line <100> newline
Line <100> eof

View File

@ -1,3 +1,4 @@
#include "pch.h"
#include "enviroment.h" #include "enviroment.h"
namespace dms { namespace dms {
bool enviroment::has(std::string index) { bool enviroment::has(std::string index) {

View File

@ -1,6 +1,5 @@
#pragma once #pragma once
#include <string> #include "pch.h"
#include <unordered_map>
#include "value.h" #include "value.h"
#include "memory.h" #include "memory.h"
#include "Invoker.h" #include "Invoker.h"

View File

@ -1,7 +1,8 @@
#pragma once #pragma once
#include <string> #include "pch.h"
#include "chunk.h" #include "chunk.h"
namespace dms::errors { namespace dms {
namespace errors {
enum errortype { enum errortype {
unknown, unknown,
string_out_of_bounds, string_out_of_bounds,
@ -25,3 +26,4 @@ namespace dms::errors {
chunk* current_chunk = nullptr; chunk* current_chunk = nullptr;
}; };
} }
}

View File

@ -3,15 +3,6 @@
money = 0 money = 0
test = nil test = nil
[Ryan:char]
age = 21
money = 1000
lname = "Ward"
known = true
// Inside a character block this syntax defines animation/image file for an emotion
calm: "./path/to/file"
excited: "./path/to/file"
[step:function(a,b,c)] [step:function(a,b,c)]
"Testing..." // testing "Testing..." // testing
//d = (100 + b) / c //d = (100 + b) / c

View File

@ -1,9 +1,13 @@
#include "pch.h"
#include "memory.h" #include "memory.h"
#include <vector>
#include <iostream>
#include "utils.h" #include "utils.h"
namespace dms { namespace dms {
value& memory::operator[](std::string str) { value& memory::operator[](std::string str) {
/*if (!mem[str].isNil())
return mem[str];
else if (parent != nullptr && parent->count(str)) {
return parent->mem[str];
}*/
return mem[str]; return mem[str];
} }
std::vector<value> memory::examine(datatypes dt) std::vector<value> memory::examine(datatypes dt)
@ -23,4 +27,9 @@ namespace dms {
void memory::erase(std::string str) { void memory::erase(std::string str) {
mem.erase(str); mem.erase(str);
} }
memory::memory(const memory& other) {
mem = other.mem;
parent = other.parent;
}
memory::memory(){}
} }

View File

@ -1,7 +1,5 @@
#pragma once #pragma once
#include <unordered_map> #include "pch.h"
#include <string>
#include <vector>
#include "value.h" #include "value.h"
namespace dms { namespace dms {
struct memory struct memory
@ -10,6 +8,9 @@ namespace dms {
void erase(std::string); void erase(std::string);
value& operator[](std::string); value& operator[](std::string);
std::vector<value> examine(datatypes dt); std::vector<value> examine(datatypes dt);
memory* parent = nullptr;
memory(const memory& other);
memory();
private: private:
std::unordered_map<std::string, value> mem; std::unordered_map<std::string, value> mem;
}; };

View File

1
DMS/pch.cpp Normal file
View File

@ -0,0 +1 @@
#include "pch.h"

18
DMS/pch.h Normal file
View File

@ -0,0 +1,18 @@
#pragma once
#include <iostream>
#include <chrono>
#include <vector>
#include <random>
#include <string>
#include <unordered_map>
#include <exception>
#include <fstream>
#include <stack>
#include <iterator>
#include <stdio.h>
#include <ctype.h>
#include <sstream>
#include <cstdarg>
#include <algorithm>
#include <time.h>
#include <map>

31
DMS/s_value.h Normal file
View File

@ -0,0 +1,31 @@
#pragma once
extern "C" {
// 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
const char sv_escape = 0x00;
const char sv_nil = 0x01;
const char sv_number = 0x02;
const char sv_int = 0x03;
const char sv_boolean = 0x04;
const char sv_env = 0x05;
const char sv_string = 0x06;
const char sv_custom = 0x07;
const char sv_variable = 0x08;
const char sv_block = 0x09;
const char sv_error = 0x10;
struct s_value {
char type = sv_nil; // The type of the value
const char* s; // Contains the string part.
long long int i; // The int portion of the code
long double n;
};
void sm_value_setEscape(s_value& sv) { sv.type = sv_escape; } // An escape type, used at the end of an array of values.
void sm_value_setInt(s_value& sv, int n) { sv.type = sv_int; sv.i = n; } // Define value as an int
void sm_value_setDouble(s_value& sv, long double d) { sv.type = sv_number; sv.n = d; } // Define value as a double
void sm_value_setString(s_value& sv, const char* str) { sv.type = sv_string; sv.s = str; } // Define value as a string
void sm_value_setBlock(s_value& sv, const char* str) { sv.type = sv_block; sv.s = str; } // Define value as a block
void sm_value_setVariable(s_value& sv, const char* str) { sv.type = sv_variable; sv.s = str; } // Define value as a variable
void sm_value_setNil(s_value& sv) { sv.type = sv_nil; } // Define value as nil
}

92
DMS/sound.cpp Normal file
View File

@ -0,0 +1,92 @@
#include "pch.h"
#include "sound.h"
//sf::Music music;
//if (!music.openFromFile("test2.ogg"))
//return -1; // error
//music.setPitch(.6);
//music.setLoop(true);
//music.play();
namespace dms::audio {
value play(void* self, dms_state* state, dms_args* args) {
// Self, since it is a custom object will be equal to whatever we declared to the c pointer!
sf::Music* music = (sf::Music*)self;
music->play();
return value();
}
value pause(void* self, dms_state* state, dms_args* args) {
sf::Music* music = (sf::Music*)self;
music->pause();
return value();
}
value stop(void* self, dms_state* state, dms_args* args) {
sf::Music* music = (sf::Music*)self;
music->stop();
return value();
}
value setLoop(void* self, dms_state* state, dms_args* args) {
if (args->size() || args->args[0].resolve(state).type == datatypes::boolean) {
sf::Music* music = (sf::Music*)self;
music->setLoop(args->args[0].resolve(state).b);
return NULL;
}
}
value setPitch(void* self, dms_state* state, dms_args* args) {
if (args->size() || args->args[0].resolve(state).isNum()) {
sf::Music* music = (sf::Music*)self;
music->setPitch(args->args[0].resolve(state).getDouble());
return NULL;
}
}
value setVolume(void* self, dms_state* state, dms_args* args) {
if (args->size() || args->args[0].resolve(state).isNum()) {
sf::Music* music = (sf::Music*)self;
music->setVolume(args->args[0].resolve(state).getDouble());
return NULL;
}
}
value getStatus(void* self, dms_state* state, dms_args* args) {
sf::Music* music = (sf::Music*)self;
if (music->getStatus() == sf::Music::Status::Paused) {
return "paused";
}
else if (music->getStatus() == sf::Music::Status::Playing) {
return "playing";
}
else {
return "stopped";
}
}
// The customtype will be "sound"
// We need to assoiate the sound type with an invoker so the interperter knows how to handle it
Invoker* inv = new Invoker;
void init(dms_state* state) {
inv->registerFunction("play",play);
inv->registerFunction("resume",play);
inv->registerFunction("pause", pause);
inv->registerFunction("stop", stop);
inv->registerFunction("setLoop",setLoop);
inv->registerFunction("setPitch", setPitch);
inv->registerFunction("setVolume", setVolume);
inv->registerFunction("getStatus", getStatus);
state->assoiateType("audiostream",inv);
state->invoker.registerFunction("loadMusic", loadMusic);
}
value loadMusic(void* self, dms_state* state, dms_args* args)
{
if (args->size() || args->args[0].resolve(state).type == datatypes::string) {
sf::Music* music = new sf::Music;
if (!music->openFromFile(args->args[0].s)) {
return value("Cannot open audio stream!", datatypes::error);
}
return value(music, "audiostream");
}
return value("First argument must be a string!",datatypes::error);
}
}

9
DMS/sound.h Normal file
View File

@ -0,0 +1,9 @@
#pragma once
#include "pch.h"
#include <SFML/Audio.hpp>
#include "dms_state.h"
namespace dms::audio {
void init(dms_state*);
value loadMusic(void*, dms_state*, dms_args*);
// I want to do more with this, like effects and stuff. For now only simple things are implemented
}

View File

@ -4,30 +4,85 @@ disable omniscient
disable 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
//loadfile "Ryan.dms"
//enable leaking //enable leaking
//enable debugging //enable debugging
//loadfile "loadtest.dms" //loadfile "loadtest.dms"
version 0.2 version 0.2
using extendedDefine using extendedDefine
// this code will reside within
music = loadMusic("test2.ogg")
music2 = loadMusic("test.ogg")
[main] [main]
Ryan: "Hello Mr. " + Bob["lname"] + "! How are you doing?" a = 10
Bob.setName("Rob") tester()
Ryan: "Hello " + Bob + "! How are you doing?" print("a = " + a)
//io.print(test 122 + 7) // music.setPitch(.7)
// print(music.getStatus())
// music.play()
// print(music.getStatus())
// print("Type: " + type(music2))
// while(music.getStatus()!="stopped"){
// wait 1
// }
// print("Done")
// a = 0
// while (true){
// asm {
// add %a %a 1
// add %p "a = " %a
// func %print nil %p
// }
// a = a + 1
// print("a = " + a)
// }
// while(true){
// song = SelectSong()
// player(song)
// }
// Ryan: "I am good" [tester:function()]
// John: "Hi " + Ryan + " how are you?" print(a)
// sqrt 144 + 10
// speed
[test:function(n)] [SelectSong:function()]
return n + 1 choice "Pick song:" {
"Music 1" {
return music
}
"Music 2" {
return music2
}
}
[player:function(song)]
choice "What you wanna do?" {
"play/resume" {
song.play()
player(song)
}
"pause" {
song.pause()
player(song)
}
"stop" {
song.stop()
player(song)
}
"newSong" {
song.stop()
player(song)
}
"quit" exit 0
}
[Ryan:char] [Ryan:char]
age = 21
money = 1000
lname = "Ward" lname = "Ward"
age = 24
known = true known = true
money = 0 // Inside a character block this syntax defines animation/image file for an emotion
calm: "./path/to/file"
excited: "./path/to/file"
[John:char] [John:char]
lname = "Johnson" lname = "Johnson"

BIN
DMS/test.ogg Normal file

Binary file not shown.

BIN
DMS/test2.ogg Normal file

Binary file not shown.

View File

@ -1,8 +1,9 @@
#pragma once #pragma once
#include <string> #include "pch.h"
#include "codes.h" #include "codes.h"
#include "utils.h" #include "utils.h"
namespace dms::tokens { namespace dms {
namespace tokens {
enum tokentype { enum tokentype {
none, none,
noop, noop,
@ -134,3 +135,4 @@ namespace dms::tokens {
} }
}; };
} }
}

View File

@ -1,8 +1,23 @@
#include "pch.h"
#include "utils.h" #include "utils.h"
namespace dms::utils { namespace dms::utils {
void print(const value val) { void print(const value val) {
printf(val.getPrintable().c_str()); printf(val.getPrintable().c_str());
} }
std::vector<std::string> split(const std::string& str, const std::string& delim)
{
std::vector<std::string> tokens;
size_t prev = 0, pos = 0;
do
{
pos = str.find(delim, prev);
if (pos == std::string::npos) pos = str.length();
std::string token = str.substr(prev, pos - prev);
if (!token.empty()) tokens.push_back(token);
prev = pos + delim.length();
} while (pos < str.length() && prev < str.length());
return tokens;
}
std::string concat(value& v1, value& v2, value& v3, value& v4, value& v5, value& v7, value& v8, value& v9, value& v10, value& v11, value& v12) { std::string concat(value& v1, value& v2, value& v3, value& v4, value& v5, value& v7, value& v8, value& v9, value& v10, value& v11, value& v12) {
std::vector<value> list{v1,v2,v3,v4,v5,v7,v8,v9,v10,v11,v12}; std::vector<value> list{v1,v2,v3,v4,v5,v7,v8,v9,v10,v11,v12};
std::string str=""; std::string str="";

View File

@ -1,14 +1,9 @@
#pragma once #pragma once
#include <iostream> #include "pch.h"
#include <sstream>
#include <cstdarg>
#include <string>
#include <algorithm>
#include "value.h" #include "value.h"
#include <unordered_map>
#include "dms_state.h" #include "dms_state.h"
#include <time.h> namespace dms {
namespace dms::utils { namespace utils {
template<class... Args> template<class... Args>
void debug(const Args... args) { void debug(const Args... args) {
(std::cout << ... << args) << std::endl; (std::cout << ... << args) << std::endl;
@ -24,6 +19,7 @@ namespace dms::utils {
(str << ... << args); (str << ... << args);
return str.str(); return str.str();
} }
std::vector<std::string> split(const std::string& str, const std::string& delim);
void sleep(unsigned int mseconds); void sleep(unsigned int mseconds);
std::string random_string(size_t length); std::string random_string(size_t length);
bool typeassert(dms_args args, datatypes t1 = nil, datatypes t2 = nil, datatypes t3 = nil, datatypes t4 = nil, datatypes t5 = nil, datatypes t6 = nil, datatypes t7 = nil, datatypes t8 = nil, datatypes t9 = nil, datatypes t10 = nil, datatypes t11 = nil, datatypes t12 = nil); //Type asserting is mostly an internal thing for build in methods. It's not needed for dms code! bool typeassert(dms_args args, datatypes t1 = nil, datatypes t2 = nil, datatypes t3 = nil, datatypes t4 = nil, datatypes t5 = nil, datatypes t6 = nil, datatypes t7 = nil, datatypes t8 = nil, datatypes t9 = nil, datatypes t10 = nil, datatypes t11 = nil, datatypes t12 = nil); //Type asserting is mostly an internal thing for build in methods. It's not needed for dms code!
@ -37,3 +33,4 @@ namespace dms::utils {
void trim(std::string& s); void trim(std::string& s);
void wait(); void wait();
} }
}

View File

@ -1,3 +1,4 @@
#include "pch.h"
#include "value.h" #include "value.h"
#include "dms_state.h" #include "dms_state.h"
#include "utils.h" #include "utils.h"
@ -6,6 +7,12 @@ namespace dms {
value::value() { value::value() {
// Nothing to do here! // Nothing to do here!
} }
value::value(void* cdata, std::string t)
{
type = datatypes::custom;
c = cdata;
ctype = t;
}
value::value(char const* str, datatypes t) { value::value(char const* str, datatypes t) {
type = t; type = t;
s = str; s = str;
@ -65,6 +72,8 @@ namespace dms {
break; break;
case datatypes::custom: case datatypes::custom:
// Handle this later // Handle this later
c = other.c;
ctype = other.ctype;
break; break;
case datatypes::env: case datatypes::env:
// Handle this later // Handle this later
@ -107,7 +116,8 @@ namespace dms {
b = other.b; b = other.b;
break; break;
case datatypes::custom: case datatypes::custom:
// Handle this later c = other.c;
ctype = other.ctype;
break; break;
case datatypes::env: case datatypes::env:
// Handle this later // Handle this later
@ -156,7 +166,8 @@ namespace dms {
b = other.b; b = other.b;
break; break;
case datatypes::custom: case datatypes::custom:
// Handle this later c = other.c;
ctype = other.ctype;
break; break;
case datatypes::env: case datatypes::env:
// Handle this later // Handle this later
@ -357,7 +368,13 @@ namespace dms {
return resolve(state); return resolve(state);
} }
void dms_args::push(value val) { void dms_args::push(value val) {
args.push_back(val); args.emplace_back(val);
}
dms_args::dms_args(int n) {
args.reserve(n);
}
dms_args::dms_args() {
args.reserve(5);
} }
size_t dms_args::size() { size_t dms_args::size() {
return args.size(); return args.size();
@ -415,12 +432,28 @@ namespace dms {
std::string value::toString() const { std::string value::toString() const {
return getPrintable(); return getPrintable();
} }
double value::getDouble() const
{
if (type == datatypes::int64)
return (double)i;
else if (type == datatypes::number)
return n;
else
return nan("");
}
int64_t value::getInt() const
{
if (type == datatypes::int64)
return i;
else if (type == datatypes::number)
return (int64_t)n;
else
return INT_MIN;
}
// Compile time // Compile time
void value::nuke() { void value::nuke() {
delete e; delete e;
delete c;
e = nullptr; e = nullptr;
c = nullptr;
} }
std::ostream& operator << (std::ostream& out, const value& c) { std::ostream& operator << (std::ostream& out, const value& c) {
if (c.type == string) { if (c.type == string) {
@ -491,10 +524,9 @@ namespace dms {
e = en; e = en;
type = env; type = env;
} }
void dms::value::set(dms_custom* cus) { void dms::value::set(void* cus) {
nuke(); nuke();
c = cus; c = cus;
c->_set(this);
type = custom; type = custom;
} }
void value::set() { void value::set() {

View File

@ -1,9 +1,5 @@
#pragma once #pragma once
#include <iostream> #include "pch.h"
#include <sstream>
#include <vector>
#include <unordered_map>
#include <map>
namespace dms { namespace dms {
struct dms_list; struct dms_list;
@ -41,9 +37,11 @@ namespace dms {
int64_t i=0; int64_t i=0;
std::string s; std::string s;
dms_list* e = nullptr; dms_list* e = nullptr;
dms_custom* c = nullptr; void* c = nullptr; // A custom link to void data. Must be void* for compatiablity with c-API
std::string ctype; // The type of the custom data
dms_state* state = nullptr; dms_state* state = nullptr;
value(); value();
value(void* cdata,std::string t);
value(datatypes); value(datatypes);
value(char const*,datatypes); value(char const*,datatypes);
value(std::string, datatypes); value(std::string, datatypes);
@ -79,15 +77,19 @@ namespace dms {
void set(bool bo); void set(bool bo);
void set(double num); void set(double num);
void set(dms_list* en); void set(dms_list* en);
void set(dms_custom* cus); void set(void* cus);
void set(); void set();
bool typeMatch(const value* o) const; bool typeMatch(const value* o) const;
std::string getPrintable() const; std::string getPrintable() const;
std::string toString() const; std::string toString() const;
double getDouble() const;
int64_t getInt() const;
friend std::ostream& operator << (std::ostream& out, const value& c); friend std::ostream& operator << (std::ostream& out, const value& c);
}; };
struct dms_args { struct dms_args {
dms_args(int n);
dms_args();
std::vector<value> args; std::vector<value> args;
void push(value val); void push(value val);
size_t size(); size_t size();

View File

@ -1,23 +1,3 @@
#pragma once #pragma once
#include "enviroment.h" #include "enviroment.h"
// This file converts the c++ objects into a form that c is happy with // 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 {
};
}