void import_heap_library(environment_t env) { struct pair_s { char* name; native_function_pt func; }; int i; value_t string_table; environment_push_str(env, "heap"); environment_push_table(env); string_table = list_element(list_rbegin(env->stack), value_t, link); table_push_pair(environment_get_global_table(env), env); struct pair_s pairs[] = { { "alloc", native_heap_alloc }, { "free", native_heap_free }, }; for (i = 0; i < sizeof(pairs) / sizeof(struct pair_s); i++) { environment_push_str(env, pairs[i].name); environment_push_native_function(env, pairs[i].func); table_push_pair(string_table->u.object_value->u.table, env); } }
struct list_elem* first_clean(){ struct list_elem *e; for (e = list_rbegin (&framelist); e != list_rend (&framelist); e = list_prev(e)) { struct frame *f = list_entry(e, struct frame , elem); /* printf(" first clean %p %p \n ",f->upage,f->kpage); */ if(!pagedir_is_dirty(thread_current()->pagedir,f->upage) && f->thread==thread_current()) return e; } return NULL; }
static void native_math_tan(environment_t env, unsigned int argc) { value_t value; value_t* values; value = list_element(list_rbegin(env->stack), value_t, link); values = array_base(value->u.object_value->u.array, value_t*); if (argc < 1) { environment_pop_value(env); environment_push_null(env); return; } environment_push_double(env, tan(native_check_double_value(values[0]))); environment_xchg_stack(env); environment_pop_value(env); }
static void native_heap_free(environment_t env, unsigned int argc) { value_t value; value_t* values; value = list_element(list_rbegin(env->stack), value_t, link); values = array_base(value->u.object_value->u.array, value_t*); if (argc < 1) { environment_pop_value(env); environment_push_null(env); return; } free(native_check_pointer_value(values[0])); environment_pop_value(env); environment_push_null(env); }
void import_math_library(environment_t env) { struct pair_s { char* name; native_function_pt func; }; int i; value_t math_table; environment_push_str(env, "math"); environment_push_table(env); math_table = list_element(list_rbegin(env->stack), value_t, link); table_push_pair(environment_get_global_table(env), env); import_math_const(env, math_table->u.object_value->u.table); struct pair_s pairs[] = { { "sqrt", native_math_sqrt }, { "sin", native_math_sin }, { "cos", native_math_cos }, { "tan", native_math_tan }, { "asin", native_math_asin }, { "acos", native_math_acos }, { "atan", native_math_atan }, { "atan2", native_math_atan2 }, { "cosh", native_math_cosh }, }; for (i = 0; i < sizeof(pairs) / sizeof(struct pair_s); i++) { environment_push_str(env, pairs[i].name); environment_push_native_function(env, pairs[i].func); table_push_pair(math_table->u.object_value->u.table, env); } }