genius r646 - in trunk: . help/C src



Author: jirka
Date: Sun Feb 24 21:32:30 2008
New Revision: 646
URL: http://svn.gnome.org/viewvc/genius?rev=646&view=rev

Log:

Sun Feb 24 15:25:45 2008  Jiri (George) Lebl <jirka 5z com>

	* src/dict.c, src/funclib.c: Add IsDefined and undefine.  Implement
	  d_delete.  protect and unprotect now work with matrices of
	  identifiers.

	* src/geniustests.txt: add tests

	* help/C/*.xml: update docs

	* TODO: problems with subst lists can lead to crash, document this



Modified:
   trunk/ChangeLog
   trunk/NEWS
   trunk/TODO
   trunk/help/C/gel-function-list.xml
   trunk/help/C/genius.xml
   trunk/src/dict.c
   trunk/src/funclib.c
   trunk/src/geniustests.txt

Modified: trunk/NEWS
==============================================================================
--- trunk/NEWS	(original)
+++ trunk/NEWS	Sun Feb 24 21:32:30 2008
@@ -1,10 +1,13 @@
 Changes to 1.0.3
 
-* Add IsMersennePrime, MersennePrimeExponents
+Syntax and semantical changes are marked with CHANGE:
+
+* Add IsMersennePrime, MersennePrimeExponents, IsDefined, undefine
 * QuadraticFormula built in and more numerically stable
 * CHANGE: It's Fibonacci in correct spelling, short name is still fib
 * Calling internal functions is now slightly faster
 * Fix some memory leaks
+* Translations (FIXME)
 
 Changes to 1.0.2
 

Modified: trunk/TODO
==============================================================================
--- trunk/TODO	(original)
+++ trunk/TODO	Sun Feb 24 21:32:30 2008
@@ -5,6 +5,15 @@
   with context > 0 on the toplevel context.   It's strange.  And I can't
   repro it now
 
+* crash:
+  function f(x) = (k=1; ff=`()=(k+1) ; k=(`()=0) ; ff); ll=f(5)
+
+* behaviour?:
+  function f(x) = (k=1; ff=`()=(k+1) ; k=null ; ff)
+  the returned function should return 2 not "((null)+1)" shouldn't it?
+  That is, replacement (putting into extra_dict)
+  should happen on function definition, not on context pop.
+
 * Implement max_nodes in the command line version
   * Implement MaxNodes parameter
 

Modified: trunk/help/C/gel-function-list.xml
==============================================================================
--- trunk/help/C/gel-function-list.xml	(original)
+++ trunk/help/C/gel-function-list.xml	Sun Feb 24 21:32:30 2008
@@ -130,6 +130,17 @@
          </listitem>
         </varlistentry>
 
+        <varlistentry id="gel-function-IsDefined">
+         <term>IsDefined</term>
+         <listitem>
+          <synopsis>IsDefined (id)</synopsis>
+          <para>Check if an id is defined.  You should pass a string or
+	   and identifier.  If you pass a matrix, each entry will be
+	   evaluated separately and the matrix should contain strings
+	   or identifiers.</para>
+         </listitem>
+        </varlistentry>
+
         <varlistentry id="gel-function-IsFunction">
          <term>IsFunction</term>
          <listitem>
@@ -325,6 +336,16 @@
          </listitem>
         </varlistentry>
 
+        <varlistentry id="gel-function-undefine">
+         <term>undefine</term>
+         <listitem>
+          <synopsis>undefine (id)</synopsis>
+          <para>Undefine a variable.  This includes locals and globals,
+	    every value on all context levels is wiped.  This function
+	    should really not be used on local variables.</para>
+         </listitem>
+        </varlistentry>
+
         <varlistentry id="gel-function-unprotect">
          <term>unprotect</term>
          <listitem>

Modified: trunk/help/C/genius.xml
==============================================================================
--- trunk/help/C/genius.xml	(original)
+++ trunk/help/C/genius.xml	Sun Feb 24 21:32:30 2008
@@ -3,7 +3,7 @@
 "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"; [
   <!ENTITY app "<application>Genius Mathematics Tool</application>">
   <!ENTITY appname "Genius">
-  <!ENTITY appversion "1.0.2">
+  <!ENTITY appversion "1.0.3">
   <!ENTITY manrevision "0.2.2">
   <!ENTITY date "February 2008">
 
@@ -28,7 +28,7 @@
     <title>&appname; Manual</title>       
 
     <copyright>
-      <year>1997-2007</year>
+      <year>1997-2008</year>
       <holder>Ji&#345;&iacute; (George) Lebl</holder>
     </copyright>
     <copyright>

Modified: trunk/src/dict.c
==============================================================================
--- trunk/src/dict.c	(original)
+++ trunk/src/dict.c	Sun Feb 24 21:32:30 2008
@@ -1,5 +1,5 @@
 /* GENIUS Calculator
- * Copyright (C) 1997-2007 Jiri (George) Lebl
+ * Copyright (C) 1997-2008 Jiri (George) Lebl
  *
  * Author: Jiri (George) Lebl
  *
@@ -491,11 +491,43 @@
 	return tok;
 }
 
+/* this may be inefficient as it also goes through global,
+ * but we don't assume we do this kind of thing often.  Only 
+ * done in d_delete which is only done on Undefine. */
+static void
+whack_from_all_contexts (GelEFunc *func)
+{
+	GSList *li;
+	for (li = context.stack; li != NULL; li = li->next) {
+		GSList *fl = g_slist_find (li->data, func);
+		if (fl != NULL) {
+			li->data = g_slist_delete_link (li->data, fl);
+			return;
+		}
+	}
+}
+
 gboolean
 d_delete(GelToken *id)
 {
-	/*FIXME: Delete function!*/
-	return FALSE;
+	GSList *li, *list;
+
+	id->protected_ = 0;
+	id->parameter = 0;
+	id->built_in_parameter = 0;
+
+	id->curref = NULL;
+	list = id->refs;
+	id->refs = NULL;
+	for (li = list; li != NULL; li = li->next) {
+		GelEFunc *f = li->data;
+		f->id = NULL;
+		whack_from_all_contexts (f);
+		d_freefunc (f);
+	}
+	g_slist_free (list);
+
+	return TRUE;
 }
 
 /*clear all context dictionaries and pop out all the contexts except

Modified: trunk/src/funclib.c
==============================================================================
--- trunk/src/funclib.c	(original)
+++ trunk/src/funclib.c	Sun Feb 24 21:32:30 2008
@@ -260,6 +260,61 @@
 }
 
 static GelETree *
+IsDefined_op (GelCtx *ctx, GelETree * * a, gboolean *exception)
+{
+	GelToken *tok;
+
+	if (a[0]->type == MATRIX_NODE)
+		return gel_apply_func_to_matrix
+			(ctx, a[0], IsDefined_op, "IsDefined",
+			 exception);
+
+	if G_UNLIKELY ( ! check_argument_string_or_identifier (a, 0, "IsDefined"))
+		return NULL;
+
+	if (a[0]->type == IDENTIFIER_NODE) {
+		tok = a[0]->id.id;
+	} else /* STRING_NODE */ {
+		tok = d_intern (a[0]->str.str);
+	}
+
+	if (d_lookup_global (tok) != NULL)
+		return gel_makenum_bool (1);
+	else
+		return gel_makenum_bool (0);
+}
+
+static GelETree *
+undefine_op (GelCtx *ctx, GelETree * * a, gboolean *exception)
+{
+	GelToken *tok;
+
+	if (a[0]->type == MATRIX_NODE)
+		return gel_apply_func_to_matrix
+			(ctx, a[0], undefine_op, "undefine",
+			 exception);
+
+	if G_UNLIKELY ( ! check_argument_string_or_identifier (a, 0, "undefine"))
+		return NULL;
+
+	if (a[0]->type == IDENTIFIER_NODE) {
+		tok = a[0]->id.id;
+	} else /* STRING_NODE */ {
+		tok = d_intern (a[0]->str.str);
+	}
+
+	if G_UNLIKELY (tok->protected_) {
+		gel_errorout (_("%s: trying to undefine a protected id!"),
+			      "undefine");
+		return NULL;
+	}
+
+	d_delete (tok);
+
+	return gel_makenum_null ();
+}
+
+static GelETree *
 true_op (GelCtx *ctx, GelETree * * a, gboolean *exception)
 {
 	return gel_makenum_bool (1);
@@ -5209,6 +5264,11 @@
 {
 	GelToken *tok;
 
+	if (a[0]->type == MATRIX_NODE)
+		return gel_apply_func_to_matrix
+			(ctx, a[0], protect_op, "protect",
+			 exception);
+
 	if G_UNLIKELY ( ! check_argument_string_or_identifier (a, 0, "protect"))
 		return NULL;
 
@@ -5228,6 +5288,11 @@
 {
 	GelToken *tok;
 
+	if (a[0]->type == MATRIX_NODE)
+		return gel_apply_func_to_matrix
+			(ctx, a[0], unprotect_op, "unprotect",
+			 exception);
+
 	if G_UNLIKELY ( ! check_argument_string_or_identifier (a, 0, "unprotect"))
 		return NULL;
 
@@ -6173,6 +6238,8 @@
 	FUNC (unprotect, 1, "id", "basic", N_("Unprotect a variable from being modified"));
 	VFUNC (SetFunctionFlags, 2, "id,flags", "basic", N_("Set flags for a function, currently \"PropagateMod\" and \"NoModuloArguments\""));
 	FUNC (GetCurrentModulo, 0, "", "basic", N_("Get current modulo from the context outside the function"));
+	FUNC (IsDefined, 1, "id", "basic", N_("Check if a variable or function is defined"));
+	FUNC (undefine, 1, "id", "basic", N_("Undefine a variable (including locals and globals)"));
 
 	FUNC (CompositeSimpsonsRule, 4, "f,a,b,n", "calculus", N_("Integration of f by Composite Simpson's Rule on the interval [a,b] with n subintervals with error of max(f'''')*h^4*(b-a)/180, note that n should be even"));
 	f->no_mod_all_args = 1;

Modified: trunk/src/geniustests.txt
==============================================================================
--- trunk/src/geniustests.txt	(original)
+++ trunk/src/geniustests.txt	Sun Feb 24 21:32:30 2008
@@ -886,5 +886,10 @@
 [1,2;3,4]@([1,2],null)+1					((null)+1)
 [1,2;3,4]@(null,2)+1						((null)+1)
 [1,2;3,4]@(null,[1,2])+1					((null)+1)
+IsDefined("IsDefined")						true
+IsDefined(`IsDefined)						true
+IsDefined(`UguUguUgu)						false
+a=9;undefine(`a);a						a
+a=9;undefine("a");a						a
 load "nullspacetest.gel"					true
 load "longtest.gel"						true



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