Ver Fonte

Merge branch 'development' into coroutines_2024

Simon Krajewski há 1 ano atrás
pai
commit
de3e495580

+ 77 - 29
.github/workflows/main.yml

@@ -24,7 +24,7 @@ jobs:
           rm C:\msys64\usr\bin\bash.exe
 
       - name: choco install nsis
-        uses: nick-invision/retry@v2
+        uses: nick-invision/retry@v3
         with:
           timeout_minutes: 10
           max_attempts: 10
@@ -114,7 +114,7 @@ jobs:
           [ $(ls -1 out | wc -l) -eq "3" ]
 
       - name: Upload artifact
-        uses: actions/upload-artifact@v3
+        uses: actions/upload-artifact@v4
         with:
           name: win${{env.ARCH}}Binaries
           path: out
@@ -136,7 +136,7 @@ jobs:
 
       - name: Cache opam
         id: cache-opam
-        uses: actions/cache@v3.0.11
+        uses: actions/cache@v4
         with:
           path: ~/.opam/
           key: ${{ runner.os }}-${{ matrix.ocaml }}-${{ hashFiles('./haxe.opam', './libs/') }}
@@ -213,13 +213,13 @@ jobs:
           EOL
 
       - name: Upload artifact
-        uses: actions/upload-artifact@v3
+        uses: actions/upload-artifact@v4
         with:
           name: linuxBinaries${{ (matrix.ocaml == '5.0.0' && '_ocaml5') || '' }}
           path: out
 
       - name: Upload xmldoc artifact
-        uses: actions/upload-artifact@v3
+        uses: actions/upload-artifact@v4
         if: matrix.ocaml == '4.08.1'
         with:
           name: xmldoc
@@ -251,7 +251,7 @@ jobs:
       - uses: actions/checkout@main
         with:
           submodules: recursive
-      - uses: actions/download-artifact@v3
+      - uses: actions/download-artifact@v4
         with:
           name: linuxBinaries${{ (matrix.ocaml == '5.0.0' && '_ocaml5') || '' }}
           path: linuxBinaries
@@ -321,13 +321,13 @@ jobs:
         with:
           submodules: recursive
 
-      - uses: actions/download-artifact@v3
+      - uses: actions/download-artifact@v4
         with:
           name: linuxBinaries
           path: linuxBinaries
 
       - name: Download xmldoc artifact
-        uses: actions/download-artifact@v3
+        uses: actions/download-artifact@v4
         with:
           name: xmldoc
           path: xmldoc
@@ -396,7 +396,7 @@ jobs:
       FORCE_COLOR: 1
     steps:
       - name: Login to GitHub Container Registry
-        uses: docker/login-action@v2
+        uses: docker/login-action@v3
         with:
           registry: ghcr.io
           username: ${{ github.actor }}
@@ -407,7 +407,7 @@ jobs:
 
       - name: Set up QEMU
         id: qemu
-        uses: docker/setup-qemu-action@v2
+        uses: docker/setup-qemu-action@v3
         with:
             image: tonistiigi/binfmt:latest
             platforms: all
@@ -439,17 +439,23 @@ jobs:
           EARTHLY_REMOTE_CACHE: "ghcr.io/${{env.CONTAINER_REG}}_cache:build-${{env.CONTAINER_TAG}}-arm64"
 
       - name: Upload artifact
-        uses: actions/upload-artifact@v3
+        uses: actions/upload-artifact@v4
         with:
           name: linuxArm64Binaries
           path: out/linux/arm64
 
   mac-build:
-    runs-on: macos-latest
+    strategy:
+      fail-fast: false
+      matrix:
+        os: [macos-latest, macos-14]
+    runs-on: ${{ matrix.os }}
     env:
       PLATFORM: mac
       OPAMYES: 1
       MACOSX_DEPLOYMENT_TARGET: 10.13
+      OCAML_VERSION: 5.1.1
+      CTYPES: 0.21.1
     steps:
       - uses: actions/checkout@main
         with:
@@ -457,10 +463,10 @@ jobs:
 
       - name: Cache opam
         id: cache-opam
-        uses: actions/cache@v3.0.11
+        uses: actions/cache@v4
         with:
           path: ~/.opam/
