Exemple #1
0
void c_write_header(model_t*model, state_t*s)
{
    node_t*root = (node_t*)model->code;

    if(node_has_child(root, &node_arg_max)) {
        c_write_function_arg_min_or_max(s, "max", "", "double", ">");
    }
    if(node_has_child(root, &node_arg_max_i)) {
        c_write_function_arg_min_or_max(s, "max", "_i", "int", ">");
    }
    if(node_has_child(root, &node_arg_min)) {
        c_write_function_arg_min_or_max(s, "min", "", "double", "<");
    }
    if(node_has_child(root, &node_arg_min_i)) {
        c_write_function_arg_min_or_max(s, "min", "_i", "int", "<");
    }
    if(node_has_child(root, &node_array_arg_max_i)) {
        c_write_function_array_arg_max_i(s);
    }
    if(node_has_child(root, &node_sqr)) {
        c_write_function_sqr(s);
    }
    if(node_has_child(root, &node_sort_float_array_asc)) {
        c_write_function_compare_float_ptr(s);
    }

    constant_type_t type = node_type(root, model);
    strf(s, "%s predict(", c_type_name(type));
    int t;
    for(t=0;t<model->sig->num_inputs;t++) {
        if(t) strf(s, ", ");
        if(s->model->sig->has_column_names) {
            strf(s, "%s %s", c_type_name(model_param_type(s->model,t)), s->model->sig->column_names[t]);
        } else {
            strf(s, "%s p%d", c_type_name(model_param_type(s->model,t)), t);
        }
    }
    strf(s, ")\n");
    strf(s, "{\n");
    indent(s);
    int num_locals = 0;
    constant_type_t*types = node_local_types(root, s->model, &num_locals);
    for(t=0;t<num_locals;t++) {
        if(types[t] != CONSTANT_MISSING) {
            strf(s, "%s v%d;\n", c_type_name(types[t]), t);
        }
    }
    c_enumerate_arrays(root, s);

}
Exemple #2
0
static void print_base_type(compile_t* c, printbuf_t* buf, ast_t* type)
{
  if(ast_id(type) == TK_NOMINAL)
  {
    const char* name = genname_type(type);
    const char* c_name = c_type_name(c, name);

    if(c_name != NULL)
      printbuf(buf, c_name);
    else
      printbuf(buf, "%s*", name);
  } else {
    printbuf(buf, "void*");
  }
}
Exemple #3
0
void c_enumerate_arrays(node_t*node, state_t*s)
{
    if(node_is_array(node)) {
        strf(s, "%s a%x[%d] = ", 
                c_type_name(constant_array_subtype(&node->value)),
                (long)(node->value.a),
                node->value.a->size
                );
        c_write_constant(&node->value, s);
        strf(s, ";\n");
    } else {
        int t;
        for(t=0;t<node->num_children;t++) {
            c_enumerate_arrays(node->child[t], s);
        }
    }
}