Source: modules/foundation/ + web/js/foundation_bridge.js

Foundation — What's Implemented

Pure-C runtime for Date / Calendar / URL math (compiled into foundation.wasm) plus a JS bridge for things that need browser APIs (UserDefaults / JSON / Date formatting / Unicode classification).

49
Date functions (extract · arithmetic · comparison)
16
URL functions (components · manipulation)
11
Calendar lookup tables (locale-ready)
15
JS-bridge functions (UserDefaults · JSON · Unicode · formatter)
Full — implemented end-to-end · Partial — basic shape only · Not yet — Foundation surface absent
Date & Calendar (60) URL (16) JS Bridge (15) Type registry Not yet supported

Date & Calendar

All date math is plain C — Gregorian-only. foundation.wasm exports these; user code reaches them via Date.now, Calendar.current.dateComponents(...), etc.

Component extraction14 functions
__date_year / __date_month / __date_day
Y / M / D from epoch seconds.
__date_hour / __date_minute / __date_second
Time-of-day components.
__date_nanosecond
Sub-second precision (limited by JS Date).
__date_weekday / __date_day_of_year
Day-of-week (1 = Sunday) + day-of-year (1–366).
__date_week_of_year / __date_week_of_month
ISO week number variants.
__date_quarter / __date_era
Quarter (1–4) + era (1 = AD).
__date_component
Generic dispatch by Calendar.Component enum.
Arithmetic12 functions
__date_add_seconds / __date_add_minutes / __date_add_hours
Time-unit additions.
__date_add_days / __date_add_weeks / __date_add_months / __date_add_quarters / __date_add_years
Calendar-aware additions (handles month-end, leap years).
__date_add_component / __date_by_adding_components
Generic component-based add (Calendar.Component dispatch).
__date_by_setting / __date_by_setting_time
Replace specific components.
__date_start_of_day
Truncate to 00:00:00 in the local calendar.
Conversion / construction5 functions
__date_now
Current epoch seconds (Date()).
__date_from_components / __date_to_components
Construct from / decompose into DateComponents.
__date_iso
ISO 8601 numeric pieces (without formatting — see bridge for string).
Comparison & predicates10 functions
__date_compare
Three-way compare (-1 / 0 / 1).
__date_components_diff
Difference between two dates by Component.
__date_is_in_today / __date_is_in_yesterday / __date_is_in_tomorrow
Day-relative predicates against now.
__date_is_in_weekend / __date_is_same_day
Calendar-aware predicates.
__date_is_equal_to_granularity / __date_matches_components
Comparison restricted to a granularity / matching DateComponents.
Range queries6 functions
__date_range_of_in / __date_range_of_in_lo / __date_range_of_in_len
Calendar.range(of:in:for:) — bounds of a unit within another.
__date_range_lo / __date_range_len
Bounds + length helpers.
__date_ordinality_of_in
Ordinal of a unit within a containing unit (e.g. day-of-month).
Calendar — locale tables11 functions
__calendar_month_names_long / _short / _vshort
"January…" / "Jan…" / "J…" — comma-joined.
__calendar_weekday_names_long / _short / _vshort
"Sunday…" / "Sun…" / "S…".
__calendar_ampm_names
"AM,PM".
__calendar_identifier
Currently only "gregorian".
Other identifiers (buddhist, islamic, hebrew…) not implemented
__calendar_first_weekday / __calendar_min_days_in_first_week
Locale-driven; defaults to Sunday + 1.

URL Functions

RFC 3986–compatible parsing in pure C — no allocator surprises, output strings live as long as the input.

