[genius] Thu Jul 23 16:28:59 2009 Jiri (George) Lebl <jirka 5z com>



commit ee3caa8c2d6b97274916d3731501bf2495b25bda
Author: Jiri (George) Lebl <jirka 5z com>
Date:   Thu Jul 23 16:29:26 2009 -0500

    Thu Jul 23 16:28:59 2009  Jiri (George) Lebl <jirka 5z com>
    
    	* src/dict.c, src/eval.c: remove some forgotten debug prints
    
    	* src/eval.c: do not allow setting a new parameter over a protected
    	  id
    
    	* src/funclib.c: Add UserVariables function
    
    	* src/geniustests.txt, src/testscope.gel: add new tests

 ChangeLog           |   11 +++++++++
 src/dict.c          |    2 -
 src/eval.c          |    8 ++++++-
 src/funclib.c       |   58 +++++++++++++++++++++++++++++++++++++++++++-------
 src/geniustests.txt |   11 +++++++++
 src/testscope.gel   |   18 +++++++++++++++
 6 files changed, 97 insertions(+), 11 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 8bdd64c..5fc2172 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+Thu Jul 23 16:28:59 2009  Jiri (George) Lebl <jirka 5z com>
+
+	* src/dict.c, src/eval.c: remove some forgotten debug prints
+
+	* src/eval.c: do not allow setting a new parameter over a protected
+	  id
+
+	* src/funclib.c: Add UserVariables function
+
+	* src/geniustests.txt, src/testscope.gel: add new tests
+
 Thu Jul 23 12:26:47 2009  Jiri (George) Lebl <jirka 5z com>
 
 	* src/funclib.c: Add UndefineAll, ProtectAll, make Undefine an alias
diff --git a/src/dict.c b/src/dict.c
index d8ff824..a2ff62e 100644
--- a/src/dict.c
+++ b/src/dict.c
@@ -551,8 +551,6 @@ d_delete_global(GelToken *id)
 
 	g_return_val_if_fail (id != NULL && id->token != NULL, FALSE);
 
-			printf ("FOO3 %s\n", id->token);
-
 	id->protected_ = 0;
 	id->parameter = 0;
 	id->built_in_parameter = 0;
diff --git a/src/eval.c b/src/eval.c
index 528c3a0..fd5c92d 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -5698,7 +5698,13 @@ iter_parameterop (GelETree *n)
 		gel_errorout (_("Parameters can only be created in the global context"));
 		return;
 	}
-	
+
+	if G_UNLIKELY (r->id.id->protected_) {
+		gel_errorout (_("Trying to set a protected id '%s'"),
+			      r->id.id->token);
+		return;
+	}
+
 	d_addfunc (d_makevfunc (r->id.id, gel_copynode (rr)));
 	r->id.id->parameter = 1;
 
diff --git a/src/funclib.c b/src/funclib.c
index d1f1867..c920727 100644
--- a/src/funclib.c
+++ b/src/funclib.c
@@ -286,16 +286,8 @@ UndefineAll_op (GelCtx *ctx, GelETree * * a, gboolean *exception)
 	     li = li->next) {
 		GelEFunc *f = li->data;
 		GelToken *tok = f->id;
-		if (tok->parameter) {
-			printf ("FOO %s %d %d %p\n",
-				tok->token,
-				tok->parameter,
-				tok->protected_,
-				f);
-		}
 		if ( ! tok->protected_ &&
 		    strcmp (tok->token, "Ans") != 0) {
-			printf ("FOO2 %s\n", tok->token);
 			d_delete_global (tok);
 		}
 	}
@@ -312,6 +304,55 @@ ProtectAll_op (GelCtx *ctx, GelETree * * a, gboolean *exception)
 }
 
 static GelETree *
