Skip to content

Commit b27cf19

Browse files
committed
[[ Emscripten ]] Tweaks to build of engine
This patch allows multiple object files to be included in the javascriptify call, and ensures the builtin engine module object is passed through directly to it, so that everything needed gets included.
1 parent 3c9189e commit b27cf19

4 files changed

Lines changed: 26 additions & 8 deletions

File tree

engine/engine.gyp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,11 @@
535535
},
536536
},
537537

538+
'sources':
539+
[
540+
'<(PRODUCT_DIR)/obj.target/engine_lcb_modules/geni/engine_lcb_modules.o',
541+
],
542+
538543
'sources!':
539544
[
540545
'src/dummy.cpp',

libscript/src/script-builder.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,6 +1910,10 @@ MCScriptMapTypeToForeignPrimitiveTypeInModule(MCScriptModuleBuilderRef self, uin
19101910
/* Foundation Types */
19111911
{ "undefined", kMCScriptForeignPrimitiveTypePointer },
19121912
{ "any", kMCScriptForeignPrimitiveTypePointer },
1913+
{ "bool", kMCScriptForeignPrimitiveTypeCBool },
1914+
{ "double", kMCScriptForeignPrimitiveTypeCDouble },
1915+
{ "sint", kMCScriptForeignPrimitiveTypeSInt },
1916+
{ "uint", kMCScriptForeignPrimitiveTypeUInt },
19131917

19141918
{ "Boolean", kMCScriptForeignPrimitiveTypePointer },
19151919
{ "Number", kMCScriptForeignPrimitiveTypePointer },

toolchain/lc-compile/src/emit.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,9 @@ static MCStringRef EmittedBuiltinAdd(NameRef p_symbol_name, uindex_t p_type_inde
368368
t_builtin->parameter_count = MCScriptQueryForeignHandlerParameterCountInModule(s_builder, p_type_index);
369369
t_builtin->parameter_types = new MCScriptForeignPrimitiveType[t_builtin->parameter_count];
370370
for(uindex_t i = 0; i < t_builtin->parameter_count; i++)
371+
{
371372
t_builtin->parameter_types[i] = MCScriptQueryForeignHandlerParameterTypeInModule(s_builder, p_type_index, i);
373+
}
372374
}
373375
else
374376
{
@@ -1065,12 +1067,12 @@ void EmitVariableDefinition(intptr_t p_index, PositionRef p_position, NameRef p_
10651067
cstring_from_nameref(p_name), p_type_index);
10661068
}
10671069

1068-
void EmitForeignHandlerDefinition(intptr_t p_index, PositionRef p_position, NameRef p_name, intptr_t p_type_index, intptr_t p_binding)
1070+
static void EmitForeignHandlerDefinition(intptr_t p_index, PositionRef p_position, NameRef p_name, intptr_t p_type_index, intptr_t p_binding, bool p_force_builtin)
10691071
{
10701072
MCAutoStringRef t_binding_str;
1071-
if (strcmp((const char *)p_binding, "<builtin>") == 0)
1073+
if (strcmp((const char *)p_binding, "<builtin>") == 0 || p_force_builtin)
10721074
{
1073-
t_binding_str = EmittedBuiltinAdd(p_name, p_type_index);
1075+
t_binding_str = EmittedBuiltinAdd(p_force_builtin ? nameref_from_cstring((const char *)p_binding) : p_name, p_type_index);
10741076
}
10751077
else
10761078
t_binding_str = to_mcstringref(p_binding);
@@ -1109,6 +1111,11 @@ void EmitForeignHandlerDefinition(intptr_t p_index, PositionRef p_position, Name
11091111
(const char *) p_binding);
11101112
}
11111113

1114+
void EmitForeignHandlerDefinition(intptr_t p_index, PositionRef p_position, NameRef p_name, intptr_t p_type_index, intptr_t p_binding)
1115+
{
1116+
EmitForeignHandlerDefinition(p_index, p_position, p_name, p_type_index, p_binding, false);
1117+
}
1118+
11121119
void EmitPropertyDefinition(intptr_t p_index, PositionRef p_position, NameRef p_name, intptr_t p_getter, intptr_t p_setter)
11131120
{
11141121
MCScriptAddPropertyToModule(s_builder, to_mcnameref(p_name), (uindex_t)p_getter, (uindex_t)p_setter, (uindex_t)p_index);
@@ -2415,13 +2422,13 @@ static void BuildBuiltinModule_ForeignType(const char *p_name, const char *p_for
24152422
static void BuildBuiltinModule_ForeignHandler1(intptr_t p_return_type, MCHandlerTypeFieldMode p_arg_mode_0, const char *p_arg_name_0, intptr_t p_arg_type_0, const char *p_name, const char *p_foreign_name)
24162423
{
24172424
intptr_t t_handler_type_index = -1;
2418-
EmitBeginHandlerType(p_return_type);
2425+
EmitBeginForeignHandlerType(p_return_type);
24192426
EmitHandlerTypeParameter(p_arg_mode_0, nameref_from_cstring(p_arg_name_0), p_arg_type_0);
24202427
EmitEndHandlerType(t_handler_type_index);
24212428

24222429
intptr_t t_handler_def = -1;
24232430
EmitDefinitionIndex("foreignhandler", t_handler_def);
2424-
EmitForeignHandlerDefinition(t_handler_def, 0, nameref_from_cstring(p_name), t_handler_type_index, (intptr_t)p_foreign_name);
2431+
EmitForeignHandlerDefinition(t_handler_def, 0, nameref_from_cstring(p_name), t_handler_type_index, (intptr_t)p_foreign_name, true);
24252432
EmitExportedDefinition(t_handler_def);
24262433
}
24272434

@@ -2431,14 +2438,14 @@ static void BuildBuiltinModule_ForeignHandler2(intptr_t p_return_type,
24312438
const char *p_name, const char *p_foreign_name)
24322439
{
24332440
intptr_t t_handler_type_index = -1;
2434-
EmitBeginHandlerType(p_return_type);
2441+
EmitBeginForeignHandlerType(p_return_type);
24352442
EmitHandlerTypeParameter(p_arg_mode_0, nameref_from_cstring(p_arg_name_0), p_arg_type_0);
24362443
EmitHandlerTypeParameter(p_arg_mode_1, nameref_from_cstring(p_arg_name_1), p_arg_type_1);
24372444
EmitEndHandlerType(t_handler_type_index);
24382445

24392446
intptr_t t_handler_def = -1;
24402447
EmitDefinitionIndex("foreignhandler", t_handler_def);
2441-
EmitForeignHandlerDefinition(t_handler_def, 0, nameref_from_cstring(p_name), t_handler_type_index, (intptr_t)p_foreign_name);
2448+
EmitForeignHandlerDefinition(t_handler_def, 0, nameref_from_cstring(p_name), t_handler_type_index, (intptr_t)p_foreign_name, true);
24422449
EmitExportedDefinition(t_handler_def);
24432450
}
24442451

util/emscripten-javascriptify.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@
6767

6868
command = emcc + optimisation_flags + cflags
6969

70-
command.append(options['input'][0])
70+
for input in options['input']:
71+
command.append(input)
72+
7173
command += ['-o', options['output'][0]]
7274

7375
for setting in sorted(settings.keys()):

0 commit comments

Comments
 (0)