summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2008-09-16 17:05:51 +0000
committerPaul Buetow <paul@buetow.org>2008-09-16 17:05:51 +0000
commit71185ab0ab0b08b4d5bb2e750ff85e11f105a453 (patch)
treea6ad933176f92b60d2f1560d2f1bac46ec6b9566
parent8b31b18a43dea55489e70d5b2ea6fc183cc67533 (diff)
array progress
-rw-r--r--Makefile2
-rw-r--r--README392
-rw-r--r--docs/help.txt2
-rw-r--r--docs/pod/fype.1.gzbin6105 -> 6302 bytes
-rw-r--r--docs/pod/fype.html191
-rw-r--r--docs/pod/fype.man157
-rw-r--r--docs/pod/fype.pod142
-rw-r--r--docs/pod/fype.tex154
-rw-r--r--docs/pod/fype.txt392
-rw-r--r--docs/stats.txt4
-rw-r--r--docs/version.txt2
-rw-r--r--examples/types.fy4
-rw-r--r--src/build.h2
-rw-r--r--src/core/convert.c23
-rw-r--r--src/core/function.c86
-rw-r--r--src/core/interpret.c65
-rw-r--r--src/core/symbol.c14
-rw-r--r--src/core/token.c53
-rw-r--r--src/core/token.h6
-rw-r--r--src/data/array.c50
-rw-r--r--src/data/array.h2
-rw-r--r--src/defines.h1
-rw-r--r--tmp/test.fy11
-rw-r--r--tmp/test.out28
24 files changed, 1065 insertions, 718 deletions
diff --git a/Makefile b/Makefile
index 5624b2e..719200c 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@ SRCS!=find ./src -name '*.c'
OBJS=$(SRCS:.c=.o)
CC?=cc
#CC=mingw32-gcc
-#DEBUG=-g3 -ggdb3
+DEBUG=-g3 -ggdb3
CFLAGS+=-c -Wall -std=c99 -pedantic $(DEBUG)
LDADD+=
HEADER?=docs/header.txt
diff --git a/README b/README
index 66a9695..b6f6969 100644
--- a/README
+++ b/README
@@ -75,42 +75,6 @@ GETTING STARTED
See the ./examples subdir of the Fype source distribution for examples!
See also fype -h for a list of all options.
-DATA TYPES
- Fype uses auto type conversion. However, if you want to know what's
- going on you may take a look at the provided basic datatypes.
-
- The basic data types
- *integer*
- Specifies an integer number
-
- *double*
- Specifies a double number
-
- *string*
- Specifies a string
-
- *number*
- May be an integer or a double number
-
- *any*
- May be of any type above
-
- *void*
- No type
-
- *identifier*
- It's a variable name or a procedure name or a function name
-
- Explicit type conversions
- (*integer*) integer *any*
- Converts any type to an integer
-
- (*double*) double *any*
- Converts any type to a double
-
- (*string*) string *any*
- Converts any type to a string
-
SYNTAX
Comments
Text from a # character until the end of the current line is considered
@@ -126,8 +90,8 @@ SYNTAX
say foo;
exit foo - bar;
- Paranthesis
- All paranthesis of function calls are optional. They help to make the
+ Parenthesis
+ All parenthesis of function calls are optional. They help to make the
code better readable. They also help to force precedences of
expressions.
@@ -175,216 +139,270 @@ SYNTAX
Runs the statements as long as the the expression evaluates to a
false value.
+DATA TYPES
+ Fype uses auto type conversion. However, if you want to know what's
+ going on you may take a look at the provided basic datatypes.
+
+ The basic data types
+ *integer*
+ (Internal name TT_INTEGER)
+
+ *double*
+ (Internal name TT_DOUBLE)
+
+ *string*
+ (Internal name TT_STRING)
+
+ *array*
+ (Internal name TT_ARRAY)
+
+ *number*
+ May be an integer or a double number
+
+ *any*
+ May be of any type above
+
+ *void*
+ No type
+
+ *identifier*
+ It's a variable name or a procedure name or a function name
+
+ Explicit type conversions
+ The data types inside the brackets are only showing the return types of
+ each function.
+
+ (*integer*) integer *any*
+ Converts any type to an integer.
+
+ (*double*) double *any*
+ Converts any type to a double.
+
+ (*string*) string *any*
+ Converts any type to a string.
+
+ (*array*) array *any*
+ Converts any type to an array. This function is not yet implemented.
+
+ More functions for data types
+ (*string*) type *any*
+ Returns the name of the current type. Examples:
+
+ my foo = 1;
+ put type foo; # Prints "TT_INTEGER"
+ put type 1.2; # Prints "TT_DOUBLE"
+
VARIABLES
- Variables can be defined with the my keyword. If you don't assign a
- value during declaration, then it's using the default integer value 0.
- Variables may be changed during program runtime. Variables may be
- deleted using the undef keyword! Example of defining variables:
+ Variables can be defined with the my keyword. If you don't assign a
+ value during declaration, then it's using the default integer value
+ 0. Variables may be changed during program runtime. Variables may be
+ deleted using the undef keyword! Example of defining variables:
- my foo = 1 + 2;
- say foo;
+ my foo = 1 + 2;
+ say foo;
- my bar = 12, baz = foo;
- say 1 + bar;
- say bar;
+ my bar = 12, baz = foo;
+ say 1 + bar;
+ say bar;
- my baz;
- say baz; # Will print out 0
+ my baz;
+ say baz; # Will print out 0
- You may use the defined keyword to check if an identifier has been
- defined or not.
+ You may use the defined keyword to check if an identifier has been
+ defined or not.
- ifnot defined foo {
- say "No foo yet defined";
- }
+ ifnot defined foo {
+ say "No foo yet defined";
+ }
- my foo = 1;
+ my foo = 1;
- if defined foo {
- put "foo is defined and has the value ";
- say foo;
- }
+ if defined foo {
+ put "foo is defined and has the value ";
+ say foo;
+ }
BUILT IN FUNCTIONS
- In Fype, operators are built in functions as well. The difference is,
- that they may be written in infix notation instead in front of the
- arguments. The types inside the () specify the return types.
+ In Fype, operators are built in functions as well. The difference
+ is, that they may be written in infix notation instead in front of
+ the arguments. The types inside the () specify the return types.
Math
- (*any*) *any* + *any*
- Special string behavior: A string will get auto convertet into an
- *integer*.
+ (*any*) *any* + *any*
+ Special string behavior: A string will get auto convertet into
+ an *integer*.
- (*any*) *any* - *any*
- Special string behavior: A string will get auto convertet into an
- *integer*.
+ (*any*) *any* - *any*
+ Special string behavior: A string will get auto convertet into
+ an *integer*.
- (*any*) *any* * *any*
- Special string behavior: A string will get auto convertet into an
- *integer*.
+ (*any*) *any* * *any*
+ Special string behavior: A string will get auto convertet into
+ an *integer*.
- (*any*) *any* / *any*
- Special string behavior: A string will get auto convertet into an
- *integer*.
+ (*any*) *any* / *any*
+ Special string behavior: A string will get auto convertet into
+ an *integer*.
Conditional
- (*integer*) *any* == *any*
- (*integer*) *any* != *any*
- (*integer*) *any* <= *any*
- (*integer*) *any* >= *any*
- (*integer*) *any* < *any*
- (*integer*) *any* > *any*
- (*integer*) not *any*
+ (*integer*) *any* == *any*
+ (*integer*) *any* != *any*
+ (*integer*) *any* <= *any*
+ (*integer*) *any* >= *any*
+ (*integer*) *any* < *any*
+ (*integer*) *any* > *any*
+ (*integer*) not *any*
Definedness
- (*integer*) defined *identifier*
- Returns 1 if *identifier* has been defined. Returns 0 else.
+ (*integer*) defined *identifier*
+ Returns 1 if *identifier* has been defined. Returns 0 else.
- (*integer*) undef *identifier*
- Tries to undefine/delete the *identifier*. Returns 1 if success,
- otherwise 0 is returned.
+ (*integer*) undef *identifier*
+ Tries to undefine/delete the *identifier*. Returns 1 if success,
+ otherwise 0 is returned.
Bitwise
- (*integer*) *any* :< *any*
- (*integer*) *any* :> *any*
- (*integer*) *any* and *any*
- (*integer*) *any* or *any*
- (*integer*) *any* xor *any*
+ (*integer*) *any* :< *any*
+ (*integer*) *any* :> *any*
+ (*integer*) *any* and *any*
+ (*integer*) *any* or *any*
+ (*integer*) *any* xor *any*
Numeric
- (*number*) neg *number*
- This function returns the negative value of *any*
+ (*number*) neg *number*
+ This function returns the negative value of *any*
- (*integer*) no [*integer*]
- This function returns 1 if the argument is 0, otherwise it will
- return 0! If no argument is given, then 0 is returned!
+ (*integer*) no [*integer*]
+ This function returns 1 if the argument is 0, otherwise it will
+ return 0! If no argument is given, then 0 is returned!
- (*integer*) yes [*integer*]
- This function always returns 1. The parameter is optional.
+ (*integer*) yes [*integer*]
+ This function always returns 1. The parameter is optional.
- # Prints out 1, because foo is not defined
- if yes { say no defined foo; }
+ # Prints out 1, because foo is not defined
+ if yes { say no defined foo; }
System
- (*void*) end
- Exits the program with the exit status of 0
+ (*void*) end
+ Exits the program with the exit status of 0
- (*void*) exit *integer*
- Exits the program with the specified exit status
+ (*void*) exit *integer*
+ Exits the program with the specified exit status
- (*integer*) fork
- Fork forks a subprocess. It returns 0 for the child process and the
- pid of the child process otherwise! Example:
+ (*integer*) fork
+ Fork forks a subprocess. It returns 0 for the child process and
+ the pid of the child process otherwise! Example:
- my pid = fork;
+ my pid = fork;
- if pid {
- put "I am the parent process; child has the pid ";
- say pid;
+ if pid {
+ put "I am the parent process; child has the pid ";
+ say pid;
- } ifnot pid {
- say "I am the child process";
- }
+ } ifnot pid {
+ say "I am the child process";
+ }
- (*integer*) gc
- Executes the garbage collector and returns the number of items
- freed! You may wonder why most of the time it will return a value of
- 0! Fype tries to free not needed memory asap. This may change in
- future versions in order to gain faster execution of scripts!
+ (*integer*) gc
+ Executes the garbage collector and returns the number of items
+ freed! You may wonder why most of the time it will return a
+ value of 0! Fype tries to free not needed memory asap. This may
+ change in future versions in order to gain faster execution of
+ scripts!
I/O
- (*any*) put *any*
- Prints out the argument
+ (*any*) put *any*
+ Prints out the argument
- (*any*) say *any*
- Same as put, but also includes an ending newline
+ (*any*) say *any*
+ Same as put, but also includes an ending newline
- (*void*) ln
- Just prints a newline
+ (*void*) ln
+ Just prints a newline
SELF DEFINING PROCEDURES AND FUNCTIONS
Procedures
- A procedure can be defined with the proc keyword and deleted with the
- undef keyword. A procedure does not return any value and does not
- support parameter passing. It's using already defined variables (e.g.
- global variables). A procedure does not have its own namespace. It's
- using the calling namespace. It is possible to define new variabes
- inside of a procedure in the current namespace.
-
- proc foo {
- say 1 + a * 3 + b;
- my c = 6;
- }
+ A procedure can be defined with the proc keyword and deleted with
+ the undef keyword. A procedure does not return any value and does
+ not support parameter passing. It's using already defined variables
+ (e.g. global variables). A procedure does not have its own
+ namespace. It's using the calling namespace. It is possible to
+ define new variabes inside of a procedure in the current namespace.
+
+ proc foo {
+ say 1 + a * 3 + b;
+ my c = 6;
+ }
- my a = 2, b = 4;
+ my a = 2, b = 4;
- foo; # Run the procedure. Print out "11\n"
- say c; # Print out "6\n";
+ foo; # Run the procedure. Print out "11\n"
+ say c; # Print out "6\n";
Nested procedures
- It's possible to define procedures inside of procedures. Since
- procedures don't have its own scope, nested procedures will be available
- to the current scope as soon as the main procedure has run the first
- time. You may use the defined keyword in order to check if a procedure
- has been defined or not.
-
- proc foo {
- say "I am foo";
-
- undef bar;
- proc bar {
- say "I am bar";
- }
- }
+ It's possible to define procedures inside of procedures. Since
+ procedures don't have its own scope, nested procedures will be
+ available to the current scope as soon as the main procedure has run
+ the first time. You may use the defined keyword in order to check if
+ a procedure has been defined or not.
+
+ proc foo {
+ say "I am foo";
+
+ undef bar;
+ proc bar {
+ say "I am bar";
+ }
+ }
- # Here bar would produce an error because
- # the proc is not yet defined!
- # bar;
+ # Here bar would produce an error because
+ # the proc is not yet defined!
+ # bar;
- foo; # Here the procedure foo will define the procedure bar!
- bar; # Now the procedure bar is defined!
- foo; # Here the procedure foo will redefine bar again!
+ foo; # Here the procedure foo will define the procedure bar!
+ bar; # Now the procedure bar is defined!
+ foo; # Here the procedure foo will redefine bar again!
Functions
- A function should be defined with the func keyword and deleted with the
- undef keyword. Function not yet return values (will be changed in future
- versions) and supports not yet parameter passing (will be changed in
- future versions). It's using local (lexical scoped) variables. If a
- certain variable does not exist It's using already defined variables
- (e.g. one scope above).
-
- func foo {
- say 1 + a * 3 + b;
- my c = 6;
- }
+ A function should be defined with the func keyword and deleted with
+ the undef keyword. Function not yet return values (will be changed
+ in future versions) and supports not yet parameter passing (will be
+ changed in future versions). It's using local (lexical scoped)
+ variables. If a certain variable does not exist It's using already
+ defined variables (e.g. one scope above).
+
+ func foo {
+ say 1 + a * 3 + b;
+ my c = 6;
+ }
- my a = 2, b = 4;
+ my a = 2, b = 4;
- foo; # Run the procedure. Print out "11\n"
- say c; # Will produce an error, because c is out of scoped!
+ foo; # Run the procedure. Print out "11\n"
+ say c; # Will produce an error, because c is out of scoped!
Nested functions
- Nested functions work the same way the nested procedures work, with the
- exception that nested functions will not be available any more after the
- function has been left!
+ Nested functions work the same way the nested procedures work, with
+ the exception that nested functions will not be available any more
+ after the function has been left!
- func foo {
- func bar {
- say "Hello i am nested";
- }
+ func foo {
+ func bar {
+ say "Hello i am nested";
+ }
- bar; # Calling nested
- }
+ bar; # Calling nested
+ }
- foo;
- bar; # Will produce an error, because bar is out of scope!
+ foo;
+ bar; # Will produce an error, because bar is out of scope!
AUTHOR
- Paul C. Buetow (http://paul.buetow.org)
+ Paul C. Buetow (http://paul.buetow.org)
WEBSITE
- The Fype Language (http://fype.buetow.org)
+ The Fype Language (http://fype.buetow.org)
SEE ALSO
- awk(1) cc(1) make(1)
+ awk(1) cc(1)
diff --git a/docs/help.txt b/docs/help.txt
index d7163e6..25988ea 100644
--- a/docs/help.txt
+++ b/docs/help.txt
@@ -1,4 +1,4 @@
-Fype v0.1-devel Build 9208
+Fype v0.1-devel Build 9322
Copyright by Paul C. Buetow (2005 - 2008) <fype@dev.buetow.org>
-e Executes given code string (see synopses)
-h Prints this help
diff --git a/docs/pod/fype.1.gz b/docs/pod/fype.1.gz
index e05d4c5..29ae39d 100644
--- a/docs/pod/fype.1.gz
+++ b/docs/pod/fype.1.gz
Binary files differ
diff --git a/docs/pod/fype.html b/docs/pod/fype.html
index b88a1b4..47397a4 100644
--- a/docs/pod/fype.html
+++ b/docs/pod/fype.html
@@ -20,23 +20,24 @@
<li><a href="#parsing___code_generation">PARSING / CODE GENERATION</a></li>
<li><a href="#requirements">REQUIREMENTS</a></li>
<li><a href="#getting_started">GETTING STARTED</a></li>
- <li><a href="#data_types">DATA TYPES</a></li>
- <ul>
-
- <li><a href="#the_basic_data_types">The basic data types</a></li>
- <li><a href="#explicit_type_conversions">Explicit type conversions</a></li>
- </ul>
-
<li><a href="#syntax">SYNTAX</a></li>
<ul>
<li><a href="#comments">Comments</a></li>
<li><a href="#statements">Statements</a></li>
- <li><a href="#paranthesis">Paranthesis</a></li>
+ <li><a href="#parenthesis">Parenthesis</a></li>
<li><a href="#scopeing">Scopeing</a></li>
<li><a href="#control_statements">Control statements</a></li>
</ul>
+ <li><a href="#data_types">DATA TYPES</a></li>
+ <ul>
+
+ <li><a href="#the_basic_data_types">The basic data types</a></li>
+ <li><a href="#explicit_type_conversions">Explicit type conversions</a></li>
+ <li><a href="#more_functions_for_data_types">More functions for data types</a></li>
+ </ul>
+
<li><a href="#variables">VARIABLES</a></li>
<li><a href="#built_in_functions">BUILT IN FUNCTIONS</a></li>
<ul>
@@ -132,6 +133,81 @@ TODO file of the source distribution of Fype!</p>
<p>
</p>
<hr />
+<h1><a name="syntax">SYNTAX</a></h1>
+<p>
+</p>
+<h2><a name="comments">Comments</a></h2>
+<p>Text from a <strong>#</strong> character until the end of the current line is considered being a comment. Multi line comments may start with an <strong>#*</strong> and and with an <strong>*#</strong> anywhere. Exceptions are if those signs are inside of strings.</p>
+<p>
+</p>
+<h2><a name="statements">Statements</a></h2>
+<p>A Fype program is a list of statements. Each keyword, expression or function call is part of a statement. Each statement is ended with a semicolon. Example:</p>
+<pre>
+ my bar = 3, foo = 1 + 2;
+ say foo;
+ exit foo - bar;</pre>
+<p>
+</p>
+<h2><a name="parenthesis">Parenthesis</a></h2>
+<p>All parenthesis of function calls are optional. They help to make the code better readable. They also help to force precedences of expressions.</p>
+<p>
+</p>
+<h2><a name="scopeing">Scopeing</a></h2>
+<p>A new scope starts with an { and ends with an }. An exception is a procedure, which does not use its own scope (see later in this manual). Control statements and functions support scopeings. Here is a small example how to use scopes:</p>
+<pre>
+ my foo = 1;</pre>
+<pre>
+ {
+ # Prints out 1
+ put defined foo;
+ {
+ my bar = 2;</pre>
+<pre>
+ # Prints out 1
+ put defined bar;
+ }</pre>
+<pre>
+ # Prints out 0
+ put defined bar;</pre>
+<pre>
+ my baz = 3;
+ }</pre>
+<pre>
+ # Prints out 0
+ say defined bar;</pre>
+<p>
+</p>
+<h2><a name="control_statements">Control statements</a></h2>
+<p>Fype knows the following control statements:</p>
+<dl>
+<dt><strong><a name="item_if__3cexpression_3e__7b__3cstatements_3e__7d">if <em>&lt;expression</em>&gt; { <em>&lt;statements</em>&gt; }</a></strong>
+
+<dd>
+<p>Runs the statements if the expression evaluates to a true value.</p>
+</dd>
+</li>
+<dt><strong><a name="item_ifnot__3cexpression_3e__7b__3cstatements_3e__7d">ifnot <em>&lt;expression</em>&gt; { <em>&lt;statements</em>&gt; }</a></strong>
+
+<dd>
+<p>Runs the statements if the expression evaluates to a false value.</p>
+</dd>
+</li>
+<dt><strong><a name="item_while__3cexpression_3e__7b__3cstatements_3e__7d">while <em>&lt;expression</em>&gt; { <em>&lt;statements</em>&gt; }</a></strong>
+
+<dd>
+<p>Runs the statements as long as the the expression evaluates to a true value.</p>
+</dd>
+</li>
+<dt><strong><a name="item_until__3cexpression_3e__7b__3cstatements_3e__7d">until <em>&lt;expression</em>&gt; { <em>&lt;statements</em>&gt; }</a></strong>
+
+<dd>
+<p>Runs the statements as long as the the expression evaluates to a false value.</p>
+</dd>
+</li>
+</dl>
+<p>
+</p>
+<hr />
<h1><a name="data_types">DATA TYPES</a></h1>
<p>Fype uses auto type conversion. However, if you want to know what's going on you may take a look at the provided basic datatypes.</p>
<p>
@@ -141,19 +217,25 @@ TODO file of the source distribution of Fype!</p>
<dt><strong><a name="item_integer"><em>integer</em></a></strong>
<dd>
-<p>Specifies an integer number</p>
+<p>(Internal name TT_INTEGER)</p>
</dd>
</li>
<dt><strong><a name="item_double"><em>double</em></a></strong>
<dd>
-<p>Specifies a double number</p>
+<p>(Internal name TT_DOUBLE)</p>
</dd>
</li>
<dt><strong><a name="item_string"><em>string</em></a></strong>
<dd>
-<p>Specifies a string</p>
+<p>(Internal name TT_STRING)</p>
+</dd>
+</li>
+<dt><strong><a name="item_array"><em>array</em></a></strong>
+
+<dd>
+<p>(Internal name TT_ARRAY)</p>
</dd>
</li>
<dt><strong><a name="item_number"><em>number</em></a></strong>
@@ -184,98 +266,47 @@ TODO file of the source distribution of Fype!</p>
<p>
</p>
<h2><a name="explicit_type_conversions">Explicit type conversions</a></h2>
+<p>The data types inside the brackets are only showing the return types of each function.</p>
<dl>
<dt><strong><a name="item__28integer_29_integer_any">(<em>integer</em>) <strong>integer</strong> <em>any</em></a></strong>
<dd>
-<p>Converts any type to an integer</p>
+<p>Converts any type to an integer.</p>
</dd>
</li>
<dt><strong><a name="item__28double_29_double_any">(<em>double</em>) <strong>double</strong> <em>any</em></a></strong>
<dd>
-<p>Converts any type to a double</p>
+<p>Converts any type to a double.</p>
</dd>
</li>
<dt><strong><a name="item__28string_29_string_any">(<em>string</em>) <strong>string</strong> <em>any</em></a></strong>
<dd>
-<p>Converts any type to a string</p>
+<p>Converts any type to a string.</p>
</dd>
</li>
-</dl>
-<p>
-</p>
-<hr />
-<h1><a name="syntax">SYNTAX</a></h1>
-<p>
-</p>
-<h2><a name="comments">Comments</a></h2>
-<p>Text from a <strong>#</strong> character until the end of the current line is considered being a comment. Multi line comments may start with an <strong>#*</strong> and and with an <strong>*#</strong> anywhere. Exceptions are if those signs are inside of strings.</p>
-<p>
-</p>
-<h2><a name="statements">Statements</a></h2>
-<p>A Fype program is a list of statements. Each keyword, expression or function call is part of a statement. Each statement is ended with a semicolon. Example:</p>
-<pre>
- my bar = 3, foo = 1 + 2;
- say foo;
- exit foo - bar;</pre>
-<p>
-</p>
-<h2><a name="paranthesis">Paranthesis</a></h2>
-<p>All paranthesis of function calls are optional. They help to make the code better readable. They also help to force precedences of expressions.</p>
-<p>
-</p>
-<h2><a name="scopeing">Scopeing</a></h2>
-<p>A new scope starts with an { and ends with an }. An exception is a procedure, which does not use its own scope (see later in this manual). Control statements and functions support scopeings. Here is a small example how to use scopes:</p>
-<pre>
- my foo = 1;</pre>
-<pre>
- {
- # Prints out 1
- put defined foo;
- {
- my bar = 2;</pre>
-<pre>
- # Prints out 1
- put defined bar;
- }</pre>
-<pre>
- # Prints out 0
- put defined bar;</pre>
-<pre>
- my baz = 3;
- }</pre>
-<pre>
- # Prints out 0
- say defined bar;</pre>
-<p>
-</p>
-<h2><a name="control_statements">Control statements</a></h2>
-<p>Fype knows the following control statements:</p>
-<dl>
-<dt><strong><a name="item_if__3cexpression_3e__7b__3cstatements_3e__7d">if <em>&lt;expression</em>&gt; { <em>&lt;statements</em>&gt; }</a></strong>
-
-<dd>
-<p>Runs the statements if the expression evaluates to a true value.</p>
-</dd>
-</li>
-<dt><strong><a name="item_ifnot__3cexpression_3e__7b__3cstatements_3e__7d">ifnot <em>&lt;expression</em>&gt; { <em>&lt;statements</em>&gt; }</a></strong>
+<dt><strong><a name="item__28array_29_array_any">(<em>array</em>) <strong>array</strong> <em>any</em></a></strong>
<dd>
-<p>Runs the statements if the expression evaluates to a false value.</p>
+<p>Converts any type to an array. This function is not yet implemented.</p>
</dd>
</li>
-<dt><strong><a name="item_while__3cexpression_3e__7b__3cstatements_3e__7d">while <em>&lt;expression</em>&gt; { <em>&lt;statements</em>&gt; }</a></strong>
+</dl>
+<p>
+</p>
+<h2><a name="more_functions_for_data_types">More functions for data types</a></h2>
+<dl>
+<dt><strong><a name="item__28string_29_type_any">(<em>string</em>) <strong>type</strong> <em>any</em></a></strong>
<dd>
-<p>Runs the statements as long as the the expression evaluates to a true value.</p>
+<p>Returns the name of the current type. Examples:</p>
</dd>
-</li>
-<dt><strong><a name="item_until__3cexpression_3e__7b__3cstatements_3e__7d">until <em>&lt;expression</em>&gt; { <em>&lt;statements</em>&gt; }</a></strong>
-
<dd>
-<p>Runs the statements as long as the the expression evaluates to a false value.</p>
+<pre>
+ my foo = 1;
+ put type foo; # Prints &quot;TT_INTEGER&quot;
+ put type 1.2; # Prints &quot;TT_DOUBLE&quot;</pre>
</dd>
</li>
</dl>
@@ -580,7 +611,7 @@ keyword in order to check if a procedure has been defined or not.</p>
</p>
<hr />
<h1><a name="see_also">SEE ALSO</a></h1>
-<p><code>awk(1)</code> <code>cc(1)</code> <code>make(1)</code>
+<p><code>awk(1)</code> <code>cc(1)</code>
</p>
diff --git a/docs/pod/fype.man b/docs/pod/fype.man
index b3d89bf..1be72ec 100644
--- a/docs/pod/fype.man
+++ b/docs/pod/fype.man
@@ -129,7 +129,7 @@
.\" ========================================================================
.\"
.IX Title "FYPE 1"
-.TH FYPE 1 "2008-09-06" "Fype v0.1-devel Build 9208" "The Fype Users Manual Page"
+.TH FYPE 1 "2008-09-16" "Fype v0.1-devel Build 9269" "The Fype Users Manual Page"
.SH "NAME"
\&\fBFype\fR is \fBF\fRor \fBY\fRour \fBP\fRrogram \fBE\fRxecution
.PP
@@ -201,43 +201,6 @@ Run a .fy file:
.Ve
.PP
See the ./examples subdir of the Fype source distribution for examples! See also fype \-h for a list of all options.
-.SH "DATA TYPES"
-.IX Header "DATA TYPES"
-Fype uses auto type conversion. However, if you want to know what's going on you may take a look at the provided basic datatypes.
-.Sh "The basic data types"
-.IX Subsection "The basic data types"
-.IP "\fIinteger\fR" 4
-.IX Item "integer"
-Specifies an integer number
-.IP "\fIdouble\fR" 4
-.IX Item "double"
-Specifies a double number
-.IP "\fIstring\fR" 4
-.IX Item "string"
-Specifies a string
-.IP "\fInumber\fR" 4
-.IX Item "number"
-May be an integer or a double number
-.IP "\fIany\fR" 4
-.IX Item "any"
-May be of any type above
-.IP "\fIvoid\fR" 4
-.IX Item "void"
-No type
-.IP "\fIidentifier\fR" 4
-.IX Item "identifier"
-It's a variable name or a procedure name or a function name
-.Sh "Explicit type conversions"
-.IX Subsection "Explicit type conversions"
-.IP "(\fIinteger\fR) \fBinteger\fR \fIany\fR" 4
-.IX Item "(integer) integer any"
-Converts any type to an integer
-.IP "(\fIdouble\fR) \fBdouble\fR \fIany\fR" 4
-.IX Item "(double) double any"
-Converts any type to a double
-.IP "(\fIstring\fR) \fBstring\fR \fIany\fR" 4
-.IX Item "(string) string any"
-Converts any type to a string
.SH "SYNTAX"
.IX Header "SYNTAX"
.Sh "Comments"
@@ -252,9 +215,9 @@ A Fype program is a list of statements. Each keyword, expression or function cal
\& say foo;
\& exit foo - bar;
.Ve
-.Sh "Paranthesis"
-.IX Subsection "Paranthesis"
-All paranthesis of function calls are optional. They help to make the code better readable. They also help to force precedences of expressions.
+.Sh "Parenthesis"
+.IX Subsection "Parenthesis"
+All parenthesis of function calls are optional. They help to make the code better readable. They also help to force precedences of expressions.
.Sh "Scopeing"
.IX Subsection "Scopeing"
A new scope starts with an { and ends with an }. An exception is a procedure, which does not use its own scope (see later in this manual). Control statements and functions support scopeings. Here is a small example how to use scopes:
@@ -306,39 +269,94 @@ Runs the statements as long as the the expression evaluates to a true value.
.IP "until \fI<expression\fR> { \fI<statements\fR> }" 4
.IX Item "until <expression> { <statements> }"
Runs the statements as long as the the expression evaluates to a false value.
+.SH "DATA TYPES"
+.IX Header "DATA TYPES"
+Fype uses auto type conversion. However, if you want to know what's going on you may take a look at the provided basic datatypes.
+.Sh "The basic data types"
+.IX Subsection "The basic data types"
+.IP "\fIinteger\fR" 4
+.IX Item "integer"
+(Internal name \s-1TT_INTEGER\s0)
+.IP "\fIdouble\fR" 4
+.IX Item "double"
+(Internal name \s-1TT_DOUBLE\s0)
+.IP "\fIstring\fR" 4
+.IX Item "string"
+(Internal name \s-1TT_STRING\s0)
+.IP "\fIarray\fR" 4
+.IX Item "array"
+(Internal name \s-1TT_ARRAY\s0)
+.IP "\fInumber\fR" 4
+.IX Item "number"
+May be an integer or a double number
+.IP "\fIany\fR" 4
+.IX Item "any"
+May be of any type above
+.IP "\fIvoid\fR" 4
+.IX Item "void"
+No type
+.IP "\fIidentifier\fR" 4
+.IX Item "identifier"
+It's a variable name or a procedure name or a function name
+.Sh "Explicit type conversions"
+.IX Subsection "Explicit type conversions"
+The data types inside the brackets are only showing the return types of each function.
+.IP "(\fIinteger\fR) \fBinteger\fR \fIany\fR" 4
+.IX Item "(integer) integer any"
+Converts any type to an integer.
+.IP "(\fIdouble\fR) \fBdouble\fR \fIany\fR" 4
+.IX Item "(double) double any"
+Converts any type to a double.
+.IP "(\fIstring\fR) \fBstring\fR \fIany\fR" 4
+.IX Item "(string) string any"
+Converts any type to a string.
+.IP "(\fIarray\fR) \fBarray\fR \fIany\fR" 4
+.IX Item "(array) array any"
+Converts any type to an array. This function is not yet implemented.
+.Sh "More functions for data types"
+.IX Subsection "More functions for data types"
+.IP "(\fIstring\fR) \fBtype\fR \fIany\fR" 4
+.IX Item "(string) type any"
+Returns the name of the current type. Examples:
+.Sp
+.Vb 3
+\& my foo = 1;
+\& put type foo; # Prints "TT_INTEGER"
+\& put type 1.2; # Prints "TT_DOUBLE"
+.Ve
.SH "VARIABLES"
.IX Header "VARIABLES"
Variables can be defined with the \fBmy\fR keyword. If you don't assign a value during declaration, then it's using the default integer value 0. Variables may be changed during program runtime. Variables may be deleted using the \fBundef\fR keyword! Example of defining variables:
-.PP
+.Sp
.Vb 2
\& my foo = 1 + 2;
\& say foo;
.Ve
-.PP
+.Sp
.Vb 3
\& my bar = 12, baz = foo;
\& say 1 + bar;
\& say bar;
.Ve
-.PP
+.Sp
.Vb 2
\& my baz;
\& say baz; # Will print out 0
.Ve
-.PP
+.Sp
You may use the \fBdefined\fR keyword to check if an identifier has been defined or
not.
-.PP
+.Sp
.Vb 3
\& ifnot defined foo {
\& say "No foo yet defined";
\& }
.Ve
-.PP
+.Sp
.Vb 1
\& my foo = 1;
.Ve
-.PP
+.Sp
.Vb 4
\& if defined foo {
\& put "foo is defined and has the value ";
@@ -350,6 +368,7 @@ not.
In Fype, operators are built in functions as well. The difference is, that they may be written in infix notation instead in front of the arguments. The types inside the () specify the return types.
.Sh "Math"
.IX Subsection "Math"
+.RS 4
.IP "(\fIany\fR) \fIany\fR \fB+\fR \fIany\fR" 4
.IX Item "(any) any + any"
Special string behavior: A string will get auto convertet into an \fIinteger\fR.
@@ -362,6 +381,8 @@ Special string behavior: A string will get auto convertet into an \fIinteger\fR.
.IP "(\fIany\fR) \fIany\fR \fB/\fR \fIany\fR" 4
.IX Item "(any) any / any"
Special string behavior: A string will get auto convertet into an \fIinteger\fR.
+.RE
+.RS 4
.Sh "Conditional"
.IX Subsection "Conditional"
.IP "(\fIinteger\fR) \fIany\fR \fB==\fR \fIany\fR" 4
@@ -379,6 +400,8 @@ Special string behavior: A string will get auto convertet into an \fIinteger\fR.
.IX Item "(integer) any > any"
.IP "(\fIinteger\fR) \fBnot\fR \fIany\fR" 4
.IX Item "(integer) not any"
+.RE
+.RS 4
.PD
.Sh "Definedness"
.IX Subsection "Definedness"
@@ -388,6 +411,8 @@ Returns 1 if \fIidentifier\fR has been defined. Returns 0 else.
.IP "(\fIinteger\fR) \fBundef\fR \fIidentifier\fR" 4
.IX Item "(integer) undef identifier"
Tries to undefine/delete the \fIidentifier\fR. Returns 1 if success, otherwise 0 is returned.
+.RE
+.RS 4
.Sh "Bitwise"
.IX Subsection "Bitwise"
.IP "(\fIinteger\fR) \fIany\fR \fB:<\fR \fIany\fR" 4
@@ -401,6 +426,8 @@ Tries to undefine/delete the \fIidentifier\fR. Returns 1 if success, otherwise 0
.IX Item "(integer) any or any"
.IP "(\fIinteger\fR) \fIany\fR \fBxor\fR \fIany\fR" 4
.IX Item "(integer) any xor any"
+.RE
+.RS 4
.PD
.Sh "Numeric"
.IX Subsection "Numeric"
@@ -419,6 +446,8 @@ This function always returns 1. The parameter is optional.
\& # Prints out 1, because foo is not defined
\& if yes { say no defined foo; }
.Ve
+.RE
+.RS 4
.Sh "System"
.IX Subsection "System"
.IP "(\fIvoid\fR) \fBend\fR" 4
@@ -453,6 +482,8 @@ Executes the garbage collector and returns the number of items freed! You may
wonder why most of the time it will return a value of 0! Fype tries to free not
needed memory asap. This may change in future versions in order to gain faster
execution of scripts!
+.RE
+.RS 4
.Sh "I/O"
.IX Subsection "I/O"
.IP "(\fIany\fR) \fBput\fR \fIany\fR" 4
@@ -464,23 +495,25 @@ Same as put, but also includes an ending newline
.IP "(\fIvoid\fR) \fBln\fR" 4
.IX Item "(void) ln"
Just prints a newline
+.RE
+.RS 4
.SH "SELF DEFINING PROCEDURES AND FUNCTIONS"
.IX Header "SELF DEFINING PROCEDURES AND FUNCTIONS"
.Sh "Procedures"
.IX Subsection "Procedures"
A procedure can be defined with the \fBproc\fR keyword and deleted with the \fBundef\fR keyword. A procedure does not return any value and does not support parameter passing. It's using already defined variables (e.g. global variables). A procedure does not have its own namespace. It's using the calling namespace. It is possible to define new variabes inside of a procedure in the current namespace.
-.PP
+.Sp
.Vb 4
\& proc foo {
\& say 1 + a * 3 + b;
\& my c = 6;
\& }
.Ve
-.PP
+.Sp
.Vb 1
\& my a = 2, b = 4;
.Ve
-.PP
+.Sp
.Vb 2
\& foo; # Run the procedure. Print out "11\en"
\& say c; # Print out "6\en";
@@ -491,12 +524,12 @@ It's possible to define procedures inside of procedures. Since procedures don't
have its own scope, nested procedures will be available to the current scope as
soon as the main procedure has run the first time. You may use the \fBdefined\fR
keyword in order to check if a procedure has been defined or not.
-.PP
+.Sp
.Vb 2
\& proc foo {
\& say "I am foo";
.Ve
-.PP
+.Sp
.Vb 5
\& undef bar;
\& proc bar {
@@ -504,13 +537,13 @@ keyword in order to check if a procedure has been defined or not.
\& }
\& }
.Ve
-.PP
+.Sp
.Vb 3
\& # Here bar would produce an error because
\& # the proc is not yet defined!
\& # bar;
.Ve
-.PP
+.Sp
.Vb 3
\& foo; # Here the procedure foo will define the procedure bar!
\& bar; # Now the procedure bar is defined!
@@ -519,18 +552,18 @@ keyword in order to check if a procedure has been defined or not.
.Sh "Functions"
.IX Subsection "Functions"
A function should be defined with the \fBfunc\fR keyword and deleted with the \fBundef\fR keyword. Function not yet return values (will be changed in future versions) and supports not yet parameter passing (will be changed in future versions). It's using local (lexical scoped) variables. If a certain variable does not exist It's using already defined variables (e.g. one scope above).
-.PP
+.Sp
.Vb 4
\& func foo {
\& say 1 + a * 3 + b;
\& my c = 6;
\& }
.Ve
-.PP
+.Sp
.Vb 1
\& my a = 2, b = 4;
.Ve
-.PP
+.Sp
.Vb 2
\& foo; # Run the procedure. Print out "11\en"
\& say c; # Will produce an error, because c is out of scoped!
@@ -538,19 +571,19 @@ A function should be defined with the \fBfunc\fR keyword and deleted with the \f
.Sh "Nested functions"
.IX Subsection "Nested functions"
Nested functions work the same way the nested procedures work, with the exception that nested functions will not be available any more after the function has been left!
-.PP
+.Sp
.Vb 4
\& func foo {
\& func bar {
\& say "Hello i am nested";
\& }
.Ve
-.PP
+.Sp
.Vb 2
\& bar; # Calling nested
\& }
.Ve
-.PP
+.Sp
.Vb 2
\& foo;
\& bar; # Will produce an error, because bar is out of scope!
@@ -563,4 +596,4 @@ Paul C. Buetow (http://paul.buetow.org)
The Fype Language (http://fype.buetow.org)
.SH "SEE ALSO"
.IX Header "SEE ALSO"
-\&\fIawk\fR\|(1) \fIcc\fR\|(1) \fImake\fR\|(1)
+\&\fIawk\fR\|(1) \fIcc\fR\|(1)
diff --git a/docs/pod/fype.pod b/docs/pod/fype.pod
index 2e41645..6ec8061 100644
--- a/docs/pod/fype.pod
+++ b/docs/pod/fype.pod
@@ -68,62 +68,6 @@ Run a .fy file:
See the ./examples subdir of the Fype source distribution for examples! See also fype -h for a list of all options.
-=head1 DATA TYPES
-
-Fype uses auto type conversion. However, if you want to know what's going on you may take a look at the provided basic datatypes.
-
-=head2 The basic data types
-
-=over
-
-=item I<integer>
-
-Specifies an integer number
-
-=item I<double>
-
-Specifies a double number
-
-=item I<string>
-
-Specifies a string
-
-=item I<number>
-
-May be an integer or a double number
-
-=item I<any>
-
-May be of any type above
-
-=item I<void>
-
-No type
-
-=item I<identifier>
-
-It's a variable name or a procedure name or a function name
-
-=back
-
-=head2 Explicit type conversions
-
-=over
-
-=item (I<integer>) B<integer> I<any>
-
-Converts any type to an integer
-
-=item (I<double>) B<double> I<any>
-
-Converts any type to a double
-
-=item (I<string>) B<string> I<any>
-
-Converts any type to a string
-
-=back
-
=head1 SYNTAX
=head2 Comments
@@ -138,9 +82,9 @@ A Fype program is a list of statements. Each keyword, expression or function cal
say foo;
exit foo - bar;
-=head2 Paranthesis
+=head2 Parenthesis
-All paranthesis of function calls are optional. They help to make the code better readable. They also help to force precedences of expressions.
+All parenthesis of function calls are optional. They help to make the code better readable. They also help to force precedences of expressions.
=head2 Scopeing
@@ -191,6 +135,84 @@ Runs the statements as long as the the expression evaluates to a false value.
=back
+=head1 DATA TYPES
+
+Fype uses auto type conversion. However, if you want to know what's going on you may take a look at the provided basic datatypes.
+
+=head2 The basic data types
+
+=over
+
+=item I<integer>
+
+(Internal name TT_INTEGER)
+
+=item I<double>
+
+(Internal name TT_DOUBLE)
+
+=item I<string>
+
+(Internal name TT_STRING)
+
+=item I<array>
+
+(Internal name TT_ARRAY)
+
+=item I<number>
+
+May be an integer or a double number
+
+=item I<any>
+
+May be of any type above
+
+=item I<void>
+
+No type
+
+=item I<identifier>
+
+It's a variable name or a procedure name or a function name
+
+=back
+
+=head2 Explicit type conversions
+
+The data types inside the brackets are only showing the return types of each function.
+
+=over
+
+=item (I<integer>) B<integer> I<any>
+
+Converts any type to an integer.
+
+=item (I<double>) B<double> I<any>
+
+Converts any type to a double.
+
+=item (I<string>) B<string> I<any>
+
+Converts any type to a string.
+
+=item (I<array>) B<array> I<any>
+
+Converts any type to an array. This function is not yet implemented.
+
+=back
+
+=head2 More functions for data types
+
+=over
+
+=item (I<string>) B<type> I<any>
+
+Returns the name of the current type. Examples:
+
+ my foo = 1;
+ put type foo; # Prints "TT_INTEGER"
+ put type 1.2; # Prints "TT_DOUBLE"
+
=head1 VARIABLES
Variables can be defined with the B<my> keyword. If you don't assign a value during declaration, then it's using the default integer value 0. Variables may be changed during program runtime. Variables may be deleted using the B<undef> keyword! Example of defining variables:
@@ -423,7 +445,7 @@ A function should be defined with the B<func> keyword and deleted with the B<und
my a = 2, b = 4;
foo; # Run the procedure. Print out "11\n"
- say c; # Will produce an error, because c is out of scoped!
+ say c; # Will produce an error, because c is out of scope!
=head2 Nested functions
@@ -450,5 +472,5 @@ The Fype Language (http://fype.buetow.org)
=head1 SEE ALSO
-awk(1) cc(1) make(1)
+awk(1) cc(1)
diff --git a/docs/pod/fype.tex b/docs/pod/fype.tex
index bcdea5f..b29ea4f 100644
--- a/docs/pod/fype.tex
+++ b/docs/pod/fype.tex
@@ -94,67 +94,6 @@ Run a .fy file:
See the ./examples subdir of the Fype source distribution for examples! See also fype -h for a list of all options.
-\section{DATA TYPES\label{DATA_TYPES}\index{DATA TYPES}}
-
-
-Fype uses auto type conversion. However, if you want to know what's going on you may take a look at the provided basic datatypes.
-
-\subsection*{The basic data types\label{The_basic_data_types}\index{The basic data types}}
-\begin{description}
-
-\item[{\textit{integer}}] \mbox{}
-
-Specifies an integer number
-
-
-\item[{\textit{double}}] \mbox{}
-
-Specifies a double number
-
-
-\item[{\textit{string}}] \mbox{}
-
-Specifies a string
-
-
-\item[{\textit{number}}] \mbox{}
-
-May be an integer or a double number
-
-
-\item[{\textit{any}}] \mbox{}
-
-May be of any type above
-
-
-\item[{\textit{void}}] \mbox{}
-
-No type
-
-
-\item[{\textit{identifier}}] \mbox{}
-
-It's a variable name or a procedure name or a function name
-
-\end{description}
-\subsection*{Explicit type conversions\label{Explicit_type_conversions}\index{Explicit type conversions}}
-\begin{description}
-
-\item[{(\textit{integer}) \textbf{integer} \textit{any}}] \mbox{}
-
-Converts any type to an integer
-
-
-\item[{(\textit{double}) \textbf{double} \textit{any}}] \mbox{}
-
-Converts any type to a double
-
-
-\item[{(\textit{string}) \textbf{string} \textit{any}}] \mbox{}
-
-Converts any type to a string
-
-\end{description}
\section{SYNTAX\label{SYNTAX}\index{SYNTAX}}
\subsection*{Comments\label{Comments}\index{Comments}}
@@ -171,10 +110,10 @@ A Fype program is a list of statements. Each keyword, expression or function cal
say foo;
exit foo - bar;
\end{verbatim}
-\subsection*{Paranthesis\label{Paranthesis}\index{Paranthesis}}
+\subsection*{Parenthesis\label{Parenthesis}\index{Parenthesis}}
-All paranthesis of function calls are optional. They help to make the code better readable. They also help to force precedences of expressions.
+All parenthesis of function calls are optional. They help to make the code better readable. They also help to force precedences of expressions.
\subsection*{Scopeing\label{Scopeing}\index{Scopeing}}
@@ -235,6 +174,93 @@ Runs the statements as long as the the expression evaluates to a true value.
Runs the statements as long as the the expression evaluates to a false value.
\end{description}
+\section{DATA TYPES\label{DATA_TYPES}\index{DATA TYPES}}
+
+
+Fype uses auto type conversion. However, if you want to know what's going on you may take a look at the provided basic datatypes.
+
+\subsection*{The basic data types\label{The_basic_data_types}\index{The basic data types}}
+\begin{description}
+
+\item[{\textit{integer}}] \mbox{}
+
+(Internal name TT\_INTEGER)
+
+
+\item[{\textit{double}}] \mbox{}
+
+(Internal name TT\_DOUBLE)
+
+
+\item[{\textit{string}}] \mbox{}
+
+(Internal name TT\_STRING)
+
+
+\item[{\textit{array}}] \mbox{}
+
+(Internal name TT\_ARRAY)
+
+
+\item[{\textit{number}}] \mbox{}
+
+May be an integer or a double number
+
+
+\item[{\textit{any}}] \mbox{}
+
+May be of any type above
+
+
+\item[{\textit{void}}] \mbox{}
+
+No type
+
+
+\item[{\textit{identifier}}] \mbox{}
+
+It's a variable name or a procedure name or a function name
+
+\end{description}
+\subsection*{Explicit type conversions\label{Explicit_type_conversions}\index{Explicit type conversions}}
+
+
+The data types inside the brackets are only showing the return types of each function.
+
+\begin{description}
+
+\item[{(\textit{integer}) \textbf{integer} \textit{any}}] \mbox{}
+
+Converts any type to an integer.
+
+
+\item[{(\textit{double}) \textbf{double} \textit{any}}] \mbox{}
+
+Converts any type to a double.
+
+
+\item[{(\textit{string}) \textbf{string} \textit{any}}] \mbox{}
+
+Converts any type to a string.
+
+
+\item[{(\textit{array}) \textbf{array} \textit{any}}] \mbox{}
+
+Converts any type to an array. This function is not yet implemented.
+
+\end{description}
+\subsection*{More functions for data types\label{More_functions_for_data_types}\index{More functions for data types}}
+\begin{description}
+
+\item[{(\textit{string}) \textbf{type} \textit{any}}] \mbox{}
+
+Returns the name of the current type. Examples:
+
+\begin{verbatim}
+ my foo = 1;
+ put type foo; # Prints "TT_INTEGER"
+ put type 1.2; # Prints "TT_DOUBLE"
+\end{verbatim}
\section{VARIABLES\label{VARIABLES}\index{VARIABLES}}
@@ -510,5 +536,5 @@ The Fype Language (http://fype.buetow.org)
\section{SEE ALSO\label{SEE_ALSO}\index{SEE ALSO}}
-awk(1) cc(1) make(1)
+awk(1) cc(1)
diff --git a/docs/pod/fype.txt b/docs/pod/fype.txt
index 66a9695..b6f6969 100644
--- a/docs/pod/fype.txt
+++ b/docs/pod/fype.txt
@@ -75,42 +75,6 @@ GETTING STARTED
See the ./examples subdir of the Fype source distribution for examples!
See also fype -h for a list of all options.
-DATA TYPES
- Fype uses auto type conversion. However, if you want to know what's
- going on you may take a look at the provided basic datatypes.
-
- The basic data types
- *integer*
- Specifies an integer number
-
- *double*
- Specifies a double number
-
- *string*
- Specifies a string
-
- *number*
- May be an integer or a double number
-
- *any*
- May be of any type above
-
- *void*
- No type
-
- *identifier*
- It's a variable name or a procedure name or a function name
-
- Explicit type conversions
- (*integer*) integer *any*
- Converts any type to an integer
-
- (*double*) double *any*
- Converts any type to a double
-
- (*string*) string *any*
- Converts any type to a string
-
SYNTAX
Comments
Text from a # character until the end of the current line is considered
@@ -126,8 +90,8 @@ SYNTAX
say foo;
exit foo - bar;
- Paranthesis
- All paranthesis of function calls are optional. They help to make the
+ Parenthesis
+ All parenthesis of function calls are optional. They help to make the
code better readable. They also help to force precedences of
expressions.
@@ -175,216 +139,270 @@ SYNTAX
Runs the statements as long as the the expression evaluates to a
false value.
+DATA TYPES
+ Fype uses auto type conversion. However, if you want to know what's
+ going on you may take a look at the provided basic datatypes.
+
+ The basic data types
+ *integer*
+ (Internal name TT_INTEGER)
+
+ *double*
+ (Internal name TT_DOUBLE)
+
+ *string*
+ (Internal name TT_STRING)
+
+ *array*
+ (Internal name TT_ARRAY)
+
+ *number*
+ May be an integer or a double number
+
+ *any*
+ May be of any type above
+
+ *void*
+ No type
+
+ *identifier*
+ It's a variable name or a procedure name or a function name
+
+ Explicit type conversions
+ The data types inside the brackets are only showing the return types of
+ each function.
+
+ (*integer*) integer *any*
+ Converts any type to an integer.
+
+ (*double*) double *any*
+ Converts any type to a double.
+
+ (*string*) string *any*
+ Converts any type to a string.
+
+ (*array*) array *any*
+ Converts any type to an array. This function is not yet implemented.
+
+ More functions for data types
+ (*string*) type *any*
+ Returns the name of the current type. Examples:
+
+ my foo = 1;
+ put type foo; # Prints "TT_INTEGER"
+ put type 1.2; # Prints "TT_DOUBLE"
+
VARIABLES
- Variables can be defined with the my keyword. If you don't assign a
- value during declaration, then it's using the default integer value 0.
- Variables may be changed during program runtime. Variables may be
- deleted using the undef keyword! Example of defining variables:
+ Variables can be defined with the my keyword. If you don't assign a
+ value during declaration, then it's using the default integer value
+ 0. Variables may be changed during program runtime. Variables may be
+ deleted using the undef keyword! Example of defining variables:
- my foo = 1 + 2;
- say foo;
+ my foo = 1 + 2;
+ say foo;
- my bar = 12, baz = foo;
- say 1 + bar;
- say bar;
+ my bar = 12, baz = foo;
+ say 1 + bar;
+ say bar;
- my baz;
- say baz; # Will print out 0
+ my baz;
+ say baz; # Will print out 0
- You may use the defined keyword to check if an identifier has been
- defined or not.
+ You may use the defined keyword to check if an identifier has been
+ defined or not.
- ifnot defined foo {
- say "No foo yet defined";
- }
+ ifnot defined foo {
+ say "No foo yet defined";
+ }
- my foo = 1;
+ my foo = 1;
- if defined foo {
- put "foo is defined and has the value ";
- say foo;
- }
+ if defined foo {
+ put "foo is defined and has the value ";
+ say foo;
+ }
BUILT IN FUNCTIONS
- In Fype, operators are built in functions as well. The difference is,
- that they may be written in infix notation instead in front of the
- arguments. The types inside the () specify the return types.
+ In Fype, operators are built in functions as well. The difference
+ is, that they may be written in infix notation instead in front of
+ the arguments. The types inside the () specify the return types.
Math
- (*any*) *any* + *any*
- Special string behavior: A string will get auto convertet into an
- *integer*.
+ (*any*) *any* + *any*
+ Special string behavior: A string will get auto convertet into
+ an *integer*.
- (*any*) *any* - *any*
- Special string behavior: A string will get auto convertet into an
- *integer*.
+ (*any*) *any* - *any*
+ Special string behavior: A string will get auto convertet into
+ an *integer*.
- (*any*) *any* * *any*
- Special string behavior: A string will get auto convertet into an
- *integer*.
+ (*any*) *any* * *any*
+ Special string behavior: A string will get auto convertet into
+ an *integer*.
- (*any*) *any* / *any*
- Special string behavior: A string will get auto convertet into an
- *integer*.
+ (*any*) *any* / *any*
+ Special string behavior: A string will get auto convertet into
+ an *integer*.
Conditional
- (*integer*) *any* == *any*
- (*integer*) *any* != *any*
- (*integer*) *any* <= *any*
- (*integer*) *any* >= *any*
- (*integer*) *any* < *any*
- (*integer*) *any* > *any*
- (*integer*) not *any*
+ (*integer*) *any* == *any*
+ (*integer*) *any* != *any*
+ (*integer*) *any* <= *any*
+ (*integer*) *any* >= *any*
+ (*integer*) *any* < *any*
+ (*integer*) *any* > *any*
+ (*integer*) not *any*
Definedness
- (*integer*) defined *identifier*
- Returns 1 if *identifier* has been defined. Returns 0 else.
+ (*integer*) defined *identifier*
+ Returns 1 if *identifier* has been defined. Returns 0 else.
- (*integer*) undef *identifier*
- Tries to undefine/delete the *identifier*. Returns 1 if success,
- otherwise 0 is returned.
+ (*integer*) undef *identifier*
+ Tries to undefine/delete the *identifier*. Returns 1 if success,
+ otherwise 0 is returned.
Bitwise
- (*integer*) *any* :< *any*
- (*integer*) *any* :> *any*
- (*integer*) *any* and *any*
- (*integer*) *any* or *any*
- (*integer*) *any* xor *any*
+ (*integer*) *any* :< *any*
+ (*integer*) *any* :> *any*
+ (*integer*) *any* and *any*
+ (*integer*) *any* or *any*
+ (*integer*) *any* xor *any*
Numeric
- (*number*) neg *number*
- This function returns the negative value of *any*
+ (*number*) neg *number*
+ This function returns the negative value of *any*
- (*integer*) no [*integer*]
- This function returns 1 if the argument is 0, otherwise it will
- return 0! If no argument is given, then 0 is returned!
+ (*integer*) no [*integer*]
+ This function returns 1 if the argument is 0, otherwise it will
+ return 0! If no argument is given, then 0 is returned!
- (*integer*) yes [*integer*]
- This function always returns 1. The parameter is optional.
+ (*integer*) yes [*integer*]
+ This function always returns 1. The parameter is optional.
- # Prints out 1, because foo is not defined
- if yes { say no defined foo; }
+ # Prints out 1, because foo is not defined
+ if yes { say no defined foo; }
System
- (*void*) end
- Exits the program with the exit status of 0
+ (*void*) end
+ Exits the program with the exit status of 0
- (*void*) exit *integer*
- Exits the program with the specified exit status
+ (*void*) exit *integer*
+ Exits the program with the specified exit status
- (*integer*) fork
- Fork forks a subprocess. It returns 0 for the child process and the
- pid of the child process otherwise! Example:
+ (*integer*) fork
+ Fork forks a subprocess. It returns 0 for the child process and
+ the pid of the child process otherwise! Example:
- my pid = fork;
+ my pid = fork;
- if pid {
- put "I am the parent process; child has the pid ";
- say pid;
+ if pid {
+ put "I am the parent process; child has the pid ";
+ say pid;
- } ifnot pid {
- say "I am the child process";
- }
+ } ifnot pid {
+ say "I am the child process";
+ }
- (*integer*) gc
- Executes the garbage collector and returns the number of items
- freed! You may wonder why most of the time it will return a value of
- 0! Fype tries to free not needed memory asap. This may change in
- future versions in order to gain faster execution of scripts!
+ (*integer*) gc
+ Executes the garbage collector and returns the number of items
+ freed! You may wonder why most of the time it will return a
+ value of 0! Fype tries to free not needed memory asap. This may
+ change in future versions in order to gain faster execution of
+ scripts!
I/O
- (*any*) put *any*
- Prints out the argument
+ (*any*) put *any*
+ Prints out the argument
- (*any*) say *any*
- Same as put, but also includes an ending newline
+ (*any*) say *any*
+ Same as put, but also includes an ending newline
- (*void*) ln
- Just prints a newline
+ (*void*) ln
+ Just prints a newline
SELF DEFINING PROCEDURES AND FUNCTIONS
Procedures
- A procedure can be defined with the proc keyword and deleted with the
- undef keyword. A procedure does not return any value and does not
- support parameter passing. It's using already defined variables (e.g.
- global variables). A procedure does not have its own namespace. It's
- using the calling namespace. It is possible to define new variabes
- inside of a procedure in the current namespace.
-
- proc foo {
- say 1 + a * 3 + b;
- my c = 6;
- }
+ A procedure can be defined with the proc keyword and deleted with
+ the undef keyword. A procedure does not return any value and does
+ not support parameter passing. It's using already defined variables
+ (e.g. global variables). A procedure does not have its own
+ namespace. It's using the calling namespace. It is possible to
+ define new variabes inside of a procedure in the current namespace.
+
+ proc foo {
+ say 1 + a * 3 + b;
+ my c = 6;
+ }
- my a = 2, b = 4;
+ my a = 2, b = 4;
- foo; # Run the procedure. Print out "11\n"
- say c; # Print out "6\n";
+ foo; # Run the procedure. Print out "11\n"
+ say c; # Print out "6\n";
Nested procedures
- It's possible to define procedures inside of procedures. Since
- procedures don't have its own scope, nested procedures will be available
- to the current scope as soon as the main procedure has run the first
- time. You may use the defined keyword in order to check if a procedure
- has been defined or not.
-
- proc foo {
- say "I am foo";
-
- undef bar;
- proc bar {
- say "I am bar";
- }
- }
+ It's possible to define procedures inside of procedures. Since
+ procedures don't have its own scope, nested procedures will be
+ available to the current scope as soon as the main procedure has run
+ the first time. You may use the defined keyword in order to check if
+ a procedure has been defined or not.
+
+ proc foo {
+ say "I am foo";
+
+ undef bar;
+ proc bar {
+ say "I am bar";
+ }
+ }
- # Here bar would produce an error because
- # the proc is not yet defined!
- # bar;
+ # Here bar would produce an error because
+ # the proc is not yet defined!
+ # bar;
- foo; # Here the procedure foo will define the procedure bar!
- bar; # Now the procedure bar is defined!
- foo; # Here the procedure foo will redefine bar again!
+ foo; # Here the procedure foo will define the procedure bar!
+ bar; # Now the procedure bar is defined!
+ foo; # Here the procedure foo will redefine bar again!
Functions
- A function should be defined with the func keyword and deleted with the
- undef keyword. Function not yet return values (will be changed in future
- versions) and supports not yet parameter passing (will be changed in
- future versions). It's using local (lexical scoped) variables. If a
- certain variable does not exist It's using already defined variables
- (e.g. one scope above).
-
- func foo {
- say 1 + a * 3 + b;
- my c = 6;
- }
+ A function should be defined with the func keyword and deleted with
+ the undef keyword. Function not yet return values (will be changed
+ in future versions) and supports not yet parameter passing (will be
+ changed in future versions). It's using local (lexical scoped)
+ variables. If a certain variable does not exist It's using already
+ defined variables (e.g. one scope above).
+
+ func foo {
+ say 1 + a * 3 + b;
+ my c = 6;
+ }
- my a = 2, b = 4;
+ my a = 2, b = 4;
- foo; # Run the procedure. Print out "11\n"
- say c; # Will produce an error, because c is out of scoped!
+ foo; # Run the procedure. Print out "11\n"
+ say c; # Will produce an error, because c is out of scoped!
Nested functions
- Nested functions work the same way the nested procedures work, with the
- exception that nested functions will not be available any more after the
- function has been left!
+ Nested functions work the same way the nested procedures work, with
+ the exception that nested functions will not be available any more
+ after the function has been left!
- func foo {
- func bar {
- say "Hello i am nested";
- }
+ func foo {
+ func bar {
+ say "Hello i am nested";
+ }
- bar; # Calling nested
- }
+ bar; # Calling nested
+ }
- foo;
- bar; # Will produce an error, because bar is out of scope!
+ foo;
+ bar; # Will produce an error, because bar is out of scope!
AUTHOR
- Paul C. Buetow (http://paul.buetow.org)
+ Paul C. Buetow (http://paul.buetow.org)
WEBSITE
- The Fype Language (http://fype.buetow.org)
+ The Fype Language (http://fype.buetow.org)
SEE ALSO
- awk(1) cc(1) make(1)
+ awk(1) cc(1)
diff --git a/docs/stats.txt b/docs/stats.txt
index b49fcc8..f3e5de9 100644
--- a/docs/stats.txt
+++ b/docs/stats.txt
@@ -1,4 +1,4 @@
===> Num of C source files : 42
-===> Num of C source lines : 7460
+===> Num of C source lines : 7620
===> Num of Fype source examples : 13
-===> Num of Fype source lines : 321
+===> Num of Fype source lines : 325
diff --git a/docs/version.txt b/docs/version.txt
index 8493ac9..7595f6e 100644
--- a/docs/version.txt
+++ b/docs/version.txt
@@ -1 +1 @@
-Fype v0.1-devel Build 9208
+Fype v0.1-devel Build 9322
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];
diff --git a/src/build.h b/src/build.h
index b717a22..80ea007 100644
--- a/src/build.h
+++ b/src/build.h
@@ -35,7 +35,7 @@
#ifndef BUILD_H
#define BUILD_H
-#define BUILDNR 9209
+#define BUILDNR 9330
#define OS_FREEBSD
#endif
diff --git a/src/core/convert.c b/src/core/convert.c
index 73fb8a2..081e92e 100644
--- a/src/core/convert.c
+++ b/src/core/convert.c
@@ -33,6 +33,7 @@
*:*/
#include "convert.h"
+#include "../data/array.h"
void
convert_to_integer(Token *p_token) {
@@ -47,6 +48,10 @@ convert_to_integer(Token *p_token) {
token_set_tt(p_token, TT_INTEGER);
token_set_ival(p_token, atoi(token_get_val(p_token)));
break;
+ case TT_ARRAY:
+ token_set_tt(p_token, TT_INTEGER);
+ token_set_ival(p_token, array_get_size(p_token->p_array)-1);
+ break;
default:
ERROR("Ouups(%s)", tt_get_name(token_get_tt(p_token)));
break;
@@ -62,6 +67,9 @@ convert_to_integer_get(Token *p_token) {
return ((int) token_get_dval(p_token));
case TT_STRING:
return (atoi(token_get_val(p_token)));
+ case TT_ARRAY:
+ return (array_get_size(p_token->p_array)-1);
+ break;
default:
ERROR("Ouups(%s)", tt_get_name(token_get_tt(p_token)));
}
@@ -82,6 +90,10 @@ convert_to_double(Token *p_token) {
token_set_tt(p_token, TT_DOUBLE);
token_set_dval(p_token, atof(token_get_val(p_token)));
break;
+ case TT_ARRAY:
+ token_set_tt(p_token, TT_DOUBLE);
+ token_set_dval(p_token, array_get_size(p_token->p_array)-1);
+ break;
default:
token_print_val(p_token);
ERROR("Datatype conversion error '%s'", token_get_val(p_token));
@@ -116,6 +128,17 @@ convert_to_string(Token *p_token) {
break;
case TT_STRING:
break;
+ case TT_ARRAY:
+ token_set_tt(p_token, TT_STRING);
+ char c_tmp[1024];
+ sprintf(c_tmp, "%d", array_get_size(p_token->p_array)-1);
+ int i_len = strlen(c_tmp);
+ p_token->c_val = realloc(p_token->c_val, sizeof(char) * (i_len + 1));
+ strcpy(p_token->c_val, c_tmp);
+ p_token->c_val[i_len] = 0;
+ array_iterate(p_token->p_array, token_delete_cb);
+
+ break;
default:
ERROR("Datatype conversion error");
break;
diff --git a/src/core/function.c b/src/core/function.c
index fda40b8..979454d 100644
--- a/src/core/function.c
+++ b/src/core/function.c
@@ -52,6 +52,34 @@
)
void
+_print_val(Token *p_token) {
+ switch (token_get_tt(p_token)) {
+ case TT_INTEGER:
+ printf("%d", token_get_ival(p_token));
+ break;
+ case TT_DOUBLE:
+ printf("%f", token_get_dval(p_token));
+ break;
+ case TT_STRING:
+ printf("%s", token_get_val(p_token));
+ break;
+ case TT_ARRAY:
+ {
+ Array *p_array = p_token->p_array;
+ ArrayIterator *p_iter = arrayiterator_new(p_array);
+ while (arrayiterator_has_next(p_iter)) {
+ Token *p_next = arrayiterator_next(p_iter);
+ _print_val(p_next);
+ printf(" ");
+ }
+ arrayiterator_delete(p_iter);
+ }
+ break;
+ NO_DEFAULT;
+ }
+}
+
+void
_process(Interpret *p_interpret, Token *p_token_store, Token *p_token_op,
Token *p_token_op2, Token *p_token_next) {
@@ -575,6 +603,9 @@ function_is_buildin(Token *p_token_ident) {
if (strcmp("not", token_get_val(p_token_ident)) == 0)
return (true);
+ if (strcmp("type", token_get_val(p_token_ident)) == 0)
+ return (true);
+
return (false);
}
@@ -734,18 +765,7 @@ function_process_buildin(Interpret *p_interpret, Token *p_token_ident,
StackIterator *p_iter = stackiterator_new(p_stack_args);
while (stackiterator_has_next(p_iter)) {
Token *p_token = stackiterator_next(p_iter);
- switch (token_get_tt(p_token)) {
- case TT_INTEGER:
- printf("%d", token_get_ival(p_token));
- break;
- case TT_DOUBLE:
- printf("%f", token_get_dval(p_token));
- break;
- case TT_STRING:
- printf("%s", token_get_val(p_token));
- break;
- NO_DEFAULT;
- }
+ _print_val(p_token);
}
stackiterator_delete(p_iter);
@@ -753,18 +773,7 @@ function_process_buildin(Interpret *p_interpret, Token *p_token_ident,
StackIterator *p_iter = stackiterator_new(p_stack_args);
while (stackiterator_has_next(p_iter)) {
Token *p_token = stackiterator_next(p_iter);
- switch (token_get_tt(p_token)) {
- case TT_INTEGER:
- printf("%d", token_get_ival(p_token));
- break;
- case TT_DOUBLE:
- printf("%f", token_get_dval(p_token));
- break;
- case TT_STRING:
- printf("%s", token_get_val(p_token));
- break;
- NO_DEFAULT;
- }
+ _print_val(p_token);
}
stackiterator_delete(p_iter);
printf("\n");
@@ -812,6 +821,35 @@ function_process_buildin(Interpret *p_interpret, Token *p_token_ident,
break;
NO_DEFAULT;
}
+ } else if (strcmp("not", token_get_val(p_token_ident)) == 0) {
+ if (0 == stack_size(p_stack_args))
+ _FUNCTION_ERROR("No argument given", p_token_ident);
+
+ Token *p_token = token_new_copy(stack_pop(p_stack_args));
+ stack_push(p_stack_args, p_token);
+
+ switch (token_get_tt(p_token)) {
+ case TT_INTEGER:
+ token_set_ival(p_token, !token_get_ival(p_token));
+ break;
+ case TT_DOUBLE:
+ token_set_dval(p_token, !token_get_dval(p_token));
+ break;
+ case TT_STRING:
+ token_set_ival(p_token, !atoi(token_get_val(p_token)));
+ token_set_tt(p_token, TT_INTEGER);
+ break;
+ NO_DEFAULT;
+ }
+ } else if (strcmp("type", token_get_val(p_token_ident)) == 0) {
+ if (0 == stack_size(p_stack_args))
+ _FUNCTION_ERROR("No argument given", p_token_ident);
+
+ Token *p_token = stack_pop(p_stack_args);
+ TokenType tt = token_get_tt(p_token);
+
+ Token *p_token_type = token_new_string(tt_get_name(tt));
+ stack_push(p_stack_args, p_token_type);
}
}
diff --git a/src/core/interpret.c b/src/core/interpret.c
index 5aa07ef..c3f781c 100644
--- a/src/core/interpret.c
+++ b/src/core/interpret.c
@@ -54,15 +54,16 @@
#define _NEXT_TT _next_tt(p_interpret)
#define _SKIP _next(p_interpret);
-void _print_lookahead(Interpret *p_interpret);
+int __expression_get(Interpret *p_interpret, List *p_list_block);
+int __array_get(Interpret *p_interpret, Token *p_token_arr);
+void __print_lookahead(Interpret *p_interpret);
int _next(Interpret *p_interpret);
int _program(Interpret *p_interpret);
int _var_decl(Interpret *p_interpret);
int _var_assign(Interpret *p_interpret);
int _var_list(Interpret *p_interpret);
-int _expression_get(Interpret *p_interpret, List *p_list_block);
int _block_get(Interpret *p_interpret, List *p_list_block);
-int _block_skip(Interpret *p_interpret);
+int __block_skip(Interpret *p_interpret);
int _proc_decl(Interpret *p_interpret);
int _func_decl(Interpret *p_interpret);
int _statement(Interpret *p_interpret);
@@ -114,7 +115,7 @@ interpret_delete(Interpret *p_interpret) {
}
void
-_print_lookahead(Interpret *p_interpret) {
+__print_lookahead(Interpret *p_interpret) {
ListIterator *p_iter = p_interpret->p_iter;
ListIteratorState *p_state = listiterator_get_state(p_iter);
@@ -175,7 +176,6 @@ _var_decl(Interpret *p_interpret) {
_CHECK TRACK
switch (p_interpret->tt) {
- //case TT_ARR: //TODO cleanup TT_ARR
case TT_MY:
{
if (_NEXT_TT != TT_IDENT)
@@ -200,7 +200,7 @@ _var_decl(Interpret *p_interpret) {
}
}
default:
- break;
+ break;
}
return (0);
@@ -226,8 +226,8 @@ _var_assign(Interpret *p_interpret) {
p_interpret->p_stack = stack_new();
if (_expression_(p_interpret)) {
- function_process_buildin(p_interpret, p_token,
- p_interpret->p_stack);
+ function_process_buildin(p_interpret, p_token,
+ p_interpret->p_stack);
stack_merge(p_stack, p_interpret->p_stack);
stack_delete(p_interpret->p_stack);
@@ -236,7 +236,6 @@ _var_assign(Interpret *p_interpret) {
p_token = stack_top(p_interpret->p_stack);
Symbol *p_symbol = symbol_new(SYM_VARIABLE, p_token);
scope_newset(p_interpret->p_scope, c_name, p_symbol);
-
} else {
return (0);
}
@@ -298,11 +297,10 @@ _block_get(Interpret *p_interpret, List *p_list_block) {
}
int
-_expression_get(Interpret *p_interpret, List *p_list_expression) {
+__expression_get(Interpret *p_interpret, List *p_list_expression) {
for (;;) {
- if (p_interpret->tt == TT_PARANT_CL) {
+ if (p_interpret->tt == TT_PARANT_CL)
break; /* for */
- }
list_add_back(p_list_expression, p_interpret->p_token);
@@ -319,7 +317,36 @@ _expression_get(Interpret *p_interpret, List *p_list_expression) {
}
int
-_block_skip(Interpret *p_interpret) {
+__array_get(Interpret *p_interpret, Token *p_token_arr) {
+#ifdef DEBUG_ARRAY_GET
+ printf("====> ARRAY\n");
+#endif /* DEBUG_ARRAY_GET */
+ Array *p_array = p_token_arr->p_array;
+
+ do {
+ Token *p_token = p_interpret->p_token;
+
+#ifdef DEBUG_ARRAY_GET
+ printf("Insert: ");
+ token_print_ln(p_token);
+#endif /* DEBUG_ARRAY_GET */
+
+ array_unshift(p_array, p_token);
+ token_ref_up(p_token);
+ _NEXT
+ } while (p_interpret->tt != TT_PARANT_AR);
+
+#ifdef DEBUG_ARRAY_GET
+ printf("<==== ARRAY\n");
+#endif /* DEBUG_ARRAY_GET */
+ /* Ignore TT_PARANT_AR */
+ _NEXT
+
+ return (0);
+}
+
+int
+__block_skip(Interpret *p_interpret) {
if (p_interpret->tt != TT_PARANT_CL)
_INTERPRET_ERROR("Expected '{'", p_interpret->p_token);
_NEXT
@@ -523,7 +550,7 @@ _control(Interpret *p_interpret) {
_NEXT
- _expression_get(p_interpret, p_list_expr);
+ __expression_get(p_interpret, p_list_expr);
_block_get(p_interpret, p_list_block);
Token *p_token_backup = p_interpret->p_token;
@@ -541,7 +568,6 @@ _control(Interpret *p_interpret) {
Token *p_token_top = stack_pop(p_interpret->p_stack);
if (p_token_top == NULL) {
- printf("FOO\n");
exit(0);
}
if (tt == TT_WHILE) {
@@ -786,6 +812,7 @@ _term(Interpret *p_interpret) {
case TT_INTEGER:
case TT_DOUBLE:
case TT_STRING:
+ case TT_ARRAY:
stack_push(p_interpret->p_stack, p_interpret->p_token);
_NEXT
return (1);
@@ -917,9 +944,13 @@ _term(Interpret *p_interpret) {
Token *p_token = p_interpret->p_token;
_NEXT
- Token *p_token_arr = token_new_array(ARRAY_SIZE);
+ Token *p_token_arr = token_new_array(ARRAY_SIZE);
stack_push(p_interpret->p_stack, p_token_arr);
- _INTERPRET_ERROR("arrays not yet fully implemented", p_token_arr);
+
+ if (__array_get(p_interpret, p_token_arr) != 0)
+ _INTERPRET_ERROR("Array syntax error", p_token);
+
+ return (1);
}
break;
diff --git a/src/core/symbol.c b/src/core/symbol.c
index 2343cdb..9a98e63 100644
--- a/src/core/symbol.c
+++ b/src/core/symbol.c
@@ -33,7 +33,9 @@
*:*/
#include "symbol.h"
+#include "token.h"
+#include "../data/array.h"
#include "../data/list.h"
Symbol*
@@ -55,8 +57,20 @@ symbol_delete(Symbol *p_symbol) {
list_delete(p_list_token);
}
break;
+ case SYM_VARIABLE:
+ {
+ Token *p_token = symbol_get_val(p_symbol);
+ switch (token_get_tt(p_token)) {
+ case TT_ARRAY:
+ array_iterate(p_token->p_array, token_delete_cb);
+ break;
+ NO_DEFAULT;
+ }
+ }
+ break;
NO_DEFAULT;
}
+
free(p_symbol);
}
diff --git a/src/core/token.c b/src/core/token.c
index 1a2aec9..49a9721 100644
--- a/src/core/token.c
+++ b/src/core/token.c
@@ -57,7 +57,6 @@ get_tt(char *c_token) {
CHECK("proc") TT_PROC;
CHECK("func") TT_FUNC;
CHECK("my") TT_MY;
- CHECK("arr") TT_ARR;
CHECK("!") TT_NOT;
CHECK("!=") TT_NEQ;
CHECK("=~") TT_RE;
@@ -123,7 +122,6 @@ tt_get_name(TokenType tt_cur) {
CASE(TT_PROC,"TT_PROC")
CASE(TT_FUNC,"TT_FUNC")
CASE(TT_MY,"TT_MY")
- CASE(TT_ARR,"TT_ARR")
CASE(TT_WHILE,"TT_WHILE")
CASE(TT_UNTIL,"TT_UNTIL")
CASE(TT_NEXT,"TT_NEXT")
@@ -248,7 +246,11 @@ Token*
token_new_array(int i_size) {
Token *p_token = token_new_dummy();
token_set_tt(p_token, TT_ARRAY);
- array_resize(p_token->p_array, i_size);
+
+ if (p_token->p_array == NULL)
+ p_token->p_array = array_new();
+
+ //array_resize(p_token->p_array, i_size);
return (p_token);
}
@@ -305,10 +307,24 @@ void token_copy_vals(Token *p_token_to, Token *p_token_from) {
i_len = strlen(p_token_from->c_val);
p_token_to->c_val = calloc(i_len+1, sizeof(char));
strcpy(p_token_to->c_val, p_token_from->c_val);
+
} else {
p_token_to->c_val = NULL;
}
+ if (p_token_from->tt_cur == TT_ARRAY) {
+ p_token_to->p_array = array_new();
+ ArrayIterator *p_iter = arrayiterator_new(p_token_from->p_array);
+ while (arrayiterator_has_next(p_iter)) {
+ Token *p_token = arrayiterator_next(p_iter);
+ token_ref_up(p_token);
+ array_unshift(p_token_to->p_array, p_token);
+ }
+ arrayiterator_delete(p_iter);
+ } else {
+ p_token_to->p_array = NULL;
+ }
+
p_token_to->tt_cur = p_token_from->tt_cur;
p_token_to->i_val = p_token_from->i_val;
p_token_to->d_val = p_token_from->d_val;
@@ -344,8 +360,10 @@ token_delete(Token *p_token) {
if (p_token->c_val)
free(p_token->c_val);
- if (p_token->p_array)
- array_delete(p_token->p_array);
+ if (p_token->p_array) {
+ array_iterate(p_token->p_array, token_delete_cb);
+ array_delete(p_token->p_array);
+ }
free(p_token);
}
@@ -366,16 +384,27 @@ token_delete(Token *p_token) {
void
token_print(Token *p_token) {
- printf("(id=%05u, line=%05d, pos=%04d, type=%s, val=%s, ival=%d, dval=%f,"
- " refs=%d)",
+ printf("(id=%05u, line=%05d, pos=%04d, type=%s",
p_token->u_token_id,
p_token->i_line_nr,
p_token->i_pos_nr,
- tt_get_name(p_token->tt_cur),
- p_token->c_val,
- p_token->i_val,
- p_token->d_val,
- p_token->i_ref_count);
+ tt_get_name(p_token->tt_cur));
+
+ if (IS_ARRAY(p_token)) {
+ } else {
+ printf(", val=%s, ival=%d, dval=%f",
+ p_token->c_val,
+ p_token->i_val,
+ p_token->d_val);
+ }
+
+ printf(", refs=%d)", p_token->i_ref_count);
+}
+
+void
+token_print_ln(Token *p_token) {
+ token_print(p_token);
+ printf("\n");
}
void
diff --git a/src/core/token.h b/src/core/token.h
index caf4854..af74e98 100644
--- a/src/core/token.h
+++ b/src/core/token.h
@@ -53,6 +53,8 @@
#define IS_ASSIGNABLE(t) (START_ASSIGNABLES < t && t < END_ASSIGNABLES)
#define IS_NUMERICAL(t) (START_NUMERICAL < t && t < END_NUMERICAL)
#define IS_NOT_NUMERICAL(t) !(IS_NUMERICAL(t))
+#define IS_ARRAY(t) (t->tt_cur == TT_ARRAY)
+#define IS_NOT_ARRAY(t) !(IS_ARRAY(t))
#define token_get_filename(t) \
(t->c_filename != NULL ? t->c_filename : "Code string")
@@ -86,8 +88,8 @@ typedef enum {
TT_INTEGER,
TT_DOUBLE,
END_NUMERICAL,
- TT_STRING,
TT_ARRAY,
+ TT_STRING,
END_ASSIGNABLES,
TT_IDENT,
END_TYPES,
@@ -103,7 +105,6 @@ typedef enum {
TT_PROC,
TT_FUNC,
TT_MY,
- TT_ARR,
TT_WHILE,
TT_UNTIL,
TT_NEXT,
@@ -184,6 +185,7 @@ void* token_copy_cb(void *p_token);
char* tt_get_name(TokenType tt_cur);
void token_print_cb(void *p_void);
void token_print(Token *p_token);
+void token_print_ln(Token *p_token);
void token_print_val(Token *p_token);
TokenType get_tt(char *c_token);
diff --git a/src/data/array.c b/src/data/array.c
index 2ae4ece..da5bee8 100644
--- a/src/data/array.c
+++ b/src/data/array.c
@@ -41,7 +41,7 @@ array_new() {
p_array->i_size = 0;
p_array->pp_ae = NULL;
- return p_array;
+ return (p_array);
}
@@ -92,7 +92,7 @@ array_insert(Array *p_array, int i_index, void *p_val) {
void*
array_remove(Array *p_array, int i_index) {
if (p_array->i_size <= i_index)
- return NULL;
+ return (NULL);
ArrayElement *p_ae = p_array->pp_ae[i_index];
void *p_ret = p_ae->p_val;
@@ -105,7 +105,7 @@ array_remove(Array *p_array, int i_index) {
array_resize(p_array, p_array->i_size - 1);
- return p_ret;
+ return (p_ret);
}
void
@@ -147,17 +147,17 @@ array_resize(Array *p_array, int i_size) {
void*
array_get(Array *p_array, int i_index) {
if (p_array->i_size > i_index)
- return p_array->pp_ae[i_index]->p_val;
+ return (p_array->pp_ae[i_index]->p_val);
- return NULL;
+ return (NULL);
}
_Bool
array_defined(Array *p_array, int i_index) {
if (i_index >= p_array->i_size)
- return false;
+ return (false);
- return p_array->pp_ae[i_index]->p_val != NULL;
+ return (p_array->pp_ae[i_index]->p_val != NULL);
}
void
@@ -222,7 +222,7 @@ arrayelement_new(void *p_val) {
p_ae->p_val = p_val;
- return p_ae;
+ return (p_ae);
}
void
@@ -235,14 +235,27 @@ arrayelement_delete(ArrayElement *p_ae) {
ArrayIterator*
arrayiterator_new(Array *p_array) {
- if (!p_array)
- return NULL;
+ if (p_array == NULL)
+ return (NULL);
ArrayIterator *p_arrayiterator = malloc(sizeof(ArrayIterator));
p_arrayiterator->p_array = p_array;
p_arrayiterator->i_cur_pos = 0;
+ p_arrayiterator->b_is_reverse = false;
+
+ return (p_arrayiterator);
+}
+
+ArrayIterator*
+arrayiterator_new_reverse(Array *p_array) {
+ ArrayIterator *p_arrayiterator = arrayiterator_new(p_array);
+ if (p_arrayiterator == NULL)
+ return (NULL);
+
+ p_arrayiterator->b_is_reverse = true;
+ p_arrayiterator->i_cur_pos = p_array->i_size;
- return p_arrayiterator;
+ return (p_arrayiterator);
}
void
@@ -253,14 +266,21 @@ arrayiterator_delete(ArrayIterator *p_arrayiterator) {
_Bool
arrayiterator_has_next(ArrayIterator *p_arrayiterator) {
- return p_arrayiterator->i_cur_pos <
- array_get_size(p_arrayiterator->p_array);
+ if (p_arrayiterator->b_is_reverse)
+ return (p_arrayiterator->i_cur_pos >= 0);
+
+ return (p_arrayiterator->i_cur_pos <
+ array_get_size(p_arrayiterator->p_array));
}
void*
arrayiterator_next(ArrayIterator *p_arrayiterator) {
if (!arrayiterator_has_next(p_arrayiterator))
- return NULL;
+ return (NULL);
+
+ if (p_arrayiterator->b_is_reverse)
+ return (array_get(p_arrayiterator->p_array,
+ p_arrayiterator->i_cur_pos--));
- return array_get(p_arrayiterator->p_array, p_arrayiterator->i_cur_pos++);
+ return (array_get(p_arrayiterator->p_array, p_arrayiterator->i_cur_pos++));
}
diff --git a/src/data/array.h b/src/data/array.h
index b343521..6170c29 100644
--- a/src/data/array.h
+++ b/src/data/array.h
@@ -58,6 +58,7 @@ typedef struct {
typedef struct {
Array *p_array;
int i_cur_pos;
+ _Bool b_is_reverse;
} ArrayIterator;
Array *array_new();
@@ -80,6 +81,7 @@ ArrayElement *arrayelement_new(void *p_val);
void arrayelement_delete(ArrayElement *p_ae);
ArrayIterator *arrayiterator_new(Array *p_array);
+ArrayIterator *arrayiterator_new_reverse(Array *p_array);
void arrayiterator_delete(ArrayIterator *p_arrayiterator);
_Bool arrayiterator_has_next(ArrayIterator *p_arrayiterator);
void *arrayiterator_next(ArrayIterator *p_arrayiterator);
diff --git a/src/defines.h b/src/defines.h
index 569d20a..8cd1114 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -80,6 +80,7 @@
//#define DEBUG_TRACK
//#define DEBUG_BLOCK_GET
//#define DEBUG_EXPRESSION_GET
+//#define DEBUG_ARRAY_GET
#ifdef DEBUG_TRACK
#define TRACK \
diff --git a/tmp/test.fy b/tmp/test.fy
index afe2cec..7e030a5 100644
--- a/tmp/test.fy
+++ b/tmp/test.fy
@@ -1,3 +1,12 @@
-my foo = [1, 2.2, "3"];
+#my foo = [1 2 3];
+#assert "TT_INTEGER" == type say integer foo;
+
+#my bar = [1 2 3];
+#assert "TT_DOUBLE" == type say double bar;
+
+#my baz = [1 2 3];
+#assert "TT_STRING" == type say string baz;
+#say [1 3 5 6];
+
diff --git a/tmp/test.out b/tmp/test.out
index afe2cec..fd06f6e 100644
--- a/tmp/test.out
+++ b/tmp/test.out
@@ -1,3 +1,29 @@
+#*
+my foo = [1 2 3];
+assert "TT_INTEGER" == type say integer foo;
+my bar = [1 2 3];
+assert "TT_DOUBLE" == type say double bar;
-my foo = [1, 2.2, "3"];
+my baz = [1 2 3];
+assert "TT_STRING" == type say string baz;
+*#
+say [1 3 5 6];
+
+Token (id=00000, line=00011, pos=0004, type=TT_IDENT, val=say, ival=0, dval=0.000000, refs=1)
+Token (id=00001, line=00011, pos=0006, type=TT_PARANT_AL, val=[, ival=0, dval=0.000000, refs=1)
+Token (id=00002, line=00011, pos=0007, type=TT_INTEGER, val=1, ival=1, dval=0.000000, refs=1)
+Token (id=00003, line=00011, pos=0009, type=TT_INTEGER, val=3, ival=3, dval=0.000000, refs=1)
+Token (id=00004, line=00011, pos=0011, type=TT_INTEGER, val=5, ival=5, dval=0.000000, refs=1)
+Token (id=00005, line=00011, pos=0013, type=TT_INTEGER, val=6, ival=6, dval=0.000000, refs=1)
+Token (id=00006, line=00011, pos=0013, type=TT_SEMICOLON, val=;, ival=0, dval=0.000000, refs=1)
+Token (id=00007, line=00011, pos=0014, type=TT_PARANT_AR, val=], ival=0, dval=0.000000, refs=1)
+Token (id=00008, line=00011, pos=0015, type=TT_SEMICOLON, val=;, ival=0, dval=0.000000, refs=1)
+1 3 5 6
+The garbage collector still has 5 registered items which don't have a zero ref count!
+(id=00002, line=00011, pos=0007, type=TT_INTEGER, val=1, ival=1, dval=0.000000, refs=1)
+(id=00003, line=00011, pos=0009, type=TT_INTEGER, val=3, ival=3, dval=0.000000, refs=1)
+(id=00004, line=00011, pos=0011, type=TT_INTEGER, val=5, ival=5, dval=0.000000, refs=1)
+(id=00005, line=00011, pos=0013, type=TT_INTEGER, val=6, ival=6, dval=0.000000, refs=1)
+(id=00006, line=00011, pos=0013, type=TT_SEMICOLON, val=;, ival=0, dval=0.000000, refs=1)
+Garbage left: Garbage error (Fype @ ./src/core/garbage.c line 82)