-          key: ${{ runner.os }}-${{ hashFiles('./haxe.opam', './libs/') }}
+          key: ${{ matrix.os }}-${{ hashFiles('./haxe.opam', './libs/') }}
 
       - name: Install Neko from S3
         run: |
@@ -494,16 +500,16 @@ jobs:
           curl -L https://github.com/madler/zlib/releases/download/v$ZLIB_VERSION/zlib-$ZLIB_VERSION.tar.gz | tar xz
           cd zlib-$ZLIB_VERSION
           ./configure
-          make && make install
+          sudo make && sudo make install
           cd ..
           curl -L https://github.com/ARMmbed/mbedtls/archive/v$MBEDTLS_VERSION.tar.gz | tar xz
           cd mbedtls-$MBEDTLS_VERSION
-          make && make install
+          sudo make && sudo make install
           cd ..
           curl -L https://github.com/PCRE2Project/pcre2/releases/download/pcre2-$PCRE2_VERSION/pcre2-$PCRE2_VERSION.tar.gz | tar xz
           cd pcre2-$PCRE2_VERSION
           ./configure --enable-unicode --enable-pcre2-8 --enable-pcre2-16 --enable-pcre2-32 --enable-unicode-properties --enable-pcre2grep-libz --enable-pcre2grep-libbz2 --enable-jit
-          make && make install
+          sudo make && sudo make install
           cd ..
 
       - name: Install OCaml libraries
@@ -512,10 +518,10 @@ jobs:
           set -ex
           opam init # --disable-sandboxing
           opam update
-          opam switch create 4.08.1
+          opam switch create ${{env.OCAML_VERSION}}
           eval $(opam env)
           opam env
-          opam pin add ctypes 0.17.1 --yes
+          opam pin add ctypes ${{env.CTYPES}} --yes
           opam pin add haxe . --no-action
           opam install haxe --deps-only --assume-depexts
           opam list
@@ -536,10 +542,18 @@ jobs:
           otool -L ./haxe
           otool -L ./haxelib
 
-      - name: Upload artifact
-        uses: actions/upload-artifact@v3
+      - name: Upload artifact (x64)
+        if: matrix.os == 'macos-latest'
+        uses: actions/upload-artifact@v4
         with:
-          name: macBinaries
+          name: macX64Binaries
+          path: out
+
+      - name: Upload artifact (arm)
+        if: matrix.os == 'macos-14'
+        uses: actions/upload-artifact@v4
+        with:
+          name: macArmBinaries
           path: out
 
 
@@ -561,7 +575,7 @@ jobs:
       - uses: actions/checkout@main
         with:
           submodules: recursive
-      - uses: actions/download-artifact@v3
+      - uses: actions/download-artifact@v4
         with:
           name: win${{env.ARCH}}Binaries
           path: win${{env.ARCH}}Binaries
@@ -578,7 +592,7 @@ jobs:
       - name: Print Neko version
         run: neko -version 2>&1
 
-      - uses: actions/setup-node@v3
+      - uses: actions/setup-node@v4
         with:
           node-version: 18.17.1
 
@@ -639,9 +653,43 @@ jobs:
         working-directory: ${{github.workspace}}/tests
 
 
-  mac-test:
+  mac-build-universal:
     needs: mac-build
     runs-on: macos-latest
