Parcourir la source

LF normalization

Caue Waneck il y a 12 ans
Parent
commit
8e32d7f112
100 fichiers modifiés avec 14929 ajouts et 14927 suppressions
  1. 2 0
      .gitattributes
  2. 171 171
      Makefile
  3. 497 497
      dce.ml
  4. 24 24
      doc/CONTRIB.txt
  5. 327 327
      doc/EnvVarUpdate.nsh
  6. 54 54
      doc/all.hxproj
  7. 5 5
      doc/extract.hxml
  8. 1224 1224
      doc/extract.patch
  9. 183 183
      doc/installer.nsi
  10. 142 142
      haxe.hxproj
  11. 4544 4544
      interp.ml
  12. 1306 1306
      matcher.ml
  13. 175 175
      std/Map.hx
  14. 131 131
      std/Sys.hx
  15. 29 29
      std/cpp/FastIterator.hx
  16. 47 47
      std/cpp/_std/StringBuf.hx
  17. 152 152
      std/cpp/_std/Sys.hx
  18. 47 47
      std/cpp/_std/haxe/Int32.hx
  19. 39 39
      std/cpp/_std/haxe/Resource.hx
  20. 76 76
      std/cpp/_std/haxe/ds/ObjectMap.hx
  21. 29 29
      std/cpp/rtti/FieldIntegerLookup.hx
  22. 29 29
      std/cpp/rtti/FieldNumericIntegerLookup.hx
  23. 110 110
      std/cpp/vm/Debugger.hx
  24. 61 61
      std/cpp/zip/Compress.hx
  25. 43 43
      std/cs/Boot.hx
  26. 274 274
      std/cs/Lib.hx
  27. 33 33
      std/cs/NativeArray.hx
  28. 29 29
      std/cs/Out.hx
  29. 53 53
      std/cs/Pointer.hx
  30. 29 29
      std/cs/Ref.hx
  31. 29 29
      std/cs/StdTypes.hx
  32. 35 35
      std/cs/StringBuilder.hx
  33. 180 180
      std/cs/_std/Date.hx
  34. 119 119
      std/cs/_std/FieldLookup.hx
  35. 165 165
      std/cs/_std/Math.hx
  36. 259 259
      std/cs/_std/Reflect.hx
  37. 64 64
      std/cs/_std/String.hx
  38. 47 47
      std/cs/_std/StringBuf.hx
  39. 273 273
      std/cs/_std/Sys.hx
  40. 388 388
      std/cs/_std/Type.hx
  41. 345 345
      std/cs/_std/Xml.hx
  42. 146 146
      std/cs/_std/haxe/Int64.hx
  43. 156 156
      std/cs/_std/sys/FileSystem.hx
  44. 93 93
      std/cs/_std/sys/io/File.hx
  45. 32 32
      std/cs/_std/sys/io/FileInput.hx
  46. 32 32
      std/cs/_std/sys/io/FileOutput.hx
  47. 110 110
      std/cs/_std/sys/io/Process.hx
  48. 57 57
      std/cs/internal/Exceptions.hx
  49. 121 121
      std/cs/internal/FieldLookup.hx
  50. 80 80
      std/cs/internal/Function.hx
  51. 37 37
      std/cs/internal/Iterator.hx
  52. 87 87
      std/cs/io/NativeInput.hx
  53. 78 78
      std/cs/io/NativeOutput.hx
  54. 26 26
      std/cs/system/Activator.hx
  55. 28 28
      std/cs/system/Array.hx
  56. 40 40
      std/cs/system/BitConverter.hx
  57. 43 43
      std/cs/system/Console.hx
  58. 24 24
      std/cs/system/Converter.hx
  59. 65 65
      std/cs/system/DateTime.hx
  60. 40 40
      std/cs/system/Environment.hx
  61. 28 28
      std/cs/system/Exception.hx
  62. 26 26
      std/cs/system/IConvertible.hx
  63. 26 26
      std/cs/system/IFormatProvider.hx
  64. 26 26
      std/cs/system/LocalDataStoreSlot.hx
  65. 44 44
      std/cs/system/Math.hx
  66. 33 33
      std/cs/system/OperatingSystem.hx
  67. 38 38
      std/cs/system/PlatformID.hx
  68. 34 34
      std/cs/system/Random.hx
  69. 37 37
      std/cs/system/Type.hx
  70. 35 35
      std/cs/system/Version.hx
  71. 31 31
      std/cs/system/collections/ICollection.hx
  72. 40 40
      std/cs/system/collections/IDictionary.hx
  73. 26 26
      std/cs/system/collections/IEnumerable.hx
  74. 28 28
      std/cs/system/collections/IEnumerator.hx
  75. 40 40
      std/cs/system/io/Directory.hx
  76. 38 38
      std/cs/system/io/DirectoryInfo.hx
  77. 40 40
      std/cs/system/io/File.hx
  78. 28 28
      std/cs/system/io/FileAccess.hx
  79. 39 39
      std/cs/system/io/FileAttributes.hx
  80. 39 39
      std/cs/system/io/FileInfo.hx
  81. 31 31
      std/cs/system/io/FileMode.hx
  82. 29 29
      std/cs/system/io/FileShare.hx
  83. 32 32
      std/cs/system/io/FileStream.hx
  84. 32 32
      std/cs/system/io/MemoryStream.hx
  85. 28 28
      std/cs/system/io/SeekOrigin.hx
  86. 47 47
      std/cs/system/io/Stream.hx
  87. 32 32
      std/cs/system/io/StreamReader.hx
  88. 32 32
      std/cs/system/io/StreamWriter.hx
  89. 28 28
      std/cs/system/reflection/ConstructorInfo.hx
  90. 32 32
      std/cs/system/reflection/MethodBase.hx
  91. 29 29
      std/cs/system/reflection/MethodInfo.hx
  92. 26 26
      std/cs/system/reflection/ParameterInfo.hx
  93. 32 32
      std/cs/system/text/Encoding.hx
  94. 76 76
      std/cs/system/text/regularExpressions/Regex.hx
  95. 43 43
      std/cs/system/threading/Thread.hx
  96. 412 412
      std/flash/_std/Xml.hx
  97. 120 120
      std/flash/_std/haxe/ds/ObjectMap.hx
  98. 120 120
      std/flash/_std/haxe/ds/WeakMap.hx
  99. 4 4
      std/flash/errors/ArgumentError.hx
  100. 4 4
      std/flash/errors/SecurityError.hx

+ 2 - 0
.gitattributes

@@ -0,0 +1,2 @@
+# Auto detect text files and perform LF normalization
+* text=auto

+ 171 - 171
Makefile

@@ -1,171 +1,171 @@
-# Haxe compiler Makefile
-#
-#  - use 'make' to build all
-#  - use 'make haxe' to build only the compiler (not the libraries)
-#  - if you want to build quickly, install 'ocamlopt.opt' and change OCAMLOPT=ocamlopt.top
-#
-#  Windows users :
-#  - use 'make -f Makefile.win' to build for Windows
-#  - use 'make MSVC=1 -f Makefile.win' to build for Windows with OCaml/MSVC
-#
-.SUFFIXES : .ml .mli .cmo .cmi .cmx .mll .mly
-
-INSTALL_DIR=/usr
-
-OUTPUT=haxe
-EXTENSION=
-OCAMLOPT=ocamlopt
-
-CFLAGS= -g -I libs/extlib -I libs/extc -I libs/neko -I libs/javalib -I libs/ziplib -I libs/swflib -I libs/xml-light -I libs/ttflib
-
-CC_CMD = $(OCAMLOPT) $(CFLAGS) -c $<
-CC_PARSER_CMD = $(OCAMLOPT) -pp camlp4o $(CFLAGS) -c parser.ml
-
-LIBS=unix.cmxa str.cmxa libs/extlib/extLib.cmxa libs/xml-light/xml-light.cmxa libs/swflib/swflib.cmxa \
-	libs/extc/extc.cmxa libs/neko/neko.cmxa libs/javalib/java.cmxa libs/ziplib/zip.cmxa libs/ttflib/ttf.cmxa
-
-NATIVE_LIBS=-cclib libs/extc/extc_stubs.o -cclib -lz
-
-RELDIR=../../..
-
-EXPORT=../../../projects/motionTools/haxe
-
-MODULES=ast type lexer common genxml parser typecore optimizer typeload \
-codegen gencommon genas3 gencpp genjs genneko genphp genswf8 \
-	genswf9 genswf genjava gencs interp typer matcher dce main
-
-export HAXE_STD_PATH=$(CURDIR)/std
-
-all: libs haxe
-
-libs:
-	make -C libs/extlib opt
-	make -C libs/extc native
-	make -C libs/neko
-	make -C libs/javalib
-	make -C libs/ziplib
-	make -C libs/swflib
-	make -C libs/xml-light xml-light.cmxa
-	make -C libs/ttflib
-
-haxe: $(MODULES:=.cmx)
-	$(OCAMLOPT) -o $(OUTPUT) $(NATIVE_LIBS) $(LIBS) $(MODULES:=.cmx)
-
-haxelib:
-	$(CURDIR)/$(OUTPUT) --cwd "$(CURDIR)/std/tools/haxelib" haxelib.hxml
-	cp std/tools/haxelib/haxelib$(EXTENSION) haxelib$(EXTENSION)
-
-haxedoc:
-	$(CURDIR)/$(OUTPUT) --cwd "$(CURDIR)/std/tools/haxedoc" haxedoc.hxml
-	cp std/tools/haxedoc/haxedoc$(EXTENSION) haxedoc$(EXTENSION)
-
-tools: haxelib haxedoc
-
-install:
-	cp haxe $(INSTALL_DIR)/bin/haxe
-	rm -rf $(INSTALL_DIR)/lib/haxe/std
-	-mkdir -p $(INSTALL_DIR)/lib/haxe
-	cp -rf std $(INSTALL_DIR)/lib/haxe/std
-	-mkdir -p $(INSTALL_DIR)/lib/haxe/lib
-	chmod -R a+rx $(INSTALL_DIR)/lib/haxe
-	chmod 777 $(INSTALL_DIR)/lib/haxe/lib
-	cp std/tools/haxelib/haxelib.sh $(INSTALL_DIR)/bin/haxelib
-	cp std/tools/haxedoc/haxedoc.sh $(INSTALL_DIR)/bin/haxedoc
-	chmod a+rx $(INSTALL_DIR)/bin/haxe $(INSTALL_DIR)/bin/haxelib $(INSTALL_DIR)/bin/haxedoc
-
-# will install native version of the tools instead of script ones
-install_tools: tools
-	cp haxelib ${INSTALL_DIR}/bin/haxelib
-	cp haxedoc ${INSTALL_DIR}/bin/haxedoc
-	chmod a+rx $(INSTALL_DIR)/bin/haxelib $(INSTALL_DIR)/bin/haxedoc
-
-uninstall:
-	rm -rf $(INSTALL_DIR)/bin/haxe $(INSTALL_DIR)/bin/haxelib $(INSTALL_DIR)/lib/haxe
-
-export:
-	cp haxe*.exe doc/CHANGES.txt $(EXPORT)
-	rsync -a --exclude .svn --exclude *.n --exclude std/libs --delete std $(EXPORT)
-
-codegen.cmx: optimizer.cmx typeload.cmx typecore.cmx type.cmx genxml.cmx common.cmx ast.cmx
-
-common.cmx: type.cmx ast.cmx
-
-dce.cmx: ast.cmx common.cmx type.cmx
-
-genas3.cmx: type.cmx common.cmx codegen.cmx ast.cmx
-
-gencommon.cmx: type.cmx common.cmx codegen.cmx ast.cmx
-
-gencpp.cmx: type.cmx lexer.cmx common.cmx codegen.cmx ast.cmx
-
-gencs.cmx: type.cmx lexer.cmx gencommon.cmx common.cmx codegen.cmx ast.cmx
-
-genjava.cmx: type.cmx gencommon.cmx common.cmx codegen.cmx ast.cmx
-
-genjs.cmx: type.cmx optimizer.cmx lexer.cmx common.cmx codegen.cmx ast.cmx
-
-genneko.cmx: type.cmx lexer.cmx common.cmx codegen.cmx ast.cmx
-
-genphp.cmx: type.cmx lexer.cmx common.cmx codegen.cmx ast.cmx
-
-genswf.cmx: type.cmx genswf9.cmx genswf8.cmx common.cmx ast.cmx
-
-genswf8.cmx: type.cmx lexer.cmx common.cmx codegen.cmx ast.cmx
-
-genswf9.cmx: type.cmx lexer.cmx genswf8.cmx common.cmx codegen.cmx ast.cmx
-
-genxml.cmx: type.cmx lexer.cmx common.cmx ast.cmx
-
-interp.cmx: typecore.cmx type.cmx lexer.cmx genneko.cmx common.cmx codegen.cmx ast.cmx genswf.cmx parser.cmx
-
-matcher.cmx: optimizer.cmx codegen.cmx typecore.cmx type.cmx typer.cmx common.cmx ast.cmx
-
-main.cmx: dce.cmx matcher.cmx typer.cmx typeload.cmx typecore.cmx type.cmx parser.cmx optimizer.cmx lexer.cmx interp.cmx genxml.cmx genswf.cmx genphp.cmx genneko.cmx genjs.cmx gencpp.cmx genas3.cmx common.cmx codegen.cmx ast.cmx gencommon.cmx genjava.cmx gencs.cmx
-
-optimizer.cmx: typecore.cmx type.cmx parser.cmx common.cmx ast.cmx
-
-parser.cmx: parser.ml lexer.cmx common.cmx ast.cmx
-	$(CC_PARSER_CMD)
-
-type.cmx: ast.cmx
-
-typecore.cmx: type.cmx common.cmx ast.cmx
-
-typeload.cmx: typecore.cmx type.cmx parser.cmx optimizer.cmx lexer.cmx common.cmx ast.cmx
-
-typer.cmx: typeload.cmx typecore.cmx type.cmx parser.cmx optimizer.cmx lexer.cmx interp.cmx genneko.cmx genjs.cmx common.cmx codegen.cmx ast.cmx
-
-lexer.cmx: lexer.ml
-
-lexer.cmx: ast.cmx
-
-
-clean: clean_libs clean_haxe clean_tools
-
-clean_libs:
-	make -C libs/extlib clean
-	make -C libs/extc clean
-	make -C libs/neko clean
-	make -C libs/ziplib clean
-	make -C libs/javalib clean
-	make -C libs/swflib clean
-	make -C libs/xml-light clean
-	make -C libs/ttflib clean
-
-clean_haxe:
-	rm -f $(MODULES:=.obj) $(MODULES:=.o) $(MODULES:=.cmx) $(MODULES:=.cmi) lexer.ml
-
-clean_tools:
-	rm -f $(OUTPUT) haxelib haxedoc
-
-# SUFFIXES
-.ml.cmx:
-	$(CC_CMD)
-
-.mli.cmi:
-	$(CC_CMD)
-
-.mll.ml:
-	ocamllex $<
-
-.PHONY: haxe libs
+# Haxe compiler Makefile
+#
+#  - use 'make' to build all
+#  - use 'make haxe' to build only the compiler (not the libraries)
+#  - if you want to build quickly, install 'ocamlopt.opt' and change OCAMLOPT=ocamlopt.top
+#
+#  Windows users :
+#  - use 'make -f Makefile.win' to build for Windows
+#  - use 'make MSVC=1 -f Makefile.win' to build for Windows with OCaml/MSVC
+#
+.SUFFIXES : .ml .mli .cmo .cmi .cmx .mll .mly
+
+INSTALL_DIR=/usr
+
+OUTPUT=haxe
+EXTENSION=
+OCAMLOPT=ocamlopt
+
+CFLAGS= -g -I libs/extlib -I libs/extc -I libs/neko -I libs/javalib -I libs/ziplib -I libs/swflib -I libs/xml-light -I libs/ttflib
+
+CC_CMD = $(OCAMLOPT) $(CFLAGS) -c $<
+CC_PARSER_CMD = $(OCAMLOPT) -pp camlp4o $(CFLAGS) -c parser.ml
+
+LIBS=unix.cmxa str.cmxa libs/extlib/extLib.cmxa libs/xml-light/xml-light.cmxa libs/swflib/swflib.cmxa \
+	libs/extc/extc.cmxa libs/neko/neko.cmxa libs/javalib/java.cmxa libs/ziplib/zip.cmxa libs/ttflib/ttf.cmxa
+
+NATIVE_LIBS=-cclib libs/extc/extc_stubs.o -cclib -lz
+
+RELDIR=../../..
+
+EXPORT=../../../projects/motionTools/haxe
+
+MODULES=ast type lexer common genxml parser typecore optimizer typeload \
+codegen gencommon genas3 gencpp genjs genneko genphp genswf8 \
+	genswf9 genswf genjava gencs interp typer matcher dce main
+
+export HAXE_STD_PATH=$(CURDIR)/std
+
+all: libs haxe
+
+libs:
+	make -C libs/extlib opt
+	make -C libs/extc native
+	make -C libs/neko
+	make -C libs/javalib
+	make -C libs/ziplib
+	make -C libs/swflib
+	make -C libs/xml-light xml-light.cmxa
+	make -C libs/ttflib
+
+haxe: $(MODULES:=.cmx)
+	$(OCAMLOPT) -o $(OUTPUT) $(NATIVE_LIBS) $(LIBS) $(MODULES:=.cmx)
+
+haxelib:
+	$(CURDIR)/$(OUTPUT) --cwd "$(CURDIR)/std/tools/haxelib" haxelib.hxml
+	cp std/tools/haxelib/haxelib$(EXTENSION) haxelib$(EXTENSION)
+
+haxedoc:
+	$(CURDIR)/$(OUTPUT) --cwd "$(CURDIR)/std/tools/haxedoc" haxedoc.hxml
+	cp std/tools/haxedoc/haxedoc$(EXTENSION) haxedoc$(EXTENSION)
+
+tools: haxelib haxedoc
+
+install:
+	cp haxe $(INSTALL_DIR)/bin/haxe
+	rm -rf $(INSTALL_DIR)/lib/haxe/std
+	-mkdir -p $(INSTALL_DIR)/lib/haxe
+	cp -rf std $(INSTALL_DIR)/lib/haxe/std
+	-mkdir -p $(INSTALL_DIR)/lib/haxe/lib
+	chmod -R a+rx $(INSTALL_DIR)/lib/haxe
+	chmod 777 $(INSTALL_DIR)/lib/haxe/lib
+	cp std/tools/haxelib/haxelib.sh $(INSTALL_DIR)/bin/haxelib
+	cp std/tools/haxedoc/haxedoc.sh $(INSTALL_DIR)/bin/haxedoc
+	chmod a+rx $(INSTALL_DIR)/bin/haxe $(INSTALL_DIR)/bin/haxelib $(INSTALL_DIR)/bin/haxedoc
+
+# will install native version of the tools instead of script ones
+install_tools: tools
+	cp haxelib ${INSTALL_DIR}/bin/haxelib
+	cp haxedoc ${INSTALL_DIR}/bin/haxedoc
+	chmod a+rx $(INSTALL_DIR)/bin/haxelib $(INSTALL_DIR)/bin/haxedoc
+
+uninstall:
+	rm -rf $(INSTALL_DIR)/bin/haxe $(INSTALL_DIR)/bin/haxelib $(INSTALL_DIR)/lib/haxe
+
+export:
+	cp haxe*.exe doc/CHANGES.txt $(EXPORT)
+	rsync -a --exclude .svn --exclude *.n --exclude std/libs --delete std $(EXPORT)
+
+codegen.cmx: optimizer.cmx typeload.cmx typecore.cmx type.cmx genxml.cmx common.cmx ast.cmx
+
+common.cmx: type.cmx ast.cmx
+
+dce.cmx: ast.cmx common.cmx type.cmx
+
+genas3.cmx: type.cmx common.cmx codegen.cmx ast.cmx
+
+gencommon.cmx: type.cmx common.cmx codegen.cmx ast.cmx
+
+gencpp.cmx: type.cmx lexer.cmx common.cmx codegen.cmx ast.cmx
+
+gencs.cmx: type.cmx lexer.cmx gencommon.cmx common.cmx codegen.cmx ast.cmx
+
+genjava.cmx: type.cmx gencommon.cmx common.cmx codegen.cmx ast.cmx
+
+genjs.cmx: type.cmx optimizer.cmx lexer.cmx common.cmx codegen.cmx ast.cmx
+
+genneko.cmx: type.cmx lexer.cmx common.cmx codegen.cmx ast.cmx
+
+genphp.cmx: type.cmx lexer.cmx common.cmx codegen.cmx ast.cmx
+
+genswf.cmx: type.cmx genswf9.cmx genswf8.cmx common.cmx ast.cmx
+
+genswf8.cmx: type.cmx lexer.cmx common.cmx codegen.cmx ast.cmx
+
+genswf9.cmx: type.cmx lexer.cmx genswf8.cmx common.cmx codegen.cmx ast.cmx
+
+genxml.cmx: type.cmx lexer.cmx common.cmx ast.cmx
+
+interp.cmx: typecore.cmx type.cmx lexer.cmx genneko.cmx common.cmx codegen.cmx ast.cmx genswf.cmx parser.cmx
+
+matcher.cmx: optimizer.cmx codegen.cmx typecore.cmx type.cmx typer.cmx common.cmx ast.cmx
+
+main.cmx: dce.cmx matcher.cmx typer.cmx typeload.cmx typecore.cmx type.cmx parser.cmx optimizer.cmx lexer.cmx interp.cmx genxml.cmx genswf.cmx genphp.cmx genneko.cmx genjs.cmx gencpp.cmx genas3.cmx common.cmx codegen.cmx ast.cmx gencommon.cmx genjava.cmx gencs.cmx
+
+optimizer.cmx: typecore.cmx type.cmx parser.cmx common.cmx ast.cmx
+
+parser.cmx: parser.ml lexer.cmx common.cmx ast.cmx
+	$(CC_PARSER_CMD)
+
+type.cmx: ast.cmx
+
+typecore.cmx: type.cmx common.cmx ast.cmx
+
+typeload.cmx: typecore.cmx type.cmx parser.cmx optimizer.cmx lexer.cmx common.cmx ast.cmx
+
+typer.cmx: typeload.cmx typecore.cmx type.cmx parser.cmx optimizer.cmx lexer.cmx interp.cmx genneko.cmx genjs.cmx common.cmx codegen.cmx ast.cmx
+
+lexer.cmx: lexer.ml
+
+lexer.cmx: ast.cmx
+
+
+clean: clean_libs clean_haxe clean_tools
+
+clean_libs:
+	make -C libs/extlib clean
+	make -C libs/extc clean
+	make -C libs/neko clean
+	make -C libs/ziplib clean
+	make -C libs/javalib clean
+	make -C libs/swflib clean
+	make -C libs/xml-light clean
+	make -C libs/ttflib clean
+
+clean_haxe:
+	rm -f $(MODULES:=.obj) $(MODULES:=.o) $(MODULES:=.cmx) $(MODULES:=.cmi) lexer.ml
+
+clean_tools:
+	rm -f $(OUTPUT) haxelib haxedoc
+
+# SUFFIXES
+.ml.cmx:
+	$(CC_CMD)
+
+.mli.cmi:
+	$(CC_CMD)
+
+.mll.ml:
+	ocamllex $<
+
+.PHONY: haxe libs

+ 497 - 497
dce.ml

@@ -1,497 +1,497 @@
-(*
- * Copyright (C)2005-2013 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *)
-
-open Ast
-open Common
-open Type
-
-type dce = {
-	com : context;
-	full : bool;
-	std_dirs : string list;
-	debug : bool;
-	follow_expr : dce -> texpr -> unit;
-	mutable added_fields : (tclass * tclass_field * bool) list;
-	mutable marked_fields : tclass_field list;
-	mutable marked_maybe_fields : tclass_field list;
-	mutable t_stack : t list;
-}
-
-(* checking *)
-
-(* check for @:keepSub metadata, which forces @:keep on child classes *)
-let rec super_forces_keep c =
-	Meta.has Meta.KeepSub c.cl_meta || match c.cl_super with
-	| Some (csup,_) -> super_forces_keep csup
-	| _ -> false
-
-let is_std_file dce file =
-	List.exists (ExtString.String.starts_with file) dce.std_dirs
-
-(* check if a class is kept entirely *)
-let keep_whole_class dce c =
-	Meta.has Meta.Keep c.cl_meta
-	|| not (dce.full || is_std_file dce c.cl_module.m_extra.m_file)
-	|| super_forces_keep c
-	|| (match c with
-		| { cl_extern = true; cl_path = ([],("Math"|"Array"))} when dce.com.platform = Js -> false
-		| { cl_extern = true }
-		| { cl_path = ["flash";"_Boot"],"RealBoot" } -> true
-		| { cl_path = [],"String" }
-		| { cl_path = [],"Array" } -> not (dce.com.platform = Js)
-		| _ -> false)
-
-(* check if a metadata contains @:ifFeature with a used feature argument *)
-let has_used_feature com meta =
-	try
-		let _,el,_ = Meta.get Meta.IfFeature meta in
-		List.exists (fun e -> match fst e with
-			| EConst(String s) when Common.has_feature com s -> true
-			| _ -> false
-		) el
-	with Not_found ->
-		false
-
-(* check if a field is kept *)
-let keep_field dce cf =
-	Meta.has Meta.Keep cf.cf_meta
-	|| Meta.has Meta.Used cf.cf_meta
-	|| cf.cf_name = "__init__"
-	|| has_used_feature dce.com cf.cf_meta
-
-(* marking *)
-
-(* mark a field as kept *)
-let rec mark_field dce c cf stat =
-	let add () =
-		if not (Meta.has Meta.Used cf.cf_meta) then begin
-			cf.cf_meta <- (Meta.Used,[],cf.cf_pos) :: cf.cf_meta;
-			dce.added_fields <- (c,cf,stat) :: dce.added_fields;
-			dce.marked_fields <- cf :: dce.marked_fields
-		end
-	in
-	if not (PMap.mem cf.cf_name (if stat then c.cl_statics else c.cl_fields)) then begin
-		match c.cl_super with
-		| None -> add()
-		| Some (c,_) -> mark_field dce c cf stat
-	end else
-		add()
-
-let rec update_marked_class_fields dce c =
-	(* mark all :?used fields as surely :used now *)
-	List.iter (fun cf ->
-		if Meta.has Meta.MaybeUsed cf.cf_meta then mark_field dce c cf true
-	) c.cl_ordered_statics;
-	List.iter (fun cf ->
-		if Meta.has Meta.MaybeUsed cf.cf_meta then mark_field dce c cf false
-	) c.cl_ordered_fields;
-	(* we always have to keep super classes and implemented interfaces *)
-	(match c.cl_init with None -> () | Some init -> dce.follow_expr dce init);
-	List.iter (fun (c,_) -> mark_class dce c) c.cl_implements;
-	(match c.cl_super with None -> () | Some (csup,pl) -> mark_class dce csup)
-
-(* mark a class as kept. If the class has fields marked as @:?keep, make sure to keep them *)
-and mark_class dce c = if not (Meta.has Meta.Used c.cl_meta) then begin
-	c.cl_meta <- (Meta.Used,[],c.cl_pos) :: c.cl_meta;
-	update_marked_class_fields dce c;
-end
-
-let rec mark_enum dce e = if not (Meta.has Meta.Used e.e_meta) then begin
-	e.e_meta <- (Meta.Used,[],e.e_pos) :: e.e_meta;
-	PMap.iter (fun _ ef -> mark_t dce ef.ef_type) e.e_constrs;
-end
-
-and mark_abstract dce a = if not (Meta.has Meta.Used a.a_meta) then
-	a.a_meta <- (Meta.Used,[],a.a_pos) :: a.a_meta
-
-(* mark a type as kept *)
-and mark_t dce t = match follow t with
-	| TInst({cl_kind = KTypeParameter tl} as c,pl) ->
-		if not (Meta.has Meta.Used c.cl_meta) then begin
-			c.cl_meta <- (Meta.Used,[],c.cl_pos) :: c.cl_meta;
-			List.iter (mark_t dce) tl;
-		end;
-		List.iter (mark_t dce) pl
-	| TInst(c,pl) ->
-		mark_class dce c;
-		List.iter (mark_t dce) pl
-	| TFun(args,ret) ->
-		List.iter (fun (_,_,t) -> mark_t dce t) args;
-		mark_t dce ret
-	| TEnum(e,pl) ->
-		mark_enum dce e;
-		List.iter (mark_t dce) pl
-	| TAbstract(a,pl) ->
-		mark_abstract dce a;
-		List.iter (mark_t dce) pl
-	| TLazy _ | TDynamic _ | TAnon _ | TType _ | TMono _ -> ()
-
-let mark_mt dce mt = match mt with
-	| TClassDecl c ->
-		mark_class dce c;
-	| TEnumDecl e ->
-		mark_enum dce e
-	| TAbstractDecl a ->
-		(* abstract 'feature' is defined as the abstract type beeing used as a value, not as a type *)
-		if not (Meta.has Meta.ValueUsed a.a_meta) then a.a_meta <- (Meta.ValueUsed,[],a.a_pos) :: a.a_meta;
-		mark_abstract dce a
-	| TTypeDecl _ ->
-		()
-
-(* find all dependent fields by checking implementing/subclassing types *)
-let rec mark_dependent_fields dce csup n stat =
-	List.iter (fun mt -> match mt with
-		| TClassDecl c when is_parent csup c ->
-			let rec loop c =
-				(try
-					let cf = PMap.find n (if stat then c.cl_statics else c.cl_fields) in
-					(* if it's clear that the class is kept, the field has to be kept as well. This is also true for
-					   extern interfaces because we cannot remove fields from them *)
-					if Meta.has Meta.Used c.cl_meta || (csup.cl_interface && csup.cl_extern) then mark_field dce c cf stat
-					(* otherwise it might be kept if the class is kept later, so mark it as :?used *)
-					else if not (Meta.has Meta.MaybeUsed cf.cf_meta) then begin
-						cf.cf_meta <- (Meta.MaybeUsed,[],cf.cf_pos) :: cf.cf_meta;
-						dce.marked_maybe_fields <- cf :: dce.marked_maybe_fields;
-					end
-				with Not_found ->
-					(* if the field is not present on current class, it might come from a base class *)
-					(match c.cl_super with None -> () | Some (csup,_) -> loop csup))
-			in
-			loop c
-		| _ -> ()
-	) dce.com.types
-
-(* expr and field evaluation *)
-
-let opt f e = match e with None -> () | Some e -> f e
-
-let rec to_string dce t =
-	let push t =
-		dce.t_stack <- t :: dce.t_stack;
-		fun () -> dce.t_stack <- List.tl dce.t_stack
-	in
-	let t = follow t in
-	if not (List.exists (fun t2 -> Type.fast_eq t t2) dce.t_stack) then match follow t with
-	| TInst(c,pl) as t ->
-		let pop = push t in
-		field dce c "toString" false;
-		List.iter (to_string dce) pl;
-		pop();
-	| TEnum(en,pl) as t ->
-		let pop = push t in
-		PMap.iter (fun _ ef -> to_string dce ef.ef_type) en.e_constrs;
-		List.iter (to_string dce) pl;
-		pop();
-	| TAnon a as t ->
-		let pop = push t in
-		PMap.iter (fun _ cf -> to_string dce cf.cf_type) a.a_fields;
-		pop();
-	| TFun(args,r) as t ->
-		let pop = push t in
-		List.iter (fun (_,_,t) -> to_string dce t) args;
-		to_string dce r;
-		pop();
-	| _ -> ()
-
-and field dce c n stat =
-	let find_field n =
-		if n = "new" then match c.cl_constructor with
-			| None -> raise Not_found
-			| Some cf -> cf
-		else PMap.find n (if stat then c.cl_statics else c.cl_fields)
-	in
-	(try
-		let cf = find_field n in
-		mark_field dce c cf stat;
-	with Not_found -> try
-		(* me might have a property access on an interface *)
- 		let l = String.length n - 4 in
-		if l < 0 then raise Not_found;
-		let prefix = String.sub n 0 4 in
-		let pn = String.sub n 4 l in
-		let cf = find_field pn in
-		if not (Meta.has Meta.Used cf.cf_meta) then begin
-			let keep () =
-				mark_dependent_fields dce c n stat;
-				field dce c pn stat
-			in
-			(match prefix,cf.cf_kind with
-				| "get_",Var {v_read = AccCall} when "get_" ^ cf.cf_name = n -> keep()
-				| "set_",Var {v_write = AccCall} when "set_" ^ cf.cf_name = n -> keep()
-				| _ -> raise Not_found
-			);
-		end;
-		raise Not_found
-	with Not_found -> try
-		if c.cl_interface then begin
-			let rec loop cl = match cl with
-				| [] -> raise Not_found
-				| (c,_) :: cl ->
-					try field dce c n stat with Not_found -> loop cl
-			in
-			loop c.cl_implements
-		end else match c.cl_super with Some (csup,_) -> field dce csup n stat | None -> raise Not_found
-	with Not_found -> try
-		match c.cl_kind with
-		| KTypeParameter tl ->
-			let rec loop tl = match tl with
-				| [] -> raise Not_found
-				| TInst(c,_) :: cl ->
-					(try field dce c n stat with Not_found -> loop cl)
-				| t :: tl ->
-					loop tl
-			in
-			loop tl
-		| _ -> raise Not_found
-	with Not_found ->
-		if dce.debug then prerr_endline ("[DCE] Field " ^ n ^ " not found on " ^ (s_type_path c.cl_path)) else ())
-
-and expr dce e =
-	mark_t dce e.etype;
-	match e.eexpr with
-	| TNew(c,pl,el) ->
-		mark_class dce c;
-		let rec loop c =
-			field dce c "new" false;
-			match c.cl_super with None -> () | Some (csup,_) -> loop csup
-		in
-		loop c;
-		List.iter (expr dce) el;
-		List.iter (mark_t dce) pl;
-	| TVars vl ->
-		List.iter (fun (v,e) ->
-			opt (expr dce) e;
-			mark_t dce v.v_type;
-		) vl;
-	| TCast(e, Some mt) ->
-		mark_mt dce mt;
-		expr dce e;
-	| TTypeExpr mt ->
-		mark_mt dce mt
-	| TTry(e, vl) ->
-		expr dce e;
-		List.iter (fun (v,e) ->
-			expr dce e;
-			mark_t dce v.v_type;
-		) vl;
-	| TCall ({eexpr = TLocal ({v_name = "__define_feature__"})},[{eexpr = TConst (TString ft)};e]) ->
-		Common.add_feature dce.com ft;
-		expr dce e
-	(* keep toString method when the class is argument to Std.string or haxe.Log.trace *)
-	| TCall ({eexpr = TField({eexpr = TTypeExpr (TClassDecl ({cl_path = (["haxe"],"Log")} as c))},FStatic (_,{cf_name="trace"}))} as ef, ([e2;_] as args))
-	| TCall ({eexpr = TField({eexpr = TTypeExpr (TClassDecl ({cl_path = ([],"Std")} as c))},FStatic (_,{cf_name="string"}))} as ef, ([e2] as args)) ->
-		mark_class dce c;
-		to_string dce e2.etype;
-		expr dce ef;
-		List.iter (expr dce) args;
-	| TCall ({eexpr = TConst TSuper} as e,el) ->
-		mark_t dce e.etype;
-		List.iter (expr dce) el;
-	| TField(e,fa) ->
-		begin match fa with
-			| FStatic(c,cf) ->
-				mark_class dce c;
-				mark_field dce c cf true;
-			| FInstance(c,cf) ->
-				mark_class dce c;
-				mark_field dce c cf false;
-			| _ ->
-				let n = field_name fa in
-				begin match follow e.etype with
-					| TInst(c,_) ->
-						mark_class dce c;
-						field dce c n false;
-					| TAnon a ->
-						(match !(a.a_status) with
-						| Statics c ->
-							mark_class dce c;
-							field dce c n true;
-						| _ -> ())
-					| _ -> ()
-				end;
-		end;
-		expr dce e;
-	| TThrow e ->
-		to_string dce e.etype;
-		expr dce e
-	| _ ->
-		Type.iter (expr dce) e
-
-let run com main full =
-	let dce = {
-		com = com;
-		full = full;
-		std_dirs = if full then [] else List.map Common.unique_full_path com.std_path;
-		debug = Common.defined com Define.DceDebug;
-		added_fields = [];
-		follow_expr = expr;
-		marked_fields = [];
-		marked_maybe_fields = [];
-		t_stack = [];
-	} in
-	begin match main with
-		| Some {eexpr = TCall({eexpr = TField(e,(FStatic(c,cf)))},_)} ->
-			cf.cf_meta <- (Meta.Keep,[],cf.cf_pos) :: cf.cf_meta
-		| _ ->
-			()
-	end;
-	(* first step: get all entry points, which is the main method and all class methods which are marked with @:keep *)
-	List.iter (fun t -> match t with
-		| TClassDecl c ->
-			let keep_class = keep_whole_class dce c && (not c.cl_extern || c.cl_interface) in
-			let loop stat cf =
-				if keep_class || keep_field dce cf then mark_field dce c cf stat
-			in
-			List.iter (loop true) c.cl_ordered_statics;
-			List.iter (loop false) c.cl_ordered_fields;
-			begin match c.cl_constructor with
-				| Some cf -> loop false cf
-				| None -> ()
-			end
-		| _ ->
-			()
-	) com.types;
-	if dce.debug then begin
-		List.iter (fun (c,cf,_) -> match cf.cf_expr with
-			| None -> ()
-			| Some _ -> print_endline ("[DCE] Entry point: " ^ (s_type_path c.cl_path) ^ "." ^ cf.cf_name)
-		) dce.added_fields;
-	end;
-	(* second step: initiate DCE passes and keep going until no new fields were added *)
-	let rec loop () =
-		match dce.added_fields with
-		| [] -> ()
-		| cfl ->
-			dce.added_fields <- [];
-			(* extend to dependent (= overriding/implementing) class fields *)
-			List.iter (fun (c,cf,stat) -> mark_dependent_fields dce c cf.cf_name stat) cfl;
-			(* mark fields as used *)
-			List.iter (fun (c,cf,stat) ->
-				mark_class dce c;
-				mark_field dce c cf stat;
-				mark_t dce cf.cf_type
-			) cfl;
-			(* follow expressions to new types/fields *)
-			List.iter (fun (_,cf,_) ->
-				opt (expr dce) cf.cf_expr;
-				List.iter (fun cf -> if cf.cf_expr <> None then opt (expr dce) cf.cf_expr) cf.cf_overloads
-			) cfl;
-			loop ()
-	in
-	loop ();
-	(* third step: filter types *)
-	let rec loop acc types =
-		match types with
-		| (TClassDecl c) as mt :: l when keep_whole_class dce c ->
-			loop (mt :: acc) l
-		| (TClassDecl c) as mt :: l ->
-			(* add :keep so subsequent filter calls do not process class fields again *)
-			c.cl_meta <- (Meta.Keep,[],c.cl_pos) :: c.cl_meta;
- 			c.cl_ordered_statics <- List.filter (fun cf ->
-				let b = keep_field dce cf in
-				if not b then begin
-					if dce.debug then print_endline ("[DCE] Removed field " ^ (s_type_path c.cl_path) ^ "." ^ (cf.cf_name));
-					c.cl_statics <- PMap.remove cf.cf_name c.cl_statics;
-				end;
-				b
-			) c.cl_ordered_statics;
-			c.cl_ordered_fields <- List.filter (fun cf ->
-				let b = keep_field dce cf in
-				if not b then begin
-					if dce.debug then print_endline ("[DCE] Removed field " ^ (s_type_path c.cl_path) ^ "." ^ (cf.cf_name));
-					c.cl_fields <- PMap.remove cf.cf_name c.cl_fields;
-				end;
-				b
-			) c.cl_ordered_fields;
-			(match c.cl_constructor with Some cf when not (keep_field dce cf) -> c.cl_constructor <- None | _ -> ());
-			(* we keep a class if it was used or has a used field *)
-			if Meta.has Meta.Used c.cl_meta || c.cl_ordered_statics <> [] || c.cl_ordered_fields <> [] then loop (mt :: acc) l else begin
-				(match c.cl_init with
-				| Some f when Meta.has Meta.KeepInit c.cl_meta ->
-					(* it means that we only need the __init__ block *)
-					c.cl_extern <- true;
-					loop (mt :: acc) l
-				| _ ->
-					if dce.debug then print_endline ("[DCE] Removed class " ^ (s_type_path c.cl_path));
-					loop acc l)
-			end
- 		| (TEnumDecl e) as mt :: l when Meta.has Meta.Used e.e_meta || Meta.has Meta.Keep e.e_meta || e.e_extern || not (dce.full || is_std_file dce e.e_module.m_extra.m_file) ->
-			loop (mt :: acc) l
-		| TEnumDecl e :: l ->
-			if dce.debug then print_endline ("[DCE] Removed enum " ^ (s_type_path e.e_path));
-			loop acc l
-		| mt :: l ->
-			loop (mt :: acc) l
-		| [] ->
-			acc
-	in
-	com.types <- loop [] (List.rev com.types);
-
-	(* extra step to adjust properties that had accessors removed (required for Php and Cpp) *)
-	List.iter (fun mt -> match mt with
-		| (TClassDecl c) ->
-			let rec has_accessor c n stat =
-				PMap.mem n (if stat then c.cl_statics else c.cl_fields)
-				|| match c.cl_super with Some (csup,_) -> has_accessor csup n stat | None -> false
-			in
-			let check_prop stat cf =
-				(match cf.cf_kind with
-				| Var {v_read = AccCall; v_write = a} ->
-					let s = "get_" ^ cf.cf_name in
-					cf.cf_kind <- Var {v_read = if has_accessor c s stat then AccCall else AccNever; v_write = a}
-				| _ -> ());
-				(match cf.cf_kind with
-				| Var {v_write = AccCall; v_read = a} ->
-					let s = "set_" ^ cf.cf_name in
-					cf.cf_kind <- Var {v_write = if has_accessor c s stat then AccCall else AccNever; v_read = a}
-				| _ -> ())
-			in
-			List.iter (check_prop true) c.cl_ordered_statics;
-			List.iter (check_prop false) c.cl_ordered_fields;
-		| _ -> ()
-	) com.types;
-
-	(* remove "override" from fields that do not override anything anymore *)
-	List.iter (fun mt -> match mt with
-		| TClassDecl c ->
-			c.cl_overrides <- List.filter (fun s ->
-				let rec loop c =
-					match c.cl_super with
-					| Some (csup,_) when PMap.mem s.cf_name csup.cl_fields -> true
-					| Some (csup,_) -> loop csup
-					| None -> false
-				in
-				loop c
-			) c.cl_overrides;
-		| _ -> ()
-	) com.types;
-
-	(* cleanup added fields metadata - compatibility with compilation server *)
-	let rec remove_meta m = function
-		| [] -> []
-		| (m2,_,_) :: l when m = m2 -> l
-		| x :: l -> x :: remove_meta m l
-	in
-	List.iter (fun cf -> cf.cf_meta <- remove_meta Meta.Used cf.cf_meta) dce.marked_fields;
-	List.iter (fun cf -> cf.cf_meta <- remove_meta Meta.MaybeUsed cf.cf_meta) dce.marked_maybe_fields;
-
-
+(*
+ * Copyright (C)2005-2013 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *)
+
+open Ast
+open Common
+open Type
+
+type dce = {
+	com : context;
+	full : bool;
+	std_dirs : string list;
+	debug : bool;
+	follow_expr : dce -> texpr -> unit;
+	mutable added_fields : (tclass * tclass_field * bool) list;
+	mutable marked_fields : tclass_field list;
+	mutable marked_maybe_fields : tclass_field list;
+	mutable t_stack : t list;
+}
+
+(* checking *)
+
+(* check for @:keepSub metadata, which forces @:keep on child classes *)
+let rec super_forces_keep c =
+	Meta.has Meta.KeepSub c.cl_meta || match c.cl_super with
+	| Some (csup,_) -> super_forces_keep csup
+	| _ -> false
+
+let is_std_file dce file =
+	List.exists (ExtString.String.starts_with file) dce.std_dirs
+
+(* check if a class is kept entirely *)
+let keep_whole_class dce c =
+	Meta.has Meta.Keep c.cl_meta
+	|| not (dce.full || is_std_file dce c.cl_module.m_extra.m_file)
+	|| super_forces_keep c
+	|| (match c with
+		| { cl_extern = true; cl_path = ([],("Math"|"Array"))} when dce.com.platform = Js -> false
+		| { cl_extern = true }
+		| { cl_path = ["flash";"_Boot"],"RealBoot" } -> true
+		| { cl_path = [],"String" }
+		| { cl_path = [],"Array" } -> not (dce.com.platform = Js)
+		| _ -> false)
+
+(* check if a metadata contains @:ifFeature with a used feature argument *)
+let has_used_feature com meta =
+	try
+		let _,el,_ = Meta.get Meta.IfFeature meta in
+		List.exists (fun e -> match fst e with
+			| EConst(String s) when Common.has_feature com s -> true
+			| _ -> false
+		) el
+	with Not_found ->
+		false
+
+(* check if a field is kept *)
+let keep_field dce cf =
+	Meta.has Meta.Keep cf.cf_meta
+	|| Meta.has Meta.Used cf.cf_meta
+	|| cf.cf_name = "__init__"
+	|| has_used_feature dce.com cf.cf_meta
+
+(* marking *)
+
+(* mark a field as kept *)
+let rec mark_field dce c cf stat =
+	let add () =
+		if not (Meta.has Meta.Used cf.cf_meta) then begin
+			cf.cf_meta <- (Meta.Used,[],cf.cf_pos) :: cf.cf_meta;
+			dce.added_fields <- (c,cf,stat) :: dce.added_fields;
+			dce.marked_fields <- cf :: dce.marked_fields
+		end
+	in
+	if not (PMap.mem cf.cf_name (if stat then c.cl_statics else c.cl_fields)) then begin
+		match c.cl_super with
+		| None -> add()
+		| Some (c,_) -> mark_field dce c cf stat
+	end else
+		add()
+
+let rec update_marked_class_fields dce c =
+	(* mark all :?used fields as surely :used now *)
+	List.iter (fun cf ->
+		if Meta.has Meta.MaybeUsed cf.cf_meta then mark_field dce c cf true
+	) c.cl_ordered_statics;
+	List.iter (fun cf ->
+		if Meta.has Meta.MaybeUsed cf.cf_meta then mark_field dce c cf false
+	) c.cl_ordered_fields;
+	(* we always have to keep super classes and implemented interfaces *)
+	(match c.cl_init with None -> () | Some init -> dce.follow_expr dce init);
+	List.iter (fun (c,_) -> mark_class dce c) c.cl_implements;
+	(match c.cl_super with None -> () | Some (csup,pl) -> mark_class dce csup)
+
+(* mark a class as kept. If the class has fields marked as @:?keep, make sure to keep them *)
+and mark_class dce c = if not (Meta.has Meta.Used c.cl_meta) then begin
+	c.cl_meta <- (Meta.Used,[],c.cl_pos) :: c.cl_meta;
+	update_marked_class_fields dce c;
+end
+
+let rec mark_enum dce e = if not (Meta.has Meta.Used e.e_meta) then begin
+	e.e_meta <- (Meta.Used,[],e.e_pos) :: e.e_meta;
+	PMap.iter (fun _ ef -> mark_t dce ef.ef_type) e.e_constrs;
+end
+
+and mark_abstract dce a = if not (Meta.has Meta.Used a.a_meta) then
+	a.a_meta <- (Meta.Used,[],a.a_pos) :: a.a_meta
+
+(* mark a type as kept *)
+and mark_t dce t = match follow t with
+	| TInst({cl_kind = KTypeParameter tl} as c,pl) ->
+		if not (Meta.has Meta.Used c.cl_meta) then begin
+			c.cl_meta <- (Meta.Used,[],c.cl_pos) :: c.cl_meta;
+			List.iter (mark_t dce) tl;
+		end;
+		List.iter (mark_t dce) pl
+	| TInst(c,pl) ->
+		mark_class dce c;
+		List.iter (mark_t dce) pl
+	| TFun(args,ret) ->
+		List.iter (fun (_,_,t) -> mark_t dce t) args;
+		mark_t dce ret
+	| TEnum(e,pl) ->
+		mark_enum dce e;
+		List.iter (mark_t dce) pl
+	| TAbstract(a,pl) ->
+		mark_abstract dce a;
+		List.iter (mark_t dce) pl
+	| TLazy _ | TDynamic _ | TAnon _ | TType _ | TMono _ -> ()
+
+let mark_mt dce mt = match mt with
+	| TClassDecl c ->
+		mark_class dce c;
+	| TEnumDecl e ->
+		mark_enum dce e
+	| TAbstractDecl a ->
+		(* abstract 'feature' is defined as the abstract type beeing used as a value, not as a type *)
+		if not (Meta.has Meta.ValueUsed a.a_meta) then a.a_meta <- (Meta.ValueUsed,[],a.a_pos) :: a.a_meta;
+		mark_abstract dce a
+	| TTypeDecl _ ->
+		()
+
+(* find all dependent fields by checking implementing/subclassing types *)
+let rec mark_dependent_fields dce csup n stat =
+	List.iter (fun mt -> match mt with
+		| TClassDecl c when is_parent csup c ->
+			let rec loop c =
+				(try
+					let cf = PMap.find n (if stat then c.cl_statics else c.cl_fields) in
+					(* if it's clear that the class is kept, the field has to be kept as well. This is also true for
+					   extern interfaces because we cannot remove fields from them *)
+					if Meta.has Meta.Used c.cl_meta || (csup.cl_interface && csup.cl_extern) then mark_field dce c cf stat
+					(* otherwise it might be kept if the class is kept later, so mark it as :?used *)
+					else if not (Meta.has Meta.MaybeUsed cf.cf_meta) then begin
+						cf.cf_meta <- (Meta.MaybeUsed,[],cf.cf_pos) :: cf.cf_meta;
+						dce.marked_maybe_fields <- cf :: dce.marked_maybe_fields;
+					end
+				with Not_found ->
+					(* if the field is not present on current class, it might come from a base class *)
+					(match c.cl_super with None -> () | Some (csup,_) -> loop csup))
+			in
+			loop c
+		| _ -> ()
+	) dce.com.types
+
+(* expr and field evaluation *)
+
+let opt f e = match e with None -> () | Some e -> f e
+
+let rec to_string dce t =
+	let push t =
+		dce.t_stack <- t :: dce.t_stack;
+		fun () -> dce.t_stack <- List.tl dce.t_stack
+	in
+	let t = follow t in
+	if not (List.exists (fun t2 -> Type.fast_eq t t2) dce.t_stack) then match follow t with
+	| TInst(c,pl) as t ->
+		let pop = push t in
+		field dce c "toString" false;
+		List.iter (to_string dce) pl;
+		pop();
+	| TEnum(en,pl) as t ->
+		let pop = push t in
+		PMap.iter (fun _ ef -> to_string dce ef.ef_type) en.e_constrs;
+		List.iter (to_string dce) pl;
+		pop();
+	| TAnon a as t ->
+		let pop = push t in
+		PMap.iter (fun _ cf -> to_string dce cf.cf_type) a.a_fields;
+		pop();
+	| TFun(args,r) as t ->
+		let pop = push t in
+		List.iter (fun (_,_,t) -> to_string dce t) args;
+		to_string dce r;
+		pop();
+	| _ -> ()
+
+and field dce c n stat =
+	let find_field n =
+		if n = "new" then match c.cl_constructor with
+			| None -> raise Not_found
+			| Some cf -> cf
+		else PMap.find n (if stat then c.cl_statics else c.cl_fields)
+	in
+	(try
+		let cf = find_field n in
+		mark_field dce c cf stat;
+	with Not_found -> try
+		(* me might have a property access on an interface *)
+ 		let l = String.length n - 4 in
+		if l < 0 then raise Not_found;
+		let prefix = String.sub n 0 4 in
+		let pn = String.sub n 4 l in
+		let cf = find_field pn in
+		if not (Meta.has Meta.Used cf.cf_meta) then begin
+			let keep () =
+				mark_dependent_fields dce c n stat;
+				field dce c pn stat
+			in
+			(match prefix,cf.cf_kind with
+				| "get_",Var {v_read = AccCall} when "get_" ^ cf.cf_name = n -> keep()
+				| "set_",Var {v_write = AccCall} when "set_" ^ cf.cf_name = n -> keep()
+				| _ -> raise Not_found
+			);
+		end;
+		raise Not_found
+	with Not_found -> try
+		if c.cl_interface then begin
+			let rec loop cl = match cl with
+				| [] -> raise Not_found
+				| (c,_) :: cl ->
+					try field dce c n stat with Not_found -> loop cl
+			in
+			loop c.cl_implements
+		end else match c.cl_super with Some (csup,_) -> field dce csup n stat | None -> raise Not_found
+	with Not_found -> try
+		match c.cl_kind with
+		| KTypeParameter tl ->
+			let rec loop tl = match tl with
+				| [] -> raise Not_found
+				| TInst(c,_) :: cl ->
+					(try field dce c n stat with Not_found -> loop cl)
+				| t :: tl ->
+					loop tl
+			in
+			loop tl
+		| _ -> raise Not_found
+	with Not_found ->
+		if dce.debug then prerr_endline ("[DCE] Field " ^ n ^ " not found on " ^ (s_type_path c.cl_path)) else ())
+
+and expr dce e =
+	mark_t dce e.etype;
+	match e.eexpr with
+	| TNew(c,pl,el) ->
+		mark_class dce c;
+		let rec loop c =
+			field dce c "new" false;
+			match c.cl_super with None -> () | Some (csup,_) -> loop csup
+		in
+		loop c;
+		List.iter (expr dce) el;
+		List.iter (mark_t dce) pl;
+	| TVars vl ->
+		List.iter (fun (v,e) ->
+			opt (expr dce) e;
+			mark_t dce v.v_type;
+		) vl;
+	| TCast(e, Some mt) ->
+		mark_mt dce mt;
+		expr dce e;
+	| TTypeExpr mt ->
+		mark_mt dce mt
+	| TTry(e, vl) ->
+		expr dce e;
+		List.iter (fun (v,e) ->
+			expr dce e;
+			mark_t dce v.v_type;
+		) vl;
+	| TCall ({eexpr = TLocal ({v_name = "__define_feature__"})},[{eexpr = TConst (TString ft)};e]) ->
+		Common.add_feature dce.com ft;
+		expr dce e
+	(* keep toString method when the class is argument to Std.string or haxe.Log.trace *)
+	| TCall ({eexpr = TField({eexpr = TTypeExpr (TClassDecl ({cl_path = (["haxe"],"Log")} as c))},FStatic (_,{cf_name="trace"}))} as ef, ([e2;_] as args))
+	| TCall ({eexpr = TField({eexpr = TTypeExpr (TClassDecl ({cl_path = ([],"Std")} as c))},FStatic (_,{cf_name="string"}))} as ef, ([e2] as args)) ->
+		mark_class dce c;
+		to_string dce e2.etype;
+		expr dce ef;
+		List.iter (expr dce) args;
+	| TCall ({eexpr = TConst TSuper} as e,el) ->
+		mark_t dce e.etype;
+		List.iter (expr dce) el;
+	| TField(e,fa) ->
+		begin match fa with
+			| FStatic(c,cf) ->
+				mark_class dce c;
+				mark_field dce c cf true;
+			| FInstance(c,cf) ->
+				mark_class dce c;
+				mark_field dce c cf false;
+			| _ ->
+				let n = field_name fa in
+				begin match follow e.etype with
+					| TInst(c,_) ->
+						mark_class dce c;
+						field dce c n false;
+					| TAnon a ->
+						(match !(a.a_status) with
+						| Statics c ->
+							mark_class dce c;
+							field dce c n true;
+						| _ -> ())
+					| _ -> ()
+				end;
+		end;
+		expr dce e;
+	| TThrow e ->
+		to_string dce e.etype;
+		expr dce e
+	| _ ->
+		Type.iter (expr dce) e
+
+let run com main full =
+	let dce = {
+		com = com;
+		full = full;
+		std_dirs = if full then [] else List.map Common.unique_full_path com.std_path;
+		debug = Common.defined com Define.DceDebug;
+		added_fields = [];
+		follow_expr = expr;
+		marked_fields = [];
+		marked_maybe_fields = [];
+		t_stack = [];
+	} in
+	begin match main with
+		| Some {eexpr = TCall({eexpr = TField(e,(FStatic(c,cf)))},_)} ->
+			cf.cf_meta <- (Meta.Keep,[],cf.cf_pos) :: cf.cf_meta
+		| _ ->
+			()
+	end;
+	(* first step: get all entry points, which is the main method and all class methods which are marked with @:keep *)
+	List.iter (fun t -> match t with
+		| TClassDecl c ->
+			let keep_class = keep_whole_class dce c && (not c.cl_extern || c.cl_interface) in
+			let loop stat cf =
+				if keep_class || keep_field dce cf then mark_field dce c cf stat
+			in
+			List.iter (loop true) c.cl_ordered_statics;
+			List.iter (loop false) c.cl_ordered_fields;
+			begin match c.cl_constructor with
+				| Some cf -> loop false cf
+				| None -> ()
+			end
+		| _ ->
+			()
+	) com.types;
+	if dce.debug then begin
+		List.iter (fun (c,cf,_) -> match cf.cf_expr with
+			| None -> ()
+			| Some _ -> print_endline ("[DCE] Entry point: " ^ (s_type_path c.cl_path) ^ "." ^ cf.cf_name)
+		) dce.added_fields;
+	end;
+	(* second step: initiate DCE passes and keep going until no new fields were added *)
+	let rec loop () =
+		match dce.added_fields with
+		| [] -> ()
+		| cfl ->
+			dce.added_fields <- [];
+			(* extend to dependent (= overriding/implementing) class fields *)
+			List.iter (fun (c,cf,stat) -> mark_dependent_fields dce c cf.cf_name stat) cfl;
+			(* mark fields as used *)
+			List.iter (fun (c,cf,stat) ->
+				mark_class dce c;
+				mark_field dce c cf stat;
+				mark_t dce cf.cf_type
+			) cfl;
+			(* follow expressions to new types/fields *)
+			List.iter (fun (_,cf,_) ->
+				opt (expr dce) cf.cf_expr;
+				List.iter (fun cf -> if cf.cf_expr <> None then opt (expr dce) cf.cf_expr) cf.cf_overloads
+			) cfl;
+			loop ()
+	in
+	loop ();
+	(* third step: filter types *)
+	let rec loop acc types =
+		match types with
+		| (TClassDecl c) as mt :: l when keep_whole_class dce c ->
+			loop (mt :: acc) l
+		| (TClassDecl c) as mt :: l ->
+			(* add :keep so subsequent filter calls do not process class fields again *)
+			c.cl_meta <- (Meta.Keep,[],c.cl_pos) :: c.cl_meta;
+ 			c.cl_ordered_statics <- List.filter (fun cf ->
+				let b = keep_field dce cf in
+				if not b then begin
+					if dce.debug then print_endline ("[DCE] Removed field " ^ (s_type_path c.cl_path) ^ "." ^ (cf.cf_name));
+					c.cl_statics <- PMap.remove cf.cf_name c.cl_statics;
+				end;
+				b
+			) c.cl_ordered_statics;
+			c.cl_ordered_fields <- List.filter (fun cf ->
+				let b = keep_field dce cf in
+				if not b then begin
+					if dce.debug then print_endline ("[DCE] Removed field " ^ (s_type_path c.cl_path) ^ "." ^ (cf.cf_name));
+					c.cl_fields <- PMap.remove cf.cf_name c.cl_fields;
+				end;
+				b
+			) c.cl_ordered_fields;
+			(match c.cl_constructor with Some cf when not (keep_field dce cf) -> c.cl_constructor <- None | _ -> ());
+			(* we keep a class if it was used or has a used field *)
+			if Meta.has Meta.Used c.cl_meta || c.cl_ordered_statics <> [] || c.cl_ordered_fields <> [] then loop (mt :: acc) l else begin
+				(match c.cl_init with
+				| Some f when Meta.has Meta.KeepInit c.cl_meta ->
+					(* it means that we only need the __init__ block *)
+					c.cl_extern <- true;
+					loop (mt :: acc) l
+				| _ ->
+					if dce.debug then print_endline ("[DCE] Removed class " ^ (s_type_path c.cl_path));
+					loop acc l)
+			end
+ 		| (TEnumDecl e) as mt :: l when Meta.has Meta.Used e.e_meta || Meta.has Meta.Keep e.e_meta || e.e_extern || not (dce.full || is_std_file dce e.e_module.m_extra.m_file) ->
+			loop (mt :: acc) l
+		| TEnumDecl e :: l ->
+			if dce.debug then print_endline ("[DCE] Removed enum " ^ (s_type_path e.e_path));
+			loop acc l
+		| mt :: l ->
+			loop (mt :: acc) l
+		| [] ->
+			acc
+	in
+	com.types <- loop [] (List.rev com.types);
+
+	(* extra step to adjust properties that had accessors removed (required for Php and Cpp) *)
+	List.iter (fun mt -> match mt with
+		| (TClassDecl c) ->
+			let rec has_accessor c n stat =
+				PMap.mem n (if stat then c.cl_statics else c.cl_fields)
+				|| match c.cl_super with Some (csup,_) -> has_accessor csup n stat | None -> false
+			in
+			let check_prop stat cf =
+				(match cf.cf_kind with
+				| Var {v_read = AccCall; v_write = a} ->
+					let s = "get_" ^ cf.cf_name in
+					cf.cf_kind <- Var {v_read = if has_accessor c s stat then AccCall else AccNever; v_write = a}
+				| _ -> ());
+				(match cf.cf_kind with
+				| Var {v_write = AccCall; v_read = a} ->
+					let s = "set_" ^ cf.cf_name in
+					cf.cf_kind <- Var {v_write = if has_accessor c s stat then AccCall else AccNever; v_read = a}
+				| _ -> ())
+			in
+			List.iter (check_prop true) c.cl_ordered_statics;
+			List.iter (check_prop false) c.cl_ordered_fields;
+		| _ -> ()
+	) com.types;
+
+	(* remove "override" from fields that do not override anything anymore *)
+	List.iter (fun mt -> match mt with
+		| TClassDecl c ->
+			c.cl_overrides <- List.filter (fun s ->
+				let rec loop c =
+					match c.cl_super with
+					| Some (csup,_) when PMap.mem s.cf_name csup.cl_fields -> true
+					| Some (csup,_) -> loop csup
+					| None -> false
+				in
+				loop c
+			) c.cl_overrides;
+		| _ -> ()
+	) com.types;
+
+	(* cleanup added fields metadata - compatibility with compilation server *)
+	let rec remove_meta m = function
+		| [] -> []
+		| (m2,_,_) :: l when m = m2 -> l
+		| x :: l -> x :: remove_meta m l
+	in
+	List.iter (fun cf -> cf.cf_meta <- remove_meta Meta.Used cf.cf_meta) dce.marked_fields;
+	List.iter (fun cf -> cf.cf_meta <- remove_meta Meta.MaybeUsed cf.cf_meta) dce.marked_maybe_fields;
+
+

+ 24 - 24
doc/CONTRIB.txt

@@ -1,25 +1,25 @@
-Contributor License Agreement :
-
-You accept and agree to the following terms and conditions for Your present and future Contributions submitted to the project Haxe :
-
-1) Definitions 
-
-  "Contribution" : any source code, documentation, including any modifications or additions to an existing work that is intentionally submitted by You to the Haxe Foundation for inclusion in, or documentation of, any of the products managed and maintained by the Haxe Foundation.
-
-  "Submitted" means any form or electronic, verbal or written communication, including but not limited to communication on electronic mailing lists, source code control systems and issue tracking system that are managed by, or on behalf of, the Haxe Foundation for the purpose of improving Haxe.
-
-2) Grant of Copyright License. Subject to the terms and conditions of this Grant, You hereby grant to the Haxe Foundation and to recipients of software distributed by the Haxe Foundation a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute Your Contributions and such derivative works.
-
-3) You represent that you are legally entitled to grant the above license. If your employer(s) has rights to intellectual property that you create that includes your Contributions, you represent that you have received permission to make Contributions on behalf of that employer, that your employer has waived such rights for your Contributions to the Haxe Foundation, or that your employer has executed a separate Corporate Contributor License Grant with the Haxe Foundation.
-
-4) You represent that each of Your Contributions is Your original creation (see section 7 for submissions on behalf of others). You represent that Your Contribution submissions include complete details of any third-party license or other restriction (including, but not limited to, related patents and trademarks) of which you are personally aware and which are associated with any part of Your Contributions.
-
-5) You are not expected to provide support for Your Contributions, except to the extent You desire to provide support. You may provide support for free, for a fee, or not at all. Unless required by applicable law or agreed to in writing, You provide Your Contributions on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON- INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE.
-
-Full Name :
-Email :
-Mailing Address :
-Country :
-
-
+Contributor License Agreement :
+
+You accept and agree to the following terms and conditions for Your present and future Contributions submitted to the project Haxe :
+
+1) Definitions 
+
+  "Contribution" : any source code, documentation, including any modifications or additions to an existing work that is intentionally submitted by You to the Haxe Foundation for inclusion in, or documentation of, any of the products managed and maintained by the Haxe Foundation.
+
+  "Submitted" means any form or electronic, verbal or written communication, including but not limited to communication on electronic mailing lists, source code control systems and issue tracking system that are managed by, or on behalf of, the Haxe Foundation for the purpose of improving Haxe.
+
+2) Grant of Copyright License. Subject to the terms and conditions of this Grant, You hereby grant to the Haxe Foundation and to recipients of software distributed by the Haxe Foundation a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute Your Contributions and such derivative works.
+
+3) You represent that you are legally entitled to grant the above license. If your employer(s) has rights to intellectual property that you create that includes your Contributions, you represent that you have received permission to make Contributions on behalf of that employer, that your employer has waived such rights for your Contributions to the Haxe Foundation, or that your employer has executed a separate Corporate Contributor License Grant with the Haxe Foundation.
+
+4) You represent that each of Your Contributions is Your original creation (see section 7 for submissions on behalf of others). You represent that Your Contribution submissions include complete details of any third-party license or other restriction (including, but not limited to, related patents and trademarks) of which you are personally aware and which are associated with any part of Your Contributions.
+
+5) You are not expected to provide support for Your Contributions, except to the extent You desire to provide support. You may provide support for free, for a fee, or not at all. Unless required by applicable law or agreed to in writing, You provide Your Contributions on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON- INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE.
+
+Full Name :
+Email :
+Mailing Address :
+Country :
+
+
 Signature:

+ 327 - 327
doc/EnvVarUpdate.nsh

@@ -1,327 +1,327 @@
-/**
- *  EnvVarUpdate.nsh
- *    : Environmental Variables: append, prepend, and remove entries
- *
- *     WARNING: If you use StrFunc.nsh header then include it before this file
- *              with all required definitions. This is to avoid conflicts
- *
- *  Usage:
- *    ${EnvVarUpdate} "ResultVar" "EnvVarName" "Action" "RegLoc" "PathString"
- *
- *  Credits:
- *  Version 1.0 
- *  * Cal Turney (turnec2)
- *  * Amir Szekely (KiCHiK) and e-circ for developing the forerunners of this
- *    function: AddToPath, un.RemoveFromPath, AddToEnvVar, un.RemoveFromEnvVar,
- *    WriteEnvStr, and un.DeleteEnvStr
- *  * Diego Pedroso (deguix) for StrTok
- *  * Kevin English (kenglish_hi) for StrContains
- *  * Hendri Adriaens (Smile2Me), Diego Pedroso (deguix), and Dan Fuhry  
- *    (dandaman32) for StrReplace
- *
- *  Version 1.1 (compatibility with StrFunc.nsh)
- *  * techtonik
- *
- *  http://nsis.sourceforge.net/Environmental_Variables:_append%2C_prepend%2C_and_remove_entries
- *
- */
-
-
-!ifndef ENVVARUPDATE_FUNCTION
-!define ENVVARUPDATE_FUNCTION
-!verbose push
-!verbose 3
-!include "LogicLib.nsh"
-!include "WinMessages.NSH"
-!include "StrFunc.nsh"
-
-; ---- Fix for conflict if StrFunc.nsh is already includes in main file -----------------------
-!macro _IncludeStrFunction StrFuncName
-  !ifndef ${StrFuncName}_INCLUDED
-    ${${StrFuncName}}
-  !endif
-  !ifndef Un${StrFuncName}_INCLUDED
-    ${Un${StrFuncName}}
-  !endif
-  !define un.${StrFuncName} "${Un${StrFuncName}}"
-!macroend
-
-!insertmacro _IncludeStrFunction StrTok
-!insertmacro _IncludeStrFunction StrStr
-!insertmacro _IncludeStrFunction StrRep
-
-; ---------------------------------- Macro Definitions ----------------------------------------
-!macro _EnvVarUpdateConstructor ResultVar EnvVarName Action Regloc PathString
-  Push "${EnvVarName}"
-  Push "${Action}"
-  Push "${RegLoc}"
-  Push "${PathString}"
-    Call EnvVarUpdate
-  Pop "${ResultVar}"
-!macroend
-!define EnvVarUpdate '!insertmacro "_EnvVarUpdateConstructor"'
- 
-!macro _unEnvVarUpdateConstructor ResultVar EnvVarName Action Regloc PathString
-  Push "${EnvVarName}"
-  Push "${Action}"
-  Push "${RegLoc}"
-  Push "${PathString}"
-    Call un.EnvVarUpdate
-  Pop "${ResultVar}"
-!macroend
-!define un.EnvVarUpdate '!insertmacro "_unEnvVarUpdateConstructor"'
-; ---------------------------------- Macro Definitions end-------------------------------------
- 
-;----------------------------------- EnvVarUpdate start----------------------------------------
-!define hklm_all_users     'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
-!define hkcu_current_user  'HKCU "Environment"'
- 
-!macro EnvVarUpdate UN
- 
-Function ${UN}EnvVarUpdate
- 
-  Push $0
-  Exch 4
-  Exch $1
-  Exch 3
-  Exch $2
-  Exch 2
-  Exch $3
-  Exch
-  Exch $4
-  Push $5
-  Push $6
-  Push $7
-  Push $8
-  Push $9
-  Push $R0
- 
-  /* After this point:
-  -------------------------
-     $0 = ResultVar     (returned)
-     $1 = EnvVarName    (input)
-     $2 = Action        (input)
-     $3 = RegLoc        (input)
-     $4 = PathString    (input)
-     $5 = Orig EnvVar   (read from registry)
-     $6 = Len of $0     (temp)
-     $7 = tempstr1      (temp)
-     $8 = Entry counter (temp)
-     $9 = tempstr2      (temp)
-     $R0 = tempChar     (temp)  */
- 
-  ; Step 1:  Read contents of EnvVarName from RegLoc
-  ;
-  ; Check for empty EnvVarName
-  ${If} $1 == ""
-    SetErrors
-    DetailPrint "ERROR: EnvVarName is blank"
-    Goto EnvVarUpdate_Restore_Vars
-  ${EndIf}
- 
-  ; Check for valid Action
-  ${If}    $2 != "A"
-  ${AndIf} $2 != "P"
-  ${AndIf} $2 != "R"
-    SetErrors
-    DetailPrint "ERROR: Invalid Action - must be A, P, or R"
-    Goto EnvVarUpdate_Restore_Vars
-  ${EndIf}
- 
-  ${If} $3 == HKLM
-    ReadRegStr $5 ${hklm_all_users} $1     ; Get EnvVarName from all users into $5
-  ${ElseIf} $3 == HKCU
-    ReadRegStr $5 ${hkcu_current_user} $1  ; Read EnvVarName from current user into $5
-  ${Else}
-    SetErrors
-    DetailPrint 'ERROR: Action is [$3] but must be "HKLM" or HKCU"'
-    Goto EnvVarUpdate_Restore_Vars
-  ${EndIf}
- 
-  ; Check for empty PathString
-  ${If} $4 == ""
-    SetErrors
-    DetailPrint "ERROR: PathString is blank"
-    Goto EnvVarUpdate_Restore_Vars
-  ${EndIf}
- 
-  ; Make sure we've got some work to do
-  ${If} $5 == ""
-  ${AndIf} $2 == "R"
-    SetErrors
-    DetailPrint "$1 is empty - Nothing to remove"
-    Goto EnvVarUpdate_Restore_Vars
-  ${EndIf}
- 
-  ; Step 2: Scrub EnvVar
-  ;
-  StrCpy $0 $5                             ; Copy the contents to $0
-  ; Remove spaces around semicolons (NOTE: spaces before the 1st entry or
-  ; after the last one are not removed here but instead in Step 3)
-  ${If} $0 != ""                           ; If EnvVar is not empty ...
-    ${Do}
-      ${${UN}StrStr} $7 $0 " ;"
-      ${If} $7 == ""
-        ${ExitDo}
-      ${EndIf}
-      ${${UN}StrRep} $0  $0 " ;" ";"         ; Remove '<space>;'
-    ${Loop}
-    ${Do}
-      ${${UN}StrStr} $7 $0 "; "
-      ${If} $7 == ""
-        ${ExitDo}
-      ${EndIf}
-      ${${UN}StrRep} $0  $0 "; " ";"         ; Remove ';<space>'
-    ${Loop}
-    ${Do}
-      ${${UN}StrStr} $7 $0 ";;" 
-      ${If} $7 == ""
-        ${ExitDo}
-      ${EndIf}
-      ${${UN}StrRep} $0  $0 ";;" ";"
-    ${Loop}
- 
-    ; Remove a leading or trailing semicolon from EnvVar
-    StrCpy  $7  $0 1 0
-    ${If} $7 == ";"
-      StrCpy $0  $0 "" 1                   ; Change ';<EnvVar>' to '<EnvVar>'
-    ${EndIf}
-    StrLen $6 $0
-    IntOp $6 $6 - 1
-    StrCpy $7  $0 1 $6
-    ${If} $7 == ";"
-     StrCpy $0  $0 $6                      ; Change ';<EnvVar>' to '<EnvVar>'
-    ${EndIf}
-    ; DetailPrint "Scrubbed $1: [$0]"      ; Uncomment to debug
-  ${EndIf}
- 
-  /* Step 3. Remove all instances of the target path/string (even if "A" or "P")
-     $6 = bool flag (1 = found and removed PathString)
-     $7 = a string (e.g. path) delimited by semicolon(s)
-     $8 = entry counter starting at 0
-     $9 = copy of $0
-     $R0 = tempChar      */
- 
-  ${If} $5 != ""                           ; If EnvVar is not empty ...
-    StrCpy $9 $0
-    StrCpy $0 ""
-    StrCpy $8 0
-    StrCpy $6 0
- 
-    ${Do}
-      ${${UN}StrTok} $7 $9 ";" $8 "0"      ; $7 = next entry, $8 = entry counter
- 
-      ${If} $7 == ""                       ; If we've run out of entries,
-        ${ExitDo}                          ;    were done
-      ${EndIf}                             ;
- 
-      ; Remove leading and trailing spaces from this entry (critical step for Action=Remove)
-      ${Do}
-        StrCpy $R0  $7 1
-        ${If} $R0 != " "
-          ${ExitDo}
-        ${EndIf}
-        StrCpy $7   $7 "" 1                ;  Remove leading space
-      ${Loop}
-      ${Do}
-        StrCpy $R0  $7 1 -1
-        ${If} $R0 != " "
-          ${ExitDo}
-        ${EndIf}
-        StrCpy $7   $7 -1                  ;  Remove trailing space
-      ${Loop}
-      ${If} $7 == $4                       ; If string matches, remove it by not appending it
-        StrCpy $6 1                        ; Set 'found' flag
-      ${ElseIf} $7 != $4                   ; If string does NOT match
-      ${AndIf}  $0 == ""                   ;    and the 1st string being added to $0,
-        StrCpy $0 $7                       ;    copy it to $0 without a prepended semicolon
-      ${ElseIf} $7 != $4                   ; If string does NOT match
-      ${AndIf}  $0 != ""                   ;    and this is NOT the 1st string to be added to $0,
-        StrCpy $0 $0;$7                    ;    append path to $0 with a prepended semicolon
-      ${EndIf}                             ;
- 
-      IntOp $8 $8 + 1                      ; Bump counter
-    ${Loop}                                ; Check for duplicates until we run out of paths
-  ${EndIf}
- 
-  ; Step 4:  Perform the requested Action
-  ;
-  ${If} $2 != "R"                          ; If Append or Prepend
-    ${If} $6 == 1                          ; And if we found the target
-      DetailPrint "Target is already present in $1. It will be removed and"
-    ${EndIf}
-    ${If} $0 == ""                         ; If EnvVar is (now) empty
-      StrCpy $0 $4                         ;   just copy PathString to EnvVar
-      ${If} $6 == 0                        ; If found flag is either 0
-      ${OrIf} $6 == ""                     ; or blank (if EnvVarName is empty)
-        DetailPrint "$1 was empty and has been updated with the target"
-      ${EndIf}
-    ${ElseIf} $2 == "A"                    ;  If Append (and EnvVar is not empty),
-      StrCpy $0 $0;$4                      ;     append PathString
-      ${If} $6 == 1
-        DetailPrint "appended to $1"
-      ${Else}
-        DetailPrint "Target was appended to $1"
-      ${EndIf}
-    ${Else}                                ;  If Prepend (and EnvVar is not empty),
-      StrCpy $0 $4;$0                      ;     prepend PathString
-      ${If} $6 == 1
-        DetailPrint "prepended to $1"
-      ${Else}
-        DetailPrint "Target was prepended to $1"
-      ${EndIf}
-    ${EndIf}
-  ${Else}                                  ; If Action = Remove
-    ${If} $6 == 1                          ;   and we found the target
-      DetailPrint "Target was found and removed from $1"
-    ${Else}
-      DetailPrint "Target was NOT found in $1 (nothing to remove)"
-    ${EndIf}
-    ${If} $0 == ""
-      DetailPrint "$1 is now empty"
-    ${EndIf}
-  ${EndIf}
- 
-  ; Step 5:  Update the registry at RegLoc with the updated EnvVar and announce the change
-  ;
-  ClearErrors
-  ${If} $3  == HKLM
-    WriteRegExpandStr ${hklm_all_users} $1 $0     ; Write it in all users section
-  ${ElseIf} $3 == HKCU
-    WriteRegExpandStr ${hkcu_current_user} $1 $0  ; Write it to current user section
-  ${EndIf}
- 
-  IfErrors 0 +4
-    MessageBox MB_OK|MB_ICONEXCLAMATION "Could not write updated $1 to $3"
-    DetailPrint "Could not write updated $1 to $3"
-    Goto EnvVarUpdate_Restore_Vars
- 
-  ; "Export" our change
-  SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
- 
-  EnvVarUpdate_Restore_Vars:
-  ;
-  ; Restore the user's variables and return ResultVar
-  Pop $R0
-  Pop $9
-  Pop $8
-  Pop $7
-  Pop $6
-  Pop $5
-  Pop $4
-  Pop $3
-  Pop $2
-  Pop $1
-  Push $0  ; Push my $0 (ResultVar)
-  Exch
-  Pop $0   ; Restore his $0
- 
-FunctionEnd
- 
-!macroend   ; EnvVarUpdate UN
-!insertmacro EnvVarUpdate ""
-!insertmacro EnvVarUpdate "un."
-;----------------------------------- EnvVarUpdate end----------------------------------------
- 
-!verbose pop
-!endif
+/**
+ *  EnvVarUpdate.nsh
+ *    : Environmental Variables: append, prepend, and remove entries
+ *
+ *     WARNING: If you use StrFunc.nsh header then include it before this file
+ *              with all required definitions. This is to avoid conflicts
+ *
+ *  Usage:
+ *    ${EnvVarUpdate} "ResultVar" "EnvVarName" "Action" "RegLoc" "PathString"
+ *
+ *  Credits:
+ *  Version 1.0 
+ *  * Cal Turney (turnec2)
+ *  * Amir Szekely (KiCHiK) and e-circ for developing the forerunners of this
+ *    function: AddToPath, un.RemoveFromPath, AddToEnvVar, un.RemoveFromEnvVar,
+ *    WriteEnvStr, and un.DeleteEnvStr
+ *  * Diego Pedroso (deguix) for StrTok
+ *  * Kevin English (kenglish_hi) for StrContains
+ *  * Hendri Adriaens (Smile2Me), Diego Pedroso (deguix), and Dan Fuhry  
+ *    (dandaman32) for StrReplace
+ *
+ *  Version 1.1 (compatibility with StrFunc.nsh)
+ *  * techtonik
+ *
+ *  http://nsis.sourceforge.net/Environmental_Variables:_append%2C_prepend%2C_and_remove_entries
+ *
+ */
+
+
+!ifndef ENVVARUPDATE_FUNCTION
+!define ENVVARUPDATE_FUNCTION
+!verbose push
+!verbose 3
+!include "LogicLib.nsh"
+!include "WinMessages.NSH"
+!include "StrFunc.nsh"
+
+; ---- Fix for conflict if StrFunc.nsh is already includes in main file -----------------------
+!macro _IncludeStrFunction StrFuncName
+  !ifndef ${StrFuncName}_INCLUDED
+    ${${StrFuncName}}
+  !endif
+  !ifndef Un${StrFuncName}_INCLUDED
+    ${Un${StrFuncName}}
+  !endif
+  !define un.${StrFuncName} "${Un${StrFuncName}}"
+!macroend
+
+!insertmacro _IncludeStrFunction StrTok
+!insertmacro _IncludeStrFunction StrStr
+!insertmacro _IncludeStrFunction StrRep
+
+; ---------------------------------- Macro Definitions ----------------------------------------
+!macro _EnvVarUpdateConstructor ResultVar EnvVarName Action Regloc PathString
+  Push "${EnvVarName}"
+  Push "${Action}"
+  Push "${RegLoc}"
+  Push "${PathString}"
+    Call EnvVarUpdate
+  Pop "${ResultVar}"
+!macroend
+!define EnvVarUpdate '!insertmacro "_EnvVarUpdateConstructor"'
+ 
+!macro _unEnvVarUpdateConstructor ResultVar EnvVarName Action Regloc PathString
+  Push "${EnvVarName}"
+  Push "${Action}"
+  Push "${RegLoc}"
+  Push "${PathString}"
+    Call un.EnvVarUpdate
+  Pop "${ResultVar}"
+!macroend
+!define un.EnvVarUpdate '!insertmacro "_unEnvVarUpdateConstructor"'
+; ---------------------------------- Macro Definitions end-------------------------------------
+ 
+;----------------------------------- EnvVarUpdate start----------------------------------------
+!define hklm_all_users     'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
+!define hkcu_current_user  'HKCU "Environment"'
+ 
+!macro EnvVarUpdate UN
+ 
+Function ${UN}EnvVarUpdate
+ 
+  Push $0
+  Exch 4
+  Exch $1
+  Exch 3
+  Exch $2
+  Exch 2
+  Exch $3
+  Exch
+  Exch $4
+  Push $5
+  Push $6
+  Push $7
+  Push $8
+  Push $9
+  Push $R0
+ 
+  /* After this point:
+  -------------------------
+     $0 = ResultVar     (returned)
+     $1 = EnvVarName    (input)
+     $2 = Action        (input)
+     $3 = RegLoc        (input)
+     $4 = PathString    (input)
+     $5 = Orig EnvVar   (read from registry)
+     $6 = Len of $0     (temp)
+     $7 = tempstr1      (temp)
+     $8 = Entry counter (temp)
+     $9 = tempstr2      (temp)
+     $R0 = tempChar     (temp)  */
+ 
+  ; Step 1:  Read contents of EnvVarName from RegLoc
+  ;
+  ; Check for empty EnvVarName
+  ${If} $1 == ""
+    SetErrors
+    DetailPrint "ERROR: EnvVarName is blank"
+    Goto EnvVarUpdate_Restore_Vars
+  ${EndIf}
+ 
+  ; Check for valid Action
+  ${If}    $2 != "A"
+  ${AndIf} $2 != "P"
+  ${AndIf} $2 != "R"
+    SetErrors
+    DetailPrint "ERROR: Invalid Action - must be A, P, or R"
+    Goto EnvVarUpdate_Restore_Vars
+  ${EndIf}
+ 
+  ${If} $3 == HKLM
+    ReadRegStr $5 ${hklm_all_users} $1     ; Get EnvVarName from all users into $5
+  ${ElseIf} $3 == HKCU
+    ReadRegStr $5 ${hkcu_current_user} $1  ; Read EnvVarName from current user into $5
+  ${Else}
+    SetErrors
+    DetailPrint 'ERROR: Action is [$3] but must be "HKLM" or HKCU"'
+    Goto EnvVarUpdate_Restore_Vars
+  ${EndIf}
+ 
+  ; Check for empty PathString
+  ${If} $4 == ""
+    SetErrors
+    DetailPrint "ERROR: PathString is blank"
+    Goto EnvVarUpdate_Restore_Vars
+  ${EndIf}
+ 
+  ; Make sure we've got some work to do
+  ${If} $5 == ""
+  ${AndIf} $2 == "R"
+    SetErrors
+    DetailPrint "$1 is empty - Nothing to remove"
+    Goto EnvVarUpdate_Restore_Vars
+  ${EndIf}
+ 
+  ; Step 2: Scrub EnvVar
+  ;
+  StrCpy $0 $5                             ; Copy the contents to $0
+  ; Remove spaces around semicolons (NOTE: spaces before the 1st entry or
+  ; after the last one are not removed here but instead in Step 3)
+  ${If} $0 != ""                           ; If EnvVar is not empty ...
+    ${Do}
+      ${${UN}StrStr} $7 $0 " ;"
+      ${If} $7 == ""
+        ${ExitDo}
+      ${EndIf}
+      ${${UN}StrRep} $0  $0 " ;" ";"         ; Remove '<space>;'
+    ${Loop}
+    ${Do}
+      ${${UN}StrStr} $7 $0 "; "
+      ${If} $7 == ""
+        ${ExitDo}
+      ${EndIf}
+      ${${UN}StrRep} $0  $0 "; " ";"         ; Remove ';<space>'
+    ${Loop}
+    ${Do}
+      ${${UN}StrStr} $7 $0 ";;" 
+      ${If} $7 == ""
+        ${ExitDo}
+      ${EndIf}
+      ${${UN}StrRep} $0  $0 ";;" ";"
+    ${Loop}
+ 
+    ; Remove a leading or trailing semicolon from EnvVar
+    StrCpy  $7  $0 1 0
+    ${If} $7 == ";"
+      StrCpy $0  $0 "" 1                   ; Change ';<EnvVar>' to '<EnvVar>'
+    ${EndIf}
+    StrLen $6 $0
+    IntOp $6 $6 - 1
+    StrCpy $7  $0 1 $6
+    ${If} $7 == ";"
+     StrCpy $0  $0 $6                      ; Change ';<EnvVar>' to '<EnvVar>'
+    ${EndIf}
+    ; DetailPrint "Scrubbed $1: [$0]"      ; Uncomment to debug
+  ${EndIf}
+ 
+  /* Step 3. Remove all instances of the target path/string (even if "A" or "P")
+     $6 = bool flag (1 = found and removed PathString)
+     $7 = a string (e.g. path) delimited by semicolon(s)
+     $8 = entry counter starting at 0
+     $9 = copy of $0
+     $R0 = tempChar      */
+ 
+  ${If} $5 != ""                           ; If EnvVar is not empty ...
+    StrCpy $9 $0
+    StrCpy $0 ""
+    StrCpy $8 0
+    StrCpy $6 0
+ 
+    ${Do}
+      ${${UN}StrTok} $7 $9 ";" $8 "0"      ; $7 = next entry, $8 = entry counter
+ 
+      ${If} $7 == ""                       ; If we've run out of entries,
+        ${ExitDo}                          ;    were done
+      ${EndIf}                             ;
+ 
+      ; Remove leading and trailing spaces from this entry (critical step for Action=Remove)
+      ${Do}
+        StrCpy $R0  $7 1
+        ${If} $R0 != " "
+          ${ExitDo}
+        ${EndIf}
+        StrCpy $7   $7 "" 1                ;  Remove leading space
+      ${Loop}
+      ${Do}
+        StrCpy $R0  $7 1 -1
+        ${If} $R0 != " "
+          ${ExitDo}
+        ${EndIf}
+        StrCpy $7   $7 -1                  ;  Remove trailing space
+      ${Loop}
+      ${If} $7 == $4                       ; If string matches, remove it by not appending it
+        StrCpy $6 1                        ; Set 'found' flag
+      ${ElseIf} $7 != $4                   ; If string does NOT match
+      ${AndIf}  $0 == ""                   ;    and the 1st string being added to $0,
+        StrCpy $0 $7                       ;    copy it to $0 without a prepended semicolon
+      ${ElseIf} $7 != $4                   ; If string does NOT match
+      ${AndIf}  $0 != ""                   ;    and this is NOT the 1st string to be added to $0,
+        StrCpy $0 $0;$7                    ;    append path to $0 with a prepended semicolon
+      ${EndIf}                             ;
+ 
+      IntOp $8 $8 + 1                      ; Bump counter
+    ${Loop}                                ; Check for duplicates until we run out of paths
+  ${EndIf}
+ 
+  ; Step 4:  Perform the requested Action
+  ;
+  ${If} $2 != "R"                          ; If Append or Prepend
+    ${If} $6 == 1                          ; And if we found the target
+      DetailPrint "Target is already present in $1. It will be removed and"
+    ${EndIf}
+    ${If} $0 == ""                         ; If EnvVar is (now) empty
+      StrCpy $0 $4                         ;   just copy PathString to EnvVar
+      ${If} $6 == 0                        ; If found flag is either 0
+      ${OrIf} $6 == ""                     ; or blank (if EnvVarName is empty)
+        DetailPrint "$1 was empty and has been updated with the target"
+      ${EndIf}
+    ${ElseIf} $2 == "A"                    ;  If Append (and EnvVar is not empty),
+      StrCpy $0 $0;$4                      ;     append PathString
+      ${If} $6 == 1
+        DetailPrint "appended to $1"
+      ${Else}
+        DetailPrint "Target was appended to $1"
+      ${EndIf}
+    ${Else}                                ;  If Prepend (and EnvVar is not empty),
+      StrCpy $0 $4;$0                      ;     prepend PathString
+      ${If} $6 == 1
+        DetailPrint "prepended to $1"
+      ${Else}
+        DetailPrint "Target was prepended to $1"
+      ${EndIf}
+    ${EndIf}
+  ${Else}                                  ; If Action = Remove
+    ${If} $6 == 1                          ;   and we found the target
+      DetailPrint "Target was found and removed from $1"
+    ${Else}
+      DetailPrint "Target was NOT found in $1 (nothing to remove)"
+    ${EndIf}
+    ${If} $0 == ""
+      DetailPrint "$1 is now empty"
+    ${EndIf}
+  ${EndIf}
+ 
+  ; Step 5:  Update the registry at RegLoc with the updated EnvVar and announce the change
+  ;
+  ClearErrors
+  ${If} $3  == HKLM
+    WriteRegExpandStr ${hklm_all_users} $1 $0     ; Write it in all users section
+  ${ElseIf} $3 == HKCU
+    WriteRegExpandStr ${hkcu_current_user} $1 $0  ; Write it to current user section
+  ${EndIf}
+ 
+  IfErrors 0 +4
+    MessageBox MB_OK|MB_ICONEXCLAMATION "Could not write updated $1 to $3"
+    DetailPrint "Could not write updated $1 to $3"
+    Goto EnvVarUpdate_Restore_Vars
+ 
+  ; "Export" our change
+  SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
+ 
+  EnvVarUpdate_Restore_Vars:
+  ;
+  ; Restore the user's variables and return ResultVar
+  Pop $R0
+  Pop $9
+  Pop $8
+  Pop $7
+  Pop $6
+  Pop $5
+  Pop $4
+  Pop $3
+  Pop $2
+  Pop $1
+  Push $0  ; Push my $0 (ResultVar)
+  Exch
+  Pop $0   ; Restore his $0
+ 
+FunctionEnd
+ 
+!macroend   ; EnvVarUpdate UN
+!insertmacro EnvVarUpdate ""
+!insertmacro EnvVarUpdate "un."
+;----------------------------------- EnvVarUpdate end----------------------------------------
+ 
+!verbose pop
+!endif

+ 54 - 54
doc/all.hxproj

@@ -1,55 +1,55 @@
-<?xml version="1.0" encoding="utf-8"?>
-<project version="2">
-  <!-- Output SWF options -->
-  <output>
-    <movie outputType="CustomBuild" />
-    <movie input="" />
-    <movie path="" />
-    <movie fps="30" />
-    <movie width="800" />
-    <movie height="600" />
-    <movie version="9" />
-    <movie minorVersion="0" />
-    <movie platform="Flash Player" />
-    <movie background="#FFFFFF" />
-  </output>
-  <!-- Other classes to be compiled into your SWF -->
-  <classpaths>
-    <!-- example: <class path="..." /> -->
-  </classpaths>
-  <!-- Build options -->
-  <build>
-    <option directives="" />
-    <option flashStrict="False" />
-    <option mainClass="" />
-    <option enabledebug="False" />
-    <option additional="" />
-  </build>
-  <!-- haxelib libraries -->
-  <haxelib>
-    <!-- example: <library name="..." /> -->
-  </haxelib>
-  <!-- Class files to compile (other referenced classes will automatically be included) -->
-  <compileTargets>
-    <!-- example: <compile path="..." /> -->
-  </compileTargets>
-  <!-- Assets to embed into the output SWF -->
-  <library>
-    <!-- example: <asset path="..." id="..." update="..." glyphs="..." mode="..." place="..." sharepoint="..." /> -->
-  </library>
-  <!-- Paths to exclude from the Project Explorer tree -->
-  <hiddenPaths>
-    <!-- example: <hidden path="..." /> -->
-  </hiddenPaths>
-  <!-- Executed before build -->
-  <preBuildCommand>haxe all.hxml</preBuildCommand>
-  <!-- Executed after build -->
-  <postBuildCommand alwaysRun="False" />
-  <!-- Other project options -->
-  <options>
-    <option showHiddenPaths="False" />
-    <option testMovie="Default" />
-  </options>
-  <!-- Plugin storage -->
-  <storage />
+<?xml version="1.0" encoding="utf-8"?>
+<project version="2">
+  <!-- Output SWF options -->
+  <output>
+    <movie outputType="CustomBuild" />
+    <movie input="" />
+    <movie path="" />
+    <movie fps="30" />
+    <movie width="800" />
+    <movie height="600" />
+    <movie version="9" />
+    <movie minorVersion="0" />
+    <movie platform="Flash Player" />
+    <movie background="#FFFFFF" />
+  </output>
+  <!-- Other classes to be compiled into your SWF -->
+  <classpaths>
+    <!-- example: <class path="..." /> -->
+  </classpaths>
+  <!-- Build options -->
+  <build>
+    <option directives="" />
+    <option flashStrict="False" />
+    <option mainClass="" />
+    <option enabledebug="False" />
+    <option additional="" />
+  </build>
+  <!-- haxelib libraries -->
+  <haxelib>
+    <!-- example: <library name="..." /> -->
+  </haxelib>
+  <!-- Class files to compile (other referenced classes will automatically be included) -->
+  <compileTargets>
+    <!-- example: <compile path="..." /> -->
+  </compileTargets>
+  <!-- Assets to embed into the output SWF -->
+  <library>
+    <!-- example: <asset path="..." id="..." update="..." glyphs="..." mode="..." place="..." sharepoint="..." /> -->
+  </library>
+  <!-- Paths to exclude from the Project Explorer tree -->
+  <hiddenPaths>
+    <!-- example: <hidden path="..." /> -->
+  </hiddenPaths>
+  <!-- Executed before build -->
+  <preBuildCommand>haxe all.hxml</preBuildCommand>
+  <!-- Executed after build -->
+  <postBuildCommand alwaysRun="False" />
+  <!-- Other project options -->
+  <options>
+    <option showHiddenPaths="False" />
+    <option testMovie="Default" />
+  </options>
+  <!-- Plugin storage -->
+  <storage />
 </project>

+ 5 - 5
doc/extract.hxml

@@ -1,6 +1,6 @@
--debug
--swf-lib library.swf
--swf test.swf
--swf-version 11.7
---macro patchTypes("../doc/extract.patch")
+-debug
+-swf-lib library.swf
+-swf test.swf
+-swf-version 11.7
+--macro patchTypes("../doc/extract.patch")
 --gen-hx-classes

+ 1224 - 1224
doc/extract.patch

@@ -1,1224 +1,1224 @@
-// types patches configuration for playerglobal.swc
-
-flash.display.DisplayObject.filters : Array<flash.filters.BitmapFilter>;
-
--flash.accessibility.Accessibility.new
-@:require(flash10_1) flash.accessibility.ISearchableText
-@:require(flash10_1) flash.accessibility.ISimpleTextSelection
-
-@:require(flash10_1) flash.automation.ActionGenerator
-@:require(flash10_1) flash.automation.AutomationAction
-@:require(flash10_1) flash.automation.Configuration
-@:require(flash10_1) flash.automation.KeyboardAutomationAction
-@:require(flash10_1) flash.automation.MouseAutomationAction
-@:require(flash10_1) flash.automation.StageCapture
-@:require(flash10_1) flash.automation.StageCaptureEvent
-
--flash.desktop.Clipboard.new
-flash.desktop.Clipboard.formats : Array<ClipboardFormats>;
-flash.desktop.Clipboard.$format : ClipboardFormats;
-flash.desktop.Clipboard.$transferMode : ClipboardTransferMode;
-
-enum flash.desktop.ClipboardFormats;
-enum flash.desktop.ClipboardTransferMode;
-
-enum flash.display.PixelSnapping;
-enum flash.display.BlendMode;
-
-@:require(flash10) flash.desktop.Clipboard
-@:require(flash10) flash.desktop.ClipboardFormats
-@:require(flash10) flash.desktop.ClipboardTransferMode
-
-flash.display.Bitmap.pixelSnapping : PixelSnapping;
-flash.display.Bitmap.$pixelSnapping : PixelSnapping;
-flash.display.BitmapData.$blendMode : BlendMode;
-flash.display.BitmapData.$redArray : Array<Int>;
-flash.display.BitmapData.$greenArray : Array<Int>;
-flash.display.BitmapData.$blueArray : Array<Int>;
-flash.display.BitmapData.$alphaArray : Array<Int>;
-flash.display.BitmapData.$offsets : Array<flash.geom.Point>;
-@:require(flash10) flash.display.BitmapData.setVector
-@:require(flash10) flash.display.BitmapData.getVector
-@:require(flash10) flash.display.BitmapData.histogram
-
-@:require(flash10_1) flash.display.Loader.uncaughtErrorEvents;
-@:require(flash10_1) flash.display.LoaderInfo.isURLInaccessible;
-@:require(flash10_1) flash.display.LoaderInfo.uncaughtErrorEvents;
-
-@:require(flash10_1) flash.display.ColorCorrection
-@:require(flash10_1) flash.display.ColorCorrectionSupport
-@:require(flash10_1) flash.display.FocusDirection
-@:require(flash10_1) flash.display.NativeMenu
-@:require(flash10_1) flash.display.NativeMenuItem
-
-@:require(flash10) flash.display.DisplayObject.blendShader
-@:require(flash10) flash.display.DisplayObject.rotationX
-@:require(flash10) flash.display.DisplayObject.rotationY
-@:require(flash10) flash.display.DisplayObject.rotationZ
-@:require(flash10) flash.display.DisplayObject.scaleZ
-@:require(flash10) flash.display.DisplayObject.z
-@:require(flash10) flash.display.DisplayObject.globalToLocal3D
-@:require(flash10) flash.display.DisplayObject.local3DToGlobal
--flash.display.DisplayObject.new
-flash.display.DisplayObject.blendMode : BlendMode;
-flash.display.DisplayObject.opaqueBackground : Null<UInt>;
-flash.display.DisplayObjectContainer.getObjectsUnderPoint : Array<DisplayObject>;
-
-@:require(flash10_1) flash.display.Sprite.startTouchDrag;
-@:require(flash10_1) flash.display.Sprite.stopTouchDrag;
-
-@:require(flash10_1) flash.display.Stage.wmodeGPU;
-
-enum flash.display.GradientType;
-enum flash.display.CapsStyle;
-enum flash.display.JointStyle;
-enum flash.display.GraphicsPathWinding;
-enum flash.display.TriangleCulling;
-enum flash.display.InterpolationMethod;
-enum flash.display.LineScaleMode;
-enum flash.display.ShaderParameterType;
-enum flash.display.ShaderPrecision;
-enum flash.display.SpreadMethod;
-enum flash.display.StageAlign;
-enum flash.display.StageDisplayState;
-enum flash.display.StageQuality;
-enum flash.display.StageScaleMode;
--flash.display.SWFVersion.new
-
-flash.display.Graphics.$type : GradientType;
-flash.display.Graphics.$colors : Array<UInt>;
-flash.display.Graphics.$spreadMethod : SpreadMethod;
-flash.display.Graphics.$interpolationMethod : InterpolationMethod;
-flash.display.Graphics.$scaleMode : LineScaleMode;
-flash.display.Graphics.$caps : CapsStyle;
-flash.display.Graphics.$joints : JointStyle;
-flash.display.Graphics.$winding : GraphicsPathWinding;
-flash.display.Graphics.$culling : TriangleCulling;
-@:require(flash10) flash.display.Graphics.beginShaderFill
-@:require(flash10) flash.display.Graphics.copyFrom
-@:require(flash10) flash.display.Graphics.drawGraphicsData
-@:require(flash10) flash.display.Graphics.drawPath
-@:require(flash10) flash.display.Graphics.drawTriangles
-@:require(flash10) flash.display.Graphics.lineBitmapStyle
-@:require(flash10) flash.display.Graphics.lineShaderStyle
-
-
-flash.display.GraphicsGradientFill.type : GradientType;
-flash.display.GraphicsGradientFill.colors : Array<UInt>;
-flash.display.GraphicsGradientFill.spreadMethod : SpreadMethod;
-flash.display.GraphicsGradientFill.interpolationMethod : InterpolationMethod;
-flash.display.GraphicsGradientFill.alphas : Array<Float>;
-flash.display.GraphicsGradientFill.ratios : Array<Float>;
-flash.display.GraphicsGradientFill.$type : GradientType;
-flash.display.GraphicsGradientFill.$colors : Array<UInt>;
-flash.display.GraphicsGradientFill.$spreadMethod : SpreadMethod;
-flash.display.GraphicsGradientFill.$interpolationMethod : InterpolationMethod;
-flash.display.GraphicsGradientFill.$alphas : Array<Float>;
-flash.display.GraphicsGradientFill.$ratios : Array<Float>;
-flash.display.GraphicsGradientFill.$matrix : flash.geom.Matrix;
-
-flash.display.GraphicsPath.winding : GraphicsPathWinding;
-flash.display.GraphicsPath.$winding : GraphicsPathWinding;
-
-flash.display.GraphicsStroke.scaleMode : LineScaleMode;
-flash.display.GraphicsStroke.caps : CapsStyle;
-flash.display.GraphicsStroke.joints : JointStyle;
-flash.display.GraphicsStroke.$scaleMode : LineScaleMode;
-flash.display.GraphicsStroke.$caps : CapsStyle;
-flash.display.GraphicsStroke.$joints : JointStyle;
-
-flash.display.GraphicsTrianglePath.culling : TriangleCulling;
-flash.display.GraphicsTrianglePath.$culling : TriangleCulling;
-
-
-@:require(flash10) flash.display.Loader.unloadAndStop
-
-enum flash.display.ActionScriptVersion;
-enum flash.display.ColorCorrection;
-enum flash.display.ColorCorrectionSupport;
-
--flash.display.LoaderInfo.new
-flash.display.LoaderInfo.parameters : Dynamic<String>;
-flash.display.LoaderInfo.actionScriptVersion : ActionScriptVersion;
-
--flash.display.MorphShape.new
-
-@:require(flash10) flash.display.MovieClip.currentFrameLabel
-flash.display.MovieClip.currentLabels : Array<FrameLabel>;
-flash.display.MovieClip.scenes : Array<Scene>;
-
-flash.display.Scene.labels : Array<FrameLabel>;
-flash.display.Scene.$labels : Array<FrameLabel>;
-
-@:require(flash10) flash.display.Shader;
-flash.display.Shader.precisionHint : ShaderPrecision;
-
--flash.display.ShaderParameter.new
-flash.display.ShaderParameter.type : ShaderParameterType;
-
--flash.display.Stage.new
-flash.display.Stage.align : StageAlign;
-flash.display.Stage.quality : StageQuality;
-flash.display.Stage.scaleMode : StageScaleMode;
-flash.display.Stage.colorCorrection : ColorCorrection;
-flash.display.Stage.colorCorrectionSupport : ColorCorrectionSupport;
-flash.display.Stage.displayState : StageDisplayState;
-flash.display.Stage.displayState : StageDisplayState;
-
-@:require(flash10) flash.display.Stage.colorCorrection
-@:require(flash10) flash.display.Stage.colorCorrectionSupport
-
-@:require(flash10_1) flash.errors.DRMManagerError
-@:require(flash10_1) flash.events.AccelerometerEvent
-@:require(flash10_1) flash.events.DRMAuthenticateEvent
-@:require(flash10_1) flash.events.DRMAuthenticationCompleteEvent
-@:require(flash10_1) flash.events.DRMAuthenticationErrorEvent
-@:require(flash10_1) flash.events.DRMCustomProperties
-@:require(flash10_1) flash.events.DRMErrorEvent
-@:require(flash10_1) flash.events.DRMStatusEvent
-@:require(flash10_1) flash.events.GeolocationEvent
-@:require(flash10_1) flash.events.GestureEvent
-@:require(flash10_1) flash.events.GesturePhase
-@:require(flash10_1) flash.events.PressAndTapGestureEvent
-@:require(flash10_1) flash.events.TouchEvent
-@:require(flash10_1) flash.events.TransformGestureEvent
-@:require(flash10_1) flash.events.UncaughtErrorEvent;
-@:require(flash10_1) flash.events.UncaughtErrorEvents;
-
-@:require(flash10) static flash.events.Event.CLEAR;
-@:require(flash10) static flash.events.Event.COPY;
-@:require(flash10) static flash.events.Event.CUT;
-@:require(flash10) static flash.events.Event.EXIT_FRAME;
-@:require(flash10) static flash.events.Event.FRAME_CONSTRUCTED;
-@:require(flash10) static flash.events.Event.PASTE;
-@:require(flash10) static flash.events.Event.SELECT_ALL;
-
-@:require(flash10) flash.events.ContextMenuEvent.isMouseTargetInaccessible
-@:require(flash10) flash.events.FocusEvent.isRelatedObjectInaccessible
-@:require(flash10) flash.events.MouseEvent.isRelatedObjectInaccessible
-
-flash.events.IEventDispatcher.$listener : Dynamic -> Void;
-flash.events.EventDispatcher.$listener : Dynamic -> Void;
-
-enum flash.events.EventPhase;
-enum flash.events.GesturePhase;
-
-flash.events.Event.eventPhase : EventPhase;
-
-flash.events.KeyboardEvent.keyLocation : flash.ui.KeyLocation;
-flash.events.KeyboardEvent.$keyLocationValue : flash.ui.KeyLocation;
-flash.events.KeyboardEvent.$keyLocation : flash.ui.KeyLocation;
-
-@:require(flash10_1) flash.events.ErrorEvent.errorID;
-
-@:require(flash10_1) flash.events.HTTPStatusEvent.responseHeaders;
-@:require(flash10_1) flash.events.HTTPStatusEvent.responseURL;
-@:require(flash10_1) static flash.events.HTTPStatusEvent.HTTP_RESPONSE_STATUS;
-
-@:require(flash10_1) flash.events.IMEEvent.imeClient;
-@:require(flash10_1) static flash.events.IMEEvent.IME_START_COMPOSITION;
-
--flash.events.WeakFunctionClosure.new
-
--flash.external.ExternalInterface.new
-
-enum flash.filters.BitmapFilterType;
-enum flash.filters.DisplacementMapFilterMode;
-
-flash.filters.BevelFilter.type : BitmapFilterType;
-flash.filters.BevelFilter.$type : BitmapFilterType;
-
-flash.filters.DisplacementMapFilter.mode : DisplacementMapFilterMode;
-flash.filters.DisplacementMapFilter.$mode : DisplacementMapFilterMode;
-
-flash.filters.GradientGlowFilter.type : BitmapFilterType;
-flash.filters.GradientGlowFilter.$type : BitmapFilterType;
-
-enum flash.geom.Orientation3D;
-
-flash.geom.Matrix3D.$orientationStyle : Orientation3D;
-
-@:require(flash10) flash.geom.Matrix3D;
-@:require(flash10) flash.geom.Utils3D;
-@:require(flash10) flash.geom.Vector3D;
-@:require(flash10) flash.geom.PerspectiveProjection;
-@:require(flash10) flash.geom.Transform.matrix3D;
-@:require(flash10) flash.geom.Transform.perspectiveProjection;
-@:require(flash10) flash.geom.Transform.getRelativeMatrix3D;
-
--flash.geom.Utils3D.new
-
-@:require(flash10_1) static flash.media.Camera.isSupported;
-@:require(flash10_1) static flash.media.Camera._scanHardware;
-
-enum flash.media.SoundCodec;
-
-flash.media.Microphone.codec : SoundCodec;
-
-@:require(flash10) flash.media.Microphone.codec;
-@:require(flash10) flash.media.Microphone.encodeQuality;
-@:require(flash10) flash.media.Microphone.framesPerPacket;
-
-@:require(flash10_1) flash.media.Microphone.enableVAD;
-@:require(flash10_1) flash.media.Microphone.noiseSuppressionLevel;
-@:require(flash10_1) static flash.media.Microphone.isSupported;
-
-@:require(flash10) flash.media.Sound.extract;
-
-@:require(flash10_1) flash.media.Sound.isURLInaccessible;
-
-@:require(flash10) flash.net.FileReference.data;
-@:require(flash10) flash.net.FileReference.load;
-@:require(flash10) flash.net.FileReference.save;
-
--flash.media.SoundMixer.new
-
-@:require(flash10_1) flash.net.LocalConnection.isPerUser;
-@:require(flash10_1) static flash.net.LocalConnection.isSupported;
-
-flash.net.FileReference.$typeFilter : Array<FileFilter>;
-flash.net.FileReferenceList.fileList : Array<FileReference>;
-flash.net.FileReferenceList.$typeFilter : Array<FileFilter>;
-
-@:require(flash10_1) flash.net.GroupSpecifier;
-@:require(flash10_1) flash.net.NetGroup;
-@:require(flash10_1) flash.net.NetGroupInfo;
-@:require(flash10_1) flash.net.NetStreamMulticastInfo;
-
-@:require(flash10) flash.net.NetConnection.farID;
-@:require(flash10) flash.net.NetConnection.farNonce;
-@:require(flash10) flash.net.NetConnection.maxPeerConnections;
-@:require(flash10) flash.net.NetConnection.nearID;
-@:require(flash10) flash.net.NetConnection.nearNonce;
-@:require(flash10) flash.net.NetConnection.protocol;
-@:require(flash10) flash.net.NetConnection.unconnectedPeerStreams;
-
-@:require(flash10) flash.net.NetStream.farID;
-@:require(flash10) flash.net.NetStream.farNonce;
-@:require(flash10) flash.net.NetStream.info;
-@:require(flash10) flash.net.NetStream.maxPauseBufferTime;
-@:require(flash10) flash.net.NetStream.nearNonce;
-@:require(flash10) flash.net.NetStream.peerStreams;
-@:require(flash10) flash.net.NetStream.onPeerConnect;
-@:require(flash10) flash.net.NetStream.play2;
-@:require(flash10) static flash.net.NetStream.CONNECT_TO_FMS;
-@:require(flash10) static flash.net.NetStream.DIRECT_CONNECTIONS;
-
-@:require(flash10_1) flash.net.NetStream.audioReliable;
-@:require(flash10_1) flash.net.NetStream.audioSampleAccess;
-@:require(flash10_1) flash.net.NetStream.backBufferLength;
-@:require(flash10_1) flash.net.NetStream.backBufferTime;
-@:require(flash10_1) flash.net.NetStream.bufferTimeMax;
-@:require(flash10_1) flash.net.NetStream.dataReliable;
-@:require(flash10_1) flash.net.NetStream.inBufferSeek;
-@:require(flash10_1) flash.net.NetStream.multicastAvailabilitySendToAll;
-@:require(flash10_1) flash.net.NetStream.multicastAvailabilityUpdatePeriod;
-@:require(flash10_1) flash.net.NetStream.multicastFetchPeriod;
-@:require(flash10_1) flash.net.NetStream.multicastInfo;
-@:require(flash10_1) flash.net.NetStream.multicastPushNeighborLimit;
-@:require(flash10_1) flash.net.NetStream.multicastRelayMarginDuration;
-@:require(flash10_1) flash.net.NetStream.multicastWindowDuration;
-@:require(flash10_1) flash.net.NetStream.videoReliable;
-@:require(flash10_1) flash.net.NetStream.videoSampleAccess;
-@:require(flash10_1) flash.net.NetStream.appendBytes;
-@:require(flash10_1) flash.net.NetStream.appendBytesAction;
-@:require(flash10_1) flash.net.NetStream.attach;
-@:require(flash10_1) flash.net.NetStream.step;
-
-@:require(flash10_1) flash.net.NetStreamInfo.videoLossRate;
-
-@:require(flash10_1) flash.net.NetStreamPlayOptions.offset;
-
-@:require(flash10_1) static flash.net.URLRequestMethod.DELETE;
-@:require(flash10_1) static flash.net.URLRequestMethod.HEAD;
-@:require(flash10_1) static flash.net.URLRequestMethod.OPTIONS;
-@:require(flash10_1) static flash.net.URLRequestMethod.PUT;
-
-@:require(flash10) flash.net.Socket.timeout;
-@:require(flash10) flash.net.XMLSocket.timeout;
-
--flash.net.ObjectEncoding.new
--flash.net.URLRequestMethod.new
-
-enum flash.net.URLLoaderDataFormat;
-
-flash.net.Socket.endian : flash.utils.Endian;
-flash.net.URLLoader.dataFormat : URLLoaderDataFormat;
-flash.net.URLRequest.requestHeaders : Array<URLRequestHeader>;
-flash.net.URLStream.endian : flash.utils.Endian;
-
-enum flash.printing.PrintJobOrientation;
-
-flash.printing.PrintJob.orientation : PrintJobOrientation;
-@:require(flash10_1) static flash.printing.PrintJob.isSupported;
-
--flash.sampler.DeleteObjectSample.new
--flash.sampler.NewObjectSample.new
--flash.sampler.Sample.new
-flash.sampler.Sample.stack : Array<StackFrame>;
--flash.sampler.StackFrame.new
-@:require(flash10_1) flash.sampler.NewObjectSample.size;
-@:require(flash10_1) flash.sampler.StackFrame.scriptID;
-
--flash.system.Capabilities.new
--flash.system.IME.new
--flash.system.FSCommand.new
-
-enum flash.system.IMEConversionMode;
-
-static flash.system.IME.conversionMode : IMEConversionMode
-
-@:require(flash10) flash.system.ApplicationDomain.domainMemory;
-@:require(flash10) static flash.system.ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH;
-
-@:require(flash10) static flash.system.Capabilities.isEmbeddedInAcrobat;
-@:require(flash10) static flash.system.Capabilities.maxLevelIDC;
-
-@:require(flash10_1) static flash.system.Capabilities.cpuArchitecture;
-@:require(flash10_1) static flash.system.Capabilities.supports32BitProcesses;
-@:require(flash10_1) static flash.system.Capabilities.supports64BitProcesses;
-@:require(flash10_1) static flash.system.Capabilities.touchscreenType;
-static flash.system.Capabilities.touchscreenType : TouchscreenType;
-
-enum flash.system.TouchscreenType;
-
-
-@:require(flash10_1) static flash.system.IME.isSupported;
-@:require(flash10_1) static flash.system.IME.compositionAbandoned;
-@:require(flash10_1) static flash.system.IME.compositionSelectionChanged;
-
-
-@:require(flash10) flash.system.JPEGLoaderContext;
-
-
-@:require(flash10_1) flash.system.LoaderContext.allowCodeImport;
-@:require(flash10_1) flash.system.LoaderContext.allowLoadBytesCodeExecution;
-
-@:require(flash10_1) static flash.system.Security.APPLICATION;
-@:require(flash10_1) static flash.system.Security.duplicateSandboxBridgeInputArguments;
-@:require(flash10_1) static flash.system.Security.duplicateSandboxBridgeOutputArgument;
-
-@:require(flash10_1) static flash.system.System.currentTime;
-@:require(flash10_1) static flash.system.System.freeMemory;
-@:require(flash10_1) static flash.system.System.preciseStartupTime;
-@:require(flash10_1) static flash.system.System.privateMemory;
-@:require(flash10_1) static flash.system.System.totalMemoryNumber;
-@:require(flash10_1) static flash.system.System.disposeXML;
-@:require(flash10_1) static flash.system.System.nativeConstructionOnly;
-
-enum flash.system.SecurityPanel;
-
--flash.system.Security.new
-flash.system.Security.$panel : SecurityPanel
--flash.system.SecurityDomain.new
--flash.system.System.new
-flash.system.SystemUpdater.$typer : SystemAdapterType;
-
-enum flash.text.AntiAliasType;
-enum flash.text.GridFitType;
-enum flash.text.FontStyle;
-enum flash.text.FontType;
-enum flash.text.TextDisplayMode;
-enum flash.text.TextFieldType;
-enum flash.text.TextFieldAutoSize;
-enum flash.text.TextFormatAlign;
-enum flash.text.TextFormatDisplay;
-enum flash.text.TextColorType;
-
-flash.text.Font.fontStyle : FontStyle;
-flash.text.Font.fontType : FontType;
-static flash.text.Font.enumerateFonts : Array<Font>;
-flash.text.TextField.autoSize : TextFieldAutoSize;
-flash.text.TextField.antiAliasType : AntiAliasType;
-flash.text.TextField.gridFitType : GridFitType;
-flash.text.TextField.type : TextFieldType;
-
-flash.text.TextFormat.align : TextFormatAlign;
-flash.text.TextFormat.blockIndent : Null<Float>
-flash.text.TextFormat.bold : Null<Bool>;
-flash.text.TextFormat.bullet : Null<Bool>;
-flash.text.TextFormat.color : Null<UInt>;
-flash.text.TextFormat.display : TextFormatDisplay;
-flash.text.TextFormat.indent : Null<Float>;
-flash.text.TextFormat.italic : Null<Bool>;
-flash.text.TextFormat.kerning : Null<Bool>;
-flash.text.TextFormat.leading : Null<Float>;
-flash.text.TextFormat.leftMargin : Null<Float>;
-flash.text.TextFormat.letterSpacing : Null<Float>;
-flash.text.TextFormat.rightMargin : Null<Float>;
-flash.text.TextFormat.size : Null<Float>;
-flash.text.TextFormat.tabStops : Array<UInt>;
-flash.text.TextFormat.underline : Null<Bool>;
-flash.text.TextFormat.$size : Null<Float>;
-flash.text.TextFormat.$color : Null<UInt>;
-flash.text.TextFormat.$bold : Null<Bool>;
-flash.text.TextFormat.$italic : Null<Bool>;
-flash.text.TextFormat.$underline : Null<Bool>;
-flash.text.TextFormat.$align : TextFormatAlign;
-flash.text.TextFormat.$leftMargin : Null<Float>;
-flash.text.TextFormat.$rightMargin : Null<Float>;
-flash.text.TextFormat.$indent : Null<Float>;
-flash.text.TextFormat.$leading : Null<Float>;
-
-@:require(flash10) static flash.text.TextField.isFontCompatible;
-
--flash.text.TextRenderer.new
-static flash.text.TextRenderer.antiAliasType : AntiAliasType;
-static flash.text.TextRenderer.displayMode : TextDisplayMode;
-flash.text.TextRenderer.$fontStyle : FontStyle;
-flash.text.TextRenderer.$colorType : TextColorType;
-
-@:require(flash10_1) static flash.text.engine.FontDescription.isDeviceFontCompatible;
-@:require(flash10_1) flash.text.engine.SpaceJustifier.maximumSpacing;
-@:require(flash10_1) flash.text.engine.SpaceJustifier.minimumSpacing;
-@:require(flash10_1) flash.text.engine.SpaceJustifier.optimumSpacing;
-@:require(flash10_1) flash.text.engine.TextBlock.recreateTextLine;
-@:require(flash10_1) flash.text.engine.TextBlock.releaseLineCreationData;
-@:require(flash10_1) flash.text.engine.TextLine.hasTabs;
-
-flash.text.engine.ContentElement.textRotation : TextRotation;
-flash.text.engine.ContentElement.$textRotation : TextRotation;
-
-flash.text.engine.EastAsianJustifier.justificationStyle : JustificationStyle;
-flash.text.engine.EastAsianJustifier.$justificationStyle : JustificationStyle;
-flash.text.engine.EastAsianJustifier.$lineJustification : LineJustification;
-
-enum flash.text.engine.BreakOpportunity;
-enum flash.text.engine.CFFHinting;
-enum flash.text.engine.DigitCase;
-enum flash.text.engine.DigitWidth;
-enum flash.text.engine.FontLookup;
-enum flash.text.engine.FontPosture;
-enum flash.text.engine.FontWeight;
-enum flash.text.engine.JustificationStyle;
-enum flash.text.engine.Kerning;
-enum flash.text.engine.LigatureLevel;
-enum flash.text.engine.LineJustification;
-enum flash.text.engine.RenderingMode;
-enum flash.text.engine.TabAlignment;
-enum flash.text.engine.TextBaseline;
-enum flash.text.engine.TextLineCreationResult;
-enum flash.text.engine.TextLineValidity;
-enum flash.text.engine.TextRotation;
-enum flash.text.engine.TypographicCase;
-
-
-flash.text.engine.ElementFormat.alignmentBaseline : TextBaseline;
-flash.text.engine.ElementFormat.breakOpportunity : BreakOpportunity;
-flash.text.engine.ElementFormat.digitCase : DigitCase;
-flash.text.engine.ElementFormat.digitWidth : DigitWidth;
-flash.text.engine.ElementFormat.dominantBaseline : TextBaseline;
-flash.text.engine.ElementFormat.kerning : Kerning;
-flash.text.engine.ElementFormat.ligatureLevel : LigatureLevel;
-flash.text.engine.ElementFormat.textRotation : TextRotation;
-flash.text.engine.ElementFormat.typographicCase : TypographicCase;
-flash.text.engine.ElementFormat.$alignmentBaseline : TextBaseline;
-flash.text.engine.ElementFormat.$breakOpportunity : BreakOpportunity;
-flash.text.engine.ElementFormat.$digitCase : DigitCase;
-flash.text.engine.ElementFormat.$digitWidth : DigitWidth;
-flash.text.engine.ElementFormat.$dominantBaseline : TextBaseline;
-flash.text.engine.ElementFormat.$kerning : Kerning;
-flash.text.engine.ElementFormat.$ligatureLevel : LigatureLevel;
-flash.text.engine.ElementFormat.$textRotation : TextRotation;
-flash.text.engine.ElementFormat.$typographicCase : TypographicCase;
-
-flash.text.engine.FontDescription.cffHinting : CFFHinting;
-flash.text.engine.FontDescription.fontLookup : FontLookup;
-flash.text.engine.FontDescription.fontPosture : FontPosture;
-flash.text.engine.FontDescription.fontWeight : FontWeight;
-flash.text.engine.FontDescription.renderingMode : RenderingMode;
-flash.text.engine.FontDescription.$cffHinting : CFFHinting;
-flash.text.engine.FontDescription.$fontLookup : FontLookup;
-flash.text.engine.FontDescription.$fontPosture : FontPosture;
-flash.text.engine.FontDescription.$fontWeight : FontWeight;
-flash.text.engine.FontDescription.$renderingMode : RenderingMode;
-
-flash.text.engine.GraphicElement.$textRotation : TextRotation;
-flash.text.engine.GroupElement.$textRotation : TextRotation;
-flash.text.engine.SpaceJustifier.$lineJustification : LineJustification;
-flash.text.engine.TabStop.alignment : TabAlignment;
-flash.text.engine.TabStop.$alignment : TabAlignment;
-
-flash.text.engine.TextBlock.baselineZero : TextBaseline;
-flash.text.engine.TextBlock.lineRotation : TextRotation;
-flash.text.engine.TextBlock.textLineCreationResult : TextLineCreationResult;
-flash.text.engine.TextBlock.$baselineZero : TextBaseline;
-flash.text.engine.TextBlock.$lineRotation : TextRotation;
-flash.text.engine.TextBlock.$textLineCreationResult : TextLineCreationResult;
-
-flash.text.engine.TextElement.$textRotation : TextRotation;
-
-flash.text.engine.TextJustifier.lineJustification : LineJustification;
-flash.text.engine.TextJustifier.$lineJustification : LineJustification;
-
-flash.text.engine.TextLine.baseline : TextBaseline;
-
--flash.trace.Trace.new
-
--static flash.xml.XMLList.length
--static flash.xml.XML.length
--flash.text.engine.TextElement.text
-
--flash.ui.Keyboard.new
--flash.ui.Mouse.new
-
-enum flash.ui.MultitouchInputMode;
-
--flash.ui.Multitouch.new
-flash.ui.Multitouch.inputMode : MultitouchInputMode;
-
-@:require(flash10) flash.ui.ContextMenu.clipboardItems;
-@:require(flash10) flash.ui.ContextMenu.clipboardMenu;
-@:require(flash10) flash.ui.ContextMenu.link;
-
-@:require(flash10_1) static flash.ui.ContextMenu.isSupported;
-
-@:require(flash10) static flash.ui.Mouse.cursor;
-static flash.ui.Mouse.cursor : Dynamic;
-
-@:require(flash10_1) static flash.ui.Keyboard.A;
-@:require(flash10_1) static flash.ui.Keyboard.B;
-@:require(flash10_1) static flash.ui.Keyboard.C;
-@:require(flash10_1) static flash.ui.Keyboard.D;
-@:require(flash10_1) static flash.ui.Keyboard.E;
-@:require(flash10_1) static flash.ui.Keyboard.F;
-@:require(flash10_1) static flash.ui.Keyboard.G;
-@:require(flash10_1) static flash.ui.Keyboard.H;
-@:require(flash10_1) static flash.ui.Keyboard.I;
-@:require(flash10_1) static flash.ui.Keyboard.J;
-@:require(flash10_1) static flash.ui.Keyboard.K;
-@:require(flash10_1) static flash.ui.Keyboard.L;
-@:require(flash10_1) static flash.ui.Keyboard.M;
-@:require(flash10_1) static flash.ui.Keyboard.N;
-@:require(flash10_1) static flash.ui.Keyboard.O;
-@:require(flash10_1) static flash.ui.Keyboard.P;
-@:require(flash10_1) static flash.ui.Keyboard.Q;
-@:require(flash10_1) static flash.ui.Keyboard.R;
-@:require(flash10_1) static flash.ui.Keyboard.S;
-@:require(flash10_1) static flash.ui.Keyboard.T;
-@:require(flash10_1) static flash.ui.Keyboard.U;
-@:require(flash10_1) static flash.ui.Keyboard.V;
-@:require(flash10_1) static flash.ui.Keyboard.W;
-@:require(flash10_1) static flash.ui.Keyboard.X;
-@:require(flash10_1) static flash.ui.Keyboard.Y;
-@:require(flash10_1) static flash.ui.Keyboard.Z;
-@:require(flash10_1) static flash.ui.Keyboard.ALTERNATE;
-@:require(flash10_1) static flash.ui.Keyboard.BACKQUOTE;
-@:require(flash10_1) static flash.ui.Keyboard.BACKSLASH;
-@:require(flash10_1) static flash.ui.Keyboard.COMMA;
-@:require(flash10_1) static flash.ui.Keyboard.COMMAND;
-@:require(flash10_1) static flash.ui.Keyboard.CharCodeStrings;
-@:require(flash10_1) static flash.ui.Keyboard.EQUAL;
-@:require(flash10_1) static flash.ui.Keyboard.LEFTBRACKET;
-@:require(flash10_1) static flash.ui.Keyboard.MINUS;
-@:require(flash10_1) static flash.ui.Keyboard.NUMBER_0;
-@:require(flash10_1) static flash.ui.Keyboard.NUMBER_1;
-@:require(flash10_1) static flash.ui.Keyboard.NUMBER_2;
-@:require(flash10_1) static flash.ui.Keyboard.NUMBER_3;
-@:require(flash10_1) static flash.ui.Keyboard.NUMBER_4;
-@:require(flash10_1) static flash.ui.Keyboard.NUMBER_5;
-@:require(flash10_1) static flash.ui.Keyboard.NUMBER_6;
-@:require(flash10_1) static flash.ui.Keyboard.NUMBER_7;
-@:require(flash10_1) static flash.ui.Keyboard.NUMBER_8;
-@:require(flash10_1) static flash.ui.Keyboard.NUMBER_9;
-@:require(flash10_1) static flash.ui.Keyboard.NUMPAD;
-@:require(flash10_1) static flash.ui.Keyboard.PERIOD;
-@:require(flash10_1) static flash.ui.Keyboard.QUOTE;
-@:require(flash10_1) static flash.ui.Keyboard.RIGHTBRACKET;
-@:require(flash10_1) static flash.ui.Keyboard.SEMICOLON;
-@:require(flash10_1) static flash.ui.Keyboard.SLASH;
-@:require(flash10_1) static flash.ui.Keyboard.hasVirtualKeyboard;
-@:require(flash10_1) static flash.ui.Keyboard.physicalKeyboardType;
-
-enum flash.ui.KeyboardType;
-enum flash.ui.KeyLocation;
-
-static flash.ui.Keyboard.physicalKeyboardType : KeyboardType;
-
-@:require(flash10_1) flash.ui.Multitouch;
-static flash.ui.Multitouch.inputMode : MultitouchInputMode;
-@:require(flash10_1) flash.ui.MultitouchInputMode;
-
-@:require(flash10_1) static flash.ui.Keyboard.STRING_BEGIN;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_BREAK;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_CLEARDISPLAY;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_CLEARLINE;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_DELETE;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_DELETECHAR;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_DELETELINE;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_DOWNARROW;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_END;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_EXECUTE;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_F1;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_F10;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_F11;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_F12;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_F13;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_F14;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_F15;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_F16;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_F17;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_F18;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_F19;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_F2;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_F20;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_F21;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_F22;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_F23;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_F24;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_F25;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_F26;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_F27;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_F28;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_F29;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_F3;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_F30;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_F31;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_F32;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_F33;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_F34;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_F35;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_F4;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_F5;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_F6;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_F7;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_F8;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_F9;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_FIND;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_HELP;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_HOME;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_INSERT;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_INSERTCHAR;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_INSERTLINE;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_LEFTARROW;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_MENU;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_MODESWITCH;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_NEXT;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_PAGEDOWN;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_PAGEUP;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_PAUSE;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_PREV;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_PRINT;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_PRINTSCREEN;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_REDO;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_RESET;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_RIGHTARROW;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_SCROLLLOCK;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_SELECT;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_STOP;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_SYSREQ;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_SYSTEM;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_UNDO;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_UPARROW;
-@:require(flash10_1) static flash.ui.Keyboard.STRING_USER;
-
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_BEGIN;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_BREAK;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_CLEARDISPLAY;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_CLEARLINE;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_DELETE;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_DELETECHAR;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_DELETELINE;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_DOWNARROW;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_END;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_EXECUTE;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F1;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F10;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F11;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F12;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F13;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F14;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F15;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F16;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F17;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F18;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F19;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F2;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F20;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F21;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F22;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F23;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F24;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F25;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F26;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F27;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F28;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F29;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F3;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F30;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F31;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F32;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F33;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F34;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F35;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F4;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F5;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F6;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F7;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F8;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F9;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_FIND;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_HELP;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_HOME;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_INSERT;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_INSERTCHAR;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_INSERTLINE;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_LEFTARROW;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_MENU;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_MODESWITCH;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_NEXT;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_PAGEDOWN;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_PAGEUP;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_PAUSE;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_PREV;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_PRINT;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_PRINTSCREEN;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_REDO;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_RESET;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_RIGHTARROW;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_SCROLLLOCK;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_SELECT;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_STOP;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_SYSREQ;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_SYSTEM;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_UNDO;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_UPARROW;
-@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_USER;
-
-@:require(flash10_1) static flash.ui.Mouse.supportsCursor;
-
-enum flash.utils.Endian;
-
-@:native("RegExp") flash.utils.RegExp;
--static flash.utils.RegExp.length;
-
-flash.utils.ObjectInput.endian : Endian;
-flash.utils.ObjectOutput.endian : Endian;
-flash.utils.ByteArray.endian : Endian;
-flash.utils.IDataInput.endian : Endian;
-flash.utils.IDataOutput.endian : Endian;
-
-@:require(flash10) flash.utils.ByteArray.clear;
-@:require(flash10) flash.utils.ByteArray.deflate;
-@:require(flash10) flash.utils.ByteArray.inflate;
-
-@:require(flash10) flash.utils.SetIntervalTimer.clearArrayEntry;
-
--flash.utils.Namespace.toString
--flash.utils.Namespace.valueOf
--static flash.utils.Namespace.length
-
--flash.utils.QName.toString
--flash.utils.QName.valueOf
--static flash.utils.QName.length
-
-enum flash.xml.XMLNodeType;
-
-flash.xml.XMLNode.nodeType : XMLNodeType;
-flash.xml.XMLNode.$type : XMLNodeType;
-
-flash.xml.XML.namespace : flash.utils.Namespace;
-flash.xml.XML.parent : XML;
-flash.xml.XMLList.namespace : flash.utils.Namespace;
-flash.xml.XMLList.parent : XML;
-flash.xml.XMLTag.type : XMLNodeType;
-
-
-enum flash.system.SystemUpdaterType;
-
-@:require(flash10_1) flash.system.SystemUpdater;
-flash.system.SystemUpdater.$type : SystemUpdaterType;
-
-@:require(flash10_1) flash.sensors.Accelerometer;
-@:require(flash10_1) flash.sensors.Geolocation;
-
-@:require(flash10_1) flash.globalization.Collator;
-@:require(flash10_1) flash.globalization.CurrencyFormatter;
-@:require(flash10_1) flash.globalization.DateTimeFormatter;
-@:require(flash10_1) flash.globalization.LocaleID;
-@:require(flash10_1) flash.globalization.StringTools;
-@:require(flash10_1) flash.globalization.NumberFormatter;
-@:require(flash10_1) flash.globalization.NumberParseResult;
-
-enum flash.globalization.CollatorMode;
-enum flash.globalization.DateTimeNameContext;
-enum flash.globalization.DateTimeNameStyle;
-enum flash.globalization.DateTimeStyle;
-enum flash.globalization.LastOperationStatus;
-enum flash.globalization.NationalDigitsType;
-
-flash.globalization.Collator.lastOperationStatus : LastOperationStatus;
-flash.globalization.Collator.$initialMode : CollatorMode;
-flash.globalization.CurrencyFormatter.lastOperationStatus : LastOperationStatus;
-
-flash.globalization.DateTimeFormatter.lastOperationStatus : LastOperationStatus;
-flash.globalization.DateTimeFormatter.$dateStyle : DateTimeStyle;
-flash.globalization.DateTimeFormatter.$nameStyle : DateTimeNameStyle;
-flash.globalization.DateTimeFormatter.$timeStyle : DateTimeStyle;
-flash.globalization.DateTimeFormatter.$context : DateTimeNameContext;
-flash.globalization.DateTimeFormatter.getDateStyle : DateTimeStyle;
-flash.globalization.DateTimeFormatter.getTimeStyle : DateTimeStyle;
-flash.globalization.DateTimeFormatter.getDateTimePattern : DateTimeStyle;
-flash.globalization.LocaleID.lastOperationStatus : LastOperationStatus;
-flash.globalization.NumberFormatter.lastOperationStatus : LastOperationStatus;
-flash.globalization.NumberFormatter.digitsType : NationalDigitsType;
-flash.globalization.StringTools.lastOperationStatus : LastOperationStatus;
-
-// FP 10.2
-
-@:require(flash10_2) flash.ui.MouseCursorData;
-@:require(flash10_2) flash.events.StageVideoEvent;
-@:require(flash10_2) flash.events.VideoEvent;
-@:require(flash10_2) flash.media.MicrophoneEnhancedMode;
-@:require(flash10_2) flash.media.MicrophoneEnhancedOptions;
-@:require(flash10_2) flash.media.StageVideo;
-
-@:require(flash10_2) flash.display.Stage.color;
-@:require(flash10_2) flash.display.Stage.stageVideos;
-
-@:require(flash10_2) flash.media.Microphone.enhancedOptions;
-@:require(flash10_2) static flash.media.Microphone.getEnhancedMicrophone;
-
-@:require(flash10_2) static flash.system.Capabilities.allowsFullScreen;
-
-@:require(flash10_2) static flash.ui.Keyboard.AUDIO;
-@:require(flash10_2) static flash.ui.Keyboard.BACK;
-@:require(flash10_2) static flash.ui.Keyboard.BLUE;
-@:require(flash10_2) static flash.ui.Keyboard.CHANNEL_DOWN;
-@:require(flash10_2) static flash.ui.Keyboard.CHANNEL_UP;
-@:require(flash10_2) static flash.ui.Keyboard.DVR;
-@:require(flash10_2) static flash.ui.Keyboard.EXIT;
-@:require(flash10_2) static flash.ui.Keyboard.FAST_FORWARD;
-@:require(flash10_2) static flash.ui.Keyboard.GREEN;
-@:require(flash10_2) static flash.ui.Keyboard.GUIDE;
-@:require(flash10_2) static flash.ui.Keyboard.HELP;
-@:require(flash10_2) static flash.ui.Keyboard.INFO;
-@:require(flash10_2) static flash.ui.Keyboard.INPUT;
-@:require(flash10_2) static flash.ui.Keyboard.LAST;
-@:require(flash10_2) static flash.ui.Keyboard.LIVE;
-@:require(flash10_2) static flash.ui.Keyboard.MASTER_SHELL;
-@:require(flash10_2) static flash.ui.Keyboard.MENU;
-@:require(flash10_2) static flash.ui.Keyboard.NEXT;
-@:require(flash10_2) static flash.ui.Keyboard.PAUSE;
-@:require(flash10_2) static flash.ui.Keyboard.PLAY;
-@:require(flash10_2) static flash.ui.Keyboard.PREVIOUS;
-@:require(flash10_2) static flash.ui.Keyboard.RECORD;
-@:require(flash10_2) static flash.ui.Keyboard.RED;
-@:require(flash10_2) static flash.ui.Keyboard.REWIND;
-@:require(flash10_2) static flash.ui.Keyboard.SEARCH;
-@:require(flash10_2) static flash.ui.Keyboard.SETUP;
-@:require(flash10_2) static flash.ui.Keyboard.SKIP_BACKWARD;
-@:require(flash10_2) static flash.ui.Keyboard.SKIP_FORWARD;
-@:require(flash10_2) static flash.ui.Keyboard.STOP;
-@:require(flash10_2) static flash.ui.Keyboard.SUBTITLE;
-@:require(flash10_2) static flash.ui.Keyboard.VOD;
-@:require(flash10_2) static flash.ui.Keyboard.YELLOW;
-
-@:require(flash10_2) static flash.ui.Mouse.registerCursor;
-
-enum flash.media.MicrophoneEnhancedMode;
-
-flash.media.MicrophoneEnhancedOptions.mode : MicrophoneEnhancedMode;
-
-enum flash.display.FocusDirection;
-
-
-// FLASH 11 FEATURES
-
--flash.automation.Configuration.new
-
-@:require(flash11) flash.display.DisplayObjectContainer.removeChildren;
-@:require(flash11) flash.display.Graphics.cubicCurveTo;
-@:require(flash11) flash.display.GraphicsPath.cubicCurveTo;
-
-@:require(flash11) flash.display.InteractiveObject.needsSoftKeyboard;
-@:require(flash11) flash.display.InteractiveObject.softKeyboardInputAreaOfInterest;
-@:require(flash11) flash.display.InteractiveObject.requestSoftKeyboard;
-
-@:require(flash11) flash.display.MovieClip.isPlaying;
-
-@:require(flash11) flash.display.Stage.allowsFullScreen;
-@:require(flash11) flash.display.Stage.displayContextInfo;
-@:require(flash11) flash.display.Stage.softKeyboardRect;
-@:require(flash11) flash.display.Stage.stage3Ds;
-@:require(flash11) flash.display.Stage3D;
-
--flash.display.Stage.constructor;
--flash.display.Stage.hasOwnProperty;
--flash.display.Stage.isPrototypeOf;
--flash.display.Stage.propertyIsEnumerable;
--flash.display.Stage.setPropertyIsEnumerable;
--flash.display.Stage.toLocaleString;
--flash.display.Stage.valueOf;
-
-enum flash.display3D.Context3DBlendFactor;
-enum flash.display3D.;
-
-@:require(flash11) static flash.events.Event.CONTEXT3D_CREATE;
-@:require(flash11) static flash.events.Event.TEXT_INTERACTION_MODE_CHANGE;
-
-@:require(flash11) static flash.events.StageVideoEvent.RENDER_STATUS_AVAILABLE;
-@:require(flash11) static flash.events.StageVideoEvent.STAGE_VIDEO_STATE;
-
-@:require(flash11) flash.geom.Matrix3D.copyColumnFrom;
-@:require(flash11) flash.geom.Matrix3D.copyColumnTo;
-@:require(flash11) flash.geom.Matrix3D.copyFrom;
-@:require(flash11) flash.geom.Matrix3D.copyRawDataFrom;
-@:require(flash11) flash.geom.Matrix3D.copyRawDataTo;
-@:require(flash11) flash.geom.Matrix3D.copyRowFrom;
-@:require(flash11) flash.geom.Matrix3D.copyRowTo;
-@:require(flash11) flash.geom.Matrix3D.copyToMatrix3D;
-
-@:require(flash11) flash.geom.Matrix.copyColumnFrom;
-@:require(flash11) flash.geom.Matrix.copyColumnTo;
-@:require(flash11) flash.geom.Matrix.copyFrom;
-@:require(flash11) flash.geom.Matrix.copyRowFrom;
-@:require(flash11) flash.geom.Matrix.copyRowTo;
-@:require(flash11) flash.geom.Matrix.setTo;
-
-@:require(flash11) flash.geom.Point.copyFrom;
-@:require(flash11) flash.geom.Point.setTo;
-
-@:require(flash11) flash.geom.Rectangle.copyFrom;
-@:require(flash11) flash.geom.Rectangle.setTo;
-
-@:require(flash11) flash.geom.Vector3D.copyFrom;
-@:require(flash11) flash.geom.Vector3D.setTo;
-
-
-
-@:require(flash11) flash.media.Sound.loadCompressedDataFromByteArray;
-@:require(flash11) flash.media.Sound.loadPCMFromByteArray;
-
-@:require(flash11) flash.net.Socket.bytesPending;
-
--flash.display3D.Context3DClearMask.new;
-enum flash.display3D.Context3DCompareMode;
-enum flash.display3D.Context3DProgramType;
-enum flash.display3D.Context3DRenderMode;
-enum flash.display3D.Context3DStencilAction;
-enum flash.display3D.Context3DTextureFormat;
-enum flash.display3D.Context3DTriangleFace;
-enum flash.display3D.Context3DVertexBufferFormat;
-
--flash.display.Stage3D.new;
--flash.display3D.Context3D.new;
--flash.display3D.IndexBuffer3D.new;
--flash.display3D.Program3D.new;
--flash.display3D.VertexBuffer3D.new;
--flash.display3D.textures.CubeTexture.new;
--flash.display3D.textures.TextureBase.new;
--flash.display3D.textures.Texture.new;
-
-flash.display3D.Context3D.$sourceFactor : Context3DBlendFactor;
-flash.display3D.Context3D.$destinationFactor : Context3DBlendFactor;
-flash.display3D.Context3D.$format : Context3DTextureFormat;
-flash.display3D.Context3D.$triangleFaceToCull : Context3DTriangleFace;
-flash.display3D.Context3D.$triangleFace : Context3DTriangleFace;
-flash.display3D.Context3D.$passCompareMode : Context3DCompareMode;
-flash.display3D.Context3D.$compareMode : Context3DCompareMode;
-flash.display3D.Context3D.$programType : Context3DProgramType;
-flash.display3D.Context3D.$actionOnBothPass : Context3DStencilAction;
-flash.display3D.Context3D.$actionOnDepthFail : Context3DStencilAction;
-flash.display3D.Context3D.$actionOnDepthPassStencilFail : Context3DStencilAction;
-flash.display3D.Context3D.$setVertexBufferAt__format : Context3DVertexBufferFormat;
-
-@:require(flash11) flash.net.NetStream.useHardwareDecoder;
-@:require(flash11) flash.net.NetStream.videoStreamSettings;
-
-@:require(flash11) flash.net.SecureSocket;
-@:require(flash11) flash.net.NetMonitor;
-
-@:require(flash11) static flash.system.Capabilities.hasMultiChannelAudio;
-
-@:require(flash11) flash.system.LoaderContext.imageDecodingPolicy;
-@:require(flash11) flash.system.LoaderContext.parameters;
-@:require(flash11) flash.system.LoaderContext.requestedContentParent;
-
-enum flash.system.ImageDecodingPolicy;
-
-flash.system.LoaderContext.imageDecodingPolicy : ImageDecodingPolicy;
-
-@:require(flash11) static flash.system.Security.pageDomain;
-
-@:require(flash11) static flash.system.System.processCPUUsage;
-@:require(flash11) static flash.system.System.pauseForGCIfCollectionImminent;
-
-@:require(flash11) static flash.ui.Mouse.supportsNativeCursor;
-@:require(flash11) static flash.ui.Mouse.unregisterCursor;
-
--flash.ui.MouseCursor.new;
-
-@:require(flash11) flash.utils.CompressionAlgorithm;
-enum flash.utils.CompressionAlgorithm;
-
-@:require(flash11) flash.xml.XML.toJSON;
-@:require(flash11) flash.xml.XMLList.toJSON;
-
-flash.utils.ByteArray.$algorithm : CompressionAlgorithm;
-
-@:require(flash11) flash.text.TextField.textInteractionMode;
-
-enum flash.text.TextInteractionMode;
-
-flash.text.TextField.textInteractionMode : TextInteractionMode;
-
-// 11.2
-
-enum flash.display.BitmapCompressColorSpace;
-
-@:require(flash11_2) flash.display.BitmapData.compress;
-@:require(flash11_2) flash.media.Camera.position;
-@:require(flash11_2) flash.net.NetStream.dispose;
-
-@:require(flash11_2) flash.display.StageWorker;
-@:require(flash11_2) flash.display.Worker;
-@:require(flash11_2) flash.events.GameInputEvent;
-@:require(flash11_2) flash.events.ThrottleEvent;
-
-flash.events.ThrottleEvent.$type : ThrottleType;
-
-enum flash.events.ThrottleType;
-
-@:require(flash11_2) flash.ui.GameInput;
-@:require(flash11_2) flash.ui.GameInputDevice;
--flash.ui.GameInput.new;
-
-@:require(flash11_2) flash.utils.Telemetry;
-
-enum flash.ui.GameInputFinger;
-enum flash.ui.GameInputHand;
-enum flash.ui.GameInputControlType;
-
-flash.ui.GameInputControl.finger : flash.ui.GameInputFinger;
-flash.ui.GameInputControl.hand : flash.ui.GameInputHand;
-flash.ui.GameInputControl.type : flash.ui.GameInputControlType;
-
-
-// 11.2
-
-@:require(flash11_2) flash.display3D.Context3D.setProgramConstantsFromByteArray
-@:require(flash11_2) flash.display.Stage.mouseLock;
-
-@:require(flash11_2) flash.events.MouseEvent.movementX;
-@:require(flash11_2) flash.events.MouseEvent.movementY;
-
-@:require(flash11_2) static flash.events.MouseEvent.CONTEXT_MENU;
-@:require(flash11_2) static flash.events.MouseEvent.MIDDLE_CLICK;
-@:require(flash11_2) static flash.events.MouseEvent.MIDDLE_MOUSE_DOWN;
-@:require(flash11_2) static flash.events.MouseEvent.MIDDLE_MOUSE_UP;
-@:require(flash11_2) static flash.events.MouseEvent.RIGHT_CLICK;
-@:require(flash11_2) static flash.events.MouseEvent.RIGHT_MOUSE_DOWN;
-@:require(flash11_2) static flash.events.MouseEvent.RIGHT_MOUSE_UP;
-
-
-// 11.3
-
-@:require(flash11_3) flash.display.BitmapData.drawWithQuality
-
-flash.display.BitmapData.$quality : StageQuality;
-
-enum flash.display.BitmapEncodingColorSpace;
-
-flash.display.JPEGXREncoderOptions.$colorSpace : BitmapEncodingColorSpace;
-flash.display.JPEGXREncoderOptions.colorSpace : BitmapEncodingColorSpace;
-
-@:require(flash11_3) flash.display.BitmapData.encode
-@:require(flash11_3) flash.display.Stage.allowsFullScreenInteractive
-
-@:require(flash11_3) static flash.events.Event.FRAME_LABEL;
-@:require(flash11_3) static flash.events.Event.SUSPEND;
-
-@:require(flash11_3) static flash.events.FullScreenEvent.FULL_SCREEN_INTERACTIVE_ACCEPTED;
-@:require(flash11_3) flash.events.FullScreenEvent.interactive;
-
-@:require(flash11_3) static flash.events.MouseEvent.RELEASE_OUTSIDE;
-
-@:require(flash11_3) flash.net.NetStream.useJitterBuffer;
-
-@:require(flash11_3) flash.system.ApplicationDomain.getQualifiedDefinitionNames;
-
-@:require(flash11_3) flash.system.SecurityDomain.domainID;
-
-@:require(flash11_3) flash.system.ApplicationInstaller;
-@:require(flash11_3) flash.system.AuthorizedFeatures;
-@:require(flash11_3) flash.system.AuthorizedFeaturesLoader;
-
-@:require(flash11_3) static flash.events.Event.TEXTURE_READY;
-
-
-// 11.4
-
-@:require(flash11_4) flash.display3D.Context3D.createRectangleTexture
-@:require(flash11_4) flash.display.BitmapData.copyPixelsToByteArray;
-
-@:require(flash11_4) flash.concurrent.Mutex;
-@:require(flash11_4) flash.concurrent.Condition;
-
-enum flash.display3D.Context3DProfile;
-
-flash.display.Stage3D.$profile : flash.display3D.Context3DProfile;
-
-@:require(flash11_4) flash.display.LoaderInfo.childSandboxBridge;
-@:require(flash11_4) flash.display.LoaderInfo.parentSandboxBridge;
-
-@:require(flash11_4) flash.display.Stage.contentsScaleFactor;
-
-
-@:require(flash11_4) flash.media.Camera.copyToByteArray;
-@:require(flash11_4) flash.media.Camera.copyToVector;
-@:require(flash11_4) flash.media.Camera.drawToBitmapData;
-@:require(flash11_4) flash.media.StageVideo.attachCamera;
-
-@:require(flash11_4) flash.net.URLStream.diskCacheEnabled;
-@:require(flash11_4) flash.net.URLStream.length;
-@:require(flash11_4) flash.net.URLStream.position;
-@:require(flash11_4) flash.net.URLStream.stop;
-
-@:require(flash11_4) flash.system.AuthorizedFeatures.enableDiskCache;
-@:require(flash11_4) flash.system.AuthorizedFeatures.isFeatureEnabled;
-@:require(flash11_4) flash.system.AuthorizedFeatures.isNegativeToken;
-@:require(flash11_4) flash.system.AuthorizedFeaturesLoader.makeGlobal;
-
-@:require(flash11_4) flash.utils.ByteArray.shareable;
-@:require(flash11_4) flash.utils.ByteArray.atomicCompareAndSwapIntAt;
-@:require(flash11_4) flash.utils.ByteArray.atomicCompareAndSwapLength;
-
-//not supported @:require(flash11_4) flash.utils.CompressionAlgorithm.LZMA;
-
-@:require(flash11_4) flash.system.Worker;
-@:require(flash11_4) flash.system.WorkerDomain;
-
-@:require(flash11_4) flash.system.MessageChannel;
-
--flash.system.Worker.new;
--flash.system.MessageChannel.new;
-
-flash.system.Worker.state : WorkerState;
-flash.system.MessageChannel.state : MessageChannelState;
-
-enum flash.system.WorkerState;
-
-
-// ---  11.6 API
-
-enum flash.display3D.Context3DMipFilter
-enum flash.display3D.Context3DTextureFilter
-enum flash.display3D.Context3DWrapMode
-enum flash.system.ApplicationInstallerMode
-
-@:require(flash11_6) flash.display3D.Context3D.setSamplerStateAt
-flash.display3D.Context3D.$wrap : Context3DWrapMode;
-flash.display3D.Context3D.$filter : Context3DTextureFilter;
-flash.display3D.Context3D.$mipfilter : Context3DMipFilter;
-
--flash.display.DisplayObject.metaData
-
-@:require(flash11_6) flash.display.Graphics.readGraphicsData
-
-@:require(flash11_7) flash.media.StageVideo.attachAVStream;
-@:require(flash11_7) static flash.net.SharedObject.preventBackup;
-@:require(flash11_7) flash.system.AuthorizedFeatures.enableHLSPlayback;
-@:require(flash11_7) flash.system.AuthorizedFeaturesLoader.loadAuthorizedFeaturesFromData;
-
-
+// types patches configuration for playerglobal.swc
+
+flash.display.DisplayObject.filters : Array<flash.filters.BitmapFilter>;
+
+-flash.accessibility.Accessibility.new
+@:require(flash10_1) flash.accessibility.ISearchableText
+@:require(flash10_1) flash.accessibility.ISimpleTextSelection
+
+@:require(flash10_1) flash.automation.ActionGenerator
+@:require(flash10_1) flash.automation.AutomationAction
+@:require(flash10_1) flash.automation.Configuration
+@:require(flash10_1) flash.automation.KeyboardAutomationAction
+@:require(flash10_1) flash.automation.MouseAutomationAction
+@:require(flash10_1) flash.automation.StageCapture
+@:require(flash10_1) flash.automation.StageCaptureEvent
+
+-flash.desktop.Clipboard.new
+flash.desktop.Clipboard.formats : Array<ClipboardFormats>;
+flash.desktop.Clipboard.$format : ClipboardFormats;
+flash.desktop.Clipboard.$transferMode : ClipboardTransferMode;
+
+enum flash.desktop.ClipboardFormats;
+enum flash.desktop.ClipboardTransferMode;
+
+enum flash.display.PixelSnapping;
+enum flash.display.BlendMode;
+
+@:require(flash10) flash.desktop.Clipboard
+@:require(flash10) flash.desktop.ClipboardFormats
+@:require(flash10) flash.desktop.ClipboardTransferMode
+
+flash.display.Bitmap.pixelSnapping : PixelSnapping;
+flash.display.Bitmap.$pixelSnapping : PixelSnapping;
+flash.display.BitmapData.$blendMode : BlendMode;
+flash.display.BitmapData.$redArray : Array<Int>;
+flash.display.BitmapData.$greenArray : Array<Int>;
+flash.display.BitmapData.$blueArray : Array<Int>;
+flash.display.BitmapData.$alphaArray : Array<Int>;
+flash.display.BitmapData.$offsets : Array<flash.geom.Point>;
+@:require(flash10) flash.display.BitmapData.setVector
+@:require(flash10) flash.display.BitmapData.getVector
+@:require(flash10) flash.display.BitmapData.histogram
+
+@:require(flash10_1) flash.display.Loader.uncaughtErrorEvents;
+@:require(flash10_1) flash.display.LoaderInfo.isURLInaccessible;
+@:require(flash10_1) flash.display.LoaderInfo.uncaughtErrorEvents;
+
+@:require(flash10_1) flash.display.ColorCorrection
+@:require(flash10_1) flash.display.ColorCorrectionSupport
+@:require(flash10_1) flash.display.FocusDirection
+@:require(flash10_1) flash.display.NativeMenu
+@:require(flash10_1) flash.display.NativeMenuItem
+
+@:require(flash10) flash.display.DisplayObject.blendShader
+@:require(flash10) flash.display.DisplayObject.rotationX
+@:require(flash10) flash.display.DisplayObject.rotationY
+@:require(flash10) flash.display.DisplayObject.rotationZ
+@:require(flash10) flash.display.DisplayObject.scaleZ
+@:require(flash10) flash.display.DisplayObject.z
+@:require(flash10) flash.display.DisplayObject.globalToLocal3D
+@:require(flash10) flash.display.DisplayObject.local3DToGlobal
+-flash.display.DisplayObject.new
+flash.display.DisplayObject.blendMode : BlendMode;
+flash.display.DisplayObject.opaqueBackground : Null<UInt>;
+flash.display.DisplayObjectContainer.getObjectsUnderPoint : Array<DisplayObject>;
+
+@:require(flash10_1) flash.display.Sprite.startTouchDrag;
+@:require(flash10_1) flash.display.Sprite.stopTouchDrag;
+
+@:require(flash10_1) flash.display.Stage.wmodeGPU;
+
+enum flash.display.GradientType;
+enum flash.display.CapsStyle;
+enum flash.display.JointStyle;
+enum flash.display.GraphicsPathWinding;
+enum flash.display.TriangleCulling;
+enum flash.display.InterpolationMethod;
+enum flash.display.LineScaleMode;
+enum flash.display.ShaderParameterType;
+enum flash.display.ShaderPrecision;
+enum flash.display.SpreadMethod;
+enum flash.display.StageAlign;
+enum flash.display.StageDisplayState;
+enum flash.display.StageQuality;
+enum flash.display.StageScaleMode;
+-flash.display.SWFVersion.new
+
+flash.display.Graphics.$type : GradientType;
+flash.display.Graphics.$colors : Array<UInt>;
+flash.display.Graphics.$spreadMethod : SpreadMethod;
+flash.display.Graphics.$interpolationMethod : InterpolationMethod;
+flash.display.Graphics.$scaleMode : LineScaleMode;
+flash.display.Graphics.$caps : CapsStyle;
+flash.display.Graphics.$joints : JointStyle;
+flash.display.Graphics.$winding : GraphicsPathWinding;
+flash.display.Graphics.$culling : TriangleCulling;
+@:require(flash10) flash.display.Graphics.beginShaderFill
+@:require(flash10) flash.display.Graphics.copyFrom
+@:require(flash10) flash.display.Graphics.drawGraphicsData
+@:require(flash10) flash.display.Graphics.drawPath
+@:require(flash10) flash.display.Graphics.drawTriangles
+@:require(flash10) flash.display.Graphics.lineBitmapStyle
+@:require(flash10) flash.display.Graphics.lineShaderStyle
+
+
+flash.display.GraphicsGradientFill.type : GradientType;
+flash.display.GraphicsGradientFill.colors : Array<UInt>;
+flash.display.GraphicsGradientFill.spreadMethod : SpreadMethod;
+flash.display.GraphicsGradientFill.interpolationMethod : InterpolationMethod;
+flash.display.GraphicsGradientFill.alphas : Array<Float>;
+flash.display.GraphicsGradientFill.ratios : Array<Float>;
+flash.display.GraphicsGradientFill.$type : GradientType;
+flash.display.GraphicsGradientFill.$colors : Array<UInt>;
+flash.display.GraphicsGradientFill.$spreadMethod : SpreadMethod;
+flash.display.GraphicsGradientFill.$interpolationMethod : InterpolationMethod;
+flash.display.GraphicsGradientFill.$alphas : Array<Float>;
+flash.display.GraphicsGradientFill.$ratios : Array<Float>;
+flash.display.GraphicsGradientFill.$matrix : flash.geom.Matrix;
+
+flash.display.GraphicsPath.winding : GraphicsPathWinding;
+flash.display.GraphicsPath.$winding : GraphicsPathWinding;
+
+flash.display.GraphicsStroke.scaleMode : LineScaleMode;
+flash.display.GraphicsStroke.caps : CapsStyle;
+flash.display.GraphicsStroke.joints : JointStyle;
+flash.display.GraphicsStroke.$scaleMode : LineScaleMode;
+flash.display.GraphicsStroke.$caps : CapsStyle;
+flash.display.GraphicsStroke.$joints : JointStyle;
+
+flash.display.GraphicsTrianglePath.culling : TriangleCulling;
+flash.display.GraphicsTrianglePath.$culling : TriangleCulling;
+
+
+@:require(flash10) flash.display.Loader.unloadAndStop
+
+enum flash.display.ActionScriptVersion;
+enum flash.display.ColorCorrection;
+enum flash.display.ColorCorrectionSupport;
+
+-flash.display.LoaderInfo.new
+flash.display.LoaderInfo.parameters : Dynamic<String>;
+flash.display.LoaderInfo.actionScriptVersion : ActionScriptVersion;
+
+-flash.display.MorphShape.new
+
+@:require(flash10) flash.display.MovieClip.currentFrameLabel
+flash.display.MovieClip.currentLabels : Array<FrameLabel>;
+flash.display.MovieClip.scenes : Array<Scene>;
+
+flash.display.Scene.labels : Array<FrameLabel>;
+flash.display.Scene.$labels : Array<FrameLabel>;
+
+@:require(flash10) flash.display.Shader;
+flash.display.Shader.precisionHint : ShaderPrecision;
+
+-flash.display.ShaderParameter.new
+flash.display.ShaderParameter.type : ShaderParameterType;
+
+-flash.display.Stage.new
+flash.display.Stage.align : StageAlign;
+flash.display.Stage.quality : StageQuality;
+flash.display.Stage.scaleMode : StageScaleMode;
+flash.display.Stage.colorCorrection : ColorCorrection;
+flash.display.Stage.colorCorrectionSupport : ColorCorrectionSupport;
+flash.display.Stage.displayState : StageDisplayState;
+flash.display.Stage.displayState : StageDisplayState;
+
+@:require(flash10) flash.display.Stage.colorCorrection
+@:require(flash10) flash.display.Stage.colorCorrectionSupport
+
+@:require(flash10_1) flash.errors.DRMManagerError
+@:require(flash10_1) flash.events.AccelerometerEvent
+@:require(flash10_1) flash.events.DRMAuthenticateEvent
+@:require(flash10_1) flash.events.DRMAuthenticationCompleteEvent
+@:require(flash10_1) flash.events.DRMAuthenticationErrorEvent
+@:require(flash10_1) flash.events.DRMCustomProperties
+@:require(flash10_1) flash.events.DRMErrorEvent
+@:require(flash10_1) flash.events.DRMStatusEvent
+@:require(flash10_1) flash.events.GeolocationEvent
+@:require(flash10_1) flash.events.GestureEvent
+@:require(flash10_1) flash.events.GesturePhase
+@:require(flash10_1) flash.events.PressAndTapGestureEvent
+@:require(flash10_1) flash.events.TouchEvent
+@:require(flash10_1) flash.events.TransformGestureEvent
+@:require(flash10_1) flash.events.UncaughtErrorEvent;
+@:require(flash10_1) flash.events.UncaughtErrorEvents;
+
+@:require(flash10) static flash.events.Event.CLEAR;
+@:require(flash10) static flash.events.Event.COPY;
+@:require(flash10) static flash.events.Event.CUT;
+@:require(flash10) static flash.events.Event.EXIT_FRAME;
+@:require(flash10) static flash.events.Event.FRAME_CONSTRUCTED;
+@:require(flash10) static flash.events.Event.PASTE;
+@:require(flash10) static flash.events.Event.SELECT_ALL;
+
+@:require(flash10) flash.events.ContextMenuEvent.isMouseTargetInaccessible
+@:require(flash10) flash.events.FocusEvent.isRelatedObjectInaccessible
+@:require(flash10) flash.events.MouseEvent.isRelatedObjectInaccessible
+
+flash.events.IEventDispatcher.$listener : Dynamic -> Void;
+flash.events.EventDispatcher.$listener : Dynamic -> Void;
+
+enum flash.events.EventPhase;
+enum flash.events.GesturePhase;
+
+flash.events.Event.eventPhase : EventPhase;
+
+flash.events.KeyboardEvent.keyLocation : flash.ui.KeyLocation;
+flash.events.KeyboardEvent.$keyLocationValue : flash.ui.KeyLocation;
+flash.events.KeyboardEvent.$keyLocation : flash.ui.KeyLocation;
+
+@:require(flash10_1) flash.events.ErrorEvent.errorID;
+
+@:require(flash10_1) flash.events.HTTPStatusEvent.responseHeaders;
+@:require(flash10_1) flash.events.HTTPStatusEvent.responseURL;
+@:require(flash10_1) static flash.events.HTTPStatusEvent.HTTP_RESPONSE_STATUS;
+
+@:require(flash10_1) flash.events.IMEEvent.imeClient;
+@:require(flash10_1) static flash.events.IMEEvent.IME_START_COMPOSITION;
+
+-flash.events.WeakFunctionClosure.new
+
+-flash.external.ExternalInterface.new
+
+enum flash.filters.BitmapFilterType;
+enum flash.filters.DisplacementMapFilterMode;
+
+flash.filters.BevelFilter.type : BitmapFilterType;
+flash.filters.BevelFilter.$type : BitmapFilterType;
+
+flash.filters.DisplacementMapFilter.mode : DisplacementMapFilterMode;
+flash.filters.DisplacementMapFilter.$mode : DisplacementMapFilterMode;
+
+flash.filters.GradientGlowFilter.type : BitmapFilterType;
+flash.filters.GradientGlowFilter.$type : BitmapFilterType;
+
+enum flash.geom.Orientation3D;
+
+flash.geom.Matrix3D.$orientationStyle : Orientation3D;
+
+@:require(flash10) flash.geom.Matrix3D;
+@:require(flash10) flash.geom.Utils3D;
+@:require(flash10) flash.geom.Vector3D;
+@:require(flash10) flash.geom.PerspectiveProjection;
+@:require(flash10) flash.geom.Transform.matrix3D;
+@:require(flash10) flash.geom.Transform.perspectiveProjection;
+@:require(flash10) flash.geom.Transform.getRelativeMatrix3D;
+
+-flash.geom.Utils3D.new
+
+@:require(flash10_1) static flash.media.Camera.isSupported;
+@:require(flash10_1) static flash.media.Camera._scanHardware;
+
+enum flash.media.SoundCodec;
+
+flash.media.Microphone.codec : SoundCodec;
+
+@:require(flash10) flash.media.Microphone.codec;
+@:require(flash10) flash.media.Microphone.encodeQuality;
+@:require(flash10) flash.media.Microphone.framesPerPacket;
+
+@:require(flash10_1) flash.media.Microphone.enableVAD;
+@:require(flash10_1) flash.media.Microphone.noiseSuppressionLevel;
+@:require(flash10_1) static flash.media.Microphone.isSupported;
+
+@:require(flash10) flash.media.Sound.extract;
+
+@:require(flash10_1) flash.media.Sound.isURLInaccessible;
+
+@:require(flash10) flash.net.FileReference.data;
+@:require(flash10) flash.net.FileReference.load;
+@:require(flash10) flash.net.FileReference.save;
+
+-flash.media.SoundMixer.new
+
+@:require(flash10_1) flash.net.LocalConnection.isPerUser;
+@:require(flash10_1) static flash.net.LocalConnection.isSupported;
+
+flash.net.FileReference.$typeFilter : Array<FileFilter>;
+flash.net.FileReferenceList.fileList : Array<FileReference>;
+flash.net.FileReferenceList.$typeFilter : Array<FileFilter>;
+
+@:require(flash10_1) flash.net.GroupSpecifier;
+@:require(flash10_1) flash.net.NetGroup;
+@:require(flash10_1) flash.net.NetGroupInfo;
+@:require(flash10_1) flash.net.NetStreamMulticastInfo;
+
+@:require(flash10) flash.net.NetConnection.farID;
+@:require(flash10) flash.net.NetConnection.farNonce;
+@:require(flash10) flash.net.NetConnection.maxPeerConnections;
+@:require(flash10) flash.net.NetConnection.nearID;
+@:require(flash10) flash.net.NetConnection.nearNonce;
+@:require(flash10) flash.net.NetConnection.protocol;
+@:require(flash10) flash.net.NetConnection.unconnectedPeerStreams;
+
+@:require(flash10) flash.net.NetStream.farID;
+@:require(flash10) flash.net.NetStream.farNonce;
+@:require(flash10) flash.net.NetStream.info;
+@:require(flash10) flash.net.NetStream.maxPauseBufferTime;
+@:require(flash10) flash.net.NetStream.nearNonce;
+@:require(flash10) flash.net.NetStream.peerStreams;
+@:require(flash10) flash.net.NetStream.onPeerConnect;
+@:require(flash10) flash.net.NetStream.play2;
+@:require(flash10) static flash.net.NetStream.CONNECT_TO_FMS;
+@:require(flash10) static flash.net.NetStream.DIRECT_CONNECTIONS;
+
+@:require(flash10_1) flash.net.NetStream.audioReliable;
+@:require(flash10_1) flash.net.NetStream.audioSampleAccess;
+@:require(flash10_1) flash.net.NetStream.backBufferLength;
+@:require(flash10_1) flash.net.NetStream.backBufferTime;
+@:require(flash10_1) flash.net.NetStream.bufferTimeMax;
+@:require(flash10_1) flash.net.NetStream.dataReliable;
+@:require(flash10_1) flash.net.NetStream.inBufferSeek;
+@:require(flash10_1) flash.net.NetStream.multicastAvailabilitySendToAll;
+@:require(flash10_1) flash.net.NetStream.multicastAvailabilityUpdatePeriod;
+@:require(flash10_1) flash.net.NetStream.multicastFetchPeriod;
+@:require(flash10_1) flash.net.NetStream.multicastInfo;
+@:require(flash10_1) flash.net.NetStream.multicastPushNeighborLimit;
+@:require(flash10_1) flash.net.NetStream.multicastRelayMarginDuration;
+@:require(flash10_1) flash.net.NetStream.multicastWindowDuration;
+@:require(flash10_1) flash.net.NetStream.videoReliable;
+@:require(flash10_1) flash.net.NetStream.videoSampleAccess;
+@:require(flash10_1) flash.net.NetStream.appendBytes;
+@:require(flash10_1) flash.net.NetStream.appendBytesAction;
+@:require(flash10_1) flash.net.NetStream.attach;
+@:require(flash10_1) flash.net.NetStream.step;
+
+@:require(flash10_1) flash.net.NetStreamInfo.videoLossRate;
+
+@:require(flash10_1) flash.net.NetStreamPlayOptions.offset;
+
+@:require(flash10_1) static flash.net.URLRequestMethod.DELETE;
+@:require(flash10_1) static flash.net.URLRequestMethod.HEAD;
+@:require(flash10_1) static flash.net.URLRequestMethod.OPTIONS;
+@:require(flash10_1) static flash.net.URLRequestMethod.PUT;
+
+@:require(flash10) flash.net.Socket.timeout;
+@:require(flash10) flash.net.XMLSocket.timeout;
+
+-flash.net.ObjectEncoding.new
+-flash.net.URLRequestMethod.new
+
+enum flash.net.URLLoaderDataFormat;
+
+flash.net.Socket.endian : flash.utils.Endian;
+flash.net.URLLoader.dataFormat : URLLoaderDataFormat;
+flash.net.URLRequest.requestHeaders : Array<URLRequestHeader>;
+flash.net.URLStream.endian : flash.utils.Endian;
+
+enum flash.printing.PrintJobOrientation;
+
+flash.printing.PrintJob.orientation : PrintJobOrientation;
+@:require(flash10_1) static flash.printing.PrintJob.isSupported;
+
+-flash.sampler.DeleteObjectSample.new
+-flash.sampler.NewObjectSample.new
+-flash.sampler.Sample.new
+flash.sampler.Sample.stack : Array<StackFrame>;
+-flash.sampler.StackFrame.new
+@:require(flash10_1) flash.sampler.NewObjectSample.size;
+@:require(flash10_1) flash.sampler.StackFrame.scriptID;
+
+-flash.system.Capabilities.new
+-flash.system.IME.new
+-flash.system.FSCommand.new
+
+enum flash.system.IMEConversionMode;
+
+static flash.system.IME.conversionMode : IMEConversionMode
+
+@:require(flash10) flash.system.ApplicationDomain.domainMemory;
+@:require(flash10) static flash.system.ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH;
+
+@:require(flash10) static flash.system.Capabilities.isEmbeddedInAcrobat;
+@:require(flash10) static flash.system.Capabilities.maxLevelIDC;
+
+@:require(flash10_1) static flash.system.Capabilities.cpuArchitecture;
+@:require(flash10_1) static flash.system.Capabilities.supports32BitProcesses;
+@:require(flash10_1) static flash.system.Capabilities.supports64BitProcesses;
+@:require(flash10_1) static flash.system.Capabilities.touchscreenType;
+static flash.system.Capabilities.touchscreenType : TouchscreenType;
+
+enum flash.system.TouchscreenType;
+
+
+@:require(flash10_1) static flash.system.IME.isSupported;
+@:require(flash10_1) static flash.system.IME.compositionAbandoned;
+@:require(flash10_1) static flash.system.IME.compositionSelectionChanged;
+
+
+@:require(flash10) flash.system.JPEGLoaderContext;
+
+
+@:require(flash10_1) flash.system.LoaderContext.allowCodeImport;
+@:require(flash10_1) flash.system.LoaderContext.allowLoadBytesCodeExecution;
+
+@:require(flash10_1) static flash.system.Security.APPLICATION;
+@:require(flash10_1) static flash.system.Security.duplicateSandboxBridgeInputArguments;
+@:require(flash10_1) static flash.system.Security.duplicateSandboxBridgeOutputArgument;
+
+@:require(flash10_1) static flash.system.System.currentTime;
+@:require(flash10_1) static flash.system.System.freeMemory;
+@:require(flash10_1) static flash.system.System.preciseStartupTime;
+@:require(flash10_1) static flash.system.System.privateMemory;
+@:require(flash10_1) static flash.system.System.totalMemoryNumber;
+@:require(flash10_1) static flash.system.System.disposeXML;
+@:require(flash10_1) static flash.system.System.nativeConstructionOnly;
+
+enum flash.system.SecurityPanel;
+
+-flash.system.Security.new
+flash.system.Security.$panel : SecurityPanel
+-flash.system.SecurityDomain.new
+-flash.system.System.new
+flash.system.SystemUpdater.$typer : SystemAdapterType;
+
+enum flash.text.AntiAliasType;
+enum flash.text.GridFitType;
+enum flash.text.FontStyle;
+enum flash.text.FontType;
+enum flash.text.TextDisplayMode;
+enum flash.text.TextFieldType;
+enum flash.text.TextFieldAutoSize;
+enum flash.text.TextFormatAlign;
+enum flash.text.TextFormatDisplay;
+enum flash.text.TextColorType;
+
+flash.text.Font.fontStyle : FontStyle;
+flash.text.Font.fontType : FontType;
+static flash.text.Font.enumerateFonts : Array<Font>;
+flash.text.TextField.autoSize : TextFieldAutoSize;
+flash.text.TextField.antiAliasType : AntiAliasType;
+flash.text.TextField.gridFitType : GridFitType;
+flash.text.TextField.type : TextFieldType;
+
+flash.text.TextFormat.align : TextFormatAlign;
+flash.text.TextFormat.blockIndent : Null<Float>
+flash.text.TextFormat.bold : Null<Bool>;
+flash.text.TextFormat.bullet : Null<Bool>;
+flash.text.TextFormat.color : Null<UInt>;
+flash.text.TextFormat.display : TextFormatDisplay;
+flash.text.TextFormat.indent : Null<Float>;
+flash.text.TextFormat.italic : Null<Bool>;
+flash.text.TextFormat.kerning : Null<Bool>;
+flash.text.TextFormat.leading : Null<Float>;
+flash.text.TextFormat.leftMargin : Null<Float>;
+flash.text.TextFormat.letterSpacing : Null<Float>;
+flash.text.TextFormat.rightMargin : Null<Float>;
+flash.text.TextFormat.size : Null<Float>;
+flash.text.TextFormat.tabStops : Array<UInt>;
+flash.text.TextFormat.underline : Null<Bool>;
+flash.text.TextFormat.$size : Null<Float>;
+flash.text.TextFormat.$color : Null<UInt>;
+flash.text.TextFormat.$bold : Null<Bool>;
+flash.text.TextFormat.$italic : Null<Bool>;
+flash.text.TextFormat.$underline : Null<Bool>;
+flash.text.TextFormat.$align : TextFormatAlign;
+flash.text.TextFormat.$leftMargin : Null<Float>;
+flash.text.TextFormat.$rightMargin : Null<Float>;
+flash.text.TextFormat.$indent : Null<Float>;
+flash.text.TextFormat.$leading : Null<Float>;
+
+@:require(flash10) static flash.text.TextField.isFontCompatible;
+
+-flash.text.TextRenderer.new
+static flash.text.TextRenderer.antiAliasType : AntiAliasType;
+static flash.text.TextRenderer.displayMode : TextDisplayMode;
+flash.text.TextRenderer.$fontStyle : FontStyle;
+flash.text.TextRenderer.$colorType : TextColorType;
+
+@:require(flash10_1) static flash.text.engine.FontDescription.isDeviceFontCompatible;
+@:require(flash10_1) flash.text.engine.SpaceJustifier.maximumSpacing;
+@:require(flash10_1) flash.text.engine.SpaceJustifier.minimumSpacing;
+@:require(flash10_1) flash.text.engine.SpaceJustifier.optimumSpacing;
+@:require(flash10_1) flash.text.engine.TextBlock.recreateTextLine;
+@:require(flash10_1) flash.text.engine.TextBlock.releaseLineCreationData;
+@:require(flash10_1) flash.text.engine.TextLine.hasTabs;
+
+flash.text.engine.ContentElement.textRotation : TextRotation;
+flash.text.engine.ContentElement.$textRotation : TextRotation;
+
+flash.text.engine.EastAsianJustifier.justificationStyle : JustificationStyle;
+flash.text.engine.EastAsianJustifier.$justificationStyle : JustificationStyle;
+flash.text.engine.EastAsianJustifier.$lineJustification : LineJustification;
+
+enum flash.text.engine.BreakOpportunity;
+enum flash.text.engine.CFFHinting;
+enum flash.text.engine.DigitCase;
+enum flash.text.engine.DigitWidth;
+enum flash.text.engine.FontLookup;
+enum flash.text.engine.FontPosture;
+enum flash.text.engine.FontWeight;
+enum flash.text.engine.JustificationStyle;
+enum flash.text.engine.Kerning;
+enum flash.text.engine.LigatureLevel;
+enum flash.text.engine.LineJustification;
+enum flash.text.engine.RenderingMode;
+enum flash.text.engine.TabAlignment;
+enum flash.text.engine.TextBaseline;
+enum flash.text.engine.TextLineCreationResult;
+enum flash.text.engine.TextLineValidity;
+enum flash.text.engine.TextRotation;
+enum flash.text.engine.TypographicCase;
+
+
+flash.text.engine.ElementFormat.alignmentBaseline : TextBaseline;
+flash.text.engine.ElementFormat.breakOpportunity : BreakOpportunity;
+flash.text.engine.ElementFormat.digitCase : DigitCase;
+flash.text.engine.ElementFormat.digitWidth : DigitWidth;
+flash.text.engine.ElementFormat.dominantBaseline : TextBaseline;
+flash.text.engine.ElementFormat.kerning : Kerning;
+flash.text.engine.ElementFormat.ligatureLevel : LigatureLevel;
+flash.text.engine.ElementFormat.textRotation : TextRotation;
+flash.text.engine.ElementFormat.typographicCase : TypographicCase;
+flash.text.engine.ElementFormat.$alignmentBaseline : TextBaseline;
+flash.text.engine.ElementFormat.$breakOpportunity : BreakOpportunity;
+flash.text.engine.ElementFormat.$digitCase : DigitCase;
+flash.text.engine.ElementFormat.$digitWidth : DigitWidth;
+flash.text.engine.ElementFormat.$dominantBaseline : TextBaseline;
+flash.text.engine.ElementFormat.$kerning : Kerning;
+flash.text.engine.ElementFormat.$ligatureLevel : LigatureLevel;
+flash.text.engine.ElementFormat.$textRotation : TextRotation;
+flash.text.engine.ElementFormat.$typographicCase : TypographicCase;
+
+flash.text.engine.FontDescription.cffHinting : CFFHinting;
+flash.text.engine.FontDescription.fontLookup : FontLookup;
+flash.text.engine.FontDescription.fontPosture : FontPosture;
+flash.text.engine.FontDescription.fontWeight : FontWeight;
+flash.text.engine.FontDescription.renderingMode : RenderingMode;
+flash.text.engine.FontDescription.$cffHinting : CFFHinting;
+flash.text.engine.FontDescription.$fontLookup : FontLookup;
+flash.text.engine.FontDescription.$fontPosture : FontPosture;
+flash.text.engine.FontDescription.$fontWeight : FontWeight;
+flash.text.engine.FontDescription.$renderingMode : RenderingMode;
+
+flash.text.engine.GraphicElement.$textRotation : TextRotation;
+flash.text.engine.GroupElement.$textRotation : TextRotation;
+flash.text.engine.SpaceJustifier.$lineJustification : LineJustification;
+flash.text.engine.TabStop.alignment : TabAlignment;
+flash.text.engine.TabStop.$alignment : TabAlignment;
+
+flash.text.engine.TextBlock.baselineZero : TextBaseline;
+flash.text.engine.TextBlock.lineRotation : TextRotation;
+flash.text.engine.TextBlock.textLineCreationResult : TextLineCreationResult;
+flash.text.engine.TextBlock.$baselineZero : TextBaseline;
+flash.text.engine.TextBlock.$lineRotation : TextRotation;
+flash.text.engine.TextBlock.$textLineCreationResult : TextLineCreationResult;
+
+flash.text.engine.TextElement.$textRotation : TextRotation;
+
+flash.text.engine.TextJustifier.lineJustification : LineJustification;
+flash.text.engine.TextJustifier.$lineJustification : LineJustification;
+
+flash.text.engine.TextLine.baseline : TextBaseline;
+
+-flash.trace.Trace.new
+
+-static flash.xml.XMLList.length
+-static flash.xml.XML.length
+-flash.text.engine.TextElement.text
+
+-flash.ui.Keyboard.new
+-flash.ui.Mouse.new
+
+enum flash.ui.MultitouchInputMode;
+
+-flash.ui.Multitouch.new
+flash.ui.Multitouch.inputMode : MultitouchInputMode;
+
+@:require(flash10) flash.ui.ContextMenu.clipboardItems;
+@:require(flash10) flash.ui.ContextMenu.clipboardMenu;
+@:require(flash10) flash.ui.ContextMenu.link;
+
+@:require(flash10_1) static flash.ui.ContextMenu.isSupported;
+
+@:require(flash10) static flash.ui.Mouse.cursor;
+static flash.ui.Mouse.cursor : Dynamic;
+
+@:require(flash10_1) static flash.ui.Keyboard.A;
+@:require(flash10_1) static flash.ui.Keyboard.B;
+@:require(flash10_1) static flash.ui.Keyboard.C;
+@:require(flash10_1) static flash.ui.Keyboard.D;
+@:require(flash10_1) static flash.ui.Keyboard.E;
+@:require(flash10_1) static flash.ui.Keyboard.F;
+@:require(flash10_1) static flash.ui.Keyboard.G;
+@:require(flash10_1) static flash.ui.Keyboard.H;
+@:require(flash10_1) static flash.ui.Keyboard.I;
+@:require(flash10_1) static flash.ui.Keyboard.J;
+@:require(flash10_1) static flash.ui.Keyboard.K;
+@:require(flash10_1) static flash.ui.Keyboard.L;
+@:require(flash10_1) static flash.ui.Keyboard.M;
+@:require(flash10_1) static flash.ui.Keyboard.N;
+@:require(flash10_1) static flash.ui.Keyboard.O;
+@:require(flash10_1) static flash.ui.Keyboard.P;
+@:require(flash10_1) static flash.ui.Keyboard.Q;
+@:require(flash10_1) static flash.ui.Keyboard.R;
+@:require(flash10_1) static flash.ui.Keyboard.S;
+@:require(flash10_1) static flash.ui.Keyboard.T;
+@:require(flash10_1) static flash.ui.Keyboard.U;
+@:require(flash10_1) static flash.ui.Keyboard.V;
+@:require(flash10_1) static flash.ui.Keyboard.W;
+@:require(flash10_1) static flash.ui.Keyboard.X;
+@:require(flash10_1) static flash.ui.Keyboard.Y;
+@:require(flash10_1) static flash.ui.Keyboard.Z;
+@:require(flash10_1) static flash.ui.Keyboard.ALTERNATE;
+@:require(flash10_1) static flash.ui.Keyboard.BACKQUOTE;
+@:require(flash10_1) static flash.ui.Keyboard.BACKSLASH;
+@:require(flash10_1) static flash.ui.Keyboard.COMMA;
+@:require(flash10_1) static flash.ui.Keyboard.COMMAND;
+@:require(flash10_1) static flash.ui.Keyboard.CharCodeStrings;
+@:require(flash10_1) static flash.ui.Keyboard.EQUAL;
+@:require(flash10_1) static flash.ui.Keyboard.LEFTBRACKET;
+@:require(flash10_1) static flash.ui.Keyboard.MINUS;
+@:require(flash10_1) static flash.ui.Keyboard.NUMBER_0;
+@:require(flash10_1) static flash.ui.Keyboard.NUMBER_1;
+@:require(flash10_1) static flash.ui.Keyboard.NUMBER_2;
+@:require(flash10_1) static flash.ui.Keyboard.NUMBER_3;
+@:require(flash10_1) static flash.ui.Keyboard.NUMBER_4;
+@:require(flash10_1) static flash.ui.Keyboard.NUMBER_5;
+@:require(flash10_1) static flash.ui.Keyboard.NUMBER_6;
+@:require(flash10_1) static flash.ui.Keyboard.NUMBER_7;
+@:require(flash10_1) static flash.ui.Keyboard.NUMBER_8;
+@:require(flash10_1) static flash.ui.Keyboard.NUMBER_9;
+@:require(flash10_1) static flash.ui.Keyboard.NUMPAD;
+@:require(flash10_1) static flash.ui.Keyboard.PERIOD;
+@:require(flash10_1) static flash.ui.Keyboard.QUOTE;
+@:require(flash10_1) static flash.ui.Keyboard.RIGHTBRACKET;
+@:require(flash10_1) static flash.ui.Keyboard.SEMICOLON;
+@:require(flash10_1) static flash.ui.Keyboard.SLASH;
+@:require(flash10_1) static flash.ui.Keyboard.hasVirtualKeyboard;
+@:require(flash10_1) static flash.ui.Keyboard.physicalKeyboardType;
+
+enum flash.ui.KeyboardType;
+enum flash.ui.KeyLocation;
+
+static flash.ui.Keyboard.physicalKeyboardType : KeyboardType;
+
+@:require(flash10_1) flash.ui.Multitouch;
+static flash.ui.Multitouch.inputMode : MultitouchInputMode;
+@:require(flash10_1) flash.ui.MultitouchInputMode;
+
+@:require(flash10_1) static flash.ui.Keyboard.STRING_BEGIN;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_BREAK;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_CLEARDISPLAY;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_CLEARLINE;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_DELETE;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_DELETECHAR;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_DELETELINE;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_DOWNARROW;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_END;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_EXECUTE;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_F1;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_F10;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_F11;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_F12;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_F13;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_F14;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_F15;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_F16;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_F17;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_F18;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_F19;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_F2;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_F20;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_F21;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_F22;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_F23;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_F24;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_F25;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_F26;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_F27;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_F28;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_F29;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_F3;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_F30;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_F31;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_F32;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_F33;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_F34;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_F35;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_F4;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_F5;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_F6;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_F7;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_F8;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_F9;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_FIND;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_HELP;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_HOME;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_INSERT;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_INSERTCHAR;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_INSERTLINE;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_LEFTARROW;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_MENU;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_MODESWITCH;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_NEXT;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_PAGEDOWN;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_PAGEUP;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_PAUSE;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_PREV;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_PRINT;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_PRINTSCREEN;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_REDO;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_RESET;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_RIGHTARROW;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_SCROLLLOCK;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_SELECT;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_STOP;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_SYSREQ;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_SYSTEM;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_UNDO;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_UPARROW;
+@:require(flash10_1) static flash.ui.Keyboard.STRING_USER;
+
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_BEGIN;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_BREAK;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_CLEARDISPLAY;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_CLEARLINE;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_DELETE;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_DELETECHAR;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_DELETELINE;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_DOWNARROW;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_END;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_EXECUTE;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F1;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F10;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F11;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F12;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F13;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F14;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F15;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F16;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F17;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F18;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F19;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F2;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F20;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F21;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F22;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F23;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F24;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F25;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F26;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F27;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F28;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F29;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F3;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F30;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F31;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F32;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F33;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F34;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F35;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F4;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F5;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F6;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F7;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F8;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_F9;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_FIND;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_HELP;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_HOME;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_INSERT;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_INSERTCHAR;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_INSERTLINE;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_LEFTARROW;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_MENU;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_MODESWITCH;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_NEXT;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_PAGEDOWN;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_PAGEUP;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_PAUSE;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_PREV;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_PRINT;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_PRINTSCREEN;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_REDO;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_RESET;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_RIGHTARROW;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_SCROLLLOCK;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_SELECT;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_STOP;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_SYSREQ;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_SYSTEM;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_UNDO;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_UPARROW;
+@:require(flash10_1) static flash.ui.Keyboard.KEYNAME_USER;
+
+@:require(flash10_1) static flash.ui.Mouse.supportsCursor;
+
+enum flash.utils.Endian;
+
+@:native("RegExp") flash.utils.RegExp;
+-static flash.utils.RegExp.length;
+
+flash.utils.ObjectInput.endian : Endian;
+flash.utils.ObjectOutput.endian : Endian;
+flash.utils.ByteArray.endian : Endian;
+flash.utils.IDataInput.endian : Endian;
+flash.utils.IDataOutput.endian : Endian;
+
+@:require(flash10) flash.utils.ByteArray.clear;
+@:require(flash10) flash.utils.ByteArray.deflate;
+@:require(flash10) flash.utils.ByteArray.inflate;
+
+@:require(flash10) flash.utils.SetIntervalTimer.clearArrayEntry;
+
+-flash.utils.Namespace.toString
+-flash.utils.Namespace.valueOf
+-static flash.utils.Namespace.length
+
+-flash.utils.QName.toString
+-flash.utils.QName.valueOf
+-static flash.utils.QName.length
+
+enum flash.xml.XMLNodeType;
+
+flash.xml.XMLNode.nodeType : XMLNodeType;
+flash.xml.XMLNode.$type : XMLNodeType;
+
+flash.xml.XML.namespace : flash.utils.Namespace;
+flash.xml.XML.parent : XML;
+flash.xml.XMLList.namespace : flash.utils.Namespace;
+flash.xml.XMLList.parent : XML;
+flash.xml.XMLTag.type : XMLNodeType;
+
+
+enum flash.system.SystemUpdaterType;
+
+@:require(flash10_1) flash.system.SystemUpdater;
+flash.system.SystemUpdater.$type : SystemUpdaterType;
+
+@:require(flash10_1) flash.sensors.Accelerometer;
+@:require(flash10_1) flash.sensors.Geolocation;
+
+@:require(flash10_1) flash.globalization.Collator;
+@:require(flash10_1) flash.globalization.CurrencyFormatter;
+@:require(flash10_1) flash.globalization.DateTimeFormatter;
+@:require(flash10_1) flash.globalization.LocaleID;
+@:require(flash10_1) flash.globalization.StringTools;
+@:require(flash10_1) flash.globalization.NumberFormatter;
+@:require(flash10_1) flash.globalization.NumberParseResult;
+
+enum flash.globalization.CollatorMode;
+enum flash.globalization.DateTimeNameContext;
+enum flash.globalization.DateTimeNameStyle;
+enum flash.globalization.DateTimeStyle;
+enum flash.globalization.LastOperationStatus;
+enum flash.globalization.NationalDigitsType;
+
+flash.globalization.Collator.lastOperationStatus : LastOperationStatus;
+flash.globalization.Collator.$initialMode : CollatorMode;
+flash.globalization.CurrencyFormatter.lastOperationStatus : LastOperationStatus;
+
+flash.globalization.DateTimeFormatter.lastOperationStatus : LastOperationStatus;
+flash.globalization.DateTimeFormatter.$dateStyle : DateTimeStyle;
+flash.globalization.DateTimeFormatter.$nameStyle : DateTimeNameStyle;
+flash.globalization.DateTimeFormatter.$timeStyle : DateTimeStyle;
+flash.globalization.DateTimeFormatter.$context : DateTimeNameContext;
+flash.globalization.DateTimeFormatter.getDateStyle : DateTimeStyle;
+flash.globalization.DateTimeFormatter.getTimeStyle : DateTimeStyle;
+flash.globalization.DateTimeFormatter.getDateTimePattern : DateTimeStyle;
+flash.globalization.LocaleID.lastOperationStatus : LastOperationStatus;
+flash.globalization.NumberFormatter.lastOperationStatus : LastOperationStatus;
+flash.globalization.NumberFormatter.digitsType : NationalDigitsType;
+flash.globalization.StringTools.lastOperationStatus : LastOperationStatus;
+
+// FP 10.2
+
+@:require(flash10_2) flash.ui.MouseCursorData;
+@:require(flash10_2) flash.events.StageVideoEvent;
+@:require(flash10_2) flash.events.VideoEvent;
+@:require(flash10_2) flash.media.MicrophoneEnhancedMode;
+@:require(flash10_2) flash.media.MicrophoneEnhancedOptions;
+@:require(flash10_2) flash.media.StageVideo;
+
+@:require(flash10_2) flash.display.Stage.color;
+@:require(flash10_2) flash.display.Stage.stageVideos;
+
+@:require(flash10_2) flash.media.Microphone.enhancedOptions;
+@:require(flash10_2) static flash.media.Microphone.getEnhancedMicrophone;
+
+@:require(flash10_2) static flash.system.Capabilities.allowsFullScreen;
+
+@:require(flash10_2) static flash.ui.Keyboard.AUDIO;
+@:require(flash10_2) static flash.ui.Keyboard.BACK;
+@:require(flash10_2) static flash.ui.Keyboard.BLUE;
+@:require(flash10_2) static flash.ui.Keyboard.CHANNEL_DOWN;
+@:require(flash10_2) static flash.ui.Keyboard.CHANNEL_UP;
+@:require(flash10_2) static flash.ui.Keyboard.DVR;
+@:require(flash10_2) static flash.ui.Keyboard.EXIT;
+@:require(flash10_2) static flash.ui.Keyboard.FAST_FORWARD;
+@:require(flash10_2) static flash.ui.Keyboard.GREEN;
+@:require(flash10_2) static flash.ui.Keyboard.GUIDE;
+@:require(flash10_2) static flash.ui.Keyboard.HELP;
+@:require(flash10_2) static flash.ui.Keyboard.INFO;
+@:require(flash10_2) static flash.ui.Keyboard.INPUT;
+@:require(flash10_2) static flash.ui.Keyboard.LAST;
+@:require(flash10_2) static flash.ui.Keyboard.LIVE;
+@:require(flash10_2) static flash.ui.Keyboard.MASTER_SHELL;
+@:require(flash10_2) static flash.ui.Keyboard.MENU;
+@:require(flash10_2) static flash.ui.Keyboard.NEXT;
+@:require(flash10_2) static flash.ui.Keyboard.PAUSE;
+@:require(flash10_2) static flash.ui.Keyboard.PLAY;
+@:require(flash10_2) static flash.ui.Keyboard.PREVIOUS;
+@:require(flash10_2) static flash.ui.Keyboard.RECORD;
+@:require(flash10_2) static flash.ui.Keyboard.RED;
+@:require(flash10_2) static flash.ui.Keyboard.REWIND;
+@:require(flash10_2) static flash.ui.Keyboard.SEARCH;
+@:require(flash10_2) static flash.ui.Keyboard.SETUP;
+@:require(flash10_2) static flash.ui.Keyboard.SKIP_BACKWARD;
+@:require(flash10_2) static flash.ui.Keyboard.SKIP_FORWARD;
+@:require(flash10_2) static flash.ui.Keyboard.STOP;
+@:require(flash10_2) static flash.ui.Keyboard.SUBTITLE;
+@:require(flash10_2) static flash.ui.Keyboard.VOD;
+@:require(flash10_2) static flash.ui.Keyboard.YELLOW;
+
+@:require(flash10_2) static flash.ui.Mouse.registerCursor;
+
+enum flash.media.MicrophoneEnhancedMode;
+
+flash.media.MicrophoneEnhancedOptions.mode : MicrophoneEnhancedMode;
+
+enum flash.display.FocusDirection;
+
+
+// FLASH 11 FEATURES
+
+-flash.automation.Configuration.new
+
+@:require(flash11) flash.display.DisplayObjectContainer.removeChildren;
+@:require(flash11) flash.display.Graphics.cubicCurveTo;
+@:require(flash11) flash.display.GraphicsPath.cubicCurveTo;
+
+@:require(flash11) flash.display.InteractiveObject.needsSoftKeyboard;
+@:require(flash11) flash.display.InteractiveObject.softKeyboardInputAreaOfInterest;
+@:require(flash11) flash.display.InteractiveObject.requestSoftKeyboard;
+
+@:require(flash11) flash.display.MovieClip.isPlaying;
+
+@:require(flash11) flash.display.Stage.allowsFullScreen;
+@:require(flash11) flash.display.Stage.displayContextInfo;
+@:require(flash11) flash.display.Stage.softKeyboardRect;
+@:require(flash11) flash.display.Stage.stage3Ds;
+@:require(flash11) flash.display.Stage3D;
+
+-flash.display.Stage.constructor;
+-flash.display.Stage.hasOwnProperty;
+-flash.display.Stage.isPrototypeOf;
+-flash.display.Stage.propertyIsEnumerable;
+-flash.display.Stage.setPropertyIsEnumerable;
+-flash.display.Stage.toLocaleString;
+-flash.display.Stage.valueOf;
+
+enum flash.display3D.Context3DBlendFactor;
+enum flash.display3D.;
+
+@:require(flash11) static flash.events.Event.CONTEXT3D_CREATE;
+@:require(flash11) static flash.events.Event.TEXT_INTERACTION_MODE_CHANGE;
+
+@:require(flash11) static flash.events.StageVideoEvent.RENDER_STATUS_AVAILABLE;
+@:require(flash11) static flash.events.StageVideoEvent.STAGE_VIDEO_STATE;
+
+@:require(flash11) flash.geom.Matrix3D.copyColumnFrom;
+@:require(flash11) flash.geom.Matrix3D.copyColumnTo;
+@:require(flash11) flash.geom.Matrix3D.copyFrom;
+@:require(flash11) flash.geom.Matrix3D.copyRawDataFrom;
+@:require(flash11) flash.geom.Matrix3D.copyRawDataTo;
+@:require(flash11) flash.geom.Matrix3D.copyRowFrom;
+@:require(flash11) flash.geom.Matrix3D.copyRowTo;
+@:require(flash11) flash.geom.Matrix3D.copyToMatrix3D;
+
+@:require(flash11) flash.geom.Matrix.copyColumnFrom;
+@:require(flash11) flash.geom.Matrix.copyColumnTo;
+@:require(flash11) flash.geom.Matrix.copyFrom;
+@:require(flash11) flash.geom.Matrix.copyRowFrom;
+@:require(flash11) flash.geom.Matrix.copyRowTo;
+@:require(flash11) flash.geom.Matrix.setTo;
+
+@:require(flash11) flash.geom.Point.copyFrom;
+@:require(flash11) flash.geom.Point.setTo;
+
+@:require(flash11) flash.geom.Rectangle.copyFrom;
+@:require(flash11) flash.geom.Rectangle.setTo;
+
+@:require(flash11) flash.geom.Vector3D.copyFrom;
+@:require(flash11) flash.geom.Vector3D.setTo;
+
+
+
+@:require(flash11) flash.media.Sound.loadCompressedDataFromByteArray;
+@:require(flash11) flash.media.Sound.loadPCMFromByteArray;
+
+@:require(flash11) flash.net.Socket.bytesPending;
+
+-flash.display3D.Context3DClearMask.new;
+enum flash.display3D.Context3DCompareMode;
+enum flash.display3D.Context3DProgramType;
+enum flash.display3D.Context3DRenderMode;
+enum flash.display3D.Context3DStencilAction;
+enum flash.display3D.Context3DTextureFormat;
+enum flash.display3D.Context3DTriangleFace;
+enum flash.display3D.Context3DVertexBufferFormat;
+
+-flash.display.Stage3D.new;
+-flash.display3D.Context3D.new;
+-flash.display3D.IndexBuffer3D.new;
+-flash.display3D.Program3D.new;
+-flash.display3D.VertexBuffer3D.new;
+-flash.display3D.textures.CubeTexture.new;
+-flash.display3D.textures.TextureBase.new;
+-flash.display3D.textures.Texture.new;
+
+flash.display3D.Context3D.$sourceFactor : Context3DBlendFactor;
+flash.display3D.Context3D.$destinationFactor : Context3DBlendFactor;
+flash.display3D.Context3D.$format : Context3DTextureFormat;
+flash.display3D.Context3D.$triangleFaceToCull : Context3DTriangleFace;
+flash.display3D.Context3D.$triangleFace : Context3DTriangleFace;
+flash.display3D.Context3D.$passCompareMode : Context3DCompareMode;
+flash.display3D.Context3D.$compareMode : Context3DCompareMode;
+flash.display3D.Context3D.$programType : Context3DProgramType;
+flash.display3D.Context3D.$actionOnBothPass : Context3DStencilAction;
+flash.display3D.Context3D.$actionOnDepthFail : Context3DStencilAction;
+flash.display3D.Context3D.$actionOnDepthPassStencilFail : Context3DStencilAction;
+flash.display3D.Context3D.$setVertexBufferAt__format : Context3DVertexBufferFormat;
+
+@:require(flash11) flash.net.NetStream.useHardwareDecoder;
+@:require(flash11) flash.net.NetStream.videoStreamSettings;
+
+@:require(flash11) flash.net.SecureSocket;
+@:require(flash11) flash.net.NetMonitor;
+
+@:require(flash11) static flash.system.Capabilities.hasMultiChannelAudio;
+
+@:require(flash11) flash.system.LoaderContext.imageDecodingPolicy;
+@:require(flash11) flash.system.LoaderContext.parameters;
+@:require(flash11) flash.system.LoaderContext.requestedContentParent;
+
+enum flash.system.ImageDecodingPolicy;
+
+flash.system.LoaderContext.imageDecodingPolicy : ImageDecodingPolicy;
+
+@:require(flash11) static flash.system.Security.pageDomain;
+
+@:require(flash11) static flash.system.System.processCPUUsage;
+@:require(flash11) static flash.system.System.pauseForGCIfCollectionImminent;
+
+@:require(flash11) static flash.ui.Mouse.supportsNativeCursor;
+@:require(flash11) static flash.ui.Mouse.unregisterCursor;
+
+-flash.ui.MouseCursor.new;
+
+@:require(flash11) flash.utils.CompressionAlgorithm;
+enum flash.utils.CompressionAlgorithm;
+
+@:require(flash11) flash.xml.XML.toJSON;
+@:require(flash11) flash.xml.XMLList.toJSON;
+
+flash.utils.ByteArray.$algorithm : CompressionAlgorithm;
+
+@:require(flash11) flash.text.TextField.textInteractionMode;
+
+enum flash.text.TextInteractionMode;
+
+flash.text.TextField.textInteractionMode : TextInteractionMode;
+
+// 11.2
+
+enum flash.display.BitmapCompressColorSpace;
+
+@:require(flash11_2) flash.display.BitmapData.compress;
+@:require(flash11_2) flash.media.Camera.position;
+@:require(flash11_2) flash.net.NetStream.dispose;
+
+@:require(flash11_2) flash.display.StageWorker;
+@:require(flash11_2) flash.display.Worker;
+@:require(flash11_2) flash.events.GameInputEvent;
+@:require(flash11_2) flash.events.ThrottleEvent;
+
+flash.events.ThrottleEvent.$type : ThrottleType;
+
+enum flash.events.ThrottleType;
+
+@:require(flash11_2) flash.ui.GameInput;
+@:require(flash11_2) flash.ui.GameInputDevice;
+-flash.ui.GameInput.new;
+
+@:require(flash11_2) flash.utils.Telemetry;
+
+enum flash.ui.GameInputFinger;
+enum flash.ui.GameInputHand;
+enum flash.ui.GameInputControlType;
+
+flash.ui.GameInputControl.finger : flash.ui.GameInputFinger;
+flash.ui.GameInputControl.hand : flash.ui.GameInputHand;
+flash.ui.GameInputControl.type : flash.ui.GameInputControlType;
+
+
+// 11.2
+
+@:require(flash11_2) flash.display3D.Context3D.setProgramConstantsFromByteArray
+@:require(flash11_2) flash.display.Stage.mouseLock;
+
+@:require(flash11_2) flash.events.MouseEvent.movementX;
+@:require(flash11_2) flash.events.MouseEvent.movementY;
+
+@:require(flash11_2) static flash.events.MouseEvent.CONTEXT_MENU;
+@:require(flash11_2) static flash.events.MouseEvent.MIDDLE_CLICK;
+@:require(flash11_2) static flash.events.MouseEvent.MIDDLE_MOUSE_DOWN;
+@:require(flash11_2) static flash.events.MouseEvent.MIDDLE_MOUSE_UP;
+@:require(flash11_2) static flash.events.MouseEvent.RIGHT_CLICK;
+@:require(flash11_2) static flash.events.MouseEvent.RIGHT_MOUSE_DOWN;
+@:require(flash11_2) static flash.events.MouseEvent.RIGHT_MOUSE_UP;
+
+
+// 11.3
+
+@:require(flash11_3) flash.display.BitmapData.drawWithQuality
+
+flash.display.BitmapData.$quality : StageQuality;
+
+enum flash.display.BitmapEncodingColorSpace;
+
+flash.display.JPEGXREncoderOptions.$colorSpace : BitmapEncodingColorSpace;
+flash.display.JPEGXREncoderOptions.colorSpace : BitmapEncodingColorSpace;
+
+@:require(flash11_3) flash.display.BitmapData.encode
+@:require(flash11_3) flash.display.Stage.allowsFullScreenInteractive
+
+@:require(flash11_3) static flash.events.Event.FRAME_LABEL;
+@:require(flash11_3) static flash.events.Event.SUSPEND;
+
+@:require(flash11_3) static flash.events.FullScreenEvent.FULL_SCREEN_INTERACTIVE_ACCEPTED;
+@:require(flash11_3) flash.events.FullScreenEvent.interactive;
+
+@:require(flash11_3) static flash.events.MouseEvent.RELEASE_OUTSIDE;
+
+@:require(flash11_3) flash.net.NetStream.useJitterBuffer;
+
+@:require(flash11_3) flash.system.ApplicationDomain.getQualifiedDefinitionNames;
+
+@:require(flash11_3) flash.system.SecurityDomain.domainID;
+
+@:require(flash11_3) flash.system.ApplicationInstaller;
+@:require(flash11_3) flash.system.AuthorizedFeatures;
+@:require(flash11_3) flash.system.AuthorizedFeaturesLoader;
+
+@:require(flash11_3) static flash.events.Event.TEXTURE_READY;
+
+
+// 11.4
+
+@:require(flash11_4) flash.display3D.Context3D.createRectangleTexture
+@:require(flash11_4) flash.display.BitmapData.copyPixelsToByteArray;
+
+@:require(flash11_4) flash.concurrent.Mutex;
+@:require(flash11_4) flash.concurrent.Condition;
+
+enum flash.display3D.Context3DProfile;
+
+flash.display.Stage3D.$profile : flash.display3D.Context3DProfile;
+
+@:require(flash11_4) flash.display.LoaderInfo.childSandboxBridge;
+@:require(flash11_4) flash.display.LoaderInfo.parentSandboxBridge;
+
+@:require(flash11_4) flash.display.Stage.contentsScaleFactor;
+
+
+@:require(flash11_4) flash.media.Camera.copyToByteArray;
+@:require(flash11_4) flash.media.Camera.copyToVector;
+@:require(flash11_4) flash.media.Camera.drawToBitmapData;
+@:require(flash11_4) flash.media.StageVideo.attachCamera;
+
+@:require(flash11_4) flash.net.URLStream.diskCacheEnabled;
+@:require(flash11_4) flash.net.URLStream.length;
+@:require(flash11_4) flash.net.URLStream.position;
+@:require(flash11_4) flash.net.URLStream.stop;
+
+@:require(flash11_4) flash.system.AuthorizedFeatures.enableDiskCache;
+@:require(flash11_4) flash.system.AuthorizedFeatures.isFeatureEnabled;
+@:require(flash11_4) flash.system.AuthorizedFeatures.isNegativeToken;
+@:require(flash11_4) flash.system.AuthorizedFeaturesLoader.makeGlobal;
+
+@:require(flash11_4) flash.utils.ByteArray.shareable;
+@:require(flash11_4) flash.utils.ByteArray.atomicCompareAndSwapIntAt;
+@:require(flash11_4) flash.utils.ByteArray.atomicCompareAndSwapLength;
+
+//not supported @:require(flash11_4) flash.utils.CompressionAlgorithm.LZMA;
+
+@:require(flash11_4) flash.system.Worker;
+@:require(flash11_4) flash.system.WorkerDomain;
+
+@:require(flash11_4) flash.system.MessageChannel;
+
+-flash.system.Worker.new;
+-flash.system.MessageChannel.new;
+
+flash.system.Worker.state : WorkerState;
+flash.system.MessageChannel.state : MessageChannelState;
+
+enum flash.system.WorkerState;
+
+
+// ---  11.6 API
+
+enum flash.display3D.Context3DMipFilter
+enum flash.display3D.Context3DTextureFilter
+enum flash.display3D.Context3DWrapMode
+enum flash.system.ApplicationInstallerMode
+
+@:require(flash11_6) flash.display3D.Context3D.setSamplerStateAt
+flash.display3D.Context3D.$wrap : Context3DWrapMode;
+flash.display3D.Context3D.$filter : Context3DTextureFilter;
+flash.display3D.Context3D.$mipfilter : Context3DMipFilter;
+
+-flash.display.DisplayObject.metaData
+
+@:require(flash11_6) flash.display.Graphics.readGraphicsData
+
+@:require(flash11_7) flash.media.StageVideo.attachAVStream;
+@:require(flash11_7) static flash.net.SharedObject.preventBackup;
+@:require(flash11_7) flash.system.AuthorizedFeatures.enableHLSPlayback;
+@:require(flash11_7) flash.system.AuthorizedFeaturesLoader.loadAuthorizedFeaturesFromData;
+
+

+ 183 - 183
doc/installer.nsi

@@ -1,183 +1,183 @@
-; Haxe/Neko Install script
-
-;--------------------------------
-
-!include "MUI.nsh"
-!include "LogicLib.nsh"
-!include "WordFunc.nsh"
-!include "winmessages.nsh"
-!include "EnvVarUpdate.nsh"
-
-;--------------------------------
-
-; Define version info
-!define VERSION "3.0.0"
-
-; Define Neko info
-!define NEKO_VERSION "2.0.0"
-
-; Installer details
-VIAddVersionKey "CompanyName" "Haxe Foundation"
-VIAddVersionKey "ProductName" "Haxe Installer"
-VIAddVersionKey "LegalCopyright" "Haxe Foundation 2005-2013"
-VIAddVersionKey "FileDescription" "Haxe Installer"
-VIAddVersionKey "ProductVersion" "${VERSION}.0"
-VIAddVersionKey "FileVersion" "${VERSION}.0"
-VIProductVersion "${VERSION}.0"
-
-; The name of the installer
-Name "Haxe ${VERSION}"
-
-; The captions of the installer
-Caption "Haxe ${VERSION} Setup"
-UninstallCaption "Haxe ${VERSION} Uninstall"
-
-; The file to write
-OutFile "haxe-${VERSION}-win.exe"
-
-; Default installation folder
-InstallDir "C:\HaxeToolkit\"
-
-; Define executable files
-!define EXECUTABLE "$INSTDIR\haxe\haxe.exe"
-!define HaxeLIB "$INSTDIR\Haxe\haxelib.exe"
-!define NEKOEXE "$INSTDIR\neko\neko.exe"
-
-; Vista redirects $SMPROGRAMS to all users without this
-RequestExecutionLevel admin
-
-; Use replace and version compare
-!insertmacro WordReplace
-!insertmacro VersionCompare
-
-; Required props
-SetFont /LANG=${LANG_ENGLISH} "Tahoma" 8
-SetCompressor /SOLID lzma
-CRCCheck on
-XPStyle on
-
-;--------------------------------
-
-; Interface Configuration
-
-!define MUI_HEADERIMAGE
-!define MUI_ABORTWARNING
-!define MUI_HEADERIMAGE_BITMAP "images\Banner.bmp"
-!define MUI_WELCOMEFINISHPAGE_BITMAP "images\Wizard.bmp"
-!define MUI_UNWELCOMEFINISHPAGE_BITMAP "images\Wizard.bmp"
-!define MUI_PAGE_HEADER_SUBTEXT "Please view the license before installing Haxe ${VERSION}."
-!define MUI_WELCOMEPAGE_TEXT "This wizard will guide you through the installation of $(^NameDA).\r\n\r\nIt is recommended that you close all other applications before starting Setup. This will make it possible to update relevant system files without having to reboot your computer.\r\n\r\n$_CLICK"
-
-;--------------------------------
-
-; Pages
-
-!insertmacro MUI_PAGE_WELCOME
-!insertmacro MUI_PAGE_COMPONENTS
-!insertmacro MUI_PAGE_DIRECTORY
-!insertmacro MUI_PAGE_INSTFILES
-!insertmacro MUI_PAGE_FINISH
-!insertmacro MUI_UNPAGE_WELCOME
-!insertmacro MUI_UNPAGE_CONFIRM
-!insertmacro MUI_UNPAGE_COMPONENTS
-!insertmacro MUI_UNPAGE_INSTFILES
-!insertmacro MUI_UNPAGE_FINISH
-!insertmacro MUI_LANGUAGE "English"
-
-;--------------------------------
-
-; InstallTypes
-
-InstType "Default"
-InstType "un.Default"
-InstType "un.Full"
-
-;--------------------------------
-
-; Functions
-
-
-
-Function .onInit
-
-
-
-FunctionEnd
-
-;--------------------------------
-
-; Install Sections
-
-!define env_hklm 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
-!define env_hkcu 'HKCU "Environment"'
-
-Section "Haxe ${VERSION}" Main
-
-	SectionIn 1 2 RO
-	SetOverwrite on
-
-	SetOutPath "$INSTDIR\haxe"
-
-	File /r /x .svn /x *.db /x Exceptions.log /x .local /x .multi /x *.pdb /x *.vshost.exe /x *.vshost.exe.config /x *.vshost.exe.manifest "resources\haxe\*.*"
-
-	ExecWait "$INSTDIR\haxe\haxesetup.exe -silent"
-
-	WriteUninstaller "$INSTDIR\Uninstall.exe"
-
-SectionEnd
-
-Section "Neko ${NEKO_VERSION}" Neko
-
-	SectionIn 1 2
-	SetOverwrite on
-
-	SetOutPath "$INSTDIR\neko"
-
-	File /r /x .svn /x *.db /x Exceptions.log /x .local /x .multi /x *.pdb /x *.vshost.exe /x *.vshost.exe.config /x *.vshost.exe.manifest "resources\neko\*.*"
-
-SectionEnd
-
-
-
-
-;--------------------------------
-
-; Install section strings
-
-!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
-!insertmacro MUI_DESCRIPTION_TEXT ${Main} "Installs Haxe and other core files."
-!insertmacro MUI_DESCRIPTION_TEXT ${Neko} "Installs Neko, which is required by various Haxe tools."
-!insertmacro MUI_FUNCTION_DESCRIPTION_END
-
-;--------------------------------
-
-; Uninstall Sections
-
-Section "un.Haxe" UninstMain
-
-	RMDir /r "$INSTDIR\haxe"
-	${un.EnvVarUpdate} $0 "PATH" "R" "HKCU" "%HAXEPATH%"
-	DeleteRegValue ${env_hkcu} HAXEPATH
-	SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
-
-SectionEnd
-
-Section "un.Neko" UninstNeko
-
-	RMDir /r "$INSTDIR\neko"
-	${un.EnvVarUpdate} $0 "PATH" "R" "HKCU" "%NEKO_INSTPATH%"
-	DeleteRegValue ${env_hkcu} NEKO_INSTPATH
-	SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
-
-SectionEnd
-
-;--------------------------------
-
-; Uninstall section strings
-
-!insertmacro MUI_UNFUNCTION_DESCRIPTION_BEGIN
-!insertmacro MUI_DESCRIPTION_TEXT ${UninstMain} "Uninstalls Haxe and other core files."
-!insertmacro MUI_DESCRIPTION_TEXT ${UninstNeko} "Uninstalls Neko."
-!insertmacro MUI_UNFUNCTION_DESCRIPTION_END
-
-;--------------------------------
+; Haxe/Neko Install script
+
+;--------------------------------
+
+!include "MUI.nsh"
+!include "LogicLib.nsh"
+!include "WordFunc.nsh"
+!include "winmessages.nsh"
+!include "EnvVarUpdate.nsh"
+
+;--------------------------------
+
+; Define version info
+!define VERSION "3.0.0"
+
+; Define Neko info
+!define NEKO_VERSION "2.0.0"
+
+; Installer details
+VIAddVersionKey "CompanyName" "Haxe Foundation"
+VIAddVersionKey "ProductName" "Haxe Installer"
+VIAddVersionKey "LegalCopyright" "Haxe Foundation 2005-2013"
+VIAddVersionKey "FileDescription" "Haxe Installer"
+VIAddVersionKey "ProductVersion" "${VERSION}.0"
+VIAddVersionKey "FileVersion" "${VERSION}.0"
+VIProductVersion "${VERSION}.0"
+
+; The name of the installer
+Name "Haxe ${VERSION}"
+
+; The captions of the installer
+Caption "Haxe ${VERSION} Setup"
+UninstallCaption "Haxe ${VERSION} Uninstall"
+
+; The file to write
+OutFile "haxe-${VERSION}-win.exe"
+
+; Default installation folder
+InstallDir "C:\HaxeToolkit\"
+
+; Define executable files
+!define EXECUTABLE "$INSTDIR\haxe\haxe.exe"
+!define HaxeLIB "$INSTDIR\Haxe\haxelib.exe"
+!define NEKOEXE "$INSTDIR\neko\neko.exe"
+
+; Vista redirects $SMPROGRAMS to all users without this
+RequestExecutionLevel admin
+
+; Use replace and version compare
+!insertmacro WordReplace
+!insertmacro VersionCompare
+
+; Required props
+SetFont /LANG=${LANG_ENGLISH} "Tahoma" 8
+SetCompressor /SOLID lzma
+CRCCheck on
+XPStyle on
+
+;--------------------------------
+
+; Interface Configuration
+
+!define MUI_HEADERIMAGE
+!define MUI_ABORTWARNING
+!define MUI_HEADERIMAGE_BITMAP "images\Banner.bmp"
+!define MUI_WELCOMEFINISHPAGE_BITMAP "images\Wizard.bmp"
+!define MUI_UNWELCOMEFINISHPAGE_BITMAP "images\Wizard.bmp"
+!define MUI_PAGE_HEADER_SUBTEXT "Please view the license before installing Haxe ${VERSION}."
+!define MUI_WELCOMEPAGE_TEXT "This wizard will guide you through the installation of $(^NameDA).\r\n\r\nIt is recommended that you close all other applications before starting Setup. This will make it possible to update relevant system files without having to reboot your computer.\r\n\r\n$_CLICK"
+
+;--------------------------------
+
+; Pages
+
+!insertmacro MUI_PAGE_WELCOME
+!insertmacro MUI_PAGE_COMPONENTS
+!insertmacro MUI_PAGE_DIRECTORY
+!insertmacro MUI_PAGE_INSTFILES
+!insertmacro MUI_PAGE_FINISH
+!insertmacro MUI_UNPAGE_WELCOME
+!insertmacro MUI_UNPAGE_CONFIRM
+!insertmacro MUI_UNPAGE_COMPONENTS
+!insertmacro MUI_UNPAGE_INSTFILES
+!insertmacro MUI_UNPAGE_FINISH
+!insertmacro MUI_LANGUAGE "English"
+
+;--------------------------------
+
+; InstallTypes
+
+InstType "Default"
+InstType "un.Default"
+InstType "un.Full"
+
+;--------------------------------
+
+; Functions
+
+
+
+Function .onInit
+
+
+
+FunctionEnd
+
+;--------------------------------
+
+; Install Sections
+
+!define env_hklm 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
+!define env_hkcu 'HKCU "Environment"'
+
+Section "Haxe ${VERSION}" Main
+
+	SectionIn 1 2 RO
+	SetOverwrite on
+
+	SetOutPath "$INSTDIR\haxe"
+
+	File /r /x .svn /x *.db /x Exceptions.log /x .local /x .multi /x *.pdb /x *.vshost.exe /x *.vshost.exe.config /x *.vshost.exe.manifest "resources\haxe\*.*"
+
+	ExecWait "$INSTDIR\haxe\haxesetup.exe -silent"
+
+	WriteUninstaller "$INSTDIR\Uninstall.exe"
+
+SectionEnd
+
+Section "Neko ${NEKO_VERSION}" Neko
+
+	SectionIn 1 2
+	SetOverwrite on
+
+	SetOutPath "$INSTDIR\neko"
+
+	File /r /x .svn /x *.db /x Exceptions.log /x .local /x .multi /x *.pdb /x *.vshost.exe /x *.vshost.exe.config /x *.vshost.exe.manifest "resources\neko\*.*"
+
+SectionEnd
+
+
+
+
+;--------------------------------
+
+; Install section strings
+
+!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
+!insertmacro MUI_DESCRIPTION_TEXT ${Main} "Installs Haxe and other core files."
+!insertmacro MUI_DESCRIPTION_TEXT ${Neko} "Installs Neko, which is required by various Haxe tools."
+!insertmacro MUI_FUNCTION_DESCRIPTION_END
+
+;--------------------------------
+
+; Uninstall Sections
+
+Section "un.Haxe" UninstMain
+
+	RMDir /r "$INSTDIR\haxe"
+	${un.EnvVarUpdate} $0 "PATH" "R" "HKCU" "%HAXEPATH%"
+	DeleteRegValue ${env_hkcu} HAXEPATH
+	SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
+
+SectionEnd
+
+Section "un.Neko" UninstNeko
+
+	RMDir /r "$INSTDIR\neko"
+	${un.EnvVarUpdate} $0 "PATH" "R" "HKCU" "%NEKO_INSTPATH%"
+	DeleteRegValue ${env_hkcu} NEKO_INSTPATH
+	SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
+
+SectionEnd
+
+;--------------------------------
+
+; Uninstall section strings
+
+!insertmacro MUI_UNFUNCTION_DESCRIPTION_BEGIN
+!insertmacro MUI_DESCRIPTION_TEXT ${UninstMain} "Uninstalls Haxe and other core files."
+!insertmacro MUI_DESCRIPTION_TEXT ${UninstNeko} "Uninstalls Neko."
+!insertmacro MUI_UNFUNCTION_DESCRIPTION_END
+
+;--------------------------------

+ 142 - 142
haxe.hxproj

@@ -1,143 +1,143 @@
-<?xml version="1.0" encoding="utf-8"?>
-<project version="2">
-  <!-- Output SWF options -->
-  <output>
-    <movie outputType="CustomBuild" />
-    <movie input="" />
-    <movie path="" />
-    <movie fps="30" />
-    <movie width="800" />
-    <movie height="600" />
-    <movie version="10" />
-    <movie minorVersion="3" />
-    <movie platform="Flash Player" />
-    <movie background="#FFFFFF" />
-  </output>
-  <!-- Other classes to be compiled into your SWF -->
-  <classpaths>
-    <!-- example: <class path="..." /> -->
-  </classpaths>
-  <!-- Build options -->
-  <build>
-    <option directives="" />
-    <option flashStrict="False" />
-    <option mainClass="" />
-    <option enabledebug="False" />
-    <option additional="" />
-  </build>
-  <!-- haxelib libraries -->
-  <haxelib>
-    <!-- example: <library name="..." /> -->
-  </haxelib>
-  <!-- Class files to compile (other referenced classes will automatically be included) -->
-  <compileTargets>
-    <!-- example: <compile path="..." /> -->
-  </compileTargets>
-  <!-- Assets to embed into the output SWF -->
-  <library>
-    <!-- example: <asset path="..." id="..." update="..." glyphs="..." mode="..." place="..." sharepoint="..." /> -->
-  </library>
-  <!-- Paths to exclude from the Project Explorer tree -->
-  <hiddenPaths>
-    <hidden path="ast.cmi" />
-    <hidden path="ast.cmx" />
-    <hidden path="typer.cmi" />
-    <hidden path="haxe.vcxproj.user" />
-    <hidden path="haxesetup.exe" />
-    <hidden path="interp.cmi" />
-    <hidden path="interp.cmx" />
-    <hidden path="interp.obj" />
-    <hidden path="lexer.cmi" />
-    <hidden path="lexer.cmx" />
-    <hidden path="lexer.ml" />
-    <hidden path="lexer.obj" />
-    <hidden path="main.cmi" />
-    <hidden path="main.cmx" />
-    <hidden path="main.obj" />
-    <hidden path="optimizer.cmi" />
-    <hidden path="optimizer.cmx" />
-    <hidden path="optimizer.obj" />
-    <hidden path="parser.cmi" />
-    <hidden path="parser.cmx" />
-    <hidden path="parser.obj" />
-    <hidden path="tmp.cmi" />
-    <hidden path="type.cmi" />
-    <hidden path="type.cmx" />
-    <hidden path="type.obj" />
-    <hidden path="typecore.cmi" />
-    <hidden path="typecore.cmx" />
-    <hidden path="typecore.obj" />
-    <hidden path="typeload.cmi" />
-    <hidden path="typeload.cmx" />
-    <hidden path="typeload.obj" />
-    <hidden path="haxe.vcproj" />
-    <hidden path="typer.obj" />
-    <hidden path="gencpp.cmi" />
-    <hidden path="gencpp.cmx" />
-    <hidden path="gencpp.obj" />
-    <hidden path="gencs.cmi" />
-    <hidden path="gencs.cmx" />
-    <hidden path="gencs.obj" />
-    <hidden path="genjava.cmi" />
-    <hidden path="genjava.cmx" />
-    <hidden path="genjava.obj" />
-    <hidden path="genjs.cmi" />
-    <hidden path="genjs.cmx" />
-    <hidden path="genjs.obj" />
-    <hidden path="genneko.cmi" />
-    <hidden path="genneko.cmx" />
-    <hidden path="genneko.obj" />
-    <hidden path="genphp.cmi" />
-    <hidden path="genphp.cmx" />
-    <hidden path="genphp.obj" />
-    <hidden path="genswf.cmi" />
-    <hidden path="genswf.cmx" />
-    <hidden path="genswf.obj" />
-    <hidden path="genswf8.cmi" />
-    <hidden path="genswf8.cmx" />
-    <hidden path="genswf8.obj" />
-    <hidden path="genswf9.cmi" />
-    <hidden path="genswf9.cmx" />
-    <hidden path="genswf9.obj" />
-    <hidden path="genxml.cmi" />
-    <hidden path="genxml.cmx" />
-    <hidden path="genxml.obj" />
-    <hidden path="haxe.exe" />
-    <hidden path="haxe.sdf" />
-    <hidden path="haxe.sln" />
-    <hidden path="haxe.suo" />
-    <hidden path="typer.cmx" />
-    <hidden path="gencommon.obj" />
-    <hidden path="codegen.cmi" />
-    <hidden path="codegen.cmx" />
-    <hidden path="codegen.obj" />
-    <hidden path="common.cmi" />
-    <hidden path="common.cmx" />
-    <hidden path="common.obj" />
-    <hidden path="dce.cmi" />
-    <hidden path="dce.cmx" />
-    <hidden path="dce.obj" />
-    <hidden path="genas3.cmi" />
-    <hidden path="genas3.cmx" />
-    <hidden path="genas3.obj" />
-    <hidden path="gencommon.cmi" />
-    <hidden path="gencommon.cmx" />
-    <hidden path="ast.obj" />
-    <hidden path="haxelib.exe" />
-    <hidden path="haxe.hxml" />
-    <hidden path="matcher.obj" />
-    <hidden path="matcher.cmx" />
-    <hidden path="matcher.cmi" />
-  </hiddenPaths>
-  <!-- Executed before build -->
-  <preBuildCommand>make -j4 MSVC=1 FD_OUTPUT=1 -f Makefile.win kill haxe</preBuildCommand>
-  <!-- Executed after build -->
-  <postBuildCommand alwaysRun="False" />
-  <!-- Other project options -->
-  <options>
-    <option showHiddenPaths="False" />
-    <option testMovie="Default" />
-  </options>
-  <!-- Plugin storage -->
-  <storage />
+<?xml version="1.0" encoding="utf-8"?>
+<project version="2">
+  <!-- Output SWF options -->
+  <output>
+    <movie outputType="CustomBuild" />
+    <movie input="" />
+    <movie path="" />
+    <movie fps="30" />
+    <movie width="800" />
+    <movie height="600" />
+    <movie version="10" />
+    <movie minorVersion="3" />
+    <movie platform="Flash Player" />
+    <movie background="#FFFFFF" />
+  </output>
+  <!-- Other classes to be compiled into your SWF -->
+  <classpaths>
+    <!-- example: <class path="..." /> -->
+  </classpaths>
+  <!-- Build options -->
+  <build>
+    <option directives="" />
+    <option flashStrict="False" />
+    <option mainClass="" />
+    <option enabledebug="False" />
+    <option additional="" />
+  </build>
+  <!-- haxelib libraries -->
+  <haxelib>
+    <!-- example: <library name="..." /> -->
+  </haxelib>
+  <!-- Class files to compile (other referenced classes will automatically be included) -->
+  <compileTargets>
+    <!-- example: <compile path="..." /> -->
+  </compileTargets>
+  <!-- Assets to embed into the output SWF -->
+  <library>
+    <!-- example: <asset path="..." id="..." update="..." glyphs="..." mode="..." place="..." sharepoint="..." /> -->
+  </library>
+  <!-- Paths to exclude from the Project Explorer tree -->
+  <hiddenPaths>
+    <hidden path="ast.cmi" />
+    <hidden path="ast.cmx" />
+    <hidden path="typer.cmi" />
+    <hidden path="haxe.vcxproj.user" />
+    <hidden path="haxesetup.exe" />
+    <hidden path="interp.cmi" />
+    <hidden path="interp.cmx" />
+    <hidden path="interp.obj" />
+    <hidden path="lexer.cmi" />
+    <hidden path="lexer.cmx" />
+    <hidden path="lexer.ml" />
+    <hidden path="lexer.obj" />
+    <hidden path="main.cmi" />
+    <hidden path="main.cmx" />
+    <hidden path="main.obj" />
+    <hidden path="optimizer.cmi" />
+    <hidden path="optimizer.cmx" />
+    <hidden path="optimizer.obj" />
+    <hidden path="parser.cmi" />
+    <hidden path="parser.cmx" />
+    <hidden path="parser.obj" />
+    <hidden path="tmp.cmi" />
+    <hidden path="type.cmi" />
+    <hidden path="type.cmx" />
+    <hidden path="type.obj" />
+    <hidden path="typecore.cmi" />
+    <hidden path="typecore.cmx" />
+    <hidden path="typecore.obj" />
+    <hidden path="typeload.cmi" />
+    <hidden path="typeload.cmx" />
+    <hidden path="typeload.obj" />
+    <hidden path="haxe.vcproj" />
+    <hidden path="typer.obj" />
+    <hidden path="gencpp.cmi" />
+    <hidden path="gencpp.cmx" />
+    <hidden path="gencpp.obj" />
+    <hidden path="gencs.cmi" />
+    <hidden path="gencs.cmx" />
+    <hidden path="gencs.obj" />
+    <hidden path="genjava.cmi" />
+    <hidden path="genjava.cmx" />
+    <hidden path="genjava.obj" />
+    <hidden path="genjs.cmi" />
+    <hidden path="genjs.cmx" />
+    <hidden path="genjs.obj" />
+    <hidden path="genneko.cmi" />
+    <hidden path="genneko.cmx" />
+    <hidden path="genneko.obj" />
+    <hidden path="genphp.cmi" />
+    <hidden path="genphp.cmx" />
+    <hidden path="genphp.obj" />
+    <hidden path="genswf.cmi" />
+    <hidden path="genswf.cmx" />
+    <hidden path="genswf.obj" />
+    <hidden path="genswf8.cmi" />
+    <hidden path="genswf8.cmx" />
+    <hidden path="genswf8.obj" />
+    <hidden path="genswf9.cmi" />
+    <hidden path="genswf9.cmx" />
+    <hidden path="genswf9.obj" />
+    <hidden path="genxml.cmi" />
+    <hidden path="genxml.cmx" />
+    <hidden path="genxml.obj" />
+    <hidden path="haxe.exe" />
+    <hidden path="haxe.sdf" />
+    <hidden path="haxe.sln" />
+    <hidden path="haxe.suo" />
+    <hidden path="typer.cmx" />
+    <hidden path="gencommon.obj" />
+    <hidden path="codegen.cmi" />
+    <hidden path="codegen.cmx" />
+    <hidden path="codegen.obj" />
+    <hidden path="common.cmi" />
+    <hidden path="common.cmx" />
+    <hidden path="common.obj" />
+    <hidden path="dce.cmi" />
+    <hidden path="dce.cmx" />
+    <hidden path="dce.obj" />
+    <hidden path="genas3.cmi" />
+    <hidden path="genas3.cmx" />
+    <hidden path="genas3.obj" />
+    <hidden path="gencommon.cmi" />
+    <hidden path="gencommon.cmx" />
+    <hidden path="ast.obj" />
+    <hidden path="haxelib.exe" />
+    <hidden path="haxe.hxml" />
+    <hidden path="matcher.obj" />
+    <hidden path="matcher.cmx" />
+    <hidden path="matcher.cmi" />
+  </hiddenPaths>
+  <!-- Executed before build -->
+  <preBuildCommand>make -j4 MSVC=1 FD_OUTPUT=1 -f Makefile.win kill haxe</preBuildCommand>
+  <!-- Executed after build -->
+  <postBuildCommand alwaysRun="False" />
+  <!-- Other project options -->
+  <options>
+    <option showHiddenPaths="False" />
+    <option testMovie="Default" />
+  </options>
+  <!-- Plugin storage -->
+  <storage />
 </project>

+ 4544 - 4544
interp.ml

@@ -1,4545 +1,4545 @@
-(*
- * Copyright (C)2005-2013 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *)
-
-open Common
-open Nast
-open Unix
-open Type
-
-(* ---------------------------------------------------------------------- *)
-(* TYPES *)
-
-type value =
-	| VNull
-	| VBool of bool
-	| VInt of int
-	| VFloat of float
-	| VString of string
-	| VObject of vobject
-	| VArray of value array
-	| VAbstract of vabstract
-	| VFunction of vfunction
-	| VClosure of value list * (value list -> value list -> value)
-	| VInt32 of int32
-
-and vobject = {
-	mutable ofields : (int * value) array;
-	mutable oproto : vobject option;
-}
-
-and vabstract =
-	| AKind of vabstract
-	| AHash of (value, value) Hashtbl.t
-	| ARandom of Random.State.t ref
-	| ABuffer of Buffer.t
-	| APos of Ast.pos
-	| AFRead of in_channel
-	| AFWrite of out_channel
-	| AReg of regexp
-	| AZipI of zlib
-	| AZipD of zlib
-	| AUtf8 of UTF8.Buf.buf
-	| ASocket of Unix.file_descr
-	| ATExpr of texpr
-	| ATDecl of module_type
-	| AUnsafe of Obj.t
-	| ALazyType of (unit -> Type.t) ref
-	| ANekoAbstract of Extc.value
-	| ANekoBuffer of value
-	| ACacheRef of value
-	| AInt32Kind
-
-and vfunction =
-	| Fun0 of (unit -> value)
-	| Fun1 of (value -> value)
-	| Fun2 of (value -> value -> value)
-	| Fun3 of (value -> value -> value -> value)
-	| Fun4 of (value -> value -> value -> value -> value)
-	| Fun5 of (value -> value -> value -> value -> value -> value)
-	| FunVar of (value list -> value)
-
-and regexp = {
-	r : Str.regexp;
-	mutable r_string : string;
-	mutable r_groups : (int * int) option array;
-}
-
-and zlib = {
-	z : Extc.zstream;
-	mutable z_flush : Extc.zflush;
-}
-
-type cmp =
-	| CEq
-	| CSup
-	| CInf
-	| CUndef
-
-type extern_api = {
-	pos : Ast.pos;
-	get_com : unit -> Common.context;
-	get_type : string -> Type.t option;
-	get_module : string -> Type.t list;
-	on_generate : (Type.t list -> unit) -> unit;
-	on_type_not_found : (string -> value) -> unit;
-	parse_string : string -> Ast.pos -> bool -> Ast.expr;
-	typeof : Ast.expr -> Type.t;
-	get_display : string -> string;
-	allow_package : string -> unit;
-	type_patch : string -> string -> bool -> string option -> unit;
-	meta_patch : string -> string -> string option -> bool -> unit;
-	set_js_generator : (value -> unit) -> unit;
-	get_local_type : unit -> t option;
-	get_local_method : unit -> string;
-	get_local_using : unit -> tclass list;
-	get_local_vars : unit -> (string, Type.tvar) PMap.t;
-	get_build_fields : unit -> value;
-	get_pattern_locals : Ast.expr -> Type.t -> (string,Type.tvar) PMap.t;
-	define_type : value -> unit;
-	module_dependency : string -> string -> bool -> unit;
-	current_module : unit -> module_def;
-	delayed_macro : int -> (unit -> (unit -> value));
-	use_cache : unit -> bool;
-}
-
-type callstack = {
-	cpos : pos;
-	cthis : value;
-	cstack : int;
-	cenv : value array;
-}
-
-type context = {
-	gen : Genneko.context;
-	types : (Type.path,int) Hashtbl.t;
-	prototypes : (string list, vobject) Hashtbl.t;
-	fields_cache : (int,string) Hashtbl.t;
-	mutable error : bool;
-	mutable error_proto : vobject;
-	mutable enums : (value * string) array array;
-	mutable do_call : value -> value -> value list -> pos -> value;
-	mutable do_string : value -> string;
-	mutable do_loadprim : value -> value -> value;
-	mutable do_compare : value -> value -> cmp;
-	mutable loader : value;
-	mutable exports : value;
-	(* runtime *)
-	mutable stack : value DynArray.t;
-	mutable callstack : callstack list;
-	mutable callsize : int;
-	mutable exc : pos list;
-	mutable vthis : value;
-	mutable venv : value array;
-	(* context *)
-	mutable curapi : extern_api;
-	mutable on_reused : (unit -> bool) list;
-	mutable is_reused : bool;
-	(* eval *)
-	mutable locals_map : (string, int) PMap.t;
-	mutable locals_count : int;
-	mutable locals_barrier : int;
-	mutable locals_env : string DynArray.t;
-	mutable globals : (string, value ref) PMap.t;
-}
-
-type access =
-	| AccThis
-	| AccLocal of int
-	| AccGlobal of value ref
-	| AccEnv of int
-	| AccField of (unit -> value) * string
-	| AccArray of (unit -> value) * (unit -> value)
-
-exception Runtime of value
-exception Builtin_error
-
-exception Error of string * Ast.pos list
-
-exception Abort
-exception Continue
-exception Break of value
-exception Return of value
-exception Invalid_expr
-
-(* ---------------------------------------------------------------------- *)
-(* UTILS *)
-
-let get_ctx_ref = ref (fun() -> assert false)
-let encode_complex_type_ref = ref (fun t -> assert false)
-let encode_type_ref = ref (fun t -> assert false)
-let decode_type_ref = ref (fun t -> assert false)
-let encode_expr_ref = ref (fun e -> assert false)
-let decode_expr_ref = ref (fun e -> assert false)
-let encode_clref_ref = ref (fun c -> assert false)
-let enc_hash_ref = ref (fun h -> assert false)
-let enc_array_ref = ref (fun l -> assert false)
-let enc_string_ref = ref (fun s -> assert false)
-let make_ast_ref = ref (fun _ -> assert false)
-let make_complex_type_ref = ref (fun _ -> assert false)
-let get_ctx() = (!get_ctx_ref)()
-let enc_array (l:value list) : value = (!enc_array_ref) l
-let encode_complex_type (t:Ast.complex_type) : value = (!encode_complex_type_ref) t
-let encode_type (t:Type.t) : value = (!encode_type_ref) t
-let decode_type (v:value) : Type.t = (!decode_type_ref) v
-let encode_expr (e:Ast.expr) : value = (!encode_expr_ref) e
-let decode_expr (e:value) : Ast.expr = (!decode_expr_ref) e
-let encode_clref (c:tclass) : value = (!encode_clref_ref) c
-let enc_hash (h:('a,'b) Hashtbl.t) : value = (!enc_hash_ref) h
-let make_ast (e:texpr) : Ast.expr = (!make_ast_ref) e
-let enc_string (s:string) : value = (!enc_string_ref) s
-let make_complex_type (t:Type.t) : Ast.complex_type = (!make_complex_type_ref) t
-
-let to_int f = Int32.of_float (mod_float f 2147483648.0)
-let need_32_bits i = Int32.compare (Int32.logand (Int32.add i 0x40000000l) 0x80000000l) Int32.zero <> 0
-let best_int i = if need_32_bits i then VInt32 i else VInt (Int32.to_int i)
-
-let make_pos p =
-	let low = p.pline land 0xFFFFF in
-	{
-		Ast.pfile = p.psource;
-		Ast.pmin = low;
-		Ast.pmax = low + (p.pline lsr 20);
-	}
-
-let warn ctx msg p =
-	(ctx.curapi.get_com()).Common.warning msg (make_pos p)
-
-let rec pop ctx n =
-	if n > 0 then begin
-		DynArray.delete_last ctx.stack;
-		pop ctx (n - 1);
-	end
-
-let pop_ret ctx f n =
-	let v = f() in
-	pop ctx n;
-	v
-
-let push ctx v =
-	DynArray.add ctx.stack v
-
-let hash f =
-	let h = ref 0 in
-	for i = 0 to String.length f - 1 do
-		h := !h * 223 + int_of_char (String.unsafe_get f i);
-	done;
-	if Sys.word_size = 64 then Int32.to_int (Int32.shift_right (Int32.shift_left (Int32.of_int !h) 1) 1) else !h
-
-let constants =
-	let h = Hashtbl.create 0 in
-	List.iter (fun f -> Hashtbl.add h (hash f) f)
-	["done";"read";"write";"min";"max";"file";"args";"loadprim";"loadmodule";"__a";"__s";"h";
-    "tag";"index";"length";"message";"pack";"name";"params";"sub";"doc";"kind";"meta";"access";
-	"constraints";"opt";"type";"value";"ret";"expr";"field";"values";"get";"__string";"toString";
-	"$";"add";"remove";"has";"__t";"module";"isPrivate";"isPublic";"isExtern";"isInterface";"exclude";
-	"constructs";"names";"superClass";"interfaces";"fields";"statics";"constructor";"init";"t";
-	"gid";"uid";"atime";"mtime";"ctime";"dev";"ino";"nlink";"rdev";"size";"mode";"pos";"len";
-	"binops";"unops";"from";"to";"array";"op";"isPostfix";"impl"];
-	h
-
-let h_get = hash "__get" and h_set = hash "__set"
-and h_add = hash "__add" and h_radd = hash "__radd"
-and h_sub = hash "__sub" and h_rsub = hash "__rsub"
-and h_mult = hash "__mult" and h_rmult = hash "__rmult"
-and h_div = hash "__div" and h_rdiv = hash "__rdiv"
-and h_mod = hash "__mod" and h_rmod = hash "__rmod"
-and h_string = hash "__string" and h_compare = hash "__compare"
-
-and h_constructs = hash "__constructs__" and h_a = hash "__a" and h_s = hash "__s"
-and h_class = hash "__class__"
-
-let exc v =
-	raise (Runtime v)
-
-let hash_field ctx f =
-	let h = hash f in
-	(try
-		let f2 = Hashtbl.find ctx.fields_cache h in
-		if f <> f2 then exc (VString ("Field conflict between " ^ f ^ " and " ^ f2));
-	with Not_found ->
-		Hashtbl.add ctx.fields_cache h f);
-	h
-
-let field_name ctx fid =
-	try
-		Hashtbl.find ctx.fields_cache fid
-	with Not_found ->
-		"???"
-
-let obj hash fields =
-	let fields = Array.of_list (List.map (fun (k,v) -> hash k, v) fields) in
-	Array.sort (fun (k1,_) (k2,_) -> compare k1 k2) fields;
-	{
-		ofields = fields;
-		oproto = None;
-	}
-
-let parse_int s =
-	let rec loop_hex i =
-		if i = String.length s then s else
-		match String.unsafe_get s i with
-		| '0'..'9' | 'a'..'f' | 'A'..'F' -> loop_hex (i + 1)
-		| _ -> String.sub s 0 i
-	in
-	let rec loop sp i =
-		if i = String.length s then (if sp = 0 then s else String.sub s sp (i - sp)) else
-		match String.unsafe_get s i with
-		| '0'..'9' -> loop sp (i + 1)
-		| ' ' when sp = i -> loop (sp + 1) (i + 1)
-		| '-' when i = 0 -> loop sp (i + 1)
-		| ('x' | 'X') when i = 1 && String.get s 0 = '0' -> loop_hex (i + 1)
-		| _ -> String.sub s sp (i - sp)
-	in
-	best_int (Int32.of_string (loop 0 0))
-
-let parse_float s =
-	let rec loop sp i =
-		if i = String.length s then (if sp = 0 then s else String.sub s sp (i - sp)) else
-		match String.unsafe_get s i with
-		| ' ' when sp = i -> loop (sp + 1) (i + 1)
-		| '0'..'9' | '-' | 'e' | 'E' | '.' -> loop sp (i + 1)
-		| _ -> String.sub s sp (i - sp)
-	in
-	float_of_string (loop 0 0)
-
-let find_sub str sub start =
-	let sublen = String.length sub in
-	if sublen = 0 then
-		0
-	else
-		let found = ref 0 in
-		let len = String.length str in
-		try
-			for i = start to len - sublen do
-				let j = ref 0 in
-				while String.unsafe_get str (i + !j) = String.unsafe_get sub !j do
-					incr j;
-					if !j = sublen then begin found := i; raise Exit; end;
-				done;
-			done;
-			raise Not_found
-		with
-			Exit -> !found
-
-let nargs = function
-	| Fun0 _ -> 0
-	| Fun1 _ -> 1
-	| Fun2 _ -> 2
-	| Fun3 _ -> 3
-	| Fun4 _ -> 4
-	| Fun5 _ -> 5
-	| FunVar _ -> -1
-
-let rec get_field o fid =
-	let rec loop min max =
-		if min < max then begin
-			let mid = (min + max) lsr 1 in
-			let cid, v = Array.unsafe_get o.ofields mid in
-			if cid < fid then
-				loop (mid + 1) max
-			else if cid > fid then
-				loop min mid
-			else
-				v
-		end else
-			match o.oproto with
-			| None -> VNull
-			| Some p -> get_field p fid
-	in
-	loop 0 (Array.length o.ofields)
-
-let set_field o fid v =
-	let rec loop min max =
-		let mid = (min + max) lsr 1 in
-		if min < max then begin
-			let cid, _ = Array.unsafe_get o.ofields mid in
-			if cid < fid then
-				loop (mid + 1) max
-			else if cid > fid then
-				loop min mid
-			else
-				Array.unsafe_set o.ofields mid (cid,v)
-		end else
-			let fields = Array.make (Array.length o.ofields + 1) (fid,v) in
-			Array.blit o.ofields 0 fields 0 mid;
-			Array.blit o.ofields mid fields (mid + 1) (Array.length o.ofields - mid);
-			o.ofields <- fields
-	in
-	loop 0 (Array.length o.ofields)
-
-let rec remove_field o fid =
-	let rec loop min max =
-		let mid = (min + max) lsr 1 in
-		if min < max then begin
-			let cid, v = Array.unsafe_get o.ofields mid in
-			if cid < fid then
-				loop (mid + 1) max
-			else if cid > fid then
-				loop min mid
-			else begin
-				let fields = Array.make (Array.length o.ofields - 1) (fid,VNull) in
-				Array.blit o.ofields 0 fields 0 mid;
-				Array.blit o.ofields (mid + 1) fields mid (Array.length o.ofields - mid - 1);
-				o.ofields <- fields;
-				true
-			end
-		end else
-			false
-	in
-	loop 0 (Array.length o.ofields)
-
-let rec get_field_opt o fid =
-	let rec loop min max =
-		if min < max then begin
-			let mid = (min + max) lsr 1 in
-			let cid, v = Array.unsafe_get o.ofields mid in
-			if cid < fid then
-				loop (mid + 1) max
-			else if cid > fid then
-				loop min mid
-			else
-				Some v
-		end else
-			match o.oproto with
-			| None -> None
-			| Some p -> get_field_opt p fid
-	in
-	loop 0 (Array.length o.ofields)
-
-let catch_errors ctx ?(final=(fun() -> ())) f =
-	let n = DynArray.length ctx.stack in
-	try
-		let v = f() in
-		final();
-		Some v
-	with Runtime v ->
-		pop ctx (DynArray.length ctx.stack - n);
-		final();
-		let rec loop o =
-			if o == ctx.error_proto then true else match o.oproto with None -> false | Some p -> loop p
-		in
-		(match v with
-		| VObject o when loop o ->
-			(match get_field o (hash "message"), get_field o (hash "pos") with
-			| VObject msg, VAbstract (APos pos) ->
-				(match get_field msg h_s with
-				| VString msg -> raise (Typecore.Error (Typecore.Custom msg,pos))
-				| _ -> ());
-			| _ -> ());
-		| _ -> ());
-		raise (Error (ctx.do_string v,List.map (fun s -> make_pos s.cpos) ctx.callstack))
-	| Abort ->
-		pop ctx (DynArray.length ctx.stack - n);
-		final();
-		None
-
-let make_library fl =
-	let h = Hashtbl.create 0 in
-	List.iter (fun (n,f) -> Hashtbl.add h n f) fl;
-	h
-
-(* ---------------------------------------------------------------------- *)
-(* NEKO INTEROP *)
-
-type primitive = (string * Extc.value * int)
-
-type neko_context = {
-	load : string -> int -> primitive;
-	call : primitive -> value list -> value;
-}
-
-let neko =
-	let is_win = Sys.os_type = "Win32" || Sys.os_type = "Cygwin" in
-	let neko = Extc.dlopen (if is_win then "neko.dll" else "libneko.so") in
-	let null = Extc.dlint 0 in
-	let neko = if Obj.magic neko == null && not is_win then Extc.dlopen "libneko.dylib" else neko in
-	if Obj.magic neko == null then
-		None
-	else
-	let load v =
-		let s = Extc.dlsym neko v in
-		if (Obj.magic s) == null then failwith ("Could not load neko." ^ v);
-		s
-	in
-	ignore(Extc.dlcall0 (load "neko_global_init"));
-	let vm = Extc.dlcall1 (load "neko_vm_alloc") null in
-	ignore(Extc.dlcall1 (load "neko_vm_select") vm);
-	let loader = Extc.dlcall2 (load "neko_default_loader") null null in
-	let loadprim = Extc.dlcall2 (load "neko_val_field") loader (Extc.dlcall1 (load "neko_val_id") (Extc.dlstring "loadprim")) in
-
-	let callN = load "neko_val_callN" in
-	let callEx = load "neko_val_callEx" in
-	let copy_string = load "neko_copy_string" in
-
-	let alloc_root = load "neko_alloc_root" in
-	let free_root = load "neko_free_root" in
-
-	let alloc_root v =
-		let r = Extc.dlcall1 alloc_root (Extc.dlint 1) in
-		Extc.dlsetptr r v;
-		r
-	in
-	let free_root r =
-		ignore(Extc.dlcall1 free_root r)
-	in
-
-	ignore(alloc_root vm);
-	ignore(alloc_root loader);
-	ignore(alloc_root loadprim);
-
-	let alloc_string s =
-		Extc.dlcall2 copy_string (Extc.dlstring s) (Extc.dlint (String.length s))
-	in
-	let alloc_int (i:int) : Extc.value =
-		Obj.magic i
-	in
-	let loadprim n args =
-		let exc = ref null in
-		let vargs = [|alloc_string n;alloc_int args|] in
-		let p = Extc.dlcall5 callEx loader loadprim (Obj.magic vargs) (Extc.dlint 2) (Obj.magic exc) in
-		if !exc != null then failwith ("Failed to load " ^ n ^ ":" ^ string_of_int args);
-		ignore(alloc_root p);
-		(n,p,args)
-	in
-	let call_raw_prim (_,p,nargs) (args:Extc.value array) =
-		Extc.dlcall3 callN p (Obj.magic args) (Extc.dlint nargs)
-	in
-
-	(* a bit tricky since load "val_true" does not work as expected on Windows *)
-	let unser = try loadprim "std@unserialize" 2 with _ -> ("",null,0) in
-
-	(* did we fail to load std.ndll ? *)
-	if (match unser with ("",_,_) -> true | _ -> false) then None else
-
-	let val_true = call_raw_prim unser [|alloc_string "T";loader|] in
-	let val_false = call_raw_prim unser [|alloc_string "F";loader|] in
-	let val_null = call_raw_prim unser [|alloc_string "N";loader|] in
-
-	let is_64 = call_raw_prim (loadprim "std@sys_is64" 0) [||] == val_true in
-	let alloc_i32, is_v2 = (try load "neko_alloc_int32", true with _ -> Obj.magic 0, false) in
-	let alloc_i32 = if is_v2 then
-		(fun i -> Extc.dlcall1 alloc_i32 (Extc.dlint32 i))
-	else
-		(fun i -> alloc_int (Int32.to_int (if Int32.compare i Int32.zero < 0 then Int32.logand i 0x7FFFFFFFl else Int32.logor i 0x80000000l)))
-	in
-	let tag_bits = if is_v2 then 4 else 3 in
-	let tag_mask = (1 lsl tag_bits) - 1 in
-	let ptr_size = if is_64 then 8 else 4 in
-	let val_field v i = Extc.dladdr v ((i + 1) * ptr_size) in
-	let val_str v = Extc.dladdr v 4 in
-	let val_fun_env v = Extc.dladdr v (8 + ptr_size) in
-
-	(* alloc support *)
-
-	let alloc_function = load "neko_alloc_function" in
-	let alloc_array = load "neko_alloc_array" in
-	let alloc_float = load "neko_alloc_float" in
-	let alloc_object = load "neko_alloc_object" in
-	let alloc_field = load "neko_alloc_field" in
-	let alloc_abstract = load "neko_alloc_abstract" in
-	let val_gc = load "neko_val_gc" in
-	let val_field_name = load "neko_val_field_name" in
-	let val_iter_fields = load "neko_val_iter_fields" in
-	let gen_callback = Extc.dlcaml_callback 2 in
-
-	(* roots *)
-
-	let on_abstract_gc = Extc.dlcaml_callback 1 in
-	let root_index = ref 0 in
-	let roots = Hashtbl.create 0 in
-	Callback.register "dlcallb1" (fun a ->
-		let index : int = Obj.magic (Extc.dlptr (val_field a 1)) in
-		Hashtbl.remove roots index;
-		null
-	);
-
-	(* wrapping *)
-
-	let copy_string v =
-		let head = Extc.dltoint (Extc.dlptr v) in
-		let size = head asr tag_bits in
-		let s = String.create size in
-		Extc.dlmemcpy (Extc.dlstring s) (val_str v) size;
-		s
-	in
-
-	let buffers = ref [] in
-
-	let rec value_neko ?(obj=VNull) = function
-		| VNull -> val_null
-		| VBool b -> if b then val_true else val_false
-		| VInt i -> alloc_int i
-		| VAbstract (ANekoAbstract a) -> a
-		| VAbstract (ANekoBuffer (VString buf)) ->
-			let v = value_neko (VString buf) in
-			buffers := (buf,v) :: !buffers;
-			v
-		| VString s ->
-			let v = alloc_string s in (* make a copy *)
-			ignore(copy_string v);
-			v
-		| VObject o as obj ->
-			let vo = Extc.dlcall1 alloc_object null in
-			Array.iter (fun (id,v) ->
-				ignore(Extc.dlcall3 alloc_field vo (Extc.dlint id) (value_neko ~obj v))
-			) o.ofields;
-			vo
-		| VClosure _ ->
-			failwith "Closure not supported"
-		| VFunction f ->
-			let callb = Extc.dlcall3 alloc_function gen_callback (Extc.dlint (-1)) (Obj.magic "<callback>") in
-			let index = !root_index in
-			incr root_index;
-			Hashtbl.add roots index (f,obj);
-			let a = Extc.dlcall2 alloc_abstract null (Obj.magic index) in
-			if Extc.dlptr (val_field a 1) != Obj.magic index then assert false;
-			ignore(Extc.dlcall2 val_gc a on_abstract_gc);
-			Extc.dlsetptr (val_fun_env callb) a;
-			callb
-		| VArray a ->
-			let va = Extc.dlcall1 alloc_array (Extc.dlint (Array.length a)) in
-			Array.iteri (fun i v ->
-				Extc.dlsetptr (val_field va i) (value_neko v)
-			) a;
-			va
-		| VFloat f ->
-			Extc.dlcall1 alloc_float (Obj.magic f)
-		| VAbstract _ ->
-			failwith "Abstract not supported"
-		| VInt32 i ->
-			alloc_i32 i
-	in
-	let obj_r = ref [] in
-	let obj_fun = (fun v id -> obj_r := (v,id) :: !obj_r; val_null) in
-	let rec neko_value (v:Extc.value) =
-		if Obj.is_int (Obj.magic v) then
-			VInt (Obj.magic v)
-		else
-			let head = Extc.dltoint (Extc.dlptr v) in
-			match head land tag_mask with
-			| 0 -> VNull
-			| 2 -> VBool (v == val_true)
-			| 3 -> VString (copy_string v)
-			| 4 ->
-				ignore(Extc.dlcall3 val_iter_fields v (Extc.dlcallback 2) (Obj.magic obj_fun));
-				let r = !obj_r in
-				obj_r := [];
-				let ctx = get_ctx() in
-				let fields = List.rev_map (fun (v,id) ->
-					let iid = Extc.dltoint id in
-					if not (Hashtbl.mem ctx.fields_cache iid) then begin
-						let name = copy_string (Extc.dlcall1 val_field_name id) in
-						ignore(hash_field ctx name);
-					end;
-					iid, neko_value v
-				) r in
-				VObject { ofields = Array.of_list fields; oproto = None }
-			| 5 ->
-				VArray (Array.init (head asr tag_bits) (fun i -> neko_value (Extc.dlptr (val_field v i))))
-			| 7 ->
-				let r = alloc_root v in
-				let a = ANekoAbstract v in
-				Gc.finalise (fun _ -> free_root r) a;
-				VAbstract a
-			| t ->
-				failwith ("Unsupported Neko value tag " ^ string_of_int t)
-	in
-
-	Callback.register "dlcallb2" (fun args nargs ->
-		(* get back the VM env, which was set in value_neko *)
-		let env = Extc.dlptr (Extc.dladdr vm (2 * ptr_size)) in
-		(* extract the index stored in abstract data *)
-		let index : int = Obj.magic (Extc.dlptr (val_field env 1)) in
-		let f, obj = (try Hashtbl.find roots index with Not_found -> assert false) in
-		let nargs = Extc.dltoint nargs in
-		let rec loop i =
-			if i = nargs then [] else neko_value (Extc.dlptr (Extc.dladdr args (i * ptr_size))) :: loop (i + 1)
-		in
-		let v = (get_ctx()).do_call obj (VFunction f) (loop 0) { psource = "<callback>"; pline = 0; } in
-		value_neko v
-	);
-
-	let callprim (n,p,nargs) args =
-		let arr = Array.of_list (List.map value_neko args) in
-		let exc = ref null in
-		if Array.length arr <> nargs then failwith n;
-		let ret = Extc.dlcall5 callEx val_null p (Obj.magic arr) (Extc.dlint nargs) (Obj.magic exc) in
-		if !exc != null then raise (Runtime (neko_value !exc));
-		(match !buffers with
-		| [] -> ()
-		| l ->
-			buffers := [];
-			(* copy back data *)
-			List.iter (fun (buf,v) ->
-				Extc.dlmemcpy (Extc.dlstring buf) (val_str v) (String.length buf);
-			) l);
-		neko_value ret
-	in
-	Some {
-		load = loadprim;
-		call = callprim;
-	}
-
-(* ---------------------------------------------------------------------- *)
-(* BUILTINS *)
-
-let builtins =
-	let p = { psource = "<builtin>"; pline = 0 } in
-	let error() =
-		raise Builtin_error
-	in
-	let vint = function
-		| VInt n -> n
-		| _ -> error()
-	in
-	let varray = function
-		| VArray a -> a
-		| _ -> error()
-	in
-	let vstring = function
-		| VString s -> s
-		| _ -> error()
-	in
-	let vobj = function
-		| VObject o -> o
-		| _ -> error()
-	in
-	let vfun = function
-		| VFunction f -> f
-		| VClosure (cl,f) -> FunVar (f cl)
-		| _ -> error()
-	in
-	let vhash = function
-		| VAbstract (AHash h) -> h
-		| _ -> error()
-	in
-	let build_stack sl =
-		let make p =
-			let p = make_pos p in
-			VArray [|VString p.Ast.pfile;VInt (Lexer.get_error_line p)|]
-		in
-		VArray (Array.of_list (List.map make sl))
-	in
-	let do_closure args args2 =
-		match args with
-		| f :: obj :: args ->
-			(get_ctx()).do_call obj f (args @ args2) p
-		| _ ->
-			assert false
-	in
-	let funcs = [
-	(* array *)
-		"array", FunVar (fun vl -> VArray (Array.of_list vl));
-		"amake", Fun1 (fun v -> VArray (Array.create (vint v) VNull));
-		"acopy", Fun1 (fun a -> VArray (Array.copy (varray a)));
-		"asize", Fun1 (fun a -> VInt (Array.length (varray a)));
-		"asub", Fun3 (fun a p l -> VArray (Array.sub (varray a) (vint p) (vint l)));
-		"ablit", Fun5 (fun dst dstp src p l ->
-			Array.blit (varray src) (vint p) (varray dst) (vint dstp) (vint l);
-			VNull
-		);
-		"aconcat", Fun1 (fun arr ->
-			let arr = Array.map varray (varray arr) in
-			VArray (Array.concat (Array.to_list arr))
-		);
-	(* string *)
-		"string", Fun1 (fun v -> VString ((get_ctx()).do_string v));
-		"smake", Fun1 (fun l -> VString (String.make (vint l) '\000'));
-		"ssize", Fun1 (fun s -> VInt (String.length (vstring s)));
-		"scopy", Fun1 (fun s -> VString (String.copy (vstring s)));
-		"ssub", Fun3 (fun s p l -> VString (String.sub (vstring s) (vint p) (vint l)));
-		"sget", Fun2 (fun s p ->
-			try VInt (int_of_char (String.get (vstring s) (vint p))) with Invalid_argument _ -> VNull
-		);
-		"sset", Fun3 (fun s p c ->
-			let c = char_of_int ((vint c) land 0xFF) in
-			try
-				String.set (vstring s) (vint p) c;
-				VInt (int_of_char c)
-			with Invalid_argument _ -> VNull);
-		"sblit", Fun5 (fun dst dstp src p l ->
-			String.blit (vstring src) (vint p) (vstring dst) (vint dstp) (vint l);
-			VNull
-		);
-		"sfind", Fun3 (fun src pos pat ->
-			try VInt (find_sub (vstring src) (vstring pat) (vint pos)) with Not_found -> VNull
-		);
-	(* object *)
-		"new", Fun1 (fun o ->
-			match o with
-			| VNull -> VObject { ofields = [||]; oproto = None }
-			| VObject o -> VObject { ofields = Array.copy o.ofields; oproto = o.oproto }
-			| _ -> error()
-		);
-		"objget", Fun2 (fun o f ->
-			match o with
-			| VObject o -> get_field o (vint f)
-			| _ -> VNull
-		);
-		"objset", Fun3 (fun o f v ->
-			match o with
-			| VObject o -> set_field o (vint f) v; v
-			| _ -> VNull
-		);
-		"objcall", Fun3 (fun o f pl ->
-			match o with
-			| VObject oo ->
-				(get_ctx()).do_call o (get_field oo (vint f)) (Array.to_list (varray pl)) p
-			| _ -> VNull
-		);
-		"objfield", Fun2 (fun o f ->
-			match o with
-			| VObject o ->
-				let p = o.oproto in
-				o.oproto <- None;
-				let v = get_field_opt o (vint f) in
-				o.oproto <- p;
-				VBool (v <> None)
-			| _ -> VBool false
-		);
-		"objremove", Fun2 (fun o f ->
-			VBool (remove_field (vobj o) (vint f))
-		);
-		"objfields", Fun1 (fun o ->
-			VArray (Array.map (fun (fid,_) -> VInt fid) (vobj o).ofields)
-		);
-		"hash", Fun1 (fun v -> VInt (hash_field (get_ctx()) (vstring v)));
-		"fasthash", Fun1 (fun v -> VInt (hash (vstring v)));
-		"field", Fun1 (fun v ->
-			try VString (Hashtbl.find (get_ctx()).fields_cache (vint v)) with Not_found -> VNull
-		);
-		"objsetproto", Fun2 (fun o p ->
-			let o = vobj o in
-			(match p with
-			| VNull -> o.oproto <- None
-			| VObject p -> o.oproto <- Some p
-			| _ -> error());
-			VNull;
-		);
-		"objgetproto", Fun1 (fun o ->
-			match (vobj o).oproto with
-			| None -> VNull
-			| Some p -> VObject p
-		);
-	(* function *)
-		"nargs", Fun1 (fun f ->
-			VInt (nargs (vfun f))
-		);
-		"call", Fun3 (fun f o args ->
-			(get_ctx()).do_call o f (Array.to_list (varray args)) p
-		);
-		"closure", FunVar (fun vl ->
-			match vl with
-			| VFunction f :: _ :: _ ->
-				VClosure (vl, do_closure)
-			| _ -> exc (VString "Can't create closure : value is not a function")
-		);
-		"apply", FunVar (fun vl ->
-			match vl with
-			| f :: args ->
-				let f = vfun f in
-				VFunction (FunVar (fun args2 -> (get_ctx()).do_call VNull (VFunction f) (args @ args2) p))
-			| _ -> exc (VString "Invalid closure arguments number")
-		);
-		"varargs", Fun1 (fun f ->
-			match f with
-			| VFunction (FunVar _) | VFunction (Fun1 _) | VClosure _ ->
-				VFunction (FunVar (fun vl -> (get_ctx()).do_call VNull f [VArray (Array.of_list vl)] p))
-			| _ ->
-				error()
-		);
-	(* numbers *)
-		(* skip iadd, isub, idiv, imult *)
-		"isnan", Fun1 (fun f ->
-			match f with
-			| VFloat f -> VBool (f <> f)
-			| _ -> VBool false
-		);
-		"isinfinite", Fun1 (fun f ->
-			match f with
-			| VFloat f -> VBool (f = infinity || f = neg_infinity)
-			| _ -> VBool false
-		);
-		"int", Fun1 (fun v ->
-			match v with
-			| VInt _ | VInt32 _ -> v
-			| VFloat f -> best_int (to_int f)
-			| VString s -> (try parse_int s with _ -> VNull)
-			| _ -> VNull
-		);
-		"float", Fun1 (fun v ->
-			match v with
-			| VInt i -> VFloat (float_of_int i)
-			| VInt32 i -> VFloat (Int32.to_float i)
-			| VFloat _ -> v
-			| VString s -> (try VFloat (parse_float s) with _ -> VNull)
-			| _ -> VNull
-		);
-	(* abstract *)
-		"getkind", Fun1 (fun v ->
-			match v with
-			| VAbstract a -> VAbstract (AKind a)
-			| VInt32 _ -> VAbstract (AKind AInt32Kind)
-			| _ -> error()
-		);
-		"iskind", Fun2 (fun v k ->
-			match v, k with
-			| VAbstract a, VAbstract (AKind k) -> VBool (Obj.tag (Obj.repr a) = Obj.tag (Obj.repr k))
-			| VInt32 _, VAbstract (AKind AInt32Kind) -> VBool true
-			| _, VAbstract (AKind _) -> VBool false
-			| _ -> error()
-		);
-	(* hash *)
-		"hkey", Fun1 (fun v -> VInt (Hashtbl.hash v));
-		"hnew", Fun1 (fun v ->
-			VAbstract (AHash (match v with
-			| VNull -> Hashtbl.create 0
-			| VInt n -> Hashtbl.create n
-			| _ -> error()))
-		);
-		"hresize", Fun1 (fun v -> VNull);
-		"hget", Fun3 (fun h k cmp ->
-			if cmp <> VNull then assert false;
-			(try Hashtbl.find (vhash h) k with Not_found -> VNull)
-		);
-		"hmem", Fun3 (fun h k cmp ->
-			if cmp <> VNull then assert false;
-			VBool (Hashtbl.mem (vhash h) k)
-		);
-		"hremove", Fun3 (fun h k cmp ->
-			if cmp <> VNull then assert false;
-			let h = vhash h in
-			let old = Hashtbl.mem h k in
-			if old then Hashtbl.remove h k;
-			VBool old
-		);
-		"hset", Fun4 (fun h k v cmp ->
-			if cmp <> VNull then assert false;
-			let h = vhash h in
-			let old = Hashtbl.mem h k in
-			Hashtbl.replace h k v;
-			VBool (not old);
-		);
-		"hadd", Fun4 (fun h k v cmp ->
-			if cmp <> VNull then assert false;
-			let h = vhash h in
-			let old = Hashtbl.mem h k in
-			Hashtbl.add h k v;
-			VBool (not old);
-		);
-		"hiter", Fun2 (fun h f -> Hashtbl.iter (fun k v -> ignore ((get_ctx()).do_call VNull f [k;v] p)) (vhash h); VNull);
-		"hcount", Fun1 (fun h -> VInt (Hashtbl.length (vhash h)));
-		"hsize", Fun1 (fun h -> VInt (Hashtbl.length (vhash h)));
-	(* misc *)
-		"print", FunVar (fun vl -> List.iter (fun v ->
-			let ctx = get_ctx() in
-			let com = ctx.curapi.get_com() in
-			com.print (ctx.do_string v)
-		) vl; VNull);
-		"throw", Fun1 (fun v -> exc v);
-		"rethrow", Fun1 (fun v ->
-			let ctx = get_ctx() in
-			ctx.callstack <- List.rev (List.map (fun p -> { cpos = p; cthis = ctx.vthis; cstack = DynArray.length ctx.stack; cenv = ctx.venv }) ctx.exc) @ ctx.callstack;
-			exc v
-		);
-		"istrue", Fun1 (fun v ->
-			match v with
-			| VNull | VInt 0 | VBool false | VInt32 0l -> VBool false
-			| _ -> VBool true
-		);
-		"not", Fun1 (fun v ->
-			match v with
-			| VNull | VInt 0 | VBool false | VInt32 0l -> VBool true
-			| _ -> VBool false
-		);
-		"typeof", Fun1 (fun v ->
-			VInt (match v with
-			| VNull -> 0
-			| VInt _ | VInt32 _ -> 1
-			| VFloat _ -> 2
-			| VBool _ -> 3
-			| VString _ -> 4
-			| VObject _ -> 5
-			| VArray _ -> 6
-			| VFunction _ | VClosure _ -> 7
-			| VAbstract _ -> 8)
-		);
-		"compare", Fun2 (fun a b ->
-			match (get_ctx()).do_compare a b with
-			| CUndef -> VNull
-			| CEq -> VInt 0
-			| CSup -> VInt 1
-			| CInf -> VInt (-1)
-		);
-		"pcompare", Fun2 (fun a b ->
-	 		assert false
-	 	);
-	 	"excstack", Fun0 (fun() ->
-			build_stack (get_ctx()).exc
-	 	);
-	 	"callstack", Fun0 (fun() ->
-	 		build_stack (List.map (fun s -> s.cpos) (get_ctx()).callstack)
-	 	);
-	 	"version", Fun0 (fun() ->
-	 		VInt 200
-	 	);
-	(* extra *)
-		"use_neko_dll", Fun0 (fun() ->
-			VBool (neko <> None)
-		);
-	] in
-	let vals = [
-		"tnull", VInt 0;
-		"tint", VInt 1;
-		"tfloat", VInt 2;
-		"tbool", VInt 3;
-		"tstring", VInt 4;
-		"tobject", VInt 5;
-		"tarray", VInt 6;
-		"tfunction", VInt 7;
-		"tabstract", VInt 8;
-	] in
-	let h = Hashtbl.create 0 in
-	List.iter (fun (n,f) -> Hashtbl.add h n (VFunction f)) funcs;
-	List.iter (fun (n,v) -> Hashtbl.add h n v) vals;
-	h
-
-(* ---------------------------------------------------------------------- *)
-(* STD LIBRARY *)
-
-let std_lib =
-	let p = { psource = "<stdlib>"; pline = 0 } in
-	let error() =
-		raise Builtin_error
-	in
-	let make_list l =
-		let rec loop acc = function
-			| [] -> acc
-			| x :: l -> loop (VArray [|x;acc|]) l
-		in
-		loop VNull (List.rev l)
-	in
-	let num = function
-		| VInt i -> float_of_int i
-		| VInt32 i -> Int32.to_float i
-		| VFloat f -> f
-		| _ -> error()
-	in
-	let make_date f =
-		VInt32 (Int32.of_float f)
-	in
-	let date = function
-		| VInt32 i -> Int32.to_float i
-		| VInt i -> float_of_int i
-		| _ -> error()
-	in
-	let make_i32 i =
-		VInt32 i
-	in
-	let int32 = function
-		| VInt i -> Int32.of_int i
-		| VInt32 i -> i
-		| _ -> error()
-	in
-	let vint = function
-		| VInt n -> n
-		| _ -> error()
-	in
-	let vstring = function
-		| VString s -> s
-		| _ -> error()
-	in
-	let int32_addr h =
-		let base = Int32.to_int (Int32.logand h 0xFFFFFFl) in
-		let str = Printf.sprintf "%ld.%d.%d.%d" (Int32.shift_right_logical h 24) (base lsr 16) ((base lsr 8) land 0xFF) (base land 0xFF) in
-		Unix.inet_addr_of_string str
-	in
-	let int32_op op = Fun2 (fun a b -> make_i32 (op (int32 a) (int32 b))) in
-	make_library ([
-	(* math *)
-		"math_atan2", Fun2 (fun a b -> VFloat (atan2 (num a) (num b)));
-		"math_pow", Fun2 (fun a b -> VFloat ((num a) ** (num b)));
-		"math_abs", Fun1 (fun v ->
-			match v with
-			| VInt i -> VInt (abs i)
-			| VInt32 i -> VInt32 (Int32.abs i)
-			| VFloat f -> VFloat (abs_float f)
-			| _ -> error()
-		);
-		"math_ceil", Fun1 (fun v -> match v with VInt _ | VInt32 _ -> v | _ -> best_int (to_int (ceil (num v))));
-		"math_floor", Fun1 (fun v -> match v with VInt _ | VInt32 _ -> v | _ -> best_int (to_int (floor (num v))));
-		"math_round", Fun1 (fun v -> match v with VInt _ | VInt32 _ -> v | _ -> best_int (to_int (floor (num v +. 0.5))));
-		"math_pi", Fun0 (fun() -> VFloat (4.0 *. atan 1.0));
-		"math_sqrt", Fun1 (fun v -> VFloat (sqrt (num v)));
-		"math_atan", Fun1 (fun v -> VFloat (atan (num v)));
-		"math_cos", Fun1 (fun v -> VFloat (cos (num v)));
-		"math_sin", Fun1 (fun v -> VFloat (sin (num v)));
-		"math_tan", Fun1 (fun v -> VFloat (tan (num v)));
-		"math_log", Fun1 (fun v -> VFloat (Pervasives.log (num v)));
-		"math_exp", Fun1 (fun v -> VFloat (exp (num v)));
-		"math_acos", Fun1 (fun v -> VFloat (acos (num v)));
-		"math_asin", Fun1 (fun v -> VFloat (asin (num v)));
-		"math_fceil", Fun1 (fun v -> VFloat (ceil (num v)));
-		"math_ffloor", Fun1 (fun v -> VFloat (floor (num v)));
-		"math_fround", Fun1 (fun v -> VFloat (floor (num v +. 0.5)));
-		"math_int", Fun1 (fun v ->
-			match v with
-			| VInt _ | VInt32 _ -> v
-			| VFloat f -> best_int (to_int (if f < 0. then ceil f else floor f))
-			| _ -> error()
-		);
-	(* buffer *)
-		"buffer_new", Fun0 (fun() ->
-			VAbstract (ABuffer (Buffer.create 0))
-		);
-		"buffer_add", Fun2 (fun b v ->
-			match b with
-			| VAbstract (ABuffer b) -> Buffer.add_string b ((get_ctx()).do_string v); VNull
-			| _ -> error()
-		);
-		"buffer_add_char", Fun2 (fun b v ->
-			match b, v with
-			| VAbstract (ABuffer b), VInt n when n >= 0 && n < 256 -> Buffer.add_char b (char_of_int n); VNull
-			| _ -> error()
-		);
-		"buffer_add_sub", Fun4 (fun b s p l ->
-			match b, s, p, l with
-			| VAbstract (ABuffer b), VString s, VInt p, VInt l -> (try Buffer.add_substring b s p l; VNull with _ -> error())
-			| _ -> error()
-		);
-		"buffer_string", Fun1 (fun b ->
-			match b with
-			| VAbstract (ABuffer b) -> VString (Buffer.contents b)
-			| _ -> error()
-		);
-		"buffer_reset", Fun1 (fun b ->
-			match b with
-			| VAbstract (ABuffer b) -> Buffer.reset b; VNull;
-			| _ -> error()
-		);
-	(* date *)
-		"date_now", Fun0 (fun () ->
-			make_date (Unix.time())
-		);
-		"date_new", Fun1 (fun v ->
-			make_date (match v with
-			| VNull -> Unix.time()
-			| VString s ->
-				(match String.length s with
-				| 19 ->
-					let r = Str.regexp "^\\([0-9][0-9][0-9][0-9]\\)-\\([0-9][0-9]\\)-\\([0-9][0-9]\\) \\([0-9][0-9]\\):\\([0-9][0-9]\\):\\([0-9][0-9]\\)$" in
-					if not (Str.string_match r s 0) then exc (VString ("Invalid date format : " ^ s));
-					let t = Unix.localtime (Unix.time()) in
-					let t = { t with
-						tm_year = int_of_string (Str.matched_group 1 s) - 1900;
-						tm_mon = int_of_string (Str.matched_group 2 s) - 1;
-						tm_mday = int_of_string (Str.matched_group 3 s);
-						tm_hour = int_of_string (Str.matched_group 4 s);
-						tm_min = int_of_string (Str.matched_group 5 s);
-						tm_sec = int_of_string (Str.matched_group 6 s);
-					} in
-					fst (Unix.mktime t)
-				| 10 ->
-					assert false
-				| 8 ->
-					assert false
-				| _ ->
-					exc (VString ("Invalid date format : " ^ s)));
-			| _ -> error())
-		);
-		"date_set_hour", Fun4 (fun d h m s ->
-			let d = date d in
-			let t = Unix.localtime d in
-			make_date (fst (Unix.mktime { t with tm_hour = vint h; tm_min = vint m; tm_sec = vint s }))
-		);
-		"date_set_day", Fun4 (fun d y m da ->
-			let d = date d in
-			let t = Unix.localtime d in
-			make_date (fst (Unix.mktime { t with tm_year = vint y - 1900; tm_mon = vint m - 1; tm_mday = vint da }))
-		);
-		"date_format", Fun2 (fun d fmt ->
-			match fmt with
-			| VNull ->
-				let t = Unix.localtime (date d) in
-				VString (Printf.sprintf "%.4d-%.2d-%.2d %.2d:%.2d:%.2d" (t.tm_year + 1900) (t.tm_mon + 1) t.tm_mday t.tm_hour t.tm_min t.tm_sec)
-			| VString "%w" ->
-				(* week day *)
-				let t = Unix.localtime (date d) in
-				VString (string_of_int t.tm_wday)
-			| VString _ ->
-				exc (VString "Custom date format is not supported") (* use native Haxe implementation *)
-			| _ ->
-				error()
-		);
-		"date_get_hour", Fun1 (fun d ->
-			let t = Unix.localtime (date d) in
-			let o = obj (hash_field (get_ctx())) [
-				"h", VInt t.tm_hour;
-				"m", VInt t.tm_min;
-				"s", VInt t.tm_sec;
-			] in
-			VObject o
-		);
-		"date_get_day", Fun1 (fun d ->
-			let t = Unix.localtime (date d) in
-			let o = obj (hash_field (get_ctx())) [
-				"d", VInt t.tm_mday;
-				"m", VInt (t.tm_mon + 1);
-				"y", VInt (t.tm_year + 1900);
-			] in
-			VObject o
-		);
-	(* string *)
-		"string_split", Fun2 (fun s d ->
-			make_list (match s, d with
-			| VString "", VString _ -> [VString ""]
-			| VString s, VString "" -> Array.to_list (Array.init (String.length s) (fun i -> VString (String.make 1 (String.get s i))))
-			| VString s, VString d -> List.map (fun s -> VString s) (ExtString.String.nsplit s d)
-			| _ -> error())
-		);
-		"url_encode", Fun1 (fun s ->
-			let s = vstring s in
-			let b = Buffer.create 0 in
-			let hex = "0123456789ABCDEF" in
-			for i = 0 to String.length s - 1 do
-				let c = String.unsafe_get s i in
-				match c with
-				| 'A'..'Z' | 'a'..'z' | '0'..'9' | '_' | '-' | '.' ->
-					Buffer.add_char b c
-				| _ ->
-					Buffer.add_char b '%';
-					Buffer.add_char b (String.unsafe_get hex (int_of_char c lsr 4));
-					Buffer.add_char b (String.unsafe_get hex (int_of_char c land 0xF));
-			done;
-			VString (Buffer.contents b)
-		);
-		"url_decode", Fun1 (fun s ->
-			let s = vstring s in
-			let b = Buffer.create 0 in
-			let len = String.length s in
-			let decode c =
-				match c with
-				| '0'..'9' -> Some (int_of_char c - int_of_char '0')
-				| 'a'..'f' -> Some (int_of_char c - int_of_char 'a' + 10)
-				| 'A'..'F' -> Some (int_of_char c - int_of_char 'A' + 10)
-				| _ -> None
-			in
-			let rec loop i =
-				if i = len then () else
-				let c = String.unsafe_get s i in
-				match c with
-				| '%' ->
-					let p1 = (try decode (String.get s (i + 1)) with _ -> None) in
-					let p2 = (try decode (String.get s (i + 2)) with _ -> None) in
-					(match p1, p2 with
-					| Some c1, Some c2 ->
-						Buffer.add_char b (char_of_int ((c1 lsl 4) lor c2));
-						loop (i + 3)
-					| _ ->
-						loop (i + 1));
-				| '+' ->
-					Buffer.add_char b ' ';
-					loop (i + 1)
-				| c ->
-					Buffer.add_char b c;
-					loop (i + 1)
-			in
-			loop 0;
-			VString (Buffer.contents b)
-		);
-		"base_encode", Fun2 (fun s b ->
-			match s, b with
-			| VString s, VString "0123456789abcdef" when String.length s = 16 ->
-				VString (Digest.to_hex s)
-			| VString s, VString b ->
-				if String.length b <> 64 then assert false;
-				let tbl = Array.init 64 (String.unsafe_get b) in
-				VString (Base64.str_encode ~tbl s)
-			| _ -> error()
-		);
-		"base_decode", Fun2 (fun s b ->
-			let s = vstring s in
-			let b = vstring b in
-			if String.length b <> 64 then assert false;
-			let tbl = Array.init 64 (String.unsafe_get b) in
-			VString (Base64.str_decode ~tbl:(Base64.make_decoding_table tbl) s)
-		);
-		"make_md5", Fun1 (fun s ->
-			VString (Digest.string (vstring s))
-		);
-		(* sprintf *)
-	(* int32 *)
-		"int32_new", Fun1 (fun v ->
-			match v with
-			| VInt32 _ -> v
-			| VInt i -> make_i32 (Int32.of_int i)
-			| VFloat f -> make_i32 (Int32.of_float f)
-			| _ -> error()
-		);
-		"int32_to_int", Fun1 (fun v ->
-			let v = int32 v in
-			let i = Int32.to_int v in
-			if Int32.compare (Int32.of_int i) v <> 0 then error();
-			VInt i
-		);
-		"int32_to_float", Fun1 (fun v ->
-			VFloat (Int32.to_float (int32 v))
-		);
-		"int32_compare", Fun2 (fun a b ->
-			VInt (Int32.compare (int32 a) (int32 b))
-		);
-		"int32_add", int32_op Int32.add;
-		"int32_sub", int32_op Int32.sub;
-		"int32_mul", int32_op Int32.mul;
-		"int32_div", int32_op Int32.div;
-		"int32_shl", int32_op (fun a b -> Int32.shift_left a (Int32.to_int b));
-		"int32_shr", int32_op (fun a b -> Int32.shift_right a (Int32.to_int b));
-		"int32_ushr", int32_op (fun a b -> Int32.shift_right_logical a (Int32.to_int b));
-		"int32_mod", int32_op Int32.rem;
-		"int32_or", int32_op Int32.logor;
-		"int32_and", int32_op Int32.logand;
-		"int32_xor", int32_op Int32.logxor;
-		"int32_neg", Fun1 (fun v -> make_i32 (Int32.neg (int32 v)));
-		"int32_complement", Fun1 (fun v -> make_i32 (Int32.lognot (int32 v)));
-	(* misc *)
-		"same_closure", Fun2 (fun a b ->
-			VBool (match a, b with
-			| VClosure (la,fa), VClosure (lb,fb) ->
-				fa == fb && List.length la = List.length lb && List.for_all2 (fun a b -> (get_ctx()).do_compare a b = CEq) la lb
-			| VFunction a, VFunction b -> a == b
-			| _ -> false)
-		);
-		"double_bytes", Fun2 (fun f big ->
-			let f = (match f with VFloat f -> f | VInt i -> float_of_int i | _ -> error()) in
-			match big with
-			| VBool big ->
-				let ch = IO.output_string() in
-				if big then IO.BigEndian.write_double ch f else IO.write_double ch f;
-				VString (IO.close_out ch)
-			| _ ->
-				error()
-		);
-		"float_bytes", Fun2 (fun f big ->
-			let f = (match f with VFloat f -> f | VInt i -> float_of_int i | _ -> error()) in
-			match big with
-			| VBool big ->
-				let ch = IO.output_string() in
-				let i = Int32.bits_of_float f in
-				if big then IO.BigEndian.write_real_i32 ch i else IO.write_real_i32 ch i;
-				VString (IO.close_out ch)
-			| _ ->
-				error()
-		);
-		"double_of_bytes", Fun2 (fun s big ->
-			match s, big with
-			| VString s, VBool big when String.length s = 8 ->
-				let ch = IO.input_string s in
-				VFloat (if big then IO.BigEndian.read_double ch else IO.read_double ch)
-			| _ ->
-				error()
-		);
-		"float_of_bytes", Fun2 (fun s big ->
-			match s, big with
-			| VString s, VBool big when String.length s = 4 ->
-				let ch = IO.input_string s in
-				VFloat (Int32.float_of_bits (if big then IO.BigEndian.read_real_i32 ch else IO.read_real_i32 ch))
-			| _ ->
-				error()
-		);
-	(* random *)
-		"random_new", Fun0 (fun() -> VAbstract (ARandom (ref (Random.State.make_self_init()))));
-		"random_set_seed", Fun2 (fun r s ->
-			match r, s with
-			| VAbstract (ARandom r), VInt seed -> r := Random.State.make [|seed|]; VNull
-			| VAbstract (ARandom r), VInt32 seed -> r := Random.State.make [|Int32.to_int seed|]; VNull
-			| _ -> error()
-		);
-		"random_int", Fun2 (fun r s ->
-			match r, s with
-			| VAbstract (ARandom r), VInt max -> VInt (Random.State.int (!r) (if max <= 0 then 1 else max))
-			| _ -> error()
-		);
-		"random_float", Fun1 (fun r ->
-			match r with
-			| VAbstract (ARandom r) -> VFloat (Random.State.float (!r) 1.0)
-			| _ -> error()
-		);
-	(* file *)
-		"file_open", Fun2 (fun f r ->
-			match f, r with
-			| VString f, VString r ->
-				let perms = 0o666 in
-				VAbstract (match r with
-					| "r" -> AFRead (open_in_gen [Open_rdonly] 0 f)
-					| "rb" -> AFRead (open_in_gen [Open_rdonly;Open_binary] 0 f)
-					| "w" -> AFWrite (open_out_gen [Open_wronly;Open_creat;Open_trunc] perms f)
-					| "wb" -> AFWrite (open_out_gen [Open_wronly;Open_creat;Open_trunc;Open_binary] perms f)
-					| "a" -> AFWrite (open_out_gen [Open_append] perms f)
-					| "ab" -> AFWrite (open_out_gen [Open_append;Open_binary] perms f)
-					| _ -> error())
-			| _ -> error()
-		);
-		"file_close", Fun1 (fun f ->
-			(match f with
-			| VAbstract (AFRead f) -> close_in f
-			| VAbstract (AFWrite f) -> close_out f
-			| _ -> error());
-			VNull
-		);
-		(* file_name *)
-		"file_write", Fun4 (fun f s p l ->
-			match f, s, p, l with
-			| VAbstract (AFWrite f), VString s, VInt p, VInt l -> output f s p l; VInt l
-			| _ -> error()
-		);
-		"file_read", Fun4 (fun f s p l ->
-			match f, s, p, l with
-			| VAbstract (AFRead f), VString s, VInt p, VInt l ->
-				let n = input f s p l in
-				if n = 0 then exc (VArray [|VString "file_read"|]);
-				VInt n
-			| _ -> error()
-		);
-		"file_write_char", Fun2 (fun f c ->
-			match f, c with
-			| VAbstract (AFWrite f), VInt c -> output_char f (char_of_int c); VNull
-			| _ -> error()
-		);
-		"file_read_char", Fun1 (fun f ->
-			match f with
-			| VAbstract (AFRead f) -> VInt (int_of_char (try input_char f with _ -> exc (VArray [|VString "file_read_char"|])))
-			| _ -> error()
-		);
-		"file_seek", Fun3 (fun f pos mode ->
-			match f, pos, mode with
-			| VAbstract (AFRead f), VInt pos, VInt mode ->
-				seek_in f (match mode with 0 -> pos | 1 -> pos_in f + pos | 2 -> in_channel_length f - pos | _ -> error());
-				VNull;
-			| VAbstract (AFWrite f), VInt pos, VInt mode ->
-				seek_out f (match mode with 0 -> pos | 1 -> pos_out f + pos | 2 -> out_channel_length f - pos | _ -> error());
-				VNull;
-			| _ -> error()
-		);
-		"file_tell", Fun1 (fun f ->
-			match f with
-			| VAbstract (AFRead f) -> VInt (pos_in f)
-			| VAbstract (AFWrite f) -> VInt (pos_out f)
-			| _ -> error()
-		);
-		"file_eof", Fun1 (fun f ->
-			match f with
-			| VAbstract (AFRead f) ->
-				VBool (try
-					ignore(input_char f);
-					seek_in f (pos_in f - 1);
-					false
-				with End_of_file ->
-					true)
-			| _ -> error()
-		);
-		"file_flush", Fun1 (fun f ->
-			(match f with
-			| VAbstract (AFWrite f) -> flush f
-			| _ -> error());
-			VNull
-		);
-		"file_contents", Fun1 (fun f ->
-			match f with
-			| VString f -> VString (Std.input_file ~bin:true f)
-			| _ -> error()
-		);
-		"file_stdin", Fun0 (fun() -> VAbstract (AFRead Pervasives.stdin));
-		"file_stdout", Fun0 (fun() -> VAbstract (AFWrite Pervasives.stdout));
-		"file_stderr", Fun0 (fun() -> VAbstract (AFWrite Pervasives.stderr));
-	(* serialize *)
-		(* TODO *)
-	(* socket *)
-		"socket_init", Fun0 (fun() -> VNull);
-		"socket_new", Fun1 (fun v ->
-			match v with
-			| VBool b -> VAbstract (ASocket (Unix.socket PF_INET (if b then SOCK_DGRAM else SOCK_STREAM) 0));
-			| _ -> error()
-		);
-		"socket_close", Fun1 (fun s ->
-			match s with
-			| VAbstract (ASocket s) -> Unix.close s; VNull
-			| _ -> error()
-		);
-		"socket_send_char", Fun2 (fun s c ->
-			match s, c with
-			| VAbstract (ASocket s), VInt c when c >= 0 && c <= 255 ->
-				ignore(Unix.send s (String.make 1 (char_of_int c)) 0 1 []);
-				VNull
-			| _ -> error()
-		);
-		"socket_send", Fun4 (fun s buf pos len ->
-			match s, buf, pos, len with
-			| VAbstract (ASocket s), VString buf, VInt pos, VInt len -> VInt (Unix.send s buf pos len [])
-			| _ -> error()
-		);
-		"socket_recv", Fun4 (fun s buf pos len ->
-			match s, buf, pos, len with
-			| VAbstract (ASocket s), VString buf, VInt pos, VInt len -> VInt (Unix.recv s buf pos len [])
-			| _ -> error()
-		);
-		"socket_recv_char", Fun1 (fun s ->
-			match s with
-			| VAbstract (ASocket s) ->
-				let buf = String.make 1 '\000' in
-				ignore(Unix.recv s buf 0 1 []);
-				VInt (int_of_char (String.unsafe_get buf 0))
-			| _ -> error()
-		);
-		"socket_write", Fun2 (fun s str ->
-			match s, str with
-			| VAbstract (ASocket s), VString str ->
-				let pos = ref 0 in
-				let len = ref (String.length str) in
-				while !len > 0 do
-					let k = Unix.send s str (!pos) (!len) [] in
-					pos := !pos + k;
-					len := !len - k;
-				done;
-				VNull
-			| _ -> error()
-		);
-		"socket_read", Fun1 (fun s ->
-			match s with
-			| VAbstract (ASocket s) ->
-				let tmp = String.make 1024 '\000' in
-				let buf = Buffer.create 0 in
-				let rec loop() =
-					let k = (try Unix.recv s tmp 0 1024 [] with Unix_error _ -> 0) in
-					if k > 0 then begin
-						Buffer.add_substring buf tmp 0 k;
-						loop();
-					end
-				in
-				loop();
-				VString (Buffer.contents buf)
-			| _ -> error()
-		);
-		"host_resolve", Fun1 (fun s ->
-			let h = (try Unix.gethostbyname (vstring s) with Not_found -> error()) in
-			let addr = Unix.string_of_inet_addr h.h_addr_list.(0) in
-			let a, b, c, d = Scanf.sscanf addr "%d.%d.%d.%d" (fun a b c d -> a,b,c,d) in
-			VInt32 (Int32.logor (Int32.shift_left (Int32.of_int a) 24) (Int32.of_int (d lor (c lsl 8) lor (b lsl 16))))
-		);
-		"host_to_string", Fun1 (fun h ->
-			match h with
-			| VInt32 h -> VString (Unix.string_of_inet_addr (int32_addr h));
-			| _ -> error()
-		);
-		"host_reverse", Fun1 (fun h ->
-			match h with
-			| VInt32 h -> VString (gethostbyaddr (int32_addr h)).h_name
-			| _ -> error()
-		);
-		"host_local", Fun0 (fun() ->
-			VString (Unix.gethostname())
-		);
-		"socket_connect", Fun3 (fun s h p ->
-			match s, h, p with
-			| VAbstract (ASocket s), VInt32 h, VInt p ->
-				Unix.connect s (ADDR_INET (int32_addr h,p));
-				VNull
-			| _ -> error()
-		);
-		"socket_listen", Fun2 (fun s l ->
-			match s, l with
-			| VAbstract (ASocket s), VInt l ->
-				Unix.listen s l;
-				VNull
-			| _ -> error()
-		);
-		"socket_set_timeout", Fun2 (fun s t ->
-			match s with
-			| VAbstract (ASocket s) ->
-				let t = (match t with VNull -> 0. | VInt t -> float_of_int t | VFloat f -> f | _ -> error()) in
-				Unix.setsockopt_float s SO_RCVTIMEO t;
-				Unix.setsockopt_float s SO_SNDTIMEO t;
-				VNull
-			| _ -> error()
-		);
-		"socket_shutdown", Fun3 (fun s r w ->
-			match s, r, w with
-			| VAbstract (ASocket s), VBool r, VBool w ->
-				Unix.shutdown s (match r, w with true, true -> SHUTDOWN_ALL | true, false -> SHUTDOWN_RECEIVE | false, true -> SHUTDOWN_SEND | _ -> error());
-				VNull
-			| _ -> error()
-		);
-		(* TODO : select, bind, accept, peer, host *)
-		(* poll_alloc, poll : not planned *)
-	(* system *)
-		"get_env", Fun1 (fun v ->
-			try VString (Unix.getenv (vstring v)) with _ -> VNull
-		);
-		"put_env", Fun2 (fun e v ->
-			Unix.putenv (vstring e) (vstring v);
-			VNull
-		);
-		"sys_sleep", Fun1 (fun f ->
-			match f with
-			| VFloat f -> ignore(Unix.select [] [] [] f); VNull
-			| _ -> error()
-		);
-		"set_time_locale", Fun1 (fun l ->
-			match l with
-			| VString s -> VBool false (* always fail *)
-			| _ -> error()
-		);
-		"get_cwd", Fun0 (fun() ->
-			let dir = Unix.getcwd() in
-			let l = String.length dir in
-			VString (if l = 0 then "./" else match dir.[l - 1] with '/' | '\\' -> dir | _ -> dir ^ "/")
-		);
-		"set_cwd", Fun1 (fun s ->
-			Unix.chdir (vstring s);
-			VNull;
-		);
-		"sys_string", Fun0 (fun() ->
-			VString (match Sys.os_type with
-			| "Unix" -> "Linux"
-			| "Win32" | "Cygwin" -> "Windows"
-			| s -> s)
-		);
-		"sys_is64", Fun0 (fun() ->
-			VBool (Sys.word_size = 64)
-		);
-		"sys_command", Fun1 (fun cmd ->
-			VInt (((get_ctx()).curapi.get_com()).run_command (vstring cmd))
-		);
-		"sys_exit", Fun1 (fun code ->
-			if (get_ctx()).curapi.use_cache() then raise Typecore.Fatal_error;
-			exit (vint code);
-		);
-		"sys_exists", Fun1 (fun file ->
-			VBool (Sys.file_exists (vstring file))
-		);
-		"file_delete", Fun1 (fun file ->
-			Sys.remove (vstring file);
-			VNull;
-		);
-		"sys_rename", Fun2 (fun file target ->
-			Sys.rename (vstring file) (vstring target);
-			VNull;
-		);
-		"sys_stat", Fun1 (fun file ->
-			let s = Unix.stat (vstring file) in
-			VObject (obj (hash_field (get_ctx())) [
-				"gid", VInt s.st_gid;
-				"uid", VInt s.st_uid;
-				"atime", VInt32 (Int32.of_float s.st_atime);
-				"mtime", VInt32 (Int32.of_float s.st_mtime);
-				"ctime", VInt32 (Int32.of_float s.st_ctime);
-				"dev", VInt s.st_dev;
-				"ino", VInt s.st_ino;
-				"nlink", VInt s.st_nlink;
-				"rdev", VInt s.st_rdev;
-				"size", VInt s.st_size;
-				"mode", VInt s.st_perm;
-			])
-		);
-		"sys_file_type", Fun1 (fun file ->
-			VString (match (Unix.stat (vstring file)).st_kind with
-			| S_REG -> "file"
-			| S_DIR -> "dir"
-			| S_CHR -> "char"
-			| S_BLK -> "block"
-			| S_LNK -> "symlink"
-			| S_FIFO -> "fifo"
-			| S_SOCK -> "sock")
-		);
-		"sys_create_dir", Fun2 (fun dir mode ->
-			Unix.mkdir (vstring dir) (vint mode);
-			VNull
-		);
-		"sys_remove_dir", Fun1 (fun dir ->
-			Unix.rmdir (vstring dir);
-			VNull;
-		);
-		"sys_time", Fun0 (fun() ->
-			VFloat (Unix.gettimeofday())
-		);
-		"sys_cpu_time", Fun0 (fun() ->
-			VFloat (Sys.time())
-		);
-		"sys_read_dir", Fun1 (fun dir ->
-			let d = Sys.readdir (vstring dir) in
-			let rec loop acc i =
-				if i < 0 then
-					acc
-				else
-					loop (VArray [|VString d.(i);acc|]) (i - 1)
-			in
-			loop VNull (Array.length d - 1)
-		);
-		"file_full_path", Fun1 (fun file ->
-			VString (try Extc.get_full_path (vstring file) with _ -> error())
-		);
-		"sys_exe_path", Fun0 (fun() ->
-			VString (Extc.executable_path())
-		);
-		"sys_env", Fun0 (fun() ->
-			let env = Unix.environment() in
-			let rec loop acc i =
-				if i < 0 then
-					acc
-				else
-					let e, v = ExtString.String.split "=" env.(i) in
-					loop (VArray [|VString e;VString v;acc|]) (i - 1)
-			in
-			loop VNull (Array.length env - 1)
-		);
-		"sys_getch", Fun1 (fun echo ->
-			match echo with
-			| VBool b -> VInt (Extc.getch b)
-			| _ -> error()
-		);
-		"sys_get_pid", Fun0 (fun() ->
-			VInt (Unix.getpid())
-		);
-	(* utf8 *)
-		"utf8_buf_alloc", Fun1 (fun v ->
-			VAbstract (AUtf8 (UTF8.Buf.create (vint v)))
-		);
-		"utf8_buf_add", Fun2 (fun b c ->
-			match b with
-			| VAbstract (AUtf8 buf) -> UTF8.Buf.add_char buf (UChar.chr_of_uint (vint c)); VNull
-			| _ -> error()
-		);
-		"utf8_buf_content", Fun1 (fun b ->
-			match b with
-			| VAbstract (AUtf8 buf) -> VString (UTF8.Buf.contents buf);
-			| _ -> error()
-		);
-		"utf8_buf_length", Fun1 (fun b ->
-			match b with
-			| VAbstract (AUtf8 buf) -> VInt (UTF8.length (UTF8.Buf.contents buf));
-			| _ -> error()
-		);
-		"utf8_buf_size", Fun1 (fun b ->
-			match b with
-			| VAbstract (AUtf8 buf) -> VInt (String.length (UTF8.Buf.contents buf));
-			| _ -> error()
-		);
-		"utf8_validate", Fun1 (fun s ->
-			VBool (try UTF8.validate (vstring s); true with UTF8.Malformed_code -> false)
-		);
-		"utf8_length", Fun1 (fun s ->
-			VInt (UTF8.length (vstring s))
-		);
-		"utf8_sub", Fun3 (fun s p l ->
-			let buf = UTF8.Buf.create 0 in
-			let pos = ref (-1) in
-			let p = vint p and l = vint l in
-			UTF8.iter (fun c ->
-				incr pos;
-				if !pos >= p && !pos < p + l then UTF8.Buf.add_char buf c;
-			) (vstring s);
-			if !pos < p + l then error();
-			VString (UTF8.Buf.contents buf)
-		);
-		"utf8_get", Fun2 (fun s p ->
-			VInt (UChar.uint_code (try UTF8.look (vstring s) (vint p) with _ -> error()))
-		);
-		"utf8_iter", Fun2 (fun s f ->
-			let ctx = get_ctx() in
-			UTF8.iter (fun c ->
-				ignore(ctx.do_call VNull f [VInt (UChar.uint_code c)] p);
-			) (vstring s);
-			VNull;
-		);
-		"utf8_compare", Fun2 (fun s1 s2 ->
-			VInt (UTF8.compare (vstring s1) (vstring s2))
-		);
-	(* xml *)
-		"parse_xml", (match neko with
-		| None -> Fun2 (fun str o ->
-			match str, o with
-			| VString str, VObject events ->
-				let ctx = get_ctx() in
-				let p = { psource = "parse_xml"; pline = 0 } in
-				let xml = get_field events (hash "xml") in
-				let don = get_field events (hash "done") in
-				let pcdata = get_field events (hash "pcdata") in
-				(*
-
-				Since we use the Xml parser, we don't have support for
-				- CDATA
-				- comments, prolog, doctype (allowed but skipped)
-
-				let cdata = get_field events (hash "cdata") in
-				let comment = get_field events (hash "comment") in
-				*)
-				let rec loop = function
-					| Xml.Element (node, attribs, children) ->
-						ignore(ctx.do_call o xml [VString node;VObject (obj (hash_field ctx) (List.map (fun (a,v) -> a, VString v) attribs))] p);
-						List.iter loop children;
-						ignore(ctx.do_call o don [] p);
-					| Xml.PCData s ->
-						ignore(ctx.do_call o pcdata [VString s] p);
-				in
-				let x = XmlParser.make() in
-				XmlParser.check_eof x false;
-				loop (try
-					XmlParser.parse x (XmlParser.SString str)
-				with Xml.Error e -> failwith ("Parser failure (" ^ Xml.error e ^ ")")
-				| e -> failwith ("Parser failure (" ^ Printexc.to_string e ^ ")"));
-				VNull
-			| _ -> error())
-		| Some neko ->
-			let parse_xml = neko.load "std@parse_xml" 2 in
-			Fun2 (fun str o -> neko.call parse_xml [str;o])
-		);
-	(* memory, module, thread : not planned *)
-	]
-	(* process *)
-	@ (match neko with
-	| None -> []
-	| Some neko ->
-		let p_run = neko.load "std@process_run" 2 in
-		let p_stdout_read = neko.load "std@process_stdout_read" 4 in
-		let p_stderr_read = neko.load "std@process_stderr_read" 4 in
-		let p_stdin_write = neko.load "std@process_stdin_write" 4 in
-		let p_stdin_close = neko.load "std@process_stdin_close" 1 in
-		let p_exit = neko.load "std@process_exit" 1 in
-		let p_pid = neko.load "std@process_pid" 1 in
-		let p_close = neko.load "std@process_close" 1 in
-		let win_ec = (try Some (neko.load "std@win_env_changed" 0) with _ -> None) in
-	[
-		"process_run", (Fun2 (fun a b -> neko.call p_run [a;b]));
-		"process_stdout_read", (Fun4 (fun a b c d -> neko.call p_stdout_read [a;VAbstract (ANekoBuffer b);c;d]));
-		"process_stderr_read", (Fun4 (fun a b c d -> neko.call p_stderr_read [a;VAbstract (ANekoBuffer b);c;d]));
-		"process_stdin_write", (Fun4 (fun a b c d -> neko.call p_stdin_write [a;b;c;d]));
-		"process_stdin_close", (Fun1 (fun p -> neko.call p_stdin_close [p]));
-		"process_exit", (Fun1 (fun p -> neko.call p_exit [p]));
-		"process_pid", (Fun1 (fun p -> neko.call p_pid [p]));
-		"process_close", (Fun1 (fun p -> neko.call p_close [p]));
-		"win_env_changed", (Fun0 (fun() -> match win_ec with None -> error() | Some f -> neko.call f []));
-	]))
-
-
-(* ---------------------------------------------------------------------- *)
-(* REGEXP LIBRARY *)
-
-let reg_lib =
-	let error() =
-		raise Builtin_error
-	in
-	(* try to load regexp first : we might fail if pcre is not installed *)
-	let neko = (match neko with
-		| None -> None
-		| Some neko ->
-			(try ignore(neko.load "regexp@regexp_new_options" 2); Some neko with _ -> None)
-	) in
-	match neko with
-	| None ->
-	make_library [
-		(* regexp_new : deprecated *)
-		"regexp_new_options", Fun2 (fun str opt ->
-			match str, opt with
-			| VString str, VString opt ->
-				let case_sensitive = ref true in
-				List.iter (function
-					| 'm' -> () (* always ON ? *)
-					| 'i' -> case_sensitive := false
-					| c -> failwith ("Unsupported regexp option '" ^ String.make 1 c ^ "'")
-				) (ExtString.String.explode opt);
-				let buf = Buffer.create 0 in
-				let rec loop prev esc = function
-					| [] -> ()
-					| c :: l when esc ->
-						(match c with
-						| 'n' -> Buffer.add_char buf '\n'
-						| 'r' -> Buffer.add_char buf '\r'
-						| 't' -> Buffer.add_char buf '\t'
-						| 'd' -> Buffer.add_string buf "[0-9]"
-						| '\\' -> Buffer.add_string buf "\\\\"
-						| '(' | ')' -> Buffer.add_char buf c
-						| '1'..'9' | '+' | '$' | '^' | '*' | '?' | '.' | '[' | ']' ->
-							Buffer.add_char buf '\\';
-							Buffer.add_char buf c;
-						| _ -> failwith ("Unsupported escaped char '" ^ String.make 1 c ^ "'"));
-						loop c false l
-					| c :: l ->
-						match c with
-						| '\\' -> loop prev true l
-						| '(' | '|' | ')' ->
-							Buffer.add_char buf '\\';
-							Buffer.add_char buf c;
-							loop c false l
-						| '?' when prev = '(' && (match l with ':' :: _ -> true | _ -> false) ->
-							failwith "Non capturing groups '(?:' are not supported in macros"
-						| '?' when prev = '*' ->
-							failwith "Ungreedy *? are not supported in macros"
-						| _ ->
-							Buffer.add_char buf c;
-							loop c false l
-				in
-				loop '\000' false (ExtString.String.explode str);
-				let str = Buffer.contents buf in
-				let r = {
-					r = if !case_sensitive then Str.regexp str else Str.regexp_case_fold str;
-					r_string = "";
-					r_groups = [||];
-				} in
-				VAbstract (AReg r)
-			| _ -> error()
-		);
-		"regexp_match", Fun4 (fun r str pos len ->
-			match r, str, pos, len with
-			| VAbstract (AReg r), VString str, VInt pos, VInt len ->
-				let nstr, npos, delta = (if len = String.length str - pos then str, pos, 0 else String.sub str pos len, 0, pos) in
-				(try
-					ignore(Str.search_forward r.r nstr npos);
-					let rec loop n =
-						if n = 9 then
-							[]
-						else try
-							(Some (Str.group_beginning n + delta, Str.group_end n + delta)) :: loop (n + 1)
-						with Not_found ->
-							None :: loop (n + 1)
-						| Invalid_argument _ ->
-							[]
-					in
-					r.r_string <- str;
-					r.r_groups <- Array.of_list (loop 0);
-					VBool true;
-				with Not_found ->
-					VBool false)
-			| _ -> error()
-		);
-		"regexp_matched", Fun2 (fun r n ->
-			match r, n with
-			| VAbstract (AReg r), VInt n ->
-				(match (try r.r_groups.(n) with _ -> failwith ("Invalid group " ^ string_of_int n)) with
-				| None -> VNull
-				| Some (pos,pend) -> VString (String.sub r.r_string pos (pend - pos)))
-			| _ -> error()
-		);
-		"regexp_matched_pos", Fun2 (fun r n ->
-			match r, n with
-			| VAbstract (AReg r), VInt n ->
-				(match (try r.r_groups.(n) with _ -> failwith ("Invalid group " ^ string_of_int n)) with
-				| None -> VNull
-				| Some (pos,pend) -> VObject (obj (hash_field (get_ctx())) ["pos",VInt pos;"len",VInt (pend - pos)]))
-			| _ -> error()
-		);
-		(* regexp_replace : not used by Haxe *)
-		(* regexp_replace_all : not used by Haxe *)
-		(* regexp_replace_fun : not used by Haxe *)
-	]
-	| Some neko ->
-	let regexp_new_options = neko.load "regexp@regexp_new_options" 2 in
-	let regexp_match = neko.load "regexp@regexp_match" 4 in
-	let regexp_matched = neko.load "regexp@regexp_matched" 2 in
-	let regexp_matched_pos = neko.load "regexp@regexp_matched_pos" 2 in
-	make_library [
-		"regexp_new_options", Fun2 (fun str opt -> neko.call regexp_new_options [str;opt]);
-		"regexp_match", Fun4 (fun r str pos len -> neko.call regexp_match [r;str;pos;len]);
-		"regexp_matched", Fun2 (fun r n -> neko.call regexp_matched [r;n]);
-		"regexp_matched_pos", Fun2 (fun r n -> neko.call regexp_matched_pos [r;n]);
-	]
-
-
-(* ---------------------------------------------------------------------- *)
-(* ZLIB LIBRARY *)
-
-let z_lib =
-	let error() =
-		raise Builtin_error
-	in
-	make_library [
-		"inflate_init", Fun1 (fun f ->
-			let z = Extc.zlib_inflate_init2 (match f with VNull -> 15 | VInt i -> i | _ -> error()) in
-			VAbstract (AZipI { z = z; z_flush = Extc.Z_NO_FLUSH })
-		);
-		"deflate_init", Fun1 (fun f ->
-			let z = Extc.zlib_deflate_init (match f with VInt i -> i | _ -> error()) in
-			VAbstract (AZipD { z = z; z_flush = Extc.Z_NO_FLUSH })
-		);
-		"deflate_end", Fun1 (fun z ->
-			match z with
-			| VAbstract (AZipD z) -> Extc.zlib_deflate_end z.z; VNull;
-			| _ -> error()
-		);
-		"inflate_end", Fun1 (fun z ->
-			match z with
-			| VAbstract (AZipI z) -> Extc.zlib_inflate_end z.z; VNull;
-			| _ -> error()
-		);
-		"set_flush_mode", Fun2 (fun z f ->
-			match z, f with
-			| VAbstract (AZipI z | AZipD z), VString s ->
-				z.z_flush <- (match s with
-					| "NO" -> Extc.Z_NO_FLUSH
-					| "SYNC" -> Extc.Z_SYNC_FLUSH
-					| "FULL" -> Extc.Z_FULL_FLUSH
-					| "FINISH" -> Extc.Z_FINISH
-					| "BLOCK" -> Extc.Z_PARTIAL_FLUSH
-					| _ -> error());
-				VNull;
-			| _ -> error()
-		);
-		"inflate_buffer", Fun5 (fun z src pos dst dpos ->
-			match z, src, pos, dst, dpos with
-			| VAbstract (AZipI z), VString src, VInt pos, VString dst, VInt dpos ->
-				let r = Extc.zlib_inflate z.z src pos (String.length src - pos) dst dpos (String.length dst - dpos) z.z_flush in
-				VObject (obj (hash_field (get_ctx())) [
-					"done", VBool r.Extc.z_finish;
-					"read", VInt r.Extc.z_read;
-					"write", VInt r.Extc.z_wrote;
-				])
-			| _ -> error()
-		);
-		"deflate_buffer", Fun5 (fun z src pos dst dpos ->
-			match z, src, pos, dst, dpos with
-			| VAbstract (AZipD z), VString src, VInt pos, VString dst, VInt dpos ->
-				let r = Extc.zlib_deflate z.z src pos (String.length src - pos) dst dpos (String.length dst - dpos) z.z_flush in
-				VObject (obj (hash_field (get_ctx())) [
-					"done", VBool r.Extc.z_finish;
-					"read", VInt r.Extc.z_read;
-					"write", VInt r.Extc.z_wrote;
-				])
-			| _ -> error()
-		);
-		"deflate_bound", Fun2 (fun z size ->
-			match z, size with
-			| VAbstract (AZipD z), VInt size -> VInt (size + 1024)
-			| _ -> error()
-		);
-	]
-
-(* ---------------------------------------------------------------------- *)
-(* MACRO LIBRARY *)
-
-let macro_lib =
-	let error() =
-		raise Builtin_error
-	in
-	let ccom() =
-		(get_ctx()).curapi.get_com()
-	in
-	make_library [
-		"curpos", Fun0 (fun() -> VAbstract (APos (get_ctx()).curapi.pos));
-		"error", Fun2 (fun msg p ->
-			match msg, p with
-			| VString s, VAbstract (APos p) ->
-				(ccom()).Common.error s p;
-				raise Abort
-			| _ -> error()
-		);
-		"warning", Fun2 (fun msg p ->
-			match msg, p with
-			| VString s, VAbstract (APos p) ->
-				(ccom()).warning s p;
-				VNull;
-			| _ -> error()
-		);
-		"class_path", Fun0 (fun() ->
-			VArray (Array.of_list (List.map (fun s -> VString s) (ccom()).class_path));
-		);
-		"resolve", Fun1 (fun file ->
-			match file with
-			| VString s -> VString (try Common.find_file (ccom()) s with Not_found -> failwith ("File not found '" ^ s ^ "'"))
-			| _ -> error();
-		);
-		"define", Fun1 (fun s ->
-			match s with
-			| VString s -> Common.raw_define (ccom()) s; VNull
-			| _ -> error();
-		);
-		"defined", Fun1 (fun s ->
-			match s with
-			| VString s -> VBool (Common.raw_defined (ccom()) s)
-			| _ -> error();
-		);
-		"defined_value", Fun1 (fun s ->
-			match s with
-			| VString s -> (try VString (Common.raw_defined_value (ccom()) s) with Not_found -> VNull)
-			| _ -> error();
-		);
-		"get_type", Fun1 (fun s ->
-			match s with
-			| VString s ->
-				(match (get_ctx()).curapi.get_type s with
-				| None -> failwith ("Type not found '" ^ s ^ "'")
-				| Some t -> encode_type t)
-			| _ -> error()
-		);
-		"get_module", Fun1 (fun s ->
-			match s with
-			| VString s ->
-				enc_array (List.map encode_type ((get_ctx()).curapi.get_module s))
-			| _ -> error()
-		);
-		"on_generate", Fun1 (fun f ->
-			match f with
-			| VFunction (Fun1 _) ->
-				let ctx = get_ctx() in
-				ctx.curapi.on_generate (fun tl ->
-					ignore(catch_errors ctx (fun() -> ctx.do_call VNull f [enc_array (List.map encode_type tl)] null_pos));
-				);
-				VNull
-			| _ -> error()
-		);
-		"on_type_not_found", Fun1 (fun f ->
-			match f with
-			| VFunction (Fun1 _) ->
-				let ctx = get_ctx() in
-				ctx.curapi.on_type_not_found (fun path ->
-					ctx.do_call VNull f [enc_string path] null_pos
-				);
-				VNull
-			| _ -> error()
-		);
-		"parse", Fun3 (fun s p b ->
-			match s, p, b with
-			| VString s, VAbstract (APos p), VBool b -> encode_expr ((get_ctx()).curapi.parse_string s p b)
-			| _ -> error()
-		);
-		"make_expr", Fun2 (fun v p ->
-			match p with
-			| VAbstract (APos p) ->
-				let h_enum = hash "__enum__" and h_et = hash "__et__" and h_ct = hash "__ct__" in
-				let h_tag = hash "tag" and h_args = hash "args" in
-				let h_length = hash "length" in
-				let ctx = get_ctx() in
-				let error v = failwith ("Unsupported value " ^ ctx.do_string v) in
-				let make_path t =
-					let rec loop = function
-						| [] -> assert false
-						| [name] -> (Ast.EConst (Ast.Ident name),p)
-						| name :: l -> (Ast.EField (loop l,name),p)
-					in
-					let t = t_infos t in
-					loop (List.rev (if t.mt_module.m_path = t.mt_path then fst t.mt_path @ [snd t.mt_path] else fst t.mt_module.m_path @ [snd t.mt_module.m_path;snd t.mt_path]))
-				in
-				let rec loop = function
-					| VNull -> (Ast.EConst (Ast.Ident "null"),p)
-					| VBool b -> (Ast.EConst (Ast.Ident (if b then "true" else "false")),p)
-					| VInt i -> (Ast.EConst (Ast.Int (string_of_int i)),p)
-					| VInt32 i -> (Ast.EConst (Ast.Int (Int32.to_string i)),p)
-					| VFloat f -> (Ast.EConst (Ast.Float (string_of_float f)),p)
-					| VAbstract (APos p) ->
-						(Ast.EObjectDecl (
-							("fileName" , (Ast.EConst (Ast.String p.Ast.pfile) , p)) ::
-							("lineNumber" , (Ast.EConst (Ast.Int (string_of_int (Lexer.get_error_line p))),p)) ::
-							("className" , (Ast.EConst (Ast.String ("")),p)) ::
-							[]
-						), p)
-					| VString _ | VArray _ | VAbstract _ | VFunction _ | VClosure _ as v -> error v
-					| VObject o as v ->
-						match o.oproto with
-						| None ->
-							(match get_field_opt o h_ct with
-							| Some (VAbstract (ATDecl t)) ->
-								make_path t
-							| _ ->
-								let fields = List.fold_left (fun acc (fid,v) -> (field_name ctx fid, loop v) :: acc) [] (Array.to_list o.ofields) in
-								(Ast.EObjectDecl fields, p))
-						| Some proto ->
-							match get_field_opt proto h_enum, get_field_opt o h_a, get_field_opt o h_s, get_field_opt o h_length with
-							| _, Some (VArray a), _, Some (VInt len) ->
-								(Ast.EArrayDecl (List.map loop (Array.to_list (Array.sub a 0 len))),p)
-							| _, _, Some (VString s), _ ->
-								(Ast.EConst (Ast.String s),p)
-							| Some (VObject en), _, _, _ ->
-								(match get_field en h_et, get_field o h_tag with
-								| VAbstract (ATDecl t), VString tag ->
-									let e = (Ast.EField (make_path t,tag),p) in
-									(match get_field_opt o h_args with
-									| Some (VArray args) ->
-										let args = List.map loop (Array.to_list args) in
-										(Ast.ECall (e,args),p)
-									| _ -> e)
-								| _ ->
-									error v)
-							| _ ->
-								error v
-				in
-				encode_expr (loop v)
-			| _ -> error()
-		);
-		"signature", Fun1 (fun v ->
-			let cache = ref [] in
-			let cache_count = ref 0 in
-			let hfiles = Hashtbl.create 0 in
-			let get_file f =
-				try
-					Hashtbl.find hfiles f
-				with Not_found ->
-					let ff = Common.unique_full_path f in
-					Hashtbl.add hfiles f ff;
-					ff
-			in
-			let do_cache (v:value) (v2:value) =
-				(*
-					tricky : we need to have a quick not-linear cache based on objects address
-					but we can't use address since the GC might be triggered here.
-					Instead let's mutate the object temporary.
-				*)
-				let vt = Obj.repr v in
-				let old = Obj.tag vt in
-				let old_val = Obj.field vt 0 in
-				let abstract_tag = 7 in
-				Obj.set_tag vt abstract_tag;
-				Obj.set_field vt 0 (Obj.repr (ACacheRef v2));
-				cache := (vt,old,old_val) :: !cache;
-				incr cache_count
-			in
-			let rec loop v =
-				match v with
-				| VNull | VBool _ | VInt _ | VFloat _ | VString _ | VInt32 _ -> v
-				| VObject o ->
-					let o2 = { ofields = [||]; oproto = None } in
-					let v2 = VObject o2 in
-					do_cache v v2;
-					Array.iter (fun (f,v) -> if f <> h_class then set_field o2 f (loop v)) o.ofields;
-					(match o.oproto with
-					| None -> ()
-					| Some p -> (match loop (VObject p) with VObject p2 -> o2.oproto <- Some p2 | _ -> assert false));
-					v2
-				| VArray a ->
-					let a2 = Array.create (Array.length a) VNull in
-					let v2 = VArray a2 in
-					do_cache v v2;
-					for i = 0 to Array.length a - 1 do
-						a2.(i) <- loop a.(i);
-					done;
-					v2
-				| VFunction f ->
-					let v2 = VFunction (Obj.magic !cache_count) in
-					do_cache v v2;
-					v2
-				| VClosure (vl,f) ->
-					let rl = ref [] in
-					let v2 = VClosure (Obj.magic rl, Obj.magic !cache_count) in
-					do_cache v v2;
-					rl := List.map loop vl;
-					v2
-				| VAbstract (APos p) -> VAbstract (APos { p with Ast.pfile = get_file p.Ast.pfile })
-				| VAbstract (ACacheRef v) -> v
-				| VAbstract (AHash h) ->
-					let h2 = Hashtbl.create 0 in
-					let v2 = VAbstract (AHash h2) in
-					do_cache v v2;
-					Hashtbl.iter (fun k v -> Hashtbl.add h2 k (loop v)) h2;
-					v2
-				| VAbstract _ ->
-					let v2 = VAbstract (Obj.magic !cache_count) in
-					do_cache v v2;
-					v2
-			in
-			let v = loop v in
-			(* restore *)
-			List.iter (fun (vt,tag,field) ->
-				Obj.set_tag vt tag;
-				Obj.set_field vt 0 field;
-			) !cache;
-			VString (Digest.to_hex (Digest.string (Marshal.to_string v [Marshal.Closures])))
-		);
-		"to_complex", Fun1 (fun v ->
-			try	encode_complex_type (make_complex_type (decode_type v))
-			with Exit -> VNull
-		);
-		"unify", Fun2 (fun t1 t2 ->
-			try Type.unify (decode_type t1) (decode_type t2); VBool true
-			with Unify_error _ -> VBool false
-		);
-		"typeof", Fun1 (fun v ->
-			encode_type ((get_ctx()).curapi.typeof (decode_expr v))
-		);
-		"s_type", Fun1 (fun v ->
-			VString (Type.s_type (print_context()) (decode_type v))
-		);
-		"display", Fun1 (fun v ->
-			match v with
-			| VString s ->
-				VString ((get_ctx()).curapi.get_display s)
-			| _ ->
-				error()
-		);
-		"allow_package", Fun1 (fun v ->
-			match v with
-			| VString s ->
-				(get_ctx()).curapi.allow_package s;
-				VNull
-			| _ -> error());
-		"type_patch", Fun4 (fun t f s v ->
-			let p = (get_ctx()).curapi.type_patch in
-			(match t, f, s, v with
-			| VString t, VString f, VBool s, VString v -> p t f s (Some v)
-			| VString t, VString f, VBool s, VNull -> p t f s None
-			| _ -> error());
-			VNull
-		);
-		"meta_patch", Fun4 (fun m t f s ->
-			let p = (get_ctx()).curapi.meta_patch in
-			(match m, t, f, s with
-			| VString m, VString t, VString f, VBool s -> p m t (Some f) s
-			| VString m, VString t, VNull, VBool s -> p m t None s
-			| _ -> error());
-			VNull
-		);
-		"custom_js", Fun1 (fun f ->
-			match f with
-			| VFunction (Fun1 _) ->
-				let ctx = get_ctx() in
-				ctx.curapi.set_js_generator (fun api ->
-					ignore(catch_errors ctx (fun() -> ctx.do_call VNull f [api] null_pos));
-				);
-				VNull
-			| _ -> error()
-		);
-		"get_pos_infos", Fun1 (fun p ->
-			match p with
-			| VAbstract (APos p) -> VObject (obj (hash_field (get_ctx())) ["min",VInt p.Ast.pmin;"max",VInt p.Ast.pmax;"file",VString p.Ast.pfile])
-			| _ -> error()
-		);
-		"make_pos", Fun3 (fun min max file ->
-			match min, max, file with
-			| VInt min, VInt max, VString file -> VAbstract (APos { Ast.pmin = min; Ast.pmax = max; Ast.pfile = file })
-			| _ -> error()
-		);
-		"add_resource", Fun2 (fun name data ->
-			match name, data with
-			| VString name, VString data ->
-				Hashtbl.replace (ccom()).resources name data;
-				let m = (get_ctx()).curapi.current_module() in
-				m.m_extra.m_binded_res <- PMap.add name data m.m_extra.m_binded_res;
-				VNull
-			| _ -> error()
-		);
-		"local_type", Fun0 (fun() ->
-			match (get_ctx()).curapi.get_local_type() with
-			| None -> VNull
-			| Some t -> encode_type t
-		);
-		"local_method", Fun0 (fun() ->
-			VString ((get_ctx()).curapi.get_local_method())
-		);
-		"local_using", Fun0 (fun() ->
-			enc_array (List.map encode_clref ((get_ctx()).curapi.get_local_using()))
-		);
-		"local_vars", Fun0 (fun() ->
-			let vars = (get_ctx()).curapi.get_local_vars() in
-			let h = Hashtbl.create 0 in
-			PMap.iter (fun n v -> Hashtbl.replace h (VString n) (encode_type v.v_type)) vars;
-			enc_hash h
-		);
-		"follow", Fun2 (fun v once ->
-			let t = decode_type v in
-			let follow_once t =
-				match t with
-				| TMono r ->
-					(match !r with
-					| None -> t
-					| Some t -> t)
-				| TAbstract _ | TEnum _ | TInst _ | TFun _ | TAnon _ | TDynamic _ ->
-					t
-				| TType (t,tl) ->
-					apply_params t.t_types tl t.t_type
-				| TLazy f ->
-					(!f)()
-			in
-			encode_type (match once with VNull | VBool false -> follow t | VBool true -> follow_once t | _ -> error())
-		);
-		"build_fields", Fun0 (fun() ->
-			(get_ctx()).curapi.get_build_fields()
-		);
-		"define_type", Fun1 (fun v ->
-			(get_ctx()).curapi.define_type v;
-			VNull
-		);
-		"add_class_path", Fun1 (fun v ->
-			match v with
-			| VString cp ->
-				let com = ccom() in
-				com.class_path <- (Common.normalize_path cp) :: com.class_path;
-				VNull
-			| _ ->
-				error()
-		);
-		"add_native_lib", Fun1 (fun v ->
-			match v with
-			| VString file ->
-				let com = ccom() in
-				(match com.platform with
-				| Flash -> Genswf.add_swf_lib com file false
-				| _ -> failwith "Unsupported platform");
-				VNull
-			| _ ->
-				error()
-		);
-		"module_dependency", Fun2 (fun m file ->
-			match m, file with
-			| VString m, VString file ->
-				(get_ctx()).curapi.module_dependency m file false;
-				VNull
-			| _ -> error()
-		);
-		"module_reuse_call", Fun2 (fun m mcall ->
-			match m, mcall with
-			| VString m, VString mcall ->
-				(get_ctx()).curapi.module_dependency m mcall true;
-				VNull
-			| _ -> error()
-		);
-		"get_typed_expr", Fun1 (fun e ->
-			match e with
-			| VAbstract (ATExpr e) ->
-				encode_expr (make_ast e)
-			| _ -> error()
-		);
-		"get_output", Fun0 (fun() ->
-			VString (ccom()).file
-		);
-		"set_output", Fun1 (fun s ->
-			match s with
-			| VString s -> (ccom()).file <- s; VNull
-			| _ -> error()
-		);
-		"get_display_pos", Fun0 (fun() ->
-			let p = !Parser.resume_display in
-			if p = Ast.null_pos then
-				VNull
-			else
-				VObject (obj (hash_field (get_ctx())) ["file",VString p.Ast.pfile;"pos",VInt p.Ast.pmin])
-		);
-		"pattern_locals", Fun2 (fun e t ->
-			let loc = (get_ctx()).curapi.get_pattern_locals (decode_expr e) (decode_type t) in
-			let h = Hashtbl.create 0 in
-			PMap.iter (fun n v -> Hashtbl.replace h (VString n) (encode_type v.v_type)) loc;
-			enc_hash h
-		);
-		"macro_context_reused", Fun1 (fun c ->
-			match c with
-			| VFunction (Fun0 _) ->
-				let ctx = get_ctx() in
-				ctx.on_reused <- (fun() -> catch_errors ctx (fun() -> ctx.do_call VNull c [] null_pos) = Some (VBool true)) :: ctx.on_reused;
-				VNull
-			| _ -> error()
-		);
-	]
-
-(* ---------------------------------------------------------------------- *)
-(* EVAL *)
-
-let throw ctx p msg =
-	ctx.callstack <- { cpos = p; cthis = ctx.vthis; cstack = DynArray.length ctx.stack; cenv = ctx.venv } :: ctx.callstack;
-	exc (VString msg)
-
-let declare ctx var =
-	ctx.locals_map <- PMap.add var ctx.locals_count ctx.locals_map;
-	ctx.locals_count <- ctx.locals_count + 1
-
-let save_locals ctx =
-	let old, oldcount = ctx.locals_map, ctx.locals_count in
-	(fun() ->
-		let n = ctx.locals_count - oldcount in
-		ctx.locals_count <- oldcount;
-		ctx.locals_map <- old;
-		n;
-	)
-
-let get_ident ctx s =
-	try
-		let index = PMap.find s ctx.locals_map in
-		if index >= ctx.locals_barrier then
-			AccLocal (ctx.locals_count - index)
-		else (try
-			AccEnv (DynArray.index_of (fun s2 -> s = s2) ctx.locals_env)
-		with Not_found ->
-			let index = DynArray.length ctx.locals_env in
-			DynArray.add ctx.locals_env s;
-			AccEnv index
-		)
-	with Not_found -> try
-		AccGlobal (PMap.find s ctx.globals)
-	with Not_found ->
-		let g = ref VNull in
-		ctx.globals <- PMap.add s g ctx.globals;
-		AccGlobal g
-
-let no_env = [||]
-
-let rec eval ctx (e,p) =
-	match e with
-	| EConst c ->
-		(match c with
-		| True -> (fun() -> VBool true)
-		| False -> (fun() -> VBool false)
-		| Null -> (fun() -> VNull)
-		| This -> (fun() -> ctx.vthis)
-		| Int i -> (fun() -> VInt i)
-		| Int32 i -> (fun() -> VInt32 i)
-		| Float f ->
-			let f = float_of_string f in
-			(fun() -> VFloat f)
-		| String s -> (fun() -> VString s)
-		| Builtin "loader" ->
-			(fun() -> ctx.loader)
-		| Builtin "exports" ->
-			(fun() -> ctx.exports)
-		| Builtin s ->
-			let b = (try Hashtbl.find builtins s with Not_found -> throw ctx p ("Builtin not found '" ^ s ^ "'")) in
-			(fun() -> b)
-		| Ident s ->
-			acc_get ctx p (get_ident ctx s))
-	| EBlock el ->
-		let old = save_locals ctx in
-		let el = List.map (eval ctx) el in
-		let n = old() in
-		let rec loop = function
-			| [] -> VNull
-			| [e] -> e()
-			| e :: l ->
-				ignore(e());
-				loop l
-		in
-		(fun() ->
-			let v = loop el in
-			pop ctx n;
-			v)
-	| EParenthesis e ->
-		eval ctx e
-	| EField (e,f) ->
-		let e = eval ctx e in
-		let h = hash_field ctx f in
-		(fun() ->
-			match e() with
-			| VObject o -> get_field o h
-			| _ -> throw ctx p ("Invalid field access : " ^ f)
-		)
-	| ECall ((EConst (Builtin "mk_pos"),_),[(ECall (_,[EConst (String file),_]),_);(EConst (Int min),_);(EConst (Int max),_)]) ->
-		let pos = VAbstract (APos { Ast.pfile = file; Ast.pmin = min; Ast.pmax = max }) in
-		(fun() -> pos)
-	| ECall ((EConst (Builtin "typewrap"),_),[t]) ->
-		(fun() -> VAbstract (ATDecl (Obj.magic t)))
-	| ECall ((EConst (Builtin "delay_call"),_),[EConst (Int index),_]) ->
-		let f = ctx.curapi.delayed_macro index in
-		let fbuild = ref None in
-		let old = { ctx with gen = ctx.gen } in
-		let compile_delayed_call() =
-			let oldl, oldc, oldb, olde = ctx.locals_map, ctx.locals_count, ctx.locals_barrier, ctx.locals_env in
-			ctx.locals_map <- old.locals_map;
-			ctx.locals_count <- old.locals_count;
-			ctx.locals_barrier <- old.locals_barrier;
-			ctx.locals_env <- DynArray.copy old.locals_env;
-			let save = save_locals ctx in
-			let e = f() in
-			let n = save() in
-			let e = if DynArray.length ctx.locals_env = DynArray.length old.locals_env then
-				e
-			else
-				let n = DynArray.get ctx.locals_env (DynArray.length ctx.locals_env - 1) in
-				(fun() -> exc (VString ("Macro-in-macro call can't access to closure variable '" ^ n ^ "'")))
-			in
-			ctx.locals_map <- oldl;
-			ctx.locals_count <- oldc;
-			ctx.locals_barrier <- oldb;
-			ctx.locals_env <- olde;
-			(fun() ->
-				let v = e() in
-				pop ctx n;
-				v
-			)
-		in
-		(fun() ->
-			let e = (match !fbuild with
-			| Some e -> e
-			| None ->
-				let e = compile_delayed_call() in
-				fbuild := Some e;
-				e
-			) in
-			e())
-	| ECall (e,el) ->
-		let el = List.map (eval ctx) el in
-		(match fst e with
-		| EField (e,f) ->
-			let e = eval ctx e in
-			let h = hash_field ctx f in
-			(fun() ->
-				let pl = List.map (fun f -> f()) el in
-				let o = e() in
-				let f = (match o with
-				| VObject o -> get_field o h
-				| _ -> throw ctx p ("Invalid field access : " ^ f)
-				) in
-				call ctx o f pl p
-			)
-		| _ ->
-			let e = eval ctx e in
-			(fun() ->
-				let pl = List.map (fun f -> f()) el in
-				call ctx ctx.vthis (e()) pl p
-			))
-	| EArray (e1,e2) ->
-		let e1 = eval ctx e1 in
-		let e2 = eval ctx e2 in
-		let acc = AccArray (e1,e2) in
-		acc_get ctx p acc
-	| EVars vl ->
-		let vl = List.map (fun (v,eo) ->
-			let eo = (match eo with None -> (fun() -> VNull) | Some e -> eval ctx e) in
-			declare ctx v;
-			eo
-		) vl in
-		(fun() ->
-			List.iter (fun e -> push ctx (e())) vl;
-			VNull
-		)
-	| EWhile (econd,e,NormalWhile) ->
-		let econd = eval ctx econd in
-		let e = eval ctx e in
-		let rec loop st =
-			match econd() with
-			| VBool true ->
-				let v = (try
-					ignore(e()); None
-				with
-					| Continue -> pop ctx (DynArray.length ctx.stack - st); None
-					| Break v -> pop ctx (DynArray.length ctx.stack - st); Some v
-				) in
-				(match v with
-				| None -> loop st
-				| Some v -> v)
-			| _ ->
-				VNull
-		in
-		(fun() -> try loop (DynArray.length ctx.stack) with Sys.Break -> throw ctx p "Ctrl+C")
-	| EWhile (econd,e,DoWhile) ->
-		let e = eval ctx e in
-		let econd = eval ctx econd in
-		let rec loop st =
-			let v = (try
-				ignore(e()); None
-			with
-				| Continue -> pop ctx (DynArray.length ctx.stack - st); None
-				| Break v -> pop ctx (DynArray.length ctx.stack - st); Some v
-			) in
-			match v with
-			| Some v -> v
-			| None ->
-				match econd() with
-				| VBool true -> loop st
-				| _ -> VNull
-		in
-		(fun() -> loop (DynArray.length ctx.stack))
-	| EIf (econd,eif,eelse) ->
-		let econd = eval ctx econd in
-		let eif = eval ctx eif in
-		let eelse = (match eelse with None -> (fun() -> VNull) | Some e -> eval ctx e) in
-		(fun() ->
-			match econd() with
-			| VBool true -> eif()
-			| _ -> eelse()
-		)
-	| ETry (e,exc,ecatch) ->
-		let old = save_locals ctx in
-		let e = eval ctx e in
-		let n1 = old() in
-		declare ctx exc;
-		let ecatch = eval ctx ecatch in
-		let n2 = old() in
-		(fun() ->
-			let vthis = ctx.vthis in
-			let venv = ctx.venv in
-			let stack = ctx.callstack in
-			let csize = ctx.callsize in
-			let size = DynArray.length ctx.stack in
-			try
-				pop_ret ctx e n1
-			with Runtime v ->
-				let rec loop n l =
-					if n = 0 then List.map (fun s -> s.cpos) l else
-					match l with
-					| [] -> []
-					| _ :: l -> loop (n - 1) l
-				in
-				ctx.exc <- loop (List.length stack) (List.rev ctx.callstack);
-				ctx.callstack <- stack;
-				ctx.callsize <- csize;
-				ctx.vthis <- vthis;
-				ctx.venv <- venv;
-				pop ctx (DynArray.length ctx.stack - size);
-				push ctx v;
-				pop_ret ctx ecatch n2
-			)
-	| EFunction (pl,e) ->
-		let old = save_locals ctx in
-		let oldb, oldenv = ctx.locals_barrier, ctx.locals_env in
-		ctx.locals_barrier <- ctx.locals_count;
-		ctx.locals_env <- DynArray.create();
-		List.iter (declare ctx) pl;
-		let e = eval ctx e in
-		ignore(old());
-		let env = ctx.locals_env in
-		ctx.locals_barrier <- oldb;
-		ctx.locals_env <- oldenv;
-		let env = DynArray.to_array (DynArray.map (fun s ->
-			acc_get ctx p (get_ident ctx s)) env
-		) in
-		let init_env = if Array.length env = 0 then
-			(fun() -> no_env)
-		else
-			(fun() -> Array.map (fun e -> e()) env)
-		in
-		(match pl with
-		| [] ->
-			(fun() ->
-				let env = init_env() in
-				VFunction (Fun0 (fun() ->
-					ctx.venv <- env;
-					e())))
-		| [a] ->
-			(fun() ->
-				let env = init_env() in
-				VFunction (Fun1 (fun v ->
-					ctx.venv <- env;
-					push ctx v;
-					e();
-				)))
-		| [a;b] ->
-			(fun() ->
-				let env = init_env() in
-				VFunction (Fun2 (fun va vb ->
-					ctx.venv <- env;
-					push ctx va;
-					push ctx vb;
-					e();
-				)))
-		| [a;b;c] ->
-			(fun() ->
-				let env = init_env() in
-				VFunction (Fun3 (fun va vb vc ->
-					ctx.venv <- env;
-					push ctx va;
-					push ctx vb;
-					push ctx vc;
-					e();
-				)))
-		| [a;b;c;d] ->
-			(fun() ->
-				let env = init_env() in
-				VFunction (Fun4 (fun va vb vc vd ->
-					ctx.venv <- env;
-					push ctx va;
-					push ctx vb;
-					push ctx vc;
-					push ctx vd;
-					e();
-				)))
-		| [a;b;c;d;pe] ->
-			(fun() ->
-				let env = init_env() in
-				VFunction (Fun5 (fun va vb vc vd ve ->
-					ctx.venv <- env;
-					push ctx va;
-					push ctx vb;
-					push ctx vc;
-					push ctx vd;
-					push ctx ve;
-					e();
-				)))
-		| _ ->
-			(fun() ->
-				let env = init_env() in
-				VFunction (FunVar (fun vl ->
-					if List.length vl != List.length pl then exc (VString "Invalid call");
-					ctx.venv <- env;
-					List.iter (push ctx) vl;
-					e();
-				)))
-		)
-	| EBinop (op,e1,e2) ->
-		eval_op ctx op e1 e2 p
-	| EReturn None ->
-		(fun() -> raise (Return VNull))
-	| EReturn (Some e) ->
-		let e = eval ctx e in
-		(fun() -> raise (Return (e())))
-	| EBreak None ->
-		(fun() -> raise (Break VNull))
-	| EBreak (Some e) ->
-		let e = eval ctx e in
-		(fun() -> raise (Break (e())))
-	| EContinue ->
-		(fun() -> raise Continue)
-	| ENext (e1,e2) ->
-		let e1 = eval ctx e1 in
-		let e2 = eval ctx e2 in
-		(fun() -> ignore(e1()); e2())
-	| EObject fl ->
-		let fl = List.map (fun (f,e) -> hash_field ctx f, eval ctx e) fl in
-		let fields = Array.of_list (List.map (fun (f,_) -> f,VNull) fl) in
-		Array.sort (fun (f1,_) (f2,_) -> compare f1 f2) fields;
-		(fun() ->
-			let o = {
-				ofields = Array.copy fields;
-				oproto = None;
-			} in
-			List.iter (fun (f,e) -> set_field o f (e())) fl;
-			VObject o
-		)
-	| ELabel l ->
-		assert false
-	| ESwitch (e1,el,eo) ->
-		let e1 = eval ctx e1 in
-		let el = List.map (fun (cond,e) -> cond, eval ctx cond, eval ctx e) el in
-		let eo = (match eo with None -> (fun() -> VNull) | Some e -> eval ctx e) in
-		let cases = (try
-			let max = ref (-1) in
-			let ints = List.map (fun (cond,_,e) ->
-				match fst cond with
-				| EConst (Int i) -> if i < 0 then raise Exit; if i > !max then max := i; i, e
-				| _ -> raise Exit
-			) el in
-			let a = Array.create (!max + 1) eo in
-			List.iter (fun (i,e) -> a.(i) <- e) (List.rev ints);
-			Some a;
-		with
-			Exit -> None
-		) in
-		let def v =
-			let rec loop = function
-				| [] -> eo()
-				| (_,c,e) :: l ->
-					if ctx.do_compare v (c()) = CEq then e() else loop l
-			in
-			loop el
-		in
-		(match cases with
-		| None -> (fun() -> def (e1()))
-		| Some t ->
-			(fun() ->
-				match e1() with
-				| VInt i -> if i >= 0 && i < Array.length t then t.(i)() else eo()
-				| v -> def v
-			))
-	| ENeko _ ->
-		throw ctx p "Inline neko code unsupported"
-
-and eval_oop ctx p o field (params:value list) =
-	match get_field_opt o field with
-	| None -> None
-	| Some f -> Some (call ctx (VObject o) f params p)
-
-and eval_access ctx (e,p) =
-	match e with
-	| EField (e,f) ->
-		let v = eval ctx e in
-		AccField (v,f)
-	| EArray (e,eindex) ->
-		let v = eval ctx e in
-		let idx = eval ctx eindex in
-		AccArray (v,idx)
-	| EConst (Ident s) ->
-		get_ident ctx s
-	| EConst This ->
-		AccThis
-	| _ ->
-		throw ctx p "Invalid assign"
-
-and eval_access_get_set ctx (e,p) =
-	match e with
-	| EField (e,f) ->
-		let v = eval ctx e in
-		let cache = ref VNull in
-		AccField ((fun() -> cache := v(); !cache),f), AccField((fun() -> !cache), f)
-	| EArray (e,eindex) ->
-		let v = eval ctx e in
-		let idx = eval ctx eindex in
-		let vcache = ref VNull and icache = ref VNull in
-		AccArray ((fun() -> vcache := v(); !vcache),(fun() -> icache := idx(); !icache)), AccArray ((fun() -> !vcache),(fun() -> !icache))
-	| EConst (Ident s) ->
-		let acc = get_ident ctx s in
-		acc, acc
-	| EConst This ->
-		AccThis, AccThis
-	| _ ->
-		throw ctx p "Invalid assign"
-
-and acc_get ctx p = function
-	| AccField (v,f) ->
-		let h = hash_field ctx f in
-		(fun() ->
-			match v() with
-			| VObject o -> get_field o h
-			| _ -> throw ctx p ("Invalid field access : " ^ f))
-	| AccArray (e,index) ->
-		(fun() ->
-			let e = e() in
-			let index = index() in
-			(match index, e with
-			| VInt i, VArray a -> (try Array.get a i with _ -> VNull)
-			| VInt32 _, VArray _ -> VNull
-			| _, VObject o ->
-				(match eval_oop ctx p o h_get [index] with
-				| None -> throw ctx p "Invalid array access"
-				| Some v -> v)
-			| _ -> throw ctx p "Invalid array access"))
-	| AccLocal i ->
-		(fun() -> DynArray.get ctx.stack (DynArray.length ctx.stack - i))
-	| AccGlobal g ->
-		(fun() -> !g)
-	| AccThis ->
-		(fun() -> ctx.vthis)
-	| AccEnv i ->
-		(fun() -> ctx.venv.(i))
-
-and acc_set ctx p acc value =
-	match acc with
-	| AccField (v,f) ->
-		let h = hash_field ctx f in
-		(fun() ->
-			let v = v() in
-			let value = value() in
-			match v with
-			| VObject o -> set_field o h value; value
-			| _ -> throw ctx p ("Invalid field access : " ^ f))
-	| AccArray (e,index) ->
-		(fun() ->
-			let e = e() in
-			let index = index() in
-			let value = value() in
-			(match index, e with
-			| VInt i, VArray a -> (try Array.set a i value; value with _ -> value)
-			| VInt32 _, VArray _ -> value
-			| _, VObject o ->
-				(match eval_oop ctx p o h_set [index;value] with
-				| None -> throw ctx p "Invalid array access"
-				| Some _ -> value);
-			| _ -> throw ctx p "Invalid array access"))
-	| AccLocal i ->
-		(fun() ->
-			let value = value() in
-			DynArray.set ctx.stack (DynArray.length ctx.stack - i) value;
-			value)
-	| AccGlobal g ->
-		(fun() ->
-			let value = value() in
-			g := value;
-			value)
-	| AccThis ->
-		(fun() ->
-			let value = value() in
-			ctx.vthis <- value;
-			value)
-	| AccEnv i ->
-		(fun() ->
-			let value = value() in
-			ctx.venv.(i) <- value;
-			value)
-
-and number_op ctx p sop iop fop oop rop v1 v2 =
-	(fun() ->
-		let v1 = v1() in
-		let v2 = v2() in
-		exc_number_op ctx p sop iop fop oop rop v1 v2)
-
-and exc_number_op ctx p sop iop fop oop rop v1 v2 =
-	match v1, v2 with
-	| VInt a, VInt b -> best_int (iop (Int32.of_int a) (Int32.of_int b))
-	| VInt32 a, VInt b -> best_int (iop a (Int32.of_int b))
-	| VInt a, VInt32 b -> best_int (iop (Int32.of_int a) b)
-	| VFloat a, VInt b -> VFloat (fop a (float_of_int b))
-	| VFloat a, VInt32 b -> VFloat (fop a (Int32.to_float b))
-	| VInt a, VFloat b -> VFloat (fop (float_of_int a) b)
-	| VInt32 a, VFloat b -> VFloat (fop (Int32.to_float a) b)
-	| VFloat a, VFloat b -> VFloat (fop a b)
-	| VInt32 a, VInt32 b -> best_int (iop a b)
-	| VObject o, _ ->
-		(match eval_oop ctx p o oop [v2] with
-		| Some v -> v
-		| None ->
-			match v2 with
-			| VObject o ->
-				(match eval_oop ctx p o rop [v1] with
-				| Some v -> v
-				| None -> throw ctx p sop)
-			| _ ->
-				throw ctx p sop)
-	| _ , VObject o ->
-		(match eval_oop ctx p o rop [v1] with
-		| Some v -> v
-		| None -> throw ctx p sop)
-	| _ ->
-		throw ctx p sop
-
-and int_op ctx p op iop v1 v2 =
-	(fun() ->
-		let v1 = v1() in
-		let v2 = v2() in
-		match v1, v2 with
-		| VInt a, VInt b -> best_int (iop (Int32.of_int a) (Int32.of_int b))
-		| VInt32 a, VInt b -> best_int (iop a (Int32.of_int b))
-		| VInt a, VInt32 b -> best_int (iop (Int32.of_int a) b)
-		| VInt32 a, VInt32 b -> best_int (iop a b)
-		| _ -> throw ctx p op)
-
-and base_op ctx op v1 v2 p =
-	match op with
-	| "+" ->
-		(fun() ->
-			let v1 = v1() in
-			let v2 = v2() in
-			match v1, v2 with
-			| (VInt _ | VInt32 _), (VInt _ | VInt32 _) | (VInt _ | VInt32 _), VFloat _ | VFloat _ , (VInt _ | VInt32 _) | VFloat _ , VFloat _ | VObject _ , _ | _ , VObject _ -> exc_number_op ctx p op Int32.add (+.) h_add h_radd v1 v2
-			| VString a, _ -> VString (a ^ ctx.do_string v2)
-			| _, VString b -> VString (ctx.do_string v1 ^ b)
-			| _ -> throw ctx p op)
-	| "-" ->
-		number_op ctx p op Int32.sub (-.) h_sub h_rsub v1 v2
-	| "*" ->
-		number_op ctx p op Int32.mul ( *. ) h_mult h_rmult v1 v2
-	| "/" ->
-		(fun() ->
-			let v1 = v1() in
-			let v2 = v2() in
-			match v1, v2 with
-			| VInt i, VInt j -> VFloat ((float_of_int i) /. (float_of_int j))
-			| VInt i, VInt32 j -> VFloat ((float_of_int i) /. (Int32.to_float j))
-			| VInt32 i, VInt j -> VFloat ((Int32.to_float i) /. (float_of_int j))
-			| VInt32 i, VInt32 j -> VFloat ((Int32.to_float i) /. (Int32.to_float j))
-			| _ -> exc_number_op ctx p op Int32.div (/.) h_div h_rdiv v1 v2)
-	| "%" ->
-		number_op ctx p op (fun x y -> if y = 0l then throw ctx p op; Int32.rem x y) mod_float h_mod h_rmod v1 v2
-	| "&" ->
-		int_op ctx p op Int32.logand v1 v2
-	| "|" ->
-		int_op ctx p op Int32.logor v1 v2
-	| "^" ->
-		int_op ctx p op Int32.logxor v1 v2
-	| "<<" ->
-		int_op ctx p op (fun x y -> Int32.shift_left x (Int32.to_int y)) v1 v2
-	| ">>" ->
-		int_op ctx p op (fun x y -> Int32.shift_right x (Int32.to_int y)) v1 v2
-	| ">>>" ->
-		int_op ctx p op (fun x y -> Int32.shift_right_logical x (Int32.to_int y)) v1 v2
-	| _ ->
-		throw ctx p op
-
-and eval_op ctx op e1 e2 p =
-	match op with
-	| "=" ->
-		let acc = eval_access ctx e1 in
-		let v = eval ctx e2 in
-		acc_set ctx p acc v
-	| "==" ->
-		let v1 = eval ctx e1 in
-		let v2 = eval ctx e2 in
-		(fun() ->
-			let v1 = v1() in
-			let v2 = v2() in
-			match ctx.do_compare v1 v2 with
-			| CEq -> VBool true
-			| _ -> VBool false)
-	| "!=" ->
-		let v1 = eval ctx e1 in
-		let v2 = eval ctx e2 in
-		(fun() ->
-			let v1 = v1() in
-			let v2 = v2() in
-			match ctx.do_compare v1 v2 with
-			| CEq -> VBool false
-			| _ -> VBool true)
-	| ">" ->
-		let v1 = eval ctx e1 in
-		let v2 = eval ctx e2 in
-		(fun() ->
-			let v1 = v1() in
-			let v2 = v2() in
-			match ctx.do_compare v1 v2 with
-			| CSup -> VBool true
-			| _ -> VBool false)
-	| ">=" ->
-		let v1 = eval ctx e1 in
-		let v2 = eval ctx e2 in
-		(fun() ->
-			let v1 = v1() in
-			let v2 = v2() in
-			match ctx.do_compare v1 v2 with
-			| CSup | CEq -> VBool true
-			| _ -> VBool false)
-	| "<" ->
-		let v1 = eval ctx e1 in
-		let v2 = eval ctx e2 in
-		(fun() ->
-			let v1 = v1() in
-			let v2 = v2() in
-			match ctx.do_compare v1 v2 with
-			| CInf -> VBool true
-			| _ -> VBool false)
-	| "<=" ->
-		let v1 = eval ctx e1 in
-		let v2 = eval ctx e2 in
-		(fun() ->
-			let v1 = v1() in
-			let v2 = v2() in
-			match ctx.do_compare v1 v2 with
-			| CInf | CEq -> VBool true
-			| _ -> VBool false)
-	| "+" | "-" | "*" | "/" | "%" | "|" | "&" | "^" | "<<" | ">>" | ">>>" ->
-		let v1 = eval ctx e1 in
-		let v2 = eval ctx e2 in
-		base_op ctx op v1 v2 p
-	| "+=" | "-=" | "*=" | "/=" | "%=" | "<<=" | ">>=" | ">>>=" | "|=" | "&=" | "^=" ->
-		let aset, aget = eval_access_get_set ctx e1 in
-		let v1 = acc_get ctx p aget in
-		let v2 = eval ctx e2 in
-		let v = base_op ctx (String.sub op 0 (String.length op - 1)) v1 v2 p in
-		acc_set ctx p aset v
-	| "&&" ->
-		let e1 = eval ctx e1 in
-		let e2 = eval ctx e2 in
-		(fun() ->
-			match e1() with
-			| VBool false as v -> v
-			| _ -> e2())
-	| "||" ->
-		let e1 = eval ctx e1 in
-		let e2 = eval ctx e2 in
-		(fun() ->
-			match e1() with
-			| VBool true as v -> v
-			| _ -> e2())
-	| "++=" | "--=" ->
-		let aset, aget = eval_access_get_set ctx e1 in
-		let v1 = acc_get ctx p aget in
-		let v2 = eval ctx e2 in
-		let vcache = ref VNull in
-		let v = base_op ctx (String.sub op 0 1) (fun() -> vcache := v1(); !vcache) v2 p in
-		let set = acc_set ctx p aset v in
-		(fun() -> ignore(set()); !vcache)
-	| _ ->
-		throw ctx p ("Unsupported " ^ op)
-
-and call ctx vthis vfun pl p =
-	let oldthis = ctx.vthis in
-	let stackpos = DynArray.length ctx.stack in
-	let oldstack = ctx.callstack in
-	let oldsize = ctx.callsize in
-	let oldenv = ctx.venv in
-	ctx.vthis <- vthis;
-	ctx.callstack <- { cpos = p; cthis = oldthis; cstack = stackpos; cenv = oldenv } :: ctx.callstack;
-	ctx.callsize <- oldsize + 1;
-	if oldsize > 200 then exc (VString "Stack overflow");
-	let ret = (try
-		(match vfun with
-		| VClosure (vl,f) ->
-			f vl pl
-		| VFunction f ->
-			(match pl, f with
-			| [], Fun0 f -> f()
-			| [a], Fun1 f -> f a
-			| [a;b], Fun2 f -> f a b
-			| [a;b;c], Fun3 f -> f a b c
-			| [a;b;c;d], Fun4 f -> f a b c d
-			| [a;b;c;d;e], Fun5 f -> f a b c d e
-			| _, FunVar f -> f pl
-			| _ -> exc (VString (Printf.sprintf "Invalid call (%d args instead of %d)" (List.length pl) (nargs f))))
-		| VAbstract (ALazyType f) ->
-			encode_type ((!f)())
-		| _ ->
-			exc (VString "Invalid call"))
-	with Return v -> v
-		| Stack_overflow -> exc (VString "Compiler Stack overflow")
-		| Sys_error msg | Failure msg -> exc (VString msg)
-		| Unix.Unix_error (_,cmd,msg) -> exc (VString ("Error " ^ cmd ^ " " ^ msg))
-		| Invalid_expr -> exc (VString "Invalid input value")
-		| Builtin_error | Invalid_argument _ -> exc (VString "Invalid call")) in
-	ctx.vthis <- oldthis;
-	ctx.venv <- oldenv;
-	ctx.callstack <- oldstack;
-	ctx.callsize <- oldsize;
-	pop ctx (DynArray.length ctx.stack - stackpos);
-	ret
-
-(* ---------------------------------------------------------------------- *)
-(* OTHERS *)
-
-let rec to_string ctx n v =
-	if n > 5 then
-		"<...>"
-	else let n = n + 1 in
-	match v with
-	| VNull -> "null"
-	| VBool true -> "true"
-	| VBool false -> "false"
-	| VInt i -> string_of_int i
-	| VInt32 i -> Int32.to_string i
-	| VFloat f ->
-		let s = string_of_float f in
-		let len = String.length s in
-		if String.unsafe_get s (len - 1) = '.' then String.sub s 0 (len - 1) else s
-	| VString s -> s
-	| VArray vl -> "[" ^ String.concat "," (Array.to_list (Array.map (to_string ctx n) vl)) ^ "]"
-	| VAbstract a ->
-		(match a with
-		| APos p -> "#pos(" ^ Lexer.get_error_pos (Printf.sprintf "%s:%d:") p ^ ")"
-		| _ -> "#abstract")
-	| VFunction f -> "#function:"  ^ string_of_int (nargs f)
-	| VClosure _ -> "#function:-1"
-	| VObject o ->
-		match eval_oop ctx null_pos o h_string [] with
-		| Some (VString s) -> s
-		| _ ->
-			let b = Buffer.create 0 in
-			let first = ref true in
-			Buffer.add_char b '{';
-			Array.iter (fun (f,v) ->
-				if !first then begin
-					Buffer.add_char b ' ';
-					first := false;
-				end else
-					Buffer.add_string b ", ";
-				Buffer.add_string b (field_name ctx f);
-				Buffer.add_string b " => ";
-				Buffer.add_string b (to_string ctx n v);
-			) o.ofields;
-			Buffer.add_string b (if !first then "}" else " }");
-			Buffer.contents b
-
-let rec compare ctx a b =
-	let fcmp (a:float) b = if a = b then CEq else if a < b then CInf else CSup in
-	let scmp (a:string) b = if a = b then CEq else if a < b then CInf else CSup in
-	let icmp (a:int32) b = let l = Int32.compare a b in if l = 0 then CEq else if l < 0 then CInf else CSup in
-	match a, b with
-	| VNull, VNull -> CEq
-	| VInt a, VInt b -> if a = b then CEq else if a < b then CInf else CSup
-	| VInt32 a, VInt32 b -> icmp a b
-	| VInt a, VInt32 b -> icmp (Int32.of_int a) b
-	| VInt32 a, VInt b -> icmp a (Int32.of_int b)
-	| VFloat a, VFloat b -> fcmp a b
-	| VFloat a, VInt b -> fcmp a (float_of_int b)
-	| VFloat a, VInt32 b -> fcmp a (Int32.to_float b)
-	| VInt a, VFloat b -> fcmp (float_of_int a) b
-	| VInt32 a, VFloat b -> fcmp (Int32.to_float a) b
-	| VBool a, VBool b -> if a = b then CEq else if a then CSup else CInf
-	| VString a, VString b -> scmp a b
-	| VInt _ , VString s
-	| VInt32 _, VString s
-	| VFloat _ , VString s
-	| VBool _ , VString s -> scmp (to_string ctx 0 a) s
-	| VString s, VInt _
-	| VString s, VInt32 _
-	| VString s, VFloat _
-	| VString s, VBool _ -> scmp s (to_string ctx 0 b)
-	| VObject oa, VObject ob ->
-		if oa == ob then CEq else
-			(match eval_oop ctx null_pos oa h_compare [b] with
-			| Some (VInt i) -> if i = 0 then CEq else if i < 0 then CInf else CSup
-			| _ -> CUndef)
-	| VAbstract a, VAbstract b ->
-		if a == b then CEq else CUndef
-	| VArray a, VArray b ->
-		if a == b then CEq else CUndef
-	| VFunction a, VFunction b ->
-		if a == b then CEq else CUndef
-	| VClosure (la,fa), VClosure (lb,fb) ->
-		if la == lb && fa == fb then CEq else CUndef
-	| _ ->
-		CUndef
-
-let select ctx =
-	get_ctx_ref := (fun() -> ctx)
-
-let load_prim ctx f n =
-	match f, n with
-	| VString f, VInt n ->
-		let lib, fname = (try ExtString.String.split f "@" with _ -> "", f) in
-		(try
-			let f = (match lib with
-			| "std" -> Hashtbl.find std_lib fname
-			| "macro" -> Hashtbl.find macro_lib fname
-			| "regexp" -> Hashtbl.find reg_lib fname
-			| "zlib" -> Hashtbl.find z_lib fname
-			| _ -> failwith ("You cannot use the library '" ^ lib ^ "' inside a macro");
-			) in
-			if nargs f <> n then raise Not_found;
-			VFunction f
-		with Not_found ->
-			VFunction (FunVar (fun _ -> exc (VString ("Primitive not found " ^ f ^ ":" ^ string_of_int n)))))
-	| _ ->
-		exc (VString "Invalid call")
-
-let create com api =
-	let loader = obj hash [
-		"args",VArray (Array.of_list (List.map (fun s -> VString s) com.sys_args));
-		"loadprim",VFunction (Fun2 (fun a b -> (get_ctx()).do_loadprim a b));
-		"loadmodule",VFunction (Fun2 (fun a b -> assert false));
-	] in
-	let ctx = {
-		gen = Genneko.new_context com 2 true;
-		types = Hashtbl.create 0;
-		error = false;
-		error_proto = { ofields = [||]; oproto = None };
-		prototypes = Hashtbl.create 0;
-		enums = [||];
-		(* eval *)
-		locals_map = PMap.empty;
-		locals_count = 0;
-		locals_barrier = 0;
-		locals_env = DynArray.create();
-		globals = PMap.empty;
-		(* runtime *)
-		callstack = [];
-		callsize = 0;
-		stack = DynArray.create();
-		exc = [];
-		vthis = VNull;
-		venv = [||];
-		fields_cache = Hashtbl.copy constants;
-		(* api *)
-		do_call = Obj.magic();
-		do_string = Obj.magic();
-		do_loadprim = Obj.magic();
-		do_compare = Obj.magic();
-		(* context *)
-		curapi = api;
-		loader = VObject loader;
-		on_reused = [];
-		is_reused = true;
-		exports = VObject { ofields = [||]; oproto = None };
-	} in
-	ctx.do_call <- call ctx;
-	ctx.do_string <- to_string ctx 0;
-	ctx.do_loadprim <- load_prim ctx;
-	ctx.do_compare <- compare ctx;
-	select ctx;
-	List.iter (fun e -> ignore((eval ctx e)())) (Genneko.header());
-	ctx
-
-
-
-let do_reuse ctx =
-	ctx.is_reused <- false
-
-let can_reuse ctx types =
-	let has_old_version t =
-		let inf = Type.t_infos t in
-		try
-			Hashtbl.find ctx.types inf.mt_path <> inf.mt_module.m_id
-		with Not_found ->
-			false
-	in
-	if List.exists has_old_version types then
-		false
-	else if ctx.is_reused then
-		true
-	else if not (List.for_all (fun f -> f()) ctx.on_reused) then
-		false
-	else begin
-		ctx.is_reused <- true;
-		true;
-	end
-
-let add_types ctx types ready =
-	let types = List.filter (fun t ->
-		let path = Type.t_path t in
-		if Hashtbl.mem ctx.types path then false else begin
-			Hashtbl.add ctx.types path (Type.t_infos t).mt_module.m_id;
-			true;
-		end
-	) types in
-	List.iter ready types;
-	let e = (EBlock (Genneko.build ctx.gen types), null_pos) in
-	ignore(catch_errors ctx (fun() -> ignore((eval ctx e)())))
-
-let eval_expr ctx e =
-	let e = Genneko.gen_expr ctx.gen e in
-	catch_errors ctx (fun() -> (eval ctx e)())
-
-let get_path ctx path p =
-	let rec loop = function
-		| [] -> assert false
-		| [x] -> (EConst (Ident x),p)
-		| x :: l -> (EField (loop l,x),p)
-	in
-	(eval ctx (loop (List.rev path)))()
-
-let set_error ctx e =
-	ctx.error <- e
-
-let call_path ctx path f vl api =
-	if ctx.error then
-		None
-	else let old = ctx.curapi in
-	ctx.curapi <- api;
-	let p = Genneko.pos ctx.gen api.pos in
-	catch_errors ctx ~final:(fun() -> ctx.curapi <- old) (fun() ->
-		match get_path ctx path p with
-		| VObject o ->
-			let f = get_field o (hash f) in
-			call ctx (VObject o) f vl p
-		| _ -> assert false
-	)
-
-(* ---------------------------------------------------------------------- *)
-(* EXPR ENCODING *)
-
-type enum_index =
-	| IExpr
-	| IBinop
-	| IUnop
-	| IConst
-	| ITParam
-	| ICType
-	| IField
-	| IType
-	| IFieldKind
-	| IMethodKind
-	| IVarAccess
-	| IAccess
-	| IClassKind
-
-let enum_name = function
-	| IExpr -> "ExprDef"
-	| IBinop -> "Binop"
-	| IUnop -> "Unop"
-	| IConst -> "Constant"
-	| ITParam -> "TypeParam"
-	| ICType -> "ComplexType"
-	| IField -> "FieldType"
-	| IType -> "Type"
-	| IFieldKind -> "FieldKind"
-	| IMethodKind -> "MethodKind"
-	| IVarAccess -> "VarAccess"
-	| IAccess -> "Access"
-	| IClassKind -> "ClassKind"
-
-let init ctx =
-	let enums = [IExpr;IBinop;IUnop;IConst;ITParam;ICType;IField;IType;IFieldKind;IMethodKind;IVarAccess;IAccess;IClassKind] in
-	let get_enum_proto e =
-		match get_path ctx ["haxe";"macro";enum_name e] null_pos with
-		| VObject e ->
-			(match get_field e h_constructs with
-			| VObject cst ->
-				(match get_field cst h_a with
-				| VArray a ->
-					Array.map (fun s ->
-						match s with
-						| VObject s -> (match get_field s h_s with VString s -> get_field e (hash s),s | _ -> assert false)
-						| _ -> assert false
-					) a
-				| _ -> assert false)
-			| _ -> assert false)
-		| _ -> failwith ("haxe.macro." ^ enum_name e ^ " does not exists")
-	in
-	ctx.enums <- Array.of_list (List.map get_enum_proto enums);
-	ctx.error_proto <- (match get_path ctx ["haxe";"macro";"Error";"prototype"] null_pos with VObject p -> p | _ -> failwith ("haxe.macro.Error does not exists"))
-
-open Ast
-
-let null f = function
-	| None -> VNull
-	| Some v -> f v
-
-let encode_pos p =
-	VAbstract (APos p)
-
-let enc_inst path fields =
-	let ctx = get_ctx() in
-	let p = (try Hashtbl.find ctx.prototypes path with Not_found -> try
-		(match get_path ctx (path@["prototype"]) Nast.null_pos with
-		| VObject o -> Hashtbl.add ctx.prototypes path o; o
-		| _ -> raise (Runtime VNull))
-	with Runtime _ ->
-		failwith ("Prototype not found " ^ String.concat "." path)
-	) in
-	let o = obj hash fields in
-	o.oproto <- Some p;
-	VObject o
-
-let enc_array l =
-	let a = Array.of_list l in
-	enc_inst ["Array"] [
-		"__a", VArray a;
-		"length", VInt (Array.length a);
-	]
-
-let enc_string s =
-	enc_inst ["String"] [
-		"__s", VString s;
-		"length", VInt (String.length s)
-	]
-
-let enc_hash h =
-	enc_inst ["haxe";"ds";"StringMap"] [
-		"h", VAbstract (AHash h);
-	]
-
-let enc_obj l = VObject (obj hash l)
-
-let enc_enum (i:enum_index) index pl =
-	let eindex : int = Obj.magic i in
-	let edef = (get_ctx()).enums.(eindex) in
-	if pl = [] then
-		fst edef.(index)
-	else
-		enc_inst ["haxe";"macro";enum_name i] [
-			"tag", VString (snd edef.(index));
-			"index", VInt index;
-			"args", VArray (Array.of_list pl);
-		]
-
-let compiler_error msg pos =
-	exc (enc_inst ["haxe";"macro";"Error"] [("message",enc_string msg);("pos",encode_pos pos)])
-
-let encode_const c =
-	let tag, pl = match c with
-	| Int s -> 0, [enc_string s]
-	| Float s -> 1, [enc_string s]
-	| String s -> 2, [enc_string s]
-	| Ident s -> 3, [enc_string s]
-	| Regexp (s,opt) -> 4, [enc_string s;enc_string opt]
-	in
-	enc_enum IConst tag pl
-
-let rec encode_binop op =
-	let tag, pl = match op with
-	| OpAdd -> 0, []
-	| OpMult -> 1, []
-	| OpDiv -> 2, []
-	| OpSub -> 3, []
-	| OpAssign -> 4, []
-	| OpEq -> 5, []
-	| OpNotEq -> 6, []
-	| OpGt -> 7, []
-	| OpGte -> 8, []
-	| OpLt -> 9, []
-	| OpLte -> 10, []
-	| OpAnd -> 11, []
-	| OpOr -> 12, []
-	| OpXor -> 13, []
-	| OpBoolAnd -> 14, []
-	| OpBoolOr -> 15, []
-	| OpShl -> 16, []
-	| OpShr -> 17, []
-	| OpUShr -> 18, []
-	| OpMod -> 19, []
-	| OpAssignOp op -> 20, [encode_binop op]
-	| OpInterval -> 21, []
-	| OpArrow -> 22, []
-	in
-	enc_enum IBinop tag pl
-
-let encode_unop op =
-	let tag = match op with
-	| Increment -> 0
-	| Decrement -> 1
-	| Not -> 2
-	| Neg -> 3
-	| NegBits -> 4
-	in
-	enc_enum IUnop tag []
-
-let rec encode_path t =
-	let fields = [
-		"pack", enc_array (List.map enc_string t.tpackage);
-		"name", enc_string t.tname;
-		"params", enc_array (List.map encode_tparam t.tparams);
-	] in
-	enc_obj (match t.tsub with
-		| None ->  fields
-		| Some s -> ("sub", enc_string s) :: fields)
-
-and encode_tparam = function
-	| TPType t -> enc_enum ITParam 0 [encode_ctype t]
-	| TPExpr e -> enc_enum ITParam 1 [encode_expr e]
-
-and encode_access a =
-	let tag = match a with
-		| APublic -> 0
-		| APrivate -> 1
-		| AStatic -> 2
-		| AOverride -> 3
-		| ADynamic -> 4
-		| AInline -> 5
-		| AMacro -> 6
-	in
-	enc_enum IAccess tag []
-
-and encode_meta_entry (m,ml,p) =
-	enc_obj [
-		"name", enc_string (fst (MetaInfo.to_string m));
-		"params", enc_array (List.map encode_expr ml);
-		"pos", encode_pos p;
-	]
-
-and encode_meta_content m =
-	enc_array (List.map encode_meta_entry m)
-
-and encode_field (f:class_field) =
-	let tag, pl = match f.cff_kind with
-		| FVar (t,e) -> 0, [null encode_ctype t; null encode_expr e]
-		| FFun f -> 1, [encode_fun f]
-		| FProp (get,set, t, e) -> 2, [enc_string get; enc_string set; null encode_ctype t; null encode_expr e]
-	in
-	enc_obj [
-		"name",enc_string f.cff_name;
-		"doc", null enc_string f.cff_doc;
-		"pos", encode_pos f.cff_pos;
-		"kind", enc_enum IField tag pl;
-		"meta", encode_meta_content f.cff_meta;
-		"access", enc_array (List.map encode_access f.cff_access);
-	]
-
-and encode_ctype t =
-	let tag, pl = match t with
-	| CTPath p ->
-		0, [encode_path p]
-	| CTFunction (pl,r) ->
-		1, [enc_array (List.map encode_ctype pl);encode_ctype r]
-	| CTAnonymous fl ->
-		2, [enc_array (List.map encode_field fl)]
-	| CTParent t ->
-		3, [encode_ctype t]
-	| CTExtend (t,fields) ->
-		4, [encode_path t; enc_array (List.map encode_field fields)]
-	| CTOptional t ->
-		5, [encode_ctype t]
-	in
-	enc_enum ICType tag pl
-
-and encode_tparam_decl tp =
-	enc_obj [
-		"name", enc_string tp.tp_name;
-		"params", enc_array (List.map encode_tparam_decl tp.tp_params);
-		"constraints", enc_array (List.map encode_ctype tp.tp_constraints);
-	]
-
-and encode_fun f =
-	enc_obj [
-		"params", enc_array (List.map encode_tparam_decl f.f_params);
-		"args", enc_array (List.map (fun (n,opt,t,e) ->
-			enc_obj [
-				"name", enc_string n;
-				"opt", VBool opt;
-				"type", null encode_ctype t;
-				"value", null encode_expr e;
-			]
-		) f.f_args);
-		"ret", null encode_ctype f.f_type;
-		"expr", null encode_expr f.f_expr
-	]
-
-and encode_expr e =
-	let rec loop (e,p) =
-		let tag, pl = match e with
-			| EConst c ->
-				0, [encode_const c]
-			| EArray (e1,e2) ->
-				1, [loop e1;loop e2]
-			| EBinop (op,e1,e2) ->
-				2, [encode_binop op;loop e1;loop e2]
-			| EField (e,f) ->
-				3, [loop e;enc_string f]
-			| EParenthesis e ->
-				4, [loop e]
-			| EObjectDecl fl ->
-				5, [enc_array (List.map (fun (f,e) -> enc_obj [
-					"field",enc_string f;
-					"expr",loop e;
-				]) fl)]
-			| EArrayDecl el ->
-				6, [enc_array (List.map loop el)]
-			| ECall (e,el) ->
-				7, [loop e;enc_array (List.map loop el)]
-			| ENew (p,el) ->
-				8, [encode_path p; enc_array (List.map loop el)]
-			| EUnop (op,flag,e) ->
-				9, [encode_unop op; VBool (match flag with Prefix -> false | Postfix -> true); loop e]
-			| EVars vl ->
-				10, [enc_array (List.map (fun (v,t,eo) ->
-					enc_obj [
-						"name",enc_string v;
-						"type",null encode_ctype t;
-						"expr",null loop eo;
-					]
-				) vl)]
-			| EFunction (name,f) ->
-				11, [null enc_string name; encode_fun f]
-			| EBlock el ->
-				12, [enc_array (List.map loop el)]
-			| EFor (e,eloop) ->
-				13, [loop e;loop eloop]
-			| EIn (e1,e2) ->
-				14, [loop e1;loop e2]
-			| EIf (econd,e,eelse) ->
-				15, [loop econd;loop e;null loop eelse]
-			| EWhile (econd,e,flag) ->
-				16, [loop econd;loop e;VBool (match flag with NormalWhile -> true | DoWhile -> false)]
-			| ESwitch (e,cases,eopt) ->
-				17, [loop e;enc_array (List.map (fun (ecl,eg,e) ->
-					enc_obj [
-						"values",enc_array (List.map loop ecl);
-						"guard",null loop eg;
-						"expr",null loop e
-					]
-				) cases);null encode_null_expr eopt]
-			| ETry (e,catches) ->
-				18, [loop e;enc_array (List.map (fun (v,t,e) ->
-					enc_obj [
-						"name",enc_string v;
-						"type",encode_ctype t;
-						"expr",loop e
-					]
-				) catches)]
-			| EReturn eo ->
-				19, [null loop eo]
-			| EBreak ->
-				20, []
-			| EContinue ->
-				21, []
-			| EUntyped e ->
-				22, [loop e]
-			| EThrow e ->
-				23, [loop e]
-			| ECast (e,t) ->
-				24, [loop e; null encode_ctype t]
-			| EDisplay (e,flag) ->
-				25, [loop e; VBool flag]
-			| EDisplayNew t ->
-				26, [encode_path t]
-			| ETernary (econd,e1,e2) ->
-				27, [loop econd;loop e1;loop e2]
-			| ECheckType (e,t) ->
-				28, [loop e; encode_ctype t]
-			| EMeta (m,e) ->
-				29, [encode_meta_entry m;loop e]
-		in
-		enc_obj [
-			"pos", encode_pos p;
-			"expr", enc_enum IExpr tag pl;
-		]
-	in
-	loop e
-
-and encode_null_expr e =
-	match e with
-	| None ->
-		enc_obj ["pos", VNull;"expr",VNull]
-	| Some e ->
-		encode_expr e
-
-(* ---------------------------------------------------------------------- *)
-(* EXPR DECODING *)
-
-let opt f v =
-	match v with
-	| VNull -> None
-	| _ -> Some (f v)
-
-let opt_list f v =
-	match v with
-	| VNull -> []
-	| _ -> f v
-
-let decode_pos = function
-	| VAbstract (APos p) -> p
-	| _ -> raise Invalid_expr
-
-let field v f =
-	match v with
-	| VObject o -> get_field o (hash f)
-	| _ -> raise Invalid_expr
-
-let decode_enum v =
-	match field v "index", field v "args" with
-	| VInt i, VNull -> i, []
-	| VInt i, VArray a -> i, Array.to_list a
-	| _ -> raise Invalid_expr
-
-let dec_bool = function
-	| VBool b -> b
-	| _ -> raise Invalid_expr
-
-let dec_string v =
-	match field v "__s" with
-	| VString s -> s
-	| _ -> raise Invalid_expr
-
-let dec_array v =
-	match field v "__a", field v "length" with
-	| VArray a, VInt l -> Array.to_list (if Array.length a = l then a else Array.sub a 0 l)
-	| _ -> raise Invalid_expr
-
-let decode_const c =
-	match decode_enum c with
-	| 0, [s] -> Int (dec_string s)
-	| 1, [s] -> Float (dec_string s)
-	| 2, [s] -> String (dec_string s)
-	| 3, [s] -> Ident (dec_string s)
-	| 4, [s;opt] -> Regexp (dec_string s, dec_string opt)
-	| 5, [s] -> Ident (dec_string s) (** deprecated CType, keep until 3.0 release **)
-	| _ -> raise Invalid_expr
-
-let rec decode_op op =
-	match decode_enum op with
-	| 0, [] -> OpAdd
-	| 1, [] -> OpMult
-	| 2, [] -> OpDiv
-	| 3, [] -> OpSub
-	| 4, [] -> OpAssign
-	| 5, [] -> OpEq
-	| 6, [] -> OpNotEq
-	| 7, [] -> OpGt
-	| 8, [] -> OpGte
-	| 9, [] -> OpLt
-	| 10, [] -> OpLte
-	| 11, [] -> OpAnd
-	| 12, [] -> OpOr
-	| 13, [] -> OpXor
-	| 14, [] -> OpBoolAnd
-	| 15, [] -> OpBoolOr
-	| 16, [] -> OpShl
-	| 17, [] -> OpShr
-	| 18, [] -> OpUShr
-	| 19, [] -> OpMod
-	| 20, [op] -> OpAssignOp (decode_op op)
-	| 21, [] -> OpInterval
-	| 22,[] -> OpArrow
-	| _ -> raise Invalid_expr
-
-let decode_unop op =
-	match decode_enum op with
-	| 0, [] -> Increment
-	| 1, [] -> Decrement
-	| 2, [] -> Not
-	| 3, [] -> Neg
-	| 4, [] -> NegBits
-	| _ -> raise Invalid_expr
-
-let rec decode_path t =
-	{
-		tpackage = List.map dec_string (dec_array (field t "pack"));
-		tname = dec_string (field t "name");
-		tparams = List.map decode_tparam (dec_array (field t "params"));
-		tsub = opt dec_string (field t "sub");
-	}
-
-and decode_tparam v =
-	match decode_enum v with
-	| 0,[t] -> TPType (decode_ctype t)
-	| 1,[e] -> TPExpr (decode_expr e)
-	| _ -> raise Invalid_expr
-
-and decode_tparam_decl v =
-	{
-		tp_name = dec_string (field v "name");
-		tp_constraints = (match field v "constraints" with VNull -> [] | a -> List.map decode_ctype (dec_array a));
-		tp_params = (match field v "params" with VNull -> [] | a -> List.map decode_tparam_decl (dec_array a));
-	}
-
-and decode_fun v =
-	{
-		f_params = List.map decode_tparam_decl (dec_array (field v "params"));
-		f_args = List.map (fun o ->
-			(dec_string (field o "name"),dec_bool (field o "opt"),opt decode_ctype (field o "type"),opt decode_expr (field o "value"))
-		) (dec_array (field v "args"));
-		f_type = opt decode_ctype (field v "ret");
-		f_expr = opt decode_expr (field v "expr");
-	}
-
-and decode_access v =
-	match decode_enum v with
-	| 0, [] -> APublic
-	| 1, [] -> APrivate
-	| 2, [] -> AStatic
-	| 3, [] -> AOverride
-	| 4, [] -> ADynamic
-	| 5, [] -> AInline
-	| 6, [] -> AMacro
-	| _ -> raise Invalid_expr
-
-and decode_meta_entry v =
-	MetaInfo.from_string (dec_string (field v "name")), List.map decode_expr (dec_array (field v "params")), decode_pos (field v "pos")
-
-and decode_meta_content v =
-	List.map decode_meta_entry (dec_array v)
-
-and decode_field v =
-	let fkind = match decode_enum (field v "kind") with
-		| 0, [t;e] ->
-			FVar (opt decode_ctype t, opt decode_expr e)
-		| 1, [f] ->
-			FFun (decode_fun f)
-		| 2, [get;set; t; e] ->
-			FProp (dec_string get, dec_string set, opt decode_ctype t, opt decode_expr e)
-		| _ ->
-			raise Invalid_expr
-	in
-	{
-		cff_name = dec_string (field v "name");
-		cff_doc = opt dec_string (field v "doc");
-		cff_pos = decode_pos (field v "pos");
-		cff_kind = fkind;
-		cff_access = List.map decode_access (opt_list dec_array (field v "access"));
-		cff_meta = opt_list decode_meta_content (field v "meta");
-	}
-
-and decode_ctype t =
-	match decode_enum t with
-	| 0, [p] ->
-		CTPath (decode_path p)
-	| 1, [a;r] ->
-		CTFunction (List.map decode_ctype (dec_array a), decode_ctype r)
-	| 2, [fl] ->
-		CTAnonymous (List.map decode_field (dec_array fl))
-	| 3, [t] ->
-		CTParent (decode_ctype t)
-	| 4, [t;fl] ->
-		CTExtend (decode_path t, List.map decode_field (dec_array fl))
-	| 5, [t] ->
-		CTOptional (decode_ctype t)
-	| _ ->
-		raise Invalid_expr
-
-let rec decode_expr v =
-	let rec loop v =
-		(decode (field v "expr"), decode_pos (field v "pos"))
-	and decode e =
-		match decode_enum e with
-		| 0, [c] ->
-			EConst (decode_const c)
-		| 1, [e1;e2] ->
-			EArray (loop e1, loop e2)
-		| 2, [op;e1;e2] ->
-			EBinop (decode_op op, loop e1, loop e2)
-		| 3, [e;f] ->
-			EField (loop e, dec_string f)
-		| 4, [e] ->
-			EParenthesis (loop e)
-		| 5, [a] ->
-			EObjectDecl (List.map (fun o ->
-				(dec_string (field o "field"), loop (field o "expr"))
-			) (dec_array a))
-		| 6, [a] ->
-			EArrayDecl (List.map loop (dec_array a))
-		| 7, [e;el] ->
-			ECall (loop e,List.map loop (dec_array el))
-		| 8, [t;el] ->
-			ENew (decode_path t,List.map loop (dec_array el))
-		| 9, [op;VBool f;e] ->
-			EUnop (decode_unop op,(if f then Postfix else Prefix),loop e)
-		| 10, [vl] ->
-			EVars (List.map (fun v ->
-				(dec_string (field v "name"),opt decode_ctype (field v "type"),opt loop (field v "expr"))
-			) (dec_array vl))
-		| 11, [fname;f] ->
-			EFunction (opt dec_string fname,decode_fun f)
-		| 12, [el] ->
-			EBlock (List.map loop (dec_array el))
-		| 13, [e1;e2] ->
-			EFor (loop e1, loop e2)
-		| 14, [e1;e2] ->
-			EIn (loop e1, loop e2)
-		| 15, [e1;e2;e3] ->
-			EIf (loop e1, loop e2, opt loop e3)
-		| 16, [e1;e2;VBool flag] ->
-			EWhile (loop e1,loop e2,if flag then NormalWhile else DoWhile)
-		| 17, [e;cases;eo] ->
-			let cases = List.map (fun c ->
-				(List.map loop (dec_array (field c "values")),opt loop (field c "guard"),opt loop (field c "expr"))
-			) (dec_array cases) in
-			ESwitch (loop e,cases,opt decode_null_expr eo)
-		| 18, [e;catches] ->
-			let catches = List.map (fun c ->
-				(dec_string (field c "name"),decode_ctype (field c "type"),loop (field c "expr"))
-			) (dec_array catches) in
-			ETry (loop e, catches)
-		| 19, [e] ->
-			EReturn (opt loop e)
-		| 20, [] ->
-			EBreak
-		| 21, [] ->
-			EContinue
-		| 22, [e] ->
-			EUntyped (loop e)
-		| 23, [e] ->
-			EThrow (loop e)
-		| 24, [e;t] ->
-			ECast (loop e,opt decode_ctype t)
-		| 25, [e;f] ->
-			EDisplay (loop e,dec_bool f)
-		| 26, [t] ->
-			EDisplayNew (decode_path t)
-		| 27, [e1;e2;e3] ->
-			ETernary (loop e1,loop e2,loop e3)
-		| 28, [e;t] ->
-			ECheckType (loop e, decode_ctype t)
-		| 29, [m;e] ->
-			EMeta (decode_meta_entry m,loop e)
-		| 30, [e;f] ->
-			EField (loop e, dec_string f) (*** deprecated EType, keep until haxe 3 **)
-		| _ ->
-			raise Invalid_expr
-	in
-	try
-		loop v
-	with Stack_overflow ->
-		raise Invalid_expr
-
-and decode_null_expr v =
-	match field v "expr" with
-	| VNull -> None
-	| _ -> Some (decode_expr v)
-
-
-(* ---------------------------------------------------------------------- *)
-(* TYPE ENCODING *)
-
-let encode_ref v convert tostr =
-	enc_obj [
-		"get", VFunction (Fun0 (fun() -> convert v));
-		"__string", VFunction (Fun0 (fun() -> VString (tostr())));
-		"toString", VFunction (Fun0 (fun() -> enc_string (tostr())));
-		"$", VAbstract (AUnsafe (Obj.repr v));
-	]
-
-let decode_ref v : 'a =
-	match field v "$" with
-	| VAbstract (AUnsafe t) -> Obj.obj t
-	| _ -> raise Invalid_expr
-
-let encode_pmap convert m =
-	let h = Hashtbl.create 0 in
-	PMap.iter (fun k v -> Hashtbl.add h (VString k) (convert v)) m;
-	enc_hash h
-
-let encode_pmap_array convert m =
-	let l = ref [] in
-	PMap.iter (fun _ v -> l := !l @ [(convert v)]) m;
-	enc_array !l
-
-let encode_array convert l =
-	enc_array (List.map convert l)
-
-let encode_meta m set =
-	let meta = ref m in
-	enc_obj [
-		"get", VFunction (Fun0 (fun() ->
-			encode_meta_content (!meta)
-		));
-		"add", VFunction (Fun3 (fun k vl p ->
-			(try
-				let el = List.map decode_expr (dec_array vl) in
-				meta := (MetaInfo.from_string (dec_string k), el, decode_pos p) :: !meta;
-				set (!meta)
-			with Invalid_expr ->
-				failwith "Invalid expression");
-			VNull
-		));
-		"remove", VFunction (Fun1 (fun k ->
-			let k = MetaInfo.from_string (try dec_string k with Invalid_expr -> raise Builtin_error) in
-			meta := List.filter (fun (m,_,_) -> m <> k) (!meta);
-			set (!meta);
-			VNull
-		));
-		"has", VFunction (Fun1 (fun k ->
-			let k = MetaInfo.from_string (try dec_string k with Invalid_expr -> raise Builtin_error) in
-			VBool (List.exists (fun (m,_,_) -> m = k) (!meta));
-		));
-	]
-
-let rec encode_mtype t fields =
-	let i = t_infos t in
-	enc_obj ([
-		"__t", 	VAbstract (ATDecl t);
-		"pack", enc_array (List.map enc_string (fst i.mt_path));
-		"name", enc_string (snd i.mt_path);
-		"pos", encode_pos i.mt_pos;
-		"module", enc_string (s_type_path i.mt_module.m_path);
-		"isPrivate", VBool i.mt_private;
-		"meta", encode_meta i.mt_meta (fun m -> i.mt_meta <- m);
-		"doc", null enc_string i.mt_doc;
-		"params", encode_type_params i.mt_types;
-	] @ fields)
-
-and encode_type_params tl =
-	enc_array (List.map (fun (n,t) -> enc_obj ["name",enc_string n;"t",encode_type t]) tl)
-
-and encode_tenum e =
-	encode_mtype (TEnumDecl e) [
-		"isExtern", VBool e.e_extern;
-		"exclude", VFunction (Fun0 (fun() -> e.e_extern <- true; VNull));
-		"constructs", encode_pmap encode_efield e.e_constrs;
-		"names", enc_array (List.map enc_string e.e_names);
-	]
-
-and encode_tabstract a =
-	encode_mtype (TAbstractDecl a) [
-		"type", encode_type a.a_this;
-		"impl", (match a.a_impl with None -> VNull | Some c -> encode_clref c);
-		"binops", enc_array (List.map (fun (op,cf) -> enc_obj [ "op",encode_binop op; "field",encode_cfield cf]) a.a_ops);
-		"unops", enc_array (List.map (fun (op,postfix,cf) -> enc_obj [ "op",encode_unop op; "isPostfix",VBool (match postfix with Postfix -> true | Prefix -> false); "field",encode_cfield cf]) a.a_unops);
-		"from", enc_array (List.map (fun (t,cfo) -> enc_obj [ "t",encode_type t; "field",match cfo with None -> VNull | Some cf -> encode_cfield cf]) a.a_from);
-		"to", enc_array (List.map (fun (t,cfo) -> enc_obj [ "t",encode_type t; "field",match cfo with None -> VNull | Some cf -> encode_cfield cf]) a.a_to);
-		"array", enc_array (List.map encode_cfield a.a_array);
-	]
-
-and encode_efield f =
-	enc_obj [
-		"name", enc_string f.ef_name;
-		"type", encode_type f.ef_type;
-		"pos", encode_pos f.ef_pos;
-		"index", VInt f.ef_index;
-		"meta", encode_meta f.ef_meta (fun m -> f.ef_meta <- m);
-		"doc", null enc_string f.ef_doc;
-		"params", encode_type_params f.ef_params;
-	]
-
-and encode_cfield f =
-	enc_obj [
-		"name", enc_string f.cf_name;
-		"type", (match f.cf_kind with Method _ -> encode_lazy_type f.cf_type | _ -> encode_type f.cf_type);
-		"isPublic", VBool f.cf_public;
-		"params", encode_type_params f.cf_params;
-		"meta", encode_meta f.cf_meta (fun m -> f.cf_meta <- m);
-		"expr", (VFunction (Fun0 (fun() -> ignore(follow f.cf_type); (match f.cf_expr with None -> VNull | Some e -> encode_texpr e))));
-		"kind", encode_field_kind f.cf_kind;
-		"pos", encode_pos f.cf_pos;
-		"doc", null enc_string f.cf_doc;
-	]
-
-and encode_field_kind k =
-	let tag, pl = (match k with
-		| Type.Var v -> 0, [encode_var_access v.v_read; encode_var_access v.v_write]
-		| Method m -> 1, [encode_method_kind m]
-	) in
-	enc_enum IFieldKind tag pl
-
-and encode_var_access a =
-	let tag, pl = (match a with
-		| AccNormal -> 0, []
-		| AccNo -> 1, []
-		| AccNever -> 2, []
-		| AccResolve -> 3, []
-		| AccCall -> 4, []
-		| AccInline	-> 5, []
-		| AccRequire (s,msg) -> 6, [enc_string s; null enc_string msg]
-	) in
-	enc_enum IVarAccess tag pl
-
-and encode_method_kind m =
-	let tag, pl = (match m with
-		| MethNormal -> 0, []
-		| MethInline -> 1, []
-		| MethDynamic -> 2, []
-		| MethMacro -> 3, []
-	) in
-	enc_enum IMethodKind tag pl
-
-and encode_class_kind k =
-	let tag, pl = (match k with
-		| KNormal -> 0, []
-		| KTypeParameter pl -> 1, [encode_tparams pl]
-		| KExtension (cl, params) -> 2, [encode_clref cl; encode_tparams params]
-		| KExpr e -> 3, [encode_expr e]
-		| KGeneric -> 4, []
-		| KGenericInstance (cl, params) -> 5, [encode_clref cl; encode_tparams params]
-		| KMacroType -> 6, []
-		| KAbstractImpl a -> 7, [encode_ref a encode_tabstract (fun() -> s_type_path a.a_path)]
-	) in
-	enc_enum IClassKind tag pl
-
-and encode_tclass c =
-	c.cl_build();
-	encode_mtype (TClassDecl c) [
-		"kind", encode_class_kind c.cl_kind;
-		"isExtern", VBool c.cl_extern;
-		"exclude", VFunction (Fun0 (fun() -> c.cl_extern <- true; c.cl_init <- None; VNull));
-		"isInterface", VBool c.cl_interface;
-		"superClass", (match c.cl_super with
-			| None -> VNull
-			| Some (c,pl) -> enc_obj ["t",encode_clref c;"params",encode_tparams pl]
-		);
-		"interfaces", enc_array (List.map (fun (c,pl) -> enc_obj ["t",encode_clref c;"params",encode_tparams pl]) c.cl_implements);
-		"fields", encode_ref c.cl_ordered_fields (encode_array encode_cfield) (fun() -> "class fields");
-		"statics", encode_ref c.cl_ordered_statics (encode_array encode_cfield) (fun() -> "class fields");
-		"constructor", (match c.cl_constructor with None -> VNull | Some c -> encode_ref c encode_cfield (fun() -> "constructor"));
-		"init", (match c.cl_init with None -> VNull | Some e -> encode_texpr e);
-	]
-
-and encode_ttype t =
-	encode_mtype (TTypeDecl t) [
-		"isExtern", VBool false;
-		"exclude", VFunction (Fun0 (fun() -> VNull));
-		"type", encode_type t.t_type;
-	]
-
-and encode_tanon a =
-	enc_obj [
-		"fields", encode_pmap_array encode_cfield a.a_fields;
-	]
-
-and encode_tparams pl =
-	enc_array (List.map encode_type pl)
-
-and encode_clref c =
-	encode_ref c encode_tclass (fun() -> s_type_path c.cl_path)
-
-and encode_type t =
-	let rec loop = function
-		| TMono r ->
-			(match !r with
-			| None -> 0, [encode_ref r (fun r -> match !r with None -> VNull | Some t -> encode_type t) (fun() -> "<mono>")]
-			| Some t -> loop t)
-		| TEnum (e, pl) ->
-			1 , [encode_ref e encode_tenum (fun() -> s_type_path e.e_path); encode_tparams pl]
-		| TInst (c, pl) ->
-			2 , [encode_clref c; encode_tparams pl]
-		| TType (t,pl) ->
-			3 , [encode_ref t encode_ttype (fun() -> s_type_path t.t_path); encode_tparams pl]
-		| TFun (pl,ret) ->
-			let pl = List.map (fun (n,o,t) ->
-				enc_obj [
-					"name",enc_string n;
-					"opt",VBool o;
-					"t",encode_type t
-				]
-			) pl in
-			4 , [enc_array pl; encode_type ret]
-		| TAnon a ->
-			5, [encode_ref a encode_tanon (fun() -> "<anonymous>")]
-		| TDynamic tsub as t ->
-			if t == t_dynamic then
-				6, [VNull]
-			else
-				6, [encode_type tsub]
-		| TLazy f ->
-			loop (!f())
-		| TAbstract (a, pl) ->
-			8, [encode_ref a encode_tabstract (fun() -> s_type_path a.a_path); encode_tparams pl]
-	in
-	let tag, pl = loop t in
-	enc_enum IType tag pl
-
-and encode_lazy_type t =
-	let rec loop = function
-		| TMono r ->
-			(match !r with
-			| Some t -> loop t
-			| _ -> encode_type t)
-		| TLazy f ->
-			enc_enum IType 7 [VAbstract (ALazyType f)]
-		| _ ->
-			encode_type t
-	in
-	loop t
-
-and decode_type t =
-	match decode_enum t with
-	| 0, [r] -> TMono (decode_ref r)
-	| 1, [e; pl] -> TEnum (decode_ref e, List.map decode_type (dec_array pl))
-	| 2, [c; pl] -> TInst (decode_ref c, List.map decode_type (dec_array pl))
-	| 3, [t; pl] -> TType (decode_ref t, List.map decode_type (dec_array pl))
-	| 4, [pl; r] -> TFun (List.map (fun p -> dec_string (field p "name"), dec_bool (field p "opt"), decode_type (field p "t")) (dec_array pl), decode_type r)
-	| 5, [a] -> TAnon (decode_ref a)
-	| 6, [VNull] -> t_dynamic
-	| 6, [t] -> TDynamic (decode_type t)
-	| 7, [VAbstract (ALazyType f)] -> TLazy f
-	| 8, [a; pl] -> TAbstract (decode_ref a, List.map decode_type (dec_array pl))
-	| _ -> raise Invalid_expr
-
-and encode_texpr e =
-	VAbstract (ATExpr e)
-
-let decode_tdecl v =
-	match v with
-	| VObject o ->
-		(match get_field o (hash "__t") with
-		| VAbstract (ATDecl t) -> t
-		| _ -> raise Invalid_expr)
-	| _ -> raise Invalid_expr
-
-(* ---------------------------------------------------------------------- *)
-(* TYPE DEFINITION *)
-
-let decode_type_def v =
-	let pack = List.map dec_string (dec_array (field v "pack")) in
-	let name = dec_string (field v "name") in
-	let meta = decode_meta_content (field v "meta") in
-	let pos = decode_pos (field v "pos") in
-	let isExtern = dec_bool (field v "isExtern") in
-	let fields = List.map decode_field (dec_array (field v "fields")) in
-	let mk fl dl =
-		{
-			d_name = name;
-			d_doc = None;
-			d_params = List.map decode_tparam_decl (dec_array (field v "params"));
-			d_meta = meta;
-			d_flags = fl;
-			d_data = dl;
-		}
-	in
-	let tdef = (match decode_enum (field v "kind") with
-	| 0, [] ->
-		let conv f =
-			let loop (n,opt,t,_) =
-				match t with
-				| None -> raise Invalid_expr
-				| Some t -> n, opt, t
-			in
-			let args, params, t = (match f.cff_kind with
-				| FVar (t,None) -> [], [], t
-				| FFun f -> List.map loop f.f_args, f.f_params, f.f_type
-				| _ -> raise Invalid_expr
-			) in
-			{
-				ec_name = f.cff_name;
-				ec_doc = f.cff_doc;
-				ec_meta = f.cff_meta;
-				ec_pos = f.cff_pos;
-				ec_args = args;
-				ec_params = params;
-				ec_type = t;
-			}
-		in
-		EEnum (mk (if isExtern then [EExtern] else []) (List.map conv fields))
-	| 1, [] ->
-		ETypedef (mk (if isExtern then [EExtern] else []) (CTAnonymous fields))
-	| 2, [ext;impl;interf] ->
-		let flags = if isExtern then [HExtern] else [] in
-		let flags = (match interf with VNull | VBool false -> flags | VBool true -> HInterface :: flags | _ -> raise Invalid_expr) in
-		let flags = (match opt decode_path ext with None -> flags | Some t -> HExtends t :: flags) in
-		let flags = (match opt (fun v -> List.map decode_path (dec_array v)) impl with None -> flags | Some l -> List.map (fun t -> HImplements t) l @ flags) in
-		EClass (mk flags fields)
-	| 3, [t] ->
-		ETypedef (mk (if isExtern then [EExtern] else []) (decode_ctype t))
-	| 4, [tthis;tfrom;tto] ->
-		let flags = match opt dec_array tfrom with None -> [] | Some ta -> List.map (fun t -> AFromType (decode_ctype t)) ta in
-		let flags = match opt dec_array tto with None -> flags | Some ta -> (List.map (fun t -> AToType (decode_ctype t)) ta) @ flags in
-		let flags = match opt decode_ctype tthis with None -> flags | Some t -> (AIsType t) :: flags in
-		EAbstract(mk flags fields)
-	| _ ->
-		raise Invalid_expr
-	) in
-	(pack, name), tdef, pos
-
-(* ---------------------------------------------------------------------- *)
-(* VALUE-TO-CONSTANT *)
-
-let rec make_const e =
-	match e.eexpr with
-	| TConst c ->
-		(match c with
-		| TInt i -> best_int i
-		| TFloat s -> VFloat (float_of_string s)
-		| TString s -> enc_string s
-		| TBool b -> VBool b
-		| TNull -> VNull
-		| TThis | TSuper -> raise Exit)
-	| TParenthesis e ->
-		make_const e
-	| TObjectDecl el ->
-		VObject (obj (hash_field (get_ctx())) (List.map (fun (f,e) -> f, make_const e) el))
-	| TArrayDecl al ->
-		enc_array (List.map make_const al)
-	| _ ->
-		raise Exit
-
-(* ---------------------------------------------------------------------- *)
-(* TEXPR-TO-AST-EXPR *)
-
-open Ast
-
-let tpath p mp pl =
-	if snd mp = snd p then
-		CTPath {
-			tpackage = fst p;
-			tname = snd p;
-			tparams = List.map (fun t -> TPType t) pl;
-			tsub = None;
-		}
-	else CTPath {
-			tpackage = fst mp;
-			tname = snd mp;
-			tparams = List.map (fun t -> TPType t) pl;
-			tsub = Some (snd p);
-		}
-
-let rec make_type = function
-	| TMono r ->
-		(match !r with
-		| None -> raise Exit
-		| Some t -> make_type t)
-	| TEnum (e,pl) ->
-		tpath e.e_path e.e_module.m_path (List.map make_type pl)
-	| TInst({cl_kind = KTypeParameter _} as c,pl) ->
-		tpath ([],snd c.cl_path) ([],snd c.cl_path) (List.map make_type pl)
-	| TInst (c,pl) ->
-		tpath c.cl_path c.cl_module.m_path (List.map make_type pl)
-	| TType (t,pl) as tf ->
-		(* recurse on type-type *)
-		if (snd t.t_path).[0] = '#' then make_type (follow tf) else tpath t.t_path t.t_module.m_path (List.map make_type pl)
-	| TAbstract (a,pl) ->
-		tpath a.a_path a.a_module.m_path (List.map make_type pl)
-	| TFun (args,ret) ->
-		CTFunction (List.map (fun (_,_,t) -> make_type t) args, make_type ret)
-	| TAnon a ->
-		begin match !(a.a_status) with
-		| Statics c -> tpath ([],"Class") ([],"Class") [tpath c.cl_path c.cl_path []]
-		| EnumStatics e -> tpath ([],"Enum") ([],"Enum") [tpath e.e_path e.e_path []]
-		| _ ->
-			CTAnonymous (PMap.foldi (fun _ f acc ->
-				{
-					cff_name = f.cf_name;
-					cff_kind = FVar (mk_ot f.cf_type,None);
-					cff_pos = f.cf_pos;
-					cff_doc = f.cf_doc;
-					cff_meta = f.cf_meta;
-					cff_access = [];
-				} :: acc
-			) a.a_fields [])
-		end
-	| (TDynamic t2) as t ->
-		tpath ([],"Dynamic") ([],"Dynamic") (if t == t_dynamic then [] else [make_type t2])
-	| TLazy f ->
-		make_type ((!f)())
-
-and mk_ot t =
-	match follow t with
-	| TMono _ -> None
-	| _ -> (try Some (make_type t) with Exit -> None)
-
-let rec make_ast e =
-	let full_type_path t =
-		let mp,p = match t with
-		| TClassDecl c -> c.cl_module.m_path,c.cl_path
-		| TEnumDecl en -> en.e_module.m_path,en.e_path
-		| TAbstractDecl a -> a.a_module.m_path,a.a_path
-		| TTypeDecl t -> t.t_module.m_path,t.t_path
-		in
-		if snd mp = snd p then p else (fst mp) @ [snd mp],snd p
-	in
-	let mk_path (pack,name) p =
-		match List.rev pack with
-		| [] -> (EConst (Ident name),p)
-		| pl ->
-			let rec loop = function
-				| [] -> assert false
-				| [n] -> (EConst (Ident n),p)
-				| n :: l -> (EField (loop l, n),p)
-			in
-			(EField (loop pl,name),p)
-	in
-	let mk_const = function
-		| TInt i -> Int (Int32.to_string i)
-		| TFloat s -> Float s
-		| TString s -> String s
-		| TBool b -> Ident (if b then "true" else "false")
-		| TNull -> Ident "null"
-		| TThis -> Ident "this"
-		| TSuper -> Ident "super"
-	in
-	let mk_ident = function
-		| "`trace" -> Ident "trace"
-		| n -> Ident n
-	in
-	let eopt = function None -> None | Some e -> Some (make_ast e) in
-	((match e.eexpr with
-	| TConst c ->
-		EConst (mk_const c)
-	| TLocal v -> EConst (mk_ident v.v_name)
-	| TArray (e1,e2) -> EArray (make_ast e1,make_ast e2)
-	| TBinop (op,e1,e2) -> EBinop (op, make_ast e1, make_ast e2)
-	| TField (e,f) -> EField (make_ast e, Type.field_name f)
-	| TTypeExpr t -> fst (mk_path (full_type_path t) e.epos)
-	| TParenthesis e -> EParenthesis (make_ast e)
-	| TObjectDecl fl -> EObjectDecl (List.map (fun (f,e) -> f, make_ast e) fl)
-	| TArrayDecl el -> EArrayDecl (List.map make_ast el)
-	| TCall (e,el) -> ECall (make_ast e,List.map make_ast el)
-	| TNew (c,pl,el) -> ENew ((match (try make_type (TInst (c,pl)) with Exit -> make_type (TInst (c,[]))) with CTPath p -> p | _ -> assert false),List.map make_ast el)
-	| TUnop (op,p,e) -> EUnop (op,p,make_ast e)
-	| TFunction f ->
-		let arg (v,c) = v.v_name, false, mk_ot v.v_type, (match c with None -> None | Some c -> Some (EConst (mk_const c),e.epos)) in
-		EFunction (None,{ f_params = []; f_args = List.map arg f.tf_args; f_type = mk_ot f.tf_type; f_expr = Some (make_ast f.tf_expr) })
-	| TVars vl ->
-		EVars (List.map (fun (v,e) -> v.v_name, mk_ot v.v_type, eopt e) vl)
-	| TBlock el -> EBlock (List.map make_ast el)
-	| TFor (v,it,e) ->
-		let ein = (EIn ((EConst (Ident v.v_name),it.epos),make_ast it),it.epos) in
-		EFor (ein,make_ast e)
-	| TIf (e,e1,e2) -> EIf (make_ast e,make_ast e1,eopt e2)
-	| TWhile (e1,e2,flag) -> EWhile (make_ast e1, make_ast e2, flag)
-	| TSwitch (e,cases,def) ->
-		let cases = List.map (fun (vl,e) ->
-			List.map make_ast vl,None,(match e.eexpr with TBlock [] -> None | _ -> Some (make_ast e))
-		) cases in
-		let def = match eopt def with None -> None | Some (EBlock [],_) -> Some None | e -> Some e in
-		ESwitch (make_ast e,cases,def)
-	| TMatch (e,(en,_),cases,def) ->
-		let scases (idx,args,e) =
-			let p = e.epos in
-			let unused = (EConst (Ident "_"),p) in
-			let args = (match args with
-				| None -> None
-				| Some l -> Some (List.map (function None -> unused | Some v -> (EConst (Ident v.v_name),p)) l)
-			) in
-			let mk_args n =
-				match args with
-				| None -> [unused]
-				| Some args ->
-					args @ Array.to_list (Array.make (n - List.length args) unused)
-			in
-			List.map (fun i ->
-				let c = (try List.nth en.e_names i with _ -> assert false) in
-				let cfield = (try PMap.find c en.e_constrs with Not_found -> assert false) in
-				let c = (EConst (Ident c),p) in
-				(match follow cfield.ef_type with TFun (eargs,_) -> (ECall (c,mk_args (List.length eargs)),p) | _ -> c)
-			) idx, None, (match e.eexpr with TBlock [] -> None | _ -> Some (make_ast e))
-		in
-		let def = match eopt def with None -> None | Some (EBlock [],_) -> Some None | e -> Some e in
-		ESwitch (make_ast e,List.map scases cases,def)
-	| TTry (e,catches) -> ETry (make_ast e,List.map (fun (v,e) -> v.v_name, (try make_type v.v_type with Exit -> assert false), make_ast e) catches)
-	| TReturn e -> EReturn (eopt e)
-	| TBreak -> EBreak
-	| TContinue -> EContinue
-	| TThrow e -> EThrow (make_ast e)
-	| TCast (e,t) ->
-		let t = (match t with
-			| None -> None
-			| Some t ->
-				let t = (match t with TClassDecl c -> TInst (c,[]) | TEnumDecl e -> TEnum (e,[]) | TTypeDecl t -> TType (t,[]) | TAbstractDecl a -> TAbstract (a,[])) in
-				Some (try make_type t with Exit -> assert false)
-		) in
-		ECast (make_ast e,t))
-	,e.epos)
-
-;;
-make_ast_ref := make_ast;
-make_complex_type_ref := make_type;
-encode_complex_type_ref := encode_ctype;
-enc_array_ref := enc_array;
-encode_type_ref := encode_type;
-decode_type_ref := decode_type;
-encode_expr_ref := encode_expr;
-decode_expr_ref := decode_expr;
-encode_clref_ref := encode_clref;
-enc_string_ref := enc_string;
+(*
+ * Copyright (C)2005-2013 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *)
+
+open Common
+open Nast
+open Unix
+open Type
+
+(* ---------------------------------------------------------------------- *)
+(* TYPES *)
+
+type value =
+	| VNull
+	| VBool of bool
+	| VInt of int
+	| VFloat of float
+	| VString of string
+	| VObject of vobject
+	| VArray of value array
+	| VAbstract of vabstract
+	| VFunction of vfunction
+	| VClosure of value list * (value list -> value list -> value)
+	| VInt32 of int32
+
+and vobject = {
+	mutable ofields : (int * value) array;
+	mutable oproto : vobject option;
+}
+
+and vabstract =
+	| AKind of vabstract
+	| AHash of (value, value) Hashtbl.t
+	| ARandom of Random.State.t ref
+	| ABuffer of Buffer.t
+	| APos of Ast.pos
+	| AFRead of in_channel
+	| AFWrite of out_channel
+	| AReg of regexp
+	| AZipI of zlib
+	| AZipD of zlib
+	| AUtf8 of UTF8.Buf.buf
+	| ASocket of Unix.file_descr
+	| ATExpr of texpr
+	| ATDecl of module_type
+	| AUnsafe of Obj.t
+	| ALazyType of (unit -> Type.t) ref
+	| ANekoAbstract of Extc.value
+	| ANekoBuffer of value
+	| ACacheRef of value
+	| AInt32Kind
+
+and vfunction =
+	| Fun0 of (unit -> value)
+	| Fun1 of (value -> value)
+	| Fun2 of (value -> value -> value)
+	| Fun3 of (value -> value -> value -> value)
+	| Fun4 of (value -> value -> value -> value -> value)
+	| Fun5 of (value -> value -> value -> value -> value -> value)
+	| FunVar of (value list -> value)
+
+and regexp = {
+	r : Str.regexp;
+	mutable r_string : string;
+	mutable r_groups : (int * int) option array;
+}
+
+and zlib = {
+	z : Extc.zstream;
+	mutable z_flush : Extc.zflush;
+}
+
+type cmp =
+	| CEq
+	| CSup
+	| CInf
+	| CUndef
+
+type extern_api = {
+	pos : Ast.pos;
+	get_com : unit -> Common.context;
+	get_type : string -> Type.t option;
+	get_module : string -> Type.t list;
+	on_generate : (Type.t list -> unit) -> unit;
+	on_type_not_found : (string -> value) -> unit;
+	parse_string : string -> Ast.pos -> bool -> Ast.expr;
+	typeof : Ast.expr -> Type.t;
+	get_display : string -> string;
+	allow_package : string -> unit;
+	type_patch : string -> string -> bool -> string option -> unit;
+	meta_patch : string -> string -> string option -> bool -> unit;
+	set_js_generator : (value -> unit) -> unit;
+	get_local_type : unit -> t option;
+	get_local_method : unit -> string;
+	get_local_using : unit -> tclass list;
+	get_local_vars : unit -> (string, Type.tvar) PMap.t;
+	get_build_fields : unit -> value;
+	get_pattern_locals : Ast.expr -> Type.t -> (string,Type.tvar) PMap.t;
+	define_type : value -> unit;
+	module_dependency : string -> string -> bool -> unit;
+	current_module : unit -> module_def;
+	delayed_macro : int -> (unit -> (unit -> value));
+	use_cache : unit -> bool;
+}
+
+type callstack = {
+	cpos : pos;
+	cthis : value;
+	cstack : int;
+	cenv : value array;
+}
+
+type context = {
+	gen : Genneko.context;
+	types : (Type.path,int) Hashtbl.t;
+	prototypes : (string list, vobject) Hashtbl.t;
+	fields_cache : (int,string) Hashtbl.t;
+	mutable error : bool;
+	mutable error_proto : vobject;
+	mutable enums : (value * string) array array;
+	mutable do_call : value -> value -> value list -> pos -> value;
+	mutable do_string : value -> string;
+	mutable do_loadprim : value -> value -> value;
+	mutable do_compare : value -> value -> cmp;
+	mutable loader : value;
+	mutable exports : value;
+	(* runtime *)
+	mutable stack : value DynArray.t;
+	mutable callstack : callstack list;
+	mutable callsize : int;
+	mutable exc : pos list;
+	mutable vthis : value;
+	mutable venv : value array;
+	(* context *)
+	mutable curapi : extern_api;
+	mutable on_reused : (unit -> bool) list;
+	mutable is_reused : bool;
+	(* eval *)
+	mutable locals_map : (string, int) PMap.t;
+	mutable locals_count : int;
+	mutable locals_barrier : int;
+	mutable locals_env : string DynArray.t;
+	mutable globals : (string, value ref) PMap.t;
+}
+
+type access =
+	| AccThis
+	| AccLocal of int
+	| AccGlobal of value ref
+	| AccEnv of int
+	| AccField of (unit -> value) * string
+	| AccArray of (unit -> value) * (unit -> value)
+
+exception Runtime of value
+exception Builtin_error
+
+exception Error of string * Ast.pos list
+
+exception Abort
+exception Continue
+exception Break of value
+exception Return of value
+exception Invalid_expr
+
+(* ---------------------------------------------------------------------- *)
+(* UTILS *)
+
+let get_ctx_ref = ref (fun() -> assert false)
+let encode_complex_type_ref = ref (fun t -> assert false)
+let encode_type_ref = ref (fun t -> assert false)
+let decode_type_ref = ref (fun t -> assert false)
+let encode_expr_ref = ref (fun e -> assert false)
+let decode_expr_ref = ref (fun e -> assert false)
+let encode_clref_ref = ref (fun c -> assert false)
+let enc_hash_ref = ref (fun h -> assert false)
+let enc_array_ref = ref (fun l -> assert false)
+let enc_string_ref = ref (fun s -> assert false)
+let make_ast_ref = ref (fun _ -> assert false)
+let make_complex_type_ref = ref (fun _ -> assert false)
+let get_ctx() = (!get_ctx_ref)()
+let enc_array (l:value list) : value = (!enc_array_ref) l
+let encode_complex_type (t:Ast.complex_type) : value = (!encode_complex_type_ref) t
+let encode_type (t:Type.t) : value = (!encode_type_ref) t
+let decode_type (v:value) : Type.t = (!decode_type_ref) v
+let encode_expr (e:Ast.expr) : value = (!encode_expr_ref) e
+let decode_expr (e:value) : Ast.expr = (!decode_expr_ref) e
+let encode_clref (c:tclass) : value = (!encode_clref_ref) c
+let enc_hash (h:('a,'b) Hashtbl.t) : value = (!enc_hash_ref) h
+let make_ast (e:texpr) : Ast.expr = (!make_ast_ref) e
+let enc_string (s:string) : value = (!enc_string_ref) s
+let make_complex_type (t:Type.t) : Ast.complex_type = (!make_complex_type_ref) t
+
+let to_int f = Int32.of_float (mod_float f 2147483648.0)
+let need_32_bits i = Int32.compare (Int32.logand (Int32.add i 0x40000000l) 0x80000000l) Int32.zero <> 0
+let best_int i = if need_32_bits i then VInt32 i else VInt (Int32.to_int i)
+
+let make_pos p =
+	let low = p.pline land 0xFFFFF in
+	{
+		Ast.pfile = p.psource;
+		Ast.pmin = low;
+		Ast.pmax = low + (p.pline lsr 20);
+	}
+
+let warn ctx msg p =
+	(ctx.curapi.get_com()).Common.warning msg (make_pos p)
+
+let rec pop ctx n =
+	if n > 0 then begin
+		DynArray.delete_last ctx.stack;
+		pop ctx (n - 1);
+	end
+
+let pop_ret ctx f n =
+	let v = f() in
+	pop ctx n;
+	v
+
+let push ctx v =
+	DynArray.add ctx.stack v
+
+let hash f =
+	let h = ref 0 in
+	for i = 0 to String.length f - 1 do
+		h := !h * 223 + int_of_char (String.unsafe_get f i);
+	done;
+	if Sys.word_size = 64 then Int32.to_int (Int32.shift_right (Int32.shift_left (Int32.of_int !h) 1) 1) else !h
+
+let constants =
+	let h = Hashtbl.create 0 in
+	List.iter (fun f -> Hashtbl.add h (hash f) f)
+	["done";"read";"write";"min";"max";"file";"args";"loadprim";"loadmodule";"__a";"__s";"h";
+    "tag";"index";"length";"message";"pack";"name";"params";"sub";"doc";"kind";"meta";"access";
+	"constraints";"opt";"type";"value";"ret";"expr";"field";"values";"get";"__string";"toString";
+	"$";"add";"remove";"has";"__t";"module";"isPrivate";"isPublic";"isExtern";"isInterface";"exclude";
+	"constructs";"names";"superClass";"interfaces";"fields";"statics";"constructor";"init";"t";
+	"gid";"uid";"atime";"mtime";"ctime";"dev";"ino";"nlink";"rdev";"size";"mode";"pos";"len";
+	"binops";"unops";"from";"to";"array";"op";"isPostfix";"impl"];
+	h
+
+let h_get = hash "__get" and h_set = hash "__set"
+and h_add = hash "__add" and h_radd = hash "__radd"
+and h_sub = hash "__sub" and h_rsub = hash "__rsub"
+and h_mult = hash "__mult" and h_rmult = hash "__rmult"
+and h_div = hash "__div" and h_rdiv = hash "__rdiv"
+and h_mod = hash "__mod" and h_rmod = hash "__rmod"
+and h_string = hash "__string" and h_compare = hash "__compare"
+
+and h_constructs = hash "__constructs__" and h_a = hash "__a" and h_s = hash "__s"
+and h_class = hash "__class__"
+
+let exc v =
+	raise (Runtime v)
+
+let hash_field ctx f =
+	let h = hash f in
+	(try
+		let f2 = Hashtbl.find ctx.fields_cache h in
+		if f <> f2 then exc (VString ("Field conflict between " ^ f ^ " and " ^ f2));
+	with Not_found ->
+		Hashtbl.add ctx.fields_cache h f);
+	h
+
+let field_name ctx fid =
+	try
+		Hashtbl.find ctx.fields_cache fid
+	with Not_found ->
+		"???"
+
+let obj hash fields =
+	let fields = Array.of_list (List.map (fun (k,v) -> hash k, v) fields) in
+	Array.sort (fun (k1,_) (k2,_) -> compare k1 k2) fields;
+	{
+		ofields = fields;
+		oproto = None;
+	}
+
+let parse_int s =
+	let rec loop_hex i =
+		if i = String.length s then s else
+		match String.unsafe_get s i with
+		| '0'..'9' | 'a'..'f' | 'A'..'F' -> loop_hex (i + 1)
+		| _ -> String.sub s 0 i
+	in
+	let rec loop sp i =
+		if i = String.length s then (if sp = 0 then s else String.sub s sp (i - sp)) else
+		match String.unsafe_get s i with
+		| '0'..'9' -> loop sp (i + 1)
+		| ' ' when sp = i -> loop (sp + 1) (i + 1)
+		| '-' when i = 0 -> loop sp (i + 1)
+		| ('x' | 'X') when i = 1 && String.get s 0 = '0' -> loop_hex (i + 1)
+		| _ -> String.sub s sp (i - sp)
+	in
+	best_int (Int32.of_string (loop 0 0))
+
+let parse_float s =
+	let rec loop sp i =
+		if i = String.length s then (if sp = 0 then s else String.sub s sp (i - sp)) else
+		match String.unsafe_get s i with
+		| ' ' when sp = i -> loop (sp + 1) (i + 1)
+		| '0'..'9' | '-' | 'e' | 'E' | '.' -> loop sp (i + 1)
+		| _ -> String.sub s sp (i - sp)
+	in
+	float_of_string (loop 0 0)
+
+let find_sub str sub start =
+	let sublen = String.length sub in
+	if sublen = 0 then
+		0
+	else
+		let found = ref 0 in
+		let len = String.length str in
+		try
+			for i = start to len - sublen do
+				let j = ref 0 in
+				while String.unsafe_get str (i + !j) = String.unsafe_get sub !j do
+					incr j;
+					if !j = sublen then begin found := i; raise Exit; end;
+				done;
+			done;
+			raise Not_found
+		with
+			Exit -> !found
+
+let nargs = function
+	| Fun0 _ -> 0
+	| Fun1 _ -> 1
+	| Fun2 _ -> 2
+	| Fun3 _ -> 3
+	| Fun4 _ -> 4
+	| Fun5 _ -> 5
+	| FunVar _ -> -1
+
+let rec get_field o fid =
+	let rec loop min max =
+		if min < max then begin
+			let mid = (min + max) lsr 1 in
+			let cid, v = Array.unsafe_get o.ofields mid in
+			if cid < fid then
+				loop (mid + 1) max
+			else if cid > fid then
+				loop min mid
+			else
+				v
+		end else
+			match o.oproto with
+			| None -> VNull
+			| Some p -> get_field p fid
+	in
+	loop 0 (Array.length o.ofields)
+
+let set_field o fid v =
+	let rec loop min max =
+		let mid = (min + max) lsr 1 in
+		if min < max then begin
+			let cid, _ = Array.unsafe_get o.ofields mid in
+			if cid < fid then
+				loop (mid + 1) max
+			else if cid > fid then
+				loop min mid
+			else
+				Array.unsafe_set o.ofields mid (cid,v)
+		end else
+			let fields = Array.make (Array.length o.ofields + 1) (fid,v) in
+			Array.blit o.ofields 0 fields 0 mid;
+			Array.blit o.ofields mid fields (mid + 1) (Array.length o.ofields - mid);
+			o.ofields <- fields
+	in
+	loop 0 (Array.length o.ofields)
+
+let rec remove_field o fid =
+	let rec loop min max =
+		let mid = (min + max) lsr 1 in
+		if min < max then begin
+			let cid, v = Array.unsafe_get o.ofields mid in
+			if cid < fid then
+				loop (mid + 1) max
+			else if cid > fid then
+				loop min mid
+			else begin
+				let fields = Array.make (Array.length o.ofields - 1) (fid,VNull) in
+				Array.blit o.ofields 0 fields 0 mid;
+				Array.blit o.ofields (mid + 1) fields mid (Array.length o.ofields - mid - 1);
+				o.ofields <- fields;
+				true
+			end
+		end else
+			false
+	in
+	loop 0 (Array.length o.ofields)
+
+let rec get_field_opt o fid =
+	let rec loop min max =
+		if min < max then begin
+			let mid = (min + max) lsr 1 in
+			let cid, v = Array.unsafe_get o.ofields mid in
+			if cid < fid then
+				loop (mid + 1) max
+			else if cid > fid then
+				loop min mid
+			else
+				Some v
+		end else
+			match o.oproto with
+			| None -> None
+			| Some p -> get_field_opt p fid
+	in
+	loop 0 (Array.length o.ofields)
+
+let catch_errors ctx ?(final=(fun() -> ())) f =
+	let n = DynArray.length ctx.stack in
+	try
+		let v = f() in
+		final();
+		Some v
+	with Runtime v ->
+		pop ctx (DynArray.length ctx.stack - n);
+		final();
+		let rec loop o =
+			if o == ctx.error_proto then true else match o.oproto with None -> false | Some p -> loop p
+		in
+		(match v with
+		| VObject o when loop o ->
+			(match get_field o (hash "message"), get_field o (hash "pos") with
+			| VObject msg, VAbstract (APos pos) ->
+				(match get_field msg h_s with
+				| VString msg -> raise (Typecore.Error (Typecore.Custom msg,pos))
+				| _ -> ());
+			| _ -> ());
+		| _ -> ());
+		raise (Error (ctx.do_string v,List.map (fun s -> make_pos s.cpos) ctx.callstack))
+	| Abort ->
+		pop ctx (DynArray.length ctx.stack - n);
+		final();
+		None
+
+let make_library fl =
+	let h = Hashtbl.create 0 in
+	List.iter (fun (n,f) -> Hashtbl.add h n f) fl;
+	h
+
+(* ---------------------------------------------------------------------- *)
+(* NEKO INTEROP *)
+
+type primitive = (string * Extc.value * int)
+
+type neko_context = {
+	load : string -> int -> primitive;
+	call : primitive -> value list -> value;
+}
+
+let neko =
+	let is_win = Sys.os_type = "Win32" || Sys.os_type = "Cygwin" in
+	let neko = Extc.dlopen (if is_win then "neko.dll" else "libneko.so") in
+	let null = Extc.dlint 0 in
+	let neko = if Obj.magic neko == null && not is_win then Extc.dlopen "libneko.dylib" else neko in
+	if Obj.magic neko == null then
+		None
+	else
+	let load v =
+		let s = Extc.dlsym neko v in
+		if (Obj.magic s) == null then failwith ("Could not load neko." ^ v);
+		s
+	in
+	ignore(Extc.dlcall0 (load "neko_global_init"));
+	let vm = Extc.dlcall1 (load "neko_vm_alloc") null in
+	ignore(Extc.dlcall1 (load "neko_vm_select") vm);
+	let loader = Extc.dlcall2 (load "neko_default_loader") null null in
+	let loadprim = Extc.dlcall2 (load "neko_val_field") loader (Extc.dlcall1 (load "neko_val_id") (Extc.dlstring "loadprim")) in
+
+	let callN = load "neko_val_callN" in
+	let callEx = load "neko_val_callEx" in
+	let copy_string = load "neko_copy_string" in
+
+	let alloc_root = load "neko_alloc_root" in
+	let free_root = load "neko_free_root" in
+
+	let alloc_root v =
+		let r = Extc.dlcall1 alloc_root (Extc.dlint 1) in
+		Extc.dlsetptr r v;
+		r
+	in
+	let free_root r =
+		ignore(Extc.dlcall1 free_root r)
+	in
+
+	ignore(alloc_root vm);
+	ignore(alloc_root loader);
+	ignore(alloc_root loadprim);
+
+	let alloc_string s =
+		Extc.dlcall2 copy_string (Extc.dlstring s) (Extc.dlint (String.length s))
+	in
+	let alloc_int (i:int) : Extc.value =
+		Obj.magic i
+	in
+	let loadprim n args =
+		let exc = ref null in
+		let vargs = [|alloc_string n;alloc_int args|] in
+		let p = Extc.dlcall5 callEx loader loadprim (Obj.magic vargs) (Extc.dlint 2) (Obj.magic exc) in
+		if !exc != null then failwith ("Failed to load " ^ n ^ ":" ^ string_of_int args);
+		ignore(alloc_root p);
+		(n,p,args)
+	in
+	let call_raw_prim (_,p,nargs) (args:Extc.value array) =
+		Extc.dlcall3 callN p (Obj.magic args) (Extc.dlint nargs)
+	in
+
+	(* a bit tricky since load "val_true" does not work as expected on Windows *)
+	let unser = try loadprim "std@unserialize" 2 with _ -> ("",null,0) in
+
+	(* did we fail to load std.ndll ? *)
+	if (match unser with ("",_,_) -> true | _ -> false) then None else
+
+	let val_true = call_raw_prim unser [|alloc_string "T";loader|] in
+	let val_false = call_raw_prim unser [|alloc_string "F";loader|] in
+	let val_null = call_raw_prim unser [|alloc_string "N";loader|] in
+
+	let is_64 = call_raw_prim (loadprim "std@sys_is64" 0) [||] == val_true in
+	let alloc_i32, is_v2 = (try load "neko_alloc_int32", true with _ -> Obj.magic 0, false) in
+	let alloc_i32 = if is_v2 then
+		(fun i -> Extc.dlcall1 alloc_i32 (Extc.dlint32 i))
+	else
+		(fun i -> alloc_int (Int32.to_int (if Int32.compare i Int32.zero < 0 then Int32.logand i 0x7FFFFFFFl else Int32.logor i 0x80000000l)))
+	in
+	let tag_bits = if is_v2 then 4 else 3 in
+	let tag_mask = (1 lsl tag_bits) - 1 in
+	let ptr_size = if is_64 then 8 else 4 in
+	let val_field v i = Extc.dladdr v ((i + 1) * ptr_size) in
+	let val_str v = Extc.dladdr v 4 in
+	let val_fun_env v = Extc.dladdr v (8 + ptr_size) in
+
+	(* alloc support *)
+
+	let alloc_function = load "neko_alloc_function" in
+	let alloc_array = load "neko_alloc_array" in
+	let alloc_float = load "neko_alloc_float" in
+	let alloc_object = load "neko_alloc_object" in
+	let alloc_field = load "neko_alloc_field" in
+	let alloc_abstract = load "neko_alloc_abstract" in
+	let val_gc = load "neko_val_gc" in
+	let val_field_name = load "neko_val_field_name" in
+	let val_iter_fields = load "neko_val_iter_fields" in
+	let gen_callback = Extc.dlcaml_callback 2 in
+
+	(* roots *)
+
+	let on_abstract_gc = Extc.dlcaml_callback 1 in
+	let root_index = ref 0 in
+	let roots = Hashtbl.create 0 in
+	Callback.register "dlcallb1" (fun a ->
+		let index : int = Obj.magic (Extc.dlptr (val_field a 1)) in
+		Hashtbl.remove roots index;
+		null
+	);
+
+	(* wrapping *)
+
+	let copy_string v =
+		let head = Extc.dltoint (Extc.dlptr v) in
+		let size = head asr tag_bits in
+		let s = String.create size in
+		Extc.dlmemcpy (Extc.dlstring s) (val_str v) size;
+		s
+	in
+
+	let buffers = ref [] in
+
+	let rec value_neko ?(obj=VNull) = function
+		| VNull -> val_null
+		| VBool b -> if b then val_true else val_false
+		| VInt i -> alloc_int i
+		| VAbstract (ANekoAbstract a) -> a
+		| VAbstract (ANekoBuffer (VString buf)) ->
+			let v = value_neko (VString buf) in
+			buffers := (buf,v) :: !buffers;
+			v
+		| VString s ->
+			let v = alloc_string s in (* make a copy *)
+			ignore(copy_string v);
+			v
+		| VObject o as obj ->
+			let vo = Extc.dlcall1 alloc_object null in
+			Array.iter (fun (id,v) ->
+				ignore(Extc.dlcall3 alloc_field vo (Extc.dlint id) (value_neko ~obj v))
+			) o.ofields;
+			vo
+		| VClosure _ ->
+			failwith "Closure not supported"
+		| VFunction f ->
+			let callb = Extc.dlcall3 alloc_function gen_callback (Extc.dlint (-1)) (Obj.magic "<callback>") in
+			let index = !root_index in
+			incr root_index;
+			Hashtbl.add roots index (f,obj);
+			let a = Extc.dlcall2 alloc_abstract null (Obj.magic index) in
+			if Extc.dlptr (val_field a 1) != Obj.magic index then assert false;
+			ignore(Extc.dlcall2 val_gc a on_abstract_gc);
+			Extc.dlsetptr (val_fun_env callb) a;
+			callb
+		| VArray a ->
+			let va = Extc.dlcall1 alloc_array (Extc.dlint (Array.length a)) in
+			Array.iteri (fun i v ->
+				Extc.dlsetptr (val_field va i) (value_neko v)
+			) a;
+			va
+		| VFloat f ->
+			Extc.dlcall1 alloc_float (Obj.magic f)
+		| VAbstract _ ->
+			failwith "Abstract not supported"
+		| VInt32 i ->
+			alloc_i32 i
+	in
+	let obj_r = ref [] in
+	let obj_fun = (fun v id -> obj_r := (v,id) :: !obj_r; val_null) in
+	let rec neko_value (v:Extc.value) =
+		if Obj.is_int (Obj.magic v) then
+			VInt (Obj.magic v)
+		else
+			let head = Extc.dltoint (Extc.dlptr v) in
+			match head land tag_mask with
+			| 0 -> VNull
+			| 2 -> VBool (v == val_true)
+			| 3 -> VString (copy_string v)
+			| 4 ->
+				ignore(Extc.dlcall3 val_iter_fields v (Extc.dlcallback 2) (Obj.magic obj_fun));
+				let r = !obj_r in
+				obj_r := [];
+				let ctx = get_ctx() in
+				let fields = List.rev_map (fun (v,id) ->
+					let iid = Extc.dltoint id in
+					if not (Hashtbl.mem ctx.fields_cache iid) then begin
+						let name = copy_string (Extc.dlcall1 val_field_name id) in
+						ignore(hash_field ctx name);
+					end;
+					iid, neko_value v
+				) r in
+				VObject { ofields = Array.of_list fields; oproto = None }
+			| 5 ->
+				VArray (Array.init (head asr tag_bits) (fun i -> neko_value (Extc.dlptr (val_field v i))))
+			| 7 ->
+				let r = alloc_root v in
+				let a = ANekoAbstract v in
+				Gc.finalise (fun _ -> free_root r) a;
+				VAbstract a
+			| t ->
+				failwith ("Unsupported Neko value tag " ^ string_of_int t)
+	in
+
+	Callback.register "dlcallb2" (fun args nargs ->
+		(* get back the VM env, which was set in value_neko *)
+		let env = Extc.dlptr (Extc.dladdr vm (2 * ptr_size)) in
+		(* extract the index stored in abstract data *)
+		let index : int = Obj.magic (Extc.dlptr (val_field env 1)) in
+		let f, obj = (try Hashtbl.find roots index with Not_found -> assert false) in
+		let nargs = Extc.dltoint nargs in
+		let rec loop i =
+			if i = nargs then [] else neko_value (Extc.dlptr (Extc.dladdr args (i * ptr_size))) :: loop (i + 1)
+		in
+		let v = (get_ctx()).do_call obj (VFunction f) (loop 0) { psource = "<callback>"; pline = 0; } in
+		value_neko v
+	);
+
+	let callprim (n,p,nargs) args =
+		let arr = Array.of_list (List.map value_neko args) in
+		let exc = ref null in
+		if Array.length arr <> nargs then failwith n;
+		let ret = Extc.dlcall5 callEx val_null p (Obj.magic arr) (Extc.dlint nargs) (Obj.magic exc) in
+		if !exc != null then raise (Runtime (neko_value !exc));
+		(match !buffers with
+		| [] -> ()
+		| l ->
+			buffers := [];
+			(* copy back data *)
+			List.iter (fun (buf,v) ->
+				Extc.dlmemcpy (Extc.dlstring buf) (val_str v) (String.length buf);
+			) l);
+		neko_value ret
+	in
+	Some {
+		load = loadprim;
+		call = callprim;
+	}
+
+(* ---------------------------------------------------------------------- *)
+(* BUILTINS *)
+
+let builtins =
+	let p = { psource = "<builtin>"; pline = 0 } in
+	let error() =
+		raise Builtin_error
+	in
+	let vint = function
+		| VInt n -> n
+		| _ -> error()
+	in
+	let varray = function
+		| VArray a -> a
+		| _ -> error()
+	in
+	let vstring = function
+		| VString s -> s
+		| _ -> error()
+	in
+	let vobj = function
+		| VObject o -> o
+		| _ -> error()
+	in
+	let vfun = function
+		| VFunction f -> f
+		| VClosure (cl,f) -> FunVar (f cl)
+		| _ -> error()
+	in
+	let vhash = function
+		| VAbstract (AHash h) -> h
+		| _ -> error()
+	in
+	let build_stack sl =
+		let make p =
+			let p = make_pos p in
+			VArray [|VString p.Ast.pfile;VInt (Lexer.get_error_line p)|]
+		in
+		VArray (Array.of_list (List.map make sl))
+	in
+	let do_closure args args2 =
+		match args with
+		| f :: obj :: args ->
+			(get_ctx()).do_call obj f (args @ args2) p
+		| _ ->
+			assert false
+	in
+	let funcs = [
+	(* array *)
+		"array", FunVar (fun vl -> VArray (Array.of_list vl));
+		"amake", Fun1 (fun v -> VArray (Array.create (vint v) VNull));
+		"acopy", Fun1 (fun a -> VArray (Array.copy (varray a)));
+		"asize", Fun1 (fun a -> VInt (Array.length (varray a)));
+		"asub", Fun3 (fun a p l -> VArray (Array.sub (varray a) (vint p) (vint l)));
+		"ablit", Fun5 (fun dst dstp src p l ->
+			Array.blit (varray src) (vint p) (varray dst) (vint dstp) (vint l);
+			VNull
+		);
+		"aconcat", Fun1 (fun arr ->
+			let arr = Array.map varray (varray arr) in
+			VArray (Array.concat (Array.to_list arr))
+		);
+	(* string *)
+		"string", Fun1 (fun v -> VString ((get_ctx()).do_string v));
+		"smake", Fun1 (fun l -> VString (String.make (vint l) '\000'));
+		"ssize", Fun1 (fun s -> VInt (String.length (vstring s)));
+		"scopy", Fun1 (fun s -> VString (String.copy (vstring s)));
+		"ssub", Fun3 (fun s p l -> VString (String.sub (vstring s) (vint p) (vint l)));
+		"sget", Fun2 (fun s p ->
+			try VInt (int_of_char (String.get (vstring s) (vint p))) with Invalid_argument _ -> VNull
+		);
+		"sset", Fun3 (fun s p c ->
+			let c = char_of_int ((vint c) land 0xFF) in
+			try
+				String.set (vstring s) (vint p) c;
+				VInt (int_of_char c)
+			with Invalid_argument _ -> VNull);
+		"sblit", Fun5 (fun dst dstp src p l ->
+			String.blit (vstring src) (vint p) (vstring dst) (vint dstp) (vint l);
+			VNull
+		);
+		"sfind", Fun3 (fun src pos pat ->
+			try VInt (find_sub (vstring src) (vstring pat) (vint pos)) with Not_found -> VNull
+		);
+	(* object *)
+		"new", Fun1 (fun o ->
+			match o with
+			| VNull -> VObject { ofields = [||]; oproto = None }
+			| VObject o -> VObject { ofields = Array.copy o.ofields; oproto = o.oproto }
+			| _ -> error()
+		);
+		"objget", Fun2 (fun o f ->
+			match o with
+			| VObject o -> get_field o (vint f)
+			| _ -> VNull
+		);
+		"objset", Fun3 (fun o f v ->
+			match o with
+			| VObject o -> set_field o (vint f) v; v
+			| _ -> VNull
+		);
+		"objcall", Fun3 (fun o f pl ->
+			match o with
+			| VObject oo ->
+				(get_ctx()).do_call o (get_field oo (vint f)) (Array.to_list (varray pl)) p
+			| _ -> VNull
+		);
+		"objfield", Fun2 (fun o f ->
+			match o with
+			| VObject o ->
+				let p = o.oproto in
+				o.oproto <- None;
+				let v = get_field_opt o (vint f) in
+				o.oproto <- p;
+				VBool (v <> None)
+			| _ -> VBool false
+		);
+		"objremove", Fun2 (fun o f ->
+			VBool (remove_field (vobj o) (vint f))
+		);
+		"objfields", Fun1 (fun o ->
+			VArray (Array.map (fun (fid,_) -> VInt fid) (vobj o).ofields)
+		);
+		"hash", Fun1 (fun v -> VInt (hash_field (get_ctx()) (vstring v)));
+		"fasthash", Fun1 (fun v -> VInt (hash (vstring v)));
+		"field", Fun1 (fun v ->
+			try VString (Hashtbl.find (get_ctx()).fields_cache (vint v)) with Not_found -> VNull
+		);
+		"objsetproto", Fun2 (fun o p ->
+			let o = vobj o in
+			(match p with
+			| VNull -> o.oproto <- None
+			| VObject p -> o.oproto <- Some p
+			| _ -> error());
+			VNull;
+		);
+		"objgetproto", Fun1 (fun o ->
+			match (vobj o).oproto with
+			| None -> VNull
+			| Some p -> VObject p
+		);
+	(* function *)
+		"nargs", Fun1 (fun f ->
+			VInt (nargs (vfun f))
+		);
+		"call", Fun3 (fun f o args ->
+			(get_ctx()).do_call o f (Array.to_list (varray args)) p
+		);
+		"closure", FunVar (fun vl ->
+			match vl with
+			| VFunction f :: _ :: _ ->
+				VClosure (vl, do_closure)
+			| _ -> exc (VString "Can't create closure : value is not a function")
+		);
+		"apply", FunVar (fun vl ->
+			match vl with
+			| f :: args ->
+				let f = vfun f in
+				VFunction (FunVar (fun args2 -> (get_ctx()).do_call VNull (VFunction f) (args @ args2) p))
+			| _ -> exc (VString "Invalid closure arguments number")
+		);
+		"varargs", Fun1 (fun f ->
+			match f with
+			| VFunction (FunVar _) | VFunction (Fun1 _) | VClosure _ ->
+				VFunction (FunVar (fun vl -> (get_ctx()).do_call VNull f [VArray (Array.of_list vl)] p))
+			| _ ->
+				error()
+		);
+	(* numbers *)
+		(* skip iadd, isub, idiv, imult *)
+		"isnan", Fun1 (fun f ->
+			match f with
+			| VFloat f -> VBool (f <> f)
+			| _ -> VBool false
+		);
+		"isinfinite", Fun1 (fun f ->
+			match f with
+			| VFloat f -> VBool (f = infinity || f = neg_infinity)
+			| _ -> VBool false
+		);
+		"int", Fun1 (fun v ->
+			match v with
+			| VInt _ | VInt32 _ -> v
+			| VFloat f -> best_int (to_int f)
+			| VString s -> (try parse_int s with _ -> VNull)
+			| _ -> VNull
+		);
+		"float", Fun1 (fun v ->
+			match v with
+			| VInt i -> VFloat (float_of_int i)
+			| VInt32 i -> VFloat (Int32.to_float i)
+			| VFloat _ -> v
+			| VString s -> (try VFloat (parse_float s) with _ -> VNull)
+			| _ -> VNull
+		);
+	(* abstract *)
+		"getkind", Fun1 (fun v ->
+			match v with
+			| VAbstract a -> VAbstract (AKind a)
+			| VInt32 _ -> VAbstract (AKind AInt32Kind)
+			| _ -> error()
+		);
+		"iskind", Fun2 (fun v k ->
+			match v, k with
+			| VAbstract a, VAbstract (AKind k) -> VBool (Obj.tag (Obj.repr a) = Obj.tag (Obj.repr k))
+			| VInt32 _, VAbstract (AKind AInt32Kind) -> VBool true
+			| _, VAbstract (AKind _) -> VBool false
+			| _ -> error()
+		);
+	(* hash *)
+		"hkey", Fun1 (fun v -> VInt (Hashtbl.hash v));
+		"hnew", Fun1 (fun v ->
+			VAbstract (AHash (match v with
+			| VNull -> Hashtbl.create 0
+			| VInt n -> Hashtbl.create n
+			| _ -> error()))
+		);
+		"hresize", Fun1 (fun v -> VNull);
+		"hget", Fun3 (fun h k cmp ->
+			if cmp <> VNull then assert false;
+			(try Hashtbl.find (vhash h) k with Not_found -> VNull)
+		);
+		"hmem", Fun3 (fun h k cmp ->
+			if cmp <> VNull then assert false;
+			VBool (Hashtbl.mem (vhash h) k)
+		);
+		"hremove", Fun3 (fun h k cmp ->
+			if cmp <> VNull then assert false;
+			let h = vhash h in
+			let old = Hashtbl.mem h k in
+			if old then Hashtbl.remove h k;
+			VBool old
+		);
+		"hset", Fun4 (fun h k v cmp ->
+			if cmp <> VNull then assert false;
+			let h = vhash h in
+			let old = Hashtbl.mem h k in
+			Hashtbl.replace h k v;
+			VBool (not old);
+		);
+		"hadd", Fun4 (fun h k v cmp ->
+			if cmp <> VNull then assert false;
+			let h = vhash h in
+			let old = Hashtbl.mem h k in
+			Hashtbl.add h k v;
+			VBool (not old);
+		);
+		"hiter", Fun2 (fun h f -> Hashtbl.iter (fun k v -> ignore ((get_ctx()).do_call VNull f [k;v] p)) (vhash h); VNull);
+		"hcount", Fun1 (fun h -> VInt (Hashtbl.length (vhash h)));
+		"hsize", Fun1 (fun h -> VInt (Hashtbl.length (vhash h)));
+	(* misc *)
+		"print", FunVar (fun vl -> List.iter (fun v ->
+			let ctx = get_ctx() in
+			let com = ctx.curapi.get_com() in
+			com.print (ctx.do_string v)
+		) vl; VNull);
+		"throw", Fun1 (fun v -> exc v);
+		"rethrow", Fun1 (fun v ->
+			let ctx = get_ctx() in
+			ctx.callstack <- List.rev (List.map (fun p -> { cpos = p; cthis = ctx.vthis; cstack = DynArray.length ctx.stack; cenv = ctx.venv }) ctx.exc) @ ctx.callstack;
+			exc v
+		);
+		"istrue", Fun1 (fun v ->
+			match v with
+			| VNull | VInt 0 | VBool false | VInt32 0l -> VBool false
+			| _ -> VBool true
+		);
+		"not", Fun1 (fun v ->
+			match v with
+			| VNull | VInt 0 | VBool false | VInt32 0l -> VBool true
+			| _ -> VBool false
+		);
+		"typeof", Fun1 (fun v ->
+			VInt (match v with
+			| VNull -> 0
+			| VInt _ | VInt32 _ -> 1
+			| VFloat _ -> 2
+			| VBool _ -> 3
+			| VString _ -> 4
+			| VObject _ -> 5
+			| VArray _ -> 6
+			| VFunction _ | VClosure _ -> 7
+			| VAbstract _ -> 8)
+		);
+		"compare", Fun2 (fun a b ->
+			match (get_ctx()).do_compare a b with
+			| CUndef -> VNull
+			| CEq -> VInt 0
+			| CSup -> VInt 1
+			| CInf -> VInt (-1)
+		);
+		"pcompare", Fun2 (fun a b ->
+	 		assert false
+	 	);
+	 	"excstack", Fun0 (fun() ->
+			build_stack (get_ctx()).exc
+	 	);
+	 	"callstack", Fun0 (fun() ->
+	 		build_stack (List.map (fun s -> s.cpos) (get_ctx()).callstack)
+	 	);
+	 	"version", Fun0 (fun() ->
+	 		VInt 200
+	 	);
+	(* extra *)
+		"use_neko_dll", Fun0 (fun() ->
+			VBool (neko <> None)
+		);
+	] in
+	let vals = [
+		"tnull", VInt 0;
+		"tint", VInt 1;
+		"tfloat", VInt 2;
+		"tbool", VInt 3;
+		"tstring", VInt 4;
+		"tobject", VInt 5;
+		"tarray", VInt 6;
+		"tfunction", VInt 7;
+		"tabstract", VInt 8;
+	] in
+	let h = Hashtbl.create 0 in
+	List.iter (fun (n,f) -> Hashtbl.add h n (VFunction f)) funcs;
+	List.iter (fun (n,v) -> Hashtbl.add h n v) vals;
+	h
+
+(* ---------------------------------------------------------------------- *)
+(* STD LIBRARY *)
+
+let std_lib =
+	let p = { psource = "<stdlib>"; pline = 0 } in
+	let error() =
+		raise Builtin_error
+	in
+	let make_list l =
+		let rec loop acc = function
+			| [] -> acc
+			| x :: l -> loop (VArray [|x;acc|]) l
+		in
+		loop VNull (List.rev l)
+	in
+	let num = function
+		| VInt i -> float_of_int i
+		| VInt32 i -> Int32.to_float i
+		| VFloat f -> f
+		| _ -> error()
+	in
+	let make_date f =
+		VInt32 (Int32.of_float f)
+	in
+	let date = function
+		| VInt32 i -> Int32.to_float i
+		| VInt i -> float_of_int i
+		| _ -> error()
+	in
+	let make_i32 i =
+		VInt32 i
+	in
+	let int32 = function
+		| VInt i -> Int32.of_int i
+		| VInt32 i -> i
+		| _ -> error()
+	in
+	let vint = function
+		| VInt n -> n
+		| _ -> error()
+	in
+	let vstring = function
+		| VString s -> s
+		| _ -> error()
+	in
+	let int32_addr h =
+		let base = Int32.to_int (Int32.logand h 0xFFFFFFl) in
+		let str = Printf.sprintf "%ld.%d.%d.%d" (Int32.shift_right_logical h 24) (base lsr 16) ((base lsr 8) land 0xFF) (base land 0xFF) in
+		Unix.inet_addr_of_string str
+	in
+	let int32_op op = Fun2 (fun a b -> make_i32 (op (int32 a) (int32 b))) in
+	make_library ([
+	(* math *)
+		"math_atan2", Fun2 (fun a b -> VFloat (atan2 (num a) (num b)));
+		"math_pow", Fun2 (fun a b -> VFloat ((num a) ** (num b)));
+		"math_abs", Fun1 (fun v ->
+			match v with
+			| VInt i -> VInt (abs i)
+			| VInt32 i -> VInt32 (Int32.abs i)
+			| VFloat f -> VFloat (abs_float f)
+			| _ -> error()
+		);
+		"math_ceil", Fun1 (fun v -> match v with VInt _ | VInt32 _ -> v | _ -> best_int (to_int (ceil (num v))));
+		"math_floor", Fun1 (fun v -> match v with VInt _ | VInt32 _ -> v | _ -> best_int (to_int (floor (num v))));
+		"math_round", Fun1 (fun v -> match v with VInt _ | VInt32 _ -> v | _ -> best_int (to_int (floor (num v +. 0.5))));
+		"math_pi", Fun0 (fun() -> VFloat (4.0 *. atan 1.0));
+		"math_sqrt", Fun1 (fun v -> VFloat (sqrt (num v)));
+		"math_atan", Fun1 (fun v -> VFloat (atan (num v)));
+		"math_cos", Fun1 (fun v -> VFloat (cos (num v)));
+		"math_sin", Fun1 (fun v -> VFloat (sin (num v)));
+		"math_tan", Fun1 (fun v -> VFloat (tan (num v)));
+		"math_log", Fun1 (fun v -> VFloat (Pervasives.log (num v)));
+		"math_exp", Fun1 (fun v -> VFloat (exp (num v)));
+		"math_acos", Fun1 (fun v -> VFloat (acos (num v)));
+		"math_asin", Fun1 (fun v -> VFloat (asin (num v)));
+		"math_fceil", Fun1 (fun v -> VFloat (ceil (num v)));
+		"math_ffloor", Fun1 (fun v -> VFloat (floor (num v)));
+		"math_fround", Fun1 (fun v -> VFloat (floor (num v +. 0.5)));
+		"math_int", Fun1 (fun v ->
+			match v with
+			| VInt _ | VInt32 _ -> v
+			| VFloat f -> best_int (to_int (if f < 0. then ceil f else floor f))
+			| _ -> error()
+		);
+	(* buffer *)
+		"buffer_new", Fun0 (fun() ->
+			VAbstract (ABuffer (Buffer.create 0))
+		);
+		"buffer_add", Fun2 (fun b v ->
+			match b with
+			| VAbstract (ABuffer b) -> Buffer.add_string b ((get_ctx()).do_string v); VNull
+			| _ -> error()
+		);
+		"buffer_add_char", Fun2 (fun b v ->
+			match b, v with
+			| VAbstract (ABuffer b), VInt n when n >= 0 && n < 256 -> Buffer.add_char b (char_of_int n); VNull
+			| _ -> error()
+		);
+		"buffer_add_sub", Fun4 (fun b s p l ->
+			match b, s, p, l with
+			| VAbstract (ABuffer b), VString s, VInt p, VInt l -> (try Buffer.add_substring b s p l; VNull with _ -> error())
+			| _ -> error()
+		);
+		"buffer_string", Fun1 (fun b ->
+			match b with
+			| VAbstract (ABuffer b) -> VString (Buffer.contents b)
+			| _ -> error()
+		);
+		"buffer_reset", Fun1 (fun b ->
+			match b with
+			| VAbstract (ABuffer b) -> Buffer.reset b; VNull;
+			| _ -> error()
+		);
+	(* date *)
+		"date_now", Fun0 (fun () ->
+			make_date (Unix.time())
+		);
+		"date_new", Fun1 (fun v ->
+			make_date (match v with
+			| VNull -> Unix.time()
+			| VString s ->
+				(match String.length s with
+				| 19 ->
+					let r = Str.regexp "^\\([0-9][0-9][0-9][0-9]\\)-\\([0-9][0-9]\\)-\\([0-9][0-9]\\) \\([0-9][0-9]\\):\\([0-9][0-9]\\):\\([0-9][0-9]\\)$" in
+					if not (Str.string_match r s 0) then exc (VString ("Invalid date format : " ^ s));
+					let t = Unix.localtime (Unix.time()) in
+					let t = { t with
+						tm_year = int_of_string (Str.matched_group 1 s) - 1900;
+						tm_mon = int_of_string (Str.matched_group 2 s) - 1;
+						tm_mday = int_of_string (Str.matched_group 3 s);
+						tm_hour = int_of_string (Str.matched_group 4 s);
+						tm_min = int_of_string (Str.matched_group 5 s);
+						tm_sec = int_of_string (Str.matched_group 6 s);
+					} in
+					fst (Unix.mktime t)
+				| 10 ->
+					assert false
+				| 8 ->
+					assert false
+				| _ ->
+					exc (VString ("Invalid date format : " ^ s)));
+			| _ -> error())
+		);
+		"date_set_hour", Fun4 (fun d h m s ->
+			let d = date d in
+			let t = Unix.localtime d in
+			make_date (fst (Unix.mktime { t with tm_hour = vint h; tm_min = vint m; tm_sec = vint s }))
+		);
+		"date_set_day", Fun4 (fun d y m da ->
+			let d = date d in
+			let t = Unix.localtime d in
+			make_date (fst (Unix.mktime { t with tm_year = vint y - 1900; tm_mon = vint m - 1; tm_mday = vint da }))
+		);
+		"date_format", Fun2 (fun d fmt ->
+			match fmt with
+			| VNull ->
+				let t = Unix.localtime (date d) in
+				VString (Printf.sprintf "%.4d-%.2d-%.2d %.2d:%.2d:%.2d" (t.tm_year + 1900) (t.tm_mon + 1) t.tm_mday t.tm_hour t.tm_min t.tm_sec)
+			| VString "%w" ->
+				(* week day *)
+				let t = Unix.localtime (date d) in
+				VString (string_of_int t.tm_wday)
+			| VString _ ->
+				exc (VString "Custom date format is not supported") (* use native Haxe implementation *)
+			| _ ->
+				error()
+		);
+		"date_get_hour", Fun1 (fun d ->
+			let t = Unix.localtime (date d) in
+			let o = obj (hash_field (get_ctx())) [
+				"h", VInt t.tm_hour;
+				"m", VInt t.tm_min;
+				"s", VInt t.tm_sec;
+			] in
+			VObject o
+		);
+		"date_get_day", Fun1 (fun d ->
+			let t = Unix.localtime (date d) in
+			let o = obj (hash_field (get_ctx())) [
+				"d", VInt t.tm_mday;
+				"m", VInt (t.tm_mon + 1);
+				"y", VInt (t.tm_year + 1900);
+			] in
+			VObject o
+		);
+	(* string *)
+		"string_split", Fun2 (fun s d ->
+			make_list (match s, d with
+			| VString "", VString _ -> [VString ""]
+			| VString s, VString "" -> Array.to_list (Array.init (String.length s) (fun i -> VString (String.make 1 (String.get s i))))
+			| VString s, VString d -> List.map (fun s -> VString s) (ExtString.String.nsplit s d)
+			| _ -> error())
+		);
+		"url_encode", Fun1 (fun s ->
+			let s = vstring s in
+			let b = Buffer.create 0 in
+			let hex = "0123456789ABCDEF" in
+			for i = 0 to String.length s - 1 do
+				let c = String.unsafe_get s i in
+				match c with
+				| 'A'..'Z' | 'a'..'z' | '0'..'9' | '_' | '-' | '.' ->
+					Buffer.add_char b c
+				| _ ->
+					Buffer.add_char b '%';
+					Buffer.add_char b (String.unsafe_get hex (int_of_char c lsr 4));
+					Buffer.add_char b (String.unsafe_get hex (int_of_char c land 0xF));
+			done;
+			VString (Buffer.contents b)
+		);
+		"url_decode", Fun1 (fun s ->
+			let s = vstring s in
+			let b = Buffer.create 0 in
+			let len = String.length s in
+			let decode c =
+				match c with
+				| '0'..'9' -> Some (int_of_char c - int_of_char '0')
+				| 'a'..'f' -> Some (int_of_char c - int_of_char 'a' + 10)
+				| 'A'..'F' -> Some (int_of_char c - int_of_char 'A' + 10)
+				| _ -> None
+			in
+			let rec loop i =
+				if i = len then () else
+				let c = String.unsafe_get s i in
+				match c with
+				| '%' ->
+					let p1 = (try decode (String.get s (i + 1)) with _ -> None) in
+					let p2 = (try decode (String.get s (i + 2)) with _ -> None) in
+					(match p1, p2 with
+					| Some c1, Some c2 ->
+						Buffer.add_char b (char_of_int ((c1 lsl 4) lor c2));
+						loop (i + 3)
+					| _ ->
+						loop (i + 1));
+				| '+' ->
+					Buffer.add_char b ' ';
+					loop (i + 1)
+				| c ->
+					Buffer.add_char b c;
+					loop (i + 1)
+			in
+			loop 0;
+			VString (Buffer.contents b)
+		);
+		"base_encode", Fun2 (fun s b ->
+			match s, b with
+			| VString s, VString "0123456789abcdef" when String.length s = 16 ->
+				VString (Digest.to_hex s)
+			| VString s, VString b ->
+				if String.length b <> 64 then assert false;
+				let tbl = Array.init 64 (String.unsafe_get b) in
+				VString (Base64.str_encode ~tbl s)
+			| _ -> error()
+		);
+		"base_decode", Fun2 (fun s b ->
+			let s = vstring s in
+			let b = vstring b in
+			if String.length b <> 64 then assert false;
+			let tbl = Array.init 64 (String.unsafe_get b) in
+			VString (Base64.str_decode ~tbl:(Base64.make_decoding_table tbl) s)
+		);
+		"make_md5", Fun1 (fun s ->
+			VString (Digest.string (vstring s))
+		);
+		(* sprintf *)
+	(* int32 *)
+		"int32_new", Fun1 (fun v ->
+			match v with
+			| VInt32 _ -> v
+			| VInt i -> make_i32 (Int32.of_int i)
+			| VFloat f -> make_i32 (Int32.of_float f)
+			| _ -> error()
+		);
+		"int32_to_int", Fun1 (fun v ->
+			let v = int32 v in
+			let i = Int32.to_int v in
+			if Int32.compare (Int32.of_int i) v <> 0 then error();
+			VInt i
+		);
+		"int32_to_float", Fun1 (fun v ->
+			VFloat (Int32.to_float (int32 v))
+		);
+		"int32_compare", Fun2 (fun a b ->
+			VInt (Int32.compare (int32 a) (int32 b))
+		);
+		"int32_add", int32_op Int32.add;
+		"int32_sub", int32_op Int32.sub;
+		"int32_mul", int32_op Int32.mul;
+		"int32_div", int32_op Int32.div;
+		"int32_shl", int32_op (fun a b -> Int32.shift_left a (Int32.to_int b));
+		"int32_shr", int32_op (fun a b -> Int32.shift_right a (Int32.to_int b));
+		"int32_ushr", int32_op (fun a b -> Int32.shift_right_logical a (Int32.to_int b));
+		"int32_mod", int32_op Int32.rem;
+		"int32_or", int32_op Int32.logor;
+		"int32_and", int32_op Int32.logand;
+		"int32_xor", int32_op Int32.logxor;
+		"int32_neg", Fun1 (fun v -> make_i32 (Int32.neg (int32 v)));
+		"int32_complement", Fun1 (fun v -> make_i32 (Int32.lognot (int32 v)));
+	(* misc *)
+		"same_closure", Fun2 (fun a b ->
+			VBool (match a, b with
+			| VClosure (la,fa), VClosure (lb,fb) ->
+				fa == fb && List.length la = List.length lb && List.for_all2 (fun a b -> (get_ctx()).do_compare a b = CEq) la lb
+			| VFunction a, VFunction b -> a == b
+			| _ -> false)
+		);
+		"double_bytes", Fun2 (fun f big ->
+			let f = (match f with VFloat f -> f | VInt i -> float_of_int i | _ -> error()) in
+			match big with
+			| VBool big ->
+				let ch = IO.output_string() in
+				if big then IO.BigEndian.write_double ch f else IO.write_double ch f;
+				VString (IO.close_out ch)
+			| _ ->
+				error()
+		);
+		"float_bytes", Fun2 (fun f big ->
+			let f = (match f with VFloat f -> f | VInt i -> float_of_int i | _ -> error()) in
+			match big with
+			| VBool big ->
+				let ch = IO.output_string() in
+				let i = Int32.bits_of_float f in
+				if big then IO.BigEndian.write_real_i32 ch i else IO.write_real_i32 ch i;
+				VString (IO.close_out ch)
+			| _ ->
+				error()
+		);
+		"double_of_bytes", Fun2 (fun s big ->
+			match s, big with
+			| VString s, VBool big when String.length s = 8 ->
+				let ch = IO.input_string s in
+				VFloat (if big then IO.BigEndian.read_double ch else IO.read_double ch)
+			| _ ->
+				error()
+		);
+		"float_of_bytes", Fun2 (fun s big ->
+			match s, big with
+			| VString s, VBool big when String.length s = 4 ->
+				let ch = IO.input_string s in
+				VFloat (Int32.float_of_bits (if big then IO.BigEndian.read_real_i32 ch else IO.read_real_i32 ch))
+			| _ ->
+				error()
+		);
+	(* random *)
+		"random_new", Fun0 (fun() -> VAbstract (ARandom (ref (Random.State.make_self_init()))));
+		"random_set_seed", Fun2 (fun r s ->
+			match r, s with
+			| VAbstract (ARandom r), VInt seed -> r := Random.State.make [|seed|]; VNull
+			| VAbstract (ARandom r), VInt32 seed -> r := Random.State.make [|Int32.to_int seed|]; VNull
+			| _ -> error()
+		);
+		"random_int", Fun2 (fun r s ->
+			match r, s with
+			| VAbstract (ARandom r), VInt max -> VInt (Random.State.int (!r) (if max <= 0 then 1 else max))
+			| _ -> error()
+		);
+		"random_float", Fun1 (fun r ->
+			match r with
+			| VAbstract (ARandom r) -> VFloat (Random.State.float (!r) 1.0)
+			| _ -> error()
+		);
+	(* file *)
+		"file_open", Fun2 (fun f r ->
+			match f, r with
+			| VString f, VString r ->
+				let perms = 0o666 in
+				VAbstract (match r with
+					| "r" -> AFRead (open_in_gen [Open_rdonly] 0 f)
+					| "rb" -> AFRead (open_in_gen [Open_rdonly;Open_binary] 0 f)
+					| "w" -> AFWrite (open_out_gen [Open_wronly;Open_creat;Open_trunc] perms f)
+					| "wb" -> AFWrite (open_out_gen [Open_wronly;Open_creat;Open_trunc;Open_binary] perms f)
+					| "a" -> AFWrite (open_out_gen [Open_append] perms f)
+					| "ab" -> AFWrite (open_out_gen [Open_append;Open_binary] perms f)
+					| _ -> error())
+			| _ -> error()
+		);
+		"file_close", Fun1 (fun f ->
+			(match f with
+			| VAbstract (AFRead f) -> close_in f
+			| VAbstract (AFWrite f) -> close_out f
+			| _ -> error());
+			VNull
+		);
+		(* file_name *)
+		"file_write", Fun4 (fun f s p l ->
+			match f, s, p, l with
+			| VAbstract (AFWrite f), VString s, VInt p, VInt l -> output f s p l; VInt l
+			| _ -> error()
+		);
+		"file_read", Fun4 (fun f s p l ->
+			match f, s, p, l with
+			| VAbstract (AFRead f), VString s, VInt p, VInt l ->
+				let n = input f s p l in
+				if n = 0 then exc (VArray [|VString "file_read"|]);
+				VInt n
+			| _ -> error()
+		);
+		"file_write_char", Fun2 (fun f c ->
+			match f, c with
+			| VAbstract (AFWrite f), VInt c -> output_char f (char_of_int c); VNull
+			| _ -> error()
+		);
+		"file_read_char", Fun1 (fun f ->
+			match f with
+			| VAbstract (AFRead f) -> VInt (int_of_char (try input_char f with _ -> exc (VArray [|VString "file_read_char"|])))
+			| _ -> error()
+		);
+		"file_seek", Fun3 (fun f pos mode ->
+			match f, pos, mode with
+			| VAbstract (AFRead f), VInt pos, VInt mode ->
+				seek_in f (match mode with 0 -> pos | 1 -> pos_in f + pos | 2 -> in_channel_length f - pos | _ -> error());
+				VNull;
+			| VAbstract (AFWrite f), VInt pos, VInt mode ->
+				seek_out f (match mode with 0 -> pos | 1 -> pos_out f + pos | 2 -> out_channel_length f - pos | _ -> error());
+				VNull;
+			| _ -> error()
+		);
+		"file_tell", Fun1 (fun f ->
+			match f with
+			| VAbstract (AFRead f) -> VInt (pos_in f)
+			| VAbstract (AFWrite f) -> VInt (pos_out f)
+			| _ -> error()
+		);
+		"file_eof", Fun1 (fun f ->
+			match f with
+			| VAbstract (AFRead f) ->
+				VBool (try
+					ignore(input_char f);
+					seek_in f (pos_in f - 1);
+					false
+				with End_of_file ->
+					true)
+			| _ -> error()
+		);
+		"file_flush", Fun1 (fun f ->
+			(match f with
+			| VAbstract (AFWrite f) -> flush f
+			| _ -> error());
+			VNull
+		);
+		"file_contents", Fun1 (fun f ->
+			match f with
+			| VString f -> VString (Std.input_file ~bin:true f)
+			| _ -> error()
+		);
+		"file_stdin", Fun0 (fun() -> VAbstract (AFRead Pervasives.stdin));
+		"file_stdout", Fun0 (fun() -> VAbstract (AFWrite Pervasives.stdout));
+		"file_stderr", Fun0 (fun() -> VAbstract (AFWrite Pervasives.stderr));
+	(* serialize *)
+		(* TODO *)
+	(* socket *)
+		"socket_init", Fun0 (fun() -> VNull);
+		"socket_new", Fun1 (fun v ->
+			match v with
+			| VBool b -> VAbstract (ASocket (Unix.socket PF_INET (if b then SOCK_DGRAM else SOCK_STREAM) 0));
+			| _ -> error()
+		);
+		"socket_close", Fun1 (fun s ->
+			match s with
+			| VAbstract (ASocket s) -> Unix.close s; VNull
+			| _ -> error()
+		);
+		"socket_send_char", Fun2 (fun s c ->
+			match s, c with
+			| VAbstract (ASocket s), VInt c when c >= 0 && c <= 255 ->
+				ignore(Unix.send s (String.make 1 (char_of_int c)) 0 1 []);
+				VNull
+			| _ -> error()
+		);
+		"socket_send", Fun4 (fun s buf pos len ->
+			match s, buf, pos, len with
+			| VAbstract (ASocket s), VString buf, VInt pos, VInt len -> VInt (Unix.send s buf pos len [])
+			| _ -> error()
+		);
+		"socket_recv", Fun4 (fun s buf pos len ->
+			match s, buf, pos, len with
+			| VAbstract (ASocket s), VString buf, VInt pos, VInt len -> VInt (Unix.recv s buf pos len [])
+			| _ -> error()
+		);
+		"socket_recv_char", Fun1 (fun s ->
+			match s with
+			| VAbstract (ASocket s) ->
+				let buf = String.make 1 '\000' in
+				ignore(Unix.recv s buf 0 1 []);
+				VInt (int_of_char (String.unsafe_get buf 0))
+			| _ -> error()
+		);
+		"socket_write", Fun2 (fun s str ->
+			match s, str with
+			| VAbstract (ASocket s), VString str ->
+				let pos = ref 0 in
+				let len = ref (String.length str) in
+				while !len > 0 do
+					let k = Unix.send s str (!pos) (!len) [] in
+					pos := !pos + k;
+					len := !len - k;
+				done;
+				VNull
+			| _ -> error()
+		);
+		"socket_read", Fun1 (fun s ->
+			match s with
+			| VAbstract (ASocket s) ->
+				let tmp = String.make 1024 '\000' in
+				let buf = Buffer.create 0 in
+				let rec loop() =
+					let k = (try Unix.recv s tmp 0 1024 [] with Unix_error _ -> 0) in
+					if k > 0 then begin
+						Buffer.add_substring buf tmp 0 k;
+						loop();
+					end
+				in
+				loop();
+				VString (Buffer.contents buf)
+			| _ -> error()
+		);
+		"host_resolve", Fun1 (fun s ->
+			let h = (try Unix.gethostbyname (vstring s) with Not_found -> error()) in
+			let addr = Unix.string_of_inet_addr h.h_addr_list.(0) in
+			let a, b, c, d = Scanf.sscanf addr "%d.%d.%d.%d" (fun a b c d -> a,b,c,d) in
+			VInt32 (Int32.logor (Int32.shift_left (Int32.of_int a) 24) (Int32.of_int (d lor (c lsl 8) lor (b lsl 16))))
+		);
+		"host_to_string", Fun1 (fun h ->
+			match h with
+			| VInt32 h -> VString (Unix.string_of_inet_addr (int32_addr h));
+			| _ -> error()
+		);
+		"host_reverse", Fun1 (fun h ->
+			match h with
+			| VInt32 h -> VString (gethostbyaddr (int32_addr h)).h_name
+			| _ -> error()
+		);
+		"host_local", Fun0 (fun() ->
+			VString (Unix.gethostname())
+		);
+		"socket_connect", Fun3 (fun s h p ->
+			match s, h, p with
+			| VAbstract (ASocket s), VInt32 h, VInt p ->
+				Unix.connect s (ADDR_INET (int32_addr h,p));
+				VNull
+			| _ -> error()
+		);
+		"socket_listen", Fun2 (fun s l ->
+			match s, l with
+			| VAbstract (ASocket s), VInt l ->
+				Unix.listen s l;
+				VNull
+			| _ -> error()
+		);
+		"socket_set_timeout", Fun2 (fun s t ->
+			match s with
+			| VAbstract (ASocket s) ->
+				let t = (match t with VNull -> 0. | VInt t -> float_of_int t | VFloat f -> f | _ -> error()) in
+				Unix.setsockopt_float s SO_RCVTIMEO t;
+				Unix.setsockopt_float s SO_SNDTIMEO t;
+				VNull
+			| _ -> error()
+		);
+		"socket_shutdown", Fun3 (fun s r w ->
+			match s, r, w with
+			| VAbstract (ASocket s), VBool r, VBool w ->
+				Unix.shutdown s (match r, w with true, true -> SHUTDOWN_ALL | true, false -> SHUTDOWN_RECEIVE | false, true -> SHUTDOWN_SEND | _ -> error());
+				VNull
+			| _ -> error()
+		);
+		(* TODO : select, bind, accept, peer, host *)
+		(* poll_alloc, poll : not planned *)
+	(* system *)
+		"get_env", Fun1 (fun v ->
+			try VString (Unix.getenv (vstring v)) with _ -> VNull
+		);
+		"put_env", Fun2 (fun e v ->
+			Unix.putenv (vstring e) (vstring v);
+			VNull
+		);
+		"sys_sleep", Fun1 (fun f ->
+			match f with
+			| VFloat f -> ignore(Unix.select [] [] [] f); VNull
+			| _ -> error()
+		);
+		"set_time_locale", Fun1 (fun l ->
+			match l with
+			| VString s -> VBool false (* always fail *)
+			| _ -> error()
+		);
+		"get_cwd", Fun0 (fun() ->
+			let dir = Unix.getcwd() in
+			let l = String.length dir in
+			VString (if l = 0 then "./" else match dir.[l - 1] with '/' | '\\' -> dir | _ -> dir ^ "/")
+		);
+		"set_cwd", Fun1 (fun s ->
+			Unix.chdir (vstring s);
+			VNull;
+		);
+		"sys_string", Fun0 (fun() ->
+			VString (match Sys.os_type with
+			| "Unix" -> "Linux"
+			| "Win32" | "Cygwin" -> "Windows"
+			| s -> s)
+		);
+		"sys_is64", Fun0 (fun() ->
+			VBool (Sys.word_size = 64)
+		);
+		"sys_command", Fun1 (fun cmd ->
+			VInt (((get_ctx()).curapi.get_com()).run_command (vstring cmd))
+		);
+		"sys_exit", Fun1 (fun code ->
+			if (get_ctx()).curapi.use_cache() then raise Typecore.Fatal_error;
+			exit (vint code);
+		);
+		"sys_exists", Fun1 (fun file ->
+			VBool (Sys.file_exists (vstring file))
+		);
+		"file_delete", Fun1 (fun file ->
+			Sys.remove (vstring file);
+			VNull;
+		);
+		"sys_rename", Fun2 (fun file target ->
+			Sys.rename (vstring file) (vstring target);
+			VNull;
+		);
+		"sys_stat", Fun1 (fun file ->
+			let s = Unix.stat (vstring file) in
+			VObject (obj (hash_field (get_ctx())) [
+				"gid", VInt s.st_gid;
+				"uid", VInt s.st_uid;
+				"atime", VInt32 (Int32.of_float s.st_atime);
+				"mtime", VInt32 (Int32.of_float s.st_mtime);
+				"ctime", VInt32 (Int32.of_float s.st_ctime);
+				"dev", VInt s.st_dev;
+				"ino", VInt s.st_ino;
+				"nlink", VInt s.st_nlink;
+				"rdev", VInt s.st_rdev;
+				"size", VInt s.st_size;
+				"mode", VInt s.st_perm;
+			])
+		);
+		"sys_file_type", Fun1 (fun file ->
+			VString (match (Unix.stat (vstring file)).st_kind with
+			| S_REG -> "file"
+			| S_DIR -> "dir"
+			| S_CHR -> "char"
+			| S_BLK -> "block"
+			| S_LNK -> "symlink"
+			| S_FIFO -> "fifo"
+			| S_SOCK -> "sock")
+		);
+		"sys_create_dir", Fun2 (fun dir mode ->
+			Unix.mkdir (vstring dir) (vint mode);
+			VNull
+		);
+		"sys_remove_dir", Fun1 (fun dir ->
+			Unix.rmdir (vstring dir);
+			VNull;
+		);
+		"sys_time", Fun0 (fun() ->
+			VFloat (Unix.gettimeofday())
+		);
+		"sys_cpu_time", Fun0 (fun() ->
+			VFloat (Sys.time())
+		);
+		"sys_read_dir", Fun1 (fun dir ->
+			let d = Sys.readdir (vstring dir) in
+			let rec loop acc i =
+				if i < 0 then
+					acc
+				else
+					loop (VArray [|VString d.(i);acc|]) (i - 1)
+			in
+			loop VNull (Array.length d - 1)
+		);
+		"file_full_path", Fun1 (fun file ->
+			VString (try Extc.get_full_path (vstring file) with _ -> error())
+		);
+		"sys_exe_path", Fun0 (fun() ->
+			VString (Extc.executable_path())
+		);
+		"sys_env", Fun0 (fun() ->
+			let env = Unix.environment() in
+			let rec loop acc i =
+				if i < 0 then
+					acc
+				else
+					let e, v = ExtString.String.split "=" env.(i) in
+					loop (VArray [|VString e;VString v;acc|]) (i - 1)
+			in
+			loop VNull (Array.length env - 1)
+		);
+		"sys_getch", Fun1 (fun echo ->
+			match echo with
+			| VBool b -> VInt (Extc.getch b)
+			| _ -> error()
+		);
+		"sys_get_pid", Fun0 (fun() ->
+			VInt (Unix.getpid())
+		);
+	(* utf8 *)
+		"utf8_buf_alloc", Fun1 (fun v ->
+			VAbstract (AUtf8 (UTF8.Buf.create (vint v)))
+		);
+		"utf8_buf_add", Fun2 (fun b c ->
+			match b with
+			| VAbstract (AUtf8 buf) -> UTF8.Buf.add_char buf (UChar.chr_of_uint (vint c)); VNull
+			| _ -> error()
+		);
+		"utf8_buf_content", Fun1 (fun b ->
+			match b with
+			| VAbstract (AUtf8 buf) -> VString (UTF8.Buf.contents buf);
+			| _ -> error()
+		);
+		"utf8_buf_length", Fun1 (fun b ->
+			match b with
+			| VAbstract (AUtf8 buf) -> VInt (UTF8.length (UTF8.Buf.contents buf));
+			| _ -> error()
+		);
+		"utf8_buf_size", Fun1 (fun b ->
+			match b with
+			| VAbstract (AUtf8 buf) -> VInt (String.length (UTF8.Buf.contents buf));
+			| _ -> error()
+		);
+		"utf8_validate", Fun1 (fun s ->
+			VBool (try UTF8.validate (vstring s); true with UTF8.Malformed_code -> false)
+		);
+		"utf8_length", Fun1 (fun s ->
+			VInt (UTF8.length (vstring s))
+		);
+		"utf8_sub", Fun3 (fun s p l ->
+			let buf = UTF8.Buf.create 0 in
+			let pos = ref (-1) in
+			let p = vint p and l = vint l in
+			UTF8.iter (fun c ->
+				incr pos;
+				if !pos >= p && !pos < p + l then UTF8.Buf.add_char buf c;
+			) (vstring s);
+			if !pos < p + l then error();
+			VString (UTF8.Buf.contents buf)
+		);
+		"utf8_get", Fun2 (fun s p ->
+			VInt (UChar.uint_code (try UTF8.look (vstring s) (vint p) with _ -> error()))
+		);
+		"utf8_iter", Fun2 (fun s f ->
+			let ctx = get_ctx() in
+			UTF8.iter (fun c ->
+				ignore(ctx.do_call VNull f [VInt (UChar.uint_code c)] p);
+			) (vstring s);
+			VNull;
+		);
+		"utf8_compare", Fun2 (fun s1 s2 ->
+			VInt (UTF8.compare (vstring s1) (vstring s2))
+		);
+	(* xml *)
+		"parse_xml", (match neko with
+		| None -> Fun2 (fun str o ->
+			match str, o with
+			| VString str, VObject events ->
+				let ctx = get_ctx() in
+				let p = { psource = "parse_xml"; pline = 0 } in
+				let xml = get_field events (hash "xml") in
+				let don = get_field events (hash "done") in
+				let pcdata = get_field events (hash "pcdata") in
+				(*
+
+				Since we use the Xml parser, we don't have support for
+				- CDATA
+				- comments, prolog, doctype (allowed but skipped)
+
+				let cdata = get_field events (hash "cdata") in
+				let comment = get_field events (hash "comment") in
+				*)
+				let rec loop = function
+					| Xml.Element (node, attribs, children) ->
+						ignore(ctx.do_call o xml [VString node;VObject (obj (hash_field ctx) (List.map (fun (a,v) -> a, VString v) attribs))] p);
+						List.iter loop children;
+						ignore(ctx.do_call o don [] p);
+					| Xml.PCData s ->
+						ignore(ctx.do_call o pcdata [VString s] p);
+				in
+				let x = XmlParser.make() in
+				XmlParser.check_eof x false;
+				loop (try
+					XmlParser.parse x (XmlParser.SString str)
+				with Xml.Error e -> failwith ("Parser failure (" ^ Xml.error e ^ ")")
+				| e -> failwith ("Parser failure (" ^ Printexc.to_string e ^ ")"));
+				VNull
+			| _ -> error())
+		| Some neko ->
+			let parse_xml = neko.load "std@parse_xml" 2 in
+			Fun2 (fun str o -> neko.call parse_xml [str;o])
+		);
+	(* memory, module, thread : not planned *)
+	]
+	(* process *)
+	@ (match neko with
+	| None -> []
+	| Some neko ->
+		let p_run = neko.load "std@process_run" 2 in
+		let p_stdout_read = neko.load "std@process_stdout_read" 4 in
+		let p_stderr_read = neko.load "std@process_stderr_read" 4 in
+		let p_stdin_write = neko.load "std@process_stdin_write" 4 in
+		let p_stdin_close = neko.load "std@process_stdin_close" 1 in
+		let p_exit = neko.load "std@process_exit" 1 in
+		let p_pid = neko.load "std@process_pid" 1 in
+		let p_close = neko.load "std@process_close" 1 in
+		let win_ec = (try Some (neko.load "std@win_env_changed" 0) with _ -> None) in
+	[
+		"process_run", (Fun2 (fun a b -> neko.call p_run [a;b]));
+		"process_stdout_read", (Fun4 (fun a b c d -> neko.call p_stdout_read [a;VAbstract (ANekoBuffer b);c;d]));
+		"process_stderr_read", (Fun4 (fun a b c d -> neko.call p_stderr_read [a;VAbstract (ANekoBuffer b);c;d]));
+		"process_stdin_write", (Fun4 (fun a b c d -> neko.call p_stdin_write [a;b;c;d]));
+		"process_stdin_close", (Fun1 (fun p -> neko.call p_stdin_close [p]));
+		"process_exit", (Fun1 (fun p -> neko.call p_exit [p]));
+		"process_pid", (Fun1 (fun p -> neko.call p_pid [p]));
+		"process_close", (Fun1 (fun p -> neko.call p_close [p]));
+		"win_env_changed", (Fun0 (fun() -> match win_ec with None -> error() | Some f -> neko.call f []));
+	]))
+
+
+(* ---------------------------------------------------------------------- *)
+(* REGEXP LIBRARY *)
+
+let reg_lib =
+	let error() =
+		raise Builtin_error
+	in
+	(* try to load regexp first : we might fail if pcre is not installed *)
+	let neko = (match neko with
+		| None -> None
+		| Some neko ->
+			(try ignore(neko.load "regexp@regexp_new_options" 2); Some neko with _ -> None)
+	) in
+	match neko with
+	| None ->
+	make_library [
+		(* regexp_new : deprecated *)
+		"regexp_new_options", Fun2 (fun str opt ->
+			match str, opt with
+			| VString str, VString opt ->
+				let case_sensitive = ref true in
+				List.iter (function
+					| 'm' -> () (* always ON ? *)
+					| 'i' -> case_sensitive := false
+					| c -> failwith ("Unsupported regexp option '" ^ String.make 1 c ^ "'")
+				) (ExtString.String.explode opt);
+				let buf = Buffer.create 0 in
+				let rec loop prev esc = function
+					| [] -> ()
+					| c :: l when esc ->
+						(match c with
+						| 'n' -> Buffer.add_char buf '\n'
+						| 'r' -> Buffer.add_char buf '\r'
+						| 't' -> Buffer.add_char buf '\t'
+						| 'd' -> Buffer.add_string buf "[0-9]"
+						| '\\' -> Buffer.add_string buf "\\\\"
+						| '(' | ')' -> Buffer.add_char buf c
+						| '1'..'9' | '+' | '$' | '^' | '*' | '?' | '.' | '[' | ']' ->
+							Buffer.add_char buf '\\';
+							Buffer.add_char buf c;
+						| _ -> failwith ("Unsupported escaped char '" ^ String.make 1 c ^ "'"));
+						loop c false l
+					| c :: l ->
+						match c with
+						| '\\' -> loop prev true l
+						| '(' | '|' | ')' ->
+							Buffer.add_char buf '\\';
+							Buffer.add_char buf c;
+							loop c false l
+						| '?' when prev = '(' && (match l with ':' :: _ -> true | _ -> false) ->
+							failwith "Non capturing groups '(?:' are not supported in macros"
+						| '?' when prev = '*' ->
+							failwith "Ungreedy *? are not supported in macros"
+						| _ ->
+							Buffer.add_char buf c;
+							loop c false l
+				in
+				loop '\000' false (ExtString.String.explode str);
+				let str = Buffer.contents buf in
+				let r = {
+					r = if !case_sensitive then Str.regexp str else Str.regexp_case_fold str;
+					r_string = "";
+					r_groups = [||];
+				} in
+				VAbstract (AReg r)
+			| _ -> error()
+		);
+		"regexp_match", Fun4 (fun r str pos len ->
+			match r, str, pos, len with
+			| VAbstract (AReg r), VString str, VInt pos, VInt len ->
+				let nstr, npos, delta = (if len = String.length str - pos then str, pos, 0 else String.sub str pos len, 0, pos) in
+				(try
+					ignore(Str.search_forward r.r nstr npos);
+					let rec loop n =
+						if n = 9 then
+							[]
+						else try
+							(Some (Str.group_beginning n + delta, Str.group_end n + delta)) :: loop (n + 1)
+						with Not_found ->
+							None :: loop (n + 1)
+						| Invalid_argument _ ->
+							[]
+					in
+					r.r_string <- str;
+					r.r_groups <- Array.of_list (loop 0);
+					VBool true;
+				with Not_found ->
+					VBool false)
+			| _ -> error()
+		);
+		"regexp_matched", Fun2 (fun r n ->
+			match r, n with
+			| VAbstract (AReg r), VInt n ->
+				(match (try r.r_groups.(n) with _ -> failwith ("Invalid group " ^ string_of_int n)) with
+				| None -> VNull
+				| Some (pos,pend) -> VString (String.sub r.r_string pos (pend - pos)))
+			| _ -> error()
+		);
+		"regexp_matched_pos", Fun2 (fun r n ->
+			match r, n with
+			| VAbstract (AReg r), VInt n ->
+				(match (try r.r_groups.(n) with _ -> failwith ("Invalid group " ^ string_of_int n)) with
+				| None -> VNull
+				| Some (pos,pend) -> VObject (obj (hash_field (get_ctx())) ["pos",VInt pos;"len",VInt (pend - pos)]))
+			| _ -> error()
+		);
+		(* regexp_replace : not used by Haxe *)
+		(* regexp_replace_all : not used by Haxe *)
+		(* regexp_replace_fun : not used by Haxe *)
+	]
+	| Some neko ->
+	let regexp_new_options = neko.load "regexp@regexp_new_options" 2 in
+	let regexp_match = neko.load "regexp@regexp_match" 4 in
+	let regexp_matched = neko.load "regexp@regexp_matched" 2 in
+	let regexp_matched_pos = neko.load "regexp@regexp_matched_pos" 2 in
+	make_library [
+		"regexp_new_options", Fun2 (fun str opt -> neko.call regexp_new_options [str;opt]);
+		"regexp_match", Fun4 (fun r str pos len -> neko.call regexp_match [r;str;pos;len]);
+		"regexp_matched", Fun2 (fun r n -> neko.call regexp_matched [r;n]);
+		"regexp_matched_pos", Fun2 (fun r n -> neko.call regexp_matched_pos [r;n]);
+	]
+
+
+(* ---------------------------------------------------------------------- *)
+(* ZLIB LIBRARY *)
+
+let z_lib =
+	let error() =
+		raise Builtin_error
+	in
+	make_library [
+		"inflate_init", Fun1 (fun f ->
+			let z = Extc.zlib_inflate_init2 (match f with VNull -> 15 | VInt i -> i | _ -> error()) in
+			VAbstract (AZipI { z = z; z_flush = Extc.Z_NO_FLUSH })
+		);
+		"deflate_init", Fun1 (fun f ->
+			let z = Extc.zlib_deflate_init (match f with VInt i -> i | _ -> error()) in
+			VAbstract (AZipD { z = z; z_flush = Extc.Z_NO_FLUSH })
+		);
+		"deflate_end", Fun1 (fun z ->
+			match z with
+			| VAbstract (AZipD z) -> Extc.zlib_deflate_end z.z; VNull;
+			| _ -> error()
+		);
+		"inflate_end", Fun1 (fun z ->
+			match z with
+			| VAbstract (AZipI z) -> Extc.zlib_inflate_end z.z; VNull;
+			| _ -> error()
+		);
+		"set_flush_mode", Fun2 (fun z f ->
+			match z, f with
+			| VAbstract (AZipI z | AZipD z), VString s ->
+				z.z_flush <- (match s with
+					| "NO" -> Extc.Z_NO_FLUSH
+					| "SYNC" -> Extc.Z_SYNC_FLUSH
+					| "FULL" -> Extc.Z_FULL_FLUSH
+					| "FINISH" -> Extc.Z_FINISH
+					| "BLOCK" -> Extc.Z_PARTIAL_FLUSH
+					| _ -> error());
+				VNull;
+			| _ -> error()
+		);
+		"inflate_buffer", Fun5 (fun z src pos dst dpos ->
+			match z, src, pos, dst, dpos with
+			| VAbstract (AZipI z), VString src, VInt pos, VString dst, VInt dpos ->
+				let r = Extc.zlib_inflate z.z src pos (String.length src - pos) dst dpos (String.length dst - dpos) z.z_flush in
+				VObject (obj (hash_field (get_ctx())) [
+					"done", VBool r.Extc.z_finish;
+					"read", VInt r.Extc.z_read;
+					"write", VInt r.Extc.z_wrote;
+				])
+			| _ -> error()
+		);
+		"deflate_buffer", Fun5 (fun z src pos dst dpos ->
+			match z, src, pos, dst, dpos with
+			| VAbstract (AZipD z), VString src, VInt pos, VString dst, VInt dpos ->
+				let r = Extc.zlib_deflate z.z src pos (String.length src - pos) dst dpos (String.length dst - dpos) z.z_flush in
+				VObject (obj (hash_field (get_ctx())) [
+					"done", VBool r.Extc.z_finish;
+					"read", VInt r.Extc.z_read;
+					"write", VInt r.Extc.z_wrote;
+				])
+			| _ -> error()
+		);
+		"deflate_bound", Fun2 (fun z size ->
+			match z, size with
+			| VAbstract (AZipD z), VInt size -> VInt (size + 1024)
+			| _ -> error()
+		);
+	]
+
+(* ---------------------------------------------------------------------- *)
+(* MACRO LIBRARY *)
+
+let macro_lib =
+	let error() =
+		raise Builtin_error
+	in
+	let ccom() =
+		(get_ctx()).curapi.get_com()
+	in
+	make_library [
+		"curpos", Fun0 (fun() -> VAbstract (APos (get_ctx()).curapi.pos));
+		"error", Fun2 (fun msg p ->
+			match msg, p with
+			| VString s, VAbstract (APos p) ->
+				(ccom()).Common.error s p;
+				raise Abort
+			| _ -> error()
+		);
+		"warning", Fun2 (fun msg p ->
+			match msg, p with
+			| VString s, VAbstract (APos p) ->
+				(ccom()).warning s p;
+				VNull;
+			| _ -> error()
+		);
+		"class_path", Fun0 (fun() ->
+			VArray (Array.of_list (List.map (fun s -> VString s) (ccom()).class_path));
+		);
+		"resolve", Fun1 (fun file ->
+			match file with
+			| VString s -> VString (try Common.find_file (ccom()) s with Not_found -> failwith ("File not found '" ^ s ^ "'"))
+			| _ -> error();
+		);
+		"define", Fun1 (fun s ->
+			match s with
+			| VString s -> Common.raw_define (ccom()) s; VNull
+			| _ -> error();
+		);
+		"defined", Fun1 (fun s ->
+			match s with
+			| VString s -> VBool (Common.raw_defined (ccom()) s)
+			| _ -> error();
+		);
+		"defined_value", Fun1 (fun s ->
+			match s with
+			| VString s -> (try VString (Common.raw_defined_value (ccom()) s) with Not_found -> VNull)
+			| _ -> error();
+		);
+		"get_type", Fun1 (fun s ->
+			match s with
+			| VString s ->
+				(match (get_ctx()).curapi.get_type s with
+				| None -> failwith ("Type not found '" ^ s ^ "'")
+				| Some t -> encode_type t)
+			| _ -> error()
+		);
+		"get_module", Fun1 (fun s ->
+			match s with
+			| VString s ->
+				enc_array (List.map encode_type ((get_ctx()).curapi.get_module s))
+			| _ -> error()
+		);
+		"on_generate", Fun1 (fun f ->
+			match f with
+			| VFunction (Fun1 _) ->
+				let ctx = get_ctx() in
+				ctx.curapi.on_generate (fun tl ->
+					ignore(catch_errors ctx (fun() -> ctx.do_call VNull f [enc_array (List.map encode_type tl)] null_pos));
+				);
+				VNull
+			| _ -> error()
+		);
+		"on_type_not_found", Fun1 (fun f ->
+			match f with
+			| VFunction (Fun1 _) ->
+				let ctx = get_ctx() in
+				ctx.curapi.on_type_not_found (fun path ->
+					ctx.do_call VNull f [enc_string path] null_pos
+				);
+				VNull
+			| _ -> error()
+		);
+		"parse", Fun3 (fun s p b ->
+			match s, p, b with
+			| VString s, VAbstract (APos p), VBool b -> encode_expr ((get_ctx()).curapi.parse_string s p b)
+			| _ -> error()
+		);
+		"make_expr", Fun2 (fun v p ->
+			match p with
+			| VAbstract (APos p) ->
+				let h_enum = hash "__enum__" and h_et = hash "__et__" and h_ct = hash "__ct__" in
+				let h_tag = hash "tag" and h_args = hash "args" in
+				let h_length = hash "length" in
+				let ctx = get_ctx() in
+				let error v = failwith ("Unsupported value " ^ ctx.do_string v) in
+				let make_path t =
+					let rec loop = function
+						| [] -> assert false
+						| [name] -> (Ast.EConst (Ast.Ident name),p)
+						| name :: l -> (Ast.EField (loop l,name),p)
+					in
+					let t = t_infos t in
+					loop (List.rev (if t.mt_module.m_path = t.mt_path then fst t.mt_path @ [snd t.mt_path] else fst t.mt_module.m_path @ [snd t.mt_module.m_path;snd t.mt_path]))
+				in
+				let rec loop = function
+					| VNull -> (Ast.EConst (Ast.Ident "null"),p)
+					| VBool b -> (Ast.EConst (Ast.Ident (if b then "true" else "false")),p)
+					| VInt i -> (Ast.EConst (Ast.Int (string_of_int i)),p)
+					| VInt32 i -> (Ast.EConst (Ast.Int (Int32.to_string i)),p)
+					| VFloat f -> (Ast.EConst (Ast.Float (string_of_float f)),p)
+					| VAbstract (APos p) ->
+						(Ast.EObjectDecl (
+							("fileName" , (Ast.EConst (Ast.String p.Ast.pfile) , p)) ::
+							("lineNumber" , (Ast.EConst (Ast.Int (string_of_int (Lexer.get_error_line p))),p)) ::
+							("className" , (Ast.EConst (Ast.String ("")),p)) ::
+							[]
+						), p)
+					| VString _ | VArray _ | VAbstract _ | VFunction _ | VClosure _ as v -> error v
+					| VObject o as v ->
+						match o.oproto with
+						| None ->
+							(match get_field_opt o h_ct with
+							| Some (VAbstract (ATDecl t)) ->
+								make_path t
+							| _ ->
+								let fields = List.fold_left (fun acc (fid,v) -> (field_name ctx fid, loop v) :: acc) [] (Array.to_list o.ofields) in
+								(Ast.EObjectDecl fields, p))
+						| Some proto ->
+							match get_field_opt proto h_enum, get_field_opt o h_a, get_field_opt o h_s, get_field_opt o h_length with
+							| _, Some (VArray a), _, Some (VInt len) ->
+								(Ast.EArrayDecl (List.map loop (Array.to_list (Array.sub a 0 len))),p)
+							| _, _, Some (VString s), _ ->
+								(Ast.EConst (Ast.String s),p)
+							| Some (VObject en), _, _, _ ->
+								(match get_field en h_et, get_field o h_tag with
+								| VAbstract (ATDecl t), VString tag ->
+									let e = (Ast.EField (make_path t,tag),p) in
+									(match get_field_opt o h_args with
+									| Some (VArray args) ->
+										let args = List.map loop (Array.to_list args) in
+										(Ast.ECall (e,args),p)
+									| _ -> e)
+								| _ ->
+									error v)
+							| _ ->
+								error v
+				in
+				encode_expr (loop v)
+			| _ -> error()
+		);
+		"signature", Fun1 (fun v ->
+			let cache = ref [] in
+			let cache_count = ref 0 in
+			let hfiles = Hashtbl.create 0 in
+			let get_file f =
+				try
+					Hashtbl.find hfiles f
+				with Not_found ->
+					let ff = Common.unique_full_path f in
+					Hashtbl.add hfiles f ff;
+					ff
+			in
+			let do_cache (v:value) (v2:value) =
+				(*
+					tricky : we need to have a quick not-linear cache based on objects address
+					but we can't use address since the GC might be triggered here.
+					Instead let's mutate the object temporary.
+				*)
+				let vt = Obj.repr v in
+				let old = Obj.tag vt in
+				let old_val = Obj.field vt 0 in
+				let abstract_tag = 7 in
+				Obj.set_tag vt abstract_tag;
+				Obj.set_field vt 0 (Obj.repr (ACacheRef v2));
+				cache := (vt,old,old_val) :: !cache;
+				incr cache_count
+			in
+			let rec loop v =
+				match v with
+				| VNull | VBool _ | VInt _ | VFloat _ | VString _ | VInt32 _ -> v
+				| VObject o ->
+					let o2 = { ofields = [||]; oproto = None } in
+					let v2 = VObject o2 in
+					do_cache v v2;
+					Array.iter (fun (f,v) -> if f <> h_class then set_field o2 f (loop v)) o.ofields;
+					(match o.oproto with
+					| None -> ()
+					| Some p -> (match loop (VObject p) with VObject p2 -> o2.oproto <- Some p2 | _ -> assert false));
+					v2
+				| VArray a ->
+					let a2 = Array.create (Array.length a) VNull in
+					let v2 = VArray a2 in
+					do_cache v v2;
+					for i = 0 to Array.length a - 1 do
+						a2.(i) <- loop a.(i);
+					done;
+					v2
+				| VFunction f ->
+					let v2 = VFunction (Obj.magic !cache_count) in
+					do_cache v v2;
+					v2
+				| VClosure (vl,f) ->
+					let rl = ref [] in
+					let v2 = VClosure (Obj.magic rl, Obj.magic !cache_count) in
+					do_cache v v2;
+					rl := List.map loop vl;
+					v2
+				| VAbstract (APos p) -> VAbstract (APos { p with Ast.pfile = get_file p.Ast.pfile })
+				| VAbstract (ACacheRef v) -> v
+				| VAbstract (AHash h) ->
+					let h2 = Hashtbl.create 0 in
+					let v2 = VAbstract (AHash h2) in
+					do_cache v v2;
+					Hashtbl.iter (fun k v -> Hashtbl.add h2 k (loop v)) h2;
+					v2
+				| VAbstract _ ->
+					let v2 = VAbstract (Obj.magic !cache_count) in
+					do_cache v v2;
+					v2
+			in
+			let v = loop v in
+			(* restore *)
+			List.iter (fun (vt,tag,field) ->
+				Obj.set_tag vt tag;
+				Obj.set_field vt 0 field;
+			) !cache;
+			VString (Digest.to_hex (Digest.string (Marshal.to_string v [Marshal.Closures])))
+		);
+		"to_complex", Fun1 (fun v ->
+			try	encode_complex_type (make_complex_type (decode_type v))
+			with Exit -> VNull
+		);
+		"unify", Fun2 (fun t1 t2 ->
+			try Type.unify (decode_type t1) (decode_type t2); VBool true
+			with Unify_error _ -> VBool false
+		);
+		"typeof", Fun1 (fun v ->
+			encode_type ((get_ctx()).curapi.typeof (decode_expr v))
+		);
+		"s_type", Fun1 (fun v ->
+			VString (Type.s_type (print_context()) (decode_type v))
+		);
+		"display", Fun1 (fun v ->
+			match v with
+			| VString s ->
+				VString ((get_ctx()).curapi.get_display s)
+			| _ ->
+				error()
+		);
+		"allow_package", Fun1 (fun v ->
+			match v with
+			| VString s ->
+				(get_ctx()).curapi.allow_package s;
+				VNull
+			| _ -> error());
+		"type_patch", Fun4 (fun t f s v ->
+			let p = (get_ctx()).curapi.type_patch in
+			(match t, f, s, v with
+			| VString t, VString f, VBool s, VString v -> p t f s (Some v)
+			| VString t, VString f, VBool s, VNull -> p t f s None
+			| _ -> error());
+			VNull
+		);
+		"meta_patch", Fun4 (fun m t f s ->
+			let p = (get_ctx()).curapi.meta_patch in
+			(match m, t, f, s with
+			| VString m, VString t, VString f, VBool s -> p m t (Some f) s
+			| VString m, VString t, VNull, VBool s -> p m t None s
+			| _ -> error());
+			VNull
+		);
+		"custom_js", Fun1 (fun f ->
+			match f with
+			| VFunction (Fun1 _) ->
+				let ctx = get_ctx() in
+				ctx.curapi.set_js_generator (fun api ->
+					ignore(catch_errors ctx (fun() -> ctx.do_call VNull f [api] null_pos));
+				);
+				VNull
+			| _ -> error()
+		);
+		"get_pos_infos", Fun1 (fun p ->
+			match p with
+			| VAbstract (APos p) -> VObject (obj (hash_field (get_ctx())) ["min",VInt p.Ast.pmin;"max",VInt p.Ast.pmax;"file",VString p.Ast.pfile])
+			| _ -> error()
+		);
+		"make_pos", Fun3 (fun min max file ->
+			match min, max, file with
+			| VInt min, VInt max, VString file -> VAbstract (APos { Ast.pmin = min; Ast.pmax = max; Ast.pfile = file })
+			| _ -> error()
+		);
+		"add_resource", Fun2 (fun name data ->
+			match name, data with
+			| VString name, VString data ->
+				Hashtbl.replace (ccom()).resources name data;
+				let m = (get_ctx()).curapi.current_module() in
+				m.m_extra.m_binded_res <- PMap.add name data m.m_extra.m_binded_res;
+				VNull
+			| _ -> error()
+		);
+		"local_type", Fun0 (fun() ->
+			match (get_ctx()).curapi.get_local_type() with
+			| None -> VNull
+			| Some t -> encode_type t
+		);
+		"local_method", Fun0 (fun() ->
+			VString ((get_ctx()).curapi.get_local_method())
+		);
+		"local_using", Fun0 (fun() ->
+			enc_array (List.map encode_clref ((get_ctx()).curapi.get_local_using()))
+		);
+		"local_vars", Fun0 (fun() ->
+			let vars = (get_ctx()).curapi.get_local_vars() in
+			let h = Hashtbl.create 0 in
+			PMap.iter (fun n v -> Hashtbl.replace h (VString n) (encode_type v.v_type)) vars;
+			enc_hash h
+		);
+		"follow", Fun2 (fun v once ->
+			let t = decode_type v in
+			let follow_once t =
+				match t with
+				| TMono r ->
+					(match !r with
+					| None -> t
+					| Some t -> t)
+				| TAbstract _ | TEnum _ | TInst _ | TFun _ | TAnon _ | TDynamic _ ->
+					t
+				| TType (t,tl) ->
+					apply_params t.t_types tl t.t_type
+				| TLazy f ->
+					(!f)()
+			in
+			encode_type (match once with VNull | VBool false -> follow t | VBool true -> follow_once t | _ -> error())
+		);
+		"build_fields", Fun0 (fun() ->
+			(get_ctx()).curapi.get_build_fields()
+		);
+		"define_type", Fun1 (fun v ->
+			(get_ctx()).curapi.define_type v;
+			VNull
+		);
+		"add_class_path", Fun1 (fun v ->
+			match v with
+			| VString cp ->
+				let com = ccom() in
+				com.class_path <- (Common.normalize_path cp) :: com.class_path;
+				VNull
+			| _ ->
+				error()
+		);
+		"add_native_lib", Fun1 (fun v ->
+			match v with
+			| VString file ->
+				let com = ccom() in
+				(match com.platform with
+				| Flash -> Genswf.add_swf_lib com file false
+				| _ -> failwith "Unsupported platform");
+				VNull
+			| _ ->
+				error()
+		);
+		"module_dependency", Fun2 (fun m file ->
+			match m, file with
+			| VString m, VString file ->
+				(get_ctx()).curapi.module_dependency m file false;
+				VNull
+			| _ -> error()
+		);
+		"module_reuse_call", Fun2 (fun m mcall ->
+			match m, mcall with
+			| VString m, VString mcall ->
+				(get_ctx()).curapi.module_dependency m mcall true;
+				VNull
+			| _ -> error()
+		);
+		"get_typed_expr", Fun1 (fun e ->
+			match e with
+			| VAbstract (ATExpr e) ->
+				encode_expr (make_ast e)
+			| _ -> error()
+		);
+		"get_output", Fun0 (fun() ->
+			VString (ccom()).file
+		);
+		"set_output", Fun1 (fun s ->
+			match s with
+			| VString s -> (ccom()).file <- s; VNull
+			| _ -> error()
+		);
+		"get_display_pos", Fun0 (fun() ->
+			let p = !Parser.resume_display in
+			if p = Ast.null_pos then
+				VNull
+			else
+				VObject (obj (hash_field (get_ctx())) ["file",VString p.Ast.pfile;"pos",VInt p.Ast.pmin])
+		);
+		"pattern_locals", Fun2 (fun e t ->
+			let loc = (get_ctx()).curapi.get_pattern_locals (decode_expr e) (decode_type t) in
+			let h = Hashtbl.create 0 in
+			PMap.iter (fun n v -> Hashtbl.replace h (VString n) (encode_type v.v_type)) loc;
+			enc_hash h
+		);
+		"macro_context_reused", Fun1 (fun c ->
+			match c with
+			| VFunction (Fun0 _) ->
+				let ctx = get_ctx() in
+				ctx.on_reused <- (fun() -> catch_errors ctx (fun() -> ctx.do_call VNull c [] null_pos) = Some (VBool true)) :: ctx.on_reused;
+				VNull
+			| _ -> error()
+		);
+	]
+
+(* ---------------------------------------------------------------------- *)
+(* EVAL *)
+
+let throw ctx p msg =
+	ctx.callstack <- { cpos = p; cthis = ctx.vthis; cstack = DynArray.length ctx.stack; cenv = ctx.venv } :: ctx.callstack;
+	exc (VString msg)
+
+let declare ctx var =
+	ctx.locals_map <- PMap.add var ctx.locals_count ctx.locals_map;
+	ctx.locals_count <- ctx.locals_count + 1
+
+let save_locals ctx =
+	let old, oldcount = ctx.locals_map, ctx.locals_count in
+	(fun() ->
+		let n = ctx.locals_count - oldcount in
+		ctx.locals_count <- oldcount;
+		ctx.locals_map <- old;
+		n;
+	)
+
+let get_ident ctx s =
+	try
+		let index = PMap.find s ctx.locals_map in
+		if index >= ctx.locals_barrier then
+			AccLocal (ctx.locals_count - index)
+		else (try
+			AccEnv (DynArray.index_of (fun s2 -> s = s2) ctx.locals_env)
+		with Not_found ->
+			let index = DynArray.length ctx.locals_env in
+			DynArray.add ctx.locals_env s;
+			AccEnv index
+		)
+	with Not_found -> try
+		AccGlobal (PMap.find s ctx.globals)
+	with Not_found ->
+		let g = ref VNull in
+		ctx.globals <- PMap.add s g ctx.globals;
+		AccGlobal g
+
+let no_env = [||]
+
+let rec eval ctx (e,p) =
+	match e with
+	| EConst c ->
+		(match c with
+		| True -> (fun() -> VBool true)
+		| False -> (fun() -> VBool false)
+		| Null -> (fun() -> VNull)
+		| This -> (fun() -> ctx.vthis)
+		| Int i -> (fun() -> VInt i)
+		| Int32 i -> (fun() -> VInt32 i)
+		| Float f ->
+			let f = float_of_string f in
+			(fun() -> VFloat f)
+		| String s -> (fun() -> VString s)
+		| Builtin "loader" ->
+			(fun() -> ctx.loader)
+		| Builtin "exports" ->
+			(fun() -> ctx.exports)
+		| Builtin s ->
+			let b = (try Hashtbl.find builtins s with Not_found -> throw ctx p ("Builtin not found '" ^ s ^ "'")) in
+			(fun() -> b)
+		| Ident s ->
+			acc_get ctx p (get_ident ctx s))
+	| EBlock el ->
+		let old = save_locals ctx in
+		let el = List.map (eval ctx) el in
+		let n = old() in
+		let rec loop = function
+			| [] -> VNull
+			| [e] -> e()
+			| e :: l ->
+				ignore(e());
+				loop l
+		in
+		(fun() ->
+			let v = loop el in
+			pop ctx n;
+			v)
+	| EParenthesis e ->
+		eval ctx e
+	| EField (e,f) ->
+		let e = eval ctx e in
+		let h = hash_field ctx f in
+		(fun() ->
+			match e() with
+			| VObject o -> get_field o h
+			| _ -> throw ctx p ("Invalid field access : " ^ f)
+		)
+	| ECall ((EConst (Builtin "mk_pos"),_),[(ECall (_,[EConst (String file),_]),_);(EConst (Int min),_);(EConst (Int max),_)]) ->
+		let pos = VAbstract (APos { Ast.pfile = file; Ast.pmin = min; Ast.pmax = max }) in
+		(fun() -> pos)
+	| ECall ((EConst (Builtin "typewrap"),_),[t]) ->
+		(fun() -> VAbstract (ATDecl (Obj.magic t)))
+	| ECall ((EConst (Builtin "delay_call"),_),[EConst (Int index),_]) ->
+		let f = ctx.curapi.delayed_macro index in
+		let fbuild = ref None in
+		let old = { ctx with gen = ctx.gen } in
+		let compile_delayed_call() =
+			let oldl, oldc, oldb, olde = ctx.locals_map, ctx.locals_count, ctx.locals_barrier, ctx.locals_env in
+			ctx.locals_map <- old.locals_map;
+			ctx.locals_count <- old.locals_count;
+			ctx.locals_barrier <- old.locals_barrier;
+			ctx.locals_env <- DynArray.copy old.locals_env;
+			let save = save_locals ctx in
+			let e = f() in
+			let n = save() in
+			let e = if DynArray.length ctx.locals_env = DynArray.length old.locals_env then
+				e
+			else
+				let n = DynArray.get ctx.locals_env (DynArray.length ctx.locals_env - 1) in
+				(fun() -> exc (VString ("Macro-in-macro call can't access to closure variable '" ^ n ^ "'")))
+			in
+			ctx.locals_map <- oldl;
+			ctx.locals_count <- oldc;
+			ctx.locals_barrier <- oldb;
+			ctx.locals_env <- olde;
+			(fun() ->
+				let v = e() in
+				pop ctx n;
+				v
+			)
+		in
+		(fun() ->
+			let e = (match !fbuild with
+			| Some e -> e
+			| None ->
+				let e = compile_delayed_call() in
+				fbuild := Some e;
+				e
+			) in
+			e())
+	| ECall (e,el) ->
+		let el = List.map (eval ctx) el in
+		(match fst e with
+		| EField (e,f) ->
+			let e = eval ctx e in
+			let h = hash_field ctx f in
+			(fun() ->
+				let pl = List.map (fun f -> f()) el in
+				let o = e() in
+				let f = (match o with
+				| VObject o -> get_field o h
+				| _ -> throw ctx p ("Invalid field access : " ^ f)
+				) in
+				call ctx o f pl p
+			)
+		| _ ->
+			let e = eval ctx e in
+			(fun() ->
+				let pl = List.map (fun f -> f()) el in
+				call ctx ctx.vthis (e()) pl p
+			))
+	| EArray (e1,e2) ->
+		let e1 = eval ctx e1 in
+		let e2 = eval ctx e2 in
+		let acc = AccArray (e1,e2) in
+		acc_get ctx p acc
+	| EVars vl ->
+		let vl = List.map (fun (v,eo) ->
+			let eo = (match eo with None -> (fun() -> VNull) | Some e -> eval ctx e) in
+			declare ctx v;
+			eo
+		) vl in
+		(fun() ->
+			List.iter (fun e -> push ctx (e())) vl;
+			VNull
+		)
+	| EWhile (econd,e,NormalWhile) ->
+		let econd = eval ctx econd in
+		let e = eval ctx e in
+		let rec loop st =
+			match econd() with
+			| VBool true ->
+				let v = (try
+					ignore(e()); None
+				with
+					| Continue -> pop ctx (DynArray.length ctx.stack - st); None
+					| Break v -> pop ctx (DynArray.length ctx.stack - st); Some v
+				) in
+				(match v with
+				| None -> loop st
+				| Some v -> v)
+			| _ ->
+				VNull
+		in
+		(fun() -> try loop (DynArray.length ctx.stack) with Sys.Break -> throw ctx p "Ctrl+C")
+	| EWhile (econd,e,DoWhile) ->
+		let e = eval ctx e in
+		let econd = eval ctx econd in
+		let rec loop st =
+			let v = (try
+				ignore(e()); None
+			with
+				| Continue -> pop ctx (DynArray.length ctx.stack - st); None
+				| Break v -> pop ctx (DynArray.length ctx.stack - st); Some v
+			) in
+			match v with
+			| Some v -> v
+			| None ->
+				match econd() with
+				| VBool true -> loop st
+				| _ -> VNull
+		in
+		(fun() -> loop (DynArray.length ctx.stack))
+	| EIf (econd,eif,eelse) ->
+		let econd = eval ctx econd in
+		let eif = eval ctx eif in
+		let eelse = (match eelse with None -> (fun() -> VNull) | Some e -> eval ctx e) in
+		(fun() ->
+			match econd() with
+			| VBool true -> eif()
+			| _ -> eelse()
+		)
+	| ETry (e,exc,ecatch) ->
+		let old = save_locals ctx in
+		let e = eval ctx e in
+		let n1 = old() in
+		declare ctx exc;
+		let ecatch = eval ctx ecatch in
+		let n2 = old() in
+		(fun() ->
+			let vthis = ctx.vthis in
+			let venv = ctx.venv in
+			let stack = ctx.callstack in
+			let csize = ctx.callsize in
+			let size = DynArray.length ctx.stack in
+			try
+				pop_ret ctx e n1
+			with Runtime v ->
+				let rec loop n l =
+					if n = 0 then List.map (fun s -> s.cpos) l else
+					match l with
+					| [] -> []
+					| _ :: l -> loop (n - 1) l
+				in
+				ctx.exc <- loop (List.length stack) (List.rev ctx.callstack);
+				ctx.callstack <- stack;
+				ctx.callsize <- csize;
+				ctx.vthis <- vthis;
+				ctx.venv <- venv;
+				pop ctx (DynArray.length ctx.stack - size);
+				push ctx v;
+				pop_ret ctx ecatch n2
+			)
+	| EFunction (pl,e) ->
+		let old = save_locals ctx in
+		let oldb, oldenv = ctx.locals_barrier, ctx.locals_env in
+		ctx.locals_barrier <- ctx.locals_count;
+		ctx.locals_env <- DynArray.create();
+		List.iter (declare ctx) pl;
+		let e = eval ctx e in
+		ignore(old());
+		let env = ctx.locals_env in
+		ctx.locals_barrier <- oldb;
+		ctx.locals_env <- oldenv;
+		let env = DynArray.to_array (DynArray.map (fun s ->
+			acc_get ctx p (get_ident ctx s)) env
+		) in
+		let init_env = if Array.length env = 0 then
+			(fun() -> no_env)
+		else
+			(fun() -> Array.map (fun e -> e()) env)
+		in
+		(match pl with
+		| [] ->
+			(fun() ->
+				let env = init_env() in
+				VFunction (Fun0 (fun() ->
+					ctx.venv <- env;
+					e())))
+		| [a] ->
+			(fun() ->
+				let env = init_env() in
+				VFunction (Fun1 (fun v ->
+					ctx.venv <- env;
+					push ctx v;
+					e();
+				)))
+		| [a;b] ->
+			(fun() ->
+				let env = init_env() in
+				VFunction (Fun2 (fun va vb ->
+					ctx.venv <- env;
+					push ctx va;
+					push ctx vb;
+					e();
+				)))
+		| [a;b;c] ->
+			(fun() ->
+				let env = init_env() in
+				VFunction (Fun3 (fun va vb vc ->
+					ctx.venv <- env;
+					push ctx va;
+					push ctx vb;
+					push ctx vc;
+					e();
+				)))
+		| [a;b;c;d] ->
+			(fun() ->
+				let env = init_env() in
+				VFunction (Fun4 (fun va vb vc vd ->
+					ctx.venv <- env;
+					push ctx va;
+					push ctx vb;
+					push ctx vc;
+					push ctx vd;
+					e();
+				)))
+		| [a;b;c;d;pe] ->
+			(fun() ->
+				let env = init_env() in
+				VFunction (Fun5 (fun va vb vc vd ve ->
+					ctx.venv <- env;
+					push ctx va;
+					push ctx vb;
+					push ctx vc;
+					push ctx vd;
+					push ctx ve;
+					e();
+				)))
+		| _ ->
+			(fun() ->
+				let env = init_env() in
+				VFunction (FunVar (fun vl ->
+					if List.length vl != List.length pl then exc (VString "Invalid call");
+					ctx.venv <- env;
+					List.iter (push ctx) vl;
+					e();
+				)))
+		)
+	| EBinop (op,e1,e2) ->
+		eval_op ctx op e1 e2 p
+	| EReturn None ->
+		(fun() -> raise (Return VNull))
+	| EReturn (Some e) ->
+		let e = eval ctx e in
+		(fun() -> raise (Return (e())))
+	| EBreak None ->
+		(fun() -> raise (Break VNull))
+	| EBreak (Some e) ->
+		let e = eval ctx e in
+		(fun() -> raise (Break (e())))
+	| EContinue ->
+		(fun() -> raise Continue)
+	| ENext (e1,e2) ->
+		let e1 = eval ctx e1 in
+		let e2 = eval ctx e2 in
+		(fun() -> ignore(e1()); e2())
+	| EObject fl ->
+		let fl = List.map (fun (f,e) -> hash_field ctx f, eval ctx e) fl in
+		let fields = Array.of_list (List.map (fun (f,_) -> f,VNull) fl) in
+		Array.sort (fun (f1,_) (f2,_) -> compare f1 f2) fields;
+		(fun() ->
+			let o = {
+				ofields = Array.copy fields;
+				oproto = None;
+			} in
+			List.iter (fun (f,e) -> set_field o f (e())) fl;
+			VObject o
+		)
+	| ELabel l ->
+		assert false
+	| ESwitch (e1,el,eo) ->
+		let e1 = eval ctx e1 in
+		let el = List.map (fun (cond,e) -> cond, eval ctx cond, eval ctx e) el in
+		let eo = (match eo with None -> (fun() -> VNull) | Some e -> eval ctx e) in
+		let cases = (try
+			let max = ref (-1) in
+			let ints = List.map (fun (cond,_,e) ->
+				match fst cond with
+				| EConst (Int i) -> if i < 0 then raise Exit; if i > !max then max := i; i, e
+				| _ -> raise Exit
+			) el in
+			let a = Array.create (!max + 1) eo in
+			List.iter (fun (i,e) -> a.(i) <- e) (List.rev ints);
+			Some a;
+		with
+			Exit -> None
+		) in
+		let def v =
+			let rec loop = function
+				| [] -> eo()
+				| (_,c,e) :: l ->
+					if ctx.do_compare v (c()) = CEq then e() else loop l
+			in
+			loop el
+		in
+		(match cases with
+		| None -> (fun() -> def (e1()))
+		| Some t ->
+			(fun() ->
+				match e1() with
+				| VInt i -> if i >= 0 && i < Array.length t then t.(i)() else eo()
+				| v -> def v
+			))
+	| ENeko _ ->
+		throw ctx p "Inline neko code unsupported"
+
+and eval_oop ctx p o field (params:value list) =
+	match get_field_opt o field with
+	| None -> None
+	| Some f -> Some (call ctx (VObject o) f params p)
+
+and eval_access ctx (e,p) =
+	match e with
+	| EField (e,f) ->
+		let v = eval ctx e in
+		AccField (v,f)
+	| EArray (e,eindex) ->
+		let v = eval ctx e in
+		let idx = eval ctx eindex in
+		AccArray (v,idx)
+	| EConst (Ident s) ->
+		get_ident ctx s
+	| EConst This ->
+		AccThis
+	| _ ->
+		throw ctx p "Invalid assign"
+
+and eval_access_get_set ctx (e,p) =
+	match e with
+	| EField (e,f) ->
+		let v = eval ctx e in
+		let cache = ref VNull in
+		AccField ((fun() -> cache := v(); !cache),f), AccField((fun() -> !cache), f)
+	| EArray (e,eindex) ->
+		let v = eval ctx e in
+		let idx = eval ctx eindex in
+		let vcache = ref VNull and icache = ref VNull in
+		AccArray ((fun() -> vcache := v(); !vcache),(fun() -> icache := idx(); !icache)), AccArray ((fun() -> !vcache),(fun() -> !icache))
+	| EConst (Ident s) ->
+		let acc = get_ident ctx s in
+		acc, acc
+	| EConst This ->
+		AccThis, AccThis
+	| _ ->
+		throw ctx p "Invalid assign"
+
+and acc_get ctx p = function
+	| AccField (v,f) ->
+		let h = hash_field ctx f in
+		(fun() ->
+			match v() with
+			| VObject o -> get_field o h
+			| _ -> throw ctx p ("Invalid field access : " ^ f))
+	| AccArray (e,index) ->
+		(fun() ->
+			let e = e() in
+			let index = index() in
+			(match index, e with
+			| VInt i, VArray a -> (try Array.get a i with _ -> VNull)
+			| VInt32 _, VArray _ -> VNull
+			| _, VObject o ->
+				(match eval_oop ctx p o h_get [index] with
+				| None -> throw ctx p "Invalid array access"
+				| Some v -> v)
+			| _ -> throw ctx p "Invalid array access"))
+	| AccLocal i ->
+		(fun() -> DynArray.get ctx.stack (DynArray.length ctx.stack - i))
+	| AccGlobal g ->
+		(fun() -> !g)
+	| AccThis ->
+		(fun() -> ctx.vthis)
+	| AccEnv i ->
+		(fun() -> ctx.venv.(i))
+
+and acc_set ctx p acc value =
+	match acc with
+	| AccField (v,f) ->
+		let h = hash_field ctx f in
+		(fun() ->
+			let v = v() in
+			let value = value() in
+			match v with
+			| VObject o -> set_field o h value; value
+			| _ -> throw ctx p ("Invalid field access : " ^ f))
+	| AccArray (e,index) ->
+		(fun() ->
+			let e = e() in
+			let index = index() in
+			let value = value() in
+			(match index, e with
+			| VInt i, VArray a -> (try Array.set a i value; value with _ -> value)
+			| VInt32 _, VArray _ -> value
+			| _, VObject o ->
+				(match eval_oop ctx p o h_set [index;value] with
+				| None -> throw ctx p "Invalid array access"
+				| Some _ -> value);
+			| _ -> throw ctx p "Invalid array access"))
+	| AccLocal i ->
+		(fun() ->
+			let value = value() in
+			DynArray.set ctx.stack (DynArray.length ctx.stack - i) value;
+			value)
+	| AccGlobal g ->
+		(fun() ->
+			let value = value() in
+			g := value;
+			value)
+	| AccThis ->
+		(fun() ->
+			let value = value() in
+			ctx.vthis <- value;
+			value)
+	| AccEnv i ->
+		(fun() ->
+			let value = value() in
+			ctx.venv.(i) <- value;
+			value)
+
+and number_op ctx p sop iop fop oop rop v1 v2 =
+	(fun() ->
+		let v1 = v1() in
+		let v2 = v2() in
+		exc_number_op ctx p sop iop fop oop rop v1 v2)
+
+and exc_number_op ctx p sop iop fop oop rop v1 v2 =
+	match v1, v2 with
+	| VInt a, VInt b -> best_int (iop (Int32.of_int a) (Int32.of_int b))
+	| VInt32 a, VInt b -> best_int (iop a (Int32.of_int b))
+	| VInt a, VInt32 b -> best_int (iop (Int32.of_int a) b)
+	| VFloat a, VInt b -> VFloat (fop a (float_of_int b))
+	| VFloat a, VInt32 b -> VFloat (fop a (Int32.to_float b))
+	| VInt a, VFloat b -> VFloat (fop (float_of_int a) b)
+	| VInt32 a, VFloat b -> VFloat (fop (Int32.to_float a) b)
+	| VFloat a, VFloat b -> VFloat (fop a b)
+	| VInt32 a, VInt32 b -> best_int (iop a b)
+	| VObject o, _ ->
+		(match eval_oop ctx p o oop [v2] with
+		| Some v -> v
+		| None ->
+			match v2 with
+			| VObject o ->
+				(match eval_oop ctx p o rop [v1] with
+				| Some v -> v
+				| None -> throw ctx p sop)
+			| _ ->
+				throw ctx p sop)
+	| _ , VObject o ->
+		(match eval_oop ctx p o rop [v1] with
+		| Some v -> v
+		| None -> throw ctx p sop)
+	| _ ->
+		throw ctx p sop
+
+and int_op ctx p op iop v1 v2 =
+	(fun() ->
+		let v1 = v1() in
+		let v2 = v2() in
+		match v1, v2 with
+		| VInt a, VInt b -> best_int (iop (Int32.of_int a) (Int32.of_int b))
+		| VInt32 a, VInt b -> best_int (iop a (Int32.of_int b))
+		| VInt a, VInt32 b -> best_int (iop (Int32.of_int a) b)
+		| VInt32 a, VInt32 b -> best_int (iop a b)
+		| _ -> throw ctx p op)
+
+and base_op ctx op v1 v2 p =
+	match op with
+	| "+" ->
+		(fun() ->
+			let v1 = v1() in
+			let v2 = v2() in
+			match v1, v2 with
+			| (VInt _ | VInt32 _), (VInt _ | VInt32 _) | (VInt _ | VInt32 _), VFloat _ | VFloat _ , (VInt _ | VInt32 _) | VFloat _ , VFloat _ | VObject _ , _ | _ , VObject _ -> exc_number_op ctx p op Int32.add (+.) h_add h_radd v1 v2
+			| VString a, _ -> VString (a ^ ctx.do_string v2)
+			| _, VString b -> VString (ctx.do_string v1 ^ b)
+			| _ -> throw ctx p op)
+	| "-" ->
+		number_op ctx p op Int32.sub (-.) h_sub h_rsub v1 v2
+	| "*" ->
+		number_op ctx p op Int32.mul ( *. ) h_mult h_rmult v1 v2
+	| "/" ->
+		(fun() ->
+			let v1 = v1() in
+			let v2 = v2() in
+			match v1, v2 with
+			| VInt i, VInt j -> VFloat ((float_of_int i) /. (float_of_int j))
+			| VInt i, VInt32 j -> VFloat ((float_of_int i) /. (Int32.to_float j))
+			| VInt32 i, VInt j -> VFloat ((Int32.to_float i) /. (float_of_int j))
+			| VInt32 i, VInt32 j -> VFloat ((Int32.to_float i) /. (Int32.to_float j))
+			| _ -> exc_number_op ctx p op Int32.div (/.) h_div h_rdiv v1 v2)
+	| "%" ->
+		number_op ctx p op (fun x y -> if y = 0l then throw ctx p op; Int32.rem x y) mod_float h_mod h_rmod v1 v2
+	| "&" ->
+		int_op ctx p op Int32.logand v1 v2
+	| "|" ->
+		int_op ctx p op Int32.logor v1 v2
+	| "^" ->
+		int_op ctx p op Int32.logxor v1 v2
+	| "<<" ->
+		int_op ctx p op (fun x y -> Int32.shift_left x (Int32.to_int y)) v1 v2
+	| ">>" ->
+		int_op ctx p op (fun x y -> Int32.shift_right x (Int32.to_int y)) v1 v2
+	| ">>>" ->
+		int_op ctx p op (fun x y -> Int32.shift_right_logical x (Int32.to_int y)) v1 v2
+	| _ ->
+		throw ctx p op
+
+and eval_op ctx op e1 e2 p =
+	match op with
+	| "=" ->
+		let acc = eval_access ctx e1 in
+		let v = eval ctx e2 in
+		acc_set ctx p acc v
+	| "==" ->
+		let v1 = eval ctx e1 in
+		let v2 = eval ctx e2 in
+		(fun() ->
+			let v1 = v1() in
+			let v2 = v2() in
+			match ctx.do_compare v1 v2 with
+			| CEq -> VBool true
+			| _ -> VBool false)
+	| "!=" ->
+		let v1 = eval ctx e1 in
+		let v2 = eval ctx e2 in
+		(fun() ->
+			let v1 = v1() in
+			let v2 = v2() in
+			match ctx.do_compare v1 v2 with
+			| CEq -> VBool false
+			| _ -> VBool true)
+	| ">" ->
+		let v1 = eval ctx e1 in
+		let v2 = eval ctx e2 in
+		(fun() ->
+			let v1 = v1() in
+			let v2 = v2() in
+			match ctx.do_compare v1 v2 with
+			| CSup -> VBool true
+			| _ -> VBool false)
+	| ">=" ->
+		let v1 = eval ctx e1 in
+		let v2 = eval ctx e2 in
+		(fun() ->
+			let v1 = v1() in
+			let v2 = v2() in
+			match ctx.do_compare v1 v2 with
+			| CSup | CEq -> VBool true
+			| _ -> VBool false)
+	| "<" ->
+		let v1 = eval ctx e1 in
+		let v2 = eval ctx e2 in
+		(fun() ->
+			let v1 = v1() in
+			let v2 = v2() in
+			match ctx.do_compare v1 v2 with
+			| CInf -> VBool true
+			| _ -> VBool false)
+	| "<=" ->
+		let v1 = eval ctx e1 in
+		let v2 = eval ctx e2 in
+		(fun() ->
+			let v1 = v1() in
+			let v2 = v2() in
+			match ctx.do_compare v1 v2 with
+			| CInf | CEq -> VBool true
+			| _ -> VBool false)
+	| "+" | "-" | "*" | "/" | "%" | "|" | "&" | "^" | "<<" | ">>" | ">>>" ->
+		let v1 = eval ctx e1 in
+		let v2 = eval ctx e2 in
+		base_op ctx op v1 v2 p
+	| "+=" | "-=" | "*=" | "/=" | "%=" | "<<=" | ">>=" | ">>>=" | "|=" | "&=" | "^=" ->
+		let aset, aget = eval_access_get_set ctx e1 in
+		let v1 = acc_get ctx p aget in
+		let v2 = eval ctx e2 in
+		let v = base_op ctx (String.sub op 0 (String.length op - 1)) v1 v2 p in
+		acc_set ctx p aset v
+	| "&&" ->
+		let e1 = eval ctx e1 in
+		let e2 = eval ctx e2 in
+		(fun() ->
+			match e1() with
+			| VBool false as v -> v
+			| _ -> e2())
+	| "||" ->
+		let e1 = eval ctx e1 in
+		let e2 = eval ctx e2 in
+		(fun() ->
+			match e1() with
+			| VBool true as v -> v
+			| _ -> e2())
+	| "++=" | "--=" ->
+		let aset, aget = eval_access_get_set ctx e1 in
+		let v1 = acc_get ctx p aget in
+		let v2 = eval ctx e2 in
+		let vcache = ref VNull in
+		let v = base_op ctx (String.sub op 0 1) (fun() -> vcache := v1(); !vcache) v2 p in
+		let set = acc_set ctx p aset v in
+		(fun() -> ignore(set()); !vcache)
+	| _ ->
+		throw ctx p ("Unsupported " ^ op)
+
+and call ctx vthis vfun pl p =
+	let oldthis = ctx.vthis in
+	let stackpos = DynArray.length ctx.stack in
+	let oldstack = ctx.callstack in
+	let oldsize = ctx.callsize in
+	let oldenv = ctx.venv in
+	ctx.vthis <- vthis;
+	ctx.callstack <- { cpos = p; cthis = oldthis; cstack = stackpos; cenv = oldenv } :: ctx.callstack;
+	ctx.callsize <- oldsize + 1;
+	if oldsize > 200 then exc (VString "Stack overflow");
+	let ret = (try
+		(match vfun with
+		| VClosure (vl,f) ->
+			f vl pl
+		| VFunction f ->
+			(match pl, f with
+			| [], Fun0 f -> f()
+			| [a], Fun1 f -> f a
+			| [a;b], Fun2 f -> f a b
+			| [a;b;c], Fun3 f -> f a b c
+			| [a;b;c;d], Fun4 f -> f a b c d
+			| [a;b;c;d;e], Fun5 f -> f a b c d e
+			| _, FunVar f -> f pl
+			| _ -> exc (VString (Printf.sprintf "Invalid call (%d args instead of %d)" (List.length pl) (nargs f))))
+		| VAbstract (ALazyType f) ->
+			encode_type ((!f)())
+		| _ ->
+			exc (VString "Invalid call"))
+	with Return v -> v
+		| Stack_overflow -> exc (VString "Compiler Stack overflow")
+		| Sys_error msg | Failure msg -> exc (VString msg)
+		| Unix.Unix_error (_,cmd,msg) -> exc (VString ("Error " ^ cmd ^ " " ^ msg))
+		| Invalid_expr -> exc (VString "Invalid input value")
+		| Builtin_error | Invalid_argument _ -> exc (VString "Invalid call")) in
+	ctx.vthis <- oldthis;
+	ctx.venv <- oldenv;
+	ctx.callstack <- oldstack;
+	ctx.callsize <- oldsize;
+	pop ctx (DynArray.length ctx.stack - stackpos);
+	ret
+
+(* ---------------------------------------------------------------------- *)
+(* OTHERS *)
+
+let rec to_string ctx n v =
+	if n > 5 then
+		"<...>"
+	else let n = n + 1 in
+	match v with
+	| VNull -> "null"
+	| VBool true -> "true"
+	| VBool false -> "false"
+	| VInt i -> string_of_int i
+	| VInt32 i -> Int32.to_string i
+	| VFloat f ->
+		let s = string_of_float f in
+		let len = String.length s in
+		if String.unsafe_get s (len - 1) = '.' then String.sub s 0 (len - 1) else s
+	| VString s -> s
+	| VArray vl -> "[" ^ String.concat "," (Array.to_list (Array.map (to_string ctx n) vl)) ^ "]"
+	| VAbstract a ->
+		(match a with
+		| APos p -> "#pos(" ^ Lexer.get_error_pos (Printf.sprintf "%s:%d:") p ^ ")"
+		| _ -> "#abstract")
+	| VFunction f -> "#function:"  ^ string_of_int (nargs f)
+	| VClosure _ -> "#function:-1"
+	| VObject o ->
+		match eval_oop ctx null_pos o h_string [] with
+		| Some (VString s) -> s
+		| _ ->
+			let b = Buffer.create 0 in
+			let first = ref true in
+			Buffer.add_char b '{';
+			Array.iter (fun (f,v) ->
+				if !first then begin
+					Buffer.add_char b ' ';
+					first := false;
+				end else
+					Buffer.add_string b ", ";
+				Buffer.add_string b (field_name ctx f);
+				Buffer.add_string b " => ";
+				Buffer.add_string b (to_string ctx n v);
+			) o.ofields;
+			Buffer.add_string b (if !first then "}" else " }");
+			Buffer.contents b
+
+let rec compare ctx a b =
+	let fcmp (a:float) b = if a = b then CEq else if a < b then CInf else CSup in
+	let scmp (a:string) b = if a = b then CEq else if a < b then CInf else CSup in
+	let icmp (a:int32) b = let l = Int32.compare a b in if l = 0 then CEq else if l < 0 then CInf else CSup in
+	match a, b with
+	| VNull, VNull -> CEq
+	| VInt a, VInt b -> if a = b then CEq else if a < b then CInf else CSup
+	| VInt32 a, VInt32 b -> icmp a b
+	| VInt a, VInt32 b -> icmp (Int32.of_int a) b
+	| VInt32 a, VInt b -> icmp a (Int32.of_int b)
+	| VFloat a, VFloat b -> fcmp a b
+	| VFloat a, VInt b -> fcmp a (float_of_int b)
+	| VFloat a, VInt32 b -> fcmp a (Int32.to_float b)
+	| VInt a, VFloat b -> fcmp (float_of_int a) b
+	| VInt32 a, VFloat b -> fcmp (Int32.to_float a) b
+	| VBool a, VBool b -> if a = b then CEq else if a then CSup else CInf
+	| VString a, VString b -> scmp a b
+	| VInt _ , VString s
+	| VInt32 _, VString s
+	| VFloat _ , VString s
+	| VBool _ , VString s -> scmp (to_string ctx 0 a) s
+	| VString s, VInt _
+	| VString s, VInt32 _
+	| VString s, VFloat _
+	| VString s, VBool _ -> scmp s (to_string ctx 0 b)
+	| VObject oa, VObject ob ->
+		if oa == ob then CEq else
+			(match eval_oop ctx null_pos oa h_compare [b] with
+			| Some (VInt i) -> if i = 0 then CEq else if i < 0 then CInf else CSup
+			| _ -> CUndef)
+	| VAbstract a, VAbstract b ->
+		if a == b then CEq else CUndef
+	| VArray a, VArray b ->
+		if a == b then CEq else CUndef
+	| VFunction a, VFunction b ->
+		if a == b then CEq else CUndef
+	| VClosure (la,fa), VClosure (lb,fb) ->
+		if la == lb && fa == fb then CEq else CUndef
+	| _ ->
+		CUndef
+
+let select ctx =
+	get_ctx_ref := (fun() -> ctx)
+
+let load_prim ctx f n =
+	match f, n with
+	| VString f, VInt n ->
+		let lib, fname = (try ExtString.String.split f "@" with _ -> "", f) in
+		(try
+			let f = (match lib with
+			| "std" -> Hashtbl.find std_lib fname
+			| "macro" -> Hashtbl.find macro_lib fname
+			| "regexp" -> Hashtbl.find reg_lib fname
+			| "zlib" -> Hashtbl.find z_lib fname
+			| _ -> failwith ("You cannot use the library '" ^ lib ^ "' inside a macro");
+			) in
+			if nargs f <> n then raise Not_found;
+			VFunction f
+		with Not_found ->
+			VFunction (FunVar (fun _ -> exc (VString ("Primitive not found " ^ f ^ ":" ^ string_of_int n)))))
+	| _ ->
+		exc (VString "Invalid call")
+
+let create com api =
+	let loader = obj hash [
+		"args",VArray (Array.of_list (List.map (fun s -> VString s) com.sys_args));
+		"loadprim",VFunction (Fun2 (fun a b -> (get_ctx()).do_loadprim a b));
+		"loadmodule",VFunction (Fun2 (fun a b -> assert false));
+	] in
+	let ctx = {
+		gen = Genneko.new_context com 2 true;
+		types = Hashtbl.create 0;
+		error = false;
+		error_proto = { ofields = [||]; oproto = None };
+		prototypes = Hashtbl.create 0;
+		enums = [||];
+		(* eval *)
+		locals_map = PMap.empty;
+		locals_count = 0;
+		locals_barrier = 0;
+		locals_env = DynArray.create();
+		globals = PMap.empty;
+		(* runtime *)
+		callstack = [];
+		callsize = 0;
+		stack = DynArray.create();
+		exc = [];
+		vthis = VNull;
+		venv = [||];
+		fields_cache = Hashtbl.copy constants;
+		(* api *)
+		do_call = Obj.magic();
+		do_string = Obj.magic();
+		do_loadprim = Obj.magic();
+		do_compare = Obj.magic();
+		(* context *)
+		curapi = api;
+		loader = VObject loader;
+		on_reused = [];
+		is_reused = true;
+		exports = VObject { ofields = [||]; oproto = None };
+	} in
+	ctx.do_call <- call ctx;
+	ctx.do_string <- to_string ctx 0;
+	ctx.do_loadprim <- load_prim ctx;
+	ctx.do_compare <- compare ctx;
+	select ctx;
+	List.iter (fun e -> ignore((eval ctx e)())) (Genneko.header());
+	ctx
+
+
+
+let do_reuse ctx =
+	ctx.is_reused <- false
+
+let can_reuse ctx types =
+	let has_old_version t =
+		let inf = Type.t_infos t in
+		try
+			Hashtbl.find ctx.types inf.mt_path <> inf.mt_module.m_id
+		with Not_found ->
+			false
+	in
+	if List.exists has_old_version types then
+		false
+	else if ctx.is_reused then
+		true
+	else if not (List.for_all (fun f -> f()) ctx.on_reused) then
+		false
+	else begin
+		ctx.is_reused <- true;
+		true;
+	end
+
+let add_types ctx types ready =
+	let types = List.filter (fun t ->
+		let path = Type.t_path t in
+		if Hashtbl.mem ctx.types path then false else begin
+			Hashtbl.add ctx.types path (Type.t_infos t).mt_module.m_id;
+			true;
+		end
+	) types in
+	List.iter ready types;
+	let e = (EBlock (Genneko.build ctx.gen types), null_pos) in
+	ignore(catch_errors ctx (fun() -> ignore((eval ctx e)())))
+
+let eval_expr ctx e =
+	let e = Genneko.gen_expr ctx.gen e in
+	catch_errors ctx (fun() -> (eval ctx e)())
+
+let get_path ctx path p =
+	let rec loop = function
+		| [] -> assert false
+		| [x] -> (EConst (Ident x),p)
+		| x :: l -> (EField (loop l,x),p)
+	in
+	(eval ctx (loop (List.rev path)))()
+
+let set_error ctx e =
+	ctx.error <- e
+
+let call_path ctx path f vl api =
+	if ctx.error then
+		None
+	else let old = ctx.curapi in
+	ctx.curapi <- api;
+	let p = Genneko.pos ctx.gen api.pos in
+	catch_errors ctx ~final:(fun() -> ctx.curapi <- old) (fun() ->
+		match get_path ctx path p with
+		| VObject o ->
+			let f = get_field o (hash f) in
+			call ctx (VObject o) f vl p
+		| _ -> assert false
+	)
+
+(* ---------------------------------------------------------------------- *)
+(* EXPR ENCODING *)
+
+type enum_index =
+	| IExpr
+	| IBinop
+	| IUnop
+	| IConst
+	| ITParam
+	| ICType
+	| IField
+	| IType
+	| IFieldKind
+	| IMethodKind
+	| IVarAccess
+	| IAccess
+	| IClassKind
+
+let enum_name = function
+	| IExpr -> "ExprDef"
+	| IBinop -> "Binop"
+	| IUnop -> "Unop"
+	| IConst -> "Constant"
+	| ITParam -> "TypeParam"
+	| ICType -> "ComplexType"
+	| IField -> "FieldType"
+	| IType -> "Type"
+	| IFieldKind -> "FieldKind"
+	| IMethodKind -> "MethodKind"
+	| IVarAccess -> "VarAccess"
+	| IAccess -> "Access"
+	| IClassKind -> "ClassKind"
+
+let init ctx =
+	let enums = [IExpr;IBinop;IUnop;IConst;ITParam;ICType;IField;IType;IFieldKind;IMethodKind;IVarAccess;IAccess;IClassKind] in
+	let get_enum_proto e =
+		match get_path ctx ["haxe";"macro";enum_name e] null_pos with
+		| VObject e ->
+			(match get_field e h_constructs with
+			| VObject cst ->
+				(match get_field cst h_a with
+				| VArray a ->
+					Array.map (fun s ->
+						match s with
+						| VObject s -> (match get_field s h_s with VString s -> get_field e (hash s),s | _ -> assert false)
+						| _ -> assert false
+					) a
+				| _ -> assert false)
+			| _ -> assert false)
+		| _ -> failwith ("haxe.macro." ^ enum_name e ^ " does not exists")
+	in
+	ctx.enums <- Array.of_list (List.map get_enum_proto enums);
+	ctx.error_proto <- (match get_path ctx ["haxe";"macro";"Error";"prototype"] null_pos with VObject p -> p | _ -> failwith ("haxe.macro.Error does not exists"))
+
+open Ast
+
+let null f = function
+	| None -> VNull
+	| Some v -> f v
+
+let encode_pos p =
+	VAbstract (APos p)
+
+let enc_inst path fields =
+	let ctx = get_ctx() in
+	let p = (try Hashtbl.find ctx.prototypes path with Not_found -> try
+		(match get_path ctx (path@["prototype"]) Nast.null_pos with
+		| VObject o -> Hashtbl.add ctx.prototypes path o; o
+		| _ -> raise (Runtime VNull))
+	with Runtime _ ->
+		failwith ("Prototype not found " ^ String.concat "." path)
+	) in
+	let o = obj hash fields in
+	o.oproto <- Some p;
+	VObject o
+
+let enc_array l =
+	let a = Array.of_list l in
+	enc_inst ["Array"] [
+		"__a", VArray a;
+		"length", VInt (Array.length a);
+	]
+
+let enc_string s =
+	enc_inst ["String"] [
+		"__s", VString s;
+		"length", VInt (String.length s)
+	]
+
+let enc_hash h =
+	enc_inst ["haxe";"ds";"StringMap"] [
+		"h", VAbstract (AHash h);
+	]
+
+let enc_obj l = VObject (obj hash l)
+
+let enc_enum (i:enum_index) index pl =
+	let eindex : int = Obj.magic i in
+	let edef = (get_ctx()).enums.(eindex) in
+	if pl = [] then
+		fst edef.(index)
+	else
+		enc_inst ["haxe";"macro";enum_name i] [
+			"tag", VString (snd edef.(index));
+			"index", VInt index;
+			"args", VArray (Array.of_list pl);
+		]
+
+let compiler_error msg pos =
+	exc (enc_inst ["haxe";"macro";"Error"] [("message",enc_string msg);("pos",encode_pos pos)])
+
+let encode_const c =
+	let tag, pl = match c with
+	| Int s -> 0, [enc_string s]
+	| Float s -> 1, [enc_string s]
+	| String s -> 2, [enc_string s]
+	| Ident s -> 3, [enc_string s]
+	| Regexp (s,opt) -> 4, [enc_string s;enc_string opt]
+	in
+	enc_enum IConst tag pl
+
+let rec encode_binop op =
+	let tag, pl = match op with
+	| OpAdd -> 0, []
+	| OpMult -> 1, []
+	| OpDiv -> 2, []
+	| OpSub -> 3, []
+	| OpAssign -> 4, []
+	| OpEq -> 5, []
+	| OpNotEq -> 6, []
+	| OpGt -> 7, []
+	| OpGte -> 8, []
+	| OpLt -> 9, []
+	| OpLte -> 10, []
+	| OpAnd -> 11, []
+	| OpOr -> 12, []
+	| OpXor -> 13, []
+	| OpBoolAnd -> 14, []
+	| OpBoolOr -> 15, []
+	| OpShl -> 16, []
+	| OpShr -> 17, []
+	| OpUShr -> 18, []
+	| OpMod -> 19, []
+	| OpAssignOp op -> 20, [encode_binop op]
+	| OpInterval -> 21, []
+	| OpArrow -> 22, []
+	in
+	enc_enum IBinop tag pl
+
+let encode_unop op =
+	let tag = match op with
+	| Increment -> 0
+	| Decrement -> 1
+	| Not -> 2
+	| Neg -> 3
+	| NegBits -> 4
+	in
+	enc_enum IUnop tag []
+
+let rec encode_path t =
+	let fields = [
+		"pack", enc_array (List.map enc_string t.tpackage);
+		"name", enc_string t.tname;
+		"params", enc_array (List.map encode_tparam t.tparams);
+	] in
+	enc_obj (match t.tsub with
+		| None ->  fields
+		| Some s -> ("sub", enc_string s) :: fields)
+
+and encode_tparam = function
+	| TPType t -> enc_enum ITParam 0 [encode_ctype t]
+	| TPExpr e -> enc_enum ITParam 1 [encode_expr e]
+
+and encode_access a =
+	let tag = match a with
+		| APublic -> 0
+		| APrivate -> 1
+		| AStatic -> 2
+		| AOverride -> 3
+		| ADynamic -> 4
+		| AInline -> 5
+		| AMacro -> 6
+	in
+	enc_enum IAccess tag []
+
+and encode_meta_entry (m,ml,p) =
+	enc_obj [
+		"name", enc_string (fst (MetaInfo.to_string m));
+		"params", enc_array (List.map encode_expr ml);
+		"pos", encode_pos p;
+	]
+
+and encode_meta_content m =
+	enc_array (List.map encode_meta_entry m)
+
+and encode_field (f:class_field) =
+	let tag, pl = match f.cff_kind with
+		| FVar (t,e) -> 0, [null encode_ctype t; null encode_expr e]
+		| FFun f -> 1, [encode_fun f]
+		| FProp (get,set, t, e) -> 2, [enc_string get; enc_string set; null encode_ctype t; null encode_expr e]
+	in
+	enc_obj [
+		"name",enc_string f.cff_name;
+		"doc", null enc_string f.cff_doc;
+		"pos", encode_pos f.cff_pos;
+		"kind", enc_enum IField tag pl;
+		"meta", encode_meta_content f.cff_meta;
+		"access", enc_array (List.map encode_access f.cff_access);
+	]
+
+and encode_ctype t =
+	let tag, pl = match t with
+	| CTPath p ->
+		0, [encode_path p]
+	| CTFunction (pl,r) ->
+		1, [enc_array (List.map encode_ctype pl);encode_ctype r]
+	| CTAnonymous fl ->
+		2, [enc_array (List.map encode_field fl)]
+	| CTParent t ->
+		3, [encode_ctype t]
+	| CTExtend (t,fields) ->
+		4, [encode_path t; enc_array (List.map encode_field fields)]
+	| CTOptional t ->
+		5, [encode_ctype t]
+	in
+	enc_enum ICType tag pl
+
+and encode_tparam_decl tp =
+	enc_obj [
+		"name", enc_string tp.tp_name;
+		"params", enc_array (List.map encode_tparam_decl tp.tp_params);
+		"constraints", enc_array (List.map encode_ctype tp.tp_constraints);
+	]
+
+and encode_fun f =
+	enc_obj [
+		"params", enc_array (List.map encode_tparam_decl f.f_params);
+		"args", enc_array (List.map (fun (n,opt,t,e) ->
+			enc_obj [
+				"name", enc_string n;
+				"opt", VBool opt;
+				"type", null encode_ctype t;
+				"value", null encode_expr e;
+			]
+		) f.f_args);
+		"ret", null encode_ctype f.f_type;
+		"expr", null encode_expr f.f_expr
+	]
+
+and encode_expr e =
+	let rec loop (e,p) =
+		let tag, pl = match e with
+			| EConst c ->
+				0, [encode_const c]
+			| EArray (e1,e2) ->
+				1, [loop e1;loop e2]
+			| EBinop (op,e1,e2) ->
+				2, [encode_binop op;loop e1;loop e2]
+			| EField (e,f) ->
+				3, [loop e;enc_string f]
+			| EParenthesis e ->
+				4, [loop e]
+			| EObjectDecl fl ->
+				5, [enc_array (List.map (fun (f,e) -> enc_obj [
+					"field",enc_string f;
+					"expr",loop e;
+				]) fl)]
+			| EArrayDecl el ->
+				6, [enc_array (List.map loop el)]
+			| ECall (e,el) ->
+				7, [loop e;enc_array (List.map loop el)]
+			| ENew (p,el) ->
+				8, [encode_path p; enc_array (List.map loop el)]
+			| EUnop (op,flag,e) ->
+				9, [encode_unop op; VBool (match flag with Prefix -> false | Postfix -> true); loop e]
+			| EVars vl ->
+				10, [enc_array (List.map (fun (v,t,eo) ->
+					enc_obj [
+						"name",enc_string v;
+						"type",null encode_ctype t;
+						"expr",null loop eo;
+					]
+				) vl)]
+			| EFunction (name,f) ->
+				11, [null enc_string name; encode_fun f]
+			| EBlock el ->
+				12, [enc_array (List.map loop el)]
+			| EFor (e,eloop) ->
+				13, [loop e;loop eloop]
+			| EIn (e1,e2) ->
+				14, [loop e1;loop e2]
+			| EIf (econd,e,eelse) ->
+				15, [loop econd;loop e;null loop eelse]
+			| EWhile (econd,e,flag) ->
+				16, [loop econd;loop e;VBool (match flag with NormalWhile -> true | DoWhile -> false)]
+			| ESwitch (e,cases,eopt) ->
+				17, [loop e;enc_array (List.map (fun (ecl,eg,e) ->
+					enc_obj [
+						"values",enc_array (List.map loop ecl);
+						"guard",null loop eg;
+						"expr",null loop e
+					]
+				) cases);null encode_null_expr eopt]
+			| ETry (e,catches) ->
+				18, [loop e;enc_array (List.map (fun (v,t,e) ->
+					enc_obj [
+						"name",enc_string v;
+						"type",encode_ctype t;
+						"expr",loop e
+					]
+				) catches)]
+			| EReturn eo ->
+				19, [null loop eo]
+			| EBreak ->
+				20, []
+			| EContinue ->
+				21, []
+			| EUntyped e ->
+				22, [loop e]
+			| EThrow e ->
+				23, [loop e]
+			| ECast (e,t) ->
+				24, [loop e; null encode_ctype t]
+			| EDisplay (e,flag) ->
+				25, [loop e; VBool flag]
+			| EDisplayNew t ->
+				26, [encode_path t]
+			| ETernary (econd,e1,e2) ->
+				27, [loop econd;loop e1;loop e2]
+			| ECheckType (e,t) ->
+				28, [loop e; encode_ctype t]
+			| EMeta (m,e) ->
+				29, [encode_meta_entry m;loop e]
+		in
+		enc_obj [
+			"pos", encode_pos p;
+			"expr", enc_enum IExpr tag pl;
+		]
+	in
+	loop e
+
+and encode_null_expr e =
+	match e with
+	| None ->
+		enc_obj ["pos", VNull;"expr",VNull]
+	| Some e ->
+		encode_expr e
+
+(* ---------------------------------------------------------------------- *)
+(* EXPR DECODING *)
+
+let opt f v =
+	match v with
+	| VNull -> None
+	| _ -> Some (f v)
+
+let opt_list f v =
+	match v with
+	| VNull -> []
+	| _ -> f v
+
+let decode_pos = function
+	| VAbstract (APos p) -> p
+	| _ -> raise Invalid_expr
+
+let field v f =
+	match v with
+	| VObject o -> get_field o (hash f)
+	| _ -> raise Invalid_expr
+
+let decode_enum v =
+	match field v "index", field v "args" with
+	| VInt i, VNull -> i, []
+	| VInt i, VArray a -> i, Array.to_list a
+	| _ -> raise Invalid_expr
+
+let dec_bool = function
+	| VBool b -> b
+	| _ -> raise Invalid_expr
+
+let dec_string v =
+	match field v "__s" with
+	| VString s -> s
+	| _ -> raise Invalid_expr
+
+let dec_array v =
+	match field v "__a", field v "length" with
+	| VArray a, VInt l -> Array.to_list (if Array.length a = l then a else Array.sub a 0 l)
+	| _ -> raise Invalid_expr
+
+let decode_const c =
+	match decode_enum c with
+	| 0, [s] -> Int (dec_string s)
+	| 1, [s] -> Float (dec_string s)
+	| 2, [s] -> String (dec_string s)
+	| 3, [s] -> Ident (dec_string s)
+	| 4, [s;opt] -> Regexp (dec_string s, dec_string opt)
+	| 5, [s] -> Ident (dec_string s) (** deprecated CType, keep until 3.0 release **)
+	| _ -> raise Invalid_expr
+
+let rec decode_op op =
+	match decode_enum op with
+	| 0, [] -> OpAdd
+	| 1, [] -> OpMult
+	| 2, [] -> OpDiv
+	| 3, [] -> OpSub
+	| 4, [] -> OpAssign
+	| 5, [] -> OpEq
+	| 6, [] -> OpNotEq
+	| 7, [] -> OpGt
+	| 8, [] -> OpGte
+	| 9, [] -> OpLt
+	| 10, [] -> OpLte
+	| 11, [] -> OpAnd
+	| 12, [] -> OpOr
+	| 13, [] -> OpXor
+	| 14, [] -> OpBoolAnd
+	| 15, [] -> OpBoolOr
+	| 16, [] -> OpShl
+	| 17, [] -> OpShr
+	| 18, [] -> OpUShr
+	| 19, [] -> OpMod
+	| 20, [op] -> OpAssignOp (decode_op op)
+	| 21, [] -> OpInterval
+	| 22,[] -> OpArrow
+	| _ -> raise Invalid_expr
+
+let decode_unop op =
+	match decode_enum op with
+	| 0, [] -> Increment
+	| 1, [] -> Decrement
+	| 2, [] -> Not
+	| 3, [] -> Neg
+	| 4, [] -> NegBits
+	| _ -> raise Invalid_expr
+
+let rec decode_path t =
+	{
+		tpackage = List.map dec_string (dec_array (field t "pack"));
+		tname = dec_string (field t "name");
+		tparams = List.map decode_tparam (dec_array (field t "params"));
+		tsub = opt dec_string (field t "sub");
+	}
+
+and decode_tparam v =
+	match decode_enum v with
+	| 0,[t] -> TPType (decode_ctype t)
+	| 1,[e] -> TPExpr (decode_expr e)
+	| _ -> raise Invalid_expr
+
+and decode_tparam_decl v =
+	{
+		tp_name = dec_string (field v "name");
+		tp_constraints = (match field v "constraints" with VNull -> [] | a -> List.map decode_ctype (dec_array a));
+		tp_params = (match field v "params" with VNull -> [] | a -> List.map decode_tparam_decl (dec_array a));
+	}
+
+and decode_fun v =
+	{
+		f_params = List.map decode_tparam_decl (dec_array (field v "params"));
+		f_args = List.map (fun o ->
+			(dec_string (field o "name"),dec_bool (field o "opt"),opt decode_ctype (field o "type"),opt decode_expr (field o "value"))
+		) (dec_array (field v "args"));
+		f_type = opt decode_ctype (field v "ret");
+		f_expr = opt decode_expr (field v "expr");
+	}
+
+and decode_access v =
+	match decode_enum v with
+	| 0, [] -> APublic
+	| 1, [] -> APrivate
+	| 2, [] -> AStatic
+	| 3, [] -> AOverride
+	| 4, [] -> ADynamic
+	| 5, [] -> AInline
+	| 6, [] -> AMacro
+	| _ -> raise Invalid_expr
+
+and decode_meta_entry v =
+	MetaInfo.from_string (dec_string (field v "name")), List.map decode_expr (dec_array (field v "params")), decode_pos (field v "pos")
+
+and decode_meta_content v =
+	List.map decode_meta_entry (dec_array v)
+
+and decode_field v =
+	let fkind = match decode_enum (field v "kind") with
+		| 0, [t;e] ->
+			FVar (opt decode_ctype t, opt decode_expr e)
+		| 1, [f] ->
+			FFun (decode_fun f)
+		| 2, [get;set; t; e] ->
+			FProp (dec_string get, dec_string set, opt decode_ctype t, opt decode_expr e)
+		| _ ->
+			raise Invalid_expr
+	in
+	{
+		cff_name = dec_string (field v "name");
+		cff_doc = opt dec_string (field v "doc");
+		cff_pos = decode_pos (field v "pos");
+		cff_kind = fkind;
+		cff_access = List.map decode_access (opt_list dec_array (field v "access"));
+		cff_meta = opt_list decode_meta_content (field v "meta");
+	}
+
+and decode_ctype t =
+	match decode_enum t with
+	| 0, [p] ->
+		CTPath (decode_path p)
+	| 1, [a;r] ->
+		CTFunction (List.map decode_ctype (dec_array a), decode_ctype r)
+	| 2, [fl] ->
+		CTAnonymous (List.map decode_field (dec_array fl))
+	| 3, [t] ->
+		CTParent (decode_ctype t)
+	| 4, [t;fl] ->
+		CTExtend (decode_path t, List.map decode_field (dec_array fl))
+	| 5, [t] ->
+		CTOptional (decode_ctype t)
+	| _ ->
+		raise Invalid_expr
+
+let rec decode_expr v =
+	let rec loop v =
+		(decode (field v "expr"), decode_pos (field v "pos"))
+	and decode e =
+		match decode_enum e with
+		| 0, [c] ->
+			EConst (decode_const c)
+		| 1, [e1;e2] ->
+			EArray (loop e1, loop e2)
+		| 2, [op;e1;e2] ->
+			EBinop (decode_op op, loop e1, loop e2)
+		| 3, [e;f] ->
+			EField (loop e, dec_string f)
+		| 4, [e] ->
+			EParenthesis (loop e)
+		| 5, [a] ->
+			EObjectDecl (List.map (fun o ->
+				(dec_string (field o "field"), loop (field o "expr"))
+			) (dec_array a))
+		| 6, [a] ->
+			EArrayDecl (List.map loop (dec_array a))
+		| 7, [e;el] ->
+			ECall (loop e,List.map loop (dec_array el))
+		| 8, [t;el] ->
+			ENew (decode_path t,List.map loop (dec_array el))
+		| 9, [op;VBool f;e] ->
+			EUnop (decode_unop op,(if f then Postfix else Prefix),loop e)
+		| 10, [vl] ->
+			EVars (List.map (fun v ->
+				(dec_string (field v "name"),opt decode_ctype (field v "type"),opt loop (field v "expr"))
+			) (dec_array vl))
+		| 11, [fname;f] ->
+			EFunction (opt dec_string fname,decode_fun f)
+		| 12, [el] ->
+			EBlock (List.map loop (dec_array el))
+		| 13, [e1;e2] ->
+			EFor (loop e1, loop e2)
+		| 14, [e1;e2] ->
+			EIn (loop e1, loop e2)
+		| 15, [e1;e2;e3] ->
+			EIf (loop e1, loop e2, opt loop e3)
+		| 16, [e1;e2;VBool flag] ->
+			EWhile (loop e1,loop e2,if flag then NormalWhile else DoWhile)
+		| 17, [e;cases;eo] ->
+			let cases = List.map (fun c ->
+				(List.map loop (dec_array (field c "values")),opt loop (field c "guard"),opt loop (field c "expr"))
+			) (dec_array cases) in
+			ESwitch (loop e,cases,opt decode_null_expr eo)
+		| 18, [e;catches] ->
+			let catches = List.map (fun c ->
+				(dec_string (field c "name"),decode_ctype (field c "type"),loop (field c "expr"))
+			) (dec_array catches) in
+			ETry (loop e, catches)
+		| 19, [e] ->
+			EReturn (opt loop e)
+		| 20, [] ->
+			EBreak
+		| 21, [] ->
+			EContinue
+		| 22, [e] ->
+			EUntyped (loop e)
+		| 23, [e] ->
+			EThrow (loop e)
+		| 24, [e;t] ->
+			ECast (loop e,opt decode_ctype t)
+		| 25, [e;f] ->
+			EDisplay (loop e,dec_bool f)
+		| 26, [t] ->
+			EDisplayNew (decode_path t)
+		| 27, [e1;e2;e3] ->
+			ETernary (loop e1,loop e2,loop e3)
+		| 28, [e;t] ->
+			ECheckType (loop e, decode_ctype t)
+		| 29, [m;e] ->
+			EMeta (decode_meta_entry m,loop e)
+		| 30, [e;f] ->
+			EField (loop e, dec_string f) (*** deprecated EType, keep until haxe 3 **)
+		| _ ->
+			raise Invalid_expr
+	in
+	try
+		loop v
+	with Stack_overflow ->
+		raise Invalid_expr
+
+and decode_null_expr v =
+	match field v "expr" with
+	| VNull -> None
+	| _ -> Some (decode_expr v)
+
+
+(* ---------------------------------------------------------------------- *)
+(* TYPE ENCODING *)
+
+let encode_ref v convert tostr =
+	enc_obj [
+		"get", VFunction (Fun0 (fun() -> convert v));
+		"__string", VFunction (Fun0 (fun() -> VString (tostr())));
+		"toString", VFunction (Fun0 (fun() -> enc_string (tostr())));
+		"$", VAbstract (AUnsafe (Obj.repr v));
+	]
+
+let decode_ref v : 'a =
+	match field v "$" with
+	| VAbstract (AUnsafe t) -> Obj.obj t
+	| _ -> raise Invalid_expr
+
+let encode_pmap convert m =
+	let h = Hashtbl.create 0 in
+	PMap.iter (fun k v -> Hashtbl.add h (VString k) (convert v)) m;
+	enc_hash h
+
+let encode_pmap_array convert m =
+	let l = ref [] in
+	PMap.iter (fun _ v -> l := !l @ [(convert v)]) m;
+	enc_array !l
+
+let encode_array convert l =
+	enc_array (List.map convert l)
+
+let encode_meta m set =
+	let meta = ref m in
+	enc_obj [
+		"get", VFunction (Fun0 (fun() ->
+			encode_meta_content (!meta)
+		));
+		"add", VFunction (Fun3 (fun k vl p ->
+			(try
+				let el = List.map decode_expr (dec_array vl) in
+				meta := (MetaInfo.from_string (dec_string k), el, decode_pos p) :: !meta;
+				set (!meta)
+			with Invalid_expr ->
+				failwith "Invalid expression");
+			VNull
+		));
+		"remove", VFunction (Fun1 (fun k ->
+			let k = MetaInfo.from_string (try dec_string k with Invalid_expr -> raise Builtin_error) in
+			meta := List.filter (fun (m,_,_) -> m <> k) (!meta);
+			set (!meta);
+			VNull
+		));
+		"has", VFunction (Fun1 (fun k ->
+			let k = MetaInfo.from_string (try dec_string k with Invalid_expr -> raise Builtin_error) in
+			VBool (List.exists (fun (m,_,_) -> m = k) (!meta));
+		));
+	]
+
+let rec encode_mtype t fields =
+	let i = t_infos t in
+	enc_obj ([
+		"__t", 	VAbstract (ATDecl t);
+		"pack", enc_array (List.map enc_string (fst i.mt_path));
+		"name", enc_string (snd i.mt_path);
+		"pos", encode_pos i.mt_pos;
+		"module", enc_string (s_type_path i.mt_module.m_path);
+		"isPrivate", VBool i.mt_private;
+		"meta", encode_meta i.mt_meta (fun m -> i.mt_meta <- m);
+		"doc", null enc_string i.mt_doc;
+		"params", encode_type_params i.mt_types;
+	] @ fields)
+
+and encode_type_params tl =
+	enc_array (List.map (fun (n,t) -> enc_obj ["name",enc_string n;"t",encode_type t]) tl)
+
+and encode_tenum e =
+	encode_mtype (TEnumDecl e) [
+		"isExtern", VBool e.e_extern;
+		"exclude", VFunction (Fun0 (fun() -> e.e_extern <- true; VNull));
+		"constructs", encode_pmap encode_efield e.e_constrs;
+		"names", enc_array (List.map enc_string e.e_names);
+	]
+
+and encode_tabstract a =
+	encode_mtype (TAbstractDecl a) [
+		"type", encode_type a.a_this;
+		"impl", (match a.a_impl with None -> VNull | Some c -> encode_clref c);
+		"binops", enc_array (List.map (fun (op,cf) -> enc_obj [ "op",encode_binop op; "field",encode_cfield cf]) a.a_ops);
+		"unops", enc_array (List.map (fun (op,postfix,cf) -> enc_obj [ "op",encode_unop op; "isPostfix",VBool (match postfix with Postfix -> true | Prefix -> false); "field",encode_cfield cf]) a.a_unops);
+		"from", enc_array (List.map (fun (t,cfo) -> enc_obj [ "t",encode_type t; "field",match cfo with None -> VNull | Some cf -> encode_cfield cf]) a.a_from);
+		"to", enc_array (List.map (fun (t,cfo) -> enc_obj [ "t",encode_type t; "field",match cfo with None -> VNull | Some cf -> encode_cfield cf]) a.a_to);
+		"array", enc_array (List.map encode_cfield a.a_array);
+	]
+
+and encode_efield f =
+	enc_obj [
+		"name", enc_string f.ef_name;
+		"type", encode_type f.ef_type;
+		"pos", encode_pos f.ef_pos;
+		"index", VInt f.ef_index;
+		"meta", encode_meta f.ef_meta (fun m -> f.ef_meta <- m);
+		"doc", null enc_string f.ef_doc;
+		"params", encode_type_params f.ef_params;
+	]
+
+and encode_cfield f =
+	enc_obj [
+		"name", enc_string f.cf_name;
+		"type", (match f.cf_kind with Method _ -> encode_lazy_type f.cf_type | _ -> encode_type f.cf_type);
+		"isPublic", VBool f.cf_public;
+		"params", encode_type_params f.cf_params;
+		"meta", encode_meta f.cf_meta (fun m -> f.cf_meta <- m);
+		"expr", (VFunction (Fun0 (fun() -> ignore(follow f.cf_type); (match f.cf_expr with None -> VNull | Some e -> encode_texpr e))));
+		"kind", encode_field_kind f.cf_kind;
+		"pos", encode_pos f.cf_pos;
+		"doc", null enc_string f.cf_doc;
+	]
+
+and encode_field_kind k =
+	let tag, pl = (match k with
+		| Type.Var v -> 0, [encode_var_access v.v_read; encode_var_access v.v_write]
+		| Method m -> 1, [encode_method_kind m]
+	) in
+	enc_enum IFieldKind tag pl
+
+and encode_var_access a =
+	let tag, pl = (match a with
+		| AccNormal -> 0, []
+		| AccNo -> 1, []
+		| AccNever -> 2, []
+		| AccResolve -> 3, []
+		| AccCall -> 4, []
+		| AccInline	-> 5, []
+		| AccRequire (s,msg) -> 6, [enc_string s; null enc_string msg]
+	) in
+	enc_enum IVarAccess tag pl
+
+and encode_method_kind m =
+	let tag, pl = (match m with
+		| MethNormal -> 0, []
+		| MethInline -> 1, []
+		| MethDynamic -> 2, []
+		| MethMacro -> 3, []
+	) in
+	enc_enum IMethodKind tag pl
+
+and encode_class_kind k =
+	let tag, pl = (match k with
+		| KNormal -> 0, []
+		| KTypeParameter pl -> 1, [encode_tparams pl]
+		| KExtension (cl, params) -> 2, [encode_clref cl; encode_tparams params]
+		| KExpr e -> 3, [encode_expr e]
+		| KGeneric -> 4, []
+		| KGenericInstance (cl, params) -> 5, [encode_clref cl; encode_tparams params]
+		| KMacroType -> 6, []
+		| KAbstractImpl a -> 7, [encode_ref a encode_tabstract (fun() -> s_type_path a.a_path)]
+	) in
+	enc_enum IClassKind tag pl
+
+and encode_tclass c =
+	c.cl_build();
+	encode_mtype (TClassDecl c) [
+		"kind", encode_class_kind c.cl_kind;
+		"isExtern", VBool c.cl_extern;
+		"exclude", VFunction (Fun0 (fun() -> c.cl_extern <- true; c.cl_init <- None; VNull));
+		"isInterface", VBool c.cl_interface;
+		"superClass", (match c.cl_super with
+			| None -> VNull
+			| Some (c,pl) -> enc_obj ["t",encode_clref c;"params",encode_tparams pl]
+		);
+		"interfaces", enc_array (List.map (fun (c,pl) -> enc_obj ["t",encode_clref c;"params",encode_tparams pl]) c.cl_implements);
+		"fields", encode_ref c.cl_ordered_fields (encode_array encode_cfield) (fun() -> "class fields");
+		"statics", encode_ref c.cl_ordered_statics (encode_array encode_cfield) (fun() -> "class fields");
+		"constructor", (match c.cl_constructor with None -> VNull | Some c -> encode_ref c encode_cfield (fun() -> "constructor"));
+		"init", (match c.cl_init with None -> VNull | Some e -> encode_texpr e);
+	]
+
+and encode_ttype t =
+	encode_mtype (TTypeDecl t) [
+		"isExtern", VBool false;
+		"exclude", VFunction (Fun0 (fun() -> VNull));
+		"type", encode_type t.t_type;
+	]
+
+and encode_tanon a =
+	enc_obj [
+		"fields", encode_pmap_array encode_cfield a.a_fields;
+	]
+
+and encode_tparams pl =
+	enc_array (List.map encode_type pl)
+
+and encode_clref c =
+	encode_ref c encode_tclass (fun() -> s_type_path c.cl_path)
+
+and encode_type t =
+	let rec loop = function
+		| TMono r ->
+			(match !r with
+			| None -> 0, [encode_ref r (fun r -> match !r with None -> VNull | Some t -> encode_type t) (fun() -> "<mono>")]
+			| Some t -> loop t)
+		| TEnum (e, pl) ->
+			1 , [encode_ref e encode_tenum (fun() -> s_type_path e.e_path); encode_tparams pl]
+		| TInst (c, pl) ->
+			2 , [encode_clref c; encode_tparams pl]
+		| TType (t,pl) ->
+			3 , [encode_ref t encode_ttype (fun() -> s_type_path t.t_path); encode_tparams pl]
+		| TFun (pl,ret) ->
+			let pl = List.map (fun (n,o,t) ->
+				enc_obj [
+					"name",enc_string n;
+					"opt",VBool o;
+					"t",encode_type t
+				]
+			) pl in
+			4 , [enc_array pl; encode_type ret]
+		| TAnon a ->
+			5, [encode_ref a encode_tanon (fun() -> "<anonymous>")]
+		| TDynamic tsub as t ->
+			if t == t_dynamic then
+				6, [VNull]
+			else
+				6, [encode_type tsub]
+		| TLazy f ->
+			loop (!f())
+		| TAbstract (a, pl) ->
+			8, [encode_ref a encode_tabstract (fun() -> s_type_path a.a_path); encode_tparams pl]
+	in
+	let tag, pl = loop t in
+	enc_enum IType tag pl
+
+and encode_lazy_type t =
+	let rec loop = function
+		| TMono r ->
+			(match !r with
+			| Some t -> loop t
+			| _ -> encode_type t)
+		| TLazy f ->
+			enc_enum IType 7 [VAbstract (ALazyType f)]
+		| _ ->
+			encode_type t
+	in
+	loop t
+
+and decode_type t =
+	match decode_enum t with
+	| 0, [r] -> TMono (decode_ref r)
+	| 1, [e; pl] -> TEnum (decode_ref e, List.map decode_type (dec_array pl))
+	| 2, [c; pl] -> TInst (decode_ref c, List.map decode_type (dec_array pl))
+	| 3, [t; pl] -> TType (decode_ref t, List.map decode_type (dec_array pl))
+	| 4, [pl; r] -> TFun (List.map (fun p -> dec_string (field p "name"), dec_bool (field p "opt"), decode_type (field p "t")) (dec_array pl), decode_type r)
+	| 5, [a] -> TAnon (decode_ref a)
+	| 6, [VNull] -> t_dynamic
+	| 6, [t] -> TDynamic (decode_type t)
+	| 7, [VAbstract (ALazyType f)] -> TLazy f
+	| 8, [a; pl] -> TAbstract (decode_ref a, List.map decode_type (dec_array pl))
+	| _ -> raise Invalid_expr
+
+and encode_texpr e =
+	VAbstract (ATExpr e)
+
+let decode_tdecl v =
+	match v with
+	| VObject o ->
+		(match get_field o (hash "__t") with
+		| VAbstract (ATDecl t) -> t
+		| _ -> raise Invalid_expr)
+	| _ -> raise Invalid_expr
+
+(* ---------------------------------------------------------------------- *)
+(* TYPE DEFINITION *)
+
+let decode_type_def v =
+	let pack = List.map dec_string (dec_array (field v "pack")) in
+	let name = dec_string (field v "name") in
+	let meta = decode_meta_content (field v "meta") in
+	let pos = decode_pos (field v "pos") in
+	let isExtern = dec_bool (field v "isExtern") in
+	let fields = List.map decode_field (dec_array (field v "fields")) in
+	let mk fl dl =
+		{
+			d_name = name;
+			d_doc = None;
+			d_params = List.map decode_tparam_decl (dec_array (field v "params"));
+			d_meta = meta;
+			d_flags = fl;
+			d_data = dl;
+		}
+	in
+	let tdef = (match decode_enum (field v "kind") with
+	| 0, [] ->
+		let conv f =
+			let loop (n,opt,t,_) =
+				match t with
+				| None -> raise Invalid_expr
+				| Some t -> n, opt, t
+			in
+			let args, params, t = (match f.cff_kind with
+				| FVar (t,None) -> [], [], t
+				| FFun f -> List.map loop f.f_args, f.f_params, f.f_type
+				| _ -> raise Invalid_expr
+			) in
+			{
+				ec_name = f.cff_name;
+				ec_doc = f.cff_doc;
+				ec_meta = f.cff_meta;
+				ec_pos = f.cff_pos;
+				ec_args = args;
+				ec_params = params;
+				ec_type = t;
+			}
+		in
+		EEnum (mk (if isExtern then [EExtern] else []) (List.map conv fields))
+	| 1, [] ->
+		ETypedef (mk (if isExtern then [EExtern] else []) (CTAnonymous fields))
+	| 2, [ext;impl;interf] ->
+		let flags = if isExtern then [HExtern] else [] in
+		let flags = (match interf with VNull | VBool false -> flags | VBool true -> HInterface :: flags | _ -> raise Invalid_expr) in
+		let flags = (match opt decode_path ext with None -> flags | Some t -> HExtends t :: flags) in
+		let flags = (match opt (fun v -> List.map decode_path (dec_array v)) impl with None -> flags | Some l -> List.map (fun t -> HImplements t) l @ flags) in
+		EClass (mk flags fields)
+	| 3, [t] ->
+		ETypedef (mk (if isExtern then [EExtern] else []) (decode_ctype t))
+	| 4, [tthis;tfrom;tto] ->
+		let flags = match opt dec_array tfrom with None -> [] | Some ta -> List.map (fun t -> AFromType (decode_ctype t)) ta in
+		let flags = match opt dec_array tto with None -> flags | Some ta -> (List.map (fun t -> AToType (decode_ctype t)) ta) @ flags in
+		let flags = match opt decode_ctype tthis with None -> flags | Some t -> (AIsType t) :: flags in
+		EAbstract(mk flags fields)
+	| _ ->
+		raise Invalid_expr
+	) in
+	(pack, name), tdef, pos
+
+(* ---------------------------------------------------------------------- *)
+(* VALUE-TO-CONSTANT *)
+
+let rec make_const e =
+	match e.eexpr with
+	| TConst c ->
+		(match c with
+		| TInt i -> best_int i
+		| TFloat s -> VFloat (float_of_string s)
+		| TString s -> enc_string s
+		| TBool b -> VBool b
+		| TNull -> VNull
+		| TThis | TSuper -> raise Exit)
+	| TParenthesis e ->
+		make_const e
+	| TObjectDecl el ->
+		VObject (obj (hash_field (get_ctx())) (List.map (fun (f,e) -> f, make_const e) el))
+	| TArrayDecl al ->
+		enc_array (List.map make_const al)
+	| _ ->
+		raise Exit
+
+(* ---------------------------------------------------------------------- *)
+(* TEXPR-TO-AST-EXPR *)
+
+open Ast
+
+let tpath p mp pl =
+	if snd mp = snd p then
+		CTPath {
+			tpackage = fst p;
+			tname = snd p;
+			tparams = List.map (fun t -> TPType t) pl;
+			tsub = None;
+		}
+	else CTPath {
+			tpackage = fst mp;
+			tname = snd mp;
+			tparams = List.map (fun t -> TPType t) pl;
+			tsub = Some (snd p);
+		}
+
+let rec make_type = function
+	| TMono r ->
+		(match !r with
+		| None -> raise Exit
+		| Some t -> make_type t)
+	| TEnum (e,pl) ->
+		tpath e.e_path e.e_module.m_path (List.map make_type pl)
+	| TInst({cl_kind = KTypeParameter _} as c,pl) ->
+		tpath ([],snd c.cl_path) ([],snd c.cl_path) (List.map make_type pl)
+	| TInst (c,pl) ->
+		tpath c.cl_path c.cl_module.m_path (List.map make_type pl)
+	| TType (t,pl) as tf ->
+		(* recurse on type-type *)
+		if (snd t.t_path).[0] = '#' then make_type (follow tf) else tpath t.t_path t.t_module.m_path (List.map make_type pl)
+	| TAbstract (a,pl) ->
+		tpath a.a_path a.a_module.m_path (List.map make_type pl)
+	| TFun (args,ret) ->
+		CTFunction (List.map (fun (_,_,t) -> make_type t) args, make_type ret)
+	| TAnon a ->
+		begin match !(a.a_status) with
+		| Statics c -> tpath ([],"Class") ([],"Class") [tpath c.cl_path c.cl_path []]
+		| EnumStatics e -> tpath ([],"Enum") ([],"Enum") [tpath e.e_path e.e_path []]
+		| _ ->
+			CTAnonymous (PMap.foldi (fun _ f acc ->
+				{
+					cff_name = f.cf_name;
+					cff_kind = FVar (mk_ot f.cf_type,None);
+					cff_pos = f.cf_pos;
+					cff_doc = f.cf_doc;
+					cff_meta = f.cf_meta;
+					cff_access = [];
+				} :: acc
+			) a.a_fields [])
+		end
+	| (TDynamic t2) as t ->
+		tpath ([],"Dynamic") ([],"Dynamic") (if t == t_dynamic then [] else [make_type t2])
+	| TLazy f ->
+		make_type ((!f)())
+
+and mk_ot t =
+	match follow t with
+	| TMono _ -> None
+	| _ -> (try Some (make_type t) with Exit -> None)
+
+let rec make_ast e =
+	let full_type_path t =
+		let mp,p = match t with
+		| TClassDecl c -> c.cl_module.m_path,c.cl_path
+		| TEnumDecl en -> en.e_module.m_path,en.e_path
+		| TAbstractDecl a -> a.a_module.m_path,a.a_path
+		| TTypeDecl t -> t.t_module.m_path,t.t_path
+		in
+		if snd mp = snd p then p else (fst mp) @ [snd mp],snd p
+	in
+	let mk_path (pack,name) p =
+		match List.rev pack with
+		| [] -> (EConst (Ident name),p)
+		| pl ->
+			let rec loop = function
+				| [] -> assert false
+				| [n] -> (EConst (Ident n),p)
+				| n :: l -> (EField (loop l, n),p)
+			in
+			(EField (loop pl,name),p)
+	in
+	let mk_const = function
+		| TInt i -> Int (Int32.to_string i)
+		| TFloat s -> Float s
+		| TString s -> String s
+		| TBool b -> Ident (if b then "true" else "false")
+		| TNull -> Ident "null"
+		| TThis -> Ident "this"
+		| TSuper -> Ident "super"
+	in
+	let mk_ident = function
+		| "`trace" -> Ident "trace"
+		| n -> Ident n
+	in
+	let eopt = function None -> None | Some e -> Some (make_ast e) in
+	((match e.eexpr with
+	| TConst c ->
+		EConst (mk_const c)
+	| TLocal v -> EConst (mk_ident v.v_name)
+	| TArray (e1,e2) -> EArray (make_ast e1,make_ast e2)
+	| TBinop (op,e1,e2) -> EBinop (op, make_ast e1, make_ast e2)
+	| TField (e,f) -> EField (make_ast e, Type.field_name f)
+	| TTypeExpr t -> fst (mk_path (full_type_path t) e.epos)
+	| TParenthesis e -> EParenthesis (make_ast e)
+	| TObjectDecl fl -> EObjectDecl (List.map (fun (f,e) -> f, make_ast e) fl)
+	| TArrayDecl el -> EArrayDecl (List.map make_ast el)
+	| TCall (e,el) -> ECall (make_ast e,List.map make_ast el)
+	| TNew (c,pl,el) -> ENew ((match (try make_type (TInst (c,pl)) with Exit -> make_type (TInst (c,[]))) with CTPath p -> p | _ -> assert false),List.map make_ast el)
+	| TUnop (op,p,e) -> EUnop (op,p,make_ast e)
+	| TFunction f ->
+		let arg (v,c) = v.v_name, false, mk_ot v.v_type, (match c with None -> None | Some c -> Some (EConst (mk_const c),e.epos)) in
+		EFunction (None,{ f_params = []; f_args = List.map arg f.tf_args; f_type = mk_ot f.tf_type; f_expr = Some (make_ast f.tf_expr) })
+	| TVars vl ->
+		EVars (List.map (fun (v,e) -> v.v_name, mk_ot v.v_type, eopt e) vl)
+	| TBlock el -> EBlock (List.map make_ast el)
+	| TFor (v,it,e) ->
+		let ein = (EIn ((EConst (Ident v.v_name),it.epos),make_ast it),it.epos) in
+		EFor (ein,make_ast e)
+	| TIf (e,e1,e2) -> EIf (make_ast e,make_ast e1,eopt e2)
+	| TWhile (e1,e2,flag) -> EWhile (make_ast e1, make_ast e2, flag)
+	| TSwitch (e,cases,def) ->
+		let cases = List.map (fun (vl,e) ->
+			List.map make_ast vl,None,(match e.eexpr with TBlock [] -> None | _ -> Some (make_ast e))
+		) cases in
+		let def = match eopt def with None -> None | Some (EBlock [],_) -> Some None | e -> Some e in
+		ESwitch (make_ast e,cases,def)
+	| TMatch (e,(en,_),cases,def) ->
+		let scases (idx,args,e) =
+			let p = e.epos in
+			let unused = (EConst (Ident "_"),p) in
+			let args = (match args with
+				| None -> None
+				| Some l -> Some (List.map (function None -> unused | Some v -> (EConst (Ident v.v_name),p)) l)
+			) in
+			let mk_args n =
+				match args with
+				| None -> [unused]
+				| Some args ->
+					args @ Array.to_list (Array.make (n - List.length args) unused)
+			in
+			List.map (fun i ->
+				let c = (try List.nth en.e_names i with _ -> assert false) in
+				let cfield = (try PMap.find c en.e_constrs with Not_found -> assert false) in
+				let c = (EConst (Ident c),p) in
+				(match follow cfield.ef_type with TFun (eargs,_) -> (ECall (c,mk_args (List.length eargs)),p) | _ -> c)
+			) idx, None, (match e.eexpr with TBlock [] -> None | _ -> Some (make_ast e))
+		in
+		let def = match eopt def with None -> None | Some (EBlock [],_) -> Some None | e -> Some e in
+		ESwitch (make_ast e,List.map scases cases,def)
+	| TTry (e,catches) -> ETry (make_ast e,List.map (fun (v,e) -> v.v_name, (try make_type v.v_type with Exit -> assert false), make_ast e) catches)
+	| TReturn e -> EReturn (eopt e)
+	| TBreak -> EBreak
+	| TContinue -> EContinue
+	| TThrow e -> EThrow (make_ast e)
+	| TCast (e,t) ->
+		let t = (match t with
+			| None -> None
+			| Some t ->
+				let t = (match t with TClassDecl c -> TInst (c,[]) | TEnumDecl e -> TEnum (e,[]) | TTypeDecl t -> TType (t,[]) | TAbstractDecl a -> TAbstract (a,[])) in
+				Some (try make_type t with Exit -> assert false)
+		) in
+		ECast (make_ast e,t))
+	,e.epos)
+
+;;
+make_ast_ref := make_ast;
+make_complex_type_ref := make_type;
+encode_complex_type_ref := encode_ctype;
+enc_array_ref := enc_array;
+encode_type_ref := encode_type;
+decode_type_ref := decode_type;
+encode_expr_ref := encode_expr;
+decode_expr_ref := decode_expr;
+encode_clref_ref := encode_clref;
+enc_string_ref := enc_string;
 enc_hash_ref := enc_hash

+ 1306 - 1306
matcher.ml

@@ -1,1307 +1,1307 @@
-(*
- * Copyright (C)2005-2013 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *)
-
-open Ast
-open Common
-open Type
-open Typecore
-
-type con_def =
-	| CEnum of tenum * tenum_field
-	| CConst of tconstant
-	| CType of module_type
-	| CArray of int
-	| CFields of int * (string * tclass_field) list
-	| CExpr of texpr
-
-and con = {
-	c_def : con_def;
-	c_type : t;
-	c_pos : pos;
-}
-
-type pvar = tvar * pos
-
-type pat_def =
-	| PAny
-	| PVar of pvar
-	| PCon of con * pat list
-	| POr of pat * pat
-	| PBind of pvar * pat
-	| PTuple of pat array
-
-and pat = {
-	p_def : pat_def;
-	p_type : t;
-	p_pos : pos;
-}
-
-type st_def =
-	| SVar of tvar
-	| SField of st * string
-	| SEnum of st * string * int
-	| SArray of st * int
-	| STuple of st * int * int
-
-and st = {
-	st_def : st_def;
-	st_type : t;
-	st_pos : pos;
-}
-
-type out = {
-	o_expr : texpr;
-	o_guard : texpr option;
-	o_pos : pos;
-	o_id : int;
-}
-
-type pat_vec = pat array * out
-type pat_matrix = pat_vec list
-
-type pattern_ctx = {
-	mutable pc_locals : (string, pvar) PMap.t;
-	mutable pc_sub_vars : (string, pvar) PMap.t option;
-	mutable pc_reify : bool;
-}
-
-type dt =
-	| Out of out * dt option
-	| Switch of st * (con * dt) list
-	| Bind of (pvar * st) list * dt
-	| Goto of int
-
-type matcher = {
-	ctx : typer;
-	stl : st list;
-	need_val : bool;
-	v_lookup : (string,tvar) Hashtbl.t;
-	mutable outcomes : (pat list,out) PMap.t;
-	mutable out_type : Type.t;
-	mutable toplevel_or : bool;
-	mutable used_paths : (int,bool) Hashtbl.t;
-	mutable eval_stack : (pvar * st) list list;
-}
-
-exception Not_exhaustive of pat * st
-exception Unrecognized_pattern of Ast.expr
-
-let arity con = match con.c_def with
-	| CEnum (_,{ef_type = TFun(args,_)}) -> List.length args
-	| CEnum _ -> 0
-	| CConst _ -> 0
-	| CType mt -> 0
-	| CArray i -> i
-	| CFields (i,_) -> i
-	| CExpr _ -> 0
-
-let mk_st def t p = {
-	st_def = def;
-	st_type = t;
-	st_pos = p;
-}
-
-let mk_out mctx id e eg pl p =
-	let out = {
-		o_expr = e;
-		o_guard = eg;
-		o_pos = p;
-		o_id = id;
-	} in
-	mctx.outcomes <- PMap.add pl out mctx.outcomes;
-	out
-
-let clone_out mctx out pl p =
-	let out = {out with o_pos = p; } in
-	out
-
-let mk_pat pdef t p = {
-	p_def = pdef;
-	p_type = t;
-	p_pos = p;
-}
-
-let mk_con cdef t p = {
-	c_def = cdef;
-	c_type = t;
-	c_pos = p;
-}
-
-let mk_con_pat cdef pl t p = {
-	p_def = PCon(mk_con cdef t p,pl);
-	p_type = t;
-	p_pos = p;
-}
-
-let mk_any t p = {
-	p_def = PAny;
-	p_type = t;
-	p_pos = p;
-}
-
-let any = mk_any t_dynamic Ast.null_pos
-
-let fake_tuple_type = TInst(mk_class null_module ([],"-Tuple") null_pos, [])
-
-let mk_subs st con =
-	let map = match follow st.st_type with
-		| TInst(c,pl) -> apply_params c.cl_types pl
-		| TEnum(en,pl) -> apply_params en.e_types pl
-		| _ -> fun t -> t
-	in
-	match con.c_def with
-	| CFields (_,fl) -> List.map (fun (s,cf) -> mk_st (SField(st,s)) (map cf.cf_type) st.st_pos) fl
-	| CEnum (en,({ef_type = TFun _} as ef)) ->
-		let pl = match follow con.c_type with TEnum(_,pl) | TAbstract({a_this = TEnum(_)},pl)-> pl | TAbstract({a_path = [],"EnumValue"},[]) -> [] | _ -> [] in
-		begin match apply_params en.e_types pl (monomorphs ef.ef_params ef.ef_type) with
-			| TFun(args,r) ->
-				ExtList.List.mapi (fun i (_,_,t) ->
-					mk_st (SEnum(st,ef.ef_name,i)) t st.st_pos
-				) args
-			| _ ->
-				assert false
-		end
-	| CArray 0 -> []
-	| CArray i ->
-		let t = match follow con.c_type with TInst({cl_path=[],"Array"},[t]) -> t | _ -> assert false in
-		ExtList.List.init i (fun i -> mk_st (SArray(st,i)) t st.st_pos)
-	| CEnum _ | CConst _ | CType _ | CExpr _ ->
-		[]
-
-let get_tuple_types t = match t with
-	| TFun(tl,tr) when tr == fake_tuple_type -> Some tl
-	| _ -> None
-
-(* Printing *)
-
-let s_type = s_type (print_context())
-
-let rec s_expr_small e = match e.eexpr with
-	| TLocal v -> v.v_name
-	| TField (e,s) -> s_expr_small e ^ "." ^ field_name s
-	| TBlock [] -> "{}"
-	| _ -> s_expr (s_type) e
-
-let s_con con = match con.c_def with
-	| CEnum(_,ef) -> ef.ef_name
-	| CConst TNull -> "_"
-	| CConst c -> s_const c
-	| CType mt -> s_type_path (t_path mt)
-	| CArray i -> "[" ^(string_of_int i) ^ "]"
-	| CFields (_,fl) -> String.concat "," (List.map (fun (s,_) -> s) fl)
-	| CExpr e -> s_expr s_type e
-
-let rec s_pat pat = match pat.p_def with
-	| PVar (v,_) -> v.v_name
-	| PCon (c,[]) -> s_con c
-	| PCon (c,pl) -> s_con c ^ "(" ^ (String.concat "," (List.map s_pat pl)) ^ ")"
-	| POr (pat1,pat2) -> s_pat pat1 ^ " | " ^ s_pat pat2
-	| PAny -> "_"
-	| PBind((v,_),pat) -> v.v_name ^ "=" ^ s_pat pat
-	| PTuple pl -> "(" ^ (String.concat " " (Array.to_list (Array.map s_pat pl))) ^ ")"
-
-let st_args l r v =
-	(if l > 0 then (String.concat "," (ExtList.List.make l "_")) ^ "," else "")
-	^ v ^
-	(if r > 0 then "," ^ (String.concat "," (ExtList.List.make r "_")) else "")
-
-let rec s_st st = (match st.st_def with
-	| SVar v -> v.v_name
-	| SEnum (st,n,i) -> s_st st ^ "." ^ n ^ "." ^ (string_of_int i)
-	| SArray (st,i) -> s_st st ^ "[" ^ (string_of_int i) ^ "]"
-	| STuple (st,i,a) -> "(" ^ (st_args i (a - i - 1) (s_st st)) ^ ")"
-	| SField (st,n) -> s_st st ^ "." ^ n)
-	(* ^ ":" ^ (s_type st.st_type) *)
-
-let rec s_pat_vec pl =
-	String.concat " " (Array.to_list (Array.map s_pat pl))
-
-let s_out out = ""
-	(* ^ s_expr_small out.o_expr *)
-
-let rec s_pat_matrix pmat =
-	String.concat "\n" (List.map (fun (pl,out) -> (s_pat_vec pl) ^ "->" ^ (s_out out)) pmat)
-
-let rec s_dt tabs tree = tabs ^ match tree with
-	| Out(out,None)->
-		s_out out;
-	| Out(out,Some dt) ->
-		"if (" ^ (s_expr_small (match out.o_guard with Some e -> e | None -> assert false)) ^ ") " ^ (s_out out) ^ " else " ^ s_dt tabs dt
-	| Switch (st, cl) ->
-		"switch(" ^ (s_st st) ^ ") { \n" ^ tabs
-		^ (String.concat ("\n" ^ tabs) (List.map (fun (c,dt) ->
-			"case " ^ (s_con c) ^ ":\n" ^ (s_dt (tabs ^ "\t") dt)
-		) cl))
-		^ "\n" ^ (if String.length tabs = 0 then "" else (String.sub tabs 0 (String.length tabs - 1))) ^ "}"
-	| Bind (bl, dt) -> "bind " ^ (String.concat "," (List.map (fun ((v,_),st) -> v.v_name ^ "(" ^ (string_of_int v.v_id) ^ ") =" ^ (s_st st)) bl)) ^ "\n" ^ (s_dt tabs dt)
-	| Goto i ->
-		"goto " ^ (string_of_int i)
-
-(* Pattern parsing *)
-
-let unify_enum_field en pl ef t =
-	let t2 = match follow ef.ef_type with
-		| TFun(_,r) -> r
-		| t2 -> t2
-	in
-	let t2 = (apply_params en.e_types pl (monomorphs ef.ef_params t2)) in
-	Type.unify t2 t
-
-let unify ctx a b p =
-	try unify_raise ctx a b p with Error (Unify l,p) -> error (error_msg (Unify l)) p
-
-let rec is_value_type = function
-	| TMono r ->
-		(match !r with None -> false | Some t -> is_value_type t)
-	| TType (t,tl) ->
-		is_value_type (apply_params t.t_types tl t.t_type)
-	| TInst({cl_path=[],"String"},[]) ->
-		true
-	| TAbstract _ ->
-		true
-	| _ ->
-		false
-
-let to_pattern ctx e t =
-	let perror p = error "Unrecognized pattern" p in
-	let verror n p = error ("Variable " ^ n ^ " must appear exactly once in each sub-pattern") p in
-	let mk_var tctx s t p =
-		let v = match tctx.pc_sub_vars with
-			| Some vmap -> fst (try PMap.find s vmap with Not_found -> verror s p)
-			| None -> alloc_var s t
-		in
-		unify ctx t v.v_type p;
-		if PMap.mem s tctx.pc_locals then verror s p;
-		tctx.pc_locals <- PMap.add s (v,p) tctx.pc_locals;
-		v
-	in
-	let rec loop pctx e t =
-		let p = pos e in
-		match fst e with
-		| EConst(Ident "null") ->
-			error "null-patterns are not allowed" p
-		| ECheckType(e, CTPath({tpackage=["haxe";"macro"]; tname="Expr"})) ->
-			let old = pctx.pc_reify in
-			pctx.pc_reify <- true;
-			let e = loop pctx e t in
-			pctx.pc_reify <- old;
-			e
-		| EParenthesis e ->
-			loop pctx e t
-		| ECast(e1,None) ->
-			loop pctx e1 t
-		| EConst((Ident ("false" | "true") | Int _ | String _ | Float _) as c) ->
-			let e = Codegen.type_constant ctx.com c p in
-			unify ctx e.etype t p;
-			let c = match e.eexpr with TConst c -> c | _ -> assert false in
-			mk_con_pat (CConst c) [] t p
-		| EField _ ->
-			let e = type_expr ctx e (WithType t) in
-			let e = match Optimizer.make_constant_expression ctx ~concat_strings:true e with Some e -> e | None -> e in
-			(match e.eexpr with
-			| TConst c -> mk_con_pat (CConst c) [] t p
-			| TTypeExpr mt -> mk_con_pat (CType mt) [] t p
-			| TField(_, FStatic(_,cf)) when is_value_type cf.cf_type ->
-				mk_con_pat (CExpr e) [] cf.cf_type p
-			| TField(_, FEnum(en,ef)) ->
-				begin try
-					unify_enum_field en (List.map (fun _ -> mk_mono()) en.e_types) ef t
-				with Unify_error l ->
-					error (error_msg (Unify l)) p
-				end;
-				mk_con_pat (CEnum(en,ef)) [] t p
-			| _ -> error "Constant expression expected" p)
-		| ECall(ec,el) ->
-			let ec = type_expr ctx ec (WithType t) in
-			(match follow ec.etype with
-			| TEnum(en,pl)
-			| TFun(_,TEnum(en,pl)) ->
-				let ef = match ec.eexpr with
-					| TField (_,FEnum (_,f)) -> f
-					| _ -> error ("Expected constructor for enum " ^ (s_type_path en.e_path)) p
-				in
-				let monos = List.map (fun _ -> mk_mono()) ef.ef_params in
-				let tl,r = match apply_params en.e_types pl (apply_params ef.ef_params monos ef.ef_type) with
-					| TFun(args,r) ->
-						unify ctx r t p;
-						List.map (fun (n,_,t) -> t) args,r
-					| _ -> error "Arguments expected" p
-				in
-				let rec loop2 i el tl = match el,tl with
-					| (EConst(Ident "_"),pany) :: [], t :: tl ->
-						let pat = mk_pat PAny t_dynamic pany in
-						(ExtList.List.make ((List.length tl) + 1) pat)
-					| e :: el, t :: tl ->
-						let pat = loop pctx e t in
-						pat :: loop2 (i + 1) el tl
-					| e :: _, [] ->
-						error "Too many arguments" (pos e);
-					| [],_ :: _ ->
-						error "Not enough arguments" p;
-					| [],[] ->
-						[]
-				in
-				let el = loop2 0 el tl in
-				List.iter2 (fun m (_,t) -> match follow m with TMono _ -> Type.unify m t | _ -> ()) monos ef.ef_params;
-				mk_con_pat (CEnum(en,ef)) el r p
-			| _ -> perror p)
-		| EConst(Ident "_") ->
-			begin match get_tuple_types t with
-			| Some tl ->
-				let pl = List.map (fun (_,_,t) -> mk_any t p) tl in
-				{
-					p_def = PTuple (Array.of_list pl);
-					p_pos = p;
-					p_type = t_dynamic;
-				}
-			| None ->
-				mk_any t p
-			end
-		| EConst(Ident s) ->
-			begin try
-				let ec = match follow t with
-					| TEnum(en,pl) ->
-						let ef = try
-							PMap.find s en.e_constrs
-						with Not_found when not (is_lower_ident s) ->
-							error (string_error s en.e_names ("Expected constructor for enum " ^ (s_type_path en.e_path))) p
-						in
-						(match ef.ef_type with
-							| TFun (args,_) ->
-								let msg = Printf.sprintf "Enum constructor %s.%s requires parameters %s"
-									(s_type_path en.e_path)
-									ef.ef_name
-									(String.concat ", " (List.map (fun (n,_,t) -> n ^ ":" ^ (s_type t)) args))
-								in
-								error msg p
-							| _ -> ());
-						let et = mk (TTypeExpr (TEnumDecl en)) (TAnon { a_fields = PMap.empty; a_status = ref (EnumStatics en) }) p in
-						mk (TField (et,FEnum (en,ef))) (apply_params en.e_types pl ef.ef_type) p
-					| _ ->
-						let old = ctx.untyped in
-						ctx.untyped <- true;
-						let e = try type_expr ctx e (WithType t) with _ -> ctx.untyped <- old; raise Not_found in
-						ctx.untyped <- old;
-						e
-				in
-				let ec = match Optimizer.make_constant_expression ctx ~concat_strings:true ec with Some e -> e | None -> ec in
-				(match ec.eexpr with
-					| TField (_,FEnum (en,ef)) ->
-						begin try unify_raise ctx ec.etype t ec.epos with Error (Unify _,_) -> raise Not_found end;
-						begin try
-							unify_enum_field en (List.map (fun _ -> mk_mono()) en.e_types) ef t;
-						with Unify_error l ->
-							error (error_msg (Unify l)) p
-						end;
-						mk_con_pat (CEnum(en,ef)) [] t p
-                    | TConst c ->
-                    	begin try unify_raise ctx ec.etype t ec.epos with Error (Unify _,_) -> raise Not_found end;
-                        unify ctx ec.etype t p;
-                        mk_con_pat (CConst c) [] t p
-					| TTypeExpr mt ->
-						let tcl = Typeload.load_instance ctx {tname="Class";tpackage=[];tsub=None;tparams=[]} p true in
-						let t2 = match tcl with TAbstract(a,_) -> TAbstract(a,[mk_mono()]) | _ -> assert false in
-						mk_con_pat (CType mt) [] t2 p
-					| _ ->
-						raise Not_found);
-			with Not_found ->
-				if not (is_lower_ident s) && s.[0] <> '`' then error "Capture variables must be lower-case" p;
-				begin match get_tuple_types t with
-					| Some _ ->
-						error "Cannot bind tuple" p
-					| None ->
-						let v = mk_var pctx s t p in
-						mk_pat (PVar (v,p)) v.v_type p
-				end
-			end
-		| (EObjectDecl fl) ->
-			let is_matchable cf = match cf.cf_kind with Method _ | Var {v_read = AccCall} -> false | _ -> true in
-			let is_valid_field_name fields n p =
-				try
-					let cf = PMap.find n fields in
-					if not (is_matchable cf) then error ("Cannot match against method or property with getter " ^ n) p;
-				with Not_found ->
-					error (unify_error_msg (print_context()) (has_extra_field t n)) p
-			in
-			begin match follow t with
-			| TAnon {a_fields = fields} ->
-				List.iter (fun (n,(_,p)) -> is_valid_field_name fields n p) fl;
-				let sl,pl,i = PMap.foldi (fun n cf (sl,pl,i) ->
-					if not (is_matchable cf) then
-						sl,pl,i
-					else
-						let pat =
-							try
-								if pctx.pc_reify && cf.cf_name = "pos" then raise Not_found;
-								loop pctx (List.assoc n fl) cf.cf_type
-							with Not_found ->
-								(mk_any cf.cf_type p)
-						in
-						(n,cf) :: sl,pat :: pl,i + 1
-				) fields ([],[],0) in
-				mk_con_pat (CFields(i,sl)) pl t p
-			| TInst(c,tl) ->
-				List.iter (fun (n,(_,p)) -> is_valid_field_name c.cl_fields n p) fl;
-				let sl,pl,i = PMap.foldi (fun n cf (sl,pl,i) ->
-					if not (is_matchable cf) then
-						sl,pl,i
-					else
-						let t = apply_params c.cl_types tl (monomorphs cf.cf_params cf.cf_type) in
-						let pat = try loop pctx (List.assoc n fl) t with Not_found -> (mk_any t p) in
-						(n,cf) :: sl,pat :: pl,i + 1
-				) c.cl_fields ([],[],0) in
-				mk_con_pat (CFields(i,sl)) pl t p
-			| _ ->
-				error ((s_type t) ^ " should be { }") p
-			end
-		| EArrayDecl [] ->
-			mk_con_pat (CArray 0) [] t p
-		| EArrayDecl el ->
-			begin match follow t with
-				| TInst({cl_path=[],"Array"},[t2]) ->
-					let pl = ExtList.List.mapi (fun i e ->
-						loop pctx e t2
-					) el in
-					mk_con_pat (CArray (List.length el)) pl t p
-				| TFun(tl,tr) when tr == fake_tuple_type ->
-					let pl = try
-						List.map2 (fun e (_,_,t) -> loop pctx e t) el tl
-					with Invalid_argument _ ->
-						error ("Invalid number of arguments: expected " ^ (string_of_int (List.length tl)) ^ ", found " ^ (string_of_int (List.length el))) p
-					in
-					{
-						p_def = PTuple (Array.of_list pl);
-						p_pos = p;
-						p_type = t_dynamic;
-					}
-				| _ ->
-					error ((s_type t) ^ " should be Array") p
-			end
-		| EBinop(OpAssign,(EConst(Ident s),p2),e1) ->
-			let v = mk_var pctx s t p in
-			let pat1 = loop pctx e1 t in
-			mk_pat (PBind((v,p),pat1)) t p2
-		| EBinop(OpOr,(EBinop(OpOr,e1,e2),p2),e3) ->
-			loop pctx (EBinop(OpOr,e1,(EBinop(OpOr,e2,e3),p2)),p) t
-		| EBinop(OpOr,e1,e2) ->
-			let old = pctx.pc_locals in
-			let rec dup t = match t with
-				| TMono r -> (match !r with
-					| None -> mk_mono()
-					| Some t -> Type.map dup t)
-				| _ -> Type.map dup t
-			in
-			let t2 = dup t in
-			let pat1 = loop pctx e1 t in
-			begin match pat1.p_def with
-				| PAny | PVar _ ->
-					ctx.com.warning "This pattern is unused" (pos e2);
-					pat1
-				| _ ->
-					let pctx2 = {
-						pc_sub_vars = Some pctx.pc_locals;
-						pc_locals = old;
-						pc_reify = pctx.pc_reify;
-					} in
-					let pat2 = loop pctx2 e2 t2 in
-					PMap.iter (fun s (_,p) -> if not (PMap.mem s pctx2.pc_locals) then verror s p) pctx.pc_locals;
-					mk_pat (POr(pat1,pat2)) pat2.p_type (punion pat1.p_pos pat2.p_pos);
-			end
-		| _ ->
-			raise (Unrecognized_pattern e)
-	in
-	let pctx = {
-		pc_locals = PMap.empty;
-		pc_sub_vars = None;
-		pc_reify = false;
-	} in
-	loop pctx e t, pctx.pc_locals
-
-let get_pattern_locals ctx e t =
-	try
-		let _,locals = to_pattern ctx e t in
-		PMap.foldi (fun n (v,_) acc -> PMap.add n v acc) locals PMap.empty
-	with Unrecognized_pattern _ ->
-		PMap.empty
-
-(* Match compilation *)
-
-let unify_con con1 con2 = match con1.c_def,con2.c_def with
-	| CExpr e1, CExpr e2 ->
-		e1 == e2
-	| CConst c1,CConst c2 ->
-		c1 = c2
-	| CEnum(e1,ef1),CEnum(e2,ef2) ->
-		e1 == e2 && ef1.ef_name = ef2.ef_name
-	| CFields (i1,fl1),CFields (i2,fl2) ->
-		(try
-			List.iter (fun (s,_) -> if not (List.mem_assoc s fl1) then raise Not_found) fl2;
-			true
-		with Not_found ->
-			false)
-	| CType mt1,CType mt2 ->
-		t_path mt1 = t_path mt2
-	| CArray a1, CArray a2 ->
-		a1 == a2
-	| _ ->
-		false
-
-let array_tl arr = Array.sub arr 1 (Array.length arr - 1)
-
-let spec mctx con pmat =
-	let a = arity con in
-	let r = DynArray.create () in
-	let add pv out =
-		DynArray.add r (pv,out)
-	in
-	let rec loop2 pv out = match pv.(0).p_def with
-		| PCon(c2,pl) when unify_con c2 con ->
-			add (Array.append (Array.of_list pl) (array_tl pv)) out
-		| PCon(c2,pl) ->
-			()
-		| PAny | PVar _->
-			add (Array.append (Array.make a (mk_any (pv.(0).p_type) (pv.(0).p_pos))) (array_tl pv)) out
- 		| POr(pat1,pat2) ->
-			let tl = array_tl pv in
-			let out2 = clone_out mctx out [pat2] pat2.p_pos in
-			loop2 (Array.append [|pat1|] tl) out;
-			loop2 (Array.append [|pat2|] tl) out2;
-		| PBind(_,pat) ->
-			loop2 (Array.append [|pat|] (array_tl pv)) out
-		| PTuple tl ->
-			loop2 tl out
-	in
-	let rec loop pmat = match pmat with
-		| (pv,out) :: pl ->
-			loop2 pv out;
-			loop pl
-		| [] ->
-			()
-	in
-	loop pmat;
-	DynArray.to_list r
-
-let default mctx pmat =
-	let r = DynArray.create () in
-	let add pv out =
-		DynArray.add r (pv,out)
-	in
-	let rec loop2 pv out = match pv.(0).p_def with
-		| PCon _ ->
-			()
-		| PAny | PVar _->
-			add (array_tl pv) out
- 		| POr(pat1,pat2) ->
-			let tl = array_tl pv in
-			let out2 = clone_out mctx out [pat2] pat2.p_pos in
-			loop2 (Array.append [|pat1|] tl) out;
-			loop2 (Array.append [|pat2|] tl) out2;
-		| PBind(_,pat) ->
-			loop2 (Array.append [|pat|] (array_tl pv)) out
-		| PTuple tl ->
-			loop2 tl out
-	in
- 	let rec loop pmat = match pmat with
-		| (pv,out) :: pl ->
-			loop2 pv out;
-			loop pl;
-		| [] ->
-			()
-	in
-	loop pmat;
-	DynArray.to_list r
-
-let pick_column pmat =
-	let rec loop i pv = if Array.length pv = 0 then -1 else match pv.(0).p_def with
-		| PVar _ | PAny ->
-			loop (i + 1) (array_tl pv)
-		| PTuple pl ->
-			loop i pl
-		| _ ->
-			i
-	in
-	loop 0 (fst (List.hd pmat))
-
-let swap_pmat_columns i pmat =
-	List.map (fun (pv,out) ->
-		let pv = match pv with [|{p_def = PTuple pt}|] -> pt | _ -> pv in
-		let tmp = pv.(i) in
-		Array.set pv i pv.(0);
-		Array.set pv 0 tmp;
-		pv,out
-	) pmat
-
-let swap_columns i (row : 'a list) : 'a list =
-	match row with
-	| rh :: rt ->
-		let rec loop count acc col = match col with
-			| [] -> acc
-			| ch :: cl when i = count ->
-				ch :: (List.rev acc) @ [rh] @ cl
-			| ch :: cl ->
-				loop (count + 1) (ch :: acc) cl
-		in
-		loop 1 [] rt
-	| _ ->
-		[]
-
-let column_sigma mctx st pmat =
-	let acc = ref [] in
-	let bindings = ref [] in
-	let unguarded = Hashtbl.create 0 in
-	let add c g =
-		if not (List.exists (fun c2 -> unify_con c2 c) !acc) then acc := c :: !acc;
-		if not g then Hashtbl.replace unguarded c.c_def true;
-	in
-	let bind_st out st v =
-		if not (List.exists (fun ((v2,p),_) -> v2.v_id == (fst v).v_id) !bindings) then bindings := (v,st) :: !bindings
-	in
-	let rec loop pmat = match pmat with
-		| (pv,out) :: pr ->
-			let rec loop2 out = function
-				| PCon (c,_) ->
-					add c (out.o_guard <> None);
-				| POr(pat1,pat2) ->
-					let out2 = clone_out mctx out [pat2] pat2.p_pos in
-					loop2 out pat1.p_def;
-					loop2 out2 pat2.p_def;
-				| PVar v ->
-					bind_st out st v;
-				| PBind(v,pat) ->
-					bind_st out st v;
-					loop2 out pat.p_def
-				| PAny ->
-					()
-				| PTuple tl ->
-					loop2 out tl.(0).p_def
-			in
-			loop2 out pv.(0).p_def;
-			loop pr
-		| [] ->
-			()
-	in
-	loop pmat;
-	List.rev_map (fun con -> con,not (Hashtbl.mem unguarded con.c_def)) !acc,!bindings
-
-let all_ctors mctx st =
-	let h = ref PMap.empty in
-	let inf = match follow st.st_type with
-	| TAbstract({a_path = [],"Bool"},_) ->
-		h := PMap.add (CConst(TBool true)) Ast.null_pos !h;
-		h := PMap.add (CConst(TBool false)) Ast.null_pos !h;
-		false
-	| TInst({cl_path=[],"String"},_)
-	| TInst({cl_path=[],"Array"},_)
-	| TAbstract _ ->
-		true
-	| TEnum(en,pl) ->
-		PMap.iter (fun _ ef ->
-			let tc = monomorphs mctx.ctx.type_params st.st_type in
-			try unify_enum_field en pl ef tc;
-				h := PMap.add (CEnum(en,ef)) ef.ef_pos !h
-			with Unify_error _ ->
-				()
-		) en.e_constrs;
-		false
-	| TInst ({cl_kind = KTypeParameter _},_) ->
-		error "Unapplied type parameter" st.st_pos
-	| TAnon a ->
-		(match !(a.a_status) with
-		| Statics c ->
-			true
-		| _ ->
-			false)
-	| TInst(_,_) ->
-		false
-	| _ ->
-		true
-	in
-	h,inf
-
-let rec collapse_pattern pl = match pl with
-	| pat :: [] ->
-		pat
-	| pat :: pl ->
-		let pat2 = collapse_pattern pl in
-		{
-			p_def = POr(pat,pat2);
-			p_pos = punion pat.p_pos pat2.p_pos;
-			p_type = pat.p_type
-		}
-	| [] ->
-		assert false
-
-let bind_remaining out pv stl =
-	let rec loop stl pv =
-		if Array.length pv = 0 then
-			[]
-		else
-			match stl,pv.(0).p_def with
-			| st :: stl,PAny ->
-				loop stl (array_tl pv)
-			| st :: stl,PVar v ->
-				(v,st) :: loop stl (array_tl pv)
-			| stl,PTuple pl ->
-				loop stl pl
-			| _ :: _,_->
-				loop stl (array_tl pv)
-			| [],_ ->
-				[]
-	in
-	loop stl pv
-
-let rec compile mctx stl pmat = match pmat with
-	| [] ->
-		(match stl with
-		| st :: stl ->
-			let all,inf = all_ctors mctx st in
-			let pl = PMap.foldi (fun cd p acc -> (mk_con_pat cd [] t_dynamic p) :: acc) !all [] in
-			begin match pl,inf with
-				| _,true
-				| [],_ ->
-					raise (Not_exhaustive(any,st))
-				| _ ->
-					raise (Not_exhaustive(collapse_pattern pl,st))
-			end
-		| _ ->
-			assert false)
-	| ([|{p_def = PTuple pt}|],out) :: pl ->
-		compile mctx stl ((pt,out) :: pl)
-	| (pv,out) :: pl ->
-		let i = pick_column pmat in
-		if i = -1 then begin
-			Hashtbl.replace mctx.used_paths out.o_id true;
-			let bl = bind_remaining out pv stl in
-			let dt = if out.o_guard = None || match pl with [] -> true | _ -> false then
-				Out(out,None)
-			else
-				Out(out,Some (compile mctx stl pl))
-			in
-			if bl = [] then dt else Bind(bl,dt)
-		end else if i > 0 then begin
-			let pmat = swap_pmat_columns i pmat in
-			let stls = swap_columns i stl in
-			compile mctx stls pmat
-		end else begin
-			let st_head,st_tail = match stl with st :: stl -> st,stl | _ -> assert false in
-			let sigma,bl = column_sigma mctx st_head pmat in
-			let all,inf = all_ctors mctx st_head in
-			let cases = List.map (fun (c,g) ->
-				if not g then all := PMap.remove c.c_def !all;
-				let spec = spec mctx c pmat in
-				let hsubs = mk_subs st_head c in
-				let subs = hsubs @ st_tail in
-				let dt = compile mctx subs spec in
-				c,dt
-			) sigma in
-			let def = default mctx pmat in
-			let dt = match def,cases with
-			| _,[{c_def = CFields _},dt] ->
-				dt
-			| _ when not inf && PMap.is_empty !all ->
-				Switch(st_head,cases)
-			| [],_ when inf && not mctx.need_val ->
-				Switch(st_head,cases)
-			| [],_ when inf ->
-				raise (Not_exhaustive(any,st_head))
-			| [],_ ->
-				let pl = PMap.foldi (fun cd p acc -> (mk_con_pat cd [] t_dynamic p) :: acc) !all [] in
-				raise (Not_exhaustive(collapse_pattern pl,st_head))
-			| def,[] ->
-				compile mctx st_tail def
-			| def,_ ->
-				let cdef = mk_con (CConst TNull) t_dynamic st_head.st_pos in
-				let cases = cases @ [cdef,compile mctx st_tail def] in
-				Switch(st_head,cases)
-			in
-			if bl = [] then dt else Bind(bl,dt)
-		end
-
-(* Conversion to typed AST *)
-
-let mk_const ctx p = function
-	| TString s -> mk (TConst (TString s)) ctx.com.basic.tstring p
-	| TInt i -> mk (TConst (TInt i)) ctx.com.basic.tint p
-	| TFloat f -> mk (TConst (TFloat f)) ctx.com.basic.tfloat p
-	| TBool b -> mk (TConst (TBool b)) ctx.com.basic.tbool p
-	| TNull -> mk (TConst TNull) (ctx.com.basic.tnull (mk_mono())) p
-	| _ -> error "Unsupported constant" p
-
-let rec st_to_unique_name ctx st = match st.st_def with
-	| SField(st,f) -> st_to_unique_name ctx st ^ "_f" ^ f
-	| SArray(st,i) -> st_to_unique_name ctx st ^ "_a" ^ (string_of_int i)
-	| SEnum(st,n,i) -> st_to_unique_name ctx st ^ "_e" ^ n ^ "_" ^ (string_of_int i)
-	| SVar v -> v.v_name
-	| STuple (st,_,_) -> st_to_unique_name ctx st
-
-let rec st_to_texpr mctx st = match st.st_def with
-	| SVar v -> mk (TLocal v) v.v_type st.st_pos
-	| SField (sts,f) ->
-		let e = st_to_texpr mctx sts in
-		let fa = try quick_field e.etype f with Not_found -> FDynamic f in
-		mk (TField(e,fa)) st.st_type st.st_pos
-	| SArray (sts,i) -> mk (TArray(st_to_texpr mctx sts,mk_const mctx.ctx st.st_pos (TInt (Int32.of_int i)))) st.st_type st.st_pos
-	| STuple (st,_,_) -> st_to_texpr mctx st
-	| SEnum _ ->
-		let n = st_to_unique_name mctx st in
-		let v = try	Hashtbl.find mctx.v_lookup n with Not_found ->
-			let v = alloc_var n st.st_type in
-			Hashtbl.add mctx.v_lookup n v;
-			v
-		in
-		mctx.ctx.locals <- PMap.add n v mctx.ctx.locals;
-		mk (TLocal v) v.v_type st.st_pos
-
-let rec st_eq st1 st2 = match st1.st_def,st2.st_def with
-	| STuple (st1,i1,_), STuple(st2,i2,_) -> i1 = i2 && st_eq st1 st2
-	| SEnum(st1,_,i1), SEnum(st2,_,i2) -> i1 = i2 && st_eq st1 st2
-	| SField(st1,f1),SField(st2,f2) -> f1 = f2 && st_eq st1 st2
-	| SArray(st1,i1),SArray(st2,i2) -> i1 = i1 && st_eq st1 st2
-	| SVar _, SVar _ -> true
-	| _ -> false
-
-let is_compatible out1 out2 =
-	out1.o_id = out2.o_id
-	&& out1.o_guard = None
-
-let replace_locals mctx out e =
-	let replace v =
-		let rec loop vl = match vl with
-			| vl :: vll -> (try snd (List.find (fun ((v2,_),st) -> v2 == v) vl) with Not_found -> loop vll)
-			| [] -> raise Not_found
-		in
-		loop mctx.eval_stack
-	in
-	let rec loop e = match e.eexpr with
-		| TLocal v ->
-			(try
-				let st = replace v in
-				unify mctx.ctx e.etype st.st_type e.epos;
-				st_to_texpr mctx st
-			with Not_found ->
-				e)
-		| _ ->
-			Type.map_expr loop e
-	in
-	let e = loop e in
-	(*      if not (Common.defined mctx.ctx.com Define.NoUnusedVarWarnings) then
-	Hashtbl.iter (fun _ (v,p) -> if (String.length v.v_name) > 0 && v.v_name.[0] <> '_' then mctx.ctx.com.warning "This variable is unused" p) all_subterms; *)
-	e
-
-let rec to_typed_ast mctx dt =
-	match dt with
-	| Goto _ ->
-		error "Not implemented yet" Ast.null_pos
-	| Out(out,dt) ->
-		replace_locals mctx out begin match out.o_guard,dt with
-			| Some eg,None ->
-				mk (TIf(eg,out.o_expr,None)) t_dynamic out.o_expr.epos
-			| Some eg,Some dt ->
-				let eelse = to_typed_ast mctx dt in
-				mk (TIf(eg,out.o_expr,Some eelse)) eelse.etype (punion out.o_expr.epos eelse.epos)
-			| _,None ->
-				out.o_expr
-			| _ -> assert false
-		end
-	| Bind (bl, dt) ->
-		List.iter (fun ((v,_),st) ->
-			let e = st_to_texpr mctx st in
-			begin match e.eexpr with
-				| TLocal v2 -> v2.v_name <- v.v_name
-				| _ -> ()
-			end;
-		) bl;
-		mctx.eval_stack <- bl :: mctx.eval_stack;
-		let e = to_typed_ast mctx dt in
-		mctx.eval_stack <- List.tl mctx.eval_stack;
-		e
-	| Switch(st,cases) ->
-		match follow st.st_type with
-		| TEnum(en,pl) | TAbstract({a_this = TEnum(en,_)},pl) -> to_enum_switch mctx en pl st cases
-		| TInst({cl_path = [],"Array"},[t]) -> to_array_switch mctx t st cases
-		| t -> to_value_switch mctx t st cases
-
-and group_cases mctx cases to_case =
-	let def = ref None in
-	let group,cases,dto = List.fold_left (fun (group,cases,dto) (con,dt) -> match con.c_def with
-		| CConst TNull ->
-			let e = to_typed_ast mctx dt in
-			def := Some e;
-			(group,cases,dto)
-		| _ -> match dto with
-			| None -> ([to_case con],cases,Some dt)
-			| Some dt2 -> match dt,dt2 with
-				| Out(out1,_),Out(out2,_) when is_compatible out1 out2 ->
-					((to_case con) :: group,cases,dto)
-				| _ ->
-					let e = to_typed_ast mctx dt2 in
-					([to_case con],(List.rev group,e) :: cases, Some dt)
-	) ([],[],None) cases in
-	let cases = List.rev (match group,dto with
-		| [],None ->
-			cases
-		| group,Some dt ->
-			let e = to_typed_ast mctx dt in
-			(List.rev group,e) :: cases
-		| _ ->
-			assert false
-	) in
-	cases,def
-
-and to_enum_switch mctx en pl st cases =
-	let eval = st_to_texpr mctx st in
-	let to_case con = match con.c_def with
-		| CEnum(en,ef) -> en,ef
-		| _ ->
-			error ("Unexpected") con.c_pos
-	in
-	let type_case group dt p =
-		let group = List.rev group in
-		let en,ef = List.hd group in
-		let save = save_locals mctx.ctx in
-		let etf = follow (monomorphs en.e_types (monomorphs ef.ef_params ef.ef_type)) in
-		(* TODO: this is horrible !!! *)
-		let capture_vars = match dt with
-			| Out(out,None) ->
-				let vl = PMap.foldi (fun k v acc -> (k,v) :: acc) (List.fold_left (fun acc vl -> List.fold_left (fun acc (v,st) -> if PMap.mem v acc then acc else PMap.add v st acc) acc vl) PMap.empty mctx.eval_stack) [] in
-				Some vl
-			| _ ->
-				None
-		in
-		let vl = match etf with
-			| TFun(args,r) ->
-				let vl = ExtList.List.mapi (fun i (_,_,t) ->
-					let st = mk_st (SEnum(st,ef.ef_name,i)) t st.st_pos in
-					let mk_e () = Some (match (st_to_texpr mctx st).eexpr with TLocal v -> v | _ -> assert false) in
-					begin match capture_vars with
-						| Some cvl ->
-							let rec check st2 = st_eq st st2 || match st2.st_def with
-								| SEnum(st,_,_) | SArray(st,_) | STuple(st,_,_) | SField(st,_) -> check st
-								| SVar _ -> false
-							in
-							let rec loop cvl = match cvl with
-								| [] -> None
-								| (_,st2) :: cvl ->
-									if check st2 then mk_e() else loop cvl
-							in
-							loop cvl
-						| _ ->
-							mk_e()
-					end
-				) args in
-				if List.exists (fun e -> e <> None) vl then (Some vl) else None
-			| _ -> None
-		in
-		let e = to_typed_ast mctx dt in
-		save();
-		(List.map (fun (_,ef) -> ef.ef_index) group),vl,e
-	in
-	let def = ref None in
-	let group,cases,dto = List.fold_left (fun (group,cases,dto) (con,dt) -> match con.c_def with
-		| CConst TNull ->
-			let e = to_typed_ast mctx dt in
-			def := Some e;
-			(group,cases,dto)
-		| _ -> match dto with
-			| None -> ([to_case con],cases,Some dt)
-			| Some dt2 -> match dt,dt2 with
-				| Out(out1,_),Out(out2,_) when is_compatible out1 out2 ->
-					((to_case con) :: group,cases,dto)
-				| _ ->
-					let g = type_case group dt2 con.c_pos in
-					([to_case con],g :: cases, Some dt)
-	) ([],[],None) cases in
-	let cases = List.rev (match group,dto with
-		| [],None ->
-			cases
-		| group,Some dt ->
-			let g = type_case group dt eval.epos in
-			g :: cases
-		| _ ->
-			assert false
-	) in
-	mk (TMatch(eval,(en,pl),cases,!def)) mctx.out_type eval.epos
-
-and to_value_switch mctx t st cases =
-	let eval = st_to_texpr mctx st in
-	let to_case con = match con.c_def with
-		| CConst c ->
-			mk_const mctx.ctx con.c_pos c
-		| CType mt ->
-			Typer.type_module_type mctx.ctx mt None con.c_pos
-		| CExpr e ->
-			e
-		| _ ->
-			error ("Unexpected "  ^ (s_con con)) con.c_pos
-	in
-	let cases,def = group_cases mctx cases to_case in
-	mk (TSwitch(eval,cases,!def)) mctx.out_type eval.epos
-
-and to_array_switch mctx t st cases =
-	let to_case con = match con.c_def with
-		| CArray i ->
-			mk_const mctx.ctx con.c_pos (TInt (Int32.of_int i))
-		| _ ->
-			error ("Unexpected "  ^ (s_con con)) con.c_pos
-	in
-	let cases,def = group_cases mctx cases to_case in
-	let eval = st_to_texpr mctx st in
-	let eval = mk (TField(eval,quick_field eval.etype "length")) mctx.ctx.com.basic.tint st.st_pos in
-	mk (TSwitch(eval,cases,!def)) mctx.out_type eval.epos
-
-(* Main *)
-
-let rec collapse_case el = match el with
-	| e :: [] ->
-		e
-	| e :: el ->
-		let e2 = collapse_case el in
-		EBinop(OpOr,e,e2),punion (pos e) (pos e2)
-	| [] ->
-		assert false
-
-let match_expr ctx e cases def with_type p =
-	let need_val,with_type,tmono = match with_type with
-		| NoValue -> false,NoValue,None
-		| WithType t | WithTypeResume t when (match follow t with TMono _ -> true | _ -> false) ->
-			(* we don't want to unify with each case individually, but instead at the end after unify_min *)
-			true,Value,Some with_type
-		| t -> true,t,None
-	in
-	(* turn default into case _ *)
-	let cases = match cases,def with
-		| [],None -> []
-		| cases,Some def ->
-			let p = match def with
-				| None -> p
-				| Some (_,p) -> p
-			in
-			cases @ [[(EConst(Ident "_")),p],None,def]
-		| _ -> cases
-	in
-	(* type subject(s) *)
-	let evals = match fst e with
-		| EArrayDecl el | EParenthesis(EArrayDecl el,_) ->
-			List.map (fun e -> type_expr ctx e Value) el
-		| _ ->
-			let e = type_expr ctx e Value in
-			begin match follow e.etype with
-			| TEnum(en,_) when PMap.is_empty en.e_constrs || Meta.has Meta.FakeEnum en.e_meta ->
-				raise Exit
-			| _ ->
-				()
-			end;
-			[e]
-	in
-	let var_inits = ref [] in
-	let a = List.length evals in
-	(* turn subjects to subterms and handle variable initialization where necessary *)
-	let stl = ExtList.List.mapi (fun i e ->
-		let rec loop e = match e.eexpr with
-			| TField (ef,s) when (match s with FEnum _ -> false | _ -> true) ->
-				mk_st (SField(loop ef,field_name s)) e.etype e.epos
-			| TParenthesis e ->
-				loop e
-			| TLocal v ->
-				mk_st (SVar v) e.etype e.epos
-			| _ ->
-				let v = gen_local ctx e.etype in
-				var_inits := (v, Some e) :: !var_inits;
-				mk_st (SVar v) e.etype e.epos
-		in
-		let st = loop e in
-		if a = 1 then st else mk_st (STuple(st,i,a)) st.st_type st.st_pos
-	) evals in
-	let tl = List.map (fun st -> st.st_type) stl in
-	(* create matcher context *)
-	let mctx = {
-		ctx = ctx;
-		stl = stl;
-		need_val = need_val;
-		v_lookup = Hashtbl.create 0;
-		outcomes = PMap.empty;
-		out_type = mk_mono();
-		toplevel_or = false;
-		used_paths = Hashtbl.create 0;
-		eval_stack = [];
-	} in
-	(* flatten cases *)
-	let cases = List.map (fun (el,eg,e) ->
-		List.iter (fun e -> match fst e with EBinop(OpOr,_,_) -> mctx.toplevel_or <- true; | _ -> ()) el;
-		collapse_case el,eg,e
-	) cases in
-	let add_pattern_locals (pat,locals) =
-		PMap.iter (fun n (v,p) -> ctx.locals <- PMap.add n v ctx.locals) locals;
-		pat
-	in
-	(* evaluate patterns *)
-	let pl = ExtList.List.mapi (fun i (ep,eg,e) ->
-		let save = save_locals ctx in
-		(* type case patterns *)
-		let pl,restore,with_type = try (match tl with
-				| [t] ->
-					(* context type parameters are turned into monomorphs until the pattern has been typed *)
-					let monos = List.map (fun _ -> mk_mono()) ctx.type_params in
-					let t = apply_params ctx.type_params monos t in
-					let pl = [add_pattern_locals (to_pattern ctx ep t)] in
-					let restore = match with_type with
-						| Value | NoValue -> []
-						| WithType _ | WithTypeResume _ ->
-							PMap.fold (fun v acc ->
-								(* apply context monomorphs to locals and replace them back after typing the case body *)
-								let t = v.v_type in
-								v.v_type <- apply_params ctx.type_params monos v.v_type;
-								(fun () -> v.v_type <- t) :: acc
-							) ctx.locals []
-					in
-					(* turn any still unknown types back into type parameters *)
-					List.iter2 (fun m (_,t) -> match follow m with TMono _ -> Type.unify m t | _ -> ()) monos ctx.type_params;
-					pl,restore,(match with_type with
-						| WithType t -> WithType (apply_params ctx.type_params monos t)
-						| WithTypeResume t -> WithTypeResume (apply_params ctx.type_params monos t)
-						| _ -> with_type);
-				| tl ->
-					let t = monomorphs ctx.type_params (tfun tl fake_tuple_type) in
-					[add_pattern_locals (to_pattern ctx ep t)],[],with_type)
-			with Unrecognized_pattern (e,p) ->
-				error "Case expression must be a constant value or a pattern, not an arbitrary expression" p
-		in
-		(* type case body *)
-		let e = match e with
-			| None -> mk (TBlock []) ctx.com.basic.tvoid (pos ep)
-			| Some e ->
-				let e = type_expr ctx e with_type in
-				match with_type with
-				| WithType t ->
-					unify ctx e.etype t e.epos;
-					Codegen.Abstract.check_cast ctx t e e.epos;
-				| WithTypeResume t ->
-					(try unify_raise ctx e.etype t e.epos with Error (Unify l,p) -> raise (Typer.WithTypeError (l,p)));
-					Codegen.Abstract.check_cast ctx t e e.epos
-				| _ -> e
-		in
-		(* type case guard *)
-		let eg = match eg with
-			| None -> None
-			| Some e ->
-				let eg = type_expr ctx e (WithType ctx.com.basic.tbool) in
-				unify ctx eg.etype ctx.com.basic.tbool eg.epos;
-				Some eg
-		in
-		List.iter (fun f -> f()) restore;
-		save();
-		let out = mk_out mctx i e eg pl (pos ep) in
-		Array.of_list pl,out
-	) cases in
-	let check_unused () =
-		let unused p =
-			display_error ctx "This pattern is unused" p;
-			let old_error = ctx.on_error in
-			ctx.on_error <- (fun ctx s p -> ctx.on_error <- old_error; raise Exit);
-	 		let check_expr e p =
-				try begin match fst e with
-						| EConst(Ident ("null" | "true" | "false")) -> ()
-						| EConst(Ident _) ->
-							ignore (type_expr ctx e Value);
-							display_error ctx "Case expression must be a constant value or a pattern, not an arbitrary expression" (pos e)
-						| _ -> ()
-				end with Exit -> ()
-			in
-			let rec loop prev cl = match cl with
-				| (_,Some _,_) :: cl -> loop prev cl
-				| ((e,p2),_,_) :: cl ->
-					if p2.pmin >= p.pmin then check_expr prev p else loop (e,p2) cl
-				| [] ->
-					check_expr prev p
-			in
-			(match cases with (e,_,_) :: cl -> loop e cl | [] -> assert false);
-			ctx.on_error <- old_error;
-		in
- 		PMap.iter (fun _ out -> if not (Hashtbl.mem mctx.used_paths out.o_id) then begin
-			if out.o_pos == p then display_error ctx "The default pattern is unused" p
-			else unused out.o_pos;
-			if mctx.toplevel_or then begin match evals with
-				| [{etype = t}] when (match follow t with TAbstract({a_path=[],"Int"},[]) -> true | _ -> false) ->
-					display_error ctx "Note: Int | Int is an or-pattern now" p;
-				| _ -> ()
-			end;
-		end) mctx.outcomes;
-	in
-	begin try
-		(* compile decision tree *)
-		let dt = compile mctx stl pl in
-		(* check for unused patterns *)
-		check_unused();
-		(* determine type of switch statement *)
-		let t = if not need_val then
-			mk_mono()
-		else match with_type with
-			| WithType t | WithTypeResume t -> t
-			| _ -> try Typer.unify_min_raise ctx (List.rev_map (fun (_,out) -> out.o_expr) (List.rev pl)) with Error (Unify l,p) -> error (error_msg (Unify l)) p
-		in
-		(* unify with expected type if necessary *)
-		begin match tmono with
-			| None -> ()
-			| Some (WithType t2) -> unify ctx t2 t p
-			| Some (WithTypeResume t2) -> (try unify_raise ctx t2 t p with Error (Unify l,p) -> raise (Typer.WithTypeError (l,p)))
-			| _ -> assert false
-		end;
-		(* generate typed AST from decision tree *)
-		let e = to_typed_ast mctx dt in
-		let e = { e with epos = p; etype = t} in
-		if !var_inits = [] then
-			e
-		else begin
-			mk (TBlock [
-				mk (TVars (List.rev !var_inits)) t_dynamic e.epos;
-				e;
-			]) t e.epos
-		end
-	with Not_exhaustive(pat,st) ->
- 		let rec s_st_r top pre st v = match st.st_def with
- 			| SVar v1 ->
- 				if not pre then v else begin try
- 					let e = match List.assoc v1 !var_inits with Some e -> e | None -> assert false in
- 					(Type.s_expr_pretty "" (Type.s_type (print_context())) e) ^ v
- 				with Not_found ->
- 					v1.v_name ^ v
- 				end
- 			| STuple(st,i,a) ->
- 				let r = a - i - 1 in
- 				Printf.sprintf "[%s]" (st_args i r (s_st_r top false st v))
- 			| SArray(st,i) ->
- 				s_st_r false true st (Printf.sprintf "[%i]%s" i (if top then " = " ^ v else v))
-  			| SField(st,f) ->
- 				s_st_r false true st (Printf.sprintf ".%s%s" f (if top then " = " ^ v else v))
- 			| SEnum(st,n,i) ->
-				let ef = match follow st.st_type with
- 					| TEnum(en,_) -> PMap.find n en.e_constrs
- 					| _ -> raise Not_found
- 				in
- 				let len = match follow ef.ef_type with TFun(args,_) -> List.length args | _ -> 0 in
-				s_st_r false false st (Printf.sprintf "%s(%s)" ef.ef_name (st_args i (len - 1 - i) v))
-		in
-		error ("Unmatched patterns: " ^ (s_st_r true false st (s_pat pat))) st.st_pos
-	end;
-;;
-match_expr_ref := match_expr;
+(*
+ * Copyright (C)2005-2013 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *)
+
+open Ast
+open Common
+open Type
+open Typecore
+
+type con_def =
+	| CEnum of tenum * tenum_field
+	| CConst of tconstant
+	| CType of module_type
+	| CArray of int
+	| CFields of int * (string * tclass_field) list
+	| CExpr of texpr
+
+and con = {
+	c_def : con_def;
+	c_type : t;
+	c_pos : pos;
+}
+
+type pvar = tvar * pos
+
+type pat_def =
+	| PAny
+	| PVar of pvar
+	| PCon of con * pat list
+	| POr of pat * pat
+	| PBind of pvar * pat
+	| PTuple of pat array
+
+and pat = {
+	p_def : pat_def;
+	p_type : t;
+	p_pos : pos;
+}
+
+type st_def =
+	| SVar of tvar
+	| SField of st * string
+	| SEnum of st * string * int
+	| SArray of st * int
+	| STuple of st * int * int
+
+and st = {
+	st_def : st_def;
+	st_type : t;
+	st_pos : pos;
+}
+
+type out = {
+	o_expr : texpr;
+	o_guard : texpr option;
+	o_pos : pos;
+	o_id : int;
+}
+
+type pat_vec = pat array * out
+type pat_matrix = pat_vec list
+
+type pattern_ctx = {
+	mutable pc_locals : (string, pvar) PMap.t;
+	mutable pc_sub_vars : (string, pvar) PMap.t option;
+	mutable pc_reify : bool;
+}
+
+type dt =
+	| Out of out * dt option
+	| Switch of st * (con * dt) list
+	| Bind of (pvar * st) list * dt
+	| Goto of int
+
+type matcher = {
+	ctx : typer;
+	stl : st list;
+	need_val : bool;
+	v_lookup : (string,tvar) Hashtbl.t;
+	mutable outcomes : (pat list,out) PMap.t;
+	mutable out_type : Type.t;
+	mutable toplevel_or : bool;
+	mutable used_paths : (int,bool) Hashtbl.t;
+	mutable eval_stack : (pvar * st) list list;
+}
+
+exception Not_exhaustive of pat * st
+exception Unrecognized_pattern of Ast.expr
+
+let arity con = match con.c_def with
+	| CEnum (_,{ef_type = TFun(args,_)}) -> List.length args
+	| CEnum _ -> 0
+	| CConst _ -> 0
+	| CType mt -> 0
+	| CArray i -> i
+	| CFields (i,_) -> i
+	| CExpr _ -> 0
+
+let mk_st def t p = {
+	st_def = def;
+	st_type = t;
+	st_pos = p;
+}
+
+let mk_out mctx id e eg pl p =
+	let out = {
+		o_expr = e;
+		o_guard = eg;
+		o_pos = p;
+		o_id = id;
+	} in
+	mctx.outcomes <- PMap.add pl out mctx.outcomes;
+	out
+
+let clone_out mctx out pl p =
+	let out = {out with o_pos = p; } in
+	out
+
+let mk_pat pdef t p = {
+	p_def = pdef;
+	p_type = t;
+	p_pos = p;
+}
+
+let mk_con cdef t p = {
+	c_def = cdef;
+	c_type = t;
+	c_pos = p;
+}
+
+let mk_con_pat cdef pl t p = {
+	p_def = PCon(mk_con cdef t p,pl);
+	p_type = t;
+	p_pos = p;
+}
+
+let mk_any t p = {
+	p_def = PAny;
+	p_type = t;
+	p_pos = p;
+}
+
+let any = mk_any t_dynamic Ast.null_pos
+
+let fake_tuple_type = TInst(mk_class null_module ([],"-Tuple") null_pos, [])
+
+let mk_subs st con =
+	let map = match follow st.st_type with
+		| TInst(c,pl) -> apply_params c.cl_types pl
+		| TEnum(en,pl) -> apply_params en.e_types pl
+		| _ -> fun t -> t
+	in
+	match con.c_def with
+	| CFields (_,fl) -> List.map (fun (s,cf) -> mk_st (SField(st,s)) (map cf.cf_type) st.st_pos) fl
+	| CEnum (en,({ef_type = TFun _} as ef)) ->
+		let pl = match follow con.c_type with TEnum(_,pl) | TAbstract({a_this = TEnum(_)},pl)-> pl | TAbstract({a_path = [],"EnumValue"},[]) -> [] | _ -> [] in
+		begin match apply_params en.e_types pl (monomorphs ef.ef_params ef.ef_type) with
+			| TFun(args,r) ->
+				ExtList.List.mapi (fun i (_,_,t) ->
+					mk_st (SEnum(st,ef.ef_name,i)) t st.st_pos
+				) args
+			| _ ->
+				assert false
+		end
+	| CArray 0 -> []
+	| CArray i ->
+		let t = match follow con.c_type with TInst({cl_path=[],"Array"},[t]) -> t | _ -> assert false in
+		ExtList.List.init i (fun i -> mk_st (SArray(st,i)) t st.st_pos)
+	| CEnum _ | CConst _ | CType _ | CExpr _ ->
+		[]
+
+let get_tuple_types t = match t with
+	| TFun(tl,tr) when tr == fake_tuple_type -> Some tl
+	| _ -> None
+
+(* Printing *)
+
+let s_type = s_type (print_context())
+
+let rec s_expr_small e = match e.eexpr with
+	| TLocal v -> v.v_name
+	| TField (e,s) -> s_expr_small e ^ "." ^ field_name s
+	| TBlock [] -> "{}"
+	| _ -> s_expr (s_type) e
+
+let s_con con = match con.c_def with
+	| CEnum(_,ef) -> ef.ef_name
+	| CConst TNull -> "_"
+	| CConst c -> s_const c
+	| CType mt -> s_type_path (t_path mt)
+	| CArray i -> "[" ^(string_of_int i) ^ "]"
+	| CFields (_,fl) -> String.concat "," (List.map (fun (s,_) -> s) fl)
+	| CExpr e -> s_expr s_type e
+
+let rec s_pat pat = match pat.p_def with
+	| PVar (v,_) -> v.v_name
+	| PCon (c,[]) -> s_con c
+	| PCon (c,pl) -> s_con c ^ "(" ^ (String.concat "," (List.map s_pat pl)) ^ ")"
+	| POr (pat1,pat2) -> s_pat pat1 ^ " | " ^ s_pat pat2
+	| PAny -> "_"
+	| PBind((v,_),pat) -> v.v_name ^ "=" ^ s_pat pat
+	| PTuple pl -> "(" ^ (String.concat " " (Array.to_list (Array.map s_pat pl))) ^ ")"
+
+let st_args l r v =
+	(if l > 0 then (String.concat "," (ExtList.List.make l "_")) ^ "," else "")
+	^ v ^
+	(if r > 0 then "," ^ (String.concat "," (ExtList.List.make r "_")) else "")
+
+let rec s_st st = (match st.st_def with
+	| SVar v -> v.v_name
+	| SEnum (st,n,i) -> s_st st ^ "." ^ n ^ "." ^ (string_of_int i)
+	| SArray (st,i) -> s_st st ^ "[" ^ (string_of_int i) ^ "]"
+	| STuple (st,i,a) -> "(" ^ (st_args i (a - i - 1) (s_st st)) ^ ")"
+	| SField (st,n) -> s_st st ^ "." ^ n)
+	(* ^ ":" ^ (s_type st.st_type) *)
+
+let rec s_pat_vec pl =
+	String.concat " " (Array.to_list (Array.map s_pat pl))
+
+let s_out out = ""
+	(* ^ s_expr_small out.o_expr *)
+
+let rec s_pat_matrix pmat =
+	String.concat "\n" (List.map (fun (pl,out) -> (s_pat_vec pl) ^ "->" ^ (s_out out)) pmat)
+
+let rec s_dt tabs tree = tabs ^ match tree with
+	| Out(out,None)->
+		s_out out;
+	| Out(out,Some dt) ->
+		"if (" ^ (s_expr_small (match out.o_guard with Some e -> e | None -> assert false)) ^ ") " ^ (s_out out) ^ " else " ^ s_dt tabs dt
+	| Switch (st, cl) ->
+		"switch(" ^ (s_st st) ^ ") { \n" ^ tabs
+		^ (String.concat ("\n" ^ tabs) (List.map (fun (c,dt) ->
+			"case " ^ (s_con c) ^ ":\n" ^ (s_dt (tabs ^ "\t") dt)
+		) cl))
+		^ "\n" ^ (if String.length tabs = 0 then "" else (String.sub tabs 0 (String.length tabs - 1))) ^ "}"
+	| Bind (bl, dt) -> "bind " ^ (String.concat "," (List.map (fun ((v,_),st) -> v.v_name ^ "(" ^ (string_of_int v.v_id) ^ ") =" ^ (s_st st)) bl)) ^ "\n" ^ (s_dt tabs dt)
+	| Goto i ->
+		"goto " ^ (string_of_int i)
+
+(* Pattern parsing *)
+
+let unify_enum_field en pl ef t =
+	let t2 = match follow ef.ef_type with
+		| TFun(_,r) -> r
+		| t2 -> t2
+	in
+	let t2 = (apply_params en.e_types pl (monomorphs ef.ef_params t2)) in
+	Type.unify t2 t
+
+let unify ctx a b p =
+	try unify_raise ctx a b p with Error (Unify l,p) -> error (error_msg (Unify l)) p
+
+let rec is_value_type = function
+	| TMono r ->
+		(match !r with None -> false | Some t -> is_value_type t)
+	| TType (t,tl) ->
+		is_value_type (apply_params t.t_types tl t.t_type)
+	| TInst({cl_path=[],"String"},[]) ->
+		true
+	| TAbstract _ ->
+		true
+	| _ ->
+		false
+
+let to_pattern ctx e t =
+	let perror p = error "Unrecognized pattern" p in
+	let verror n p = error ("Variable " ^ n ^ " must appear exactly once in each sub-pattern") p in
+	let mk_var tctx s t p =
+		let v = match tctx.pc_sub_vars with
+			| Some vmap -> fst (try PMap.find s vmap with Not_found -> verror s p)
+			| None -> alloc_var s t
+		in
+		unify ctx t v.v_type p;
+		if PMap.mem s tctx.pc_locals then verror s p;
+		tctx.pc_locals <- PMap.add s (v,p) tctx.pc_locals;
+		v
+	in
+	let rec loop pctx e t =
+		let p = pos e in
+		match fst e with
+		| EConst(Ident "null") ->
+			error "null-patterns are not allowed" p
+		| ECheckType(e, CTPath({tpackage=["haxe";"macro"]; tname="Expr"})) ->
+			let old = pctx.pc_reify in
+			pctx.pc_reify <- true;
+			let e = loop pctx e t in
+			pctx.pc_reify <- old;
+			e
+		| EParenthesis e ->
+			loop pctx e t
+		| ECast(e1,None) ->
+			loop pctx e1 t
+		| EConst((Ident ("false" | "true") | Int _ | String _ | Float _) as c) ->
+			let e = Codegen.type_constant ctx.com c p in
+			unify ctx e.etype t p;
+			let c = match e.eexpr with TConst c -> c | _ -> assert false in
+			mk_con_pat (CConst c) [] t p
+		| EField _ ->
+			let e = type_expr ctx e (WithType t) in
+			let e = match Optimizer.make_constant_expression ctx ~concat_strings:true e with Some e -> e | None -> e in
+			(match e.eexpr with
+			| TConst c -> mk_con_pat (CConst c) [] t p
+			| TTypeExpr mt -> mk_con_pat (CType mt) [] t p
+			| TField(_, FStatic(_,cf)) when is_value_type cf.cf_type ->
+				mk_con_pat (CExpr e) [] cf.cf_type p
+			| TField(_, FEnum(en,ef)) ->
+				begin try
+					unify_enum_field en (List.map (fun _ -> mk_mono()) en.e_types) ef t
+				with Unify_error l ->
+					error (error_msg (Unify l)) p
+				end;
+				mk_con_pat (CEnum(en,ef)) [] t p
+			| _ -> error "Constant expression expected" p)
+		| ECall(ec,el) ->
+			let ec = type_expr ctx ec (WithType t) in
+			(match follow ec.etype with
+			| TEnum(en,pl)
+			| TFun(_,TEnum(en,pl)) ->
+				let ef = match ec.eexpr with
+					| TField (_,FEnum (_,f)) -> f
+					| _ -> error ("Expected constructor for enum " ^ (s_type_path en.e_path)) p
+				in
+				let monos = List.map (fun _ -> mk_mono()) ef.ef_params in
+				let tl,r = match apply_params en.e_types pl (apply_params ef.ef_params monos ef.ef_type) with
+					| TFun(args,r) ->
+						unify ctx r t p;
+						List.map (fun (n,_,t) -> t) args,r
+					| _ -> error "Arguments expected" p
+				in
+				let rec loop2 i el tl = match el,tl with
+					| (EConst(Ident "_"),pany) :: [], t :: tl ->
+						let pat = mk_pat PAny t_dynamic pany in
+						(ExtList.List.make ((List.length tl) + 1) pat)
+					| e :: el, t :: tl ->
+						let pat = loop pctx e t in
+						pat :: loop2 (i + 1) el tl
+					| e :: _, [] ->
+						error "Too many arguments" (pos e);
+					| [],_ :: _ ->
+						error "Not enough arguments" p;
+					| [],[] ->
+						[]
+				in
+				let el = loop2 0 el tl in
+				List.iter2 (fun m (_,t) -> match follow m with TMono _ -> Type.unify m t | _ -> ()) monos ef.ef_params;
+				mk_con_pat (CEnum(en,ef)) el r p
+			| _ -> perror p)
+		| EConst(Ident "_") ->
+			begin match get_tuple_types t with
+			| Some tl ->
+				let pl = List.map (fun (_,_,t) -> mk_any t p) tl in
+				{
+					p_def = PTuple (Array.of_list pl);
+					p_pos = p;
+					p_type = t_dynamic;
+				}
+			| None ->
+				mk_any t p
+			end
+		| EConst(Ident s) ->
+			begin try
+				let ec = match follow t with
+					| TEnum(en,pl) ->
+						let ef = try
+							PMap.find s en.e_constrs
+						with Not_found when not (is_lower_ident s) ->
+							error (string_error s en.e_names ("Expected constructor for enum " ^ (s_type_path en.e_path))) p
+						in
+						(match ef.ef_type with
+							| TFun (args,_) ->
+								let msg = Printf.sprintf "Enum constructor %s.%s requires parameters %s"
+									(s_type_path en.e_path)
+									ef.ef_name
+									(String.concat ", " (List.map (fun (n,_,t) -> n ^ ":" ^ (s_type t)) args))
+								in
+								error msg p
+							| _ -> ());
+						let et = mk (TTypeExpr (TEnumDecl en)) (TAnon { a_fields = PMap.empty; a_status = ref (EnumStatics en) }) p in
+						mk (TField (et,FEnum (en,ef))) (apply_params en.e_types pl ef.ef_type) p
+					| _ ->
+						let old = ctx.untyped in
+						ctx.untyped <- true;
+						let e = try type_expr ctx e (WithType t) with _ -> ctx.untyped <- old; raise Not_found in
+						ctx.untyped <- old;
+						e
+				in
+				let ec = match Optimizer.make_constant_expression ctx ~concat_strings:true ec with Some e -> e | None -> ec in
+				(match ec.eexpr with
+					| TField (_,FEnum (en,ef)) ->
+						begin try unify_raise ctx ec.etype t ec.epos with Error (Unify _,_) -> raise Not_found end;
+						begin try
+							unify_enum_field en (List.map (fun _ -> mk_mono()) en.e_types) ef t;
+						with Unify_error l ->
+							error (error_msg (Unify l)) p
+						end;
+						mk_con_pat (CEnum(en,ef)) [] t p
+                    | TConst c ->
+                    	begin try unify_raise ctx ec.etype t ec.epos with Error (Unify _,_) -> raise Not_found end;
+                        unify ctx ec.etype t p;
+                        mk_con_pat (CConst c) [] t p
+					| TTypeExpr mt ->
+						let tcl = Typeload.load_instance ctx {tname="Class";tpackage=[];tsub=None;tparams=[]} p true in
+						let t2 = match tcl with TAbstract(a,_) -> TAbstract(a,[mk_mono()]) | _ -> assert false in
+						mk_con_pat (CType mt) [] t2 p
+					| _ ->
+						raise Not_found);
+			with Not_found ->
+				if not (is_lower_ident s) && s.[0] <> '`' then error "Capture variables must be lower-case" p;
+				begin match get_tuple_types t with
+					| Some _ ->
+						error "Cannot bind tuple" p
+					| None ->
+						let v = mk_var pctx s t p in
+						mk_pat (PVar (v,p)) v.v_type p
+				end
+			end
+		| (EObjectDecl fl) ->
+			let is_matchable cf = match cf.cf_kind with Method _ | Var {v_read = AccCall} -> false | _ -> true in
+			let is_valid_field_name fields n p =
+				try
+					let cf = PMap.find n fields in
+					if not (is_matchable cf) then error ("Cannot match against method or property with getter " ^ n) p;
+				with Not_found ->
+					error (unify_error_msg (print_context()) (has_extra_field t n)) p
+			in
+			begin match follow t with
+			| TAnon {a_fields = fields} ->
+				List.iter (fun (n,(_,p)) -> is_valid_field_name fields n p) fl;
+				let sl,pl,i = PMap.foldi (fun n cf (sl,pl,i) ->
+					if not (is_matchable cf) then
+						sl,pl,i
+					else
+						let pat =
+							try
+								if pctx.pc_reify && cf.cf_name = "pos" then raise Not_found;
+								loop pctx (List.assoc n fl) cf.cf_type
+							with Not_found ->
+								(mk_any cf.cf_type p)
+						in
+						(n,cf) :: sl,pat :: pl,i + 1
+				) fields ([],[],0) in
+				mk_con_pat (CFields(i,sl)) pl t p
+			| TInst(c,tl) ->
+				List.iter (fun (n,(_,p)) -> is_valid_field_name c.cl_fields n p) fl;
+				let sl,pl,i = PMap.foldi (fun n cf (sl,pl,i) ->
+					if not (is_matchable cf) then
+						sl,pl,i
+					else
+						let t = apply_params c.cl_types tl (monomorphs cf.cf_params cf.cf_type) in
+						let pat = try loop pctx (List.assoc n fl) t with Not_found -> (mk_any t p) in
+						(n,cf) :: sl,pat :: pl,i + 1
+				) c.cl_fields ([],[],0) in
+				mk_con_pat (CFields(i,sl)) pl t p
+			| _ ->
+				error ((s_type t) ^ " should be { }") p
+			end
+		| EArrayDecl [] ->
+			mk_con_pat (CArray 0) [] t p
+		| EArrayDecl el ->
+			begin match follow t with
+				| TInst({cl_path=[],"Array"},[t2]) ->
+					let pl = ExtList.List.mapi (fun i e ->
+						loop pctx e t2
+					) el in
+					mk_con_pat (CArray (List.length el)) pl t p
+				| TFun(tl,tr) when tr == fake_tuple_type ->
+					let pl = try
+						List.map2 (fun e (_,_,t) -> loop pctx e t) el tl
+					with Invalid_argument _ ->
+						error ("Invalid number of arguments: expected " ^ (string_of_int (List.length tl)) ^ ", found " ^ (string_of_int (List.length el))) p
+					in
+					{
+						p_def = PTuple (Array.of_list pl);
+						p_pos = p;
+						p_type = t_dynamic;
+					}
+				| _ ->
+					error ((s_type t) ^ " should be Array") p
+			end
+		| EBinop(OpAssign,(EConst(Ident s),p2),e1) ->
+			let v = mk_var pctx s t p in
+			let pat1 = loop pctx e1 t in
+			mk_pat (PBind((v,p),pat1)) t p2
+		| EBinop(OpOr,(EBinop(OpOr,e1,e2),p2),e3) ->
+			loop pctx (EBinop(OpOr,e1,(EBinop(OpOr,e2,e3),p2)),p) t
+		| EBinop(OpOr,e1,e2) ->
+			let old = pctx.pc_locals in
+			let rec dup t = match t with
+				| TMono r -> (match !r with
+					| None -> mk_mono()
+					| Some t -> Type.map dup t)
+				| _ -> Type.map dup t
+			in
+			let t2 = dup t in
+			let pat1 = loop pctx e1 t in
+			begin match pat1.p_def with
+				| PAny | PVar _ ->
+					ctx.com.warning "This pattern is unused" (pos e2);
+					pat1
+				| _ ->
+					let pctx2 = {
+						pc_sub_vars = Some pctx.pc_locals;
+						pc_locals = old;
+						pc_reify = pctx.pc_reify;
+					} in
+					let pat2 = loop pctx2 e2 t2 in
+					PMap.iter (fun s (_,p) -> if not (PMap.mem s pctx2.pc_locals) then verror s p) pctx.pc_locals;
+					mk_pat (POr(pat1,pat2)) pat2.p_type (punion pat1.p_pos pat2.p_pos);
+			end
+		| _ ->
+			raise (Unrecognized_pattern e)
+	in
+	let pctx = {
+		pc_locals = PMap.empty;
+		pc_sub_vars = None;
+		pc_reify = false;
+	} in
+	loop pctx e t, pctx.pc_locals
+
+let get_pattern_locals ctx e t =
+	try
+		let _,locals = to_pattern ctx e t in
+		PMap.foldi (fun n (v,_) acc -> PMap.add n v acc) locals PMap.empty
+	with Unrecognized_pattern _ ->
+		PMap.empty
+
+(* Match compilation *)
+
+let unify_con con1 con2 = match con1.c_def,con2.c_def with
+	| CExpr e1, CExpr e2 ->
+		e1 == e2
+	| CConst c1,CConst c2 ->
+		c1 = c2
+	| CEnum(e1,ef1),CEnum(e2,ef2) ->
+		e1 == e2 && ef1.ef_name = ef2.ef_name
+	| CFields (i1,fl1),CFields (i2,fl2) ->
+		(try
+			List.iter (fun (s,_) -> if not (List.mem_assoc s fl1) then raise Not_found) fl2;
+			true
+		with Not_found ->
+			false)
+	| CType mt1,CType mt2 ->
+		t_path mt1 = t_path mt2
+	| CArray a1, CArray a2 ->
+		a1 == a2
+	| _ ->
+		false
+
+let array_tl arr = Array.sub arr 1 (Array.length arr - 1)
+
+let spec mctx con pmat =
+	let a = arity con in
+	let r = DynArray.create () in
+	let add pv out =
+		DynArray.add r (pv,out)
+	in
+	let rec loop2 pv out = match pv.(0).p_def with
+		| PCon(c2,pl) when unify_con c2 con ->
+			add (Array.append (Array.of_list pl) (array_tl pv)) out
+		| PCon(c2,pl) ->
+			()
+		| PAny | PVar _->
+			add (Array.append (Array.make a (mk_any (pv.(0).p_type) (pv.(0).p_pos))) (array_tl pv)) out
+ 		| POr(pat1,pat2) ->
+			let tl = array_tl pv in
+			let out2 = clone_out mctx out [pat2] pat2.p_pos in
+			loop2 (Array.append [|pat1|] tl) out;
+			loop2 (Array.append [|pat2|] tl) out2;
+		| PBind(_,pat) ->
+			loop2 (Array.append [|pat|] (array_tl pv)) out
+		| PTuple tl ->
+			loop2 tl out
+	in
+	let rec loop pmat = match pmat with
+		| (pv,out) :: pl ->
+			loop2 pv out;
+			loop pl
+		| [] ->
+			()
+	in
+	loop pmat;
+	DynArray.to_list r
+
+let default mctx pmat =
+	let r = DynArray.create () in
+	let add pv out =
+		DynArray.add r (pv,out)
+	in
+	let rec loop2 pv out = match pv.(0).p_def with
+		| PCon _ ->
+			()
+		| PAny | PVar _->
+			add (array_tl pv) out
+ 		| POr(pat1,pat2) ->
+			let tl = array_tl pv in
+			let out2 = clone_out mctx out [pat2] pat2.p_pos in
+			loop2 (Array.append [|pat1|] tl) out;
+			loop2 (Array.append [|pat2|] tl) out2;
+		| PBind(_,pat) ->
+			loop2 (Array.append [|pat|] (array_tl pv)) out
+		| PTuple tl ->
+			loop2 tl out
+	in
+ 	let rec loop pmat = match pmat with
+		| (pv,out) :: pl ->
+			loop2 pv out;
+			loop pl;
+		| [] ->
+			()
+	in
+	loop pmat;
+	DynArray.to_list r
+
+let pick_column pmat =
+	let rec loop i pv = if Array.length pv = 0 then -1 else match pv.(0).p_def with
+		| PVar _ | PAny ->
+			loop (i + 1) (array_tl pv)
+		| PTuple pl ->
+			loop i pl
+		| _ ->
+			i
+	in
+	loop 0 (fst (List.hd pmat))
+
+let swap_pmat_columns i pmat =
+	List.map (fun (pv,out) ->
+		let pv = match pv with [|{p_def = PTuple pt}|] -> pt | _ -> pv in
+		let tmp = pv.(i) in
+		Array.set pv i pv.(0);
+		Array.set pv 0 tmp;
+		pv,out
+	) pmat
+
+let swap_columns i (row : 'a list) : 'a list =
+	match row with
+	| rh :: rt ->
+		let rec loop count acc col = match col with
+			| [] -> acc
+			| ch :: cl when i = count ->
+				ch :: (List.rev acc) @ [rh] @ cl
+			| ch :: cl ->
+				loop (count + 1) (ch :: acc) cl
+		in
+		loop 1 [] rt
+	| _ ->
+		[]
+
+let column_sigma mctx st pmat =
+	let acc = ref [] in
+	let bindings = ref [] in
+	let unguarded = Hashtbl.create 0 in
+	let add c g =
+		if not (List.exists (fun c2 -> unify_con c2 c) !acc) then acc := c :: !acc;
+		if not g then Hashtbl.replace unguarded c.c_def true;
+	in
+	let bind_st out st v =
+		if not (List.exists (fun ((v2,p),_) -> v2.v_id == (fst v).v_id) !bindings) then bindings := (v,st) :: !bindings
+	in
+	let rec loop pmat = match pmat with
+		| (pv,out) :: pr ->
+			let rec loop2 out = function
+				| PCon (c,_) ->
+					add c (out.o_guard <> None);
+				| POr(pat1,pat2) ->
+					let out2 = clone_out mctx out [pat2] pat2.p_pos in
+					loop2 out pat1.p_def;
+					loop2 out2 pat2.p_def;
+				| PVar v ->
+					bind_st out st v;
+				| PBind(v,pat) ->
+					bind_st out st v;
+					loop2 out pat.p_def
+				| PAny ->
+					()
+				| PTuple tl ->
+					loop2 out tl.(0).p_def
+			in
+			loop2 out pv.(0).p_def;
+			loop pr
+		| [] ->
+			()
+	in
+	loop pmat;
+	List.rev_map (fun con -> con,not (Hashtbl.mem unguarded con.c_def)) !acc,!bindings
+
+let all_ctors mctx st =
+	let h = ref PMap.empty in
+	let inf = match follow st.st_type with
+	| TAbstract({a_path = [],"Bool"},_) ->
+		h := PMap.add (CConst(TBool true)) Ast.null_pos !h;
+		h := PMap.add (CConst(TBool false)) Ast.null_pos !h;
+		false
+	| TInst({cl_path=[],"String"},_)
+	| TInst({cl_path=[],"Array"},_)
+	| TAbstract _ ->
+		true
+	| TEnum(en,pl) ->
+		PMap.iter (fun _ ef ->
+			let tc = monomorphs mctx.ctx.type_params st.st_type in
+			try unify_enum_field en pl ef tc;
+				h := PMap.add (CEnum(en,ef)) ef.ef_pos !h
+			with Unify_error _ ->
+				()
+		) en.e_constrs;
+		false
+	| TInst ({cl_kind = KTypeParameter _},_) ->
+		error "Unapplied type parameter" st.st_pos
+	| TAnon a ->
+		(match !(a.a_status) with
+		| Statics c ->
+			true
+		| _ ->
+			false)
+	| TInst(_,_) ->
+		false
+	| _ ->
+		true
+	in
+	h,inf
+
+let rec collapse_pattern pl = match pl with
+	| pat :: [] ->
+		pat
+	| pat :: pl ->
+		let pat2 = collapse_pattern pl in
+		{
+			p_def = POr(pat,pat2);
+			p_pos = punion pat.p_pos pat2.p_pos;
+			p_type = pat.p_type
+		}
+	| [] ->
+		assert false
+
+let bind_remaining out pv stl =
+	let rec loop stl pv =
+		if Array.length pv = 0 then
+			[]
+		else
+			match stl,pv.(0).p_def with
+			| st :: stl,PAny ->
+				loop stl (array_tl pv)
+			| st :: stl,PVar v ->
+				(v,st) :: loop stl (array_tl pv)
+			| stl,PTuple pl ->
+				loop stl pl
+			| _ :: _,_->
+				loop stl (array_tl pv)
+			| [],_ ->
+				[]
+	in
+	loop stl pv
+
+let rec compile mctx stl pmat = match pmat with
+	| [] ->
+		(match stl with
+		| st :: stl ->
+			let all,inf = all_ctors mctx st in
+			let pl = PMap.foldi (fun cd p acc -> (mk_con_pat cd [] t_dynamic p) :: acc) !all [] in
+			begin match pl,inf with
+				| _,true
+				| [],_ ->
+					raise (Not_exhaustive(any,st))
+				| _ ->
+					raise (Not_exhaustive(collapse_pattern pl,st))
+			end
+		| _ ->
+			assert false)
+	| ([|{p_def = PTuple pt}|],out) :: pl ->
+		compile mctx stl ((pt,out) :: pl)
+	| (pv,out) :: pl ->
+		let i = pick_column pmat in
+		if i = -1 then begin
+			Hashtbl.replace mctx.used_paths out.o_id true;
+			let bl = bind_remaining out pv stl in
+			let dt = if out.o_guard = None || match pl with [] -> true | _ -> false then
+				Out(out,None)
+			else
+				Out(out,Some (compile mctx stl pl))
+			in
+			if bl = [] then dt else Bind(bl,dt)
+		end else if i > 0 then begin
+			let pmat = swap_pmat_columns i pmat in
+			let stls = swap_columns i stl in
+			compile mctx stls pmat
+		end else begin
+			let st_head,st_tail = match stl with st :: stl -> st,stl | _ -> assert false in
+			let sigma,bl = column_sigma mctx st_head pmat in
+			let all,inf = all_ctors mctx st_head in
+			let cases = List.map (fun (c,g) ->
+				if not g then all := PMap.remove c.c_def !all;
+				let spec = spec mctx c pmat in
+				let hsubs = mk_subs st_head c in
+				let subs = hsubs @ st_tail in
+				let dt = compile mctx subs spec in
+				c,dt
+			) sigma in
+			let def = default mctx pmat in
+			let dt = match def,cases with
+			| _,[{c_def = CFields _},dt] ->
+				dt
+			| _ when not inf && PMap.is_empty !all ->
+				Switch(st_head,cases)
+			| [],_ when inf && not mctx.need_val ->
+				Switch(st_head,cases)
+			| [],_ when inf ->
+				raise (Not_exhaustive(any,st_head))
+			| [],_ ->
+				let pl = PMap.foldi (fun cd p acc -> (mk_con_pat cd [] t_dynamic p) :: acc) !all [] in
+				raise (Not_exhaustive(collapse_pattern pl,st_head))
+			| def,[] ->
+				compile mctx st_tail def
+			| def,_ ->
+				let cdef = mk_con (CConst TNull) t_dynamic st_head.st_pos in
+				let cases = cases @ [cdef,compile mctx st_tail def] in
+				Switch(st_head,cases)
+			in
+			if bl = [] then dt else Bind(bl,dt)
+		end
+
+(* Conversion to typed AST *)
+
+let mk_const ctx p = function
+	| TString s -> mk (TConst (TString s)) ctx.com.basic.tstring p
+	| TInt i -> mk (TConst (TInt i)) ctx.com.basic.tint p
+	| TFloat f -> mk (TConst (TFloat f)) ctx.com.basic.tfloat p
+	| TBool b -> mk (TConst (TBool b)) ctx.com.basic.tbool p
+	| TNull -> mk (TConst TNull) (ctx.com.basic.tnull (mk_mono())) p
+	| _ -> error "Unsupported constant" p
+
+let rec st_to_unique_name ctx st = match st.st_def with
+	| SField(st,f) -> st_to_unique_name ctx st ^ "_f" ^ f
+	| SArray(st,i) -> st_to_unique_name ctx st ^ "_a" ^ (string_of_int i)
+	| SEnum(st,n,i) -> st_to_unique_name ctx st ^ "_e" ^ n ^ "_" ^ (string_of_int i)
+	| SVar v -> v.v_name
+	| STuple (st,_,_) -> st_to_unique_name ctx st
+
+let rec st_to_texpr mctx st = match st.st_def with
+	| SVar v -> mk (TLocal v) v.v_type st.st_pos
+	| SField (sts,f) ->
+		let e = st_to_texpr mctx sts in
+		let fa = try quick_field e.etype f with Not_found -> FDynamic f in
+		mk (TField(e,fa)) st.st_type st.st_pos
+	| SArray (sts,i) -> mk (TArray(st_to_texpr mctx sts,mk_const mctx.ctx st.st_pos (TInt (Int32.of_int i)))) st.st_type st.st_pos
+	| STuple (st,_,_) -> st_to_texpr mctx st
+	| SEnum _ ->
+		let n = st_to_unique_name mctx st in
+		let v = try	Hashtbl.find mctx.v_lookup n with Not_found ->
+			let v = alloc_var n st.st_type in
+			Hashtbl.add mctx.v_lookup n v;
+			v
+		in
+		mctx.ctx.locals <- PMap.add n v mctx.ctx.locals;
+		mk (TLocal v) v.v_type st.st_pos
+
+let rec st_eq st1 st2 = match st1.st_def,st2.st_def with
+	| STuple (st1,i1,_), STuple(st2,i2,_) -> i1 = i2 && st_eq st1 st2
+	| SEnum(st1,_,i1), SEnum(st2,_,i2) -> i1 = i2 && st_eq st1 st2
+	| SField(st1,f1),SField(st2,f2) -> f1 = f2 && st_eq st1 st2
+	| SArray(st1,i1),SArray(st2,i2) -> i1 = i1 && st_eq st1 st2
+	| SVar _, SVar _ -> true
+	| _ -> false
+
+let is_compatible out1 out2 =
+	out1.o_id = out2.o_id
+	&& out1.o_guard = None
+
+let replace_locals mctx out e =
+	let replace v =
+		let rec loop vl = match vl with
+			| vl :: vll -> (try snd (List.find (fun ((v2,_),st) -> v2 == v) vl) with Not_found -> loop vll)
+			| [] -> raise Not_found
+		in
+		loop mctx.eval_stack
+	in
+	let rec loop e = match e.eexpr with
+		| TLocal v ->
+			(try
+				let st = replace v in
+				unify mctx.ctx e.etype st.st_type e.epos;
+				st_to_texpr mctx st
+			with Not_found ->
+				e)
+		| _ ->
+			Type.map_expr loop e
+	in
+	let e = loop e in
+	(*      if not (Common.defined mctx.ctx.com Define.NoUnusedVarWarnings) then
+	Hashtbl.iter (fun _ (v,p) -> if (String.length v.v_name) > 0 && v.v_name.[0] <> '_' then mctx.ctx.com.warning "This variable is unused" p) all_subterms; *)
+	e
+
+let rec to_typed_ast mctx dt =
+	match dt with
+	| Goto _ ->
+		error "Not implemented yet" Ast.null_pos
+	| Out(out,dt) ->
+		replace_locals mctx out begin match out.o_guard,dt with
+			| Some eg,None ->
+				mk (TIf(eg,out.o_expr,None)) t_dynamic out.o_expr.epos
+			| Some eg,Some dt ->
+				let eelse = to_typed_ast mctx dt in
+				mk (TIf(eg,out.o_expr,Some eelse)) eelse.etype (punion out.o_expr.epos eelse.epos)
+			| _,None ->
+				out.o_expr
+			| _ -> assert false
+		end
+	| Bind (bl, dt) ->
+		List.iter (fun ((v,_),st) ->
+			let e = st_to_texpr mctx st in
+			begin match e.eexpr with
+				| TLocal v2 -> v2.v_name <- v.v_name
+				| _ -> ()
+			end;
+		) bl;
+		mctx.eval_stack <- bl :: mctx.eval_stack;
+		let e = to_typed_ast mctx dt in
+		mctx.eval_stack <- List.tl mctx.eval_stack;
+		e
+	| Switch(st,cases) ->
+		match follow st.st_type with
+		| TEnum(en,pl) | TAbstract({a_this = TEnum(en,_)},pl) -> to_enum_switch mctx en pl st cases
+		| TInst({cl_path = [],"Array"},[t]) -> to_array_switch mctx t st cases
+		| t -> to_value_switch mctx t st cases
+
+and group_cases mctx cases to_case =
+	let def = ref None in
+	let group,cases,dto = List.fold_left (fun (group,cases,dto) (con,dt) -> match con.c_def with
+		| CConst TNull ->
+			let e = to_typed_ast mctx dt in
+			def := Some e;
+			(group,cases,dto)
+		| _ -> match dto with
+			| None -> ([to_case con],cases,Some dt)
+			| Some dt2 -> match dt,dt2 with
+				| Out(out1,_),Out(out2,_) when is_compatible out1 out2 ->
+					((to_case con) :: group,cases,dto)
+				| _ ->
+					let e = to_typed_ast mctx dt2 in
+					([to_case con],(List.rev group,e) :: cases, Some dt)
+	) ([],[],None) cases in
+	let cases = List.rev (match group,dto with
+		| [],None ->
+			cases
+		| group,Some dt ->
+			let e = to_typed_ast mctx dt in
+			(List.rev group,e) :: cases
+		| _ ->
+			assert false
+	) in
+	cases,def
+
+and to_enum_switch mctx en pl st cases =
+	let eval = st_to_texpr mctx st in
+	let to_case con = match con.c_def with
+		| CEnum(en,ef) -> en,ef
+		| _ ->
+			error ("Unexpected") con.c_pos
+	in
+	let type_case group dt p =
+		let group = List.rev group in
+		let en,ef = List.hd group in
+		let save = save_locals mctx.ctx in
+		let etf = follow (monomorphs en.e_types (monomorphs ef.ef_params ef.ef_type)) in
+		(* TODO: this is horrible !!! *)
+		let capture_vars = match dt with
+			| Out(out,None) ->
+				let vl = PMap.foldi (fun k v acc -> (k,v) :: acc) (List.fold_left (fun acc vl -> List.fold_left (fun acc (v,st) -> if PMap.mem v acc then acc else PMap.add v st acc) acc vl) PMap.empty mctx.eval_stack) [] in
+				Some vl
+			| _ ->
+				None
+		in
+		let vl = match etf with
+			| TFun(args,r) ->
+				let vl = ExtList.List.mapi (fun i (_,_,t) ->
+					let st = mk_st (SEnum(st,ef.ef_name,i)) t st.st_pos in
+					let mk_e () = Some (match (st_to_texpr mctx st).eexpr with TLocal v -> v | _ -> assert false) in
+					begin match capture_vars with
+						| Some cvl ->
+							let rec check st2 = st_eq st st2 || match st2.st_def with
+								| SEnum(st,_,_) | SArray(st,_) | STuple(st,_,_) | SField(st,_) -> check st
+								| SVar _ -> false
+							in
+							let rec loop cvl = match cvl with
+								| [] -> None
+								| (_,st2) :: cvl ->
+									if check st2 then mk_e() else loop cvl
+							in
+							loop cvl
+						| _ ->
+							mk_e()
+					end
+				) args in
+				if List.exists (fun e -> e <> None) vl then (Some vl) else None
+			| _ -> None
+		in
+		let e = to_typed_ast mctx dt in
+		save();
+		(List.map (fun (_,ef) -> ef.ef_index) group),vl,e
+	in
+	let def = ref None in
+	let group,cases,dto = List.fold_left (fun (group,cases,dto) (con,dt) -> match con.c_def with
+		| CConst TNull ->
+			let e = to_typed_ast mctx dt in
+			def := Some e;
+			(group,cases,dto)
+		| _ -> match dto with
+			| None -> ([to_case con],cases,Some dt)
+			| Some dt2 -> match dt,dt2 with
+				| Out(out1,_),Out(out2,_) when is_compatible out1 out2 ->
+					((to_case con) :: group,cases,dto)
+				| _ ->
+					let g = type_case group dt2 con.c_pos in
+					([to_case con],g :: cases, Some dt)
+	) ([],[],None) cases in
+	let cases = List.rev (match group,dto with
+		| [],None ->
+			cases
+		| group,Some dt ->
+			let g = type_case group dt eval.epos in
+			g :: cases
+		| _ ->
+			assert false
+	) in
+	mk (TMatch(eval,(en,pl),cases,!def)) mctx.out_type eval.epos
+
+and to_value_switch mctx t st cases =
+	let eval = st_to_texpr mctx st in
+	let to_case con = match con.c_def with
+		| CConst c ->
+			mk_const mctx.ctx con.c_pos c
+		| CType mt ->
+			Typer.type_module_type mctx.ctx mt None con.c_pos
+		| CExpr e ->
+			e
+		| _ ->
+			error ("Unexpected "  ^ (s_con con)) con.c_pos
+	in
+	let cases,def = group_cases mctx cases to_case in
+	mk (TSwitch(eval,cases,!def)) mctx.out_type eval.epos
+
+and to_array_switch mctx t st cases =
+	let to_case con = match con.c_def with
+		| CArray i ->
+			mk_const mctx.ctx con.c_pos (TInt (Int32.of_int i))
+		| _ ->
+			error ("Unexpected "  ^ (s_con con)) con.c_pos
+	in
+	let cases,def = group_cases mctx cases to_case in
+	let eval = st_to_texpr mctx st in
+	let eval = mk (TField(eval,quick_field eval.etype "length")) mctx.ctx.com.basic.tint st.st_pos in
+	mk (TSwitch(eval,cases,!def)) mctx.out_type eval.epos
+
+(* Main *)
+
+let rec collapse_case el = match el with
+	| e :: [] ->
+		e
+	| e :: el ->
+		let e2 = collapse_case el in
+		EBinop(OpOr,e,e2),punion (pos e) (pos e2)
+	| [] ->
+		assert false
+
+let match_expr ctx e cases def with_type p =
+	let need_val,with_type,tmono = match with_type with
+		| NoValue -> false,NoValue,None
+		| WithType t | WithTypeResume t when (match follow t with TMono _ -> true | _ -> false) ->
+			(* we don't want to unify with each case individually, but instead at the end after unify_min *)
+			true,Value,Some with_type
+		| t -> true,t,None
+	in
+	(* turn default into case _ *)
+	let cases = match cases,def with
+		| [],None -> []
+		| cases,Some def ->
+			let p = match def with
+				| None -> p
+				| Some (_,p) -> p
+			in
+			cases @ [[(EConst(Ident "_")),p],None,def]
+		| _ -> cases
+	in
+	(* type subject(s) *)
+	let evals = match fst e with
+		| EArrayDecl el | EParenthesis(EArrayDecl el,_) ->
+			List.map (fun e -> type_expr ctx e Value) el
+		| _ ->
+			let e = type_expr ctx e Value in
+			begin match follow e.etype with
+			| TEnum(en,_) when PMap.is_empty en.e_constrs || Meta.has Meta.FakeEnum en.e_meta ->
+				raise Exit
+			| _ ->
+				()
+			end;
+			[e]
+	in
+	let var_inits = ref [] in
+	let a = List.length evals in
+	(* turn subjects to subterms and handle variable initialization where necessary *)
+	let stl = ExtList.List.mapi (fun i e ->
+		let rec loop e = match e.eexpr with
+			| TField (ef,s) when (match s with FEnum _ -> false | _ -> true) ->
+				mk_st (SField(loop ef,field_name s)) e.etype e.epos
+			| TParenthesis e ->
+				loop e
+			| TLocal v ->
+				mk_st (SVar v) e.etype e.epos
+			| _ ->
+				let v = gen_local ctx e.etype in
+				var_inits := (v, Some e) :: !var_inits;
+				mk_st (SVar v) e.etype e.epos
+		in
+		let st = loop e in
+		if a = 1 then st else mk_st (STuple(st,i,a)) st.st_type st.st_pos
+	) evals in
+	let tl = List.map (fun st -> st.st_type) stl in
+	(* create matcher context *)
+	let mctx = {
+		ctx = ctx;
+		stl = stl;
+		need_val = need_val;
+		v_lookup = Hashtbl.create 0;
+		outcomes = PMap.empty;
+		out_type = mk_mono();
+		toplevel_or = false;
+		used_paths = Hashtbl.create 0;
+		eval_stack = [];
+	} in
+	(* flatten cases *)
+	let cases = List.map (fun (el,eg,e) ->
+		List.iter (fun e -> match fst e with EBinop(OpOr,_,_) -> mctx.toplevel_or <- true; | _ -> ()) el;
+		collapse_case el,eg,e
+	) cases in
+	let add_pattern_locals (pat,locals) =
+		PMap.iter (fun n (v,p) -> ctx.locals <- PMap.add n v ctx.locals) locals;
+		pat
+	in
+	(* evaluate patterns *)
+	let pl = ExtList.List.mapi (fun i (ep,eg,e) ->
+		let save = save_locals ctx in
+		(* type case patterns *)
+		let pl,restore,with_type = try (match tl with
+				| [t] ->
+					(* context type parameters are turned into monomorphs until the pattern has been typed *)
+					let monos = List.map (fun _ -> mk_mono()) ctx.type_params in
+					let t = apply_params ctx.type_params monos t in
+					let pl = [add_pattern_locals (to_pattern ctx ep t)] in
+					let restore = match with_type with
+						| Value | NoValue -> []
+						| WithType _ | WithTypeResume _ ->
+							PMap.fold (fun v acc ->
+								(* apply context monomorphs to locals and replace them back after typing the case body *)
+								let t = v.v_type in
+								v.v_type <- apply_params ctx.type_params monos v.v_type;
+								(fun () -> v.v_type <- t) :: acc
+							) ctx.locals []
+					in
+					(* turn any still unknown types back into type parameters *)
+					List.iter2 (fun m (_,t) -> match follow m with TMono _ -> Type.unify m t | _ -> ()) monos ctx.type_params;
+					pl,restore,(match with_type with
+						| WithType t -> WithType (apply_params ctx.type_params monos t)
+						| WithTypeResume t -> WithTypeResume (apply_params ctx.type_params monos t)
+						| _ -> with_type);
+				| tl ->
+					let t = monomorphs ctx.type_params (tfun tl fake_tuple_type) in
+					[add_pattern_locals (to_pattern ctx ep t)],[],with_type)
+			with Unrecognized_pattern (e,p) ->
+				error "Case expression must be a constant value or a pattern, not an arbitrary expression" p
+		in
+		(* type case body *)
+		let e = match e with
+			| None -> mk (TBlock []) ctx.com.basic.tvoid (pos ep)
+			| Some e ->
+				let e = type_expr ctx e with_type in
+				match with_type with
+				| WithType t ->
+					unify ctx e.etype t e.epos;
+					Codegen.Abstract.check_cast ctx t e e.epos;
+				| WithTypeResume t ->
+					(try unify_raise ctx e.etype t e.epos with Error (Unify l,p) -> raise (Typer.WithTypeError (l,p)));
+					Codegen.Abstract.check_cast ctx t e e.epos
+				| _ -> e
+		in
+		(* type case guard *)
+		let eg = match eg with
+			| None -> None
+			| Some e ->
+				let eg = type_expr ctx e (WithType ctx.com.basic.tbool) in
+				unify ctx eg.etype ctx.com.basic.tbool eg.epos;
+				Some eg
+		in
+		List.iter (fun f -> f()) restore;
+		save();
+		let out = mk_out mctx i e eg pl (pos ep) in
+		Array.of_list pl,out
+	) cases in
+	let check_unused () =
+		let unused p =
+			display_error ctx "This pattern is unused" p;
+			let old_error = ctx.on_error in
+			ctx.on_error <- (fun ctx s p -> ctx.on_error <- old_error; raise Exit);
+	 		let check_expr e p =
+				try begin match fst e with
+						| EConst(Ident ("null" | "true" | "false")) -> ()
+						| EConst(Ident _) ->
+							ignore (type_expr ctx e Value);
+							display_error ctx "Case expression must be a constant value or a pattern, not an arbitrary expression" (pos e)
+						| _ -> ()
+				end with Exit -> ()
+			in
+			let rec loop prev cl = match cl with
+				| (_,Some _,_) :: cl -> loop prev cl
+				| ((e,p2),_,_) :: cl ->
+					if p2.pmin >= p.pmin then check_expr prev p else loop (e,p2) cl
+				| [] ->
+					check_expr prev p
+			in
+			(match cases with (e,_,_) :: cl -> loop e cl | [] -> assert false);
+			ctx.on_error <- old_error;
+		in
+ 		PMap.iter (fun _ out -> if not (Hashtbl.mem mctx.used_paths out.o_id) then begin
+			if out.o_pos == p then display_error ctx "The default pattern is unused" p
+			else unused out.o_pos;
+			if mctx.toplevel_or then begin match evals with
+				| [{etype = t}] when (match follow t with TAbstract({a_path=[],"Int"},[]) -> true | _ -> false) ->
+					display_error ctx "Note: Int | Int is an or-pattern now" p;
+				| _ -> ()
+			end;
+		end) mctx.outcomes;
+	in
+	begin try
+		(* compile decision tree *)
+		let dt = compile mctx stl pl in
+		(* check for unused patterns *)
+		check_unused();
+		(* determine type of switch statement *)
+		let t = if not need_val then
+			mk_mono()
+		else match with_type with
+			| WithType t | WithTypeResume t -> t
+			| _ -> try Typer.unify_min_raise ctx (List.rev_map (fun (_,out) -> out.o_expr) (List.rev pl)) with Error (Unify l,p) -> error (error_msg (Unify l)) p
+		in
+		(* unify with expected type if necessary *)
+		begin match tmono with
+			| None -> ()
+			| Some (WithType t2) -> unify ctx t2 t p
+			| Some (WithTypeResume t2) -> (try unify_raise ctx t2 t p with Error (Unify l,p) -> raise (Typer.WithTypeError (l,p)))
+			| _ -> assert false
+		end;
+		(* generate typed AST from decision tree *)
+		let e = to_typed_ast mctx dt in
+		let e = { e with epos = p; etype = t} in
+		if !var_inits = [] then
+			e
+		else begin
+			mk (TBlock [
+				mk (TVars (List.rev !var_inits)) t_dynamic e.epos;
+				e;
+			]) t e.epos
+		end
+	with Not_exhaustive(pat,st) ->
+ 		let rec s_st_r top pre st v = match st.st_def with
+ 			| SVar v1 ->
+ 				if not pre then v else begin try
+ 					let e = match List.assoc v1 !var_inits with Some e -> e | None -> assert false in
+ 					(Type.s_expr_pretty "" (Type.s_type (print_context())) e) ^ v
+ 				with Not_found ->
+ 					v1.v_name ^ v
+ 				end
+ 			| STuple(st,i,a) ->
+ 				let r = a - i - 1 in
+ 				Printf.sprintf "[%s]" (st_args i r (s_st_r top false st v))
+ 			| SArray(st,i) ->
+ 				s_st_r false true st (Printf.sprintf "[%i]%s" i (if top then " = " ^ v else v))
+  			| SField(st,f) ->
+ 				s_st_r false true st (Printf.sprintf ".%s%s" f (if top then " = " ^ v else v))
+ 			| SEnum(st,n,i) ->
+				let ef = match follow st.st_type with
+ 					| TEnum(en,_) -> PMap.find n en.e_constrs
+ 					| _ -> raise Not_found
+ 				in
+ 				let len = match follow ef.ef_type with TFun(args,_) -> List.length args | _ -> 0 in
+				s_st_r false false st (Printf.sprintf "%s(%s)" ef.ef_name (st_args i (len - 1 - i) v))
+		in
+		error ("Unmatched patterns: " ^ (s_st_r true false st (s_pat pat))) st.st_pos
+	end;
+;;
+match_expr_ref := match_expr;
 get_pattern_locals_ref := get_pattern_locals

+ 175 - 175
std/Map.hx

@@ -1,176 +1,176 @@
-/*
- * Copyright (C)2005-2013 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-import haxe.ds.StringMap;
-import haxe.ds.IntMap;
-import haxe.ds.HashMap;
-import haxe.ds.ObjectMap;
-import haxe.ds.WeakMap;
-import haxe.ds.EnumValueMap;
-
- /**
-	Map allows key to value mapping for arbitrary value types, and many key
-	types.
-		
-	This is a multi-type abstract, it is instantiated as one of its
-	specialization types depending on its type parameters.
-	
-	A Map can be instantiated without explicit type parameters. Type inference
-	will then determine the type parameters from the usage.
-	
-	Maps can also be created with [key1 => value1, key2 => value2] syntax.
-	
-	Map is an abstract type, it is not available at runtime.
-**/
-@:multiType
-abstract Map<K,V>(IMap<K,V> ) {
-	
-	/**
-		Creates a new Map.
-		
-		This becomes a constructor call to one of the specialization types in
-		the output. The rules for that are as follows:
-		
-		1. if K is a String, haxe.ds.StringMap is used
-		2. if K is an Int, haxe.ds.IntMap is used
-		3. if K is an enum, haxe.ds.EnumValueMap is used
-		4. if K is any other class or structure, haxe.ds.ObjectMap is used
-		5. if K is any other type, it causes a compile-time error
-			
-		(Cpp) Map does not use weak keys on ObjectMap by default.
-	**/
-	public function new();
-
-	/**
-		Maps [key] to [value].
-		
-		If [key] already has a mapping, the previous value disappears.
-		
-		If [key] is null, the result is unspecified.
-	**/
-	public inline function set(key:K, value:V) this.set(key, value);
-	
-	/**
-		Returns the current mapping of [key].
-		
-		If no such mapping exists, null is returned.
-		
-		Note that a check like map.get(key) == null can hold for two reasons:
-		
-		1. the map has no mapping for [key]
-		2. the map has a mapping with a value of null
-		
-		If it is important to distinguish these cases, exists() should be used.
-		
-		If [key] is null, the result is unspecified.
-	**/
-	@:arrayAccess public inline function get(key:K) return this.get(key);
-	
-	/**
-		Returns true if [key] has a mapping, false otherwise.
-		
-		If [key] is null, the result is unspecified.
-	**/
-	public inline function exists(key:K) return this.exists(key);
-	
-	/**
-		Removes the mapping of [key] and returns true if such a mapping existed,
-		false otherwise.
-		
-		If [key] is null, the result is unspecified.
-	**/
-	public inline function remove(key:K) return this.remove(key);
-	
-	/**
-		Returns an Iterator over the keys of [this] Map.
-		
-		The order of keys is undefined.
-	**/
-	public inline function keys():Iterator<K> {
-		return this.keys();
-	}
-	
-	/**
-		Returns an Iterator over the values of [this] Map.
-		
-		The order of values is undefined.
-	**/
-	public inline function iterator():Iterator<V> {
-		return this.iterator();
-	}
-	
-	/**
-		Returns a String representation of [this] Map.
-		
-		The exact representation depends on the platform and key-type.
-	**/
-	public inline function toString():String {
-		return this.toString();
-	}
-	
-	@:arrayAccess @:noCompletion public inline function arrayWrite(k:K, v:V):V {
-		this.set(k, v);
-		return v;
-	}
-	
-	@:to static inline function toStringMap(t:IMap<String,V>):StringMap<V> {
-		return new StringMap<V>();
-	}
-
-	@:to static inline function toIntMap(t:IMap<Int,V>):IntMap<V> {
-		return new IntMap<V>();
-	}
-	
-	@:to static inline function toEnumValueMapMap<K:EnumValue>(t:IMap<K,V>):EnumValueMap<K,V> {
-		return new EnumValueMap<K, V>();
-	}
-
-	@:to static inline function toObjectMap<K:{ }>(t:IMap<K,V>):ObjectMap<K,V> {
-		return new ObjectMap<K, V>();
-	}
-	
-	@:from static inline function fromStringMap<V>(map:StringMap<V>):Map< String, V > {
-		return map;
-	}
-	
-	@:from static inline function fromIntMap<V>(map:IntMap<V>):Map< Int, V > {
-		return map;
-	}
-
-	@:from static inline function fromObjectMap<K:{ }, V>(map:ObjectMap<K,V>):Map<K,V> {
-		return map;
-	}
-}
-
-interface IMap<K,V> {
-	public function get(k:K):Null<V>;
-	public function set(k:K, v:V):Void;
-	public function exists(k:K):Bool;
-	public function remove(k:K):Bool;
-	public function keys():Iterator<K>;
-	public function iterator():Iterator<V>;
-	public function toString():String;
-}
-
-private typedef Hashable = {
-	function hashCode():Int;
+/*
+ * Copyright (C)2005-2013 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+import haxe.ds.StringMap;
+import haxe.ds.IntMap;
+import haxe.ds.HashMap;
+import haxe.ds.ObjectMap;
+import haxe.ds.WeakMap;
+import haxe.ds.EnumValueMap;
+
+ /**
+	Map allows key to value mapping for arbitrary value types, and many key
+	types.
+		
+	This is a multi-type abstract, it is instantiated as one of its
+	specialization types depending on its type parameters.
+	
+	A Map can be instantiated without explicit type parameters. Type inference
+	will then determine the type parameters from the usage.
+	
+	Maps can also be created with [key1 => value1, key2 => value2] syntax.
+	
+	Map is an abstract type, it is not available at runtime.
+**/
+@:multiType
+abstract Map<K,V>(IMap<K,V> ) {
+	
+	/**
+		Creates a new Map.
+		
+		This becomes a constructor call to one of the specialization types in
+		the output. The rules for that are as follows:
+		
+		1. if K is a String, haxe.ds.StringMap is used
+		2. if K is an Int, haxe.ds.IntMap is used
+		3. if K is an enum, haxe.ds.EnumValueMap is used
+		4. if K is any other class or structure, haxe.ds.ObjectMap is used
+		5. if K is any other type, it causes a compile-time error
+			
+		(Cpp) Map does not use weak keys on ObjectMap by default.
+	**/
+	public function new();
+
+	/**
+		Maps [key] to [value].
+		
+		If [key] already has a mapping, the previous value disappears.
+		
+		If [key] is null, the result is unspecified.
+	**/
+	public inline function set(key:K, value:V) this.set(key, value);
+	
+	/**
+		Returns the current mapping of [key].
+		
+		If no such mapping exists, null is returned.
+		
+		Note that a check like map.get(key) == null can hold for two reasons:
+		
+		1. the map has no mapping for [key]
+		2. the map has a mapping with a value of null
+		
+		If it is important to distinguish these cases, exists() should be used.
+		
+		If [key] is null, the result is unspecified.
+	**/
+	@:arrayAccess public inline function get(key:K) return this.get(key);
+	
+	/**
+		Returns true if [key] has a mapping, false otherwise.
+		
+		If [key] is null, the result is unspecified.
+	**/
+	public inline function exists(key:K) return this.exists(key);
+	
+	/**
+		Removes the mapping of [key] and returns true if such a mapping existed,
+		false otherwise.
+		
+		If [key] is null, the result is unspecified.
+	**/
+	public inline function remove(key:K) return this.remove(key);
+	
+	/**
+		Returns an Iterator over the keys of [this] Map.
+		
+		The order of keys is undefined.
+	**/
+	public inline function keys():Iterator<K> {
+		return this.keys();
+	}
+	
+	/**
+		Returns an Iterator over the values of [this] Map.
+		
+		The order of values is undefined.
+	**/
+	public inline function iterator():Iterator<V> {
+		return this.iterator();
+	}
+	
+	/**
+		Returns a String representation of [this] Map.
+		
+		The exact representation depends on the platform and key-type.
+	**/
+	public inline function toString():String {
+		return this.toString();
+	}
+	
+	@:arrayAccess @:noCompletion public inline function arrayWrite(k:K, v:V):V {
+		this.set(k, v);
+		return v;
+	}
+	
+	@:to static inline function toStringMap(t:IMap<String,V>):StringMap<V> {
+		return new StringMap<V>();
+	}
+
+	@:to static inline function toIntMap(t:IMap<Int,V>):IntMap<V> {
+		return new IntMap<V>();
+	}
+	
+	@:to static inline function toEnumValueMapMap<K:EnumValue>(t:IMap<K,V>):EnumValueMap<K,V> {
+		return new EnumValueMap<K, V>();
+	}
+
+	@:to static inline function toObjectMap<K:{ }>(t:IMap<K,V>):ObjectMap<K,V> {
+		return new ObjectMap<K, V>();
+	}
+	
+	@:from static inline function fromStringMap<V>(map:StringMap<V>):Map< String, V > {
+		return map;
+	}
+	
+	@:from static inline function fromIntMap<V>(map:IntMap<V>):Map< Int, V > {
+		return map;
+	}
+
+	@:from static inline function fromObjectMap<K:{ }, V>(map:ObjectMap<K,V>):Map<K,V> {
+		return map;
+	}
+}
+
+interface IMap<K,V> {
+	public function get(k:K):Null<V>;
+	public function set(k:K, v:V):Void;
+	public function exists(k:K):Bool;
+	public function remove(k:K):Bool;
+	public function keys():Iterator<K>;
+	public function iterator():Iterator<V>;
+	public function toString():String;
+}
+
+private typedef Hashable = {
+	function hashCode():Int;
 }

+ 131 - 131
std/Sys.hx

@@ -1,132 +1,132 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-/**
-	This class gives you access to many base functionalities of system platforms. Looks in [sys] sub packages for more system APIs.
-**/
-@:require(sys)
-extern class Sys {
-
-	/**
-		Print any value on the standard output.
-	**/
-	static function print( v : Dynamic ) : Void;
-
-	/**
-		Print any value on the standard output, followed by a newline
-	**/
-	static function println( v : Dynamic ) : Void;
-
-	/**
-		Returns all the arguments that were passed by the commandline.
-	**/
-	static function args() : Array<String>;
-
-	/**
-		Returns the value of the given environment variable.
-	**/
-	static function getEnv( s : String ) : String;
-
-	/**
-		Set the value of the given environment variable.
-	**/
-	static function putEnv( s : String, v : String ) : Void;
-
-	/**
-		Returns the whole environement variables.
-	**/
-	static function environment() : haxe.ds.StringMap<String>;
-
-	/**
-		Suspend the current execution for the given time (in seconds).
-	**/
-	static function sleep( seconds : Float ) : Void;
-
-	/**
-		Change the current time locale, which will affect [DateTools.format] date formating.
-		Returns true if the locale was successfully changed
-	**/
-	static function setTimeLocale( loc : String ) : Bool;
-
-	/**
-		Get the current working directory (usually the one in which the program was started)
-	**/
-	static function getCwd() : String;
-
-	/**
-		Change the current working directory.
-	**/
-	static function setCwd( s : String ) : Void;
-
-	/**
-		Returns the name of the system you are running on. For instance :
-			"Windows", "Linux", "BSD" and "Mac" depending on your desktop OS.
-	**/
-	static function systemName() : String;
-
-	/**
-		Run the given command with the list of arguments. The command output will be printed on the same output as the current process.
-		The current process will block until the command terminates and it will return the command result (0 if there was no error).
-		Read the [sys.io.Process] api for a more complete way to start background processes.
-	**/
-	static function command( cmd : String, ?args : Array<String> ) : Int;
-
-	/**
-		Exit the current process with the given error code.
-	**/
-	static function exit( code : Int ) : Void;
-
-	/**
-		Gives the most precise timestamp value (in seconds).
-	**/
-	static function time() : Float;
-
-	/**
-		Gives the most precise timestamp value (in seconds) but only account for the actual time spent running on the CPU for the current thread/process.
-	**/
-	static function cpuTime() : Float;
-
-	/**
-		Returns the path to the current executable that we are running.
-	**/
-	static function executablePath() : String;
-
-	/**
-		Read a single input character from the standard input (without blocking) and returns it. Setting [echo] to true will also display it on the output.
-	**/
-	static function getChar( echo : Bool ) : Int;
-
-	/**
-		Returns the process standard input, from which you can read what user enters. Usually it will block until the user send a full input line. See [getChar] for an alternative.
-	**/
-	static function stdin() : haxe.io.Input;
-
-	/**
-		Returns the process standard output on which you can write.
-	**/
-	static function stdout() : haxe.io.Output;
-
-	/**
-		Returns the process standard error on which you can write.
-	**/
-	static function stderr() : haxe.io.Output;
-
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+/**
+	This class gives you access to many base functionalities of system platforms. Looks in [sys] sub packages for more system APIs.
+**/
+@:require(sys)
+extern class Sys {
+
+	/**
+		Print any value on the standard output.
+	**/
+	static function print( v : Dynamic ) : Void;
+
+	/**
+		Print any value on the standard output, followed by a newline
+	**/
+	static function println( v : Dynamic ) : Void;
+
+	/**
+		Returns all the arguments that were passed by the commandline.
+	**/
+	static function args() : Array<String>;
+
+	/**
+		Returns the value of the given environment variable.
+	**/
+	static function getEnv( s : String ) : String;
+
+	/**
+		Set the value of the given environment variable.
+	**/
+	static function putEnv( s : String, v : String ) : Void;
+
+	/**
+		Returns the whole environement variables.
+	**/
+	static function environment() : haxe.ds.StringMap<String>;
+
+	/**
+		Suspend the current execution for the given time (in seconds).
+	**/
+	static function sleep( seconds : Float ) : Void;
+
+	/**
+		Change the current time locale, which will affect [DateTools.format] date formating.
+		Returns true if the locale was successfully changed
+	**/
+	static function setTimeLocale( loc : String ) : Bool;
+
+	/**
+		Get the current working directory (usually the one in which the program was started)
+	**/
+	static function getCwd() : String;
+
+	/**
+		Change the current working directory.
+	**/
+	static function setCwd( s : String ) : Void;
+
+	/**
+		Returns the name of the system you are running on. For instance :
+			"Windows", "Linux", "BSD" and "Mac" depending on your desktop OS.
+	**/
+	static function systemName() : String;
+
+	/**
+		Run the given command with the list of arguments. The command output will be printed on the same output as the current process.
+		The current process will block until the command terminates and it will return the command result (0 if there was no error).
+		Read the [sys.io.Process] api for a more complete way to start background processes.
+	**/
+	static function command( cmd : String, ?args : Array<String> ) : Int;
+
+	/**
+		Exit the current process with the given error code.
+	**/
+	static function exit( code : Int ) : Void;
+
+	/**
+		Gives the most precise timestamp value (in seconds).
+	**/
+	static function time() : Float;
+
+	/**
+		Gives the most precise timestamp value (in seconds) but only account for the actual time spent running on the CPU for the current thread/process.
+	**/
+	static function cpuTime() : Float;
+
+	/**
+		Returns the path to the current executable that we are running.
+	**/
+	static function executablePath() : String;
+
+	/**
+		Read a single input character from the standard input (without blocking) and returns it. Setting [echo] to true will also display it on the output.
+	**/
+	static function getChar( echo : Bool ) : Int;
+
+	/**
+		Returns the process standard input, from which you can read what user enters. Usually it will block until the user send a full input line. See [getChar] for an alternative.
+	**/
+	static function stdin() : haxe.io.Input;
+
+	/**
+		Returns the process standard output on which you can write.
+	**/
+	static function stdout() : haxe.io.Output;
+
+	/**
+		Returns the process standard error on which you can write.
+	**/
+	static function stderr() : haxe.io.Output;
+
 }

+ 29 - 29
std/cpp/FastIterator.hx

@@ -1,29 +1,29 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cpp;
-
-extern class FastIterator<T>
-{
-	public function hasNext():Bool;
-	public function next():T;
-}
-
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cpp;
+
+extern class FastIterator<T>
+{
+	public function hasNext():Bool;
+	public function next():T;
+}
+

+ 47 - 47
std/cpp/_std/StringBuf.hx

@@ -1,47 +1,47 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-@:coreApi
-class StringBuf {
-
-	private var b : Array<String>;
-
-	public function new() : Void {
-		b = new Array();
-	}
-
-	public function add( x : Dynamic ) : Void {
-		b.push(x);
-	}
-
-	public inline function addSub( s : String, pos : Int, ?len : Int ) : Void {
-		b.push(s.substr(pos,len));
-	}
-
-	public inline function addChar( c : Int ) : Void untyped {
-		b.push(String.fromCharCode(c));
-	}
-
-	public inline function toString() : String {
-		return b.join("");
-	}
-
-}
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+@:coreApi
+class StringBuf {
+
+	private var b : Array<String>;
+
+	public function new() : Void {
+		b = new Array();
+	}
+
+	public function add( x : Dynamic ) : Void {
+		b.push(x);
+	}
+
+	public inline function addSub( s : String, pos : Int, ?len : Int ) : Void {
+		b.push(s.substr(pos,len));
+	}
+
+	public inline function addChar( c : Int ) : Void untyped {
+		b.push(String.fromCharCode(c));
+	}
+
+	public inline function toString() : String {
+		return b.join("");
+	}
+
+}

+ 152 - 152
std/cpp/_std/Sys.hx

@@ -1,153 +1,153 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-@:coreApi class Sys {
-
-	public static function print( v : Dynamic ) : Void {
-		untyped __global__.__hxcpp_print(v);
-	}
-
-	public static function println( v : Dynamic ) : Void {
-		print(v);
-		print("\n");
-	}
-
-	public static function stdin() : haxe.io.Input {
-		return untyped new sys.io.FileInput(file_stdin());
-	}
-
-	public static function stdout() : haxe.io.Output {
-		return untyped new sys.io.FileOutput(file_stdout());
-	}
-
-	public static function stderr() : haxe.io.Output {
-		return untyped new sys.io.FileOutput(file_stderr());
-	}
-
-	public static function getChar( echo : Bool ) : Int {
-		return getch(echo);
-	}
-
-	public static function args() : Array<String> untyped {
-		return __global__.__get_args();
-	}
-
-	public static function getEnv( s : String ):String {
-		var v = get_env(s);
-		if( v == null )
-			return null;
-		return v;
-	}
-
-	public static function putEnv( s : String, v : String ) : Void {
-		put_env(s,v);
-	}
-
-	public static function sleep( seconds : Float ) : Void {
-		_sleep(seconds);
-	}
-
-	public static function setTimeLocale( loc : String ) : Bool {
-		return set_time_locale(loc);
-	}
-
-	public static function getCwd() : String {
-		return new String(get_cwd());
-	}
-
-	public static function setCwd( s : String ) : Void {
-		set_cwd(s);
-	}
-
-	public static function systemName() : String {
-		return sys_string();
-	}
-
-	static function escapeArgument( arg : String ) : String {
-		var ok = true;
-		for( i in 0...arg.length )
-			switch( arg.charCodeAt(i) ) {
-			case 32, 34: // [space] "
-				ok = false;
-			case 0, 13, 10: // [eof] [cr] [lf]
-				arg = arg.substr(0,i);
-			}
-		if( ok )
-			return arg;
-		return '"'+arg.split('"').join('\\"')+'"';
-	}
-
-	public static function command( cmd : String, ?args : Array<String> ) : Int {
-		if( args != null ) {
-			cmd = escapeArgument(cmd);
-			for( a in args )
-				cmd += " "+escapeArgument(a);
-		}
-		return sys_command(cmd);
-	}
-
-	public static function exit( code : Int ) : Void {
-		sys_exit(code);
-	}
-
-	public static function time() : Float {
-		return sys_time();
-	}
-
-	public static function cpuTime() : Float {
-		return sys_cpu_time();
-	}
-
-	public static function executablePath() : String {
-		return new String(sys_exe_path());
-	}
-
-	public static function environment() : haxe.ds.StringMap<String> {
-		var vars:Array<String> = sys_env();
-		var result = new haxe.ds.StringMap<String>();
-		var i = 0;
-		while(i<vars.length) {
-			result.set( vars[i], vars[i+1] );
-			i+=2;
-		}
-		return result;
-	}
-
-	private static var get_env = cpp.Lib.load("std","get_env",1);
-	private static var put_env = cpp.Lib.load("std","put_env",2);
-	private static var _sleep = cpp.Lib.load("std","sys_sleep",1);
-	private static var set_time_locale = cpp.Lib.load("std","set_time_locale",1);
-	private static var get_cwd = cpp.Lib.load("std","get_cwd",0);
-	private static var set_cwd = cpp.Lib.load("std","set_cwd",1);
-	private static var sys_string = cpp.Lib.load("std","sys_string",0);
-	private static var sys_command = cpp.Lib.load("std","sys_command",1);
-	private static var sys_exit = cpp.Lib.load("std","sys_exit",1);
-	private static var sys_time = cpp.Lib.load("std","sys_time",0);
-	private static var sys_cpu_time = cpp.Lib.load("std","sys_cpu_time",0);
-	private static var sys_exe_path = cpp.Lib.load("std","sys_exe_path",0);
-	private static var sys_env = cpp.Lib.load("std","sys_env",0);
-
-	private static var file_stdin = cpp.Lib.load("std","file_stdin",0);
-	private static var file_stdout = cpp.Lib.load("std","file_stdout",0);
-	private static var file_stderr = cpp.Lib.load("std","file_stderr",0);
-
-	private static var getch = cpp.Lib.load("std","sys_getch",1);
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+@:coreApi class Sys {
+
+	public static function print( v : Dynamic ) : Void {
+		untyped __global__.__hxcpp_print(v);
+	}
+
+	public static function println( v : Dynamic ) : Void {
+		print(v);
+		print("\n");
+	}
+
+	public static function stdin() : haxe.io.Input {
+		return untyped new sys.io.FileInput(file_stdin());
+	}
+
+	public static function stdout() : haxe.io.Output {
+		return untyped new sys.io.FileOutput(file_stdout());
+	}
+
+	public static function stderr() : haxe.io.Output {
+		return untyped new sys.io.FileOutput(file_stderr());
+	}
+
+	public static function getChar( echo : Bool ) : Int {
+		return getch(echo);
+	}
+
+	public static function args() : Array<String> untyped {
+		return __global__.__get_args();
+	}
+
+	public static function getEnv( s : String ):String {
+		var v = get_env(s);
+		if( v == null )
+			return null;
+		return v;
+	}
+
+	public static function putEnv( s : String, v : String ) : Void {
+		put_env(s,v);
+	}
+
+	public static function sleep( seconds : Float ) : Void {
+		_sleep(seconds);
+	}
+
+	public static function setTimeLocale( loc : String ) : Bool {
+		return set_time_locale(loc);
+	}
+
+	public static function getCwd() : String {
+		return new String(get_cwd());
+	}
+
+	public static function setCwd( s : String ) : Void {
+		set_cwd(s);
+	}
+
+	public static function systemName() : String {
+		return sys_string();
+	}
+
+	static function escapeArgument( arg : String ) : String {
+		var ok = true;
+		for( i in 0...arg.length )
+			switch( arg.charCodeAt(i) ) {
+			case 32, 34: // [space] "
+				ok = false;
+			case 0, 13, 10: // [eof] [cr] [lf]
+				arg = arg.substr(0,i);
+			}
+		if( ok )
+			return arg;
+		return '"'+arg.split('"').join('\\"')+'"';
+	}
+
+	public static function command( cmd : String, ?args : Array<String> ) : Int {
+		if( args != null ) {
+			cmd = escapeArgument(cmd);
+			for( a in args )
+				cmd += " "+escapeArgument(a);
+		}
+		return sys_command(cmd);
+	}
+
+	public static function exit( code : Int ) : Void {
+		sys_exit(code);
+	}
+
+	public static function time() : Float {
+		return sys_time();
+	}
+
+	public static function cpuTime() : Float {
+		return sys_cpu_time();
+	}
+
+	public static function executablePath() : String {
+		return new String(sys_exe_path());
+	}
+
+	public static function environment() : haxe.ds.StringMap<String> {
+		var vars:Array<String> = sys_env();
+		var result = new haxe.ds.StringMap<String>();
+		var i = 0;
+		while(i<vars.length) {
+			result.set( vars[i], vars[i+1] );
+			i+=2;
+		}
+		return result;
+	}
+
+	private static var get_env = cpp.Lib.load("std","get_env",1);
+	private static var put_env = cpp.Lib.load("std","put_env",2);
+	private static var _sleep = cpp.Lib.load("std","sys_sleep",1);
+	private static var set_time_locale = cpp.Lib.load("std","set_time_locale",1);
+	private static var get_cwd = cpp.Lib.load("std","get_cwd",0);
+	private static var set_cwd = cpp.Lib.load("std","set_cwd",1);
+	private static var sys_string = cpp.Lib.load("std","sys_string",0);
+	private static var sys_command = cpp.Lib.load("std","sys_command",1);
+	private static var sys_exit = cpp.Lib.load("std","sys_exit",1);
+	private static var sys_time = cpp.Lib.load("std","sys_time",0);
+	private static var sys_cpu_time = cpp.Lib.load("std","sys_cpu_time",0);
+	private static var sys_exe_path = cpp.Lib.load("std","sys_exe_path",0);
+	private static var sys_env = cpp.Lib.load("std","sys_env",0);
+
+	private static var file_stdin = cpp.Lib.load("std","file_stdin",0);
+	private static var file_stdout = cpp.Lib.load("std","file_stdout",0);
+	private static var file_stderr = cpp.Lib.load("std","file_stderr",0);
+
+	private static var getch = cpp.Lib.load("std","sys_getch",1);
 }

+ 47 - 47
std/cpp/_std/haxe/Int32.hx

@@ -1,47 +1,47 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package haxe;
-
-@:native("cpp.CppInt32__") extern class Int32 {
-	public static  function make( a : Int, b : Int ) : Int32;
-	public static  function ofInt( x : Int ) : Int32;
-	public static  function toInt( x : Int32 ) : Int;
-	public static  function add( a : Int32, b : Int32 ) : Int32;
-	public static  function sub( a : Int32, b : Int32 ) : Int32;
-	public static  function mul( a : Int32, b : Int32 ) : Int32;
-	public static  function div( a : Int32, b : Int32 ) : Int32;
-	public static  function mod( a : Int32, b : Int32 ) : Int32;
-	public static  function shl( a : Int32, b : Int ) : Int32;
-	public static  function shr( a : Int32, b : Int ) : Int32;
-	public static  function ushr( a : Int32, b : Int ) : Int32;
-	public static  function and( a : Int32, b : Int32 ) : Int32;
-	public static  function or( a : Int32, b : Int32 ) : Int32;
-	public static  function xor( a : Int32, b : Int32 ) : Int32;
-	public static  function neg( a : Int32 ) : Int32;
-	public static  function complement( a : Int32 ) : Int32;
-	public static  function compare( a : Int32, b : Int32 ) : Int;
-	public static  function isNeg( a : Int32 ) : Bool;
-	public static  function isZero( a : Int32 ) : Bool;
-	public static  function ucompare( a : Int32, b : Int32 ) : Int;
-	public static  function toNativeInt(a:Int32) : Int;
-}
-
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package haxe;
+
+@:native("cpp.CppInt32__") extern class Int32 {
+	public static  function make( a : Int, b : Int ) : Int32;
+	public static  function ofInt( x : Int ) : Int32;
+	public static  function toInt( x : Int32 ) : Int;
+	public static  function add( a : Int32, b : Int32 ) : Int32;
+	public static  function sub( a : Int32, b : Int32 ) : Int32;
+	public static  function mul( a : Int32, b : Int32 ) : Int32;
+	public static  function div( a : Int32, b : Int32 ) : Int32;
+	public static  function mod( a : Int32, b : Int32 ) : Int32;
+	public static  function shl( a : Int32, b : Int ) : Int32;
+	public static  function shr( a : Int32, b : Int ) : Int32;
+	public static  function ushr( a : Int32, b : Int ) : Int32;
+	public static  function and( a : Int32, b : Int32 ) : Int32;
+	public static  function or( a : Int32, b : Int32 ) : Int32;
+	public static  function xor( a : Int32, b : Int32 ) : Int32;
+	public static  function neg( a : Int32 ) : Int32;
+	public static  function complement( a : Int32 ) : Int32;
+	public static  function compare( a : Int32, b : Int32 ) : Int;
+	public static  function isNeg( a : Int32 ) : Bool;
+	public static  function isZero( a : Int32 ) : Bool;
+	public static  function ucompare( a : Int32, b : Int32 ) : Int;
+	public static  function toNativeInt(a:Int32) : Int;
+}
+

+ 39 - 39
std/cpp/_std/haxe/Resource.hx

@@ -1,39 +1,39 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package haxe;
-
-@:coreApi
-class Resource {
-
-	public static function listNames() : Array<String> {
-		return untyped __global__.__hxcpp_resource_names();
-	}
-	public static function getString(name:String) : String {
-		return untyped __global__.__hxcpp_resource_string(name);
-	}
-	public static function getBytes(name:String) : haxe.io.Bytes {
-		var array:haxe.io.BytesData = untyped __global__.__hxcpp_resource_bytes(name);
-		if (array==null) return null;
-		return haxe.io.Bytes.ofData(array);
-	}
-
-}
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package haxe;
+
+@:coreApi
+class Resource {
+
+	public static function listNames() : Array<String> {
+		return untyped __global__.__hxcpp_resource_names();
+	}
+	public static function getString(name:String) : String {
+		return untyped __global__.__hxcpp_resource_string(name);
+	}
+	public static function getBytes(name:String) : haxe.io.Bytes {
+		var array:haxe.io.BytesData = untyped __global__.__hxcpp_resource_bytes(name);
+		if (array==null) return null;
+		return haxe.io.Bytes.ofData(array);
+	}
+
+}

+ 76 - 76
std/cpp/_std/haxe/ds/ObjectMap.hx

@@ -1,76 +1,76 @@
-/*
- * Copyright (C)2005-2013 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package haxe.ds;
-
-@:coreApi
-class ObjectMap<K:{},V> implements Map.IMap<K,V> {
-	private var __Internal : IntMap<V>;
-	private var __KeyRefs : IntMap<K>;
-
-	public function new() : Void {
-		__Internal = new IntMap<V>();
-		__KeyRefs = new IntMap<K>();
-	}
-
-	public function set( key : K, value : V ) : Void {
-		var id = untyped __global__.__hxcpp_obj_id(key);
-		__Internal.set( id, value );
-		__KeyRefs.set( id, key );
-	}
-
-	public function get( key : K ) : Null<V> {
-		return __Internal.get( untyped __global__.__hxcpp_obj_id(key) );
-	}
-
-	public inline function exists( key : K ) : Bool {
-		return __Internal.exists( untyped __global__.__hxcpp_obj_id(key) );
-	}
-
-	public function remove( key : K ) : Bool {
-		var id = untyped __global__.__hxcpp_obj_id(key);
-		return __Internal.remove(id);
-		return __KeyRefs.remove(id);
-	}
-
-	public function keys() : Iterator<K> {
-		return __KeyRefs.iterator();
-	}
-
-	public function iterator() : Iterator<V> {
-		return __Internal.iterator();
-	}
-
-	public function toString() : String {
-		var s = new StringBuf();
-		s.add("{");
-		var it = __Internal.keys();
-		for( i in it ) {
-			s.add(Std.string(__KeyRefs.get(i)));
-			s.add(" => ");
-			s.add(Std.string(__Internal.get(i)));
-			if( it.hasNext() )
-				s.add(", ");
-		}
-		s.add("}");
-		return s.toString();
-	}
-}
+/*
+ * Copyright (C)2005-2013 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package haxe.ds;
+
+@:coreApi
+class ObjectMap<K:{},V> implements Map.IMap<K,V> {
+	private var __Internal : IntMap<V>;
+	private var __KeyRefs : IntMap<K>;
+
+	public function new() : Void {
+		__Internal = new IntMap<V>();
+		__KeyRefs = new IntMap<K>();
+	}
+
+	public function set( key : K, value : V ) : Void {
+		var id = untyped __global__.__hxcpp_obj_id(key);
+		__Internal.set( id, value );
+		__KeyRefs.set( id, key );
+	}
+
+	public function get( key : K ) : Null<V> {
+		return __Internal.get( untyped __global__.__hxcpp_obj_id(key) );
+	}
+
+	public inline function exists( key : K ) : Bool {
+		return __Internal.exists( untyped __global__.__hxcpp_obj_id(key) );
+	}
+
+	public function remove( key : K ) : Bool {
+		var id = untyped __global__.__hxcpp_obj_id(key);
+		return __Internal.remove(id);
+		return __KeyRefs.remove(id);
+	}
+
+	public function keys() : Iterator<K> {
+		return __KeyRefs.iterator();
+	}
+
+	public function iterator() : Iterator<V> {
+		return __Internal.iterator();
+	}
+
+	public function toString() : String {
+		var s = new StringBuf();
+		s.add("{");
+		var it = __Internal.keys();
+		for( i in it ) {
+			s.add(Std.string(__KeyRefs.get(i)));
+			s.add(" => ");
+			s.add(Std.string(__Internal.get(i)));
+			if( it.hasNext() )
+				s.add(", ");
+		}
+		s.add("}");
+		return s.toString();
+	}
+}

+ 29 - 29
std/cpp/rtti/FieldIntegerLookup.hx

@@ -1,29 +1,29 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cpp.rtti;
-
-/**
-	If you implement this interface, then the backend will generate code that
-	allows fast dynamic access to fields by integer id.  This should speed up the CFFI.
-**/
-interface FieldIntegerLookup {
-}
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cpp.rtti;
+
+/**
+	If you implement this interface, then the backend will generate code that
+	allows fast dynamic access to fields by integer id.  This should speed up the CFFI.
+**/
+interface FieldIntegerLookup {
+}

+ 29 - 29
std/cpp/rtti/FieldNumericIntegerLookup.hx

@@ -1,29 +1,29 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cpp.rtti;
-
-/**
-	If you implement this interface, then the backend will generate code that
-	allows fast numeric access to fields by integer id.  This should speed up the CFFI.
-**/
-interface FieldNumericIntegerLookup {
-}
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cpp.rtti;
+
+/**
+	If you implement this interface, then the backend will generate code that
+	allows fast numeric access to fields by integer id.  This should speed up the CFFI.
+**/
+interface FieldNumericIntegerLookup {
+}

+ 110 - 110
std/cpp/vm/Debugger.hx

@@ -1,110 +1,110 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cpp.vm;
-
-import haxe.CallStack;
-
-class Debugger
-{
-   public static inline var BRK_THIS      = -2;
-   public static inline var BRK_TERMINATE = -1;
-
-   public static inline var BRK_NONE  = 0;
-   public static inline var BRK_ASAP  = 1;
-   public static inline var BRK_STEP  = 2;
-   public static inline var BRK_ENTER = 3;
-   public static inline var BRK_LEAVE = 4;
-
-   public static function setHandler(inHandler:Void->Void)
-   {
-      untyped __global__.__hxcpp_dbg_set_handler(inHandler);
-   }
-
-   public static function setThread(?inDebugThread:Thread)
-   {
-      untyped __global__.__hxcpp_dbg_set_thread(inDebugThread==null?Thread.current().handle:inDebugThread.handle);
-   }
-
-
-   // Generate a handler callback ASAP
-   public static function setBreak(inMode:Int)
-   {
-      untyped __global__.__hxcpp_dbg_set_break(inMode);
-   }
-
-   public static function exit()
-   {
-      untyped __global__.__hxcpp_dbg_set_break(BRK_TERMINATE);
-   }
-   public static function breakBad()
-   {
-      untyped __global__.__hxcpp_dbg_set_break(BRK_THIS);
-   }
-
-
-
-   // Breakpoint
-   public static function addBreakpoint(inFileId:Int, inLine:Int)
-   {
-      untyped __global__.__hxcpp_breakpoints_add(inFileId, inLine);
-   }
-
-   public static function getBreakpoints() : Array<String>
-   {
-      return untyped __global__.__hxcpp_dbg_breakpoints_get();
-   }
-
-   public static function deleteBreakpoint(inI:Int)
-   {
-      untyped __global__.__hxcpp_dbg_breakpoints_delete(inI);
-   }
-
-   // Thread - todo
-   // public static function suspendAll()
-
-   // Callstack
-   public static function getStackFrames() : Array<haxe.StackItem>
-   {
-      return untyped __global__.__hxcpp_dbg_stack_frames_get();
-   }
-
-   public static function getStackVars(inFrame:Int) : Array<String>
-   {
-      return untyped __global__.__hxcpp_dbg_get_stack_vars(inFrame);
-   }
-
-   public static function getStackVar(inFrame:Int,inVar:String) : Dynamic
-   {
-      return untyped __global__.__hxcpp_dbg_get_stack_var(inFrame,inVar);
-   }
-
-   public static function setStackVar(inFrame:Int,inVar:String, inValue:Dynamic)
-   {
-      untyped __global__.__hxcpp_dbg_set_stack_var(inFrame,inVar,inValue);
-   }
-
-   public static function getFiles() : Array<String>
-   {
-      return untyped __global__.__hxcpp_dbg_get_files();
-   }
-}
-
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cpp.vm;
+
+import haxe.CallStack;
+
+class Debugger
+{
+   public static inline var BRK_THIS      = -2;
+   public static inline var BRK_TERMINATE = -1;
+
+   public static inline var BRK_NONE  = 0;
+   public static inline var BRK_ASAP  = 1;
+   public static inline var BRK_STEP  = 2;
+   public static inline var BRK_ENTER = 3;
+   public static inline var BRK_LEAVE = 4;
+
+   public static function setHandler(inHandler:Void->Void)
+   {
+      untyped __global__.__hxcpp_dbg_set_handler(inHandler);
+   }
+
+   public static function setThread(?inDebugThread:Thread)
+   {
+      untyped __global__.__hxcpp_dbg_set_thread(inDebugThread==null?Thread.current().handle:inDebugThread.handle);
+   }
+
+
+   // Generate a handler callback ASAP
+   public static function setBreak(inMode:Int)
+   {
+      untyped __global__.__hxcpp_dbg_set_break(inMode);
+   }
+
+   public static function exit()
+   {
+      untyped __global__.__hxcpp_dbg_set_break(BRK_TERMINATE);
+   }
+   public static function breakBad()
+   {
+      untyped __global__.__hxcpp_dbg_set_break(BRK_THIS);
+   }
+
+
+
+   // Breakpoint
+   public static function addBreakpoint(inFileId:Int, inLine:Int)
+   {
+      untyped __global__.__hxcpp_breakpoints_add(inFileId, inLine);
+   }
+
+   public static function getBreakpoints() : Array<String>
+   {
+      return untyped __global__.__hxcpp_dbg_breakpoints_get();
+   }
+
+   public static function deleteBreakpoint(inI:Int)
+   {
+      untyped __global__.__hxcpp_dbg_breakpoints_delete(inI);
+   }
+
+   // Thread - todo
+   // public static function suspendAll()
+
+   // Callstack
+   public static function getStackFrames() : Array<haxe.StackItem>
+   {
+      return untyped __global__.__hxcpp_dbg_stack_frames_get();
+   }
+
+   public static function getStackVars(inFrame:Int) : Array<String>
+   {
+      return untyped __global__.__hxcpp_dbg_get_stack_vars(inFrame);
+   }
+
+   public static function getStackVar(inFrame:Int,inVar:String) : Dynamic
+   {
+      return untyped __global__.__hxcpp_dbg_get_stack_var(inFrame,inVar);
+   }
+
+   public static function setStackVar(inFrame:Int,inVar:String, inValue:Dynamic)
+   {
+      untyped __global__.__hxcpp_dbg_set_stack_var(inFrame,inVar,inValue);
+   }
+
+   public static function getFiles() : Array<String>
+   {
+      return untyped __global__.__hxcpp_dbg_get_files();
+   }
+}
+

+ 61 - 61
std/cpp/zip/Compress.hx

@@ -1,61 +1,61 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cpp.zip;
- 
-class Compress {
- 
-	var s : Dynamic;
- 
-	public function new( level : Int ) {
-		s = _deflate_init(level);
-	}
- 
-	public function execute( src : haxe.io.Bytes, srcPos : Int, dst : haxe.io.Bytes, dstPos : Int ) : { done : Bool, read : Int, write : Int } {
-		return _deflate_buffer(s,src.getData(),srcPos,dst.getData(),dstPos);
-	}
- 
-	public function setFlushMode( f : Flush ) {
-		_set_flush_mode(s,Std.string(f));
-	}
- 
-	public function close() {
-		_deflate_end(s);
-	}
- 
-	public static function run( s : haxe.io.Bytes, level : Int ) : haxe.io.Bytes {
-		var c = new Compress(level);
-		c.setFlushMode(Flush.FINISH);
-		var out = haxe.io.Bytes.alloc(_deflate_bound(c.s,s.length));
-		var r = c.execute(s,0,out,0);
-		c.close();
-		if( !r.done || r.read != s.length )
-			throw "Compression failed";
-		return out.sub(0,r.write);
-	}
- 
-	static var _deflate_init = cpp.Lib.load("zlib","deflate_init",1);
-	static var _deflate_bound = cpp.Lib.load("zlib","deflate_bound",2);
-	static var _deflate_buffer = cpp.Lib.load("zlib","deflate_buffer",5);
-	static var _deflate_end = cpp.Lib.load("zlib","deflate_end",1);
-	static var _set_flush_mode = cpp.Lib.load("zlib","set_flush_mode",2);
- 
-}
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cpp.zip;
+ 
+class Compress {
+ 
+	var s : Dynamic;
+ 
+	public function new( level : Int ) {
+		s = _deflate_init(level);
+	}
+ 
+	public function execute( src : haxe.io.Bytes, srcPos : Int, dst : haxe.io.Bytes, dstPos : Int ) : { done : Bool, read : Int, write : Int } {
+		return _deflate_buffer(s,src.getData(),srcPos,dst.getData(),dstPos);
+	}
+ 
+	public function setFlushMode( f : Flush ) {
+		_set_flush_mode(s,Std.string(f));
+	}
+ 
+	public function close() {
+		_deflate_end(s);
+	}
+ 
+	public static function run( s : haxe.io.Bytes, level : Int ) : haxe.io.Bytes {
+		var c = new Compress(level);
+		c.setFlushMode(Flush.FINISH);
+		var out = haxe.io.Bytes.alloc(_deflate_bound(c.s,s.length));
+		var r = c.execute(s,0,out,0);
+		c.close();
+		if( !r.done || r.read != s.length )
+			throw "Compression failed";
+		return out.sub(0,r.write);
+	}
+ 
+	static var _deflate_init = cpp.Lib.load("zlib","deflate_init",1);
+	static var _deflate_bound = cpp.Lib.load("zlib","deflate_bound",2);
+	static var _deflate_buffer = cpp.Lib.load("zlib","deflate_buffer",5);
+	static var _deflate_end = cpp.Lib.load("zlib","deflate_end",1);
+	static var _set_flush_mode = cpp.Lib.load("zlib","set_flush_mode",2);
+ 
+}

+ 43 - 43
std/cs/Boot.hx

@@ -1,43 +1,43 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs;
-import cs.internal.Exceptions;
-import cs.internal.FieldLookup;
-import cs.internal.Function;
-import cs.internal.HxObject;
-import cs.internal.Runtime;
-import cs.internal.Iterator;
-import cs.internal.Null;
-import cs.internal.StringExt;
-import cs.StdTypes;
-import haxe.ds.StringMap;
-import Reflect;
-
-class Boot
-{
-
-	@:keep public static function init():Void
-	{
-		cs.Lib.applyCultureChanges();
-	}
-
-}
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs;
+import cs.internal.Exceptions;
+import cs.internal.FieldLookup;
+import cs.internal.Function;
+import cs.internal.HxObject;
+import cs.internal.Runtime;
+import cs.internal.Iterator;
+import cs.internal.Null;
+import cs.internal.StringExt;
+import cs.StdTypes;
+import haxe.ds.StringMap;
+import Reflect;
+
+class Boot
+{
+
+	@:keep public static function init():Void
+	{
+		cs.Lib.applyCultureChanges();
+	}
+
+}

+ 274 - 274
std/cs/Lib.hx

@@ -1,274 +1,274 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs;
-import cs.system.Type;
-
-/**
-	Platform-specific C# Library. Provides some platform-specific functions for the C# target,
-	such as conversion from haxe types to native types and vice-versa.
-**/
-class Lib
-{
-	@:keep private static var decimalSeparator:String;
-
-	/**
-		Changes the current culture settings to allow a consistent cross-target behavior.
-		Currently the only change made is in regard to the decimal separator, which is always set to "."
-	**/
-	@:functionCode('
-			System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(System.Threading.Thread.CurrentThread.CurrentCulture.Name, true);
-			decimalSeparator = ci.NumberFormat.NumberDecimalSeparator;
-            ci.NumberFormat.NumberDecimalSeparator = ".";
-            System.Threading.Thread.CurrentThread.CurrentCulture = ci;
-	')
-	@:keep public static function applyCultureChanges():Void
-	{
-
-	}
-
-	/**
-		Reverts the culture changes to the default settings.
-	**/
-	@:functionCode('
-		System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(System.Threading.Thread.CurrentThread.CurrentCulture.Name, true);
-		System.Threading.Thread.CurrentThread.CurrentCulture = ci;
-	')
-	public static function revertDefaultCulture():Void
-	{
-
-	}
-
-	/**
-		Returns a native array from the supplied Array. This native array is unsafe to be written on,
-		as it may or may not be linked to the actual Array implementation.
-
-		If equalLengthRequired is true, the result might be a copy of an array with the correct size.
-	**/
-	public static function nativeArray<T>(arr:Array<T>, equalLengthRequired:Bool):NativeArray<T>
-	{
-		var native:NativeArray<T> = untyped arr.__a;
-		var len = arr.length;
-		if (!equalLengthRequired || native.Length == len)
-		{
-			return native;
-		} else {
-			var ret = new NativeArray<T>(len);
-			cs.system.Array.Copy(native, 0, ret, 0, len);
-			return ret;
-		}
-	}
-
-	/**
-		Provides support for the "as" keyword in C#.
-		If the object is not of the supplied type "T", it will return null instead of rasing an exception.
-
-		This function will not work with Value Types (such as Int, Float, Bool...)
-	**/
-	@:functionCode('
-			throw new haxe.lang.HaxeException("This function cannot be accessed at runtime");
-	')
-	@:extern public static inline function as<T>(obj:Dynamic, cl:Class<T>):T
-	{
-		return untyped __as__(obj, cl);
-	}
-
-	/**
-		Returns a Class<> equivalent to the native System.Type type.
-
-		Currently Haxe's Class<> is equivalent to System.Type, but this is an implementation detail.
-		This may change in the future, so use this function whenever you need to perform such conversion.
-	**/
-	public static inline function fromNativeType(t:cs.system.Type):Class<Dynamic>
-	{
-		return untyped t;
-	}
-
-	/**
-		Returns a System.Type equivalent to the Haxe Class<> type.
-
-		Currently Haxe's Class<> is equivalent to System.Type, but this is an implementation detail.
-		This may change in the future, so use this function whenever you need to perform such conversion.
-	**/
-	public static inline function toNativeType(cl:Class<Dynamic>):Type
-	{
-		return untyped cl;
-	}
-
-	/**
-		Gets the native System.Type from the supplied object. Will throw an exception in case of null being passed.
-	**/
-	public static function nativeType(obj:Dynamic):Type
-	{
-		return untyped obj.GetType();
-	}
-
-	/**
-		Returns a Haxe Array of a native Array.
-		It won't copy the contents of the native array, so unless any operation triggers an array resize,
-		all changes made to the Haxe array will affect the native array argument.
-	**/
-	public static function array<T>(native:cs.NativeArray<T>):Array<T>
-	{
-		return untyped Array.ofNative(native);
-	}
-
-	/**
-		Allocates a new Haxe Array with a predetermined size
-	**/
-	public static function arrayAlloc<T>(size:Int):Array<T>
-	{
-		return untyped Array.alloc(size);
-	}
-
-	/**
-		Creates a "checked" block, which throws exceptions for overflows.
-
-		Usage:
-			cs.Lib.checked({
-				var x = 1000;
-				while(true)
-				{
-					x *= x;
-				}
-			});
-		This method only exists at compile-time, so it can't be called via reflection.
-	**/
-	@:extern public static inline function checked<V>(block:V):Void
-	{
-		untyped __checked__(block);
-	}
-
-	/**
-		Ensures that one thread does not enter a critical section of code while another thread
-		is in the critical section. If another thread attempts to enter a locked code, it
-		will wait, block, until the object is released.
-
-		This method only exists at compile-time, so it can't be called via reflection.
-	**/
-	@:extern public static inline function lock<O,V>(obj:O, block:V):Void
-	{
-		untyped __lock__(obj, block);
-	}
-
-	//Unsafe code manipulation
-	#if unsafe
-	/**
-		Marks its parameters as fixed objects inside the defined block.
-		The first variable declarations that use cs.Lib.pointerOfArray() will be the fixed definitions.
-		Usage:
-			cs.Lib.fixed({
-				var obj1 = cs.Lib.pointerOfArray(someArray);
-				var obj2 = cs.Lib.pointerOfArray(someArray2);
-				var obj3 = cs.Lib.pointerOfArray(someArray3);
-				//from now on, obj1, obj2 and obj3 are fixed
-				//we cannot change obj1, obj2 or obj3 variables like this:
-				//obj1++;
-			});
-
-		This method only exists at compile-time, so it can't be called via reflection.
-	**/
-	@:extern public static inline function fixed<V>(block:V):Void
-	{
-		untyped __fixed__(block);
-	}
-
-	/**
-		Marks the contained block as an unsafe block, meaning that it can contain unsafe code.
-		Usage:
-			cs.Lib.unsafe({
-				//unsafe code is allowed inside here
-			});
-
-		This method only exists at compile-time, so it can't be called via reflection.
-	**/
-	@:extern public static inline function unsafe<V>(block:V):Void
-	{
-		untyped __unsafe__(block);
-	}
-
-	/**
-		Gets the pointer to the address of current local. Equivalent to the "&" operator in C#
-		Usage:
-			var x:Int = 0;
-			cs.Lib.unsafe({
-				var addr = cs.Lib.addressOf(x);
-				x[0] = 42;
-			});
-			trace(x); //42
-
-		This method only exists at compile-time, so it can't be called via reflection.
-		Warning: This method will only work if a local variable is passed as an argument.
-	**/
-	@:extern public static inline function addressOf<T>(variable:T):cs.Pointer<T>
-	{
-		return untyped __addressOf__(variable);
-	}
-
-	/**
-		Gets the value of the pointer address.
-		Usage:
-			var x:Int = 0;
-			cs.Lib.unsafe({
-				var addr = cs.Lib.addressOf(x);
-				trace(cs.Lib.valueOf(addr)); //0
-				addr[0] = 42;
-				trace(cs.Lib.valueOf(addr)); //42
-			});
-			trace(x); //42
-
-		This method only exists at compile-time, so it can't be called via reflection.
-	**/
-	@:extern public static inline function valueOf<T>(pointer:cs.Pointer<T>):T
-	{
-		return untyped __valueOf__(pointer);
-	}
-
-	/**
-		Transforms a managed native array into a Pointer. Must be inside a fixed statement
-		Usage:
-			var x:cs.NativeArray<Int> = new cs.NativeArray(1);
-			cs.Lib.unsafe({
-				cs.Lib.fixed({
-					var addr = cs.Lib.pointerOfArray(x);
-					trace(cs.Lib.valueOf(addr)); //0
-					addr[0] = 42;
-					trace(cs.Lib.valueOf(addr)); //42
-				});
-			});
-			trace(x[0]); //42
-
-		This method only exists at compile-time, so it can't be called via reflection.
-	**/
-	@:extern public static inline function pointerOfArray<T>(array:cs.NativeArray<T>):cs.Pointer<T>
-	{
-		return cast array;
-	}
-
-	/**
-		Returns the byte size of the given struct. Only works with structs and basic types.
-	**/
-	@:extern public static inline function sizeof(struct:Class<Dynamic>):Int
-	{
-		return untyped __sizeof__(struct);
-	}
-	#end
-}
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs;
+import cs.system.Type;
+
+/**
+	Platform-specific C# Library. Provides some platform-specific functions for the C# target,
+	such as conversion from haxe types to native types and vice-versa.
+**/
+class Lib
+{
+	@:keep private static var decimalSeparator:String;
+
+	/**
+		Changes the current culture settings to allow a consistent cross-target behavior.
+		Currently the only change made is in regard to the decimal separator, which is always set to "."
+	**/
+	@:functionCode('
+			System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(System.Threading.Thread.CurrentThread.CurrentCulture.Name, true);
+			decimalSeparator = ci.NumberFormat.NumberDecimalSeparator;
+            ci.NumberFormat.NumberDecimalSeparator = ".";
+            System.Threading.Thread.CurrentThread.CurrentCulture = ci;
+	')
+	@:keep public static function applyCultureChanges():Void
+	{
+
+	}
+
+	/**
+		Reverts the culture changes to the default settings.
+	**/
+	@:functionCode('
+		System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(System.Threading.Thread.CurrentThread.CurrentCulture.Name, true);
+		System.Threading.Thread.CurrentThread.CurrentCulture = ci;
+	')
+	public static function revertDefaultCulture():Void
+	{
+
+	}
+
+	/**
+		Returns a native array from the supplied Array. This native array is unsafe to be written on,
+		as it may or may not be linked to the actual Array implementation.
+
+		If equalLengthRequired is true, the result might be a copy of an array with the correct size.
+	**/
+	public static function nativeArray<T>(arr:Array<T>, equalLengthRequired:Bool):NativeArray<T>
+	{
+		var native:NativeArray<T> = untyped arr.__a;
+		var len = arr.length;
+		if (!equalLengthRequired || native.Length == len)
+		{
+			return native;
+		} else {
+			var ret = new NativeArray<T>(len);
+			cs.system.Array.Copy(native, 0, ret, 0, len);
+			return ret;
+		}
+	}
+
+	/**
+		Provides support for the "as" keyword in C#.
+		If the object is not of the supplied type "T", it will return null instead of rasing an exception.
+
+		This function will not work with Value Types (such as Int, Float, Bool...)
+	**/
+	@:functionCode('
+			throw new haxe.lang.HaxeException("This function cannot be accessed at runtime");
+	')
+	@:extern public static inline function as<T>(obj:Dynamic, cl:Class<T>):T
+	{
+		return untyped __as__(obj, cl);
+	}
+
+	/**
+		Returns a Class<> equivalent to the native System.Type type.
+
+		Currently Haxe's Class<> is equivalent to System.Type, but this is an implementation detail.
+		This may change in the future, so use this function whenever you need to perform such conversion.
+	**/
+	public static inline function fromNativeType(t:cs.system.Type):Class<Dynamic>
+	{
+		return untyped t;
+	}
+
+	/**
+		Returns a System.Type equivalent to the Haxe Class<> type.
+
+		Currently Haxe's Class<> is equivalent to System.Type, but this is an implementation detail.
+		This may change in the future, so use this function whenever you need to perform such conversion.
+	**/
+	public static inline function toNativeType(cl:Class<Dynamic>):Type
+	{
+		return untyped cl;
+	}
+
+	/**
+		Gets the native System.Type from the supplied object. Will throw an exception in case of null being passed.
+	**/
+	public static function nativeType(obj:Dynamic):Type
+	{
+		return untyped obj.GetType();
+	}
+
+	/**
+		Returns a Haxe Array of a native Array.
+		It won't copy the contents of the native array, so unless any operation triggers an array resize,
+		all changes made to the Haxe array will affect the native array argument.
+	**/
+	public static function array<T>(native:cs.NativeArray<T>):Array<T>
+	{
+		return untyped Array.ofNative(native);
+	}
+
+	/**
+		Allocates a new Haxe Array with a predetermined size
+	**/
+	public static function arrayAlloc<T>(size:Int):Array<T>
+	{
+		return untyped Array.alloc(size);
+	}
+
+	/**
+		Creates a "checked" block, which throws exceptions for overflows.
+
+		Usage:
+			cs.Lib.checked({
+				var x = 1000;
+				while(true)
+				{
+					x *= x;
+				}
+			});
+		This method only exists at compile-time, so it can't be called via reflection.
+	**/
+	@:extern public static inline function checked<V>(block:V):Void
+	{
+		untyped __checked__(block);
+	}
+
+	/**
+		Ensures that one thread does not enter a critical section of code while another thread
+		is in the critical section. If another thread attempts to enter a locked code, it
+		will wait, block, until the object is released.
+
+		This method only exists at compile-time, so it can't be called via reflection.
+	**/
+	@:extern public static inline function lock<O,V>(obj:O, block:V):Void
+	{
+		untyped __lock__(obj, block);
+	}
+
+	//Unsafe code manipulation
+	#if unsafe
+	/**
+		Marks its parameters as fixed objects inside the defined block.
+		The first variable declarations that use cs.Lib.pointerOfArray() will be the fixed definitions.
+		Usage:
+			cs.Lib.fixed({
+				var obj1 = cs.Lib.pointerOfArray(someArray);
+				var obj2 = cs.Lib.pointerOfArray(someArray2);
+				var obj3 = cs.Lib.pointerOfArray(someArray3);
+				//from now on, obj1, obj2 and obj3 are fixed
+				//we cannot change obj1, obj2 or obj3 variables like this:
+				//obj1++;
+			});
+
+		This method only exists at compile-time, so it can't be called via reflection.
+	**/
+	@:extern public static inline function fixed<V>(block:V):Void
+	{
+		untyped __fixed__(block);
+	}
+
+	/**
+		Marks the contained block as an unsafe block, meaning that it can contain unsafe code.
+		Usage:
+			cs.Lib.unsafe({
+				//unsafe code is allowed inside here
+			});
+
+		This method only exists at compile-time, so it can't be called via reflection.
+	**/
+	@:extern public static inline function unsafe<V>(block:V):Void
+	{
+		untyped __unsafe__(block);
+	}
+
+	/**
+		Gets the pointer to the address of current local. Equivalent to the "&" operator in C#
+		Usage:
+			var x:Int = 0;
+			cs.Lib.unsafe({
+				var addr = cs.Lib.addressOf(x);
+				x[0] = 42;
+			});
+			trace(x); //42
+
+		This method only exists at compile-time, so it can't be called via reflection.
+		Warning: This method will only work if a local variable is passed as an argument.
+	**/
+	@:extern public static inline function addressOf<T>(variable:T):cs.Pointer<T>
+	{
+		return untyped __addressOf__(variable);
+	}
+
+	/**
+		Gets the value of the pointer address.
+		Usage:
+			var x:Int = 0;
+			cs.Lib.unsafe({
+				var addr = cs.Lib.addressOf(x);
+				trace(cs.Lib.valueOf(addr)); //0
+				addr[0] = 42;
+				trace(cs.Lib.valueOf(addr)); //42
+			});
+			trace(x); //42
+
+		This method only exists at compile-time, so it can't be called via reflection.
+	**/
+	@:extern public static inline function valueOf<T>(pointer:cs.Pointer<T>):T
+	{
+		return untyped __valueOf__(pointer);
+	}
+
+	/**
+		Transforms a managed native array into a Pointer. Must be inside a fixed statement
+		Usage:
+			var x:cs.NativeArray<Int> = new cs.NativeArray(1);
+			cs.Lib.unsafe({
+				cs.Lib.fixed({
+					var addr = cs.Lib.pointerOfArray(x);
+					trace(cs.Lib.valueOf(addr)); //0
+					addr[0] = 42;
+					trace(cs.Lib.valueOf(addr)); //42
+				});
+			});
+			trace(x[0]); //42
+
+		This method only exists at compile-time, so it can't be called via reflection.
+	**/
+	@:extern public static inline function pointerOfArray<T>(array:cs.NativeArray<T>):cs.Pointer<T>
+	{
+		return cast array;
+	}
+
+	/**
+		Returns the byte size of the given struct. Only works with structs and basic types.
+	**/
+	@:extern public static inline function sizeof(struct:Class<Dynamic>):Int
+	{
+		return untyped __sizeof__(struct);
+	}
+	#end
+}

+ 33 - 33
std/cs/NativeArray.hx

@@ -1,34 +1,34 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs;
-
-extern class NativeArray<T> extends cs.system.Array implements ArrayAccess<T>
-{
-	public var Length(default, null):Int;
-	
-	public function new(len:Int):Void;
-	
-	@:overload(function(arr:cs.system.Array, destIndex:haxe.Int64):Void {} )
-	public function CopyTo(arr:cs.system.Array, destIndex:Int):Void;
-	
-	static function Reverse(arr:cs.system.Array):Void;
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs;
+
+extern class NativeArray<T> extends cs.system.Array implements ArrayAccess<T>
+{
+	public var Length(default, null):Int;
+	
+	public function new(len:Int):Void;
+	
+	@:overload(function(arr:cs.system.Array, destIndex:haxe.Int64):Void {} )
+	public function CopyTo(arr:cs.system.Array, destIndex:Int):Void;
+	
+	static function Reverse(arr:cs.system.Array):Void;
 }

+ 29 - 29
std/cs/Out.hx

@@ -1,30 +1,30 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs;
-
-/**
-	This type represents "out" types for C# function parameters. 
-	It only has effect on function parameters, and conversion to/from the referenced type is automatic.
-	
-	Note: Using this type should be considered a bad practice unless overriding a native function is needed.
-**/
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs;
+
+/**
+	This type represents "out" types for C# function parameters. 
+	It only has effect on function parameters, and conversion to/from the referenced type is automatic.
+	
+	Note: Using this type should be considered a bad practice unless overriding a native function is needed.
+**/
 typedef Out<T> = T;

+ 53 - 53
std/cs/Pointer.hx

@@ -1,53 +1,53 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs;
-
-/**
-	This type represents pointer types for C# function parameters. It should only
-	be used inside an unsafe context (not checked by the Haxe compiler)
-
-	C# code:
-		int[] src;
-		fixed (int* pSrc = src)
-		{
-			...
-		}
-	Haxe code:
-		var pSrc:cs.Pointer<Int>;
-		cs.Lib.fixed(pSrc = cast src,
-		{
-			...
-		});
-
-**/
-#if !unsafe
-#error "You need to define 'unsafe' to be able to use unsafe code in hxcs"
-#else
-extern class Pointer<T> /*extends Int,*/ implements ArrayAccess<T>
-{
-	static function op_Addition<T>(p:Pointer<T>, i:Int):Pointer<T>;
-	public inline function add(i:Int):Pointer<T>
-	{
-		return op_Addition(this,i);
-	}
-}
-#end
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs;
+
+/**
+	This type represents pointer types for C# function parameters. It should only
+	be used inside an unsafe context (not checked by the Haxe compiler)
+
+	C# code:
+		int[] src;
+		fixed (int* pSrc = src)
+		{
+			...
+		}
+	Haxe code:
+		var pSrc:cs.Pointer<Int>;
+		cs.Lib.fixed(pSrc = cast src,
+		{
+			...
+		});
+
+**/
+#if !unsafe
+#error "You need to define 'unsafe' to be able to use unsafe code in hxcs"
+#else
+extern class Pointer<T> /*extends Int,*/ implements ArrayAccess<T>
+{
+	static function op_Addition<T>(p:Pointer<T>, i:Int):Pointer<T>;
+	public inline function add(i:Int):Pointer<T>
+	{
+		return op_Addition(this,i);
+	}
+}
+#end

+ 29 - 29
std/cs/Ref.hx

@@ -1,30 +1,30 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs;
-
-/**
-	This type represents "ref" types for C# function parameters. 
-	It only has effect on function parameters, and conversion to/from the referenced type is automatic.
-	
-	Note: Using this type should be considered a bad practice unless overriding a native function is needed.
-**/
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs;
+
+/**
+	This type represents "ref" types for C# function parameters. 
+	It only has effect on function parameters, and conversion to/from the referenced type is automatic.
+	
+	Note: Using this type should be considered a bad practice unless overriding a native function is needed.
+**/
 typedef Ref<T> = T;

+ 29 - 29
std/cs/StdTypes.hx

@@ -1,30 +1,30 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs;
-
-typedef Int8 = Int;
-typedef UInt8 = Int;
-typedef Int16 = Int;
-typedef UInt16 = Int;
-//UInt is top-level
-typedef UInt64 = haxe.Int64;
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs;
+
+typedef Int8 = Int;
+typedef UInt8 = Int;
+typedef Int16 = Int;
+typedef UInt16 = Int;
+//UInt is top-level
+typedef UInt64 = haxe.Int64;
 typedef Char16 = Int;

+ 35 - 35
std/cs/StringBuilder.hx

@@ -1,36 +1,36 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs;
-
-//FIXME this class is here due to seemingly a bug in type resolution inside _std packages.
-//Once this bug is fixed, it will be moved back to the cs.system.text package
-@:native('System.Text.StringBuilder') extern class StringBuilder 
-{
-
-	function new():Void;
-	
-	@:overload(function(char:cs.StdTypes.Char16):cs.StringBuilder {})
-	@:overload(function(str:String, startIndex:Int, len:Int):cs.StringBuilder {})
-	function Append(obj:Dynamic):StringBuilder;
-	
-	function ToString():String;
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs;
+
+//FIXME this class is here due to seemingly a bug in type resolution inside _std packages.
+//Once this bug is fixed, it will be moved back to the cs.system.text package
+@:native('System.Text.StringBuilder') extern class StringBuilder 
+{
+
+	function new():Void;
+	
+	@:overload(function(char:cs.StdTypes.Char16):cs.StringBuilder {})
+	@:overload(function(str:String, startIndex:Int, len:Int):cs.StringBuilder {})
+	function Append(obj:Dynamic):StringBuilder;
+	
+	function ToString():String;
 }

+ 180 - 180
std/cs/_std/Date.hx

@@ -1,180 +1,180 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package;
-import cs.system.DateTime;
-import haxe.Int64;
-
-@:coreApi class Date
-{
-	private var date:DateTime;
-
-	/**
-		Creates a new date object.
-	**/
-	public function new(year : Int, month : Int, day : Int, hour : Int, min : Int, sec : Int ) : Void
-	{
-		if (day <= 0) day = 1;
-		if (year <= 0) year = 1;
-		date = new DateTime(year, month + 1, day, hour, min, sec);
-	}
-
-	/**
-		Returns the timestamp of the date. It's the number of milliseconds
-		elapsed since 1st January 1970. It might only have a per-second precision
-		depending on the platforms.
-	**/
-	public inline function getTime() : Float
-	{
-		return (cast(date.Ticks, Float) / TimeSpan.TicksPerMillisecond);
-	}
-
-	/**
-		Returns the hours value of the date (0-23 range).
-	**/
-	public inline function getHours() : Int
-	{
-		return date.Hour;
-	}
-
-	/**
-		Returns the minutes value of the date (0-59 range).
-	**/
-	public inline function getMinutes() : Int
-	{
-		return date.Minute;
-	}
-
-	/**
-		Returns the seconds of the date (0-59 range).
-	**/
-	public inline function getSeconds() : Int
-	{
-		return date.Second;
-	}
-
-	/**
-		Returns the full year of the date.
-	**/
-	public inline function getFullYear() : Int
-	{
-		return date.Year;
-	}
-
-	/**
-		Returns the month of the date (0-11 range).
-	**/
-	public inline function getMonth() : Int
-	{
-		return date.Month - 1;
-	}
-
-	/**
-		Returns the day of the date (1-31 range).
-	**/
-	public inline function getDate() : Int
-	{
-		return date.Day;
-	}
-
-	/**
-		Returns the week day of the date (0-6 range).
-	**/
-	public inline function getDay() : Int
-	{
-		return cast(date.DayOfWeek, Int);
-	}
-
-	/**
-		Returns a string representation for the Date, by using the
-		standard format [YYYY-MM-DD HH:MM:SS]. See [DateTools.format] for
-		other formating rules.
-	**/
-	public function toString():String
-	{
-		var m = getMonth() + 1;
-		var d = getDate();
-		var h = getHours();
-		var mi = getMinutes();
-		var s = getSeconds();
-		return (getFullYear())
-			+"-"+(if( m < 10 ) "0"+m else ""+m)
-			+"-"+(if( d < 10 ) "0"+d else ""+d)
-			+" "+(if( h < 10 ) "0"+h else ""+h)
-			+":"+(if( mi < 10 ) "0"+mi else ""+mi)
-			+":"+(if( s < 10 ) "0"+s else ""+s);
-	}
-
-	/**
-		Returns a Date representing the current local time.
-	**/
-	static public function now() : Date
-	{
-		var d = new Date(0, 0, 0, 0, 0, 0);
-		d.date = DateTime.Now;
-		return d;
-	}
-
-	/**
-		Returns a Date from a timestamp [t] which is the number of
-		milliseconds elapsed since 1st January 1970.
-	**/
-	static public function fromTime( t : Float ) : Date
-	{
-		var d = new Date(0, 0, 0, 0, 0, 0);
-		d.date = new DateTime(cast(t * TimeSpan.TicksPerMillisecond, Int64));
-		return d;
-	}
-
-
-	/**
-		Returns a Date from a formated string of one of the following formats :
-		[YYYY-MM-DD hh:mm:ss] or [YYYY-MM-DD] or [hh:mm:ss]. The first two formats
-		are expressed in local time, the third in UTC Epoch.
-	**/
-	static public function fromString( s : String ) : Date
-	{
-		switch( s.length )
-		{
-			case 8: // hh:mm:ss
-				var k = s.split(":");
-				var d : Date = new Date(1, 1, 1, Std.parseInt(k[0]), Std.parseInt(k[1]), Std.parseInt(k[2]));
-				return d;
-			case 10: // YYYY-MM-DD
-				var k = s.split("-");
-				return new Date(Std.parseInt(k[0]),Std.parseInt(k[1]) - 1,Std.parseInt(k[2]),0,0,0);
-			case 19: // YYYY-MM-DD hh:mm:ss
-				var k = s.split(" ");
-				var y = k[0].split("-");
-				var t = k[1].split(":");
-				return new Date(Std.parseInt(y[0]),Std.parseInt(y[1]) - 1,Std.parseInt(y[2]),Std.parseInt(t[0]),Std.parseInt(t[1]),Std.parseInt(t[2]));
-			default:
-				throw "Invalid date format : " + s;
-		}
-	}
-
-	private static function fromNative( d : cs.system.DateTime ) : Date
-	{
-		var date = new Date(0, 0, 0, 0, 0, 0);
-		date.date = d;
-		return date;
-	}
-}
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package;
+import cs.system.DateTime;
+import haxe.Int64;
+
+@:coreApi class Date
+{
+	private var date:DateTime;
+
+	/**
+		Creates a new date object.
+	**/
+	public function new(year : Int, month : Int, day : Int, hour : Int, min : Int, sec : Int ) : Void
+	{
+		if (day <= 0) day = 1;
+		if (year <= 0) year = 1;
+		date = new DateTime(year, month + 1, day, hour, min, sec);
+	}
+
+	/**
+		Returns the timestamp of the date. It's the number of milliseconds
+		elapsed since 1st January 1970. It might only have a per-second precision
+		depending on the platforms.
+	**/
+	public inline function getTime() : Float
+	{
+		return (cast(date.Ticks, Float) / TimeSpan.TicksPerMillisecond);
+	}
+
+	/**
+		Returns the hours value of the date (0-23 range).
+	**/
+	public inline function getHours() : Int
+	{
+		return date.Hour;
+	}
+
+	/**
+		Returns the minutes value of the date (0-59 range).
+	**/
+	public inline function getMinutes() : Int
+	{
+		return date.Minute;
+	}
+
+	/**
+		Returns the seconds of the date (0-59 range).
+	**/
+	public inline function getSeconds() : Int
+	{
+		return date.Second;
+	}
+
+	/**
+		Returns the full year of the date.
+	**/
+	public inline function getFullYear() : Int
+	{
+		return date.Year;
+	}
+
+	/**
+		Returns the month of the date (0-11 range).
+	**/
+	public inline function getMonth() : Int
+	{
+		return date.Month - 1;
+	}
+
+	/**
+		Returns the day of the date (1-31 range).
+	**/
+	public inline function getDate() : Int
+	{
+		return date.Day;
+	}
+
+	/**
+		Returns the week day of the date (0-6 range).
+	**/
+	public inline function getDay() : Int
+	{
+		return cast(date.DayOfWeek, Int);
+	}
+
+	/**
+		Returns a string representation for the Date, by using the
+		standard format [YYYY-MM-DD HH:MM:SS]. See [DateTools.format] for
+		other formating rules.
+	**/
+	public function toString():String
+	{
+		var m = getMonth() + 1;
+		var d = getDate();
+		var h = getHours();
+		var mi = getMinutes();
+		var s = getSeconds();
+		return (getFullYear())
+			+"-"+(if( m < 10 ) "0"+m else ""+m)
+			+"-"+(if( d < 10 ) "0"+d else ""+d)
+			+" "+(if( h < 10 ) "0"+h else ""+h)
+			+":"+(if( mi < 10 ) "0"+mi else ""+mi)
+			+":"+(if( s < 10 ) "0"+s else ""+s);
+	}
+
+	/**
+		Returns a Date representing the current local time.
+	**/
+	static public function now() : Date
+	{
+		var d = new Date(0, 0, 0, 0, 0, 0);
+		d.date = DateTime.Now;
+		return d;
+	}
+
+	/**
+		Returns a Date from a timestamp [t] which is the number of
+		milliseconds elapsed since 1st January 1970.
+	**/
+	static public function fromTime( t : Float ) : Date
+	{
+		var d = new Date(0, 0, 0, 0, 0, 0);
+		d.date = new DateTime(cast(t * TimeSpan.TicksPerMillisecond, Int64));
+		return d;
+	}
+
+
+	/**
+		Returns a Date from a formated string of one of the following formats :
+		[YYYY-MM-DD hh:mm:ss] or [YYYY-MM-DD] or [hh:mm:ss]. The first two formats
+		are expressed in local time, the third in UTC Epoch.
+	**/
+	static public function fromString( s : String ) : Date
+	{
+		switch( s.length )
+		{
+			case 8: // hh:mm:ss
+				var k = s.split(":");
+				var d : Date = new Date(1, 1, 1, Std.parseInt(k[0]), Std.parseInt(k[1]), Std.parseInt(k[2]));
+				return d;
+			case 10: // YYYY-MM-DD
+				var k = s.split("-");
+				return new Date(Std.parseInt(k[0]),Std.parseInt(k[1]) - 1,Std.parseInt(k[2]),0,0,0);
+			case 19: // YYYY-MM-DD hh:mm:ss
+				var k = s.split(" ");
+				var y = k[0].split("-");
+				var t = k[1].split(":");
+				return new Date(Std.parseInt(y[0]),Std.parseInt(y[1]) - 1,Std.parseInt(y[2]),Std.parseInt(t[0]),Std.parseInt(t[1]),Std.parseInt(t[2]));
+			default:
+				throw "Invalid date format : " + s;
+		}
+	}
+
+	private static function fromNative( d : cs.system.DateTime ) : Date
+	{
+		var date = new Date(0, 0, 0, 0, 0, 0);
+		date.date = d;
+		return date;
+	}
+}

+ 119 - 119
std/cs/_std/FieldLookup.hx

@@ -1,120 +1,120 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-@:native('haxe.lang.FieldLookup')
-@:static private class FieldLookup
-{
-
-	@:private private static var fieldIds:Array<Int>;
-	@:private private static var fields:Array<String>;
-
-	//s cannot be null here
-	private static inline function doHash(s:String):Int
-	{
-		var acc = 0; //alloc_int
-		for (i in 0...s.length)
-		{
-			acc = (( 223 * (acc >> 1) + s.charCodeAt(i) ) << 1);
-		}
-
-		return acc >>> 1; //always positive
-	}
-
-	public static function lookupHash(key:Int):String
-	{
-		//start of binary search algorithm
-		var ids = fieldIds;
-		var min = 0;
-		var max = ids.length;
-
-		while (min < max)
-		{
-			var mid = Std.int(min + (max - min) / 2); //overflow safe
-			var imid = ids[mid];
-			if (key < imid)
-			{
-				max = mid;
-			} else if (key > imid) {
-				min = mid + 1;
-			} else {
-				return fields[mid];
-			}
-		}
-		//if not found, it's definately an error
-		throw "Field not found for hash " + key;
-	}
-
-	public static function hash(s:String):Int
-	{
-		if (s == null) return 0;
-
-		var key = doHash(s);
-
-		//start of binary search algorithm
-		var ids = fieldIds;
-		var min = 0;
-		var max = ids.length;
-
-		while (min < max)
-		{
-			var mid = Std.int(min + (max - min) / 2); //overflow safe
-			var imid = ids[mid];
-			if (key < imid)
-			{
-				max = mid;
-			} else if (key > imid) {
-				min = mid + 1;
-			} else {
-				var field = fields[mid];
-				if (field != s)
-					return -(key + 1); //special case
-				return key;
-			}
-		}
-		//if not found, min holds the value where we should insert the key
-		ids.insert(min, key);
-		fields.insert(min, s);
-		return key;
-	}
-
-	public static function findHash(hash:Int, hashs:Array<Int>):Int
-	{
-		var min = 0;
-		var max = hashs.length;
-
-		while (min < max)
-		{
-			var mid = Std.int((max + min) / 2); //overflow safe
-			var imid = hashs[mid];
-			if (hash < imid)
-			{
-				max = mid;
-			} else if (hash > imid) {
-				min = mid + 1;
-			} else {
-				return min;
-			}
-		}
-		//if not found, return a negative value of where it should be inserted
-		return ~min;
-	}
-
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+@:native('haxe.lang.FieldLookup')
+@:static private class FieldLookup
+{
+
+	@:private private static var fieldIds:Array<Int>;
+	@:private private static var fields:Array<String>;
+
+	//s cannot be null here
+	private static inline function doHash(s:String):Int
+	{
+		var acc = 0; //alloc_int
+		for (i in 0...s.length)
+		{
+			acc = (( 223 * (acc >> 1) + s.charCodeAt(i) ) << 1);
+		}
+
+		return acc >>> 1; //always positive
+	}
+
+	public static function lookupHash(key:Int):String
+	{
+		//start of binary search algorithm
+		var ids = fieldIds;
+		var min = 0;
+		var max = ids.length;
+
+		while (min < max)
+		{
+			var mid = Std.int(min + (max - min) / 2); //overflow safe
+			var imid = ids[mid];
+			if (key < imid)
+			{
+				max = mid;
+			} else if (key > imid) {
+				min = mid + 1;
+			} else {
+				return fields[mid];
+			}
+		}
+		//if not found, it's definately an error
+		throw "Field not found for hash " + key;
+	}
+
+	public static function hash(s:String):Int
+	{
+		if (s == null) return 0;
+
+		var key = doHash(s);
+
+		//start of binary search algorithm
+		var ids = fieldIds;
+		var min = 0;
+		var max = ids.length;
+
+		while (min < max)
+		{
+			var mid = Std.int(min + (max - min) / 2); //overflow safe
+			var imid = ids[mid];
+			if (key < imid)
+			{
+				max = mid;
+			} else if (key > imid) {
+				min = mid + 1;
+			} else {
+				var field = fields[mid];
+				if (field != s)
+					return -(key + 1); //special case
+				return key;
+			}
+		}
+		//if not found, min holds the value where we should insert the key
+		ids.insert(min, key);
+		fields.insert(min, s);
+		return key;
+	}
+
+	public static function findHash(hash:Int, hashs:Array<Int>):Int
+	{
+		var min = 0;
+		var max = hashs.length;
+
+		while (min < max)
+		{
+			var mid = Std.int((max + min) / 2); //overflow safe
+			var imid = hashs[mid];
+			if (hash < imid)
+			{
+				max = mid;
+			} else if (hash > imid) {
+				min = mid + 1;
+			} else {
+				return min;
+			}
+		}
+		//if not found, return a negative value of where it should be inserted
+		return ~min;
+	}
+
 }

+ 165 - 165
std/cs/_std/Math.hx

@@ -1,165 +1,165 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package;
-import cs.system.Random;
-
-@:coreApi @:nativeGen class Math
-{
-	public static inline function __init__():Void
-	{
-		PI = cs.system.Math.PI;
-		NaN = untyped __cs__("double.NaN");
-		NEGATIVE_INFINITY = untyped __cs__("double.NegativeInfinity");
-		POSITIVE_INFINITY = untyped __cs__("double.PositiveInfinity");
-		rand = new Random();
-
-	}
-
-	private static var rand:Random;
-	public static var PI(default, null) : Float;
-	public static var NaN(default,null) : Float;
-	public static var NEGATIVE_INFINITY(default,null) : Float;
-	public static var POSITIVE_INFINITY(default,null) : Float;
-
-	public static inline function abs(v:Float):Float
-	{
-		return cs.system.Math.Abs(v);
-	}
-
-	public static inline function min(a:Float, b:Float):Float
-	{
-		return cs.system.Math.Min(a,b);
-	}
-
-	public static inline function max(a:Float, b:Float):Float
-	{
-		return cs.system.Math.Max(a,b);
-	}
-
-	public static inline function sin(v:Float):Float
-	{
-		return cs.system.Math.Sin(v);
-	}
-
-	public static inline function cos(v:Float):Float
-	{
-		return cs.system.Math.Cos(v);
-	}
-
-	public static inline function atan2(y:Float, x:Float):Float
-	{
-		return cs.system.Math.Atan2(y, x);
-	}
-
-	public static inline function tan(v:Float):Float
-	{
-		return cs.system.Math.Tan(v);
-	}
-
-	public static inline function exp(v:Float):Float
-	{
-		return cs.system.Math.Exp(v);
-	}
-
-	public static inline function log(v:Float):Float
-	{
-		return cs.system.Math.Log(v);
-	}
-
-	public static inline function sqrt(v:Float):Float
-	{
-		return cs.system.Math.Sqrt(v);
-	}
-
-	public static inline function fround(v:Float):Float
-	{
-		return cs.system.Math.Round(v);
-	}
-
-	public static inline function ffloor(v:Float):Float
-	{
-		return cs.system.Math.Floor(v);
-	}
-
-	public static inline function fceil(v:Float):Float
-	{
-		return cs.system.Math.Ceiling(v);
-	}
-
-	public static function round(v:Float):Int
-	{
-		var vint = Std.int(v);
-		var dec = v - vint;
-		if (dec >= 1 || dec <= -1)
-			return vint; //overflow
-		if (dec >= .5)
-			return vint + 1;
-		if (dec < -.5)
-			return vint - 1;
-		return vint;
-	}
-
-	public static inline function floor(v:Float):Int
-	{
-		return Std.int(cs.system.Math.Floor(v));
-	}
-
-	public static inline function ceil(v:Float):Int
-	{
-		return Std.int(cs.system.Math.Ceiling(v));
-	}
-
-	public static inline function atan(v:Float):Float
-	{
-		return cs.system.Math.Atan(v);
-	}
-
-	public static inline function asin(v:Float):Float
-	{
-		return cs.system.Math.Asin(v);
-	}
-
-	public static inline function acos(v:Float):Float
-	{
-		return cs.system.Math.Acos(v);
-	}
-
-	public static inline function pow(v:Float, exp:Float):Float
-	{
-		return cs.system.Math.Pow(v, exp);
-	}
-
-	public static inline function random() : Float
-	{
-		return rand.NextDouble();
-	}
-
-	public static function isFinite( f : Float ) : Bool
-	{
-		return untyped __cs__("!double.IsInfinity(f) && !double.IsNaN(f)");
-	}
-
-	public static function isNaN( f : Float ) : Bool
-	{
-		return untyped __cs__("double.IsNaN(f)");
-	}
-}
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package;
+import cs.system.Random;
+
+@:coreApi @:nativeGen class Math
+{
+	public static inline function __init__():Void
+	{
+		PI = cs.system.Math.PI;
+		NaN = untyped __cs__("double.NaN");
+		NEGATIVE_INFINITY = untyped __cs__("double.NegativeInfinity");
+		POSITIVE_INFINITY = untyped __cs__("double.PositiveInfinity");
+		rand = new Random();
+
+	}
+
+	private static var rand:Random;
+	public static var PI(default, null) : Float;
+	public static var NaN(default,null) : Float;
+	public static var NEGATIVE_INFINITY(default,null) : Float;
+	public static var POSITIVE_INFINITY(default,null) : Float;
+
+	public static inline function abs(v:Float):Float
+	{
+		return cs.system.Math.Abs(v);
+	}
+
+	public static inline function min(a:Float, b:Float):Float
+	{
+		return cs.system.Math.Min(a,b);
+	}
+
+	public static inline function max(a:Float, b:Float):Float
+	{
+		return cs.system.Math.Max(a,b);
+	}
+
+	public static inline function sin(v:Float):Float
+	{
+		return cs.system.Math.Sin(v);
+	}
+
+	public static inline function cos(v:Float):Float
+	{
+		return cs.system.Math.Cos(v);
+	}
+
+	public static inline function atan2(y:Float, x:Float):Float
+	{
+		return cs.system.Math.Atan2(y, x);
+	}
+
+	public static inline function tan(v:Float):Float
+	{
+		return cs.system.Math.Tan(v);
+	}
+
+	public static inline function exp(v:Float):Float
+	{
+		return cs.system.Math.Exp(v);
+	}
+
+	public static inline function log(v:Float):Float
+	{
+		return cs.system.Math.Log(v);
+	}
+
+	public static inline function sqrt(v:Float):Float
+	{
+		return cs.system.Math.Sqrt(v);
+	}
+
+	public static inline function fround(v:Float):Float
+	{
+		return cs.system.Math.Round(v);
+	}
+
+	public static inline function ffloor(v:Float):Float
+	{
+		return cs.system.Math.Floor(v);
+	}
+
+	public static inline function fceil(v:Float):Float
+	{
+		return cs.system.Math.Ceiling(v);
+	}
+
+	public static function round(v:Float):Int
+	{
+		var vint = Std.int(v);
+		var dec = v - vint;
+		if (dec >= 1 || dec <= -1)
+			return vint; //overflow
+		if (dec >= .5)
+			return vint + 1;
+		if (dec < -.5)
+			return vint - 1;
+		return vint;
+	}
+
+	public static inline function floor(v:Float):Int
+	{
+		return Std.int(cs.system.Math.Floor(v));
+	}
+
+	public static inline function ceil(v:Float):Int
+	{
+		return Std.int(cs.system.Math.Ceiling(v));
+	}
+
+	public static inline function atan(v:Float):Float
+	{
+		return cs.system.Math.Atan(v);
+	}
+
+	public static inline function asin(v:Float):Float
+	{
+		return cs.system.Math.Asin(v);
+	}
+
+	public static inline function acos(v:Float):Float
+	{
+		return cs.system.Math.Acos(v);
+	}
+
+	public static inline function pow(v:Float, exp:Float):Float
+	{
+		return cs.system.Math.Pow(v, exp);
+	}
+
+	public static inline function random() : Float
+	{
+		return rand.NextDouble();
+	}
+
+	public static function isFinite( f : Float ) : Bool
+	{
+		return untyped __cs__("!double.IsInfinity(f) && !double.IsNaN(f)");
+	}
+
+	public static function isNaN( f : Float ) : Bool
+	{
+		return untyped __cs__("double.IsNaN(f)");
+	}
+}

+ 259 - 259
std/cs/_std/Reflect.hx

@@ -1,259 +1,259 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-import cs.internal.Function;
-/*
- * Copyright (c) 2005, The haXe Project Contributors
- * All rights reserved.
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- *   - Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- *   - Redistributions in binary form must reproduce the above copyright
- *     notice, this list of conditions and the following disclaimer in the
- *     documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- */
-
-/**
-	The Reflect API is a way to manipulate values dynamicly through an
-	abstract interface in an untyped manner. Use with care.
-**/
-@:keep @:coreApi class Reflect {
-
-	/**
-		Tells if an object has a field set. This doesn't take into account the object prototype (class methods).
-	**/
-	@:functionCode('
-		if (o is haxe.lang.IHxObject)
-			return ((haxe.lang.IHxObject) o).__hx_getField(field, haxe.lang.FieldLookup.hash(field), false, true, false) != haxe.lang.Runtime.undefined;
-
-		return haxe.lang.Runtime.slowHasField(o, field);
-	')
-	public static function hasField( o : Dynamic, field : String ) : Bool
-	{
-		return false;
-	}
-
-	/**
-		Returns the field of an object, or null if [o] is not an object or doesn't have this field.
-	**/
-	@:functionCode('
-		if (o is haxe.lang.IHxObject)
-			return ((haxe.lang.IHxObject) o).__hx_getField(field, haxe.lang.FieldLookup.hash(field), false, false, false);
-
-		return haxe.lang.Runtime.slowGetField(o, field, false);
-	')
-	public static function field( o : Dynamic, field : String ) : Dynamic
-	{
-		return null;
-	}
-
-
-	/**
-		Set an object field value.
-	**/
-	@:functionCode('
-		if (o is haxe.lang.IHxObject)
-			((haxe.lang.IHxObject) o).__hx_setField(field, haxe.lang.FieldLookup.hash(field), value, false);
-		else
-			haxe.lang.Runtime.slowSetField(o, field, value);
-	')
-	public static function setField( o : Dynamic, field : String, value : Dynamic ) : Void
-	{
-
-	}
-
-	/**
-		Similar to field but also supports property (might be slower).
-	**/
-	@:functionCode('
-		if (o is haxe.lang.IHxObject)
-			return ((haxe.lang.IHxObject) o).__hx_getField(field, haxe.lang.FieldLookup.hash(field), false, false, true);
-
-		if (haxe.lang.Runtime.slowHasField(o, "get_" + field))
-			return haxe.lang.Runtime.slowCallField(o, "get_" + field, null);
-
-		return haxe.lang.Runtime.slowGetField(o, field, false);
-	')
-	public static function getProperty( o : Dynamic, field : String ) : Dynamic
-	{
-		return null;
-	}
-
-	/**
-		Similar to setField but also supports property (might be slower).
-	**/
-	@:functionCode('
-		if (o is haxe.lang.IHxObject)
-			((haxe.lang.IHxObject) o).__hx_setField(field, haxe.lang.FieldLookup.hash(field), value, true);
-		else if (haxe.lang.Runtime.slowHasField(o, "set_" + field))
-			haxe.lang.Runtime.slowCallField(o, "set_" + field, new Array<object>(new object[]{value}));
-		else
-			haxe.lang.Runtime.slowSetField(o, field, value);
-	')
-	public static function setProperty( o : Dynamic, field : String, value : Dynamic ) : Void
-	{
-
-	}
-
-	/**
-		Call a method with the given object and arguments.
-	**/
-	@:functionCode('
-		return ((haxe.lang.Function) func).__hx_invokeDynamic(args);
-	')
-	public static function callMethod( o : Dynamic, func : Dynamic, args : Array<Dynamic> ) : Dynamic
-	{
-		return null;
-	}
-
-	/**
-		Returns the list of fields of an object, excluding its prototype (class methods).
-	**/
-	@:functionCode('
-		if (o is haxe.lang.IHxObject)
-		{
-			Array<object> ret = new Array<object>();
-				((haxe.lang.IHxObject) o).__hx_getFields(ret);
-			return ret;
-		} else if (o is System.Type) {
-			return Type.getClassFields( (System.Type) o);
-		} else {
-			return new Array<object>();
-		}
-	')
-	public static function fields( o : Dynamic ) : Array<String>
-	{
-		return null;
-	}
-
-	/**
-		Tells if a value is a function or not.
-	**/
-	@:functionCode('
-		return f is haxe.lang.Function;
-	')
-	public static function isFunction( f : Dynamic ) : Bool
-	{
-		return false;
-	}
-
-	/**
-		Generic comparison function, does not work for methods, see [compareMethods]
-	**/
-	@:functionCode('
-		return haxe.lang.Runtime.compare(a, b);
-	')
-	public static function compare<T>( a : T, b : T ) : Int
-	{
-		return 0;
-	}
-
-	/**
-		Compare two methods closures. Returns true if it's the same method of the same instance.
-	**/
-	@:functionCode('
-		if (f1 == f2)
-			return true;
-
-		if (f1 is haxe.lang.Closure && f2 is haxe.lang.Closure)
-		{
-			haxe.lang.Closure f1c = (haxe.lang.Closure) f1;
-			haxe.lang.Closure f2c = (haxe.lang.Closure) f2;
-
-			return haxe.lang.Runtime.refEq(f1c.obj, f2c.obj) && f1c.field.Equals(f2c.field);
-		}
-
-		return false;
-	')
-	public static function compareMethods( f1 : Dynamic, f2 : Dynamic ) : Bool
-	{
-		return false;
-	}
-
-	/**
-		Tells if a value is an object or not.
-
-	**/
-	@:functionCode('
-		return v != null && !(v is haxe.lang.Enum || v is haxe.lang.Function || v is System.ValueType);
-	')
-	public static function isObject( v : Dynamic ) : Bool
-	{
-		return false;
-	}
-
-	@:functionCode('
-		return v != null && (v is haxe.lang.Enum || v is System.Enum);
-	')
-	public static function isEnumValue( v : Dynamic ) : Bool {
-		return switch(Type.typeof(v)) {
-			case TEnum(_): true;
-			case _: false;
-		}
-	}
-
-	/**
-		Delete an object field.
-	**/
-	@:functionCode('
-		return (o is haxe.lang.DynamicObject && ((haxe.lang.DynamicObject) o).__hx_deleteField(field, haxe.lang.FieldLookup.hash(field)));
-	')
-	public static function deleteField( o : Dynamic, field : String ) : Bool
-	{
-		return false;
-	}
-
-	/**
-		Make a copy of the fields of an object.
-	**/
-	public static function copy<T>( o : T ) : T
-	{
-		var o2 : Dynamic = {};
-		for( f in Reflect.fields(o) )
-			Reflect.setField(o2,f,Reflect.field(o,f));
-		return cast o2;
-	}
-
-	/**
-		Transform a function taking an array of arguments into a function that can
-		be called with any number of arguments.
-	**/
-	@:overload(function( f : Array<Dynamic> -> Void ) : Dynamic {})
-	public static function makeVarArgs( f : Array<Dynamic> -> Dynamic ) : Dynamic
-	{
-		return new VarArgsFunction(f);
-	}
-
-}
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+import cs.internal.Function;
+/*
+ * Copyright (c) 2005, The haXe Project Contributors
+ * All rights reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   - Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   - Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ */
+
+/**
+	The Reflect API is a way to manipulate values dynamicly through an
+	abstract interface in an untyped manner. Use with care.
+**/
+@:keep @:coreApi class Reflect {
+
+	/**
+		Tells if an object has a field set. This doesn't take into account the object prototype (class methods).
+	**/
+	@:functionCode('
+		if (o is haxe.lang.IHxObject)
+			return ((haxe.lang.IHxObject) o).__hx_getField(field, haxe.lang.FieldLookup.hash(field), false, true, false) != haxe.lang.Runtime.undefined;
+
+		return haxe.lang.Runtime.slowHasField(o, field);
+	')
+	public static function hasField( o : Dynamic, field : String ) : Bool
+	{
+		return false;
+	}
+
+	/**
+		Returns the field of an object, or null if [o] is not an object or doesn't have this field.
+	**/
+	@:functionCode('
+		if (o is haxe.lang.IHxObject)
+			return ((haxe.lang.IHxObject) o).__hx_getField(field, haxe.lang.FieldLookup.hash(field), false, false, false);
+
+		return haxe.lang.Runtime.slowGetField(o, field, false);
+	')
+	public static function field( o : Dynamic, field : String ) : Dynamic
+	{
+		return null;
+	}
+
+
+	/**
+		Set an object field value.
+	**/
+	@:functionCode('
+		if (o is haxe.lang.IHxObject)
+			((haxe.lang.IHxObject) o).__hx_setField(field, haxe.lang.FieldLookup.hash(field), value, false);
+		else
+			haxe.lang.Runtime.slowSetField(o, field, value);
+	')
+	public static function setField( o : Dynamic, field : String, value : Dynamic ) : Void
+	{
+
+	}
+
+	/**
+		Similar to field but also supports property (might be slower).
+	**/
+	@:functionCode('
+		if (o is haxe.lang.IHxObject)
+			return ((haxe.lang.IHxObject) o).__hx_getField(field, haxe.lang.FieldLookup.hash(field), false, false, true);
+
+		if (haxe.lang.Runtime.slowHasField(o, "get_" + field))
+			return haxe.lang.Runtime.slowCallField(o, "get_" + field, null);
+
+		return haxe.lang.Runtime.slowGetField(o, field, false);
+	')
+	public static function getProperty( o : Dynamic, field : String ) : Dynamic
+	{
+		return null;
+	}
+
+	/**
+		Similar to setField but also supports property (might be slower).
+	**/
+	@:functionCode('
+		if (o is haxe.lang.IHxObject)
+			((haxe.lang.IHxObject) o).__hx_setField(field, haxe.lang.FieldLookup.hash(field), value, true);
+		else if (haxe.lang.Runtime.slowHasField(o, "set_" + field))
+			haxe.lang.Runtime.slowCallField(o, "set_" + field, new Array<object>(new object[]{value}));
+		else
+			haxe.lang.Runtime.slowSetField(o, field, value);
+	')
+	public static function setProperty( o : Dynamic, field : String, value : Dynamic ) : Void
+	{
+
+	}
+
+	/**
+		Call a method with the given object and arguments.
+	**/
+	@:functionCode('
+		return ((haxe.lang.Function) func).__hx_invokeDynamic(args);
+	')
+	public static function callMethod( o : Dynamic, func : Dynamic, args : Array<Dynamic> ) : Dynamic
+	{
+		return null;
+	}
+
+	/**
+		Returns the list of fields of an object, excluding its prototype (class methods).
+	**/
+	@:functionCode('
+		if (o is haxe.lang.IHxObject)
+		{
+			Array<object> ret = new Array<object>();
+				((haxe.lang.IHxObject) o).__hx_getFields(ret);
+			return ret;
+		} else if (o is System.Type) {
+			return Type.getClassFields( (System.Type) o);
+		} else {
+			return new Array<object>();
+		}
+	')
+	public static function fields( o : Dynamic ) : Array<String>
+	{
+		return null;
+	}
+
+	/**
+		Tells if a value is a function or not.
+	**/
+	@:functionCode('
+		return f is haxe.lang.Function;
+	')
+	public static function isFunction( f : Dynamic ) : Bool
+	{
+		return false;
+	}
+
+	/**
+		Generic comparison function, does not work for methods, see [compareMethods]
+	**/
+	@:functionCode('
+		return haxe.lang.Runtime.compare(a, b);
+	')
+	public static function compare<T>( a : T, b : T ) : Int
+	{
+		return 0;
+	}
+
+	/**
+		Compare two methods closures. Returns true if it's the same method of the same instance.
+	**/
+	@:functionCode('
+		if (f1 == f2)
+			return true;
+
+		if (f1 is haxe.lang.Closure && f2 is haxe.lang.Closure)
+		{
+			haxe.lang.Closure f1c = (haxe.lang.Closure) f1;
+			haxe.lang.Closure f2c = (haxe.lang.Closure) f2;
+
+			return haxe.lang.Runtime.refEq(f1c.obj, f2c.obj) && f1c.field.Equals(f2c.field);
+		}
+
+		return false;
+	')
+	public static function compareMethods( f1 : Dynamic, f2 : Dynamic ) : Bool
+	{
+		return false;
+	}
+
+	/**
+		Tells if a value is an object or not.
+
+	**/
+	@:functionCode('
+		return v != null && !(v is haxe.lang.Enum || v is haxe.lang.Function || v is System.ValueType);
+	')
+	public static function isObject( v : Dynamic ) : Bool
+	{
+		return false;
+	}
+
+	@:functionCode('
+		return v != null && (v is haxe.lang.Enum || v is System.Enum);
+	')
+	public static function isEnumValue( v : Dynamic ) : Bool {
+		return switch(Type.typeof(v)) {
+			case TEnum(_): true;
+			case _: false;
+		}
+	}
+
+	/**
+		Delete an object field.
+	**/
+	@:functionCode('
+		return (o is haxe.lang.DynamicObject && ((haxe.lang.DynamicObject) o).__hx_deleteField(field, haxe.lang.FieldLookup.hash(field)));
+	')
+	public static function deleteField( o : Dynamic, field : String ) : Bool
+	{
+		return false;
+	}
+
+	/**
+		Make a copy of the fields of an object.
+	**/
+	public static function copy<T>( o : T ) : T
+	{
+		var o2 : Dynamic = {};
+		for( f in Reflect.fields(o) )
+			Reflect.setField(o2,f,Reflect.field(o,f));
+		return cast o2;
+	}
+
+	/**
+		Transform a function taking an array of arguments into a function that can
+		be called with any number of arguments.
+	**/
+	@:overload(function( f : Array<Dynamic> -> Void ) : Dynamic {})
+	public static function makeVarArgs( f : Array<Dynamic> -> Dynamic ) : Dynamic
+	{
+		return new VarArgsFunction(f);
+	}
+
+}

+ 64 - 64
std/cs/_std/String.hx

@@ -1,64 +1,64 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-import cs.StdTypes;
-
-@:coreType extern class String implements ArrayAccess<Char16> {
-
-	private static function Compare(s1:String, s2:String):Int;
-
-	var length(default,null) : Int;
-
-	function new(string:String) : Void;
-
-	function toUpperCase() : String;
-
-	function toLowerCase() : String;
-
-	function charAt( index : Int) : String;
-
-	function charCodeAt( index : Int) : Null<Int>;
-
-	function indexOf( str : String, ?startIndex : Int ) : Int;
-
-	function lastIndexOf( str : String, ?startIndex : Int ) : Int;
-
-	function split( delimiter : String ) : Array<String>;
-
-	function substr( pos : Int, ?len : Int ) : String;
-
-	function substring( startIndex : Int, ?endIndex : Int ) : String;
-
-	function toString() : String;
-
-	static function fromCharCode( code : Int ) : String;
-
-	private function Replace(oldValue:String, newValue:String):String;
-	private function StartsWith(value:String):Bool;
-	private function EndsWith(value:String):Bool;
-	private function TrimStart():String;
-	private function TrimEnd():String;
-	private function Trim():String;
-	private function CompareTo(obj:Dynamic):Int;
-	@:overload(function(startIndex:Int):String {})
-	private function Substring(startIndex:Int, length:Int):String;
-
-}
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+import cs.StdTypes;
+
+@:coreType extern class String implements ArrayAccess<Char16> {
+
+	private static function Compare(s1:String, s2:String):Int;
+
+	var length(default,null) : Int;
+
+	function new(string:String) : Void;
+
+	function toUpperCase() : String;
+
+	function toLowerCase() : String;
+
+	function charAt( index : Int) : String;
+
+	function charCodeAt( index : Int) : Null<Int>;
+
+	function indexOf( str : String, ?startIndex : Int ) : Int;
+
+	function lastIndexOf( str : String, ?startIndex : Int ) : Int;
+
+	function split( delimiter : String ) : Array<String>;
+
+	function substr( pos : Int, ?len : Int ) : String;
+
+	function substring( startIndex : Int, ?endIndex : Int ) : String;
+
+	function toString() : String;
+
+	static function fromCharCode( code : Int ) : String;
+
+	private function Replace(oldValue:String, newValue:String):String;
+	private function StartsWith(value:String):Bool;
+	private function EndsWith(value:String):Bool;
+	private function TrimStart():String;
+	private function TrimEnd():String;
+	private function Trim():String;
+	private function CompareTo(obj:Dynamic):Int;
+	@:overload(function(startIndex:Int):String {})
+	private function Substring(startIndex:Int, length:Int):String;
+
+}

+ 47 - 47
std/cs/_std/StringBuf.hx

@@ -1,48 +1,48 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-@:coreApi
-class StringBuf {
-
-	private var b : cs.StringBuilder;
-
-	public function new() : Void {
-		b = new cs.StringBuilder();
-	}
-
-	public inline function add( x : Dynamic ) : Void {
-		b.Append(Std.string(x));
-	}
-
-	public function addSub( s : String, pos : Int, ?len : Int ) : Void {
-		var l:Int = (len == null) ? (s.length - pos) : len;
-		b.Append(s, pos, l);
-	}
-
-	public inline function addChar( c : Int ) : Void untyped {
-		b.Append(cast(c, cs.StdTypes.Char16));
-	}
-
-	public function toString() : String {
-		return b.ToString();
-	}
-
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+@:coreApi
+class StringBuf {
+
+	private var b : cs.StringBuilder;
+
+	public function new() : Void {
+		b = new cs.StringBuilder();
+	}
+
+	public inline function add( x : Dynamic ) : Void {
+		b.Append(Std.string(x));
+	}
+
+	public function addSub( s : String, pos : Int, ?len : Int ) : Void {
+		var l:Int = (len == null) ? (s.length - pos) : len;
+		b.Append(s, pos, l);
+	}
+
+	public inline function addChar( c : Int ) : Void untyped {
+		b.Append(cast(c, cs.StdTypes.Char16));
+	}
+
+	public function toString() : String {
+		return b.ToString();
+	}
+
 }

+ 273 - 273
std/cs/_std/Sys.hx

@@ -1,273 +1,273 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-import sys.io.Process;
-import cs.system.Environment;
-import cs.system.threading.Thread;
-/*
- * Copyright (c) 2005-2012, The haXe Project Contributors
- * All rights reserved.
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- *   - Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- *   - Redistributions in binary form must reproduce the above copyright
- *     notice, this list of conditions and the following disclaimer in the
- *     documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- */
-
-/**
-	This class gives you access to many base functionalities of system platforms. Looks in [sys] sub packages for more system APIs.
-**/
-@:coreApi
-class Sys {
-	private static var _env:haxe.ds.StringMap<String>;
-	private static var _args:Array<String>;
-
-	/**
-		Print any value on the standard output.
-	**/
-	public static function print( v : Dynamic ) : Void
-	{
-		cs.system.Console.Write(v);
-	}
-
-	/**
-		Print any value on the standard output, followed by a newline
-	**/
-	public static function println( v : Dynamic ) : Void
-	{
-		cs.system.Console.WriteLine(v);
-	}
-
-	/**
-		Returns all the arguments that were passed by the commandline.
-	**/
-	public static function args() : Array<String>
-	{
-		if (_args == null)
-		{
-			var ret = cs.Lib.array(Environment.GetCommandLineArgs());
-			ret.shift();
-			_args = ret;
-		}
-		return _args.copy();
-	}
-
-	/**
-		Returns the value of the given environment variable.
-	**/
-	public static function getEnv( s : String ) : String
-	{
-		return Environment.GetEnvironmentVariable(s);
-	}
-
-	/**
-		Set the value of the given environment variable.
-	**/
-	public static function putEnv( s : String, v : String ) : Void
-	{
-		Environment.SetEnvironmentVariable(s, v);
-		if (_env != null)
-			_env.set(s, v);
-	}
-
-	/**
-		Returns the whole environement variables.
-	**/
-	public static function environment() : haxe.ds.StringMap<String>
-	{
-		if (_env == null)
-		{
-			var e = _env = new haxe.ds.StringMap();
-			var nenv = Environment.GetEnvironmentVariables().GetEnumerator();
-			while (nenv.MoveNext())
-			{
-				e.set(nenv.Key, nenv.Value);
-			}
-		}
-
-		return _env;
-	}
-
-	/**
-		Suspend the current execution for the given time (in seconds).
-	**/
-	public static function sleep( seconds : Float ) : Void
-	{
-		Thread.Sleep( Std.int(seconds * 1000) );
-	}
-
-	/**
-		Change the current time locale, which will affect [DateTools.format] date formating.
-		Returns true if the locale was successfully changed
-	**/
-	public static function setTimeLocale( loc : String ) : Bool
-	{
-		//TODO C#
-		return false;
-	}
-
-	/**
-		Get the current working directory (usually the one in which the program was started)
-	**/
-	public static function getCwd() : String
-	{
-		return cs.system.io.Directory.GetCurrentDirectory();
-	}
-
-	/**
-		Change the current working directory.
-	**/
-	public static function setCwd( s : String ) : Void
-	{
-		cs.system.io.Directory.SetCurrentDirectory(s);
-	}
-
-	/**
-		Returns the name of the system you are running on. For instance :
-			"Windows", "Linux", "BSD" and "Mac" depending on your desktop OS.
-	**/
-	public static function systemName() : String
-	{
-		//doing a switch with strings since MacOS might not be available
-		switch(Environment.OSVersion.Platform + "")
-		{
-			case "Unix": return "Linux";
-			case "Xbox": return "Xbox";
-			case "MacOSX": return "Mac";
-			default:
-				var ver = cast(Environment.OSVersion.Platform, Int);
-				if (ver == 4 || ver == 6 || ver == 128)
-					return "Linux";
-				return "Windows";
-		}
-	}
-
-	/**
-		Run the given command with the list of arguments. The command output will be printed on the same output as the current process.
-		The current process will block until the command terminates and it will return the command result (0 if there was no error).
-		Read the [sys.io.Process] api for a more complete way to start background processes.
-	**/
-	public static function command( cmd : String, ?args : Array<String> ) : Int
-	{
-		var proc:Process = new Process(cmd, args == null ? [] : args);
-		var ret = proc.exitCode();
-		proc.close();
-
-		return ret;
-	}
-
-	/**
-		Exit the current process with the given error code.
-	**/
-	public static function exit( code : Int ) : Void
-	{
-		Environment.Exit(code);
-	}
-
-	/**
-		Gives the most precise timestamp value (in seconds).
-	**/
-	public static function time() : Float
-	{
-		return Date.now().getTime() / 1000;
-	}
-
-	/**
-		Gives the most precise timestamp value (in seconds) but only account for the actual time spent running on the CPU for the current thread/process.
-	**/
-	public static function cpuTime() : Float
-	{
-		return Environment.TickCount / 1000;
-	}
-
-	/**
-		Returns the path to the current executable that we are running.
-	**/
-	public static function executablePath() : String
-	{
-		//TODO: add extern references
-		return untyped __cs__('System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase');
-	}
-
-	/**
-		Read a single input character from the standard input (without blocking) and returns it. Setting [echo] to true will also display it on the output.
-	**/
-	public static function getChar( echo : Bool ) : Int
-	{
-		#if !(Xbox || CF || MF) //Xbox, Compact Framework, Micro Framework
-		return untyped __cs__('((int) System.Console.ReadKey(!echo).KeyChar)');
-		#else
-		return -1;
-		#end
-	}
-
-	/**
-		Returns the process standard input, from which you can read what user enters. Usually it will block until the user send a full input line. See [getChar] for an alternative.
-	**/
-	public static function stdin() : haxe.io.Input
-	{
-#if !(Xbox || CF || MF)
-		return new cs.io.NativeInput(cs.system.Console.OpenStandardInput());
-#else
-		return null;
-#end
-	}
-
-	/**
-		Returns the process standard output on which you can write.
-	**/
-	public static function stdout() : haxe.io.Output
-	{
-#if !(Xbox || CF || MF)
-		return new cs.io.NativeOutput(cs.system.Console.OpenStandardOutput());
-#else
-		return null;
-#end
-	}
-
-	/**
-		Returns the process standard error on which you can write.
-	**/
-	public static function stderr() : haxe.io.Output
-	{
-#if !(Xbox || CF || MF)
-		return new cs.io.NativeOutput(cs.system.Console.OpenStandardError());
-#else
-		return null;
-#end
-	}
-
-}
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+import sys.io.Process;
+import cs.system.Environment;
+import cs.system.threading.Thread;
+/*
+ * Copyright (c) 2005-2012, The haXe Project Contributors
+ * All rights reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   - Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   - Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ */
+
+/**
+	This class gives you access to many base functionalities of system platforms. Looks in [sys] sub packages for more system APIs.
+**/
+@:coreApi
+class Sys {
+	private static var _env:haxe.ds.StringMap<String>;
+	private static var _args:Array<String>;
+
+	/**
+		Print any value on the standard output.
+	**/
+	public static function print( v : Dynamic ) : Void
+	{
+		cs.system.Console.Write(v);
+	}
+
+	/**
+		Print any value on the standard output, followed by a newline
+	**/
+	public static function println( v : Dynamic ) : Void
+	{
+		cs.system.Console.WriteLine(v);
+	}
+
+	/**
+		Returns all the arguments that were passed by the commandline.
+	**/
+	public static function args() : Array<String>
+	{
+		if (_args == null)
+		{
+			var ret = cs.Lib.array(Environment.GetCommandLineArgs());
+			ret.shift();
+			_args = ret;
+		}
+		return _args.copy();
+	}
+
+	/**
+		Returns the value of the given environment variable.
+	**/
+	public static function getEnv( s : String ) : String
+	{
+		return Environment.GetEnvironmentVariable(s);
+	}
+
+	/**
+		Set the value of the given environment variable.
+	**/
+	public static function putEnv( s : String, v : String ) : Void
+	{
+		Environment.SetEnvironmentVariable(s, v);
+		if (_env != null)
+			_env.set(s, v);
+	}
+
+	/**
+		Returns the whole environement variables.
+	**/
+	public static function environment() : haxe.ds.StringMap<String>
+	{
+		if (_env == null)
+		{
+			var e = _env = new haxe.ds.StringMap();
+			var nenv = Environment.GetEnvironmentVariables().GetEnumerator();
+			while (nenv.MoveNext())
+			{
+				e.set(nenv.Key, nenv.Value);
+			}
+		}
+
+		return _env;
+	}
+
+	/**
+		Suspend the current execution for the given time (in seconds).
+	**/
+	public static function sleep( seconds : Float ) : Void
+	{
+		Thread.Sleep( Std.int(seconds * 1000) );
+	}
+
+	/**
+		Change the current time locale, which will affect [DateTools.format] date formating.
+		Returns true if the locale was successfully changed
+	**/
+	public static function setTimeLocale( loc : String ) : Bool
+	{
+		//TODO C#
+		return false;
+	}
+
+	/**
+		Get the current working directory (usually the one in which the program was started)
+	**/
+	public static function getCwd() : String
+	{
+		return cs.system.io.Directory.GetCurrentDirectory();
+	}
+
+	/**
+		Change the current working directory.
+	**/
+	public static function setCwd( s : String ) : Void
+	{
+		cs.system.io.Directory.SetCurrentDirectory(s);
+	}
+
+	/**
+		Returns the name of the system you are running on. For instance :
+			"Windows", "Linux", "BSD" and "Mac" depending on your desktop OS.
+	**/
+	public static function systemName() : String
+	{
+		//doing a switch with strings since MacOS might not be available
+		switch(Environment.OSVersion.Platform + "")
+		{
+			case "Unix": return "Linux";
+			case "Xbox": return "Xbox";
+			case "MacOSX": return "Mac";
+			default:
+				var ver = cast(Environment.OSVersion.Platform, Int);
+				if (ver == 4 || ver == 6 || ver == 128)
+					return "Linux";
+				return "Windows";
+		}
+	}
+
+	/**
+		Run the given command with the list of arguments. The command output will be printed on the same output as the current process.
+		The current process will block until the command terminates and it will return the command result (0 if there was no error).
+		Read the [sys.io.Process] api for a more complete way to start background processes.
+	**/
+	public static function command( cmd : String, ?args : Array<String> ) : Int
+	{
+		var proc:Process = new Process(cmd, args == null ? [] : args);
+		var ret = proc.exitCode();
+		proc.close();
+
+		return ret;
+	}
+
+	/**
+		Exit the current process with the given error code.
+	**/
+	public static function exit( code : Int ) : Void
+	{
+		Environment.Exit(code);
+	}
+
+	/**
+		Gives the most precise timestamp value (in seconds).
+	**/
+	public static function time() : Float
+	{
+		return Date.now().getTime() / 1000;
+	}
+
+	/**
+		Gives the most precise timestamp value (in seconds) but only account for the actual time spent running on the CPU for the current thread/process.
+	**/
+	public static function cpuTime() : Float
+	{
+		return Environment.TickCount / 1000;
+	}
+
+	/**
+		Returns the path to the current executable that we are running.
+	**/
+	public static function executablePath() : String
+	{
+		//TODO: add extern references
+		return untyped __cs__('System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase');
+	}
+
+	/**
+		Read a single input character from the standard input (without blocking) and returns it. Setting [echo] to true will also display it on the output.
+	**/
+	public static function getChar( echo : Bool ) : Int
+	{
+		#if !(Xbox || CF || MF) //Xbox, Compact Framework, Micro Framework
+		return untyped __cs__('((int) System.Console.ReadKey(!echo).KeyChar)');
+		#else
+		return -1;
+		#end
+	}
+
+	/**
+		Returns the process standard input, from which you can read what user enters. Usually it will block until the user send a full input line. See [getChar] for an alternative.
+	**/
+	public static function stdin() : haxe.io.Input
+	{
+#if !(Xbox || CF || MF)
+		return new cs.io.NativeInput(cs.system.Console.OpenStandardInput());
+#else
+		return null;
+#end
+	}
+
+	/**
+		Returns the process standard output on which you can write.
+	**/
+	public static function stdout() : haxe.io.Output
+	{
+#if !(Xbox || CF || MF)
+		return new cs.io.NativeOutput(cs.system.Console.OpenStandardOutput());
+#else
+		return null;
+#end
+	}
+
+	/**
+		Returns the process standard error on which you can write.
+	**/
+	public static function stderr() : haxe.io.Output
+	{
+#if !(Xbox || CF || MF)
+		return new cs.io.NativeOutput(cs.system.Console.OpenStandardError());
+#else
+		return null;
+#end
+	}
+
+}

+ 388 - 388
std/cs/_std/Type.hx

@@ -1,388 +1,388 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-import cs.Lib;
-import cs.internal.HxObject;
-import cs.internal.Runtime;
-/*
- * Copyright (c) 2005, The haXe Project Contributors
- * All rights reserved.
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- *   - Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- *   - Redistributions in binary form must reproduce the above copyright
- *     notice, this list of conditions and the following disclaimer in the
- *     documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- */
-
-@:keep enum ValueType {
-	TNull;
-	TInt;
-	TFloat;
-	TBool;
-	TObject;
-	TFunction;
-	TClass( c : Class<Dynamic> );
-	TEnum( e : Enum<Dynamic> );
-	TUnknown;
-}
-
-@:keep @:coreApi class Type {
-
-	@:functionCode('
-		if (o == null || o is haxe.lang.DynamicObject || o is System.Type)
-			return null;
-
-		return o.GetType();
-	')
-	public static function getClass<T>( o : T ) : Class<T> untyped
-	{
-		return null;
-	}
-
-	@:functionCode('
-		if (o is System.Enum || o is haxe.lang.Enum)
-			return o.GetType();
-		return null;
-	')
-	public static function getEnum( o : EnumValue ) : Enum<Dynamic> untyped
-	{
-		return null;
-	}
-
-	public static function getSuperClass( c : Class<Dynamic> ) : Class<Dynamic>
-	{
-		var t:cs.system.Type = Lib.toNativeType(c);
-		var base = t.BaseType;
-		if (base == null || (base + "") == ("haxe.lang.HxObject") || (base + "") == ("System.Object"))
-		{
-			return null;
-		}
-
-		return Lib.fromNativeType(base);
-	}
-
-	public static function getClassName( c : Class<Dynamic> ) : String {
-		var ret:String = cast Lib.toNativeType(c);
-#if no_root
-		if (ret.length > 10 && StringTools.startsWith(ret, "haxe.root."))
-			ret = ret.substr(10);
-#end
-
-		return switch(ret)
-		{
-			case "System.Int32": "Int";
-			case "System.Double": "Float";
-			case "System.String": "String";
-			case "System.Object": "Dynamic";
-			case "System.Type": "Class";
-			default: ret.split("`")[0];
-		}
-	}
-
-	public static function getEnumName( e : Enum<Dynamic> ) : String
-	{
-		var ret:String = cast Lib.toNativeType(untyped e);
-#if no_root
-		if (ret.length > 10 && StringTools.startsWith(ret, "haxe.root."))
-			ret = ret.substr(10);
-#end
-		if (ret.length == 14 && ret == "System.Boolean")
-			return "Bool";
-		return ret;
-	}
-
-	public static function resolveClass( name : String ) : Class<Dynamic>
-	{
-#if no_root
-		if (name.indexOf(".") == -1)
-			name = "haxe.root." + name;
-#end
-		var t:cs.system.Type = cs.system.Type.GetType(name);
-		if (t == null)
-		{
-			switch(name)
-			{
-				case #if no_root "haxe.root.Int" #else "Int" #end: return cast Int;
-				case #if no_root "haxe.root.Float" #else "Float" #end: return cast Float;
-				case #if no_root "haxe.root.Class" #else "Class" #end: return cast Class;
-				case #if no_root "haxe.root.Dynamic" #else "Dynamic" #end: return cast Dynamic;
-				case #if no_root "haxe.root.String" #else "String" #end: return cast String;
-				default: return null;
-			}
-		} else if (t.IsInterface && cast(untyped __typeof__(IGenericObject), cs.system.Type).IsAssignableFrom(t)) {
-			t = null;
-			var i = 0;
-			var ts = "";
-			while (t == null && i < 18)
-			{
-				i++;
-				ts += (i == 1 ? "" : ",") + "System.Object";
-				t = cs.system.Type.GetType(name + "`" + i + "[" + ts + "]");
-			}
-
-			return Lib.fromNativeType(t);
-		} else {
-			return Lib.fromNativeType(t);
-		}
-	}
-
-	@:functionCode('
-		if (name == "Bool") return typeof(bool);
-		System.Type t = resolveClass(name);
-		if (t != null && (t.BaseType.Equals(typeof(System.Enum)) || t.BaseType.Equals(typeof(haxe.lang.Enum))))
-			return t;
-		return null;
-	')
-	public static function resolveEnum( name : String ) : Enum<Dynamic> untyped
-	{
-		if (name == "Bool") return Bool;
-		return cast resolveClass(name);
-	}
-
-	public static function createInstance<T>( cl : Class<T>, args : Array<Dynamic> ) : T
-	{
-		if (untyped cl == String)
-			return args[0];
-		var t:cs.system.Type = Lib.toNativeType(cl);
-		if (t.IsInterface)
-		{
-			//may be generic
-			t = Lib.toNativeType(resolveClass(getClassName(cl)));
-		}
-		var ctors = t.GetConstructors();
-		return Runtime.callMethod(null, cast ctors, ctors.Length, args);
-	}
-
-	public static function createEmptyInstance<T>( cl : Class<T> ) : T
-	{
-		var t:cs.system.Type = Lib.toNativeType(cl);
-		if (t.IsInterface)
-		{
-			//may be generic
-			t = Lib.toNativeType(resolveClass(getClassName(cl)));
-		}
-
-		if (Reflect.hasField(cl, "__hx_createEmpty"))
-			return untyped cl.__hx_createEmpty();
-		return createInstance(cl, []);
-	}
-
-	@:functionCode('
-		if (@params == null || @params[0] == null)
-		{
-			object ret = haxe.lang.Runtime.slowGetField(e, constr, true);
-			if (ret is haxe.lang.Function)
-				throw haxe.lang.HaxeException.wrap("Constructor " + constr + " needs parameters");
-			return (T) ret;
-		} else {
-			return (T) haxe.lang.Runtime.slowCallField(e, constr, @params);
-		}
-	')
-	public static function createEnum<T>( e : Enum<T>, constr : String, ?params : Array<Dynamic> ) : T
-	{
-		return null;
-	}
-
-	public static function createEnumIndex<T>( e : Enum<T>, index : Int, ?params : Array<Dynamic> ) : T {
-		var constr = getEnumConstructs(e);
-		return createEnum(e, constr[index], params);
-	}
-
-	@:functionCode('
-		if (c == typeof(string))
-		{
-			return haxe.lang.StringRefl.fields;
-		}
-
-		Array<object> ret = new Array<object>();
-
-        System.Reflection.MemberInfo[] mis = c.GetMembers(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.FlattenHierarchy);
-        for (int i = 0; i < mis.Length; i++)
-        {
-			if (mis[i] is System.Reflection.PropertyInfo)
-                continue;
-			string n = mis[i].Name;
-			if (!n.StartsWith("__hx_") && n[0] != \'.\' && !n.Equals("Equals") && !n.Equals("ToString") && !n.Equals("GetHashCode") && !n.Equals("GetType"))
-				ret.push(mis[i].Name);
-        }
-
-		return ret;
-	')
-	public static function getInstanceFields( c : Class<Dynamic> ) : Array<String> {
-		return null;
-	}
-
-	@:functionCode('
-		Array<object> ret = new Array<object>();
-
-		if (c == typeof(string))
-		{
-			ret.push("fromCharCode");
-			return ret;
-		}
-
-        System.Reflection.MemberInfo[] mis = c.GetMembers(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
-        for (int i = 0; i < mis.Length; i++)
-        {
-            string n = mis[i].Name;
-			if (!n.StartsWith("__hx_"))
-				ret.push(mis[i].Name);
-        }
-
-        return ret;
-	')
-	public static function getClassFields( c : Class<Dynamic> ) : Array<String> {
-		return null;
-	}
-
-	public static function getEnumConstructs( e : Enum<Dynamic> ) : Array<String> {
-		if (Reflect.hasField(e, "constructs"))
-			return untyped e.constructs.copy();
-		return untyped __cs__("new Array<object>(System.Enum.GetNames(e))");
-	}
-
-	@:functionCode('
-		if (v == null) return ValueType.TNull;
-
-        System.Type t = v as System.Type;
-        if (t != null)
-        {
-            //class type
-            return ValueType.TObject;
-        }
-
-        t = v.GetType();
-        if (t.IsEnum)
-            return ValueType.TEnum(t);
-        if (t.IsValueType)
-        {
-            System.IConvertible vc = v as System.IConvertible;
-            if (vc != null)
-            {
-                switch (vc.GetTypeCode())
-                {
-                    case System.TypeCode.Boolean: return ValueType.TBool;
-                    case System.TypeCode.Double:
-						double d = vc.ToDouble(null);
-						if (d >= int.MinValue && d <= int.MaxValue && d == vc.ToInt32(null))
-							return ValueType.TInt;
-						else
-							return ValueType.TFloat;
-                    case System.TypeCode.Int32:
-                        return ValueType.TInt;
-                    default:
-                        return ValueType.TClass(t);
-                }
-            } else {
-                return ValueType.TClass(t);
-            }
-        }
-
-        if (v is haxe.lang.IHxObject)
-        {
-            if (v is haxe.lang.DynamicObject)
-                return ValueType.TObject;
-            else if (v is haxe.lang.Enum)
-                return ValueType.TEnum(t);
-            return ValueType.TClass(t);
-        } else if (v is haxe.lang.Function) {
-            return ValueType.TFunction;
-        } else {
-            return ValueType.TClass(t);
-        }
-	')
-	public static function typeof( v : Dynamic ) : ValueType
-	{
-		return null;
-	}
-
-	@:functionCode('
-			if (a is haxe.lang.Enum)
-				return a.Equals(b);
-			else
-				return haxe.lang.Runtime.eq(a, b);
-	')
-	public static function enumEq<T>( a : T, b : T ) : Bool
-	{
-		return untyped a.Equals(b);
-	}
-
-	@:functionCode('
-		if (e is System.Enum)
-			return e + "";
-		else
-			return ((haxe.lang.Enum) e).getTag();
-	')
-	public static function enumConstructor( e : EnumValue ) : String untyped
-	{
-		return e.tag;
-	}
-
-	@:functionCode('
-		return ( e is System.Enum ) ? new Array<object>() : ((haxe.lang.Enum) e).@params;
-	')
-	public static function enumParameters( e : EnumValue ) : Array<Dynamic> untyped
-	{
-		return null;
-	}
-
-	@:functionCode('
-		if (e is System.Enum)
-			return ((System.IConvertible) e).ToInt32(null);
-		else
-			return ((haxe.lang.Enum) e).index;
-	')
-	public static function enumIndex( e : EnumValue ) : Int  untyped
-	{
-		return e.index;
-	}
-
-	public static function allEnums<T>( e : Enum<T> ) : Array<T>
-	{
-		var ctors = getEnumConstructs(e);
-		var ret = [];
-		for (ctor in ctors)
-		{
-			var v = Reflect.field(e, ctor);
-			if (Std.is(v, e))
-				ret.push(v);
-		}
-
-		return ret;
-	}
-
-}
-
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+import cs.Lib;
+import cs.internal.HxObject;
+import cs.internal.Runtime;
+/*
+ * Copyright (c) 2005, The haXe Project Contributors
+ * All rights reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   - Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   - Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ */
+
+@:keep enum ValueType {
+	TNull;
+	TInt;
+	TFloat;
+	TBool;
+	TObject;
+	TFunction;
+	TClass( c : Class<Dynamic> );
+	TEnum( e : Enum<Dynamic> );
+	TUnknown;
+}
+
+@:keep @:coreApi class Type {
+
+	@:functionCode('
+		if (o == null || o is haxe.lang.DynamicObject || o is System.Type)
+			return null;
+
+		return o.GetType();
+	')
+	public static function getClass<T>( o : T ) : Class<T> untyped
+	{
+		return null;
+	}
+
+	@:functionCode('
+		if (o is System.Enum || o is haxe.lang.Enum)
+			return o.GetType();
+		return null;
+	')
+	public static function getEnum( o : EnumValue ) : Enum<Dynamic> untyped
+	{
+		return null;
+	}
+
+	public static function getSuperClass( c : Class<Dynamic> ) : Class<Dynamic>
+	{
+		var t:cs.system.Type = Lib.toNativeType(c);
+		var base = t.BaseType;
+		if (base == null || (base + "") == ("haxe.lang.HxObject") || (base + "") == ("System.Object"))
+		{
+			return null;
+		}
+
+		return Lib.fromNativeType(base);
+	}
+
+	public static function getClassName( c : Class<Dynamic> ) : String {
+		var ret:String = cast Lib.toNativeType(c);
+#if no_root
+		if (ret.length > 10 && StringTools.startsWith(ret, "haxe.root."))
+			ret = ret.substr(10);
+#end
+
+		return switch(ret)
+		{
+			case "System.Int32": "Int";
+			case "System.Double": "Float";
+			case "System.String": "String";
+			case "System.Object": "Dynamic";
+			case "System.Type": "Class";
+			default: ret.split("`")[0];
+		}
+	}
+
+	public static function getEnumName( e : Enum<Dynamic> ) : String
+	{
+		var ret:String = cast Lib.toNativeType(untyped e);
+#if no_root
+		if (ret.length > 10 && StringTools.startsWith(ret, "haxe.root."))
+			ret = ret.substr(10);
+#end
+		if (ret.length == 14 && ret == "System.Boolean")
+			return "Bool";
+		return ret;
+	}
+
+	public static function resolveClass( name : String ) : Class<Dynamic>
+	{
+#if no_root
+		if (name.indexOf(".") == -1)
+			name = "haxe.root." + name;
+#end
+		var t:cs.system.Type = cs.system.Type.GetType(name);
+		if (t == null)
+		{
+			switch(name)
+			{
+				case #if no_root "haxe.root.Int" #else "Int" #end: return cast Int;
+				case #if no_root "haxe.root.Float" #else "Float" #end: return cast Float;
+				case #if no_root "haxe.root.Class" #else "Class" #end: return cast Class;
+				case #if no_root "haxe.root.Dynamic" #else "Dynamic" #end: return cast Dynamic;
+				case #if no_root "haxe.root.String" #else "String" #end: return cast String;
+				default: return null;
+			}
+		} else if (t.IsInterface && cast(untyped __typeof__(IGenericObject), cs.system.Type).IsAssignableFrom(t)) {
+			t = null;
+			var i = 0;
+			var ts = "";
+			while (t == null && i < 18)
+			{
+				i++;
+				ts += (i == 1 ? "" : ",") + "System.Object";
+				t = cs.system.Type.GetType(name + "`" + i + "[" + ts + "]");
+			}
+
+			return Lib.fromNativeType(t);
+		} else {
+			return Lib.fromNativeType(t);
+		}
+	}
+
+	@:functionCode('
+		if (name == "Bool") return typeof(bool);
+		System.Type t = resolveClass(name);
+		if (t != null && (t.BaseType.Equals(typeof(System.Enum)) || t.BaseType.Equals(typeof(haxe.lang.Enum))))
+			return t;
+		return null;
+	')
+	public static function resolveEnum( name : String ) : Enum<Dynamic> untyped
+	{
+		if (name == "Bool") return Bool;
+		return cast resolveClass(name);
+	}
+
+	public static function createInstance<T>( cl : Class<T>, args : Array<Dynamic> ) : T
+	{
+		if (untyped cl == String)
+			return args[0];
+		var t:cs.system.Type = Lib.toNativeType(cl);
+		if (t.IsInterface)
+		{
+			//may be generic
+			t = Lib.toNativeType(resolveClass(getClassName(cl)));
+		}
+		var ctors = t.GetConstructors();
+		return Runtime.callMethod(null, cast ctors, ctors.Length, args);
+	}
+
+	public static function createEmptyInstance<T>( cl : Class<T> ) : T
+	{
+		var t:cs.system.Type = Lib.toNativeType(cl);
+		if (t.IsInterface)
+		{
+			//may be generic
+			t = Lib.toNativeType(resolveClass(getClassName(cl)));
+		}
+
+		if (Reflect.hasField(cl, "__hx_createEmpty"))
+			return untyped cl.__hx_createEmpty();
+		return createInstance(cl, []);
+	}
+
+	@:functionCode('
+		if (@params == null || @params[0] == null)
+		{
+			object ret = haxe.lang.Runtime.slowGetField(e, constr, true);
+			if (ret is haxe.lang.Function)
+				throw haxe.lang.HaxeException.wrap("Constructor " + constr + " needs parameters");
+			return (T) ret;
+		} else {
+			return (T) haxe.lang.Runtime.slowCallField(e, constr, @params);
+		}
+	')
+	public static function createEnum<T>( e : Enum<T>, constr : String, ?params : Array<Dynamic> ) : T
+	{
+		return null;
+	}
+
+	public static function createEnumIndex<T>( e : Enum<T>, index : Int, ?params : Array<Dynamic> ) : T {
+		var constr = getEnumConstructs(e);
+		return createEnum(e, constr[index], params);
+	}
+
+	@:functionCode('
+		if (c == typeof(string))
+		{
+			return haxe.lang.StringRefl.fields;
+		}
+
+		Array<object> ret = new Array<object>();
+
+        System.Reflection.MemberInfo[] mis = c.GetMembers(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.FlattenHierarchy);
+        for (int i = 0; i < mis.Length; i++)
+        {
+			if (mis[i] is System.Reflection.PropertyInfo)
+                continue;
+			string n = mis[i].Name;
+			if (!n.StartsWith("__hx_") && n[0] != \'.\' && !n.Equals("Equals") && !n.Equals("ToString") && !n.Equals("GetHashCode") && !n.Equals("GetType"))
+				ret.push(mis[i].Name);
+        }
+
+		return ret;
+	')
+	public static function getInstanceFields( c : Class<Dynamic> ) : Array<String> {
+		return null;
+	}
+
+	@:functionCode('
+		Array<object> ret = new Array<object>();
+
+		if (c == typeof(string))
+		{
+			ret.push("fromCharCode");
+			return ret;
+		}
+
+        System.Reflection.MemberInfo[] mis = c.GetMembers(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
+        for (int i = 0; i < mis.Length; i++)
+        {
+            string n = mis[i].Name;
+			if (!n.StartsWith("__hx_"))
+				ret.push(mis[i].Name);
+        }
+
+        return ret;
+	')
+	public static function getClassFields( c : Class<Dynamic> ) : Array<String> {
+		return null;
+	}
+
+	public static function getEnumConstructs( e : Enum<Dynamic> ) : Array<String> {
+		if (Reflect.hasField(e, "constructs"))
+			return untyped e.constructs.copy();
+		return untyped __cs__("new Array<object>(System.Enum.GetNames(e))");
+	}
+
+	@:functionCode('
+		if (v == null) return ValueType.TNull;
+
+        System.Type t = v as System.Type;
+        if (t != null)
+        {
+            //class type
+            return ValueType.TObject;
+        }
+
+        t = v.GetType();
+        if (t.IsEnum)
+            return ValueType.TEnum(t);
+        if (t.IsValueType)
+        {
+            System.IConvertible vc = v as System.IConvertible;
+            if (vc != null)
+            {
+                switch (vc.GetTypeCode())
+                {
+                    case System.TypeCode.Boolean: return ValueType.TBool;
+                    case System.TypeCode.Double:
+						double d = vc.ToDouble(null);
+						if (d >= int.MinValue && d <= int.MaxValue && d == vc.ToInt32(null))
+							return ValueType.TInt;
+						else
+							return ValueType.TFloat;
+                    case System.TypeCode.Int32:
+                        return ValueType.TInt;
+                    default:
+                        return ValueType.TClass(t);
+                }
+            } else {
+                return ValueType.TClass(t);
+            }
+        }
+
+        if (v is haxe.lang.IHxObject)
+        {
+            if (v is haxe.lang.DynamicObject)
+                return ValueType.TObject;
+            else if (v is haxe.lang.Enum)
+                return ValueType.TEnum(t);
+            return ValueType.TClass(t);
+        } else if (v is haxe.lang.Function) {
+            return ValueType.TFunction;
+        } else {
+            return ValueType.TClass(t);
+        }
+	')
+	public static function typeof( v : Dynamic ) : ValueType
+	{
+		return null;
+	}
+
+	@:functionCode('
+			if (a is haxe.lang.Enum)
+				return a.Equals(b);
+			else
+				return haxe.lang.Runtime.eq(a, b);
+	')
+	public static function enumEq<T>( a : T, b : T ) : Bool
+	{
+		return untyped a.Equals(b);
+	}
+
+	@:functionCode('
+		if (e is System.Enum)
+			return e + "";
+		else
+			return ((haxe.lang.Enum) e).getTag();
+	')
+	public static function enumConstructor( e : EnumValue ) : String untyped
+	{
+		return e.tag;
+	}
+
+	@:functionCode('
+		return ( e is System.Enum ) ? new Array<object>() : ((haxe.lang.Enum) e).@params;
+	')
+	public static function enumParameters( e : EnumValue ) : Array<Dynamic> untyped
+	{
+		return null;
+	}
+
+	@:functionCode('
+		if (e is System.Enum)
+			return ((System.IConvertible) e).ToInt32(null);
+		else
+			return ((haxe.lang.Enum) e).index;
+	')
+	public static function enumIndex( e : EnumValue ) : Int  untyped
+	{
+		return e.index;
+	}
+
+	public static function allEnums<T>( e : Enum<T> ) : Array<T>
+	{
+		var ctors = getEnumConstructs(e);
+		var ret = [];
+		for (ctor in ctors)
+		{
+			var v = Reflect.field(e, ctor);
+			if (Std.is(v, e))
+				ret.push(v);
+		}
+
+		return ret;
+	}
+
+}
+

+ 345 - 345
std/cs/_std/Xml.hx

@@ -1,345 +1,345 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-@:native("_Xml.RealXmlType")
-extern enum XmlType {
-}
-
-private enum RealXmlType {
-        Element;
-        PCData;
-        CData;
-        Comment;
-        DocType;
-        ProcessingInstruction;
-        Document;
-}
-
-@:coreApi class Xml {
-
-	public static var Element(default,null) : XmlType;
-	public static var PCData(default,null) : XmlType;
-	public static var CData(default,null) : XmlType;
-	public static var Comment(default,null) : XmlType;
-	public static var DocType(default,null) : XmlType;
-	public static var ProcessingInstruction(default,null) : XmlType;
-	public static var Document(default,null) : XmlType;
-
-	public var nodeType(default,null) : XmlType;
-	public var nodeName(get,set) : String;
-	public var nodeValue(get,set) : String;
-	public var parent(get,null) : Xml;
-
-	var _nodeName : String;
-	var _nodeValue : String;
-	var _attributes : haxe.ds.StringMap<String>;
-	var _children : Array<Xml>;
-	var _parent : Xml;
-
-	public static function parse( str : String ) : Xml {
-		return haxe.xml.Parser.parse(str);
-	}
-
-	private function new() : Void {
-	}
-
-	public static function createElement( name : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.Element;
-		r._children = new Array();
-		r._attributes = new haxe.ds.StringMap();
-		r.set_nodeName( name );
-		return r;
-	}
-
-	public static function createPCData( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.PCData;
-		r.set_nodeValue( data );
-		return r;
-	}
-
-	public static function createCData( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.CData;
-		r.set_nodeValue( data );
-		return r;
-	}
-
-	public static function createComment( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.Comment;
-		r.set_nodeValue( data );
-		return r;
-	}
-
-	public static function createDocType( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.DocType;
-		r.set_nodeValue( data );
-		return r;
-	}
-
-	public static function createProcessingInstruction( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.ProcessingInstruction;
-		r.set_nodeValue( data );
-		return r;
-	}
-
-	public static function createDocument() : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.Document;
-		r._children = new Array();
-		return r;
-	}
-
-	private function get_nodeName() : String {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return _nodeName;
-	}
-
-	private function set_nodeName( n : String ) : String {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return _nodeName = n;
-	}
-
-	private function get_nodeValue() : String {
-		if( nodeType == Xml.Element || nodeType == Xml.Document )
-			throw "bad nodeType";
-		return _nodeValue;
-	}
-
-	private function set_nodeValue( v : String ) : String {
-		if( nodeType == Xml.Element || nodeType == Xml.Document )
-			throw "bad nodeType";
-		return _nodeValue = v;
-	}
-
-	private function get_parent() : Xml {
-		return _parent;
-	}
-
-	public function get( att : String ) : String {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return _attributes.get( att );
-	}
-
-	public function set( att : String, value : String ) : Void {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		_attributes.set( att, value );
-	}
-
-	public function remove( att : String ) : Void{
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		_attributes.remove( att );
-	}
-
-	public function exists( att : String ) : Bool {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return _attributes.exists( att );
-	}
-
-	public function attributes() : Iterator<String> {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return _attributes.keys();
-	}
-
-	public function iterator() : Iterator<Xml> {
-		if ( _children == null ) throw "bad nodetype";
-		var cur = 0;
-		var x = this._children;
-		return {
-			hasNext : function(){
-				return cur < x.length;
-			},
-			next : function(){
-				return x[cur++];
-			}
-		}
-	}
-
-	public function elements() : Iterator<Xml> {
-		if ( _children == null ) throw "bad nodetype";
-		var cur = 0;
-		var x = _children;
-		return untyped {
-			hasNext : function() {
-				var k = cur;
-				var l = x.length;
-				while( k < l ) {
-					if( x[k].nodeType == Xml.Element )
-						break;
-					k += 1;
-				}
-				cur = k;
-				return k < l;
-			},
-			next : function() {
-				var k = cur;
-				var l = x.length;
-				while( k < l ) {
-					var n = x[k];
-					k += 1;
-					if( n.nodeType == Xml.Element ) {
-						cur = k;
-						return n;
-					}
-				}
-				return null;
-			}
-		}
-	}
-
-	public function elementsNamed( name : String ) : Iterator<Xml> {
-		if ( _children == null ) throw "bad nodetype";
-		var x = _children;
-		var cur = 0;
-		return untyped {
-			cur: 0,
-			x: this._children,
-			hasNext : function() {
-				var k = cur;
-				var l = x.length;
-				while( k < l ) {
-					var n = x[k];
-					if( n.nodeType == Xml.Element && n._nodeName == name )
-						break;
-					k++;
-				}
-				cur = k;
-				return k < l;
-			},
-			next : function() {
-				var k = cur;
-				var l = x.length;
-				while( k < l ) {
-					var n = x[k];
-					k++;
-					if( n.nodeType == Xml.Element && n._nodeName == name ) {
-						cur = k;
-						return n;
-					}
-				}
-				return null;
-			}
-		}
-	}
-
-	public function firstChild() : Xml {
-		if( _children == null ) throw "bad nodetype";
-		return _children[0];
-	}
-
-	public function firstElement() : Xml {
-		if( _children == null ) throw "bad nodetype";
-		var cur = 0;
-		var l = _children.length;
-		while( cur < l ) {
-			var n = _children[cur];
-			if( n.nodeType == Xml.Element )
-				return n;
-			cur++;
-		}
-		return null;
-	}
-
-	public function addChild( x : Xml ) : Void {
-		if( _children == null ) throw "bad nodetype";
-		if( x._parent != null ) x._parent._children.remove(x);
-		x._parent = this;
-		_children.push( x );
-	}
-
-	public function removeChild( x : Xml ) : Bool {
-		if( _children == null ) throw "bad nodetype";
-		var b = _children.remove( x );
-		if( b )
-			x._parent = null;
-		return b;
-	}
-
-	public function insertChild( x : Xml, pos : Int ) : Void {
-		if( _children == null ) throw "bad nodetype";
-		if( x._parent != null ) x._parent._children.remove(x);
-		x._parent = this;
-		_children.insert( pos, x );
-	}
-
-	public function toString() : String {
-		if( nodeType == Xml.PCData )
-			return StringTools.htmlEscape(_nodeValue);
-		if( nodeType == Xml.CData )
-			return "<![CDATA["+_nodeValue+"]]>";
-		if( nodeType == Xml.Comment )
-			return "<!--"+_nodeValue+"-->";
-		if( nodeType == Xml.DocType )
-			return "<!DOCTYPE "+_nodeValue+">";
-		if( nodeType == Xml.ProcessingInstruction )
-			return "<?"+_nodeValue+"?>";
-		var s = new StringBuf();
-
-		if( nodeType == Xml.Element ) {
-			s.add("<");
-			s.add(_nodeName);
-			for( k in _attributes.keys() ){
-				s.add(" ");
-				s.add(k);
-				s.add("=\"");
-				s.add(_attributes.get(k));
-				s.add("\"");
-			}
-			if( _children.length == 0 ) {
-				s.add("/>");
-				return s.toString();
-			}
-			s.add(">");
-		}
-
-		for( x in iterator() )
-			s.add(x.toString());
-
-		if( nodeType == Xml.Element ) {
-			s.add("</");
-			s.add(_nodeName);
-			s.add(">");
-		}
-		return s.toString();
-	}
-
-	static function __init__() : Void untyped {
-		Xml.Element = cast RealXmlType.Element;
-		Xml.PCData = cast RealXmlType.PCData;
-		Xml.CData = cast RealXmlType.CData;
-		Xml.Comment = cast RealXmlType.Comment;
-		Xml.DocType = cast RealXmlType.DocType;
-		Xml.ProcessingInstruction = cast RealXmlType.ProcessingInstruction;
-		Xml.Document = cast RealXmlType.Document;
-	}
-
-}
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+@:native("_Xml.RealXmlType")
+extern enum XmlType {
+}
+
+private enum RealXmlType {
+        Element;
+        PCData;
+        CData;
+        Comment;
+        DocType;
+        ProcessingInstruction;
+        Document;
+}
+
+@:coreApi class Xml {
+
+	public static var Element(default,null) : XmlType;
+	public static var PCData(default,null) : XmlType;
+	public static var CData(default,null) : XmlType;
+	public static var Comment(default,null) : XmlType;
+	public static var DocType(default,null) : XmlType;
+	public static var ProcessingInstruction(default,null) : XmlType;
+	public static var Document(default,null) : XmlType;
+
+	public var nodeType(default,null) : XmlType;
+	public var nodeName(get,set) : String;
+	public var nodeValue(get,set) : String;
+	public var parent(get,null) : Xml;
+
+	var _nodeName : String;
+	var _nodeValue : String;
+	var _attributes : haxe.ds.StringMap<String>;
+	var _children : Array<Xml>;
+	var _parent : Xml;
+
+	public static function parse( str : String ) : Xml {
+		return haxe.xml.Parser.parse(str);
+	}
+
+	private function new() : Void {
+	}
+
+	public static function createElement( name : String ) : Xml {
+		var r = new Xml();
+		r.nodeType = Xml.Element;
+		r._children = new Array();
+		r._attributes = new haxe.ds.StringMap();
+		r.set_nodeName( name );
+		return r;
+	}
+
+	public static function createPCData( data : String ) : Xml {
+		var r = new Xml();
+		r.nodeType = Xml.PCData;
+		r.set_nodeValue( data );
+		return r;
+	}
+
+	public static function createCData( data : String ) : Xml {
+		var r = new Xml();
+		r.nodeType = Xml.CData;
+		r.set_nodeValue( data );
+		return r;
+	}
+
+	public static function createComment( data : String ) : Xml {
+		var r = new Xml();
+		r.nodeType = Xml.Comment;
+		r.set_nodeValue( data );
+		return r;
+	}
+
+	public static function createDocType( data : String ) : Xml {
+		var r = new Xml();
+		r.nodeType = Xml.DocType;
+		r.set_nodeValue( data );
+		return r;
+	}
+
+	public static function createProcessingInstruction( data : String ) : Xml {
+		var r = new Xml();
+		r.nodeType = Xml.ProcessingInstruction;
+		r.set_nodeValue( data );
+		return r;
+	}
+
+	public static function createDocument() : Xml {
+		var r = new Xml();
+		r.nodeType = Xml.Document;
+		r._children = new Array();
+		return r;
+	}
+
+	private function get_nodeName() : String {
+		if( nodeType != Xml.Element )
+			throw "bad nodeType";
+		return _nodeName;
+	}
+
+	private function set_nodeName( n : String ) : String {
+		if( nodeType != Xml.Element )
+			throw "bad nodeType";
+		return _nodeName = n;
+	}
+
+	private function get_nodeValue() : String {
+		if( nodeType == Xml.Element || nodeType == Xml.Document )
+			throw "bad nodeType";
+		return _nodeValue;
+	}
+
+	private function set_nodeValue( v : String ) : String {
+		if( nodeType == Xml.Element || nodeType == Xml.Document )
+			throw "bad nodeType";
+		return _nodeValue = v;
+	}
+
+	private function get_parent() : Xml {
+		return _parent;
+	}
+
+	public function get( att : String ) : String {
+		if( nodeType != Xml.Element )
+			throw "bad nodeType";
+		return _attributes.get( att );
+	}
+
+	public function set( att : String, value : String ) : Void {
+		if( nodeType != Xml.Element )
+			throw "bad nodeType";
+		_attributes.set( att, value );
+	}
+
+	public function remove( att : String ) : Void{
+		if( nodeType != Xml.Element )
+			throw "bad nodeType";
+		_attributes.remove( att );
+	}
+
+	public function exists( att : String ) : Bool {
+		if( nodeType != Xml.Element )
+			throw "bad nodeType";
+		return _attributes.exists( att );
+	}
+
+	public function attributes() : Iterator<String> {
+		if( nodeType != Xml.Element )
+			throw "bad nodeType";
+		return _attributes.keys();
+	}
+
+	public function iterator() : Iterator<Xml> {
+		if ( _children == null ) throw "bad nodetype";
+		var cur = 0;
+		var x = this._children;
+		return {
+			hasNext : function(){
+				return cur < x.length;
+			},
+			next : function(){
+				return x[cur++];
+			}
+		}
+	}
+
+	public function elements() : Iterator<Xml> {
+		if ( _children == null ) throw "bad nodetype";
+		var cur = 0;
+		var x = _children;
+		return untyped {
+			hasNext : function() {
+				var k = cur;
+				var l = x.length;
+				while( k < l ) {
+					if( x[k].nodeType == Xml.Element )
+						break;
+					k += 1;
+				}
+				cur = k;
+				return k < l;
+			},
+			next : function() {
+				var k = cur;
+				var l = x.length;
+				while( k < l ) {
+					var n = x[k];
+					k += 1;
+					if( n.nodeType == Xml.Element ) {
+						cur = k;
+						return n;
+					}
+				}
+				return null;
+			}
+		}
+	}
+
+	public function elementsNamed( name : String ) : Iterator<Xml> {
+		if ( _children == null ) throw "bad nodetype";
+		var x = _children;
+		var cur = 0;
+		return untyped {
+			cur: 0,
+			x: this._children,
+			hasNext : function() {
+				var k = cur;
+				var l = x.length;
+				while( k < l ) {
+					var n = x[k];
+					if( n.nodeType == Xml.Element && n._nodeName == name )
+						break;
+					k++;
+				}
+				cur = k;
+				return k < l;
+			},
+			next : function() {
+				var k = cur;
+				var l = x.length;
+				while( k < l ) {
+					var n = x[k];
+					k++;
+					if( n.nodeType == Xml.Element && n._nodeName == name ) {
+						cur = k;
+						return n;
+					}
+				}
+				return null;
+			}
+		}
+	}
+
+	public function firstChild() : Xml {
+		if( _children == null ) throw "bad nodetype";
+		return _children[0];
+	}
+
+	public function firstElement() : Xml {
+		if( _children == null ) throw "bad nodetype";
+		var cur = 0;
+		var l = _children.length;
+		while( cur < l ) {
+			var n = _children[cur];
+			if( n.nodeType == Xml.Element )
+				return n;
+			cur++;
+		}
+		return null;
+	}
+
+	public function addChild( x : Xml ) : Void {
+		if( _children == null ) throw "bad nodetype";
+		if( x._parent != null ) x._parent._children.remove(x);
+		x._parent = this;
+		_children.push( x );
+	}
+
+	public function removeChild( x : Xml ) : Bool {
+		if( _children == null ) throw "bad nodetype";
+		var b = _children.remove( x );
+		if( b )
+			x._parent = null;
+		return b;
+	}
+
+	public function insertChild( x : Xml, pos : Int ) : Void {
+		if( _children == null ) throw "bad nodetype";
+		if( x._parent != null ) x._parent._children.remove(x);
+		x._parent = this;
+		_children.insert( pos, x );
+	}
+
+	public function toString() : String {
+		if( nodeType == Xml.PCData )
+			return StringTools.htmlEscape(_nodeValue);
+		if( nodeType == Xml.CData )
+			return "<![CDATA["+_nodeValue+"]]>";
+		if( nodeType == Xml.Comment )
+			return "<!--"+_nodeValue+"-->";
+		if( nodeType == Xml.DocType )
+			return "<!DOCTYPE "+_nodeValue+">";
+		if( nodeType == Xml.ProcessingInstruction )
+			return "<?"+_nodeValue+"?>";
+		var s = new StringBuf();
+
+		if( nodeType == Xml.Element ) {
+			s.add("<");
+			s.add(_nodeName);
+			for( k in _attributes.keys() ){
+				s.add(" ");
+				s.add(k);
+				s.add("=\"");
+				s.add(_attributes.get(k));
+				s.add("\"");
+			}
+			if( _children.length == 0 ) {
+				s.add("/>");
+				return s.toString();
+			}
+			s.add(">");
+		}
+
+		for( x in iterator() )
+			s.add(x.toString());
+
+		if( nodeType == Xml.Element ) {
+			s.add("</");
+			s.add(_nodeName);
+			s.add(">");
+		}
+		return s.toString();
+	}
+
+	static function __init__() : Void untyped {
+		Xml.Element = cast RealXmlType.Element;
+		Xml.PCData = cast RealXmlType.PCData;
+		Xml.CData = cast RealXmlType.CData;
+		Xml.Comment = cast RealXmlType.Comment;
+		Xml.DocType = cast RealXmlType.DocType;
+		Xml.ProcessingInstruction = cast RealXmlType.ProcessingInstruction;
+		Xml.Document = cast RealXmlType.Document;
+	}
+
+}

+ 146 - 146
std/cs/_std/haxe/Int64.hx

@@ -1,146 +1,146 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package haxe;
-using haxe.Int64;
-@:coreType @:notNull @:runtimeValue private abstract NativeInt64 from Int to Int {}
-@:coreType @:notNull @:runtimeValue private abstract NativeUInt64 from Int to Int {}
-
-@:coreApi
-@:nativeGen class Int64
-{
-	@:extern private static inline function asNative(i:Int64):NativeInt64 return untyped i;
-	@:extern private static inline function ofNative(i:NativeInt64):Int64 return untyped i;
-	@:extern private static inline function mkNative(i:Dynamic):NativeInt64 return i;
-
-	public static inline function make( high : Int, low : Int ) : Int64
-	{
-		return ((cast(high, NativeInt64) << 32 ) | (low & untyped __cs__('0xffffffffL'))).ofNative();
-	}
-
-	public static inline function getLow( x : Int64 ) : Int
-	{
-		return cast (x.asNative() & (untyped __cs__("0xFFFFFFFFL")), Int);
-	}
-
-	public static inline function getHigh( x : Int64 ) : Int {
-		return cast(cast(x,NativeUInt64) >> 32, Int);
-	}
-
-	public static inline function ofInt( x : Int ) : Int64 {
-		return cast x;
-	}
-
-	public static inline function toInt( x : Int64 ) : Int
-	{
-		return cast x;
-	}
-
-	public static inline function add( a : Int64, b : Int64 ) : Int64
-	{
-		return (a.asNative() + b.asNative()).ofNative();
-	}
-
-	public static inline function sub( a : Int64, b : Int64 ) : Int64
-	{
-		return (a.asNative() - b.asNative()).ofNative();
-	}
-
-	public static inline function mul( a : Int64, b : Int64 ) : Int64 {
-		return (a.asNative() * b.asNative()).ofNative();
-	}
-
-	static function divMod( modulus : Int64, divisor : Int64 ) : { quotient : Int64, modulus : Int64 }
-	{
-		var q:Int64 = (modulus.asNative() / divisor.asNative()).mkNative().ofNative();
-		var m:Int64 = (modulus.asNative() % divisor.asNative()).mkNative().ofNative();
-		return { quotient : q, modulus : m };
-	}
-
-	public static inline function div( a : Int64, b : Int64 ) : Int64 {
-		return (a.asNative() / b.asNative()).mkNative().ofNative();
-	}
-
-	public static inline function mod( a : Int64, b : Int64 ) : Int64 {
-		return (a.asNative() % b.asNative()).mkNative().ofNative();
-	}
-
-	public static inline function shl( a : Int64, b : Int ) : Int64 {
-		return (a.asNative() << b).ofNative();
-	}
-
-	public static inline function shr( a : Int64, b : Int ) : Int64 {
-		return (a.asNative() >> b).ofNative();
-	}
-
-	public static inline function ushr( a : Int64, b : Int ) : Int64 {
-		return ( cast(a, NativeUInt64) >> b).ofNative();
-	}
-
-	public static inline function and( a : Int64, b : Int64 ) : Int64
-	{
-		return (a.asNative() & b.asNative()).ofNative();
-	}
-
-	public static inline function or( a : Int64, b : Int64 ) : Int64
-	{
-		return (a.asNative() | b.asNative()).ofNative();
-	}
-
-	public static inline function xor( a : Int64, b : Int64 ) : Int64
-	{
-		return (a.asNative() ^ b.asNative()).ofNative();
-	}
-
-	public static inline function neg( a : Int64 ) : Int64
-	{
-		return (~a.asNative()).ofNative();
-	}
-
-	public static inline function isNeg( a : Int64 ) : Bool
-	{
-		return (a.asNative() < 0.mkNative());
-	}
-
-	public static inline function isZero( a : Int64 ) : Bool
-	{
-		return (a.asNative() == 0.mkNative());
-	}
-
-	public static inline function compare( a : Int64, b : Int64 ) : Int
-	{
-		return cast (a.asNative() - b.asNative());
-	}
-
-	/**
-		Compare two Int64 in unsigned mode.
-	**/
-	public static function ucompare( a : Int64, b : Int64 ) : Int
-	{
-		if (a.asNative() < 0.mkNative())
-			return (b.asNative() < 0.mkNative()) ? compare( (~a.asNative()).ofNative(), (~b.asNative()).ofNative()) : 1;
-		return (b.asNative() < 0.mkNative()) ? -1 : compare(a, b);
-	}
-
-	public static inline function toStr( a : Int64 ) : String {
-		return a + "";
-	}
-}
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package haxe;
+using haxe.Int64;
+@:coreType @:notNull @:runtimeValue private abstract NativeInt64 from Int to Int {}
+@:coreType @:notNull @:runtimeValue private abstract NativeUInt64 from Int to Int {}
+
+@:coreApi
+@:nativeGen class Int64
+{
+	@:extern private static inline function asNative(i:Int64):NativeInt64 return untyped i;
+	@:extern private static inline function ofNative(i:NativeInt64):Int64 return untyped i;
+	@:extern private static inline function mkNative(i:Dynamic):NativeInt64 return i;
+
+	public static inline function make( high : Int, low : Int ) : Int64
+	{
+		return ((cast(high, NativeInt64) << 32 ) | (low & untyped __cs__('0xffffffffL'))).ofNative();
+	}
+
+	public static inline function getLow( x : Int64 ) : Int
+	{
+		return cast (x.asNative() & (untyped __cs__("0xFFFFFFFFL")), Int);
+	}
+
+	public static inline function getHigh( x : Int64 ) : Int {
+		return cast(cast(x,NativeUInt64) >> 32, Int);
+	}
+
+	public static inline function ofInt( x : Int ) : Int64 {
+		return cast x;
+	}
+
+	public static inline function toInt( x : Int64 ) : Int
+	{
+		return cast x;
+	}
+
+	public static inline function add( a : Int64, b : Int64 ) : Int64
+	{
+		return (a.asNative() + b.asNative()).ofNative();
+	}
+
+	public static inline function sub( a : Int64, b : Int64 ) : Int64
+	{
+		return (a.asNative() - b.asNative()).ofNative();
+	}
+
+	public static inline function mul( a : Int64, b : Int64 ) : Int64 {
+		return (a.asNative() * b.asNative()).ofNative();
+	}
+
+	static function divMod( modulus : Int64, divisor : Int64 ) : { quotient : Int64, modulus : Int64 }
+	{
+		var q:Int64 = (modulus.asNative() / divisor.asNative()).mkNative().ofNative();
+		var m:Int64 = (modulus.asNative() % divisor.asNative()).mkNative().ofNative();
+		return { quotient : q, modulus : m };
+	}
+
+	public static inline function div( a : Int64, b : Int64 ) : Int64 {
+		return (a.asNative() / b.asNative()).mkNative().ofNative();
+	}
+
+	public static inline function mod( a : Int64, b : Int64 ) : Int64 {
+		return (a.asNative() % b.asNative()).mkNative().ofNative();
+	}
+
+	public static inline function shl( a : Int64, b : Int ) : Int64 {
+		return (a.asNative() << b).ofNative();
+	}
+
+	public static inline function shr( a : Int64, b : Int ) : Int64 {
+		return (a.asNative() >> b).ofNative();
+	}
+
+	public static inline function ushr( a : Int64, b : Int ) : Int64 {
+		return ( cast(a, NativeUInt64) >> b).ofNative();
+	}
+
+	public static inline function and( a : Int64, b : Int64 ) : Int64
+	{
+		return (a.asNative() & b.asNative()).ofNative();
+	}
+
+	public static inline function or( a : Int64, b : Int64 ) : Int64
+	{
+		return (a.asNative() | b.asNative()).ofNative();
+	}
+
+	public static inline function xor( a : Int64, b : Int64 ) : Int64
+	{
+		return (a.asNative() ^ b.asNative()).ofNative();
+	}
+
+	public static inline function neg( a : Int64 ) : Int64
+	{
+		return (~a.asNative()).ofNative();
+	}
+
+	public static inline function isNeg( a : Int64 ) : Bool
+	{
+		return (a.asNative() < 0.mkNative());
+	}
+
+	public static inline function isZero( a : Int64 ) : Bool
+	{
+		return (a.asNative() == 0.mkNative());
+	}
+
+	public static inline function compare( a : Int64, b : Int64 ) : Int
+	{
+		return cast (a.asNative() - b.asNative());
+	}
+
+	/**
+		Compare two Int64 in unsigned mode.
+	**/
+	public static function ucompare( a : Int64, b : Int64 ) : Int
+	{
+		if (a.asNative() < 0.mkNative())
+			return (b.asNative() < 0.mkNative()) ? compare( (~a.asNative()).ofNative(), (~b.asNative()).ofNative()) : 1;
+		return (b.asNative() < 0.mkNative()) ? -1 : compare(a, b);
+	}
+
+	public static inline function toStr( a : Int64 ) : String {
+		return a + "";
+	}
+}

+ 156 - 156
std/cs/_std/sys/FileSystem.hx

@@ -1,157 +1,157 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package sys;
-import cs.system.io.DirectoryInfo;
-import cs.system.io.File;
-import cs.system.io.Directory;
-import cs.system.io.FileInfo;
-
-/**
-	This class allows you to get informations about the files and directories.
-**/
-@:coreApi
-class FileSystem {
-
-	/**
-		Tells if the given file or directory exists.
-	**/
-	public static function exists( path : String ) : Bool
-	{
-		return (File.Exists(path) || Directory.Exists(path));
-	}
-
-	/**
-		Rename the corresponding file or directory, allow to move it accross directories as well.
-	**/
-	public static function rename( path : String, newpath : String ) : Void
-	{
-		Directory.Move(path, newpath);
-	}
-
-	/**
-		Returns informations for the given file/directory.
-	**/
-	public static function stat( path : String ) : FileStat
-	{
-		if (File.Exists(path))
-		{
-			var fi = new FileInfo(path);
-			return {
-				gid: 0, //C# doesn't let you get this info
-				uid: 0, //same
-				atime: untyped Date.fromNative(fi.LastAccessTime),
-				mtime: untyped Date.fromNative(fi.LastWriteTime),
-				ctime: untyped Date.fromNative(fi.CreationTime),
-				size: cast(fi.Length, Int), //TODO: maybe change to Int64 for Haxe 3?
-				dev: 0, //FIXME: not sure what that is
-				ino: 0, //FIXME: not sure what that is
-				nlink: 0, //FIXME: not sure what that is
-				rdev: 0, //FIXME: not sure what that is
-				mode: 0 //FIXME: not sure what that is
-			};
-		} else if (Directory.Exists(path)) {
-			var fi = new DirectoryInfo(path);
-			return {
-				gid: 0, //C# doesn't let you get this info
-				uid: 0, //same
-				atime: untyped Date.fromNative(fi.LastAccessTime),
-				mtime: untyped Date.fromNative(fi.LastWriteTime),
-				ctime: untyped Date.fromNative(fi.CreationTime),
-				size: 0, //TODO: maybe change to Int64 for Haxe 3?
-				dev: 0, //FIXME: not sure what that is
-				ino: 0, //FIXME: not sure what that is
-				nlink: 0, //FIXME: not sure what that is
-				rdev: 0, //FIXME: not sure what that is
-				mode: 0 //FIXME: not sure what that is
-			};
-		} else {
-			throw "Path '" + path + "' doesn't exist";
-		}
-
-	}
-
-	/**
-		Returns the full path for the given path which is relative to the current working directory.
-	**/
-	public static function fullPath( relpath : String ) : String
-	{
-		return new FileInfo(relpath).FullName;
-	}
-
-	/**
-		Tells if the given path is a directory. Throw an exception if it does not exists or is not accesible.
-	**/
-	public static function isDirectory( path : String ) : Bool
-	{
-		var isdir = Directory.Exists(path);
-		if (isdir != File.Exists(path))
-			return isdir;
-		throw "Path '" + path + "' doesn't exist";
-	}
-
-	/**
-		Create the given directory. Not recursive : the parent directory must exists.
-	**/
-	public static function createDirectory( path : String ) : Void
-	{
-		Directory.CreateDirectory(path);
-	}
-
-	/**
-		Delete a given file.
-	**/
-	public static function deleteFile( path : String ) : Void
-	{
-		File.Delete(path);
-	}
-
-	/**
-		Delete a given directory.
-	**/
-	public static function deleteDirectory( path : String ) : Void
-	{
-		Directory.Delete(path);
-	}
-
-	/**
-		Read all the files/directories stored into the given directory.
-	**/
-	public static function readDirectory( path : String ) : Array<String>
-	{
-		var ret = Directory.GetFileSystemEntries(path);
-		if (ret.Length > 0)
-		{
-			var fst = ret[0];
-			var sep = "/";
-			if (fst.lastIndexOf(sep) < fst.lastIndexOf("\\"))
-				sep = "\\";
-			for (i in 0...ret.Length)
-			{
-				var path = ret[i];
-				ret[i] = path.substr(path.lastIndexOf(sep) + 1);
-			}
-		}
-
-		return cs.Lib.array( ret );
-	}
-
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package sys;
+import cs.system.io.DirectoryInfo;
+import cs.system.io.File;
+import cs.system.io.Directory;
+import cs.system.io.FileInfo;
+
+/**
+	This class allows you to get informations about the files and directories.
+**/
+@:coreApi
+class FileSystem {
+
+	/**
+		Tells if the given file or directory exists.
+	**/
+	public static function exists( path : String ) : Bool
+	{
+		return (File.Exists(path) || Directory.Exists(path));
+	}
+
+	/**
+		Rename the corresponding file or directory, allow to move it accross directories as well.
+	**/
+	public static function rename( path : String, newpath : String ) : Void
+	{
+		Directory.Move(path, newpath);
+	}
+
+	/**
+		Returns informations for the given file/directory.
+	**/
+	public static function stat( path : String ) : FileStat
+	{
+		if (File.Exists(path))
+		{
+			var fi = new FileInfo(path);
+			return {
+				gid: 0, //C# doesn't let you get this info
+				uid: 0, //same
+				atime: untyped Date.fromNative(fi.LastAccessTime),
+				mtime: untyped Date.fromNative(fi.LastWriteTime),
+				ctime: untyped Date.fromNative(fi.CreationTime),
+				size: cast(fi.Length, Int), //TODO: maybe change to Int64 for Haxe 3?
+				dev: 0, //FIXME: not sure what that is
+				ino: 0, //FIXME: not sure what that is
+				nlink: 0, //FIXME: not sure what that is
+				rdev: 0, //FIXME: not sure what that is
+				mode: 0 //FIXME: not sure what that is
+			};
+		} else if (Directory.Exists(path)) {
+			var fi = new DirectoryInfo(path);
+			return {
+				gid: 0, //C# doesn't let you get this info
+				uid: 0, //same
+				atime: untyped Date.fromNative(fi.LastAccessTime),
+				mtime: untyped Date.fromNative(fi.LastWriteTime),
+				ctime: untyped Date.fromNative(fi.CreationTime),
+				size: 0, //TODO: maybe change to Int64 for Haxe 3?
+				dev: 0, //FIXME: not sure what that is
+				ino: 0, //FIXME: not sure what that is
+				nlink: 0, //FIXME: not sure what that is
+				rdev: 0, //FIXME: not sure what that is
+				mode: 0 //FIXME: not sure what that is
+			};
+		} else {
+			throw "Path '" + path + "' doesn't exist";
+		}
+
+	}
+
+	/**
+		Returns the full path for the given path which is relative to the current working directory.
+	**/
+	public static function fullPath( relpath : String ) : String
+	{
+		return new FileInfo(relpath).FullName;
+	}
+
+	/**
+		Tells if the given path is a directory. Throw an exception if it does not exists or is not accesible.
+	**/
+	public static function isDirectory( path : String ) : Bool
+	{
+		var isdir = Directory.Exists(path);
+		if (isdir != File.Exists(path))
+			return isdir;
+		throw "Path '" + path + "' doesn't exist";
+	}
+
+	/**
+		Create the given directory. Not recursive : the parent directory must exists.
+	**/
+	public static function createDirectory( path : String ) : Void
+	{
+		Directory.CreateDirectory(path);
+	}
+
+	/**
+		Delete a given file.
+	**/
+	public static function deleteFile( path : String ) : Void
+	{
+		File.Delete(path);
+	}
+
+	/**
+		Delete a given directory.
+	**/
+	public static function deleteDirectory( path : String ) : Void
+	{
+		Directory.Delete(path);
+	}
+
+	/**
+		Read all the files/directories stored into the given directory.
+	**/
+	public static function readDirectory( path : String ) : Array<String>
+	{
+		var ret = Directory.GetFileSystemEntries(path);
+		if (ret.Length > 0)
+		{
+			var fst = ret[0];
+			var sep = "/";
+			if (fst.lastIndexOf(sep) < fst.lastIndexOf("\\"))
+				sep = "\\";
+			for (i in 0...ret.Length)
+			{
+				var path = ret[i];
+				ret[i] = path.substr(path.lastIndexOf(sep) + 1);
+			}
+		}
+
+		return cs.Lib.array( ret );
+	}
+
 }

+ 93 - 93
std/cs/_std/sys/io/File.hx

@@ -1,94 +1,94 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package sys.io;
-
-/**
-	API for reading and writing to files.
-**/
-@:coreApi
-class File {
-
-	public static function getContent( path : String ) : String
-	{
-		var f = read(path, false);
-		var ret = f.readAll().toString();
-		f.close();
-		return ret;
-	}
-
-	public static function saveContent( path : String, content : String ) : Void
-	{
-		var f = write(path, false);
-		f.writeString(content);
-		f.close();
-	}
-
-	public static function getBytes( path : String ) : haxe.io.Bytes
-	{
-		var f = read(path, true);
-		var ret = f.readAll();
-		f.close();
-		return ret;
-	}
-
-	public static function saveBytes( path : String, bytes : haxe.io.Bytes ) : Void
-	{
-		var f = write(path, true);
-		f.writeBytes(bytes, 0, bytes.length);
-		f.close();
-	}
-
-	public static function read( path : String, binary : Bool = true ) : FileInput
-	{
-		#if std-buffer //standardize 4kb buffers
-		var stream = new cs.system.io.FileStream(path, Open, Read, ReadWrite, 4096);
-		#else
-		var stream = new cs.system.io.FileStream(path, Open, Read, ReadWrite);
-		#end
-		return new FileInput(stream);
-	}
-
-	public static function write( path : String, binary : Bool = true ) : FileOutput
-	{
-		#if std-buffer //standardize 4kb buffers
-		var stream = new cs.system.io.FileStream(path, Create, Write, ReadWrite, 4096);
-		#else
-		var stream = new cs.system.io.FileStream(path, Create, Write, ReadWrite);
-		#end
-		return new FileOutput(stream);
-	}
-
-	public static function append( path : String, binary : Bool = true ) : FileOutput
-	{
-		#if std-buffer //standardize 4kb buffers
-		var stream = new cs.system.io.FileStream(path, Append, Write, ReadWrite, 4096);
-		#else
-		var stream = new cs.system.io.FileStream(path, Append, Write, ReadWrite);
-		#end
-		return new FileOutput(stream);
-	}
-
-	public static function copy( src : String, dst : String ) : Void
-	{
-		cs.system.io.File.Copy(src, dst);
-	}
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package sys.io;
+
+/**
+	API for reading and writing to files.
+**/
+@:coreApi
+class File {
+
+	public static function getContent( path : String ) : String
+	{
+		var f = read(path, false);
+		var ret = f.readAll().toString();
+		f.close();
+		return ret;
+	}
+
+	public static function saveContent( path : String, content : String ) : Void
+	{
+		var f = write(path, false);
+		f.writeString(content);
+		f.close();
+	}
+
+	public static function getBytes( path : String ) : haxe.io.Bytes
+	{
+		var f = read(path, true);
+		var ret = f.readAll();
+		f.close();
+		return ret;
+	}
+
+	public static function saveBytes( path : String, bytes : haxe.io.Bytes ) : Void
+	{
+		var f = write(path, true);
+		f.writeBytes(bytes, 0, bytes.length);
+		f.close();
+	}
+
+	public static function read( path : String, binary : Bool = true ) : FileInput
+	{
+		#if std-buffer //standardize 4kb buffers
+		var stream = new cs.system.io.FileStream(path, Open, Read, ReadWrite, 4096);
+		#else
+		var stream = new cs.system.io.FileStream(path, Open, Read, ReadWrite);
+		#end
+		return new FileInput(stream);
+	}
+
+	public static function write( path : String, binary : Bool = true ) : FileOutput
+	{
+		#if std-buffer //standardize 4kb buffers
+		var stream = new cs.system.io.FileStream(path, Create, Write, ReadWrite, 4096);
+		#else
+		var stream = new cs.system.io.FileStream(path, Create, Write, ReadWrite);
+		#end
+		return new FileOutput(stream);
+	}
+
+	public static function append( path : String, binary : Bool = true ) : FileOutput
+	{
+		#if std-buffer //standardize 4kb buffers
+		var stream = new cs.system.io.FileStream(path, Append, Write, ReadWrite, 4096);
+		#else
+		var stream = new cs.system.io.FileStream(path, Append, Write, ReadWrite);
+		#end
+		return new FileOutput(stream);
+	}
+
+	public static function copy( src : String, dst : String ) : Void
+	{
+		cs.system.io.File.Copy(src, dst);
+	}
 }

+ 32 - 32
std/cs/_std/sys/io/FileInput.hx

@@ -1,32 +1,32 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package sys.io;
-
-/**
-	Use [sys.io.File.read] to create a [FileInput]
-**/
-class FileInput extends cs.io.NativeInput {
-	public function new(stream:cs.system.io.FileStream)
-	{
-		super(stream);
-	}
-}
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package sys.io;
+
+/**
+	Use [sys.io.File.read] to create a [FileInput]
+**/
+class FileInput extends cs.io.NativeInput {
+	public function new(stream:cs.system.io.FileStream)
+	{
+		super(stream);
+	}
+}

+ 32 - 32
std/cs/_std/sys/io/FileOutput.hx

@@ -1,32 +1,32 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package sys.io;
-
-/**
-	Use [sys.io.File.write] to create a [FileOutput]
-**/
-class FileOutput extends cs.io.NativeOutput {
-	public function new(stream:cs.system.io.FileStream)
-	{
-		super(stream);
-	}
-}
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package sys.io;
+
+/**
+	Use [sys.io.File.write] to create a [FileOutput]
+**/
+class FileOutput extends cs.io.NativeOutput {
+	public function new(stream:cs.system.io.FileStream)
+	{
+		super(stream);
+	}
+}

+ 110 - 110
std/cs/_std/sys/io/Process.hx

@@ -1,111 +1,111 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package sys.io;
-import haxe.io.BytesInput;
-import cs.system.io.StreamReader;
-import cs.system.io.StreamWriter;
-
-@:coreApi
-class Process {
-
-	public var stdout(default,null) : haxe.io.Input;
-	public var stderr(default,null) : haxe.io.Input;
-	public var stdin(default, null) : haxe.io.Output;
-
-	private var native:NativeProcess;
-
-
-	public function new( cmd : String, args : Array<String> ) : Void
-	{
-		this.native = new NativeProcess();
-		native.StartInfo.FileName = cmd;
-		var buf = new StringBuf();
-		for (arg in args)
-		{
-			buf.add("\"");
-			buf.add(StringTools.replace(arg, "\"", "\\\""));
-			buf.add("\" ");
-		}
-		native.StartInfo.Arguments = buf.toString();
-		native.StartInfo.RedirectStandardError = native.StartInfo.RedirectStandardInput = native.StartInfo.RedirectStandardOutput = true;
-		native.StartInfo.UseShellExecute = false;
-
-		native.Start();
-
-		this.stdout = new cs.io.NativeInput(native.StandardOutput.BaseStream);
-		this.stderr = new cs.io.NativeInput(native.StandardError.BaseStream);
-		this.stdin = new cs.io.NativeOutput(native.StandardInput.BaseStream);
-	}
-
-	public function getPid() : Int
-	{
-		return native.Id;
-	}
-
-	public function exitCode() : Int
-	{
-		native.WaitForExit();
-		return native.ExitCode;
-	}
-
-	public function close() : Void
-	{
-		native.Close();
-	}
-
-	public function kill() : Void
-	{
-		native.Kill();
-	}
-
-}
-
-/*
-FIXME: The actual process class is much more complex than this, so here it is included a very simplified version.
-*/
-@:native('System.Diagnostics.Process') private extern class NativeProcess
-{
-	var ExitCode(default, null):Int;
-	var Id(default, null):Int;
-	var StartInfo(default, null):NativeStartInfo;
-	var StandardError(default, null):StreamReader;
-	var StandardInput(default, null):StreamWriter;
-	var StandardOutput(default, null):StreamReader;
-
-	function new():Void;
-	function Close():Void;
-	function Kill():Void;
-	function Start():Void;
-	function WaitForExit():Void;
-}
-
-@:native('System.Diagnostics.ProcessStartInfo') private extern class NativeStartInfo
-{
-	var Arguments:String;
-	var FileName:String;
-	var RedirectStandardError:Bool;
-	var RedirectStandardInput:Bool;
-	var RedirectStandardOutput:Bool;
-	var UseShellExecute:Bool;
-	function new(filename:String, args:String):Void;
-
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package sys.io;
+import haxe.io.BytesInput;
+import cs.system.io.StreamReader;
+import cs.system.io.StreamWriter;
+
+@:coreApi
+class Process {
+
+	public var stdout(default,null) : haxe.io.Input;
+	public var stderr(default,null) : haxe.io.Input;
+	public var stdin(default, null) : haxe.io.Output;
+
+	private var native:NativeProcess;
+
+
+	public function new( cmd : String, args : Array<String> ) : Void
+	{
+		this.native = new NativeProcess();
+		native.StartInfo.FileName = cmd;
+		var buf = new StringBuf();
+		for (arg in args)
+		{
+			buf.add("\"");
+			buf.add(StringTools.replace(arg, "\"", "\\\""));
+			buf.add("\" ");
+		}
+		native.StartInfo.Arguments = buf.toString();
+		native.StartInfo.RedirectStandardError = native.StartInfo.RedirectStandardInput = native.StartInfo.RedirectStandardOutput = true;
+		native.StartInfo.UseShellExecute = false;
+
+		native.Start();
+
+		this.stdout = new cs.io.NativeInput(native.StandardOutput.BaseStream);
+		this.stderr = new cs.io.NativeInput(native.StandardError.BaseStream);
+		this.stdin = new cs.io.NativeOutput(native.StandardInput.BaseStream);
+	}
+
+	public function getPid() : Int
+	{
+		return native.Id;
+	}
+
+	public function exitCode() : Int
+	{
+		native.WaitForExit();
+		return native.ExitCode;
+	}
+
+	public function close() : Void
+	{
+		native.Close();
+	}
+
+	public function kill() : Void
+	{
+		native.Kill();
+	}
+
+}
+
+/*
+FIXME: The actual process class is much more complex than this, so here it is included a very simplified version.
+*/
+@:native('System.Diagnostics.Process') private extern class NativeProcess
+{
+	var ExitCode(default, null):Int;
+	var Id(default, null):Int;
+	var StartInfo(default, null):NativeStartInfo;
+	var StandardError(default, null):StreamReader;
+	var StandardInput(default, null):StreamWriter;
+	var StandardOutput(default, null):StreamReader;
+
+	function new():Void;
+	function Close():Void;
+	function Kill():Void;
+	function Start():Void;
+	function WaitForExit():Void;
+}
+
+@:native('System.Diagnostics.ProcessStartInfo') private extern class NativeStartInfo
+{
+	var Arguments:String;
+	var FileName:String;
+	var RedirectStandardError:Bool;
+	var RedirectStandardInput:Bool;
+	var RedirectStandardOutput:Bool;
+	var UseShellExecute:Bool;
+	function new(filename:String, args:String):Void;
+
 }

+ 57 - 57
std/cs/internal/Exceptions.hx

@@ -1,58 +1,58 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.internal;
-import cs.system.Exception;
-
-//should NOT be usable inside haxe code
-@:nativeGen @:keep @:native("haxe.lang.HaxeException") private class HaxeException extends Exception
-{
-	private var obj:Dynamic;
-
-	public function new(obj:Dynamic)
-	{
-		super();
-
-		if (Std.is(obj, HaxeException))
-		{
-			var _obj:HaxeException = cast obj;
-			obj = _obj.getObject();
-		}
-		this.obj = obj;
-	}
-
-	public function getObject():Dynamic
-	{
-		return obj;
-	}
-
-	public function toString():String
-	{
-		return "Haxe Exception: " + obj;
-	}
-
-	public static function wrap(obj:Dynamic):Exception
-	{
-		if (Std.is(obj, Exception)) return obj;
-
-		return new HaxeException(obj);
-	}
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.internal;
+import cs.system.Exception;
+
+//should NOT be usable inside haxe code
+@:nativeGen @:keep @:native("haxe.lang.HaxeException") private class HaxeException extends Exception
+{
+	private var obj:Dynamic;
+
+	public function new(obj:Dynamic)
+	{
+		super();
+
+		if (Std.is(obj, HaxeException))
+		{
+			var _obj:HaxeException = cast obj;
+			obj = _obj.getObject();
+		}
+		this.obj = obj;
+	}
+
+	public function getObject():Dynamic
+	{
+		return obj;
+	}
+
+	public function toString():String
+	{
+		return "Haxe Exception: " + obj;
+	}
+
+	public static function wrap(obj:Dynamic):Exception
+	{
+		if (Std.is(obj, Exception)) return obj;
+
+		return new HaxeException(obj);
+	}
 }

+ 121 - 121
std/cs/internal/FieldLookup.hx

@@ -1,122 +1,122 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.internal;
-
-@:native('haxe.lang.FieldLookup')
-@:keep @:static private class FieldLookup 
-{
-
-	@:private private static var fieldIds:Array<Int>;
-	@:private private static var fields:Array<String>;
-	
-	//s cannot be null here
-	private static inline function doHash(s:String):Int
-	{
-		var acc = 0; //alloc_int
-		for (i in 0...s.length)
-		{
-			acc = (( 223 * (acc >> 1) + s.charCodeAt(i) ) << 1);
-		}
-		
-		return acc >>> 1; //always positive
-	}
-	
-	public static function lookupHash(key:Int):String
-	{
-		//start of binary search algorithm
-		var ids = fieldIds;
-		var min = 0;
-		var max = ids.length;
-		
-		while (min < max)
-		{
-			var mid = min + Std.int((max - min) / 2);
-			var imid = ids[mid];
-			if (key < imid)
-			{
-				max = mid;
-			} else if (key > imid) {
-				min = mid + 1;
-			} else {
-				return fields[mid];
-			}
-		}
-		//if not found, it's definately an error
-		throw "Field not found for hash " + key;
-	}
-	
-	public static function hash(s:String):Int
-	{
-		if (s == null) return 0;
-		
-		var key = doHash(s);
-		
-		//start of binary search algorithm
-		var ids = fieldIds;
-		var min = 0;
-		var max = ids.length;
-		
-		while (min < max)
-		{
-			var mid = Std.int(min + (max - min) / 2); //overflow safe
-			var imid = ids[mid];
-			if (key < imid)
-			{
-				max = mid;
-			} else if (key > imid) {
-				min = mid + 1;
-			} else {
-				var field = fields[mid];
-				if (field != s)
-					return ~key; //special case
-				return key;
-			}
-		}
-		//if not found, min holds the value where we should insert the key
-		ids.insert(min, key);
-		fields.insert(min, s);
-		return key;
-	}
-	
-	public static function findHash(hash:Int, hashs:Array<Int>):Int
-	{
-		var min = 0;
-		var max = hashs.length;
-		
-		while (min < max)
-		{
-			var mid = Std.int((max + min) / 2); //overflow safe
-			var imid = hashs[mid];
-			if (hash < imid)
-			{
-				max = mid;
-			} else if (hash > imid) {
-				min = mid + 1;
-			} else {
-				return mid;
-			}
-		}
-		//if not found, return a negative value of where it should be inserted
-		return ~min;
-	}
-	
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.internal;
+
+@:native('haxe.lang.FieldLookup')
+@:keep @:static private class FieldLookup 
+{
+
+	@:private private static var fieldIds:Array<Int>;
+	@:private private static var fields:Array<String>;
+	
+	//s cannot be null here
+	private static inline function doHash(s:String):Int
+	{
+		var acc = 0; //alloc_int
+		for (i in 0...s.length)
+		{
+			acc = (( 223 * (acc >> 1) + s.charCodeAt(i) ) << 1);
+		}
+		
+		return acc >>> 1; //always positive
+	}
+	
+	public static function lookupHash(key:Int):String
+	{
+		//start of binary search algorithm
+		var ids = fieldIds;
+		var min = 0;
+		var max = ids.length;
+		
+		while (min < max)
+		{
+			var mid = min + Std.int((max - min) / 2);
+			var imid = ids[mid];
+			if (key < imid)
+			{
+				max = mid;
+			} else if (key > imid) {
+				min = mid + 1;
+			} else {
+				return fields[mid];
+			}
+		}
+		//if not found, it's definately an error
+		throw "Field not found for hash " + key;
+	}
+	
+	public static function hash(s:String):Int
+	{
+		if (s == null) return 0;
+		
+		var key = doHash(s);
+		
+		//start of binary search algorithm
+		var ids = fieldIds;
+		var min = 0;
+		var max = ids.length;
+		
+		while (min < max)
+		{
+			var mid = Std.int(min + (max - min) / 2); //overflow safe
+			var imid = ids[mid];
+			if (key < imid)
+			{
+				max = mid;
+			} else if (key > imid) {
+				min = mid + 1;
+			} else {
+				var field = fields[mid];
+				if (field != s)
+					return ~key; //special case
+				return key;
+			}
+		}
+		//if not found, min holds the value where we should insert the key
+		ids.insert(min, key);
+		fields.insert(min, s);
+		return key;
+	}
+	
+	public static function findHash(hash:Int, hashs:Array<Int>):Int
+	{
+		var min = 0;
+		var max = hashs.length;
+		
+		while (min < max)
+		{
+			var mid = Std.int((max + min) / 2); //overflow safe
+			var imid = hashs[mid];
+			if (hash < imid)
+			{
+				max = mid;
+			} else if (hash > imid) {
+				min = mid + 1;
+			} else {
+				return mid;
+			}
+		}
+		//if not found, return a negative value of where it should be inserted
+		return ~min;
+	}
+	
 }

+ 80 - 80
std/cs/internal/Function.hx

@@ -1,81 +1,81 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.internal;
-
-/**
- These classes are automatically generated by the compiler. They are only
- here so there is an option for e.g. defining them as externs if you are compiling
- in modules (untested).
-**/
-
-@:keep @:abstract @:nativeGen @:native("haxe.lang.Function") private class Function
-{
-	function new(arity:Int, type:Int)
-	{
-
-	}
-}
-
-@:keep @:nativeGen @:native("haxe.lang.VarArgsBase") private class VarArgsBase extends Function
-{
-	public function __hx_invokeDynamic(dynArgs:Array<Dynamic>):Dynamic
-	{
-		throw "Abstract implementation";
-		return null;
-	}
-}
-
-@:keep @:nativeGen @:native('haxe.lang.VarArgsFunction') class VarArgsFunction extends VarArgsBase
-{
-	private var fun:Array<Dynamic>->Dynamic;
-
-	public function new(fun)
-	{
-		super(-1, -1);
-		this.fun = fun;
-	}
-
-	override public function __hx_invokeDynamic(dynArgs:Array<Dynamic>):Dynamic
-	{
-		return fun(dynArgs);
-	}
-}
-
-@:keep @:nativeGen @:native('haxe.lang.Closure') class Closure extends VarArgsBase
-{
-	private var obj:Dynamic;
-	private var field:String;
-	private var hash:Int;
-
-	public function new(obj:Dynamic, field, hash)
-	{
-		super(-1, -1);
-		this.obj = obj;
-		this.field = field;
-		this.hash = hash;
-	}
-
-	override public function __hx_invokeDynamic(dynArgs:Array<Dynamic>):Dynamic
-	{
-		return Runtime.callField(obj, field, hash, dynArgs);
-	}
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.internal;
+
+/**
+ These classes are automatically generated by the compiler. They are only
+ here so there is an option for e.g. defining them as externs if you are compiling
+ in modules (untested).
+**/
+
+@:keep @:abstract @:nativeGen @:native("haxe.lang.Function") private class Function
+{
+	function new(arity:Int, type:Int)
+	{
+
+	}
+}
+
+@:keep @:nativeGen @:native("haxe.lang.VarArgsBase") private class VarArgsBase extends Function
+{
+	public function __hx_invokeDynamic(dynArgs:Array<Dynamic>):Dynamic
+	{
+		throw "Abstract implementation";
+		return null;
+	}
+}
+
+@:keep @:nativeGen @:native('haxe.lang.VarArgsFunction') class VarArgsFunction extends VarArgsBase
+{
+	private var fun:Array<Dynamic>->Dynamic;
+
+	public function new(fun)
+	{
+		super(-1, -1);
+		this.fun = fun;
+	}
+
+	override public function __hx_invokeDynamic(dynArgs:Array<Dynamic>):Dynamic
+	{
+		return fun(dynArgs);
+	}
+}
+
+@:keep @:nativeGen @:native('haxe.lang.Closure') class Closure extends VarArgsBase
+{
+	private var obj:Dynamic;
+	private var field:String;
+	private var hash:Int;
+
+	public function new(obj:Dynamic, field, hash)
+	{
+		super(-1, -1);
+		this.obj = obj;
+		this.field = field;
+		this.hash = hash;
+	}
+
+	override public function __hx_invokeDynamic(dynArgs:Array<Dynamic>):Dynamic
+	{
+		return Runtime.callField(obj, field, hash, dynArgs);
+	}
 }

+ 37 - 37
std/cs/internal/Iterator.hx

@@ -1,38 +1,38 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.internal;
-
-@:keep @:native('haxe.lang.Iterator') interface Iterator<T>
-{
-	
-	public function hasNext():Bool;
-	
-	public function next():T;
-	
-}
-
-@:keep @:native('haxe.lang.Iterable') interface Iterable<T>
-{
-	
-	public function iterator():Iterator<T>;
-	
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.internal;
+
+@:keep @:native('haxe.lang.Iterator') interface Iterator<T>
+{
+	
+	public function hasNext():Bool;
+	
+	public function next():T;
+	
+}
+
+@:keep @:native('haxe.lang.Iterable') interface Iterable<T>
+{
+	
+	public function iterator():Iterator<T>;
+	
 }

+ 87 - 87
std/cs/io/NativeInput.hx

@@ -1,88 +1,88 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.io;
-import haxe.Int64;
-import haxe.io.Bytes;
-import haxe.io.Eof;
-import haxe.io.Error;
-import haxe.io.Input;
-
-class NativeInput extends Input
-{
-	public var canSeek(get_canSeek, null):Bool;
-	
-	var stream:cs.system.io.Stream;
-	public function new(stream)
-	{
-		this.stream = stream;
-		if (!stream.CanRead) throw "Write-only stream";
-	}
-	
-	override public function readByte():Int 
-	{
-		var ret = stream.ReadByte();
-		if (ret == -1) throw new Eof();
-		return ret;
-	}
-	
-	override public function readBytes(s:Bytes, pos:Int, len:Int):Int 
-	{
-		if( pos < 0 || len < 0 || pos + len > s.length )
-			throw Error.OutsideBounds;
-		var ret = stream.Read(s.getData(), pos, len);
-		if (ret == 0)
-			throw new Eof();
-		return ret;
-	}
-	
-	override public function close():Void
-	{
-		stream.Close();
-	}
-	
-	private function get_canSeek():Bool
-	{
-		return stream.CanSeek;
-	}
-	
-	public function seek( p : Int, pos : sys.io.FileSeek ) : Void
-	{
-		var p = switch(pos)
-		{
-			case SeekBegin: cs.system.io.SeekOrigin.Begin;
-			case SeekCur: cs.system.io.SeekOrigin.Current;
-			case SeekEnd: cs.system.io.SeekOrigin.End;
-		};
-		
-		stream.Seek(cast(p, Int64), p);
-	}
-	
-	public function tell() : Int
-	{
-		return cast(stream.Position, Int);
-	}
-	
-	public function eof() : Bool
-	{
-		return stream.Position == stream.Length;
-	}
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.io;
+import haxe.Int64;
+import haxe.io.Bytes;
+import haxe.io.Eof;
+import haxe.io.Error;
+import haxe.io.Input;
+
+class NativeInput extends Input
+{
+	public var canSeek(get_canSeek, null):Bool;
+	
+	var stream:cs.system.io.Stream;
+	public function new(stream)
+	{
+		this.stream = stream;
+		if (!stream.CanRead) throw "Write-only stream";
+	}
+	
+	override public function readByte():Int 
+	{
+		var ret = stream.ReadByte();
+		if (ret == -1) throw new Eof();
+		return ret;
+	}
+	
+	override public function readBytes(s:Bytes, pos:Int, len:Int):Int 
+	{
+		if( pos < 0 || len < 0 || pos + len > s.length )
+			throw Error.OutsideBounds;
+		var ret = stream.Read(s.getData(), pos, len);
+		if (ret == 0)
+			throw new Eof();
+		return ret;
+	}
+	
+	override public function close():Void
+	{
+		stream.Close();
+	}
+	
+	private function get_canSeek():Bool
+	{
+		return stream.CanSeek;
+	}
+	
+	public function seek( p : Int, pos : sys.io.FileSeek ) : Void
+	{
+		var p = switch(pos)
+		{
+			case SeekBegin: cs.system.io.SeekOrigin.Begin;
+			case SeekCur: cs.system.io.SeekOrigin.Current;
+			case SeekEnd: cs.system.io.SeekOrigin.End;
+		};
+		
+		stream.Seek(cast(p, Int64), p);
+	}
+	
+	public function tell() : Int
+	{
+		return cast(stream.Position, Int);
+	}
+	
+	public function eof() : Bool
+	{
+		return stream.Position == stream.Length;
+	}
 }

+ 78 - 78
std/cs/io/NativeOutput.hx

@@ -1,79 +1,79 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.io;
-import haxe.Int64;
-import haxe.io.Bytes;
-import haxe.io.Output;
-
-class NativeOutput extends Output
-{
-	var canSeek(get_canSeek, null):Bool;
-	var stream:cs.system.io.Stream;
-	public function new(stream)
-	{
-		this.stream = stream;
-		if (!stream.CanWrite) throw "Read-only stream";
-	}
-	
-	override public function writeByte(c:Int):Void 
-	{
-		stream.WriteByte(c);
-	}
-	
-	override public function close():Void
-	{
-		stream.Close();
-	}
-	
-	override public function flush():Void
-	{
-		stream.Flush();
-	}
-	
-	override public function prepare(nbytes:Int):Void
-	{
-		//TODO see if implementation is correct
-		stream.SetLength(haxe.Int64.add(stream.Length, cast(nbytes, Int64)));
-	}
-	
-	private function get_canSeek():Bool
-	{
-		return stream.CanSeek;
-	}
-	
-	public function seek( p : Int, pos : sys.io.FileSeek ) : Void
-	{
-		var p = switch(pos)
-		{
-			case SeekBegin: cs.system.io.SeekOrigin.Begin;
-			case SeekCur: cs.system.io.SeekOrigin.Current;
-			case SeekEnd: cs.system.io.SeekOrigin.End;
-		};
-		
-		stream.Seek(cast(p, Int64), p);
-	}
-	
-	public function tell() : Int
-	{
-		return cast(stream.Position, Int);
-	}
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.io;
+import haxe.Int64;
+import haxe.io.Bytes;
+import haxe.io.Output;
+
+class NativeOutput extends Output
+{
+	var canSeek(get_canSeek, null):Bool;
+	var stream:cs.system.io.Stream;
+	public function new(stream)
+	{
+		this.stream = stream;
+		if (!stream.CanWrite) throw "Read-only stream";
+	}
+	
+	override public function writeByte(c:Int):Void 
+	{
+		stream.WriteByte(c);
+	}
+	
+	override public function close():Void
+	{
+		stream.Close();
+	}
+	
+	override public function flush():Void
+	{
+		stream.Flush();
+	}
+	
+	override public function prepare(nbytes:Int):Void
+	{
+		//TODO see if implementation is correct
+		stream.SetLength(haxe.Int64.add(stream.Length, cast(nbytes, Int64)));
+	}
+	
+	private function get_canSeek():Bool
+	{
+		return stream.CanSeek;
+	}
+	
+	public function seek( p : Int, pos : sys.io.FileSeek ) : Void
+	{
+		var p = switch(pos)
+		{
+			case SeekBegin: cs.system.io.SeekOrigin.Begin;
+			case SeekCur: cs.system.io.SeekOrigin.Current;
+			case SeekEnd: cs.system.io.SeekOrigin.End;
+		};
+		
+		stream.Seek(cast(p, Int64), p);
+	}
+	
+	public function tell() : Int
+	{
+		return cast(stream.Position, Int);
+	}
 }

+ 26 - 26
std/cs/system/Activator.hx

@@ -1,27 +1,27 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system;
-
-@:native('System.Activator') extern class Activator 
-{
-	static function CreateInstance(t:cs.system.Type):Dynamic;
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system;
+
+@:native('System.Activator') extern class Activator 
+{
+	static function CreateInstance(t:cs.system.Type):Dynamic;
 }

+ 28 - 28
std/cs/system/Array.hx

@@ -1,29 +1,29 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system;
- 
-@:native("System.Array")
-extern class Array 
-{
-
-	public static function Copy(sourceArray:Array, sourceIndex:Int, destinationArray:Array, destinationIndex:Int, length:Int):Void;
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system;
+ 
+@:native("System.Array")
+extern class Array 
+{
+
+	public static function Copy(sourceArray:Array, sourceIndex:Int, destinationArray:Array, destinationIndex:Int, length:Int):Void;
 }

+ 40 - 40
std/cs/system/BitConverter.hx

@@ -1,41 +1,41 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system;
-import cs.NativeArray;
-import cs.NativeArray;
-import cs.StdTypes;
-import haxe.Int64;
-
-@:native('System.BitConverter') extern class BitConverter 
-{
-	static var IsLittleEndian(default, null):Bool;
-	static function DoubleToInt64Bits(v:Float):Int64;
-	static function Int64BitsToDouble(v:Int64):Float;
-	static function GetBytes(d:Dynamic):NativeArray<UInt8>;
-	static function ToBoolean(b:NativeArray<UInt8>, startIndex:Int):Bool;
-	static function ToChar(b:NativeArray<UInt8>, startIndex:Int):Char16;
-	static function ToDouble(b:NativeArray<UInt8>, startIndex:Int):Float;
-	static function ToInt16(b:NativeArray<UInt8>, startIndex:Int):Int16;
-	static function ToInt32(b:NativeArray<UInt8>, startIndex:Int):Int;
-	static function ToInt64(b:NativeArray<UInt8>, startIndex:Int):Int64;
-	static function ToSingle(b:NativeArray<UInt8>, startIndex:Int):Single;
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system;
+import cs.NativeArray;
+import cs.NativeArray;
+import cs.StdTypes;
+import haxe.Int64;
+
+@:native('System.BitConverter') extern class BitConverter 
+{
+	static var IsLittleEndian(default, null):Bool;
+	static function DoubleToInt64Bits(v:Float):Int64;
+	static function Int64BitsToDouble(v:Int64):Float;
+	static function GetBytes(d:Dynamic):NativeArray<UInt8>;
+	static function ToBoolean(b:NativeArray<UInt8>, startIndex:Int):Bool;
+	static function ToChar(b:NativeArray<UInt8>, startIndex:Int):Char16;
+	static function ToDouble(b:NativeArray<UInt8>, startIndex:Int):Float;
+	static function ToInt16(b:NativeArray<UInt8>, startIndex:Int):Int16;
+	static function ToInt32(b:NativeArray<UInt8>, startIndex:Int):Int;
+	static function ToInt64(b:NativeArray<UInt8>, startIndex:Int):Int64;
+	static function ToSingle(b:NativeArray<UInt8>, startIndex:Int):Single;
 }

+ 43 - 43
std/cs/system/Console.hx

@@ -1,44 +1,44 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system;
-
-/**
-	Warning: This class definition is incomplete.
-	In order to get most current extern definitions, install/update hxcs library with:
-		haxelib install hxcs
-	Please refer to http://lib.haxe.org/p/hxcs for more information.
-**/
-@:native('System.Console') extern class Console 
-{
-	static var Error(default, null):cs.system.io.StreamWriter;
-	static var In(default, null):cs.system.io.StreamReader;
-	static var Out(default, null):cs.system.io.StreamWriter;
-	
-	static function Write(obj:Dynamic):Void;
-	static function WriteLine(obj:Dynamic):Void;
-	
-	#if !(Xbox || CF || MF)
-	static function OpenStandardOutput():cs.system.io.Stream;
-	static function OpenStandardInput():cs.system.io.Stream;
-	static function OpenStandardError():cs.system.io.Stream;
-	#end
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system;
+
+/**
+	Warning: This class definition is incomplete.
+	In order to get most current extern definitions, install/update hxcs library with:
+		haxelib install hxcs
+	Please refer to http://lib.haxe.org/p/hxcs for more information.
+**/
+@:native('System.Console') extern class Console 
+{
+	static var Error(default, null):cs.system.io.StreamWriter;
+	static var In(default, null):cs.system.io.StreamReader;
+	static var Out(default, null):cs.system.io.StreamWriter;
+	
+	static function Write(obj:Dynamic):Void;
+	static function WriteLine(obj:Dynamic):Void;
+	
+	#if !(Xbox || CF || MF)
+	static function OpenStandardOutput():cs.system.io.Stream;
+	static function OpenStandardInput():cs.system.io.Stream;
+	static function OpenStandardError():cs.system.io.Stream;
+	#end
 }

+ 24 - 24
std/cs/system/Converter.hx

@@ -1,25 +1,25 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system;
-
-@:native("System.Converter") 
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system;
+
+@:native("System.Converter") 
 @:delegate extern typedef Converter<TInput,TOutput> = TInput->TOutput;

+ 65 - 65
std/cs/system/DateTime.hx

@@ -1,66 +1,66 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system;
-import haxe.Int64;
-
-/**
- * ...
- * @author waneck
- */
-
-@:native("System.DateTime")
-extern class DateTime 
-{
-
-	@:overload(function(year : Int, month : Int, day : Int, hour : Int, min : Int, sec : Int ):Void {})
-	function new(ticks:Int64):Void;
-	
-	var Day(default, null):Int;
-	var DayOfWeek(default, null):DayOfWeek;
-	var DayOfYear(default, null):Int;
-	var Hour(default, null):Int;
-	var Millisecond(default, null):Int;
-	var Minute(default, null):Int;
-	var Second(default, null):Int;
-	var Year(default, null):Int;
-	var Month(default, null):Int;
-	var Ticks(default, null):Int64;
-	static var Now(default, null):DateTime;
-	static var UtcNow(default, null):DateTime;
-}
-
-@:native("System.DayOfWeek")
-extern enum DayOfWeek
-{
-	Sunday;
-	Monday;
-	Tuesday;
-	Wedsneday;
-	Thursday;
-	Friday;
-	Saturday;
-}
-@:native("System.TimeSpan")
-extern class TimeSpan
-{
-	static var TicksPerMillisecond(default, null):Int;
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system;
+import haxe.Int64;
+
+/**
+ * ...
+ * @author waneck
+ */
+
+@:native("System.DateTime")
+extern class DateTime 
+{
+
+	@:overload(function(year : Int, month : Int, day : Int, hour : Int, min : Int, sec : Int ):Void {})
+	function new(ticks:Int64):Void;
+	
+	var Day(default, null):Int;
+	var DayOfWeek(default, null):DayOfWeek;
+	var DayOfYear(default, null):Int;
+	var Hour(default, null):Int;
+	var Millisecond(default, null):Int;
+	var Minute(default, null):Int;
+	var Second(default, null):Int;
+	var Year(default, null):Int;
+	var Month(default, null):Int;
+	var Ticks(default, null):Int64;
+	static var Now(default, null):DateTime;
+	static var UtcNow(default, null):DateTime;
+}
+
+@:native("System.DayOfWeek")
+extern enum DayOfWeek
+{
+	Sunday;
+	Monday;
+	Tuesday;
+	Wedsneday;
+	Thursday;
+	Friday;
+	Saturday;
+}
+@:native("System.TimeSpan")
+extern class TimeSpan
+{
+	static var TicksPerMillisecond(default, null):Int;
 }

+ 40 - 40
std/cs/system/Environment.hx

@@ -1,41 +1,41 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system;
-
-/**
-	Warning: This class definition is incomplete.
-	In order to get most current extern definitions, install/update hxcs library with:
-		haxelib install hxcs
-	Please refer to http://lib.haxe.org/p/hxcs for more information.
-**/
-@:native('System.Environment') extern class Environment
-{
-	static function Exit(code:Int):Void;
-	static function GetEnvironmentVariables():cs.system.collections.IDictionary;
-	static function GetEnvironmentVariable(k:String):String;
-	static function SetEnvironmentVariable(k:String, v:String):Void;
-	static function GetCommandLineArgs():cs.NativeArray<String>;
-	static var NewLine(default, null):String;
-	static var TickCount(default, null):Int;
-	static var OSVersion(default, null):OperatingSystem;
-	
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system;
+
+/**
+	Warning: This class definition is incomplete.
+	In order to get most current extern definitions, install/update hxcs library with:
+		haxelib install hxcs
+	Please refer to http://lib.haxe.org/p/hxcs for more information.
+**/
+@:native('System.Environment') extern class Environment
+{
+	static function Exit(code:Int):Void;
+	static function GetEnvironmentVariables():cs.system.collections.IDictionary;
+	static function GetEnvironmentVariable(k:String):String;
+	static function SetEnvironmentVariable(k:String, v:String):Void;
+	static function GetCommandLineArgs():cs.NativeArray<String>;
+	static var NewLine(default, null):String;
+	static var TickCount(default, null):Int;
+	static var OSVersion(default, null):OperatingSystem;
+	
 }

+ 28 - 28
std/cs/system/Exception.hx

@@ -1,29 +1,29 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system;
-
-@:native("System.Exception") @:nativeGen extern class Exception
-{
-	public var message:String;
-
-	private function new():Void;
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system;
+
+@:native("System.Exception") @:nativeGen extern class Exception
+{
+	public var message:String;
+
+	private function new():Void;
 }

+ 26 - 26
std/cs/system/IConvertible.hx

@@ -1,27 +1,27 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system;
-
-@:native("System.IConvertible") extern interface IConvertible
-{
-	function ToType(conversionType:cs.system.Type, provider:IFormatProvider):Dynamic;
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system;
+
+@:native("System.IConvertible") extern interface IConvertible
+{
+	function ToType(conversionType:cs.system.Type, provider:IFormatProvider):Dynamic;
 }

+ 26 - 26
std/cs/system/IFormatProvider.hx

@@ -1,27 +1,27 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system;
-
-@:native("System.IFormatProvider") extern interface IFormatProvider
-{
-	
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system;
+
+@:native("System.IFormatProvider") extern interface IFormatProvider
+{
+	
 }

+ 26 - 26
std/cs/system/LocalDataStoreSlot.hx

@@ -1,27 +1,27 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system;
-
-@:final @:native('System.LocalDataStoreSlot') extern class LocalDataStoreSlot 
-{
-	
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system;
+
+@:final @:native('System.LocalDataStoreSlot') extern class LocalDataStoreSlot 
+{
+	
 }

+ 44 - 44
std/cs/system/Math.hx

@@ -1,45 +1,45 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system;
-
-@:native("System.Math") @:nativeGen extern class Math
-{
-	public static var PI(default, null) : Float;
-
-	public static function Abs(v:Float):Float;
-	public static function Min(a:Float,b:Float):Float;
-	public static function Max(a:Float,b:Float):Float;
-	public static function Sin(v:Float):Float;
-	public static function Cos(v:Float):Float;
-	public static function Atan2(y:Float,x:Float):Float;
-	public static function Tan(v:Float):Float;
-	public static function Exp(v:Float):Float;
-	public static function Log(v:Float):Float;
-	public static function Sqrt(v:Float):Float;
-	public static function Round(v:Float):Float;
-	public static function Floor(v:Float):Float;
-	public static function Ceiling(v:Float):Float;
-	public static function Atan(v:Float):Float;
-	public static function Asin(v:Float):Float;
-	public static function Acos(v:Float):Float;
-	public static function Pow(v:Float,exp:Float):Float;
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system;
+
+@:native("System.Math") @:nativeGen extern class Math
+{
+	public static var PI(default, null) : Float;
+
+	public static function Abs(v:Float):Float;
+	public static function Min(a:Float,b:Float):Float;
+	public static function Max(a:Float,b:Float):Float;
+	public static function Sin(v:Float):Float;
+	public static function Cos(v:Float):Float;
+	public static function Atan2(y:Float,x:Float):Float;
+	public static function Tan(v:Float):Float;
+	public static function Exp(v:Float):Float;
+	public static function Log(v:Float):Float;
+	public static function Sqrt(v:Float):Float;
+	public static function Round(v:Float):Float;
+	public static function Floor(v:Float):Float;
+	public static function Ceiling(v:Float):Float;
+	public static function Atan(v:Float):Float;
+	public static function Asin(v:Float):Float;
+	public static function Acos(v:Float):Float;
+	public static function Pow(v:Float,exp:Float):Float;
 }

+ 33 - 33
std/cs/system/OperatingSystem.hx

@@ -1,34 +1,34 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system;
-
-/**
-	Warning: This class definition is incomplete.
-	In order to get most current extern definitions, install/update hxcs library with:
-		haxelib install hxcs
-	Please refer to http://lib.haxe.org/p/hxcs for more information.
-**/
-@:native('System.OperatingSystem') extern class OperatingSystem
-{
-	var Platform(default, null):cs.system.PlatformID;
-	var Version(default, null):cs.system.Version;
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system;
+
+/**
+	Warning: This class definition is incomplete.
+	In order to get most current extern definitions, install/update hxcs library with:
+		haxelib install hxcs
+	Please refer to http://lib.haxe.org/p/hxcs for more information.
+**/
+@:native('System.OperatingSystem') extern class OperatingSystem
+{
+	var Platform(default, null):cs.system.PlatformID;
+	var Version(default, null):cs.system.Version;
 }

+ 38 - 38
std/cs/system/PlatformID.hx

@@ -1,39 +1,39 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system;
-
-/**
-	Warning: This class definition is incomplete.
-	In order to get most current extern definitions, install/update hxcs library with:
-		haxelib install hxcs
-	Please refer to http://lib.haxe.org/p/hxcs for more information.
-**/
-@:native('System.PlatformID') extern enum PlatformID
-{
-	Win32S;
-	Win32Windows;
-	Win32NT;
-	WinCE;
-	Unix;
-	Xbox;
-	MacOSX;
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system;
+
+/**
+	Warning: This class definition is incomplete.
+	In order to get most current extern definitions, install/update hxcs library with:
+		haxelib install hxcs
+	Please refer to http://lib.haxe.org/p/hxcs for more information.
+**/
+@:native('System.PlatformID') extern enum PlatformID
+{
+	Win32S;
+	Win32Windows;
+	Win32NT;
+	WinCE;
+	Unix;
+	Xbox;
+	MacOSX;
 }

+ 34 - 34
std/cs/system/Random.hx

@@ -1,35 +1,35 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system;
-
-@:native("System.Random")
-extern class Random 
-{
-
-	public function new():Void;
-	
-	@:overload(function(max:Int):Int {})
-	@:overload(function(min:Int, max:Int):Int {})
-	public function Next():Int;
-	
-	public function NextDouble():Float;
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system;
+
+@:native("System.Random")
+extern class Random 
+{
+
+	public function new():Void;
+	
+	@:overload(function(max:Int):Int {})
+	@:overload(function(min:Int, max:Int):Int {})
+	public function Next():Int;
+	
+	public function NextDouble():Float;
 }

+ 37 - 37
std/cs/system/Type.hx

@@ -1,38 +1,38 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system;
-import cs.NativeArray;
-import cs.system.reflection.ConstructorInfo;
-
-@:native("System.Type")
-extern class Type 
-{
-	public var Name(default, null):String;
-	public var BaseType(default, null):Type;
-	public var IsInterface(default, null):Bool;
-	public var ContainsGenericParameters(default, null):Bool;
-	public var IsValueType(default, null):Bool;
-	public function IsAssignableFrom(c:Type):Bool;
-	
-	public static function GetType(name:String):Null<Type>;
-	public function GetConstructors():NativeArray<ConstructorInfo>;
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system;
+import cs.NativeArray;
+import cs.system.reflection.ConstructorInfo;
+
+@:native("System.Type")
+extern class Type 
+{
+	public var Name(default, null):String;
+	public var BaseType(default, null):Type;
+	public var IsInterface(default, null):Bool;
+	public var ContainsGenericParameters(default, null):Bool;
+	public var IsValueType(default, null):Bool;
+	public function IsAssignableFrom(c:Type):Bool;
+	
+	public static function GetType(name:String):Null<Type>;
+	public function GetConstructors():NativeArray<ConstructorInfo>;
 }

+ 35 - 35
std/cs/system/Version.hx

@@ -1,36 +1,36 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system;
-
-/**
-	Warning: This class definition is incomplete.
-	In order to get most current extern definitions, install/update hxcs library with:
-		haxelib install hxcs
-	Please refer to http://lib.haxe.org/p/hxcs for more information.
-**/
-@:native('System.Version') extern class Version
-{
-	var Build(default, null):Int;
-	var Major(default, null):Int;
-	var Minor(default, null):Int;
-	var Revision(default, null):Int;
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system;
+
+/**
+	Warning: This class definition is incomplete.
+	In order to get most current extern definitions, install/update hxcs library with:
+		haxelib install hxcs
+	Please refer to http://lib.haxe.org/p/hxcs for more information.
+**/
+@:native('System.Version') extern class Version
+{
+	var Build(default, null):Int;
+	var Major(default, null):Int;
+	var Minor(default, null):Int;
+	var Revision(default, null):Int;
 }

+ 31 - 31
std/cs/system/collections/ICollection.hx

@@ -1,32 +1,32 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system.collections;
-
-@:native('System.Collections.ICollection') extern interface ICollection extends IEnumerable
-{
-	var Count(default, null):Int;
-	var IsSynchronized(default, null):Bool;
-	var SyncRoot(default, null):Bool;
-	
-	function CopyTo(arr:cs.system.Array, index:Int):Void;
-	function GetEnumerator():IEnumerator;
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system.collections;
+
+@:native('System.Collections.ICollection') extern interface ICollection extends IEnumerable
+{
+	var Count(default, null):Int;
+	var IsSynchronized(default, null):Bool;
+	var SyncRoot(default, null):Bool;
+	
+	function CopyTo(arr:cs.system.Array, index:Int):Void;
+	function GetEnumerator():IEnumerator;
 }

+ 40 - 40
std/cs/system/collections/IDictionary.hx

@@ -1,40 +1,40 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system.collections;
-
-@:native('System.Collections.IDictionary') extern interface IDictionary extends ICollection
-{
-	var IsFixedSize(default, null):Bool;
-	var IsReadOnly(default, null):Bool;
-
-	function Add(key:Dynamic, value:Dynamic):Void;
-	function Clear():Void;
-	function Contains(key:Dynamic):Bool;
-	function Remove(key:Dynamic):Void;
-	function GetEnumerator():IDictionaryEnumerator;
-}
-
-@:native('System.Collections.IDictionaryEnumerator') extern interface IDictionaryEnumerator extends IEnumerator
-{
-	var Key(default, null):Dynamic;
-	var Value(default, null):Dynamic;
-}
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system.collections;
+
+@:native('System.Collections.IDictionary') extern interface IDictionary extends ICollection
+{
+	var IsFixedSize(default, null):Bool;
+	var IsReadOnly(default, null):Bool;
+
+	function Add(key:Dynamic, value:Dynamic):Void;
+	function Clear():Void;
+	function Contains(key:Dynamic):Bool;
+	function Remove(key:Dynamic):Void;
+	function GetEnumerator():IDictionaryEnumerator;
+}
+
+@:native('System.Collections.IDictionaryEnumerator') extern interface IDictionaryEnumerator extends IEnumerator
+{
+	var Key(default, null):Dynamic;
+	var Value(default, null):Dynamic;
+}

+ 26 - 26
std/cs/system/collections/IEnumerable.hx

@@ -1,27 +1,27 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system.collections;
-
-@:native('System.Collections.IEnumerable') extern interface IEnumerable
-{
-	function GetEnumerator():IEnumerator;
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system.collections;
+
+@:native('System.Collections.IEnumerable') extern interface IEnumerable
+{
+	function GetEnumerator():IEnumerator;
 }

+ 28 - 28
std/cs/system/collections/IEnumerator.hx

@@ -1,29 +1,29 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system.collections;
-
-@:native('System.Collections.IEnumerator') extern interface IEnumerator
-{
-	var Current(default, null):Dynamic;
-	function MoveNext():Bool;
-	function Reset():Void;
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system.collections;
+
+@:native('System.Collections.IEnumerator') extern interface IEnumerator
+{
+	var Current(default, null):Dynamic;
+	function MoveNext():Bool;
+	function Reset():Void;
 }

+ 40 - 40
std/cs/system/io/Directory.hx

@@ -1,41 +1,41 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system.io;
-import cs.NativeArray;
-import cs.NativeArray;
-
-@:native('System.IO.Directory') extern class Directory 
-{
-	static function CreateDirectory(path:String):Void;
-	static function Delete(path:String):Void;
-	static function Exists(path:String):Bool;
-	static function GetCurrentDirectory():String;
-	static function GetDirectories(path:String):NativeArray<String>;
-	static function GetDirectoryRoot(path:String):String;
-	static function GetFiles(path:String):NativeArray<String>;
-	static function GetFileSystemEntries(path:String):NativeArray<String>;
-	static function GetCreationTime(path:String):cs.system.DateTime;
-	static function GetLastAccessTime(path:String):cs.system.DateTime;
-	static function GetLastWriteTime(path:String):cs.system.DateTime;
-	static function Move(path:String, newpath:String):Void;
-	static function SetCurrentDirectory(path:String):Void;
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system.io;
+import cs.NativeArray;
+import cs.NativeArray;
+
+@:native('System.IO.Directory') extern class Directory 
+{
+	static function CreateDirectory(path:String):Void;
+	static function Delete(path:String):Void;
+	static function Exists(path:String):Bool;
+	static function GetCurrentDirectory():String;
+	static function GetDirectories(path:String):NativeArray<String>;
+	static function GetDirectoryRoot(path:String):String;
+	static function GetFiles(path:String):NativeArray<String>;
+	static function GetFileSystemEntries(path:String):NativeArray<String>;
+	static function GetCreationTime(path:String):cs.system.DateTime;
+	static function GetLastAccessTime(path:String):cs.system.DateTime;
+	static function GetLastWriteTime(path:String):cs.system.DateTime;
+	static function Move(path:String, newpath:String):Void;
+	static function SetCurrentDirectory(path:String):Void;
 }

+ 38 - 38
std/cs/system/io/DirectoryInfo.hx

@@ -1,39 +1,39 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system.io;
-import haxe.Int64;
-
-@:final @:native('System.IO.DirectoryInfo') extern class DirectoryInfo 
-{
-	var Attributes(default, null):FileAttributes;
-	var CreationTime(default, null):cs.system.DateTime;
-	var Exists(default, null):Bool;
-	var Extension(default, null):String;
-	var FullName(default, null):String;
-	var LastAccessTime(default, null):cs.system.DateTime;
-	var LastWriteTime(default, null):cs.system.DateTime;
-	var Name(default, null):String;
-	var Parent(default, null):DirectoryInfo;
-	var Root(default, null):DirectoryInfo;
-	
-	function new(path:String):Void;
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system.io;
+import haxe.Int64;
+
+@:final @:native('System.IO.DirectoryInfo') extern class DirectoryInfo 
+{
+	var Attributes(default, null):FileAttributes;
+	var CreationTime(default, null):cs.system.DateTime;
+	var Exists(default, null):Bool;
+	var Extension(default, null):String;
+	var FullName(default, null):String;
+	var LastAccessTime(default, null):cs.system.DateTime;
+	var LastWriteTime(default, null):cs.system.DateTime;
+	var Name(default, null):String;
+	var Parent(default, null):DirectoryInfo;
+	var Root(default, null):DirectoryInfo;
+	
+	function new(path:String):Void;
 }

+ 40 - 40
std/cs/system/io/File.hx

@@ -1,41 +1,41 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system.io;
-
-@:native('System.IO.File') extern class File 
-{
-	//not compatible with XNA
-	//static function AppendAllText(path:String, contents:String):Void;
-	static function Copy(source:String, dest:String):Void;
-	
-	@:overload(function(path:String, bufferSize:Int):FileStream {})
-	static function Create(path:String):FileStream;
-	
-	static function Delete(path:String):Void;
-	static function Exists(path:String):Bool;
-	static function GetCreationTime(path:String):cs.system.DateTime;
-	static function GetLastAccessTime(path:String):cs.system.DateTime;
-	static function GetLastWriteTime(path:String):cs.system.DateTime;
-	static function Move(source:String, dest:String):Void;
-	
-	
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system.io;
+
+@:native('System.IO.File') extern class File 
+{
+	//not compatible with XNA
+	//static function AppendAllText(path:String, contents:String):Void;
+	static function Copy(source:String, dest:String):Void;
+	
+	@:overload(function(path:String, bufferSize:Int):FileStream {})
+	static function Create(path:String):FileStream;
+	
+	static function Delete(path:String):Void;
+	static function Exists(path:String):Bool;
+	static function GetCreationTime(path:String):cs.system.DateTime;
+	static function GetLastAccessTime(path:String):cs.system.DateTime;
+	static function GetLastWriteTime(path:String):cs.system.DateTime;
+	static function Move(source:String, dest:String):Void;
+	
+	
 }

+ 28 - 28
std/cs/system/io/FileAccess.hx

@@ -1,29 +1,29 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system.io;
-
-@:native('System.IO.FileAccess') extern enum FileAccess 
-{
-	Read;
-	Write;
-	ReadWrite;
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system.io;
+
+@:native('System.IO.FileAccess') extern enum FileAccess 
+{
+	Read;
+	Write;
+	ReadWrite;
 }

+ 39 - 39
std/cs/system/io/FileAttributes.hx

@@ -1,40 +1,40 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system.io;
-
-@:native('System.IO.FileAttributes') extern enum FileAttributes 
-{
-	ReadOnly;
-	Hidden;
-	System;
-	Directory;
-	Archive;
-	Device;
-	Normal;
-	Temporary;
-	SparseFile;
-	ReparsePoint;
-	Compressed;
-	Offline;
-	NotContentIndexed;
-	Encrypted;
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system.io;
+
+@:native('System.IO.FileAttributes') extern enum FileAttributes 
+{
+	ReadOnly;
+	Hidden;
+	System;
+	Directory;
+	Archive;
+	Device;
+	Normal;
+	Temporary;
+	SparseFile;
+	ReparsePoint;
+	Compressed;
+	Offline;
+	NotContentIndexed;
+	Encrypted;
 }

+ 39 - 39
std/cs/system/io/FileInfo.hx

@@ -1,40 +1,40 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system.io;
-import haxe.Int64;
-
-@:final @:native('System.IO.FileInfo') extern class FileInfo 
-{
-	var Attributes(default, null):FileAttributes;
-	var CreationTime(default, null):cs.system.DateTime;
-	var Directory(default, null):DirectoryInfo;
-	var DirectoryName(default, null):String;
-	var Exists(default, null):Bool;
-	var Extension(default, null):String;
-	var FullName(default, null):String;
-	var LastAccessTime(default, null):cs.system.DateTime;
-	var LastWriteTime(default, null):cs.system.DateTime;
-	var Length(default, null):Int64;
-	var Name(default, null):String;
-	
-	function new(filename:String):Void;
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system.io;
+import haxe.Int64;
+
+@:final @:native('System.IO.FileInfo') extern class FileInfo 
+{
+	var Attributes(default, null):FileAttributes;
+	var CreationTime(default, null):cs.system.DateTime;
+	var Directory(default, null):DirectoryInfo;
+	var DirectoryName(default, null):String;
+	var Exists(default, null):Bool;
+	var Extension(default, null):String;
+	var FullName(default, null):String;
+	var LastAccessTime(default, null):cs.system.DateTime;
+	var LastWriteTime(default, null):cs.system.DateTime;
+	var Length(default, null):Int64;
+	var Name(default, null):String;
+	
+	function new(filename:String):Void;
 }

+ 31 - 31
std/cs/system/io/FileMode.hx

@@ -1,32 +1,32 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system.io;
-
-@:native('System.IO.FileMode') extern enum FileMode 
-{
-	CreateNew;
-	Create;
-	Open;
-	OpenOrCreate;
-	Truncate;
-	Append;
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system.io;
+
+@:native('System.IO.FileMode') extern enum FileMode 
+{
+	CreateNew;
+	Create;
+	Open;
+	OpenOrCreate;
+	Truncate;
+	Append;
 }

+ 29 - 29
std/cs/system/io/FileShare.hx

@@ -1,30 +1,30 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system.io;
-
-@:native('System.IO.FileShare') extern enum FileShare 
-{
-	None;
-	Read;
-	Write;
-	ReadWrite;
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system.io;
+
+@:native('System.IO.FileShare') extern enum FileShare 
+{
+	None;
+	Read;
+	Write;
+	ReadWrite;
 }

+ 32 - 32
std/cs/system/io/FileStream.hx

@@ -1,33 +1,33 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system.io;
-
-@:native('System.IO.FileStream') extern class FileStream extends Stream
-{
-	@:overload(function (path:String, mode:FileMode, access:FileAccess, share:FileShare, bufferSize:Int, useAsync:Bool):Void {})
-	@:overload(function (path:String, mode:FileMode, access:FileAccess, share:FileShare, bufferSize:Int):Void {})
-	@:overload(function (path:String, mode:FileMode, access:FileAccess, share:FileShare):Void {})
-	@:overload(function (path:String, mode:FileMode, access:FileAccess):Void {})
-	function new(path:String, mode:FileMode):Void;
-	var IsAsync(default, null):Bool;
-	var Name(default, null):String;
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system.io;
+
+@:native('System.IO.FileStream') extern class FileStream extends Stream
+{
+	@:overload(function (path:String, mode:FileMode, access:FileAccess, share:FileShare, bufferSize:Int, useAsync:Bool):Void {})
+	@:overload(function (path:String, mode:FileMode, access:FileAccess, share:FileShare, bufferSize:Int):Void {})
+	@:overload(function (path:String, mode:FileMode, access:FileAccess, share:FileShare):Void {})
+	@:overload(function (path:String, mode:FileMode, access:FileAccess):Void {})
+	function new(path:String, mode:FileMode):Void;
+	var IsAsync(default, null):Bool;
+	var Name(default, null):String;
 }

+ 32 - 32
std/cs/system/io/MemoryStream.hx

@@ -1,33 +1,33 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system.io;
-import cs.NativeArray;
-import cs.StdTypes;
-import haxe.Int64;
-import haxe.io.BytesData;
-
-@:native('System.IO.MemoryStream') extern class MemoryStream extends Stream 
-{
-	function new():Void;
-	function GetBuffer():NativeArray<UInt8>;
-	
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system.io;
+import cs.NativeArray;
+import cs.StdTypes;
+import haxe.Int64;
+import haxe.io.BytesData;
+
+@:native('System.IO.MemoryStream') extern class MemoryStream extends Stream 
+{
+	function new():Void;
+	function GetBuffer():NativeArray<UInt8>;
+	
 }

+ 28 - 28
std/cs/system/io/SeekOrigin.hx

@@ -1,29 +1,29 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system.io;
-
-@:native('System.IO.SeekOrigin') extern enum SeekOrigin 
-{
-	Begin;
-	Current;
-	End;
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system.io;
+
+@:native('System.IO.SeekOrigin') extern enum SeekOrigin 
+{
+	Begin;
+	Current;
+	End;
 }

+ 47 - 47
std/cs/system/io/Stream.hx

@@ -1,48 +1,48 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system.io;
-import cs.StdTypes;
-import haxe.Int64;
-import haxe.io.BytesData;
-
-@:native('System.IO.Stream') extern class Stream 
-{
-	var CanRead(default, null):Bool;
-	var CanSeek(default, null):Bool;
-	var CanTimeout(default, null):Bool;
-	var CanWrite(default, null):Bool;
-	var Length(default, null):Int64;
-	var Position(default, null):Int64;
-	var ReadTimeout:Bool;
-	var WriteTimeout:Bool;
-	
-	function Close():Void;
-	function CopyTo(dest:Stream):Void;
-	function Dispose():Void;
-	function Flush():Void;
-	function Read(buf:BytesData, offset:Int, count:Int):Int;
-	function ReadByte():Int;
-	function Seek(offset:Int64, origin:SeekOrigin):Int64;
-	function SetLength(value:Int64):Void;
-	function Write(buf:BytesData, offset:Int, count:Int):Void;
-	function WriteByte(value:UInt8):Void;
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system.io;
+import cs.StdTypes;
+import haxe.Int64;
+import haxe.io.BytesData;
+
+@:native('System.IO.Stream') extern class Stream 
+{
+	var CanRead(default, null):Bool;
+	var CanSeek(default, null):Bool;
+	var CanTimeout(default, null):Bool;
+	var CanWrite(default, null):Bool;
+	var Length(default, null):Int64;
+	var Position(default, null):Int64;
+	var ReadTimeout:Bool;
+	var WriteTimeout:Bool;
+	
+	function Close():Void;
+	function CopyTo(dest:Stream):Void;
+	function Dispose():Void;
+	function Flush():Void;
+	function Read(buf:BytesData, offset:Int, count:Int):Int;
+	function ReadByte():Int;
+	function Seek(offset:Int64, origin:SeekOrigin):Int64;
+	function SetLength(value:Int64):Void;
+	function Write(buf:BytesData, offset:Int, count:Int):Void;
+	function WriteByte(value:UInt8):Void;
 }

+ 32 - 32
std/cs/system/io/StreamReader.hx

@@ -1,33 +1,33 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system.io;
-
-/**
-	Warning: This class definition is incomplete.
-	In order to get most current extern definitions, install hxcs library with:
-		haxelib install hxcs
-	Please refer to http://lib.haxe.org/p/hxcs for more information.
-**/
-@:native('System.IO.StreamReader') extern class StreamReader 
-{
-	var BaseStream(default, null):cs.system.io.Stream;
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system.io;
+
+/**
+	Warning: This class definition is incomplete.
+	In order to get most current extern definitions, install hxcs library with:
+		haxelib install hxcs
+	Please refer to http://lib.haxe.org/p/hxcs for more information.
+**/
+@:native('System.IO.StreamReader') extern class StreamReader 
+{
+	var BaseStream(default, null):cs.system.io.Stream;
 }

+ 32 - 32
std/cs/system/io/StreamWriter.hx

@@ -1,33 +1,33 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system.io;
-
-/**
-	Warning: This class definition is incomplete.
-	In order to get most current extern definitions, install hxcs library with:
-		haxelib install hxcs
-	Please refer to http://lib.haxe.org/p/hxcs for more information.
-**/
-@:native('System.IO.StreamWriter') extern class StreamWriter 
-{
-	var BaseStream(default, null):cs.system.io.Stream;
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system.io;
+
+/**
+	Warning: This class definition is incomplete.
+	In order to get most current extern definitions, install hxcs library with:
+		haxelib install hxcs
+	Please refer to http://lib.haxe.org/p/hxcs for more information.
+**/
+@:native('System.IO.StreamWriter') extern class StreamWriter 
+{
+	var BaseStream(default, null):cs.system.io.Stream;
 }

+ 28 - 28
std/cs/system/reflection/ConstructorInfo.hx

@@ -1,29 +1,29 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system.reflection;
-import cs.NativeArray;
-
-@:native('System.Reflection.ConstructorInfo') extern class ConstructorInfo extends MethodBase
-{
-	@:overload(function(args:NativeArray<Dynamic>):Dynamic {})
-	override function Invoke(obj:Dynamic, args:NativeArray<Dynamic>):Dynamic;
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system.reflection;
+import cs.NativeArray;
+
+@:native('System.Reflection.ConstructorInfo') extern class ConstructorInfo extends MethodBase
+{
+	@:overload(function(args:NativeArray<Dynamic>):Dynamic {})
+	override function Invoke(obj:Dynamic, args:NativeArray<Dynamic>):Dynamic;
 }

+ 32 - 32
std/cs/system/reflection/MethodBase.hx

@@ -1,33 +1,33 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system.reflection;
-import cs.NativeArray;
-
-@:native('System.Reflection.MethodBase') extern class MethodBase 
-{
-	var Name(default, null):String;
-	var ContainsGenericParameters(default, null):Bool;
-	function GetParameters():NativeArray<ParameterInfo>;
-	function GetGenericArguments():NativeArray<cs.system.Type>;
-	@:overload(function():Dynamic {})
-	function Invoke(obj:Dynamic, args:NativeArray<Dynamic>):Dynamic;
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system.reflection;
+import cs.NativeArray;
+
+@:native('System.Reflection.MethodBase') extern class MethodBase 
+{
+	var Name(default, null):String;
+	var ContainsGenericParameters(default, null):Bool;
+	function GetParameters():NativeArray<ParameterInfo>;
+	function GetGenericArguments():NativeArray<cs.system.Type>;
+	@:overload(function():Dynamic {})
+	function Invoke(obj:Dynamic, args:NativeArray<Dynamic>):Dynamic;
 }

+ 29 - 29
std/cs/system/reflection/MethodInfo.hx

@@ -1,30 +1,30 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system.reflection;
-import cs.NativeArray;
-import cs.NativeArray;
-import cs.system.Type;
-
-@:native('System.Reflection.MethodInfo') extern class MethodInfo extends MethodBase 
-{
-	function MakeGenericMethod(g:NativeArray<Type>):MethodInfo;
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system.reflection;
+import cs.NativeArray;
+import cs.NativeArray;
+import cs.system.Type;
+
+@:native('System.Reflection.MethodInfo') extern class MethodInfo extends MethodBase 
+{
+	function MakeGenericMethod(g:NativeArray<Type>):MethodInfo;
 }

+ 26 - 26
std/cs/system/reflection/ParameterInfo.hx

@@ -1,27 +1,27 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system.reflection;
-
-@:native('System.Reflection.ParameterInfo') extern class ParameterInfo 
-{
-	var ParameterType(default, null):cs.system.Type;
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system.reflection;
+
+@:native('System.Reflection.ParameterInfo') extern class ParameterInfo 
+{
+	var ParameterType(default, null):cs.system.Type;
 }

+ 32 - 32
std/cs/system/text/Encoding.hx

@@ -1,33 +1,33 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system.text;
-import cs.NativeArray;
-import cs.StdTypes;
-
-@:native("System.Text.Encoding") extern class Encoding
-{
-	static var UTF8(default, null):Encoding;
-	
-	function GetString(b:NativeArray<UInt8>, index:Int, count:Int):String;
-	function GetBytes(s:String):NativeArray<UInt8>;
-	
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system.text;
+import cs.NativeArray;
+import cs.StdTypes;
+
+@:native("System.Text.Encoding") extern class Encoding
+{
+	static var UTF8(default, null):Encoding;
+	
+	function GetString(b:NativeArray<UInt8>, index:Int, count:Int):String;
+	function GetBytes(s:String):NativeArray<UInt8>;
+	
 }

+ 76 - 76
std/cs/system/text/regularExpressions/Regex.hx

@@ -1,76 +1,76 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system.text.regularExpressions;
-import cs.NativeArray;
-
-@:native('System.Text.RegularExpressions.Regex') extern class Regex
-{
-	function new(pattern:String, options:RegexOptions):Void;
-	@:overload(function(input:String, startPos:Int, len:Int):Match{})
-	@:overload(function(input:String, startPos:Int):Match{})
-	function Match(input:String):Match;
-	function Split(input:String):NativeArray<String>;
-	@:overload(function(input:String, replacement:String,max:Int):String{})
-	function Replace(input:String, replacement:String):String;
-}
-
-@:native("System.Text.RegularExpressions.RegexOptions") extern enum RegexOptions
-{
-	None;
-	IgnoreCase;
-	Multiline;
-	ExplicitCapture;
-	Compiled;
-	Singleline;
-	IgnorePatternWhitespace;
-	RightToLeft;
-	ECMAScript;
-	CultureInvariant;
-}
-
-@:native("System.Text.RegularExpressions.Capture") extern class Capture
-{
-	var Index(default, null):Int;
-	var Length(default, null):Int;
-	var Value(default, null):String;
-}
-
-@:native("System.Text.RegularExpressions.Group") extern class Group extends Capture
-{
-	var Success(default, null):Bool;
-}
-
-@:native("System.Text.RegularExpressions.Match") extern class Match extends Group
-{
-	var Captures(default, null):CaptureCollection;
-	var Groups(default, null):GroupCollection;
-}
-
-@:native("System.Text.RegularExpressions.CaptureCollection") extern class CaptureCollection implements ArrayAccess<Capture>
-{
-	var Count(default, null):Int;
-}
-
-@:native("System.Text.RegularExpressions.GroupCollection") extern class GroupCollection implements ArrayAccess<Group>
-{
-	var Count(default, null):Int;
-}
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system.text.regularExpressions;
+import cs.NativeArray;
+
+@:native('System.Text.RegularExpressions.Regex') extern class Regex
+{
+	function new(pattern:String, options:RegexOptions):Void;
+	@:overload(function(input:String, startPos:Int, len:Int):Match{})
+	@:overload(function(input:String, startPos:Int):Match{})
+	function Match(input:String):Match;
+	function Split(input:String):NativeArray<String>;
+	@:overload(function(input:String, replacement:String,max:Int):String{})
+	function Replace(input:String, replacement:String):String;
+}
+
+@:native("System.Text.RegularExpressions.RegexOptions") extern enum RegexOptions
+{
+	None;
+	IgnoreCase;
+	Multiline;
+	ExplicitCapture;
+	Compiled;
+	Singleline;
+	IgnorePatternWhitespace;
+	RightToLeft;
+	ECMAScript;
+	CultureInvariant;
+}
+
+@:native("System.Text.RegularExpressions.Capture") extern class Capture
+{
+	var Index(default, null):Int;
+	var Length(default, null):Int;
+	var Value(default, null):String;
+}
+
+@:native("System.Text.RegularExpressions.Group") extern class Group extends Capture
+{
+	var Success(default, null):Bool;
+}
+
+@:native("System.Text.RegularExpressions.Match") extern class Match extends Group
+{
+	var Captures(default, null):CaptureCollection;
+	var Groups(default, null):GroupCollection;
+}
+
+@:native("System.Text.RegularExpressions.CaptureCollection") extern class CaptureCollection implements ArrayAccess<Capture>
+{
+	var Count(default, null):Int;
+}
+
+@:native("System.Text.RegularExpressions.GroupCollection") extern class GroupCollection implements ArrayAccess<Group>
+{
+	var Count(default, null):Int;
+}

+ 43 - 43
std/cs/system/threading/Thread.hx

@@ -1,44 +1,44 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-package cs.system.threading;
-import cs.system.LocalDataStoreSlot;
-
-@:native("System.Threading.ThreadStart") @:delegate typedef ThreadStart = Void->Void;
-
-@:native("System.Threading.Thread") extern class Thread
-{
-	static function AllocateDataStoreSlot():LocalDataStoreSlot;
-	static function GetData(slot:LocalDataStoreSlot):Dynamic;
-	static function SetData(slot:LocalDataStoreSlot, data:Dynamic):Void;
-	static function Sleep(ms:Int):Void;
-	
-	@:overload(function(s:ThreadStart, maxStack:Int):Void {})
-	function new(s:ThreadStart):Void;
-	
-	@:overload(function(obj:Dynamic):Void {})
-	function Abort():Void;
-	
-	@:overload(function(msTimeout:Int):Void {})
-	function Join():Void;
-	
-	function Start():Void;
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package cs.system.threading;
+import cs.system.LocalDataStoreSlot;
+
+@:native("System.Threading.ThreadStart") @:delegate typedef ThreadStart = Void->Void;
+
+@:native("System.Threading.Thread") extern class Thread
+{
+	static function AllocateDataStoreSlot():LocalDataStoreSlot;
+	static function GetData(slot:LocalDataStoreSlot):Dynamic;
+	static function SetData(slot:LocalDataStoreSlot, data:Dynamic):Void;
+	static function Sleep(ms:Int):Void;
+	
+	@:overload(function(s:ThreadStart, maxStack:Int):Void {})
+	function new(s:ThreadStart):Void;
+	
+	@:overload(function(obj:Dynamic):Void {})
+	function Abort():Void;
+	
+	@:overload(function(msTimeout:Int):Void {})
+	function Join():Void;
+	
+	function Start():Void;
 }

+ 412 - 412
std/flash/_std/Xml.hx

@@ -1,412 +1,412 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-import flash.xml.XML;
-import flash.xml.XMLList;
-
-extern enum XmlType {
-}
-
-@:coreApi class Xml {
-
-	public static var Element(default,null) : XmlType;
-	public static var PCData(default,null) : XmlType;
-	public static var CData(default,null) : XmlType;
-	public static var Comment(default,null) : XmlType;
-	public static var DocType(default,null) : XmlType;
-	public static var ProcessingInstruction(default,null) : XmlType;
-	public static var Document(default,null) : XmlType;
-
-	public var nodeType(default,null) : XmlType;
-	public var nodeName(get,set) : String;
-	public var nodeValue(get,set) : String;
-	public var parent(get,null) : Xml;
-
-	var _node : flash.xml.XML;
-
-	public static function parse( str : String ) : Xml {
-		XML.ignoreWhitespace = false;
-		XML.ignoreProcessingInstructions = false;
-		XML.ignoreComments = false;
-		var prefix = "<__document";
-		var root = null;
-		while( root == null ) {
-			try {
-				root = new flash.xml.XML(prefix+">" + str + "</__document>");
-			} catch( e : flash.errors.TypeError ) {
-				// if we miss a namespace, let's add it !
-				var r = ~/"([^"]+)"/; //"
-				if( e.errorID == 1083 && r.match(e.message) ) {
-					var ns = r.matched(1);
-					prefix += " xmlns:" + ns + '="@' + ns + '"';
-				} else
-					throw e;
-			}
-		}
-		return wrap( root, Xml.Document );
-	}
-
-	@:keep #if as3 @:hack public #end static function compare( a : Xml, b : Xml ) : Bool {
-		return a == null ? b == null : (b == null ? false : a._node == b._node);
-	}
-
-	private function new() : Void {}
-
-	public static function createElement( name : String ) : Xml {
-		return wrap( new flash.xml.XML("<"+name+"/>"), Xml.Element );
-	}
-
-	public static function createPCData( data : String ) : Xml {
-		XML.ignoreWhitespace = false;
-		return wrap( new flash.xml.XML(data), Xml.PCData );
-	}
-
-	public static function createCData( data : String ) : Xml {
-		return wrap( new flash.xml.XML("<![CDATA["+data+"]]>"), Xml.CData );
-	}
-
-	public static function createComment( data : String ) : Xml {
-		XML.ignoreComments = false;
-		return wrap( new flash.xml.XML("<!--"+data+"-->"), Xml.Comment );
-	}
-
-	public static function createDocType( data : String ) : Xml {
-		return wrap( new flash.xml.XML("<!DOCTYPE "+data+">"), Xml.DocType );
-	}
-
-	public static function createProcessingInstruction( data : String ) : Xml {
-		XML.ignoreProcessingInstructions = false;
-		return wrap( new flash.xml.XML("<?"+data+"?>"), Xml.ProcessingInstruction );
-	}
-
-	public static function createDocument() : Xml {
-		return wrap( new flash.xml.XML("<__document/>"), Xml.Document );
-	}
-
-	private static function getNodeType( node : flash.xml.XML ) : XmlType {
-		switch( node.nodeKind() ) {
-		case "element":
-			return Xml.Element;
-		case "text":
-			return Xml.PCData;
-		case "processing-instruction":
-			return Xml.ProcessingInstruction;
-		case "comment":
-			return Xml.Comment;
-		default :
-			throw "unimplemented node type: " + node.nodeType;
-		}
-		return null;
-	}
-
-	private function get_nodeName() : String {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		var ns = _node.namespace();
-		return (ns.prefix == "") ? _node.localName() : ns.prefix+":"+_node.localName();
-	}
-
-	private function set_nodeName( n : String ) : String {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		var ns = n.split(":");
-		if( ns.length == 1 )
-			_node.setLocalName(n);
-		else {
-			_node.setLocalName(ns[1]);
-			_node.setNamespace(_node.namespace(ns[0]));
-		}
-		return n;
-	}
-
-	private function get_nodeValue() : String {
-		var nodeType = nodeType;
-		if( nodeType == Xml.Element || nodeType == Xml.Document )
-			throw "bad nodeType";
-		if( nodeType == Xml.Comment )
-			return _node.toString().substr(4,-7);
-		return _node.toString();
-	}
-
-	private function set_nodeValue( v : String ) : String {
-		var nodeType = nodeType;
-		var x = null;
-		if( nodeType == Xml.Element || nodeType == Xml.Document )
-			throw "bad nodeType";
-		else if( nodeType == Xml.PCData )
-			x = createPCData(v);
-		else if( nodeType == Xml.CData )
-			x = createCData(v);
-		else if( nodeType == Xml.Comment )
-			x = createComment(v);
-		else if( nodeType == Xml.DocType )
-			x = createDocType(v);
-		else
-			x = createProcessingInstruction(v);
-		var p = _node.parent();
-		if( p != null ) {
-			p.insertChildAfter(_node, x._node);
-			var i = _node.childIndex();
-			var children = p.children();
-			untyped __delete__(children, Reflect.fields(children)[i]);
-		}
-		_node = x._node;
-		return v;
-	}
-
-	private function get_parent() :Xml {
-		var p = _node.parent();
-		return p == null ? null : wrap( p );
-	}
-
-	private static function wrap( node : XML, ?type : XmlType ) : Xml {
-		var x = new Xml();
-		x._node = node;
-		x.nodeType = (type != null) ? type : getNodeType( node );
-		return x;
-	}
-
-	private function wraps( xList : XMLList ) : Array<Xml> {
-		var out = new Array<Xml>();
-		for( i in 0...xList.length() )
-			out.push( wrap(xList[i]) );
-		return out;
-	}
-
-	function getAttribNS( cur : XML, ns : Array<String> ) : XMLList {
-		var n = cur.namespace(ns[0]);
-		if( n == null ) {
-			var parent = cur.parent();
-			if( parent == null ) {
-				n = new flash.utils.Namespace(ns[0], "@"+ns[0]);
-				cur.addNamespace(n);
-			} else
-				return getAttribNS(parent, ns);
-		}
-		return _node.attribute(new flash.utils.QName(n,ns[1]));
-	}
-
-	public function get( att : String ) : String {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		var ns = att.split(":");
-		if( ns[0] == "xmlns" ) {
-			var n = _node.namespace((ns[1] == null) ? "" : ns[1]);
-			return (n == null) ? null : n.uri;
-		}
-		if( ns.length == 1 ) {
-			if( !Reflect.hasField(_node,"@"+att) )
-				return null;
-			return Reflect.field(_node, "@"+att);
-		}
-		var a = getAttribNS(_node,ns);
-		return (a.length() == 0) ? null : a.toString();
-	}
-
-	public function set( att : String, value : String ) : Void {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		var ns = att.split(":");
-		if( ns[0] == "xmlns" ) {
-			var n = _node.namespace((ns[1] == null) ? "" : ns[1]);
-			if( n != null )
-				throw "Can't modify namespace";
-			if( ns[1] == null )
-				throw "Can't set default namespace";
-			_node.addNamespace(new flash.utils.Namespace(ns[1], value));
-			return;
-		}
-		if( ns.length == 1 )
-			Reflect.setField(_node, "@"+att, value);
-		else {
-			var a = getAttribNS(_node,ns);
-			untyped a[0] = value;
-		}
-	}
-
-	public function remove( att : String ) : Void{
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		var ns = att.split(":");
-		if( ns.length == 1 )
-			Reflect.deleteField(_node, "@"+att);
-		else
-			untyped __delete__(getAttribNS(_node,ns),0);
-	}
-
-	public function exists( att : String ) : Bool {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		var ns = att.split(":");
-		if( ns[0] == "xmlns" )
-			return _node.namespace((ns[1] == null) ? "" : ns[1]) != null;
-		if( ns.length == 1 )
-			return Reflect.hasField(_node, "@"+att);
-		return getAttribNS(_node,ns).length() > 0;
-	}
-
-	public function attributes() : Iterator<String> {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		var attributes :XMLList = _node.attributes();
-		var names = Reflect.fields(attributes);
-		var cur = 0;
-		return {
-			hasNext : function(){
-				return cur < names.length;
-			},
-			next : function(){
-				return attributes[Std.parseInt(names[cur++])].name();
-			}
-		}
-	}
-
-	public function iterator() : Iterator<Xml> {
-		if( nodeType != Xml.Element && nodeType != Xml.Document )
-			throw "bad nodeType";
-		var children:XMLList = _node.children();
-		var wrappers :Array<Xml> = wraps(children);
-		var cur = 0;
-		return {
-			hasNext : function(){
-				return cur < wrappers.length;
-			},
-			next : function(){
-				return wrappers[cur++];
-			}
-		};
-	}
-
-	public function elements() : Iterator<Xml> {
-		if( nodeType != Xml.Element && nodeType != Xml.Document )
-			throw "bad nodeType";
-		var elements:XMLList = _node.elements();
-		var wrappers :Array<Xml> = wraps(elements);
-		var cur = 0;
-		return {
-			hasNext : function(){
-				return cur < wrappers.length;
-			},
-			next : function(){
-				return wrappers[cur++];
-			}
-		};
-	}
-
-	public function elementsNamed( name : String ) : Iterator<Xml> {
-		if( nodeType != Xml.Element && nodeType != Xml.Document )
-			throw "bad nodeType";
-		var ns = name.split(":");
-		var elements:XMLList;
-		if( ns.length == 1 )
-			elements = _node.elements(name);
-		else
-			elements = _node.elements();
-		var wrappers :Array<Xml> = wraps(elements);
-		if( ns.length != 1 )
-			for( w in wrappers.copy() )
-				if( w._node.localName() != ns[1] || w._node.namespace().prefix != ns[0] )
-					wrappers.remove(w);
-		var cur = 0;
-		return {
-			hasNext : function(){
-				return cur < wrappers.length;
-			},
-			next : function(){
-				return wrappers[cur++];
-			}
-		};
-	}
-
-	public function firstChild() : Xml {
-		if( nodeType != Xml.Element && nodeType != Xml.Document )
-			throw "bad nodeType";
-		var children:XMLList = _node.children();
-		if( children.length() == 0 )
-			return null;
-		return wrap( children[0] );
-	}
-
-	public function firstElement() : Xml {
-		if( nodeType != Xml.Element && nodeType != Xml.Document )
-			throw "bad nodeType";
-		var elements:XMLList = _node.elements();
-		if( elements.length() == 0 )
-			return null;
-		return wrap( elements[0] );
-	}
-
-	public function addChild( x : Xml ) : Void {
-		if( nodeType != Xml.Element && nodeType != Xml.Document )
-			throw "bad nodeType";
-		if (x.parent != null)
-			x.parent.removeChild(x);
-		var children:XMLList = _node.children();
-		_node.appendChild(x._node);
-	}
-
-	public function removeChild( x : Xml ) : Bool {
-		if( nodeType != Xml.Element && nodeType != Xml.Document )
-			throw "bad nodeType";
-		var children:XMLList = _node.children();
-		if( _node != x._node.parent() )
-			return false;
-		var i = x._node.childIndex();
-		untyped __delete__(children, Reflect.fields(children)[i]);
-		return true;
-	}
-
-	public function insertChild( x : Xml, pos : Int ) : Void {
-		if( nodeType != Xml.Element && nodeType != Xml.Document )
-			throw "bad nodeType";
-		if (x.parent != null)
-			x.parent.removeChild(x);			
-		var children:XMLList = _node.children();
-		if( pos < children.length() )
-			_node.insertChildBefore(children[pos], x._node);
-		else
-			_node.appendChild(x._node);
-	}
-
-	public function toString() : String {
-		XML.prettyPrinting = false;
-		if( nodeType == Xml.Document ) {
-			var str = _node.toXMLString();
-			// remove <__document xmlns....>STR</__document> wrapper
-			str = str.substr(str.indexOf(">") + 1);
-			str = str.substr(0, str.length - 13);
-			return str;
-		}
-		return _node.toXMLString();
-	}
-
-	static function __init__() : Void untyped {
-		Element = "element";
-		PCData = "pcdata";
-		CData = "cdata";
-		Comment = "comment";
-		DocType = "doctype";
-		ProcessingInstruction = "processingInstruction";
-		Document = "document";
-	}
-
-
-}
+/*
+ * Copyright (C)2005-2012 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+import flash.xml.XML;
+import flash.xml.XMLList;
+
+extern enum XmlType {
+}
+
+@:coreApi class Xml {
+
+	public static var Element(default,null) : XmlType;
+	public static var PCData(default,null) : XmlType;
+	public static var CData(default,null) : XmlType;
+	public static var Comment(default,null) : XmlType;
+	public static var DocType(default,null) : XmlType;
+	public static var ProcessingInstruction(default,null) : XmlType;
+	public static var Document(default,null) : XmlType;
+
+	public var nodeType(default,null) : XmlType;
+	public var nodeName(get,set) : String;
+	public var nodeValue(get,set) : String;
+	public var parent(get,null) : Xml;
+
+	var _node : flash.xml.XML;
+
+	public static function parse( str : String ) : Xml {
+		XML.ignoreWhitespace = false;
+		XML.ignoreProcessingInstructions = false;
+		XML.ignoreComments = false;
+		var prefix = "<__document";
+		var root = null;
+		while( root == null ) {
+			try {
+				root = new flash.xml.XML(prefix+">" + str + "</__document>");
+			} catch( e : flash.errors.TypeError ) {
+				// if we miss a namespace, let's add it !
+				var r = ~/"([^"]+)"/; //"
+				if( e.errorID == 1083 && r.match(e.message) ) {
+					var ns = r.matched(1);
+					prefix += " xmlns:" + ns + '="@' + ns + '"';
+				} else
+					throw e;
+			}
+		}
+		return wrap( root, Xml.Document );
+	}
+
+	@:keep #if as3 @:hack public #end static function compare( a : Xml, b : Xml ) : Bool {
+		return a == null ? b == null : (b == null ? false : a._node == b._node);
+	}
+
+	private function new() : Void {}
+
+	public static function createElement( name : String ) : Xml {
+		return wrap( new flash.xml.XML("<"+name+"/>"), Xml.Element );
+	}
+
+	public static function createPCData( data : String ) : Xml {
+		XML.ignoreWhitespace = false;
+		return wrap( new flash.xml.XML(data), Xml.PCData );
+	}
+
+	public static function createCData( data : String ) : Xml {
+		return wrap( new flash.xml.XML("<![CDATA["+data+"]]>"), Xml.CData );
+	}
+
+	public static function createComment( data : String ) : Xml {
+		XML.ignoreComments = false;
+		return wrap( new flash.xml.XML("<!--"+data+"-->"), Xml.Comment );
+	}
+
+	public static function createDocType( data : String ) : Xml {
+		return wrap( new flash.xml.XML("<!DOCTYPE "+data+">"), Xml.DocType );
+	}
+
+	public static function createProcessingInstruction( data : String ) : Xml {
+		XML.ignoreProcessingInstructions = false;
+		return wrap( new flash.xml.XML("<?"+data+"?>"), Xml.ProcessingInstruction );
+	}
+
+	public static function createDocument() : Xml {
+		return wrap( new flash.xml.XML("<__document/>"), Xml.Document );
+	}
+
+	private static function getNodeType( node : flash.xml.XML ) : XmlType {
+		switch( node.nodeKind() ) {
+		case "element":
+			return Xml.Element;
+		case "text":
+			return Xml.PCData;
+		case "processing-instruction":
+			return Xml.ProcessingInstruction;
+		case "comment":
+			return Xml.Comment;
+		default :
+			throw "unimplemented node type: " + node.nodeType;
+		}
+		return null;
+	}
+
+	private function get_nodeName() : String {
+		if( nodeType != Xml.Element )
+			throw "bad nodeType";
+		var ns = _node.namespace();
+		return (ns.prefix == "") ? _node.localName() : ns.prefix+":"+_node.localName();
+	}
+
+	private function set_nodeName( n : String ) : String {
+		if( nodeType != Xml.Element )
+			throw "bad nodeType";
+		var ns = n.split(":");
+		if( ns.length == 1 )
+			_node.setLocalName(n);
+		else {
+			_node.setLocalName(ns[1]);
+			_node.setNamespace(_node.namespace(ns[0]));
+		}
+		return n;
+	}
+
+	private function get_nodeValue() : String {
+		var nodeType = nodeType;
+		if( nodeType == Xml.Element || nodeType == Xml.Document )
+			throw "bad nodeType";
+		if( nodeType == Xml.Comment )
+			return _node.toString().substr(4,-7);
+		return _node.toString();
+	}
+
+	private function set_nodeValue( v : String ) : String {
+		var nodeType = nodeType;
+		var x = null;
+		if( nodeType == Xml.Element || nodeType == Xml.Document )
+			throw "bad nodeType";
+		else if( nodeType == Xml.PCData )
+			x = createPCData(v);
+		else if( nodeType == Xml.CData )
+			x = createCData(v);
+		else if( nodeType == Xml.Comment )
+			x = createComment(v);
+		else if( nodeType == Xml.DocType )
+			x = createDocType(v);
+		else
+			x = createProcessingInstruction(v);
+		var p = _node.parent();
+		if( p != null ) {
+			p.insertChildAfter(_node, x._node);
+			var i = _node.childIndex();
+			var children = p.children();
+			untyped __delete__(children, Reflect.fields(children)[i]);
+		}
+		_node = x._node;
+		return v;
+	}
+
+	private function get_parent() :Xml {
+		var p = _node.parent();
+		return p == null ? null : wrap( p );
+	}
+
+	private static function wrap( node : XML, ?type : XmlType ) : Xml {
+		var x = new Xml();
+		x._node = node;
+		x.nodeType = (type != null) ? type : getNodeType( node );
+		return x;
+	}
+
+	private function wraps( xList : XMLList ) : Array<Xml> {
+		var out = new Array<Xml>();
+		for( i in 0...xList.length() )
+			out.push( wrap(xList[i]) );
+		return out;
+	}
+
+	function getAttribNS( cur : XML, ns : Array<String> ) : XMLList {
+		var n = cur.namespace(ns[0]);
+		if( n == null ) {
+			var parent = cur.parent();
+			if( parent == null ) {
+				n = new flash.utils.Namespace(ns[0], "@"+ns[0]);
+				cur.addNamespace(n);
+			} else
+				return getAttribNS(parent, ns);
+		}
+		return _node.attribute(new flash.utils.QName(n,ns[1]));
+	}
+
+	public function get( att : String ) : String {
+		if( nodeType != Xml.Element )
+			throw "bad nodeType";
+		var ns = att.split(":");
+		if( ns[0] == "xmlns" ) {
+			var n = _node.namespace((ns[1] == null) ? "" : ns[1]);
+			return (n == null) ? null : n.uri;
+		}
+		if( ns.length == 1 ) {
+			if( !Reflect.hasField(_node,"@"+att) )
+				return null;
+			return Reflect.field(_node, "@"+att);
+		}
+		var a = getAttribNS(_node,ns);
+		return (a.length() == 0) ? null : a.toString();
+	}
+
+	public function set( att : String, value : String ) : Void {
+		if( nodeType != Xml.Element )
+			throw "bad nodeType";
+		var ns = att.split(":");
+		if( ns[0] == "xmlns" ) {
+			var n = _node.namespace((ns[1] == null) ? "" : ns[1]);
+			if( n != null )
+				throw "Can't modify namespace";
+			if( ns[1] == null )
+				throw "Can't set default namespace";
+			_node.addNamespace(new flash.utils.Namespace(ns[1], value));
+			return;
+		}
+		if( ns.length == 1 )
+			Reflect.setField(_node, "@"+att, value);
+		else {
+			var a = getAttribNS(_node,ns);
+			untyped a[0] = value;
+		}
+	}
+
+	public function remove( att : String ) : Void{
+		if( nodeType != Xml.Element )
+			throw "bad nodeType";
+		var ns = att.split(":");
+		if( ns.length == 1 )
+			Reflect.deleteField(_node, "@"+att);
+		else
+			untyped __delete__(getAttribNS(_node,ns),0);
+	}
+
+	public function exists( att : String ) : Bool {
+		if( nodeType != Xml.Element )
+			throw "bad nodeType";
+		var ns = att.split(":");
+		if( ns[0] == "xmlns" )
+			return _node.namespace((ns[1] == null) ? "" : ns[1]) != null;
+		if( ns.length == 1 )
+			return Reflect.hasField(_node, "@"+att);
+		return getAttribNS(_node,ns).length() > 0;
+	}
+
+	public function attributes() : Iterator<String> {
+		if( nodeType != Xml.Element )
+			throw "bad nodeType";
+		var attributes :XMLList = _node.attributes();
+		var names = Reflect.fields(attributes);
+		var cur = 0;
+		return {
+			hasNext : function(){
+				return cur < names.length;
+			},
+			next : function(){
+				return attributes[Std.parseInt(names[cur++])].name();
+			}
+		}
+	}
+
+	public function iterator() : Iterator<Xml> {
+		if( nodeType != Xml.Element && nodeType != Xml.Document )
+			throw "bad nodeType";
+		var children:XMLList = _node.children();
+		var wrappers :Array<Xml> = wraps(children);
+		var cur = 0;
+		return {
+			hasNext : function(){
+				return cur < wrappers.length;
+			},
+			next : function(){
+				return wrappers[cur++];
+			}
+		};
+	}
+
+	public function elements() : Iterator<Xml> {
+		if( nodeType != Xml.Element && nodeType != Xml.Document )
+			throw "bad nodeType";
+		var elements:XMLList = _node.elements();
+		var wrappers :Array<Xml> = wraps(elements);
+		var cur = 0;
+		return {
+			hasNext : function(){
+				return cur < wrappers.length;
+			},
+			next : function(){
+				return wrappers[cur++];
+			}
+		};
+	}
+
+	public function elementsNamed( name : String ) : Iterator<Xml> {
+		if( nodeType != Xml.Element && nodeType != Xml.Document )
+			throw "bad nodeType";
+		var ns = name.split(":");
+		var elements:XMLList;
+		if( ns.length == 1 )
+			elements = _node.elements(name);
+		else
+			elements = _node.elements();
+		var wrappers :Array<Xml> = wraps(elements);
+		if( ns.length != 1 )
+			for( w in wrappers.copy() )
+				if( w._node.localName() != ns[1] || w._node.namespace().prefix != ns[0] )
+					wrappers.remove(w);
+		var cur = 0;
+		return {
+			hasNext : function(){
+				return cur < wrappers.length;
+			},
+			next : function(){
+				return wrappers[cur++];
+			}
+		};
+	}
+
+	public function firstChild() : Xml {
+		if( nodeType != Xml.Element && nodeType != Xml.Document )
+			throw "bad nodeType";
+		var children:XMLList = _node.children();
+		if( children.length() == 0 )
+			return null;
+		return wrap( children[0] );
+	}
+
+	public function firstElement() : Xml {
+		if( nodeType != Xml.Element && nodeType != Xml.Document )
+			throw "bad nodeType";
+		var elements:XMLList = _node.elements();
+		if( elements.length() == 0 )
+			return null;
+		return wrap( elements[0] );
+	}
+
+	public function addChild( x : Xml ) : Void {
+		if( nodeType != Xml.Element && nodeType != Xml.Document )
+			throw "bad nodeType";
+		if (x.parent != null)
+			x.parent.removeChild(x);
+		var children:XMLList = _node.children();
+		_node.appendChild(x._node);
+	}
+
+	public function removeChild( x : Xml ) : Bool {
+		if( nodeType != Xml.Element && nodeType != Xml.Document )
+			throw "bad nodeType";
+		var children:XMLList = _node.children();
+		if( _node != x._node.parent() )
+			return false;
+		var i = x._node.childIndex();
+		untyped __delete__(children, Reflect.fields(children)[i]);
+		return true;
+	}
+
+	public function insertChild( x : Xml, pos : Int ) : Void {
+		if( nodeType != Xml.Element && nodeType != Xml.Document )
+			throw "bad nodeType";
+		if (x.parent != null)
+			x.parent.removeChild(x);			
+		var children:XMLList = _node.children();
+		if( pos < children.length() )
+			_node.insertChildBefore(children[pos], x._node);
+		else
+			_node.appendChild(x._node);
+	}
+
+	public function toString() : String {
+		XML.prettyPrinting = false;
+		if( nodeType == Xml.Document ) {
+			var str = _node.toXMLString();
+			// remove <__document xmlns....>STR</__document> wrapper
+			str = str.substr(str.indexOf(">") + 1);
+			str = str.substr(0, str.length - 13);
+			return str;
+		}
+		return _node.toXMLString();
+	}
+
+	static function __init__() : Void untyped {
+		Element = "element";
+		PCData = "pcdata";
+		CData = "cdata";
+		Comment = "comment";
+		DocType = "doctype";
+		ProcessingInstruction = "processingInstruction";
+		Document = "document";
+	}
+
+
+}

+ 120 - 120
std/flash/_std/haxe/ds/ObjectMap.hx

@@ -1,120 +1,120 @@
-package haxe.ds;
-
-@:coreApi
-class ObjectMap<K:{},V> extends flash.utils.Dictionary implements Map.IMap<K,V> {
-
-	public function new() {
-		super(false);
-	}
-	
-	public inline function get( key : K ) : Null<V> {
-		return untyped this[key];
-	}
-
-	public inline function set( key : K, value : V ):Void {
-		untyped this[key] = value;
-	}
-
-	public inline function exists( key : K ) : Bool {
-		return untyped this[key] != null;
-	}
-
-	public function remove( key : K ):Bool {
-		var has = exists(key);
-		untyped __delete__(this, key);
-		return has;
-	}
-
-	#if as3
-	
- 	public function keys() : Iterator<K> {
-		return untyped __keys__(this).iterator();
- 	}
-
- 	public function iterator() : Iterator<V> {
-		var ret = [];
-		for (i in keys())
-			ret.push(get(i));
-		return ret.iterator();
- 	}
-	#else
-	
-	public function keys() : Iterator<K> {
-		return NativePropertyIterator.iterator(this);
-	}
-
-	public function iterator() : Iterator<V> {
-		return NativeValueIterator.iterator(this);
-	}
-	
-	#end
-
-	public function toString() : String {
-		var s = "";
-		var it = keys();
-		for( i in it ) {
-			s += (s == "" ? "" : ",") + Std.string(i);
-			s += " => ";
-			s += Std.string(get(i));
-		}
-		return s + "}";
-	}
-}
-
-private class NativePropertyIterator {
-	var collection:Dynamic;
-	var index:Int = 0;
-
-	public static inline function iterator(collection:Dynamic):NativePropertyIterator {
-		var result = new NativePropertyIterator();
-		result.collection = collection;
-		return result;
-	}
-
-	function new() {}
-
-	public inline function hasNext():Bool {
-		var c = collection;
-		var i = index;
-		var result = untyped __has_next__(c, i);
-		collection = c;
-		index = i;
-		return result;
-	}
-
-	public inline function next():Dynamic {
-		var i = index;
-		var result = untyped __forin__(collection, i);
-		index = i;
-		return result;
-	}
-}
-
-private class NativeValueIterator {
-	var collection:Dynamic;
-	var index:Int = 0;
-
-	public static inline function iterator(collection:Dynamic):NativeValueIterator {
-		var result = new NativeValueIterator();
-		result.collection = collection;
-		return result;
-	}
-
-	function new() {}
-
-	public inline function hasNext():Bool {
-		var c = collection;
-		var i = index;
-		var result = untyped __has_next__(c, i);
-		collection = c;
-		index = i;
-		return result;
-	}
-
-	public inline function next():Dynamic {
-		var i = index;
-		var result = untyped __foreach__(collection, i);
-		index = i;
-		return result;
-	}
-}
+package haxe.ds;
+
+@:coreApi
+class ObjectMap<K:{},V> extends flash.utils.Dictionary implements Map.IMap<K,V> {
+
+	public function new() {
+		super(false);
+	}
+	
+	public inline function get( key : K ) : Null<V> {
+		return untyped this[key];
+	}
+
+	public inline function set( key : K, value : V ):Void {
+		untyped this[key] = value;
+	}
+
+	public inline function exists( key : K ) : Bool {
+		return untyped this[key] != null;
+	}
+
+	public function remove( key : K ):Bool {
+		var has = exists(key);
+		untyped __delete__(this, key);
+		return has;
+	}
+
+	#if as3
+	
+ 	public function keys() : Iterator<K> {
+		return untyped __keys__(this).iterator();
+ 	}
+
+ 	public function iterator() : Iterator<V> {
+		var ret = [];
+		for (i in keys())
+			ret.push(get(i));
+		return ret.iterator();
+ 	}
+	#else
+	
+	public function keys() : Iterator<K> {
+		return NativePropertyIterator.iterator(this);
+	}
+
+	public function iterator() : Iterator<V> {
+		return NativeValueIterator.iterator(this);
+	}
+	
+	#end
+
+	public function toString() : String {
+		var s = "";
+		var it = keys();
+		for( i in it ) {
+			s += (s == "" ? "" : ",") + Std.string(i);
+			s += " => ";
+			s += Std.string(get(i));
+		}
+		return s + "}";
+	}
+}
+
+private class NativePropertyIterator {
+	var collection:Dynamic;
+	var index:Int = 0;
+
+	public static inline function iterator(collection:Dynamic):NativePropertyIterator {
+		var result = new NativePropertyIterator();
+		result.collection = collection;
+		return result;
+	}
+
+	function new() {}
+
+	public inline function hasNext():Bool {
+		var c = collection;
+		var i = index;
+		var result = untyped __has_next__(c, i);
+		collection = c;
+		index = i;
+		return result;
+	}
+
+	public inline function next():Dynamic {
+		var i = index;
+		var result = untyped __forin__(collection, i);
+		index = i;
+		return result;
+	}
+}
+
+private class NativeValueIterator {
+	var collection:Dynamic;
+	var index:Int = 0;
+
+	public static inline function iterator(collection:Dynamic):NativeValueIterator {
+		var result = new NativeValueIterator();
+		result.collection = collection;
+		return result;
+	}
+
+	function new() {}
+
+	public inline function hasNext():Bool {
+		var c = collection;
+		var i = index;
+		var result = untyped __has_next__(c, i);
+		collection = c;
+		index = i;
+		return result;
+	}
+
+	public inline function next():Dynamic {
+		var i = index;
+		var result = untyped __foreach__(collection, i);
+		index = i;
+		return result;
+	}
+}

+ 120 - 120
std/flash/_std/haxe/ds/WeakMap.hx

@@ -1,120 +1,120 @@
-package haxe.ds;
-
-@:coreApi
-class WeakMap<K:{},V> extends flash.utils.Dictionary implements Map.IMap<K,V> {
-
-	public function new() {
-		super(true);
-	}
-	
-	public inline function get( key : K ) : Null<V> {
-		return untyped this[key];
-	}
-
-	public inline function set( key : K, value : V ):Void {
-		untyped this[key] = value;
-	}
-
-	public inline function exists( key : K ) : Bool {
-		return untyped this[key] != null;
-	}
-
-	public function remove( key : K ):Bool {
-		var has = exists(key);
-		untyped __delete__(this, key);
-		return has;
-	}
-
-	#if as3
-	
- 	public function keys() : Iterator<K> {
-		return untyped __keys__(this).iterator();
- 	}
-
- 	public function iterator() : Iterator<V> {
-		var ret = [];
-		for (i in keys())
-			ret.push(get(i));
-		return ret.iterator();
- 	}
-	#else
-	
-	public function keys() : Iterator<K> {
-		return NativePropertyIterator.iterator(this);
-	}
-
-	public function iterator() : Iterator<V> {
-		return NativeValueIterator.iterator(this);
-	}
-	
-	#end
-
-	public function toString() : String {
-		var s = "";
-		var it = keys();
-		for( i in it ) {
-			s += (s == "" ? "" : ",") + Std.string(i);
-			s += " => ";
-			s += Std.string(get(i));
-		}
-		return s + "}";
-	}
-}
-
-private class NativePropertyIterator {
-	var collection:Dynamic;
-	var index:Int = 0;
-
-	public static inline function iterator(collection:Dynamic):NativePropertyIterator {
-		var result = new NativePropertyIterator();
-		result.collection = collection;
-		return result;
-	}
-
-	function new() {}
-
-	public inline function hasNext():Bool {
-		var c = collection;
-		var i = index;
-		var result = untyped __has_next__(c, i);
-		collection = c;
-		index = i;
-		return result;
-	}
-
-	public inline function next():Dynamic {
-		var i = index;
-		var result = untyped __forin__(collection, i);
-		index = i;
-		return result;
-	}
-}
-
-private class NativeValueIterator {
-	var collection:Dynamic;
-	var index:Int = 0;
-
-	public static inline function iterator(collection:Dynamic):NativeValueIterator {
-		var result = new NativeValueIterator();
-		result.collection = collection;
-		return result;
-	}
-
-	function new() {}
-
-	public inline function hasNext():Bool {
-		var c = collection;
-		var i = index;
-		var result = untyped __has_next__(c, i);
-		collection = c;
-		index = i;
-		return result;
-	}
-
-	public inline function next():Dynamic {
-		var i = index;
-		var result = untyped __foreach__(collection, i);
-		index = i;
-		return result;
-	}
-}
+package haxe.ds;
+
+@:coreApi
+class WeakMap<K:{},V> extends flash.utils.Dictionary implements Map.IMap<K,V> {
+
+	public function new() {
+		super(true);
+	}
+	
+	public inline function get( key : K ) : Null<V> {
+		return untyped this[key];
+	}
+
+	public inline function set( key : K, value : V ):Void {
+		untyped this[key] = value;
+	}
+
+	public inline function exists( key : K ) : Bool {
+		return untyped this[key] != null;
+	}
+
+	public function remove( key : K ):Bool {
+		var has = exists(key);
+		untyped __delete__(this, key);
+		return has;
+	}
+
+	#if as3
+	
+ 	public function keys() : Iterator<K> {
+		return untyped __keys__(this).iterator();
+ 	}
+
+ 	public function iterator() : Iterator<V> {
+		var ret = [];
+		for (i in keys())
+			ret.push(get(i));
+		return ret.iterator();
+ 	}
+	#else
+	
+	public function keys() : Iterator<K> {
+		return NativePropertyIterator.iterator(this);
+	}
+
+	public function iterator() : Iterator<V> {
+		return NativeValueIterator.iterator(this);
+	}
+	
+	#end
+
+	public function toString() : String {
+		var s = "";
+		var it = keys();
+		for( i in it ) {
+			s += (s == "" ? "" : ",") + Std.string(i);
+			s += " => ";
+			s += Std.string(get(i));
+		}
+		return s + "}";
+	}
+}
+
+private class NativePropertyIterator {
+	var collection:Dynamic;
+	var index:Int = 0;
+
+	public static inline function iterator(collection:Dynamic):NativePropertyIterator {
+		var result = new NativePropertyIterator();
+		result.collection = collection;
+		return result;
+	}
+
+	function new() {}
+
+	public inline function hasNext():Bool {
+		var c = collection;
+		var i = index;
+		var result = untyped __has_next__(c, i);
+		collection = c;
+		index = i;
+		return result;
+	}
+
+	public inline function next():Dynamic {
+		var i = index;
+		var result = untyped __forin__(collection, i);
+		index = i;
+		return result;
+	}
+}
+
+private class NativeValueIterator {
+	var collection:Dynamic;
+	var index:Int = 0;
+
+	public static inline function iterator(collection:Dynamic):NativeValueIterator {
+		var result = new NativeValueIterator();
+		result.collection = collection;
+		return result;
+	}
+
+	function new() {}
+
+	public inline function hasNext():Bool {
+		var c = collection;
+		var i = index;
+		var result = untyped __has_next__(c, i);
+		collection = c;
+		index = i;
+		return result;
+	}
+
+	public inline function next():Dynamic {
+		var i = index;
+		var result = untyped __foreach__(collection, i);
+		index = i;
+		return result;
+	}
+}

+ 4 - 4
std/flash/errors/ArgumentError.hx

@@ -1,4 +1,4 @@
-package flash.errors;
-
-@:native("ArgumentError") extern class ArgumentError extends Error {
-}
+package flash.errors;
+
+@:native("ArgumentError") extern class ArgumentError extends Error {
+}

+ 4 - 4
std/flash/errors/SecurityError.hx

@@ -1,4 +1,4 @@
-package flash.errors;
-
-@:native("SecurityError") extern class SecurityError extends Error {
-}
+package flash.errors;
+
+@:native("SecurityError") extern class SecurityError extends Error {
+}

Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff