"Fossies" - the Fresh Open Source Software Archive

Member "heaplayers-351/benchmarks/mudlle/vars.mud" (15 Oct 2003, 5578 Bytes) of package /linux/misc/old/heaplayers_3_5_1.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 library vars
    2 requires system, misc
    3 defines
    4   mc:v_class, mc:v_name, mc:v_number, mc:v_indirect, mc:v_uses, mc:svar,
    5   mc:v_neighbours, mc:v_alias, mc:v_location, mc:v_lclass, mc:v_lregister,
    6   mc:v_lrtype, mc:v_lrnumber, mc:v_lspill, mc:v_lstype, mc:v_lsoffset,
    7   mc:reg_scratch, mc:reg_caller, mc:reg_callee, mc:spill_closure, mc:spill_args,
    8   mc:spill_spill, mc:v_global, mc:v_goffset, mc:v_local, mc:v_lclosure_uses,
    9   mc:closure_read, mc:closure_write, mc:v_closure, mc:v_cparent, mc:v_constant,
   10   mc:v_kvalue, mc:v_global_constant, mc:var_make_local, mc:var_make_dglobal,
   11   mc:var_make_global, mc:var_make_constant, mc:var_base, mc:var_value,
   12   mc:alias_base, mc:alias, mc:var_make_closure, mc:var_make_kglobal, 
   13   mc:v_global_define
   14 
   15 [
   16 // Variable handling.
   17 
   18 // Variables are represented by a vector, as follows:
   19 // Variable structure:
   20 //   [0] : class (mc:v_global, mc:v_local, mc:v_closure, mc:v_constant)
   21 //   [1] : name (string)
   22 //   [2] : class dependent data
   23 //   [3..n] : other data
   24 
   25 mc:v_class = 0; // class of variable
   26 mc:v_name = 1; // name of variable (string)
   27 //mc:v_data = 2; // class dependent data
   28 mc:v_number = 3; // unique number (for display)
   29 mc:v_indirect = 4; // true if variable is indirect
   30 mc:v_uses = 5; // du-chain for this variable
   31 mc:v_neighbours = 5; // varset of interfering variables (implicit graph,  register allocation)
   32 mc:v_alias = 5; // variable this is an alias of
   33 
   34 
   35 mc:v_location = 6; // where variable is stored (register, spill, etc)
   36  mc:v_lclass = 0;
   37   mc:v_lregister = 0;
   38    mc:v_lrtype = 1; // type of register (scratch, etc)
   39    mc:v_lrnumber = 2; // it's sequence number
   40   mc:v_lspill = 1;
   41    mc:v_lstype = 1; // where variable spilled (closure, etc)
   42    mc:v_lsoffset = 2; // offset in spill record
   43 
   44 mc:reg_scratch = 0;
   45 mc:reg_caller = 1;
   46 mc:reg_callee = 2;
   47 
   48 mc:spill_closure = 0;
   49 mc:spill_args = 1;
   50 mc:spill_spill = 2;
   51 
   52 mc:v_global = 0;
   53  mc:v_goffset = 2; // data: offset of global variable (integer)
   54 
   55 mc:v_local = 1;
   56  mc:v_lclosure_uses = 2; // data: how variable is used in closures (read, write, bitmask)
   57  mc:closure_read = 1; // bitmasks for above field
   58  mc:closure_write = 2;
   59 
   60 mc:v_closure = 2;
   61  mc:v_cparent = 2; // data: variable of parent (variable)
   62 
   63 mc:v_constant = 3;
   64  mc:v_kvalue = 2; // data: value of constant
   65 
   66 // global variables imported from modules 
   67 
   68 mc:v_global_constant = 4; // from protected module
   69  // uses mc:v_goffset
   70 
   71 mc:v_global_define = 5; // from own or loaded module
   72  // uses mc:v_goffset
   73 
   74 [
   75   | globals, kglobals, dglobals, vindex, make_global |
   76 
   77   vindex = 0;
   78   globals = make_table();
   79   dglobals = make_table();
   80   kglobals = make_table();
   81 
   82   make_global = 
   83     fn (globals, type)
   84       fn (name, n)
   85 	[
   86 	  | gv |
   87 
   88 	  gv = globals[name];
   89 	  if (gv != null)
   90 	    [
   91 	      gv[mc:v_uses] = null; // reset in case of bug
   92 	      gv // reuse previously created global var
   93 	    ]
   94 	  else 
   95 	    [
   96 	      | gvar |
   97 
   98 	      gvar = vector(type, name, n,
   99 			    vindex = vindex + 1, false, null, false);
  100 	      globals[name] = gvar
  101 	    ]
  102 	];
  103 
  104   mc:var_make_global = make_global(globals, mc:v_global);
  105 
  106   mc:var_make_kglobal = make_global(kglobals, mc:v_global_constant);
  107 
  108   mc:var_make_dglobal = make_global(dglobals, mc:v_global_define);
  109 
  110   mc:var_make_constant = fn "x -> var. Returns a new constant variable with value x" (x)
  111     vector(mc:v_constant, "", x, vindex = vindex + 1, false, null, false);
  112 
  113   mc:var_make_local = fn "s -> var. Returns a new local variable (name s)" (name)
  114     vector(mc:v_local, name, 0, vindex = vindex + 1, false, null, false);
  115 
  116   mc:var_make_closure = fn "s var1 -> var2. Returns a new closure variable (name s) with parent var1" (name, parent)
  117     vector(mc:v_closure, name, parent, vindex = vindex + 1, false, null, false);
  118 
  119   mc:var_base = fn "var1 -> var2. Returns the real local variable of closure var var1" (v)
  120     [
  121       while (v[mc:v_class] == mc:v_closure)
  122         v = v[mc:v_cparent];
  123       v
  124     ];
  125 
  126   mc:var_value = fn "var -> x. Returns value of constant variable var" (v)
  127     v[mc:v_kvalue];
  128 
  129   mc:alias_base = fn "var1 -> var2. Returns the variable var1 is aliased to" (v)
  130     [
  131       | n |
  132 
  133       while ((n = v[mc:v_alias]) != null) v = n;
  134       v
  135     ];
  136 
  137   mc:alias = fn "var1 var2 -> . Makes var1 an alias for var2" (v1, v2)
  138     v1[mc:v_alias] = v2;
  139 
  140 
  141   mc:svar = fn (var)
  142     [
  143       | class, base, loc |
  144 
  145       base = 
  146 	[
  147 	  class = var[mc:v_class];
  148 	  if (class == mc:v_global) format("global %s(%s)", var[mc:v_name], var[mc:v_number])
  149 	  else if (class == mc:v_global_constant) format("kglobal %s", var[mc:v_name])
  150 	  else if (class == mc:v_global_define) format("dglobal %s", var[mc:v_name])
  151 	  else if (class == mc:v_constant) format("%s", var[mc:v_kvalue])
  152 	  else if (class == mc:v_local)
  153 	    [
  154 	      | type |
  155 	      type = if (var[mc:v_indirect]) "indirect" else "local";
  156 
  157 	      if (string_length(var[mc:v_name]) > 0)
  158 		format("%s %s(%s)", type, var[mc:v_number], var[mc:v_name])
  159 	      else
  160 		format("%s %s", type, var[mc:v_number])
  161 	    ]
  162 	  else if (class == mc:v_closure)
  163 	    format("%s %s(%s)", if (var[mc:v_indirect]) "indclosure" else "closure",
  164 		   var[mc:v_number], mc:svar(var[mc:v_cparent]))
  165 	  else fail();
  166 	];
  167 
  168       if (loc = var[mc:v_location])
  169 	base + "{" +
  170 	  [
  171 	    class = loc[mc:v_lclass];
  172 	    if (class == mc:v_lregister)
  173 	      format("%s %s", '["scratch" "caller" "callee"][loc[mc:v_lrtype]],
  174 		     loc[mc:v_lrnumber])
  175 	    else if (class == mc:v_lspill)
  176 	      format("%s %s", '["closure" "args" "spill"][loc[mc:v_lstype]],
  177 		     loc[mc:v_lsoffset])
  178 	    else fail();
  179 	  ] + "}"
  180       else
  181         base
  182     ];
  183 ];
  184 
  185 ];