Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F7538306
test_tco_zeroarg.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
672 B
Referenced Files
None
Subscribers
None
test_tco_zeroarg.js
View Options
// Test: verify zero-arg tail call actually uses TCO by going deep enough to
// guarantee a stack overflow without it.
// Pure zero-arg self-recursion with no parameters at all
let
n
=
0
;
function
go
()
{
n
++
;
if
(
n
>=
1000000
)
return
'ok'
;
return
go
();
}
const
r
=
go
();
console
.
log
(
'result:'
,
r
,
'n:'
,
n
);
if
(
r
!==
'ok'
)
{
console
.
log
(
'FAIL'
);
process
.
exit
(
1
);
}
// Zero-arg mutual recursion
let
m
=
0
;
function
a
()
{
m
++
;
if
(
m
>=
1000000
)
return
m
;
return
b
();
}
function
b
()
{
m
++
;
if
(
m
>=
1000000
)
return
m
;
return
a
();
}
const
r2
=
a
();
console
.
log
(
'mutual result:'
,
r2
);
if
(
r2
!==
1000000
)
{
console
.
log
(
'FAIL'
);
process
.
exit
(
1
);
}
console
.
log
(
'PASS'
);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Jun 17, 12:56 PM (1 d, 7 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
570739
Default Alt Text
test_tco_zeroarg.js (672 B)
Attached To
Mode
rANT Ant
Attached
Detach File
Event Timeline
Log In to Comment