main6.red 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. % MAIN6.RED : Small READ-EVAL-PRINT Loop
  2. % Needs IO, SUB2, SUB3, SUB4, SUB5, SUB6
  3. IN "xxx-header.red"$
  4. IN "PT:STUBS3.RED"$
  5. IN "PT:STUBS4.RED"$
  6. IN "PT:STUBS5.RED"$
  7. IN "PT:STUBS6.RED"$
  8. on syslisp;
  9. Compiletime GLOBAL '(DEBUG !*RAISE !$EOF!$);
  10. Procedure FirstCall;
  11. Begin scalar x, Done, Hcount;
  12. Init();
  13. InitHeap();
  14. InitEval();
  15. Prin2t '"MINI-PSL: A Read-Eval-Print Loop, terminate with Q";
  16. Prin2T '" !*RAISE has been set T";
  17. Prin2T '" Run (TESTSERIES) to check BINDING etc";
  18. LispVar(DEBUG) := 'NIL; % For nice I/O
  19. InitRead();
  20. LispVar(!*RAISE) := 'T; % Upcase Input IDs
  21. LispVar(!$EOF!$) := MKID Char EOF; % Check for EOF
  22. Hcount :=0;
  23. Prin2t " .... Now Call INITCODE";
  24. InitCode();
  25. Prin2t " .... Return from INITCode, Now toploop";
  26. While Not Done do
  27. <<Hcount:=Hcount+1;
  28. Prin2 Hcount; Prin2 '" lisp> ";
  29. x:=READ();
  30. if x eq 'Q then Done := 'T
  31. else if x = !$EOF!$ then
  32. <<Terpri();
  33. Prin2T " **** Top Level EOF **** ">>
  34. else <<Terpri();
  35. x:=EVAL x;
  36. Print x>>;
  37. >>;
  38. Quit;
  39. End;
  40. CompileTime FLUID '(AA);
  41. Procedure TESTSERIES();
  42. Begin
  43. BindingTest();
  44. InterpTest();
  45. CompBindTest();
  46. End;
  47. Procedure BindingTest;
  48. Begin
  49. Dashed "Test BINDING Primitives"$
  50. LispVar(AA):=1;
  51. PBIND1('AA); % Save the 1, insert a NIL
  52. LBIND1('AA,3); % save the NIL, insert a 3
  53. ShouldBe('"3rd bound AA",LispVar(AA),3);
  54. UnBindN 1;
  55. ShouldBe('"2rd bound AA",LispVar(AA),NIL);
  56. UnBindN 1;
  57. ShouldBe('"Original AA",LispVar(AA),1);
  58. End;
  59. Global '(Lambda1 Lambda2 CodeForm!*);
  60. Procedure InterpTest();
  61. Begin
  62. Dashed "TEST of Interpreter Primitives for LAMBDA's ";
  63. Lambda1:='(LAMBDA (X1 X2) (PRINT (LIST 'LAMBDA1 X1 X2)) 'L1);
  64. Lambda2:='(LAMBDA (Y1 Y2) (PRINT (LIST 'LAMBDA2 Y1 Y2)) 'L2);
  65. Spaced "LAMBDA1: "; Print Lambda1;
  66. Dashed "FastLambdaApply on Lambda1";
  67. CodeForm!*:=Lambda1;
  68. ShouldBe("FastLambdaApply", FastLambdaApply(10,20),'L1);
  69. Dashed "Now Test FASTAPPLY";
  70. TestApply(" Compiled ID 1 ", 'Compiled1,'C1);
  71. TestApply(" CodePointer 2 ", GetFcodePointer 'Compiled2,'C2);
  72. TestApply(" Lambda Expression 1 ", Lambda1,'L1);
  73. Dashed "Test a compiled call on Interpreted code ";
  74. PutD('Interpreted3,'Expr,
  75. '(LAMBDA (ag1 ag2 ag3) (Print (list 'Interpreted3 Ag1 Ag2 Ag3)) 'L3));
  76. ShouldBe(" FlambdaLinkP",FlambdaLinkP 'Interpreted3,T);
  77. ShouldBe(" Interp3", Interpreted3(300,310,320),'L3);
  78. PutD('Interpreted2,'Expr,Lambda2);
  79. TestApply(" Interpreted ID 2 ", 'Interpreted2,'L2);
  80. End;
  81. LAP '((!*entry TestFastApply expr 0)
  82. % Args loaded so move to fluid and go
  83. (!*Move (FLUID TestCode!*) (reg t1))
  84. (!*JCALL FastApply));
  85. Procedure TestApply(Msg,Fn,Answer);
  86. Begin scalar x;
  87. Prin2 " Testapply case "; prin2 Msg;
  88. Prin2 " given ";
  89. Print Fn;
  90. TestCode!* := Fn;
  91. x:=TestFastApply('A,'B);
  92. Return ShouldBe(" answer",x,Answer);
  93. End;
  94. Procedure Compiled1(xxx,yyy);
  95. <<Prin2 " Compiled1(";
  96. Prin1 xxx; Prin2 " "; Prin1 yyy; Prin2T ")";
  97. 'C1>>;
  98. Procedure Compiled2(xxx,yyy);
  99. <<Prin2 " Compiled2(";
  100. Prin1 xxx; Prin2 " "; Prin1 yyy; Prin2T ")";
  101. 'C2>>;
  102. CompileTime Fluid '(CFL1 CFL2 CFL3);
  103. Procedure CompBindTest();
  104. Begin
  105. Dashed "Test LAMBIND and PROGBIND in compiled code";
  106. CFL1:='TOP1;
  107. CFL2:='TOP2;
  108. Cbind1('Mid0,'Mid1,'Mid2);
  109. Shouldbe("CFL1",CFL1,'Top1);
  110. Shouldbe("CFL2",CFL2,'Top2);
  111. End;
  112. procedure Cbind1(x,CFL1,CFL2);
  113. Begin
  114. Shouldbe("x ",x ,'Mid0);
  115. Shouldbe("CFL1",CFL1,'Mid1);
  116. Shouldbe("CFL2",CFL2,'Mid2);
  117. Cbind2();
  118. Shouldbe("CFL1",CFL1,'Bot1);
  119. Shouldbe("CFL2",CFL2,'Mid2);
  120. End;
  121. Procedure Cbind2();
  122. Begin
  123. Shouldbe("CFL1",CFL1,'Mid1);
  124. Shouldbe("CFL2",CFL2,'Mid2);
  125. Begin scalar x,CFL2;
  126. CFL1:='Bot1;
  127. CFL2:='Bot2;
  128. Shouldbe("CFL1",CFL1,'Bot1);
  129. Shouldbe("CFL2",CFL2,'Bot2);
  130. End;
  131. Shouldbe("CFL1",CFL1,'Bot1);
  132. Shouldbe("CFL2",CFL2,'Mid2);
  133. End;
  134. End;