Skip to content

Commit

Permalink
Merge pull request #61 from stormprograms/dev
Browse files Browse the repository at this point in the history
StormScript v0.6.0
  • Loading branch information
Metr0Gn0me authored Mar 8, 2019
2 parents d5415d5 + 62ebacb commit b42680f
Show file tree
Hide file tree
Showing 42 changed files with 413 additions and 61 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@ 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
src/stream/stsstream.cc
src/stream/loops.cc
src/stream/files.cc
src/values/stsdec.cc
src/values/man.cc
src/values/if.cc
src/values/getvals.cc
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)
set (StormScript_VERSION_MINOR 5)
set (StormScript_VERSION_MINOR 6)
install(TARGETS stormscript RUNTIME DESTINATION bin/)
14 changes: 6 additions & 8 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -11,10 +6,13 @@ pool:

steps:
- script: |
cmake CMakeLists.txt;
cmake .;
make;
mkdir build;
mv stormscript build;
install stormscript build/stormscript;
rm stormscript
displayName: 'Build'
- script: |
cd scripts;
./runtests.sh
displayName: 'make'
displayName: 'Test'
18 changes: 18 additions & 0 deletions docs/changelogs/changelog-v0.6.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# StormScript v0.6.0 "Fig"

## 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
* use `wait INT` to sleep for `INT` seconds

## 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.
* 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
* `stsvars::glob` was considered to be true by some compilers, causing crash
30 changes: 28 additions & 2 deletions docs/style.md → docs/development/style.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -64,4 +65,29 @@ source: [man.cc](/src/values/man.cc)


## Keywords
Use `'\n'` instead of `std::endl;` unless absolutely neccessary
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;
}
```
10 changes: 10 additions & 0 deletions docs/development/testing.md
Original file line number Diff line number Diff line change
@@ -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`
9 changes: 3 additions & 6 deletions example/example.sts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
do{
x: 3;
y: 10;
while x not y {
x+: 1;
printl x;
}
printl "Waiting";
wait 10;
printl "I waited for 10 seconds";
}
2 changes: 1 addition & 1 deletion scripts/runtests.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
cd ..
cmake CMakeLists.txt
make
make $1
install stormscript build/stormscript
rm stormscript
printf "\n \n \n"
Expand Down
4 changes: 3 additions & 1 deletion scripts/writenewouts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: stormscript # you probably want to 'snapcraft register <name>'
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.
Expand Down
2 changes: 1 addition & 1 deletion src/core/stormscript.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 2 additions & 0 deletions src/include/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class sts
string runlibfunc(string name, int *line, std::vector<stsvars> vars); // run library function
bool valchange(std::vector<stsvars> * pvars, std::vector<stsclasstype> *classtypes, int * ln);
stsvars math(int *y, std::vector<stsvars> vars);
void readfile(int y, stsvars *v); // file reading operations
void writefile(int y); // file writing operations
};

std::vector<stsvars> whileloop(sts *script, std::vector<stsvars> variables, int y);
Expand Down
2 changes: 2 additions & 0 deletions src/include/includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <cctype>
#include <cstdlib>
#include <memory>
#include <random>
#include <time.h>

/*
Let's forward declare these classes for the files that use them
Expand Down
11 changes: 11 additions & 0 deletions src/include/modules.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once
#ifndef MODULES_H_
#define MODULES_H_

#include "includes.h"
#include "core.h"

// Module read function
std::vector<string> readmod(string name);

#endif
21 changes: 16 additions & 5 deletions src/include/stormscript.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
#ifndef STSCLASSES_H_
#define STSCLASSES_H_

#if defined(_WIN32)
#define PLATFORM "Windows"
#if (defined(_WIN32)) || (defined(__MINGW32__))
#define PLATFORM 1
#include <windows.h>
#else
#define PLATFORM "other"
#define PLATFORM 0
#include <unistd.h>
#endif

/*
NOTE:
Place All StormScript headers here separated by 2 lines.
*/
#include "includes.h"


Expand All @@ -22,6 +27,12 @@

#include "functions.h"


#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
Expand All @@ -31,4 +42,4 @@ bool condition(sts *program, int *ln, std::vector<stsvars> vars);
bool isint(string s);
bool toBool(string s);

#endif
#endif
12 changes: 12 additions & 0 deletions src/include/stsrand.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once
#ifndef STSRAND_H_
#define STSRAND_H_

#include "includes.h"

#include "variables.h"

int genrandomintfromrange(sts *s, std::vector<stsvars> vars, int *line);
bool randombool();

#endif
2 changes: 1 addition & 1 deletion src/include/variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class stsvars {
std::vector<stsvars> vals;

int length;
bool glob;
bool glob = false;
string name;

void assignlist(sts *script, std::vector<stsvars> vars, int *line);
Expand Down
20 changes: 16 additions & 4 deletions src/interpreter/exec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void sts::exec(int *x, int function, std::vector<stsclasstype> *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';
}
}
Expand Down Expand Up @@ -69,9 +69,13 @@ void sts::exec(int *x, int function, std::vector<stsclasstype> *pclasstypes, std
if (l)
cout << "\n";
}
else if (prs[y]=="exit") {
else if (prs[y]=="write") {
y++;
writefile(y);
y+= 2;
}
else if (prs[y]=="exit")
exit(0);
}
else if (prs[y]=="in") {
vars.resize(vars.size()+1);
y++;
Expand Down Expand Up @@ -101,6 +105,7 @@ void sts::exec(int *x, int function, std::vector<stsclasstype> *pclasstypes, std
e--;
y++;
}
y--;
}
else if (prs[y]=="if") {
endreq+=1;
Expand All @@ -126,6 +131,14 @@ void sts::exec(int *x, int function, std::vector<stsclasstype> *pclasstypes, std
}
else if (prs[y]=="sys")
sys(&y, vars);
else if (prs[y] == "wait") {
#if PLATFORM == 1
Sleep(std::stoi(getval(vars, new int(y+1)).val) * 1000);
#else
sleep(std::stoi(getval(vars, new int(y+1)).val));
#endif
y++;
}
else if ((prs[y]=="}") || (prs[y]=="loop")) {
if (prs[y]=="loop"){
if (looped==0){
Expand All @@ -151,7 +164,6 @@ void sts::exec(int *x, int function, std::vector<stsclasstype> *pclasstypes, std
}
}
}

for (int i = 0; i<ct.indexes.size(); i++) {
for (int z = 0; z<vars.size(); z++) {
if (vars[z].name == ct.tpe.variables[i].name) {
Expand Down
32 changes: 26 additions & 6 deletions src/interpreter/globscope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,41 @@ 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") || (prs[x] == "while")) {
x++;
endreq++;
}
else
x++;
}
x--;
if (prs[x]=="loop")
x+=2;
}
else if (prs[x]=="do"){
else if (prs[x] == "mod") {
//cout <<
std::vector<string> mod = readmod(prs[x+1]);
std::vector<string>::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<stsvars>({}));
else if (prs[x].back() == ':') {
globvars.push_back(declare(&x, &globvars));
for (int i = 0; i<globvars.size(); i++)
globvars[i].glob = true;
}
else if ((prs[x]!=";") && (prs[x][0]!='\0')){
else if ((prs[x]!=";") && (prs[x][0]!='\0'))
error(1, prs[x]);
}
}
}
Loading

0 comments on commit b42680f

Please sign in to comment.