Beispiel #1
0
void multi_concept_model_generator::
populate(const unsigned int position, result_type& v) {
    v.prop_1(create_int(position + 0));
    v.prop_0(create_std_string(position + 1));
    v.prop_2(create_int(position + 2));
    v.prop_10(create_int(position + 3));
}
Beispiel #2
0
/* code to create classes C and D */
static void setup_classes()
{
#ifdef TAGGING
  pyobj zero = inject_int(0);
  pyobj one = inject_int(1);
#else
  pyobj zero = create_int(0);
  pyobj one = create_int(1);
#endif
  pyobj list0 = create_list(zero);
  pyobj list1 = create_list(one);

  // class C:
  //   def m(self):
  //     return self.f
  C = create_class(list0);

  // Add method m to the class.
  set_attr(C, "m", create_closure(C_m, list0));

  // class D(C):
  //   def m(self):
  //     return self.f + 1
  set_subscript(list1, zero, C); // list1[0] = C
  D = create_class(list1);

  pyobj D_m_closure = create_closure(D_m, list0);
  set_attr(D, "m", create_closure(D_m, list0));

  pyobj D_n_closure = create_closure(D_n, list0);
  set_attr(D, "n", create_closure(D_n, list0));
}
Beispiel #3
0
void multiple_refinement_concept_model_generator::
populate(const unsigned int position, result_type& v) {
    v.prop_0(create_int(position + 0));
    v.prop_1(create_int(position + 1));
    v.prop_2(create_int(position + 2));
    v.prop_3(create_int(position + 3));
    v.prop_10(create_int(position + 4));
}
Beispiel #4
0
void class_c_generator::
populate(const unsigned int position, result_type& v) {
    v.prop_0(create_int(position + 0));
    v.prop_1(create_std_vector_dogen_std_model_class_a(position + 1));
    v.prop_2(create_std_vector_dogen_std_model_class_a_unversioned_key(position + 2));
    v.prop_3(create_std_vector_dogen_std_model_class_a_versioned_key(position + 3));
}
Beispiel #5
0
Bignum* square_root(Bignum *n, Bignum *r) {
	Bignum temp, resto, r1, r2;
	char buffer[LEN];
	int pos, pos2, tambuf, aux;

	temp.sinal = resto.sinal = 1;
	if (n->len%2 == 1)
		n->digits[n->len++] = '0';
	aux = (int) (sqrt((n->digits[n->len-1] - '0')*10 + n->digits[n->len-2]-'0') + 1.0e-7);
	create_int((n->digits[n->len-1] - '0')*10 + n->digits[n->len-2]-'0' - aux*aux,&resto);
	buffer[0] = aux + '0';
	tambuf = 1;

	for (pos=n->len-3; pos > -1; pos-=2) {
		shift(&resto,2);
		resto.digits[1] = n->digits[pos], resto.digits[0] = n->digits[pos-1];
		no_zeroes(&resto);
		mult_int(create(buffer,tambuf,&temp),2,&r1);
		shift(copy(&temp,&r1),1);
		for (pos2=1; pos2 < 10; pos2++) {
			temp.digits[0] = pos2 + '0';
			if (compare(mult_int(&temp,pos2,&r1),&resto) > 0)
				break;
		}
		buffer[tambuf++] = pos2 - 1 + '0';
		temp.digits[0] = pos2 - 1 + '0';
		copy(&resto,subtract(&resto,mult_int(&temp,pos2-1,&r1),&r2));
	}
	create(buffer,tambuf,r);
	no_zeroes(n);

	return r;
}
Beispiel #6
0
Bignum* power_int(Bignum *n, int p, Bignum *r) {
	Bignum temp, aux;
	if (p == 0) return create_int(1,r);
	if (p == 1) return copy(r,n);
	power_int(n,p/2,&temp);
	if (p&1)
		return multiply(multiply(&temp,&temp,&aux),n,r);
	return multiply(&temp,&temp,r);
}
Beispiel #7
0
/*
 * def m(self): return self.f + 1
 */
