~shakna/evjl

bc14466b9185966fac7d9a33a30d62d95a99b77b — James Milne 1 year, 4 months ago 17c6f19
Commented on examples.
M example/add.e => example/add.e +9 -0
@@ 1,3 1,12 @@
/*

  This example is used in the documentation.

  It's a fairly simple demonstration of defining and calling
  a procedure.

*/

proc(adder, int, int a, int b)
  return a + b;
end

M example/coroutines.e => example/coroutines.e +13 -0
@@ 1,3 1,16 @@
/*

  evjl has support for highly limited coroutines.

  Note:
  * They can't be nested safely.
  * They are not thread-safe.
  * They require working with storage types.
  * If they are infinite like the below example, but have no return function,
  they will probably confuse the compiler.

*/

proc(example, int)
  storage(int, i, 0);
  coroutine();

M example/decimal_add.e => example/decimal_add.e +6 -0
@@ 1,3 1,9 @@
/*

  This is a simple demonstration of the Decimal type.

*/

proc(adder, Decimal, Decimal a, Decimal b)
  return a + b;
end

M example/fib.e => example/fib.e +7 -0
@@ 1,3 1,10 @@
/*

  The famous recursive fibonacci calculator.
  This is not a smart way to calculate fibonacci numbers.

*/

static proc(fib, Number, Number n)
  If n == 0 || n == 1 then
    return n;

M example/hash.e => example/hash.e +9 -0
@@ 1,3 1,12 @@
/*

  evjl has several non-cryptographic hashing functions.

  Useful for fast equality of strings if you store the value once,
  and compare many times.

*/

Main then

  String msg = "Hello, World!";

M example/helloworld.e => example/helloworld.e +5 -1
@@ 1,4 1,8 @@
comment(This is a version of the classic program for creating output to the stdout device.)
/*

  This is a version of the classic program for creating output to the stdout device.

*/

Main then
  displayln("Hello, World!");

M example/math.e => example/math.e +7 -0
@@ 1,3 1,10 @@
/*

  evjl includes the standardised C math library.
  See http://www.cplusplus.com/reference/cmath/ for more.

*/

Main then

  display(pow(1, 2));

M example/minimal.e => example/minimal.e +8 -0
@@ 1,2 1,10 @@
/*

  This comment is larger than the entire program.
  This demonstrates the smallest possible program
  you can write.

*/

Main then
end
\ No newline at end of file

M example/random.e => example/random.e +10 -0
@@ 1,3 1,13 @@
/*

  evjl gives you some non-cryptographic random functions.

  This demonstrates them:
  * random_seed (Should be called early in a program's lifespan).
  * random_num (A Number within a given range).

*/

Main then
  random_seed();


M example/user_types.e => example/user_types.e +12 -1
@@ 1,10 1,21 @@
/*

  This demonstrates evjl's support for
  user-defined types.

*/

Typedef Struct(pair)
  Number a;
  Number b;
end pair;

Main then
  pair x;
  pair x = {5, 4};
  
  displayln(x.a);
  displayln(x.b);

  x.a = 10;
  x.b = 12;


M test => test +2 -2
@@ 142,7 142,7 @@ fi
rm helloworld_test

result="$(./evjl example/user_types.e)"
expect="$(printf '10\n12')"
expect="$(printf '5\n4\n10\n12')"
if [ "$result" != "$expect" ]; then
  exitStatus=1
  echo 'Failed: user_types.e'


@@ 155,7 155,7 @@ fi

time -f '%U %S %e %P' ./evjl example/user_types.e --compile=user_types_test
result="$(./user_types_test)"
expect="$(printf '10\n12')"
expect="$(printf '5\n4\n10\n12')"
if [ "$result" != "$expect" ]; then
  exitStatus=1
  echo 'Failed: Compiled user_types.e'