diff --git a/CMakeLists.txt b/CMakeLists.txt index fc8cd7f..6b9b030 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,14 +5,13 @@ add_executable(stormscript src/core/stormscript.cc src/core/set.cc src/core/errors.cc - src/core/runlibfunc.cc src/parser/parse.cc src/parser/read.cc - src/parser/modules.cc src/interpreter/globscope.cc src/interpreter/exec.cc src/stream/io.cc src/stream/stsstream.cc + src/stream/loops.cc src/values/stsdec.cc src/values/man.cc src/values/if.cc @@ -23,5 +22,5 @@ add_executable(stormscript src/classes/dectype.cc src/classes/decmethod.cc) set (StormScript_VERSION_MAJOR 0) -set (StormScript_VERSION_MINOR 4) -install(TARGETS stormscript RUNTIME DESTINATION bin/) +set (StormScript_VERSION_MINOR 5) +install(TARGETS stormscript RUNTIME DESTINATION bin/) \ No newline at end of file diff --git a/README.md b/README.md index d59f92d..7dc1f73 100755 --- a/README.md +++ b/README.md @@ -8,43 +8,6 @@ [![Get it from the Snap Store](https://snapcraft.io/static/images/badges/en/snap-store-black.svg)](https://snapcraft.io/stormscript) -## How to Build +StormScript is a programming language made in C++ -Terminal: - -To build StormScript clone this repository and cd into it. Run -``` -$ cmake CMakeLists.txt -``` -and -``` -$ make -``` -You can then add it to path or install it to /usr/bin. - -Visual Studio Code: - -Clone this repository like before and open it in Visual Studio Code. Make sure you have the CMake, C++, and python plugins installed. Press `Build:` in the bottom left or press `f5` to start debugging. - -When it builds, it should be put into a `build/` directory. - -## Layout - -Folder | Description ------- | ----------- -docs/ | contributing guide, code of conduct. etc. -src/core/ | The core StormScript files -src/stream/ | Files that deal with the console. -build-scripts/ | Scripts to be packaged with releases -src/classes/ | Files that deal with classes. -src/values/ | Files that deal with variables and functions. -tests/ | Files for testing that core functionality is not messed up. - -## Files You Should Know - -file | Description ----- | ----------- -[src/core/stormscript.cc](src/core/stormscript.cc) | This is where files are read. -[src/core/errors.cc](src/core/errors.cc) | This is where all new errors are added. -[src/parser/parse.cc](src/parser/parse.cc) | This is the parser. -[src/interpreter/exec.cc](src/interpreter/exec.cc) | This is the function that interprets functions +Read [building.md](docs/building.md) for info on how to build \ No newline at end of file diff --git a/api/python/README.md b/api/python/README.md deleted file mode 100644 index 56312de..0000000 --- a/api/python/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# StormScript Python API - -## What is this? -The StormScript Python API allows you to create libraries for StormScript in Python. - -File | Contents ------|------- -stormscript/ | This is the python module for the API -getname.py | This file grabs the name of the library, which should be specified as an argument to `stormscript -l`. -reader.cc | This C++ file encodes the command and variable data it recieves into JSON. diff --git a/api/python/build.sh b/api/python/build.sh deleted file mode 100644 index de1b3bb..0000000 --- a/api/python/build.sh +++ /dev/null @@ -1,13 +0,0 @@ -if [ -f ./*.stslib ]; then - if [ ! -e ~/.stormscript ]; then - mkdir ~/.stormscript - echo 'export PATH=$PATH:'$HOME'/.stormscript' >> ~/.bashrc - cp -r stormscript/ ~/.stormscript - fi - cp ./*.py ~/.stormscript - cp ./*.stslib ~/.stormscript - rm build.sh -else - echo 'Error: not a library' - rm build.sh -fi \ No newline at end of file diff --git a/api/python/getname.py b/api/python/getname.py deleted file mode 100644 index 14a8811..0000000 --- a/api/python/getname.py +++ /dev/null @@ -1,9 +0,0 @@ -from sys import argv -import re -import os -x = "" -with open("reader.cc", 'r') as f: - x = f.read() - x=x.replace("test", argv[1]) -with open("reader.cc", 'w') as f: - f.write(x) \ No newline at end of file diff --git a/api/python/reader.cc b/api/python/reader.cc deleted file mode 100644 index da2375d..0000000 --- a/api/python/reader.cc +++ /dev/null @@ -1,63 +0,0 @@ -#include - -using std::string; -using std::cout; -using std::endl; - -int main(int argc, char const *argv[]) -{ - string cmd = "test.py {\\'command\\':"; - if (argc>2) { cmd+="{"; } - string args[argc]; - for (int i = 1; i0) { - if (args[i-1].back()!=':') { - cmd+="\\'"; - } - else{ - args[i] = "\\\""+val+"\\\""; - val = args[i]; - } - } - else { - cmd+="\\'"; - } - cmd+=val; - - if (i>0) { - if (args[i-1].back()==':') { - cmd+="}"; - } - else{ - cmd+=((args[i].back()==':') ? "\\':" : "\\'"); - } - if (i==argc-2){ - cmd+="]"; - } - else if (args[i-1].back()==':') { - cmd+=","; - } - } - else if (argc>i+2){ - cmd+="\\':["; - } - else{ - cmd+="\\'"; - } - } - if (argc>2) { cmd+="}"; } - cmd += "}"; - - system(cmd.c_str()); - - return 0; -} diff --git a/api/python/stormscript/__init__.py b/api/python/stormscript/__init__.py deleted file mode 100644 index 9b4303d..0000000 --- a/api/python/stormscript/__init__.py +++ /dev/null @@ -1,8 +0,0 @@ -import sys -import ast - -def getAll(): - return ast.literal_eval(sys.argv[1])["command"] - -def getVals(name): - return getAll()[name] \ No newline at end of file diff --git a/api/python/stormscript/__init__.pyc b/api/python/stormscript/__init__.pyc deleted file mode 100644 index abddbe4..0000000 Binary files a/api/python/stormscript/__init__.pyc and /dev/null differ diff --git a/azure-pipelines.yml b/azure-pipelines.yml index b6d51ff..8c1094d 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -13,5 +13,8 @@ steps: - script: | cmake CMakeLists.txt; make; + mkdir build; + mv stormscript build; + cd scripts; ./runtests.sh displayName: 'make' diff --git a/build-scripts/install.sh b/build-scripts/install.sh index 2649509..87faa08 100755 --- a/build-scripts/install.sh +++ b/build-scripts/install.sh @@ -1,17 +1,7 @@ #!/bin/bash -cmake CMakeLists.txt +cmake CMakeLists.txt -DCMAKE_CXX_COMPILER:STRING="g++" make sudo cp stormscript /usr/bin -g++ src/libraries/system/reader.cc -o src/libraries/system/system.stslib -g++ src/libraries/random/reader.cc -o src/libraries/random/random.stslib -if [ ! -e ~/.stormscript ]; then - mkdir ~/.stormscript - echo 'export PATH=$PATH:'$HOME'/.stormscript' >> ~/.bashrc -fi - -cp src/libraries/*/*.stslib ~/.stormscript -cp src/libraries/*/*.py ~/.stormscript -cp -r api/python/stormscript ~/.stormscript stormscript finished.sts exec bash \ No newline at end of file diff --git a/build-scripts/uninstall.sh b/build-scripts/uninstall.sh index e887717..b265440 100755 --- a/build-scripts/uninstall.sh +++ b/build-scripts/uninstall.sh @@ -1,4 +1,3 @@ #!/bin/bash sudo rm /usr/bin/stormscript -sudo rm -rf $HOME/.stormscript echo StormScript Removed \ No newline at end of file diff --git a/docs/building.md b/docs/building.md new file mode 100644 index 0000000..e15c98a --- /dev/null +++ b/docs/building.md @@ -0,0 +1,33 @@ +# Building StormScript + +Make a directory called build + +You must have gcc installed (MinGW for Windows) and CMake + +## Linux + +Terminal: + +To build StormScript clone this repository and cd into it. Run +``` +$ cmake CMakeLists.txt +``` +and +``` +$ make +``` +You can then add it to path or install it to /usr/bin. + +## Windows + +Make sure you have MinGW-make installed + +Run CMake GUI, and configure for MinGW-make + +output should be a MakeFile, run mingw-make in that directory. + +## Visual Studio Code + +Clone this repository like before and open it in Visual Studio Code. Make sure you have the CMake, C++, and python plugins installed. Press `Build:` in the bottom left or press `f5` to start debugging. + +When it builds, it should be put into a `build/` directory. \ No newline at end of file diff --git a/docs/changelogs/changelog-v0.5.0.md b/docs/changelogs/changelog-v0.5.0.md new file mode 100644 index 0000000..5f28ab3 --- /dev/null +++ b/docs/changelogs/changelog-v0.5.0.md @@ -0,0 +1,12 @@ +# StormScript v0.5.0 "Eggplant" + +## What's New +* `while` can be used to make while loops +* New Escape Characters, `\t` and `\\` +* Windows version +* Modules have been removed due to compatibility issues +* Libraries have been removed due to compatibility issues +* New scripts folder for build scripts + +## What's Fixed +* `runtests.sh` will now exit with code 1 on failure \ No newline at end of file diff --git a/docs/readme.md b/docs/readme.md index 5792bb0..a4396ad 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -1,13 +1,5 @@ # About -## Table of Contents -* [Why is this special?](#why-is-this-special) -* [How to Build](#how-to-build) -* [Layout](#layout) -* [Files You Should Know](#files-you-should-know) - -## Why is this special? - StormScript is important not because it presents 1 or 2 revolutionary ideas that change your usual workflow, but because it changes almost everything about common programming syntax to make it easier to read and write. **This may seem more like a problem at first,** but I believe that StormScript changes programming syntax *for the better.* Here are a few examples: 1. Keywords @@ -33,7 +25,7 @@ do{ f => x: "hi"; } ``` -Another example of this is the `|` symbol, which is usually used as a separator. In StormScript, the `|` symbol tells the intepreter to find a property. For example: +Another example of this is the `|` symbol, which is usually used as a separator. In StormScript, the `|` symbol tells the interpreter to find a property. For example: ``` type person{ @@ -54,4 +46,4 @@ do{ } ``` -In StormScript, the `is` keyword replaces the `==` symbol and `not` replaces the `!=` symbol. \ No newline at end of file +In StormScript, the `is` keyword replaces the `==` symbol and `not` replaces the `!=` symbol. \ No newline at end of file diff --git a/example/example.sts b/example/example.sts index fec672c..b0fd50f 100755 --- a/example/example.sts +++ b/example/example.sts @@ -1,12 +1,8 @@ do{ - x: 4; - printl "Hello, World!"; - - if x is 3 { - printl "hi"; - }else if x is 4 { - printl "hi there"; - }else { - printl "bye"; + x: 3; + y: 10; + while x not y { + x+: 1; + printl x; } } \ No newline at end of file diff --git a/packagerelease.sh b/scripts/packagerelease.sh similarity index 94% rename from packagerelease.sh rename to scripts/packagerelease.sh index 34c2c81..93d0eee 100755 --- a/packagerelease.sh +++ b/scripts/packagerelease.sh @@ -1,11 +1,12 @@ #!/bin/bash +cd .. rm -r release/* echo "What is the version number (Formatted M.m.p):" read vnum echo "Packaging stormscript v$vnum for release." -cmake CMakeLists.txt +cmake CMakeLists.txt -DCMAKE_CXX_COMPILER:STRING="g++" make install stormscript build/stormscript rm stormscript @@ -42,7 +43,6 @@ cd stormscript_v$vnum cp ../../CMakeLists.txt . cp -r ../../src . -cp -r ../../api . cp ../../build-scripts/* . echo "Compressing folder stormscript_v$vnum." diff --git a/runtests.sh b/scripts/runtests.sh similarity index 96% rename from runtests.sh rename to scripts/runtests.sh index 8cf76ed..c7edf7c 100755 --- a/runtests.sh +++ b/scripts/runtests.sh @@ -1,4 +1,5 @@ #!/bin/bash +cd .. cmake CMakeLists.txt make install stormscript build/stormscript @@ -29,7 +30,7 @@ for i in $( ls | grep .sts ); do else echo Test $B failed: echo expected$'\n'$(echo `cat outputs/$i.txt`)$'\n'got$'\n'$(echo `../build/stormscript $i`) - break + exit 1 fi B=$(($B+1)) diff --git a/writenewouts.sh b/scripts/writenewouts.sh similarity index 97% rename from writenewouts.sh rename to scripts/writenewouts.sh index b8b5bf8..da65b6b 100755 --- a/writenewouts.sh +++ b/scripts/writenewouts.sh @@ -1,4 +1,5 @@ #!/bin/bash +cd .. cmake CMakeLists.txt make install stormscript build/stormscript diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 8d5bab6..02df829 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,5 +1,5 @@ name: stormscript # you probably want to 'snapcraft register ' -version: 'v0.4.1' # just for humans, typically '1.2+git' or '1.3.2' +version: 'v0.5.0' # just for humans, typically '1.2+git' or '1.3.2' summary: StormScript is an easy to use, open-source scripting language # 79 char long summary description: | StormScript is an open source scripting language. StormScript was created on the belief that a good scripting language can be both powerful and easily readable and learnable. diff --git a/src/core/runlibfunc.cc b/src/core/runlibfunc.cc deleted file mode 100644 index a4c66cf..0000000 --- a/src/core/runlibfunc.cc +++ /dev/null @@ -1,54 +0,0 @@ -#include "../include/stormscript.h" - -string sts::runlibfunc(string name, int *line, std::vector vars) { - int y = *line; - string cmd1; - string cmd0 = "echo `"+name; - if (PLATFORM=="Windows"){ - cmd1 = "stslib.exe "; - } - else{ - cmd1 = ".stslib "; - } - cmd0+=cmd1.c_str(); - cmd0+=prs[y].c_str(); - y++; - - if (prs[y]=="=>") { - y++; - - while (prs[y]!=";") { - cmd0+=" "; - if (prs[y].back()!=':') { - cmd0+="\'"; - cmd0+=getval(vars, &y).val; - cmd0+="\'"; - } - else { - cmd0+=prs[y].c_str(); - } - y++; - } - y--; - } - cmd0 += "` >> output.log"; - system(cmd0.c_str()); - - - std::ifstream command; - command.open("./output.log"); - - string output; - - while (!command.eof()) { - output.push_back(command.get()); - } - - command.close(); - system("rm output.log"); - output.pop_back(); - output.pop_back(); - - *line = y; - return output; -} \ No newline at end of file diff --git a/src/core/stormscript.cc b/src/core/stormscript.cc index 52bbb5b..efc5152 100755 --- a/src/core/stormscript.cc +++ b/src/core/stormscript.cc @@ -16,42 +16,17 @@ int main(int argc, char *argv[]) { if (argc != 1) { if (string(argv[1])=="--version"){ - cout << "StormScript v0.4.1 \"Dragon Fruit\"\n"; + cout << "StormScript v0.5.0 \"Eggplant\"\n"; } else if ((string(argv[1])=="--help") || (string(argv[1])=="-h")) { cout << "Usage: stormscript [file|options]\n"; cout << "StormScript is an open source scripting language for Linux.\n\n"; cout << " -h, --help: display help\n"; cout << " --version: show version\n"; - cout << " -l, --library [name]: initialize library\n"; - cout << " -bl, --build-library: builds library and adds it to the .stormscript folder\n\n"; system("stormscript --version"); cout << "git: https://github.com/stormprograms/StormScript\n"; cout << "For documentation, go to https://stormprograms.com/stormscript/docs\n"; } - else if ((string(argv[1])=="--library") || (string(argv[1])=="-l")) { // check for library - if ((argv[2]!=NULL)){ - string name = string(argv[2]); - cout << "Creating library '" << name << "'...\n"; - system("wget https://raw.githubusercontent.com/stormprograms/StormScript/master/api/python/reader.cc"); - system("wget https://raw.githubusercontent.com/stormprograms/StormScript/master/api/python/getname.py"); - system("mkdir stormscript && cd stormscript && wget https://raw.githubusercontent.com/stormprograms/StormScript/master/api/python/stormscript/__init__.py"); - string cmd = "python getname.py " + name + " && rm getname.py"; - system(cmd.c_str()); - string cmd2 = "touch "+name+".py && echo '#!/usr/bin/python\nimport stormscript' > "+name+".py && chmod u+x "+name+".py"; - system(cmd2.c_str()); - string command = "g++ reader.cc -o " + name + ".stslib"; - system(command.c_str()); - } - else { - script.error(13, ""); - } - } - else if ((string(argv[1])=="-bl") || (string(argv[1])=="--build-library")) { - cout << "Building...\n"; - system("wget https://raw.githubusercontent.com/stormprograms/StormScript/master/api/python/build.sh"); - system("sh build.sh"); - } else { script.read(argv, argc, argv[1]); } diff --git a/src/include/core.h b/src/include/core.h index 4ff601d..7a380bd 100644 --- a/src/include/core.h +++ b/src/include/core.h @@ -14,7 +14,6 @@ class sts int lineon; //line the parser is on unsigned int sizeoff = 0; //size of the program std::vector functions; //functions - std::vector names; //imported libraries std::vector prg; //unparsed program std::vector prs; //parsed program std::vector globvars; //global variables @@ -33,10 +32,9 @@ class sts stsvars in(int line); std::vector parse(std::vector prg); void interp(string fname, int psize, char *argv[], int argc); - void addmodule(int *ln); bool compare(int *y, std::vector current_vars); void ifs(int *line, int *endr, std::vector vars); - void exec(int *x, int function, std::vector *pclasstypes, std::vector objects); + void exec(int *x, int function, std::vector *pclasstypes, std::vector objects, std::vector *variables); void runfunc(std::vector * pvars, std::vector *classtypes, int * ln); void set(string command, string setto, int x); // set command string runlibfunc(string name, int *line, std::vector vars); // run library function @@ -44,4 +42,6 @@ class sts stsvars math(int *y, std::vector vars); }; +std::vector whileloop(sts *script, std::vector variables, int y); + #endif \ No newline at end of file diff --git a/src/interpreter/exec.cc b/src/interpreter/exec.cc index b06862a..45ac364 100644 --- a/src/interpreter/exec.cc +++ b/src/interpreter/exec.cc @@ -1,11 +1,12 @@ #include "../include/stormscript.h" -void sts::exec(int *x, int function, std::vector *pclasstypes, std::vector objects) { // how each command is executed +void sts::exec(int *x, int function, std::vector *pclasstypes, std::vector objects, std::vector *variables) { // how each command is executed std::vector vars; std::vector classtypes; std::vector originalnames; stsclasstype ct; - vars = globvars; + vars = *variables; + vars.insert(vars.end(), globvars.begin(), globvars.end()); int y = ((prs[*x]=="do") ? *x+1 : *x); bool looped=0; int endreq = 1; @@ -52,13 +53,7 @@ void sts::exec(int *x, int function, std::vector *pclasstypes, std continue; } prs = parse(prg); - - if (prs[y]=="lib") { - y++; - names.push_back(prs[y]); - y++; - } - else if (prs[y]=="set") { + if (prs[y]=="set") { y++; set(prs[y], prs[y+2], y); } @@ -87,14 +82,45 @@ void sts::exec(int *x, int function, std::vector *pclasstypes, std vars.back().val = std::to_string(vars[vars.size()-2].length); vars.back().type = 'i'; } - else if ((prs[y]=="if")) { + else if (prs[y] == "while") { + whileloop(this, vars, y); + y++; + + // this will iterate over y until it is the end of the while scope + + int e = 1; + while (e != 0) { + if ((prs[y] == "if") || (prs[y] == "while")) + e++; + else if (prs[y] == "else") { + e++; + if (prs[y+1] == "if") + y++; + } + else if (prs[y] == "}") + e--; + y++; + } + } + else if (prs[y]=="if") { endreq+=1; ifs(&y, &endreq, vars); if (prs[y]!="else") y--; } else if (prs[y] == "else") { - while (prs[y] != "}") { + y++; + int e = 1; + while (e != 0) { + if ((prs[y] == "if") || (prs[y] == "while")) + e++; + else if (prs[y] == "else") { + e++; + if (prs[y+1] == "if") + y++; + } + else if (prs[y] == "}") + e--; y++; } } @@ -134,6 +160,8 @@ void sts::exec(int *x, int function, std::vector *pclasstypes, std } } } + for (int i = 0; isize(); i++) + variables->at(i) = vars[i]; endreq--; if (endreq==0) diff --git a/src/interpreter/globscope.cc b/src/interpreter/globscope.cc index 0ac762c..411d8bf 100644 --- a/src/interpreter/globscope.cc +++ b/src/interpreter/globscope.cc @@ -14,23 +14,12 @@ void sts::interp(string fname,int psize, char *argv[], int argc){ } for (int x = 0; x({})); } else if ((prs[x]!=";") && (prs[x][0]!='\0')){ error(1, prs[x]); diff --git a/src/libraries/helloworld/helloworld.stslib b/src/libraries/helloworld/helloworld.stslib deleted file mode 100755 index 06a3dd4..0000000 --- a/src/libraries/helloworld/helloworld.stslib +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env stormscript -lib system; - -do{ - cmd: arg[1]; - - if cmd is "out"{ - printl "Hello, World!"; - }else{ - printl "helloworld library doesn't have command '", cmd, "'."; - } -} diff --git a/src/libraries/random/randomsts.py b/src/libraries/random/randomsts.py deleted file mode 100755 index 4d9c641..0000000 --- a/src/libraries/random/randomsts.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/python -from stormscript import getAll, getVals -import random - -commands = getAll() - -if 'gen' in commands: - vals = getVals('gen') - fr = int(vals[0]["from"]) - to = int(vals[1]["to"]) - print random.randrange(fr, to) \ No newline at end of file diff --git a/src/libraries/random/reader.cc b/src/libraries/random/reader.cc deleted file mode 100644 index af06184..0000000 --- a/src/libraries/random/reader.cc +++ /dev/null @@ -1,63 +0,0 @@ -#include - -using std::string; -using std::cout; -using std::endl; - -int main(int argc, char const *argv[]) -{ - string cmd = "randomsts.py {\\'command\\':"; - if (argc>2) { cmd+="{"; } - string args[argc]; - for (int i = 1; i0) { - if (args[i-1].back()!=':') { - cmd+="\\'"; - } - else{ - args[i] = "\\\""+val+"\\\""; - val = args[i]; - } - } - else { - cmd+="\\'"; - } - cmd+=val; - - if (i>0) { - if (args[i-1].back()==':') { - cmd+="}"; - } - else{ - cmd+=((args[i].back()==':') ? "\\':" : "\\'"); - } - if (i==argc-2){ - cmd+="]"; - } - else if (args[i-1].back()==':') { - cmd+=","; - } - } - else if (argc>i+2){ - cmd+="\\':["; - } - else{ - cmd+="\\'"; - } - } - if (argc>2) { cmd+="}"; } - cmd += "}"; - - system(cmd.c_str()); - - return 0; -} diff --git a/src/libraries/system/reader.cc b/src/libraries/system/reader.cc deleted file mode 100644 index b5f7067..0000000 --- a/src/libraries/system/reader.cc +++ /dev/null @@ -1,63 +0,0 @@ -#include - -using std::string; -using std::cout; -using std::endl; - -int main(int argc, char const *argv[]) -{ - string cmd = "system.py {\\'command\\':"; - if (argc>2) { cmd+="{"; } - string args[argc]; - for (int i = 1; i0) { - if (args[i-1].back()!=':') { - cmd+="\\'"; - } - else{ - args[i] = "\\\""+val+"\\\""; - val = args[i]; - } - } - else { - cmd+="\\'"; - } - cmd+=val; - - if (i>0) { - if (args[i-1].back()==':') { - cmd+="}"; - } - else{ - cmd+=((args[i].back()==':') ? "\\':" : "\\'"); - } - if (i==argc-2){ - cmd+="]"; - } - else if (args[i-1].back()==':') { - cmd+=","; - } - } - else if (argc>i+2){ - cmd+="\\':["; - } - else{ - cmd+="\\'"; - } - } - if (argc>2) { cmd+="}"; } - cmd += "}"; - - system(cmd.c_str()); - - return 0; -} diff --git a/src/libraries/system/system.py b/src/libraries/system/system.py deleted file mode 100755 index 3dc3bdb..0000000 --- a/src/libraries/system/system.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/python -from stormscript import getAll, getVals -import sys -import os - -cmds = getAll() - -if "setTempVar" in cmds: # appends path for this session - vals = getVals("setTempVar") - if "PATH" in vals[0]: - sys.path.append(vals[0]["PATH"]) - -if "setVar" in cmds: # adds to bashrc so that path is always appended - vals = getVals("setVar") - if "PATH" in vals[0]: - cmd = "echo 'export PATH="+'$PATH ' + vals[0]['PATH'] + "' >> " + os.path.expanduser("~")+"/.bashrc" - os.system(cmd) -if "stdout" in cmds: - vals = getVals("stdout") - if "message" in vals[0]: - sys.stdout.write(vals[0]['message']) -if "stderr" in cmds: - vals = getVals("stderr") - if "message" in vals[0]: - sys.stderr.write(vals[0]['message']) \ No newline at end of file diff --git a/src/parser/modules.cc b/src/parser/modules.cc deleted file mode 100644 index 1a3b017..0000000 --- a/src/parser/modules.cc +++ /dev/null @@ -1,28 +0,0 @@ -#include "../include/stormscript.h" - -void sts::addmodule(int *ln) { - char **args; - string filename = prs[*ln]+".sts"; - sts module; - - module.read(args,1, filename); - int ls = 5; - if (module.prs[2]=="=>") { - while (module.prs[ls]!="{") - ls++; - ls+=2; - } - - for (int i = 0; i=0; i--) - prs.insert(prs.begin()+*ln+2, module.prs[i]); -} \ No newline at end of file diff --git a/src/stream/io.cc b/src/stream/io.cc index 97e75d5..43ce531 100644 --- a/src/stream/io.cc +++ b/src/stream/io.cc @@ -6,9 +6,19 @@ void sts::print(int line, int *y, std::vector current_vars){ //handles string value = v.val; for (int x = 0; x<=value.size(); x++) { - if ((value[x]=='\\') && (value[x+1]=='n')){ - value.pop_back(); - value[x]='\n'; + if (value[x] == '\\') { + if (value[x+1]=='n') { + value.erase(value.begin() + x); + value[x]='\n'; + } + else if (value[x+1] == '\\') { + value.erase(value.begin() + x); + value[x]='\\'; + } + else if (value[x+1] == 't') { + value.erase(value.begin() + x); + value[x]='\t'; + } } } diff --git a/src/stream/loops.cc b/src/stream/loops.cc new file mode 100644 index 0000000..04b725b --- /dev/null +++ b/src/stream/loops.cc @@ -0,0 +1,12 @@ +#include "../include/stormscript.h" + +std::vector whileloop(sts *script, std::vector variables, int y) { + std::vector prs = script->prs; + y++; + while (condition(script, new int(y), variables)) { + script->exec(new int(y+3), -1, {}, {}, &variables); + } + + + return variables; +} \ No newline at end of file diff --git a/src/values/getvals.cc b/src/values/getvals.cc index d25066f..124858d 100644 --- a/src/values/getvals.cc +++ b/src/values/getvals.cc @@ -128,17 +128,6 @@ stsvars sts::getval(std::vector vars, int *line) { v = functions[x].value; } } - if (names.size()!=0){ - for (int z = 0; z * pvars, std::vector *cla } } - // find in libfuncs - if (names.size()!=0){ - for (int z = 0; z<=names.size()-1 && names[z-1]!=prs[y]; z++){ - if (names[z]==prs[y]) { - y++; - runlibfunc(names[z], &y, vars); - - *ln = y; - *classtypes = ct; - *pvars = vars; - - return true; - } - } - } - if (functions.size()>0){ bool isfunc = false; diff --git a/src/values/runfunc.cc b/src/values/runfunc.cc index b65c58d..17515da 100644 --- a/src/values/runfunc.cc +++ b/src/values/runfunc.cc @@ -17,7 +17,7 @@ void sts::runfunc(std::vector * pvars, std::vector *class functions[z].args[i] = argval; delete name; } - exec(new int(functions[z].linestarted), z, {}, {}); + exec(new int(functions[z].linestarted), z, {}, {}, new std::vector({})); } else { std::vector o; @@ -31,7 +31,7 @@ void sts::runfunc(std::vector * pvars, std::vector *class } } - exec(new int(functions[z].linestarted), z, classtypes, o); + exec(new int(functions[z].linestarted), z, classtypes, o, new std::vector({})); } *ln = y; diff --git a/tests/outputs/whiletest.sts.txt b/tests/outputs/whiletest.sts.txt new file mode 100644 index 0000000..dd3f6eb --- /dev/null +++ b/tests/outputs/whiletest.sts.txt @@ -0,0 +1 @@ +4 5 6 7 8 9 10 diff --git a/tests/whiletest.sts b/tests/whiletest.sts new file mode 100644 index 0000000..b0fd50f --- /dev/null +++ b/tests/whiletest.sts @@ -0,0 +1,8 @@ +do{ + x: 3; + y: 10; + while x not y { + x+: 1; + printl x; + } +} \ No newline at end of file