+static declaration_t *find_typedef(const type_t *type)
+{
+ /* first: search for a matching typedef in the global type... */
+ declaration_t *declaration = global_scope->declarations;
+ while(declaration != NULL) {
+ if(! (declaration->storage_class == STORAGE_CLASS_TYPEDEF)) {
+ declaration = declaration->next;
+ continue;
+ }
+ if(declaration->type == type)
+ break;
+ declaration = declaration->next;
+ }
+
+ return declaration;
+}
+
+static void write_compound_type(const compound_type_t *type)
+{
+ declaration_t *declaration = find_typedef((const type_t*) type);
+ if(declaration != NULL) {
+ fprintf(out, "%s", declaration->symbol->string);
+ return;
+ }
+
+ /* does the struct have a name? */
+ symbol_t *symbol = type->declaration->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)
+{
+ declaration_t *declaration = find_typedef((const type_t*) type);
+ if(declaration != NULL) {
+ fprintf(out, "%s", declaration->symbol->string);
+ return;
+ }
+
+ /* does the enum have a name? */
+ symbol_t *symbol = type->declaration->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, ")");
+}
+