Skip to content

Commit

Permalink
Fix reinterpret template to work with pointers.
Browse files Browse the repository at this point in the history
  • Loading branch information
skaller committed Aug 18, 2022
1 parent 8598d4a commit cc8105f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/compiler/flx_frontend/flx_xcoerce.ml
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,10 @@ print_endline ("FINAL RESULT " ^ Flx_print.sbe bsym_table result);
*)
result
end

(* pointer to nominal type coercion *)
| BTYP_ptr (_,BTYP_inst (`Nominal _, src,sts,_),[]), BTYP_ptr (_, BTYP_inst (`Nominal _, dst,dts,_),[]) ->
bexpr_reinterpret_cast (srce, dstt)

| BTYP_linearfunction (ld,lc) , BTYP_function (rd,rc) ->
(* print_endline ("Coercing linear function type to ordinary function type .."); *)
Expand Down
14 changes: 14 additions & 0 deletions src/packages/rtl.fdoc
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,20 @@ T &reinterpret(U const &x) {
return reinterpret_cast<T&>(const_cast<U&>(x));
}

// convert any pointer to any other: the T should be a pointer.
template<typename T, typename U>
T reinterpret(U const *x) {
return reinterpret_cast<T>(const_cast<U*>(x));
}

// convert any pointer to non-const to any other: the T should be a pointer.
template<typename T, typename U>
T reinterpret(U *x) {
return reinterpret_cast<T>(x);
}



// dflt init
template<typename T>
void dflt_init(T *p){ new(p) T(); }
Expand Down

0 comments on commit cc8105f

Please sign in to comment.