+static entity_t *find_typedef(const type_t *type)
+{
+ /* first: search for a matching typedef in the global type... */
+ entity_t *entity = global_scope->entities;
+ for ( ; entity != NULL; entity = entity->base.next) {
+ if (entity->kind != ENTITY_TYPEDEF)
+ continue;
+ if (entity->typedefe.type == type)
+ break;
+ }
+
+ return entity;
+}
+
+static void write_compound_type(const compound_type_t *type)
+{
+ entity_t *entity = find_typedef((const type_t*) type);
+ if(entity != NULL) {
+ fprintf(out, "%s", entity->base.symbol->string);
+ return;
+ }
+
+ /* does the struct have a name? */
+ symbol_t *symbol = type->compound->base.symbol;
+ if(symbol != NULL) {
+ /* TODO: make sure we create a struct for it... */
+ fprintf(out, "%s", symbol->string);
+ return;
+ }
+ /* TODO: create a struct and use its name here... */
+ fprintf(out, "/* TODO anonymous struct */byte");
+}
+
+static void write_enum_type(const enum_type_t *type)
+{
+ entity_t *entity = find_typedef((const type_t*) type);
+ if (entity != NULL) {
+ fprintf(out, "%s", entity->base.symbol->string);
+ return;
+ }
+
+ /* does the enum have a name? */
+ symbol_t *symbol = type->enume->base.symbol;
+ if (symbol != NULL) {
+ /* TODO: make sure we create an enum for it... */
+ fprintf(out, "%s", symbol->string);
+ return;
+ }
+ /* TODO: create a struct and use its name here... */
+ fprintf(out, "/* TODO anonymous enum */byte");
+}
+
+static void write_function_type(const function_type_t *type)
+{
+ fprintf(out, "(func(");
+
+ function_parameter_t *parameter = type->parameters;
+ int first = 1;
+ while(parameter != NULL) {
+ if(!first) {
+ fprintf(out, ", ");
+ } else {
+ first = 0;
+ }
+
+#if 0
+ if(parameter->symbol != NULL) {
+ fprintf(out, "%s : ", parameter->symbol->string);
+ } else {
+ /* TODO make up some unused names (or allow _ in fluffy?) */
+ fprintf(out, "_ : ");
+ }
+#endif
+ fputs("_ : ", out);
+ write_type(parameter->type);
+
+ parameter = parameter->next;
+ }
+
+ fprintf(out, ") : ");
+ write_type(type->return_type);
+ fprintf(out, ")");
+}
+