diff --git a/src/compiler/args.ml b/src/compiler/args.ml
index bcbb614ce..0db5da047 100644
--- a/src/compiler/args.ml
+++ b/src/compiler/args.ml
@@ -84,6 +84,9 @@ let parse_args com =
("Target",["--cs"],["-cs"],Arg.String (fun dir ->
set_platform com Cs dir;
),"<directory>","generate C# code into target directory");
+ ("Target",["--kotlin"],["-kotlin"],Arg.String (fun dir ->
+ set_platform com Kotlin dir;
+ ),"<directory>","generate Kotlin code into target directory");
("Target",["--java"],["-java"],Arg.String (fun dir ->
set_platform com Java dir;
),"<directory>","generate Java code into target directory");
@@ -371,4 +374,4 @@ let parse_args com =
actx.raise_usage <- (fun () -> raise (Helper.HelpMessage (usage_string basic_args_spec usage)));
(* Handle CLI arguments *)
process com.args;
- actx
\ No newline at end of file
+ actx
diff --git a/src/compiler/compiler.ml b/src/compiler/compiler.ml
index ce469600e..bb70fc337 100644
--- a/src/compiler/compiler.ml
+++ b/src/compiler/compiler.ml
@@ -136,6 +136,10 @@ module Setup = struct
end;
add_std "java";
"java"
+ | Kotlin ->
+ Java.before_generate com;
+ add_std "kotlin";
+ "kotlin"
| Python ->
add_std "python";
if not (Common.defined com Define.PythonVersion) then
@@ -602,6 +606,8 @@ module HighLevel = struct
loop acc (lines @ args)
| ("--jvm" | "--java" | "-java" as arg) :: dir :: args ->
loop_lib arg dir "hxjava" acc args
+ | ("--kotlin" | "-kotlin" as arg) :: dir :: args ->
+ loop_lib arg dir "hxjava" acc args
| ("--cs" | "-cs" as arg) :: dir :: args ->
loop_lib arg dir "hxcs" acc args
| arg :: l ->
diff --git a/src/compiler/generate.ml b/src/compiler/generate.ml
index 1cbcd6df1..c1755b311 100644
--- a/src/compiler/generate.ml
+++ b/src/compiler/generate.ml
@@ -53,6 +53,7 @@ let generate ctx tctx ext actx =
| Cpp when Common.defined com Define.Cppia -> ()
| Cpp | Cs | Php -> Path.mkdir_from_path (com.file ^ "/.")
| Java when not actx.jvm_flag -> Path.mkdir_from_path (com.file ^ "/.")
+ | Kotlin -> Path.mkdir_from_path (com.file ^ "/.")
| _ -> Path.mkdir_from_path com.file
end;
if actx.interp then
@@ -83,6 +84,8 @@ let generate ctx tctx ext actx =
Genjvm.generate actx.jvm_flag,"java"
else
Genjava.generate,"java"
+ | Kotlin ->
+ Genkotlin.generate,"kotlin"
| Python ->
Genpy.generate,"python"
| Hl ->
diff --git a/src/context/common.ml b/src/context/common.ml
index 1517252d0..2b1745c43 100644
--- a/src/context/common.ml
+++ b/src/context/common.ml
@@ -525,6 +525,7 @@ let short_platform_name = function
| Cpp -> "cpp"
| Cs -> "cs"
| Java -> "jav"
+ | Kotlin -> "kt"
| Python -> "py"
| Hl -> "hl"
| Eval -> "evl"
@@ -745,6 +746,32 @@ let get_config com =
};
pf_supports_atomics = true;
}
+ | Kotlin ->
+ {
+ default_config with
+ pf_capture_policy = CPWrapRef;
+ pf_pad_nulls = true;
+ pf_overload = true;
+ pf_supports_threads = true;
+ pf_supports_rest_args = true;
+ pf_this_before_super = false;
+ pf_exceptions = { default_config.pf_exceptions with
+ ec_native_throws = [
+ ["haxe"],"Exception";
+ ];
+ ec_native_catches = [
+ ["haxe"],"Exception";
+ ];
+ ec_wildcard_catch = (["haxe"],"Exception");
+ ec_base_throw = (["haxe"],"Exception");
+ };
+ pf_scoping =
+ {
+ vs_scope = FunctionScope;
+ vs_flags = [NoShadowing; ReserveAllTopLevelSymbols; ReserveNames(["_"])];
+ };
+ pf_supports_atomics = true;
+ }
| Python ->
{
default_config with
diff --git a/src/context/nativeLibraryHandler.ml b/src/context/nativeLibraryHandler.ml
index db6837204..594814b3e 100644
--- a/src/context/nativeLibraryHandler.ml
+++ b/src/context/nativeLibraryHandler.ml
@@ -36,6 +36,18 @@ let add_native_lib com file is_extern = match com.platform with
) (Sys.readdir file))
else
add file
+ | Globals.Kotlin ->
+ let add file =
+ let std = file = "lib/hxjava-std.jar" in
+ Java.add_java_lib com file std is_extern false
+ in
+ if try Sys.is_directory file with Sys_error _ -> false then
+ let dir = file in
+ (fun _ -> Array.iter (fun file ->
+ if ExtString.String.ends_with file ".jar" then add (dir ^ "/" ^ file) ()
+ ) (Sys.readdir file))
+ else
+ add file
| Globals.Cs ->
let file, is_std = match ExtString.String.nsplit file "@" with
| [file] ->
@@ -46,4 +58,4 @@ let add_native_lib com file is_extern = match com.platform with
in
Dotnet.add_net_lib com file is_std is_extern
| pf ->
- failwith (Printf.sprintf "Target %s does not support native libraries (trying to load %s)" (platform_name pf) file);
\ No newline at end of file
+ failwith (Printf.sprintf "Target %s does not support native libraries (trying to load %s)" (platform_name pf) file);
diff --git a/src/core/globals.ml b/src/core/globals.ml
index 4292add77..49b7a499d 100644
--- a/src/core/globals.ml
+++ b/src/core/globals.ml
@@ -20,6 +20,7 @@ type platform =
| Cpp
| Cs
| Java
+ | Kotlin
| Python
| Hl
| Eval
@@ -85,6 +86,7 @@ let platforms = [
Cpp;
Cs;
Java;
+ Kotlin;
Python;
Hl;
Eval;
@@ -101,6 +103,7 @@ let platform_name = function
| Cpp -> "cpp"
| Cs -> "cs"
| Java -> "java"
+ | Kotlin -> "kotlin"
| Python -> "python"
| Hl -> "hl"
| Eval -> "eval"
@@ -116,6 +119,7 @@ let parse_platform = function
| "cpp" -> Cpp
| "cs" -> Cs
| "java" -> Java
+ | "kotlin" -> Kotlin
| "python" -> Python
| "hl" -> Hl
| "eval" -> Eval
diff --git a/src/filters/exceptions.ml b/src/filters/exceptions.ml
index a9c97dfde..cb58ca1aa 100644
--- a/src/filters/exceptions.ml
+++ b/src/filters/exceptions.ml
@@ -522,7 +522,7 @@ let catch_native ctx catches t p =
let filter tctx =
let stub e = e in
match tctx.com.platform with (* TODO: implement for all targets *)
- | Php | Js | Java | Cs | Python | Lua | Eval | Neko | Flash | Hl | Cpp ->
+ | Php | Js | Java | Kotlin | Cs | Python | Lua | Eval | Neko | Flash | Hl | Cpp ->
let config = tctx.com.config.pf_exceptions in
let tp (pack,name) =
match List.rev pack with