c3da7f2000-07-04Martin Stjernholm /* -*- c -*- */
3a5b1d2000-05-24Fredrik Hübinette (Hubbe) #include "global.h" #include "interpret.h" #include "svalue.h" #include "opcodes.h" #include "pike_macros.h" #include "object.h" #include "program.h" #include "array.h" #include "error.h" #include "constants.h" #include "mapping.h" #include "stralloc.h" #include "multiset.h" #include "pike_types.h" #include "pike_memory.h" #include "threads.h" #include <math.h> #include <ctype.h> #include "module_support.h" #include "cyclic.h" #include "bignum.h"
098c802000-05-24Fredrik Hübinette (Hubbe) #include "main.h"
b8c5b22000-05-25Fredrik Hübinette (Hubbe) #include "operators.h"
3a5b1d2000-05-24Fredrik Hübinette (Hubbe)  PIKEFUN array column(array tmp, mixed val) efun; optflags OPT_TRY_OPTIMIZE; { INT32 e; struct array *a; DECLARE_CYCLIC(); /* Optimization */ if(tmp->refs == 1) { /* An array with one ref cannot possibly be cyclic */ struct svalue sval; tmp->type_field = BIT_MIXED | BIT_UNFINISHED; for(e=0;e<tmp->size;e++) { index_no_free(&sval, ITEM(tmp)+e, val); free_svalue(ITEM(tmp)+e); ITEM(tmp)[e]=sval; } pop_stack(); return; } if((a=(struct array *)BEGIN_CYCLIC(tmp,0))) { add_ref(a); }else{ push_array(a=allocate_array(tmp->size)); SET_CYCLIC_RET(a); for(e=0;e<a->size;e++) index_no_free(ITEM(a)+e, ITEM(tmp)+e, val); sp--; } END_CYCLIC(); RETURN a; } PIKEFUN multiset(1) mkmultiset(array(1=mixed) a) efun; optflags OPT_TRY_OPTIMIZE; { RETURN mkmultiset(a); }
098c802000-05-24Fredrik Hübinette (Hubbe) PIKEFUN int trace(int t) efun; optflags OPT_SIDE_EFFECT; { pop_n_elems(args); push_int(t_flag); t_flag=t; } PIKEFUN string ctime(int x) efun; optflags OPT_TRY_OPTIMIZE; { time_t i=(time_t)x; RETURN make_shared_string(ctime(&i)); } PIKEFUN mapping(1:2) mkmapping(array(1=mixed) a, array(2=mixed) b) efun; optflags OPT_TRY_OPTIMIZE; { if(a->size != b->size) bad_arg_error("mkmapping", sp-args, args, 2, "array", sp+1-args, "mkmapping called on arrays of different sizes (%d != %d)\n", a->size, b->size); RETURN mkmapping(a,b); }
3a5b1d2000-05-24Fredrik Hübinette (Hubbe) 
89fc4c2000-08-10Henrik Grubbström (Grubba) PIKEFUN ptrdiff_t string_count(string haystack, string needle)
991fdf2000-05-25Fredrik Hübinette (Hubbe)  errname String.count; optflags OPT_TRY_OPTIMIZE; {
89fc4c2000-08-10Henrik Grubbström (Grubba)  ptrdiff_t c = 0; ptrdiff_t i, j;
991fdf2000-05-25Fredrik Hübinette (Hubbe)  switch (needle->len) { case 0: switch (haystack->len) { case 0: c=1; break; /* "" appears one time in "" */ case 1: c=0; break; /* "" doesn't appear in "x" */ default: c=haystack->len-1; /* one time between each character */ } break; case 1: /* maybe optimize? */ default: for (i=0; i<haystack->len; i++) { j=string_search(haystack,needle,i); if (j==-1) break; i=j+needle->len-1; c++; } break; } RETURN c; } PIKEFUN int program_implements(program p, program p2) errname Program.implements; optflags OPT_TRY_OPTIMIZE; { RETURN implements(p,p2); } PIKEFUN int program_inherits(program p, program p2) errname Program.inherits; optflags OPT_TRY_OPTIMIZE; { RETURN !!low_get_storage(p2,p); }
b8c5b22000-05-25Fredrik Hübinette (Hubbe) PIKEFUN string program_defined(program p) errname Program.defined; optflags OPT_TRY_OPTIMIZE; { if(p && p->num_linenumbers) { char *tmp; INT32 line; if((tmp=get_line(p->program, p, &line))) { struct pike_string *tmp2; tmp2=make_shared_string(tmp); pop_n_elems(args); push_string(tmp2); if(line > 1) { push_constant_text(":"); push_int(line); f_add(3); } return; } } pop_n_elems(args); push_int(0); }
991fdf2000-05-25Fredrik Hübinette (Hubbe) PIKEFUN int string_width(string s) errname String.width; optflags OPT_TRY_OPTIMIZE; { RETURN 8 * (1 << s->size_shift); }
7f80d42000-06-19Fredrik Hübinette (Hubbe) PIKEFUN 1 m_delete(mapping(mixed:1=mixed) m, mixed val) efun; optflags OPT_SIDE_EFFECT; { struct svalue s; map_delete_no_free(m, val, &s); pop_n_elems(args); *sp=s; sp++; }
ee9fa92000-07-06Martin Stjernholm PIKEFUN int get_weak_flag(mixed m) efun; optflags OPT_TRY_OPTIMIZE; { int flag; switch (m->type) { case T_ARRAY: flag = !!(m->u.array->flags & ARRAY_WEAK_FLAG); break; case T_MAPPING: flag = !!(m->u.mapping->flags & MAPPING_FLAG_WEAK); break; case T_MULTISET: flag = !!(m->u.multiset->ind->flags & (ARRAY_WEAK_FLAG|ARRAY_WEAK_SHRINK)); break; default: SIMPLE_BAD_ARG_ERROR("get_weak_flag",1,"array|mapping|multiset"); } pop_n_elems(args); push_int(flag); }
3a5b1d2000-05-24Fredrik Hübinette (Hubbe) void init_builtin(void) {
ab82822000-05-25Fredrik Hübinette (Hubbe) INIT
3a5b1d2000-05-24Fredrik Hübinette (Hubbe) }