Skip to content

Commit

Permalink
Update standard and test files to reflect changes in syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
positively-charged committed Jan 4, 2017
1 parent 317512f commit a85c307
Show file tree
Hide file tree
Showing 36 changed files with 117 additions and 111 deletions.
4 changes: 3 additions & 1 deletion lib/zasm.bcs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
#error you must #import this file
#endif

typeaware namespace {
// ==========================================================================
strict namespace {
// ==========================================================================

// Instruction opcodes.
enum {
Expand Down
8 changes: 5 additions & 3 deletions lib/zcommon.bcs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
#error you must #import this file
#endif

typeaware namespace {
// ==========================================================================
strict namespace {
// ==========================================================================

// Constants
// ==========================================================================
// --------------------------------------------------------------------------

enum { OFF = 0 };
enum { ON = 1 };
Expand Down Expand Up @@ -1155,7 +1157,7 @@ enum { INT_MIN = -INT_MAX - 1 };
enum { INT_MAX = 2147483647 };

// Functions
// ==========================================================================
// --------------------------------------------------------------------------

special

Expand Down
20 changes: 10 additions & 10 deletions test/bigint.bcs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "zcommon.h"

// ==========================================================================
typeaware blockscoping namespace {
strict namespace {
// ==========================================================================

script "Main" open {
Expand All @@ -24,13 +24,13 @@ script "Main" open {
}

// ==========================================================================
typeaware blockscoping namespace BigInt {
strict namespace BigInt {
// ==========================================================================

str Add( str a, str b ) {
return StrParam( msgbuild: ( function msgbuild {
return StrParam( msgbuild: ( msgbuild auto() ) {
// Calculate sum.
str sum = StrParam( msgbuild: ( function msgbuild {
str sum = StrParam( msgbuild: ( msgbuild auto() ) {
int i_a = a.length() - 1;
int i_b = b.length() - 1;
int carry = 0;
Expand All @@ -43,18 +43,18 @@ str Add( str a, str b ) {
--i_b;
}
append( c: carry * '1' );
} ) );
} );
// Output sum.
int i = sum.length() - 1;
while ( i >= 0 ) {
append( c: sum[ i ] );
--i;
}
} ) );
} );
}

str Sub( str a, str b ) {
return StrParam( msgbuild: ( function msgbuild {
return StrParam( msgbuild: ( msgbuild auto() ) {
// Negative.
if ( Lt( a, b ) ) {
append( c: '-' );
Expand All @@ -63,7 +63,7 @@ str Sub( str a, str b ) {
b = temp_a;
}
// Calculate difference.
str diff = StrParam( msgbuild: ( function msgbuild {
str diff = StrParam( msgbuild: ( msgbuild auto() ) {
int i_a = a.length() - 1;
int i_b = b.length() - 1;
int borrow = 0;
Expand All @@ -76,7 +76,7 @@ str Sub( str a, str b ) {
--i_a;
--i_b;
}
} ) );
} );
// Output difference.
int i = diff.length() - 1;
while ( i >= 1 && diff[ i ] == '0' ) {
Expand All @@ -86,7 +86,7 @@ str Sub( str a, str b ) {
append( c: diff[ i ] );
--i;
}
} ) );
} );
}

bool Lt( str a, str b ) {
Expand Down
18 changes: 9 additions & 9 deletions test/functions.bcs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ==========================================================================
typeaware blockscoping namespace FuncTest {
strict namespace FuncTest {
// ==========================================================================

// Compare two strings for equality, up to the specified length.
Expand Down Expand Up @@ -36,7 +36,7 @@ int StriCmp( str a, str b, int length = -1 ) {

// Get substring.
str StrMid( str string, int start, int length ) {
return StrParam( msgbuild: ( function msgbuild {
return StrParam( msgbuild: ( msgbuild auto() ) {
if ( start < 0 ) {
start = 0;
}
Expand All @@ -47,7 +47,7 @@ str StrMid( str string, int start, int length ) {
append( c: c );
++i;
}
} ) );
} );
}

// Get substring, starting at offset 0.
Expand All @@ -62,7 +62,7 @@ str StrRight( str string, int length ) {

// Get string as uppercase. Character encoding assumed to be ASCII.
str StrToUpper( str string ) {
return StrParam( msgbuild: ( function msgbuild {
return StrParam( msgbuild: ( msgbuild auto() ) {
foreach ( auto ch; string ) {
if ( ch >= 97 && ch <= 122 ) {
append( c: ch - 32 );
Expand All @@ -71,12 +71,12 @@ str StrToUpper( str string ) {
append( c: ch );
}
}
} ) );
} );
}

// Get string as lowercase.
str StrToLower( str string ) {
return StrParam( msgbuild: ( function msgbuild {
return StrParam( msgbuild: ( msgbuild auto() ) {
foreach ( auto ch; string ) {
if ( ch >= 65 && ch <= 90 ) {
append( c: ch + 32 );
Expand All @@ -85,14 +85,14 @@ str StrToLower( str string ) {
append( c: ch );
}
}
} ) );
} );
}

// Supports up to 10 arguments, integer or string.
void Printf( str format, raw arg1 = 0, raw arg2 = 0, raw arg3 = 0,
raw arg4 = 0, raw arg5 = 0, raw arg6 = 0, raw arg7 = 0, raw arg8 = 0,
raw arg9 = 0, raw arg10 = 0 ) {
Print( msgbuild: ( function msgbuild {
Print( msgbuild: ( msgbuild auto() ) {
int num = 0;
int pos = 0;
while ( num < 10 ) {
Expand Down Expand Up @@ -140,7 +140,7 @@ void Printf( str format, raw arg1 = 0, raw arg2 = 0, raw arg3 = 0,
++num;
}
done:
} ) );
} );
}

}
Loading

0 comments on commit a85c307

Please sign in to comment.