static inline void expose_VM(STATE, VALUE lobby) { VALUE vm = Value_new(state, ObjectType); Value_set(state, lobby, "VM", vm); // VM.primitives map DArray *prims = DArray_create(sizeof(VALUE), 10); VALUE primitives = Map_new(state, prims); Value_set(state, vm, "primitives", primitives); // Object DEFPRIM("to_s", Primitive_to_s); DEFPRIM("prototype", Primitive_prototype); DEFPRIM("or", Primitive_or); DEFPRIM("equals", Primitive_equals); DEFPRIM("is", Primitive_is); DEFPRIM("print", Primitive_print); DEFPRIM("puts", Primitive_puts); DEFPRIM("require", Primitive_require); DEFPRIM("clone", Primitive_clone); // Vector DEFPRIM("vector_[]", Primitive_Vector_at); DEFPRIM("vector_push", Primitive_Vector_push); DEFPRIM("vector_to_map", Primitive_Vector_to_map); DEFPRIM("vector_each", Primitive_Vector_each); DEFPRIM("vector_each_with_index", Primitive_Vector_each_with_index); // Number DEFPRIM("number_+", Primitive_Number_add); DEFPRIM("number_-", Primitive_Number_sub); DEFPRIM("number_*", Primitive_Number_mul); DEFPRIM("number_/", Primitive_Number_div); DEFPRIM("number_<", Primitive_Number_lt); DEFPRIM("number_>", Primitive_Number_gt); // String DEFPRIM("string_+", Primitive_String_concat); // Map DEFPRIM("map_each", Primitive_Map_each); // VM.types map DArray *ts = DArray_create(sizeof(VALUE), 10); VALUE types = Map_new(state, ts); Value_set(state, vm, "types", types); DEFVALUE("object", Object_bp); DEFVALUE("number", Number_bp); DEFVALUE("string", String_bp); DEFVALUE("vector", Vector_bp); DEFVALUE("map", Map_bp); DEFVALUE("closure", Closure_bp); }
RenderQueue* RenderQueue_new() { RenderQueue* newRenderQueue = allocate(RenderQueue); newRenderQueue->renderBatches = Map_new(Map_compareInts); smug_assert(_invariant(newRenderQueue)); return newRenderQueue; }
void test_map_pairs (void* data) { Map* map = Map_new(runtime); Map_put(map, hash_for(NIL), NIL, TRUE); Map_put(map, hash_for(TRUE), TRUE, FALSE); Map_put(map, hash_for(FALSE), FALSE, NIL); Vector* pairs = Map_pairs(map); for (uint64_t i = 0; i < Vector_length(pairs); i++) { Tuple* pair = Vector_get(pairs, i); if (is_nil(Tuple_get(pair, 0))) { tt_assert(is_true(Tuple_get(pair, 1))); } else if (is_true(Tuple_get(pair, 0))) { tt_assert(is_false(Tuple_get(pair, 1))); } else if (is_false(Tuple_get(pair, 0))) { tt_assert(is_nil(Tuple_get(pair, 1))); } } end: Map_destroy(map); }
void test_map_new (void* data) { Map* map = Map_new(runtime); tt_assert(map); end: Map_destroy(map); }
void test_map_put (void* data) { Map* map = Map_new(runtime); Tuple* pair = Map_put(map, hash_for(TRUE), TRUE, FALSE); tt_assert(is_true(Tuple_get(pair, 0))); tt_assert(is_false(Tuple_get(pair, 1))); pair = Map_put(map, hash_for(TRUE), TRUE, NIL); tt_assert(is_true(Tuple_get(pair, 0))); tt_assert(is_nil(Tuple_get(pair, 1))); end: Map_destroy(map); }
void test_map_values (void* data) { Map* map = Map_new(runtime); Map_put(map, hash_for(NIL), NIL, TRUE); Map_put(map, hash_for(TRUE), TRUE, FALSE); Map_put(map, hash_for(FALSE), FALSE, NIL); Vector* values = Map_values(map); for (uint64_t i = 0; i < Vector_length(values); i++) { Value* value = Vector_get(values, i); tt_assert(is_nil(value) || is_true(value) || is_false(value)); } end: Map_destroy(map); }