Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions kai.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
5D41B52C20CE32E8005E9A8E /* gen_xcode_tests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = gen_xcode_tests.cpp; sourceTree = "<group>"; };
5D41B53420CE393F005E9A8E /* kai-xctests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "kai-xctests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
5D41B53820CE393F005E9A8E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
5D50634C21BF57AF0054B90E /* ast_descriptions.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = ast_descriptions.c; path = src/ast_descriptions.c; sourceTree = "<group>"; };
5D50634E21C08B920054B90E /* targets.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = targets.h; path = src/targets.h; sourceTree = "<group>"; };
5D5612AD20ABA02E00E2F4E8 /* targets.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = targets.c; path = src/targets.c; sourceTree = "<group>"; };
5D5612AE20ABAD5B00E2F4E8 /* os.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = os.c; path = src/os.c; sourceTree = "<group>"; };
5D9C729920A5E7C400755A1B /* flags.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; name = flags.c; path = src/flags.c; sourceTree = "<group>"; };
Expand Down Expand Up @@ -145,6 +147,7 @@
5DBC259A20BC133A0086904A /* tools */,
B25AB22520B987D0002E1440 /* array.h */,
B25AB22620B987D0002E1440 /* ast.h */,
5D50634E21C08B920054B90E /* targets.h */,
B25AB22B20B987D1002E1440 /* checker.h */,
5D405841212E4EF3007A7E8F /* string.h */,
B25AB22720B987D0002E1440 /* common.h */,
Expand All @@ -170,6 +173,7 @@
B249A258209B80E00016B49E /* lexer.c */,
B249A25A209B80E00016B49E /* map.c */,
5DA7CA2720A9653F00E4640D /* ast.c */,
5D50634C21BF57AF0054B90E /* ast_descriptions.c */,
B249A259209B80E00016B49E /* parser.c */,
B249A25E209B80E00016B49E /* string.c */,
B249A25F209B80E00016B49E /* utf.c */,
Expand Down Expand Up @@ -471,7 +475,7 @@
CODE_SIGN_STYLE = Automatic;
GCC_C_LANGUAGE_STANDARD = c11;
GCC_WARN_CHECK_SWITCH_STATEMENTS = YES;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MACOSX_DEPLOYMENT_TARGET = 10.14;
OTHER_CFLAGS = (
"-Wno-c99-extensions",
"-Wno-c11-extensions",
Expand Down Expand Up @@ -501,7 +505,7 @@
CODE_SIGN_STYLE = Automatic;
GCC_C_LANGUAGE_STANDARD = c11;
GCC_WARN_CHECK_SWITCH_STATEMENTS = YES;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MACOSX_DEPLOYMENT_TARGET = 10.14;
OTHER_CFLAGS = (
"-Wno-c99-extensions",
"-Wno-c11-extensions",
Expand Down
14 changes: 1 addition & 13 deletions src/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,7 @@ b32 isDecl(Stmt *stmt) {
return stmt->kind > _DeclKind_Start && stmt->kind < _DeclKind_End;
}

// @ErrorQuality
// FIXME: Better description
const char *DescribeStmt(Stmt *stmt) {
return AstDescriptions[stmt->kind];
}

const char *DescribeExpr(Expr *expr) {
return AstDescriptions[expr->kind];
}

const char *DescribeDecl(Decl *decl) {
return AstDescriptions[decl->kind];
}
#include "ast_descriptions.c"

void *AllocAst(Package *package, size_t size) {
ASSERT(size != 0);
Expand Down
26 changes: 26 additions & 0 deletions src/ast_descriptions.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

// @ErrorQuality
// FIXME: Better description
const char *DescribeStmt(Stmt *stmt) {
return AstDescriptions[stmt->kind];
}

const char *DescribeExpr(Expr *expr) {
char buf[1024];

switch (expr->kind) {
case ExprKind_Ident:
return expr->Ident.name;

case ExprKind_LitInt:
sprintf(buf, "%llu", expr->LitInt.val);
return StrIntern(buf);

default:
return AstDescriptions[expr->kind];
}
}

const char *DescribeDecl(Decl *decl) {
return AstDescriptions[decl->kind];
}
41 changes: 39 additions & 2 deletions src/checker.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ b32 IsFloat(Type *type) {
return type->kind == TypeKind_Float;
}

b32 IsPointer(Type *type) {
return (type->kind == TypeKind_Pointer);
}

b32 isFunction(Type *type) {
return type->kind == TypeKind_Function;
}
Expand Down Expand Up @@ -1626,6 +1630,31 @@ Type *checkExprSelector(Expr *expr, CheckerContext *ctx, Package *pkg) {
break;
}

case TypeKind_Slice: {
SelectorValue val;
if (expr->Selector.name == internRaw) {
type = NewTypePointer(TypeFlag_None, base->Slice.elementType);
val.Struct.index = 0;
val.Struct.offset = TargetPointer->Width;
} else if (expr->Selector.name == internLen) {
type = U64Type;
val.Struct.index = 1;
val.Struct.offset = TargetPointer->Width * 2;
} else if (expr->Selector.name == internCap) {
type = U64Type;
val.Struct.index = 2;
val.Struct.offset = TargetPointer->Width * 3;
} else {
ReportError(pkg, TODOError, expr->Selector.start, "Slice %s has no member %s",
DescribeExpr(expr->Selector.expr), expr->Selector.name);
goto error;
}
storeInfoSelector(pkg, expr, type, SelectorKind_Slice, val, ctx);
ctx->mode = ExprMode_Addressable;
ctx->flags &= ~CheckerContextFlag_Constant;
break;
}

TypeKind_File: {
Symbol *file = pkg->checkerInfo[expr->Selector.expr->id].Ident.symbol;
Package *import = (Package *) file->backendUserdata;
Expand Down Expand Up @@ -1664,7 +1693,8 @@ Type *checkExprSelector(Expr *expr, CheckerContext *ctx, Package *pkg) {
}

default: {
ReportError(pkg, TODOError, expr->start, "%s has no member '%s'", DescribeExpr(expr->Selector.expr), expr->Selector.name);
ReportError(pkg, TODOError, expr->start, "%s (type %s) has no member '%s'",
DescribeExpr(expr->Selector.expr), DescribeType(base), expr->Selector.name);
goto error;
}
}
Expand Down Expand Up @@ -2022,6 +2052,9 @@ void checkDeclVariable(Decl *decl, CheckerContext *ctx, Package *pkg) {
if (exprCtx.mode == ExprMode_Invalid) {
// This may not best handle users declaring from mixed calls & not calls
markSymbolInvalid(symbols[lhsIndex]);

values += 1;
lhsIndex += 1;
continue;
}

Expand Down Expand Up @@ -2185,7 +2218,11 @@ void checkStmtAssign(Stmt *stmt, CheckerContext *ctx, Package *pkg) {

ctx->desiredType = lhsTypes[lhsIndex];
Type *type = checkExpr(expr, ctx, pkg);
if (ctx->mode == ExprMode_Invalid) continue;
if (ctx->mode == ExprMode_Invalid) {
values += 1;
lhsIndex += 1;
continue;
}
if (ctx->mode == ExprMode_Unresolved) goto unresolved;

if (type->kind == TypeKind_Tuple) {
Expand Down
2 changes: 2 additions & 0 deletions src/checker.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ typedef u8 SelectorKind;
#define SelectorKind_None 0x0
#define SelectorKind_Struct 0x1
#define SelectorKind_Import 0x2
#define SelectorKind_Slice 0x4

typedef struct Selector_Struct Selector_Struct;
struct Selector_Struct {
Expand Down Expand Up @@ -158,6 +159,7 @@ Type *TypeFromCheckerInfo(CheckerInfo info);
b32 IsInteger(Type *type);
b32 IsSigned(Type *type);
b32 IsFloat(Type *type);
b32 IsPointer(Type *type);
#ifdef __cplusplus
}
#endif
Expand Down
8 changes: 8 additions & 0 deletions src/lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ const char *internSemicolon;
const char *internUnderscore;
const char *internIn;

const char *internRaw;
const char *internLen;
const char *internCap;

// Directive names
const char *internLine;
const char *internFile;
Expand Down Expand Up @@ -84,6 +88,10 @@ void InitKeywords() {
internUnderscore = StrIntern("_");
internIn = StrIntern("in");

internRaw = StrIntern("raw");
internLen = StrIntern("len");
internCap = StrIntern("cap");

internLine = StrIntern("line");
internFile = StrIntern("file");
internAssert = StrIntern("assert");
Expand Down
Loading