Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions packages/compiler/src/backend/emission/emit-exprs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ function streamTypedRefAdapter(
` ScrDyn *d = scr_dyn_new_arr();`,
` for (size_t sc_i = 0; sc_i < v->len; sc_i++) {`,
);
if (elem.kind === "f64") {
if (elem.kind === "f64" || elem.kind === "date") {
lines.push(
` scr_dyn_arr_push(d, ${box(elem, "scr_arr_get_f64(v, (double)sc_i)")});`,
);
Expand Down Expand Up @@ -384,7 +384,7 @@ function streamFromArrayAdapter(
);
}
d.push(`${sig} { /* ReadableStream.from array<${key}> */`);
if (elem.kind === "f64") {
if (elem.kind === "f64" || elem.kind === "date") {
d.push(
` return ${E.toDynHelper(elem)}(scr_arr_get_f64(sc_a, sc_i));`,
);
Expand Down Expand Up @@ -3004,7 +3004,7 @@ export function emitExpr(E: CEmitter, e: IrExpr): Temp {
if (e.type.inner.kind !== "array") throw new InternalCompilerError("emitter bug: promise.all result");
const elem = e.type.inner.elem;
const store =
elem.kind === "f64"
(elem.kind === "f64" || elem.kind === "date")
? "scr_promise_all_store_f64"
: elem.kind === "bool"
? "scr_promise_all_store_bool"
Expand Down Expand Up @@ -7438,6 +7438,8 @@ export function emitExpr(E: CEmitter, e: IrExpr): Temp {
const v = E.emitExpr(e.value);
switch (e.value.type.kind) {
case "f64":
case "date":
// Date crossing IN: passed as millisecond timestamp (a JS number).
return E.newTemp(e.type, `scr_jsval_from_f64(${v.name})`);
case "bool":
return E.newTemp(e.type, `scr_jsval_from_bool(${v.name})`);
Expand Down
6 changes: 4 additions & 2 deletions packages/compiler/src/backend/emission/emit-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ export function elemKindC(elem: IrType): string {
}
switch (elem.kind) {
case "f64":
// Dates are epoch-ms f64 scalars at the C level — use the same slot.
case "date":
return "SCR_ELEM_F64";
case "bool":
return "SCR_ELEM_BOOL";
Expand Down Expand Up @@ -303,7 +305,6 @@ export function elemKindC(elem: IrType): string {
// pointer identity — exactly JS function identity.
case "func":
return "SCR_ELEM_REF";
case "date":
case "procStream":
case "undefinedT":
case "nullT":
Expand Down Expand Up @@ -381,7 +382,8 @@ export const DV_SET_KIND_C: Record<string, string> = {
/** Runtime accessor suffix for an element type: arrays store f64 and bool
* unboxed and everything refcounted as a pointer (`_ref`). */
export function elemAccess(elem: IrType): "f64" | "bool" | "ref" {
return elem.kind === "f64" ? "f64" : elem.kind === "bool" ? "bool" : "ref";
// Dates are stored as epoch-ms f64 scalars at the C level.
return (elem.kind === "f64" || elem.kind === "date") ? "f64" : elem.kind === "bool" ? "bool" : "ref";
}

/** Runtime suffix for a map's KEY kind (f64 with SameValueZero, or string
Expand Down
2 changes: 2 additions & 0 deletions packages/compiler/src/backend/llvm/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7812,6 +7812,8 @@ class LlEmitter {
};
switch (e.value.type.kind) {
case "f64":
case "date":
// Date crossing IN: passed as millisecond timestamp (a JS number).
return simple("scr_jsval_from_f64", "double", false);
case "bool":
return simple("scr_jsval_from_bool", "i1", false);
Expand Down
4 changes: 3 additions & 1 deletion packages/compiler/src/backend/llvm/shapes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,15 @@ export function traceArg(host: ShapeHost, t: IrType): string {
/** Runtime accessor suffix for an element type (matches emit-types.ts:
* f64 and bool unboxed, everything refcounted through the `_ref` family). */
export function elemAccess(elem: IrType): "f64" | "bool" | "ref" {
return elem.kind === "f64" ? "f64" : elem.kind === "bool" ? "bool" : "ref";
return (elem.kind === "f64" || elem.kind === "date") ? "f64" : elem.kind === "bool" ? "bool" : "ref";
}

/** The ScrElemKind constant for the plain (non-REF) construction path. */
function elemKindNum(elem: IrType): number {
switch (elem.kind) {
case "f64":
// Dates are epoch-ms f64 scalars at the C level — same slot kind.
case "date":
return 0; // SCR_ELEM_F64
case "bool":
return 1; // SCR_ELEM_BOOL
Expand Down
9 changes: 5 additions & 4 deletions packages/compiler/src/frontend/lowering/lowerer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6109,9 +6109,10 @@ export class Lowerer {
jsvalLiftable(t: IrType, visiting: Set<string> = new Set()): boolean {
if (t.kind === "jsval") return true;
if (this.boundarySafe(t)) return true;
// Typed arrays and URLs marshal IN without joining the round-trip
// (JSON) set: an engine typed-array copy / an engine URL from href.
if (t.kind === "bytes" || t.kind === "url") return true;
// Typed arrays, URLs, and Dates marshal IN without joining the round-trip
// (JSON) set: an engine typed-array copy / an engine URL from href /
// a Date as its millisecond timestamp (scr_jsval_from_f64).
if (t.kind === "bytes" || t.kind === "url" || t.kind === "date") return true;
// Checked-dynamic values deep-copy in (scr_jsval_from_dyn — data
// kinds; a boxed function/handle/promise throws at runtime).
if (t.kind === "dyn") return true;
Expand Down Expand Up @@ -6162,7 +6163,7 @@ export class Lowerer {
if (this.boundarySafe(e.type)) {
return { kind: "jsMarshal", value: e, type: JSVAL, loc };
}
if (e.type.kind === "bytes" || e.type.kind === "url") {
if (e.type.kind === "bytes" || e.type.kind === "url" || e.type.kind === "date") {
return { kind: "jsMarshal", value: e, type: JSVAL, loc };
}
if (e.type.kind === "record") {
Expand Down
3 changes: 3 additions & 0 deletions packages/compiler/src/ir/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,9 @@ export function isSupportedArrayElem(t: IrType): boolean {
case "netServer":
case "symbol":
case "classval":
// Dates are scalar f64 (epoch-ms) at the C level — stored in SCR_ELEM_F64
// slots. Array element reads re-box the ms value into a date handle.
case "date":
return true;
default:
return false;
Expand Down