コード例 #1
0
extern "C" closure builtin_function_show(OperationArgs& Args)
{
  auto x = Args.evaluate(0);
  
  object_ptr<String> v (new String);

  if (x.is_double())
    *v = convertToString<double>(x.as_double());
  else if (x.is_int())
    *v = convertToString<int>(x.as_int());
  else if (x.is_log_double())
    *v = "LD"+convertToString<double>(x.as_log_double().log());
  else if (x.is_char())
  {
    std::string s;
    s = x.as_char();
    *v = s;
  }
  else if (x.is_a<String>())
    *v = x.as_<String>();
  else
    throw myexception()<<"show: object '"<<x.print()<<"' is not double, int, log_double, char, or string'";

  return v;
}
コード例 #2
0
extern "C" closure builtin_function_pow(OperationArgs& Args)
{
  auto x = Args.evaluate(0);
  auto y = Args.evaluate(1);

  double yy = 0;
  if (y.is_double())
    yy = y.as_double();
  else if (y.is_int())
    yy = y.as_int();
  else
    throw myexception()<<"pow: exponent '"<<x.print()<<"' is not double or int";
    
  if (x.is_double())
  {
    double xx = x.as_double();
    assert(xx > 0.0);
    return {pow(xx,yy)};
  }
  else if (x.is_int())
  {
    double xx = x.as_int();
    assert(xx > 0.0);
    return {pow(xx,yy)};
  }
  else if (x.is_log_double())
  {
    log_double_t xx = x.as_log_double();
    return {pow(xx,yy)};
  }

  throw myexception()<<"pow: object '"<<x.print()<<"' is not double, int, or log_double";
}
コード例 #3
0
extern "C" closure builtin_function_floor(OperationArgs& Args)
{
  double x = Args.evaluate(0).as_double();
  assert(x > 0.0);

  return {floor(x)};
}
コード例 #4
0
shared_ptr<const Object> Model::operator()(OperationArgs& Args) const
{
  shared_ptr<Model> M (clone());
  for(int i=0;i<n_parameters();i++)
    M->set_parameter_value(i,Args.evaluate(i));
  return M->result();
}
コード例 #5
0
extern "C" closure builtin_function_putStrLn(OperationArgs& Args)
{
  std::string message = Args.evaluate(0).as_<String>();

  std::cout<<message<<std::endl;

  return constructor("()",0);
}
コード例 #6
0
extern "C" closure builtin_function_get_modifiable_for_index(OperationArgs& Args)
{
  assert(not Args.evaluate_changeables());

  int R1 = Args.evaluate(0).as_int();

  return {index_var(0),{R1}};
}
コード例 #7
0
extern "C" closure builtin_function_read_int(OperationArgs& Args)
{
  string s = Args.evaluate(0).as_<String>();
  int i;
  if (can_be_converted_to(s,i))
    return {i};
  throw myexception()<<"Cannot convert string '"<<s<<"' to int!";
}
コード例 #8
0
extern "C" closure builtin_function_read_double(OperationArgs& Args)
{
  string s = Args.evaluate(0).as_<String>();
  double d;
  if (can_be_converted_to(s,d))
    return {d};
  throw myexception()<<"Cannot convert string '"<<s<<"' to double!";
}
コード例 #9
0
boost::shared_ptr<const Object> model_prior::operator()(OperationArgs& Args) const
{
  expression_ref R = Args.evaluate(0);

  vector<expression_ref> v = get_ref_vector_from_tuple(R);

  shared_ptr<Model> M2 (M->clone());
  for(int i=0;i<M2->n_parameters();i++)
    M2->set_parameter_value(i,v[i]);

  return shared_ptr<const Object>(new Log_Double(M2->prior()));
}
コード例 #10
0
extern "C" closure builtin_function_trigger(OperationArgs& Args)
{
  int i = Args.evaluate(0).as_int();

  reg_heap& M = Args.memory();

  // We should be executing in the root token

  M.triggers().push_back(i);

  return constructor("()",0);
}
コード例 #11
0
extern "C" closure builtin_function_negate(OperationArgs& Args)
{
  auto x = Args.evaluate(0);
  
  if (x.is_double())
    return {-x.as_double()};
  else if (x.is_int())
    return {-x.as_int()};
  else if (x.is_char())
    return {-x.as_char()};
  else
    throw myexception()<<"Negate: object '"<<x.print()<<"' is not double, int, or char'";
}
コード例 #12
0
extern "C" closure builtin_function_set_modifiable_value(OperationArgs& Args)
{
  assert(not Args.evaluate_changeables());

  int c = Args.evaluate(0).as_int();

  int R1 = Args.evaluate_slot_to_reg(1);
  int R2 = Args.evaluate_slot_to_reg(2);

  Args.memory().set_reg_value_in_context(R1, {index_var(0),{R2}}, c);

  return constructor("()",0);
}
コード例 #13
0
extern "C" closure builtin_function_mod(OperationArgs& Args)
{
  using boost::dynamic_pointer_cast;

  auto x = Args.evaluate(0);
  auto y = Args.evaluate(1);
  
  if (x.is_int())
    return { x.as_int() % y.as_int() };
  else if (x.is_char())
    return { x.as_char() % y.as_char() };
  else
    throw myexception()<<"Mod: object '"<<x.print()<<"' is not int, or char'";
}
コード例 #14
0
extern "C" closure builtin_function_add_parameter(OperationArgs& Args)
{
  assert(not Args.evaluate_changeables());

  const std::string name = Args.evaluate(0).as_<String>();

  int R = Args.evaluate_slot_to_reg(1);

  auto& M = Args.memory();

  M.parameters.push_back({name,R});

  return constructor("()",0);
}
コード例 #15
0
extern "C" closure builtin_function_get_modifiable_value(OperationArgs& Args)
{
  assert(not Args.evaluate_changeables());

  int c = Args.evaluate(0).as_int();

  int R1 = Args.evaluate_slot_to_reg(1);

  int R2 = Args.memory().get_modifiable_value_in_context(R1, c);

  assert( R2 );

  return {index_var(0),{R2}};
}
コード例 #16
0
extern "C" closure builtin_function_lessthanorequal(OperationArgs& Args)
{
  auto x = Args.evaluate(0);
  auto y = Args.evaluate(1);
  
  if (x.is_double())
    return {x.as_double() <= y.as_double()};
  else if (x.is_int())
    return {x.as_int() <= y.as_int()};
  else if (x.is_log_double())
    return {x.as_log_double() <= y.as_log_double()};
  else if (x.is_char())
    return {x.as_char() <= y.as_char()};
  else
    throw myexception()<<"<=: object '"<<x.print()<<"' is not double, int, log_double, or char'";
}
コード例 #17
0
extern "C" closure builtin_function_evaluate(OperationArgs& Args)
{
  auto& M = Args.memory();

  int c = Args.evaluate(0).as_int();

#ifndef NDEBUG
  if (Args.evaluate_changeables() and c >= 0)
    throw myexception()<<"Calling builtin_function_evaluate( ) when evaluate_changeables=true and c >= 0";
#endif

  int R1 = Args.reg_for_slot(1);

  int R2 = 0;

  if (c < 0)
    R2 = M.incremental_evaluate_unchangeable(R1);
  else
    R2 = M.incremental_evaluate_in_context(R1, c).first;

  assert( R2 );

  return {index_var(0),{R2}};
}
コード例 #18
0
extern "C" closure builtin_function_log(OperationArgs& Args)
{
  auto x = Args.evaluate(0);

  if (x.is_double())
  {
    double xx = x.as_double();
    assert(xx > 0.0);
    return {log(xx)};
  }
  else if (x.is_int())
  {
    double xx = x.as_int();
    assert(xx > 0.0);
    return {log(xx)};
  }
  else if (x.is_log_double())
  {
    log_double_t xx = x.as_log_double();
    return {log(xx)};
  }

  throw myexception()<<"log: object '"<<x.print()<<"' is not double, int, or log_double";
}
コード例 #19
0
extern "C" closure builtin_function_ceiling(OperationArgs& Args)
{
  double x = Args.evaluate(0).as_double();

  return {ceil(x)};
}
コード例 #20
0
extern "C" closure builtin_function_truncate(OperationArgs& Args)
{
  double x = Args.evaluate(0).as_double();

  return {trunc(x)};
}
コード例 #21
0
extern "C" closure builtin_function_doubleToInt(OperationArgs& Args)
{
  double x = Args.evaluate(0).as_double();
  int xi = (int)x;
  return {xi};
}
コード例 #22
0
extern "C" closure builtin_function_builtinError(OperationArgs& Args)
{
  std::string message = Args.evaluate(0).as_<String>();
  
  throw myexception()<<message;
}
コード例 #23
0
extern "C" closure builtin_function_intToDouble(OperationArgs& Args)
{
  int i = Args.evaluate(0).as_int();
  return {double(i)};
}
コード例 #24
0
extern "C" closure builtin_function_doubleToLogDouble(OperationArgs& Args)
{
  double d = Args.evaluate(0).as_double();
  return {log_double_t(d)};
}