diff --git a/lib/master.pike.in b/lib/master.pike.in index 836353fce9f8dc478dcadce3f9592dc5b81315b8..aaeb131650520a12ab4b586ce655b6f3b61066a9 100644 --- a/lib/master.pike.in +++ b/lib/master.pike.in @@ -1,4 +1,4 @@ -/* $Id: master.pike.in,v 1.58 1999/10/06 14:26:30 grubba Exp $ +/* $Id: master.pike.in,v 1.59 1999/10/09 23:28:39 hubbe Exp $ * * Master-file for Pike. * @@ -443,6 +443,18 @@ void create() add_constant("UNDEFINED", UNDEFINED); add_constant("write", _static_modules.files()->_stdout->write); +#if "�share_prefix�"[0]!='�' + // add path for architecture-dependant files + add_include_path("�share_prefix�/include"); + add_module_path("�share_prefix�/modules"); +#endif + +#if "�lib_prefix�"[0]!='�' + // add path for architecture-dependant files + add_include_path("�lib_prefix�/include"); + add_module_path("�lib_prefix�/modules"); +#endif + random_seed(time() + (getpid() * 0x11111111)); } @@ -782,19 +794,6 @@ void _main(string *orig_argv, string *env) -#if "�share_prefix�"[0]!='�' - // add path for architecture-dependant files - add_include_path("�share_prefix�/include"); - add_module_path("�share_prefix�/modules"); -#endif - -#if "�lib_prefix�"[0]!='�' - // add path for architecture-dependant files - add_include_path("�lib_prefix�/include"); - add_module_path("�lib_prefix�/modules"); -#endif - - #ifndef NOT_INSTALLED q=(getenv("PIKE_INCLUDE_PATH")||"")/":"-({""}); for(i=sizeof(q)-1;i>=0;i--) add_include_path(q[i]); @@ -999,7 +998,10 @@ void set_inhibit_compile_errors(mixed f) string trim_file_name(string s) { + if(getenv("LONG_PIKE_ERRORS")) return s; if(getenv("SHORT_PIKE_ERRORS")) return BASENAME(s); + string cwd=getcwd(); + if(s[..sizeof(cwd)-1]==cwd) return s[sizeof(cwd)..]; return s; } @@ -1212,7 +1214,7 @@ string describe_program(program p) { if(sscanf(reverse(s),"%s.%s",string ext,string rest) && ext=="domp") return EXPLODE_PATH(reverse(rest))[-1]; - return s; + return trim_file_name(s); } if(functionp(p)) diff --git a/src/bignum.c b/src/bignum.c index 849ae42a96fa69c46e82c44176a88efca5834136..2f6ad8caf2816df5718396dcf1085e8b3bc31b02 100644 --- a/src/bignum.c +++ b/src/bignum.c @@ -8,51 +8,60 @@ #include "svalue.h" #include "error.h" -/* FIXME: Cache the mpz-function? */ -struct object *make_bignum_object(void) + +struct svalue auto_bignum_program = { T_INT }; + +static void resolve_auto_bignum_program(void) { - struct object *o; - - push_text("Gmp.mpz"); - SAFE_APPLY_MASTER("resolv", 1); - - if(sp[-1].type != T_FUNCTION) - error("Failed to resolv Gmp.mpz!\n"); - - stack_swap(); - f_call_function(2); - - o = sp[-1].u.object; - sp--; + if(auto_bignum_program.type == T_INT) + { + push_text("Gmp.mpz"); + SAFE_APPLY_MASTER("resolv", 1); + + if(sp[-1].type != T_FUNCTION) + error("Failed to resolv Gmp.mpz!\n"); + + auto_bignum_program=sp[-1]; + sp--; + } +} - return o; +void exit_auto_bignum(void) +{ + free_svalue(&auto_bignum_program); + auto_bignum_program.type=T_INT; } -#if 0 /* Hubbe's example. */ +void convert_stack_top_to_bignum(void) +{ + resolve_auto_bignum_program(); + apply_svalue(&auto_bignum_program, 1); -struct program *auto_bignum_program=0; + if(sp[-1].type != T_OBJECT) + error("Gmp.mpz conversion failed.\n"); +} -void exit_auto_bignum(void) + +struct object *make_bignum_object(void) { - if(auto_bignum_program) - { - free_program(auto_bignum_program); - auto_bignum_program=0; - } + convert_stack_top_to_bignum(); + return (--sp)->u.object; +} + +struct object *bignum_from_svalue(struct svalue *s) +{ + push_svalue(s); + convert_stack_top_to_bignum(); + return (--sp)->u.object; } -struct program *get_auto_bignum_program() +void convert_svalue_to_bignum(struct svalue *s) { - if(auto_bignum_program) - return auto_bignum_program; - - push_text("Gmp.mpz"); - APPLY_MASTER("resolv",1); - if(sp[-1].type != T_PROGRAM) - error("Failed to resolv Gmp.mpz!\n"); - auto_bignum_program=sp[-1].u.program; + push_svalue(s); + convert_stack_top_to_bignum(); + free_svalue(s); + *s=sp[-1]; sp--; } -#endif #endif /* AUTO_BIGNUM */ diff --git a/src/bignum.h b/src/bignum.h index f07105e695f6c1633956a434308c8646c5e687f8..83ea61aaa6667a75ec97bdd77c42978c7ca4c3fa 100644 --- a/src/bignum.h +++ b/src/bignum.h @@ -1,14 +1,10 @@ #include "global.h" -#ifdef AUTO_BIGNUM - #ifndef BIGNUM_H #define BIGNUM_H -struct object *make_bignum_object(void); +#ifdef AUTO_BIGNUM -struct program *get_auto_bignum_program(void); -void exit_auto_bignum(void); /* NOTE: These functions assume some properties of the CPU. */ @@ -22,10 +18,20 @@ void exit_auto_bignum(void); (INT_TYPE_SIGN(a) == INT_TYPE_SIGN(b) && \ INT_TYPE_SIGN(a) != INT_TYPE_SIGN((a)+(b))) -#define INT_TYPE_SUB_OVERFLOW(a, b) INT_TYPE_ADD_OVERFLOW((a), -(b)) +#define INT_TYPE_SUB_OVERFFLOW(a, b) INT_TYPE_ADD_OVERFLOW((a), -(b)) +#define INT_TYPE_SUB_OVERFLOW(a, b) INT_TYPE_ADD_OVERFLOW((a), -(b)) #define INT_TYPE_ASL_OVERFLOW(a, b) ((((a)<<(b))>>(b)) != (a)) -#endif /* BIGNUM_H */ + +/* Prototypes begin here */ +void convert_stack_top_to_bignum(void); +struct object *make_bignum_object(void); +struct object *bignum_from_svalue(struct svalue *s); +void convert_svalue_to_bignum(struct svalue *s); +/* Prototypes end here */ #endif /* AUTO_BIGNUM */ + +#endif /* BIGNUM_H */ + diff --git a/src/builtin_functions.c b/src/builtin_functions.c index 1a4b6363bc74a25d65a8110cf26f12dcedad8d9c..67346bf5262f700935f64e88b842f9546823ad10 100644 --- a/src/builtin_functions.c +++ b/src/builtin_functions.c @@ -5,7 +5,7 @@ \*/ /**/ #include "global.h" -RCSID("$Id: builtin_functions.c,v 1.183 1999/09/06 11:12:08 hubbe Exp $"); +RCSID("$Id: builtin_functions.c,v 1.184 1999/10/09 23:28:57 hubbe Exp $"); #include "interpret.h" #include "svalue.h" #include "pike_macros.h" @@ -349,7 +349,15 @@ void f_random(INT32 args) void f_random_seed(INT32 args) { INT_TYPE i; +#ifdef AUTO_BIGNUM + check_all_args("random_seed",args,BIT_INT | BIT_OBJECT, 0); + if(sp[-args].type == T_INT) + i=sp[-args].u.integer; + else + i=hash_svalue(sp-args); +#else get_all_args("random_seed",args,"%i",&i); +#endif my_srand(i); pop_n_elems(args); } diff --git a/src/language.yacc b/src/language.yacc index c619ba5ad8176f42931c3038df754e3d34ad249c..cdd883721edbf40bdeafa6dd32f625a9ce0496af 100644 --- a/src/language.yacc +++ b/src/language.yacc @@ -182,7 +182,7 @@ /* This is the grammar definition of Pike. */ #include "global.h" -RCSID("$Id: language.yacc,v 1.124 1999/09/19 22:59:11 hubbe Exp $"); +RCSID("$Id: language.yacc,v 1.125 1999/10/09 23:28:58 hubbe Exp $"); #ifdef HAVE_MEMORY_H #include <memory.h> #endif @@ -1257,6 +1257,7 @@ class: modifiers F_CLASS optional_identifier int i; struct program *p; struct identifier *id; + int tmp=compiler_pass; i=isidentifier($3->u.sval.u.string); if(i<0) { @@ -1280,6 +1281,7 @@ class: modifiers F_CLASS optional_identifier low_start_new_program(new_program, 0,0); } } + compiler_pass=tmp; } num_parse_error=num_errors; /* Kluge to prevent gazillion error messages */ } diff --git a/src/main.c b/src/main.c index f8c3a8074d20f699b36d74be38592f8e76ee671a..0ed4868e2d85245825843d4cc2abe905dafc8d18 100644 --- a/src/main.c +++ b/src/main.c @@ -5,7 +5,7 @@ \*/ /**/ #include "global.h" -RCSID("$Id: main.c,v 1.76 1999/09/25 23:50:19 grubba Exp $"); +RCSID("$Id: main.c,v 1.77 1999/10/09 23:29:00 hubbe Exp $"); #include "fdlib.h" #include "backend.h" #include "module.h" @@ -547,6 +547,10 @@ void low_exit_main(void) void cleanup_compiler(void); void cleanup_backend(void); +#ifdef AUTO_BIGNUM + void exit_auto_bignum(void); + exit_auto_bignum(); +#endif th_cleanup(); exit_object(); exit_dynamic_load(); diff --git a/src/operators.c b/src/operators.c index 6e14bfc76fb857f86fbd88f314d70e859e205bfb..0c02531d5f4c50eb9184d4004ae2c8c466c5e713 100644 --- a/src/operators.c +++ b/src/operators.c @@ -6,7 +6,7 @@ /**/ #include "global.h" #include <math.h> -RCSID("$Id: operators.c,v 1.61 1999/10/08 16:35:18 noring Exp $"); +RCSID("$Id: operators.c,v 1.62 1999/10/09 23:29:01 hubbe Exp $"); #include "interpret.h" #include "svalue.h" #include "multiset.h" @@ -267,35 +267,22 @@ void f_add(INT32 args) case BIT_INT: #ifdef AUTO_BIGNUM - /* FIXME: I believe this routine is somewhat buggy... */ - { - struct object *o = 0; - ONERROR onerr; - size = 0; for(e = -args; e < 0; e++) { - if(o) - apply_lfun(o, LFUN_ADD, 1); - else if(INT_TYPE_ADD_OVERFLOW(sp[-1].u.integer, size)) + if(INT_TYPE_ADD_OVERFLOW(sp[e].u.integer, size)) { - push_int(size); - o = make_bignum_object(); - SET_ONERROR(onerr, do_free_object, o); - apply_lfun(o, LFUN_ADD, 1); + convert_svalue_to_bignum(sp-args); + f_add(args); + return; } else { - size += sp[-1].u.integer; - sp--; + size += sp[e].u.integer; } } - - if(o) - CALL_AND_UNSET_ONERROR(onerr); - else - push_int(size); - } + sp-=args; + push_int(size); #else size=0; for(e=-args; e<0; e++) size+=sp[e].u.integer; @@ -1282,32 +1269,18 @@ void o_multiply(void) case TWO_TYPES(T_INT,T_INT): #ifdef AUTO_BIGNUM - { - static int ign = 1; /* FIXME: VERY UGLY PATCH, but since I cannot - get through the master while loading Gmp.mpz, - we have to ignore that the very first mul - will actually overflow. */ - - if(!ign && INT_TYPE_MUL_OVERFLOW(sp[-2].u.integer, sp[-1].u.integer)) + if(INT_TYPE_MUL_OVERFLOW(sp[-2].u.integer, sp[-1].u.integer)) { - struct object *o; - ONERROR tmp; - - o = make_bignum_object(); - - SET_ONERROR(tmp, do_free_object, o); - apply_lfun(o, LFUN_MULTIPLY, 1); - CALL_AND_UNSET_ONERROR(tmp); - return; + convert_stack_top_to_bignum(); + goto do_lfun_multiply; } - ign = 0; - } #endif /* AUTO_BIGNUM */ sp--; sp[-1].u.integer *= sp[0].u.integer; return; default: + do_lfun_multiply: if(call_lfun(LFUN_MULTIPLY, LFUN_RMULTIPLY)) return; diff --git a/src/program.c b/src/program.c index a8f8de4ec6cd5f150799712950688697da38013d..af88d8b70a099199cd622a2748ec6b97a81c0bb1 100644 --- a/src/program.c +++ b/src/program.c @@ -5,7 +5,7 @@ \*/ /**/ #include "global.h" -RCSID("$Id: program.c,v 1.157 1999/09/28 23:49:54 grubba Exp $"); +RCSID("$Id: program.c,v 1.158 1999/10/09 23:29:02 hubbe Exp $"); #include "program.h" #include "object.h" #include "dynamic_buffer.h" @@ -554,8 +554,10 @@ void low_start_new_program(struct program *p, if(!p) { p=low_allocate_program(); + e=1; }else{ add_ref(p); + e=2; } if(name) @@ -571,6 +573,8 @@ void low_start_new_program(struct program *p, #define PUSH #include "compilation.h" + compiler_pass=e; + num_used_modules=0; if(p && (p->flags & PROGRAM_FINISHED))