pyobj D_m(pyobj self) {
  pyobj f = get_attr(self, "f");
  int i = project_int(f);
#ifdef TAGGING
  return inject_int(i+1);
#else
  return create_int(i+1);
#endif
}
Beispiel #8
0
Term* statically_infer_length_func(Branch* branch, Term* term)
{
    Term* input = term->input(0);
    if (input->function == FUNCS.copy)
        return statically_infer_length_func(branch, input->input(0));

    if (input->function == FUNCS.list)
        return create_int(branch, input->numInputs());

    if (input->function == LIST_APPEND_FUNC) {
        Term* leftLength = apply(branch, FUNCS.length, TermList(input->input(0)));
        return apply(branch, FUNCS.add, TermList(
                    statically_infer_length_func(branch, leftLength),
                    create_int(branch, 1)));
    }

    // Give up
    std::cout << "statically_infer_length_func didn't understand: "
        << input->function->name << std::endl;
    return create_symbol_value(branch, name_Unknown);
}
Beispiel #9
0
Term* statically_infer_length_func(Block* block, Term* term)
{
    Term* input = term->input(0);
    if (input->function == FUNCS.copy)
        return statically_infer_length_func(block, input->input(0));

    if (input->function == FUNCS.list)
        return create_int(block, input->numInputs());

    if (input->function == FUNCS.list_append) {
        Term* leftLength = apply(block, FUNCS.length, TermList(input->input(0)));
        return apply(block, FUNCS.add, TermList(
                    statically_infer_length_func(block, leftLength),
                    create_int(block, 1)));
    }

    // Give up
    std::cout << "statically_infer_length_func didn't understand: "
        << input->function->name << std::endl;
    return create_string(block, "unknown");
}
Beispiel #10
0
Bignum* power(Bignum *base, Bignum *exp, Bignum *r) {
	Bignum aux1, aux2;
	int resto;
	if (exp->len == 1 && exp->digits[0] == '0')
		return create_int(1,r);
	if (exp->len == 1 && exp->digits[0] == '1')
		return copy(r,base);
	div_int(exp,2,&aux1,&resto);
	power(base,&aux1,&aux2);
	if (resto == 0)
		return multiply(&aux2,&aux2,r);
	return multiply(multiply(&aux2,&aux2,&aux1),base,r);
}
void generate_source_for_function_calls() {
    Branch branch;

    Term* a = create_int(&branch, 5, "a");
    Term* b = create_int(&branch, 9, "b");
    Term* c = apply(&branch, "add", TermList(a,b));

    test_assert(should_print_term_source_line(a));
    test_assert(should_print_term_source_line(b));
    test_assert(should_print_term_source_line(c));
    test_equals(get_branch_source_text(&branch), "a = 5\nb = 9\nadd(a, b)");

    // Same test with anonymous values
    branch.clear();
    Term* d = create_int(&branch, 3);
    Term* e = create_int(&branch, 4);
    /*Term* f =*/ apply(&branch, "add", TermList(d,e));

    /*
    TODO, fix this
    test_assert(!should_print_term_source_line(d));
    test_assert(!should_print_term_source_line(e));
    test_assert(should_print_term_source_line(f));
    test_equals(get_branch_source_text(branch), "add(3, 4)");
    
    // Do a test where some calls are parser-created, and then user-created calls
    // are added.
    branch.clear();
    branch.compile("a = 1");
    branch.compile("b = 2");
    a = create_int(branch, 3, "c");
    b = create_int(branch, 4, "d");
    apply(branch, "add", TermList(a,b));

    test_equals(get_branch_source_text(branch), "a = 1\nb = 2\nc = 3\nd = 4\nadd(c, d)");
    */
}
Beispiel #12
0
void a_class_generator::
populate(const unsigned int position, result_type& v) {
    v.bool_property(create_bool(position + 0));
    v.char_property(create_char(position + 1));
    v.uchar_property(create_unsigned_char(position + 2));
    v.int_property(create_int(position + 3));
    v.uint_property(create_unsigned_int(position + 4));
    v.long_property(create_long(position + 5));
    v.ulong_property(create_unsigned_long(position + 6));
    v.long_long_property(create_long_long(position + 7));
    v.ulong_long_property(create_unsigned_long_long(position + 8));
    v.short_property(create_short(position + 9));
    v.ushort_property(create_unsigned_short(position + 10));
    v.double_property(create_double(position + 11));
    v.float_property(create_float(position + 12));
}
Beispiel #13
0
/* Eval the args given to -test and computes the function, unused */
ast_st* eval_args(int argc, const char ** argv, int par, int * index) {

  ast_st *tmp1, *tmp2;
  kind_en op = Nothing;
  int i;

  for (i = 0; i < argc; i++) {

    if (!strcmp(argv[i],"(")) {

      tmp2 = eval_args(argc-i, argv+i+1, 1, index);
      if (tmp2 == NULL) return NULL;
      i += *index;
    }
    else if (!strcmp(argv[i], ")"))
      if (par) {
        *index = i+1;
        return tmp1;
      }
      else {
        printf("Closing parenthesis unmatched\n");
        return NULL;
      }

    else if (is_op(argv[i])) { 
      op = get_op(argv[i]);
    }

    else {
      int val = !strcmp(argv[i], "") ? 0 : atoi(argv[i]);
      tmp2 = create_int(val);
      
      if (op != Nothing) {
        tmp1 = create_node(op, tmp1, tmp2);
        op = Nothing;
      } else tmp1 = tmp2;
    }
  }

  if (!par)
    return tmp1;
  else {
    printf("Opening parenthesis unmatched\n");
    return NULL;
  }
}
Beispiel #14
0
obj fn_do_events (obj args)
{
  (void) args;
  uint8_t n = 0;

  if (tick_action && millis () - last_time >= timeout)
  {
    n += 1;
    last_time = millis ();
    apply_internal (tick_action, obj_NIL);
  }

  if (serial_action && Serial.available ())
  {
    n += 1;
    apply_internal (serial_action, obj_NIL);
  }

  return (create_int (n));
}
void test_if_joining()
{
    Branch branch;

    // Test that a name defined in one branch is not rebound in outer scope
    branch.eval("if true { apple = 5 }");
    test_assert(!branch.contains("apple"));

    // Test that a name which exists in the outer scope is rebound
    Term* original_banana = create_int(&branch, 10, "banana");
    branch.eval("if true { banana = 15 }");
    test_assert(branch["banana"] != original_banana);

    // Test that if a name is defined in both 'if' and 'else' branches, that it gets
    // defined in the outer scope.
    branch.eval("if true { Cardiff = 5 } else { Cardiff = 11 }");
    test_assert(branch.contains("Cardiff"));

    // Test that the type of the joined name is correct
    branch.compile("if true { a = 4 } else { a = 5 }; a = a");
    test_equals(get_output_type(branch["a"])->name, "int");
}
Beispiel #16
0
void simple_concept_model_generator::
populate(const unsigned int position, result_type& v) {
    v.prop_0(create_int(position + 0));
    v.prop_1(create_dogen_test_models_stereotypes_value(position + 1));
    v.prop_10(create_int(position + 2));
}
Beispiel #17
0
void class_c_generator::
populate(const unsigned int position, result_type& v) {
    v.prop_0(create_int(position + 0));
    v.prop_1(create_std_vector_dogen_test_models_boost_model_class_a(position + 1));
}
Beispiel #18
0
int main()
{
  setup_classes();

  // c = C()
  pyobj c = create_object(C);

  // d = D()
  pyobj d = create_object(D);

  // TODO: call the __init__ method if it exists

#ifdef TAGGING
  pyobj one = inject_int(1);
  pyobj three = inject_int(3);
#else
  pyobj one = create_int(1);
  pyobj three = create_int(3);
#endif

  // c.f = 1
  set_attr(c, "f", one);

  // d.f = 1
  set_attr(d, "f", one);

  pyobj i, j, k, h;

  // i = c.m()
  {
    pyobj meth = get_attr(c, "m");
    pyobj fun = get_function(meth);
    void *fp = get_fun_ptr(fun);
    pyobj (*f)(pyobj) = (pyobj (*)(pyobj)) fp; // cast to a function pointer type
    i = f(get_receiver(meth));
  }

  // j = d.m()
  {
    pyobj meth = get_attr(d, "m");
    pyobj fun = get_function(meth);
    void *fp = get_fun_ptr(fun);
    pyobj (*f)(pyobj) = (pyobj (*)(pyobj)) fp; // cast to a function pointer type
    j = f(get_receiver(meth));
  }

  // d.n(3)
  {
    pyobj (*f)(pyobj, pyobj) = (pyobj (*)(pyobj, pyobj)) get_fun_ptr_from_attr(d, "n");
    f(d, three);
  }

  // k = d.m()
  {
    pyobj meth = get_attr(d, "m");
    pyobj fun = get_function(meth);
    void *fp = get_fun_ptr(fun);
    pyobj (*f)(pyobj) = (pyobj (*)(pyobj)) fp; // cast to a function pointer type
    k = f(get_receiver(meth));
  }

  // h = i + j + k
  {
#ifdef TAGGING
    // optimized, but assumes i and j are integers
    // h = i + j + k

    // unoptimized, but checks that i and j are integers
    h = inject_int(project_int(i) + project_int(j) + project_int(k));
#else
    h = create_int(project_int(i) + project_int(j) + project_int(k));
#endif
  }

  // print i, j, k
  print_any(i);
  print_any(j);
  print_any(k);
  print_any(h);
  return 0;
}
Beispiel #19
0
		node_type factory::create_list(const std::list<long long> &other) {
			boost::shared_ptr<list_node_interface> node(new list_node);
			BOOST_FOREACH(const long long &v, other) {
				node->push_back(create_int(v));
			}
Beispiel #20
0
void identity_and_other_ver_unversioned_key_generator::
populate(const unsigned int position, result_type& v) {
    v.prop_0(create_int(position + 0));
}
Beispiel #21
0
void class_derived_generator::
populate(const unsigned int position, result_type& v) {
    dogen::boost_model::class_base_generator::populate(position, v);
    v.prop_1(create_int(position + 0));
}
Beispiel #22
0
void just_identity_generator::
populate(const unsigned int position, result_type& v) {
    v.prop_0(create_int(position + 0));
}
void parent_with_members_generator::
populate(const unsigned int position, result_type& v) {
    v.prop_0(create_int(position + 0));
}
Beispiel #24
0
void first_class_generator::
populate(const unsigned int position, result_type& v) {
    v.public_attribute(create_int(position + 0));
    v.private_attribute(create_int(position + 1));
}
Beispiel #25
0
void child_generator::
populate(const unsigned int position, result_type& v) {
    dogen::trivial_inheritance::parent_outside_generator::populate(position, v);
    v.prop_1(create_int(position + 0));
}
Beispiel #26
0
void keyed_in_package_generator::
populate(const unsigned int position, result_type& v) {
    v.prop_0(create_int(position + 0));
}
Beispiel #27
0
void class_3_generator::
populate(const unsigned int position, result_type& v) {
    v.prop_0(create_int(position + 0));
}
Beispiel #28
0
void composite_identity_generator::
populate(const unsigned int position, result_type& v) {
    v.prop_0(create_int(position + 0));
    v.prop_1(create_int(position + 1));
    v.prop_2(create_int(position + 2));
}
Beispiel #29
0
pointer parse_number(parser* parse)
{
    size_t len = 0;
    bool isFloat = false;
    bool isHex = false;
    bool isBinary = false;

    const char* Start = parse->curr;

    while(!is_delimiter(*parse->curr))
    {
        if(*parse->curr == '.')
            isFloat = true;

        if(is_number_char(*parse->curr) ||
           (isHex && is_extended_hex_char(*parse->curr)))
            len++;
        else if(len == 1 &&
                *parse->curr == 'x' &&
                *Start == '0')
        {
            len++;
            isHex = true;
        }
        else if(len == 0 && *parse->curr == 'b')
            isBinary = true;
        else
            return parser_error(parse, "Unexpected char '%c' in number literal.", *parse->curr);
        parse->curr++;
    }

    {
        int TotalIs = isHex + isBinary + isFloat;
        if(TotalIs > true)
        {
            char* buffer = new char[len+1];

            strncpy(buffer, Start, len);
            buffer[len] = '\0';
            parser_error(parse, "Unexpected number literal: %s.", buffer);
            delete buffer;
            return NIL;

        }
    }

    if(isFloat)
    {
        char* buffer = new char[len+1];

        strncpy(buffer, Start, len);
        buffer[len] = '\0';

        float ret = atof(buffer);
        delete buffer;

        return create_real(ret);
    }
    else
    {
        // Might be smart to use a buffer here, in case strtol doesn't see all delimiters as we do.
        int ret;
        if(isHex)
            ret  = strtol(Start + 2, NULL,  16);
        else if(isBinary)
            ret = strtol(Start + 1, NULL, 2);
        else
            ret = strtol(Start, NULL, 10);

        return create_int(ret);
    }


}
Beispiel #30
0
void base_with_concept_generator::
populate(const unsigned int position, result_type& v) {
    v.prop_0(create_int(position + 0));
    v.prop_2(create_int(position + 1));
}