Skip to content

Commit

Permalink
* Fix remaining issues in all current tests
Browse files Browse the repository at this point in the history
  • Loading branch information
n00bmind committed Apr 11, 2021
1 parent a6812e4 commit 0feca8b
Show file tree
Hide file tree
Showing 16 changed files with 140 additions and 652 deletions.
5 changes: 4 additions & 1 deletion build.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ def end_time():
for file in test_files:
print(f'Testing {file:<30}... ', end='')

phase = 'Compilation'
# Compile it
out_args = [exepath]
out_args.append(file)
Expand All @@ -263,6 +264,7 @@ def end_time():
file = os.path.join(folder, file)
file = os.path.splitext(file)[0] + '.exe'

phase = 'Execution'
# Run it
out_args = [file]
proc = subprocess.run(out_args, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
Expand All @@ -271,7 +273,8 @@ def end_time():
print_color('[ OK ]' if ok else '[FAIL]', colors.GREEN if ok else colors.RED)

if not ok:
print(f'{phase} returned {proc.returncode}')
print(proc.stdout.decode())
print('\n')
print()

sys.exit(ret)
6 changes: 3 additions & 3 deletions examples/01_vars_types.do
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ main :: ()
// (buffers will be explained better in a later example)
greeting :string = "Hello Sailor!";
// Oh, and they're also readonly
#expecterror{ greeting[6] = 'T'; }
#expect_error{ greeting[6] = 'T'; }
ch = greeting[6];
printf( "ch = '%c' (%d)\n", ch, ch );

Expand All @@ -39,7 +39,7 @@ main :: ()

// They all need to either have a explicit typespec, or be given a value
// (anything not given an explicit initial value is zero initialized)
#expecterror { x, y, z := 0, 1; }
#expect_error { x, y, z := 0, 1; }
x, y, z :int = 0, 1;
printf( "x = %d, y = %d, z = %d\n", x, y, z );

Expand All @@ -54,7 +54,7 @@ main :: ()
printf( "hash = %x (%u)\n", hash, hash );

// Conversion to integer and back is only allowed via casting (although literals of any sign auto convert to both)
#expecterror { noCanDo :i32 = hash; }
#expect_error { noCanDo :i32 = hash; }
yesCanDo :i32 = <i32>hash;

// Booleans are a special kind of bits type. Its natural size is 8 bits, although only the least significant is used
Expand Down
2 changes: 1 addition & 1 deletion examples/02_operators.do
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ main :: ()
printf( "a + y = %f \n", z );

// Conversion back to integer requires a cast though
#expecterror { c = x - b; }
#expect_error { c = x - b; }
c = <int> ( x - b );
expect( c == 8 );

Expand Down
10 changes: 5 additions & 5 deletions examples/03_arrays.do
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ main :: ( argc: int, argv: **i8 ) -> int
{
printf( '-----\n' );
for( i in 0 .. b.length )
printf( 'Item %d is %d\n', i, b[i] );
printf( 'Item %lld is %d\n', i, b[i] );
printf( '\n' );
}

Expand All @@ -30,14 +30,14 @@ main :: ( argc: int, argv: **i8 ) -> int
PrintBuffer( nums4 );

// Open ranges do require an explicitly sized array
#expecterror
#expect_error
{ nums5: []int = { [..] = 100 }; }
#expecterror
#expect_error
{ nums5: [*]int = { [..] = 100 }; }

#expecterror
#expect_error
{
int bla = nums2[10];
bla: int = nums2[10];
}

// Creating a buffer view from an array
Expand Down
4 changes: 3 additions & 1 deletion examples/06_control_flow.do
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ main :: ()
////////////////////////////////////////////
// FOR

// TODO
/*
// Integer range (open end), default step
for( i := 0..array.count! )
{
Expand Down Expand Up @@ -52,6 +54,6 @@ main :: ()
if( SomeCondition() )
break;
}

*/
// TODO Gather more examples from actual code
}
4 changes: 4 additions & 0 deletions src/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ bool ContainsDirective( BucketArray<NodeDirective> const& directives, Directive:
}


#if 1
bool globalBreakOnError = true;
#else
bool globalBreakOnError = false;
#endif