+    steps:
+      - name: Checkout the repository
+        uses: actions/checkout@main
+      - uses: actions/download-artifact@v4
+        with:
+          name: macX64Binaries
+          path: macX64Binaries
+      - uses: actions/download-artifact@v4
+        with:
+          name: macArmBinaries
+          path: macArmBinaries
+
+      - name: Make universal binary
+        run: |
+          set -ex
+          tar -xf macX64Binaries/*_bin.tar.gz -C macX64Binaries --strip-components=1
+          tar -xf macArmBinaries/*_bin.tar.gz -C macArmBinaries --strip-components=1
+          lipo -create -output haxe macX64Binaries/haxe macArmBinaries/haxe
+          # there is only x64 haxelib
+          mv macX64Binaries/haxelib .
+          make -s package_unix package_installer_mac
+          ls -l out
+          otool -L ./haxe
+          otool -L ./haxelib
+
+      - name: Upload artifact (universal)
+        uses: actions/upload-artifact@v4
+        with:
+          name: macBinaries
+          path: out
+
+  mac-test:
+    needs: mac-build-universal
+    runs-on: macos-latest
     env:
       PLATFORM: mac
       TEST: ${{matrix.target}}
@@ -658,7 +706,7 @@ jobs:
       - uses: actions/checkout@main
         with:
           submodules: recursive
-      - uses: actions/download-artifact@v3
+      - uses: actions/download-artifact@v4
         with:
           name: macBinaries
           path: macBinaries
@@ -726,7 +774,7 @@ jobs:
         uses: actions/checkout@main
 
       - name: Download build artifacts
-        uses: actions/download-artifact@v3
+        uses: actions/download-artifact@v4
 
       - name: Install awscli
         run: |
@@ -795,7 +843,7 @@ jobs:
           sudo apt-get install -qqy libc6
 
       - name: Download Haxe
-        uses: actions/download-artifact@v3
+        uses: actions/download-artifact@v4
         with:
           name: linuxBinaries
           path: linuxBinaries
@@ -811,7 +859,7 @@ jobs:
           sudo ln -s `pwd`/linuxBinaries/std /usr/local/share/haxe/std
 
       - name: Download xmldoc artifact
-        uses: actions/download-artifact@v3
+        uses: actions/download-artifact@v4
         with:
           name: xmldoc
           path: xmldoc

+ 16 - 8
extra/github-actions/build-mac.yml

@@ -13,16 +13,16 @@
     curl -L https://github.com/madler/zlib/releases/download/v$ZLIB_VERSION/zlib-$ZLIB_VERSION.tar.gz | tar xz
     cd zlib-$ZLIB_VERSION
     ./configure
-    make && make install
+    sudo make && sudo make install
     cd ..
     curl -L https://github.com/ARMmbed/mbedtls/archive/v$MBEDTLS_VERSION.tar.gz | tar xz
     cd mbedtls-$MBEDTLS_VERSION
-    make && make install
+    sudo make && sudo make install
     cd ..
     curl -L https://github.com/PCRE2Project/pcre2/releases/download/pcre2-$PCRE2_VERSION/pcre2-$PCRE2_VERSION.tar.gz | tar xz
     cd pcre2-$PCRE2_VERSION
     ./configure --enable-unicode --enable-pcre2-8 --enable-pcre2-16 --enable-pcre2-32 --enable-unicode-properties --enable-pcre2grep-libz --enable-pcre2grep-libbz2 --enable-jit
-    make && make install
+    sudo make && sudo make install
     cd ..
 
 - name: Install OCaml libraries
@@ -31,10 +31,10 @@
     set -ex
     opam init # --disable-sandboxing
     opam update
-    opam switch create 4.08.1
+    opam switch create ${{env.OCAML_VERSION}}
     eval $(opam env)
     opam env
-    opam pin add ctypes 0.17.1 --yes
+    opam pin add ctypes ${{env.CTYPES}} --yes
     opam pin add haxe . --no-action
     opam install haxe --deps-only --assume-depexts
     opam list
@@ -55,8 +55,16 @@
     otool -L ./haxe
     otool -L ./haxelib
 
-- name: Upload artifact
-  uses: actions/upload-artifact@v3
+- name: Upload artifact (x64)
+  if: matrix.os == 'macos-latest'
+  uses: actions/upload-artifact@v4
   with:
-    name: macBinaries
+    name: macX64Binaries
+    path: out
+
+- name: Upload artifact (arm)
+  if: matrix.os == 'macos-14'
+  uses: actions/upload-artifact@v4
+  with:
+    name: macArmBinaries
     path: out

+ 1 - 1
extra/github-actions/build-windows.yml

@@ -34,7 +34,7 @@
     [ $(ls -1 out | wc -l) -eq "3" ]
 
 - name: Upload artifact
-  uses: actions/upload-artifact@v3
+  uses: actions/upload-artifact@v4
   with:
     name: win${{env.ARCH}}Binaries
     path: out

+ 1 - 1
extra/github-actions/install-nsis.yml

@@ -1,5 +1,5 @@
 - name: choco install nsis
-  uses: nick-invision/retry@v2
+  uses: nick-invision/retry@v3
   with:
     timeout_minutes: 10
     max_attempts: 10

+ 1 - 1
extra/github-actions/test-windows.yml

@@ -1,4 +1,4 @@
-- uses: actions/setup-node@v3
+- uses: actions/setup-node@v4
   with:
     node-version: 18.17.1
 

+ 58 - 18
extra/github-actions/workflows/main.yml

@@ -44,7 +44,7 @@ jobs:
 
       - name: Cache opam
         id: cache-opam
-        uses: actions/cache@v3.0.11
+        uses: actions/cache@v4
         with:
           path: ~/.opam/
           key: ${{ runner.os }}-${{ matrix.ocaml }}-${{ hashFiles('./haxe.opam', './libs/') }}
@@ -105,13 +105,13 @@ jobs:
           EOL
 
       - name: Upload artifact
-        uses: actions/upload-artifact@v3
+        uses: actions/upload-artifact@v4
         with:
           name: linuxBinaries${{ (matrix.ocaml == '5.0.0' && '_ocaml5') || '' }}
           path: out
 
       - name: Upload xmldoc artifact
-        uses: actions/upload-artifact@v3
+        uses: actions/upload-artifact@v4
         if: matrix.ocaml == '4.08.1'
         with:
           name: xmldoc
@@ -143,7 +143,7 @@ jobs:
       - uses: actions/checkout@main
         with:
           submodules: recursive
-      - uses: actions/download-artifact@v3
+      - uses: actions/download-artifact@v4
         with:
           name: linuxBinaries${{ (matrix.ocaml == '5.0.0' && '_ocaml5') || '' }}
           path: linuxBinaries
@@ -197,13 +197,13 @@ jobs:
         with:
           submodules: recursive
 
-      - uses: actions/download-artifact@v3
+      - uses: actions/download-artifact@v4
         with:
           name: linuxBinaries
           path: linuxBinaries
 
       - name: Download xmldoc artifact
-        uses: actions/download-artifact@v3
+        uses: actions/download-artifact@v4
         with:
           name: xmldoc
           path: xmldoc
@@ -256,7 +256,7 @@ jobs:
       FORCE_COLOR: 1
     steps:
       - name: Login to GitHub Container Registry
-        uses: docker/login-action@v2
+        uses: docker/login-action@v3
         with:
           registry: ghcr.io
           username: ${{ github.actor }}
@@ -267,7 +267,7 @@ jobs:
 
       - name: Set up QEMU
         id: qemu
-        uses: docker/setup-qemu-action@v2
+        uses: docker/setup-qemu-action@v3
         with:
             image: tonistiigi/binfmt:latest
             platforms: all
@@ -299,17 +299,23 @@ jobs:
           EARTHLY_REMOTE_CACHE: "ghcr.io/${{env.CONTAINER_REG}}_cache:build-${{env.CONTAINER_TAG}}-arm64"
 
       - name: Upload artifact
-        uses: actions/upload-artifact@v3
+        uses: actions/upload-artifact@v4
         with:
           name: linuxArm64Binaries
           path: out/linux/arm64
 
   mac-build:
-    runs-on: macos-latest
+    strategy:
+      fail-fast: false
+      matrix:
+        os: [macos-latest, macos-14]
+    runs-on: ${{ matrix.os }}
     env:
       PLATFORM: mac
       OPAMYES: 1
       MACOSX_DEPLOYMENT_TARGET: 10.13
+      OCAML_VERSION: 5.1.1
+      CTYPES: 0.21.1
     steps:
       - uses: actions/checkout@main
         with:
@@ -317,10 +323,10 @@ jobs:
 
       - name: Cache opam
         id: cache-opam
-        uses: actions/cache@v3.0.11
+        uses: actions/cache@v4
         with:
           path: ~/.opam/
-          key: ${{ runner.os }}-${{ hashFiles('./haxe.opam', './libs/') }}
+          key: ${{ matrix.os }}-${{ hashFiles('./haxe.opam', './libs/') }}
 
       @import install-neko-unix.yml
       @import build-mac.yml
@@ -343,7 +349,7 @@ jobs:
       - uses: actions/checkout@main
         with:
           submodules: recursive
-      - uses: actions/download-artifact@v3
+      - uses: actions/download-artifact@v4
         with:
           name: win${{env.ARCH}}Binaries
           path: win${{env.ARCH}}Binaries
@@ -351,9 +357,43 @@ jobs:
       @import install-neko-windows.yml
       @import test-windows.yml
 
-  mac-test:
+  mac-build-universal:
     needs: mac-build
     runs-on: macos-latest
+    steps:
+      - name: Checkout the repository
+        uses: actions/checkout@main
+      - uses: actions/download-artifact@v4
+        with:
+          name: macX64Binaries
+          path: macX64Binaries
+      - uses: actions/download-artifact@v4
+        with:
+          name: macArmBinaries
+          path: macArmBinaries
+
+      - name: Make universal binary
+        run: |
+          set -ex
+          tar -xf macX64Binaries/*_bin.tar.gz -C macX64Binaries --strip-components=1
+          tar -xf macArmBinaries/*_bin.tar.gz -C macArmBinaries --strip-components=1
+          lipo -create -output haxe macX64Binaries/haxe macArmBinaries/haxe
+          # there is only x64 haxelib
+          mv macX64Binaries/haxelib .
+          make -s package_unix package_installer_mac
+          ls -l out
+          otool -L ./haxe
+          otool -L ./haxelib
+
+      - name: Upload artifact (universal)
+        uses: actions/upload-artifact@v4
+        with:
+          name: macBinaries
+          path: out
+
+  mac-test:
+    needs: mac-build-universal
+    runs-on: macos-latest
     env:
       PLATFORM: mac
       TEST: ${{matrix.target}}
@@ -370,7 +410,7 @@ jobs:
       - uses: actions/checkout@main
         with:
           submodules: recursive
-      - uses: actions/download-artifact@v3
+      - uses: actions/download-artifact@v4
         with:
           name: macBinaries
           path: macBinaries
@@ -390,7 +430,7 @@ jobs:
         uses: actions/checkout@main
 
       - name: Download build artifacts
-        uses: actions/download-artifact@v3
+        uses: actions/download-artifact@v4
 
       - name: Install awscli
         run: |
@@ -459,7 +499,7 @@ jobs:
           sudo apt-get install -qqy libc6
 
       - name: Download Haxe
-        uses: actions/download-artifact@v3
+        uses: actions/download-artifact@v4
         with:
           name: linuxBinaries
           path: linuxBinaries
@@ -475,7 +515,7 @@ jobs:
           sudo ln -s `pwd`/linuxBinaries/std /usr/local/share/haxe/std
 
       - name: Download xmldoc artifact
-        uses: actions/download-artifact@v3
+        uses: actions/download-artifact@v4
         with:
           name: xmldoc
           path: xmldoc

+ 1 - 1
haxe.opam

@@ -31,7 +31,7 @@ depends: [
   "conf-libpcre2-8"
   "conf-zlib"
   "conf-neko"
-  "luv" {>= "0.5.12"}
+  "luv" {= "0.5.12"}
   "ipaddr"
   "terminal_size"
 ]

+ 11 - 3
src/generators/genlua.ml

@@ -1550,7 +1550,7 @@ let check_multireturn ctx c =
 
 let check_field_name c f =
     match f.cf_name with
-    | "prototype" | "__proto__" | "constructor" ->
+    | "prototype" | "__proto__" | "constructor" | "__mt__" ->
         raise_typing_error ("The field name '" ^ f.cf_name ^ "'  is not allowed in Lua") (match f.cf_expr with None -> c.cl_pos | Some e -> e.epos);
     | _ -> ()
 
@@ -1660,8 +1660,10 @@ let generate_class ctx c =
                     | TBlock el ->
                         let bend = open_block ctx in
                         newline ctx;
-                        if not (has_prototype ctx c) then println ctx "local self = _hx_new()" else
-                            println ctx "local self = _hx_new(%s.prototype)" p;
+                        if not (has_prototype ctx c) then
+                            println ctx "local self = _hx_new()"
+                        else
+                            println ctx "local self = _hx_nsh(%s.__mt__)" p;
                         println ctx "%s.super(%s)" p (String.concat "," ("self" :: (List.map lua_arg_name f.tf_args)));
                         if p = "String" then println ctx "self = string";
                         spr ctx "return self";
@@ -1734,6 +1736,9 @@ let generate_class ctx c =
              if has_property_reflection && Codegen.has_properties csup then
                  println ctx "setmetatable(%s.prototype.__properties__,{__index=%s.prototype.__properties__})" p psup;
         );
+
+        (* Create a metatable specific for this class *)
+        println ctx "%s.__mt__ = _hx_mmt(%s.prototype)" p p;
     end
 
 let generate_enum ctx e =
@@ -2023,6 +2028,9 @@ let generate com =
     (* base lua metatables for prototypes, inheritance, etc. *)
     print_file (Common.find_file com "lua/_lua/_hx_anon.lua");
 
+    (* Helpers for creating metatables from prototypes *)
+    print_file (Common.find_file com "lua/_lua/_hx_objects.lua");
+
     (* base runtime class stubs for haxe value types (Int, Float, etc) *)
     print_file (Common.find_file com "lua/_lua/_hx_classes.lua");
 

+ 0 - 4
std/lua/_lua/_hx_anon.lua

@@ -28,10 +28,6 @@ local function _hx_o(obj)
   return setmetatable(obj, _hx_obj_mt)
 end
 
-local function _hx_new(prototype)
-  return setmetatable({__fields__ = {}}, {__newindex=_hx_obj_newindex, __index=prototype, __tostring=_hx_tostring})
-end
-
 function _hx_field_arr(obj)
     local res = {}
     local idx = 0

+ 15 - 0
std/lua/_lua/_hx_objects.lua

@@ -0,0 +1,15 @@
+local function _hx_mmt(prototype)
+  return {
+    __newindex = _hx_obj_newindex,
+    __index = prototype,
+    __tostring = _hx_tostring
+  }
+end
+
+local function _hx_new(prototype)
+  return setmetatable({ __fields__ = {} }, _hx_mmt(prototype))
+end
+
+local function _hx_nsh(metatable)
+  return setmetatable({ __fields__ = {} }, metatable)
+end

+ 1 - 1
std/lua/_lua/_hx_tab_array.lua

@@ -1,4 +1,4 @@
-local _hx_hidden = {__id__=true, hx__closures=true, super=true, prototype=true, __fields__=true, __ifields__=true, __class__=true, __properties__=true, __fields__=true, __name__=true}
+local _hx_hidden = {__id__=true, hx__closures=true, super=true, prototype=true, __fields__=true, __ifields__=true, __class__=true, __properties__=true, __mt__=true, __name__=true}
 
 _hx_array_mt = {
     __newindex = function(t,k,v)

+ 27 - 0
tests/unit/src/unit/TestLua.hx

@@ -1,5 +1,7 @@
 package unit;
 
+import utest.Assert;
+
 class TestLua extends Test {
 	function testMultiReturnWrap(){
 		var multi : Multi = untyped MultiCall.doit();
@@ -45,6 +47,27 @@ class TestLua extends Test {
 		untyped _hx_box_mr = old_hx_box_mr;
 	}
 
+	function testMetatablesAreShared() {
+
+		// New class instances get metatables assigned to them
+		final a = new TLA();
+		t(lua.Lua.getmetatable(cast a) != null);
+
+		// Instances of the same class share a metatable
+		final a2 = new TLA();
+		eq(lua.Lua.getmetatable(cast a), lua.Lua.getmetatable(cast a2));
+
+		// Subclass does not share a metatable with the parent
+		final aChild = new TLAChild();
+		t(lua.Lua.getmetatable(cast aChild) != null);
+		Assert.notEquals(lua.Lua.getmetatable(cast a), lua.Lua.getmetatable(cast aChild));
+
+		// Neither do any other arbitrary two classes
+		final b = new TLB();
+		t(lua.Lua.getmetatable(cast b) != null);
+		Assert.notEquals(lua.Lua.getmetatable(cast a), lua.Lua.getmetatable(cast b));
+		Assert.notEquals(lua.Lua.getmetatable(cast aChild), lua.Lua.getmetatable(cast b));
+	}
 }
 
 @:multiReturn extern class Multi {
@@ -60,3 +83,7 @@ class MultiCall {
 		return lua.Lua.type(m) == "table";
 	}
 }
+
+class TLA { private var foo: String; public function new() { this.foo = "A"; } }
+class TLAChild extends TLA { public function new() { super(); this.foo = "AChild"; } }
+class TLB { private var foo: String; public function new() { this.foo = "B"; } }