本文整理汇总了C++中Branch::compile方法的典型用法代码示例。如果您正苦于以下问题:C++ Branch::compile方法的具体用法?C++ Branch::compile怎么用?C++ Branch::compile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Branch
的用法示例。
在下文中一共展示了Branch::compile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_lazy
void test_lazy()
{
#ifdef DEFERRED_CALLS_FIRST_DRAFT
Branch branch;
Term* a = branch.compile("a = add(1 2)");
set_lazy_call(a, true);
Stack context;
push_frame(&context, &branch);
run_interpreter(&context);
test_equals(get_register(&context, a), ":Unevaluated");
Frame* frame = push_frame(&context, &branch);
frame->pc = a->index;
frame->startPc = frame->pc;
frame->endPc = frame->pc + 1;
frame->strategy = ByDemand;
run_interpreter(&context);
test_equals(get_register(&context, a), "3");
reset_stack(&context);
Term* b = branch.compile("b = add(a a)");
push_frame(&context, &branch);
run_interpreter(&context);
test_equals(get_register(&context, a), "3");
test_equals(get_register(&context, b), "6");
#endif
}
示例2: repro_source_after_rename
void repro_source_after_rename()
{
Branch branch;
// Simple test
Term* a = branch.compile("a = 1");
rename(a, "apple");
test_equals(get_term_source_text(a), "apple = 1");
// Rename a function argument
Term* b = branch.compile("b = 5");
Term* add = branch.compile("add( b , 10)");
rename(b, "banana");
test_equals(get_term_source_text(add), "add( banana , 10)");
// Rename a function
Term* myfunc = import_function(&branch, NULL, "def myfunc(int)");
Term* myfunc_call = branch.compile("myfunc(555)");
rename(myfunc, "my_renamed_func");
test_equals(get_term_source_text(myfunc_call), "my_renamed_func(555)");
}
示例3: test_trimmed_state
void test_trimmed_state(std::string const& source, std::string const& dest,
std::string const& expectedTrash)
{
Branch sourceBranch;
sourceBranch.compile(source);
if (test_fail_on_static_error(&sourceBranch))
return;
Stack context;
evaluate_branch(&context, &sourceBranch);
if (test_fail_on_runtime_error(context))
return;
Branch destBranch;
destBranch.compile(dest);
if (test_fail_on_static_error(&destBranch))
return;
caValue trash;
strip_orphaned_state(&destBranch, &context.state, &trash);
if (expectedTrash != trash.toString()) {
declare_current_test_failed();
std::cout << "In test " << get_current_test_name() << std::endl;
std::cout << expectedTrash << " != " << trash.toString() << std::endl;
}
}
示例4: test_state_is_reset_when_if_fails
void test_state_is_reset_when_if_fails()
{
Branch branch;
Stack context;
Term* c = branch.compile("c = true");
branch.compile("if c { state i = 0; i += 1 } else { 'hi' }");
evaluate_branch(&context, &branch);
test_equals(&context.state, "{_if_block: [{i: 1}]}");
evaluate_branch(&context, &branch);
test_equals(&context.state, "{_if_block: [{i: 2}]}");
evaluate_branch(&context, &branch);
test_equals(&context.state, "{_if_block: [{i: 3}]}");
set_bool(c, false);
evaluate_branch(&context, &branch);
test_equals(&context.state, "{_if_block: [null, null]}");
set_bool(c, true);
evaluate_branch(&context, &branch);
test_equals(&context.state, "{_if_block: [{i: 1}]}");
}
示例5: assign_output_type
void assign_output_type()
{
Branch branch;
branch.compile("a = [1]");
Term* assign = branch.compile("a[0] = 2");
test_equals(assign->type->name, "List");
}
示例6: test_state_is_reset_when_if_fails2
void test_state_is_reset_when_if_fails2()
{
// Similar to test_state_is_reset_when_if_fails, but this one doesn't
// have an 'else' block and it uses test_oracle.
internal_debug_function::oracle_clear();
Branch branch;
Term* a = branch.compile("a = true");
branch.compile("if a { state s = test_oracle() }");
internal_debug_function::oracle_send(1);
internal_debug_function::oracle_send(2);
internal_debug_function::oracle_send(3);
Stack context;
evaluate_branch(&context, &branch);
test_equals(&context.state, "{_if_block: [{s: 1}]}");
evaluate_branch(&context, &branch);
test_equals(&context.state, "{_if_block: [{s: 1}]}");
set_bool(a, false);
evaluate_branch(&context, &branch);
test_equals(&context.state, "{_if_block: [null, null]}");
set_bool(a, true);
evaluate_branch(&context, &branch);
test_equals(&context.state, "{_if_block: [{s: 2}]}");
}
示例7: for_loop_output_type
void for_loop_output_type()
{
Branch branch;
branch.compile("a = 1");
branch.compile("for i in [1] { a = 2 }");
test_equals(branch["a"]->type->name, "int");
}
示例8: infer_type_of_append
void infer_type_of_append()
{
Branch branch;
branch.compile("a = []");
branch.compile("a.append(1)");
Term* b = branch.compile("a[0]");
test_equals(b->type->name, "int");
}
示例9: compare_builtin_types
void compare_builtin_types()
{
Branch branch;
Term* aFloat = branch.compile("1.2");
test_assert(term_output_always_satisfies_type(aFloat, unbox_type(FLOAT_TYPE)));
test_assert(term_output_never_satisfies_type(aFloat, unbox_type(INT_TYPE)));
Term* anInt = branch.compile("1");
test_assert(term_output_always_satisfies_type(anInt, unbox_type(FLOAT_TYPE)));
test_assert(term_output_always_satisfies_type(anInt, unbox_type(INT_TYPE)));
}
示例10: name_visible_iterator_1
void name_visible_iterator_1()
{
Branch branch;
branch.compile("a = 1");
Term* b = branch.compile("b = 1");
branch.compile("c = 1; d = 1; e = 1");
branch.compile("b = 2; f = 1; g = 1");
NameVisibleIterator it(b);
test_equals(it.current()->name,"c"); test_assert(!it.finished()); ++it;
test_equals(it.current()->name,"d"); test_assert(!it.finished()); ++it;
test_equals(it.current()->name,"e"); test_assert(!it.finished()); ++it;
test_assert(it.finished());
}
示例11: test_execution_with_elif
void test_execution_with_elif()
{
Branch branch;
branch.compile("x = 5");
branch.compile("if x > 5 { test_spy('Fail') } "
"elif x < 5 { test_spy('Fail')} "
"elif x == 5 { test_spy('Success')} "
"else { test_spy('Fail') }");
internal_debug_function::spy_clear();
evaluate_branch(&branch);
test_assert(&branch);
test_equals(internal_debug_function::spy_results(), "['Success']");
}
示例12: test_snippet
void test_snippet(std::string const& source)
{
Branch branch;
branch.compile(source);
if (test_fail_on_static_error(&branch))
return;
Stack context;
evaluate_branch(&context, &branch);
if (test_fail_on_runtime_error(context))
return;
// Try stripping orphaned state, this should not have an effect.
caValue trash;
strip_orphaned_state(&branch, &context.state, &trash);
if (!is_null(&trash)) {
std::cout << "Falsely orphaned state in " << get_current_test_name() << std::endl;
std::cout << "Code = " << source << std::endl;
std::cout << "Trash = " << trash.toString() << std::endl;
declare_current_test_failed();
return;
}
}
示例13: bug_reproducing_list_after_eval
void bug_reproducing_list_after_eval()
{
// There once was a bug where source repro would fail when using a list
// in a vectorized function, but only after that piece of code had been
// evaluated. This was because vectorize_vv was calling apply() which
// was changing the 'statement' property of its inputs.
Branch branch;
Term* sum = branch.compile("[1 1] + [1 1]");
Term* in0 = sum->input(0);
Term* in1 = sum->input(0);
test_equals(get_term_source_text(in0), "[1 1]");
test_equals(get_term_source_text(in1), "[1 1]");
test_equals(get_input_source_text(sum, 0), "[1 1] ");
test_equals(get_input_source_text(sum, 1), " [1 1]");
test_equals(get_branch_source_text(&branch), "[1 1] + [1 1]");
evaluate_branch(&branch);
test_equals(get_term_source_text(in0), "[1 1]");
test_equals(get_term_source_text(in1), "[1 1]");
test_equals(get_input_source_text(sum, 0), "[1 1] ");
test_equals(get_input_source_text(sum, 1), " [1 1]");
test_equals(get_branch_source_text(&branch), "[1 1] + [1 1]");
}
示例14: test_custom_object
void test_custom_object()
{
g_currentlyAllocated = 0;
g_totalAllocated = 0;
Branch branch;
branch.compile(
"type MyType; \n"
"def create_object() -> MyType\n"
"def check_object(MyType t)\n"
"s = create_object()\n"
"check_object(s)\n"
);
circa_install_function(&branch, "create_object", create_object);
circa_install_function(&branch, "check_object", check_object);
circa_setup_object_type(circa_find_type(&branch, "MyType"),
sizeof(CustomObject), CustomObjectRelease);
// Shouldn't allocate any objects before running.
test_equals(g_currentlyAllocated, 0);
test_equals(g_totalAllocated, 0);
Stack stack;
push_frame(&stack, &branch);
run_interpreter(&stack);
test_assert(&stack);
circa_clear_stack(&stack);
// Running the script should only cause 1 object allocation.
test_equals(g_currentlyAllocated, 0);
test_equals(g_totalAllocated, 1);
}
示例15: test_type_not_prematurely_used
void test_type_not_prematurely_used()
{
// Verify that a circa-defined type is not used until interpreter time. Modifying
// a type's release() handler after there are already instances of it, is not good.
Branch branch;
branch.compile(
"type MyType; \n"
"def f() -> MyType\n"
"def g(MyType t)\n"
"s = f()\n"
"g(s)\n"
"l = [s s s]\n"
"type MyCompoundType {\n"
" MyType t\n"
"}\n"
"state MyType st\n"
"state MyType st2 = create(MyType)\n"
);
Type* myType = (Type*) circa_find_type(&branch, "MyType");
Type* myCompoundType = (Type*) circa_find_type(&branch, "MyCompoundType");
test_assert(!myType->inUse);
test_assert(!myCompoundType->inUse);
circa::Value value1, value2;
create(myType, &value1);
create(myCompoundType, &value2);
test_assert(myType->inUse);
test_assert(myCompoundType->inUse);
}