summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2008-10-19 17:48:21 +0000
committerPaul Buetow <paul@buetow.org>2008-10-19 17:48:21 +0000
commit3d7b35bb37c066489546751e100c2c2b823ccba3 (patch)
treea507be11afc3c55807e254ce5b24c5412367aa46
parentd4657a5d7029ea66d19a5d238a9dd6bf75fe5bb0 (diff)
refs and syms
-rw-r--r--NEW3
-rw-r--r--README26
-rw-r--r--docs/help.txt2
-rw-r--r--docs/pod/fype.1.gzbin6311 -> 6475 bytes
-rw-r--r--docs/pod/fype.html26
-rw-r--r--docs/pod/fype.man43
-rw-r--r--docs/pod/fype.pod26
-rw-r--r--docs/pod/fype.tex34
-rw-r--r--docs/pod/fype.txt26
-rw-r--r--docs/stats.txt4
-rw-r--r--docs/version.txt2
-rw-r--r--examples/synonyms.fy5
-rwxr-xr-xfypebin425827 -> 426303 bytes
-rw-r--r--src/build.h2
-rw-r--r--src/core/function.c11
-rw-r--r--src/core/interpret.c21
-rw-r--r--src/core/token.c2
-rw-r--r--src/core/token.h1
18 files changed, 220 insertions, 14 deletions
diff --git a/NEW b/NEW
index e69de29..25373a6 100644
--- a/NEW
+++ b/NEW
@@ -0,0 +1,3 @@
+keywords:
+ syms
+ refs
diff --git a/README b/README
index 5c8b9b6..4e82ce6 100644
--- a/README
+++ b/README
@@ -205,7 +205,7 @@ VARIABLES
say foo;
}
-SYNONYMS TO VARIABLES/IDENTIFIERS
+SYNONYMS
Each variable can have as many synonyms as wished. A synonym is another
name to access the content of a specific variable. Here is an example of
how to use synomyms:
@@ -221,6 +221,30 @@ SYNONYMS TO VARIABLES/IDENTIFIERS
normal variables but can be also used for function and procedure names
etc.
+ # 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"
+
+ The syms keyword gives you the total number of synonyms pointing to a
+ specific value:
+
+ my foo = 1;
+ say syms foo; # Prints 1
+
+ my baz = \foo;
+ say syms foo; # Prints 2
+ say syms baz; # Prints 2
+
+ undef baz;
+ say syms foo; # Prints 1
+
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
diff --git a/docs/help.txt b/docs/help.txt
index 0e73284..db604de 100644
--- a/docs/help.txt
+++ b/docs/help.txt
@@ -1,4 +1,4 @@
-Fype v0.1-devel Build 9219
+Fype v0.1-devel Build 9240
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 e39eee0..64bebfb 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 02c30c4..6400295 100644
--- a/docs/pod/fype.html
+++ b/docs/pod/fype.html
@@ -38,7 +38,7 @@
</ul>
<li><a href="#variables">VARIABLES</a></li>
- <li><a href="#synonyms_to_variables_identifiers">SYNONYMS TO VARIABLES/IDENTIFIERS</a></li>
+ <li><a href="#synonyms">SYNONYMS</a></li>
<li><a href="#built_in_functions">BUILT IN FUNCTIONS</a></li>
<ul>
@@ -311,7 +311,7 @@ not.</p>
<p>
</p>
<hr />
-<h1><a name="synonyms_to_variables_identifiers">SYNONYMS TO VARIABLES/IDENTIFIERS</a></h1>
+<h1><a name="synonyms">SYNONYMS</a></h1>
<p>Each variable can have as many synonyms as wished. A synonym is another name to access the content of a specific variable. Here is an example of how to use synomyms:</p>
<pre>
my foo = &quot;foo&quot;;
@@ -321,6 +321,28 @@ not.</p>
# The synonym variable should now also set to &quot;bar&quot;
assert &quot;bar&quot; == bar;</pre>
<p>Synonyms can be used for all kind of identifiers. It's not limited to normal variables but can be also used for function and procedure names etc.</p>
+<pre>
+ # Create a new procedure baz
+ proc baz { say &quot;I am baz&quot;; }</pre>
+<pre>
+ # Make a synonym baz, and undefine baz
+ my bay = \baz;</pre>
+<pre>
+ undef baz;</pre>
+<pre>
+ # bay still has a reference of the original procedure baz
+ bay; # this prints aut &quot;I am baz&quot;</pre>
+<p>The <strong>syms</strong> keyword gives you the total number of synonyms pointing to a specific value:</p>
+<pre>
+ my foo = 1;
+ say syms foo; # Prints 1</pre>
+<pre>
+ my baz = \foo;
+ say syms foo; # Prints 2
+ say syms baz; # Prints 2</pre>
+<pre>
+ undef baz;
+ say syms foo; # Prints 1</pre>
<p>
</p>
<hr />
diff --git a/docs/pod/fype.man b/docs/pod/fype.man
index 42daf43..36f3ef2 100644
--- a/docs/pod/fype.man
+++ b/docs/pod/fype.man
@@ -129,7 +129,7 @@
.\" ========================================================================
.\"
.IX Title "FYPE 1"
-.TH FYPE 1 "2008-10-19" "Fype v0.1-devel Build 9219" "The Fype Users Manual Page"
+.TH FYPE 1 "2008-10-19" "Fype v0.1-devel Build 9240" "The Fype Users Manual Page"
.SH "NAME"
\&\fBFype\fR is \fBF\fRor \fBY\fRour \fBP\fRrogram \fBE\fRxecution
.PP
@@ -345,8 +345,8 @@ not.
\& say foo;
\& }
.Ve
-.SH "SYNONYMS TO VARIABLES/IDENTIFIERS"
-.IX Header "SYNONYMS TO VARIABLES/IDENTIFIERS"
+.SH "SYNONYMS"
+.IX Header "SYNONYMS"
Each variable can have as many synonyms as wished. A synonym is another name to access the content of a specific variable. Here is an example of how to use synomyms:
.PP
.Vb 3
@@ -361,6 +361,43 @@ Each variable can have as many synonyms as wished. A synonym is another name to
.Ve
.PP
Synonyms can be used for all kind of identifiers. It's not limited to normal variables but can be also used for function and procedure names etc.
+.PP
+.Vb 2
+\& # Create a new procedure baz
+\& proc baz { say "I am baz"; }
+.Ve
+.PP
+.Vb 2
+\& # Make a synonym baz, and undefine baz
+\& my bay = \ebaz;
+.Ve
+.PP
+.Vb 1
+\& undef baz;
+.Ve
+.PP
+.Vb 2
+\& # bay still has a reference of the original procedure baz
+\& bay; # this prints aut "I am baz"
+.Ve
+.PP
+The \fBsyms\fR keyword gives you the total number of synonyms pointing to a specific value:
+.PP
+.Vb 2
+\& my foo = 1;
+\& say syms foo; # Prints 1
+.Ve
+.PP
+.Vb 3
+\& my baz = \efoo;
+\& say syms foo; # Prints 2
+\& say syms baz; # Prints 2
+.Ve
+.PP
+.Vb 2
+\& undef baz;
+\& say syms foo; # Prints 1
+.Ve
.SH "BUILT IN FUNCTIONS"
.IX Header "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.
diff --git a/docs/pod/fype.pod b/docs/pod/fype.pod
index 2773c4e..1e29a6d 100644
--- a/docs/pod/fype.pod
+++ b/docs/pod/fype.pod
@@ -219,7 +219,7 @@ not.
say foo;
}
-=head1 SYNONYMS TO VARIABLES/IDENTIFIERS
+=head1 SYNONYMS
Each variable can have as many synonyms as wished. A synonym is another name to access the content of a specific variable. Here is an example of how to use synomyms:
@@ -232,6 +232,30 @@ Each variable can have as many synonyms as wished. A synonym is another name to
Synonyms can be used for all kind of identifiers. It's not limited to normal variables but can be also used for function and procedure names etc.
+ # 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"
+
+The B<syms> keyword gives you the total number of synonyms pointing to a specific value:
+
+ my foo = 1;
+ say syms foo; # Prints 1
+
+ my baz = \foo;
+ say syms foo; # Prints 2
+ say syms baz; # Prints 2
+
+ undef baz;
+ say syms foo; # Prints 1
+
+
=head1 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.
diff --git a/docs/pod/fype.tex b/docs/pod/fype.tex
index 19fa9f2..8bdd585 100644
--- a/docs/pod/fype.tex
+++ b/docs/pod/fype.tex
@@ -272,7 +272,7 @@ not.
say foo;
}
\end{verbatim}
-\section{SYNONYMS TO VARIABLES/IDENTIFIERS\label{SYNONYMS_TO_VARIABLES_IDENTIFIERS}\index{SYNONYMS TO VARIABLES/IDENTIFIERS}}
+\section{SYNONYMS\label{SYNONYMS}\index{SYNONYMS}}
Each variable can have as many synonyms as wished. A synonym is another name to access the content of a specific variable. Here is an example of how to use synomyms:
@@ -290,6 +290,38 @@ Each variable can have as many synonyms as wished. A synonym is another name to
Synonyms can be used for all kind of identifiers. It's not limited to normal variables but can be also used for function and procedure names etc.
+\begin{verbatim}
+ # Create a new procedure baz
+ proc baz { say "I am baz"; }
+\end{verbatim}
+\begin{verbatim}
+ # Make a synonym baz, and undefine baz
+ my bay = \baz;
+\end{verbatim}
+\begin{verbatim}
+ undef baz;
+\end{verbatim}
+\begin{verbatim}
+ # bay still has a reference of the original procedure baz
+ bay; # this prints aut "I am baz"
+\end{verbatim}
+
+
+The \textbf{syms} keyword gives you the total number of synonyms pointing to a specific value:
+
+\begin{verbatim}
+ my foo = 1;
+ say syms foo; # Prints 1
+\end{verbatim}
+\begin{verbatim}
+ my baz = \foo;
+ say syms foo; # Prints 2
+ say syms baz; # Prints 2
+\end{verbatim}
+\begin{verbatim}
+ undef baz;
+ say syms foo; # Prints 1
+\end{verbatim}
\section{BUILT IN FUNCTIONS\label{BUILT_IN_FUNCTIONS}\index{BUILT IN FUNCTIONS}}
diff --git a/docs/pod/fype.txt b/docs/pod/fype.txt
index 5c8b9b6..4e82ce6 100644
--- a/docs/pod/fype.txt
+++ b/docs/pod/fype.txt
@@ -205,7 +205,7 @@ VARIABLES
say foo;
}
-SYNONYMS TO VARIABLES/IDENTIFIERS
+SYNONYMS
Each variable can have as many synonyms as wished. A synonym is another
name to access the content of a specific variable. Here is an example of
how to use synomyms:
@@ -221,6 +221,30 @@ SYNONYMS TO VARIABLES/IDENTIFIERS
normal variables but can be also used for function and procedure names
etc.
+ # 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"
+
+ The syms keyword gives you the total number of synonyms pointing to a
+ specific value:
+
+ my foo = 1;
+ say syms foo; # Prints 1
+
+ my baz = \foo;
+ say syms foo; # Prints 2
+ say syms baz; # Prints 2
+
+ undef baz;
+ say syms foo; # Prints 1
+
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
diff --git a/docs/stats.txt b/docs/stats.txt
index ffca974..03653bc 100644
--- a/docs/stats.txt
+++ b/docs/stats.txt
@@ -1,4 +1,4 @@
===> Num of C source files : 42
-===> Num of C source lines : 7482
+===> Num of C source lines : 7517
===> Num of Fype source examples : 14
-===> Num of Fype source lines : 353
+===> Num of Fype source lines : 358
diff --git a/docs/version.txt b/docs/version.txt
index 84a6485..2d10fd4 100644
--- a/docs/version.txt
+++ b/docs/version.txt
@@ -1 +1 @@
-Fype v0.1-devel Build 9219
+Fype v0.1-devel Build 9240
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"
diff --git a/fype b/fype
index f36669e..e820c09 100755
--- a/fype
+++ b/fype
Binary files differ
diff --git a/src/build.h b/src/build.h
index 61eb78f..65820e2 100644
--- a/src/build.h
+++ b/src/build.h
@@ -35,7 +35,7 @@
#ifndef BUILD_H
#define BUILD_H
-#define BUILDNR 9235
+#define BUILDNR 9245
#define OS_FREEBSD
#endif
diff --git a/src/core/function.c b/src/core/function.c
index fda40b8..c25834d 100644
--- a/src/core/function.c
+++ b/src/core/function.c
@@ -575,6 +575,9 @@ function_is_buildin(Token *p_token_ident) {
if (strcmp("not", token_get_val(p_token_ident)) == 0)
return (true);
+ if (strcmp("refs", token_get_val(p_token_ident)) == 0)
+ return (true);
+
return (false);
}
@@ -812,6 +815,14 @@ function_process_buildin(Interpret *p_interpret, Token *p_token_ident,
break;
NO_DEFAULT;
}
+
+ } else if (strcmp("refs", 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_top = stack_pop(p_stack_args);
+ Token *p_token = token_new_integer(p_token_top->i_ref_count);
+ stack_push(p_stack_args, p_token);
}
}
diff --git a/src/core/interpret.c b/src/core/interpret.c
index 2c80163..9dbd7df 100644
--- a/src/core/interpret.c
+++ b/src/core/interpret.c
@@ -927,6 +927,27 @@ _term(Interpret *p_interpret) {
}
break;
+ case TT_SYMS:
+ {
+ _NEXT
+ if (p_interpret->tt != TT_IDENT)
+ _INTERPRET_ERROR("Expexted identifier for 'syms'",
+ p_interpret->p_token);
+
+ char *c_name = token_get_val(p_interpret->p_token);
+ Symbol *p_symbol = scope_get(p_interpret->p_scope, c_name);
+ if (p_symbol == NULL)
+ _INTERPRET_ERROR("No such symbol", p_interpret->p_token);
+
+
+ Token *p_token_num_refs = token_new_integer(p_symbol->i_refs);
+ stack_push(p_interpret->p_stack, p_token_num_refs);
+
+ _NEXT;
+ return (1);
+ }
+ break;
+
/*
case TT_PARANT_AL:
{
diff --git a/src/core/token.c b/src/core/token.c
index 4626e5a..2f08097 100644
--- a/src/core/token.c
+++ b/src/core/token.c
@@ -52,6 +52,7 @@ get_tt(char *c_token) {
CHECK("next") TT_NEXT;
CHECK("defined") TT_DEFINED;
CHECK("undef") TT_UNDEF;
+ CHECK("syms") TT_SYMS;
CHECK("ret") TT_RET;
CHECK("const") TT_CONST;
CHECK("proc") TT_PROC;
@@ -129,6 +130,7 @@ tt_get_name(TokenType tt_cur) {
CASE(TT_NEXT,"TT_NEXT")
CASE(TT_DEFINED,"TT_DEFINED")
CASE(TT_UNDEF,"TT_UNDEF")
+ CASE(TT_SYMS,"TT_SYMS")
CASE(TT_INT,"TT_INT")
CASE(END_KEYWORDS, "END_KEYWORDS")
diff --git a/src/core/token.h b/src/core/token.h
index caf4854..2107dd2 100644
--- a/src/core/token.h
+++ b/src/core/token.h
@@ -110,6 +110,7 @@ typedef enum {
TT_INT,
TT_DEFINED,
TT_UNDEF,
+ TT_SYMS,
END_KEYWORDS,
START_PARANTS,