aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/WebAssembly/Structure/Types/FuncType.php
blob: 7932eb5bf5cfb2180b2658956b1e23dc77105f7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php

declare(strict_types=1);

namespace Nsfisis\Waddiwasi\WebAssembly\Structure\Types;

use function count;

final readonly class FuncType
{
    /**
     * @param list<ValType> $params
     * @param list<ValType> $results
     */
    public function __construct(
        public array $params,
        public array $results,
    ) {
    }

    public function equals(self $other): bool
    {
        if (count($this->params) !== count($other->params)) {
            return false;
        }
        if (count($this->results) !== count($other->results)) {
            return false;
        }
        foreach ($this->params as $i => $type) {
            if ($type !== $other->params[$i]) {
                return false;
            }
        }
        foreach ($this->results as $i => $type) {
            if ($type !== $other->results[$i]) {
                return false;
            }
        }
        return true;
    }
}