Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enum Types #49

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open

Enum Types #49

wants to merge 13 commits into from

Conversation

BrettRToomey
Copy link
Contributor

No description provided.

src/checker.c Outdated Show resolved Hide resolved
src/checker.c Outdated Show resolved Hide resolved
src/checker.c Outdated Show resolved Hide resolved
case ExprKind_TypeEnum: {
symbol->state = SymbolState_Resolving;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will need to do additional work to support circular enum references ... for example:

StmtKind :: enum (u8) {
    Invalid
    Start
    // ...
    End

    ExprStart :: Start + 100
    // ...
    ExprEnd

    DeclStart :: Start + 200
    // ...
    DeclEnd
}

will work fine with a naïve solution should work fine in this case because Start is processed before DeclStart. Do we limit Enums to forbid forward references? Saves us handling the circular checking case

src/llvm.cpp Show resolved Hide resolved
src/llvm.cpp Outdated
@@ -1852,4 +1896,8 @@ void printIR(llvm::Type *value) {
puts("\n");
}

void printModule(llvm::Module *module) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/kai-language/kai-c/pull/49/files#diff-cf87bdfd88530e0c5c46f9b95cf006beR1885
There is already and overload for this called printIR let's just use it for now

@@ -0,0 +1,4 @@

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn this came back. I was trying to make it a blank file that git would keep in the repo but ignore changes. The Xcode build system fails if the file isn't there because other xcconfig files #include it and it doesn't run the script to generate this xcconfig file if any of the xcconfig files have any errors. I made my git ignore changes to it but that only works locally for myself. Not sure what would work for any contributors. Any suggestions?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I am running 6.0.1 and planning on trying out 7.0.0rc2 soon so it will change lots if we can't just ignore it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

>.>

src/checker.c Outdated Show resolved Hide resolved
src/checker.c Outdated Show resolved Hide resolved
src/checker.c Outdated Show resolved Hide resolved
src/checker.c Outdated
@@ -932,7 +928,8 @@ Type *checkExprTypeEnum(Expr *expr, CheckerContext *ctx, Package *pkg) {
}

if (hasMinMax && currentValue > maxValue) {
printf("oops!\n");
ReportError(pkg, IntOverflowError, item.init->start,
"Enum case is will overflow backing type");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReportError(pkg, IntOverflowError, item.init->start,
            "Value for enum case exceeds the max value for the enum backing type (%s)", 
            DescribeType(backingType));
ReportNote(pkg, item.init->start, 
           "You can force the overflow by explicitly casting the value '%s(%s)" 
           DescribeType(backingType), DescribeExpr(item.init));

@@ -945,6 +942,10 @@ Type *checkExprTypeEnum(Expr *expr, CheckerContext *ctx, Package *pkg) {
storeInfoBasicExpr(pkg, expr, type, ctx);
ctx->mode = ExprMode_Type;
return type;

unresolved:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the prior leak of fields with:

if (fields) ArrayFree(fields);

@@ -909,20 +910,15 @@ Type *checkExprTypeEnum(Expr *expr, CheckerContext *ctx, Package *pkg) {
if (item.init) {
CheckerContext itemCtx = {.scope = ctx->scope, .desiredType = backingType};
Type *type = checkExpr(item.init, &itemCtx, pkg);
if (itemCtx.mode == ExprMode_Unresolved) goto unresolved; // TODO: @Leak this will leak the 'fields' array

if (!IsConstant(&itemCtx)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a b32 expectType(Package *pkg, Type *type, CheckerContext *ctx, Position pos) do you think we should have a b32 expectConstant(Package *pkg, CheckerContext *ctx, Position pos)? This would mean we would get a more consistent error message. What do you think?

case SelectorKind_Enum: {
llvm::Type *type = canonicalize(ctx, info.type);
if (ctx->returnAddress) {
UNIMPLEMENTED();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The frontend should report errors if a user tries to address an enum. This should be an ASSERT(false)

src/llvm.cpp Show resolved Hide resolved
@vdka vdka changed the title First pass on enum checking. Starting codegen Enums Dec 12, 2018
@vdka vdka changed the title Enums Enum Types Dec 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants