Ejemplo n.º 1
0
void DirichletSimpleTest2::build(){
  BlogProgram *blog = new BlogProgram(0, 0);
  root = blog;
  /*
  random RealMatrix w ~ Dirichlet([1.0, 2.0, 3.0]);
  */
  {
    ArrayExpr* arr = new ArrayExpr(0, 0, 1);
    arr->add(new DoubleLiteral(0, 0, 1.0));
    arr->add(new DoubleLiteral(0, 0, 2.0));
    arr->add(new DoubleLiteral(0, 0, 3.0));
    FuncApp *dis = new FuncApp(0, 0, Symbol("Dirichlet"));
    dis->add(arr);
    FuncDecl *fd = new FuncDecl(0, 0, true, Symbol("RealMatrix"), Symbol("w"), dis);
    blog->add(fd);
  }
  /*
  random Integer x ~ Discrete(w);
  */
  {
    FuncApp *dis = new FuncApp(0, 0, Symbol("Discrete"));
    dis->add(new FuncApp(0, 0, Symbol("w")));
    FuncDecl *fd = new FuncDecl(0, 0, true, Symbol("Integer"), Symbol("x"), dis);
    blog->add(fd);
  }
  /*
  query x;
  */
  {
    blog->add(new Query(0, 0, new FuncApp(0, 0, Symbol("x"))));
  }
}
Ejemplo n.º 2
0
void IRGenerator::accept(ArrayExpr& arrayExpr)
{
    FNTRACE();

    // loads a new array of given elements from regs[1] to regs[N], where regs[0] equals N;

    Value* array = createAlloca(arrayExpr.getType(), get(1 + arrayExpr.values().size()));

    // store array size at array[0]
    createArraySet(array, get(0), get(arrayExpr.values().size()));

    // store array values at array[1] to array[N]
    for (size_t i = 1, e = 1 + arrayExpr.values().size(); i != e; ++i) {
        Value* element = codegen(arrayExpr.values()[i].get());
        createArraySet(array, get(i), element);
    }

    result_ = array;
}
Ejemplo n.º 3
0
void IRGenerator::accept(ArrayExpr& arrayExpr)
{
    FNTRACE();

    std::vector<Value*> values;
    for (size_t i = 0, e = arrayExpr.values().size(); i != e; ++i) {
        Value* element = codegen(arrayExpr.values()[i].get());
        values.push_back(element);
    }

    if (isConstant(values)) {
        std::vector<Constant*> constants;
        for (Value* value: values)
            constants.push_back(static_cast<Constant*>(value));

        result_ = get(constants);
    } else {
        // TODO: print line:col hint where this exact message occured.
        // via: reportError(arrayExpr, "Variable array elements not allowed.");
        reportError("Variable array elements not allowed.");
        result_ = nullptr;
    }
}
Ejemplo n.º 4
0
void FlowCallVisitor::accept(ArrayExpr& array)
{
    for (const auto& e: array.values()) {
        visit(e.get());
    }
}