Annotation of OpenXM/src/k097/object.kk, Revision 1.5
1.5 ! takayama 1: /* $OpenXM: OpenXM/src/k097/object.kk,v 1.4 2001/01/08 05:26:49 takayama Exp $ */
1.1 maekawa 2: /* object.kk , 1997, 4/11. */
3: Protect("showln",0);
4:
5: class Object extends PrimitiveObject {
1.5 ! takayama 6: local ;
1.1 maekawa 7: def new0() {
8: return(Object);
9: }
10: def showln() {
11: Println(this);
12: }
13: def getClass() {
14: sm1(" this 0 get /FunctionValue set ");
15: }
16: }
17:
18: sm1(" /ectag { dup isClass not { pop -1 } { lc } ifelse } def ");
19: def k00ecTag(a) { sm1(a," ectag /FunctionValue set "); }
20: def IsObject(a) {
21: if (!IsArray(a)) return(false);
22: if (Length(a) < 1) return(false);
23: if (k00ecTag(a[0]) == k00ecTag(Object[0])) return(true);
24: else return(false);
25: }
1.4 takayama 26: HelpAdd(["IsObject",
27: ["IsObject(<<a>>) return true if a is an Object."],
28: ["a"],
29: ["Tag"],
30: "check if a given object is primitive or not."
31: ]);
1.1 maekawa 32:
33:
34:
35: /* class Gmp. Number theoretic functions.
36: 1997, 4/17
37: */
38: class Gmp extends Object {
1.5 ! takayama 39: local ;
1.1 maekawa 40: def BitAnd(a,b) {
41: sm1("[(and) ",a," ",b," ] mpzext /FunctionValue set ");
42: }
43: def BitOr(a,b) {
44: sm1("[(ior) ",a," ",b," ] mpzext /FunctionValue set ");
45: }
46: def ModuloPower(base,ex,mmod) {
47: sm1("[(powm) ",base," ",ex," ",mmod," ] mpzext /FunctionValue set ");
48: }
49: def ProbabilisticPrimeP(p,reps) {
50: sm1("[(probab_prime_p) ",p," ",reps," ] mpzext /FunctionValue set ");
51: }
52: def Sqrt(a) {
53: sm1("[(sqrt) ",a, " ] mpzext /FunctionValue set ");
54: }
55: def Gcd(a,b) {
56: sm1("[(gcd) ",a," ",b," ] mpzext /FunctionValue set ");
57: }
58: def Div(a,b) {
59: sm1("[(tdiv_qr) ",a," ",b," ] mpzext /FunctionValue set ");
60: }
61: def Mod(a,b) {
62: sm1("[(tdiv_qr) ",a," ",b," ] mpzext 1 get /FunctionValue set ");
63: }
64: }
65:
66: HelpAdd(["Gmp.",
67: ["Gmp is a class which supports the following methods:",
68: "BitAnd, BitOr, ModuloPower, ProbabilisticPrimeP, Sqrt,",
69: "Gcd, Div, Mod.",
1.3 takayama 70: "These methods call functions of GNU MP package.",
71: "Note that there is no method to create an instance.",
72: "Ex. r = Gmp.Gcd(5,8); "
1.4 takayama 73: ],
74: null,
75: null,
76: "class Gmp"
77: ]);
78:
79: class Stderr extends Object {
1.5 ! takayama 80: local ;
1.4 takayama 81: def Print(s) {
82: s = ToString(s);
83: if (!Boundp("Stderr_fd")) {
84: sm1(" [37 (string) dc (stderr)] cat (w) file /Stderr_fd set ");
85: }
86: sm1(" Stderr_fd s writestring ");
87: }
88: def Println(s) {
89: Print(s); Ln();
90: }
91: def Ln() {
92: if (!Boundp("Stderr_fd")) {
93: sm1(" [37 (string) dc (stderr)] cat (w) file /Stderr_fd set ");
94: }
95: sm1(" Stderr_fd 10 (string) dc writestring ");
96: }
97: def Flush() {
98: sm1(" [(flush)] extension ");
99: }
100: }
1.1 maekawa 101:
1.4 takayama 102: HelpAdd(["Stderr.",
103: ["Stderr is a class which supports printing to stderr.",
104: "Methods are Print, Println, Ln, Flush.",
105: "Stderr_fd is a global variable to save a file descriptor."
106: ],
107: null,
108: null,
109: "class Stderr"
110: ]);
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>