Skip to content

sync#26601

Closed
ylluminate wants to merge 69 commits into
masterfrom
gg-review/main
Closed

sync#26601
ylluminate wants to merge 69 commits into
masterfrom
gg-review/main

Conversation

@ylluminate

Copy link
Copy Markdown
Contributor

Auto-review via gg sync (main branch)

Provides SSL/TLS placeholder types for the BEAM backend:
- SSLCerts, SSLConn, SSLListener structs
- new_ssl_conn, new_sslcerts functions
- read, write, dial, connect methods (stub implementations)

This allows V code using net.mbedtls to compile for BEAM.
Actual SSL operations would need Erlang ssl module integration.
- Create compress.beam.v with deflate compression stubs using Erlang zlib
- Create gzip/gzip.beam.v with gzip compression using zlib:gzip/gunzip
- Rename gzip.v to gzip.c.v to mark it as C-backend-specific

This enables tar_gz_reader.v and other code using compress.gzip to
compile for the BEAM backend.
- Add int_to_hex/1 for integer to hex string conversion
- Add hex_to_int/1 for hex string to integer parsing
- Add format_int/2 for arbitrary base (2-36) formatting
- Add interpolate/1 for V string interpolation support
- Update float_to_string and to_binary to use compact decimals
- <= becomes =< (Erlang's less-than-or-equal)
- != becomes /= (Erlang's not-equal)

Also includes string concatenation fix (string + string -> binary concat)
V's / operator performs integer division when both operands are integers.
In Erlang, / always returns a float, so we need to use 'div' instead.

- Added is_integer_type_or_literal() and is_float_type_or_literal() helpers
- Modified infix_expr() to detect integer division and emit 'div'
- Float division and mixed operations still use '/'
- Fix generic type stripping: all_before('[') before all_after_last('.')
  prevents main.BST[main.KeyVal] → 'KeyVal]' errors
- Fix empty type prefix for array types ([]Flag → 'array' prefix)
- Add method stubs for ~30 V stdlib types (File, Process, FlagParser,
  Command, Mutex, RE, Context, Termios, TcpListener, Vec3, etc.)
- Add ~60 free-standing function stubs (open_file, json, signal, etc.)
- Add u8.ascii_str and array bytestr/hex methods
- Add array get_int/get_string/get_bool/get_strings stubs
When V resolves imported functions like `import mymodules { add_xy }`,
node.mod stays as the calling module but node.name contains the full
qualified name (e.g., "mymodules.add_xy"). The codegen now detects this
pattern and emits cross-module `call 'v.mod':'fn'(args)` instead of
local `apply 'fn'/arity(args)`.

Also fixes function references to imported modules (e.g., term.green)
in core_ident - now emits cross-module call in lambda wrappers.

This single fix resolved ALL 7 previously-identified "fundamental
limitations": submodule, poll_coindesk, bst_map, mini_calculator,
jsonrpc/server, jsonrpc/client, and sync_pool all now compile.

Core Erlang parity: 110/117 (94%), remaining 7 are V compilation
failures (not Core Erlang backend issues).
Same fix as Core Erlang path: detect module prefix in full_name when
node.mod matches the calling module. V resolves imported functions
with node.mod set to caller, but node.name has the qualified name.
Stdlib stubs → real implementations:
- string.beam.v: 30+ methods implemented (split, replace, trim, contains,
  starts_with, ends_with, repeat, reverse, to_upper/lower, find_between,
  match_glob with real wildcard support, find_between_pair_rune)
- int.beam.v: hex2, hex_full, is_alnum, is_hex_digit, is_space, u8.repeat
- array.beam.v: contains, clear, trim, drop, byterune (full UTF-8), utf8_to_utf32
- strconv.beam.v: format_int/uint, ftoa family, remove_tail_zeros
- map.beam.v: fix deprecated map{} syntax, add codegen documentation

Codegen interception for C-pointer string functions (BEAM binary mapping):
- tos(s, len) → binary:part(S, 0, Len)
- tos2/3/4/5, cstring_to_vstring → hd(binary:split(S, <<0>>))
- tos_clone → binary:copy(S)
- runes() → unicode:characters_to_list(S)
- ascii_str() → erlang:list_to_binary([Byte])

Core Erlang + ETF pipeline improvements:
- Expanded core_exprs.v with string/array/map method codegen
- Expanded core_stmts.v with improved control flow
- Enhanced coregen.v module infrastructure

All 45/45 runtime tests pass on ETF, Text, and Erlang source pipelines.
…tions

irgen.v (1165→1598 lines):
- for..in range loops (label/cmp/jcc structure)
- for..in array loops (array_len + array_get iteration)
- Map IR opcodes: map_new, map_get, map_put, map_delete
- print_float opcode with float type detection
- String interpolation: println('${expr}') and expression form
- Full match expression support (general + match true pattern)
- DumpExpr, CharLiteral, ConcatExpr support

Stdlib real implementations:
- rune.beam.v: 8/8 functions (UTF-8 encoding, str(), bytes(), case conversion)
- time.beam.v: 4 new (strftime, parse_iso8601, parse_rfc3339, parse_format)
- base64.beam.v: 4 new (encode/decode with proper padding)
- os.beam.v: 7 improved (hostname, uname, real_path, glob, posix errors)

Native ARM64 tests: 9/9 pass. BEAM runtime tests: 45/45 pass.
…e 100%

JSON parser (json.beam.v 326→793 lines):
- Full recursive-descent parser: raw_decode() handles strings, numbers,
  arrays, objects, booleans, null with Unicode escape support
- encode_any/encode_array/encode_map for serialization
- Pretty-print with configurable indentation

OS/time codegen (core_exprs.v):
- 14 interceptions: getenv, setenv, unsetenv, getwd, mkdir, rmdir,
  getpid, chdir, rename, now, utc, unix, unix_milli, sys_mono_now
- Proper charlist↔binary conversion for Erlang stdlib interop

Net scaffolding (net.beam.v 621→797 lines):
- IPv4 validation, address parsing, TCP/UDP connection scaffolding
- Detailed codegen documentation for gen_tcp/gen_udp integration

Native irgen.v fixes:
- Hex/octal integer literals → decimal conversion
- Multi-return assignment bounds check
- Void type guard for method calls

Compress improvements (gzip/zstd):
- Magic number validation, empty data short-circuits, error improvements

46/46 BEAM tests, 9/9 native tests, 68/68 V examples compile natively.
@ylluminate

Copy link
Copy Markdown
Contributor Author

@codex review

@esquerbatua

Copy link
Copy Markdown
Contributor

Same as @spytheman say: "Please do not submit slop as PR - it has generated .beam, .ir, .core, .etf, .erl files, it has branched from the main repo, instead of from your own one, no tests etc :-| ."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants