Skip to content

Commit

Permalink
Further work on the deemon-to-x86 compiler
Browse files Browse the repository at this point in the history
- Implement more instructions
- Wrap call-like instructions
- Various fixes
  • Loading branch information
GrieferAtWork committed Dec 31, 2023
1 parent 616d271 commit 9a54185
Show file tree
Hide file tree
Showing 17 changed files with 2,466 additions and 1,525 deletions.
2 changes: 1 addition & 1 deletion include/deemon/attribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ struct Dee_attribute_info {
* NOTE: When the `Dee_ATTR_DOCOBJ' flag is set, then this is actually
* the `DeeString_STR()' of a string objects, to which a
* reference is being held. */
uint16_t a_perm; /* Set of `ATTR_*' flags, describing the attribute's behavior. */
uint16_t a_perm; /* Set of `Dee_ATTR_*' flags, describing the attribute's behavior. */
DREF DeeTypeObject *a_attrtype; /* [0..1] The typing of this attribute. */
};
#define Dee_attribute_info_docobj(self) \
Expand Down
2 changes: 1 addition & 1 deletion include/deemon/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -2820,7 +2820,7 @@ INTDEF NONNULL((1)) bool DCALL type_inherit_constructors(DeeTypeObject *__restri
INTDEF NONNULL((1)) bool DCALL type_inherit_str(DeeTypeObject *__restrict self); /* tp_str */
INTDEF NONNULL((1)) bool DCALL type_inherit_repr(DeeTypeObject *__restrict self); /* tp_repr */
INTDEF NONNULL((1)) bool DCALL type_inherit_bool(DeeTypeObject *__restrict self); /* tp_bool */
INTDEF NONNULL((1)) bool DCALL type_inherit_call(DeeTypeObject *__restrict self); /* tp_call */
INTDEF NONNULL((1)) bool DCALL type_inherit_call(DeeTypeObject *__restrict self); /* tp_call, tp_call_kw */
INTDEF NONNULL((1)) bool DCALL type_inherit_hash(DeeTypeObject *__restrict self); /* tp_hash */
INTDEF NONNULL((1)) bool DCALL type_inherit_int(DeeTypeObject *__restrict self); /* tp_int, tp_int32, tp_int64, tp_double */
INTDEF NONNULL((1)) bool DCALL type_inherit_inv(DeeTypeObject *__restrict self); /* tp_inv */
Expand Down
2 changes: 1 addition & 1 deletion src/deemon/objects/dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ DeeDict_NewKeyItemsInherited(size_t num_keyitems, DREF DeeObject **key_items) {
for (;; DeeDict_HashNx(i, perturb)) {
struct dict_item *item = &result->d_elem[i & mask];
if (item->di_key)
continue; /* Already in use */
continue; /* Already in use (XXX: Check for duplicates?) */
item->di_hash = hash;
item->di_key = key; /* Inherit reference. */
item->di_value = value; /* Inherit reference. */
Expand Down
4 changes: 2 additions & 2 deletions src/deemon/objects/int.c
Original file line number Diff line number Diff line change
Expand Up @@ -4052,7 +4052,7 @@ int_reqbits(DeeIntObject const *__restrict self, bool is_signed) {



PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL
INTERN WUNUSED NONNULL((1)) DREF DeeObject *DCALL
int_tobytes(DeeIntObject *self, size_t argc,
DeeObject *const *argv, DeeObject *kw) {
PRIVATE struct keyword kwlist[] = { K(length), K(byteorder), K(signed), KEND };
Expand Down Expand Up @@ -4111,7 +4111,7 @@ int_tobytes(DeeIntObject *self, size_t argc,
}


PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL
INTERN WUNUSED NONNULL((1)) DREF DeeObject *DCALL
int_bitcount(DeeIntObject *self, size_t argc,
DeeObject *const *argv, DeeObject *kw) {
PRIVATE struct keyword kwlist[] = { K(signed), KEND };
Expand Down
18 changes: 14 additions & 4 deletions src/deemon/objects/numeric.c
Original file line number Diff line number Diff line change
Expand Up @@ -1547,26 +1547,36 @@ numeric_oct(DeeObject *self, size_t argc, DeeObject *const *argv, DeeObject *kw)
return NULL;
}

INTDEF WUNUSED NONNULL((1)) DREF DeeObject *DCALL
int_tobytes(DeeIntObject *self, size_t argc,
DeeObject *const *argv, DeeObject *kw);

PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL
numeric_tobytes(DeeObject *self, size_t argc, DeeObject *const *argv, DeeObject *kw) {
numeric_tobytes(DeeObject *self, size_t argc,
DeeObject *const *argv, DeeObject *kw) {
DREF DeeObject *as_int, *result;
as_int = DeeObject_Int(self);
if unlikely(!as_int)
goto err;
result = DeeObject_CallAttrStringKw(as_int, "tobytes", argc, argv, kw);
result = int_tobytes((DeeIntObject *)as_int, argc, argv, kw);
Dee_Decref(as_int);
return result;
err:
return NULL;
}

INTDEF WUNUSED NONNULL((1)) DREF DeeObject *DCALL
int_bitcount(DeeIntObject *self, size_t argc,
DeeObject *const *argv, DeeObject *kw);

PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL
numeric_bitcount(DeeObject *self, size_t argc, DeeObject *const *argv, DeeObject *kw) {
numeric_bitcount(DeeObject *self, size_t argc,
DeeObject *const *argv, DeeObject *kw) {
DREF DeeObject *as_int, *result;
as_int = DeeObject_Int(self);
if unlikely(!as_int)
goto err;
result = DeeObject_CallAttrStringKw(as_int, "bitcount", argc, argv, kw);
result = int_bitcount((DeeIntObject *)as_int, argc, argv, kw);
Dee_Decref(as_int);
return result;
err:
Expand Down
24 changes: 10 additions & 14 deletions src/dex/_hostasm/assembler.c
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ next_cur_locX:;
none.ml_type = MEMLOC_TYPE_CONST;
none.ml_value.v_const = Dee_None;
if unlikely(Dee_function_generator_gexcept_morph_mov(self, &none, &new_loc,
0, new_refcnt))
1, new_refcnt + 1))
goto err_infostate_state_curinfo_vaddr;
ASSERT(curinfo_vaddr[new_locX] == (Dee_vstackaddr_t)-1);
curinfo_vaddr[new_locX] = state->ms_stackc;
Expand Down Expand Up @@ -1239,7 +1239,6 @@ Dee_function_assembler_ordersections(struct Dee_function_assembler *__restrict s
/* Go through the list of sections and append jump instructions wherever
* the intended fallthru target differs from the actual successor section. */
TAILQ_FOREACH (sect, &text, hs_link) {
struct Dee_host_symbol *dst;
struct Dee_host_section *want_next = sect->hs_fallthru;
struct Dee_host_section *sort_next = TAILQ_NEXT(sect, hs_link);
unsigned int n;
Expand Down Expand Up @@ -1268,20 +1267,17 @@ Dee_function_assembler_ordersections(struct Dee_function_assembler *__restrict s
}

/* Must generate a jump */
dst = Dee_function_assembler_newsym(self);
if unlikely(!dst)
goto err;
dst->hs_type = DEE_HOST_SYMBOL_SECT;
dst->hs_value.sv_sect.ss_sect = want_next;
dst->hs_value.sv_sect.ss_off = 0;
{
Dee_function_assembler_DEFINE_Dee_host_symbol_section(self, err, dst, want_next, 0);
#ifdef Dee_MallocUsableSize
sect->hs_alend = sect->hs_start + Dee_MallocUsableSize(sect->hs_start);
ASSERT(sect->hs_alend >= sect->hs_end);
sect->hs_alend = sect->hs_start + Dee_MallocUsableSize(sect->hs_start);
ASSERT(sect->hs_alend >= sect->hs_end);
#else /* Dee_MallocUsableSize */
sect->hs_alend = sect->hs_end;
sect->hs_alend = sect->hs_end;
#endif /* !Dee_MallocUsableSize */
if unlikely(_Dee_host_section_gjmp(sect, dst))
goto err;
if unlikely(_Dee_host_section_gjmp(sect, dst))
goto err;
}
/*sect->hs_fallthru = NULL;*/
no_jmp_needed:;
}
Expand Down Expand Up @@ -1598,7 +1594,7 @@ Dee_assemble(DeeFunctionObject *__restrict function,
struct Dee_hostfunc *__restrict result,
Dee_hostfunc_cc_t cc, uint16_t flags) {
struct Dee_function_assembler assembler;
Dee_function_assembler_init(&assembler, function, cc, flags);
Dee_function_assembler_init(&assembler, function, function->fo_code, cc, flags);

/* Special case: deemon code that contains user-written deemon assembly
* requires special care to include some extra checks in
Expand Down
Loading

0 comments on commit 9a54185

Please sign in to comment.