Components8 functions
__url_scheme / __url_host / __url_port
Scheme (http/https), authority host, integer port.
__url_user / __url_password
Authority user-info parts (rarely used; supported).
__url_path / __url_query / __url_fragment
Path / query string / fragment (after #).
__url_path_extension / __url_last_path_component
Filename + extension extraction.
Manipulation8 functions
__url_append_path
URL.appendingPathComponent("...").
__url_appending_path_extension / __url_deleting_path_extension
Add / strip the file extension.
__url_deleting_last_path_component
Walk up one segment.
__url_appending_query_items / __url_appending_query_string
Append URLQueryItem array or raw query string.

JS Bridge

Functions that need browser APIs — exposed under the Foundation:: namespace by web/js/foundation_bridge.js.

UserDefaults — localStorage7 functions
__ud_set_str / __ud_set_int / __ud_set_bool
Store typed values under a key.
__ud_get_str / __ud_get_int / __ud_get_bool
Read back as the original type; coerces strings.
__ud_remove
Delete the key.
JSON — JSON.parse based3 functions
__json_value
Parse + look up a top-level key (or whole doc); returns string view of the value.
__json_array_count / __json_array_item
Length + indexed read for top-level / nested arrays.
No deep keypath dispatch; one level of nesting only
Date formatting — JS Date based2 functions
__date_iso8601
ISO 8601 string ("2026-04-28T12:00:00Z") via Date.toISOString().
__date_formatter_string
DateFormatter("yyyy-MM-dd HH:mm:ss" + month/weekday tokens MMMM/MMM/EEEE/EEE).
Token vocabulary is a pragmatic subset of UTS #35
Unicode classification3 functions
__dec_is_alphanumeric
[A-Za-z0-9] — ASCII only.
__dec_is_punctuation
!"#$%& etc. — ASCII range.
__dec_is_symbol
$&+<=>^~ etc. — ASCII range.
Full Unicode tables ship via vendor/decoder for the compiler-side checks

Type Registry

Foundation types known to the type system. Concrete coverage matches the runtime function tables above.

Date / TimeInterval

Epoch-seconds Double. Initialisers, comparison, distance(to:), addingTimeInterval, ISO formatting via bridge.

Calendar / DateComponents

Gregorian calendar; .current returns the system locale. dateComponents(_:from:) / date(from:) / range(of:in:for:) all wired.

URL / URLComponents / URLQueryItem

Component extraction + manipulation. URLComponents.queryItems setter materialises through __url_appending_query_items.

UserDefaults

Backed by localStorage in the browser; .standard works with set/get/remove for primitive types.

JSONSerialization

Top-level parse + dictionary key lookup + array index lookup via the bridge. Encoder/Decoder generic Codable not yet auto.

JSONEncoder / JSONDecoder

Class registered; encoding works for primitive types and dictionaries via JSONSerialization fall-back.

ISO8601DateFormatter

Class registered; .string(from: Date()) dispatches to __date_iso8601.

DateFormatter

Format string subset (yyyy / MM / dd / HH / mm / ss / MMMM / MMM / EEEE / EEE).

NSObject

Class registered for legacy bridging; no message-passing runtime.

Data

Type registered (see ir_lowering/data.c); subscript + count basic, no NSData bridging.

Not Yet Supported

Foundation surfaces outside the current scope. Most need either a JS API binding or a non-trivial Gregorian-calendar generalisation.

FileManager

No virtual filesystem in the browser; would need OPFS or in-memory FS.

URLSession (network)

fetch() bridge not yet wired. AsyncImage uses raw fetch directly.

NotificationCenter

Observer plumbing absent; no KVO/NS bridge.

Locale

Only "en_US" hardcoded paths exercised. Real Locale.current + bcp47 codes not honoured.

NumberFormatter

Currency / percent / scientific styles not implemented.

NSRegularExpression

No regex engine; Swift 5.7 regex literals also unimplemented.

FileHandle / Process / Pipe

No process model in WASM browser env.

NSAttributedString

Type slot unfilled; styled text not supported.

Operation / OperationQueue

Pre-Swift-Concurrency queue model — superseded by Task in our runtime.

Measurement / MeasurementFormatter

Unit family + dimensional analysis not implemented.

NSError chains

NSError is a class registered for sema; user errors are Swift Error all the way down.

Bundle / preferences

No on-disk bundle; UserDefaults via localStorage is the practical replacement.

Calendar identifiers

Only "gregorian" implemented — no buddhist / hebrew / islamic / chinese.

Codable auto-synthesis

Encoder / Decoder runtime works for primitives; struct ↔ JSON requires manual coding currently.

NSCoding / Archives

Old NSKeyedArchiver / Unarchiver not implemented.