From 61e5e114227bad83c897afd6fd3e04e7db7cc379 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Sun, 10 Nov 2019 22:44:00 +0100 Subject: [PATCH 1/1] :book: initial commit [skip ci] --- .gitignore | 2 + Makefile | 26 ++++++ docs/Benchmarks.mdr | 89 +++++++++++++++++++ docs/BuildingTheDocs.mdr | 7 ++ docs/Contributing/ContributingTranslation.mdr | 51 +++++++++++ docs/Contributing/index.mdr | 1 + docs/Contributing/list | 2 + docs/Overview/BUILDING.mdr | 38 ++++++++ docs/Overview/First_Steps/Configure.mdr | 18 ++++ docs/Overview/First_Steps/InstallingGwion.mdr | 39 ++++++++ docs/Overview/First_Steps/index.mdr | 1 + docs/Overview/First_Steps/list | 3 + docs/Overview/Keywords.mdr | 31 +++++++ docs/Overview/Make.mdr | 7 ++ docs/Overview/SpecialWords.mdr | 6 ++ docs/Overview/Testing.mdr | 28 ++++++ docs/Overview/declaration.mdr | 34 +++++++ docs/Overview/globalvalues.mdr | 16 ++++ docs/Overview/index.mdr | 1 + docs/Overview/list | 9 ++ docs/Reference/ControlFlow/ControlFlow.mdr | 4 + docs/Reference/ControlFlow/Loops.mdr | 1 + docs/Reference/ControlFlow/Repeat.mdr | 21 +++++ docs/Reference/ControlFlow/forloop.mdr | 63 +++++++++++++ docs/Reference/ControlFlow/index.mdr | 1 + docs/Reference/ControlFlow/list | 6 ++ docs/Reference/ControlFlow/whileuntil.mdr | 23 +++++ docs/Reference/Extending/WIP_Driver.mdr | 9 ++ docs/Reference/Extending/WIP_Plugins.mdr | 68 ++++++++++++++ docs/Reference/Extending/index.mdr | 1 + docs/Reference/Extending/list | 3 + docs/Reference/Functions/Lambdas.mdr | 37 ++++++++ docs/Reference/Functions/Variadic.mdr | 19 ++++ docs/Reference/Functions/function.mdr | 19 ++++ docs/Reference/Functions/index.mdr | 1 + docs/Reference/Functions/list | 4 + docs/Reference/Preprocessor.mdr | 1 + docs/Reference/Types/Enums.mdr | 21 +++++ docs/Reference/Types/Function_Pointers.mdr | 1 + docs/Reference/Types/Primitives.mdr | 1 + docs/Reference/Types/Typedefs.mdr | 1 + docs/Reference/Types/Unions.mdr | 1 + docs/Reference/Types/index.mdr | 1 + docs/Reference/Types/list | 6 ++ docs/Reference/index.mdr | 1 + docs/Reference/list | 6 ++ docs/config.mk.orig | 32 +++++++ docs/custom.css | 10 +++ docs/index.mdr | 23 +++++ docs/list | 8 ++ scripts/ensure.sh | 43 +++++++++ scripts/mdr2mdbook.sh | 40 +++++++++ scripts/run.sh | 13 +++ scripts/summary.sh | 45 ++++++++++ scripts/test.sh | 29 ++++++ scripts/watch.sh | 10 +++ 56 files changed, 982 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 docs/Benchmarks.mdr create mode 100644 docs/BuildingTheDocs.mdr create mode 100644 docs/Contributing/ContributingTranslation.mdr create mode 100644 docs/Contributing/index.mdr create mode 100644 docs/Contributing/list create mode 100644 docs/Overview/BUILDING.mdr create mode 100644 docs/Overview/First_Steps/Configure.mdr create mode 100644 docs/Overview/First_Steps/InstallingGwion.mdr create mode 100644 docs/Overview/First_Steps/index.mdr create mode 100644 docs/Overview/First_Steps/list create mode 100644 docs/Overview/Keywords.mdr create mode 100644 docs/Overview/Make.mdr create mode 100644 docs/Overview/SpecialWords.mdr create mode 100644 docs/Overview/Testing.mdr create mode 100644 docs/Overview/declaration.mdr create mode 100644 docs/Overview/globalvalues.mdr create mode 100644 docs/Overview/index.mdr create mode 100644 docs/Overview/list create mode 100644 docs/Reference/ControlFlow/ControlFlow.mdr create mode 100644 docs/Reference/ControlFlow/Loops.mdr create mode 100644 docs/Reference/ControlFlow/Repeat.mdr create mode 100644 docs/Reference/ControlFlow/forloop.mdr create mode 100644 docs/Reference/ControlFlow/index.mdr create mode 100644 docs/Reference/ControlFlow/list create mode 100644 docs/Reference/ControlFlow/whileuntil.mdr create mode 100644 docs/Reference/Extending/WIP_Driver.mdr create mode 100644 docs/Reference/Extending/WIP_Plugins.mdr create mode 100644 docs/Reference/Extending/index.mdr create mode 100644 docs/Reference/Extending/list create mode 100644 docs/Reference/Functions/Lambdas.mdr create mode 100644 docs/Reference/Functions/Variadic.mdr create mode 100644 docs/Reference/Functions/function.mdr create mode 100644 docs/Reference/Functions/index.mdr create mode 100644 docs/Reference/Functions/list create mode 100644 docs/Reference/Preprocessor.mdr create mode 100644 docs/Reference/Types/Enums.mdr create mode 100644 docs/Reference/Types/Function_Pointers.mdr create mode 100644 docs/Reference/Types/Primitives.mdr create mode 100644 docs/Reference/Types/Typedefs.mdr create mode 100644 docs/Reference/Types/Unions.mdr create mode 100644 docs/Reference/Types/index.mdr create mode 100644 docs/Reference/Types/list create mode 100644 docs/Reference/index.mdr create mode 100644 docs/Reference/list create mode 100644 docs/config.mk.orig create mode 100644 docs/custom.css create mode 100644 docs/index.mdr create mode 100644 docs/list create mode 100644 scripts/ensure.sh create mode 100644 scripts/mdr2mdbook.sh create mode 100644 scripts/run.sh create mode 100644 scripts/summary.sh create mode 100644 scripts/test.sh create mode 100644 scripts/watch.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..09b67f03 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +book +book.toml diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..935c8c63 --- /dev/null +++ b/Makefile @@ -0,0 +1,26 @@ +serve: ensure + @sh scripts/run.sh + +build: ensure + @mdbook build + +book: build + +deploy: book + @git subtree push --prefix book origin gh-pages + +ensure: + @sh scripts/ensure.sh + +clean: + @[ -d src ] && mdbook clean + +clean-tests: + @rm -rf *.gw log vlog + +clean-all: clean clean-tests + @rm -rf src + +.SUFFIXES: .gw .test +.gw.test: + @sh scripts/test.sh $< "${CONTAINS}" diff --git a/docs/Benchmarks.mdr b/docs/Benchmarks.mdr new file mode 100644 index 00000000..34a60725 --- /dev/null +++ b/docs/Benchmarks.mdr @@ -0,0 +1,89 @@ +# Benchmarks + +We'll need a bash script + +
+ +### and a gnuplot script + +
+ +## Show the results +Then just run it +@exec bash benchmark.sh; rm bench.plot benchmark.sh diff --git a/docs/BuildingTheDocs.mdr b/docs/BuildingTheDocs.mdr new file mode 100644 index 00000000..99190c1c --- /dev/null +++ b/docs/BuildingTheDocs.mdr @@ -0,0 +1,7 @@ +# How this doc is build + +## mdr + +## makefile + +## mkdocs diff --git a/docs/Contributing/ContributingTranslation.mdr b/docs/Contributing/ContributingTranslation.mdr new file mode 100644 index 00000000..2cd13df4 --- /dev/null +++ b/docs/Contributing/ContributingTranslation.mdr @@ -0,0 +1,51 @@ +# Contributing translations + +First off, thank you for considering translating gwion. + +Thanks to the build system, you're gonna get on tracks fast. + + +> You might want to export TRANSLATION_TARGET, +so you don't have to set it on the command line for commands requiring it +`export TRANSLATION_TARGET="xxx"` + +## 1) Init the translation language + +You have to make sure there is a directory for your target language (e.g.: fr, en, es_ES ...). + +``` sh +make translation-init TRANSLATION_TARGET= +``` + +Where `` is your language of choice. +It will fail if your language already exists, but this is not a problem. + +## 2) Edit + +Next, you should adjust the translations. +What about using your favorite editor? + +``` sh +make translation-edit TRANSLATION_TARGET= +``` + +## 3) Update + +Maybe the sources changed, and there is more message to translate? + +``` sh +make translation-update +``` + +This will update all languages. +You can now get back to [step 2](#2-Edit). + +## Add to VCS + +It's now time to add your changes to the package + +``` sh +make translation-commit TRANSLATION_TARGET= +``` + +Now please submit a pull request. diff --git a/docs/Contributing/index.mdr b/docs/Contributing/index.mdr new file mode 100644 index 00000000..854139a3 --- /dev/null +++ b/docs/Contributing/index.mdr @@ -0,0 +1 @@ +# Contributing diff --git a/docs/Contributing/list b/docs/Contributing/list new file mode 100644 index 00000000..98402afc --- /dev/null +++ b/docs/Contributing/list @@ -0,0 +1,2 @@ +index.md +ContributingTranslation.md diff --git a/docs/Overview/BUILDING.mdr b/docs/Overview/BUILDING.mdr new file mode 100644 index 00000000..1babfe52 --- /dev/null +++ b/docs/Overview/BUILDING.mdr @@ -0,0 +1,38 @@ +# Build / Configure Gwion + +## Configure +### gwion-util + + * `USE_MEMCHECK`: compile with debug flags (`-g`) and enable asserts + * `USE_COVERAGE`: add coverage instrumentation + + +## Make +Basically, all that is left to do is +```sh +make +``` +The only environment variable affecting the operation is `PREFIX` + +Except `--(no-)double`, everything can be set when running make, +using environment variables. + +Drivers can be set on using, e.g. for *alsa* : `ALSA_D=1` or `ALSA_D=on`. +In the same way, then can be disabled with `ALSA_D=0` or `ALSA_D=off` + +### Running tests +```bash +make tests +``` +to run all tests, or +```bash +bash util/test.sh my_file_or_directory (.. other files/dirs ...) +``` +to run specific ones. +look [here](#testing.md) for more. +## Install +*maybe as root* +```sh +make install +``` +The only environment variable affecting the operation is `PREFIX` diff --git a/docs/Overview/First_Steps/Configure.mdr b/docs/Overview/First_Steps/Configure.mdr new file mode 100644 index 00000000..b05d398b --- /dev/null +++ b/docs/Overview/First_Steps/Configure.mdr @@ -0,0 +1,18 @@ +# Configuring Gwion + +## util/config.mk + +double + +gettext + +memcheck + +lto + +coverage + +## ast/config.mk + +## config.mk +Here are a few choices left diff --git a/docs/Overview/First_Steps/InstallingGwion.mdr b/docs/Overview/First_Steps/InstallingGwion.mdr new file mode 100644 index 00000000..b64f4273 --- /dev/null +++ b/docs/Overview/First_Steps/InstallingGwion.mdr @@ -0,0 +1,39 @@ +# Installing gwion + +## Get the sources + +The source is accessible on [github](https:#!github.com). + +Provided you have git installed, you can get it with: + +``` sh +git clone https:#!github.com/fennecdjay/gwion +``` + +then change to the source directory +``` sh +cd gwion +``` + +### Don't forget submodules + +You'll need the sources for all base module +``` sh +git submodule update --init util ast +``` + +> At this point, you might want to configure the build. + In this case, have a look at the [configuration page](Configure.md) + + +## Build the libraries and program +``` sh +make +``` + +## Install the package + +``` sh +make install +``` +> You may need root privilege to do this. diff --git a/docs/Overview/First_Steps/index.mdr b/docs/Overview/First_Steps/index.mdr new file mode 100644 index 00000000..3790de05 --- /dev/null +++ b/docs/Overview/First_Steps/index.mdr @@ -0,0 +1 @@ +# First Steps diff --git a/docs/Overview/First_Steps/list b/docs/Overview/First_Steps/list new file mode 100644 index 00000000..3f45f838 --- /dev/null +++ b/docs/Overview/First_Steps/list @@ -0,0 +1,3 @@ +index.md +Configure.md +InstallingGwion.md diff --git a/docs/Overview/Keywords.mdr b/docs/Overview/Keywords.mdr new file mode 100644 index 00000000..0f8af7ce --- /dev/null +++ b/docs/Overview/Keywords.mdr @@ -0,0 +1,31 @@ +# Keywords + + * fun/function + * operator + * return + * goto + * switch/case/default + * if/else + * break/continue + * until/do/while/for/repeat + + + + + * global/static + * private/protect + * const + + * new + * spork + * fork + * typeof + + * typedef + * class + * dtor + * extends + * enum + * union + + * auto diff --git a/docs/Overview/Make.mdr b/docs/Overview/Make.mdr new file mode 100644 index 00000000..45a5452d --- /dev/null +++ b/docs/Overview/Make.mdr @@ -0,0 +1,7 @@ +# Makefile + +## Basic operations + +## translations + +## Docs diff --git a/docs/Overview/SpecialWords.mdr b/docs/Overview/SpecialWords.mdr new file mode 100644 index 00000000..3b4286a9 --- /dev/null +++ b/docs/Overview/SpecialWords.mdr @@ -0,0 +1,6 @@ +# Special Values + + * me + * this + * vararg + * maybe diff --git a/docs/Overview/Testing.mdr b/docs/Overview/Testing.mdr new file mode 100644 index 00000000..5dde62b4 --- /dev/null +++ b/docs/Overview/Testing.mdr @@ -0,0 +1,28 @@ +# Tests +[test.sh](https:#!github.com/fennecdjay/Gwion/blob/dev/util/test.sh) +requires [valgrind](http:#!valgrind.org/) +there are two kinds of tests: + * [gwion](#gwion-tests) + * [bash](#bash-tests) + +## Gwion tests +those tests are just gwion (.gw) files, handling special comments: + * `#! [skip]` (*optionally* followed by reason to skip) + * `#! [todo]` (*optionally* followed by reason to delay testing) + * `#! [contains]` followed by string to match + * `#! [excludes]` followed by string not to match + +## Shell test +those tests are just bash (.sh) files. +they should start with this snippet +```bash +#!/bin/bash +# [test] #5 +n=0 +[ "$1" ] && n="$1" +[ "$n" -eq 0 ] && n=1 +source tests/sh/common.sh +``` + +## TODO + [ ] `bailout` system for early exit on failure diff --git a/docs/Overview/declaration.mdr b/docs/Overview/declaration.mdr new file mode 100644 index 00000000..82a95800 --- /dev/null +++ b/docs/Overview/declaration.mdr @@ -0,0 +1,34 @@ +# Declarations + +## Basics + +Declaring a primitive or an object is quite straight forward: +@``` decl0.gw +int i; +Object o; +<<< i, " ", o >>>; +@``` +@exec make decl0.test + +## Declaring a reference +However ... +@``` decl1.gw +Object @ref; +<<< "Reference points to no object yet: ", ref >>>; +#!Object o @=> ref; +new Object @=> ref; +<<< "But now it does: ", ref >>>; +@``` +@exec make decl1.test + +## Arrays + +### array as refs + +@``` decl2.gw +int ref[]; +<<< ref >>>; +new int[2] @=> ref; +<<< ref >>>; +@``` +@exec make decl2.test diff --git a/docs/Overview/globalvalues.mdr b/docs/Overview/globalvalues.mdr new file mode 100644 index 00000000..81566954 --- /dev/null +++ b/docs/Overview/globalvalues.mdr @@ -0,0 +1,16 @@ +# Global Values + + * adc + * blackhole + * dac + * pi + * null + * samp + * ms + * second + * hour + * me + * this + * \__func__ + * \__file__ + * \__line__ diff --git a/docs/Overview/index.mdr b/docs/Overview/index.mdr new file mode 100644 index 00000000..07dd0c5c --- /dev/null +++ b/docs/Overview/index.mdr @@ -0,0 +1 @@ +# Overview diff --git a/docs/Overview/list b/docs/Overview/list new file mode 100644 index 00000000..d54e22e8 --- /dev/null +++ b/docs/Overview/list @@ -0,0 +1,9 @@ +index.md +BUILDING.md +declaration.md +First_Steps +globalvalues.md +Keywords.md +Make.md +SpecialWords.md +Testing.md diff --git a/docs/Reference/ControlFlow/ControlFlow.mdr b/docs/Reference/ControlFlow/ControlFlow.mdr new file mode 100644 index 00000000..2e9c1854 --- /dev/null +++ b/docs/Reference/ControlFlow/ControlFlow.mdr @@ -0,0 +1,4 @@ +# Control Flow + +## Repeats +let start simple ;-) diff --git a/docs/Reference/ControlFlow/Loops.mdr b/docs/Reference/ControlFlow/Loops.mdr new file mode 100644 index 00000000..4b787b4b --- /dev/null +++ b/docs/Reference/ControlFlow/Loops.mdr @@ -0,0 +1 @@ +# Loops diff --git a/docs/Reference/ControlFlow/Repeat.mdr b/docs/Reference/ControlFlow/Repeat.mdr new file mode 100644 index 00000000..37124bb6 --- /dev/null +++ b/docs/Reference/ControlFlow/Repeat.mdr @@ -0,0 +1,21 @@ +# the Repeat keyword +let start simple ;-) +The easiest way to do an action repeatidly in Gwion is, ... the **repeat** keyword! + +## Very basic example +@``` repeat.gw +repeat(3) + <<< "Hello, world!" >>>; +@``` +@exec make -s CONTAINS="Hello" repeat.test + +## Block example +of course this also works with a block code. + +@``` repeat2.gw +repeat(3) { + maybe ? "You" : "Me" => string s; + <<< "Hello, ", s, "!" >>>; +} +@``` +@exec make -s CONTAINS="Hello" repeat2.test diff --git a/docs/Reference/ControlFlow/forloop.mdr b/docs/Reference/ControlFlow/forloop.mdr new file mode 100644 index 00000000..52597f18 --- /dev/null +++ b/docs/Reference/ControlFlow/forloop.mdr @@ -0,0 +1,63 @@ +# For Loops +**For** loops in Gwion is pretty similar to classic **C** syntax + +## basic loops +@``` forloop0.gw +for(int i; i < 3; ++i) + <<< i >>>; +@``` +@exec make -s forloop0.test + +Of course, it also works with a block of code. + +@``` forloop2.gw +for(int i; i < 3; ++i) { + i/2 => float f1; + i/2. => float f2; + <<< i, " " , f1, " ", f2 >>>; +} +@``` +@exec make -s forloop2.test + +## Nested Loops +@``` forloop3.gw +int array[3][4]; + +for(int i; i < 3; ++i) { + for(int j; j < 4; ++j) { + <<< array[i][j] >>>; + } +} +@``` +@exec make -s forloop3.test + +### Auto Loops + +#### Simple auto loop +@``` forloop4.gw +int array[2][3]; +for(auto a: array) { + <<< a >>>; + for(auto b: a) + <<< b >>>; +} +@``` +@exec make -s forloop4.test + +### Auto Pointer loop +With the simple auto loop, you only get the value in the array. +If you want to change it, you need a pointer + +@``` forloop5.gw +int array[2][3]; +int i; +for(auto a: array) { + for(auto @b: a) + <<< ++i => *b >>>; +} +for(auto a: array) { + for(auto @b: a) + <<< *b >>>; +} +@``` +@exec make -s forloop5.test diff --git a/docs/Reference/ControlFlow/index.mdr b/docs/Reference/ControlFlow/index.mdr new file mode 100644 index 00000000..0ca4f252 --- /dev/null +++ b/docs/Reference/ControlFlow/index.mdr @@ -0,0 +1 @@ +# Control Flow diff --git a/docs/Reference/ControlFlow/list b/docs/Reference/ControlFlow/list new file mode 100644 index 00000000..465d0ab8 --- /dev/null +++ b/docs/Reference/ControlFlow/list @@ -0,0 +1,6 @@ +index.md +ControlFlow.md +forloop.md +Loops.md +Repeat.md +whileuntil.md diff --git a/docs/Reference/ControlFlow/whileuntil.mdr b/docs/Reference/ControlFlow/whileuntil.mdr new file mode 100644 index 00000000..04bf9c36 --- /dev/null +++ b/docs/Reference/ControlFlow/whileuntil.mdr @@ -0,0 +1,23 @@ +# Loops + +@``` while0.gw +while(true) { + if(maybe) + break; + <<< "running..." >>>; +} +@``` +@exec make -s while0.test + +well this may output nothing... +lets try + +@``` while1.gw +<<< maybe >>>; +do{ + if(maybe) + break; + <<< "running..." >>>; +} while(true); +@``` +@exec make -s while1.test diff --git a/docs/Reference/Extending/WIP_Driver.mdr b/docs/Reference/Extending/WIP_Driver.mdr new file mode 100644 index 00000000..20478632 --- /dev/null +++ b/docs/Reference/Extending/WIP_Driver.mdr @@ -0,0 +1,9 @@ +# Giving gwion a new driver + +## basics + +> in order to use GWION_CTL ... + +# concept + +# upd driver diff --git a/docs/Reference/Extending/WIP_Plugins.mdr b/docs/Reference/Extending/WIP_Plugins.mdr new file mode 100644 index 00000000..cd1822fd --- /dev/null +++ b/docs/Reference/Extending/WIP_Plugins.mdr @@ -0,0 +1,68 @@ +# Writing a Gwion plugin + +> THIS IS OUTDATED. please look at the source code in src/lib/ instead + + * [getting started] + +## Getting started +use the script + +### headers +``` +#include "vm.h" +#include "instr.h" +#include "import.h +``` + + +### Class +Define the type: +``` +struct Type_ t_mytype = { "MyType", SZ_INT, &t_object}; +``` +> every type extending t_object should have SZ_INT + +### Handling Constructors and Destructors +#### CTOR +``` +CTOR(mytype_ctor) { + /* constructor code here */ +} +``` +#### DTOR +``` +DTOR(mytype_dtor) { + /* destructor code here */ +} +``` + +those macros provide two variables: + * `o`: the *M_Object* for the (con/des)tructor + * `shred`: the *VM_Shred* for the (con/des)tructor + +``` +CHECK_BB(import_class_begin(env, &t_mytpe, env->global_nspc, mytype_ctor, mytype_dtor)) +``` +#### variable +declare a `m_int`. coding convention require + * a leading *_o* + * a following *_type_* +```c +m_int o_mytype_myvaroffset; +``` +#### function +```c +/* declare a member function */ +MFUN(mytype_memberfunction) { + /* code here */ +} + +SFUN(mtype_staticfunction) { + /* code here */ +} +``` + +#### operator + +### Import function + diff --git a/docs/Reference/Extending/index.mdr b/docs/Reference/Extending/index.mdr new file mode 100644 index 00000000..a02bcc3d --- /dev/null +++ b/docs/Reference/Extending/index.mdr @@ -0,0 +1 @@ +# Extending diff --git a/docs/Reference/Extending/list b/docs/Reference/Extending/list new file mode 100644 index 00000000..61bdf515 --- /dev/null +++ b/docs/Reference/Extending/list @@ -0,0 +1,3 @@ +index.md +WIP_Driver.md +WIP_Plugins.md diff --git a/docs/Reference/Functions/Lambdas.mdr b/docs/Reference/Functions/Lambdas.mdr new file mode 100644 index 00000000..ce03cd8a --- /dev/null +++ b/docs/Reference/Functions/Lambdas.mdr @@ -0,0 +1,37 @@ +# Lambda + +## Overview + +Simply put, *lambda*s are anonymous functions. + +The syntax to create them is simple: +``` +\ variable0 variable1 ... { your code here } +``` +You can even use it to +### Call a function just once +@``` lambda_call0.gw +\ i { <<< "passed '", i, "'" >>>; }(3); +@``` +@exec make -s CONTAINS="passed '3'" lambda_call0.test + + +## Use case + +### Passing to a function pointer +@``` lambda_fptr0.gw +typedef void fptr_t(int); +\ i { <<< "passed '", i, "'" >>>; } @=> fptr_t fptr; +fptr(4); +@``` +@exec make -s CONTAINS="passed '4'" lambda_fptr0.test + +### As Argument to Functions +@``` lambda_args0.gw +typedef void fptr_t(int); +fun void test(fptr_t fptr) { + fptr(5); +} +test(\ i { <<< "passed '", i, "'" >>>; }); +@``` +@exec make -s CONTAINS="passed '5'" lambda_args0.test diff --git a/docs/Reference/Functions/Variadic.mdr b/docs/Reference/Functions/Variadic.mdr new file mode 100644 index 00000000..d3e1fe1c --- /dev/null +++ b/docs/Reference/Functions/Variadic.mdr @@ -0,0 +1,19 @@ +# Variadic functions + +> A function whoses arity is not fixed. + +Well, a function that takes a fixed number of arguments, and additionnal ones. + +## a simple example +@``` variadic.gw +fun void variadic_test(int i, ...) { + <<< "first argument is ", i >>>; + vararg.start; + <<< "\tadditionnal argument", vararg.i >>>; + vararg.end; +} +variadic_test(1); +variadic_test(1, 2); +variadic_test(1, 2, 3); +@``` +@exec make variadic.test diff --git a/docs/Reference/Functions/function.mdr b/docs/Reference/Functions/function.mdr new file mode 100644 index 00000000..2fab4d37 --- /dev/null +++ b/docs/Reference/Functions/function.mdr @@ -0,0 +1,19 @@ +# Functions + +## a simple (commented example) + +@``` function0.gw +#! declare function 'test_function' +#! with return type int +#! taking an int as argument +fun int test_function(int arg) { + #! return the argument + 2 + return arg + 2; +} + +#! now call the function (and debug print the result) +<<< test_function(0) >>>; +#! or use alternate syntax +<<< 1 => test_function >>>; +@``` +@exec make -s function0.test diff --git a/docs/Reference/Functions/index.mdr b/docs/Reference/Functions/index.mdr new file mode 100644 index 00000000..0c5faf50 --- /dev/null +++ b/docs/Reference/Functions/index.mdr @@ -0,0 +1 @@ +# Functions diff --git a/docs/Reference/Functions/list b/docs/Reference/Functions/list new file mode 100644 index 00000000..5a351365 --- /dev/null +++ b/docs/Reference/Functions/list @@ -0,0 +1,4 @@ +index.md +function.md +Lambdas.md +Variadic.md diff --git a/docs/Reference/Preprocessor.mdr b/docs/Reference/Preprocessor.mdr new file mode 100644 index 00000000..e4e9d832 --- /dev/null +++ b/docs/Reference/Preprocessor.mdr @@ -0,0 +1 @@ +# Gwion Preprocessor diff --git a/docs/Reference/Types/Enums.mdr b/docs/Reference/Types/Enums.mdr new file mode 100644 index 00000000..8759ae31 --- /dev/null +++ b/docs/Reference/Types/Enums.mdr @@ -0,0 +1,21 @@ +# Enums + +For those who don't know about enumerated types, +you can read about those +[here](https://www.geeksforgeeks.org/enumeration-enum-c) and +[here](https://en.wikipedia.org/wiki/Enumerated_type) + +## Enums in gwion +You simply use an enum like this +``` enum0.gw +enum Optionnal_name { + zero, one, two +}; +<<< zero, one, two >>>; +``` + +When inside a class, +Enums are automatically declared **static**, +but they accept **private** or **protect** specifiers. + +When not in a class, they can be made `global` diff --git a/docs/Reference/Types/Function_Pointers.mdr b/docs/Reference/Types/Function_Pointers.mdr new file mode 100644 index 00000000..9f45ff3a --- /dev/null +++ b/docs/Reference/Types/Function_Pointers.mdr @@ -0,0 +1 @@ +# Function Pointers diff --git a/docs/Reference/Types/Primitives.mdr b/docs/Reference/Types/Primitives.mdr new file mode 100644 index 00000000..7d279218 --- /dev/null +++ b/docs/Reference/Types/Primitives.mdr @@ -0,0 +1 @@ +# Primitive types diff --git a/docs/Reference/Types/Typedefs.mdr b/docs/Reference/Types/Typedefs.mdr new file mode 100644 index 00000000..a64999b2 --- /dev/null +++ b/docs/Reference/Types/Typedefs.mdr @@ -0,0 +1 @@ +# Typedefs diff --git a/docs/Reference/Types/Unions.mdr b/docs/Reference/Types/Unions.mdr new file mode 100644 index 00000000..3ca0d197 --- /dev/null +++ b/docs/Reference/Types/Unions.mdr @@ -0,0 +1 @@ +# Union types diff --git a/docs/Reference/Types/index.mdr b/docs/Reference/Types/index.mdr new file mode 100644 index 00000000..f54cd23d --- /dev/null +++ b/docs/Reference/Types/index.mdr @@ -0,0 +1 @@ +# Types diff --git a/docs/Reference/Types/list b/docs/Reference/Types/list new file mode 100644 index 00000000..68c6cc00 --- /dev/null +++ b/docs/Reference/Types/list @@ -0,0 +1,6 @@ +index.md +Enums.md +Function_Pointers.md +Primitives.md +Typedefs.md +Unions.md diff --git a/docs/Reference/index.mdr b/docs/Reference/index.mdr new file mode 100644 index 00000000..cf5aa074 --- /dev/null +++ b/docs/Reference/index.mdr @@ -0,0 +1 @@ +# Reference diff --git a/docs/Reference/list b/docs/Reference/list new file mode 100644 index 00000000..c9916251 --- /dev/null +++ b/docs/Reference/list @@ -0,0 +1,6 @@ +index.md +ControlFlow +Extending +Functions +Types +Preprocessor.md diff --git a/docs/config.mk.orig b/docs/config.mk.orig new file mode 100644 index 00000000..9cecde9e --- /dev/null +++ b/docs/config.mk.orig @@ -0,0 +1,32 @@ +# tool to build the doc +DOCTOOL = mkdocs -q +DOCBUILD = build +DOCSERVE = serve + +# output box css +BACKGROUND = background-color:\#f2f2f2; +BORDER = border: 5px solid \#546e7a; +PADDING = padding: 10px; +MARGIN = margin-right: 20%; margin-left: 20%; +BORDER_RADIUS = -moz-border-radius: 15px; -webkit-border-radius: 15px; +CSS = "$(BACKGROUND) $(BORDER) $(PADDING) $(MARGIN) $(BORDER_RADIUS)" + +# output box status +NOTERM_OK= &\#10004; +NOTERM_NOT_OK= &\#10008; + +# terminal status +INTERM_OK = \033[32mOK\033[0m +INTERM_NOT_OK = \033[31mNOT OK\033[0m + +# valgrind +VALGRIND ?= valgrind +VALGRIND_LOG ?= vlog +VALGRIND_OPT += --leak-check=yes --log-file=${VALGRIND_LOG} + +## ensure no valgrind if requested +ifeq ($(VALGRIND), NO_VALGRIND) +VALGRIND = +VALGRIND_OPT = +endif + diff --git a/docs/custom.css b/docs/custom.css new file mode 100644 index 00000000..c143cd46 --- /dev/null +++ b/docs/custom.css @@ -0,0 +1,10 @@ +.mdr { + + +} + +footer { + text-align: center; + font-size: small; + font-style: italic; +} diff --git a/docs/index.mdr b/docs/index.mdr new file mode 100644 index 00000000..7b15865a --- /dev/null +++ b/docs/index.mdr @@ -0,0 +1,23 @@ +# Welcome to Gwion + +gwion is a easy yet powerful, strongly-timed programming language, + +## And now for the hello world + +So, as it is mandatory, here is the piece of code you're waiting +for: + +@``` helloworld.gw +<<< "Hello, World!" >>>; +@``` +@exec make -s CONTAINS="Hello, World!" helloworld.test + +## (Bag of) Features + * [single inheritance](https://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming)#Design_constraints) + * typedef (function pointers and type aliases) + * enums and unions + * templates (both class and functions) + * easy concurrency/async + * [lambdas](Reference/Functions/Lambdas.html) + * memoization + * [variadic](Reference/Functions/Variadic.html) functions diff --git a/docs/list b/docs/list new file mode 100644 index 00000000..74753ac7 --- /dev/null +++ b/docs/list @@ -0,0 +1,8 @@ +index.md + +Overview +Reference +Contributing + +Benchmarks.md +BuildingTheDocs.md diff --git a/scripts/ensure.sh b/scripts/ensure.sh new file mode 100644 index 00000000..2a644ea6 --- /dev/null +++ b/scripts/ensure.sh @@ -0,0 +1,43 @@ +#!/bin/sh +toml() { +cat < book.toml +[book] +authors = ["Jérémie Astor"] +title = "Gwion" + +[output.html] +additional-css = ["custom.css"] + +[output.html.fold] +enable = true +level = 0 +EOF +} + +css() { +cat < src/custom.css +.mdr { + color:var(--sidebar-active); + background-color:var(--sidebar-bg); + border: 5px solid var(--sidebar-fg); + padding: 10px; + margin-right: 20%; + margin-left: 20%; + moz-border-radius: 15px; + -webkit-border-radius: 15px; +} + +footer { + text-align: center; + font-size: small; + font-style: italic; +} +EOF +} +[ -d src ] || sh scripts/mdr2mdbook.sh + +[ -f src/SUMMARY.md ] || sh scripts/summary.sh > src/SUMMARY.md + +[ -f book.toml ] || toml + +[ -f src/custom.css ] || css diff --git a/scripts/mdr2mdbook.sh b/scripts/mdr2mdbook.sh new file mode 100644 index 00000000..0997cb6a --- /dev/null +++ b/scripts/mdr2mdbook.sh @@ -0,0 +1,40 @@ +footer() { + cat << EOF + + +
+built with mdBook
+You'll find the source here, Luke! +
+EOF +} + +mk_target() { + sed 's/```\(.*\)gw/```\1cpp/' $1 + footer +} + +ensure_dir() { + mkdir -p $(dirname $1) +} + +doc2src() { + mdr $1 || return + mdfile=${1::-1} + target=$(sed 's/docs/src/' <<< $mdfile) + ensure_dir $target + mk_target $mdfile > $target + rm $mdfile +} + +runall() { + list=$(find docs -type f -name "*.mdr") + for file in $list + do doc2src "$file" + done +} + +if [ $1 ] +then doc2src $1 +else runall +fi diff --git a/scripts/run.sh b/scripts/run.sh new file mode 100644 index 00000000..b21b7e50 --- /dev/null +++ b/scripts/run.sh @@ -0,0 +1,13 @@ +run() { + mdbook serve& + while true + do sh scripts/watch.sh + done +} + +clean() { + trap - SIGINT SIGTERM ERR; killall mdbook + exit 1 +} + +trap clean SIGINT SIGTERM ERR; run diff --git a/scripts/summary.sh b/scripts/summary.sh new file mode 100644 index 00000000..25425ef5 --- /dev/null +++ b/scripts/summary.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +# print the offset +tabulate() { + for i in $(seq 1 $1) + do printf " " + done +} + +sign() { + [ "$1" -eq 1 ] && echo "- " +} + +# add an entry to symmary +entry() { + title=$(head -n1 ${1}/${2}r) + if [ "$2" = "index.md" ] && [ $3 -gt 0 ] + then idx=$(($4-1)) + else idx=$4 + fi + tabulate $idx + if [ $1 = "docs" ] + then dir="." + else dir=$(sed 's#docs/##' <<< ${1}) + fi + echo "$(sign $3)[${title:2}]($dir/$2)" +} + +# handle a directory +handle() { + while read -r line + do + if [ -z "$line" ] + then echo "" + continue + fi + if [ -f "$1/${line}r" ] + then entry $1 $line $2 $(( $3 + 1 )) + elif [ -d "$1/${line}" ] + then handle $1/$line 1 $(( $3 + 1 )) + fi + done < "${1}/list" +} + +handle docs 0 -1 diff --git a/scripts/test.sh b/scripts/test.sh new file mode 100644 index 00000000..7c92514d --- /dev/null +++ b/scripts/test.sh @@ -0,0 +1,29 @@ +NOTERM_OK="✔" +NOTERM_NOT_OK="✘" + +# terminal status +INTERM_OK="\033[32mOK\033[0m" +INTERM_NOT_OK="\033[31mNOT OK\033[0m" + +check() { + for a in $@; + do grep "$a" log >/dev/null || return 1 + done #&& [ -z "${VALGRIND}" ] || return valgrind_parse vlog +} + +interm() { + cat log; check $@ && printf "${INTERM_OK}\n" || printf "${INTERM_NOT_OK}\n" +} + +noterm() { + echo '

' + cat log + echo "
" + check $@ && printf "${NOTERM_OK}\n" || printf "${NOTERM_NOT_OK}\n" + echo '

' + +} + +${VALGRIND} ${VALGRIND_OPT} gwion "$1" &> log +shift +[ -t 1 ] && interm $@ || noterm $@ diff --git a/scripts/watch.sh b/scripts/watch.sh new file mode 100644 index 00000000..5943fa7f --- /dev/null +++ b/scripts/watch.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +wait() { + inotifywait -q -r docs --format "%w%f" | tail -1 +} + +while true +do [[ $1 == *".mdr" ]] && + sh scripts/mdr2mdbook.sh $(wait); +done -- 2.43.0