diff --git a/blombly.exe b/blombly.exe index ae0a7b4..77ba0b3 100755 Binary files a/blombly.exe and b/blombly.exe differ diff --git a/docs/advanced/preprocessor.md b/docs/advanced/preprocessor.md index 37af2b0..f0b5146 100644 --- a/docs/advanced/preprocessor.md +++ b/docs/advanced/preprocessor.md @@ -86,7 +86,7 @@ print(mylib.add(1, 2)); ```java // mylib.bb -#include "libs/std" +#include "libs/oop" enable oop; module mylib { diff --git a/docs/advanced/servers.md b/docs/advanced/servers.md index 916b82b..c48e8ea 100644 --- a/docs/advanced/servers.md +++ b/docs/advanced/servers.md @@ -1,30 +1,29 @@ # Servers +Blombly offers the ability to set up REST services. +Instantiating a server is as simple as calling `routes=std::server(port)`, +where the port is provided. The server starts running immediately, +and you can dynamically add or remove routes from it. + ## Routes -Blombly offers the ability to set up REST services. -Instantiating a server is as simpleas calling `routes=std::server(port)`, -where the port is provided. -Treat the generated server as a map from resource location strings to code blocsk -to be called when the respective resource is requested. Blocks called this +Treat the generated server as a map from resource location strings to code blocks +to be called when the respective resource is requested. Blocks that run this ways should returned either a string plain text or a request result struct (see below). Parts of resource names that reside in angular brackets `<...>` indicate that the respective part of therequest should be treated as a string argument to the callable. -For example, the following snippet uses the standard library to create the alias `server` -for `std::server` and then redirects `echo/` to echo the provided input; +For example, the following snippet redirects `echo/` to echo the provided input; run code and open the browser and visit `localhost:8000/echo/MyTest` to see this in action. ```java // main.bb -#include "libs/std" routes = server(8000); routes["/echo/"] = {return input;} while(true) {} // wait indefinitely ``` - -## Request data +## Request input data In addition to the keyword argument values obtained by parsing the request, calls to route code blocks may be enriched with several positional arguments, if available. @@ -43,9 +42,6 @@ These are listed below: ```java // main.bb -#include "libs/std" -enable std; - new { value = 0; routes = server(8000); @@ -61,4 +57,8 @@ new { print("Give me some greetings at localhost:8000/hi/"); while(true) {} // wait indefinitely -``` \ No newline at end of file +``` + +## Non-text results + +*This segment is under constructions.* \ No newline at end of file diff --git a/examples/benchmarks/factorial/factorial.py b/examples/benchmarks/factorial/factorial.py deleted file mode 100644 index b3a6a64..0000000 --- a/examples/benchmarks/factorial/factorial.py +++ /dev/null @@ -1,12 +0,0 @@ -import time - -def factorial(n): - if n == 1: - return 1 - return n * factorial(n-1) - -tic = time.time() -result = factorial(100) -toc = time.time() -print("Factorial of 100: ", result) -print("Time taken: ", toc-tic) \ No newline at end of file diff --git a/examples/benchmarks/factorial/main.bb b/examples/benchmarks/factorial/main.bb deleted file mode 100644 index 6eb48b8..0000000 --- a/examples/benchmarks/factorial/main.bb +++ /dev/null @@ -1,10 +0,0 @@ -final factorial = { - if(n==1) - return 1.0; - return n*new{n=n-1;factorial:} -} - -tic = time(); -f = factorial(n=100); -print(f); -print(time()-tic); \ No newline at end of file diff --git a/examples/benchmarks/factorial/main.bbvm b/examples/benchmarks/factorial/main.bbvm deleted file mode 100644 index 07db7ec..0000000 --- a/examples/benchmarks/factorial/main.bbvm +++ /dev/null @@ -1,29 +0,0 @@ -BEGINFINAL _bb0 -BUILTIN _bb2 I1 -eq _bb1 n _bb2 -BEGINFINAL _bb3 -BUILTIN _bb4 F1.0 -return _bbresult0 _bb4 -END -if # _bb1 _bb3 -BEGINFINAL _bb8 -BUILTIN _bb10 I1 -sub n n _bb10 -inline _bb11 factorial -return _bbresult1 this -END -new _bb6 _bb8 -mul _bb5 n _bb6 -return _bbresult2 _bb5 -END -IS factorial _bb0 -final # factorial -time tic -BEGINFINAL _bb14 -BUILTIN n I1000 -END -call f _bb14 factorial -print # f -time _bb17 -sub _bb16 _bb17 tic -print # _bb16 diff --git a/examples/benchmarks/lists/push.bb b/examples/benchmarks/lists/push.bb deleted file mode 100644 index c4a6497..0000000 --- a/examples/benchmarks/lists/push.bb +++ /dev/null @@ -1,59 +0,0 @@ -#include "libs/std" -enable std; - - -n = 10000000; -print("-------------------------------------------"); -print("Benchmark: lists with "+str(n)+" elements"); -print("Language: blombly"); -print("-------------------------------------------"); - -x = list(1); -tic = time(); -i = 0; -while(i -#include -#include -#include - - -int main(int argc, char* argv[]) { - int n = 10000000; - double* a = new double[n]; - double* b = new double[n]; - for(int i=0;i>(toc-tic).count()<<" sec\n"; - - double d = 0; - for(int i=0;in, end=n); - push(list, Vector(end-start)); - i = i+1; - ); -} - - -final PVector = { - final PVector = PVector; // grant access of this struct to its children - final put = { - this = next(args); - pos = next(args); - id = int(pos/step); - list[id][pos - id*step] = next(args); - } - final len = { - return n; - } - final at = { - this = next(args); - pos = next(args); - id = int(pos/step); - return list[id][pos - id*step]; - } - final add = { - this = next(args); - other = next(args); - ret = List(); - adder = {c[i] = a[i]+b[i]} - i = 0; - while(i2, return false); - if(1>=2, return false); - if(1<=0, return false); - if(1<0, return false); - if(1==1 && 1<1, return false); - if(1<1 && 1==1, return false); - return "all tests passed"; -} - -print(result()!="failed"); \ No newline at end of file diff --git a/examples/concepts/arithmetics.bbvm b/examples/concepts/arithmetics.bbvm deleted file mode 100644 index 99ba2cc..0000000 --- a/examples/concepts/arithmetics.bbvm +++ /dev/null @@ -1,124 +0,0 @@ -BEGIN result -BEGIN _bb0 -BUILTIN _bb1 I1 -BUILTIN _bb2 I1 -neq _bbresult0 _bb1 _bb2 -END -BEGIN _bb3 -BUILTIN _bb4 Bfalse -return _bbresult1 _bb4 -END -if # _bb0 _bb3 -BEGIN _bb5 -BUILTIN _bb6 I1 -BUILTIN _bb7 I2 -eq _bbresult2 _bb6 _bb7 -END -BEGIN _bb8 -BUILTIN _bb9 Bfalse -return _bbresult3 _bb9 -END -if # _bb5 _bb8 -BEGIN _bb10 -BUILTIN _bb12 I1 -BUILTIN _bb14 I4 -BUILTIN _bb15 I2 -div _bb13 _bb14 _bb15 -add _bb11 _bb12 _bb13 -BUILTIN _bb16 I3 -neq _bbresult4 _bb11 _bb16 -END -BEGIN _bb17 -BUILTIN _bb18 Bfalse -return _bbresult5 _bb18 -END -if # _bb10 _bb17 -BEGIN _bb19 -BUILTIN _bb22 I2 -BUILTIN _bb23 I4 -add _bb21 _bb22 _bb23 -BUILTIN _bb24 I2 -div _bb20 _bb21 _bb24 -BUILTIN _bb25 I3 -neq _bbresult6 _bb20 _bb25 -END -BEGIN _bb26 -BUILTIN _bb27 Bfalse -return _bbresult7 _bb27 -END -if # _bb19 _bb26 -BEGIN _bb28 -BUILTIN _bb29 I1 -BUILTIN _bb30 I2 -gt _bbresult8 _bb29 _bb30 -END -BEGIN _bb31 -BUILTIN _bb32 Bfalse -return _bbresult9 _bb32 -END -if # _bb28 _bb31 -BEGIN _bb33 -BUILTIN _bb34 I1 -BUILTIN _bb35 I2 -ge _bbresult10 _bb34 _bb35 -END -BEGIN _bb36 -BUILTIN _bb37 Bfalse -return _bbresult11 _bb37 -END -if # _bb33 _bb36 -BEGIN _bb38 -BUILTIN _bb39 I1 -BUILTIN _bb40 I0 -le _bbresult12 _bb39 _bb40 -END -BEGIN _bb41 -BUILTIN _bb42 Bfalse -return _bbresult13 _bb42 -END -if # _bb38 _bb41 -BEGIN _bb43 -BUILTIN _bb44 I1 -BUILTIN _bb45 I0 -lt _bbresult14 _bb44 _bb45 -END -BEGIN _bb46 -BUILTIN _bb47 Bfalse -return _bbresult15 _bb47 -END -if # _bb43 _bb46 -BEGIN _bb48 -BUILTIN _bb50 I1 -BUILTIN _bb51 I1 -eq _bb49 _bb50 _bb51 -BUILTIN _bb53 I1 -BUILTIN _bb54 I1 -lt _bb52 _bb53 _bb54 -and _bbresult16 _bb49 _bb52 -END -BEGIN _bb55 -BUILTIN _bb56 Bfalse -return _bbresult17 _bb56 -END -if # _bb48 _bb55 -BEGIN _bb57 -BUILTIN _bb59 I1 -BUILTIN _bb60 I1 -lt _bb58 _bb59 _bb60 -BUILTIN _bb62 I1 -BUILTIN _bb63 I1 -eq _bb61 _bb62 _bb63 -and _bbresult18 _bb58 _bb61 -END -BEGIN _bb64 -BUILTIN _bb65 Bfalse -return _bbresult19 _bb65 -END -if # _bb57 _bb64 -BUILTIN _bb66 "all tests passed" -return _bbresult20 _bb66 -END -call _bb68 # result -BUILTIN _bb69 "failed" -neq _bb67 _bb68 _bb69 -print # _bb67 diff --git a/examples/concepts/finals.bb b/examples/concepts/finals.bb deleted file mode 100644 index 73be030..0000000 --- a/examples/concepts/finals.bb +++ /dev/null @@ -1,12 +0,0 @@ -StaticPoint = {final x=x;final y=y;} // ensure that x, y are immutable -Normed2D = { - norm = {return x^q+y^q;} -} -extx = 1; -point = new( - x=extx; - y=2; - StaticPoint: - Normed2D: -); // created object will not store extx (only locally declared variables are kept) -print(point.normsq(q=2)); // 5 \ No newline at end of file diff --git a/examples/concepts/finals.bbvm b/examples/concepts/finals.bbvm deleted file mode 100644 index 2ed928c..0000000 --- a/examples/concepts/finals.bbvm +++ /dev/null @@ -1,29 +0,0 @@ -BEGIN StaticPoint -copy x x -final # x -copy y y -final # y -END -BEGIN Normed2D -BEGIN normsq -pow _bb1 x q -pow _bb2 y q -add _bb0 _bb1 _bb2 -return _bbresult0 _bb0 -END -END -BUILTIN extx I1 -BEGIN _bb3 -IS x extx -BUILTIN y I2 -inline _bbresult1 StaticPoint -inline _bbresult2 Normed2D -return _bbresult3 this -END -new point _bb3 -get _bb5 point normsq -BEGIN _bb6 -BUILTIN q I2 -END -call _bb4 _bb6 _bb5 -print # _bb4 diff --git a/examples/concepts/funcsync.bb b/examples/concepts/funcsync.bb deleted file mode 100644 index aec876a..0000000 --- a/examples/concepts/funcsync.bb +++ /dev/null @@ -1,30 +0,0 @@ -final DynamicPoint = { - this.x=x; - this.y=y; -} // need to declare statics for calling from within blocks -final Increment = { - inc = { - default value=1; - this.x = this.x+value; - return this; // need to return itself to enable the synchronization pattern - } -} -final Normed2D = { - norm = { - base = this.x^q+this.y^q; - return base^(1/q); - } // need to use fhis. to "see" non-final variables -} -final Point = { - new( - DynamicPoint: - Increment: - Normed2D: - ) -} - -point = Point(x=1,y=2); -print(point.norm(q=2)); // 5 -point = point.inc(); // reasignment makes sure that the function is executed before point.x -print(point.x); // 2 (without reasignment to point, this is arbitrary) -print(point.norm(q=2)); // 8 diff --git a/examples/concepts/funcsync.bbvm b/examples/concepts/funcsync.bbvm deleted file mode 100644 index c247a74..0000000 --- a/examples/concepts/funcsync.bbvm +++ /dev/null @@ -1,61 +0,0 @@ -BEGINFINAL DynamicPoint -IS _bb0 x -set # this x _bb0 -IS _bb1 y -set # this y _bb1 -END -BEGINFINAL Increment -BEGIN inc -BEGIN _bb2 -BUILTIN value I1 -END -default _bbresult0 _bb2 -get _bb3 this x -add _bb5 _bb3 value -set # this x _bb5 -return _bbresult1 this -END -END -BEGINFINAL Normed2D -BEGIN norm -get _bb7 this x -pow _bb6 _bb7 q -get _bb10 this y -pow _bb9 _bb10 q -add base _bb6 _bb9 -BUILTIN _bb14 I1 -div _bb13 _bb14 q -pow _bb12 base _bb13 -return _bbresult2 _bb12 -END -END -BEGINFINAL Point -BEGIN _bb15 -inline _bbresult3 DynamicPoint -inline _bbresult4 Increment -inline _bbresult5 Normed2D -return _bbresult6 this -END -new _bbresult7 _bb15 -END -BEGIN _bb16 -BUILTIN x I1 -BUILTIN y I2 -END -call point _bb16 Point -get _bb18 point norm -BEGIN _bb19 -BUILTIN q I2 -END -call _bb17 _bb19 _bb18 -print # _bb17 -get _bb20 point inc -call point # _bb20 -get _bb21 point x -print # _bb21 -get _bb24 point norm -BEGIN _bb25 -BUILTIN q I2 -END -call _bb23 _bb25 _bb24 -print # _bb23 diff --git a/examples/concepts/multiinheritance.bb b/examples/concepts/multiinheritance.bb deleted file mode 100644 index fd508a7..0000000 --- a/examples/concepts/multiinheritance.bb +++ /dev/null @@ -1,22 +0,0 @@ -final DynamicPoint = { - this.x=x; // could also be x=x - this.y=y; -} -final Normed2D = { - norm = { - default q = 2; - return this.x^q+this.y^q; - } // need to use this. to "see" non-final variables (othewise it would get them from the calling scope) -} -final Point = { - print(x); - new( - DynamicPoint: - Normed2D: - ) -} - - -args = {x=1,y=2} // , is the same as ; for calling -point = Point(args:); -print(point.norm(q=2)); \ No newline at end of file diff --git a/examples/concepts/multiinheritance.bbvm b/examples/concepts/multiinheritance.bbvm deleted file mode 100644 index 3005253..0000000 --- a/examples/concepts/multiinheritance.bbvm +++ /dev/null @@ -1,43 +0,0 @@ -BEGINFINAL DynamicPoint -IS _bb0 x -set # this x _bb0 -IS _bb1 y -set # this y _bb1 -END -BEGINFINAL Normed2D -BEGIN norm -BEGIN _bb2 -BUILTIN q I2 -END -default _bbresult0 _bb2 -get _bb5 this x -pow _bb4 _bb5 q -get _bb8 this y -pow _bb7 _bb8 q -add _bb3 _bb4 _bb7 -return _bbresult1 _bb3 -END -END -BEGINFINAL Point -print # x -BEGIN _bb10 -inline _bbresult2 DynamicPoint -inline _bbresult3 Normed2D -return _bbresult4 this -END -new _bbresult5 _bb10 -END -BEGIN args -BUILTIN x I1 -BUILTIN y I2 -END -BEGIN _bb11 -inline _bbresult6 args -END -call point _bb11 Point -get _bb13 point norm -BEGIN _bb14 -BUILTIN q I2 -END -call _bb12 _bb14 _bb13 -print # _bb12 diff --git a/examples/concepts/overloading.bb b/examples/concepts/overloading.bb deleted file mode 100644 index fdcde85..0000000 --- a/examples/concepts/overloading.bb +++ /dev/null @@ -1,18 +0,0 @@ -final Vector = { - final Vector = Vector; - final x = x; - final y = y; - final add = { - this = next(args); - other = next(args); - return new(this.x=x+other.x;this.y=y+other.y;Vector:); - } - final str = { - return "("+str(this.x)+","+str(this.y)+")"; - } -} - -a = new(x=1;y=2;Vector:); -b = new(x=31;y=42;Vector:); -c = a+b; -print(a, "+", b, "=", c); \ No newline at end of file diff --git a/examples/concepts/overloading.bbvm b/examples/concepts/overloading.bbvm deleted file mode 100644 index f349848..0000000 --- a/examples/concepts/overloading.bbvm +++ /dev/null @@ -1,56 +0,0 @@ -BEGINFINAL Vector -copy Vector Vector -final # Vector -copy x x -final # x -copy y y -final # y -BEGINFINAL add -next this args -next other args -BEGIN _bb1 -get _bb2 other x -add _bb4 x _bb2 -set # this x _bb4 -get _bb5 other y -add _bb7 y _bb5 -set # this y _bb7 -inline _bbresult0 Vector -return _bbresult1 this -END -new _bb0 _bb1 -return _bbresult2 _bb0 -END -BEGINFINAL str -BUILTIN _bb9 "(" -get _bb12 this x -str _bb11 _bb12 -BUILTIN _bb15 "," -get _bb18 this y -str _bb17 _bb18 -BUILTIN _bb20 ")" -add _bb16 _bb17 _bb20 -add _bb14 _bb15 _bb16 -add _bb10 _bb11 _bb14 -add _bb8 _bb9 _bb10 -return _bbresult3 _bb8 -END -END -BEGIN _bb21 -BUILTIN x I1 -BUILTIN y I2 -inline _bbresult4 Vector -return _bbresult5 this -END -new a _bb21 -BEGIN _bb22 -BUILTIN x I31 -BUILTIN y I42 -inline _bbresult6 Vector -return _bbresult7 this -END -new b _bb22 -add c a b -BUILTIN _bb23 "+" -BUILTIN _bb24 "=" -print # a _bb23 b _bb24 c diff --git a/examples/concepts/transfer_method.bb b/examples/concepts/transfer_method.bb deleted file mode 100644 index 2082dfe..0000000 --- a/examples/concepts/transfer_method.bb +++ /dev/null @@ -1,28 +0,0 @@ -final normalize = { - default q = 2; - return value/sum(value^q)^(1/q); -} - -final dot = { - return sum(x*y); -} - -final list2vector = { - n = len(list); - vector = Vector(n); - i = 0; - while(iend, return new(found=false)); - middle = int((start + end)/2); - if(list[middle]==query, return new(found=true, pos=middle)); - if(list[middle] get(int item); + std::shared_ptr get(int item); // allowMutable = true std::shared_ptr get(int item, bool allowMutable); std::shared_ptr getShallow(int item); std::shared_ptr getOrNull(int item, bool allowMutable); diff --git a/libs/numbers.bb b/libs/numbers.bb index a5865d9..1e795e9 100644 --- a/libs/numbers.bb +++ b/libs/numbers.bb @@ -1,5 +1,5 @@ -#include "libs/std" -enable std; +#include "libs/oop" +enable oop; abstract Version { diff --git a/libs/oop/.bb b/libs/oop/.bb new file mode 100644 index 0000000..8ef5d3d --- /dev/null +++ b/libs/oop/.bb @@ -0,0 +1,11 @@ +#include "libs/oop/fn" +#include "libs/oop/class" + +// enables the +#macro (enable oop;) = { + #macro (fn) = {oop::fn} + #macro (module) = {oop::module} + #macro (abstract) = {oop::abstract} + #macro (uses) = {oop::uses} + #macro (class) = {oop::class} +} \ No newline at end of file diff --git a/libs/std/oop/class.bb b/libs/oop/class.bb similarity index 74% rename from libs/std/oop/class.bb rename to libs/oop/class.bb index 786c5a5..2318b80 100644 --- a/libs/std/oop/class.bb +++ b/libs/oop/class.bb @@ -1,24 +1,24 @@ // class definition -#macro (std::class @name(@args) {@code}) = { +#macro (oop::class @name(@args) {@code}) = { final @name(@args) = { #spec type="class"; #spec name=#stringify(@name); return new { final type = @name; - std::uses @name; + oop::uses @name; @code } } } // uses definitition -#macro (std::uses @name;) = { +#macro (oop::uses @name;) = { final @name = @name; } // abstract definition -#macro (std::abstract @name {@code}) = { +#macro (oop::abstract @name {@code}) = { final @name = { #spec type="abstract"; #spec name=#stringify(@name); @@ -27,7 +27,7 @@ } // module definition -#macro (std::module @name {@code}) = { +#macro (oop::module @name {@code}) = { final @name = new { final type="module"; final name=#stringify(@name); diff --git a/libs/std/oop/fn.bb b/libs/oop/fn.bb similarity index 79% rename from libs/std/oop/fn.bb rename to libs/oop/fn.bb index 42f6e48..d681075 100644 --- a/libs/std/oop/fn.bb +++ b/libs/oop/fn.bb @@ -1,5 +1,5 @@ // function with only positional arguments (overriden by subsequent versions) -#macro (std::fn @name(@args){@code}) = { +#macro (oop::fn @name(@args){@code}) = { final @name(@args) = { #spec type="fn"; #spec name=#stringify(@name); @@ -7,7 +7,7 @@ } } // function with no arguments -#macro (std::fn @name(){@code}) = { +#macro (oop::fn @name(){@code}) = { final @name = { #spec type="fn"; #spec name=#stringify(@name); @@ -15,7 +15,7 @@ } } // function with defaults -#macro (std::fn @name(@args | @defaults){@code}) = { +#macro (oop::fn @name(@args | @defaults){@code}) = { final @name(@args) = { #spec type="fn"; #spec name=#stringify(@name); @@ -24,7 +24,7 @@ } } // function with only defaults (identified because it has an assignment) -// #macro (std::fn @name(@arg = @defaults){@code}) = { +// #macro (oop::fn @name(@arg = @defaults){@code}) = { // final @name = { // #spec type="fn"; // #spec name=#stringify(@name); diff --git a/libs/std/.bb b/libs/std/.bb deleted file mode 100644 index 566b346..0000000 --- a/libs/std/.bb +++ /dev/null @@ -1,11 +0,0 @@ -#include "libs\std\oop" - -#macro (enable std::web;) = { - // these are builtin web service tools - #macro (server) = {std::server} -} - -#macro (enable std;) = { - enable std::web; - enable std::oop; -} \ No newline at end of file diff --git a/libs/std/dict.bb b/libs/std/dict.bb deleted file mode 100644 index 51c8f46..0000000 --- a/libs/std/dict.bb +++ /dev/null @@ -1,27 +0,0 @@ -#include "std/oop" - -class Dict { - final keys = list(); - final values = map(); - final test = "hello"; - - fn \put(k, v) { - push(keys, k); - values[k] = v; - return this; - } - fn \at(k) { - return values[k]; - } - fn \len() { - return len(keys); - } - - fn \iter() { - return iter(keys); - } -} - -fn dict() { - return new{Dict:} -} \ No newline at end of file diff --git a/libs/std/loop.bb b/libs/std/loop.bb deleted file mode 100644 index 48bf33e..0000000 --- a/libs/std/loop.bb +++ /dev/null @@ -1,6 +0,0 @@ -#macro(std::for(@var in @iterable)@code;) = { // @code ; covers bracketed code too - try { - @temp = iter(@iterable); - while(@var as next(@temp)) @code; - } -} diff --git a/libs/std/oop/.bb b/libs/std/oop/.bb deleted file mode 100644 index b66bf5c..0000000 --- a/libs/std/oop/.bb +++ /dev/null @@ -1,11 +0,0 @@ -#include "libs/std/oop/fn" -#include "libs/std/oop/class" - -// enables the -#macro (enable std::oop;) = { - #macro (fn) = {std::fn} - #macro (module) = {std::module} - #macro (abstract) = {std::abstract} - #macro (uses) = {std::uses} - #macro (class) = {std::class} -} \ No newline at end of file diff --git a/main.bb b/main.bb index e4df18e..44fb5c0 100644 --- a/main.bb +++ b/main.bb @@ -1,13 +1,11 @@ -test = { - A = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15; - return iter(A); +routes = server(5000); +routes["/"] = { + return " + + +

