main4.red 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. % MAIN4.RED : Test Mini reader and function primitives,
  2. % needs IO, SUB2, SUB3 and SUB4
  3. IN "xxx-header.red"$
  4. In "PT:P-function-primitives.red"$
  5. IN "PT:STUBS4.RED"$
  6. IN "PT:STUBS3.RED"$
  7. on syslisp;
  8. Compiletime GLOBAL '(DEBUG);
  9. Procedure FirstCall;
  10. Begin scalar x,s1,s2,s3, Done,D1,D2;
  11. Init();
  12. InitHeap();
  13. LispVar(DEBUG) := 'T; % To get ID stuff out
  14. Dashed "Test EQSTR";
  15. s1:='"AB";
  16. s2:='"Ab";
  17. s3:='"ABC";
  18. ShouldBe("EqStr(AB,AB)",EqStr(s1,s1),'T);
  19. ShouldBe("EqStr(AB,AB)",EqStr(s1,"AB"),'T);
  20. ShouldBe("EqStr(AB,Ab)",EqStr(s1,s2),'NIL);
  21. ShouldBe("EqStr(AB,ABC)",EqStr(s1,s3),'NIL);
  22. Dashed "Test Intern on existing ID's";
  23. ShouldBe("Intern(A)",Intern "A", 'A);
  24. ShouldBe("Intern(AB)",Intern S1, 'AB);
  25. Dashed "Test Intern on new ID, make sure same place";
  26. D1:=Intern S3;
  27. ShouldBe("Intern(ABC)",Intern("ABC"),D1);
  28. D2:=Intern "FOO";
  29. ShouldBe("Intern(ABC) again",Intern("ABC"),D1);
  30. Dashed "Test RATOM loop. Type various ID's, STRING's and INTEGER's";
  31. MoreStuff();
  32. InitRead();
  33. While Not Done do
  34. <<x:=Ratom();
  35. prin2 "Item read=";
  36. Prtitm x;
  37. Print x;
  38. if x eq 'Q then Done := 'T;>>;
  39. LispVar(DEBUG) := 'NIL; % Turn off PRINT
  40. Dashed "Test READ loop. Type various S-expressions";
  41. MoreStuff();
  42. Done:= 'NIL;
  43. While Not Done do
  44. <<x:=READ();
  45. Prin2 '" Item read=";
  46. Prtitm x;
  47. Print x;
  48. if x eq 'Q then Done := 'T;>>;
  49. Functiontest();
  50. Quit;
  51. End;
  52. Procedure MoreStuff;
  53. <<Spaced "Move to next part of test by typing the id Q";
  54. Spaced "Inspect printout carefully">>;
  55. Fluid '(CodePtr!* CodeForm!* CodeNarg!*);
  56. procedure FunctionTest();
  57. Begin scalar c1,c2,ID1,x;
  58. Dashed "Tests of FUNCTION PRIMITIVES ";
  59. ShouldBe("FunBoundP(Compiled1)",FunBoundP 'Compiled1,NIL);
  60. ShouldBe("FunBoundP(ShouldBeUnbound)",FunBoundP 'ShouldBeUnBound,T);
  61. ShouldBe("FCodeP(Compiled1)",FCodeP 'Compiled1,T);
  62. ShouldBe("FCodeP(ShouldBeUnbound)",FcodeP 'ShouldBeUnBound,NIL);
  63. ShouldBe("FCodeP(Compiled2)",FCodeP 'Compiled2,T);
  64. Dashed "Now MakeFunBound";
  65. MakeFunBound('Compiled2);
  66. ShouldBe("FCodeP(Compiled2)",FCodeP 'Compiled2,NIL);
  67. ShouldBe("FUnBoundP(Compiled2)",FUnBoundP 'Compiled2,T);
  68. Dashed "Now copy CODEPTR of Compiled1 to Compiled2 ";
  69. C1:=GetFCodePointer('Compiled1);
  70. C2:=GetFCodePointer('Compiled2);
  71. ShouldBe("CodeP(C1)",CodeP C1,T);
  72. ShouldBe("CodeP(C2)",CodeP C2,NIL);
  73. MakeFcode('Compiled2,C1);
  74. ShouldBe("C1=GetFcodePointer 'Compiled2",
  75. C1=GetFCodePointer 'Compiled2,T);
  76. ShouldBe("Compiled2()",Compiled2(),12345);
  77. Dashed "Now test CodePrimitive";
  78. CodePtr!* := GetFCodePointer 'Compiled3;
  79. X:= CodePrimitive(10,20,30,40);
  80. Shouldbe(" X=1000",1000,X);
  81. Dashed "Test CompiledCallingInterpreted hook";
  82. CompiledCallingInterpreted();
  83. Dashed "Now Create PRETENDINTERPRETIVE";
  84. MakeFlambdaLink 'PretendInterpretive;
  85. Shouldbe("FlambdaLinkP",FlambdaLinkP 'PretendInterpretive,T);
  86. Shouldbe("Fcodep",FCodeP 'PretendInterpretive,NIL);
  87. Shouldbe("FUnBoundP",FUnBoundP 'PretendInterpretive,NIL);
  88. Dashed "Now call PRETENDINTERPRETIVE";
  89. x:=PretendInterpretive(500,600);
  90. ShouldBe("PretendInterpretive",x,1100);
  91. End;
  92. % Auxilliary Compiled routines for CodeTests:
  93. Procedure Compiled1;
  94. << Dotted "Compiled1 called";
  95. 12345>>;
  96. Procedure Compiled2;
  97. << Dotted"Compiled2 called";
  98. 67890>>;
  99. Procedure Compiled3(A1,A2,A3,A4);
  100. <<Dotted "Compiled3 called with 4 arguments , expect 10,20,30,40";
  101. Prin2 " A1=";Prin2T A1;
  102. Prin2 " A2=";Prin2T A2;
  103. Prin2 " A3=";Prin2T A3;
  104. Prin2 " A4=";Prin2T A4;
  105. Prin2t "Now return 1000 to caller";
  106. 1000>>;
  107. syslsp procedure UndefinedFunctionAuxAux ;
  108. Begin scalar FnId;
  109. FnId := MkID UndefnCode!*;
  110. Prin2 "Undefined Function ";
  111. Prin1 FnId;
  112. Prin2 " called with ";
  113. Prin2 LispVar UndefnNarg!*;
  114. prin2T " args from compiled code";
  115. Quit;
  116. End;
  117. % some primitives use by FastApply
  118. syslsp procedure CompiledCallingInterpretedAux();
  119. Begin scalar FnId,Nargs;
  120. Prin2t "COMPILED Calling INTERPRETED";
  121. Prin2 "CODEFORM!*= "; Print LispVar CodeForm!*;
  122. Nargs:=LispVar CodeNarg!*;
  123. FnId := MkID LispVar CodeForm!*;
  124. Prin2 "Function: ";
  125. Prin1 FnId;
  126. Prin2 " called with ";
  127. Prin2 Nargs;
  128. prin2T " args from compiled code";
  129. Return 1100;
  130. End;
  131. Off syslisp;
  132. End;