void ParseError( Lexer* lexer, char const* fmt, ... )
{
Expand Down
3 changes: 2 additions & 1 deletion src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ AssertHandlerFunc* globalAssertHandler = DefaultAssertHandler;
#if CONFIG_RELEASE
#define DEBUGBREAK(expr) ((void)0)
#else
#define DEBUGBREAK(expr) ((void)(expr && HALT()))
// TODO Some POSIX version of this
#define DEBUGBREAK(expr) ((void)(expr && IsDebuggerPresent() && (__debugbreak(), 1)))
#endif

#define SIZEOF(s) Sz( sizeof(s) )
Expand Down
5 changes: 5 additions & 0 deletions src/lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ internal InternString* Intern( String const& string, u32 flags = 0 )

InternString* entry = globalInternStrings.entries.Get( string );
if( entry )
{
entry->flags |= flags;
result = entry;
}
else
{
// Copy string data to permanent arena
Expand Down Expand Up @@ -52,6 +55,8 @@ Lexer::Lexer( String const& input, char const* filename_ )
token = {};

// Intern keywords & directives
// TODO At the moment we allow keywords and non-keywords with the same name (we just set the corresponding flags
// in the keyword's InternString but I wonder if this may cause any unexpected problems)
for( Keyword::Item const& k : Keyword::items )
{
InternString* intern = Intern( String( k.name ), InternString::Keyword );
Expand Down
1 change: 1 addition & 0 deletions src/lexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ ENUM_STRUCT_WITH_NAMES_VALUES(TokenKind, TokenKindValue, TOKENS)
x( Continue, "continue" ) \
x( Return, "return" ) \
x( In, "in" ) \
x( Length, "length" ) \
ENUM_STRUCT_WITH_NAMES(Keyword, KEYWORDS)
#undef KEYWORDS
Expand Down
5 changes: 3 additions & 2 deletions src/mainloop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ bool Run( int argCount, char const* args[] )
char cppFilePath[256] = {};
inputFilename.CopyTo( cppFilePath );

// TODO At some point the intermediate cpp should go to a temp folder
int extIndex = inputFilename.FindLast( '.' );
if( extIndex == -1 )
extIndex = inputFilename.length;
Expand All @@ -530,7 +531,7 @@ bool Run( int argCount, char const* args[] )
ASSERT( available >= sizeof(".cpp") );
StringCopy( ".cpp", cppFilePath + extIndex, available );

if( !globalPlatform.WriteEntireFile( cppFilePath, pages ) )
if( !globalPlatform.WriteEntireFile( cppFilePath, pages, true ) )
return false;

// Execute C compiler
Expand Down Expand Up @@ -609,7 +610,7 @@ bool Run( int argCount, char const* args[] )
globalPlatform.Print( "\nDONE." );
}
else
DEBUGBREAK( globalBreakOnError );
DEBUGBREAK( true );

return exitCode == 0;
}
Expand Down
13 changes: 12 additions & 1 deletion src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,8 @@ Expr* ParsePostfixExpr( Lexer* lexer )
else if( MatchToken( TokenKind::Pound, lexer->token ) )
{
Token field = NextToken( lexer );
if( field.kind == TokenKind::Name )
// Allow keywords too as there may be some shared names (and they're lexed as a separate token type)
if( field.kind == TokenKind::Name || field.kind == TokenKind::Keyword )
{
InternString* intern = FindIntern( field.ident );
if( !intern || (intern->flags & InternString::MetaAttr) == 0 )
Expand Down Expand Up @@ -580,6 +581,9 @@ Expr* ParseMulExpr( Lexer* lexer )
{
Expr* expr = ParseRangeExpr( lexer );

if( !expr )
return nullptr;

// NOTE Range expressions cannot really be combined (for now at least!)
if( expr->kind == Expr::Range )
return expr;
Expand Down Expand Up @@ -1047,6 +1051,13 @@ Stmt* ParseSimpleStmt( SourcePos const& pos, Lexer* lexer, StmtList* parentBlock
bool consumeSemicolon = true;

Expr* expr = ParseCommaExpr( lexer );
if( !lexer->IsValid() )
{
while( !MatchToken( TokenKind::Semicolon, lexer->token ) )
NextToken( lexer );
RequireTokenAndAdvance( TokenKind::Semicolon, lexer );
return nullptr;
}

if( (expr->kind == Expr::Comma || expr->kind == Expr::Name) &&
MatchToken( TokenKind::Colon, lexer->token ) )
Expand Down
2 changes: 1 addition & 1 deletion src/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ typedef PLATFORM_FREE(PlatformFreeFunc);
typedef PLATFORM_GET_ABSOLUTE_PATH(PlatformGetAbsolutePathFunc);
#define PLATFORM_READ_ENTIRE_FILE(name) buffer name( char const* filename, MemoryArena* arena )
typedef PLATFORM_READ_ENTIRE_FILE(PlatformReadEntireFileFunc);
#define PLATFORM_WRITE_ENTIRE_FILE(name) bool name( char const* filename, Array<buffer> const& chunks )
#define PLATFORM_WRITE_ENTIRE_FILE(name) bool name( char const* filename, Array<buffer> const& chunks, bool overwrite )
typedef PLATFORM_WRITE_ENTIRE_FILE(PlatformWriteEntireFileFunc);

#define PLATFORM_CURRENT_TIME_MILLIS(name) f64 name()
Expand Down
Loading

0 comments on commit 0feca8b

Please sign in to comment.