rev 580 - in trunk: . pr/test src
SVN User <[email protected]> Sat, 05 Jun 2004 01:53:12 -0400
| Newsgroups | gmane.comp.lang.prothon.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: mark
Date: 2004-06-05 01:53:09 -0400 (Sat, 05 Jun 2004)
New Revision: 580
Modified:
trunk/STATUS.txt
trunk/pr/test/dict.pr
trunk/pr/test/test.pr
trunk/src/builtins-dict.c
trunk/src/builtins-int.c
trunk/src/builtins-string.c
trunk/src/interp.c
trunk/src/object.h
trunk/src/prothon.y
Log:
fixed a lot of bugs, all pr tests work now except mi2.pr
Modified: trunk/STATUS.txt
===================================================================
--- trunk/STATUS.txt 2004-06-05 01:50:45 UTC (rev 579)
+++ trunk/STATUS.txt 2004-06-05 05:53:09 UTC (rev 580)
@@ -1,7 +1,7 @@
----------------------- TO-DO (highest priority first) ------------------------
---- fix bug to restart gen after exception (data.ptr == 0)
+--- add names to str.mod_, fix int display in str.mod_
--- put in skeleton code for + _"abc"
--- GNU message catalog _"abc" strings
@@ -17,10 +17,12 @@
--- Strings -> 24-bit ords
--- resolve binary vs. strings vs. unicode----- code in binary string (all binary data in binary string?)
------ new integrated binary obj_malloc?
+--- new integrated binary obj_malloc?
--- import (string variable)
+--- support long ints in prosist
+
--- Swig and/or other (what GTK port used?) backend
--- Traceback objects (stack trace of an exception), exceptions should show function names
Modified: trunk/pr/test/dict.pr
===================================================================
--- trunk/pr/test/dict.pr 2004-06-05 01:50:45 UTC (rev 579)
+++ trunk/pr/test/dict.pr 2004-06-05 05:53:09 UTC (rev 580)
@@ -2,35 +2,44 @@
# dict.pr
+def err(str):
+ print str
+ Sys.exit(1)
+
d = {1:2}
-if d.keys() != [1] : print 'error in keys'
-if d.values() != [2] : print 'error in values'
-if d.get(1) != 2 : print 'error1 in get'
-if d.get(2) != None : print 'error2 in get'
-if d.get(3,4) != 4 : print 'error3 in get'
-if d.get(3,5) != 5 : print 'error4 in get'
-if d.setDefault!(3,4) != 4 : print 'error5 in setdefault'
-if d.get(3,5) != 4 : print 'error6 in get'
-if 3 not in d: print 'error 7 in notin'
+if d.keys() != [1] : err( 'error in keys' )
+if d.values() != [2] : err( 'error in values' )
+if d.get(1) != 2 : err( 'error1 in get' )
+if d.get(2) != None : err( 'error2 in get' )
+if d.get(3,4) != 4 : err( 'error3 in get' )
+if d.get(3,5) != 5 : err( 'error4 in get' )
+if d.setDefault!(3,4) != 4 : err( 'error5 in setdefault' )
+if d.get(3,5) != 4 : err( 'error6 in get' )
+if 3 not in d: err( 'error 7 in not in' )
d = {1:2, 3:4}
e = d.copy()
if d.items() != e.items():
- print 'error1'
-
+ err( 'error1' )
+
if Len(e.items()) != 2:
- print 'error2'
+ err( 'error2' )
d.clear!()
d = {1:2}
d.update!({3:4})
if d.items() != e.items():
- print d.items(), e.items(), 'error3'
+ err( 'error3' )
-if not e.hasKey?(1) or e.hasKey?(2): print 'error4'
+if not e.hasKey?(1) or e.hasKey?(2): err( 'error4' )
+dd = Dict(a=1)
+
+if `a not in dd: err( 'error5' )
+if "a" not in dd: err( 'error6' )
+
print 'all tests passed'
print """
Modified: trunk/pr/test/test.pr
===================================================================
--- trunk/pr/test/test.pr 2004-06-05 01:50:45 UTC (rev 579)
+++ trunk/pr/test/test.pr 2004-06-05 05:53:09 UTC (rev 580)
@@ -1,16 +1,53 @@
#!/usr/bin/env prothon
-def hex(n):
- s = ""
- while n:
- d = n & 0xf
- n = n >> 4
- if d < 10: s = ('0'.ord()+d).chr() + s
- else: s = ('a'.ord()+d-10).chr() + s
- return s
-
-print hex(0x100)
-
-n=0x0123456789abcdef
+def refer(start, attrname):
+ mro = self.protoChain()
+ n = mro.len()
+ i = 0
+ while i < n:
+ if mro[i] is start:
+ break
+ i += 1
+ if i == n:
+ raise AttributeError
+ while True:
+ i += 1
+ if i == n:
+ break
+ o = mro[i]
+ attrs = o.attrs_
+ if attrname in attrs:
+ a = attrs[attrname]
+ if a.hasProto?(Func):
+ return a
+ return a
+ raise AttributeError
-print hex(n & 0x0f0f0f0f0f0f0f0f)
+object ModInt(Int):
+ modulo = 10
+ def call_(i=0):
+ call = refer(ModInt, 'call_')
+ return call{self}(i % self.modulo)
+
+ def add_(other):
+ if self.modulo != other.modulo:
+ raise TypeError
+ proto = self.protoChain()[1]
+ add = refer(ModInt, 'add_')
+ x = proto(add{self}(other))
+ return x
+
+object Mod8Int(ModInt):
+ modulo = 8
+
+m = Mod8Int(0)
+n = Mod8Int(1)
+for i in 100:
+ if m != i % 8:
+ print "test failed:",i
+ Sys.exit(1)
+ m = m + n
+
+print """
+All tests passed
+"""
Modified: trunk/src/builtins-dict.c
===================================================================
--- trunk/src/builtins-dict.c 2004-06-05 01:50:45 UTC (rev 579)
+++ trunk/src/builtins-dict.c 2004-06-05 05:53:09 UTC (rev 580)
@@ -179,12 +179,14 @@
i32_t i, hash_in;
obj_p key, res, rp[2];
dict_p dict, dp;
-
+ int new_sym = FALSE;
+try_again:
rp[0]=0; rp[1]=key_in;
rdlock_rtrn(dict_obj) NULL;
hash_in = hash_value(ist, key_in);
if (ist->exception_obj) {
read_unlock(ist, dict_obj);
+ if (new_sym) del_unlock(key_in);
return NULL;
}
if (!hash_in) hash_in++;
@@ -195,11 +197,21 @@
dict_rd_chk();
res = dp->entry.value;
read_unlock(ist, dict_obj);
+ if (new_sym) del_unlock(key_in);
return res;
}
dict_rd_chk();
}
read_unlock(ist, dict_obj);
+ if (has_proto(ist, key_in, OBJ(STRING_PROTO))) {
+ key_in = sym(ist, pr_strptr(key_in));
+ if (!ist->exception_obj) {
+ new_sym = TRUE;
+ goto try_again;
+ }
+ ist->exception_obj = NULL;
+ }
+ if (new_sym) del_unlock(key_in);
return NULL;
}
Modified: trunk/src/builtins-int.c
===================================================================
--- trunk/src/builtins-int.c 2004-06-05 01:50:45 UTC (rev 579)
+++ trunk/src/builtins-int.c 2004-06-05 05:53:09 UTC (rev 580)
@@ -112,7 +112,7 @@
static long_p mul1(long_p, wdigit);
static long_p muladd1(long_p, wdigit, wdigit);
static long_p divrem1(long_p, digit, digit *);
-static obj_p long_format(long_p aa, int base, int addL);
+obj_p long_format(long_p aa, int base, int addL);
/* Long integer representation.
The absolute value of a number is equal to
@@ -530,7 +530,7 @@
/* Convert a long int object to a string, using a given conversion base.
Return a string object.
If base is 8 or 16, add the proper prefix '0' or '0x'. */
-static obj_p long_format(long_p aa, int base, int addL) {
+obj_p long_format(long_p aa, int base, int addL) {
register long_p a = (long_p) aa;
obj_p str;
int i;
@@ -1706,10 +1706,10 @@
pr_free(temp);
temp = mod;
}
- //pr_free(a);
+// pr_free(a);
a = temp;
if (a == NULL) {
- //pr_free(z);
+// pr_free(z);
z = NULL;
break;
}
@@ -1719,7 +1719,7 @@
}
if (c && z!=NULL) {
if (l_divmod(z, (long_p)c, &div, &mod) < 0) {
- //pr_free(z);
+// pr_free(z);
z = NULL;
}
else {
@@ -1956,9 +1956,6 @@
case '^': z->digit[i] = diga ^ digb; break;
}
}
-
- pr_free(a);
- pr_free(b);
z = long_normalize(z);
if (negz == 0)
return (long_p) z;
@@ -2082,10 +2079,19 @@
DEF(Int, init_, FORM_STAR_PARAM) {
obj_p i = NULL;
+ int llen = (int) list_len(ist, parms[1]);
BIN_EMPTY_CHK();
- if (list_len(ist, parms[1]))
+ if (llen == 1) {
INT____PARAM(0, i);
- CHECK_TYPE_EXC(i, OBJ(INT_PROTO), integer);
+ } else if (llen > 1) {
+ raise_exception(ist, OBJ(TYPE_EXC), "incorrect number of parameters");
+ return NULL;
+ } else {
+ SET_TYPE_IF_EXC(Int_OBJ, self, DATA_TYPE_IMMDATA) return NULL;
+ self->imm_data_len = 8;
+ self->data.i64 = 0;
+ return OBJ(NONE);
+ }
if (i->data_type == DATA_TYPE_IMMDATA) {
SET_TYPE_IF_EXC(Int_OBJ, self, DATA_TYPE_IMMDATA) return NULL;
self->imm_data_len = 8;
@@ -2566,7 +2572,7 @@
DEF(Int, chr, NULL) {
char s[1];
BIN_CONTENT_CHK(Int);
- s[0] = (char) int_imm_value(self);
+ s[0] = (char) int2i32t(ist, self);
return NEW_STRINGN(s, 1);
}
Modified: trunk/src/builtins-string.c
===================================================================
--- trunk/src/builtins-string.c 2004-06-05 01:50:45 UTC (rev 579)
+++ trunk/src/builtins-string.c 2004-06-05 05:53:09 UTC (rev 580)
@@ -208,17 +208,37 @@
DEF(String, init_, FORM_STAR_PARAM) {
char *s;
+ obj_p res = NULL;
+ int llen;
BIN_EMPTY_CHK();
- if (!list_len(ist, parms[1]))
- s = "";
- else {
- obj_p obj = list_item(ist, parms[1], 0);
- if (has_proto(ist, obj, OBJ(SYMBOL_PROTO)))
+ llen = (int) list_len(ist, parms[1]);
+ if (llen > 2) {
+ raise_exception(ist, OBJ(TYPE_EXC), "incorrect number of parameters");
+ return NULL;
+ }
+ if (llen > 0) {
+ obj_p obj2, obj = list_item(ist, parms[1], 0);
+ if (llen == 1 && has_proto(ist, obj, OBJ(SYMBOL_PROTO))) {
s = symch(ist, obj);
- else
+ } else if ( llen == 2 && has_proto(ist, obj, OBJ(INT_PROTO)) &&
+ has_proto(ist, obj2 = list_item(ist, parms[1], 1), OBJ(INT_PROTO)) ) {
+ if (obj->data_type == DATA_TYPE_IMMDATA) {
+ res = long_format(new_longp(obj->data.i64), int2i32t(ist, obj2), FALSE);
+ s = pr_strptr(res);
+ } else {
+ res = long_format(obj->data.ptr, int2i32t(ist, obj2), FALSE);
+ s = pr_strptr(res);
+ }
+ } else if (llen == 1) {
s = as_str(ist, obj);
- }
+ } else {
+ raise_exception(ist, OBJ(TYPE_EXC), "invalid parameters");
+ return NULL;
+ }
+ } else
+ s = "";
set_string_data(ist, self, s, strlen(s));
+ if (res) del_unlock(res);
return OBJ(NONE);
}
Modified: trunk/src/interp.c
===================================================================
--- trunk/src/interp.c 2004-06-05 01:50:45 UTC (rev 579)
+++ trunk/src/interp.c 2004-06-05 05:53:09 UTC (rev 580)
@@ -1310,6 +1310,7 @@
fr_stack[fr_sp], fr_data(1), NULL, "with" );
switch_frame->prev_frame = frame;
frame->next_frame = switch_frame;
+ fr_push(OBJ(NONE));
end_op_obj: break;
case OP_CALL: {
obj_p name_obj;
Modified: trunk/src/object.h
===================================================================
--- trunk/src/object.h 2004-06-05 01:50:45 UTC (rev 579)
+++ trunk/src/object.h 2004-06-05 05:53:09 UTC (rev 580)
@@ -145,6 +145,8 @@
obj_p new_int_obj(isp ist, i64_t num);
obj_p new_int_long_obj(isp ist, long_p longp);
long_p PyLong_FromString(char *str, char **pend, int base);
+obj_p long_format(long_p aa, int base, int addL);\
+long_p new_longp(i64_t ival);
int int_is_zero(obj_p obj);
void dict2attrs(isp ist, obj_p dict, obj_p obj);
Modified: trunk/src/prothon.y
===================================================================
--- trunk/src/prothon.y 2004-06-05 01:50:45 UTC (rev 579)
+++ trunk/src/prothon.y 2004-06-05 05:53:09 UTC (rev 580)
@@ -1207,48 +1207,34 @@
ungetch(c, state);
c = '.';
}
- if (hex_flag || int_dot_flag || (c != '.' && c != 'e' && c != 'E')){
- char* p;
- if (imag_flag)
- str_index--;
- else
- ungetch(c, state);
- str_ptr[str_index++]=0;
- if (str_ptr[0] == '0') {
- if (hex_flag){
- u64_t val = 0;
- for (p=str_ptr+2; *p; p++) {
- if (*p >= '0' && *p <= '9')
- val = val * 16 + *p - '0';
- else if (*p >= 'a' && *p <= 'f')
- val = val * 16 + *p - 'a' + 10;
- else if (*p >= 'A' && *p <= 'F')
- val = val * 16 + *p - 'A' + 10;
- }
- lvalp->int_type = new_int_obj((((parse_state*) yylex_param)->ist), val);
- } else {
- u64_t val = 0;
- for (p=str_ptr+1; *p; p++) {
- val = val * 8 + *p - '0';
- }
- lvalp->int_type = new_int_obj((((parse_state*) yylex_param)->ist), val);
- }
- } else {
- if (strlen(str_ptr) < 16)
- lvalp->int_type = new_int_obj((((parse_state*) yylex_param)->ist), apr_atoi64(str_ptr));
- else
- lvalp->int_type = new_int_long_obj( (((parse_state*) yylex_param)->ist),
- PyLong_FromString(str_ptr, NULL, 10) );
- }
- if (nonzero_flag && int_is_zero(lvalp->int_type)){
- printf("Lexical error: invalid integer number format\n");
- return ERR;
- }
- if (imag_flag)
- return INT_IMAG;
- else
- return INT_;
- }
+ if (hex_flag || int_dot_flag || (c != '.' && c != 'e' && c != 'E')){
+ if (imag_flag)
+ str_index--;
+ else
+ ungetch(c, state);
+ str_ptr[str_index++] = 0;
+ if (hex_flag) {
+ lvalp->int_type = new_int_long_obj( (((parse_state*) yylex_param)->ist),
+ PyLong_FromString(str_ptr+2, NULL, 16) );
+ } else if (str_ptr[0] == '0' && strlen(str_ptr) > 2) {
+ lvalp->int_type = new_int_long_obj( (((parse_state*) yylex_param)->ist),
+ PyLong_FromString(str_ptr+1, NULL, 8) );
+ } else {
+ if (strlen(str_ptr) < 16)
+ lvalp->int_type = new_int_obj((((parse_state*) yylex_param)->ist), apr_atoi64(str_ptr));
+ else
+ lvalp->int_type = new_int_long_obj( (((parse_state*) yylex_param)->ist),
+ PyLong_FromString(str_ptr, NULL, 10) );
+ }
+ if (nonzero_flag && int_is_zero(lvalp->int_type)){
+ printf("Lexical error: invalid integer number format\n");
+ return ERR;
+ }
+ if (imag_flag)
+ return INT_IMAG;
+ else
+ return INT_;
+ }
}
if (imag_flag)
str_index--;