Skip to content

Commit

Permalink
Fixes missing stream cleanup in emscripten builds
Browse files Browse the repository at this point in the history
I did this months ago, just never committed it onto master for some reason.
  • Loading branch information
Altoids1 committed Jul 23, 2023
1 parent 7821b9b commit 57df968
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -374,3 +374,4 @@ Joao.exe

## Meson garbage
builddir
cross_wasm.txt
2 changes: 1 addition & 1 deletion Args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ static FailureOr try_run_expression(Program& prog, std::string&& expr_str) {
//This means that we'll have to get kinda funky with it if we want to get user input w/o the front-end being a laggy, spinny, crashy mess.
//
//Make sure to use the -sASYNCIFY arg to em++ to make this work.
//I'd add something to detect if you forget, but since it's a linker arg, the compiler doesn't get to know about that.
//meson.build *SHOULD* have it as a default linker argument. Try not to override it or the whole binary may just, not work at runtime.
static void detail_get_line(std::string& ret)
{
using std::cin;
Expand Down
1 change: 1 addition & 0 deletions Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ void Interpreter::UncaughtRuntime(const Value& err)
throw err;
#else
int code = err.t_value.as_object_ptr->get_property(*this, "code").t_value.as_int;
std::cout.flush();
if (code)
exit(code);
else
Expand Down
4 changes: 2 additions & 2 deletions Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -699,8 +699,8 @@ class Parser
if (t)
std::cout << t->dump();
else
std::cout << "Parser Error Error: No Token pointer provided to ParserError()!\n";

std::cout << "Parser Error Error: No Token pointer provided to ParserError()!";
std::cout << std::endl; // This is an emscripten thing. We need to make sure this is flushed.
if (!is_interactive)
#ifdef JOAO_SAFE
throw error::parser(what);
Expand Down
4 changes: 2 additions & 2 deletions docs/cross_wasm.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ ar = 'WHEREEVER_IT_IS/emscripten/emar'

[built-in options]
c_args = []
c_link_args = ['-sENVIRONMENT=web','-sASYNCIFY','--emrun', '-ojoao.html']
c_link_args = ['-sENVIRONMENT=web','-sASYNCIFY', '-sEXIT_RUNTIME=1']
cpp_args = []
cpp_link_args = ['-sENVIRONMENT=web','-sASYNCIFY','--emrun', '-ojoao.html']
cpp_link_args = ['-sENVIRONMENT=web','-sASYNCIFY', '-sEXIT_RUNTIME=1']

[host_machine]

Expand Down
10 changes: 8 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,14 @@ configure_file(input : 'config.h.in', output : 'config.h',
'patch': version_parts[2],
}
)

exe = executable('joao', nativefuncs + src)
if build_machine.system() == 'emscripten'
exe = executable('joao', nativefuncs + src,
cpp_args : [],
link_args : ['-sASYNCIFY']
)
else
exe = executable('joao', nativefuncs + src)
endif

# Diagnostic tests
diagnostics = [ #Meson has a philosophical disagreement with procedurally generating the list of files in a directory, so...
Expand Down

0 comments on commit 57df968

Please sign in to comment.