My First Heading

+

My first paragraph.

+ + " } - -show = { - while(i as next(it)) - print(i); -} - -final it = test(); -show(); -show(); \ No newline at end of file +while(true) {} // wait indefinitely diff --git a/main.bbvm b/main.bbvm index e4bb77a..62f6975 100644 --- a/main.bbvm +++ b/main.bbvm @@ -1,38 +1,13 @@ -BEGIN _bb0 -BUILTIN _bb1 I1 -BUILTIN _bb2 I2 -BUILTIN _bb3 I3 -BUILTIN _bb4 I4 -BUILTIN _bb5 I5 -BUILTIN _bb6 I6 -BUILTIN _bb7 I7 -BUILTIN _bb8 I8 -BUILTIN _bb9 I9 -BUILTIN _bb10 I10 -BUILTIN _bb11 I11 -BUILTIN _bb12 I12 -BUILTIN _bb13 I13 -BUILTIN _bb14 I14 -BUILTIN _bb15 I15 -list A _bb1 _bb2 _bb3 _bb4 _bb5 _bb6 _bb7 _bb8 _bb9 _bb10 _bb11 _bb12 _bb13 _bb14 _bb15 -iter _bb17 A -return _bbresult0 _bb17 +BUILTIN _bb0 I5000 +server routes _bb0 +BEGIN _bb2 +BUILTIN _bb3 "

