Created
January 17, 2018 17:29
-
-
Save nanjizal/7aff9114b1e9364ebdd6c323e3ee7163 to your computer and use it in GitHub Desktop.
Adding a Haxe target theory/approach
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
To add target to Haxe compiler, general theory. | |
1) Adjust main.ml and globals.ml with the language keyword as per example diffs. | |
2) Add a language folder to std folder, with subfolder _std Populate ideally with base Array etc.. implementations and add the haxe/ds and sys packages. | |
3) Add a gentarget.ml file to the generators folder that does the heavy work of converting haxe AST to target code. |
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
diff --git a/src/core/globals.ml b/src/core/globals.ml | |
index 41a391e0d..e98b5af07 100644 | |
--- a/src/core/globals.ml | |
+++ b/src/core/globals.ml | |
@@ -18,6 +18,7 @@ type platform = | |
| Cs | |
| Java | |
| Python | |
+ | Perl | |
| Hl | |
| Eval | |
@@ -40,6 +41,7 @@ let platforms = [ | |
Cs; | |
Java; | |
Python; | |
+ Perl; | |
Hl; | |
Eval; | |
] | |
@@ -55,6 +57,7 @@ let platform_name = function | |
| Cs -> "cs" | |
| Java -> "java" | |
| Python -> "python" | |
+ | Perl -> "perl" | |
| Hl -> "hl" | |
| Eval -> "eval" | |
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
diff --git a/src/compiler/main.ml b/src/compiler/main.ml | |
index e712e58e3..b54ff5065 100644 | |
--- a/src/compiler/main.ml | |
+++ b/src/compiler/main.ml | |
@@ -79,7 +79,7 @@ let error ctx msg p = | |
let reserved_flags = [ | |
"cross";"js";"lua";"neko";"flash";"php";"cpp";"cs";"java";"python"; | |
- "as3";"swc";"macro";"sys";"static" | |
+ "perl";"as3";"swc";"macro";"sys";"static" | |
] | |
let delete_file f = try Sys.remove f with _ -> () | |
@@ -263,6 +263,9 @@ module Initialize = struct | |
if not (Common.defined com Define.PythonVersion) then | |
Common.define_value com Define.PythonVersion "3.3"; | |
"python" | |
+ | Perl -> | |
+ add_std "perl"; | |
+ "perl" | |
| Hl -> | |
add_std "hl"; | |
"hl" | |
@@ -316,6 +319,8 @@ let generate tctx ext xml_out interp swf_header = | |
Genjava.generate,"java" | |
| Python -> | |
Genpy.generate,"python" | |
+ | Perl -> | |
+ Genperl.generate,"perl" | |
| Hl -> | |
Genhl.generate,"hl" | |
| Eval -> | |
@@ -494,6 +499,9 @@ try | |
("-python",Arg.String (fun dir -> | |
Initialize.set_platform com Python dir; | |
),"<file> : generate Python code as target file"); | |
+ ("-perl",Arg.String (fun dir -> | |
+ Initialize.set_platform com Perl dir; | |
+ ),"<file> : generate Perl code as target file"); | |
("-hl",Arg.String (fun file -> | |
Initialize.set_platform com Hl file; | |
),"<file> : compile HL code as target file"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment