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