pike.git / lib / master.pike.in

version» Context lines:

pike.git/lib/master.pike.in:1: - /* $Id: master.pike.in,v 1.55 1999/08/27 21:40:55 hubbe Exp $ + /* $Id: master.pike.in,v 1.56 1999/09/06 11:02:23 hubbe Exp $    *    * Master-file for Pike.    *    * Based on master.pike 1.67.    */      // Some configurable parameters useful for debugging    -  + #define PIKE_AUTORELOAD +    // Used by describe_backtrace() et al.   #if !defined(BT_MAX_STRING_LEN) || (BT_MAX_STRING_LEN <= 0)   #undef BT_MAX_STRING_LEN   #define BT_MAX_STRING_LEN 255   #endif /* !defined(BT_MAX_STRING_LEN) || (BT_MAX_STRING_LEN <= 0) */      /*    * Functions begin here.    */   
pike.git/lib/master.pike.in:62:   #define error(X) throw( ({ (X), backtrace()[0..sizeof(backtrace())-2] }) )      string describe_backtrace(mixed *trace);   object low_cast_to_object(string oname, string current_file);      string *pike_include_path=({});   string *pike_module_path=({});   string *pike_program_path=({});   int want_warnings;    + #ifdef PIKE_AUTORELOAD +  + int autoreload_on; + int newest; +  + #define AUTORELOAD_CHECK_FILE(X) \ +  if(autoreload_on) if(mixed fnord=master_file_stat(X)) if(fnord[3]>newest) newest=fnord[3]; +  + #define AUTORELOAD_BEGIN() \ +  int ___newest=newest; \ +  newest=0 +  +  + #define AUTORELOAD_FINISH(VAR, CACHE, FILE) \ +  if(autoreload_on) { \ +  if(CACHE [ FILE ] && newest <= load_time[FILE]) { \ +  VAR = CACHE [ FILE ]; \ +  } \ +  } \ +  load_time[FILE]=time(); \ +  if(___newest > newest) newest=___newest; +  +  + mapping(string:int) load_time=([]); + #else +  + #define AUTORELOAD_CHECK_FILE(X) + #define AUTORELOAD_BEGIN() + #define AUTORELOAD_FINISH(VAR,CACHE,FILE) +  + #endif +    program compile_string(string data, void|string name)   {    return compile(cpp(data,name||"-"));   }      program compile_file(string file)   { -  +  AUTORELOAD_CHECK_FILE(file);    return compile(cpp(_static_modules.files()->Fd(file,"r")->read(),file, 1));   }         #ifdef GETCWD_CACHE   string current_path;   int cd(string s)   {    current_path=0;    return predef::cd(s);
pike.git/lib/master.pike.in:197:      mapping (string:program) programs=(["/master":object_program(this_object())]);      #define capitalize(X) (upper_case((X)[..0])+(X)[1..])      static program low_findprog(string pname, string ext)   {    program ret;    array s;    string fname=pname+ext; +  + #ifdef PIKE_AUTORELOAD +  if(!autoreload_on || load_time[fname]>=time()) + #endif +  {    if(ret=programs[fname]) return ret; -  +  } +     if( (s=master_file_stat(fname)) && s[1]>=0 )    { -  +  AUTORELOAD_BEGIN();    switch(ext)    {    case "":    case ".pike":    if(array s2=master_file_stat(fname+".o"))    {    if(s2[1]>=0 && s2[3]>=s[3])    {    mixed err=catch { -  +  AUTORELOAD_CHECK_FILE(fname+".o");    return programs[fname]=decode_value(_static_modules.files()->Fd(fname+".o","r")->read(),Codec());    };    if(want_warnings)    werror("Failed to decode %s.o\n",fname);    }    } -  +  +     if ( mixed e=catch { ret=compile_file(fname); } )    {    if(arrayp(e) &&    sizeof(e)==2 &&    arrayp(e[1]) &&    sizeof(e[1]) == sizeof(backtrace()))    e[1]=({});    throw(e);    }    break;   #if constant(load_module)    case ".so":    if (fname == "") {    werror(sprintf("low_find_prog(\"%s\", \"%s\") => load_module(\"\")\n"    "%s\n", pname, ext, describe_backtrace(backtrace())));    }    ret=load_module(fname);   #endif /* load_module */    } -  +  +  AUTORELOAD_FINISH(ret,programs,fname); +     return programs[fname]=ret;    }else{    return UNDEFINED;    }   }      static program findprog(string pname, string ext)   {    switch(ext)    {
pike.git/lib/master.pike.in:762:    q=tmp->find_all_options(argv,({    ({"version",tmp->NO_ARG,({"-v","--version"})}),    ({"help",tmp->NO_ARG,({"-h","--help"})}),    ({"execute",tmp->HAS_ARG,({"-e","--execute"})}),    ({"preprocess",tmp->HAS_ARG,({"-E","--preprocess"})}),    ({"modpath",tmp->HAS_ARG,({"-M","--module-path"})}),    ({"ipath",tmp->HAS_ARG,({"-I","--include-path"})}),    ({"ppath",tmp->HAS_ARG,({"-P","--program-path"})}),    ({"showpaths",tmp->NO_ARG,"--show-paths"}),    ({"warnings",tmp->NO_ARG,({"-w","--warnings"})}), + #ifdef PIKE_AUTORELOAD +  ({"autoreload",tmp->NO_ARG,({"--autoreload"})}), + #endif    ({"master",tmp->HAS_ARG,"-m"}),    ({"compiler_trace",tmp->NO_ARG,"--compiler-trace"}),    ({"debug",tmp->MAY_HAVE_ARG,"--debug",0,1}),    ({"trace",tmp->MAY_HAVE_ARG,"--trace",0,1}),    ({"ignore",tmp->MAY_HAVE_ARG,"-Dqdatpl",0,1}),    ({"ignore",tmp->HAS_ARG,"-s"}),    }), 1);       /* Parse -M and -I backwards */    for(i=sizeof(q)-1;i>=0;i--)    {    switch(q[i][0])    { -  + #ifdef PIKE_AUTORELOAD +  case "autoreload": +  autoreload_on++; + #endif +     case "debug":    debug+=(int)q[i][1];    break;      #if constant(_compiler_trace)    case "compiler_trace":    _compiler_trace(1);    break;   #endif /* constant(_compiler_trace) */   
pike.git/lib/master.pike.in:1035:    path=0;    }       }       return path;   }      string read_include(string f)   { +  AUTORELOAD_CHECK_FILE(f)    object o=_static_modules.files()->Fd();    if(o->open(f,"r"))    return o->read();   }      // FIXME   string stupid_describe(mixed m, int maxlen)   {    switch(string typ=sprintf("%t",m))    {
pike.git/lib/master.pike.in:1078:    return "({" + stupid_describe_comma_list(m,maxlen-2) +"})";       case "mapping":    if(!sizeof(m)) return "([])";    return "mapping["+sizeof(m)+"]";       case "multiset":    if(!sizeof(m)) return "(<>)";    return "multiset["+sizeof(m)+"]";    +  case "function": +  if(string tmp=describe_program(m)) return tmp; +  if(object o=function_object(m)) +  return (describe_object(o)||"")+"->"+function_name(m); +  else +  return function_name(m) || "function"; +  +  case "program": +  if(string tmp=describe_program(m)) return tmp; +  return typ; +  +  case "object": +  if(string tmp=describe_object(m)) return tmp; +  return typ; +     default:    return typ;    }   }      string stupid_describe_comma_list(array x, int maxlen)   {    string ret="";       if(maxlen<0) return ",,,"+sizeof(x);
pike.git/lib/master.pike.in:1101:    string tmp=stupid_describe(x[pos],maxlen);    if(pos) ret+=",";    ret+=tmp;       if(sizeof(ret) >= maxlen)    return ret+",,,"+(sizeof(x)-pos);    }    return ret;   }    + string describe_object(object o) + { +  string s; +  if(!o) return 0; +  if(s=search(objects,object_program(o))) +  { +  if(sscanf(reverse(s),"%s.%s",string ext,string rest) && ext=="domp") +  return EXPLODE_PATH(reverse(rest))[-1]; +  return s; +  } +  if(( s=describe_program(object_program(o)) )) +  return s+"()"; +  return 0; + } +    string describe_program(program p)   {    string s;    if(!p) return 0;    if(s=search(programs,p))    {    if(sscanf(reverse(s),"%s.%s",string ext,string rest) && ext=="domp")    return EXPLODE_PATH(reverse(rest))[-1];    return s;    }       if(functionp(p))    if(mixed tmp=function_object(p))    if(s=describe_program(object_program(tmp)))    return s+"."+function_name(p); -  +  +  if(s=_static_modules.Builtin()->program_defined(p)) +  return EXPLODE_PATH(s)[-1]; +     return 0;   }      /* It is possible that this should be a real efun,    * it is currently used by handle_error to convert a backtrace to a    * readable message.    */   string describe_backtrace(mixed trace)   {    int e;