Add beginnings of subcompiler
This commit is contained in:
parent
3f29732c69
commit
c5e771dcd0
9 changed files with 668 additions and 216 deletions
|
|
@ -1,28 +1,90 @@
|
|||
#include "schema.h"
|
||||
|
||||
struct scope {
|
||||
struct capn_tree hdr;
|
||||
struct scope *enclosing;
|
||||
capn_text name;
|
||||
uint64_t id;
|
||||
};
|
||||
|
||||
struct scope *find_scope(struct scope *s, uint64_t id) {
|
||||
while (s && s->id != id) {
|
||||
s = (struct scope*) s->hdr.link[s->id < id];
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
struct capn_tree *insert_scope(struct capn_tree *root, struct scope *s) {
|
||||
struct capn_tree **x = &root;
|
||||
while (*x) {
|
||||
s->hdr.parent = *x;
|
||||
x = &(*x)->link[((struct scope*)*x)->id < s->id];
|
||||
}
|
||||
*x = &s->hdr;
|
||||
return capn_tree_insert(root, &s->hdr);
|
||||
}
|
||||
|
||||
int main() {
|
||||
struct capn capn;
|
||||
struct CodeGeneratorRequest_ptr root;
|
||||
CodeGeneratorRequest_ptr root;
|
||||
struct CodeGeneratorRequest req;
|
||||
int i;
|
||||
int i, j;
|
||||
|
||||
if (capn_init_fp(&capn, stdin)) {
|
||||
fprintf(stderr, "failed to read schema on input\n");
|
||||
if (capn_init_fp(&capn, stdin, 0)) {
|
||||
fprintf(stderr, "failed to read schema from stdin\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
root.p = capn_root(&capn);
|
||||
read_CodeGeneratorRequest(&root, &req);
|
||||
root.p = capn_get_root(&capn);
|
||||
read_CodeGeneratorRequest(&req, root);
|
||||
|
||||
for (i = 0; i < req.nodes.size; i++) {
|
||||
struct Node_ptr p;
|
||||
struct Node n;
|
||||
p.p = capn_getp(&req.nodes, i);
|
||||
read_Node(&p, &n);
|
||||
for (i = 0; i < req.nodes.p.size; i++) {
|
||||
struct Node N;
|
||||
struct FileNode F;
|
||||
struct StructNode S;
|
||||
struct EnumNode E;
|
||||
struct InterfaceNode I;
|
||||
struct ConstNode C;
|
||||
struct AnnotationNode A;
|
||||
|
||||
get_Node(&N, req.nodes, i);
|
||||
fprintf(stderr, "node %s id:%#llx scope:%#llx type:%d\n",
|
||||
n.displayName.str, n.id, n.scopeId, n.body_tag);
|
||||
N.displayName.str, N.id, N.scopeId, N.body_tag);
|
||||
|
||||
switch (N.body_tag) {
|
||||
case Node_fileNode:
|
||||
read_FileNode(&F, N.body.fileNode);
|
||||
for (j = 0; j < F.imports.p.size; j++) {
|
||||
struct FileNode_Import fi;
|
||||
get_FileNode_Import(&fi, F.imports, j);
|
||||
fprintf(stderr, "\timport %#llx %s\n", fi.id, fi.name.str);
|
||||
}
|
||||
break;
|
||||
case Node_structNode:
|
||||
read_StructNode(&S, N.body.structNode);
|
||||
fprintf(stderr, "\tstruct %d %d %d\n",
|
||||
S.dataSectionWordSize, S.pointerSectionSize, S.preferredListEncoding);
|
||||
for (j = 0; j < S.members.p.size; j++) {
|
||||
}
|
||||
break;
|
||||
case Node_enumNode:
|
||||
read_EnumNode(&E, N.body.enumNode);
|
||||
for (j = 0; j < E.enumerants.p.size; j++) {
|
||||
struct EnumNode_Enumerant ee;
|
||||
get_EnumNode_Enumerant(&ee, E.enumerants, j);
|
||||
fprintf(stderr, "\tenum %d %s %d\n", j, ee.name.str, ee.codeOrder);
|
||||
}
|
||||
break;
|
||||
case Node_interfaceNode:
|
||||
read_InterfaceNode(&I, N.body.interfaceNode);
|
||||
break;
|
||||
case Node_constNode:
|
||||
read_ConstNode(&C, N.body.constNode);
|
||||
break;
|
||||
case Node_annotationNode:
|
||||
read_AnnotationNode(&A, N.body.annotationNode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue