Skip to content

Commit

Permalink
fixes #219
Browse files Browse the repository at this point in the history
  • Loading branch information
thradams committed Dec 28, 2024
1 parent 4ffb539 commit 6c5add5
Show file tree
Hide file tree
Showing 7 changed files with 420 additions and 392 deletions.
34 changes: 5 additions & 29 deletions src/file.c
Original file line number Diff line number Diff line change
@@ -1,32 +1,8 @@
#pragma safety enable

struct item {
char* _Owner title;
struct item* _Owner _Opt next;
};

struct list {
struct item* _Owner _Opt head;
struct item* _Opt tail;
struct X {
int x;
};

bool list_is_empty(const struct list* list2)
true(list2.head == nullptr && list2.tail == nullptr),
false(list2.head != nullptr && list2.tail != nullptr)
{
return list2->head != nullptr;
}

void list_clear(struct list* list1)
pos(list_is_empty(list1))
{
list1->head = 0;
}


int main(int argc, char* argv[])
{
struct list l = {0};
list_clear(&l);
static_state(l.head , "null");
int main() {
constexpr struct X x = (struct X){ .x = 50 };
static_assert(x.x == 50);
}
34 changes: 24 additions & 10 deletions src/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -16642,13 +16642,27 @@ void object_set(struct object* to, struct expression* _Opt p_init_expression, co
to->state = from->state;
to->value = object_cast(to->value_type, from).value;

if (!is_constant &&
to->state == CONSTANT_VALUE_STATE_CONSTANT_EXACT)
if (is_constant)
{
if (to->state == CONSTANT_VALUE_STATE_CONSTANT_EXACT ||
to->state == CONSTANT_VALUE_STATE_EXACT)
{
/*
struct X {int x;};
int main() { constexpr struct X x = (struct X){ .x = 50 };}*/
to->state = CONSTANT_VALUE_STATE_CONSTANT_EXACT ;
}
}
else
{
//Sample int i = 1; 1 is constant but i will not be
to->state = CONSTANT_VALUE_STATE_EXACT;
if (to->state == CONSTANT_VALUE_STATE_CONSTANT_EXACT)
{
//Sample int i = 1; 1 is constant but i will not be
to->state = CONSTANT_VALUE_STATE_EXACT;
}
}


}
}

Expand Down Expand Up @@ -16819,16 +16833,16 @@ struct object* _Owner _Opt make_object_ptr_core(const struct type* p_type, const
if (p_member_obj == NULL)
throw;

p_member_obj->debug_name= strdup(buffer);
p_member_obj->debug_name = strdup(buffer);
p_member_obj->parent = p_object;
if (p_last_member_obj == NULL)
{
assert(p_object->members == NULL);
p_object->members = p_member_obj;
p_object->members = p_member_obj;
}
else
{
p_last_member_obj->next = p_member_obj;
p_last_member_obj->next = p_member_obj;
}
p_last_member_obj = p_member_obj;

Expand Down Expand Up @@ -27953,7 +27967,7 @@ void defer_start_visit_declaration(struct defer_visit_ctx* ctx, struct declarati

//#pragma once

#define CAKE_VERSION "0.9.44"
#define CAKE_VERSION "0.9.45"



Expand Down Expand Up @@ -30647,14 +30661,14 @@ struct init_declarator* _Owner _Opt init_declarator(struct parser_ctx* ctx,
p_init_declarator->p_declarator->declaration_specifiers->storage_class_specifier_flags & STORAGE_SPECIFIER_CONSTEXPR;


//intf("\n");
//ject_print_to_debug(&p_init_declarator->p_declarator->object);
//intf("\n");

initializer_init_new(ctx,
&p_init_declarator->p_declarator->type,
&p_init_declarator->p_declarator->object,
p_init_declarator->initializer,
is_constant);
//object_print_to_debug(&p_init_declarator->p_declarator->object);
}
}
else
Expand Down
28 changes: 21 additions & 7 deletions src/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -1476,13 +1476,27 @@ void object_set(struct object* to, struct expression* _Opt p_init_expression, co
to->state = from->state;
to->value = object_cast(to->value_type, from).value;

if (!is_constant &&
to->state == CONSTANT_VALUE_STATE_CONSTANT_EXACT)
if (is_constant)
{
if (to->state == CONSTANT_VALUE_STATE_CONSTANT_EXACT ||
to->state == CONSTANT_VALUE_STATE_EXACT)
{
/*
struct X {int x;};
int main() { constexpr struct X x = (struct X){ .x = 50 };}*/
to->state = CONSTANT_VALUE_STATE_CONSTANT_EXACT ;
}
}
else
{
//Sample int i = 1; 1 is constant but i will not be
to->state = CONSTANT_VALUE_STATE_EXACT;
if (to->state == CONSTANT_VALUE_STATE_CONSTANT_EXACT)
{
//Sample int i = 1; 1 is constant but i will not be
to->state = CONSTANT_VALUE_STATE_EXACT;
}
}


}
}

Expand Down Expand Up @@ -1653,16 +1667,16 @@ struct object* _Owner _Opt make_object_ptr_core(const struct type* p_type, const
if (p_member_obj == NULL)
throw;

p_member_obj->debug_name= strdup(buffer);
p_member_obj->debug_name = strdup(buffer);
p_member_obj->parent = p_object;
if (p_last_member_obj == NULL)
{
assert(p_object->members == NULL);
p_object->members = p_member_obj;
p_object->members = p_member_obj;
}
else
{
p_last_member_obj->next = p_member_obj;
p_last_member_obj->next = p_member_obj;
}
p_last_member_obj = p_member_obj;

Expand Down
4 changes: 2 additions & 2 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -2686,14 +2686,14 @@ struct init_declarator* _Owner _Opt init_declarator(struct parser_ctx* ctx,
p_init_declarator->p_declarator->declaration_specifiers->storage_class_specifier_flags & STORAGE_SPECIFIER_CONSTEXPR;


//intf("\n");
//ject_print_to_debug(&p_init_declarator->p_declarator->object);
//intf("\n");

initializer_init_new(ctx,
&p_init_declarator->p_declarator->type,
&p_init_declarator->p_declarator->object,
p_init_declarator->initializer,
is_constant);
//object_print_to_debug(&p_init_declarator->p_declarator->object);
}
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

#pragma once

#define CAKE_VERSION "0.9.44"
#define CAKE_VERSION "0.9.45"


702 changes: 359 additions & 343 deletions src/web/cake.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions tests/unit-tests/initialization_const_from_non_const.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
struct X {
int x;
};

int main() {
constexpr struct X x = (struct X){ .x = 50 };
static_assert(x.x == 50);
}

0 comments on commit 6c5add5

Please sign in to comment.