rlcont.red 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. % ----------------------------------------------------------------------
  2. % $Id: rlcont.red,v 1.5 1999/03/23 09:23:56 dolzmann Exp $
  3. % ----------------------------------------------------------------------
  4. % Copyright (c) 1995-1999 Andreas Dolzmann and Thomas Sturm
  5. % ----------------------------------------------------------------------
  6. % $Log: rlcont.red,v $
  7. % Revision 1.5 1999/03/23 09:23:56 dolzmann
  8. % Changed copyright information.
  9. %
  10. % Revision 1.4 1999/03/22 12:41:42 dolzmann
  11. % Reimplemented procedure rl_set for calling the exit functions of the
  12. % context before calling the enter function of the new context. The old
  13. % version could not handle the calling sequence rlset(dvfsf,5);
  14. % rlset(dvfsf) correctly.
  15. %
  16. % Revision 1.3 1996/10/07 12:03:55 sturm
  17. % Added fluids for CVS and copyright information.
  18. %
  19. % Revision 1.2 1996/09/05 11:16:59 dolzmann
  20. % Added procedures rl_serviadd and rl_bbiadd.
  21. %
  22. % Revision 1.1 1996/03/22 12:18:29 sturm
  23. % Moved and split.
  24. %
  25. % ----------------------------------------------------------------------
  26. lisp <<
  27. fluid '(rl_cont_rcsid!* rl_cont_copyright!*);
  28. rl_cont_rcsid!* :=
  29. "$Id: rlcont.red,v 1.5 1999/03/23 09:23:56 dolzmann Exp $";
  30. rl_cont_copyright!* := "Copyright (c) 1995-1999 by A. Dolzmann and T. Sturm"
  31. >>;
  32. module rlcont;
  33. % Reduce logic component context selection. Submodule of [redlog].
  34. put('rlset,'psopfn,'rl_set!$);
  35. procedure rl_set!$(argl);
  36. begin scalar w;
  37. if argl then <<
  38. w := reval car argl;
  39. if eqcar(w,'list) then <<
  40. if cdr argl then rederr "too many arguments";
  41. argl := cdr w
  42. >> else
  43. argl := w . for each x in cdr argl collect reval x
  44. >>;
  45. return 'list . rl_set argl
  46. end;
  47. procedure rl_set(argl);
  48. begin scalar cntxt,w;
  49. cntxt := if rl_cid!* then rl_cid!* . rl_argl!* else nil;
  50. if null argl then return cntxt;
  51. if rl_cid!* then rl_exit();
  52. w := rl_enter(argl);
  53. if w then <<
  54. if cntxt then rl_enter(cntxt);
  55. rederr w
  56. >>;
  57. return cntxt;
  58. end;
  59. procedure rl_exit();
  60. begin scalar w;
  61. w := for each pair in get(rl_cid!*,'rl_cswitches) collect
  62. car pair . rl_onp car pair;
  63. put(rl_cid!*,'rl_cswitches,w);
  64. for each pair in rl_ocswitches!* do
  65. rl_vonoff(car pair,cdr pair);
  66. if (w := get(rl_cid!*,'rl_exit)) then
  67. apply(w,nil);
  68. end;
  69. procedure rl_enter(argl);
  70. begin scalar w,enter,cid;
  71. cid := car argl;
  72. argl := cdr argl;
  73. w := errorset({'load!-package,mkquote(cid)},nil,!*backtrace)
  74. where !*msg=nil;
  75. if errorp w then
  76. return {"switching to context",cid,"failed"};
  77. if not flagp(cid,'rl_package) then
  78. return {cid,"is not an rl package"};
  79. enter := get(cid,'rl_enter);
  80. if null enter and argl then <<
  81. lprim {"extra",ioto_cplu("argument",cddr argl),"ignored"};
  82. argl := nil;
  83. >>;
  84. if enter then <<
  85. w := apply(enter,{argl});
  86. if not car w then
  87. return cdr w
  88. else
  89. argl := cdr w
  90. >>;
  91. rl_cid!* := cid;
  92. rl_argl!* := argl;
  93. rl_ocswitches!* := nil;
  94. for each pair in get(rl_cid!*,'rl_cswitches) do <<
  95. rl_ocswitches!* := (car pair . rl_onp car pair) . rl_ocswitches!*;
  96. rl_vonoff(car pair,cdr pair)
  97. >>;
  98. rl_ocswitches!* := reversip rl_ocswitches!*;
  99. rl_updcache();
  100. rmsubs();
  101. return nil
  102. end;
  103. procedure rl_onp(s);
  104. eval intern compress append(explode '!*,explode s);
  105. procedure rl_vonoff(sw,v);
  106. % Verbose [onoff]. [sw] is a switch; [v] is Bool.
  107. if v neq rl_onp sw then <<
  108. lprim {"turned",if rl_onp sw then "off" else "on","switch",sw};
  109. onoff(sw,v)
  110. >>;
  111. procedure rl_updcache();
  112. % Update cache.
  113. <<
  114. for each bbv in rl_bbl!* do
  115. set(bbv,nil);
  116. for each x in get(rl_cid!*,'rl_params) do
  117. set(car x,cdr x);
  118. for each sv in rl_servl!* do
  119. set(sv,nil);
  120. for each x in get(rl_cid!*,'rl_services) do
  121. set(car x,cdr x)
  122. >>;
  123. procedure rl_serviadd(tag,name,value);
  124. rl_sbiadd(tag,'rl_services,name,value);
  125. procedure rl_bbiadd(tag,name,value);
  126. rl_sbiadd(tag,'rl_params,name,value);
  127. procedure rl_sbiadd(tag,prp,name,value);
  128. begin scalar w,al,old;
  129. if not flagp(tag,'rl_package) then
  130. rederr {tag,"is not a context identifier"};
  131. al := get(tag,prp);
  132. w := atsoc(name,al);
  133. if null w then <<
  134. al := (name . value) . al;
  135. put(tag,prp,al);
  136. return nil
  137. >>;
  138. old := cdr w;
  139. cdr w := value;
  140. lprim {"Changed definition of",name};
  141. put(tag,prp,al);
  142. return old
  143. end;
  144. (if w then
  145. rl_deflang!* := {intern compress reversip cdr reversip cdr explode w})
  146. where w=getenv("RLDEFLANG");
  147. if rl_deflang!* then rl_set rl_deflang!*;
  148. endmodule; % [rlcont]
  149. end; % of file