static void continue_prepare(struct compile_and_run_frame *frame) { value closure; struct global_state *gcopy; if (mprepare_load_next_start(&frame->ps)) return; mprepare_vars(&frame->ps); gcopy = copy_global_state(frame->ps.ccontext->gstate); GCPRO1(gcopy); closure = compile_code(frame->ps.ccontext->gstate, frame->f->body); GCPOP(1); if (closure) { GCPRO1(closure); if (debug_lvl > 1) output_value(muderr, prt_examine, closure); frame->state = running; if (frame->dontrun) { /* Just leave the closure itself as the result */ stack_reserve(sizeof(value)); stack_push(closure); } else push_closure(closure, 0); GCPOP(1); return; } global_set(frame->ps.ccontext->gstate, gcopy); runtime_error(error_compile_error); }
static bool output_array(uint8_t *source, uint8_t *sourcelimit, dynbuffer_t *dest) { int index=0; dynbuffer_append_byte(dest, '['); while (source<sourcelimit) { /* decode type length */ uint8_t typecode; uint8_t *data; uint32_t datalen; if (!extract_type_length(source, sourcelimit, &typecode, &data, &datalen)) return false; /* comma */ if (index>0) dynbuffer_append_byte(dest, ','); /* output value */ source=data+datalen; if (!output_value(data, source, typecode, dest)) return false; index++; } dynbuffer_append_byte(dest, ']'); return true; }
/*LOCAL*/static void create_colormap (j_decompress_ptr cinfo) { my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize; JSAMPARRAY colormap; /* Created colormap */ int total_colors; /* Number of distinct output colors */ int i, j, k, nci, blksize, blkdist, ptr, val; /* Select number of colors for each component */ total_colors = select_ncolors(cinfo, cquantize->Ncolors); /* Report selected color counts */ if (cinfo->out_color_components == 3) { TRACEMS4(cinfo, 1, JTRC_QUANT_3_NCOLORS, total_colors, cquantize->Ncolors[0], cquantize->Ncolors[1], cquantize->Ncolors[2]); } else { TRACEMS1(cinfo, 1, JTRC_QUANT_NCOLORS, total_colors); } /* Allocate and fill in the colormap. */ /* The colors are ordered in the map in standard row-major order, */ /* i.e. rightmost (highest-indexed) color changes most rapidly. */ colormap = (*cinfo->mem->alloc_sarray) ((j_common_ptr) cinfo, JPOOL_IMAGE, (JDIMENSION) total_colors, (JDIMENSION) cinfo->out_color_components); /* blksize is number of adjacent repeated entries for a component */ /* blkdist is distance between groups of identical entries for a component */ blkdist = total_colors; for (i = 0; i < cinfo->out_color_components; i++) { /* fill in colormap entries for i'th color component */ nci = cquantize->Ncolors[i]; /* # of distinct values for this color */ blksize = blkdist / nci; for (j = 0; j < nci; j++) { /* Compute j'th output value (out of nci) for component */ val = output_value(cinfo, i, j, nci-1); /* Fill in all colormap entries that have this value of this component */ for (ptr = j * blksize; ptr < total_colors; ptr += blkdist) { /* fill in blksize entries beginning at ptr */ for (k = 0; k < blksize; k++) { colormap[i][ptr+k] = (JSAMPLE) val; } } } blkdist = blksize; /* blksize of this color is blkdist of next */ } /* Save the colormap in private storage, * where it will survive color quantization mode changes. */ cquantize->sv_colormap = colormap; cquantize->sv_actual = total_colors; }
/** * Transcode binary to text json into the dest buffer. * @return true on success, false on error */ bool json_transcode_binary_to_json(uint8_t *source, size_t sourcelen, dynbuffer_t *dest) { uint8_t typecode; uint8_t *data; uint32_t datalen; if (!extract_type_length(source, source+sourcelen, &typecode, &data, &datalen)) return false; return output_value(data, data+datalen, typecode, dest); }
static void execute(const char *line, bool show_result) { const char *const lines[] = { line, NULL }; struct reader_state rstate; save_reader_state(&rstate); read_from_strings(lines, NULL, NULL); value result; if (interpret(&result, 1, true) && show_result) { printf("Result: "); output_value(mudout, prt_write, false, result); printf("\n"); } restore_reader_state(&rstate); }
static bool output_object(uint8_t *source, uint8_t *sourcelimit, dynbuffer_t *dest) { int index=0; uint8_t typecode; uint8_t *data; uint32_t datalen; dynbuffer_append_byte(dest, '{'); while (source<sourcelimit) { /* object is just a sequence of pairs. pair==asciiz + value */ uint8_t *label=source; for (;;) { if (source>=sourcelimit) return false; /* short */ if (*(source++)==0) break; } if (index>0) dynbuffer_append_byte(dest, ','); /* output label */ dynbuffer_append_byte(dest, '"'); json_escape_string(dest, label, source-label-1, true, '"'); dynbuffer_append(dest, "\":", 2); /* decode type length */ if (!extract_type_length(source, sourcelimit, &typecode, &data, &datalen)) return false; /* output value */ source=data+datalen; if (!output_value(data, source, typecode, dest)) return false; index++; } dynbuffer_append_byte(dest, '}'); return true; }
/* unformatted output for affix output at end of parse etc. */ void output_value (FILE *out, value val) { if (val == value_nil) { fputs ("<value_nil>", out); return; }; switch (val -> tag) { case undefined_value: break; case string_value: fputs (val -> u.str, out); break; case integer_value: fprintf (out, "%d", val -> u.inum); break; case real_value: fprintf (out, "%g", val -> u.rnum); break; case tuple_value: { value_list vl = val -> u.tuple; fputc ('<', out); if (vl != value_list_nil) { int ix; for (ix = 0; ix < vl -> size; ix++) { if (ix != 0) fputs (" * ", out); output_value (out, vl -> array[ix]); }; }; fputc ('>', out); }; break; case small_lattice_value: if (val -> dptr == NULL) fprintf (out, "{ %08x }", val -> u.slat); else { string *lnames = (string *) val -> dptr; int nfirst = 0; int ix; fprintf (out, "{ "); for (ix = 0; ix < 32; ix++) if (val -> u.slat & (1 << ix)) { fprintf (out, "%s%s", (nfirst)?", ":"", lnames[ix]); nfirst = 1; }; fprintf (out, " }"); }; break; case large_lattice_value: { string *lnames = (string *) val -> dptr; int nfirst = 0; int lidx = 0; int_list il = val -> u.elat; int ix; fprintf (out, "{ "); if (lnames == NULL) for (ix = 0; ix < il -> size; ix++) eprint_log ("%08x", il -> array[ix]); else for (ix = il -> size - 1; 0 <= ix; ix--) { int iy; for (iy = 0; iy < 32; iy++, lidx++) if (il -> array[ix] & (1 << iy)) { fprintf (out, "%s%s", (nfirst)?", ":"", lnames [lidx]); nfirst = 1; }; }; fprintf (out, " }"); }; break; default: bad_tag (val -> tag, "output_value"); }; };
void Vegetation::output (Log& log) const { output_value (N (), "N", log); output_value (N_fixated (), "N_fixated", log); output_value (LAI (), "LAI", log); output_value (height (), "height", log); output_value (cover (), "cover", log); output_value (LAIvsH (), "LAIvsH", log); output_value (HvsLAI (), "HvsLAI", log); output_value (ACExt_PAR (), "ACExt_PAR", log); output_value (ACRef_PAR (), "ACRef_PAR", log); output_value (ACExt_NIR (), "ACExt_NIR", log); output_value (ACRef_NIR (), "ACRef_NIR", log); output_value (ARExt (), "ARExt", log); output_value (EpFactorDry (), "EpFactorDry", log); output_value (EpFactorWet (), "EpFactorWet", log); output_value (albedo (), "albedo", log); output_value (interception_capacity (), "interception_capacity", log); output_value (shadow_stomata_conductance (), "shadow_stomata_conductance", log); output_value (sunlit_stomata_conductance (), "sunlit_stomata_conductance", log); }
void output (Log& log) const { Pet::output (log); output_value (reference_evapotranspiration_dry, "reference_evapotranspiration", log); }
void SoilWater::output (Log& log) const { output_value (h_, "h", log); output_value (Theta_, "Theta", log); output_value (Theta_primary_, "Theta_primary", log); output_value (Theta_secondary_, "Theta_secondary", log); output_value (Theta_tertiary_, "Theta_p", log); output_value (S_sum_, "S_sum", log); output_value (S_root_, "S_root", log); output_value (S_drain_, "S_drain", log); output_value (S_indirect_drain_, "S_indirect_drain", log); output_value (S_soil_drain_, "S_soil_drain", log); output_value (S_incorp_, "S_incorp", log); output_value (tillage_, "tillage", log); output_value (S_B2M_, "S_B2M", log); output_value (S_M2B_, "S_M2B", log); output_value (S_p_drain_, "S_p_drain", log); output_value (S_permanent_, "S_permanent", log); output_value (S_ice_ice, "S_ice", log); output_value (S_ice_water_, "S_ice_water", log); output_value (S_forward_total_, "S_forward_total", log); output_value (S_forward_sink_, "S_forward_sink", log); output_value (X_ice_, "X_ice", log); output_value (X_ice_buffer_, "X_ice_buffer", log); output_value (h_ice_, "h_ice", log); output_value (q_matrix_, "q", log); output_value (q_primary_, "q_primary", log); output_value (q_secondary_, "q_secondary", log); output_value (q_tertiary_, "q_p", log); output_value (K_cell_, "K", log); output_value (Cw2_, "Cw2", log); if (std::isnormal (sink_dt)) { output_value (sink_dt, "dt", log); output_variable (sink_cell, log); } if (std::isnormal (table_low)) output_variable (table_low, log); if (std::isnormal (table_high)) output_variable (table_high, log); }
// PRECONDITIONS: none // POSTCONDITION: The object has been placed in the drawing queue, to be // drawn at the next glFlush() void CircuitObject::draw() const { if(type() == "SWITCH") { // Draw the button if necessary if(has_button()) { GLcolor3(0.2, 0.0, 0.0).glColor(); glRectf(left(), bottom(), left() + BUTTON_WIDTH, bottom() + BUTTON_HEIGHT); GLred3.glColor(); glRectf(left() + BUTTON_WIDTH/4, bottom() + BUTTON_HEIGHT/4, left() + 3*BUTTON_WIDTH/4, top() - BUTTON_HEIGHT/4); } // Draw the 1 ONE_COLOR.glColor(); glRectf(left() + 2*width()/3, top() - 2*height()/5, left() + 2*width()/3 + width()/9, top()); // Draw the 0 ZERO_COLOR.glColor(); glRectf(left() + 2*width()/3 - width()/12, bottom() + 3*height()/8, left() + 2*width()/3 + width()/12, bottom() + height()/2); glRectf(left() + 2*width()/3 - width()/12, bottom(), left() + 2*width()/3, bottom() + height()/2); glRectf(left() + 2*width()/3 + width()/12, bottom(), left() + 2*width()/3 + 3*width()/24, bottom() + height()/2); glRectf(left() + 2*width()/3, bottom(), left() + 2*width()/3 + width()/12, bottom() + height()/8); if(output_value() == 1) { // Draw wire from the one ONE_COLOR.glColor(); glBegin(GL_LINES); glVertex2f(left() + 2*width()/3 + width()/6, top() - height()/4); glVertex2f(left() + width(), bottom() + height()/2); glEnd(); } else { // Draw wire from the zero ZERO_COLOR.glColor(); glBegin(GL_LINES); glVertex2f(left() + 2*width()/3 + width()/6, bottom() + height()/4); glVertex2f(left() + width(), bottom() + height()/2); glEnd(); } } else if(type() == "NOT") { GATE_COLOR.glColor(); // Draw triangle glBegin(GL_POLYGON); glVertex2f(left(), bottom()); glVertex2f(left(), top()); glVertex2f(left()+2*width()/3, bottom() + height()/2); glEnd(); // Draw circle glBegin(GL_POLYGON); glVertex2f(left()+2*width()/3, bottom() + height()/2); glVertex2f(left()+5*width()/6, bottom() + 3*height()/5); glVertex2f(left()+6*width()/6, bottom() + height()/2); glVertex2f(left()+5*width()/6, bottom() + 2*height()/5); glEnd(); } else if(type() == "AND") { GATE_COLOR.glColor(); glBegin(GL_POLYGON); glVertex2f(left(), bottom()); glVertex2f(left(), top()); glVertex2f(left()+width()/2, top()); glVertex2f(right(), bottom() + 2*height()/3); glVertex2f(right(), bottom() + 1*height()/3); glVertex2f(left()+width()/2, bottom()); glEnd(); // Draw the dot GLblack3.glColor(); glRectf(left()+2*width()/5, bottom()+2*height()/5, left()+3*width()/5, bottom()+3*height()/5); glEnd(); } else if(type() == "OR") { GATE_COLOR.glColor(); // Top of the gate glBegin(GL_POLYGON); glVertex2f(left()+width()/3, bottom()+height()/2); glVertex2f(left(), top()); glVertex2f(left()+2*width()/3, top()); glVertex2f(right(), bottom() + height()/2); glEnd(); // Bottom of the gate glBegin(GL_POLYGON); glVertex2f(left()+width()/3, bottom()+height()/2); glVertex2f(left(), bottom()); glVertex2f(left()+2*width()/3, bottom()); glVertex2f(right(), bottom() + height()/2); glEnd(); // Draw the + GLblack3.glColor(); glBegin(GL_LINES); glVertex2f(left()+4*width()/7, top()-height()/4); glVertex2f(left()+4*width()/7, bottom()+height()/4); glVertex2f(left()+2*width()/5, top()-height()/2); glVertex2f(left()+4*width()/5, top()-height()/2); glEnd(); } else if(type() == "EXIT") { if(!is_open()) { // Draw the door DOOR_COLOR.glColor(); glBegin(GL_POLYGON); glVertex2f(left(), bottom()); glVertex2f(left(), top() - height()/2); glVertex2f(right(), top()); glVertex2f(right(), top() - height()/2); glEnd(); } // Draw the wall WALL_COLOR.glColor(); glBegin(GL_POLYGON); glVertex2f(left(), bottom()); glVertex2f(right(), top() - height()/2); glVertex2f(right(), bottom()); glEnd(); } }