main4.red 4.4 KB

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