From 2a0907fc4b34819e785b76caf4c164e7e6aed57b Mon Sep 17 00:00:00 2001 From: storm246 Date: Wed, 13 Feb 2019 10:33:09 -0500 Subject: [PATCH 01/33] stormscript can now read files --- CMakeLists.txt | 3 ++- docs/changelogs/changelog-v0.6.0.md | 4 ++++ example/example.sts | 8 ++------ example/example.txt | 1 + snap/snapcraft.yaml | 2 +- src/core/stormscript.cc | 2 +- src/include/core.h | 1 + src/stream/files.cc | 26 ++++++++++++++++++++++++++ src/values/getvals.cc | 7 +++++++ tests/etc/readtest.txt | 1 + tests/outputs/etc.txt | 1 + tests/outputs/modtest.sts.txt | 1 - tests/outputs/readtest.sts.txt | 1 + tests/readtest.sts | 4 ++++ 14 files changed, 52 insertions(+), 10 deletions(-) create mode 100644 docs/changelogs/changelog-v0.6.0.md create mode 100644 example/example.txt create mode 100644 src/stream/files.cc create mode 100644 tests/etc/readtest.txt create mode 100644 tests/outputs/etc.txt delete mode 100644 tests/outputs/modtest.sts.txt create mode 100644 tests/outputs/readtest.sts.txt create mode 100644 tests/readtest.sts diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b9b030..c977e94 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ add_executable(stormscript src/stream/io.cc src/stream/stsstream.cc src/stream/loops.cc + src/stream/files.cc src/values/stsdec.cc src/values/man.cc src/values/if.cc @@ -22,5 +23,5 @@ add_executable(stormscript src/classes/dectype.cc src/classes/decmethod.cc) set (StormScript_VERSION_MAJOR 0) -set (StormScript_VERSION_MINOR 5) +set (StormScript_VERSION_MINOR 6) install(TARGETS stormscript RUNTIME DESTINATION bin/) \ No newline at end of file diff --git a/docs/changelogs/changelog-v0.6.0.md b/docs/changelogs/changelog-v0.6.0.md new file mode 100644 index 0000000..f1c3188 --- /dev/null +++ b/docs/changelogs/changelog-v0.6.0.md @@ -0,0 +1,4 @@ +# StormScript v0.6.0 "Fig" + +## What's new +* StormScript can now read and write to files \ No newline at end of file diff --git a/example/example.sts b/example/example.sts index b0fd50f..14a6994 100755 --- a/example/example.sts +++ b/example/example.sts @@ -1,8 +1,4 @@ do{ - x: 3; - y: 10; - while x not y { - x+: 1; - printl x; - } + x: read "example.txt"; + printl x; } \ No newline at end of file diff --git a/example/example.txt b/example/example.txt new file mode 100644 index 0000000..95d09f2 --- /dev/null +++ b/example/example.txt @@ -0,0 +1 @@ +hello world \ No newline at end of file diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 02df829..3e81e79 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,5 +1,5 @@ name: stormscript # you probably want to 'snapcraft register ' -version: 'v0.5.0' # just for humans, typically '1.2+git' or '1.3.2' +version: 'v0.6.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/stormscript.cc b/src/core/stormscript.cc index efc5152..e7dbcba 100755 --- a/src/core/stormscript.cc +++ b/src/core/stormscript.cc @@ -16,7 +16,7 @@ int main(int argc, char *argv[]) { if (argc != 1) { if (string(argv[1])=="--version"){ - cout << "StormScript v0.5.0 \"Eggplant\"\n"; + cout << "StormScript v0.6.0 \"Fig\"\n"; } else if ((string(argv[1])=="--help") || (string(argv[1])=="-h")) { cout << "Usage: stormscript [file|options]\n"; diff --git a/src/include/core.h b/src/include/core.h index 7a380bd..8eac00f 100644 --- a/src/include/core.h +++ b/src/include/core.h @@ -40,6 +40,7 @@ class sts string runlibfunc(string name, int *line, std::vector vars); // run library function bool valchange(std::vector * pvars, std::vector *classtypes, int * ln); stsvars math(int *y, std::vector vars); + void readfile(int y, stsvars *v); // file reading operations }; std::vector whileloop(sts *script, std::vector variables, int y); diff --git a/src/stream/files.cc b/src/stream/files.cc new file mode 100644 index 0000000..c6f8a88 --- /dev/null +++ b/src/stream/files.cc @@ -0,0 +1,26 @@ +#include "../include/core.h" + +void sts::readfile(int y, stsvars *v) { + v->type = 's'; + v->glob = false; + + std::ifstream file; + string contents; + string name = striplit(prs[y]); + + file.open(name); + + if (file.fail()) + error(11, name); + + char c = file.get(); + + while (file.good()) { + contents += c; + c = file.get(); + } + + file.close(); + + v->val = contents; +} \ No newline at end of file diff --git a/src/values/getvals.cc b/src/values/getvals.cc index 124858d..72a1381 100644 --- a/src/values/getvals.cc +++ b/src/values/getvals.cc @@ -65,6 +65,13 @@ stsvars sts::getval(std::vector vars, int *line) { } } + else if (prs[y] == "read") { + y++; + readfile(y, &v); + *line = y; + return v; + } + else if (isint(prs[y])) { v.type = 'i'; v.val = prs[y]; diff --git a/tests/etc/readtest.txt b/tests/etc/readtest.txt new file mode 100644 index 0000000..95d09f2 --- /dev/null +++ b/tests/etc/readtest.txt @@ -0,0 +1 @@ +hello world \ No newline at end of file diff --git a/tests/outputs/etc.txt b/tests/outputs/etc.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/outputs/etc.txt @@ -0,0 +1 @@ + diff --git a/tests/outputs/modtest.sts.txt b/tests/outputs/modtest.sts.txt deleted file mode 100644 index 677154a..0000000 --- a/tests/outputs/modtest.sts.txt +++ /dev/null @@ -1 +0,0 @@ -3 6 diff --git a/tests/outputs/readtest.sts.txt b/tests/outputs/readtest.sts.txt new file mode 100644 index 0000000..3b18e51 --- /dev/null +++ b/tests/outputs/readtest.sts.txt @@ -0,0 +1 @@ +hello world diff --git a/tests/readtest.sts b/tests/readtest.sts new file mode 100644 index 0000000..50a6582 --- /dev/null +++ b/tests/readtest.sts @@ -0,0 +1,4 @@ +do{ + x: read "etc/readtest.txt"; + printl x; +} \ No newline at end of file From 7b8c0d479ec8aba81a2670991ebc3121f76bc37c Mon Sep 17 00:00:00 2001 From: storm246 Date: Wed, 13 Feb 2019 16:32:03 -0500 Subject: [PATCH 02/33] stormscript can now write files --- example/example.sts | 5 +++-- example/example.txt | 1 - src/include/core.h | 1 + src/interpreter/exec.cc | 5 +++++ src/stream/files.cc | 8 ++++++++ tests/example.txt | 0 tests/outputs/example.txt.txt | 1 + tests/outputs/writetest.sts.txt | 1 + tests/writetest.sts | 5 +++++ 9 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 tests/example.txt create mode 100644 tests/outputs/example.txt.txt create mode 100644 tests/outputs/writetest.sts.txt create mode 100644 tests/writetest.sts diff --git a/example/example.sts b/example/example.sts index 14a6994..9f1f4e1 100755 --- a/example/example.sts +++ b/example/example.sts @@ -1,4 +1,5 @@ do{ - x: read "example.txt"; - printl x; + write "example.txt" "hello, world"; + printl read "example.txt"; + write "example.txt" ""; } \ No newline at end of file diff --git a/example/example.txt b/example/example.txt index 95d09f2..e69de29 100644 --- a/example/example.txt +++ b/example/example.txt @@ -1 +0,0 @@ -hello world \ No newline at end of file diff --git a/src/include/core.h b/src/include/core.h index 8eac00f..d58c5e5 100644 --- a/src/include/core.h +++ b/src/include/core.h @@ -41,6 +41,7 @@ class sts bool valchange(std::vector * pvars, std::vector *classtypes, int * ln); stsvars math(int *y, std::vector vars); void readfile(int y, stsvars *v); // file reading operations + void writefile(int y); // file writing operations }; std::vector whileloop(sts *script, std::vector variables, int y); diff --git a/src/interpreter/exec.cc b/src/interpreter/exec.cc index 45ac364..ab8eb89 100644 --- a/src/interpreter/exec.cc +++ b/src/interpreter/exec.cc @@ -69,6 +69,11 @@ void sts::exec(int *x, int function, std::vector *pclasstypes, std if (l) cout << "\n"; } + else if (prs[y]=="write") { + y++; + writefile(y); + y+= 2; + } else if (prs[y]=="exit") { exit(0); } diff --git a/src/stream/files.cc b/src/stream/files.cc index c6f8a88..a01e67d 100644 --- a/src/stream/files.cc +++ b/src/stream/files.cc @@ -23,4 +23,12 @@ void sts::readfile(int y, stsvars *v) { file.close(); v->val = contents; +} + +void sts::writefile(int y) { + std::ofstream file; + string name = striplit(prs[y]); + file.open(name); + file.write(striplit(prs[y+1]).c_str(), striplit(prs[y+1]).size()); + file.close(); } \ No newline at end of file diff --git a/tests/example.txt b/tests/example.txt new file mode 100644 index 0000000..e69de29 diff --git a/tests/outputs/example.txt.txt b/tests/outputs/example.txt.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/outputs/example.txt.txt @@ -0,0 +1 @@ + diff --git a/tests/outputs/writetest.sts.txt b/tests/outputs/writetest.sts.txt new file mode 100644 index 0000000..4b5fa63 --- /dev/null +++ b/tests/outputs/writetest.sts.txt @@ -0,0 +1 @@ +hello, world diff --git a/tests/writetest.sts b/tests/writetest.sts new file mode 100644 index 0000000..9f1f4e1 --- /dev/null +++ b/tests/writetest.sts @@ -0,0 +1,5 @@ +do{ + write "example.txt" "hello, world"; + printl read "example.txt"; + write "example.txt" ""; +} \ No newline at end of file From 81fa3191d3786f519412dfdc4e32e692a99046b6 Mon Sep 17 00:00:00 2001 From: storm246 Date: Wed, 13 Feb 2019 16:38:56 -0500 Subject: [PATCH 03/33] fixed bad directory for example.txt --- tests/{ => etc}/example.txt | 0 tests/outputs/example.txt.txt | 1 - tests/writetest.sts | 8 ++++---- 3 files changed, 4 insertions(+), 5 deletions(-) rename tests/{ => etc}/example.txt (100%) delete mode 100644 tests/outputs/example.txt.txt diff --git a/tests/example.txt b/tests/etc/example.txt similarity index 100% rename from tests/example.txt rename to tests/etc/example.txt diff --git a/tests/outputs/example.txt.txt b/tests/outputs/example.txt.txt deleted file mode 100644 index 8b13789..0000000 --- a/tests/outputs/example.txt.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/tests/writetest.sts b/tests/writetest.sts index 9f1f4e1..3120904 100644 --- a/tests/writetest.sts +++ b/tests/writetest.sts @@ -1,5 +1,5 @@ do{ - write "example.txt" "hello, world"; - printl read "example.txt"; - write "example.txt" ""; -} \ No newline at end of file + write "etc/example.txt" "hello, world"; + printl read "etc/example.txt"; + write "etc/example.txt" ""; +} \ No newline at end of file From 16cdd6efa8b02d0e4733f7f22a28f38b741292f4 Mon Sep 17 00:00:00 2001 From: storm246 Date: Sat, 16 Feb 2019 15:54:10 -0500 Subject: [PATCH 04/33] fixed if statements in functions --- docs/changelogs/changelog-v0.6.0.md | 5 ++++- example/example.sts | 14 +++++++++++--- src/interpreter/globscope.cc | 16 +++++++++++++--- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/docs/changelogs/changelog-v0.6.0.md b/docs/changelogs/changelog-v0.6.0.md index f1c3188..879d7e1 100644 --- a/docs/changelogs/changelog-v0.6.0.md +++ b/docs/changelogs/changelog-v0.6.0.md @@ -1,4 +1,7 @@ # StormScript v0.6.0 "Fig" ## What's new -* StormScript can now read and write to files \ No newline at end of file +* StormScript can now read and write to files + +## What's Fixed +* else and else if statements were broken \ No newline at end of file diff --git a/example/example.sts b/example/example.sts index 9f1f4e1..43d04c9 100755 --- a/example/example.sts +++ b/example/example.sts @@ -1,5 +1,13 @@ +func f { + if "hi" is "bye" { + printl "hi"; + } + else { + printl "bye"; + } +} + + do{ - write "example.txt" "hello, world"; - printl read "example.txt"; - write "example.txt" ""; + f; } \ No newline at end of file diff --git a/src/interpreter/globscope.cc b/src/interpreter/globscope.cc index 411d8bf..f5b0389 100644 --- a/src/interpreter/globscope.cc +++ b/src/interpreter/globscope.cc @@ -48,11 +48,21 @@ void sts::interp(string fname,int psize, char *argv[], int argc){ functions.back().linestarted=x; int endreq = 1; while (endreq != 0) { - if ((prs[x]=="}") || (prs[x]=="loop")) + if (prs[x] == "}") endreq--; - else if (prs[x] == "{") + + if (prs[x] == "else") { + if (prs[x+1] == "if") + x++; + x++; endreq++; - x++; + } + else if (prs[x] == "if") { + x++; + endreq++; + } + else + x++; } x--; if (prs[x]=="loop") From 71177cf5c6cef27eec72994075814de43062be13 Mon Sep 17 00:00:00 2001 From: storm246 Date: Sat, 16 Feb 2019 16:29:21 -0500 Subject: [PATCH 05/33] fix while loops in functions --- src/interpreter/globscope.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interpreter/globscope.cc b/src/interpreter/globscope.cc index f5b0389..7742bef 100644 --- a/src/interpreter/globscope.cc +++ b/src/interpreter/globscope.cc @@ -57,7 +57,7 @@ void sts::interp(string fname,int psize, char *argv[], int argc){ x++; endreq++; } - else if (prs[x] == "if") { + else if ((prs[x] == "if") || (prs[x] == "while")) { x++; endreq++; } From 8081c79b85adc067389f5387417e8be156a9e5ad Mon Sep 17 00:00:00 2001 From: storm246 Date: Sat, 16 Feb 2019 16:41:16 -0500 Subject: [PATCH 06/33] fixed while loops --- docs/changelogs/changelog-v0.6.0.md | 4 +++- example/example.sts | 20 +++++++++++--------- src/interpreter/exec.cc | 3 ++- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/docs/changelogs/changelog-v0.6.0.md b/docs/changelogs/changelog-v0.6.0.md index 879d7e1..6d10a96 100644 --- a/docs/changelogs/changelog-v0.6.0.md +++ b/docs/changelogs/changelog-v0.6.0.md @@ -4,4 +4,6 @@ * StormScript can now read and write to files ## What's Fixed -* else and else if statements were broken \ No newline at end of file +* else and else if statements were broken +* length didn't work when used in function inside args +* while loops would cause the parser to increase the current line to the point where it was outside of the scope. \ No newline at end of file diff --git a/example/example.sts b/example/example.sts index 43d04c9..7a2ffed 100755 --- a/example/example.sts +++ b/example/example.sts @@ -1,13 +1,15 @@ -func f { - if "hi" is "bye" { - printl "hi"; - } - else { - printl "bye"; +func converttolist => word { + wlist: []; + wlen: word|length; + x: 0; + + while x less wlen { + printl word[x]; + x+: 1; } } - -do{ - f; +do { + x: "hi"; + converttolist => word: x; } \ No newline at end of file diff --git a/src/interpreter/exec.cc b/src/interpreter/exec.cc index ab8eb89..3c11371 100644 --- a/src/interpreter/exec.cc +++ b/src/interpreter/exec.cc @@ -19,7 +19,7 @@ void sts::exec(int *x, int function, std::vector *pclasstypes, std if (vars.back().type == 's') { vars.push_back(stsvars()); vars.back().name = functions[function].args[i].name + "|length"; - vars.back().val = functions[function].args[i].length; + vars.back().val = std::to_string(functions[function].args[i].length); vars.back().type = 'i'; } } @@ -106,6 +106,7 @@ void sts::exec(int *x, int function, std::vector *pclasstypes, std e--; y++; } + y--; } else if (prs[y]=="if") { endreq+=1; From 2fe4fdd6e5554f59afcb4869eb40744ae4d87210 Mon Sep 17 00:00:00 2001 From: Ethan Onstott Date: Sat, 16 Feb 2019 18:09:14 -0500 Subject: [PATCH 07/33] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 8c1094d..0e70460 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -1,8 +1,3 @@ -# C/C++ with GCC -# Build your C/C++ project with GCC using make. -# Add steps that publish test results, save build artifacts, deploy, and more: -# https://docs.microsoft.com/azure/devops/pipelines/apps/c-cpp/gcc - trigger: - master @@ -11,10 +6,14 @@ pool: steps: - script: | - cmake CMakeLists.txt; + cmake .; make; - mkdir build; - mv stormscript build; - cd scripts; - ./runtests.sh - displayName: 'make' + install stormscript build/stormscript; + rm stormscript + displayName: 'Build' +- script: | + for i in $(ls); do + touch outputs/$i.txt; + echo $(../build/stormscript $i) > outputs/$i.txt; + done + displayName: 'Test' \ No newline at end of file From 95400cb9240b895790257837eef81a8f80a571ae Mon Sep 17 00:00:00 2001 From: Ethan Onstott Date: Sat, 16 Feb 2019 18:12:11 -0500 Subject: [PATCH 08/33] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 0e70460..94cb078 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -12,6 +12,7 @@ steps: rm stormscript displayName: 'Build' - script: | + cd tests; for i in $(ls); do touch outputs/$i.txt; echo $(../build/stormscript $i) > outputs/$i.txt; From 0b00b5ed6619b5c27f0691ef3491ccaf88086851 Mon Sep 17 00:00:00 2001 From: Ethan Onstott Date: Sat, 16 Feb 2019 18:15:08 -0500 Subject: [PATCH 09/33] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 94cb078..f92bada 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -12,9 +12,20 @@ steps: rm stormscript displayName: 'Build' - script: | + echo Running tests:; cd tests; - for i in $(ls); do - touch outputs/$i.txt; - echo $(../build/stormscript $i) > outputs/$i.txt; - done + printf "\n"; + + B=0; + for i in $( ls | grep .sts ); do + if [[ $(echo `cat outputs/$i.txt`) = "$(echo `../build/stormscript $i`)" ]]; then + echo $B: Test Successful; + else + echo Test $B failed:; + echo expected$'\n'$(echo `cat outputs/$i.txt`)$'\n'got$'\n'$(echo `../build/stormscript $i`); + exit 1; + fi; + + B=$(($B+1)); + done; displayName: 'Test' \ No newline at end of file From 051df36e7c1e06a4be9b745974dbae456823c9cf Mon Sep 17 00:00:00 2001 From: Ethan Onstott Date: Sat, 16 Feb 2019 18:17:03 -0500 Subject: [PATCH 10/33] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index f92bada..5a3bd5c 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -12,20 +12,6 @@ steps: rm stormscript displayName: 'Build' - script: | - echo Running tests:; - cd tests; - printf "\n"; - - B=0; - for i in $( ls | grep .sts ); do - if [[ $(echo `cat outputs/$i.txt`) = "$(echo `../build/stormscript $i`)" ]]; then - echo $B: Test Successful; - else - echo Test $B failed:; - echo expected$'\n'$(echo `cat outputs/$i.txt`)$'\n'got$'\n'$(echo `../build/stormscript $i`); - exit 1; - fi; - - B=$(($B+1)); - done; + cd scripts; + ./runtests.sh displayName: 'Test' \ No newline at end of file From 5cdbb1565c12ee7e4f85e9981895ae1f8b88a73f Mon Sep 17 00:00:00 2001 From: Ethan Onstott Date: Sat, 16 Feb 2019 18:19:07 -0500 Subject: [PATCH 11/33] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 5a3bd5c..65d917f 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -8,6 +8,7 @@ steps: - script: | cmake .; make; + mkdir build; install stormscript build/stormscript; rm stormscript displayName: 'Build' From c960cd96cc9b61733d49a11047cf9c534a3fb738 Mon Sep 17 00:00:00 2001 From: storm246 Date: Sat, 16 Feb 2019 23:31:48 -0500 Subject: [PATCH 12/33] updated docs; adding modules back --- CMakeLists.txt | 1 + docs/{ => development}/style.md | 28 ++++++++++++++++++++++++++-- docs/development/testing.md | 0 example/example.sts | 14 ++------------ example/hello.sts | 3 +++ scripts/runtests.sh | 2 +- scripts/writenewouts.sh | 4 +++- src/include/modules.h | 11 +++++++++++ src/include/stormscript.h | 8 +++++++- src/parser/mods.cc | 5 +++++ src/stream/files.cc | 2 +- tests/outputs/etc.txt | 1 - tests/outputs/modules.txt | 1 - tests/outputs/outputs.txt | 1 - tests/outputs/readme.md | 2 -- 15 files changed, 60 insertions(+), 23 deletions(-) rename docs/{ => development}/style.md (74%) create mode 100644 docs/development/testing.md create mode 100644 example/hello.sts create mode 100644 src/include/modules.h create mode 100644 src/parser/mods.cc delete mode 100644 tests/outputs/etc.txt delete mode 100644 tests/outputs/modules.txt delete mode 100644 tests/outputs/outputs.txt delete mode 100644 tests/outputs/readme.md diff --git a/CMakeLists.txt b/CMakeLists.txt index c977e94..84def3f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,7 @@ add_executable(stormscript src/core/errors.cc src/parser/parse.cc src/parser/read.cc + src/parser/mods.cc src/interpreter/globscope.cc src/interpreter/exec.cc src/stream/io.cc diff --git a/docs/style.md b/docs/development/style.md similarity index 74% rename from docs/style.md rename to docs/development/style.md index 1a5ad68..423a1f6 100644 --- a/docs/style.md +++ b/docs/development/style.md @@ -3,7 +3,8 @@ ## Table of Contents * [Info](#info) -* [C++ Style](#c++-ctyle) +* [C++ Style](#c++-style) +* [StormScript Style](#stormscript-style) # Info I mainly created this code as a guide and less of a "law" because I feel that it is important to have readable code, but not to stress it so much as to deter newcomers. I sometimes will forget to follow this style guide, and if you do as long as your code is readable I will accept it. That said, I want you to try to use this style guide as much as you can for the sake of time. If I forget to follow this somewhere, feel free to create a PR that cleans up my code. @@ -64,4 +65,27 @@ source: [man.cc](/src/values/man.cc) ## Keywords -Use `'\n'` instead of `std::endl;` unless absolutely neccessary \ No newline at end of file +Use `'\n'` instead of `std::endl;` unless absolutely neccessary + +# StormScript Style +StormScript styling is important for tests and for core files, so naturally both should follow these guidelines. + +## Parentheses +In StormScript, parentheses are optional and should only be used when you are using the comparison operator. + +For example, +``` +do{ + y: 2; + x: (y less 3) ? "yes" : "no"; + + printl x; +} +``` +not: +do{ + y: 2; + x: y less 3 ? "yes" : "no"; + + printl x; +} \ No newline at end of file diff --git a/docs/development/testing.md b/docs/development/testing.md new file mode 100644 index 0000000..e69de29 diff --git a/example/example.sts b/example/example.sts index 7a2ffed..bab467c 100755 --- a/example/example.sts +++ b/example/example.sts @@ -1,15 +1,5 @@ -func converttolist => word { - wlist: []; - wlen: word|length; - x: 0; - - while x less wlen { - printl word[x]; - x+: 1; - } -} +mod hello; do { - x: "hi"; - converttolist => word: x; + hello; } \ No newline at end of file diff --git a/example/hello.sts b/example/hello.sts new file mode 100644 index 0000000..10514f5 --- /dev/null +++ b/example/hello.sts @@ -0,0 +1,3 @@ +func hello { + printl "hello, world" +} \ No newline at end of file diff --git a/scripts/runtests.sh b/scripts/runtests.sh index c7edf7c..4741af6 100755 --- a/scripts/runtests.sh +++ b/scripts/runtests.sh @@ -1,7 +1,7 @@ #!/bin/bash cd .. cmake CMakeLists.txt -make +make $1 install stormscript build/stormscript rm stormscript printf "\n \n \n" diff --git a/scripts/writenewouts.sh b/scripts/writenewouts.sh index da65b6b..0a019af 100755 --- a/scripts/writenewouts.sh +++ b/scripts/writenewouts.sh @@ -7,7 +7,9 @@ rm stormscript cd tests -for i in $(ls); do +rm -r outputs/* + +for i in $(ls | grep .sts); do touch outputs/$i.txt echo $(../build/stormscript $i) > outputs/$i.txt done \ No newline at end of file diff --git a/src/include/modules.h b/src/include/modules.h new file mode 100644 index 0000000..d855845 --- /dev/null +++ b/src/include/modules.h @@ -0,0 +1,11 @@ +#pragma once +#ifndef MODULES_H_ +#define MODULES_H_ + +#include "includes.h" +#include "core.h" + +// Module read function +std::vector readmod(string name); + +#endif \ No newline at end of file diff --git a/src/include/stormscript.h b/src/include/stormscript.h index 6d70fe1..67227a5 100755 --- a/src/include/stormscript.h +++ b/src/include/stormscript.h @@ -7,7 +7,10 @@ #else #define PLATFORM "other" #endif - +/* +NOTE: +Place All StormScript headers here separated by 2 lines. +*/ #include "includes.h" @@ -22,6 +25,9 @@ #include "functions.h" + +#include "includes.h" + using std::cout; // for the most part, it is a better idea to use functions outside of the sts class diff --git a/src/parser/mods.cc b/src/parser/mods.cc new file mode 100644 index 0000000..0231a25 --- /dev/null +++ b/src/parser/mods.cc @@ -0,0 +1,5 @@ +#include "../include/stormscript.h" + +std::vector readmod(string name) { + +} \ No newline at end of file diff --git a/src/stream/files.cc b/src/stream/files.cc index a01e67d..a673a24 100644 --- a/src/stream/files.cc +++ b/src/stream/files.cc @@ -1,4 +1,4 @@ -#include "../include/core.h" +#include "../include/stormscript.h" void sts::readfile(int y, stsvars *v) { v->type = 's'; diff --git a/tests/outputs/etc.txt b/tests/outputs/etc.txt deleted file mode 100644 index 8b13789..0000000 --- a/tests/outputs/etc.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/tests/outputs/modules.txt b/tests/outputs/modules.txt deleted file mode 100644 index 8b13789..0000000 --- a/tests/outputs/modules.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/tests/outputs/outputs.txt b/tests/outputs/outputs.txt deleted file mode 100644 index 8b13789..0000000 --- a/tests/outputs/outputs.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/tests/outputs/readme.md b/tests/outputs/readme.md deleted file mode 100644 index e9efec3..0000000 --- a/tests/outputs/readme.md +++ /dev/null @@ -1,2 +0,0 @@ -## Outputs -The contents of this folder are the expected outputs of tests. Whenever a new test is added, run [this file](/writenewouts.sh) \ No newline at end of file From c174a002d8525ce9a738463ed7a7146e0d86ae3c Mon Sep 17 00:00:00 2001 From: storm246 Date: Sun, 17 Feb 2019 22:16:22 -0500 Subject: [PATCH 13/33] modules --- docs/development/testing.md | 10 ++++++++++ example/hello.sts | 2 +- src/include/stormscript.h | 2 +- src/interpreter/globscope.cc | 7 +++++++ src/parser/mods.cc | 29 +++++++++++++++++++++++++++++ src/parser/parse.cc | 2 +- src/values/man.cc | 1 + tests/etc/examplemod.sts | 3 +++ tests/modtest.sts | 5 +++++ tests/outputs/modtest.sts.txt | 1 + 10 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 tests/etc/examplemod.sts create mode 100644 tests/modtest.sts create mode 100644 tests/outputs/modtest.sts.txt diff --git a/docs/development/testing.md b/docs/development/testing.md index e69de29..a2821a9 100644 --- a/docs/development/testing.md +++ b/docs/development/testing.md @@ -0,0 +1,10 @@ +# Testing + +## How often should new tests be added? +When you are adding new features (not patches) tests should be added. + +## How can I generate outputs? +Run `scripts/writenewouts.sh` + +## How can I run tests? +Run `scripts/runtests.sh` \ No newline at end of file diff --git a/example/hello.sts b/example/hello.sts index 10514f5..96656d9 100644 --- a/example/hello.sts +++ b/example/hello.sts @@ -1,3 +1,3 @@ func hello { - printl "hello, world" + printl "hello, world"; } \ No newline at end of file diff --git a/src/include/stormscript.h b/src/include/stormscript.h index 67227a5..612ca2f 100755 --- a/src/include/stormscript.h +++ b/src/include/stormscript.h @@ -26,7 +26,7 @@ Place All StormScript headers here separated by 2 lines. #include "functions.h" -#include "includes.h" +#include "modules.h" using std::cout; diff --git a/src/interpreter/globscope.cc b/src/interpreter/globscope.cc index 7742bef..681d51f 100644 --- a/src/interpreter/globscope.cc +++ b/src/interpreter/globscope.cc @@ -68,6 +68,13 @@ void sts::interp(string fname,int psize, char *argv[], int argc){ if (prs[x]=="loop") x+=2; } + else if (prs[x] == "mod") { + //cout << + std::vector mod = readmod(prs[x+1]); + std::vector::iterator it = prs.begin(); + prs.insert(it + 3, mod.begin(), mod.end()); + x += 2; + } else if (prs[x]=="do"){ exec(&x, ((psize==-1) ? -2 : -1), {}, {}, new std::vector({})); } diff --git a/src/parser/mods.cc b/src/parser/mods.cc index 0231a25..563d9c2 100644 --- a/src/parser/mods.cc +++ b/src/parser/mods.cc @@ -1,5 +1,34 @@ #include "../include/stormscript.h" std::vector readmod(string name) { + sts s; + std::ifstream f; + + f.open(name + ".sts"); + string contents; + + char c = f.get(); + + if (f.fail()) + s.error(11, name+".sts"); + + while (f.good()) { + contents += c; + c = f.get(); + } + f.close(); + + s.prg.resize(s.prg.size() + 1); + + for (int i = 0; i < contents.size(); i++) { + if (contents[i] == '\n') { + s.prg.resize(s.prg.size() + 1); + } + else { + s.prg.back() += contents[i]; + } + } + + return s.parse(s.prg); } \ No newline at end of file diff --git a/src/parser/parse.cc b/src/parser/parse.cc index 44cd0c2..4686d25 100755 --- a/src/parser/parse.cc +++ b/src/parser/parse.cc @@ -57,7 +57,7 @@ std::vector sts::parse(std::vector prg){ x.push_back( string(1,prg[y][z]) ); break; } - else if (((prg[y][z]=='+') || (prg[y][z]=='-') || (prg[y][z]=='*') || (prg[y][z]=='/') || (prg[y][z]=='[') || (prg[y][z]==']')) && (inquotes==false)) { + else if (((prg[y][z]=='+') || (prg[y][z]=='-') || (prg[y][z]=='*') || ((prg[y][z]=='/') && (x[x.size()-2]!="mod")) || (prg[y][z]=='[') || (prg[y][z]==']')) && (inquotes==false)) { x.push_back( string(1,prg[y][z]) ); x.resize(x.size()+1); } diff --git a/src/values/man.cc b/src/values/man.cc index 92defef..62dc205 100644 --- a/src/values/man.cc +++ b/src/values/man.cc @@ -85,6 +85,7 @@ bool sts::valchange(std::vector * pvars, std::vector *cla if (isfunc) { runfunc(&vars, &ct, &y); + y++; *ln = y; *classtypes = ct; *pvars = vars; diff --git a/tests/etc/examplemod.sts b/tests/etc/examplemod.sts new file mode 100644 index 0000000..1ec7a70 --- /dev/null +++ b/tests/etc/examplemod.sts @@ -0,0 +1,3 @@ +func hello { + printl "Hello, World!"; +} \ No newline at end of file diff --git a/tests/modtest.sts b/tests/modtest.sts new file mode 100644 index 0000000..fedf967 --- /dev/null +++ b/tests/modtest.sts @@ -0,0 +1,5 @@ +mod etc/examplemod; + +do { + hello; +} \ No newline at end of file diff --git a/tests/outputs/modtest.sts.txt b/tests/outputs/modtest.sts.txt new file mode 100644 index 0000000..8ab686e --- /dev/null +++ b/tests/outputs/modtest.sts.txt @@ -0,0 +1 @@ +Hello, World! From 1cf9ea99d78ed9cf9066f87d39e7f29c57bcffcf Mon Sep 17 00:00:00 2001 From: storm246 Date: Sun, 17 Feb 2019 22:17:33 -0500 Subject: [PATCH 14/33] update changelog --- docs/changelogs/changelog-v0.6.0.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelogs/changelog-v0.6.0.md b/docs/changelogs/changelog-v0.6.0.md index 6d10a96..b54ca9d 100644 --- a/docs/changelogs/changelog-v0.6.0.md +++ b/docs/changelogs/changelog-v0.6.0.md @@ -2,6 +2,7 @@ ## What's new * StormScript can now read and write to files +* StormScript now has modules, which allow you to run functions from other StormScript files. ## What's Fixed * else and else if statements were broken From 47b3a8c12cb42d2f56368bd01ac4ff8563ded60b Mon Sep 17 00:00:00 2001 From: storm246 Date: Sun, 17 Feb 2019 22:21:37 -0500 Subject: [PATCH 15/33] update changelog --- docs/changelogs/changelog-v0.6.0.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/changelogs/changelog-v0.6.0.md b/docs/changelogs/changelog-v0.6.0.md index b54ca9d..ecafe8e 100644 --- a/docs/changelogs/changelog-v0.6.0.md +++ b/docs/changelogs/changelog-v0.6.0.md @@ -7,4 +7,5 @@ ## What's Fixed * else and else if statements were broken * length didn't work when used in function inside args -* while loops would cause the parser to increase the current line to the point where it was outside of the scope. \ No newline at end of file +* while loops would cause the parser to increase the current line to the point where it was outside of the scope. +* Functions run at the end of other functions caused segmentation faults due to failing to parse a semicolon \ No newline at end of file From 021dd4ff61f61d06bde431a83e587c20d6f8686d Mon Sep 17 00:00:00 2001 From: storm246 Date: Mon, 18 Feb 2019 17:31:36 -0500 Subject: [PATCH 16/33] fixed issue #51 and issue #45 --- docs/changelogs/changelog-v0.6.0.md | 3 ++- docs/development/style.md | 4 +++- example/example.sts | 8 +++++--- example/example.txt | 0 example/hello.sts | 3 --- src/interpreter/globscope.cc | 3 +++ src/parser/mods.cc | 6 ++---- tests/globalvariables.sts | 7 +++++++ tests/outputs/globalvariables.sts.txt | 1 + 9 files changed, 23 insertions(+), 12 deletions(-) delete mode 100644 example/example.txt delete mode 100644 example/hello.sts create mode 100644 tests/globalvariables.sts create mode 100644 tests/outputs/globalvariables.sts.txt diff --git a/docs/changelogs/changelog-v0.6.0.md b/docs/changelogs/changelog-v0.6.0.md index ecafe8e..fb4579c 100644 --- a/docs/changelogs/changelog-v0.6.0.md +++ b/docs/changelogs/changelog-v0.6.0.md @@ -8,4 +8,5 @@ * else and else if statements were broken * length didn't work when used in function inside args * while loops would cause the parser to increase the current line to the point where it was outside of the scope. -* Functions run at the end of other functions caused segmentation faults due to failing to parse a semicolon \ No newline at end of file +* Functions run at the end of other functions caused segmentation faults due to failing to parse a semicolon +* Global variables couldn't be declared \ No newline at end of file diff --git a/docs/development/style.md b/docs/development/style.md index 423a1f6..2ef1f8d 100644 --- a/docs/development/style.md +++ b/docs/development/style.md @@ -83,9 +83,11 @@ do{ } ``` not: +``` do{ y: 2; x: y less 3 ? "yes" : "no"; printl x; -} \ No newline at end of file +} +``` \ No newline at end of file diff --git a/example/example.sts b/example/example.sts index bab467c..cda2cd9 100755 --- a/example/example.sts +++ b/example/example.sts @@ -1,5 +1,7 @@ -mod hello; +x: 3; -do { - hello; +do{ + printl x; + x+: 2; + printl x; } \ No newline at end of file diff --git a/example/example.txt b/example/example.txt deleted file mode 100644 index e69de29..0000000 diff --git a/example/hello.sts b/example/hello.sts deleted file mode 100644 index 96656d9..0000000 --- a/example/hello.sts +++ /dev/null @@ -1,3 +0,0 @@ -func hello { - printl "hello, world"; -} \ No newline at end of file diff --git a/src/interpreter/globscope.cc b/src/interpreter/globscope.cc index 681d51f..c39a0b6 100644 --- a/src/interpreter/globscope.cc +++ b/src/interpreter/globscope.cc @@ -78,6 +78,9 @@ void sts::interp(string fname,int psize, char *argv[], int argc){ else if (prs[x]=="do"){ exec(&x, ((psize==-1) ? -2 : -1), {}, {}, new std::vector({})); } + else if (prs[x].back() == ':') { + globvars.push_back(declare(&x, &globvars)); + } else if ((prs[x]!=";") && (prs[x][0]!='\0')){ error(1, prs[x]); } diff --git a/src/parser/mods.cc b/src/parser/mods.cc index 563d9c2..5664131 100644 --- a/src/parser/mods.cc +++ b/src/parser/mods.cc @@ -22,12 +22,10 @@ std::vector readmod(string name) { s.prg.resize(s.prg.size() + 1); for (int i = 0; i < contents.size(); i++) { - if (contents[i] == '\n') { + if (contents[i] == '\n') s.prg.resize(s.prg.size() + 1); - } - else { + else s.prg.back() += contents[i]; - } } return s.parse(s.prg); diff --git a/tests/globalvariables.sts b/tests/globalvariables.sts new file mode 100644 index 0000000..cda2cd9 --- /dev/null +++ b/tests/globalvariables.sts @@ -0,0 +1,7 @@ +x: 3; + +do{ + printl x; + x+: 2; + printl x; +} \ No newline at end of file diff --git a/tests/outputs/globalvariables.sts.txt b/tests/outputs/globalvariables.sts.txt new file mode 100644 index 0000000..99818b5 --- /dev/null +++ b/tests/outputs/globalvariables.sts.txt @@ -0,0 +1 @@ +3 5 From a686d341edca885ad8f327875055a693a2cfc6da Mon Sep 17 00:00:00 2001 From: storm246 Date: Mon, 18 Feb 2019 20:18:16 -0500 Subject: [PATCH 17/33] fixed comparisons using subscripts --- docs/changelogs/changelog-v0.6.0.md | 3 ++- example/example.sts | 13 ++++++++----- src/interpreter/exec.cc | 3 +-- src/interpreter/globscope.cc | 9 +++------ src/values/compare.cc | 11 +++++++++-- src/values/getvals.cc | 2 +- src/values/if.cc | 11 +++++++++-- tests/classtest.sts | 4 ++-- 8 files changed, 35 insertions(+), 21 deletions(-) diff --git a/docs/changelogs/changelog-v0.6.0.md b/docs/changelogs/changelog-v0.6.0.md index fb4579c..fd07392 100644 --- a/docs/changelogs/changelog-v0.6.0.md +++ b/docs/changelogs/changelog-v0.6.0.md @@ -9,4 +9,5 @@ * length didn't work when used in function inside args * while loops would cause the parser to increase the current line to the point where it was outside of the scope. * Functions run at the end of other functions caused segmentation faults due to failing to parse a semicolon -* Global variables couldn't be declared \ No newline at end of file +* Global variables couldn't be declared +* comparisons using subscripts were broken \ No newline at end of file diff --git a/example/example.sts b/example/example.sts index cda2cd9..55f7d9f 100755 --- a/example/example.sts +++ b/example/example.sts @@ -1,7 +1,10 @@ -x: 3; +word: ""; -do{ - printl x; - x+: 2; - printl x; +do { + word: "hi"; + other: "h"; + + if other is word[0]{ + printl other; + } } \ No newline at end of file diff --git a/src/interpreter/exec.cc b/src/interpreter/exec.cc index 3c11371..6f7c293 100644 --- a/src/interpreter/exec.cc +++ b/src/interpreter/exec.cc @@ -74,9 +74,8 @@ void sts::exec(int *x, int function, std::vector *pclasstypes, std writefile(y); y+= 2; } - else if (prs[y]=="exit") { + else if (prs[y]=="exit") exit(0); - } else if (prs[y]=="in") { vars.resize(vars.size()+1); y++; diff --git a/src/interpreter/globscope.cc b/src/interpreter/globscope.cc index c39a0b6..e24e3f8 100644 --- a/src/interpreter/globscope.cc +++ b/src/interpreter/globscope.cc @@ -75,14 +75,11 @@ void sts::interp(string fname,int psize, char *argv[], int argc){ prs.insert(it + 3, mod.begin(), mod.end()); x += 2; } - else if (prs[x]=="do"){ + else if (prs[x]=="do") exec(&x, ((psize==-1) ? -2 : -1), {}, {}, new std::vector({})); - } - else if (prs[x].back() == ':') { + else if (prs[x].back() == ':') globvars.push_back(declare(&x, &globvars)); - } - else if ((prs[x]!=";") && (prs[x][0]!='\0')){ + else if ((prs[x]!=";") && (prs[x][0]!='\0')) error(1, prs[x]); - } } } \ No newline at end of file diff --git a/src/values/compare.cc b/src/values/compare.cc index 49ff1fa..114ebe2 100644 --- a/src/values/compare.cc +++ b/src/values/compare.cc @@ -11,9 +11,15 @@ bool condition(sts *program, int *ln, std::vector vars) { stsvars val1 = prg.getval(vars, new int(0)); - prg.prs = { program->prs[y+2] }; - stsvars val2 = prg.getval(vars, new int(0)); + if (program->prs[y+3] != "[") + prg.prs = { program->prs[y+2] }; + else { + prg.prs = { program->prs[y+2], program->prs[y+3], program->prs[y+4] }; + y+=2; + } + stsvars val2 = prg.getval(vars, new int(0)); + if (val1.type == val2.type) { // compare based on conditional operator if (prs[y+1] == "is") { @@ -70,6 +76,7 @@ bool condition(sts *program, int *ln, std::vector vars) { // give error with value based on type program->error(9, val2.val); } + *ln = y; return v; } \ No newline at end of file diff --git a/src/values/getvals.cc b/src/values/getvals.cc index 72a1381..78a49f5 100644 --- a/src/values/getvals.cc +++ b/src/values/getvals.cc @@ -121,7 +121,7 @@ stsvars sts::getval(std::vector vars, int *line) { } } - y++; + y+= 3; } else { diff --git a/src/values/if.cc b/src/values/if.cc index 5f96228..9ca51a3 100644 --- a/src/values/if.cc +++ b/src/values/if.cc @@ -7,6 +7,7 @@ void sts::ifs(int *line, int *endr, std::vector vars) { *line = y; if (!toBool(getval(vars, line).val)){ + y = *line; y++; while (prs[y] != "}") { y++; @@ -23,8 +24,14 @@ void sts::ifs(int *line, int *endr, std::vector vars) { } } } - else - y+=3; + else { + y = *line; + + if (prs[y-1] == "[") + y+= 2; + else + y++; + } *line = y; *endr = endreq; diff --git a/tests/classtest.sts b/tests/classtest.sts index 53d99d7..def5347 100644 --- a/tests/classtest.sts +++ b/tests/classtest.sts @@ -1,6 +1,6 @@ type test{ - x; - y; + bool x; + int y; } do{ From 0392bd7c879d0ce4f01fd4b014a2d82d233795fc Mon Sep 17 00:00:00 2001 From: storm246 Date: Thu, 21 Feb 2019 11:18:38 -0500 Subject: [PATCH 18/33] fixed issue with length not changing on variable modification --- docs/changelogs/changelog-v0.6.0.md | 3 ++- example/example.sts | 14 +++++--------- src/values/man.cc | 15 +++++++++++++-- src/values/stsdec.cc | 4 ++++ 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/docs/changelogs/changelog-v0.6.0.md b/docs/changelogs/changelog-v0.6.0.md index fd07392..3c1c2dc 100644 --- a/docs/changelogs/changelog-v0.6.0.md +++ b/docs/changelogs/changelog-v0.6.0.md @@ -10,4 +10,5 @@ * while loops would cause the parser to increase the current line to the point where it was outside of the scope. * Functions run at the end of other functions caused segmentation faults due to failing to parse a semicolon * Global variables couldn't be declared -* comparisons using subscripts were broken \ No newline at end of file +* comparisons using subscripts were broken +* length did not change on modification \ No newline at end of file diff --git a/example/example.sts b/example/example.sts index 55f7d9f..af50068 100755 --- a/example/example.sts +++ b/example/example.sts @@ -1,10 +1,6 @@ -word: ""; - -do { - word: "hi"; - other: "h"; - - if other is word[0]{ - printl other; - } +do{ + x: "hi"; + printl x|length; + x: "hello"; + printl x|length; } \ No newline at end of file diff --git a/src/values/man.cc b/src/values/man.cc index 62dc205..2b5d949 100644 --- a/src/values/man.cc +++ b/src/values/man.cc @@ -30,9 +30,20 @@ bool sts::valchange(std::vector * pvars, std::vector *cla if (!isvar(pvars, *name, index)) pvars->push_back(declare(ln, pvars)); - else + else { pvars->at(*index).val = getval(vars, new int(y+1)).val; - + if ((pvars->at(*index).type == 's') || (pvars->at(*index).type == 'l')) { + int *ind = new int(0); + + // change length value of variable + if (isvar(pvars, pvars->at(*index).name + "|length", ind)) { + pvars->at(*index).length = ((pvars->at(*index).type == 's') ? + pvars->at(*index).val.size() : pvars->at(*index).vals.size()); + pvars->at(*ind).val = std::to_string(pvars->at(*index).length); + } + } + } + while (prs[y]!=";") y++; diff --git a/src/values/stsdec.cc b/src/values/stsdec.cc index da2421a..01ffb87 100755 --- a/src/values/stsdec.cc +++ b/src/values/stsdec.cc @@ -34,6 +34,10 @@ stsvars sts::declare(int *line, std::vector *vars) { //variable declara new_var.type = 'l'; new_var.assignlist(this, *vars, line); } + else if (isint(prs[y])) + new_var.type = 'i'; + else if ((prs[y] == "true") || (prs[y] == "false")) + new_var.type = 'b'; // bad idea to pop back the line, just pop back the var type = new_var.type; From 9a4966fdfc26a88b8fa113a9c2e37d95c718f9dc Mon Sep 17 00:00:00 2001 From: storm246 Date: Thu, 21 Feb 2019 13:01:49 -0500 Subject: [PATCH 19/33] fixed comparisons using subscripts --- example/example.sts | 9 ++++-- src/interpreter/exec.cc | 1 - src/interpreter/globscope.cc | 5 +++- src/values/compare.cc | 54 ++++++++++++++++++++++++++++++------ src/values/getvals.cc | 2 +- src/values/man.cc | 19 ++++++++++++- src/values/stsdec.cc | 5 ---- 7 files changed, 76 insertions(+), 19 deletions(-) diff --git a/example/example.sts b/example/example.sts index af50068..5d2d868 100755 --- a/example/example.sts +++ b/example/example.sts @@ -1,6 +1,11 @@ +x: ""; + +func getlength { + printl x|length, x; +} + do{ x: "hi"; printl x|length; - x: "hello"; - printl x|length; + getlength; } \ No newline at end of file diff --git a/src/interpreter/exec.cc b/src/interpreter/exec.cc index 6f7c293..927dd9f 100644 --- a/src/interpreter/exec.cc +++ b/src/interpreter/exec.cc @@ -156,7 +156,6 @@ void sts::exec(int *x, int function, std::vector *pclasstypes, std } } } - for (int i = 0; i({})); - else if (prs[x].back() == ':') + else if (prs[x].back() == ':') { globvars.push_back(declare(&x, &globvars)); + for (int i = 0; i prs, int y) { + int n = 0; + + /* + Prs should look like this if there is 2 subscripts + y+ | line + ---|----- + 0: var1 + 1: [ + 2: n + 3: ] + 4: comparison operator + 5: var2 + 6: [ + 7: n + 8: ] + */ + + if (prs[y+1] == "[") { + n++; + + if (prs[y+6] == "[") + n++; + } + else if (prs[y+2] == "[") { + n++; + } + + return n; +} + bool condition(sts *program, int *ln, std::vector vars) { std::vector prs = program->prs; sts prg = *program; int y = *ln; + int sbs = subscript(program->prs, y); bool v; - prg.prs = { program->prs[y] }; + if (sbs == 0) + prg.prs = { program->prs[y] }; + else { + prg.prs = { program->prs[y], program->prs[y+1], program->prs[y+2], program->prs[y+3] }; + y+= 3; + } + int sy = y + 2; stsvars val1 = prg.getval(vars, new int(0)); - if (program->prs[y+3] != "[") - prg.prs = { program->prs[y+2] }; + if (sbs <= 1) + prg.prs = { program->prs[sy] }; else { - prg.prs = { program->prs[y+2], program->prs[y+3], program->prs[y+4] }; + prg.prs = { program->prs[sy], program->prs[sy+1], program->prs[sy+2], program->prs[sy+3] }; y+=2; } @@ -31,7 +69,7 @@ bool condition(sts *program, int *ln, std::vector vars) { else if (prs[y+1] == "greater") { switch (val1.type) { case 'i': - v = (val1.val > val2.val); + v = (std::stoi(val1.val) > std::stoi(val2.val)); break; case 's': case 'b': @@ -42,7 +80,7 @@ bool condition(sts *program, int *ln, std::vector vars) { else if (prs[y+1] == "greatereq") { switch (val1.type) { case 'i': - v = (val1.val >= val2.val); + v = (std::stoi(val1.val) >= std::stoi(val2.val)); break; case 's': case 'b': @@ -52,7 +90,7 @@ bool condition(sts *program, int *ln, std::vector vars) { else if (prs[y+1] == "less") { switch (val1.type) { case 'i': - v = (val1.val < val2.val); + v = (std::stoi(val1.val) < std::stoi(val2.val)); break; case 's': case 'b': @@ -63,7 +101,7 @@ bool condition(sts *program, int *ln, std::vector vars) { else if (prs[y+1] == "lesseq") { switch (val1.type) { case 'i': - v = (val1.val <= val2.val); + v = (std::stoi(val1.val) <= std::stoi(val2.val)); break; case 's': case 'b': diff --git a/src/values/getvals.cc b/src/values/getvals.cc index 78a49f5..3d8c12c 100644 --- a/src/values/getvals.cc +++ b/src/values/getvals.cc @@ -40,7 +40,7 @@ stsvars sts::getval(std::vector vars, int *line) { *line = y; return v; } - else if ((prs[y+1] == "is") || (prs[y+1] == "not") || (prs[y+1] == "greater") || (prs[y+1] == "greatereq") || (prs[y+1] == "less") || (prs[y+1] == "lesseq")) { + else if (((prs[y+1] == "is") || (prs[y+1] == "not") || (prs[y+1] == "greater") || (prs[y+1] == "greatereq") || (prs[y+1] == "less") || (prs[y+1] == "lesseq")) || ((prs[y+1]=="[") && ((prs[y+4] == "is") || (prs[y+4] == "not") || (prs[y+4] == "greater") || (prs[y+4] == "greatereq") || (prs[y+4] == "less") || (prs[y+4] == "lesseq")))) { bool cond = condition(this, &y, vars); // check if ternary; y+=2; diff --git a/src/values/man.cc b/src/values/man.cc index 2b5d949..d8460cc 100644 --- a/src/values/man.cc +++ b/src/values/man.cc @@ -12,8 +12,10 @@ bool isvar(std::vector * pvars, string query, int *num) { for (int i = 0; i < pvars->size() && !isvar; i++) { isvar = (pvars->at(i).name == query); - *num = i; + if (isvar) + *num = i; } + return isvar; } @@ -40,8 +42,14 @@ bool sts::valchange(std::vector * pvars, std::vector *cla pvars->at(*index).length = ((pvars->at(*index).type == 's') ? pvars->at(*index).val.size() : pvars->at(*index).vals.size()); pvars->at(*ind).val = std::to_string(pvars->at(*index).length); + + if (pvars->at(*index).glob) + globvars[*ind] = pvars->at(*ind); } + } + if (pvars->at(*index).glob) + globvars[*index] = pvars->at(*index); } while (prs[y]!=";") @@ -82,6 +90,15 @@ bool sts::valchange(std::vector * pvars, std::vector *cla else error(9, prs[y]); } + if (pvars->at(*num).glob) { + int *size_num = new int(-1); + + globvars[*num] = pvars->at(*num); + + if (isvar(pvars, pvars->at(*num).name + "|length", size_num)) + globvars[*size_num] = pvars->at(*size_num); + } + y += 3; *ln = y; return true; diff --git a/src/values/stsdec.cc b/src/values/stsdec.cc index 01ffb87..18d0f31 100755 --- a/src/values/stsdec.cc +++ b/src/values/stsdec.cc @@ -34,11 +34,6 @@ stsvars sts::declare(int *line, std::vector *vars) { //variable declara new_var.type = 'l'; new_var.assignlist(this, *vars, line); } - else if (isint(prs[y])) - new_var.type = 'i'; - else if ((prs[y] == "true") || (prs[y] == "false")) - new_var.type = 'b'; - // bad idea to pop back the line, just pop back the var type = new_var.type; switch (type) { From 65ff04fb2377b89035b3b30a3e0b70dc5307ced8 Mon Sep 17 00:00:00 2001 From: stormprograms Date: Sat, 23 Feb 2019 10:39:08 -0500 Subject: [PATCH 20/33] fixed issue with the global flag on variables being assumed as true --- docs/changelogs/changelog-v0.6.0.md | 3 ++- example/example.sts | 15 ++++++--------- src/include/variables.h | 2 +- src/values/man.cc | 2 +- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/docs/changelogs/changelog-v0.6.0.md b/docs/changelogs/changelog-v0.6.0.md index 3c1c2dc..fe4dcec 100644 --- a/docs/changelogs/changelog-v0.6.0.md +++ b/docs/changelogs/changelog-v0.6.0.md @@ -11,4 +11,5 @@ * Functions run at the end of other functions caused segmentation faults due to failing to parse a semicolon * Global variables couldn't be declared * comparisons using subscripts were broken -* length did not change on modification \ No newline at end of file +* length did not change on modification +* `stsvars::glob` was considered to be true by some compilers, causing crash \ No newline at end of file diff --git a/example/example.sts b/example/example.sts index 5d2d868..b0fd50f 100755 --- a/example/example.sts +++ b/example/example.sts @@ -1,11 +1,8 @@ -x: ""; - -func getlength { - printl x|length, x; -} - do{ - x: "hi"; - printl x|length; - getlength; + x: 3; + y: 10; + while x not y { + x+: 1; + printl x; + } } \ No newline at end of file diff --git a/src/include/variables.h b/src/include/variables.h index 8f14191..f722157 100644 --- a/src/include/variables.h +++ b/src/include/variables.h @@ -13,7 +13,7 @@ class stsvars { std::vector vals; int length; - bool glob; + bool glob = false; string name; void assignlist(sts *script, std::vector vars, int *line); diff --git a/src/values/man.cc b/src/values/man.cc index d8460cc..a4e4121 100644 --- a/src/values/man.cc +++ b/src/values/man.cc @@ -19,7 +19,7 @@ bool isvar(std::vector * pvars, string query, int *num) { return isvar; } -bool sts::valchange(std::vector * pvars, std::vector *classtypes, int * ln){ //changes the value of the stsvars list +bool sts::valchange(std::vector * pvars, std::vector *classtypes, int *ln){ //changes the value of the stsvars list std::vector vars = *pvars; int y = *ln; std::vector ct = *classtypes; From 419dfd8051c582207989d1c2a0d3c9eb3e8fa08a Mon Sep 17 00:00:00 2001 From: stormprograms Date: Tue, 26 Feb 2019 20:59:04 -0500 Subject: [PATCH 21/33] added random header --- example/example.sts | 7 +------ src/include/stormscript.h | 3 +++ src/include/stsrand.h | 11 +++++++++++ src/values/random.cc | 1 + 4 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 src/include/stsrand.h create mode 100644 src/values/random.cc diff --git a/example/example.sts b/example/example.sts index b0fd50f..4f2a8b2 100755 --- a/example/example.sts +++ b/example/example.sts @@ -1,8 +1,3 @@ do{ - x: 3; - y: 10; - while x not y { - x+: 1; - printl x; - } + printl random => min: 0, max: 10; } \ No newline at end of file diff --git a/src/include/stormscript.h b/src/include/stormscript.h index 612ca2f..42bc099 100755 --- a/src/include/stormscript.h +++ b/src/include/stormscript.h @@ -28,6 +28,9 @@ Place All StormScript headers here separated by 2 lines. #include "modules.h" + +#include "stsrand.h" + using std::cout; // for the most part, it is a better idea to use functions outside of the sts class diff --git a/src/include/stsrand.h b/src/include/stsrand.h new file mode 100644 index 0000000..9e293b3 --- /dev/null +++ b/src/include/stsrand.h @@ -0,0 +1,11 @@ +#pragma once +#ifndef STSRAND_H_ +#define STSRAND_H_ + +#include "includes.h" + +#include "variables.h" + +int genrandomintfromrange(std::vector prs, int *line); + +#endif \ No newline at end of file diff --git a/src/values/random.cc b/src/values/random.cc new file mode 100644 index 0000000..3dbac77 --- /dev/null +++ b/src/values/random.cc @@ -0,0 +1 @@ +#include "../include/stormscript.h" From f240f3eb791ed03c2fbf39bef986e066cac3ba55 Mon Sep 17 00:00:00 2001 From: stormprograms Date: Wed, 27 Feb 2019 17:11:16 -0500 Subject: [PATCH 22/33] randomrange function generates random int from range --- CMakeLists.txt | 1 + docs/changelogs/changelog-v0.6.0.md | 1 + example/example.sts | 2 +- src/include/includes.h | 2 ++ src/include/stsrand.h | 1 + src/values/getvals.cc | 5 +++++ src/values/random.cc | 28 ++++++++++++++++++++++++++++ 7 files changed, 39 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 84def3f..523223a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,7 @@ add_executable(stormscript src/values/runfunc.cc src/values/compare.cc src/values/operations.cc + src/values/random.cc src/classes/dectype.cc src/classes/decmethod.cc) set (StormScript_VERSION_MAJOR 0) diff --git a/docs/changelogs/changelog-v0.6.0.md b/docs/changelogs/changelog-v0.6.0.md index fe4dcec..d06b4b4 100644 --- a/docs/changelogs/changelog-v0.6.0.md +++ b/docs/changelogs/changelog-v0.6.0.md @@ -3,6 +3,7 @@ ## What's new * StormScript can now read and write to files * StormScript now has modules, which allow you to run functions from other StormScript files. +* use `randomrange => min, max;` to generate a random integer in range min, max ## What's Fixed * else and else if statements were broken diff --git a/example/example.sts b/example/example.sts index 4f2a8b2..26861e2 100755 --- a/example/example.sts +++ b/example/example.sts @@ -1,3 +1,3 @@ do{ - printl random => min: 0, max: 10; + printl randomrange => min: 0, max: 10; } \ No newline at end of file diff --git a/src/include/includes.h b/src/include/includes.h index c4e1025..0ae6725 100644 --- a/src/include/includes.h +++ b/src/include/includes.h @@ -5,6 +5,8 @@ #include #include #include +#include +#include /* Let's forward declare these classes for the files that use them diff --git a/src/include/stsrand.h b/src/include/stsrand.h index 9e293b3..857882b 100644 --- a/src/include/stsrand.h +++ b/src/include/stsrand.h @@ -6,6 +6,7 @@ #include "variables.h" + int genrandomintfromrange(std::vector prs, int *line); #endif \ No newline at end of file diff --git a/src/values/getvals.cc b/src/values/getvals.cc index 3d8c12c..d062644 100644 --- a/src/values/getvals.cc +++ b/src/values/getvals.cc @@ -72,6 +72,11 @@ stsvars sts::getval(std::vector vars, int *line) { return v; } + else if (prs[y] == "randomrange") { + cout << genrandomintfromrange(prs, &y) << "\n"; + return v; + } + else if (isint(prs[y])) { v.type = 'i'; v.val = prs[y]; diff --git a/src/values/random.cc b/src/values/random.cc index 3dbac77..8336994 100644 --- a/src/values/random.cc +++ b/src/values/random.cc @@ -1 +1,29 @@ #include "../include/stormscript.h" + +int genrandomintfromrange(std::vector prs, int *line) { + long int ut = static_cast (time(0)); // cast unix epoch to long int + int y = *line; + int range[2]; // range will store the min and max values + + srand(ut); // seed rand() with unix epoch + + y+=2; + + if (prs[y] == "min:") + range[0] = std::stoi(prs[y+1]); + else if (prs[y] == "max:") + range[1] = std::stoi(prs[y+1]); + + y+= 2; + + if (prs[y] == "min:") + range[0] = std::stoi(prs[y+1]); + else if (prs[y] == "max:") + range[1] = std::stoi(prs[y+1]); + + y+= 2; + + *line = y; + + return rand() % range[1] + range[0]; +} \ No newline at end of file From 2dffa2dfbd209bb3433553df1a121e51f7f96b22 Mon Sep 17 00:00:00 2001 From: stormprograms Date: Wed, 27 Feb 2019 17:23:07 -0500 Subject: [PATCH 23/33] random number and bool generation --- docs/changelogs/changelog-v0.6.0.md | 1 + example/example.sts | 2 +- src/include/stsrand.h | 2 +- src/values/getvals.cc | 10 +++++++++- src/values/random.cc | 12 +++++++++--- 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/docs/changelogs/changelog-v0.6.0.md b/docs/changelogs/changelog-v0.6.0.md index d06b4b4..65757bd 100644 --- a/docs/changelogs/changelog-v0.6.0.md +++ b/docs/changelogs/changelog-v0.6.0.md @@ -3,6 +3,7 @@ ## What's new * StormScript can now read and write to files * StormScript now has modules, which allow you to run functions from other StormScript files. +* use `random` to generate a random bool * use `randomrange => min, max;` to generate a random integer in range min, max ## What's Fixed diff --git a/example/example.sts b/example/example.sts index 26861e2..f6cbe27 100755 --- a/example/example.sts +++ b/example/example.sts @@ -1,3 +1,3 @@ do{ - printl randomrange => min: 0, max: 10; + printl random; } \ No newline at end of file diff --git a/src/include/stsrand.h b/src/include/stsrand.h index 857882b..7d76b61 100644 --- a/src/include/stsrand.h +++ b/src/include/stsrand.h @@ -6,7 +6,7 @@ #include "variables.h" - int genrandomintfromrange(std::vector prs, int *line); +bool randombool(); #endif \ No newline at end of file diff --git a/src/values/getvals.cc b/src/values/getvals.cc index d062644..d608111 100644 --- a/src/values/getvals.cc +++ b/src/values/getvals.cc @@ -73,10 +73,18 @@ stsvars sts::getval(std::vector vars, int *line) { } else if (prs[y] == "randomrange") { - cout << genrandomintfromrange(prs, &y) << "\n"; + v.type = 'i'; + v.val = std::to_string(genrandomintfromrange(prs, &y)); + *line = y; return v; } + else if (prs[y] == "random") { + v.type = 'b'; + v.val = ((randombool()) ? "true" : "false"); + return v; + } + else if (isint(prs[y])) { v.type = 'i'; v.val = prs[y]; diff --git a/src/values/random.cc b/src/values/random.cc index 8336994..b6d2bf3 100644 --- a/src/values/random.cc +++ b/src/values/random.cc @@ -1,7 +1,7 @@ #include "../include/stormscript.h" int genrandomintfromrange(std::vector prs, int *line) { - long int ut = static_cast (time(0)); // cast unix epoch to long int + long int ut = static_cast (time(0)); // cast unix epoch to long int int y = *line; int range[2]; // range will store the min and max values @@ -14,16 +14,22 @@ int genrandomintfromrange(std::vector prs, int *line) { else if (prs[y] == "max:") range[1] = std::stoi(prs[y+1]); - y+= 2; + y+=2; if (prs[y] == "min:") range[0] = std::stoi(prs[y+1]); else if (prs[y] == "max:") range[1] = std::stoi(prs[y+1]); - y+= 2; + y++; *line = y; return rand() % range[1] + range[0]; +} + +bool randombool() { + long int ut = static_cast (time(0)); + srand(ut); + return rand() % 2; } \ No newline at end of file From bed668d14adb0b91d239d01b445be2791ae320b5 Mon Sep 17 00:00:00 2001 From: stormprograms Date: Wed, 27 Feb 2019 21:47:14 -0500 Subject: [PATCH 24/33] fixed issue where random range could not be set to a variable --- example/example.sts | 3 ++- src/include/stsrand.h | 2 +- src/values/getvals.cc | 2 +- src/values/random.cc | 15 +++++++++------ 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/example/example.sts b/example/example.sts index f6cbe27..1d105a6 100755 --- a/example/example.sts +++ b/example/example.sts @@ -1,3 +1,4 @@ do{ - printl random; + x: 50; + printl randomrange => min: 0, max: x; } \ No newline at end of file diff --git a/src/include/stsrand.h b/src/include/stsrand.h index 7d76b61..25503a6 100644 --- a/src/include/stsrand.h +++ b/src/include/stsrand.h @@ -6,7 +6,7 @@ #include "variables.h" -int genrandomintfromrange(std::vector prs, int *line); +int genrandomintfromrange(sts *s, std::vector vars, int *line); bool randombool(); #endif \ No newline at end of file diff --git a/src/values/getvals.cc b/src/values/getvals.cc index d608111..c8ef552 100644 --- a/src/values/getvals.cc +++ b/src/values/getvals.cc @@ -74,7 +74,7 @@ stsvars sts::getval(std::vector vars, int *line) { else if (prs[y] == "randomrange") { v.type = 'i'; - v.val = std::to_string(genrandomintfromrange(prs, &y)); + v.val = std::to_string(genrandomintfromrange(this, vars, &y)); *line = y; return v; } diff --git a/src/values/random.cc b/src/values/random.cc index b6d2bf3..2688bac 100644 --- a/src/values/random.cc +++ b/src/values/random.cc @@ -1,25 +1,27 @@ #include "../include/stormscript.h" -int genrandomintfromrange(std::vector prs, int *line) { +int genrandomintfromrange(sts *s, std::vector vars, int *line) { long int ut = static_cast (time(0)); // cast unix epoch to long int int y = *line; int range[2]; // range will store the min and max values + std::vector prs = s->prs; + srand(ut); // seed rand() with unix epoch y+=2; if (prs[y] == "min:") - range[0] = std::stoi(prs[y+1]); + range[0] = std::stoi(s->getval(vars, new int(y+1)).val); else if (prs[y] == "max:") - range[1] = std::stoi(prs[y+1]); + range[1] = std::stoi(s->getval(vars, new int(y+1)).val); y+=2; if (prs[y] == "min:") - range[0] = std::stoi(prs[y+1]); + range[0] = std::stoi(s->getval(vars, new int(y+1)).val); else if (prs[y] == "max:") - range[1] = std::stoi(prs[y+1]); + range[1] = std::stoi(s->getval(vars, new int(y+1)).val); y++; @@ -32,4 +34,5 @@ bool randombool() { long int ut = static_cast (time(0)); srand(ut); return rand() % 2; -} \ No newline at end of file +} + From e244c938372018225155a2b9ec93b6e8a23f1205 Mon Sep 17 00:00:00 2001 From: stormprograms Date: Wed, 27 Feb 2019 22:13:44 -0500 Subject: [PATCH 25/33] adding wait command --- example/example.sts | 5 +++-- src/interpreter/exec.cc | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/example/example.sts b/example/example.sts index 1d105a6..173925f 100755 --- a/example/example.sts +++ b/example/example.sts @@ -1,4 +1,5 @@ do{ - x: 50; - printl randomrange => min: 0, max: x; + printl "Waiting"; + wait 10; + printl "I waited for 10 seconds"; } \ No newline at end of file diff --git a/src/interpreter/exec.cc b/src/interpreter/exec.cc index 927dd9f..223430a 100644 --- a/src/interpreter/exec.cc +++ b/src/interpreter/exec.cc @@ -131,6 +131,12 @@ void sts::exec(int *x, int function, std::vector *pclasstypes, std } else if (prs[y]=="sys") sys(&y, vars); + else if (prs[y] == "wait") { + string cmd = "sleep "; + cmd += prs[y+1]; + system(cmd.c_str()); + y++; + } else if ((prs[y]=="}") || (prs[y]=="loop")) { if (prs[y]=="loop"){ if (looped==0){ From 71ba75685ec1c185487658c57f6d860c3fcba03f Mon Sep 17 00:00:00 2001 From: stormprograms Date: Wed, 6 Mar 2019 16:43:31 -0500 Subject: [PATCH 26/33] wait function --- src/include/stormscript.h | 6 ++++++ src/interpreter/exec.cc | 4 +--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/include/stormscript.h b/src/include/stormscript.h index 42bc099..449427c 100755 --- a/src/include/stormscript.h +++ b/src/include/stormscript.h @@ -4,8 +4,14 @@ #if defined(_WIN32) #define PLATFORM "Windows" +#include + +void sleep(unsigned int seconds) { + Sleep(seconds * 1000); +} // define 2 different sleep functions for windows and POSIX systems #else #define PLATFORM "other" +#include #endif /* NOTE: diff --git a/src/interpreter/exec.cc b/src/interpreter/exec.cc index 223430a..d42cc1f 100644 --- a/src/interpreter/exec.cc +++ b/src/interpreter/exec.cc @@ -132,9 +132,7 @@ void sts::exec(int *x, int function, std::vector *pclasstypes, std else if (prs[y]=="sys") sys(&y, vars); else if (prs[y] == "wait") { - string cmd = "sleep "; - cmd += prs[y+1]; - system(cmd.c_str()); + sleep(std::stoi(getval(vars, new int(y+1)).val)); y++; } else if ((prs[y]=="}") || (prs[y]=="loop")) { From 26779f8e706ed6fb13f676e6c80f6f0f91ae5838 Mon Sep 17 00:00:00 2001 From: Adam Lazhar <39865721+Metr0Gn0me@users.noreply.github.com> Date: Wed, 6 Mar 2019 16:46:06 -0500 Subject: [PATCH 27/33] Update stormscript.h --- src/include/stormscript.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/include/stormscript.h b/src/include/stormscript.h index 449427c..d833df9 100755 --- a/src/include/stormscript.h +++ b/src/include/stormscript.h @@ -8,7 +8,7 @@ void sleep(unsigned int seconds) { Sleep(seconds * 1000); -} // define 2 different sleep functions for windows and POSIX systems +} #else #define PLATFORM "other" #include @@ -46,4 +46,4 @@ bool condition(sts *program, int *ln, std::vector vars); bool isint(string s); bool toBool(string s); -#endif \ No newline at end of file +#endif From 545ba34430f88d3705e8c7cb19c7de45ef71f378 Mon Sep 17 00:00:00 2001 From: Ethan Onstott Date: Wed, 6 Mar 2019 16:48:51 -0500 Subject: [PATCH 28/33] Update changelog-v0.6.0.md --- docs/changelogs/changelog-v0.6.0.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/changelogs/changelog-v0.6.0.md b/docs/changelogs/changelog-v0.6.0.md index 65757bd..e0cd35f 100644 --- a/docs/changelogs/changelog-v0.6.0.md +++ b/docs/changelogs/changelog-v0.6.0.md @@ -5,6 +5,7 @@ * StormScript now has modules, which allow you to run functions from other StormScript files. * use `random` to generate a random bool * use `randomrange => min, max;` to generate a random integer in range min, max +* use `wait INT` to sleep for `INT` seconds ## What's Fixed * else and else if statements were broken @@ -14,4 +15,4 @@ * Global variables couldn't be declared * comparisons using subscripts were broken * length did not change on modification -* `stsvars::glob` was considered to be true by some compilers, causing crash \ No newline at end of file +* `stsvars::glob` was considered to be true by some compilers, causing crash From dc4d0236ac6d0304216c1aef3ec35a916d40372e Mon Sep 17 00:00:00 2001 From: Adam Lazhar Date: Wed, 6 Mar 2019 17:17:22 -0500 Subject: [PATCH 29/33] Update stormscript.h --- src/include/stormscript.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/include/stormscript.h b/src/include/stormscript.h index d833df9..2f1fe05 100755 --- a/src/include/stormscript.h +++ b/src/include/stormscript.h @@ -5,10 +5,6 @@ #if defined(_WIN32) #define PLATFORM "Windows" #include - -void sleep(unsigned int seconds) { - Sleep(seconds * 1000); -} #else #define PLATFORM "other" #include From 3c2e34c805959f5c4cd4d062bfb4e50a1200acc3 Mon Sep 17 00:00:00 2001 From: Ethan Onstott Date: Wed, 6 Mar 2019 14:23:51 -0800 Subject: [PATCH 30/33] Update exec.cc --- src/interpreter/exec.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/interpreter/exec.cc b/src/interpreter/exec.cc index d42cc1f..5ebae18 100644 --- a/src/interpreter/exec.cc +++ b/src/interpreter/exec.cc @@ -132,7 +132,10 @@ void sts::exec(int *x, int function, std::vector *pclasstypes, std else if (prs[y]=="sys") sys(&y, vars); else if (prs[y] == "wait") { - sleep(std::stoi(getval(vars, new int(y+1)).val)); + if (PLATFORM == "Windows") + Sleep(std::stoi(getval(vars, new int(y+1)).val)); + else + sleep(std::stoi(getval(vars, new int(y+1)).val)); y++; } else if ((prs[y]=="}") || (prs[y]=="loop")) { From 59e8babd60416ca155e41edea1c2cfd38aaa7896 Mon Sep 17 00:00:00 2001 From: Ethan Onstott Date: Wed, 6 Mar 2019 14:28:56 -0800 Subject: [PATCH 31/33] Update stormscript.h --- src/include/stormscript.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/include/stormscript.h b/src/include/stormscript.h index 2f1fe05..4213db1 100755 --- a/src/include/stormscript.h +++ b/src/include/stormscript.h @@ -2,7 +2,7 @@ #ifndef STSCLASSES_H_ #define STSCLASSES_H_ -#if defined(_WIN32) +#if defined(__MINGW32__) #define PLATFORM "Windows" #include #else From aa0b37e5f4aa8734c041100dafab3a4b93861277 Mon Sep 17 00:00:00 2001 From: stormprograms Date: Thu, 7 Mar 2019 20:25:38 -0500 Subject: [PATCH 32/33] using preprocessor if statements to check platform --- src/include/stormscript.h | 4 ++-- src/interpreter/exec.cc | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/include/stormscript.h b/src/include/stormscript.h index 4213db1..36df6fc 100755 --- a/src/include/stormscript.h +++ b/src/include/stormscript.h @@ -3,10 +3,10 @@ #define STSCLASSES_H_ #if defined(__MINGW32__) -#define PLATFORM "Windows" +#define PLATFORM 1 #include #else -#define PLATFORM "other" +#define PLATFORM 0 #include #endif /* diff --git a/src/interpreter/exec.cc b/src/interpreter/exec.cc index 5ebae18..459ddb4 100644 --- a/src/interpreter/exec.cc +++ b/src/interpreter/exec.cc @@ -132,10 +132,11 @@ void sts::exec(int *x, int function, std::vector *pclasstypes, std else if (prs[y]=="sys") sys(&y, vars); else if (prs[y] == "wait") { - if (PLATFORM == "Windows") + #if PLATFORM == 1 Sleep(std::stoi(getval(vars, new int(y+1)).val)); - else + #else sleep(std::stoi(getval(vars, new int(y+1)).val)); + #endif y++; } else if ((prs[y]=="}") || (prs[y]=="loop")) { From 9df57d01aba8607dc4e4a950c84ddfd13a4e5093 Mon Sep 17 00:00:00 2001 From: Ethan Onstott Date: Thu, 7 Mar 2019 17:45:54 -0800 Subject: [PATCH 33/33] fixed sleep on windows --- src/include/stormscript.h | 2 +- src/interpreter/exec.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/include/stormscript.h b/src/include/stormscript.h index 36df6fc..d1abcf6 100755 --- a/src/include/stormscript.h +++ b/src/include/stormscript.h @@ -2,7 +2,7 @@ #ifndef STSCLASSES_H_ #define STSCLASSES_H_ -#if defined(__MINGW32__) +#if (defined(_WIN32)) || (defined(__MINGW32__)) #define PLATFORM 1 #include #else diff --git a/src/interpreter/exec.cc b/src/interpreter/exec.cc index 459ddb4..6d75316 100644 --- a/src/interpreter/exec.cc +++ b/src/interpreter/exec.cc @@ -133,7 +133,7 @@ void sts::exec(int *x, int function, std::vector *pclasstypes, std sys(&y, vars); else if (prs[y] == "wait") { #if PLATFORM == 1 - Sleep(std::stoi(getval(vars, new int(y+1)).val)); + Sleep(std::stoi(getval(vars, new int(y+1)).val) * 1000); #else sleep(std::stoi(getval(vars, new int(y+1)).val)); #endif