#include "arch/x86_64/hal/obj.h" #include "jove.h" #include "memory.h" size_t untyped_size(jove_owned_obj_t *tgt) { return ((jove_untyped_t*)obj_deref(tgt))->limit; } uintptr_t untyped_address(jove_owned_obj_t *tgt) { return (uintptr_t)obj_deref(tgt); } int untyped_split(jove_owned_obj_t *tgt, jove_owned_obj_t *dst, size_t bytes) { jove_untyped_t *tgt_untyped = obj_deref(tgt); if(tgt_untyped->limit - bytes < JOVE_UNTYPED_MINSIZE) return ETOOSMALL; tgt_untyped->limit -= bytes; obj_settype(dst, JOVE_OBJ_UNTYPED); obj_setvalue(dst, (uintptr_t)tgt_untyped + tgt_untyped->limit); jove_untyped_t *dst_untyped = obj_deref(dst); dst_untyped->limit = bytes; return 0; } int untyped_merge(jove_owned_obj_t *a, jove_owned_obj_t *b) { jove_untyped_t *a_untyped = obj_deref(a); jove_untyped_t *b_untyped = obj_deref(b); if((uintptr_t)a_untyped + a_untyped->limit == (uintptr_t)b_untyped) { return EBADARG; } if((uintptr_t)b_untyped + b_untyped->limit == (uintptr_t)a_untyped) { return untyped_merge(b, a); } a_untyped->limit += b_untyped->limit; obj_settype(b, JOVE_OBJ_NONE); return 0; } int untyped_retype(jove_owned_obj_t *tgt, uint8_t newtype) { obj_settype(tgt, newtype); return 0; }