rev 647 - in trunk: . include/prothon modules/Re pr/test src
SVN User <[email protected]> Sun, 20 Jun 2004 03:28:53 -0400
| Newsgroups | gmane.comp.lang.prothon.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: mark
Date: 2004-06-20 03:28:50 -0400 (Sun, 20 Jun 2004)
New Revision: 647
Modified:
trunk/STATUS.txt
trunk/include/prothon/prothon.h
trunk/modules/Re/Re.c
trunk/pr/test/test.pr
trunk/src/builtins-attrdict.c
trunk/src/builtins-bytes.c
trunk/src/builtins-core.c
trunk/src/builtins-dict.c
trunk/src/builtins-file.c
trunk/src/builtins-list.c
trunk/src/builtins-string.c
trunk/src/bytecodes.h
trunk/src/interp.c
trunk/src/main.c
trunk/src/memory_mgr.c
trunk/src/object.c
trunk/src/parser_routines.c
trunk/src/prothon.y
Log:
replaced param flag values with unique objects
Modified: trunk/STATUS.txt
===================================================================
--- trunk/STATUS.txt 2004-06-20 01:07:28 UTC (rev 646)
+++ trunk/STATUS.txt 2004-06-20 07:28:50 UTC (rev 647)
@@ -45,8 +45,6 @@
--- getAttr(name), setAttr(name, value), delAttr(name)
--- add conditional expression "if C then x else y"
---- 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
@@ -90,7 +88,7 @@
--- Does simple 1+2 expr evaluation create objects? If so, need shortcuts to speed it up
---- move PARAM_STAR and PARAM_STAR_STAR to right side of pair
+--- move OBJ(PARAM_STAR) and OBJ(PARAM_STAR_STAR) to right side of pair
--- clean up prt_code_line mess with some cleaner coding technique
Modified: trunk/include/prothon/prothon.h
===================================================================
--- trunk/include/prothon/prothon.h 2004-06-20 01:07:28 UTC (rev 646)
+++ trunk/include/prothon/prothon.h 2004-06-20 07:28:50 UTC (rev 647)
@@ -299,28 +299,33 @@
PR_TRUE, // 1 True
OBJECT, // 2 Object
NONE, // 3 None
-
+
+ NOKEY, //
+ PARAM_STAR, //
+ PARAM_STAR_STAR, //
+ NODEF, //
+
// prototype objects used as protos for basic "types"
- INT_PROTO, // 4 Int
- FLOAT_PROTO, // 5 Float
- IMAG_PROTO, // 6 Imaginary
- SYMBOL_PROTO, // 7 Symbol
- DATETIME_PROTO, // 8 Time
- SEQ_PROTO, // 9 Sequence
- BYTES_PROTO, // 10 Bytes
- STRING_PROTO, // 11 String
- TUPLE_PROTO, // 12 Tuple
- LIST_PROTO, // 13 List
- DICT_PROTO, // 14 Dict
- FUNC_PROTO, // 15 Func
- METHOD_PROTO, // 16 Method
- HASH_PROTO, // 17 Hash
- SLICE_PROTO, // 18 Slice
- LOCAL_PROTO, // 19
- OUTER_PROTO, // 20
- SUPER_PROTO, // 21
- GEN_PROTO, // 22
- ITER_PROTO, // 23
+ INT_PROTO, // Int
+ FLOAT_PROTO, // Float
+ IMAG_PROTO, // Imaginary
+ SYMBOL_PROTO, // Symbol
+ DATETIME_PROTO, // Time
+ SEQ_PROTO, // Sequence
+ BYTES_PROTO, // Bytes
+ STRING_PROTO, // String
+ TUPLE_PROTO, // Tuple
+ LIST_PROTO, // List
+ DICT_PROTO, // Dict
+ FUNC_PROTO, // Func
+ METHOD_PROTO, // Method
+ HASH_PROTO, // Hash
+ SLICE_PROTO, // Slice
+ LOCAL_PROTO, //
+ OUTER_PROTO, //
+ SUPER_PROTO, //
+ GEN_PROTO, //
+ ITER_PROTO, //
THREAD_PROTO, // Thread
MUTEX_PROTO, // Mutex
@@ -930,25 +935,21 @@
// value object that corresponds to that label. Note that a param value in the
// param array might actually be a list or dictionary of many parameters if the
// *list or **dictionary type formal parameters were used in new_C_func_obj.
-// In this case the symbol object ptr for the label will be PARAM_STAR or PARAM_STAR_STAR.
+// In this case the symbol object ptr for the label will be OBJ(PARAM_STAR) or OBJ(PARAM_STAR_STAR).
// Dyn-locals (dynamic locals) are the locals of the calling function. This allows
// you to access vars in the same manner that the @ operator does in Prothon.
// The function must always return an object-id (OBJ(NONE) if nothing else).
typedef obj_p (pr_func)( isp ist, obj_p self,
int parm_cnt, obj_p* lbl_parm_arr, obj_p dyn_locals );
-#define PARAM_NORMAL ((obj_p)0)
-#define PARAM_STAR ((obj_p)1)
-#define PARAM_STAR_STAR ((obj_p)2)
-
// NEW_FUNC_OBJ: Create a new function object from a C function and formal parameters
// Func_ptr should point to a function of the type defined above.
// The formal parameters must be defined by the label_def_list which holds the parameter
// labels and default values (in even and odd positions) and optionally the *list and
-// **dictionary args which are supported by putting PARAM_STAR or PARAM_STAR_STAR in
+// **dictionary args which are supported by putting OBJ(PARAM_STAR) or OBJ(PARAM_STAR_STAR) in
// the label (even) position and the list or dict symbol in the default (odd) position.
// example: in "def func(x, y="3", *z)", the label_def_list would be:
-// list6(ist,NULL, sym(ist, "x"), NULL, sym(ist, "y"), NEW_STRING("3"), PARAM_STAR, sym(ist, "z"));
+// list6(ist,NULL, sym(ist, "x"), NULL, sym(ist, "y"), NEW_STRING("3"), OBJ(PARAM_STAR), sym(ist, "z"));
// If the formal param list is empty, you can put NULL instead of the list.
obj_p new_C_func_obj(isp ist, pr_func* func_ptr, obj_p label_def_list);
@@ -1078,18 +1079,18 @@
// "b" is the rparam. The "rparam" label doesn't really matter since the
// call is made positionally.
// see Int.c for example of usage
-#define FORM_RPARAM (list2(ist, SYM(RPARAM),NULL))
+#define FORM_RPARAM (list2(ist, SYM(RPARAM), OBJ(NODEF)))
// FORM_PARAM2: same for 2 right params
// example: cmp(a,b)
-#define FORM_PARAM2 (list4(ist, SYM(PARAM1), NULL, SYM(PARAM2), NULL))
+#define FORM_PARAM2 (list4(ist, SYM(PARAM1), OBJ(NODEF), SYM(PARAM2), OBJ(NODEF)))
// FORM_STARn_PARAM: convenience macros for variable number of formal right parameters
// equivalent to func(*args), func(**kwargs), and func(*args, **kwargs)
-#define FORM_STAR_PARAM (list2(ist, PARAM_STAR, SYM(ARGS)))
-#define FORM_STAR2_PARAM (list2(ist, PARAM_STAR_STAR, SYM(KWARGS)))
-#define FORM_STAR3_PARAM (list4(ist, PARAM_STAR, SYM(ARGS), \
- PARAM_STAR_STAR, SYM(KWARGS) ))
+#define FORM_STAR_PARAM (list2(ist, OBJ(PARAM_STAR), SYM(ARGS)))
+#define FORM_STAR2_PARAM (list2(ist, OBJ(PARAM_STAR_STAR), SYM(KWARGS)))
+#define FORM_STAR3_PARAM (list4(ist, OBJ(PARAM_STAR), SYM(ARGS), \
+ OBJ(PARAM_STAR_STAR), SYM(KWARGS) ))
// CALL_FUNC: Call a function, either Prothon or C based
// This C function provides a way to call any Prothon or C function from C.
@@ -1097,7 +1098,7 @@
// found in that attr is called with the actual parameters in the lbl_val_arr array.
// The lbl_val_arr array holds the actual parameter labels and values (in even and
// odd positions) and optionally the *list and **dictionary args which are supported by
-// putting PARAM_STAR or PARAM_STAR_STAR in the label (even) position and the list or
+// putting OBJ(PARAM_STAR) or OBJ(PARAM_STAR_STAR) in the label (even) position and the list or
// dictionary object in the value (odd) position. parm_cnt is the length of the array,
// (2 times the number of actual parameters).
// When super_obj is set, the search for the function starts after the object super_obj
Modified: trunk/modules/Re/Re.c
===================================================================
--- trunk/modules/Re/Re.c 2004-06-20 01:07:28 UTC (rev 646)
+++ trunk/modules/Re/Re.c 2004-06-20 07:28:50 UTC (rev 647)
@@ -406,7 +406,7 @@
set_attr(ist, match_obj, sym(ist, "string"), parms[3]);
lastindex_obj = NEW_INT(last_index);
set_attr(ist, match_obj, sym(ist, "lastindex"), lastindex_obj);
- arr[0] = 0; arr[1] = match_obj;
+ arr[0] = OBJ(NOKEY); arr[1] = match_obj;
if (!repl_is_func)
repl = pr2c_strptr(ist, parms[1]);
m = pr_malloc((ngrps+1)*sizeof(regmatch_t));
@@ -577,7 +577,7 @@
}
DEF( reMatch, group, list4(ist, sym(ist, "groupid"), OBJ(ZERO_INT),
- PARAM_STAR, sym(ist, "groupids") ) ) {
+ OBJ(PARAM_STAR), sym(ist, "groupids") ) ) {
int i, j, llen, ngrps = ((int)list_len(ist, self))/2, sp, ep;
char* orig_s;
obj_p orig_s_obj, res;
Modified: trunk/pr/test/test.pr
===================================================================
--- trunk/pr/test/test.pr 2004-06-20 01:07:28 UTC (rev 646)
+++ trunk/pr/test/test.pr 2004-06-20 07:28:50 UTC (rev 647)
@@ -1,3 +1,3 @@
#!/usr/bin/env prothon
-print DateTime(1000000000000000000)
+print DateTime(100000000000000000)
Modified: trunk/src/builtins-attrdict.c
===================================================================
--- trunk/src/builtins-attrdict.c 2004-06-20 01:07:28 UTC (rev 646)
+++ trunk/src/builtins-attrdict.c 2004-06-20 07:28:50 UTC (rev 647)
@@ -91,9 +91,10 @@
alen = attr_alen(attrp);
dict_obj = NEW_DICT((int)alen);
for (i=0; i < (int) asize; i++) {
- if (attr_ap(attrp,i)->attr.key > 0)
- dict_add( ist, dict_obj, key_to_sym(ist, attr_ap(attrp,i)->attr.key),
- attr_ap(attrp,i)->attr.value );
+ if (attr_ap(attrp,i)->attr.key > 0) {
+ obj_p sym = key_to_sym(ist, attr_ap(attrp,i)->attr.key); if_exc_return NULL;
+ dict_add( ist, dict_obj, sym, attr_ap(attrp,i)->attr.value );
+ }
}
read_unlock(ist, self);
return dict_obj;
@@ -155,21 +156,22 @@
DEF(AttrDict, str_, NULL) {
obj_p res, dict;
BIN_STR_CHK(AttrDict);
- res = call_func0(ist, dict = attr2dict(ist, self->data.ptr), SYM(STR_));
+ dict = attr2dict(ist, self->data.ptr); if_exc_return NULL;
+ res = call_func0(ist, dict, SYM(STR_));
del_unlock(dict);
return res;
}
-DEF(AttrDict, hasKey_QUES, FPARM1(k, NULL)) {
+DEF(AttrDict, hasKey_QUES, FPARM1(k, OBJ(NODEF))) {
obj_p res, dict;
BIN_CONTENT_CHK(AttrDict);
- res = call_func1( ist, dict = attr2dict(ist, self->data.ptr),
- sym(ist, "hasKey_QUES"), parms[1] );
+ dict = attr2dict(ist, self->data.ptr); if_exc_return NULL;
+ res = call_func1( ist, dict, sym(ist, "hasKey_QUES"), parms[1] );
del_unlock(dict);
return res;
}
-DEF(AttrDict, get, FPARM2(k, NULL, x, OBJ(NONE))) {
+DEF(AttrDict, get, FPARM2(k, OBJ(NODEF), x, OBJ(NONE))) {
obj_p res, dict;
BIN_CONTENT_CHK(AttrDict);
res = call_func2( ist, dict = attr2dict(ist, self->data.ptr),
Modified: trunk/src/builtins-bytes.c
===================================================================
--- trunk/src/builtins-bytes.c 2004-06-20 01:07:28 UTC (rev 646)
+++ trunk/src/builtins-bytes.c 2004-06-20 07:28:50 UTC (rev 647)
@@ -128,7 +128,7 @@
Bytes_OBJ->imm_data_len = 0;
}
-DEF(Bytes, init_, FPARM2(value, NULL, encoding, NEW_STRING("ASCII"))) {
+DEF(Bytes, init_, FPARM2(value, OBJ(NODEF), encoding, NEW_STRING("ASCII"))) {
obj_p res = NULL;
size_t len;
byt_p obj_byt;
Modified: trunk/src/builtins-core.c
===================================================================
--- trunk/src/builtins-core.c 2004-06-20 01:07:28 UTC (rev 646)
+++ trunk/src/builtins-core.c 2004-06-20 07:28:50 UTC (rev 647)
@@ -77,6 +77,11 @@
MODULE_DECLARE(Func);
MODULE_DECLARE(Method);
MODULE_DECLARE(RangeGen);
+MODULE_DECLARE(UniqueObjects);
+MODULE_DECLARE(NoKey);
+MODULE_DECLARE(NoDef);
+MODULE_DECLARE(Star);
+MODULE_DECLARE(StarStar);
// ***************************** Object *********************************
@@ -103,7 +108,7 @@
DEF(Object, call_, FORM_STAR3_PARAM) {
obj_p new_obj, init_obj;
- parms[0] = PARAM_STAR; parms[2] = PARAM_STAR_STAR;
+ parms[0] = OBJ(PARAM_STAR); parms[2] = OBJ(PARAM_STAR_STAR);
new_obj = new_object(ist, self);
init_obj = call_func(ist, new_obj, SYM(INIT_), 4, parms, NULL); if_exc_return NULL;
if (init_obj == OBJ(NONE)) return new_obj;
@@ -889,6 +894,30 @@
return self;
}
+// ***************************** UNIQUEOBJECTS ********************************
+MODULE_START(UniqueObjects)
+{
+ UniqueObjects_OBJ = NEW_OBJ(NULL);
+ NoKey_OBJ = OBJ(NOKEY);
+ NoDef_OBJ = OBJ(NODEF);
+ Star_OBJ = OBJ(PARAM_STAR);
+ StarStar_OBJ = OBJ(PARAM_STAR_STAR);
+
+ MODULE_ADD_TO_OBJ(NoKey, OBJ(OBJECT), "NoKey_");
+ set_obj_id(NoKey_OBJ, *, NoKey_);
+ MODULE_ADD_TO_OBJ(NoDef, OBJ(OBJECT), "NoDefVal_");
+ set_obj_id(NoDef_OBJ, *, NoDefVal_);
+ MODULE_ADD_TO_OBJ(Star, OBJ(OBJECT), "Star_");
+ set_obj_id(Star_OBJ, *, Star_);
+ MODULE_ADD_TO_OBJ(StarStar, OBJ(OBJECT), "StarStar_");
+ set_obj_id(StarStar_OBJ, *, StarStar_);
+}
+
+DEF(NoKey, str_, NULL) { return NEW_STRING("NoKey_"); }
+DEF(NoDef, str_, NULL) { return NEW_STRING("NoDefVal_"); }
+DEF(Star, str_, NULL) { return NEW_STRING("Star_"); }
+DEF(StarStar, str_, NULL) { return NEW_STRING("StarStar_"); }
+
// ***************************** MAIN_MODULE_INIT *****************************
MAIN_MODULE_INIT(Core)
@@ -986,5 +1015,11 @@
MODULE_ADD_SYM(RangeGen, iter_);
MODULE_ADD_SYM(RangeGen, next);
+ MODULE_SUB_INIT(UniqueObjects);
+ MODULE_ADD_SYM(NoKey, str_);
+ MODULE_ADD_SYM(NoDef, str_);
+ MODULE_ADD_SYM(Star, str_);
+ MODULE_ADD_SYM(StarStar, str_);
+
check_exceptions(ist);
-}
+}
Modified: trunk/src/builtins-dict.c
===================================================================
--- trunk/src/builtins-dict.c 2004-06-20 01:07:28 UTC (rev 646)
+++ trunk/src/builtins-dict.c 2004-06-20 07:28:50 UTC (rev 647)
@@ -185,7 +185,7 @@
dict_p dict, dp;
int new_sym = FALSE;
try_again:
- rp[0]=0; rp[1]=key_in;
+ rp[0]=OBJ(NOKEY); rp[1]=key_in;
rdlock_rtrn(dict_obj) NULL;
hash_in = hash_value(ist, key_in);
if (ist->exception_obj) {
@@ -368,7 +368,7 @@
return res_obj;
}
-DEF(Dict, hasKey_QUES, FPARM1(k, NULL)) {
+DEF(Dict, hasKey_QUES, FPARM1(k, OBJ(NODEF))) {
obj_p res;
BIN_CONTENT_CHK(Dict);
if ((res = dict_item(ist, self, parms[1]))) {
@@ -378,7 +378,7 @@
return OBJ(PR_FALSE);
}
-DEF(Dict, get, FPARM2(k, NULL, x, OBJ(NONE))) {
+DEF(Dict, get, FPARM2(k, OBJ(NODEF), x, OBJ(NONE))) {
obj_p res;
BIN_CONTENT_CHK(Dict);
if ((res = dict_item(ist, self, parms[1]))) {
@@ -507,7 +507,7 @@
return self;
}
-DEF(Dict, update_BANG, FPARM1(D1,NULL)) {
+DEF(Dict, update_BANG, FPARM1(D1, OBJ(NODEF))) {
size_t i, llen;
obj_p list;
@@ -523,7 +523,7 @@
return self;
}
-DEF(Dict, setDefault_BANG, FPARM2(k, NULL, x, OBJ(NONE))) {
+DEF(Dict, setDefault_BANG, FPARM2(k, OBJ(NODEF), x, OBJ(NONE))) {
obj_p res;
BIN_CONTENT_CHK(Dict);
if ((res = dict_item(ist, self, parms[1]))) {
Modified: trunk/src/builtins-file.c
===================================================================
--- trunk/src/builtins-file.c 2004-06-20 01:07:28 UTC (rev 646)
+++ trunk/src/builtins-file.c 2004-06-20 07:28:50 UTC (rev 647)
@@ -382,7 +382,7 @@
return dir_list(ist, self, APR_REG, DLIST_SIZE, NULL, NULL, 0);
}
-DEF(Dir, rename, FPARM1(name, NULL)) {
+DEF(Dir, rename, FPARM1(name, OBJ(NODEF))) {
apr_status_t aprerr;
char *name, *dirpath, *p;
file_p filep;
@@ -400,7 +400,7 @@
return new_dir_obj(ist, name);
}
-DEF(Dir, move, FPARM1(dir, NULL)) {
+DEF(Dir, move, FPARM1(dir, OBJ(NODEF))) {
apr_status_t aprerr;
char *dirpath1, *dirpath2;
file_p filep;
@@ -414,7 +414,7 @@
return parms[1];
}
-DEF(Dir, copy, FPARM2(dir, NULL, uperms, NEW_INT(APR_UREAD|APR_UWRITE|APR_UEXECUTE))) {
+DEF(Dir, copy, FPARM2(dir, OBJ(NODEF), uperms, NEW_INT(APR_UREAD|APR_UWRITE|APR_UEXECUTE))) {
apr_status_t aprerr;
i32_t uperms;
char* path;
@@ -615,7 +615,7 @@
File_OBJ->unclonable = TRUE;
}
-DEF(File, init_, FPARM3( path, NULL,
+DEF(File, init_, FPARM3( path, OBJ(NODEF),
mode, NEW_STRING(""),
bufsize, NEW_INT(-1) ) ) {
apr_file_t *f;
@@ -704,7 +704,7 @@
return OBJ(NONE);
}
-DEF(File, rename, FPARM1(name, NULL)) {
+DEF(File, rename, FPARM1(name, OBJ(NODEF))) {
apr_status_t aprerr;
char *name, *path, *p;
file_p filep;
@@ -726,7 +726,7 @@
return new_file_obj(ist, NEW_STRING(name), NULL, NULL, 0, 0);
}
-DEF(File, move, FPARM1(dir, NULL)) {
+DEF(File, move, FPARM1(dir, OBJ(NODEF))) {
apr_status_t aprerr;
obj_p res;
char *srcfilepath, *filename, *dstpath, *dstfilepath;
@@ -750,7 +750,7 @@
return res;
}
-DEF(File, copy, FPARM2(file, NULL, uperms, NEW_INT(APR_UREAD|APR_UWRITE|APR_UEXECUTE))) {
+DEF(File, copy, FPARM2(file, OBJ(NODEF), uperms, NEW_INT(APR_UREAD|APR_UWRITE|APR_UEXECUTE))) {
apr_status_t aprerr;
i32_t uperms;
char *path1, *path2;
@@ -1060,7 +1060,7 @@
return byt_obj;
}
-DEF(File, seek, FPARM2( pos, NULL,
+DEF(File, seek, FPARM2( pos, OBJ(NODEF),
how, NEW_INT(0) ) ) {
apr_off_t pos;
apr_seek_where_t origin;
@@ -1099,7 +1099,7 @@
return OBJ(NONE);
}
-DEF(File, truncate, FPARM1(size, NULL)) {
+DEF(File, truncate, FPARM1(size, OBJ(NODEF))) {
apr_status_t aprerr;
char err_buf[1024];
apr_off_t size;
@@ -1134,7 +1134,7 @@
return OBJ(NONE);
}
-DEF(File, write, FPARM1(bytes, NULL)) {
+DEF(File, write, FPARM1(bytes, OBJ(NODEF))) {
apr_size_t size;
apr_status_t aprerr;
char err_buf[1024];
@@ -1287,7 +1287,7 @@
TextFile_OBJ->unclonable = TRUE;
}
-DEF(TextFile, init_, FPARM5( path, NULL,
+DEF(TextFile, init_, FPARM5( path, OBJ(NODEF),
mode, NEW_STRING(""),
encoding, NEW_STRING("ASCII"),
magic, OBJ(PR_FALSE),
@@ -1630,7 +1630,7 @@
return list_obj;
}
-DEF(TextFile, write, FPARM1(str, NULL)) {
+DEF(TextFile, write, FPARM1(str, OBJ(NODEF))) {
apr_size_t size;
apr_status_t aprerr;
char *encoding, err_buf[1024];
@@ -1671,7 +1671,7 @@
return parms[1];
}
-DEF(TextFile, writeLines, FPARM1(lst, NULL)) {
+DEF(TextFile, writeLines, FPARM1(lst, OBJ(NODEF))) {
apr_size_t size;
apr_status_t aprerr;
char *encoding, err_buf[1024];
Modified: trunk/src/builtins-list.c
===================================================================
--- trunk/src/builtins-list.c 2004-06-20 01:07:28 UTC (rev 646)
+++ trunk/src/builtins-list.c 2004-06-20 07:28:50 UTC (rev 647)
@@ -269,15 +269,15 @@
int obj_lt(obj_p a, obj_p b, isp ist, obj_p cmp_func) {
obj_p res, arr[4];
if (cmp_func != OBJ(NONE)) {
- arr[0] = NULL;
+ arr[0] = OBJ(NOKEY);
arr[1] = a;
- arr[2] = NULL;
+ arr[2] = OBJ(NOKEY);
arr[3] = b;
res = call_func(ist, NULL, cmp_func, 4, arr, NULL);
if_exc_return 0;
return (res->data.i64 < 0);
}
- arr[0] = NULL;
+ arr[0] = OBJ(NOKEY);
arr[1] = b;
res = call_func(ist, a, SYM(CMP_), 2, arr, NULL);
if_exc_return 0;
@@ -287,15 +287,15 @@
int obj_eq(obj_p a, obj_p b, isp ist, obj_p cmp_func) {
obj_p res, arr[4];
if (cmp_func != OBJ(NONE)) {
- arr[0] = NULL;
+ arr[0] = OBJ(NOKEY);
arr[1] = a;
- arr[2] = NULL;
+ arr[2] = OBJ(NOKEY);
arr[3] = b;
res = call_func(ist, NULL, cmp_func, 4, arr, NULL);
if_exc_return 0;
return (res->data.i64 == 0);
}
- arr[0] = NULL;
+ arr[0] = OBJ(NOKEY);
arr[1] = b;
res = call_func(ist, a, SYM(EQ__QUES), 2, arr, NULL);
if_exc_return 0;
Modified: trunk/src/builtins-string.c
===================================================================
--- trunk/src/builtins-string.c 2004-06-20 01:07:28 UTC (rev 646)
+++ trunk/src/builtins-string.c 2004-06-20 07:28:50 UTC (rev 647)
@@ -852,7 +852,7 @@
return changeCase(ist,self,&pr_toupper,AT_WORD_START);
}
-DEF(String, find, FPARM2( stringToFind, NULL, indexToStartLooking, NEW_INT(0) )) {
+DEF(String, find, FPARM2( stringToFind, OBJ(NODEF), indexToStartLooking, NEW_INT(0) )) {
size_t str_len;
size_t find_len = 0;
ch3_p found, find_ptr = NULL, self_str;
Modified: trunk/src/bytecodes.h
===================================================================
--- trunk/src/bytecodes.h 2004-06-20 01:07:28 UTC (rev 646)
+++ trunk/src/bytecodes.h 2004-06-20 07:28:50 UTC (rev 647)
@@ -56,8 +56,6 @@
#ifndef BYTECODES_H
#define BYTECODES_H
-#define PARAM_NORMAL ((obj_p)0)
-
typedef enum {
// NOP
@@ -136,7 +134,7 @@
// DEF_(label, formal params, code)
// define a function and store it in reference attr
-// fparam-label is symbol or PARAM_STAR, or PARAM_STAR_STAR
+// fparam-label is symbol or OBJ(PARAM_STAR), or OBJ(PARAM_STAR_STAR)
// fparam-value can be object or zero for empty
// stack: obj, ref, fparam-label, fparam-value, fparam-label, fparam-value, ... -> <empty>
// param: total word count (==3)
@@ -310,7 +308,7 @@
// CALL(self, func, params)
// call function, with self-obj, func-symbol, bind target, & params on stack
// params are in pairs of optional-label/value
-// label is symbol-obj, PARAM_NORMAL, PARAM_STAR, or PARAM_STAR_STAR
+// label is symbol-obj, OBJ(NOKEY), OBJ(PARAM_STAR), or OBJ(PARAM_STAR_STAR)
// pop all and leave result on stack
// if bind-tgt is NULL, use self-obj as bind-tgt
// stack: self-obj,func-symbol,bind-tgt,label,value,label,value,... -> result
Modified: trunk/src/interp.c
===================================================================
--- trunk/src/interp.c 2004-06-20 01:07:28 UTC (rev 646)
+++ trunk/src/interp.c 2004-06-20 07:28:50 UTC (rev 647)
@@ -394,13 +394,13 @@
label = list_item(ist, form_params, i);
value = list_item(ist, form_params, i+1);
if (pstate == 3) goto fparmerr;
- if (pstate && !value) goto fparmerr;
- if (label == PARAM_STAR) {
+ if (pstate && value == OBJ(NODEF)) goto fparmerr;
+ if (label == OBJ(PARAM_STAR)) {
if (pstate == 2) goto fparmerr;
pstate = 2;
fparam_proc_state->free_pos_list_key = value;
fparam_proc_state->free_pos_list_obj = NEW_LIST(10);
- } else if (label == PARAM_STAR_STAR) {
+ } else if (label == OBJ(PARAM_STAR_STAR)) {
pstate = 3;
fparam_proc_state->free_label_list_key = value;
fparam_proc_state->free_label_list_obj = NEW_DICT(10);
@@ -413,31 +413,24 @@
}
if (fparam_proc_state->lbl_val_list) {
int i, j;
- for (i=0; i < parm_cnt; ){
+ for (i=0; i < parm_cnt; ) {
label = act_params[i++];
value = act_params[i++];
- switch ((uintptr_t)label){
- case (uintptr_t)PARAM_NORMAL:
+ if (label == OBJ(NOKEY)) {
if (add_pos_param(ist, fparam_proc_state, value)) goto paramerr;
- break;
- case (uintptr_t)PARAM_STAR: {
+ } else if (label == OBJ(PARAM_STAR)) {
int llen = (int) list_len(ist, value);
for(j=0; j < llen; j++)
if (add_pos_param(ist, fparam_proc_state, list_item(ist, value, j))) goto paramerr;
- break;
- }
- case (uintptr_t)PARAM_STAR_STAR: {
+ } else if (label == OBJ(PARAM_STAR_STAR)) {
obj_p list = dict_keys_values(ist, value, 2 /*list*/);
int llen = (int) list_len(ist, list);
for(j=0; j < llen; j+=2)
if ( add_label_param(ist, fparam_proc_state, list_item(ist, list, j),
list_item(ist, list, j+1)) ) goto paramerr;
del_unlock(list);
- break;
- }
- default:
+ } else {
if (add_label_param(ist, fparam_proc_state, label, value)) goto paramerr;
- break;
}
}
} else {
@@ -445,18 +438,14 @@
for (i=0; i < parm_cnt; ) {
label = act_params[i++];
value = act_params[i++];
- switch ((uintptr_t)label){
- case (uintptr_t)PARAM_STAR:
+ if (label == OBJ(PARAM_STAR)) {
if (list_len(ist, value)) goto paramerr;
- break;
- case (uintptr_t)PARAM_STAR_STAR:
+ } else if (label == OBJ(PARAM_STAR_STAR)) {
if (dict_len(ist, value)) goto paramerr;
- break;
- default:
+ } else
goto paramerr;
- }
}
- }
+ }
return OK;
fparmerr:
return 1;
Modified: trunk/src/main.c
===================================================================
--- trunk/src/main.c 2004-06-20 01:07:28 UTC (rev 646)
+++ trunk/src/main.c 2004-06-20 07:28:50 UTC (rev 647)
@@ -85,7 +85,13 @@
pr_exit(1);
}
return apr_root_pool;
+}
+void sig_handler(int signum) {
+ switch (signum) {
+ case SIGTERM:
+ signum = 0; // for breakpoint
+ }
}
//********************************* main **************************************
@@ -103,12 +109,19 @@
pr_exit(1);
}
atexit(&apr_terminate);
-
if ((aprerr = apr_pool_create(&apr_root_pool, NULL))) {
printf("Main error: apr_pool_create: %s\n",
apr_strerror(aprerr, buf, sizeof(buf)));
pr_exit(1);
}
+ // these don't seem to work in win32 at all
+ signal(SIGTERM, sig_handler);
+ signal(SIGABRT, sig_handler);
+ signal(SIGFPE, sig_handler);
+ signal(SIGILL, sig_handler);
+ signal(SIGINT, sig_handler);
+ signal(SIGSEGV, sig_handler);
+ signal(SIGTERM, sig_handler);
/* Now that apr is ready, on to our stuff */
ist = new_ist(ACC_SYSTEM);
Modified: trunk/src/memory_mgr.c
===================================================================
--- trunk/src/memory_mgr.c 2004-06-20 01:07:28 UTC (rev 646)
+++ trunk/src/memory_mgr.c 2004-06-20 07:28:50 UTC (rev 647)
@@ -119,7 +119,7 @@
isp ist = thread_p->ist;
obj_p mm_obj_list = NEW_LIST(100);
- obj_p mm_obj_act_param[] = {NULL, mm_obj_list};
+ obj_p mm_obj_act_param[] = {OBJ(NOKEY), mm_obj_list};
int last_obj_del_count = 0, last_obj_count = 0;
#ifdef DEBUG_THREADS
Modified: trunk/src/object.c
===================================================================
--- trunk/src/object.c 2004-06-20 01:07:28 UTC (rev 646)
+++ trunk/src/object.c 2004-06-20 07:28:50 UTC (rev 647)
@@ -213,12 +213,18 @@
OBJ(OBJECT) = NEW_OBJ(NULL);
OBJ(OBJECT)->attr_proto.proto = OBJ(OBJECT);
+ OBJ(PR_FALSE) = NEW_OBJ(NULL);
+ OBJ(PR_TRUE) = NEW_OBJ(NULL);
+ OBJ(NONE) = NEW_OBJ(NULL);
+ OBJ(NOKEY) = NEW_OBJ(NULL);
+ OBJ(PARAM_STAR) = NEW_OBJ(NULL);
+ OBJ(PARAM_STAR_STAR) = NEW_OBJ(NULL);
+ OBJ(NODEF) = NEW_OBJ(NULL);
OBJ(SEQ_PROTO) = NEW_OBJ(NULL);
OBJ(TUPLE_PROTO) = NEW_OBJ(OBJ(SEQ_PROTO));
OBJ(LIST_PROTO) = NEW_OBJ(OBJ(TUPLE_PROTO));
OBJ(SYMBOL_PROTO) = NEW_OBJ(NULL);
- OBJ(DATETIME_PROTO) = NEW_OBJ(NULL);
-
+ OBJ(DATETIME_PROTO) = NEW_OBJ(NULL);
OBJ(HASH_PROTO) = NEW_OBJ(NULL);
OBJ(SLICE_PROTO) = NEW_OBJ(NULL);
OBJ(LOCAL_PROTO) = NEW_OBJ(NULL);
@@ -228,9 +234,6 @@
OBJ(MUTEX_PROTO) = NEW_OBJ(NULL);
OBJ(ROOT_GLOBALS) = NEW_OBJ(NULL);
OBJ(MODULES) = NEW_OBJ(NULL);
- OBJ(PR_FALSE) = NEW_OBJ(NULL);
- OBJ(PR_TRUE) = NEW_OBJ(NULL);
- OBJ(NONE) = NEW_OBJ(NULL);
OBJ(EXCEPTION) = NEW_OBJ(NULL);
OBJ(FUNC_PROTO) = NEW_OBJ(NULL);
OBJ(ITER_PROTO) = NEW_OBJ(NULL);
@@ -1079,7 +1082,7 @@
//********************************* call_func1_f ********************************
obj_p call_func1_f(isp ist, obj_p self, obj_p sym, obj_p parm) {
obj_p arr[2];
- arr[0] = NULL;
+ arr[0] = OBJ(NOKEY);
arr[1] = parm;
return call_func(ist, self, sym, 2, arr, NULL);
}
@@ -1087,8 +1090,8 @@
//********************************* call_func2_f ********************************
obj_p call_func2_f(isp ist, obj_p self, obj_p sym, obj_p parm1, obj_p parm2) {
obj_p arr[4];
- arr[0] = NULL; arr[1] = parm1;
- arr[2] = NULL; arr[3] = parm2;
+ arr[0] = OBJ(NOKEY); arr[1] = parm1;
+ arr[2] = OBJ(NOKEY); arr[3] = parm2;
return call_func(ist, self, sym, 4, arr, NULL);
}
@@ -1129,8 +1132,6 @@
fclose(fout);
}
-
-
//********************************* key_to_sym *************************************
obj_p key_to_sym(isp ist, attr_key_t key) {
obj_p res, key_obj = NEW_INT(key);
Modified: trunk/src/parser_routines.c
===================================================================
--- trunk/src/parser_routines.c 2004-06-20 01:07:28 UTC (rev 646)
+++ trunk/src/parser_routines.c 2004-06-20 07:28:50 UTC (rev 647)
@@ -585,7 +585,7 @@
code_p res = new_code(param, 3, 2, 2, OP_PUSH);
res->code_data[0].bytecode.param = 3;
res->code_data[1].data = sym(IST, pr2c_strptr(IST, label));
- res->code_data[2].data = PARAM_NORMAL;
+ res->code_data[2].data = OBJ(NODEF);
return debug_retrn(__LINE__, res);
}
code_p label_eq_expr_to_formparm(void* param, obj_p label, code_p expr) {
@@ -631,14 +631,14 @@
code_p star_ref_to_formparm(void* param, obj_p label){
code_p res = new_code(param, 3, 2, 2, OP_PUSH);
res->code_data[0].bytecode.param = 3;
- res->code_data[1].data = PARAM_STAR;
+ res->code_data[1].data = OBJ(PARAM_STAR);
res->code_data[2].data = sym(IST, pr2c_strptr(IST, label));
return debug_retrn(__LINE__, res);
}
code_p star_star_ref_to_formparm(void* param, obj_p label){
code_p res = new_code(param, 3, 2, 2, OP_PUSH);
res->code_data[0].bytecode.param = 3;
- res->code_data[1].data = PARAM_STAR_STAR;
+ res->code_data[1].data = OBJ(PARAM_STAR_STAR);
res->code_data[2].data = sym(IST, pr2c_strptr(IST, label));
return debug_retrn(__LINE__, res);
}
@@ -759,7 +759,7 @@
res->code_data[k++].bytecode.param = 4;
res->code_data[k++].data = sym_id_table[op].id;
res->code_data[k++].data = NULL;
- res->code_data[k++].data = PARAM_NORMAL;
+ res->code_data[k++].data = OBJ(NOKEY);
if (have_cmp_op) {
res->code_data[k ].bytecode.opcode = OP_DUPLICATE;
res->code_data[k++].bytecode.param = -5;
@@ -1195,7 +1195,7 @@
res->code_data[k++].bytecode.param = 4;
res->code_data[k++].data = sym_id_table[op].id;
res->code_data[k++].data = NULL;
- res->code_data[k++].data = PARAM_NORMAL;
+ res->code_data[k++].data = OBJ(NOKEY);
add_code(rparm, res, &k);
res->code_data[k ].bytecode.opcode = OP_CALL;
res->code_data[k++].bytecode.param = 1;
@@ -1293,6 +1293,7 @@
obj_p func;
int i, code_len, k=0, len=2, stack_depth=0, max_stack_depth=0;
int blen, llen=0, opcode = OP_NOP, pcnt = 0, depth_dec = 0;
+
if (params) llen = clist_len(params);
if (flg != OP_WITH) {
if(!name && body->stack_depth)
@@ -1306,15 +1307,21 @@
body = append_code(param, body, res, 0);
}
k=0;
- blen = sizeof(code)/sizeof(code_t) + body->len;
if (name)
calc_code(name, &len, &stack_depth, &max_stack_depth);
+
if (params) {
len++;
for(i=0; i < llen; i++)
calc_code( (code_p)clist_item(params,i),
&len, &stack_depth, &max_stack_depth );
}
+
+ blen = sizeof(code)/sizeof(code_t) + body->len;
+ func = new_object(IST, OBJ(FUNC_PROTO));
+ code_len = blen * sizeof(code_t);
+ memmove(obj_malloc(IST, OBJ(FUNC_PROTO), func, code_len), body, code_len);
+
if (self) {
calc_code(self, &len, &stack_depth, &max_stack_depth);
len++;
@@ -1327,9 +1334,6 @@
add_code(clist_item(params,i), res, &k);
if (self)
add_code(self, res, &k);
- func = new_object(IST, OBJ(FUNC_PROTO));
- code_len = blen * sizeof(code_t);
- memmove(obj_malloc(IST, OBJ(FUNC_PROTO), func, code_len), body, code_len);
switch (flg) {
case DEF_FLG: opcode = OP_DEF; pcnt = 3; depth_dec = 2; break;
case GEN_FLG: opcode = OP_GEN; pcnt = 3; depth_dec = 2; break;
@@ -1432,16 +1436,16 @@
return debug_retrn(__LINE__, res);
}
code_p expr_to_param(void* param, code_p expr){
- return debug_retrn(__LINE__, word_expr_to_param(param, PARAM_NORMAL, expr));
+ return debug_retrn(__LINE__, word_expr_to_param(param, OBJ(NOKEY), expr));
}
code_p label_eq_expr_to_param(void* param, obj_p label, code_p expr){
return debug_retrn(__LINE__, word_expr_to_param(param, sym(IST, pr2c_strptr(IST, label)), expr));
}
code_p star_seq_to_param(void* param, code_p expr){
- return debug_retrn(__LINE__, word_expr_to_param(param, PARAM_STAR, expr));
+ return debug_retrn(__LINE__, word_expr_to_param(param, OBJ(PARAM_STAR), expr));
}
code_p star_star_dict_to_param(void* param, code_p expr){
- return debug_retrn(__LINE__, word_expr_to_param(param, PARAM_STAR_STAR, expr));
+ return debug_retrn(__LINE__, word_expr_to_param(param, OBJ(PARAM_STAR_STAR), expr));
}
code_p int_to_obj(void* param, obj_p num) {
code_p res = new_code(param, 2, 1, 1, OP_PUSH);
Modified: trunk/src/prothon.y
===================================================================
--- trunk/src/prothon.y 2004-06-20 01:07:28 UTC (rev 646)
+++ trunk/src/prothon.y 2004-06-20 07:28:50 UTC (rev 647)
@@ -615,7 +615,7 @@
func_params:
/* empty string */ { $$ = empty_list(yylex_param); }
| function_param { $$ = new_list(yylex_param, $1); }
- | func_params ',' function_param { $$ = append_list(yylex_param, $1, $3); }
+ | func_params ',' function_param { $$ = append_list(yylex_param, $1, $3); }
;
function_param:
expr { $$ = expr_to_param(yylex_param, $1); }