Skip to content

Commit 8735b4c

Browse files
Fix broken example files
1 parent f06fed4 commit 8735b4c

File tree

9 files changed

+168
-135
lines changed

9 files changed

+168
-135
lines changed

test/bigint.bcs

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,35 @@ strict namespace BigInt {
2828
// ==========================================================================
2929

3030
str Add( str a, str b ) {
31-
return StrParam( msgbuild: ( msgbuild auto() ) {
31+
return buildmsg ( StrParam() ) {
3232
// Calculate sum.
33-
str sum = StrParam( msgbuild: ( msgbuild auto() ) {
34-
int i_a = a.length() - 1;
35-
int i_b = b.length() - 1;
36-
int carry = 0;
37-
while ( i_a >= 0 || i_b >= 0 ) {
38-
int sum = ( i_a >= 0 ? a[ i_a ] - '0' : 0 ) +
39-
( i_b >= 0 ? b[ i_b ] - '0' : 0 ) + carry;
40-
append( d: sum - ( int( sum >= 10 ) * 10 ) );
41-
carry = int( sum >= 10 );
42-
--i_a;
43-
--i_b;
33+
str sum = ( auto() ) {
34+
return buildmsg ( StrParam() ) {
35+
int i_a = a.length() - 1;
36+
int i_b = b.length() - 1;
37+
int carry = 0;
38+
while ( i_a >= 0 || i_b >= 0 ) {
39+
int sum = ( i_a >= 0 ? a[ i_a ] - '0' : 0 ) +
40+
( i_b >= 0 ? b[ i_b ] - '0' : 0 ) + carry;
41+
append( d: sum - ( int( sum >= 10 ) * 10 ) );
42+
carry = int( sum >= 10 );
43+
--i_a;
44+
--i_b;
45+
}
46+
append( c: carry * '1' );
4447
}
45-
append( c: carry * '1' );
46-
} );
48+
}();
4749
// Output sum.
4850
int i = sum.length() - 1;
4951
while ( i >= 0 ) {
5052
append( c: sum[ i ] );
5153
--i;
5254
}
53-
} );
55+
}
5456
}
5557

5658
str Sub( str a, str b ) {
57-
return StrParam( msgbuild: ( msgbuild auto() ) {
59+
return buildmsg ( StrParam() ) {
5860
// Negative.
5961
if ( Lt( a, b ) ) {
6062
append( c: '-' );
@@ -63,20 +65,22 @@ str Sub( str a, str b ) {
6365
b = temp_a;
6466
}
6567
// Calculate difference.
66-
str diff = StrParam( msgbuild: ( msgbuild auto() ) {
67-
int i_a = a.length() - 1;
68-
int i_b = b.length() - 1;
69-
int borrow = 0;
70-
while ( i_a >= 0 || i_b >= 0 ) {
71-
int digit_a = ( i_a >= 0 ? a[ i_a ] - '0' : 0 );
72-
int digit_b = ( i_b >= 0 ? b[ i_b ] - '0' : 0 );
73-
append( d: ( digit_a - borrow ) +
74-
( int( digit_a - borrow < digit_b ) * 10 ) - digit_b );
75-
borrow = int( digit_a - borrow < digit_b );
76-
--i_a;
77-
--i_b;
68+
str diff = ( auto() ) {
69+
return buildmsg ( StrParam() ) {
70+
int i_a = a.length() - 1;
71+
int i_b = b.length() - 1;
72+
int borrow = 0;
73+
while ( i_a >= 0 || i_b >= 0 ) {
74+
int digit_a = ( i_a >= 0 ? a[ i_a ] - '0' : 0 );
75+
int digit_b = ( i_b >= 0 ? b[ i_b ] - '0' : 0 );
76+
append( d: ( digit_a - borrow ) +
77+
( int( digit_a - borrow < digit_b ) * 10 ) - digit_b );
78+
borrow = int( digit_a - borrow < digit_b );
79+
--i_a;
80+
--i_b;
81+
}
7882
}
79-
} );
83+
}();
8084
// Output difference.
8185
int i = diff.length() - 1;
8286
while ( i >= 1 && diff[ i ] == '0' ) {
@@ -86,7 +90,7 @@ str Sub( str a, str b ) {
8690
append( c: diff[ i ] );
8791
--i;
8892
}
89-
} );
93+
}
9094
}
9195

9296
bool Lt( str a, str b ) {
@@ -103,4 +107,4 @@ bool Lt( str a, str b ) {
103107
}
104108
}
105109

106-
}
110+
}

test/functions.bcs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ int StriCmp( str a, str b, int length = -1 ) {
3636

3737
// Get substring.
3838
str StrMid( str string, int start, int length ) {
39-
return StrParam( msgbuild: ( msgbuild auto() ) {
39+
return buildmsg ( StrParam() ) {
4040
if ( start < 0 ) {
4141
start = 0;
4242
}
@@ -47,7 +47,7 @@ str StrMid( str string, int start, int length ) {
4747
append( c: c );
4848
++i;
4949
}
50-
} );
50+
}
5151
}
5252

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

6363
// Get string as uppercase. Character encoding assumed to be ASCII.
6464
str StrToUpper( str string ) {
65-
return StrParam( msgbuild: ( msgbuild auto() ) {
65+
return buildmsg ( StrParam() ) {
6666
foreach ( auto ch; string ) {
6767
if ( ch >= 97 && ch <= 122 ) {
6868
append( c: ch - 32 );
@@ -71,12 +71,12 @@ str StrToUpper( str string ) {
7171
append( c: ch );
7272
}
7373
}
74-
} );
74+
}
7575
}
7676

7777
// Get string as lowercase.
7878
str StrToLower( str string ) {
79-
return StrParam( msgbuild: ( msgbuild auto() ) {
79+
return buildmsg ( StrParam() ) {
8080
foreach ( auto ch; string ) {
8181
if ( ch >= 65 && ch <= 90 ) {
8282
append( c: ch + 32 );
@@ -85,14 +85,14 @@ str StrToLower( str string ) {
8585
append( c: ch );
8686
}
8787
}
88-
} );
88+
}
8989
}
9090

9191
// Supports up to 10 arguments, integer or string.
9292
void Printf( str format, raw arg1 = 0, raw arg2 = 0, raw arg3 = 0,
9393
raw arg4 = 0, raw arg5 = 0, raw arg6 = 0, raw arg7 = 0, raw arg8 = 0,
9494
raw arg9 = 0, raw arg10 = 0 ) {
95-
Print( msgbuild: ( msgbuild auto() ) {
95+
buildmsg ( Print() ) {
9696
int num = 0;
9797
int pos = 0;
9898
while ( num < 10 ) {
@@ -140,7 +140,7 @@ void Printf( str format, raw arg1 = 0, raw arg2 = 0, raw arg3 = 0,
140140
++num;
141141
}
142142
done:
143-
} );
143+
}
144144
}
145145

146-
}
146+
}

0 commit comments

Comments
 (0)