main6.red 4.4 KB

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