TEST(plankton, env_resolution) { CREATE_RUNTIME(); test_resolver_data_t data; data.i0 = new_heap_instance(runtime, ROOT(runtime, empty_instance_species)); data.i1 = new_heap_instance(runtime, ROOT(runtime, empty_instance_species)); value_t i2 = new_heap_instance(runtime, ROOT(runtime, empty_instance_species)); value_mapping_t resolver; value_mapping_init(&resolver, value_to_int, &data); value_mapping_t access; value_mapping_init(&access, int_to_value, &data); value_t d0 = transcode_plankton(runtime, &resolver, &access, data.i0); ASSERT_TRUE(value_identity_compare(data.i0, d0)); value_t d1 = transcode_plankton(runtime, &resolver, &access, data.i1); ASSERT_TRUE(value_identity_compare(data.i1, d1)); value_t d2 = transcode_plankton(runtime, &resolver, &access, i2); ASSERT_FALSE(value_identity_compare(i2, d2)); value_t a0 = new_heap_array(runtime, 4); set_array_at(a0, 0, data.i0); set_array_at(a0, 1, data.i1); set_array_at(a0, 2, i2); set_array_at(a0, 3, data.i0); value_t da0 = transcode_plankton(runtime, &resolver, &access, a0); ASSERT_TRUE(value_identity_compare(data.i0, get_array_at(da0, 0))); ASSERT_TRUE(value_identity_compare(data.i1, get_array_at(da0, 1))); ASSERT_FALSE(value_identity_compare(i2, get_array_at(da0, 2))); ASSERT_TRUE(value_identity_compare(data.i0, get_array_at(da0, 3))); DISPOSE_RUNTIME(); }
TEST(plankton, cycles) { CREATE_RUNTIME(); value_t i0 = new_heap_instance(runtime, ROOT(runtime, empty_instance_species)); value_t k0 = new_integer(78); ASSERT_SUCCESS(set_instance_field(runtime, i0, k0, i0)); value_t d0 = transcode_plankton(runtime, NULL, NULL, i0); ASSERT_SAME(d0, get_instance_field(d0, k0)); value_t i1 = new_heap_instance(runtime, ROOT(runtime, empty_instance_species)); value_t i2 = new_heap_instance(runtime, ROOT(runtime, empty_instance_species)); value_t i3 = new_heap_instance(runtime, ROOT(runtime, empty_instance_species)); value_t k1 = new_integer(79); ASSERT_SUCCESS(set_instance_field(runtime, i1, k0, i2)); ASSERT_SUCCESS(set_instance_field(runtime, i1, k1, i3)); ASSERT_SUCCESS(set_instance_field(runtime, i2, k1, i3)); ASSERT_SUCCESS(set_instance_field(runtime, i3, k0, i1)); value_t d1 = transcode_plankton(runtime, NULL, NULL, i1); value_t d2 = get_instance_field(d1, k0); value_t d3 = get_instance_field(d1, k1); ASSERT_NSAME(d1, d2); ASSERT_NSAME(d1, d3); ASSERT_SAME(d3, get_instance_field(d2, k1)); ASSERT_SAME(d1, get_instance_field(d3, k0)); DISPOSE_RUNTIME(); }
static value_t new_heap_object_with_custom_tagged_type(runtime_t *runtime, value_t type) { custom_tagged_phylum_t phylum = get_custom_tagged_phylum(type); switch (phylum) { case tpNull: // For now we use null to indicate an instance. Later this should be // replaced by something else, something species-like possibly. return new_heap_instance(runtime, ROOT(runtime, empty_instance_species)); default: return new_instance_of_seed(runtime, type); } }
TEST(plankton, references) { CREATE_RUNTIME(); value_t i0 = new_heap_instance(runtime, ROOT(runtime, empty_instance_species)); value_t i1 = new_heap_instance(runtime, ROOT(runtime, empty_instance_species)); value_t i2 = new_heap_instance(runtime, ROOT(runtime, empty_instance_species)); value_t array = new_heap_array(runtime, 6); set_array_at(array, 0, i0); set_array_at(array, 1, i2); set_array_at(array, 2, i0); set_array_at(array, 3, i1); set_array_at(array, 4, i2); set_array_at(array, 5, i1); value_t decoded = check_plankton(runtime, array); ASSERT_SAME(get_array_at(decoded, 0), get_array_at(decoded, 2)); ASSERT_NSAME(get_array_at(decoded, 0), get_array_at(decoded, 1)); ASSERT_SAME(get_array_at(decoded, 1), get_array_at(decoded, 4)); ASSERT_NSAME(get_array_at(decoded, 1), get_array_at(decoded, 3)); ASSERT_SAME(get_array_at(decoded, 3), get_array_at(decoded, 5)); DISPOSE_RUNTIME(); }
TEST(plankton, instance) { CREATE_RUNTIME(); value_t instance = new_heap_instance(runtime, ROOT(runtime, empty_instance_species)); check_plankton(runtime, instance); DEF_HEAP_STR(x, "x"); ASSERT_SUCCESS(try_set_instance_field(instance, x, new_integer(8))); DEF_HEAP_STR(y, "y"); ASSERT_SUCCESS(try_set_instance_field(instance, y, new_integer(13))); value_t decoded = check_plankton(runtime, instance); ASSERT_SUCCESS(decoded); ASSERT_VALEQ(new_integer(8), get_instance_field(decoded, x)); DISPOSE_RUNTIME(); }
static value_t new_instance_of_type(runtime_t *runtime, value_t type) { TRY_DEF(species, new_heap_instance_species(runtime, type, nothing(), vmFluid)); TRY_DEF(result, new_heap_instance(runtime, species)); return result; }