Mercurial > octave-nkf
comparison src/variables.cc @ 2086:bfb775fb6fe8
[project @ 1996-04-25 05:55:19 by jwe]
author | jwe |
---|---|
date | Thu, 25 Apr 1996 05:55:19 +0000 |
parents | 36800cb7fe04 |
children | 4dcc8b77e84a |
comparison
equal
deleted
inserted
replaced
2085:7603b37325db | 2086:bfb775fb6fe8 |
---|---|
122 { | 122 { |
123 symbol_record *sr = curr_sym_tab->lookup (name, 0, 0); | 123 symbol_record *sr = curr_sym_tab->lookup (name, 0, 0); |
124 return (sr && sr->is_linked_to_global ()); | 124 return (sr && sr->is_linked_to_global ()); |
125 } | 125 } |
126 | 126 |
127 // Is this tree_constant a valid function? | 127 // Is this octave_value a valid function? |
128 | 128 |
129 tree_fvc * | 129 tree_fvc * |
130 is_valid_function (const tree_constant& arg, const string& warn_for, int warn) | 130 is_valid_function (const octave_value& arg, const string& warn_for, int warn) |
131 { | 131 { |
132 tree_fvc *ans = 0; | 132 tree_fvc *ans = 0; |
133 | 133 |
134 string fcn_name; | 134 string fcn_name; |
135 | 135 |
165 | 165 |
166 DEFUN (is_global, args, , | 166 DEFUN (is_global, args, , |
167 "is_global (X): return 1 if the string X names a global variable\n\ | 167 "is_global (X): return 1 if the string X names a global variable\n\ |
168 otherwise, return 0.") | 168 otherwise, return 0.") |
169 { | 169 { |
170 Octave_object retval = 0.0; | 170 octave_value_list retval = 0.0; |
171 | 171 |
172 int nargin = args.length (); | 172 int nargin = args.length (); |
173 | 173 |
174 if (nargin != 1) | 174 if (nargin != 1) |
175 { | 175 { |
201 1 : NAME is a variable\n\ | 201 1 : NAME is a variable\n\ |
202 2 : NAME is a function\n\ | 202 2 : NAME is a function\n\ |
203 3 : NAME is a .oct file in the current LOADPATH\n\ | 203 3 : NAME is a .oct file in the current LOADPATH\n\ |
204 5 : NAME is a built-in function") | 204 5 : NAME is a built-in function") |
205 { | 205 { |
206 Octave_object retval; | 206 octave_value_list retval; |
207 | 207 |
208 int nargin = args.length (); | 208 int nargin = args.length (); |
209 | 209 |
210 if (nargin != 1) | 210 if (nargin != 1) |
211 { | 211 { |
245 if (! struct_elts.empty ()) | 245 if (! struct_elts.empty ()) |
246 { | 246 { |
247 retval = 0.0; | 247 retval = 0.0; |
248 if (def->is_constant ()) | 248 if (def->is_constant ()) |
249 { | 249 { |
250 tree_constant *tmp = (tree_constant *) def; | 250 octave_value *tmp = (octave_value *) def; |
251 | 251 |
252 tree_constant ult = tmp->lookup_map_element (struct_elts, 0, 1); | 252 octave_value ult = tmp->lookup_map_element (struct_elts, 0, 1); |
253 | 253 |
254 if (ult.is_defined ()) | 254 if (ult.is_defined ()) |
255 retval = 1.0; | 255 retval = 1.0; |
256 } | 256 } |
257 } | 257 } |
900 | 900 |
901 tree_fvc *defn = sr->def (); | 901 tree_fvc *defn = sr->def (); |
902 | 902 |
903 if (defn) | 903 if (defn) |
904 { | 904 { |
905 tree_constant val = defn->eval (0); | 905 octave_value val = defn->eval (0); |
906 | 906 |
907 if (! error_state && val.is_string ()) | 907 if (! error_state && val.is_string ()) |
908 retval = val.string_value (); | 908 retval = val.string_value (); |
909 } | 909 } |
910 | 910 |
927 | 927 |
928 tree_fvc *defn = sr->def (); | 928 tree_fvc *defn = sr->def (); |
929 | 929 |
930 if (defn) | 930 if (defn) |
931 { | 931 { |
932 tree_constant val = defn->eval (0); | 932 octave_value val = defn->eval (0); |
933 | 933 |
934 if (! error_state && val.is_scalar_type ()) | 934 if (! error_state && val.is_scalar_type ()) |
935 { | 935 { |
936 d = val.double_value (); | 936 d = val.double_value (); |
937 status = 1; | 937 status = 1; |
941 return status; | 941 return status; |
942 } | 942 } |
943 | 943 |
944 // Look for the given name in the global symbol table. | 944 // Look for the given name in the global symbol table. |
945 | 945 |
946 tree_constant | 946 octave_value |
947 builtin_any_variable (const string& name) | 947 builtin_any_variable (const string& name) |
948 { | 948 { |
949 tree_constant retval; | 949 octave_value retval; |
950 | 950 |
951 symbol_record *sr = global_sym_tab->lookup (name, 0, 0); | 951 symbol_record *sr = global_sym_tab->lookup (name, 0, 0); |
952 | 952 |
953 // It is a prorgramming error to look for builtins that aren't. | 953 // It is a prorgramming error to look for builtins that aren't. |
954 | 954 |
988 | 988 |
989 if (sr->is_variable ()) | 989 if (sr->is_variable ()) |
990 { | 990 { |
991 // Would be nice not to have this cast. XXX FIXME XXX | 991 // Would be nice not to have this cast. XXX FIXME XXX |
992 | 992 |
993 tree_constant *tmp = (tree_constant *) sr->def (); | 993 octave_value *tmp = (octave_value *) sr->def (); |
994 if (tmp) | 994 if (tmp) |
995 tmp = new tree_constant (*tmp); | 995 tmp = new octave_value (*tmp); |
996 else | 996 else |
997 tmp = new tree_constant (); | 997 tmp = new octave_value (); |
998 gsr->define (tmp); | 998 gsr->define (tmp); |
999 } | 999 } |
1000 else | 1000 else |
1001 sr->clear (); | 1001 sr->clear (); |
1002 | 1002 |
1003 // If the global symbol is currently defined as a function, we need | 1003 // If the global symbol is currently defined as a function, we need |
1004 // to hide it with a variable. | 1004 // to hide it with a variable. |
1005 | 1005 |
1006 if (gsr->is_function ()) | 1006 if (gsr->is_function ()) |
1007 gsr->define ((tree_constant *) 0); | 1007 gsr->define ((octave_value *) 0); |
1008 | 1008 |
1009 sr->alias (gsr, 1); | 1009 sr->alias (gsr, 1); |
1010 sr->mark_as_linked_to_global (); | 1010 sr->mark_as_linked_to_global (); |
1011 } | 1011 } |
1012 | 1012 |
1193 DEFUN_TEXT (document, args, , | 1193 DEFUN_TEXT (document, args, , |
1194 "document symbol string ...\n\ | 1194 "document symbol string ...\n\ |
1195 \n\ | 1195 \n\ |
1196 Associate a cryptic message with a variable name.") | 1196 Associate a cryptic message with a variable name.") |
1197 { | 1197 { |
1198 Octave_object retval; | 1198 octave_value_list retval; |
1199 | 1199 |
1200 int argc = args.length () + 1; | 1200 int argc = args.length () + 1; |
1201 | 1201 |
1202 string_vector argv = args.make_argv ("document"); | 1202 string_vector argv = args.make_argv ("document"); |
1203 | 1203 |
1228 } | 1228 } |
1229 | 1229 |
1230 // XXX FIXME XXX -- this should take a list of regular expressions | 1230 // XXX FIXME XXX -- this should take a list of regular expressions |
1231 // naming the variables to look for. | 1231 // naming the variables to look for. |
1232 | 1232 |
1233 static Octave_object | 1233 static octave_value_list |
1234 do_who (int argc, const string_vector& argv) | 1234 do_who (int argc, const string_vector& argv) |
1235 { | 1235 { |
1236 Octave_object retval; | 1236 octave_value_list retval; |
1237 | 1237 |
1238 int show_builtins = 0; | 1238 int show_builtins = 0; |
1239 int show_functions = (curr_sym_tab == top_level_sym_tab); | 1239 int show_functions = (curr_sym_tab == top_level_sym_tab); |
1240 int show_variables = 1; | 1240 int show_variables = 1; |
1241 int show_verbose = 0; | 1241 int show_verbose = 0; |
1336 "who [-all] [-builtins] [-functions] [-long] [-variables]\n\ | 1336 "who [-all] [-builtins] [-functions] [-long] [-variables]\n\ |
1337 \n\ | 1337 \n\ |
1338 List currently defined symbol(s). Options may be shortened to one\n\ | 1338 List currently defined symbol(s). Options may be shortened to one\n\ |
1339 character, but may not be combined.") | 1339 character, but may not be combined.") |
1340 { | 1340 { |
1341 Octave_object retval; | 1341 octave_value_list retval; |
1342 | 1342 |
1343 int argc = args.length () + 1; | 1343 int argc = args.length () + 1; |
1344 | 1344 |
1345 string_vector argv = args.make_argv ("who"); | 1345 string_vector argv = args.make_argv ("who"); |
1346 | 1346 |
1356 "whos [-all] [-builtins] [-functions] [-long] [-variables]\n\ | 1356 "whos [-all] [-builtins] [-functions] [-long] [-variables]\n\ |
1357 \n\ | 1357 \n\ |
1358 List currently defined symbol(s). Options may be shortened to one\n\ | 1358 List currently defined symbol(s). Options may be shortened to one\n\ |
1359 character, but may not be combined.") | 1359 character, but may not be combined.") |
1360 { | 1360 { |
1361 Octave_object retval; | 1361 octave_value_list retval; |
1362 | 1362 |
1363 int nargin = args.length (); | 1363 int nargin = args.length (); |
1364 | 1364 |
1365 Octave_object tmp_args; | 1365 octave_value_list tmp_args; |
1366 for (int i = nargin; i > 0; i--) | 1366 for (int i = nargin; i > 0; i--) |
1367 tmp_args(i) = args(i-1); | 1367 tmp_args(i) = args(i-1); |
1368 tmp_args(0) = "-long"; | 1368 tmp_args(0) = "-long"; |
1369 | 1369 |
1370 int argc = tmp_args.length () + 1; | 1370 int argc = tmp_args.length () + 1; |
1431 bind_builtin_variable (v.name, v.value, v.protect, v.eternal, | 1431 bind_builtin_variable (v.name, v.value, v.protect, v.eternal, |
1432 v.sv_function, v.help_string); | 1432 v.sv_function, v.help_string); |
1433 } | 1433 } |
1434 | 1434 |
1435 void | 1435 void |
1436 install_builtin_variable_as_function (const string& name, tree_constant *val, | 1436 install_builtin_variable_as_function (const string& name, octave_value *val, |
1437 int protect, int eternal, | 1437 int protect, int eternal, |
1438 const string& help) | 1438 const string& help) |
1439 { | 1439 { |
1440 symbol_record *sym_rec = global_sym_tab->lookup (name, 1); | 1440 symbol_record *sym_rec = global_sym_tab->lookup (name, 1); |
1441 sym_rec->unprotect (); | 1441 sym_rec->unprotect (); |
1474 | 1474 |
1475 #if 0 | 1475 #if 0 |
1476 void | 1476 void |
1477 bind_nargin_and_nargout (symbol_table *sym_tab, int nargin, int nargout) | 1477 bind_nargin_and_nargout (symbol_table *sym_tab, int nargin, int nargout) |
1478 { | 1478 { |
1479 tree_constant *tmp; | 1479 octave_value *tmp; |
1480 symbol_record *sr; | 1480 symbol_record *sr; |
1481 | 1481 |
1482 sr = sym_tab->lookup ("nargin", 1, 0); | 1482 sr = sym_tab->lookup ("nargin", 1, 0); |
1483 sr->unprotect (); | 1483 sr->unprotect (); |
1484 tmp = new tree_constant (nargin); | 1484 tmp = new octave_value (nargin); |
1485 sr->define (tmp); | 1485 sr->define (tmp); |
1486 | 1486 |
1487 sr = sym_tab->lookup ("nargout", 1, 0); | 1487 sr = sym_tab->lookup ("nargout", 1, 0); |
1488 sr->unprotect (); | 1488 sr->unprotect (); |
1489 tmp = new tree_constant (nargout); | 1489 tmp = new octave_value (nargout); |
1490 sr->define (tmp); | 1490 sr->define (tmp); |
1491 } | 1491 } |
1492 #endif | 1492 #endif |
1493 | 1493 |
1494 void | 1494 void |
1495 bind_ans (const tree_constant& val, int print) | 1495 bind_ans (const octave_value& val, int print) |
1496 { | 1496 { |
1497 static symbol_record *sr = global_sym_tab->lookup ("ans", 1, 0); | 1497 static symbol_record *sr = global_sym_tab->lookup ("ans", 1, 0); |
1498 | 1498 |
1499 tree_identifier *ans_id = new tree_identifier (sr); | 1499 tree_identifier *ans_id = new tree_identifier (sr); |
1500 tree_constant *tmp = new tree_constant (val); | 1500 octave_value *tmp = new octave_value (val); |
1501 | 1501 |
1502 // XXX FIXME XXX -- making ans_id static, passing its address to | 1502 // XXX FIXME XXX -- making ans_id static, passing its address to |
1503 // tree_simple_assignment_expression along with a flag to not delete | 1503 // tree_simple_assignment_expression along with a flag to not delete |
1504 // it seems to create a memory leak. Hmm. | 1504 // it seems to create a memory leak. Hmm. |
1505 | 1505 |
1538 | 1538 |
1539 // How is this different than install_builtin_variable? Are both | 1539 // How is this different than install_builtin_variable? Are both |
1540 // functions needed? | 1540 // functions needed? |
1541 | 1541 |
1542 void | 1542 void |
1543 bind_builtin_variable (const string& varname, tree_constant *val, | 1543 bind_builtin_variable (const string& varname, octave_value *val, |
1544 int protect, int eternal, sv_Function sv_fcn, | 1544 int protect, int eternal, sv_Function sv_fcn, |
1545 const string& help) | 1545 const string& help) |
1546 { | 1546 { |
1547 symbol_record *sr = global_sym_tab->lookup (varname, 1, 0); | 1547 symbol_record *sr = global_sym_tab->lookup (varname, 1, 0); |
1548 | 1548 |
1570 | 1570 |
1571 sr->document (help); | 1571 sr->document (help); |
1572 } | 1572 } |
1573 | 1573 |
1574 void | 1574 void |
1575 bind_builtin_variable (const string& varname, const tree_constant& val, | 1575 bind_builtin_variable (const string& varname, const octave_value& val, |
1576 int protect, int eternal, sv_Function sv_fcn, | 1576 int protect, int eternal, sv_Function sv_fcn, |
1577 const string& help) | 1577 const string& help) |
1578 { | 1578 { |
1579 tree_constant *tc = new tree_constant (val); | 1579 octave_value *tc = new octave_value (val); |
1580 bind_builtin_variable (varname, tc, protect, eternal, sv_fcn, help); | 1580 bind_builtin_variable (varname, tc, protect, eternal, sv_fcn, help); |
1581 } | 1581 } |
1582 | 1582 |
1583 // XXX FIXME XX -- these should probably be moved to where they | 1583 // XXX FIXME XX -- these should probably be moved to where they |
1584 // logically belong instead of being all grouped here. | 1584 // logically belong instead of being all grouped here. |
1897 If no arguments are given, clear all user-defined variables and | 1897 If no arguments are given, clear all user-defined variables and |
1898 functions.\n\ | 1898 functions.\n\ |
1899 \n\ | 1899 \n\ |
1900 With -x, exclude the named variables") | 1900 With -x, exclude the named variables") |
1901 { | 1901 { |
1902 Octave_object retval; | 1902 octave_value_list retval; |
1903 | 1903 |
1904 int argc = args.length () + 1; | 1904 int argc = args.length () + 1; |
1905 | 1905 |
1906 string_vector argv = args.make_argv ("clear"); | 1906 string_vector argv = args.make_argv ("clear"); |
1907 | 1907 |