My First Heading

My first paragraph.

" +return _bbresult0 _bb3 END -IS test _bb0 -BEGIN _bb18 -next _bb19 it -AS i _bb19 -exists _bb20 i -BEGIN _bb21 -print # i -next _bb19 it -AS i _bb19 -exists _bb20 i +BUILTIN _bb4 "/" +put # routes _bb4 _bb2 +BUILTIN _bb5 Btrue +BEGIN _bb6 +BUILTIN _bb5 Btrue END -while # _bb20 _bb21 -END -IS show _bb18 -call it # test -final # it -call _bb23 # show -call _bb24 # show +while # _bb5 _bb6 diff --git a/src/bmemory.cpp b/src/bmemory.cpp index 6d65b15..fc92596 100644 --- a/src/bmemory.cpp +++ b/src/bmemory.cpp @@ -76,7 +76,7 @@ int BMemory::size() const { return data.size(); } -std::shared_ptr BMemory::get(int item) { +std::shared_ptr BMemory::get(int item) { // allowMutable = true auto ret = data[item]; if (ret && ret->getType() == FUTURE) { auto prevRet = std::dynamic_pointer_cast(ret); @@ -136,7 +136,7 @@ std::shared_ptr BMemory::getShallow(int item) { return fastLastAccess.lock(); auto it = data.find(item); if (it == data.end()) - bberror("Missing value: " + variableManager.getSymbol(item)); + bberror("Missing value 1: " + variableManager.getSymbol(item)); auto ret = it->second; if (ret && ret->getType() == FUTURE) { auto prevRet = std::dynamic_pointer_cast(ret); diff --git a/src/data/rest_server.cpp b/src/data/rest_server.cpp index 57ce8d9..df3062a 100644 --- a/src/data/rest_server.cpp +++ b/src/data/rest_server.cpp @@ -161,12 +161,23 @@ int RestServer::requestHandler(struct mg_connection* conn, void* cbdata) { std::shared_ptr result = server->executeCodeWithMemory(entry.second, mem); std::string response = result->toString(); - mg_printf(conn, - "HTTP/1.1 200 OK\r\n" - "Content-Type: text/plain\r\n" - "Content-Length: %lu\r\n" - "\r\n%s", - response.length(), response.c_str()); + + std::string html_prefix = ""; + if(html_prefix.size()>=html_prefix.length() && response.substr(0, html_prefix.length())==html_prefix) { + mg_printf(conn, + "HTTP/1.1 200 OK\r\n" + "Content-Type: text/html\r\n" + "Content-Length: %lu\r\n" + "\r\n%s", + response.length(), response.c_str()); + } + else + mg_printf(conn, + "HTTP/1.1 200 OK\r\n" + "Content-Type: text/plain\r\n" + "Content-Length: %lu\r\n" + "\r\n%s", + response.length(), response.c_str()); return 200; } catch (const BBError& e) { diff --git a/src/interpreter/functional/handle_command.cpp b/src/interpreter/functional/handle_command.cpp index 991a88e..3f6f8cc 100644 --- a/src/interpreter/functional/handle_command.cpp +++ b/src/interpreter/functional/handle_command.cpp @@ -100,7 +100,7 @@ void handleCommand(const std::shared_ptr>& program, } auto code = std::static_pointer_cast(called); if (!code->scheduleForParallelExecution || !Future::acceptsThread()) { - auto newMemory = std::make_shared(code->getDeclarationMemory(), LOCAL_EXPECTATION_FROM_CODE(code)); + auto newMemory = std::make_shared(memory, LOCAL_EXPECTATION_FROM_CODE(code)); bool newReturnSignal(false); if (context) { bbassert(context->getType() == CODE, "Call context must be a code block."); @@ -114,7 +114,7 @@ void handleCommand(const std::shared_ptr>& program, newMemory.reset(); } else { - auto newMemory = std::make_shared(code->getDeclarationMemory(), LOCAL_EXPECTATION_FROM_CODE(code)); + auto newMemory = std::make_shared(memory, LOCAL_EXPECTATION_FROM_CODE(code)); bool newReturnSignal(false); if (context) { bbassert(context->getType() == CODE, "Call context must be a code block."); @@ -404,6 +404,7 @@ void handleCommand(const std::shared_ptr>& program, else args.preallocResult = nullptr; result = Data::run(command->operation, &args); + //std::cout << "Running "+result->toString()+"\n"; } break; } //if(!result && command->knownLocal[0])