diff options
author | jaortega <jaortega> | 2000-12-08 21:30:01 +0000 |
---|---|---|
committer | jaortega <jaortega> | 2000-12-08 21:30:01 +0000 |
commit | 4d7d583e47215304d7be5487a42578081bbc8497 (patch) | |
tree | 3bb99264842fecf2d4ecb1f1eea16ac2b13d8177 /mixlib | |
parent | d0dba18550f315279d65e5b4a2fc7cbd20a98b4a (diff) | |
download | mdk-4d7d583e47215304d7be5487a42578081bbc8497.tar.gz mdk-4d7d583e47215304d7be5487a42578081bbc8497.tar.bz2 |
(mix_eval_{set,remove}symbols_from_table, mix_eval_substract_table) new functions
(mix_symbol_table_{merge,substract}_table) const-correct
Diffstat (limited to 'mixlib')
-rw-r--r-- | mixlib/mix_eval.c | 33 | ||||
-rw-r--r-- | mixlib/mix_eval.h | 17 | ||||
-rw-r--r-- | mixlib/mix_symbol_table.c | 8 | ||||
-rw-r--r-- | mixlib/mix_symbol_table.h | 34 |
4 files changed, 60 insertions, 32 deletions
diff --git a/mixlib/mix_eval.c b/mixlib/mix_eval.c index 5a65391..023a413 100644 --- a/mixlib/mix_eval.c +++ b/mixlib/mix_eval.c @@ -1,7 +1,7 @@ /* -*-c-*- -------------- mix_eval.c : * Implementation of the functions declared in mix_eval.h * ------------------------------------------------------------------ - * Last change: Time-stamp: "00/12/03 22:27:53 jose" + * Last change: Time-stamp: "00/12/08 13:16:10 jose" * ------------------------------------------------------------------ * Copyright (C) 2000 jose antonio ortega ruiz <jaortega@acm.org> * @@ -102,7 +102,7 @@ mix_eval_expression_with_loc (mix_eval_t *eval, const gchar *expr, /* get the result of the last evaluation */ mix_word_t -mix_eval_value (mix_eval_t *eval) +mix_eval_value (const mix_eval_t *eval) { g_return_val_if_fail (eval != NULL, MIX_WORD_ZERO); return eval->value; @@ -110,7 +110,7 @@ mix_eval_value (mix_eval_t *eval) /* get the last eval result code */ mix_eval_result_t -mix_eval_last_error (mix_eval_t *eval) +mix_eval_last_error (const mix_eval_t *eval) { g_return_val_if_fail (eval != NULL, MIX_EVAL_INTERN); return eval->result; @@ -118,7 +118,7 @@ mix_eval_last_error (mix_eval_t *eval) /* get the last error string */ const gchar* -mix_eval_last_error_string (mix_eval_t *eval) +mix_eval_last_error_string (const mix_eval_t *eval) { g_return_val_if_fail (eval != NULL, errors_[MIX_EVAL_INTERN]); return errors_[eval->result]; @@ -126,7 +126,7 @@ mix_eval_last_error_string (mix_eval_t *eval) /* get the position of last error */ guint -mix_eval_last_error_pos (mix_eval_t *eval) +mix_eval_last_error_pos (const mix_eval_t *eval) { g_return_val_if_fail (eval != NULL, 0); return eval->errpos; @@ -161,4 +161,25 @@ mix_eval_use_symbol_table (mix_eval_t *eval, eval->towner = FALSE; } - + +gboolean +mix_eval_set_symbols_from_table (mix_eval_t *eval, + const mix_symbol_table_t *table) +{ + g_return_val_if_fail (eval != NULL, FALSE); + if (eval->table != NULL) + return mix_symbol_table_merge_table (eval->table, table); + else + return FALSE; +} + +gboolean +mix_eval_remove_symbols_from_table (mix_eval_t *eval, + const mix_symbol_table_t *table) +{ + g_return_val_if_fail (eval != NULL, FALSE); + if (eval->table != NULL) + return mix_symbol_table_substract_table (eval->table, table); + else + return FALSE; +} diff --git a/mixlib/mix_eval.h b/mixlib/mix_eval.h index c126812..139d0b3 100644 --- a/mixlib/mix_eval.h +++ b/mixlib/mix_eval.h @@ -1,7 +1,7 @@ /* -*-c-*- ---------------- mix_eval.h : * mix_eval_t is an evaluator of MIX W-expressions * ------------------------------------------------------------------ - * Last change: Time-stamp: <00/12/03 12:29:17 jose> + * Last change: Time-stamp: <00/12/08 13:16:10 jose> * ------------------------------------------------------------------ * Copyright (C) 2000 jose antonio ortega ruiz <jaortega@acm.org> * @@ -70,19 +70,19 @@ mix_eval_expression_with_loc (mix_eval_t *eval, const gchar *expr, /* get the result of the last evaluation */ extern mix_word_t -mix_eval_value (mix_eval_t *eval); +mix_eval_value (const mix_eval_t *eval); /* get the last eval result code */ extern mix_eval_result_t -mix_eval_last_error (mix_eval_t *eval); +mix_eval_last_error (const mix_eval_t *eval); /* get the last error string */ extern const gchar* -mix_eval_last_error_string (mix_eval_t *eval); +mix_eval_last_error_string (const mix_eval_t *eval); /* get the position of last error */ extern guint -mix_eval_last_error_pos (mix_eval_t *eval); +mix_eval_last_error_pos (const mix_eval_t *eval); /* add, or redefine, a symbol. see mix_symbol_table.h for possible outcomes. */ @@ -90,9 +90,16 @@ extern gint mix_eval_set_symbol (mix_eval_t *eval, const gchar *symbol, mix_word_t value); +extern gboolean +mix_eval_set_symbols_from_table (mix_eval_t *eval, + const mix_symbol_table_t *table); + extern void mix_eval_remove_symbol (mix_eval_t *eval, const gchar *symbol); +extern gboolean +mix_eval_remove_symbols_from_table (mix_eval_t *eval, + const mix_symbol_table_t *table); diff --git a/mixlib/mix_symbol_table.c b/mixlib/mix_symbol_table.c index d59c396..1e08f2a 100644 --- a/mixlib/mix_symbol_table.c +++ b/mixlib/mix_symbol_table.c @@ -84,24 +84,24 @@ remove_symbol_(gpointer symbol, gpointer value, gpointer target) gboolean mix_symbol_table_merge_table (mix_symbol_table_t *table, - mix_symbol_table_t *from) + const mix_symbol_table_t *from) { g_return_val_if_fail (table != NULL, FALSE); if (from != NULL) { - mix_symbol_table_foreach (from, add_symbol_, table); + mix_symbol_table_foreach ((gpointer)from, add_symbol_, table); } return TRUE; } gboolean mix_symbol_table_substract_table (mix_symbol_table_t *table, - mix_symbol_table_t *other) + const mix_symbol_table_t *other) { g_return_val_if_fail (table != NULL, FALSE); if (other != NULL) { - mix_symbol_table_foreach (other, remove_symbol_, table); + mix_symbol_table_foreach ((gpointer)other, remove_symbol_, table); } return TRUE; } diff --git a/mixlib/mix_symbol_table.h b/mixlib/mix_symbol_table.h index db48ffd..9837ee0 100644 --- a/mixlib/mix_symbol_table.h +++ b/mixlib/mix_symbol_table.h @@ -34,27 +34,27 @@ typedef GHashTable mix_symbol_table_t ; /* Create an empty table */ extern mix_symbol_table_t * -mix_symbol_table_new(void); +mix_symbol_table_new (void); /* Create a table and populate it with the contents of a table stored - in -file- using mix_symbol_table_print(table, MIX_SYM_LINE, file) + in -file- using mix_symbol_table_print (table, MIX_SYM_LINE, file) */ extern mix_symbol_table_t * -mix_symbol_table_new_from_file(FILE *file); +mix_symbol_table_new_from_file (FILE *file); /* Delete a table */ extern void -mix_symbol_table_delete(mix_symbol_table_t *table); +mix_symbol_table_delete (mix_symbol_table_t *table); /* add/remove symbols from other table */ extern gboolean mix_symbol_table_merge_table (mix_symbol_table_t *table, - mix_symbol_table_t *from); + const mix_symbol_table_t *from); extern gboolean mix_symbol_table_substract_table (mix_symbol_table_t *table, - mix_symbol_table_t *other); + const mix_symbol_table_t *other); /* Add/remove symbols one by one */ /* possible outcomes: */ @@ -66,33 +66,33 @@ enum { }; extern gint -mix_symbol_table_add(mix_symbol_table_t *table, - const gchar *sym, mix_word_t value); +mix_symbol_table_add (mix_symbol_table_t *table, + const gchar *sym, mix_word_t value); #define mix_symbol_table_remove(table, sym) \ - g_hash_table_remove(table, sym) + g_hash_table_remove (table, sym) /* Add or modify symbol if it exists */ extern gint -mix_symbol_table_insert(mix_symbol_table_t *table, - const gchar *sym, mix_word_t new_value); +mix_symbol_table_insert (mix_symbol_table_t *table, + const gchar *sym, mix_word_t new_value); /* Add or modify symbol if it exists, without copiying sym */ #define mix_symbol_table_insert_static(table,sym,value)\ - g_hash_table_insert(table,(gpointer)sym,GUINT_TO_POINTER(value)) + g_hash_table_insert (table,(gpointer)sym,GUINT_TO_POINTER (value)) /* Symbols lookup */ extern gboolean -mix_symbol_table_is_defined(const mix_symbol_table_t *table, const gchar *sym); +mix_symbol_table_is_defined (const mix_symbol_table_t *table, const gchar *sym); #define mix_symbol_table_value(table,sym) \ - (mix_word_t)GPOINTER_TO_UINT (g_hash_table_lookup ((GHashTable *)table, \ + (mix_word_t)GPOINTER_TO_UINT (g_hash_table_lookup ((GHashTable *)table, \ (gpointer)sym)) /* Traverse the table */ #define mix_symbol_table_foreach(table,func,data) \ - g_hash_table_foreach(table,func,data) + g_hash_table_foreach (table,func,data) /* Print the table */ enum { @@ -101,8 +101,8 @@ enum { }; extern void -mix_symbol_table_print(const mix_symbol_table_t *table, gint mode, - FILE *file, gboolean skiplocal); +mix_symbol_table_print (const mix_symbol_table_t *table, gint mode, + FILE *file, gboolean skiplocal); #endif /* MIX_SYMBOL_TABLE_H */ |