in benchmarks/JetStream2/wasm/TSF/tsf_gpc_code_gen.c [524:620]
static tsf_bool_t generate_set_default(gpc_proto_t *proto,
tsf_type_t *dest_type,
gpc_cell_t offset) {
/* fill in default values */
unsigned i;
switch (dest_type->kind_code) {
case TSF_TK_INT8:
case TSF_TK_UINT8:
C(append(proto, GPC_I_SET_C, offset, 0));
break;
case TSF_TK_INT16:
case TSF_TK_UINT16:
C(append(proto, GPC_I_SET_S, offset, 0));
break;
case TSF_TK_INT32:
case TSF_TK_UINT32:
case TSF_TK_INTEGER:
C(append(proto, GPC_I_SET_L, offset, 0));
break;
case TSF_TK_INT64:
case TSF_TK_UINT64:
case TSF_TK_LONG:
C(append(proto, GPC_I_SET_L, offset + 0, 0));
C(append(proto, GPC_I_SET_L, offset + 4, 0));
break;
case TSF_TK_FLOAT: {
union {
float f;
uint32_t i;
} u;
u.f = (float)log(-1.); /* NaN */
C(append(proto, GPC_I_SET_L, offset, u.i));
break;
}
case TSF_TK_DOUBLE: {
union {
double d;
uint32_t i[2];
} u;
u.d = (double)log(-1.); /* NaN */
C(append(proto, GPC_I_SET_L, offset + 0, u.i[0]));
C(append(proto, GPC_I_SET_L, offset + 4, u.i[1]));
break;
}
case TSF_TK_BIT:
C(append(proto, GPC_I_SET_C, offset, 0));
break;
case TSF_TK_STRING:
C(append(proto, GPC_I_STRING_SETEMPTY, offset));
break;
case TSF_TK_ARRAY:
switch (dest_type->u.a.element_type->kind_code) {
case TSF_TK_VOID:
C(append(proto, GPC_I_SET_L,
offset + tsf_offsetof(tsf_native_void_array_t, len),
0));
break;
case TSF_TK_BIT:
C(append(proto, GPC_I_SET_L,
offset + tsf_offsetof(tsf_native_bitvector_t, num_bits),
0));
C(generate_set_zero_ptr(proto,
offset + tsf_offsetof(tsf_native_bitvector_t,
bits)));
break;
default:
C(append(proto, GPC_I_SET_L,
offset + tsf_offsetof(tsf_native_array_t, len),
0));
C(generate_set_zero_ptr(proto,
offset + tsf_offsetof(tsf_native_array_t,
data)));
break;
}
break;
case TSF_TK_STRUCT:
for (i = 0; i < tsf_struct_type_get_num_elements(dest_type); ++i) {
tsf_named_type_t *n = tsf_struct_type_get_element(dest_type, i);
C(generate_set_default(proto, n->type,
offset + n->offset));
}
break;
case TSF_TK_CHOICE:
C(append(proto, GPC_I_SET_L,
(gpc_cell_t)(offset + dest_type->u.h.value_offset),
(gpc_cell_t)UINT32_MAX));
break;
case TSF_TK_ANY:
tsf_abort("not implemented");
break;
default:
tsf_abort("bad kind code");
}
return tsf_true;
}