commit ffc9d113e722f27996752dae2d98256c86590943
parent 8f879a25878c593360b648124ca61e223b35a55c
Author: Tomas Hlavaty <tom@logand.com>
Date: Fri, 16 Mar 2012 07:30:09 +0100
uno symbols have identity
Diffstat:
M | unoidl2.c | | | 100 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- |
M | unoidl2.h | | | 1 | + |
M | unoidl2ast.c | | | 31 | ++++++++++++++++++++++++++----- |
3 files changed, 126 insertions(+), 6 deletions(-)
diff --git a/unoidl2.c b/unoidl2.c
@@ -27,7 +27,7 @@
#define NCHARA 256
struct any {
- enum {CONS, TOKEN, INUM, CHARA} tag;
+ enum {CONS, TOKEN, INUM, CHARA, SYMB} tag;
union {
struct {
struct any *car;
@@ -179,6 +179,17 @@ void print_sym1(Any x) {
}
}
+void print_sym2(Any x) {
+ Any kpv = car(x);
+ if(NIL != kpv) {
+ Any k = car(kpv);
+ Any p = cadr(kpv);
+ print_sym2(p);
+ if(NIL != car(p)) printf(".");
+ print_sym1(k);
+ }
+}
+
Any print(Any x) {
if(NIL == x)
printf("NIL");
@@ -208,6 +219,9 @@ Any print(Any x) {
case CHARA:
printf("%c", x->u.inum);
break;
+ case SYMB:
+ print_sym2(x);
+ break;
/* default: error? */
}
return x;
@@ -248,6 +262,88 @@ Any mk_relative(Any x) {
//return cons(mk(RELATIVE, "relative"), $1);
}
+static Any intern2rel(Any k, Any p) {
+ Any r = find(k, cdr(p), equal, caar);
+ if(NIL == r) {
+ con(p, cons(r = list1(list2(k, p)), cdr(p)));
+ r->tag = SYMB;
+ }
+ return r;
+}
+
+Any root2;
+
+static Any intern2abs(Any x) {
+ Any p = root2;
+ for(; NIL != x; x = cdr(x))
+ p = intern2rel(sym1(car(x)), p);
+ return p;
+}
+
+static Any get2(Any x) {return cddr(car(x));}
+static Any set2(Any x, Any v) {return con(cdr(car(x)), v);}
+
+static Any module2;
+
+static void run1_module(Any x) {
+ Any p = module2;
+ module2 = intern2rel(sym1(cadr(x)), p);
+ Any v = get2(module2);
+ if(NIL == v)
+ set2(module2, car(x));
+ mapc(NULL, run1, cddr(x));
+ module2 = p;
+}
+
+static Any subst2(void *env, Any x) {
+ Any y;
+ if(consp(x)) {
+ switch(kind(car(x))) {
+ case RELATIVE: //(relative XInterface)
+ y = cdr(x);
+ set(y, intern2rel(sym1(car(y)), module2));
+ break;
+ case ABSOLUTE: //(absolute com sun star uno XInterface)
+ y = cdr(x);
+ set(y, intern2abs(y));
+ con(y, NIL);
+ break;
+ default:
+ mapc(NULL, subst2, x);
+ }
+ }
+ return x;
+}
+
+static void run1_leave(Any x) {
+ Any s = intern2rel(sym1(cadr(x)), module2);
+ if(NIL != get2(s))
+ printf("@@@ run1_leave error: duplicate ");
+ set(cdr(x), s);
+ set2(s, subst2(NULL, x));
+}
+
+Any run1(void *env, Any x) {
+ switch(kind(car(x))) {
+ case MODULE: run1_module(x); break;
+ case DEFINTERFACE:
+ case EXCEPTION:
+ case ENUM:
+ case SERVICE:
+ case STRUCT:
+ case CONSTANTS:
+ case SINGLETON:
+ case TYPEDEF:
+ case DEFTEMPLATE: run1_leave(x); break;
+ case INTERFACE: break; // TODO eg XMultiComponentFactory?
+ default:
+ printf("@@@ run1 error: ");
+ print(x);
+ printf("\n");
+ }
+ return x;
+}
+
void init() {
heap = calloc(HSIZE, sizeof(struct any));
NIL = xalloc();
@@ -264,4 +360,6 @@ void init() {
T->tag = TOKEN;
T->u.t.kind = 0;
T->u.t.sym1 = intern1("T");
+ root2 = list1(NIL);
+ module2 = root2;
}
diff --git a/unoidl2.h b/unoidl2.h
@@ -65,4 +65,5 @@ Any mapc(void *env, Any (*fn)(void *env, Any e), Any x);
Any find(Any elt, Any lst, Fn2 cmp, Fn1 key);
Any reverse(Any x, Any a);
Any id(Any x);
+Any run1(void *env, Any x);
void init();
diff --git a/unoidl2ast.c b/unoidl2ast.c
@@ -26,17 +26,38 @@ extern int yyparse();
extern const Any NIL;
extern const Any ast;
-static void pr_all(Any x) {
- for(; NIL != x; x = cdr(x)) {
- print(car(x));
- printf("\n\n");
+static Any pr1(void *env, Any x) {
+ print(x);
+ printf("\n\n");
+}
+
+static Any print2cell(void *env, Any x) {
+ Any c = cdr(x);
+ Any kpv = car(x);
+ Any k = car(kpv);
+ Any p = cadr(kpv);
+ Any v = cddr(kpv);
+ if(NIL == v) {
+ mapc(NULL, print2cell, c);
+ } else if(MODULE == kind(v)) {
+ mapc(NULL, print2cell, c);
+ } else if(NIL == c) {
+ print(v);
+ } else {
+ printf("@@@ print2cell error: unexpected children\n");
+ print(x);
}
+ return x;
}
+extern const Any root2;
+
int main() {
init();
yyparse();
- pr_all(ast);
+ //mapc(NULL, pr1, ast);
+ mapc(NULL, run1, ast);
+ print2cell(NULL, root2);
//print(ast);
//printf("\n");
return 0;