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); }
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); }
void GLWidget::paintEvent(QPaintEvent*) { QPainter painter; painter.begin(this); painter.setRenderHint(QPainter::Antialiasing); scripts_pre_message_send(); // call onPaintEvent caValue* msg = circa_alloc_list(2); circa_set_string(circa_index(msg, 0), "onPaintEvent"); circa_set_typed_pointer(circa_index(msg, 1), circa_find_type(NULL, "Painter"), &painter); circa_actor_run_message(g_world, "View", msg); circa_dealloc_value(msg); scripts_post_message_send(); painter.end(); }