static inline void* eval(const unsigned char value, tuple_t tuple, const unsigned char **pc, Register *reg) { if (VAL_IS_HOST(value)) { return (void*)EVAL_HOST; } else if (VAL_IS_REG(value)) { return (void*)&(reg[VAL_REG(value)]); } else if (VAL_IS_TUPLE(value)) { return (void*)tuple; } else if (VAL_IS_FIELD(value)) { const unsigned char reg_index = VAL_FIELD_REG(*pc); const unsigned char field_num = VAL_FIELD_NUM(*pc); tuple_t tuple = (tuple_t)MELD_CONVERT_REG_TO_PTR(reg[reg_index]); (*pc) += 2; #ifdef DEBUG_INSTRS printf ("tuple = "); tuple_print(tuple, stdout); printf ("\n"); printf ("tuple[%d] = %lx\n", field_num, MELD_INT(GET_TUPLE_FIELD(tuple, field_num))); #endif return GET_TUPLE_FIELD(tuple, field_num); } else if (VAL_IS_INT(value)) { void *ret = (void *)(*pc); *pc = *pc + sizeof(meld_int); return ret; } else if (VAL_IS_FLOAT(value)) { void *ret = (void *)(*pc); *pc = *pc + sizeof(meld_float); return ret; } else if (VAL_IS_REVERSE(value)) { const int reg_index = VAL_FIELD_REG(*pc); const int field_num = VAL_FIELD_NUM(*pc); tuple_t tuple = (tuple_t)MELD_CONVERT_REG_TO_PTR(reg[reg_index]); (*pc) += 2; #ifdef PARALLEL_MACHINE List *route = MELD_LIST(GET_TUPLE_FIELD(tuple, field_num)); List *clone = list_copy(route); list_reverse_first(clone); thread_self()->reverse_list = clone; return (void *)&thread_self()->reverse_list; #else return GET_TUPLE_FIELD(tuple, field_num); #endif /* PARALLEL_MACHINE */ } else { assert(0 /* invalid value */ ); } assert(0); return NULL; }
void list_print(FILE* fp, const List* list) { ListElem* le; for(le = list->anchor.next; le != &list->anchor; le = le->next) { switch(list->type) { case LIST_ELEM : elem_print(fp, le->data.elem, TRUE); break; case LIST_TUPLE : tuple_print(fp, le->data.tuple); break; case LIST_ENTRY : entry_print(fp, le->data.entry); break; case LIST_LIST : list_print(fp, le->data.list); break; default : abort(); } fprintf(fp, "\n"); } }
void exception_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in) { mp_obj_exception_t *o = o_in; if (o->msg != 0) { print(env, "%s: %s", qstr_str(o->id), qstr_str(o->msg)); } else { print(env, "%s", qstr_str(o->id)); tuple_print(print, env, &o->args); } }
/* Entry is eaten. * No check is done if entry->tuple is a member of sym->set ! * This has to be done before. */ void symbol_add_entry(Symbol* sym, Entry* entry) { const Tuple* tuple; assert(symbol_is_valid(sym)); assert(entry_is_valid(entry)); assert(sym->used <= sym->size); if (sym->used == sym->size) { sym->size += sym->extend; sym->extend += sym->extend; sym->entry = realloc( sym->entry, (size_t)sym->size * sizeof(*sym->entry)); assert(sym->entry != NULL); } assert(sym->used < sym->size); tuple = entry_get_tuple(entry); /* There is no index set for the internal symbol. */ assert(!strcmp(sym->name, SYMBOL_NAME_INTERNAL) || set_lookup(sym->set, tuple)); if (hash_has_entry(sym->hash, tuple)) { if (stmt_trigger_warning(166)) { fprintf(stderr, "--- Warning 166: Duplicate element "); tuple_print(stderr, tuple); fprintf(stderr, " for symbol %s rejected\n", sym->name); } entry_free(entry); } else { /* Falls noch nicht geschehen, legen wir hier den Typ des * Symbols fest. */ if ((sym->type == SYM_ERR) && (sym->used == 0)) sym->type = entry_get_type(entry); assert(sym->type != SYM_ERR); hash_add_entry(sym->hash, entry); sym->entry[sym->used] = entry; sym->used++; } }
void facts_dump(void) { int i; for (i = 0; i < NUM_TYPES; i++) { // don't print fact types that don't exist if (TUPLES[i].head == NULL) continue; // don't print artificial tuple types /* if (tuple_names[i][0] == '_') continue; */ fprintf(stderr, "tuple %s (type %d)\n", tuple_names[i], i); tuple_entry *tupleEntry; for (tupleEntry = TUPLES[i].head; tupleEntry != NULL; tupleEntry = tupleEntry->next) { fprintf(stderr, " "); tuple_print(tupleEntry->tuple, stderr); if (TYPE_IS_AGG(i)) { fprintf(stderr, "\n [[["); tuple_entry *tpE; for (tpE = tupleEntry->records.agg_queue->head; tpE != NULL; tpE = tpE->next) { tuple_print(tpE->tuple, stderr); fprintf(stderr, "x%d\n ", tpE->records.count); } fprintf(stderr, "\b\b\b]]]\n"); } else { fprintf(stderr, "x%d\n", tupleEntry->records.count); } } } }
STATIC void mp_obj_exception_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in, mp_print_kind_t kind) { mp_obj_exception_t *o = o_in; if (kind == PRINT_REPR) { print(env, "%s", qstr_str(o->base.type->name)); } else if (kind == PRINT_EXC) { print(env, "%s: ", qstr_str(o->base.type->name)); } if (kind == PRINT_STR || kind == PRINT_EXC) { if (o->args == NULL || o->args->len == 0) { print(env, ""); return; } else if (o->args->len == 1) { mp_obj_print_helper(print, env, o->args->items[0], PRINT_STR); return; } } tuple_print(print, env, o->args, kind); }
/*执行打印节点*/ void ExecPrintNode(Var the_var) { switch ( the_var.content.type ) { case VAR_TYPE_INT: printf ( "%d",var_GetInt (the_var)); break; case VAR_TYPE_REAL: printf ( "%g",var_GetDouble (the_var)); break; case VAR_TYPE_BOOL: if ( var_GetBool (the_var)!=0 ) { printf ( "true" ); } else { printf ( "false" ); } break; case VAR_TYPE_MESSAGE: printf ( "%s",var_GetMsg (the_var)); break; case VAR_TYPE_OBJ: printf ( "handle %d ",var_getHandle (the_var)); break; case VAR_TYPE_NILL: printf("NILL"); break; case VAR_TYPE_CHAR: printf("%c",var_GetChar (the_var)); break; case VAR_TYPE_TUPLE: /*打印一个元组的所有成员*/ tuple_print(the_var); break; default: printf("print doesn't support,type: %d",var_GetType(the_var)); break; } }
void exception_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in, mp_print_kind_t kind) { mp_obj_exception_t *o = o_in; if (o->msg != NULL) { print(env, "%s: %s", qstr_str(o->id), vstr_str(o->msg)); } else { // Yes, that's how CPython has it if (kind == PRINT_REPR) { print(env, "%s", qstr_str(o->id)); } if (kind == PRINT_STR) { if (o->args.len == 0) { print(env, ""); return; } else if (o->args.len == 1) { mp_obj_print_helper(print, env, o->args.items[0], PRINT_STR); return; } } tuple_print(print, env, &o->args, kind); } }
STATIC void mp_obj_exception_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in, mp_print_kind_t kind) { mp_obj_exception_t *o = o_in; mp_print_kind_t k = kind & ~PRINT_EXC_SUBCLASS; bool is_subclass = kind & PRINT_EXC_SUBCLASS; if (!is_subclass && (k == PRINT_REPR || k == PRINT_EXC)) { print(env, "%s", qstr_str(o->base.type->name)); } if (k == PRINT_EXC) { print(env, ": "); } if (k == PRINT_STR || k == PRINT_EXC) { if (o->args == NULL || o->args->len == 0) { print(env, ""); return; } else if (o->args->len == 1) { mp_obj_print_helper(print, env, o->args->items[0], PRINT_STR); return; } } tuple_print(print, env, o->args, kind); }
PmReturn_t obj_print(pPmObj_t pobj, uint8_t is_expr_repr, uint8_t is_nested) { PmReturn_t retval = PM_RET_OK; C_ASSERT(pobj != C_NULL); /* Something gets printed unless it's None in an unnested expression */ if (!((OBJ_GET_TYPE(pobj) == OBJ_TYPE_NON) && is_expr_repr && !is_nested)) { gVmGlobal.somethingPrinted = C_TRUE; } switch (OBJ_GET_TYPE(pobj)) { case OBJ_TYPE_NON: if (!is_expr_repr || is_nested) { plat_putByte('N'); plat_putByte('o'); plat_putByte('n'); retval = plat_putByte('e'); } break; case OBJ_TYPE_INT: retval = int_print(pobj); break; #ifdef HAVE_FLOAT case OBJ_TYPE_FLT: retval = float_print(pobj); break; #endif /* HAVE_FLOAT */ case OBJ_TYPE_STR: retval = string_print(pobj, (is_expr_repr || is_nested)); break; case OBJ_TYPE_TUP: retval = tuple_print(pobj); break; case OBJ_TYPE_LST: retval = list_print(pobj); break; case OBJ_TYPE_DIC: retval = dict_print(pobj); break; case OBJ_TYPE_BOOL: if (((pPmBoolean_t) pobj)->val == C_TRUE) { plat_putByte('T'); plat_putByte('r'); plat_putByte('u'); } else { plat_putByte('F'); plat_putByte('a'); plat_putByte('l'); plat_putByte('s'); } retval = plat_putByte('e'); break; case OBJ_TYPE_CLI: #ifdef HAVE_BYTEARRAY { pPmObj_t pobj2; retval = dict_getItem((pPmObj_t)((pPmInstance_t)pobj)->cli_attrs, PM_NONE, (pPmObj_t *)&pobj2); if ((retval == PM_RET_OK) && (OBJ_GET_TYPE(pobj2) == OBJ_TYPE_BYA)) { retval = bytearray_print(pobj2); break; } } #endif /* HAVE_BYTEARRAY */ case OBJ_TYPE_COB: case OBJ_TYPE_MOD: case OBJ_TYPE_CLO: case OBJ_TYPE_FXN: case OBJ_TYPE_CIM: case OBJ_TYPE_NIM: case OBJ_TYPE_NOB: case OBJ_TYPE_THR: case OBJ_TYPE_CIO: case OBJ_TYPE_MTH: case OBJ_TYPE_SQI: plat_putByte('<'); plat_putByte('o'); plat_putByte('b'); plat_putByte('j'); plat_putByte(' '); plat_putByte('t'); plat_putByte('y'); plat_putByte('p'); plat_putByte('e'); plat_putByte(' '); plat_putByte('0'); plat_putByte('x'); int_printHexByte(OBJ_GET_TYPE(pobj)); plat_putByte(' '); plat_putByte('@'); plat_putByte(' '); plat_putByte('0'); plat_putByte('x'); _int_printHex((intptr_t)pobj); retval = plat_putByte('>'); break; default: /* Otherwise raise a TypeError */ PM_RAISE(retval, PM_RET_EX_TYPE); break; } return retval; }
PmReturn_t obj_print(pPmObj_t pobj, uint8_t is_expr_repr, uint8_t is_nested) { PmReturn_t retval = PM_RET_OK; C_ASSERT(pobj != C_NULL); /* Something gets printed unless it's None in an unnested expression */ if (!((OBJ_GET_TYPE(pobj) == OBJ_TYPE_NON) && is_expr_repr && !is_nested)) { gVmGlobal.somethingPrinted = C_TRUE; } switch (OBJ_GET_TYPE(pobj)) { case OBJ_TYPE_NON: if (!is_expr_repr || is_nested) { sli_puts((uint8_t *)"None"); } break; case OBJ_TYPE_INT: retval = int_print(pobj); break; #ifdef HAVE_FLOAT case OBJ_TYPE_FLT: retval = float_print(pobj); break; #endif /* HAVE_FLOAT */ case OBJ_TYPE_STR: retval = string_print(pobj, (is_expr_repr || is_nested)); break; case OBJ_TYPE_TUP: retval = tuple_print(pobj); break; case OBJ_TYPE_LST: retval = list_print(pobj); break; case OBJ_TYPE_DIC: retval = dict_print(pobj); break; case OBJ_TYPE_BOOL: sli_puts( (((pPmBoolean_t) pobj)->val == C_TRUE) ? (uint8_t *)"True" : (uint8_t *)"False"); break; case OBJ_TYPE_CLI: #ifdef HAVE_BYTEARRAY { pPmObj_t pobj2; retval = dict_getItem((pPmObj_t)((pPmInstance_t)pobj)->cli_attrs, PM_NONE, (pPmObj_t *)&pobj2); if ((retval == PM_RET_OK) && (OBJ_GET_TYPE(pobj2) == OBJ_TYPE_BYA)) { retval = bytearray_print(pobj2); break; } } #endif /* HAVE_BYTEARRAY */ case OBJ_TYPE_COB: case OBJ_TYPE_MOD: case OBJ_TYPE_CLO: case OBJ_TYPE_FXN: case OBJ_TYPE_CIM: case OBJ_TYPE_NIM: case OBJ_TYPE_NOB: case OBJ_TYPE_THR: case OBJ_TYPE_CIO: case OBJ_TYPE_MTH: case OBJ_TYPE_SQI: { uint8_t buf[17]; sli_puts((uint8_t *)"<obj type 0x"); sli_btoa16(OBJ_GET_TYPE(pobj), buf, sizeof(buf), C_TRUE); sli_puts(buf); sli_puts((uint8_t *)" @ 0x"); sli_ptoa16((intptr_t)pobj, buf, sizeof(buf), C_TRUE); sli_puts(buf); retval = plat_putByte('>'); break; } default: /* Otherwise raise a TypeError */ PM_RAISE(retval, PM_RET_EX_TYPE); break; } return retval; }
void cleave2(T1&& t1, disambiguator_t const&, T2&& t2){ tuple_print(t1, SeqFor<T1>()); std::cout << "\n" << "split!" << "\n"; tuple_print(t2, SeqFor<T2>()); }