mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-25 17:25:08 +02:00
This replaces the C++ IPC compiler and generator with a python3 port. For validation, the parser is nearly a line-for-line port of the C++ parser. This patch includes lexer.py, which is a simple port of our GenericLexer, as the mechanics actually felt pretty nice in python as well. The code generator does not include a port of our SourceGenerator, as that felt less nice. Instead, we write directly to a TextIO instance. The generated output is almost byte-for-byte identical with our C++ generator, with trivial whitespace differences: * The C++ generator included extraneous newlines before and after all switch statements, which is not kept here. * The C++ generator did not include newlines between message handling functions, which we now do. * The C++ generator had some extraneous spaces at the end of some lines, and incorrect tabbing (3 spaces) at the beginning of some lines.
20 lines
442 B
Python
20 lines
442 B
Python
# Copyright (c) 2026-present, the Ladybird developers.
|
|
#
|
|
# SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
|
def string_hash(string: str) -> int:
|
|
"""Port of AK::string_hash that produces the same u32 value."""
|
|
h = 0
|
|
|
|
for ch in string:
|
|
h = (h + ord(ch)) & 0xFFFFFFFF
|
|
h = (h + (h << 10)) & 0xFFFFFFFF
|
|
h ^= h >> 6
|
|
|
|
h = (h + (h << 3)) & 0xFFFFFFFF
|
|
h ^= h >> 11
|
|
h = (h + (h << 15)) & 0xFFFFFFFF
|
|
|
|
return h
|