Created
October 12, 2022 11:59
-
-
Save mattn/e9be08d58c4247f29e9d7fb6393eec7a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "runtime/exceptions.hpp" | |
#include "runtime/global_io.hpp" | |
#include "runtime/global_json.hpp" | |
#include "runtime/global_symbol.hpp" | |
#include "runtime/js_value.hpp" | |
#include <coroutine> | |
int prog() { | |
auto IO = create_IO_global(); | |
auto JSON = create_JSON_global(); | |
auto Symbol = create_symbol_global(); | |
JSValue fizzbuzz = JSValue::new_function( | |
[=](JSValue thisArg, std::vector<JSValue> &args) mutable -> JSValue { | |
{ | |
for (JSValue n = (JSValue{static_cast<double>(1)}).boxed_value(); | |
((n) <= (JSValue{static_cast<double>(100)})).coerce_to_bool(); | |
(n)++) { | |
{ | |
if ((((n) % (JSValue{static_cast<double>(15)})) == | |
(JSValue{static_cast<double>(0)})) | |
.coerce_to_bool()) { | |
IO[JSValue{"write_to_stdout"}]( | |
{(JSValue{"FizzBuzz\n"}).boxed_value()}); | |
} else { | |
if ((((n) % (JSValue{static_cast<double>(3)})) == | |
(JSValue{static_cast<double>(0)})) | |
.coerce_to_bool()) { | |
IO[JSValue{"write_to_stdout"}]( | |
{(JSValue{"Fizz\n"}).boxed_value()}); | |
} else { | |
if ((((n) % (JSValue{static_cast<double>(5)})) == | |
(JSValue{static_cast<double>(0)})) | |
.coerce_to_bool()) { | |
IO[JSValue{"write_to_stdout"}]( | |
{(JSValue{"Buzz\n"}).boxed_value()}); | |
} else { | |
IO[JSValue{"write_to_stdout"}]( | |
{((n) + (JSValue{"\n"})).boxed_value()}); | |
}; | |
}; | |
}; | |
}; | |
}; | |
} | |
return JSValue::undefined(); | |
}); | |
; | |
; | |
fizzbuzz({}); | |
return 0; | |
} | |
int main() { | |
try { | |
{ prog(); } | |
} catch (std::string e) { | |
{ printf("EXCEPTION: %s\n", e.c_str()); } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment