void Codegen_C::write_to( Stream &out ) { on.nsp = 4; make_code(); // include for( String inc : includes ) out << "#include " << inc << "\n"; // types // std::map<Type *,Vec<OutReg *> > orbt; // for( int i = 0; i < out_regs.size(); ++i ) // orbt[ out_regs[ i ].type ] << &out_regs[ i ]; // for( Type *type : types ) // orbt[ type ]; // arythmetic types out << "typedef unsigned char *TPTR;\n"; if ( types.count( ip->type_Bool ) ) out << "typedef bool Bool;\n"; if ( types.count( ip->type_SI8 ) ) out << "typedef signed char SI8;\n"; if ( types.count( ip->type_SI16 ) ) out << "typedef short SI16;\n"; if ( types.count( ip->type_SI32 ) ) out << "typedef int SI32;\n"; if ( types.count( ip->type_SI64 ) ) out << "typedef long long SI64;\n"; if ( types.count( ip->type_PI8 ) ) out << "typedef unsigned char PI8;\n"; if ( types.count( ip->type_PI16 ) ) out << "typedef unsigned short PI16;\n"; if ( types.count( ip->type_PI32 ) ) out << "typedef unsigned int PI32;\n"; if ( types.count( ip->type_PI64 ) ) out << "typedef unsigned long long PI64;\n"; if ( types.count( ip->type_FP32 ) ) out << "typedef float FP32;\n"; if ( types.count( ip->type_FP64 ) ) out << "typedef double FP64;\n"; // specific types for( auto iter : spec_types ) { out << "struct " << iter.second << " { "; out << "unsigned char data[ " << ( iter.first + 7 ) / 8 << " ]; "; out << "};\n"; } // preliminaries for( String prel : preliminaries ) out << prel << "\n"; // out << "int main() {\n"; out << " srand(time(0));\n"; // out_regs // for( auto iter : orbt ) { // if ( iter.second.size() ) { // out << " " << *iter.first << " "; // for( int n = 0; n < iter.second.size(); ++n ) { // if ( n ) // out << ", "; // out << *iter.second[ n ]; // } // out << ";\n"; // } // } out << main_os.str(); out << "}\n"; }
void resolve_derived_copies(CommPtr comm, Read<GO> verts2globs, Int deg, LOs* p_ent_verts2verts, Remotes* p_ents2owners) { auto ev2v = *p_ent_verts2verts; auto ev2vg = unmap(ev2v, verts2globs, 1); auto canon_codes = get_codes_to_canonical(deg, ev2vg); auto ev2v_canon = align_ev2v(deg, ev2v, canon_codes); *p_ent_verts2verts = ev2v_canon; auto ev2vg_canon = align_ev2v(deg, ev2vg, canon_codes); auto e2fv = get_component(ev2v_canon, deg, 0); auto total_verts = find_total_globals(comm, verts2globs); auto v2ov = globals_to_linear_owners(comm, verts2globs, total_verts); auto e2ov = unmap(e2fv, v2ov); auto linsize = linear_partition_size(comm, total_verts); auto in_dist = Dist(comm, e2ov, linsize); auto sev2vg = in_dist.exch(ev2vg_canon, deg); auto out_dist = in_dist.invert(); auto sv2svse = out_dist.roots2items(); auto nse = out_dist.nitems(); auto svse2se = LOs(nse, 0, 1); auto sv2se_codes = Read<I8>(nse, make_code(false, 0, 0)); auto sv2se = Adj(sv2svse, svse2se, sv2se_codes); auto se2fsv = invert_fan(sv2svse); LOs se2ose; Read<I8> se2ose_codes; find_matches_ex(deg, se2fsv, sev2vg, sev2vg, sv2se, &se2ose, &se2ose_codes); auto ose2oe = out_dist.items2dests(); auto se2oe = unmap(se2ose, ose2oe); out_dist.set_roots2items(LOs()); auto e2oe = out_dist.exch(se2oe, 1); *p_ents2owners = e2oe; }
/* * __make_code - Create a code object from string @s. */ static code_t *__make_code(const char *s) { char digits[CODE_DIGITS]; int i = 0; uint32_t addr, val; while (*s) { if (isxdigit(*s)) digits[i++] = *s; s++; } sscanf(digits, "%08X %08X", &addr, &val); return make_code(addr, val, 0); }
// Parse backtick code section or raw backticks, return an inline. // Assumes that the subject has a backtick at the current position. static cmark_node* handle_backticks(subject *subj) { cmark_chunk openticks = take_while(subj, isbacktick); int startpos = subj->pos; int endpos = scan_to_closing_backticks(subj, openticks.len); if (endpos == 0) { // not found subj->pos = startpos; // rewind return make_str(openticks); } else { cmark_strbuf buf = GH_BUF_INIT; cmark_strbuf_set(&buf, subj->input.data + startpos, endpos - startpos - openticks.len); cmark_strbuf_trim(&buf); cmark_strbuf_normalize_whitespace(&buf); return make_code(cmark_chunk_buf_detach(&buf)); } }
void player_plays() /**************************************/ /* Function: player looking for */ /* computer's code */ /**************************************/ { int good_try; char inst, action; int coach, quit; int t; coach = quit = FALSE; format_output("Do you want coaching, y/n [default is n] -> ",1); if ((inst = getchar()) != '\n') while (getchar() != '\n'); if (inst == 'y' || inst == 'Y') coach = TRUE; skipline(1); format_output("Choosing a code for you to guess.\n",1); t = rand() % 3 + 2; sleep(t); make_code(&code); if (JACKPOT == 1) { /* ... mark ... */ /* Mark in order to succeed with the first guess. */ printf(" You must guess: %-8s %-8s %-8s %-8s\n", col[dig[code.pegs[0].color]], col[dig[code.pegs[1].color]], col[dig[code.pegs[2].color]], col[dig[code.pegs[3].color]]); /* ... end mark ... */ } for (cur = 0; cur < MAX_TRY && !game_won;) { if (cur) { good_try = cur + 1; format_output("guess, refresh, print, or quit [default is guess] -> ",1); if ((action = getchar()) != '\n') while (getchar() != '\n'); } else action = 'g'; switch (action) { case 'r': case 'R': /* you want to see your guesses*/ if (cur != 0) { refresh(); break; } case 'q': case 'Q': /* you want to quit*/ end_game(&cur,&quit); break; case 'h': case 'H': /* you need a hint to find the code*/ help(&t); break; case 'p': case 'P': /* you want to have help*/ /*about this menu*/ print_help(); break; default: /* you want to guess*/ play(guesses,&cur,coach); break; } } if (game_won) { if (cur != 1) { format_output(" You broke the code in",0); printf(" %d tries.\n",good_try); skipline(1); format_output(" FREE GAME - PLAY AGAIN\n",0); } else { system("/usr/5bin/banner \" JACKPOT\""); } print_score_player(good_try); } else if (!quit) { skipline(1); format_output("Sorry. You've run out of guesses.\n",1); /* display the correct code*/ format_output(" The correct code was:",1); printf(" %-8s %-8s %-8s %-8s\n", col[dig[code.pegs[0].color]], col[dig[code.pegs[1].color]], col[dig[code.pegs[2].color]], col[dig[code.pegs[3].color]]); } else format_output("Was that too tough for you? I'll be nicer next time.\n",1); }