diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/boot/be/abi.ml | 15 | ||||
| -rw-r--r-- | src/boot/me/trans.ml | 48 |
2 files changed, 37 insertions, 26 deletions
diff --git a/src/boot/be/abi.ml b/src/boot/be/abi.ml index 3de553f2..3f97f0dd 100644 --- a/src/boot/be/abi.ml +++ b/src/boot/be/abi.ml @@ -45,15 +45,20 @@ let stk_field_valgrind_id = 0 + 1;; let stk_field_limit = stk_field_valgrind_id + 1;; let stk_field_data = stk_field_limit + 1;; -let obj_elt_vtbl = 0;; -let obj_elt_body_box = 1;; +(* Both obj and fn are two-word "bindings": One word points to some + * static dispatch information (vtbl or thunk), and the other points to + * some bag of bound data (object-body or closure). *) +let binding_field_dispatch = 0;; +let binding_field_bound_data = 1;; + +let obj_field_vtbl = binding_field_dispatch;; +let obj_field_body_box = binding_field_bound_data;; let obj_body_elt_tydesc = 0;; let obj_body_elt_fields = 1;; -let fn_elt_thunk = 0;; -let fn_elt_closure = 1;; - +let fn_field_thunk = binding_field_dispatch;; +let fn_field_closure = binding_field_bound_data;; let closure_elt_rc = 0;; let closure_elt_target = 1;; let closure_elt_bound_args = 2;; diff --git a/src/boot/me/trans.ml b/src/boot/me/trans.ml index 4914ac38..3d89d795 100644 --- a/src/boot/me/trans.ml +++ b/src/boot/me/trans.ml @@ -890,7 +890,7 @@ let trans_visitor let sorted_idents = sorted_htab_keys fns in let i = arr_idx sorted_idents id in let fn_ty = Hashtbl.find fns id in - let table_ptr = get_element_ptr obj_cell Abi.obj_elt_vtbl in + let table_ptr = get_element_ptr obj_cell Abi.obj_field_vtbl in (get_vtbl_entry_idx table_ptr i, fn_ty) in @@ -1479,10 +1479,10 @@ let trans_visitor Abi.indirect_args_elt_closure) in let closure_target_cell = - get_element_ptr closure_cell Abi.obj_elt_body_box + get_element_ptr closure_cell Abi.fn_field_closure in let closure_target_fn_cell = - get_element_ptr closure_target_cell Abi.obj_elt_vtbl + get_element_ptr closure_target_cell Abi.fn_field_thunk in merge_bound_args @@ -2473,7 +2473,7 @@ let trans_visitor Ast.TY_fn _ -> note_drop_step ty "drop_ty: fn path"; - let binding = get_element_ptr cell Abi.obj_elt_body_box in + let binding = get_element_ptr cell Abi.fn_field_closure in let null_jmp = null_check binding in (* Drop non-null bindings. *) (* FIXME (issue #58): this is completely wrong, Closures need to @@ -2486,7 +2486,7 @@ let trans_visitor | Ast.TY_obj _ -> note_drop_step ty "drop_ty: obj path"; - let binding = get_element_ptr cell Abi.obj_elt_body_box in + let binding = get_element_ptr cell Abi.obj_field_body_box in let null_jmp = null_check binding in let rc_jmp = drop_refcount_and_cmp binding in let obj_box = deref binding in @@ -2607,7 +2607,9 @@ let trans_visitor | Ast.TY_obj _ -> if type_has_state ty then - let binding = get_element_ptr cell Abi.obj_elt_body_box in + let binding = + get_element_ptr cell Abi.binding_field_bound_data + in sever_box binding; | _ -> @@ -3094,13 +3096,17 @@ let trans_visitor | Ast.TY_fn _ | Ast.TY_obj _ -> begin - let src_item = get_element_ptr src Abi.obj_elt_vtbl in - let dst_item = get_element_ptr dst Abi.obj_elt_vtbl in + let src_item = + get_element_ptr src Abi.binding_field_dispatch + in + let dst_item = + get_element_ptr dst Abi.binding_field_dispatch + in let src_binding = - get_element_ptr src Abi.obj_elt_body_box + get_element_ptr src Abi.binding_field_bound_data in let dst_binding = - get_element_ptr dst Abi.obj_elt_body_box + get_element_ptr dst Abi.binding_field_bound_data in mov dst_item (Il.Cell src_item); let null_jmp = null_check src_binding in @@ -3197,7 +3203,7 @@ let trans_visitor deref_ty DEREF_none initializing dst_cell dst_ty in let caller_vtbl = - get_element_ptr caller_obj Abi.obj_elt_vtbl + get_element_ptr caller_obj Abi.obj_field_vtbl in mov caller_vtbl caller_vtbl_oper end @@ -3235,10 +3241,10 @@ let trans_visitor let fix = Hashtbl.find cx.ctxt_fn_fixups item.id in let dst_pair_item_cell = - get_element_ptr dst_cell Abi.obj_elt_vtbl + get_element_ptr dst_cell Abi.fn_field_thunk in let dst_pair_binding_cell = - get_element_ptr dst_cell Abi.obj_elt_body_box + get_element_ptr dst_cell Abi.fn_field_closure in mov dst_pair_item_cell (crate_rel_imm fix); mov dst_pair_binding_cell zero @@ -3472,12 +3478,12 @@ let trans_visitor iflog (fun _ -> annotate "set closure target code ptr"); mov - (get_element_ptr targ_cell Abi.fn_elt_thunk) + (get_element_ptr targ_cell Abi.fn_field_thunk) (reify_ptr target_fn_ptr); iflog (fun _ -> annotate "set closure target closure ptr"); mov - (get_element_ptr targ_cell Abi.fn_elt_closure) + (get_element_ptr targ_cell Abi.fn_field_closure) (reify_ptr target_binding_ptr); iflog (fun _ -> annotate "set closure bound args"); @@ -3511,10 +3517,10 @@ let trans_visitor let target_binding_ptr = callee_binding_ptr flv cc in let closure_rty = closure_referent_type bound_arg_slots in let closure_sz = force_sz (Il.referent_ty_size word_bits closure_rty) in - let fn_cell = get_element_ptr dst_cell Abi.obj_elt_vtbl in + let fn_cell = get_element_ptr dst_cell Abi.fn_field_thunk in let closure_cell = ptr_cast - (get_element_ptr dst_cell Abi.obj_elt_body_box) + (get_element_ptr dst_cell Abi.fn_field_closure) (Il.ScalarTy (Il.AddrTy (closure_rty))) in iflog (fun _ -> annotate "assign glue-code to fn slot of pair"); @@ -3824,7 +3830,7 @@ let trans_visitor | CALL_indirect -> (* fptr is a pair [disp, binding*] *) let pair_cell = need_cell (reify_ptr fptr) in - let disp_cell = get_element_ptr pair_cell Abi.obj_elt_vtbl in + let disp_cell = get_element_ptr pair_cell Abi.fn_field_thunk in Il.Cell (crate_rel_to_ptr (Il.Cell disp_cell) Il.CodeTy) and callee_binding_ptr @@ -3835,7 +3841,7 @@ let trans_visitor then zero else let (pair_cell, _) = trans_lval pair_lval in - Il.Cell (get_element_ptr pair_cell Abi.obj_elt_body_box) + Il.Cell (get_element_ptr pair_cell Abi.fn_field_closure) and call_ctrl flv : call_ctrl = if lval_is_static cx flv @@ -4639,10 +4645,10 @@ let trans_visitor let _ = iflog (fun _ -> annotate "load destination obj pair ptr") in let dst_pair_cell = deref (ptr_at (fp_imm out_mem_disp) obj_ty) in let dst_pair_item_cell = - get_element_ptr dst_pair_cell Abi.obj_elt_vtbl + get_element_ptr dst_pair_cell Abi.obj_field_vtbl in let dst_pair_state_cell = - get_element_ptr dst_pair_cell Abi.obj_elt_body_box + get_element_ptr dst_pair_cell Abi.obj_field_body_box in (* Load first cell of pair with vtbl ptr.*) |