Annotation of OpenXM/src/kan96xx/Kan/kclass.c, Revision 1.3
1.3 ! takayama 1: /* $OpenXM: OpenXM/src/kan96xx/Kan/kclass.c,v 1.2 2000/01/16 07:55:39 takayama Exp $ */
1.1 maekawa 2: /* kclass.c, 1997, 3/1
3: This module handles class data base.
4: This is a top level and provides an interface for sm1 for Sclass objects.
5: Main processing is done in Kclass/*
6: See, Kclass/sample.h, Kclass/sample.c ;
7: grep the keyword CLASSNAME_sampleClass
8: */
9: #include <stdio.h>
10: #include "datatype.h"
11: #include "stackm.h"
12: #include "extern.h"
13: #include "gradedset.h"
14: #include "extern2.h"
15: #include "kclass.h"
16:
17: #define CLASSTABLE_SIZE 4096
18:
19:
20: struct object * ClassDictionaries[CLASSTABLE_SIZE];
21: char *ClassNames[CLASSTABLE_SIZE];
22: int ClassTypes[CLASSTABLE_SIZE];
23:
24: initClassDataBase() {
25: int i;
26: for (i=0; i<CLASSTABLE_SIZE; i++) {
27: ClassTypes[i] = CLASS_NOT_USED;
28: }
29: /* Initialize CLASS_INTERNAL */
30: ClassTypes[CLASSNAME_OPERANDSTACK] = CLASS_INTERNAL;
31: ClassNames[CLASSNAME_OPERANDSTACK] = "Class.OperandStack";
32: ClassDictionaries[CLASSNAME_OPERANDSTACK] = (struct object *)NULL;
33: /* We have to creat new dictionary in a future. */
34:
35: ClassTypes[CLASSNAME_ERROR_PACKET] = CLASS_OBJ;
36: ClassNames[CLASSNAME_ERROR_PACKET] = "Class.ErrorPacket";
37: ClassDictionaries[CLASSNAME_ERROR_PACKET] = (struct object *)NULL;
38: /* We have to creat new dictionary in a future. */
39:
40: ClassTypes[CLASSNAME_CONTEXT] = CLASS_INTERNAL;
41: ClassNames[CLASSNAME_CONTEXT] = "Class.Context";
42: ClassDictionaries[CLASSNAME_CONTEXT] = (struct object *)NULL;
43: /* We have to creat new dictionary in a future. */
44:
45: ClassTypes[CLASSNAME_GradedPolySet] = CLASS_INTERNAL;
46: ClassNames[CLASSNAME_GradedPolySet] = "Class.GradedPolySet";
47: ClassDictionaries[CLASSNAME_GradedPolySet] = (struct object *)NULL;
48: /* We have to creat new dictionary in a future. */
49:
50: ClassTypes[CLASSNAME_mathcap] = CLASS_OBJ;
51: ClassNames[CLASSNAME_mathcap] = "Class.mathcap";
52: ClassDictionaries[CLASSNAME_mathcap] = (struct object *)NULL;
53: /* We have to creat new dictionary in a future. */
54:
55: ClassTypes[CLASSNAME_CMO] = CLASS_OBJ;
56: ClassNames[CLASSNAME_CMO] = "Class.CMO";
57: ClassDictionaries[CLASSNAME_CMO] = (struct object *)NULL;
58: /* We have to creat new dictionary in a future. */
59:
60: ClassTypes[CLASSNAME_indeterminate] = CLASS_OBJ;
61: ClassNames[CLASSNAME_indeterminate] = "Class.indeterminate";
62: ClassDictionaries[CLASSNAME_indeterminate] = (struct object *)NULL;
63:
64: ClassTypes[CLASSNAME_tree] = CLASS_OBJ;
65: ClassNames[CLASSNAME_tree] = "Class.tree";
66: ClassDictionaries[CLASSNAME_tree] = (struct object *)NULL;
67:
68: ClassTypes[CLASSNAME_recursivePolynomial] = CLASS_OBJ;
69: ClassNames[CLASSNAME_recursivePolynomial] = "Class.recursivePolynomial";
70: ClassDictionaries[CLASSNAME_recursivePolynomial] = (struct object *)NULL;
71:
72: ClassTypes[CLASSNAME_polynomialInOneVariable] = CLASS_OBJ;
73: ClassNames[CLASSNAME_polynomialInOneVariable] = "Class.polynomialInOneVariable";
74: ClassDictionaries[CLASSNAME_polynomialInOneVariable] = (struct object *)NULL;
75:
76: ClassTypes[CLASSNAME_sampleClass] = CLASS_OBJ;
77: ClassNames[CLASSNAME_sampleClass] = "Class.sampleClass";
78: ClassDictionaries[CLASSNAME_sampleClass] = (struct object *)NULL;
79: /* We have to creat new dictionary in a future. */
80:
81: }
82:
83:
84: void fprintClass(FILE *fp,struct object obj) {
85: int tag;
86: tag = ectag(obj);
87: if (tag == -1) {
88: return ;
89: }
90: if (ClassTypes[tag] != CLASS_NOT_USED) {
91: fprintf(fp,"%s ",ClassNames[tag]);
92: }
93: switch(tag) {
94: case CLASSNAME_OPERANDSTACK:
95: break;
96: case CLASSNAME_ERROR_PACKET:
97: fprintErrorPacket(fp,KopErrorPacket(obj));
98: break;
99: case CLASSNAME_CONTEXT:
100: fprintContext(fp,KopContext(obj));
101: break;
102: case CLASSNAME_GradedPolySet:
103: outputGradedPolySet(KopGradedPolySet(obj),0);
104: break;
105: case CLASSNAME_mathcap:
106: fprintMathCap(fp,KopMathCap(obj));
107: break;
108: case CLASSNAME_CMO:
109: fprintCMOClass(fp,obj);
110: break;
111: case CLASSNAME_indeterminate:
112: fprintIndeterminate(fp,obj);
113: break;
114: case CLASSNAME_tree:
115: fprintTree(fp,obj);
116: break;
117: case CLASSNAME_recursivePolynomial:
118: fprintRecursivePolynomial(fp,obj);
119: break;
120: case CLASSNAME_polynomialInOneVariable:
121: fprintPolynomialInOneVariable(fp,obj);
122: break;
123: case CLASSNAME_sampleClass:
124: fprintSampleClass(fp,KopSampleClass(obj));
125: break;
126: default:
127: fprintf(fp,"Unknown class tag=%d.\n",tag);
128: break;
129: }
130: }
131:
132: int KclassEqualQ(struct object ob1,struct object ob2) {
133: if (ectag(ob1) != ectag(ob2)) return(0);
134: switch(ectag(ob1)) {
135: case CLASSNAME_OPERANDSTACK:
136: case CLASSNAME_CONTEXT:
137: if (ecbody(ob1) == ecbody(ob2)) return(1);
138: else return(0);
139: break;
140: case CLASSNAME_sampleClass:
141: return(eqSampleClass(KopSampleClass(ob1),KopSampleClass(ob2)));
142: break;
1.3 ! takayama 143: case CLASSNAME_indeterminate:
! 144: return(KooEqualQ(KopIndeterminate(ob1),KopIndeterminate(ob2)));
! 145: break;
1.1 maekawa 146: default:
147: errorKan1("%s\n","kclass.c (KclassEqualQ cannot compare these objects.)");
148: break;
149: }
150: }
151:
152: void fprintErrorPacket(FILE *fp,struct object *op)
153: {
154: printObject(*op,0,fp);
155: }
156:
157: void fprintMathCap(FILE *fp,struct object *op)
158: {
159: printObject(*op,0,fp);
160: }
161:
162: struct object KpoMathCap(struct object *obp) {
163: struct object rob;
164: struct object *newobp;
165:
166: newobp = (struct object *) sGC_malloc(sizeof(struct object));
167: /* Yes! You can call KpoMathCap(&localVar) */
168: if (newobp == NULL) errorKan1("%s\n","kclass.c, no more memory.");
169: *newobp = *obp;
170:
171: rob.tag = Sclass;
172: rob.lc.ival = CLASSNAME_mathcap;
173: rob.rc.voidp = newobp;
174: return(rob);
175: }
176:
177: /* try
178: [ 1 2 3] [(class) (sampleClass)] dc ::
179: */
180: struct object KclassDataConversion(struct object ob1,struct object ob2)
181: { /* It is called from primitive.c data_conversion. */
182: /* This function handles the following situnation.
183: (This is not yet documented.)
184: ob1 [(class) (class-name)] dc : method=1
185: ob1(with class tag) [(class) (class-name)] dc : method=2
186: ob1(with class tag) (usual flag) dc : method=3
187: It also create a new class object.
188: */
189: struct object rob = NullObject;
190: int method ;
191: struct object ff0;
192: struct object ff1;
193: struct object ob3; /* for work.*/
194: struct object ob4;
195: char *ccc;
196: char *key;
197:
198: if (ob1.tag == Sclass && ob2.tag == Sarray) {
199: method = 2;
200: }else if (ob1.tag == Sclass && ob2.tag == Sdollar) {
201: method = 3;
202: }else if (ob1.tag != Sclass && ob2.tag == Sarray) {
203: method = 1;
204: }else{
205: errorKan1("%s\n","kclass.c : KclassDataConversion() cannot make this data conversion.");
206: }
207: switch(method) {
208: case 1:
209: if (getoaSize(ob2) != 2) errorKan1("%s\n","kclass.c : KclassDataConversion() the second argument should be [(class) (class-name)]");
210: ff0 = getoa(ob2,0); ff1 = getoa(ob2,1);
211: if (ff0.tag != Sdollar || ff1.tag != Sdollar)
212: errorKan1("%s\n","kclass.c : KclassDataConversion() the second argument should be [(class) (class-name)]");
213: if (strcmp("class",KopString(ff0)) != 0)
214: errorKan1("%s\n","kclass.c : KclassDataConversion() the second argument should be [(class) (class-name)] (class)!!!");
215:
216: ccc = KopString(ff1); /* target data type */
217:
218: /* From primitive to Class object */
219:
220: if (strcmp(ccc,"sampleClass") == 0) {
221: rob = KpoSampleClass(&ob1);
222: }else if (strcmp(ccc,"errorPacket") == 0) {
223: if (ob1.tag != Sarray) errorKan1("%s\n","kclass.c : KclassDataConversion , !array --> errorPacket is not supported.");
224: if (getoaSize(ob1) != 3) errorKan1("%s\n","kclass.c : KclassDataConversion , only [integer, integer, string] --> errorPacket is supported.");
225: if (getoa(ob1,0).tag != Sinteger) errorKan1("%s\n","kclass.c : KclassDataConversion , only [integer, integer, string] --> errorPacket is supported.");
226: if (getoa(ob1,1).tag != Sinteger) errorKan1("%s\n","kclass.c : KclassDataConversion , only [integer, integer, string] --> errorPacket is supported.");
227: if (getoa(ob1,2).tag != Sdollar) errorKan1("%s\n","kclass.c : KclassDataConversion , only [integer, integer, string] --> errorPacket is supported.");
228: rob = KnewErrorPacketObj(ob1);
229: }else if (strcmp(ccc,"indeterminate") == 0) {
230: if (ob1.tag != Sdollar) errorKan1("%s\n","kclass.c : KclassDataConversion , !String --> indeterminate is not supported.");
231: rob = KpoIndeterminate(ob1);
232: }else if (strcmp(ccc,"mathcap") == 0) {
233: /* You should check ob1 contains mathcap data or not.
234: I've not yet written them.
235: */
236: rob = KpoMathCap(&ob1);
237: }else if (strcmp(ccc,"tree") == 0) {
1.3 ! takayama 238: if (ob1.tag != Sarray) errorKan1("%s\n","kclass.c : KclassDataConversion , !array --> tree is not supported.");
1.1 maekawa 239: rob = KpoTree(ob1);
240: }else if (strcmp(ccc,"recursivePolynomial") == 0) {
241: if (ob1.tag != Spoly) errorKan1("%s\n","kclass.c : KclassDataConversion , !poly --> recursivePoly is not supported.");
242: rob = polyToRecursivePoly(ob1);
243: }else{
244: errorKan1("%s\n","KclassDataConversion: this type of data conversion from primitive object to class object is not supported.");
245: }
246: break;
247: case 2:
248: if (getoaSize(ob2) != 2) errorKan1("%s\n","kclass.c : KclassDataConversion() the second argument should be [(class) (class-name)]");
249: ff0 = getoa(ob2,0); ff1 = getoa(ob2,1);
250: if (ff0.tag != Sdollar || ff1.tag != Sdollar)
251: errorKan1("%s\n","kclass.c : KclassDataConversion() the second argument should be [(class) (class-name)]");
252: if (strcmp("class",KopString(ff0)) != 0)
253: errorKan1("%s\n","kclass.c : KclassDataConversion() the second argument should be [(class) (class-name)] (class)!!!");
254:
255: ccc = KopString(ff1); /* target data type. */
256: switch(ectag(ob1)) {
257: case CLASSNAME_sampleClass:
258: if (strcmp(ccc,"sampleClass") == 0) {
259: rob = KpoSampleClass(&ob1);
260: }else{
261: errorKan1("%s\n","KclassDataCOnversion: this type of data conversion from class object to class object is not supported.");
262: }
263: break;
264: default:
265: errorKan1("%s\n","KclassDataConversion: this type of data conversion from class object to class object is not supported.");
266: }
267: break;
268: case 3:
269: key = KopString(ob2); /* target data type */
270: if (key[0] == 't' || key[0] =='e') {
271: if (strcmp(key,"type?")==0) {
272: rob = KpoInteger(ob1.tag);
273: return(rob);
274: }else if (strcmp(key,"type??")==0) {
275: if (ob1.tag != Sclass) {
276: rob = KpoInteger(ob1.tag);
277: }else {
278: rob = KpoInteger(ectag(ob1));
279: }
280: return(rob);
281: }else if (strcmp(key,"error")==0) {
282: rob = KnewErrorPacketObj(ob1);
283: return(rob);
284: }
285: }
286:
287: /* Class object to primtive Object */
288: switch(ectag(ob1)) {
289: case CLASSNAME_sampleClass:
290: if (strcmp(key,"array") == 0) {
291: rob = *(KopSampleClass(ob1));
292: }else{
293: errorKan1("%s\n","KclassDataCOnversion: this type of data conversion from class object to primitive object is not supported.");
294: }
295: break;
296: case CLASSNAME_mathcap:
297: if (strcmp(key,"array") == 0) {
298: rob = newObjectArray(2);
299: ob3 = KpoString("mathcap-object");
300: putoa(rob,0,ob3);
301: putoa(rob,1,*(KopMathCap(ob1)));
302: }else{
303: errorKan1("%s\n","KclassDataConversion: this type of data conversion from class object mathcap to primitive object is not supported.");
304: }
305: break;
306: case CLASSNAME_indeterminate:
307: if (strcmp(key,"string") == 0) {
308: rob = KopIndeterminate(ob1);
309: }else {
310: errorKan1("%s\n","KclassDataConversion: interminate-->?? is not supported..");
311: }
312: break;
313: case CLASSNAME_tree:
314: if (strcmp(key,"array") == 0) {
315: rob = KopTree(ob1);
316: }else {
317: errorKan1("%s\n","KclassDataConversion: tree-->?? is not supported..");
318: }
319: break;
320: case CLASSNAME_recursivePolynomial:
321: if (strcmp(key,"string") == 0) {
322: errorKan1("%s\n","Translation of recursive polynomial to a string should be implemented.");
323: }else if (strcmp(key,"poly") == 0) {
324: rob = recursivePolyToPoly(ob1);
325: }else if (strcmp(key,"array") == 0) {
326: rob = KopRecursivePolynomial(ob1);
327: }else {
328: errorKan1("%s\n","KclassDataConversion: recursivePoly-->?? is not supported..");
329: }
330: break;
331: default:
332: errorKan1("%s\n","KclassDataConversion: this type of data conversion from class object to primitive object is not supported.");
333: }
334: break;
335: }
336: return(rob);
337: }
338:
339: /* Arithmetic operations for class objects. */
340: struct object Kclass_ooAdd(struct object ob1, struct object ob2)
341: {
342: /* It is called from ooAdd(). */
343: /* ob1 or ob2 must have the class tag. */
344: struct object rob = NullObject;
345:
346: /* Default action */
347: rob = addTree(ob2,ob1);
348: return(rob);
349: }
350:
351:
352:
353:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>