+UserVariables_op (GelCtx *ctx, GelETree * * a, gboolean *exception)
+{
+	GSList *li;
+	GelMatrix *m;
+	GelETree *n;
+	int len, i;
+
+	len = 0;
+
+	for (li = d_getcontext_global ();
+	     li != NULL;
+	     li = li->next) {
+		GelEFunc *f = li->data;
+		GelToken *tok = f->id;
+		if ( ! tok->protected_ &&
+		    strcmp (tok->token, "Ans") != 0) {
+			len++;
+		}
+	}
+
+	if (len == 0)
+		return gel_makenum_null ();
+
+	m = gel_matrix_new ();
+	gel_matrix_set_size (m, len, 1, FALSE /* padding */);
+
+	i = 0;
+	for (li = d_getcontext_global ();
+	     li != NULL;
+	     li = li->next) {
+		GelEFunc *f = li->data;
+		GelToken *tok = f->id;
+		if ( ! tok->protected_ &&
+		    strcmp (tok->token, "Ans") != 0) {
+			gel_matrix_index (m, i, 0) =
+				gel_makenum_identifier (tok);
+			i++;
+		}
+	}
+
+	GEL_GET_NEW_NODE (n);
+	n->type = GEL_MATRIX_NODE;
+	n->mat.matrix = gel_matrixw_new_with_matrix (m);
+	n->mat.quoted = FALSE;
+
+	return n;
+}
+
+static GelETree *
 true_op (GelCtx *ctx, GelETree * * a, gboolean *exception)
 {
 	return gel_makenum_bool (1);
@@ -6386,6 +6427,7 @@ gel_funclib_addall(void)
 	ALIAS (Undefine, 1, undefine);
 	FUNC (UndefineAll, 0, "", "basic", N_("Undefine all unprotected (user defined) global variables and parameters.  Does not reset or change protected (system) parameters."));
 	FUNC (ProtectAll, 0, "", "basic", N_("Mark all currently defined variables as protected.  They will be treated as system defined variables from now on."));
+	FUNC (UserVariables, 0, "", "basic", N_("Return a vector of all global unprotected (user defined) variable names."));
 
 	FUNC (Parse, 1, "str", "basic", N_("Parse a string (but do not execute)"));
 	FUNC (Evaluate, 1, "str", "basic", N_("Parse and evaluate a string"));
diff --git a/src/geniustests.txt b/src/geniustests.txt
index a37472b..bebcb3c 100644
--- a/src/geniustests.txt
+++ b/src/geniustests.txt
@@ -930,6 +930,17 @@ EulersMethod (`(x,y)=[(x-y@(1));(x-y@(2))],0,[0;0],3,3)		[2.0;2.0]
 CompositeSimpsonsRule(`(x)=x^2,0,3,100)				9.0
 CompositeSimpsonsRule(`(x)=x^2,3,0,100)				-9.0
 CompositeSimpsonsRule(`(x)=x^2,3,3,100)				0
+a								a
+a=7;UndefineAll();a						a
+UndefineAll();a							a
+UndefineAll()+0							((null)+0)
+UserVariables()+0						((null)+0)
+a=9;ProtectAll();UserVariables()+0				((null)+0)
+a=9;ProtectAll();a=11;a						9
+a=7;(function f(x)=(b=9));f(8);UserVariables()			[f,a]
+a=7;(function f(x)=(b=9));f(8);UndefineAll();UserVariables()+0	((null)+0)
+parameter FloatPrecision = 888					(parameter FloatPrecision = 888)
+parameter foo = 888						888
 load "nullspacetest.gel"					true
 load "longtest.gel"						true
 load "testprec.gel"						true
diff --git a/src/testscope.gel b/src/testscope.gel
index 948de86..829ab89 100644
--- a/src/testscope.gel
+++ b/src/testscope.gel
@@ -56,6 +56,24 @@ function f(x) = (
 );
 if f(0) != 1+5+9 then (error("global lookup over all local (2) failed");exit());
 
+function g(x) = 545;
+function f(x) = (
+	local g;
+	function g(y) = 11;
+	function h(x) = g(6);
+	h(x)
+);
+if f(0) != 545 then (error("global function lookup over local failed");exit());
+
+function g(x) = -987;
+function f(x) = (
+	local *;
+	function g(y) = 11;
+	function h(x) = g(6);
+	h(x)
+);
+if f(0) != -987 then (error("global function lookup over all local failed");exit());
+
 A = 1;
 function f(x) = (
 	A = 8;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]