+ dprintf(fd, "const %s %s = ", cnst->type->name, cnst->name);
+ if (cnst->val->type == PSI_T_QUOTED_STRING) {
+ dprintf(fd, "\"%s\";\n", cnst->val->text);
+ } else {
+ dprintf(fd, "%s;\n", cnst->val->text);
+ }
+ }
+ dprintf(fd, "\n");
+ }
+ if (C->decls) {
+ for (i = 0; i < C->decls->count; ++i) {
+ decl *decl = C->decls->list[i];
+
+ dprintf(fd, "%s ", decl->abi->convention);
+ dump_decl_arg(fd, decl->func);
+ dprintf(fd, "(");
+ if (decl->args) for (j = 0; j < decl->args->count; ++j) {
+ if (j) {
+ dprintf(fd, ", ");
+ }
+ dump_decl_arg(fd, decl->args->args[j]);
+ }
+ dprintf(fd, ");\n");
+ }
+ dprintf(fd, "\n");
+ }
+ if (C->impls) {
+ for (i = 0; i < C->impls->count; ++i) {
+ impl *impl = C->impls->list[i];
+
+ dprintf(fd, "function %s(", impl->func->name);
+ if (impl->func->args) for (j = 0; j < impl->func->args->count; ++j) {
+ impl_arg *iarg = impl->func->args->args[j];
+
+ dprintf(fd, "%s%s %s$%s",
+ j ? ", " : "",
+ iarg->type->name,
+ iarg->var->reference ? "&" : "",
+ iarg->var->name);
+ if (iarg->def) {
+ dprintf(fd, " = %s", iarg->def->text);
+ }
+ }
+ dprintf(fd, ") : %s%s {\n",
+ impl->func->return_reference ? "&":"",
+ impl->func->return_type->name);
+ if (impl->stmts) {
+ for (j = 0; j < impl->stmts->let.count; ++j) {
+ let_stmt *let = impl->stmts->let.list[j];
+
+ dprintf(fd, "\tlet %s", let->var->name);
+ if (let->val) {
+ dprintf(fd, " = %s", let->val->is_reference ? "&" : "");
+ if (let->val->func) {
+ dprintf(fd, "%s(", let->val->func->name);
+ if (let->val->func->alloc) {
+ dprintf(fd, "%zu, ", let->val->func->alloc->n);
+ dump_decl_type(fd, let->val->func->alloc->type);
+ } else {
+ dprintf(fd, "$%s", let->val->var->name);
+ }
+ dprintf(fd, ");\n");
+ } else {
+ dprintf(fd, "NULL;\n");
+ }
+ }
+ }
+ for (j = 0; j < impl->stmts->ret.count; ++j) {
+ return_stmt *ret = impl->stmts->ret.list[j];
+
+ dprintf(fd, "\treturn ");
+ dump_impl_set_value(fd, ret->set, 1);
+ }
+ for (j = 0; j < impl->stmts->set.count; ++j) {
+ set_stmt *set = impl->stmts->set.list[j];
+
+ dprintf(fd, "\tset $%s = ", set->var->name);
+ dump_impl_set_value(fd, set->val, 1);
+ }
+ for (j = 0; j < impl->stmts->fre.count; ++j) {
+ free_stmt *fre = impl->stmts->fre.list[j];
+
+ dprintf(fd, "\tfree ");
+ for (k = 0; k < fre->calls->count; ++k) {
+ free_call *call = fre->calls->list[k];
+
+ if (k) {
+ dprintf(fd, ", ");
+ }
+ dprintf(fd, "%s(", call->func);
+ for (l = 0; l < call->vars->count; ++l) {
+ decl_var *fvar = call->vars->vars[l];
+
+ dump_decl_var(fd, fvar);
+ }
+ dprintf(fd, ");\n");
+ }
+ }
+ }
+ dprintf(fd, "}\n");
+ }
+ dprintf(fd, "\n");
+ }