rev 617 - in trunk: . pr/test src

SVN User <[email protected]> Sun, 13 Jun 2004 00:56:55 -0400
Newsgroups gmane.comp.lang.prothon.cvs
Message-ID <[email protected]>
Author: mark
Date: 2004-06-13 00:56:52 -0400 (Sun, 13 Jun 2004)
New Revision: 617

Modified:
   trunk/STATUS.txt
   trunk/pr/test/test.pr
   trunk/src/builtins-string.c
Log:
string.fmt() now defaults to scope vars

Modified: trunk/STATUS.txt
===================================================================
--- trunk/STATUS.txt	2004-06-13 04:19:55 UTC (rev 616)
+++ trunk/STATUS.txt	2004-06-13 04:56:52 UTC (rev 617)
@@ -1,9 +1,6 @@
 
 ----------------------- TO-DO (highest priority first) ------------------------
 
---- add vars_ default for str.fmt()
---- support list and dictionary object params in string.fmt() ???
-
 --- add \u0000 \U00000000 and \N{name} esc sequences
 
 --- unicode module - codecs
@@ -33,6 +30,8 @@
 
 --- replace <NULL>, <objptr:1>, and <objptr:2> with noDefault_, argList_, and kwDict_ 
 
+--- support list and dictionary object params directly in string.fmt() ???
+
 --- add resolution order combining prototypes and scope chains
 
 --- Add properties methods: get_,  set_, delete_

Modified: trunk/pr/test/test.pr
===================================================================
--- trunk/pr/test/test.pr	2004-06-13 04:19:55 UTC (rev 616)
+++ trunk/pr/test/test.pr	2004-06-13 04:56:52 UTC (rev 617)
@@ -1,27 +1,10 @@
 #!/usr/bin/env prothon
 
-def test(n, evalstr, exp):
-	exec 'res = ' + evalstr
-	if res != exp:
-		print "test", n, 'failed'
-		print 'evaluating:', evalstr
-		print 'expected:  ', exp
-		print 'found:     ', res
-		sys.exit(1)
+x = 123
 
-test(1, '"{0}".fmt(12.34)', '12.34')
-test(2, '"{0}".fmt(-12.34)', '-12.34')
-test(3, '"{0:3.4}".fmt(12.34)', '12.3400')
-test(4, '"{0:3.4f}".fmt(-127.6876)', '-127.6876')
-test(5, '"{0:3.2}".fmt(-127.6876)', '-127.69')
-test(6, '"{0:10.2}".fmt(-127.6876)', '   -127.69')
-test(7, '"{0:-10.2}".fmt(-127.6876)', '-127.69   ')
-test(8, '"{0:-010.2}".fmt(-127.6876)', '-127.69000')
-test(9, '"{0:010.2}".fmt(-127.6876)', '-000127.69')
-test(10, '"{0:10}".fmt(-127.6876)', '-127.687600')
-test(11, '"{0:i}".fmt(-127.6876)', '-128')
-test(12, '"{0:#x}".fmt(-127.6876)', '-0x80')
+print "{x}".fmt()	# 123
 
-print """
-all tests passed
-"""
\ No newline at end of file
+print "{x} {0} {y}".fmt("abc", y=1.23) # 123 abc 1.23
+
+print "{x} {0} {y}".fmt("abc", y=1.23, x='xyz') # xyz abc 1.23
+

Modified: trunk/src/builtins-string.c
===================================================================
--- trunk/src/builtins-string.c	2004-06-13 04:19:55 UTC (rev 616)
+++ trunk/src/builtins-string.c	2004-06-13 04:56:52 UTC (rev 617)
@@ -63,6 +63,7 @@
 #include "dict.h"
 #include "parser.h"
 #include "object.h"
+#include "interp.h"
 #include <prothon/prothon_dll.h>
 
 #include "pr_snprintf.h"
@@ -687,8 +688,11 @@
 			return NULL;
 		}
 		value = list_item(ist, list, (int) index);
-	} else
+	} else {
 		value = dict_item(ist, dict, NEW_STRING(var));
+		if (!value)
+			value = get_scope_attr(ist, ist->frame->locals, sym(ist, var), NULL, NULL);
+	}
 	if_exc_return NULL;
 	if (!value) {
 		raise_exception(ist, OBJ(VALUE_EXC), "no match in dictionary for fmt spec variable \"%s\"", var);