emscripten: intro the emscripten platform to generate to JS
authorAlexis Laferrière <alexis.laf@xymus.net>
Fri, 13 Jun 2014 22:13:03 +0000 (18:13 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Mon, 16 Jun 2014 16:09:22 +0000 (12:09 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/emscripten.nit [new file with mode: 0644]
src/emscripten_platform.nit [new file with mode: 0644]
src/nitg.nit

diff --git a/lib/emscripten.nit b/lib/emscripten.nit
new file mode 100644 (file)
index 0000000..65fe1f4
--- /dev/null
@@ -0,0 +1,17 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2014 Alexis Laferrière <alexis.laf@xymus.net>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+module emscripten is platform
diff --git a/src/emscripten_platform.nit b/src/emscripten_platform.nit
new file mode 100644 (file)
index 0000000..84d8d34
--- /dev/null
@@ -0,0 +1,57 @@
+# This file is part of NIT ( http://www.nitlanguage.org )
+#
+# Copyright 2014 Alexis Laferrière <alexis.laf@xymus.net>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Compile to JavaScript using the Emscripten SDK
+module emscripten_platform
+
+import platform
+import abstract_compiler
+
+redef class ToolContext
+       redef fun platform_from_name(name)
+       do
+               if name == "emscripten" then return new EmscriptenPlatform
+               return super
+       end
+end
+
+class EmscriptenPlatform
+       super Platform
+
+       redef fun supports_libunwind do return false
+       redef fun supports_libgc do return false
+       redef fun toolchain(toolcontext) do return new EnscriptenToolchain(toolcontext)
+end
+
+class EnscriptenToolchain
+       super MakefileToolchain
+
+       redef fun makefile_name(mainmodule) do return "{mainmodule.name}.js.mk"
+
+       redef fun default_outname(mainmodule) do return "{super}.js"
+
+       redef fun write_makefile(compiler, compile_dir, cfiles)
+       do
+               super
+
+               var emcc_make_flags = "CC=emcc CFLAGS='-g -Wno-unused-value -Wno-switch -Qunused-arguments'"
+
+               var make_flags = self.toolcontext.opt_make_flags.value  
+               if make_flags == null then
+                       self.toolcontext.opt_make_flags.value = emcc_make_flags
+               else make_flags.append emcc_make_flags
+       end
+end
index 0714632..66cd891 100644 (file)
@@ -27,6 +27,7 @@ import separate_compiler
 import android_platform
 import compiler_ffi
 import pnacl_platform
+import emscripten_platform
 
 redef class ToolContext
        redef fun process_options(args)