From be839900419c7a74c4a46efd279d0ca16b35dc1f Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Thu, 15 May 2008 23:28:07 +0000 Subject: Moved stuff into trunk. --- examples/broken/bitwise.fy | 31 +++++++++++++++++++++++++++++++ examples/comments.fy | 21 +++++++++++++++++++++ examples/conditionals.fy | 41 +++++++++++++++++++++++++++++++++++++++++ examples/control.fy | 32 ++++++++++++++++++++++++++++++++ examples/expressions.fy | 31 +++++++++++++++++++++++++++++++ examples/fork.fy | 14 ++++++++++++++ examples/functions.fy | 25 +++++++++++++++++++++++++ examples/inlinefunctions.fy | 20 ++++++++++++++++++++ examples/io.fy | 13 +++++++++++++ examples/procedures.fy | 30 ++++++++++++++++++++++++++++++ examples/scopeing.fy | 27 +++++++++++++++++++++++++++ examples/types.fy | 14 ++++++++++++++ examples/variables.fy | 21 +++++++++++++++++++++ 13 files changed, 320 insertions(+) create mode 100644 examples/broken/bitwise.fy create mode 100644 examples/comments.fy create mode 100644 examples/conditionals.fy create mode 100644 examples/control.fy create mode 100644 examples/expressions.fy create mode 100644 examples/fork.fy create mode 100644 examples/functions.fy create mode 100644 examples/inlinefunctions.fy create mode 100644 examples/io.fy create mode 100644 examples/procedures.fy create mode 100644 examples/scopeing.fy create mode 100644 examples/types.fy create mode 100644 examples/variables.fy (limited to 'examples') diff --git a/examples/broken/bitwise.fy b/examples/broken/bitwise.fy new file mode 100644 index 0000000..b124590 --- /dev/null +++ b/examples/broken/bitwise.fy @@ -0,0 +1,31 @@ +#* + * Examples of how to use bitwise operators + *# + +# Prints "01\n" +assert 0 == (put 1 and 0); +assert 1 == (say 1 and 1); + +# Prints "01\n" +assert 0 == (put 0 or 0); +assert 1 == (say 0 or 1); + +# Prints "01\n" +assert 0 == (put 1 xor 1); +assert 1 == (say 1 xor 0); + +# Prints "-1" (see "not" operator of NASM why so) +assert (neg 1) == (say not 0); + +# Prints "82\n" +assert 8 == (put 2 << 2); +assert 2 == (say 8 >> 2); + +# A bit more complex, prints "9\n" +assert 9 == (say 1 << 5 >> 5 or 2 and 5 xor 8); + +# Same result, but with parenthesis: +assert 9 == (say ((((1 << 5) >> 5) or 2) and 5) xor 8); + +# Different parenthesis, different result: "1\n" +assert 1 == (say 1 << 5 >> 5 or 2 and (5 xor 8)); diff --git a/examples/comments.fy b/examples/comments.fy new file mode 100644 index 0000000..216e41b --- /dev/null +++ b/examples/comments.fy @@ -0,0 +1,21 @@ +#* + * Simple examples how to write comments + *# + +# This is a single lined comment + +say 1 + 1; # This is a comment at the end of the line + +say 1 #* This is an embedded comment *# + 1; + +#* This is + a + multiline + comment *# + +#* + * This is + * a nicer looking + * multiline comment + *# + diff --git a/examples/conditionals.fy b/examples/conditionals.fy new file mode 100644 index 0000000..1260ae2 --- /dev/null +++ b/examples/conditionals.fy @@ -0,0 +1,41 @@ +#* + * Simple conditional tests + *# + +# "0010\n" +assert 0 == (put 1 < 1); +assert 0 == (put 1 < 0); +assert 1 == (put 0 < 1); +assert 0 == (say 0 < 0); + +# "0100\n" +assert 0 == (put 1 > 1); +assert 1 == (put 1 > 0); +assert 0 == (put 0 > 1); +assert 0 == (say 0 > 0); + +# "1001\n" +assert 1 == (put 1 == 1); +assert 0 == (put 1 == 0); +assert 0 == (put 0 == 1); +assert 1 == (say 0 == 0); + +# "0110\n" +assert 0 == (put 1 != 1); +assert 1 == (put 1 != 0); +assert 1 == (put 0 != 1); +assert 0 == (say 0 != 0); + +# "1011\n" +assert 1 == (put 1 <= 1); +assert 0 == (put 1 <= 0); +assert 1 == (put 0 <= 1); +assert 1 == (say 0 <= 0); + +## "1101\n" +assert 1 == (put 1 >= 1); +assert 1 == (put 1 >= 0); +assert 0 == (put 0 >= 1); +assert 1 == (say 0 >= 0); + + diff --git a/examples/control.fy b/examples/control.fy new file mode 100644 index 0000000..0deac78 --- /dev/null +++ b/examples/control.fy @@ -0,0 +1,32 @@ +#* + * Examples of how to use control statements + *# + +if 1 { + say "if 1"; +} + +ifnot 0 == 1 { + say "ifnot 0 == 1"; +} + +# Calculate 10! + +my n = 10, fac = 0; + +while n > 1 { + ifnot fac { + fac = 1; + } + say fac = (fac * n); + decr n; +} + +# Count up to 10 + +n = 0; + +until n == 10 { + say incr n; +} + diff --git a/examples/expressions.fy b/examples/expressions.fy new file mode 100644 index 0000000..93a278f --- /dev/null +++ b/examples/expressions.fy @@ -0,0 +1,31 @@ +#* + * Simple expression tests + *# + +# Result 10 +assert 10 == say (8 / 2) + 2 * 3; + +# Result 12 +assert 12 == say 2 * (4 + 2); + +# Result 4 +assert 4 == say 2 * (4 / 2); + +# Result 4 +assert 4 == say 2 * (4 / 2); + +# Result 4 +assert 4 == say 2 * (4 / 2); + +# Result 46 +assert 46 == say "12" + "34"; + +# Result 1231 +assert 1231 == say "1234" - "3"; + +# Result 24 +assert "24" == say "2ab" * "12"; + +# Result 5.0 +assert 5 == say "10 bla" / 2; + diff --git a/examples/fork.fy b/examples/fork.fy new file mode 100644 index 0000000..c49c878 --- /dev/null +++ b/examples/fork.fy @@ -0,0 +1,14 @@ +#* + * Examples of how to use fork + *# + +my pid = fork; + +if pid { + put "I am the parent process and the child has the pid "; + say pid; +} + +ifnot pid { + say "I am the child process"; +} diff --git a/examples/functions.fy b/examples/functions.fy new file mode 100644 index 0000000..15856a0 --- /dev/null +++ b/examples/functions.fy @@ -0,0 +1,25 @@ +#* + * Examples of how to use functions + *# + +func foo { + say 1 + a * 3 + b; + + func bar { + say "Hello i am nested"; + } + + bar; # Calling nested +} + +my a = 2, b = 4; # Create global variables +foo; +assert 0 == (defined bar); # bar is not available anymore + +func baz { + say "I am baz"; + undef baz; +} + +baz; # Baz deletes itself +assert 0 == (defined baz); # baz is not available anymore diff --git a/examples/inlinefunctions.fy b/examples/inlinefunctions.fy new file mode 100644 index 0000000..81848ce --- /dev/null +++ b/examples/inlinefunctions.fy @@ -0,0 +1,20 @@ +#* + * Simple builtin function tests + *# + +# Print "-20\n" +assert (neg 20) == (say neg 20); + +# Print "30\n" +assert 30 == (say 10 - neg 20); + +# Print "-30\n" +assert (neg 30) == (say neg neg neg 10 - neg 20); + +# Print "Hello\n" +put "Hello"; +ln; + +# Exit with exit code 0 +exit 10 + 10 - 5 - 15; + diff --git a/examples/io.fy b/examples/io.fy new file mode 100644 index 0000000..fda514d --- /dev/null +++ b/examples/io.fy @@ -0,0 +1,13 @@ +#* + * Simple I/O examples. Currently only output is supported. + *# + +# Print out 10 followed by a newline +say 10; + +# Print out 20 without a newline followed +put 20; + +# Print out a newline +ln; + diff --git a/examples/procedures.fy b/examples/procedures.fy new file mode 100644 index 0000000..cbe2121 --- /dev/null +++ b/examples/procedures.fy @@ -0,0 +1,30 @@ +#* + * Examples of how to use procedures + *# + +proc foo { + say 1 + a * 3 + b; + my c = 6; +} + +my a = 2, b = 4; + +foo; # Run the procedure. Print out "11\n" +say c; # Print out "6\n"; + +proc bar { + say "I am bar"; + + undef baz; + + proc baz { + say "I am baz"; + } +} + +# Here bar would produce an error because the proc is not yet defined! +# bar; + +bar; # Here the procedure bar will define the procedure baz! +baz; # Now the procedure baz is defined! +bar; # Here the procedure bar will redefine baz again! diff --git a/examples/scopeing.fy b/examples/scopeing.fy new file mode 100644 index 0000000..2e36c2c --- /dev/null +++ b/examples/scopeing.fy @@ -0,0 +1,27 @@ +#* + * Examples of how to use scopeing + *# + +my foo = 1; + +{ + # Prints out 1 + assert 1 == (put defined foo); + + { + my bar = 2; + + # Prints out 1 + assert 1 == (put defined bar); + } + + # Prints out 0 + assert 0 == (put defined bar); + + my baz = 3; +} + +# Prints out 0 +assert 0 == (say defined bar); + + diff --git a/examples/types.fy b/examples/types.fy new file mode 100644 index 0000000..1b9a0ac --- /dev/null +++ b/examples/types.fy @@ -0,0 +1,14 @@ +#* + * Examples how to convert types + *# + +assert 1 == say 1; # Integer output + +assert 1 == say double 1; # Double output + +assert 14 == say 1 + string 13; # Implicit type conversion to Integer + +assert 2 == say integer 2.8; # Rounds down to the Integer 2 + +assert say integer double string put say neg 12; # Nonsense but working :) + diff --git a/examples/variables.fy b/examples/variables.fy new file mode 100644 index 0000000..ac619c9 --- /dev/null +++ b/examples/variables.fy @@ -0,0 +1,21 @@ +#* + * Examples of how to define variables + *# + +# Defines the variables +my foo = 1 + 1; +my bar = 4 - 1, baz = 100 + 1, bay; + +# bay has been initialized with the default value of 0 +say bay; + +# Prints out "5\n" +assert 5 == (say foo + bar); + +# Pritns out "51101\n" +assert 51 == (put baz - 50); +assert 101 == (say baz); + +# Change the value of the variable to 99 and print it out +assert 99 == (baz = 99); +say baz; -- cgit v1.2.3 From 7f3055c1f4429a81de3715d5d4173353382e2de2 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 24 Aug 2008 19:30:11 +0000 Subject: some mods --- examples/conditionals.fy | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'examples') diff --git a/examples/conditionals.fy b/examples/conditionals.fy index 1260ae2..38bd46d 100644 --- a/examples/conditionals.fy +++ b/examples/conditionals.fy @@ -21,21 +21,21 @@ assert 0 == (put 0 == 1); assert 1 == (say 0 == 0); # "0110\n" -assert 0 == (put 1 != 1); -assert 1 == (put 1 != 0); -assert 1 == (put 0 != 1); -assert 0 == (say 0 != 0); +assert 0 == (put 1 =! 1); +assert 1 == (put 1 =! 0); +assert 1 == (put 0 =! 1); +assert 0 == (say 0 =! 0); # "1011\n" -assert 1 == (put 1 <= 1); -assert 0 == (put 1 <= 0); -assert 1 == (put 0 <= 1); -assert 1 == (say 0 <= 0); +assert 1 == (put 1 =< 1); +assert 0 == (put 1 =< 0); +assert 1 == (put 0 =< 1); +assert 1 == (say 0 =< 0); ## "1101\n" -assert 1 == (put 1 >= 1); -assert 1 == (put 1 >= 0); -assert 0 == (put 0 >= 1); -assert 1 == (say 0 >= 0); +assert 1 == (put 1 => 1); +assert 1 == (put 1 => 0); +assert 0 == (put 0 => 1); +assert 1 == (say 0 => 0); -- cgit v1.2.3 From cf9029ee902eda028f3efcb77e8c2aed25205b94 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 24 Aug 2008 19:47:50 +0000 Subject: foo bar baz --- examples/conditionals.fy | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'examples') diff --git a/examples/conditionals.fy b/examples/conditionals.fy index 38bd46d..1260ae2 100644 --- a/examples/conditionals.fy +++ b/examples/conditionals.fy @@ -21,21 +21,21 @@ assert 0 == (put 0 == 1); assert 1 == (say 0 == 0); # "0110\n" -assert 0 == (put 1 =! 1); -assert 1 == (put 1 =! 0); -assert 1 == (put 0 =! 1); -assert 0 == (say 0 =! 0); +assert 0 == (put 1 != 1); +assert 1 == (put 1 != 0); +assert 1 == (put 0 != 1); +assert 0 == (say 0 != 0); # "1011\n" -assert 1 == (put 1 =< 1); -assert 0 == (put 1 =< 0); -assert 1 == (put 0 =< 1); -assert 1 == (say 0 =< 0); +assert 1 == (put 1 <= 1); +assert 0 == (put 1 <= 0); +assert 1 == (put 0 <= 1); +assert 1 == (say 0 <= 0); ## "1101\n" -assert 1 == (put 1 => 1); -assert 1 == (put 1 => 0); -assert 0 == (put 0 => 1); -assert 1 == (say 0 => 0); +assert 1 == (put 1 >= 1); +assert 1 == (put 1 >= 0); +assert 0 == (put 0 >= 1); +assert 1 == (say 0 >= 0); -- cgit v1.2.3 From ec9899c0399f42473d311c7d0a46769d3d933c06 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 25 Aug 2008 18:48:28 +0000 Subject: bugs fixed, initial array --- examples/broken/bitwise.fy | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'examples') diff --git a/examples/broken/bitwise.fy b/examples/broken/bitwise.fy index b124590..03fda6c 100644 --- a/examples/broken/bitwise.fy +++ b/examples/broken/bitwise.fy @@ -14,18 +14,19 @@ assert 1 == (say 0 or 1); assert 0 == (put 1 xor 1); assert 1 == (say 1 xor 0); -# Prints "-1" (see "not" operator of NASM why so) -assert (neg 1) == (say not 0); - # Prints "82\n" -assert 8 == (put 2 << 2); -assert 2 == (say 8 >> 2); +assert 8 == (put 2 :< 2); +assert 2 == (say 8 :> 2); # A bit more complex, prints "9\n" -assert 9 == (say 1 << 5 >> 5 or 2 and 5 xor 8); +assert 9 == (say 1 :< 5 :> 5 or 2 and 5 xor 8); # Same result, but with parenthesis: -assert 9 == (say ((((1 << 5) >> 5) or 2) and 5) xor 8); +assert 9 == (say ((((1 :< 5) :> 5) or 2) and 5) xor 8); # Different parenthesis, different result: "1\n" -assert 1 == (say 1 << 5 >> 5 or 2 and (5 xor 8)); +assert 1 == (say 1 :< 5 :> 5 or 2 and (5 xor 8)); + +# Prints "-1" +assert (neg 1) == (say neg not 0); + -- cgit v1.2.3 From 3206d602859f5572b958fcc36ba56c9596ecb292 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 25 Aug 2008 18:49:42 +0000 Subject: butwis --- examples/bitwise.fy | 32 ++++++++++++++++++++++++++++++++ examples/broken/bitwise.fy | 32 -------------------------------- 2 files changed, 32 insertions(+), 32 deletions(-) create mode 100644 examples/bitwise.fy delete mode 100644 examples/broken/bitwise.fy (limited to 'examples') diff --git a/examples/bitwise.fy b/examples/bitwise.fy new file mode 100644 index 0000000..03fda6c --- /dev/null +++ b/examples/bitwise.fy @@ -0,0 +1,32 @@ +#* + * Examples of how to use bitwise operators + *# + +# Prints "01\n" +assert 0 == (put 1 and 0); +assert 1 == (say 1 and 1); + +# Prints "01\n" +assert 0 == (put 0 or 0); +assert 1 == (say 0 or 1); + +# Prints "01\n" +assert 0 == (put 1 xor 1); +assert 1 == (say 1 xor 0); + +# Prints "82\n" +assert 8 == (put 2 :< 2); +assert 2 == (say 8 :> 2); + +# A bit more complex, prints "9\n" +assert 9 == (say 1 :< 5 :> 5 or 2 and 5 xor 8); + +# Same result, but with parenthesis: +assert 9 == (say ((((1 :< 5) :> 5) or 2) and 5) xor 8); + +# Different parenthesis, different result: "1\n" +assert 1 == (say 1 :< 5 :> 5 or 2 and (5 xor 8)); + +# Prints "-1" +assert (neg 1) == (say neg not 0); + diff --git a/examples/broken/bitwise.fy b/examples/broken/bitwise.fy deleted file mode 100644 index 03fda6c..0000000 --- a/examples/broken/bitwise.fy +++ /dev/null @@ -1,32 +0,0 @@ -#* - * Examples of how to use bitwise operators - *# - -# Prints "01\n" -assert 0 == (put 1 and 0); -assert 1 == (say 1 and 1); - -# Prints "01\n" -assert 0 == (put 0 or 0); -assert 1 == (say 0 or 1); - -# Prints "01\n" -assert 0 == (put 1 xor 1); -assert 1 == (say 1 xor 0); - -# Prints "82\n" -assert 8 == (put 2 :< 2); -assert 2 == (say 8 :> 2); - -# A bit more complex, prints "9\n" -assert 9 == (say 1 :< 5 :> 5 or 2 and 5 xor 8); - -# Same result, but with parenthesis: -assert 9 == (say ((((1 :< 5) :> 5) or 2) and 5) xor 8); - -# Different parenthesis, different result: "1\n" -assert 1 == (say 1 :< 5 :> 5 or 2 and (5 xor 8)); - -# Prints "-1" -assert (neg 1) == (say neg not 0); - -- cgit v1.2.3 From 71185ab0ab0b08b4d5bb2e750ff85e11f105a453 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 16 Sep 2008 17:05:51 +0000 Subject: array progress --- examples/types.fy | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'examples') diff --git a/examples/types.fy b/examples/types.fy index 1b9a0ac..1ac9751 100644 --- a/examples/types.fy +++ b/examples/types.fy @@ -12,3 +12,7 @@ assert 2 == say integer 2.8; # Rounds down to the Integer 2 assert say integer double string put say neg 12; # Nonsense but working :) +assert "TT_INTEGER" == say type 1; +assert "TT_DOUBLE" == say type 1.0; +assert "TT_STRING" == say type "1"; +assert "TT_ARRAY" == say type [1 2 3]; -- cgit v1.2.3 From c25ba0d8ee9e4e6a0432fba2e8606c7e0a35d1cd Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 14 Oct 2008 21:10:31 +0000 Subject: added a scope debug flag --- examples/conditionals.fy | 2 -- 1 file changed, 2 deletions(-) (limited to 'examples') diff --git a/examples/conditionals.fy b/examples/conditionals.fy index 1260ae2..2dc027f 100644 --- a/examples/conditionals.fy +++ b/examples/conditionals.fy @@ -37,5 +37,3 @@ assert 1 == (put 1 >= 1); assert 1 == (put 1 >= 0); assert 0 == (put 0 >= 1); assert 1 == (say 0 >= 0); - - -- cgit v1.2.3 From cb1450b796eff3c8830616e2e9a3d83d4dfb4900 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 18 Oct 2008 22:47:31 +0000 Subject: backdowngrade --- examples/all-examples.txt | 335 ++++++++++++++++++++++++++++++++++++++++++++++ examples/conditionals.fy | 2 + examples/types.fy | 4 - 3 files changed, 337 insertions(+), 4 deletions(-) create mode 100644 examples/all-examples.txt (limited to 'examples') diff --git a/examples/all-examples.txt b/examples/all-examples.txt new file mode 100644 index 0000000..bdf199f --- /dev/null +++ b/examples/all-examples.txt @@ -0,0 +1,335 @@ + +#* + * Examples of how to use bitwise operators + *# + +# Prints "01\n" +assert 0 == (put 1 and 0); +assert 1 == (say 1 and 1); + +# Prints "01\n" +assert 0 == (put 0 or 0); +assert 1 == (say 0 or 1); + +# Prints "01\n" +assert 0 == (put 1 xor 1); +assert 1 == (say 1 xor 0); + +# Prints "82\n" +assert 8 == (put 2 :< 2); +assert 2 == (say 8 :> 2); + +# A bit more complex, prints "9\n" +assert 9 == (say 1 :< 5 :> 5 or 2 and 5 xor 8); + +# Same result, but with parenthesis: +assert 9 == (say ((((1 :< 5) :> 5) or 2) and 5) xor 8); + +# Different parenthesis, different result: "1\n" +assert 1 == (say 1 :< 5 :> 5 or 2 and (5 xor 8)); + +# Prints "-1" +assert (neg 1) == (say neg not 0); + + +#* + * Simple examples how to write comments + *# + +# This is a single lined comment + +say 1 + 1; # This is a comment at the end of the line + +say 1 #* This is an embedded comment *# + 1; + +#* This is + a + multiline + comment *# + +#* + * This is + * a nicer looking + * multiline comment + *# + + +#* + * Simple conditional tests + *# + +# "0010\n" +assert 0 == (put 1 < 1); +assert 0 == (put 1 < 0); +assert 1 == (put 0 < 1); +assert 0 == (say 0 < 0); + +# "0100\n" +assert 0 == (put 1 > 1); +assert 1 == (put 1 > 0); +assert 0 == (put 0 > 1); +assert 0 == (say 0 > 0); + +# "1001\n" +assert 1 == (put 1 == 1); +assert 0 == (put 1 == 0); +assert 0 == (put 0 == 1); +assert 1 == (say 0 == 0); + +# "0110\n" +assert 0 == (put 1 != 1); +assert 1 == (put 1 != 0); +assert 1 == (put 0 != 1); +assert 0 == (say 0 != 0); + +# "1011\n" +assert 1 == (put 1 <= 1); +assert 0 == (put 1 <= 0); +assert 1 == (put 0 <= 1); +assert 1 == (say 0 <= 0); + +## "1101\n" +assert 1 == (put 1 >= 1); +assert 1 == (put 1 >= 0); +assert 0 == (put 0 >= 1); +assert 1 == (say 0 >= 0); + + + +#* + * Examples of how to use control statements + *# + +if 1 { + say "if 1"; +} + +ifnot 0 == 1 { + say "ifnot 0 == 1"; +} + +# Calculate 10! + +my n = 10, fac = 0; + +while n > 1 { + ifnot fac { + fac = 1; + } + say fac = (fac * n); + decr n; +} + +# Count up to 10 + +n = 0; + +until n == 10 { + say incr n; +} + + +#* + * Simple expression tests + *# + +# Result 10 +assert 10 == say (8 / 2) + 2 * 3; + +# Result 12 +assert 12 == say 2 * (4 + 2); + +# Result 4 +assert 4 == say 2 * (4 / 2); + +# Result 4 +assert 4 == say 2 * (4 / 2); + +# Result 4 +assert 4 == say 2 * (4 / 2); + +# Result 46 +assert 46 == say "12" + "34"; + +# Result 1231 +assert 1231 == say "1234" - "3"; + +# Result 24 +assert "24" == say "2ab" * "12"; + +# Result 5.0 +assert 5 == say "10 bla" / 2; + + +#* + * Examples of how to use fork + *# + +my pid = fork; + +if pid { + put "I am the parent process and the child has the pid "; + say pid; +} + +ifnot pid { + say "I am the child process"; +} + +#* + * Examples of how to use functions + *# + +func foo { + say 1 + a * 3 + b; + + func bar { + say "Hello i am nested"; + } + + bar; # Calling nested +} + +my a = 2, b = 4; # Create global variables +foo; +assert 0 == (defined bar); # bar is not available anymore + +func baz { + say "I am baz"; + undef baz; +} + +baz; # Baz deletes itself +assert 0 == (defined baz); # baz is not available anymore + +#* + * Simple builtin function tests + *# + +# Print "-20\n" +assert (neg 20) == (say neg 20); + +# Print "30\n" +assert 30 == (say 10 - neg 20); + +# Print "-30\n" +assert (neg 30) == (say neg neg neg 10 - neg 20); + +# Print "Hello\n" +put "Hello"; +ln; + +# Exit with exit code 0 +exit 10 + 10 - 5 - 15; + + +#* + * Simple I/O examples. Currently only output is supported. + *# + +# Print out 10 followed by a newline +say 10; + +# Print out 20 without a newline followed +put 20; + +# Print out a newline +ln; + + +#* + * Examples of how to use procedures + *# + +proc foo { + say 1 + a * 3 + b; + my c = 6; +} + +my a = 2, b = 4; + +foo; # Run the procedure. Print out "11\n" +say c; # Print out "6\n"; + +proc bar { + say "I am bar"; + + undef baz; + + proc baz { + say "I am baz"; + } +} + +# Here bar would produce an error because the proc is not yet defined! +# bar; + +bar; # Here the procedure bar will define the procedure baz! +baz; # Now the procedure baz is defined! +bar; # Here the procedure bar will redefine baz again! + +#* + * Examples of how to use scopeing + *# + +my foo = 1; + +{ + # Prints out 1 + assert 1 == (put defined foo); + + { + my bar = 2; + + # Prints out 1 + assert 1 == (put defined bar); + } + + # Prints out 0 + assert 0 == (put defined bar); + + my baz = 3; +} + +# Prints out 0 +assert 0 == (say defined bar); + + + +#* + * Examples how to convert types + *# + +assert 1 == say 1; # Integer output + +assert 1 == say double 1; # Double output + +assert 14 == say 1 + string 13; # Implicit type conversion to Integer + +assert 2 == say integer 2.8; # Rounds down to the Integer 2 + +assert say integer double string put say neg 12; # Nonsense but working :) + + +#* + * Examples of how to define variables + *# + +# Defines the variables +my foo = 1 + 1; +my bar = 4 - 1, baz = 100 + 1, bay; + +# bay has been initialized with the default value of 0 +say bay; + +# Prints out "5\n" +assert 5 == (say foo + bar); + +# Pritns out "51101\n" +assert 51 == (put baz - 50); +assert 101 == (say baz); + +# Change the value of the variable to 99 and print it out +assert 99 == (baz = 99); +say baz; + diff --git a/examples/conditionals.fy b/examples/conditionals.fy index 2dc027f..1260ae2 100644 --- a/examples/conditionals.fy +++ b/examples/conditionals.fy @@ -37,3 +37,5 @@ assert 1 == (put 1 >= 1); assert 1 == (put 1 >= 0); assert 0 == (put 0 >= 1); assert 1 == (say 0 >= 0); + + diff --git a/examples/types.fy b/examples/types.fy index 1ac9751..1b9a0ac 100644 --- a/examples/types.fy +++ b/examples/types.fy @@ -12,7 +12,3 @@ assert 2 == say integer 2.8; # Rounds down to the Integer 2 assert say integer double string put say neg 12; # Nonsense but working :) -assert "TT_INTEGER" == say type 1; -assert "TT_DOUBLE" == say type 1.0; -assert "TT_STRING" == say type "1"; -assert "TT_ARRAY" == say type [1 2 3]; -- cgit v1.2.3 From 982e35bd0bd9bc9b55c0f898556c3e1831141258 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 19 Oct 2008 00:12:57 +0000 Subject: synonyms work --- examples/synonyms.fy | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 examples/synonyms.fy (limited to 'examples') diff --git a/examples/synonyms.fy b/examples/synonyms.fy new file mode 100644 index 0000000..3ffb105 --- /dev/null +++ b/examples/synonyms.fy @@ -0,0 +1,32 @@ +#* + * Examples of how to use synonyms + *# + +# Create a variable foo, and bar is a synonym for foo +my foo = "foo"; +my bar = \foo; + +# Reset the value of foo +foo = "bar"; + +# The synonym variable should now also set to "bar" +assert "bar" == say bar; + +# Create a new procedure baz +proc baz { + say "I am baz"; +} + +# Make a synonym baz, and undefine baz +my bay = \baz; +undef baz; + +# bay still has a reference of the original procedure baz +bay; # this prints aut "I am baz" + +assert 0 == defined baz; +assert 1 == defined bay; + +# This removes the procedure from memory +undef bay; + -- cgit v1.2.3 From d4657a5d7029ea66d19a5d238a9dd6bf75fe5bb0 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 19 Oct 2008 00:24:01 +0000 Subject: jo --- examples/all-examples.txt | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'examples') diff --git a/examples/all-examples.txt b/examples/all-examples.txt index bdf199f..b438de3 100644 --- a/examples/all-examples.txt +++ b/examples/all-examples.txt @@ -296,6 +296,39 @@ assert 0 == (say defined bar); +#* + * Examples of how to use synonyms + *# + +# Create a variable foo, and bar is a synonym for foo +my foo = "foo"; +my bar = \foo; + +# Reset the value of foo +foo = "bar"; + +# The synonym variable should now also set to "bar" +assert "bar" == say bar; + +# Create a new procedure baz +proc baz { + say "I am baz"; +} + +# Make a synonym baz, and undefine baz +my bay = \baz; +undef baz; + +# bay still has a reference of the original procedure baz +bay; # this prints aut "I am baz" + +assert 0 == defined baz; +assert 1 == defined bay; + +# This removes the procedure from memory +undef bay; + + #* * Examples how to convert types *# -- cgit v1.2.3 From 3d7b35bb37c066489546751e100c2c2b823ccba3 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 19 Oct 2008 17:48:21 +0000 Subject: refs and syms --- examples/synonyms.fy | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'examples') diff --git a/examples/synonyms.fy b/examples/synonyms.fy index 3ffb105..0dd30f5 100644 --- a/examples/synonyms.fy +++ b/examples/synonyms.fy @@ -19,7 +19,12 @@ proc baz { # Make a synonym baz, and undefine baz my bay = \baz; + +# Should be the num of syms for the same value +assert 2 == syms baz; +assert 2 == syms bay; undef baz; +assert 1 == syms bay; # bay still has a reference of the original procedure baz bay; # this prints aut "I am baz" -- cgit v1.2.3 From a1c3f47491b98cd9026f8e853cc9e72630805c12 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 26 Oct 2008 12:51:57 +0000 Subject: added the "scope" function --- examples/scopeing.fy | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'examples') diff --git a/examples/scopeing.fy b/examples/scopeing.fy index 2e36c2c..434f38f 100644 --- a/examples/scopeing.fy +++ b/examples/scopeing.fy @@ -13,6 +13,10 @@ my foo = 1; # Prints out 1 assert 1 == (put defined bar); + + # Prints out all available symbols at + # the current program position. + scope; } # Prints out 0 -- cgit v1.2.3 From 74576665ff39879f04e50ad6887a2178f42722c3 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 27 Oct 2008 06:52:06 +0000 Subject: --- examples/all-examples.txt | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'examples') diff --git a/examples/all-examples.txt b/examples/all-examples.txt index b438de3..f71e8a2 100644 --- a/examples/all-examples.txt +++ b/examples/all-examples.txt @@ -283,6 +283,10 @@ my foo = 1; # Prints out 1 assert 1 == (put defined bar); + + # Prints out all available symbols at + # the current program position. + scope; } # Prints out 0 @@ -317,7 +321,12 @@ proc baz { # Make a synonym baz, and undefine baz my bay = \baz; + +# Should be the num of syms for the same value +assert 2 == syms baz; +assert 2 == syms bay; undef baz; +assert 1 == syms bay; # bay still has a reference of the original procedure baz bay; # this prints aut "I am baz" -- cgit v1.2.3