@shd101wyy/yo 0.1.20 → 0.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/cjs/index.cjs +46 -46
- package/out/cjs/yo-cli.cjs +2 -2
- package/out/cjs/yo-lsp.cjs +54 -54
- package/out/esm/index.mjs +1 -1
- package/out/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/out/cjs/index.cjs
CHANGED
|
@@ -45,7 +45,7 @@ ${n.map(r=>I(r)).join(`
|
|
|
45
45
|
${e}
|
|
46
46
|
// === END auto-generated code ===
|
|
47
47
|
`,inputString:e});if(t.getParserError())throw t.getParserError();return t.getProgram()}function ba(e){return e.tag==="unit"||e.tag==="bool"||e.tag==="usize"||e.tag==="isize"||e.tag==="u8"||e.tag==="i8"||e.tag==="u16"||e.tag==="i16"||e.tag==="u32"||e.tag==="i32"||e.tag==="u64"||e.tag==="i64"||e.tag==="f32"||e.tag==="f64"||e.tag==="char"||e.tag==="short"||e.tag==="ushort"||e.tag==="int"||e.tag==="uint"||e.tag==="long"||e.tag==="ulong"||e.tag==="longlong"||e.tag==="ulonglong"||e.tag==="longdouble"}function De(e){return(e==null?void 0:e.tag)==="unit"}function rn(e){return(e==null?void 0:e.tag)==="comptime_int"}function En(e){return(e==null?void 0:e.tag)==="comptime_float"}function on(e){return(e==null?void 0:e.tag)==="comptime_string"}function sn(e){return(e==null?void 0:e.tag)==="ComptimeList"}function so(e){return sn(e)&&$n(e.childType)}function lr(e){return(e==null?void 0:e.tag)==="bool"}function ka(e){return(e==null?void 0:e.tag)==="usize"}function wa(e){return(e==null?void 0:e.tag)==="isize"}function jr(e){return(e==null?void 0:e.tag)==="u8"}function Fa(e){return(e==null?void 0:e.tag)==="i8"}function La(e){return(e==null?void 0:e.tag)==="u16"}function Ia(e){return(e==null?void 0:e.tag)==="i16"}function Aa(e){return(e==null?void 0:e.tag)==="u32"}function Sa(e){return(e==null?void 0:e.tag)==="i32"}function Na(e){return(e==null?void 0:e.tag)==="u64"}function Va(e){return(e==null?void 0:e.tag)==="i64"}function xa(e){return(e==null?void 0:e.tag)==="f32"}function Da(e){return(e==null?void 0:e.tag)==="f64"}function $n(e){return(e==null?void 0:e.tag)==="Expr"}function Je(e){return(e==null?void 0:e.tag)==="Array"}function $t(e){return(e==null?void 0:e.tag)==="Slice"}function ut(e){return(e==null?void 0:e.tag)==="Tuple"}function Bt(e){return(e==null?void 0:e.tag)==="Union"}function Be(e){return(e==null?void 0:e.tag)==="Enum"}function Ae(e){return(e==null?void 0:e.tag)==="Struct"}function en(e){return(e==null?void 0:e.tag)==="Struct"&&e.isReferenceSemantics}function oi(e){return(e==null?void 0:e.tag)==="Struct"&&e.isReferenceSemantics&&e.isAtomicRc===!0}function hr(e){return(e==null?void 0:e.tag)==="Struct"&&e.isNewtype}function Xe(e){return(e==null?void 0:e.tag)==="Module"}function ot(e){return(e==null?void 0:e.tag)==="Trait"}function gn(e){return ot(e)&&e.isFn!==void 0}function ne(e){return(e==null?void 0:e.tag)==="Function"}function Ma(e){return(e==null?void 0:e.tag)==="Function"&&e.return.isCompileTimeOnly}function St(e){return(e==null?void 0:e.tag)==="Type"}function C_(e){return St(e)&&e.tag==="Type"&&e.level===0}function z(e){return(e==null?void 0:e.tag)==="SomeType"}function je(e){return(e==null?void 0:e.tag)==="Ptr"}function hn(e){return(e==null?void 0:e.tag)==="Iso"}function st(e){return(e==null?void 0:e.tag)==="Dyn"}function Ci(e){return(e==null?void 0:e.tag)==="TypeApplication"}function rr(e){if(z(e)){let t=e;if(at(t))return!0;if(t.resolvedConcreteType)return rr(t.resolvedConcreteType)}return en(e)||st(e)||hn(e)}function ai(e){return(e==null?void 0:e.tag)==="u8"||(e==null?void 0:e.tag)==="i8"||(e==null?void 0:e.tag)==="u16"||(e==null?void 0:e.tag)==="i16"||(e==null?void 0:e.tag)==="u32"||(e==null?void 0:e.tag)==="i32"||(e==null?void 0:e.tag)==="u64"||(e==null?void 0:e.tag)==="i64"||(e==null?void 0:e.tag)==="usize"||(e==null?void 0:e.tag)==="isize"}function si(e){return(e==null?void 0:e.tag)==="f32"||(e==null?void 0:e.tag)==="f64"}function b_(e){return(e==null?void 0:e.tag)==="i8"||(e==null?void 0:e.tag)==="i16"||(e==null?void 0:e.tag)==="i32"||(e==null?void 0:e.tag)==="i64"||(e==null?void 0:e.tag)==="isize"}function Do(e){return(e==null?void 0:e.tag)==="char"}function bi(e){return(e==null?void 0:e.tag)==="void"}function Wn(e){return ot(e)&&e.isFuture!==void 0}function gs(e){return ot(e)&&e.isConcrete!==void 0}function Kr(e){return!!e&&(e.tag==="char"||e.tag==="short"||e.tag==="ushort"||e.tag==="int"||e.tag==="uint"||e.tag==="long"||e.tag==="ulong"||e.tag==="longlong"||e.tag==="ulonglong"||e.tag==="longdouble")}function Rr(e){var r;if(!e||(r=e.return)!=null&&r.isCompileTimeOnly)return!1;let t=e.parameters.some(i=>i.isCompileTimeOnly)||e.forallParameters.length>0||e.implicitParameters.length>0,n=e.parameters.some(i=>!i.isCompileTimeOnly&&z(i.type)&&!at(i.type));return t||n}function li(e){var r;if(!e||(r=e.return)!=null&&r.isCompileTimeOnly)return!1;let t=e.parameters.some(i=>i.isCompileTimeOnly)||e.forallParameters.length>0,n=e.parameters.some(i=>!i.isCompileTimeOnly&&z(i.type)&&!at(i.type));return t||n}function ru(e){var n;let t=e.type;return t?Rr(t)&&(((n=e.specializedFunctionCaches)==null?void 0:n.length)??0)>0:!1}function vr(e){var t;return en(e)?e.fields.length===1&&e.fields[0].label==="*"&&!!((t=e.typeName)!=null&&t.startsWith("Box(")):!1}function Yt(e){return(e==null?void 0:e.tag)==="EffectsRow"}function hs(e,t,n){let r=!1,i=0;for(let o of t){let a=o.type;if(n.includes(o))throw d({token:n[n.length-1].exprs.expr.token,errorMessage:`Recursive type has infinite size in field "${n[n.length-1].label}"
|
|
48
|
-
Insert some indirection (e.g., a pointer '*' or reference '&') to break the cycle.`});if(en(a))continue;let s=[...n,o],l=dn(a,s);St(l)&&(i=Math.max(i,l.level),l.tag==="Type"&&(r=!0))}return i>0?dr(i):r?Pt(e):Pt(e)}function dn(e,t=[]){if(st(e))return Pt(e);if(ba(e))return Pt(e);if(St(e))return dr(e.level+1);if(rn(e)||En(e)||on(e)||sn(e))return Pt(e);if($n(e))return Pt(e);if(ne(e))return Pt(e);if(gn(e))return Pt(e);if(Je(e))return dn(e.childType,t);if($t(e))return Pt(e);if(ut(e))return hs(e,e.fields,t);if(Ae(e))return hs(e,e.fields,t);if(Be(e)){let n=[];for(let r of e.variants)r.fields&&n.push(...r.fields);return hs(e,n,t)}else{if(Bt(e))return hs(e,e.fields,t);if(Xe(e))return dr(1,e);if(ot(e))return dr(1,e);if(z(e))return e.parentType;if(je(e))return Pt(e);if(hn(e))return Pt(e);if(Wn(e))return Pt(e);if(bi(e))return Pt(e);if(Yt(e))return dr(1);throw new Error(`Unknown type tag: ${e.tag}`)}}function k_(e){var t,n,r;if((t=e.exprs.labelExpr)!=null&&t.token)return e.exprs.labelExpr.token;if((n=e.exprs.typeExpr)!=null&&n.token)return e.exprs.typeExpr.token;if((r=e.exprs.defaultValueExpr)!=null&&r.token)return e.exprs.defaultValueExpr.token;throw new Error("Cannot get token for function parameter")}function pt(e){if(!e)return"<runtime value>";switch(e.tag){case"Type":return M(e.value);case"ComptimeInt":case"ComptimeFloat":return e.value.toString();case"ComptimeString":return JSON.stringify(e.value);case"ComptimeList":return`comptime_list(${e.elements.map(pt).join(", ")})`;case"U8":case"I8":case"U16":case"I16":case"U32":case"I32":case"U64":case"I64":case"F32":case"F64":case"Usize":case"Isize":return typeof e.value=="bigint",e.value.toString();case"Bool":return e.value.toString();case"Array":return`[${e.elements.map(pt).join(", ")}${e.elements.length===1?",":""}]`;case"Slice":return`slice[${e.sourceArray[0].elements.slice(e.startIndex,e.endIndex).map(pt).join(", ")}]`;case"Tuple":return e.fields.length===0?"()":`(${e.fields.map(pt).join(", ")}${e.fields.length===1?",":""})`;case"Struct":return`${e.type.typeName??"_"}(${e.fields.map((t,n)=>{let r=e.type.fields[n].label;return Hr(r)&&(r=`(${r})`),`${r}: ${pt(t)}`}).join(", ")})`;case"Enum":{if(e.fields.length===0)return`.${e.variantName}`;let t=e.type.variants.find(n=>n.name===e.variantName);return`.${e.variantName}(${e.fields.map((n,r)=>{let i=(t==null?void 0:t.fields[r].label)??"_";return Hr(i)&&(i=`(${i})`),`${i}: ${pt(n)}`}).join(", ")})`}case"Function":return e.funcName?`<fn ${e.funcName}>`:e.type.typeName?`<fn ${e.type.typeName}>`:"<fn>";case"Module":return`${e.type.typeName??"_"}(${e.fields.map((t,n)=>{let r=e.type.fields[n].label;return Hr(r)&&(r=`(${r})`),`${r}: ${pt(t)}`}).join(", ")})`;case"Trait":return`${e.type.typeName??"_"}(${e.fields.map((t,n)=>{let r=e.type.fields[n].label;return Hr(r)&&(r=`(${r})`),`${r}: ${pt(t)}`}).join(", ")})`;case"Unit":return"()";case"Expr":return`quote(${I(e.value)})`;case"Unknown":return e.variableName?e.variableName:`<comptime ${M(e.type)}>`;case"Ptr":{let t=e.targetValue[0];return mr(t)?`<ptr to ${pt(t.elements[e.targetIndex])}>`:`<ptr to ${pt(t)}>`}default:throw new Error("valueToString: Unsupported value")}}function W(e){return(e==null?void 0:e.tag)==="Type"}function yr(e){return(e==null?void 0:e.tag)==="ComptimeInt"}function vs(e){return(e==null?void 0:e.tag)==="ComptimeFloat"}function tt(e){return(e==null?void 0:e.tag)==="ComptimeString"}function Tr(e){return(e==null?void 0:e.tag)==="ComptimeList"}function w_(e){return Tr(e)&&$n(e.type.childType)}function ht(e){return(e==null?void 0:e.tag)==="ComptimeInt"||(e==null?void 0:e.tag)==="ComptimeFloat"||(e==null?void 0:e.tag)==="U8"||(e==null?void 0:e.tag)==="I8"||(e==null?void 0:e.tag)==="U16"||(e==null?void 0:e.tag)==="I16"||(e==null?void 0:e.tag)==="U32"||(e==null?void 0:e.tag)==="I32"||(e==null?void 0:e.tag)==="U64"||(e==null?void 0:e.tag)==="I64"||(e==null?void 0:e.tag)==="F32"||(e==null?void 0:e.tag)==="F64"||(e==null?void 0:e.tag)==="Usize"||(e==null?void 0:e.tag)==="Isize"}function Ct(e){return(e==null?void 0:e.tag)==="Bool"}function he(e){return(e==null?void 0:e.tag)==="Function"}function Ie(e){return(e==null?void 0:e.tag)==="Unknown"}function Zn(e){return(e==null?void 0:e.tag)==="Tuple"}function kn(e){return(e==null?void 0:e.tag)==="Struct"}function mr(e){return(e==null?void 0:e.tag)==="Array"}function lo(e){return(e==null?void 0:e.tag)==="Slice"}function mn(e){return(e==null?void 0:e.tag)==="Enum"}function wt(e){return(e==null?void 0:e.tag)==="Module"}function tn(e){return(e==null?void 0:e.tag)==="Trait"}function Vr(e){return(e==null?void 0:e.tag)==="Ptr"}function Dn(e){return(e==null?void 0:e.tag)==="Expr"}function Te(e){return{tag:"Type",type:dn(e),value:e}}function wn(e){return{tag:"ComptimeString",type:Fn(),value:e}}function Jn(e,t){return{tag:"ComptimeList",type:ki(e),elements:t}}function qn(e,t){let n;if(e==="ComptimeInt")n=ui();else if(e==="ComptimeFloat")n=Ro();else if(e==="U8")n=Uo();else if(e==="I8")n=zo();else if(e==="U16")n=Bo();else if(e==="I16")n=Go();else if(e==="U32")n=Wo();else if(e==="I32")n=Gi();else if(e==="U64")n=qo();else if(e==="I64")n=Yo();else if(e==="F32")n=Ho();else if(e==="F64")n=Wi();else if(e==="Usize")n=vn();else if(e==="Isize")n=Po();else throw new Error(`createNumberValue: Unsupported tag: ${e}`);return{tag:e,type:n,value:t}}function Pr(e){return qn("ComptimeInt",e)}function Ts(e){return qn("ComptimeFloat",e)}function Zt(e){return{tag:"Bool",type:Ut(),value:e}}function oe(e,{variableName:t,recursiveTypeRef:n,env:r,context:i}){if(St(e)&&e.level===0){if(!t)throw console.trace("!variableName bug found in createUnknownValue"),new Error(`createUnknownValue expects a variable name for type ${M(e)}`);let o=Er(e,t,{recursiveTypeRef:n,env:r,context:i});return Te(o)}if(ne(e)&&t){let o=e;if(o.return.isCompileTimeOnly&&St(o.return.type)&&o.return.type.level===0&&o.parameters.every(s=>s.isCompileTimeOnly)){let s=Er(o.return.type,t,{recursiveTypeRef:n,env:r,context:i});return s.kindFunctionType=o,Te(s)}}return{tag:"Unknown",type:e,variableName:t}}function Ur(e,t){return{tag:"Struct",type:e,fields:t}}function F_(e,t,n){return{tag:"Module",type:e,fields:t,moduleLevelInitExprs:n&&n.length>0?n:void 0}}function Mo(e,t){return{tag:"Trait",type:e,fields:t}}function Es(e,t){return{tag:"Tuple",type:e,fields:t}}function uo(e,t,n){return{tag:"Enum",type:e,variantName:t,fields:n}}function zi(e,t){return{tag:"Array",type:e,elements:t}}function Oo(e,t,n,r){return{tag:"Slice",type:e,sourceArray:t,startIndex:n,endIndex:r}}function Hn(e){return{tag:"Expr",type:Mn(),value:e}}function Bi(e,t,n=0){return{tag:"Ptr",type:e,targetValue:t,targetIndex:n}}function Cn(e,t){let n=e.value,r=t.value;if(n===r)return!0;if(!n||!r)return!1;if(n.tag==="Type"&&r.tag==="Type")return le({type:n.value,env:e.env},{type:r.value,env:t.env},!0);if(tt(n)&&tt(r))return n.value===r.value;if(Tr(n)&&Tr(r)){if(n.elements.length!==r.elements.length)return!1;for(let i=0;i<n.elements.length;i++)if(!Cn({value:n.elements[i],env:e.env},{value:r.elements[i],env:t.env}))return!1;return!0}else if(ht(n)&&ht(r)){let i=n.value,o=r.value;if(typeof i==typeof o)return i===o;let a=typeof i=="bigint"?i:BigInt(i),s=typeof o=="bigint"?o:BigInt(o);return a===s}else{if(Ct(n)&&Ct(r))return n.value===r.value;if(mr(n)&&mr(r)){if(n.elements.length!==r.elements.length)return!1;for(let i=0;i<n.elements.length;i++)if(!Cn({value:n.elements[i],env:e.env},{value:r.elements[i],env:t.env}))return!1;return!0}else if(lo(n)&&lo(r)){let i=n.endIndex-n.startIndex,o=r.endIndex-r.startIndex;if(i!==o)return!1;for(let a=0;a<i;a++){let s=n.sourceArray[0].elements[n.startIndex+a],l=r.sourceArray[0].elements[r.startIndex+a];if(!Cn({value:s,env:e.env},{value:l,env:t.env}))return!1}return!0}else if(Zn(n)&&Zn(r)){if(n.fields.length!==r.fields.length)return!1;for(let i=0;i<n.fields.length;i++)if(!Cn({value:n.fields[i],env:e.env},{value:r.fields[i],env:t.env}))return!1;return!0}else if(kn(n)&&kn(r)){if(n.fields.length!==r.fields.length||!le({type:n.type,env:e.env},{type:r.type,env:t.env},!0))return!1;for(let i=0;i<n.fields.length;i++)if(!Cn({value:n.fields[i],env:e.env},{value:r.fields[i],env:t.env}))return!1;return!0}else if(mn(n)&&mn(r)){if(n.fields.length!==r.fields.length||!le({type:n.type,env:e.env},{type:r.type,env:t.env},!0)||n.variantName!==r.variantName)return!1;for(let i=0;i<n.fields.length;i++)if(!Cn({value:n.fields[i],env:e.env},{value:r.fields[i],env:t.env}))return!1;return!0}else if(wt(n)&&wt(r)){if(n.fields.length!==r.fields.length||!le({type:n.type,env:e.env},{type:r.type,env:t.env},!0))return!1;for(let i=0;i<n.fields.length;i++)if(!Cn({value:n.fields[i],env:e.env},{value:r.fields[i],env:t.env}))return!1;return!0}else if(tn(n)&&tn(r)){if(n.fields.length!==r.fields.length||!le({type:n.type,env:e.env},{type:r.type,env:t.env},!0))return!1;for(let i=0;i<n.fields.length;i++)if(!Cn({value:n.fields[i],env:e.env},{value:r.fields[i],env:t.env}))return!1;return!0}else{if(Dn(n)&&Dn(r))return n.value===r.value||$s(n.value,r.value);if(Ie(n)&&Ie(r)){let i,o;if(n.variableName){let a=ae(e.env,n.variableName);if(a.length>0){let s=a[a.length-1];s.value&&!Ie(s.value[0])&&(i=s.value[0])}}if(r.variableName){let a=ae(t.env,r.variableName);if(a.length>0){let s=a[a.length-1];s.value&&!Ie(s.value[0])&&(o=s.value[0])}}return i&&o?Cn({value:i,env:e.env},{value:o,env:t.env}):i||o?!1:le({type:n.type,env:e.env},{type:r.type,env:t.env},!0)}else if(Ie(n)&&!Ie(r)){if(n.variableName){let i=ae(e.env,n.variableName);if(i.length>0){let o=i[i.length-1];if(o.value&&!Ie(o.value[0]))return Cn({value:o.value[0],env:e.env},{value:r,env:t.env})}}return!1}else if(!Ie(n)&&Ie(r)){if(r.variableName){let i=ae(t.env,r.variableName);if(i.length>0){let o=i[i.length-1];if(o.value&&!Ie(o.value[0]))return Cn({value:n,env:e.env},{value:o.value[0],env:t.env})}}return!1}else return Vr(n)&&Vr(r)?n.targetValue===r.targetValue&&n.targetIndex===r.targetIndex:!1}}}function ci(e,t){return e?_o(e,t):!1}function fi(e,t){return e?Fg(e,t):!1}function _o(e,t){return Jr(e,t)&&!Li(e,t)}function Fg(e,t){let n=Jr(e,t),r=Li(e,t);return!n&&r}function it(e,t=[]){if(!e||t.includes(e)||(t.push(e),e.isExtern))return!1;if(rr(e))return!0;switch(e.tag){case"Array":return it(e.childType,t);case"Tuple":return e.fields.some(n=>it(n.type,t));case"Union":return e.fields.some(n=>it(n.type,t));case"Struct":return e.fields.some(n=>it(n.type,t));case"Enum":return e.variants.some(n=>{var r;return(r=n.fields)==null?void 0:r.some(i=>it(i.type,t))});case"Iso":return it(e.childType,t);case"Module":return!1;case"Function":return!1;case"SomeType":{let n=e;return at(n)?!0:n.resolvedConcreteType?it(n.resolvedConcreteType,t):!0}default:return!1}}function Me(e,t=[]){if(!e||t.includes(e))return!1;if(t.push(e),z(e))return e.isExtern?!1:e.resolvedConcreteType?Me(e.resolvedConcreteType,t):!(zn(e)||at(e));switch(e.tag){case"Array":return Me(e.childType,t);case"Tuple":return e.fields.some(n=>Me(n.type,t));case"Struct":return e.fields.some(n=>!n.isEffectParam&&Me(n.type,t));case"Enum":return e.variants.some(n=>{var r;return(r=n.fields)==null?void 0:r.some(i=>Me(i.type,t))});case"Union":return e.fields.some(n=>Me(n.type,t));case"Function":{let n=e;return n.forallParameters.length>0||n.parameters.some(r=>Me(r.type,t))||Me(n.return.type,t)}case"Module":return e.fields.some(n=>Me(n.type,t));case"Ptr":return Me(e.childType,t);case"Slice":return Me(e.childType,t);case"TypeApplication":return!0;default:return!1}}function wi(e,t=new Set){return t.has(e.id)?!1:(t.add(e.id),Je(e)?Ie(e.length)?!0:wi(e.childType,t):je(e)||$t(e)?wi(e.childType,t):ut(e)?e.fields.some(n=>wi(n.type,t)):Ae(e)?e.fields.some(n=>wi(n.type,t)):Be(e)?e.variants.some(n=>{var r;return(r=n.fields)==null?void 0:r.some(i=>wi(i.type,t))}):Bt(e)?e.fields.some(n=>wi(n.type,t)):!1)}function ou(e){let t=new Set,n=new Set;function r(i){if(!(i&&n.has(i))){if(i&&n.add(i),z(i)){if(t.has(i))return;i.resolvedConcreteType||t.add(i)}switch(i.tag){case"Array":r(i.childType);break;case"Tuple":i.fields.forEach(o=>r(o.type));break;case"Struct":i.fields.forEach(o=>r(o.type));break;case"Enum":i.variants.forEach(o=>{var a;(a=o.fields)==null||a.forEach(s=>r(s.type))});break;case"Union":i.fields.forEach(o=>r(o.type));break;case"Module":i.fields.forEach(o=>r(o.type));break;case"Ptr":r(i.childType);break;default:break}}}return r(e),t}function Ko(e){if(!e)return!1;switch(e.tag){case"Array":{let t=e;return Ie(t.length)||Ko(t.childType)}case"SomeType":return!0;case"Module":return!1;case"Trait":{let t=e;return t.isFn?Ko(t.isFn.callType):!1}default:return!1}}function an({type:e,expectedType:t,expr:n,env:r}){let i;if(rn(e))i=Gi();else if(En(e))i=Wi();else if(on(e))t&&(je(t)&&(jr(t.childType)||Do(t.childType))||$t(t))&&(i=t),i||(i=S_(r));else return e;return i&&(n!=null&&n.$)&&(n.$.convertedRuntimeType=i),i??e}function iu(e,t=new Set){let n=e.label;e.isQuote?n=`quote(${n})`:e.isImplicit||e.isCompileTimeOnly&&(n=`comptime(${n})`);let r=M(e.type,t),i=e.exprs.defaultValueExpr?I(e.exprs.defaultValueExpr):"";return n===""?r:i?`(${n} : ${r}) ?= ${i}`:`${n} : ${r}`}function jo(e,t=new Set){let n=e.label;Hr(n)&&(n=`(${n})`);let r=e.defaultValue?pt(e.defaultValue):"",i=e.assignedValue?pt(e.assignedValue):"";return r?`(${n}: ${M(e.type,t)}) ?= ${r}`:i?`(${n}: ${M(e.type,t)}) = ${i}`:`${n}: ${M(e.type,t)}`}function L_(e,t=new Set){let n=e.label;Hr(n)&&(n=`(${n})`);let r=e.defaultValue?pt(e.defaultValue):"",i=e.assignedValue?pt(e.assignedValue):"";return r?`(${n} : ${M(e.type,t)}) ?= ${r}`:i?`(${n} : ${M(e.type,t)}) = ${i}`:`${n} : ${M(e.type,t)}`}function I_(e,t=new Set){var c;let n=e.parameters.map(f=>iu(f,t)).join(", "),r=e.forallParameters.length>0?`forall(${e.forallParameters.map(f=>iu(f,t)).join(", ")})`:"",i="";e.variadicParameter&&(e.variadicParameter.label==="..."?i="...":e.variadicParameter.isQuote?i=`...(quote(${e.variadicParameter.label}))`:e.variadicParameter.isCompileTimeOnly?i=`...(comptime(${e.variadicParameter.label}))`:i=`...(${e.variadicParameter.label})`);let o=M(e.return.type,t),a=o;e.return.isUnquote?e.return.label?a=`(unquote(${e.return.label}) : ${o})`:a=`unquote(${o})`:e.return.isCompileTimeOnly&&(e.return.label?a=`(comptime(${e.return.label}) : ${o})`:a=`comptime(${o})`);let s=e.implicitParameters.length>0?`using(${e.implicitParameters.map(f=>f.isEffectRowSpread?`...(${f.label})`:iu(f,t)).join(", ")})`:"",l=[r,n,s,i].filter(f=>!!f).join(", "),u=(c=e.SelfType)==null?void 0:c.typeName;return`${u?`(${u}) `:""}fn(${l}) -> ${a}`}function M(e,t=new Set){if(e.id&&t.has(e.id))return e.typeName||`<circular:${e.tag}>`;e.id&&t.add(e.id);try{return Lg(e,t)}finally{e.id&&t.delete(e.id)}}function Lg(e,t){if(!e)return"unknown";switch(e.tag){case"unit":return"unit";case"bool":return"bool";case"usize":return"usize";case"isize":return"isize";case"u8":return"u8";case"i8":return"i8";case"u16":return"u16";case"i16":return"i16";case"u32":return"u32";case"i32":return"i32";case"u64":return"u64";case"i64":return"i64";case"f32":return"f32";case"f64":return"f64";case"Type":return"level"in e&&typeof e.level=="number"&&e.level>0?`Type(${e.level})`:"Type";case"Array":return`[${M(e.childType,t)}; ${pt(e.length)}]`;case"Slice":return`[${M(e.childType,t)}]`;case"Tuple":return e.fields.length===0?"()":`(${e.fields.map(n=>jo(n,t)).join(", ")}${e.fields.length===1?",":""})`;case"Struct":{let n=e;return n.typeName?n.typeName:`${n.typeName?`(${n.typeName}) `:""}${n.isAtomicRc?"atomic ":""}${n.isReferenceSemantics?"object":n.isNewtype?"newtype":"struct"}(${n.fields.map(r=>jo(r,t)).join(", ")})`}case"Enum":{let n=e;if(n.typeName){let r=n.typeName;return n.requiredVariantNames??n.selectedVariantName?`${r} (${n.requiredVariantNames?`${n.requiredVariantNames.map(i=>`.${i}`).join(" | ")} required`:`.${n.selectedVariantName} selected`})`:r}return`${n.typeName?`(${n.typeName}) `:""}enum(${n.variants.map(r=>`${r.name}${r.fields?`(${r.fields.map(i=>jo(i,t)).join(", ")})`:""}`).join(", ")})`}case"Union":{let n=e;if(n.typeName)return n.typeName;let r=n.fields;return`${n.typeName?`(${n.typeName}) `:""}${n.typeName?"union":n.id}(${r.map(i=>jo(i,t)).join(", ")})`}case"Module":{let n=e,r;return n.typeName?r=n.typeName:r=`${n.typeName?`(${n.typeName}) `:""}module(${n.fields.map(i=>L_(i,t)).join(", ")})`,r}case"Trait":{let n=e;if(gn(n))return`Fn${I_(n.isFn.callType,t).slice(2)}`;if(Wn(n)){let i=[M(n.isFuture.outputType,t)];for(let o of n.isFuture.effects)o.isEffectRowSpread?i.push(`...(${o.label})`):i.push(M(o.type,t));return`Future(${i.join(", ")})`}let r;return n.typeName?r=n.typeName:r=`${n.typeName?`(${n.typeName}) `:""}trait(${n.fields.map(i=>L_(i,t)).join(", ")})`,n.receiverType&&(r=`(${M(n.receiverType,t)} <: ${r})`),r}case"Function":{let n=e;return n.typeName?n.typeName:I_(n,t)}case"SomeType":{let n=e;if(n.typeName)return n.typeName;if(n.functionApplication)return I(n.functionApplication);let r=[];if(n.requiredTraits&&n.requiredTraits.length>0)for(let i of n.requiredTraits)r.push(M(i.traitType,t));if(n.negativeTraits&&n.negativeTraits.length>0)for(let i of n.negativeTraits)r.push(`!(${M(i.traitType,t)})`);return r.length>0?`${n.name||"Impl"}(${r.join(", ")})`:n.name||"Impl()"}case"Ptr":return`*(${M(e.childType,t)})`;case"Iso":return`Iso(${M(e.childType,t)})`;case"Expr":return"Expr";case"ComptimeList":return`ComptimeList(${M(e.childType)})`;case"EffectsRow":{let n=e;return n.implicitParameters.length===0?"EffectsRow()":`EffectsRow(${n.implicitParameters.map(r=>`${r.label} : ${M(r.type,t)}`).join(", ")})`}case"Dyn":{let n=e;if(n.typeName)return n.typeName;let r=[];for(let{traitType:i}of n.requiredTraits)r.push(M(i,t));if(n.negativeTraits&&n.negativeTraits.length>0)for(let{traitType:i}of n.negativeTraits)r.push(`!(${M(i,t)})`);return`Dyn(${r.join(", ")})`}case"TypeApplication":{let n=e,r=M(n.constructor,t),i=n.args.map(o=>M(o,t)).join(", ");return`${r}(${i})`}default:return`${e.tag}`}}var A_=64;function Qr(){return A_}function Cs(){return A_/8}function Ig(e){let t=Yi(e.childType);if(t===null)return null;if(t===-1)return-1;let n=e.length;if(ht(n)){let r=BigInt(n.value);if(r<0)throw new Error("Array length cannot be negative");return Number(r)*t}return null}function Ag(e){let t=0,n=1;for(let r of e.fields){let i=Yi(r.type);if(i===null)return null;if(i===-1)return-1;let o=Xr(r.type);if(o===null)return null;let a=Math.ceil(i/8);t=Math.ceil(t/o)*o,t+=a,n=Math.max(n,o)}return t=Math.ceil(t/n)*n,t*8}function Sg(e){let t=0,n=1;for(let r of e.fields){let i=Yi(r.type);if(i===null)return null;if(i===-1)return-1;let o=Xr(r.type);if(o===null)return null;let a=Math.ceil(i/8);t=Math.ceil(t/o)*o,t+=a,n=Math.max(n,o)}return t=Math.ceil(t/n)*n,t*8}function Ng(e){let t=0,n=0;for(let m of e.variants){let h=0,y=1;if(m.fields)for(let v of m.fields){let T=Yi(v.type);if(T===null)return null;if(T===-1)return-1;let $=Xr(v.type);if($===null)return null;let C=Math.ceil(T/8);h=Math.ceil(h/$)*$,h+=C,y=Math.max(y,$),n=Math.max(n,$*8)}h=Math.ceil(h/y)*y;let g=h*8;t=Math.max(t,g)}let r=Math.ceil(Math.ceil(Math.log2(e.variants.length))/8)*8,i=32,o=Math.max(n,8),a=Math.max(i,o),s=r/8,l=o/8,u=(l-s%l)%l*8,_=r+u+t,c=_/8,f=a/8,p=(f-c%f)%f*8;return _+p}function Vg(e){let t=0;for(let n of e.fields){let r=Yi(n.type);if(r===null)return null;if(r===-1)return-1;t=Math.max(t,r)}return t}function Xr(e){if(z(e))return null;if(De(e)||St(e)||rn(e)||En(e)||on(e)||sn(e)||Xe(e)||ot(e)||$n(e))return 1;if(lr(e))return 1;if(ka(e)||wa(e))return Cs();if(jr(e)||Fa(e))return 1;if(La(e)||Ia(e))return 2;if(Aa(e)||Sa(e))return 4;if(Na(e)||Va(e))return 8;if(xa(e))return 4;if(Da(e))return 8;if(Je(e))return Xr(e.childType);if(ut(e)){let t=1;for(let n of e.fields){let r=Xr(n.type);if(r===null)return null;t=Math.max(t,r)}return t}else if(Ae(e)){if(e.isReferenceSemantics)return Cs();if(e.isNewtype)return Xr(e.fields[0].type);let t=1;for(let n of e.fields){let r=Xr(n.type);if(r===null)return null;t=Math.max(t,r)}return t}else if(Be(e)){let t=1;for(let n of e.variants)if(n.fields)for(let r of n.fields){let i=Xr(r.type);if(i===null)return null;t=Math.max(t,i)}return t}else if(Bt(e)){let t=1;for(let n of e.fields){let r=Xr(n.type);if(r===null)return null;t=Math.max(t,r)}return t}else{if(ne(e))return Cs();if(je(e))return Cs()}return null}function Yi(e){return z(e)?null:De(e)||St(e)||rn(e)||En(e)||on(e)||sn(e)||Xe(e)||ot(e)||$n(e)?0:lr(e)?8:ka(e)||wa(e)?Qr():jr(e)||Fa(e)?8:La(e)||Ia(e)?16:Aa(e)||Sa(e)?32:Na(e)||Va(e)?64:xa(e)?32:Da(e)?64:Je(e)?Ig(e):ut(e)?Ag(e):Ae(e)?e.isReferenceSemantics?Qr():e.isNewtype?Yi(e.fields[0].type):Sg(e):Be(e)?Ng(e):Bt(e)?Vg(e):ne(e)||je(e)?Qr():null}function Fi(e,t){if(bi(e))throw Qt([{token:t,errorMessage:`Cannot use 'void' type here.
|
|
48
|
+
Insert some indirection (e.g., a pointer '*' or reference '&') to break the cycle.`});if(en(a))continue;let s=[...n,o],l=dn(a,s);St(l)&&(i=Math.max(i,l.level),l.tag==="Type"&&(r=!0))}return i>0?dr(i):r?Pt(e):Pt(e)}function dn(e,t=[]){if(st(e))return Pt(e);if(ba(e))return Pt(e);if(St(e))return dr(e.level+1);if(rn(e)||En(e)||on(e)||sn(e))return Pt(e);if($n(e))return Pt(e);if(ne(e))return Pt(e);if(gn(e))return Pt(e);if(Je(e))return dn(e.childType,t);if($t(e))return Pt(e);if(ut(e))return hs(e,e.fields,t);if(Ae(e))return hs(e,e.fields,t);if(Be(e)){let n=[];for(let r of e.variants)r.fields&&n.push(...r.fields);return hs(e,n,t)}else{if(Bt(e))return hs(e,e.fields,t);if(Xe(e))return dr(1,e);if(ot(e))return dr(1,e);if(z(e))return e.parentType;if(je(e))return Pt(e);if(hn(e))return Pt(e);if(Wn(e))return Pt(e);if(bi(e))return Pt(e);if(Yt(e))return dr(1);throw new Error(`Unknown type tag: ${e.tag}`)}}function k_(e){var t,n,r;if((t=e.exprs.labelExpr)!=null&&t.token)return e.exprs.labelExpr.token;if((n=e.exprs.typeExpr)!=null&&n.token)return e.exprs.typeExpr.token;if((r=e.exprs.defaultValueExpr)!=null&&r.token)return e.exprs.defaultValueExpr.token;throw new Error("Cannot get token for function parameter")}function pt(e){if(!e)return"<runtime value>";switch(e.tag){case"Type":return M(e.value);case"ComptimeInt":case"ComptimeFloat":return e.value.toString();case"ComptimeString":return JSON.stringify(e.value);case"ComptimeList":return`comptime_list(${e.elements.map(pt).join(", ")})`;case"U8":case"I8":case"U16":case"I16":case"U32":case"I32":case"U64":case"I64":case"F32":case"F64":case"Usize":case"Isize":return typeof e.value=="bigint",e.value.toString();case"Bool":return e.value.toString();case"Array":return`[${e.elements.map(pt).join(", ")}${e.elements.length===1?",":""}]`;case"Slice":return`slice[${e.sourceArray[0].elements.slice(e.startIndex,e.endIndex).map(pt).join(", ")}]`;case"Tuple":return e.fields.length===0?"()":`(${e.fields.map(pt).join(", ")}${e.fields.length===1?",":""})`;case"Struct":return`${e.type.typeName??"_"}(${e.fields.map((t,n)=>{let r=e.type.fields[n].label;return Hr(r)&&(r=`(${r})`),`${r}: ${pt(t)}`}).join(", ")})`;case"Enum":{if(e.fields.length===0)return`.${e.variantName}`;let t=e.type.variants.find(n=>n.name===e.variantName);return`.${e.variantName}(${e.fields.map((n,r)=>{let i=(t==null?void 0:t.fields[r].label)??"_";return Hr(i)&&(i=`(${i})`),`${i}: ${pt(n)}`}).join(", ")})`}case"Function":return e.funcName?`<fn ${e.funcName}>`:e.type.typeName?`<fn ${e.type.typeName}>`:"<fn>";case"Module":return`${e.type.typeName??"_"}(${e.fields.map((t,n)=>{let r=e.type.fields[n].label;return Hr(r)&&(r=`(${r})`),`${r}: ${pt(t)}`}).join(", ")})`;case"Trait":return`${e.type.typeName??"_"}(${e.fields.map((t,n)=>{let r=e.type.fields[n].label;return Hr(r)&&(r=`(${r})`),`${r}: ${pt(t)}`}).join(", ")})`;case"Unit":return"()";case"Expr":return`quote(${I(e.value)})`;case"Unknown":return e.variableName?e.variableName:`<comptime ${M(e.type)}>`;case"Ptr":{let t=e.targetValue[0];return mr(t)?`<ptr to ${pt(t.elements[e.targetIndex])}>`:`<ptr to ${pt(t)}>`}default:throw new Error("valueToString: Unsupported value")}}function W(e){return(e==null?void 0:e.tag)==="Type"}function yr(e){return(e==null?void 0:e.tag)==="ComptimeInt"}function vs(e){return(e==null?void 0:e.tag)==="ComptimeFloat"}function tt(e){return(e==null?void 0:e.tag)==="ComptimeString"}function Tr(e){return(e==null?void 0:e.tag)==="ComptimeList"}function w_(e){return Tr(e)&&$n(e.type.childType)}function ht(e){return(e==null?void 0:e.tag)==="ComptimeInt"||(e==null?void 0:e.tag)==="ComptimeFloat"||(e==null?void 0:e.tag)==="U8"||(e==null?void 0:e.tag)==="I8"||(e==null?void 0:e.tag)==="U16"||(e==null?void 0:e.tag)==="I16"||(e==null?void 0:e.tag)==="U32"||(e==null?void 0:e.tag)==="I32"||(e==null?void 0:e.tag)==="U64"||(e==null?void 0:e.tag)==="I64"||(e==null?void 0:e.tag)==="F32"||(e==null?void 0:e.tag)==="F64"||(e==null?void 0:e.tag)==="Usize"||(e==null?void 0:e.tag)==="Isize"}function Ct(e){return(e==null?void 0:e.tag)==="Bool"}function ge(e){return(e==null?void 0:e.tag)==="Function"}function Ie(e){return(e==null?void 0:e.tag)==="Unknown"}function Zn(e){return(e==null?void 0:e.tag)==="Tuple"}function kn(e){return(e==null?void 0:e.tag)==="Struct"}function mr(e){return(e==null?void 0:e.tag)==="Array"}function lo(e){return(e==null?void 0:e.tag)==="Slice"}function mn(e){return(e==null?void 0:e.tag)==="Enum"}function wt(e){return(e==null?void 0:e.tag)==="Module"}function tn(e){return(e==null?void 0:e.tag)==="Trait"}function Vr(e){return(e==null?void 0:e.tag)==="Ptr"}function Dn(e){return(e==null?void 0:e.tag)==="Expr"}function Te(e){return{tag:"Type",type:dn(e),value:e}}function wn(e){return{tag:"ComptimeString",type:Fn(),value:e}}function Jn(e,t){return{tag:"ComptimeList",type:ki(e),elements:t}}function qn(e,t){let n;if(e==="ComptimeInt")n=ui();else if(e==="ComptimeFloat")n=Ro();else if(e==="U8")n=Uo();else if(e==="I8")n=zo();else if(e==="U16")n=Bo();else if(e==="I16")n=Go();else if(e==="U32")n=Wo();else if(e==="I32")n=Gi();else if(e==="U64")n=qo();else if(e==="I64")n=Yo();else if(e==="F32")n=Ho();else if(e==="F64")n=Wi();else if(e==="Usize")n=vn();else if(e==="Isize")n=Po();else throw new Error(`createNumberValue: Unsupported tag: ${e}`);return{tag:e,type:n,value:t}}function Pr(e){return qn("ComptimeInt",e)}function Ts(e){return qn("ComptimeFloat",e)}function Zt(e){return{tag:"Bool",type:Ut(),value:e}}function oe(e,{variableName:t,recursiveTypeRef:n,env:r,context:i}){if(St(e)&&e.level===0){if(!t)throw console.trace("!variableName bug found in createUnknownValue"),new Error(`createUnknownValue expects a variable name for type ${M(e)}`);let o=Er(e,t,{recursiveTypeRef:n,env:r,context:i});return Te(o)}if(ne(e)&&t){let o=e;if(o.return.isCompileTimeOnly&&St(o.return.type)&&o.return.type.level===0&&o.parameters.every(s=>s.isCompileTimeOnly)){let s=Er(o.return.type,t,{recursiveTypeRef:n,env:r,context:i});return s.kindFunctionType=o,Te(s)}}return{tag:"Unknown",type:e,variableName:t}}function Ur(e,t){return{tag:"Struct",type:e,fields:t}}function F_(e,t,n){return{tag:"Module",type:e,fields:t,moduleLevelInitExprs:n&&n.length>0?n:void 0}}function Mo(e,t){return{tag:"Trait",type:e,fields:t}}function Es(e,t){return{tag:"Tuple",type:e,fields:t}}function uo(e,t,n){return{tag:"Enum",type:e,variantName:t,fields:n}}function zi(e,t){return{tag:"Array",type:e,elements:t}}function Oo(e,t,n,r){return{tag:"Slice",type:e,sourceArray:t,startIndex:n,endIndex:r}}function Hn(e){return{tag:"Expr",type:Mn(),value:e}}function Bi(e,t,n=0){return{tag:"Ptr",type:e,targetValue:t,targetIndex:n}}function Cn(e,t){let n=e.value,r=t.value;if(n===r)return!0;if(!n||!r)return!1;if(n.tag==="Type"&&r.tag==="Type")return le({type:n.value,env:e.env},{type:r.value,env:t.env},!0);if(tt(n)&&tt(r))return n.value===r.value;if(Tr(n)&&Tr(r)){if(n.elements.length!==r.elements.length)return!1;for(let i=0;i<n.elements.length;i++)if(!Cn({value:n.elements[i],env:e.env},{value:r.elements[i],env:t.env}))return!1;return!0}else if(ht(n)&&ht(r)){let i=n.value,o=r.value;if(typeof i==typeof o)return i===o;let a=typeof i=="bigint"?i:BigInt(i),s=typeof o=="bigint"?o:BigInt(o);return a===s}else{if(Ct(n)&&Ct(r))return n.value===r.value;if(mr(n)&&mr(r)){if(n.elements.length!==r.elements.length)return!1;for(let i=0;i<n.elements.length;i++)if(!Cn({value:n.elements[i],env:e.env},{value:r.elements[i],env:t.env}))return!1;return!0}else if(lo(n)&&lo(r)){let i=n.endIndex-n.startIndex,o=r.endIndex-r.startIndex;if(i!==o)return!1;for(let a=0;a<i;a++){let s=n.sourceArray[0].elements[n.startIndex+a],l=r.sourceArray[0].elements[r.startIndex+a];if(!Cn({value:s,env:e.env},{value:l,env:t.env}))return!1}return!0}else if(Zn(n)&&Zn(r)){if(n.fields.length!==r.fields.length)return!1;for(let i=0;i<n.fields.length;i++)if(!Cn({value:n.fields[i],env:e.env},{value:r.fields[i],env:t.env}))return!1;return!0}else if(kn(n)&&kn(r)){if(n.fields.length!==r.fields.length||!le({type:n.type,env:e.env},{type:r.type,env:t.env},!0))return!1;for(let i=0;i<n.fields.length;i++)if(!Cn({value:n.fields[i],env:e.env},{value:r.fields[i],env:t.env}))return!1;return!0}else if(mn(n)&&mn(r)){if(n.fields.length!==r.fields.length||!le({type:n.type,env:e.env},{type:r.type,env:t.env},!0)||n.variantName!==r.variantName)return!1;for(let i=0;i<n.fields.length;i++)if(!Cn({value:n.fields[i],env:e.env},{value:r.fields[i],env:t.env}))return!1;return!0}else if(wt(n)&&wt(r)){if(n.fields.length!==r.fields.length||!le({type:n.type,env:e.env},{type:r.type,env:t.env},!0))return!1;for(let i=0;i<n.fields.length;i++)if(!Cn({value:n.fields[i],env:e.env},{value:r.fields[i],env:t.env}))return!1;return!0}else if(tn(n)&&tn(r)){if(n.fields.length!==r.fields.length||!le({type:n.type,env:e.env},{type:r.type,env:t.env},!0))return!1;for(let i=0;i<n.fields.length;i++)if(!Cn({value:n.fields[i],env:e.env},{value:r.fields[i],env:t.env}))return!1;return!0}else{if(Dn(n)&&Dn(r))return n.value===r.value||$s(n.value,r.value);if(Ie(n)&&Ie(r)){let i,o;if(n.variableName){let a=ae(e.env,n.variableName);if(a.length>0){let s=a[a.length-1];s.value&&!Ie(s.value[0])&&(i=s.value[0])}}if(r.variableName){let a=ae(t.env,r.variableName);if(a.length>0){let s=a[a.length-1];s.value&&!Ie(s.value[0])&&(o=s.value[0])}}return i&&o?Cn({value:i,env:e.env},{value:o,env:t.env}):i||o?!1:le({type:n.type,env:e.env},{type:r.type,env:t.env},!0)}else if(Ie(n)&&!Ie(r)){if(n.variableName){let i=ae(e.env,n.variableName);if(i.length>0){let o=i[i.length-1];if(o.value&&!Ie(o.value[0]))return Cn({value:o.value[0],env:e.env},{value:r,env:t.env})}}return!1}else if(!Ie(n)&&Ie(r)){if(r.variableName){let i=ae(t.env,r.variableName);if(i.length>0){let o=i[i.length-1];if(o.value&&!Ie(o.value[0]))return Cn({value:n,env:e.env},{value:o.value[0],env:t.env})}}return!1}else return Vr(n)&&Vr(r)?n.targetValue===r.targetValue&&n.targetIndex===r.targetIndex:!1}}}function ci(e,t){return e?_o(e,t):!1}function fi(e,t){return e?Fg(e,t):!1}function _o(e,t){return Jr(e,t)&&!Li(e,t)}function Fg(e,t){let n=Jr(e,t),r=Li(e,t);return!n&&r}function it(e,t=[]){if(!e||t.includes(e)||(t.push(e),e.isExtern))return!1;if(rr(e))return!0;switch(e.tag){case"Array":return it(e.childType,t);case"Tuple":return e.fields.some(n=>it(n.type,t));case"Union":return e.fields.some(n=>it(n.type,t));case"Struct":return e.fields.some(n=>it(n.type,t));case"Enum":return e.variants.some(n=>{var r;return(r=n.fields)==null?void 0:r.some(i=>it(i.type,t))});case"Iso":return it(e.childType,t);case"Module":return!1;case"Function":return!1;case"SomeType":{let n=e;return at(n)?!0:n.resolvedConcreteType?it(n.resolvedConcreteType,t):!0}default:return!1}}function Me(e,t=[]){if(!e||t.includes(e))return!1;if(t.push(e),z(e))return e.isExtern?!1:e.resolvedConcreteType?Me(e.resolvedConcreteType,t):!(zn(e)||at(e));switch(e.tag){case"Array":return Me(e.childType,t);case"Tuple":return e.fields.some(n=>Me(n.type,t));case"Struct":return e.fields.some(n=>!n.isEffectParam&&Me(n.type,t));case"Enum":return e.variants.some(n=>{var r;return(r=n.fields)==null?void 0:r.some(i=>Me(i.type,t))});case"Union":return e.fields.some(n=>Me(n.type,t));case"Function":{let n=e;return n.forallParameters.length>0||n.parameters.some(r=>Me(r.type,t))||Me(n.return.type,t)}case"Module":return e.fields.some(n=>Me(n.type,t));case"Ptr":return Me(e.childType,t);case"Slice":return Me(e.childType,t);case"TypeApplication":return!0;default:return!1}}function wi(e,t=new Set){return t.has(e.id)?!1:(t.add(e.id),Je(e)?Ie(e.length)?!0:wi(e.childType,t):je(e)||$t(e)?wi(e.childType,t):ut(e)?e.fields.some(n=>wi(n.type,t)):Ae(e)?e.fields.some(n=>wi(n.type,t)):Be(e)?e.variants.some(n=>{var r;return(r=n.fields)==null?void 0:r.some(i=>wi(i.type,t))}):Bt(e)?e.fields.some(n=>wi(n.type,t)):!1)}function ou(e){let t=new Set,n=new Set;function r(i){if(!(i&&n.has(i))){if(i&&n.add(i),z(i)){if(t.has(i))return;i.resolvedConcreteType||t.add(i)}switch(i.tag){case"Array":r(i.childType);break;case"Tuple":i.fields.forEach(o=>r(o.type));break;case"Struct":i.fields.forEach(o=>r(o.type));break;case"Enum":i.variants.forEach(o=>{var a;(a=o.fields)==null||a.forEach(s=>r(s.type))});break;case"Union":i.fields.forEach(o=>r(o.type));break;case"Module":i.fields.forEach(o=>r(o.type));break;case"Ptr":r(i.childType);break;default:break}}}return r(e),t}function Ko(e){if(!e)return!1;switch(e.tag){case"Array":{let t=e;return Ie(t.length)||Ko(t.childType)}case"SomeType":return!0;case"Module":return!1;case"Trait":{let t=e;return t.isFn?Ko(t.isFn.callType):!1}default:return!1}}function an({type:e,expectedType:t,expr:n,env:r}){let i;if(rn(e))i=Gi();else if(En(e))i=Wi();else if(on(e))t&&(je(t)&&(jr(t.childType)||Do(t.childType))||$t(t))&&(i=t),i||(i=S_(r));else return e;return i&&(n!=null&&n.$)&&(n.$.convertedRuntimeType=i),i??e}function iu(e,t=new Set){let n=e.label;e.isQuote?n=`quote(${n})`:e.isImplicit||e.isCompileTimeOnly&&(n=`comptime(${n})`);let r=M(e.type,t),i=e.exprs.defaultValueExpr?I(e.exprs.defaultValueExpr):"";return n===""?r:i?`(${n} : ${r}) ?= ${i}`:`${n} : ${r}`}function jo(e,t=new Set){let n=e.label;Hr(n)&&(n=`(${n})`);let r=e.defaultValue?pt(e.defaultValue):"",i=e.assignedValue?pt(e.assignedValue):"";return r?`(${n}: ${M(e.type,t)}) ?= ${r}`:i?`(${n}: ${M(e.type,t)}) = ${i}`:`${n}: ${M(e.type,t)}`}function L_(e,t=new Set){let n=e.label;Hr(n)&&(n=`(${n})`);let r=e.defaultValue?pt(e.defaultValue):"",i=e.assignedValue?pt(e.assignedValue):"";return r?`(${n} : ${M(e.type,t)}) ?= ${r}`:i?`(${n} : ${M(e.type,t)}) = ${i}`:`${n} : ${M(e.type,t)}`}function I_(e,t=new Set){var c;let n=e.parameters.map(f=>iu(f,t)).join(", "),r=e.forallParameters.length>0?`forall(${e.forallParameters.map(f=>iu(f,t)).join(", ")})`:"",i="";e.variadicParameter&&(e.variadicParameter.label==="..."?i="...":e.variadicParameter.isQuote?i=`...(quote(${e.variadicParameter.label}))`:e.variadicParameter.isCompileTimeOnly?i=`...(comptime(${e.variadicParameter.label}))`:i=`...(${e.variadicParameter.label})`);let o=M(e.return.type,t),a=o;e.return.isUnquote?e.return.label?a=`(unquote(${e.return.label}) : ${o})`:a=`unquote(${o})`:e.return.isCompileTimeOnly&&(e.return.label?a=`(comptime(${e.return.label}) : ${o})`:a=`comptime(${o})`);let s=e.implicitParameters.length>0?`using(${e.implicitParameters.map(f=>f.isEffectRowSpread?`...(${f.label})`:iu(f,t)).join(", ")})`:"",l=[r,n,s,i].filter(f=>!!f).join(", "),u=(c=e.SelfType)==null?void 0:c.typeName;return`${u?`(${u}) `:""}fn(${l}) -> ${a}`}function M(e,t=new Set){if(e.id&&t.has(e.id))return e.typeName||`<circular:${e.tag}>`;e.id&&t.add(e.id);try{return Lg(e,t)}finally{e.id&&t.delete(e.id)}}function Lg(e,t){if(!e)return"unknown";switch(e.tag){case"unit":return"unit";case"bool":return"bool";case"usize":return"usize";case"isize":return"isize";case"u8":return"u8";case"i8":return"i8";case"u16":return"u16";case"i16":return"i16";case"u32":return"u32";case"i32":return"i32";case"u64":return"u64";case"i64":return"i64";case"f32":return"f32";case"f64":return"f64";case"Type":return"level"in e&&typeof e.level=="number"&&e.level>0?`Type(${e.level})`:"Type";case"Array":return`[${M(e.childType,t)}; ${pt(e.length)}]`;case"Slice":return`[${M(e.childType,t)}]`;case"Tuple":return e.fields.length===0?"()":`(${e.fields.map(n=>jo(n,t)).join(", ")}${e.fields.length===1?",":""})`;case"Struct":{let n=e;return n.typeName?n.typeName:`${n.typeName?`(${n.typeName}) `:""}${n.isAtomicRc?"atomic ":""}${n.isReferenceSemantics?"object":n.isNewtype?"newtype":"struct"}(${n.fields.map(r=>jo(r,t)).join(", ")})`}case"Enum":{let n=e;if(n.typeName){let r=n.typeName;return n.requiredVariantNames??n.selectedVariantName?`${r} (${n.requiredVariantNames?`${n.requiredVariantNames.map(i=>`.${i}`).join(" | ")} required`:`.${n.selectedVariantName} selected`})`:r}return`${n.typeName?`(${n.typeName}) `:""}enum(${n.variants.map(r=>`${r.name}${r.fields?`(${r.fields.map(i=>jo(i,t)).join(", ")})`:""}`).join(", ")})`}case"Union":{let n=e;if(n.typeName)return n.typeName;let r=n.fields;return`${n.typeName?`(${n.typeName}) `:""}${n.typeName?"union":n.id}(${r.map(i=>jo(i,t)).join(", ")})`}case"Module":{let n=e,r;return n.typeName?r=n.typeName:r=`${n.typeName?`(${n.typeName}) `:""}module(${n.fields.map(i=>L_(i,t)).join(", ")})`,r}case"Trait":{let n=e;if(gn(n))return`Fn${I_(n.isFn.callType,t).slice(2)}`;if(Wn(n)){let i=[M(n.isFuture.outputType,t)];for(let o of n.isFuture.effects)o.isEffectRowSpread?i.push(`...(${o.label})`):i.push(M(o.type,t));return`Future(${i.join(", ")})`}let r;return n.typeName?r=n.typeName:r=`${n.typeName?`(${n.typeName}) `:""}trait(${n.fields.map(i=>L_(i,t)).join(", ")})`,n.receiverType&&(r=`(${M(n.receiverType,t)} <: ${r})`),r}case"Function":{let n=e;return n.typeName?n.typeName:I_(n,t)}case"SomeType":{let n=e;if(n.typeName)return n.typeName;if(n.functionApplication)return I(n.functionApplication);let r=[];if(n.requiredTraits&&n.requiredTraits.length>0)for(let i of n.requiredTraits)r.push(M(i.traitType,t));if(n.negativeTraits&&n.negativeTraits.length>0)for(let i of n.negativeTraits)r.push(`!(${M(i.traitType,t)})`);return r.length>0?`${n.name||"Impl"}(${r.join(", ")})`:n.name||"Impl()"}case"Ptr":return`*(${M(e.childType,t)})`;case"Iso":return`Iso(${M(e.childType,t)})`;case"Expr":return"Expr";case"ComptimeList":return`ComptimeList(${M(e.childType)})`;case"EffectsRow":{let n=e;return n.implicitParameters.length===0?"EffectsRow()":`EffectsRow(${n.implicitParameters.map(r=>`${r.label} : ${M(r.type,t)}`).join(", ")})`}case"Dyn":{let n=e;if(n.typeName)return n.typeName;let r=[];for(let{traitType:i}of n.requiredTraits)r.push(M(i,t));if(n.negativeTraits&&n.negativeTraits.length>0)for(let{traitType:i}of n.negativeTraits)r.push(`!(${M(i,t)})`);return`Dyn(${r.join(", ")})`}case"TypeApplication":{let n=e,r=M(n.constructor,t),i=n.args.map(o=>M(o,t)).join(", ");return`${r}(${i})`}default:return`${e.tag}`}}var A_=64;function Qr(){return A_}function Cs(){return A_/8}function Ig(e){let t=Yi(e.childType);if(t===null)return null;if(t===-1)return-1;let n=e.length;if(ht(n)){let r=BigInt(n.value);if(r<0)throw new Error("Array length cannot be negative");return Number(r)*t}return null}function Ag(e){let t=0,n=1;for(let r of e.fields){let i=Yi(r.type);if(i===null)return null;if(i===-1)return-1;let o=Xr(r.type);if(o===null)return null;let a=Math.ceil(i/8);t=Math.ceil(t/o)*o,t+=a,n=Math.max(n,o)}return t=Math.ceil(t/n)*n,t*8}function Sg(e){let t=0,n=1;for(let r of e.fields){let i=Yi(r.type);if(i===null)return null;if(i===-1)return-1;let o=Xr(r.type);if(o===null)return null;let a=Math.ceil(i/8);t=Math.ceil(t/o)*o,t+=a,n=Math.max(n,o)}return t=Math.ceil(t/n)*n,t*8}function Ng(e){let t=0,n=0;for(let m of e.variants){let h=0,y=1;if(m.fields)for(let v of m.fields){let T=Yi(v.type);if(T===null)return null;if(T===-1)return-1;let $=Xr(v.type);if($===null)return null;let C=Math.ceil(T/8);h=Math.ceil(h/$)*$,h+=C,y=Math.max(y,$),n=Math.max(n,$*8)}h=Math.ceil(h/y)*y;let g=h*8;t=Math.max(t,g)}let r=Math.ceil(Math.ceil(Math.log2(e.variants.length))/8)*8,i=32,o=Math.max(n,8),a=Math.max(i,o),s=r/8,l=o/8,u=(l-s%l)%l*8,_=r+u+t,c=_/8,f=a/8,p=(f-c%f)%f*8;return _+p}function Vg(e){let t=0;for(let n of e.fields){let r=Yi(n.type);if(r===null)return null;if(r===-1)return-1;t=Math.max(t,r)}return t}function Xr(e){if(z(e))return null;if(De(e)||St(e)||rn(e)||En(e)||on(e)||sn(e)||Xe(e)||ot(e)||$n(e))return 1;if(lr(e))return 1;if(ka(e)||wa(e))return Cs();if(jr(e)||Fa(e))return 1;if(La(e)||Ia(e))return 2;if(Aa(e)||Sa(e))return 4;if(Na(e)||Va(e))return 8;if(xa(e))return 4;if(Da(e))return 8;if(Je(e))return Xr(e.childType);if(ut(e)){let t=1;for(let n of e.fields){let r=Xr(n.type);if(r===null)return null;t=Math.max(t,r)}return t}else if(Ae(e)){if(e.isReferenceSemantics)return Cs();if(e.isNewtype)return Xr(e.fields[0].type);let t=1;for(let n of e.fields){let r=Xr(n.type);if(r===null)return null;t=Math.max(t,r)}return t}else if(Be(e)){let t=1;for(let n of e.variants)if(n.fields)for(let r of n.fields){let i=Xr(r.type);if(i===null)return null;t=Math.max(t,i)}return t}else if(Bt(e)){let t=1;for(let n of e.fields){let r=Xr(n.type);if(r===null)return null;t=Math.max(t,r)}return t}else{if(ne(e))return Cs();if(je(e))return Cs()}return null}function Yi(e){return z(e)?null:De(e)||St(e)||rn(e)||En(e)||on(e)||sn(e)||Xe(e)||ot(e)||$n(e)?0:lr(e)?8:ka(e)||wa(e)?Qr():jr(e)||Fa(e)?8:La(e)||Ia(e)?16:Aa(e)||Sa(e)?32:Na(e)||Va(e)?64:xa(e)?32:Da(e)?64:Je(e)?Ig(e):ut(e)?Ag(e):Ae(e)?e.isReferenceSemantics?Qr():e.isNewtype?Yi(e.fields[0].type):Sg(e):Be(e)?Ng(e):Bt(e)?Vg(e):ne(e)||je(e)?Qr():null}function Fi(e,t){if(bi(e))throw Qt([{token:t,errorMessage:`Cannot use 'void' type here.
|
|
49
49
|
Please consider use 'unit' type instead.
|
|
50
50
|
`}])}function Zr(e,t,n){if(!en(e)||co(e,n))return!1;if(t.has(e.id))return!0;t.add(e.id);try{for(let r of e.fields)if(qi(r.type,e,t,n))return!0;return!1}finally{t.delete(e.id)}}function qi(e,t,n,r){if(Ae(e)&&e.id===t.id)return!0;if(Ae(e)&&e.isReferenceSemantics)return Zr(e,new Set(n),r);if(Ae(e)&&!e.isReferenceSemantics){for(let i of e.fields)if(qi(i.type,t,n,r))return!0}if(Be(e)){for(let i of e.variants)if(i.fields){for(let o of i.fields)if(qi(o.type,t,n,r))return!0}}if(z(e))return co(e,r)?!1:e.resolvedConcreteType?qi(e.resolvedConcreteType,t,n,r):!0;if(Je(e)||$t(e))return qi(e.childType,t,n,r);if(ut(e)){for(let i of e.fields)if(qi(i.type,t,n,r))return!0}if(Bt(e)){for(let i of e.fields)if(qi(i.type,t,n,r))return!0}return st(e)?!0:(je(e),!1)}function _i(e,t){return t?e.id===t.id?!0:Je(e)||$t(e)||je(e)?_i(e.childType,t):ut(e)?e.fields.some(n=>_i(n.type,t)):Ae(e)?e.fields.some(n=>_i(n.type,t)):Bt(e)?e.fields.some(n=>_i(n.type,t)):Be(e)?e.variants.some(n=>{var r;return(r=n.fields)==null?void 0:r.some(i=>_i(i.type,t))}):ne(e)?_i(e.return.type,t):!1:!1}var su=require("crypto");function Xo(e){return"yo"+(0,su.createHash)("sha1").update(e).digest("hex").slice(0,8)}var bs=new Map;function mt(e){let t=bs.get(e);return t===void 0&&(t=0),bs.set(e,t+1),`${Xo(e)}_id_${t}`}function ks(e){bs.delete(e)}var N_=1;function V_(e){return`_${Xo(e)}_temp_`}function ws(e){return`${V_(e)}${N_++}`}function Ht(e,t){return t.startsWith(V_(e))}var au=new Map;function cn(e,t){let n="";for(let o=0;o<t.length;o++)if(xo(t[o])){let a=ms.indexOf(t[o]);n+=`${a}`}else n+=t[o];let r=Xo(e)+"_"+n,i=au.get(r);return i===void 0?i=0:i++,au.set(r,i),r+(i==0?"":`_${i}`)}function lu(e){return(0,su.createHash)("sha1").update(e).digest("hex").slice(0,10)}function uu(){bs.clear(),au.clear(),N_=1}function Hi(e){return{[e]:!0}}function zt(e,t){return(e==null?void 0:e[t])===!0}function Gt(e){return e!==void 0&&(e.return===!0||e.escape===!0||e.break===!0||e.continue===!0)}function Oa(e){let t={};for(let n of e)n.return&&(t.return=!0),n.escape&&(t.escape=!0),n.break&&(t.break=!0),n.continue&&(t.continue=!0);return t}function x_(e){let t=[];return e.return&&t.push("return"),e.escape&&t.push("escape"),e.break&&t.push("break"),e.continue&&t.push("continue"),t.join("+")}function _t(e){switch(e.tag){case"Atom":return{...e,$:void 0};case"FnCall":return{...e,func:_t(e.func),args:e.args.map(_t),$:void 0}}}function S(e){return(e==null?void 0:e.tag)==="FnCall"}function K(e){return(e==null?void 0:e.tag)==="Atom"}function ln(e,t){return e.tag==="Atom"&&(typeof t=="string"?e.token.value===t:t.includes(e.token.value))}function Qo(e){return e.tag==="Atom"&&e.token.type==="operator"}function E(e,t,n){if(e.tag!=="FnCall"||e.func.tag!=="Atom")return!1;let r=e.func.token.value;return e.tag==="FnCall"&&e.func.tag==="Atom"&&(typeof t=="string"?r===t:t.includes(r))&&(n===void 0||e.args.length===n)}function Ge(e,t,n){if(!S(e))throw d({token:e.token,errorMessage:`Expected function call, got atom:
|
|
51
51
|
${I(e)}`});if(!E(e,t))throw d({token:e.token,errorMessage:`Expected function call of ${Array.isArray(t)?t.map(r=>`"${r}"`).join(" or "):`"${t}"`}, got:
|
|
@@ -73,7 +73,7 @@ Consider using Dyn(...) for dynamic dispatch if different concrete types are nee
|
|
|
73
73
|
`:"")+(b?"Might be initialized here:":"Not initialized here:"),token:b??t[w].token})))}if(h.length===1){if(h[0]&&!s[c].consumedAtToken){let C={...s[c],consumedAtToken:h[0]};e=bt(e,s[c],C),s[c]=C}}else if(!s[c].consumedAtToken&&h.every(C=>C)){let C={...s[c],consumedAtToken:h[0]};e=bt(e,s[c],C),s[c]=C}else{let C=h.filter(b=>!!b),k=h.filter(b=>!b);if(C.length>0&&k.length>0)throw Qt(h.map((b,w)=>({errorMessage:(w===0?`Variable "${f}" is consumed in some cases but not in other cases:
|
|
74
74
|
`:"")+(b?"Consumed here:":"Not consumed here:"),token:b??t[w].token})))}if(!s[c].isOwningTheRcValue&&m.every(C=>C)){let C={...s[c],isOwningTheRcValue:!0,isOwningTheSameRcValueAs:void 0};e=bt(e,s[c],C),s[c]=C}else{let C=m.filter(b=>!!b),k=m.filter(b=>!b);if(C.length>0&&k.length>0)throw Qt(m.map((b,w)=>({errorMessage:(w===0?`Variable "${f}" might be holding the Rc value in some cases but not holding the Rc value in other cases:
|
|
75
75
|
`:"")+(b?"Might be owning the Rc value here:":"Might be not owning the Rc value here:"),token:b??t[w].token})))}let v=s[c].id,T=[];for(let C=1;C<u;C++){let w=r[C-1].frames[o].variables[c];T.push(w.id)}if(T.some(C=>C!==v)){let C=cn(e.modulePath,f),k={...s[c],id:C,value:void 0,isOwningTheSameRcValueAs:void 0};e=bt(e,s[c],k),s[c]=k}}}return e}function di(e,t){e.$=t.$,e.args=t.args,e.func=t.func,e.isInfix=t.isInfix,e.tag=t.tag,e.token=t.token}function Fs(e,t){S(e)||(e.tag=t.tag),di(e,t)}function kr(e,t,n=!1){var a,s,l;if((a=e.$)!=null&&a.value&&W((s=e.$)==null?void 0:s.value))return t;let r=(l=e.$)==null?void 0:l.variableName;if(!r)return t;let i=ae(t,r);if(i.length===0)throw Qt([{token:e.token,errorMessage:`Variable "${r}" is not defined.`}]);let o=i[i.length-1];if(o.consumedAtToken&&!n){let u=`use of moved value: \`${r}\``;throw Qt([{token:e.token,errorMessage:u},{token:o.consumedAtToken,errorMessage:"value moved here"}])}else t=bt(t,o,{...o,consumedAtToken:e.token});return t}function Bn(e,t){var r;if(!e.$||!e.$.variableName)return;if(e.$.value){let i=e.$.variableName,o=!1;if(i&&Ht(e.$.env.modulePath,i)&&it(e.$.type)){let a=ae(e.$.env,i);if(a.length>0){let s=a[a.length-1];s.isOwningTheRcValue&&!s.consumedAtToken&&(e.$.env=bt(e.$.env,s,{...s,consumedAtToken:e.token})),s.isOwningTheRcValue||(o=!0)}}if(!o)return}let n=e.$.variableName;if(!n)throw d({token:e.token,errorMessage:`Expression does not have a variable name to call ${F.___dup} on:
|
|
76
|
-
${I(e)}`});if(it(e.$.type)){if(Ht(e.$.env.modulePath,n)&&!(K(e)&&e.token.value!==n)){let a=ae(e.$.env,n);if(a.length>0){let s=a[a.length-1];if(s.isOwningTheRcValue){s.consumedAtToken||(e.$.env=bt(e.$.env,s,{...s,consumedAtToken:e.token}));return}}}let i=Dt(`${F.___dup[0]}(${n})`),o=O({expr:i,env:e.$.env,context:{...t,expectedType:void 0}});if((r=o.$)!=null&&r.variableName){let a=ae(o.$.env,o.$.variableName);if(a.length>0){let s=a[a.length-1];s.consumedAtToken||(o.$.env=bt(o.$.env,s,{...s,consumedAtToken:o.token}))}}e.$.deferredDupExpressions=[o],e.$.env=o.$.env}}function po(e,t){var o;let n=(o=e.$)==null?void 0:o.variableName;if(!n)return;let r=ae(t,n);if(r.length===0)throw Qt([{token:e.token,errorMessage:`Variable "${n}" is not defined.`}]);let i=r[r.length-1];if(i.consumedAtToken){let a=`use of moved value: \`${n}\``;throw Qt([{token:e.token,errorMessage:a},{token:i.consumedAtToken,errorMessage:"value moved here"}])}}var Tn="__yo_self";function mo(e,t,n){if(Ae(e)){if(e.isReferenceSemantics)return!1;if(n.has(e.id))return!0;n.add(e.id);let r=e.fields.every(i=>mo(i.type,t,n));return n.delete(e.id),r}if(ut(e)){if(n.has(e.id))return!0;n.add(e.id);let r=e.fields.every(i=>mo(i.type,t,n));return n.delete(e.id),r}if(Be(e)){if(n.has(e.id))return!0;n.add(e.id);let r=e.variants.every(i=>(i.fields??[]).every(o=>mo(o.type,t,n)));return n.delete(e.id),r}return Je(e)||$t(e)||je(e)?mo(e.childType,t,n):Jr(e,t)}function yo(e,t,n){if(Ae(e)){if(e.isReferenceSemantics||n.has(e.id))return!0;n.add(e.id);let r=e.fields.every(i=>yo(i.type,t,n));return n.delete(e.id),r}if(ut(e)){if(n.has(e.id))return!0;n.add(e.id);let r=e.fields.every(i=>yo(i.type,t,n));return n.delete(e.id),r}if(Be(e)){if(n.has(e.id))return!0;n.add(e.id);let r=e.variants.every(i=>(i.fields??[]).every(o=>yo(o.type,t,n)));return n.delete(e.id),r}return Je(e)||$t(e)||je(e)?yo(e.childType,t,n):Li(e,t)}function D_(e,t,n,r){let i=Dt(e),o=O({expr:i,env:n,context:{...r,SelfType:t,forceCompileTimeBindings:!1}});if(!o.$)throw new Error(`Failed to evaluate auto-generated expression: ${I(i)}`);return{expr:o,env:o.$.env}}function ea({label:e,functionSignature:t,SelfType:n,env:r,context:i}){let{expr:o,env:a}=D_(t,n,r,i);if(S(o)&&o.$&&o.$.value&&W(o.$.value)&&ne(o.$.value.value)){let s=o.$.value.value,l={label:e,type:s,assignedValue:void 0,exprs:{expr:o,labelExpr:o.args[0],typeExpr:void 0,defaultValueExpr:void 0,assignedValueExpr:void 0}};if(n.trait){let u=n.trait.fields.findIndex(_=>_.label===e);u>=0?n.trait.fields[u]=l:n.trait.fields.push(l)}}return a}function zr({label:e,functionCode:t,SelfType:n,env:r,context:i}){let{expr:o,env:a}=D_(t,n,r,i);if(S(o)&&o.$&&o.$.value&&
|
|
76
|
+
${I(e)}`});if(it(e.$.type)){if(Ht(e.$.env.modulePath,n)&&!(K(e)&&e.token.value!==n)){let a=ae(e.$.env,n);if(a.length>0){let s=a[a.length-1];if(s.isOwningTheRcValue){s.consumedAtToken||(e.$.env=bt(e.$.env,s,{...s,consumedAtToken:e.token}));return}}}let i=Dt(`${F.___dup[0]}(${n})`),o=O({expr:i,env:e.$.env,context:{...t,expectedType:void 0}});if((r=o.$)!=null&&r.variableName){let a=ae(o.$.env,o.$.variableName);if(a.length>0){let s=a[a.length-1];s.consumedAtToken||(o.$.env=bt(o.$.env,s,{...s,consumedAtToken:o.token}))}}e.$.deferredDupExpressions=[o],e.$.env=o.$.env}}function po(e,t){var o;let n=(o=e.$)==null?void 0:o.variableName;if(!n)return;let r=ae(t,n);if(r.length===0)throw Qt([{token:e.token,errorMessage:`Variable "${n}" is not defined.`}]);let i=r[r.length-1];if(i.consumedAtToken){let a=`use of moved value: \`${n}\``;throw Qt([{token:e.token,errorMessage:a},{token:i.consumedAtToken,errorMessage:"value moved here"}])}}var Tn="__yo_self";function mo(e,t,n){if(Ae(e)){if(e.isReferenceSemantics)return!1;if(n.has(e.id))return!0;n.add(e.id);let r=e.fields.every(i=>mo(i.type,t,n));return n.delete(e.id),r}if(ut(e)){if(n.has(e.id))return!0;n.add(e.id);let r=e.fields.every(i=>mo(i.type,t,n));return n.delete(e.id),r}if(Be(e)){if(n.has(e.id))return!0;n.add(e.id);let r=e.variants.every(i=>(i.fields??[]).every(o=>mo(o.type,t,n)));return n.delete(e.id),r}return Je(e)||$t(e)||je(e)?mo(e.childType,t,n):Jr(e,t)}function yo(e,t,n){if(Ae(e)){if(e.isReferenceSemantics||n.has(e.id))return!0;n.add(e.id);let r=e.fields.every(i=>yo(i.type,t,n));return n.delete(e.id),r}if(ut(e)){if(n.has(e.id))return!0;n.add(e.id);let r=e.fields.every(i=>yo(i.type,t,n));return n.delete(e.id),r}if(Be(e)){if(n.has(e.id))return!0;n.add(e.id);let r=e.variants.every(i=>(i.fields??[]).every(o=>yo(o.type,t,n)));return n.delete(e.id),r}return Je(e)||$t(e)||je(e)?yo(e.childType,t,n):Li(e,t)}function D_(e,t,n,r){let i=Dt(e),o=O({expr:i,env:n,context:{...r,SelfType:t,forceCompileTimeBindings:!1}});if(!o.$)throw new Error(`Failed to evaluate auto-generated expression: ${I(i)}`);return{expr:o,env:o.$.env}}function ea({label:e,functionSignature:t,SelfType:n,env:r,context:i}){let{expr:o,env:a}=D_(t,n,r,i);if(S(o)&&o.$&&o.$.value&&W(o.$.value)&&ne(o.$.value.value)){let s=o.$.value.value,l={label:e,type:s,assignedValue:void 0,exprs:{expr:o,labelExpr:o.args[0],typeExpr:void 0,defaultValueExpr:void 0,assignedValueExpr:void 0}};if(n.trait){let u=n.trait.fields.findIndex(_=>_.label===e);u>=0?n.trait.fields[u]=l:n.trait.fields.push(l)}}return a}function zr({label:e,functionCode:t,SelfType:n,env:r,context:i}){let{expr:o,env:a}=D_(t,n,r,i);if(S(o)&&o.$&&o.$.value&&ge(o.$.value)){o.$.value.funcId+=e,o.$.value.funcName=e;let s={label:e,type:o.$.type,assignedValue:o.$.value,exprs:{expr:o,labelExpr:o.args[0],typeExpr:void 0,defaultValueExpr:void 0,assignedValueExpr:o}};if(n.trait){let l=n.trait.fields.findIndex(u=>u.label===e);l>=0?n.trait.fields[l]=s:n.trait.fields.push(s)}}return a}var _u=`(fn(${Tn} : Self) -> unit)`,Ls=`(fn(${Tn} : Self) -> unit)`,Is=`(fn(${Tn} : Self) -> Self)`;function xg(e){return e.replace(/[^a-zA-Z0-9_]/g,t=>`_u${t.charCodeAt(0)}_`)}function Dg(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function cu(e,t){if(e.length===0)return{destructuringExpr:"",callsExpr:""};let n=[],r=[];for(let i of e)if(Dg(i)){let o=mt("field_"+i);n.push(`${i} : ${o}`),r.push(`(${t})(${o});`)}else{let o=mt("field_"+xg(i));n.push(`(${i}) : ${o}`),r.push(`(${t})(${o});`)}return{destructuringExpr:`{ ${n.join(", ")} } := ${Tn};`,callsExpr:r.join(`
|
|
77
77
|
`)}}function Mg(e){let t=_u;if(!rr(e))return{signature:t,code:`(${t} ())`};let n=e.fields.filter(a=>it(a.type)).map(a=>a.label);if(!n.length)return{signature:t,code:`(${t} ())`};let{destructuringExpr:r,callsExpr:i}=cu(n,F.___drop[0]),o=`
|
|
78
78
|
${r}
|
|
79
79
|
${i}
|
|
@@ -149,7 +149,7 @@ Given: "${M(t.type)}"`)}}}return{expectedEnv:e.env,givenEnv:t.env}}function mu(e
|
|
|
149
149
|
`)}function cc(e){let t={moduleDoc:null,declarations:[]},n=[],r=null,i="",o=0;for(;o<e.length;){let a=e[o];if(uh(a))if(r===null&&(r=a.position,i=a.modulePath),a.type==="inner_doc_line_comment"){for(n.push(hu(a.value)),o++;o<e.length&&e[o].type==="whitespace";){if(e[o].value.includes(`
|
|
150
150
|
`)){let s=o+1;for(;s<e.length&&e[s].type==="whitespace";)s++;if(s<e.length&&e[s].type==="inner_doc_line_comment"){o=s;break}else break}o++}continue}else{n.push(uc(a.value)),o++;continue}if(a.type==="doc_line_comment"){let s=[],l=a.position,u=a.modulePath;for(s.push(hu(a.value)),o++;o<e.length;){let p=o;for(;p<e.length&&e[p].type==="whitespace";)p++;if(p<e.length&&e[p].type==="doc_line_comment")s.push(hu(e[p].value)),o=p+1;else break}let _={content:s.join(`
|
|
151
151
|
`),inner:!1,position:l,modulePath:u},{name:c,position:f}=_c(e,o);t.declarations.push({comment:_,declarationName:c,declarationPosition:f});continue}if(a.type==="doc_block_comment"){let s={content:uc(a.value),inner:!1,position:a.position,modulePath:a.modulePath};o++;let{name:l,position:u}=_c(e,o);t.declarations.push({comment:s,declarationName:l,declarationPosition:u});continue}o++}return n.length>0&&r!==null&&(t.moduleDoc={content:n.join(`
|
|
152
|
-
`),inner:!0,position:r,modulePath:i}),t}function _c(e,t){let n=t;for(;n<e.length;){let r=e[n];if(_h(r)||lh(r)){n++;continue}if(r.type==="identifier")return{name:r.value,position:r.position};if(r.type==="("){n++;continue}return{name:"",position:null}}return{name:"",position:null}}function cl(e){var t;return E(e,["->","=>"])?!!(((t=e.$)==null?void 0:t.isAnonymousFunctionDefinition)===!0||S(e)&&S(e.func)&&(E(e.func,P.fn)||E(e.func,P.unsafe_fn)||E(e.func,P.Fn))||!e.$):!1}function fl(e,t){if(!S(e))return!1;if(t(e.func))return!0;for(let n of e.args)if(S(n)&&E(n,"=>")){for(let r of n.args)if(t(r))return!0}else if(t(n))return!0;return!1}function ei(e){var t,n,r;if(K(e))return ln(e,P.escape);if(S(e)){if((t=e.$)!=null&&t.macroExpansion)return ei(e.$.macroExpansion);if(E(e,P.cond)||E(e,P.match))return fl(e,ei);if(cl(e)||S(e.func)&&((n=e.func.$)==null?void 0:n.value)!==void 0&&W(e.func.$.value)&&ne(e.func.$.value.value)||S(e.func)&&((r=e.func.$)==null?void 0:r.value)!==void 0&&W(e.func.$.value)&&zn(e.func.$.value.value))return!1;if(ei(e.func))return!0;for(let i of e.args)if(ei(i))return!0}return!1}function na(e){var t,n,r;if(K(e))return ln(e,P.return)||ln(e,P.escape);if(S(e)){if(E(e,P.return)||E(e,P.escape))return!0;if((t=e.$)!=null&&t.macroExpansion)return na(e.$.macroExpansion);if(E(e,P.cond)||E(e,P.match))return fl(e,na);if(cl(e)||S(e.func)&&((n=e.func.$)==null?void 0:n.value)!==void 0&&W(e.func.$.value)&&ne(e.func.$.value.value)||S(e.func)&&((r=e.func.$)==null?void 0:r.value)!==void 0&&W(e.func.$.value)&&zn(e.func.$.value.value))return!1;if(na(e.func))return!0;for(let i of e.args)if(na(i))return!0}return!1}function er(e){var t,n,r,i,o,a,s;if(S(e)){if(((n=(t=e.func.$)==null?void 0:t.type)==null?void 0:n.ioBuiltin)==="io_await")return!0;if((r=e.$)!=null&&r.macroExpansion)return er(e.$.macroExpansion);if(E(e,P.cond)||E(e,P.match))return fl(e,er);if(((o=(i=e.func.$)==null?void 0:i.type)==null?void 0:o.ioBuiltin)==="io_async"||cl(e)||W((a=e.func.$)==null?void 0:a.value)&&ne(e.func.$.value.value)||S(e.func)&&((s=e.func.$)==null?void 0:s.value)!==void 0&&W(e.func.$.value)&&zn(e.func.$.value.value))return!1;if(er(e.func))return!0;for(let l of e.args)if(er(l))return!0}return!1}function ra(e){var t,n,r;if(K(e))return ln(e,P.break)||ln(e,P.return)||ln(e,P.escape);if(S(e)){if(E(e,P.return)||E(e,P.escape))return!0;if((t=e.$)!=null&&t.macroExpansion)return ra(e.$.macroExpansion);if(E(e,P.cond)||E(e,P.match))return fl(e,ra);if(cl(e)||S(e.func)&&((n=e.func.$)==null?void 0:n.value)!==void 0&&W(e.func.$.value)&&ne(e.func.$.value.value)||S(e.func)&&((r=e.func.$)==null?void 0:r.value)!==void 0&&W(e.func.$.value)&&zn(e.func.$.value.value))return!1;if(ra(e.func))return!0;for(let i of e.args)if(ra(i))return!0}return!1}var ue={tag:"Unit",type:xr()};function Ba(e){if(e&&e.tag==="FnCall"&&E(e,":=")){let t=e.args[0];if(t&&t.tag==="Atom"&&t.token.type==="identifier"&&t.$){let n=t.token.value,r=ae(t.$.env,n);if(r.length>0)return r[r.length-1].id}}}function pl(e,t){var a;let n=[],r=new Map,i=new Map,o=new Map;if(yi(e,n,r,i,o,t),(a=e.$)!=null&&a.deferredDropExpressions)for(let s of e.$.deferredDropExpressions)yi(s,n,r,i,o,t);return n.length===0&&r.clear(),{suspensionPoints:n,capturedVariables:Array.from(r.values()),hasSuspensions:n.length>0,variableIdRemapping:o}}function yi(e,t,n,r,i,o,a){var s,l;switch(e.tag){case"Atom":if(e.$&&e.token.type==="identifier"){let u=e.token.value,_=e.$.type,c=ae(e.$.env,u);if(c.length>0){let f=c[c.length-1];if(f&&!n.has(f.id)&&!f.isCompileTimeOnly){let p=`${f.name}:${f.frameLevel}`,m=r.get(p);if(m&&m!==f.id)i.set(f.id,m);else if(f.isOwningTheSameRcValueAs){let h=f.isOwningTheSameRcValueAs;if(!n.has(h.id)){let y={id:h.id,name:h.name,type:h.type,isOwningTheSameRcValueAs:void 0};n.set(h.id,y);let g=`${h.name}:${h.frameLevel}`;r.has(g)||r.set(g,h.id)}}else n.set(f.id,{id:f.id,name:u,type:_,isOwningTheSameRcValueAs:void 0}),r.has(p)||r.set(p,f.id)}}}break;case"FnCall":{if(E(e,P.while)){let u=t.length;yi(e.func,t,n,r,i,o,e);for(let c of e.args)yi(c,t,n,r,i,o,e);let _=t.length;if(_>u)for(let c=u;c<_;c++)t[c].isInsideWhile=!0,t[c].whileNestingDepth=(t[c].whileNestingDepth??0)+1,t[c].enclosingWhileExpr||(t[c].enclosingWhileExpr=e);break}if(E(e,P.cond)){fc(e,t,n,r,i,o);break}if(E(e,P.match)){fc(e,t,n,r,i,o);break}if(o.detect(e,a,t),o.shouldSkipBody(e)){if((s=e.$)!=null&&s.deferredDupExpressions)for(let u of e.$.deferredDupExpressions)yi(u,t,n,r,i,o,e);break}yi(e.func,t,n,r,i,o,e);for(let u of e.args)yi(u,t,n,r,i,o,e);if((l=e.$)!=null&&l.deferredDropExpressions)for(let u of e.$.deferredDropExpressions)yi(u,t,n,r,i,o,e);break}}}function fc(e,t,n,r,i,o){if(e.tag!=="FnCall")return;let a=t.length;yi(e.func,t,n,r,i,o,e);let s=new Map(r),l=[];for(let _ of e.args){let c=t.length;yi(_,t,n,r,i,o,e),l.push(t.slice(c))}r.clear();for(let[_,c]of s)r.set(_,c);let u=Math.max(...l.map(_=>_.length),0);if(u>0){t.splice(a);let _=a;for(let c=0;c<u;c++){let f;for(let p of l)if(c<p.length){f=p[c];break}f&&(f.index=t.length,f.isInsideCond=!0,c===0&&(f.needsOwnCondBranchField=!0),c>0&&(f.condBranchSourceIndex=_),t.push(f))}}}function pc(e){let n=pl(e,{detect(i,o,a){var s;if(i.tag==="FnCall"&&_r(i)){let l=i.args[0];if(!l)return;let u=(s=l.$)==null?void 0:s.type;if(u&&at(u)){let _=Ln(u);if(!_)return;let c=_.isFuture.outputType,f;if(l.tag==="Atom"&&l.token.type==="identifier"&&l.$){let m=l.token.value,h=ae(l.$.env,m);if(h.length>0){let y=h[h.length-1];y.isOwningTheSameRcValueAs?f=y.isOwningTheSameRcValueAs.id:f=y.id}}let p=Ba(o);a.push({index:a.length,expr:i,resultType:c,futureType:_,targetVariableId:p,futureVariableId:f})}}},shouldSkipBody(i){return An(i)}}),r=n.capturedVariables.map(i=>({id:i.id,name:i.name,type:i.type,kind:"local",isOwningTheSameRcValueAs:void 0}));return{awaitPoints:n.suspensionPoints,capturedVariables:r,hasAwaits:n.hasSuspensions,variableIdRemapping:n.variableIdRemapping}}function An(e){var t,n;return e.tag!=="FnCall"?!1:((n=(t=e.func.$)==null?void 0:t.type)==null?void 0:n.ioBuiltin)==="io_async"}function _r(e){var t,n;return e.tag!=="FnCall"?!1:((n=(t=e.func.$)==null?void 0:t.type)==null?void 0:n.ioBuiltin)==="io_await"}function dc(e){var t,n;return e.tag!=="FnCall"?!1:((n=(t=e.func.$)==null?void 0:t.type)==null?void 0:n.ioBuiltin)==="io_state"}function dl(e){var t,n;return e.tag!=="FnCall"?!1:((n=(t=e.func.$)==null?void 0:t.type)==null?void 0:n.ioBuiltin)==="io_spawn"}function mc(e){var t,n;return e.tag!=="FnCall"?!1:((n=(t=e.func.$)==null?void 0:t.type)==null?void 0:n.ioBuiltin)==="join_handle_await"}function Nt(e){return K(e)&&e.token.type==="identifier"||e.token.type==="operator"}function Ga(e,t,n){var a;if(!((a=e.$)!=null&&a.variableName))return;let r=ae(t,e.$.variableName);if(!r.length)return;let i=r[r.length-1],o=new Set;for(;i&&i.isOwningTheSameRcValueAs;){if(o.has(i.id))return;o.add(i.id),i=i.isOwningTheSameRcValueAs}if(i&&i.isOwningTheRcValue)return i}function Ki(e){var r,i;let t=(r=e.$)==null?void 0:r.env;if(!t)return;let n;if((i=e.$)!=null&&i.pathCollection)for(let o of e.$.pathCollection)o.length>0&&typeof o[0]=="string"&&(n=o[0]);else K(e)&&(n=e.token.value);if(n){let o=ae(t,n),a=o[o.length-1];if(a!=null&&a.isImplicit)throw d({token:e.token,errorMessage:`Cannot use implicit variable "${a.name}" in assignment. Implicit variables must be passed via using() parameters.`})}}var ml=!0;function vu({variablesToDrop:e,env:t,context:n}){let r=[],i=t;for(let o of e){let a=Dt(`${F.___drop[0]}(${o.name})`),s=O({expr:a,env:i,context:{...n,expectedType:{env:i,type:ue.type}}});r.push(s),s.$&&s.$.env&&(i=s.$.env)}return{deferredDropExpressions:r.length>0?r:void 0,env:i}}function Wa(e,t,n){var s,l;if(S(e)&&An(e))return;if((s=e.$)!=null&&s.deferredDupExpressions)for(let u of e.$.deferredDupExpressions)Wa(u,t,n);if(S(e)&&S(e.func)&&E(e.func,".",2)&&K(e.func.args[0])&&K(e.func.args[1])&&e.func.args[1].token.value===F.___dup[0]&&e.args.length===0&&((l=e.$)!=null&&l.env)){let u=e.func.args[0].token.value,_=ae(e.$.env,u);if(_.length>0){let c=_[_.length-1];t.has(c.id)||t.set(c.id,[]),t.get(c.id).push(e)}return}if(S(e)&&E(e,P.while))return;function i(u){var _,c;if(Gt((_=u.$)==null?void 0:_.controlFlow))return!0;if(S(u)&&E(u,P.begin)){let f=u.args[u.args.length-1];if(Gt((c=f==null?void 0:f.$)==null?void 0:c.controlFlow)||S(f)&&E(f,P.return))return!0}return!!(S(u)&&E(u,P.return))}function o(u){if(S(u)&&E(u,P.tuple,0))return!0;if(S(u)&&E(u,P.begin)){if(u.args.length===0)return!0;if(u.args.length===1){let _=u.args[0];if(S(_)&&E(_,P.tuple,0))return!0}}return!1}function a(u,_){let c=[],f=[],p=[];for(let h=_;h<u.args.length;h++){let y=u.args[h];if(S(y)&&E(y,"=>",2)){let g=y.args[1],v=yc(g);c.push(v),f.push(i(g)),p.push(o(g))}}let m=new Set;for(let h of c){for(let y of h.dupCalls.keys())m.add(y);for(let y of h.varsWithPartialBranchDups)n.add(y)}if(c.length>0)for(let h of m){let y=[],g=[];for(let v=0;v<c.length;v++){let T=c[v],$=T.dupCalls.has(h),C=f[v];if($){let k=T.dupCalls.get(h);C?y.push(...k):g.push(...k)}}for(let v of y)t.has(h)||t.set(h,[]),v.__isEarlyReturnDup=!0,t.get(h).push(v);if(g.length>0){let v=0,T=0;for(let $=0;$<c.length;$++)f[$]||(v++,c[$].dupCalls.has(h)&&T++);if(T===v){t.has(h)||t.set(h,[]);for(let $ of g)t.get(h).push($)}else n.add(h)}}}if(S(e)&&E(e,P.cond)){a(e,0);return}if(S(e)&&E(e,P.match)){e.args[0]&&Wa(e.args[0],t,n),a(e,1);return}if(S(e)){Wa(e.func,t,n);for(let u of e.args)Wa(u,t,n)}}function yc(e){let t=new Map,n=new Set;return Wa(e,t,n),{dupCalls:t,varsWithPartialBranchDups:n}}function yl(e){return S(e)&&E(e,P.tuple,0)}function Tu(e,t){var n;if((n=e.$)!=null&&n.deferredDupExpressions&&(e.$.deferredDupExpressions=e.$.deferredDupExpressions.filter(r=>!t.has(r)),e.$.deferredDupExpressions.length===0&&(e.$.deferredDupExpressions=void 0)),S(e)){Tu(e.func,t);for(let r of e.args)Tu(r,t)}}function ch(e,t){var i,o,a,s,l,u;let n=new Set,r=e.args;for(let _=0;_<r.length;_++){let c=r[_];if(!S(c)||!E(c,P.while))continue;let f=c.args[c.args.length-1];if(!(!f||!S(f)||!E(f,P.begin)))for(let p of f.args){if(!S(p)||!E(p,P.match))continue;let m=p.args[0];if(!m||!K(m))continue;let h=m.token.value,y,g,v;for(let L=1;L<p.args.length;L++){let N=p.args[L];if(!S(N)||!E(N,"=>",2))continue;let x=N.args[1];if(!(!S(x)||!E(x,P.begin))){for(let V of x.args)if(S(V)&&E(V,"=",2)){let U=V.args[0];if(K(U)&&U.token.value===h){y=V.args[1],g=V,v=x;break}}if(y)break}}if(!y||!g||!v||!((i=y.$)!=null&&i.deferredDupExpressions)||y.$.deferredDupExpressions.length===0)continue;let T;for(let L=0;L<_;L++){let N=r[L];if(S(N)&&E(N,"=",2)){let x=N.args[0];if(K(x)&&x.token.value===h){T=N.args[1];break}if(S(x)&&x.args.length>0&&K(x.args[0])&&x.args[0].token.value===h){T=N.args[1];break}}}if(!T)continue;let $=(o=T.$)==null?void 0:o.variableName;if(!$||!((a=T.$)!=null&&a.env))continue;let C=ae(T.$.env,$);if(C.length===0||C[C.length-1].isOwningTheRcValue||!((s=T.$)!=null&&s.deferredDupExpressions)||T.$.deferredDupExpressions.length===0)continue;let b=!1;for(let L=_+1;L<r.length;L++)if(Eu(r[L],h)){b=!0;break}if(b)continue;T.$.deferredDupExpressions=void 0,y.$.deferredDupExpressions=void 0;let w=(l=g.$)==null?void 0:l.variableName;w&&((u=v.$)!=null&&u.deferredDropExpressions)&&(v.$.deferredDropExpressions=v.$.deferredDropExpressions.filter(L=>fh(L)!==w),v.$.deferredDropExpressions.length===0&&(v.$.deferredDropExpressions=void 0)),g.$&&(g.$.variableName=void 0);let A=ae(t,h);if(A.length>0){let L=A[A.length-1];t=bt(t,L,{...L,consumedAtToken:L.token})}n.add(h)}}return{optimizedVarNames:n,env:t}}function fh(e){if(S(e)&&e.args.length===0&&S(e.func)&&E(e.func,".",2)&&K(e.func.args[1])&&e.func.args[1].token.value===F.___drop[0]&&K(e.func.args[0]))return e.func.args[0].token.value;if(S(e)&&E(e,F.___drop)&&e.args.length>=1&&K(e.args[0]))return e.args[0].token.value}function Eu(e,t){if(K(e)&&e.token.value===t)return!0;if(S(e)){if(Eu(e.func,t))return!0;for(let n of e.args)if(Eu(n,t))return!0}return!1}function un({expr:e,env:t,context:n,variablesToAdd:r=[],isEvaluatingFunctionBodyBeginBlock:i=!1}){var k,b,w,A,L,N,x,V,U;if(S(e)&&E(e,"_")&&!E(e,P.begin)){let R=e;R.args.some(H=>S(H)&&E(H,":"))||(R.func={...R.func,token:{...R.func.token,value:P.begin[0]}})}if(!S(e)||!E(e,P.begin)){let R={tag:"FnCall",func:{tag:"Atom",token:{...e.token,value:P.begin[0]}},args:[_t(e)],token:{...e.token,value:P.begin[0]}};di(e,R),e=e}let o=e.args,a=n.expectedType;if(o.length===0)return e.$={env:t,type:ue.type,value:ue,pathCollection:[]},e;t=lt(t,void 0,!0);for(let R=0;R<r.length;R++){let D=r[R],{env:H}=xe({env:t,variable:D});t=H}let s=o[o.length-1],l,u=!1;for(let R=0;R<o.length;R++){let D=o[R];if(K(D)&&ln(D,P.return)||S(D)&&E(D,P.return)){if(R!==o.length-1&&!(R===o.length-2&&yl(o[o.length-1])))throw d({token:D.token,errorMessage:'The "return" keyword can only be used as the last expression.'});if(S(D)&&Ge(D,P.return,1),!n.isEvaluatingFunctionBodyOrAsyncBlock)throw d({token:D.token,errorMessage:'The "return" keyword can only be used inside a function body or async block.'});if(l=D,K(D)){D.$={env:t,type:ue.type,value:ue,pathCollection:[],controlFlow:Hi("return")},s=D;break}else{Ge(D,P.return,1);let H=D.args[0],B=O({expr:H,env:t,context:{...n,expectedType:n.isEvaluatingFunctionBodyOrAsyncBlock.kind==="function-body"?{type:n.isEvaluatingFunctionBodyOrAsyncBlock.type.return.type,env:t}:n.expectedType}});if(!B.$)throw d({token:H.token,errorMessage:`Return expression is not evaluated correctly:
|
|
152
|
+
`),inner:!0,position:r,modulePath:i}),t}function _c(e,t){let n=t;for(;n<e.length;){let r=e[n];if(_h(r)||lh(r)){n++;continue}if(r.type==="identifier")return{name:r.value,position:r.position};if(r.type==="("){n++;continue}return{name:"",position:null}}return{name:"",position:null}}function cl(e){var t,n;return E(e,["->","=>"])?!!(((t=e.$)==null?void 0:t.isAnonymousFunctionDefinition)===!0||((n=e.$)==null?void 0:n.value)!==void 0&&ge(e.$.value)||S(e)&&S(e.func)&&(E(e.func,P.fn)||E(e.func,P.unsafe_fn)||E(e.func,P.Fn))||!e.$):!1}function fl(e,t){if(!S(e))return!1;if(t(e.func))return!0;for(let n of e.args)if(S(n)&&E(n,"=>")){for(let r of n.args)if(t(r))return!0}else if(t(n))return!0;return!1}function ei(e){var t,n,r;if(K(e))return ln(e,P.escape);if(S(e)){if((t=e.$)!=null&&t.macroExpansion)return ei(e.$.macroExpansion);if(E(e,P.cond)||E(e,P.match))return fl(e,ei);if(cl(e)||S(e.func)&&((n=e.func.$)==null?void 0:n.value)!==void 0&&W(e.func.$.value)&&ne(e.func.$.value.value)||S(e.func)&&((r=e.func.$)==null?void 0:r.value)!==void 0&&W(e.func.$.value)&&zn(e.func.$.value.value))return!1;if(ei(e.func))return!0;for(let i of e.args)if(ei(i))return!0}return!1}function na(e){var t,n,r;if(K(e))return ln(e,P.return)||ln(e,P.escape);if(S(e)){if(E(e,P.return)||E(e,P.escape))return!0;if((t=e.$)!=null&&t.macroExpansion)return na(e.$.macroExpansion);if(E(e,P.cond)||E(e,P.match))return fl(e,na);if(cl(e)||S(e.func)&&((n=e.func.$)==null?void 0:n.value)!==void 0&&W(e.func.$.value)&&ne(e.func.$.value.value)||S(e.func)&&((r=e.func.$)==null?void 0:r.value)!==void 0&&W(e.func.$.value)&&zn(e.func.$.value.value))return!1;if(na(e.func))return!0;for(let i of e.args)if(na(i))return!0}return!1}function er(e){var t,n,r,i,o,a,s;if(S(e)){if(((n=(t=e.func.$)==null?void 0:t.type)==null?void 0:n.ioBuiltin)==="io_await")return!0;if((r=e.$)!=null&&r.macroExpansion)return er(e.$.macroExpansion);if(E(e,P.cond)||E(e,P.match))return fl(e,er);if(((o=(i=e.func.$)==null?void 0:i.type)==null?void 0:o.ioBuiltin)==="io_async"||cl(e)||W((a=e.func.$)==null?void 0:a.value)&&ne(e.func.$.value.value)||S(e.func)&&((s=e.func.$)==null?void 0:s.value)!==void 0&&W(e.func.$.value)&&zn(e.func.$.value.value))return!1;if(er(e.func))return!0;for(let l of e.args)if(er(l))return!0}return!1}function ra(e){var t,n,r;if(K(e))return ln(e,P.break)||ln(e,P.return)||ln(e,P.escape);if(S(e)){if(E(e,P.return)||E(e,P.escape))return!0;if((t=e.$)!=null&&t.macroExpansion)return ra(e.$.macroExpansion);if(E(e,P.cond)||E(e,P.match))return fl(e,ra);if(cl(e)||S(e.func)&&((n=e.func.$)==null?void 0:n.value)!==void 0&&W(e.func.$.value)&&ne(e.func.$.value.value)||S(e.func)&&((r=e.func.$)==null?void 0:r.value)!==void 0&&W(e.func.$.value)&&zn(e.func.$.value.value))return!1;if(ra(e.func))return!0;for(let i of e.args)if(ra(i))return!0}return!1}var ue={tag:"Unit",type:xr()};function Ba(e){if(e&&e.tag==="FnCall"&&E(e,":=")){let t=e.args[0];if(t&&t.tag==="Atom"&&t.token.type==="identifier"&&t.$){let n=t.token.value,r=ae(t.$.env,n);if(r.length>0)return r[r.length-1].id}}}function pl(e,t){var a;let n=[],r=new Map,i=new Map,o=new Map;if(yi(e,n,r,i,o,t),(a=e.$)!=null&&a.deferredDropExpressions)for(let s of e.$.deferredDropExpressions)yi(s,n,r,i,o,t);return n.length===0&&r.clear(),{suspensionPoints:n,capturedVariables:Array.from(r.values()),hasSuspensions:n.length>0,variableIdRemapping:o}}function yi(e,t,n,r,i,o,a){var s,l;switch(e.tag){case"Atom":if(e.$&&e.token.type==="identifier"){let u=e.token.value,_=e.$.type,c=ae(e.$.env,u);if(c.length>0){let f=c[c.length-1];if(f&&!n.has(f.id)&&!f.isCompileTimeOnly){let p=`${f.name}:${f.frameLevel}`,m=r.get(p);if(m&&m!==f.id)i.set(f.id,m);else if(f.isOwningTheSameRcValueAs){let h=f.isOwningTheSameRcValueAs;if(!n.has(h.id)){let y={id:h.id,name:h.name,type:h.type,isOwningTheSameRcValueAs:void 0};n.set(h.id,y);let g=`${h.name}:${h.frameLevel}`;r.has(g)||r.set(g,h.id)}}else n.set(f.id,{id:f.id,name:u,type:_,isOwningTheSameRcValueAs:void 0}),r.has(p)||r.set(p,f.id)}}}break;case"FnCall":{if(E(e,P.while)){let u=t.length;yi(e.func,t,n,r,i,o,e);for(let c of e.args)yi(c,t,n,r,i,o,e);let _=t.length;if(_>u)for(let c=u;c<_;c++)t[c].isInsideWhile=!0,t[c].whileNestingDepth=(t[c].whileNestingDepth??0)+1,t[c].enclosingWhileExpr||(t[c].enclosingWhileExpr=e);break}if(E(e,P.cond)){fc(e,t,n,r,i,o);break}if(E(e,P.match)){fc(e,t,n,r,i,o);break}if(o.detect(e,a,t),o.shouldSkipBody(e)){if((s=e.$)!=null&&s.deferredDupExpressions)for(let u of e.$.deferredDupExpressions)yi(u,t,n,r,i,o,e);break}yi(e.func,t,n,r,i,o,e);for(let u of e.args)yi(u,t,n,r,i,o,e);if((l=e.$)!=null&&l.deferredDropExpressions)for(let u of e.$.deferredDropExpressions)yi(u,t,n,r,i,o,e);break}}}function fc(e,t,n,r,i,o){if(e.tag!=="FnCall")return;let a=t.length;yi(e.func,t,n,r,i,o,e);let s=new Map(r),l=[];for(let _ of e.args){let c=t.length;yi(_,t,n,r,i,o,e),l.push(t.slice(c))}r.clear();for(let[_,c]of s)r.set(_,c);let u=Math.max(...l.map(_=>_.length),0);if(u>0){t.splice(a);let _=a;for(let c=0;c<u;c++){let f;for(let p of l)if(c<p.length){f=p[c];break}f&&(f.index=t.length,f.isInsideCond=!0,c===0&&(f.needsOwnCondBranchField=!0),c>0&&(f.condBranchSourceIndex=_),t.push(f))}}}function pc(e){let n=pl(e,{detect(i,o,a){var s;if(i.tag==="FnCall"&&_r(i)){let l=i.args[0];if(!l)return;let u=(s=l.$)==null?void 0:s.type;if(u&&at(u)){let _=Ln(u);if(!_)return;let c=_.isFuture.outputType,f;if(l.tag==="Atom"&&l.token.type==="identifier"&&l.$){let m=l.token.value,h=ae(l.$.env,m);if(h.length>0){let y=h[h.length-1];y.isOwningTheSameRcValueAs?f=y.isOwningTheSameRcValueAs.id:f=y.id}}let p=Ba(o);a.push({index:a.length,expr:i,resultType:c,futureType:_,targetVariableId:p,futureVariableId:f})}}},shouldSkipBody(i){return An(i)}}),r=n.capturedVariables.map(i=>({id:i.id,name:i.name,type:i.type,kind:"local",isOwningTheSameRcValueAs:void 0}));return{awaitPoints:n.suspensionPoints,capturedVariables:r,hasAwaits:n.hasSuspensions,variableIdRemapping:n.variableIdRemapping}}function An(e){var t,n;return e.tag!=="FnCall"?!1:((n=(t=e.func.$)==null?void 0:t.type)==null?void 0:n.ioBuiltin)==="io_async"}function _r(e){var t,n;return e.tag!=="FnCall"?!1:((n=(t=e.func.$)==null?void 0:t.type)==null?void 0:n.ioBuiltin)==="io_await"}function dc(e){var t,n;return e.tag!=="FnCall"?!1:((n=(t=e.func.$)==null?void 0:t.type)==null?void 0:n.ioBuiltin)==="io_state"}function dl(e){var t,n;return e.tag!=="FnCall"?!1:((n=(t=e.func.$)==null?void 0:t.type)==null?void 0:n.ioBuiltin)==="io_spawn"}function mc(e){var t,n;return e.tag!=="FnCall"?!1:((n=(t=e.func.$)==null?void 0:t.type)==null?void 0:n.ioBuiltin)==="join_handle_await"}function Nt(e){return K(e)&&e.token.type==="identifier"||e.token.type==="operator"}function Ga(e,t,n){var a;if(!((a=e.$)!=null&&a.variableName))return;let r=ae(t,e.$.variableName);if(!r.length)return;let i=r[r.length-1],o=new Set;for(;i&&i.isOwningTheSameRcValueAs;){if(o.has(i.id))return;o.add(i.id),i=i.isOwningTheSameRcValueAs}if(i&&i.isOwningTheRcValue)return i}function Ki(e){var r,i;let t=(r=e.$)==null?void 0:r.env;if(!t)return;let n;if((i=e.$)!=null&&i.pathCollection)for(let o of e.$.pathCollection)o.length>0&&typeof o[0]=="string"&&(n=o[0]);else K(e)&&(n=e.token.value);if(n){let o=ae(t,n),a=o[o.length-1];if(a!=null&&a.isImplicit)throw d({token:e.token,errorMessage:`Cannot use implicit variable "${a.name}" in assignment. Implicit variables must be passed via using() parameters.`})}}var ml=!0;function vu({variablesToDrop:e,env:t,context:n}){let r=[],i=t;for(let o of e){let a=Dt(`${F.___drop[0]}(${o.name})`),s=O({expr:a,env:i,context:{...n,expectedType:{env:i,type:ue.type}}});r.push(s),s.$&&s.$.env&&(i=s.$.env)}return{deferredDropExpressions:r.length>0?r:void 0,env:i}}function Wa(e,t,n){var s,l;if(S(e)&&An(e))return;if((s=e.$)!=null&&s.deferredDupExpressions)for(let u of e.$.deferredDupExpressions)Wa(u,t,n);if(S(e)&&S(e.func)&&E(e.func,".",2)&&K(e.func.args[0])&&K(e.func.args[1])&&e.func.args[1].token.value===F.___dup[0]&&e.args.length===0&&((l=e.$)!=null&&l.env)){let u=e.func.args[0].token.value,_=ae(e.$.env,u);if(_.length>0){let c=_[_.length-1];t.has(c.id)||t.set(c.id,[]),t.get(c.id).push(e)}return}if(S(e)&&E(e,P.while))return;function i(u){var _,c;if(Gt((_=u.$)==null?void 0:_.controlFlow))return!0;if(S(u)&&E(u,P.begin)){let f=u.args[u.args.length-1];if(Gt((c=f==null?void 0:f.$)==null?void 0:c.controlFlow)||S(f)&&E(f,P.return))return!0}return!!(S(u)&&E(u,P.return))}function o(u){if(S(u)&&E(u,P.tuple,0))return!0;if(S(u)&&E(u,P.begin)){if(u.args.length===0)return!0;if(u.args.length===1){let _=u.args[0];if(S(_)&&E(_,P.tuple,0))return!0}}return!1}function a(u,_){let c=[],f=[],p=[];for(let h=_;h<u.args.length;h++){let y=u.args[h];if(S(y)&&E(y,"=>",2)){let g=y.args[1],v=yc(g);c.push(v),f.push(i(g)),p.push(o(g))}}let m=new Set;for(let h of c){for(let y of h.dupCalls.keys())m.add(y);for(let y of h.varsWithPartialBranchDups)n.add(y)}if(c.length>0)for(let h of m){let y=[],g=[];for(let v=0;v<c.length;v++){let T=c[v],$=T.dupCalls.has(h),C=f[v];if($){let k=T.dupCalls.get(h);C?y.push(...k):g.push(...k)}}for(let v of y)t.has(h)||t.set(h,[]),v.__isEarlyReturnDup=!0,t.get(h).push(v);if(g.length>0){let v=0,T=0;for(let $=0;$<c.length;$++)f[$]||(v++,c[$].dupCalls.has(h)&&T++);if(T===v){t.has(h)||t.set(h,[]);for(let $ of g)t.get(h).push($)}else n.add(h)}}}if(S(e)&&E(e,P.cond)){a(e,0);return}if(S(e)&&E(e,P.match)){e.args[0]&&Wa(e.args[0],t,n),a(e,1);return}if(S(e)){Wa(e.func,t,n);for(let u of e.args)Wa(u,t,n)}}function yc(e){let t=new Map,n=new Set;return Wa(e,t,n),{dupCalls:t,varsWithPartialBranchDups:n}}function yl(e){return S(e)&&E(e,P.tuple,0)}function Tu(e,t){var n;if((n=e.$)!=null&&n.deferredDupExpressions&&(e.$.deferredDupExpressions=e.$.deferredDupExpressions.filter(r=>!t.has(r)),e.$.deferredDupExpressions.length===0&&(e.$.deferredDupExpressions=void 0)),S(e)){Tu(e.func,t);for(let r of e.args)Tu(r,t)}}function ch(e,t){var i,o,a,s,l,u;let n=new Set,r=e.args;for(let _=0;_<r.length;_++){let c=r[_];if(!S(c)||!E(c,P.while))continue;let f=c.args[c.args.length-1];if(!(!f||!S(f)||!E(f,P.begin)))for(let p of f.args){if(!S(p)||!E(p,P.match))continue;let m=p.args[0];if(!m||!K(m))continue;let h=m.token.value,y,g,v;for(let L=1;L<p.args.length;L++){let N=p.args[L];if(!S(N)||!E(N,"=>",2))continue;let x=N.args[1];if(!(!S(x)||!E(x,P.begin))){for(let V of x.args)if(S(V)&&E(V,"=",2)){let U=V.args[0];if(K(U)&&U.token.value===h){y=V.args[1],g=V,v=x;break}}if(y)break}}if(!y||!g||!v||!((i=y.$)!=null&&i.deferredDupExpressions)||y.$.deferredDupExpressions.length===0)continue;let T;for(let L=0;L<_;L++){let N=r[L];if(S(N)&&E(N,"=",2)){let x=N.args[0];if(K(x)&&x.token.value===h){T=N.args[1];break}if(S(x)&&x.args.length>0&&K(x.args[0])&&x.args[0].token.value===h){T=N.args[1];break}}}if(!T)continue;let $=(o=T.$)==null?void 0:o.variableName;if(!$||!((a=T.$)!=null&&a.env))continue;let C=ae(T.$.env,$);if(C.length===0||C[C.length-1].isOwningTheRcValue||!((s=T.$)!=null&&s.deferredDupExpressions)||T.$.deferredDupExpressions.length===0)continue;let b=!1;for(let L=_+1;L<r.length;L++)if(Eu(r[L],h)){b=!0;break}if(b)continue;T.$.deferredDupExpressions=void 0,y.$.deferredDupExpressions=void 0;let w=(l=g.$)==null?void 0:l.variableName;w&&((u=v.$)!=null&&u.deferredDropExpressions)&&(v.$.deferredDropExpressions=v.$.deferredDropExpressions.filter(L=>fh(L)!==w),v.$.deferredDropExpressions.length===0&&(v.$.deferredDropExpressions=void 0)),g.$&&(g.$.variableName=void 0);let A=ae(t,h);if(A.length>0){let L=A[A.length-1];t=bt(t,L,{...L,consumedAtToken:L.token})}n.add(h)}}return{optimizedVarNames:n,env:t}}function fh(e){if(S(e)&&e.args.length===0&&S(e.func)&&E(e.func,".",2)&&K(e.func.args[1])&&e.func.args[1].token.value===F.___drop[0]&&K(e.func.args[0]))return e.func.args[0].token.value;if(S(e)&&E(e,F.___drop)&&e.args.length>=1&&K(e.args[0]))return e.args[0].token.value}function Eu(e,t){if(K(e)&&e.token.value===t)return!0;if(S(e)){if(Eu(e.func,t))return!0;for(let n of e.args)if(Eu(n,t))return!0}return!1}function un({expr:e,env:t,context:n,variablesToAdd:r=[],isEvaluatingFunctionBodyBeginBlock:i=!1}){var k,b,w,A,L,N,x,V,U;if(S(e)&&E(e,"_")&&!E(e,P.begin)){let R=e;R.args.some(H=>S(H)&&E(H,":"))||(R.func={...R.func,token:{...R.func.token,value:P.begin[0]}})}if(!S(e)||!E(e,P.begin)){let R={tag:"FnCall",func:{tag:"Atom",token:{...e.token,value:P.begin[0]}},args:[_t(e)],token:{...e.token,value:P.begin[0]}};di(e,R),e=e}let o=e.args,a=n.expectedType;if(o.length===0)return e.$={env:t,type:ue.type,value:ue,pathCollection:[]},e;t=lt(t,void 0,!0);for(let R=0;R<r.length;R++){let D=r[R],{env:H}=xe({env:t,variable:D});t=H}let s=o[o.length-1],l,u=!1;for(let R=0;R<o.length;R++){let D=o[R];if(K(D)&&ln(D,P.return)||S(D)&&E(D,P.return)){if(R!==o.length-1&&!(R===o.length-2&&yl(o[o.length-1])))throw d({token:D.token,errorMessage:'The "return" keyword can only be used as the last expression.'});if(S(D)&&Ge(D,P.return,1),!n.isEvaluatingFunctionBodyOrAsyncBlock)throw d({token:D.token,errorMessage:'The "return" keyword can only be used inside a function body or async block.'});if(l=D,K(D)){D.$={env:t,type:ue.type,value:ue,pathCollection:[],controlFlow:Hi("return")},s=D;break}else{Ge(D,P.return,1);let H=D.args[0],B=O({expr:H,env:t,context:{...n,expectedType:n.isEvaluatingFunctionBodyOrAsyncBlock.kind==="function-body"?{type:n.isEvaluatingFunctionBodyOrAsyncBlock.type.return.type,env:t}:n.expectedType}});if(!B.$)throw d({token:H.token,errorMessage:`Return expression is not evaluated correctly:
|
|
153
153
|
${I(H)}`});if(((k=n.isEvaluatingFunctionBodyOrAsyncBlock)==null?void 0:k.kind)==="function-body"&&z(n.isEvaluatingFunctionBodyOrAsyncBlock.type.return.type)&&n.functionReturnImplConcreteType){let G=B.$.type;if(n.functionReturnImplConcreteType.length>0){let Q=n.functionReturnImplConcreteType[0];if(!le({type:Q.concreteType,env:Q.env},{type:G,env:t}))throw Qt([{token:D.token,errorMessage:`All return statements must return the same concrete type for Impl(...).
|
|
154
154
|
Impl(...) uses static dispatch and requires the same concrete type across all returns.
|
|
155
155
|
Consider using Dyn(...) for dynamic dispatch if different concrete types are needed.`},{token:Q.token,errorMessage:`First return has concrete type: ${M(Q.concreteType)}`},{token:D.token,errorMessage:`Conflicting return has concrete type: ${M(G)}`}])}else n.functionReturnImplConcreteType.push({concreteType:G,env:t,token:D.token})}It(B,!0),t=B.$.env,D.$={env:t,type:B.$.type,value:B.$.value,pathCollection:B.$.pathCollection,variableName:B.$.variableName,controlFlow:Hi("return")},s=D;break}}else if(K(D)&&ln(D,P.break)){if(R!==o.length-1&&!(R===o.length-2&&yl(o[o.length-1])))throw d({token:D.token,errorMessage:'The "break" keyword can only be used as the last expression.'});if(!n.isEvaluatingLoopBody)throw d({token:D.token,errorMessage:'The "break" keyword can only be used inside a loop.'});D.$={env:t,type:ue.type,value:ue,pathCollection:[],controlFlow:Hi("break")},s=D;break}else if(K(D)&&ln(D,P.continue)){if(R!==o.length-1&&!(R===o.length-2&&yl(o[o.length-1])))throw d({token:D.token,errorMessage:'The "continue" keyword can only be used as the last expression.'});if(!n.isEvaluatingLoopBody)throw d({token:D.token,errorMessage:'The "continue" keyword can only be used inside a loop.'});D.$={env:t,type:ue.type,value:ue,pathCollection:[],controlFlow:Hi("continue")},s=D;break}else if(S(D)&&E(D,P.escape)){if(R!==o.length-1&&!(R===o.length-2&&yl(o[o.length-1])))throw d({token:D.token,errorMessage:'The "escape" keyword can only be used as the last expression.'});if(!n.enclosingFunctionReturnType)throw d({token:D.token,errorMessage:'The "escape" keyword can only be used inside a function that has an enclosing function.'});l=D,Ge(D,P.escape,1);let H=D.args[0],B=O({expr:H,env:t,context:{...n,expectedType:{type:n.enclosingFunctionReturnType,env:t}}});if(!B.$)throw d({token:H.token,errorMessage:`Escape expression is not evaluated correctly:
|
|
@@ -167,14 +167,14 @@ ${I(N)}`});if(k=N.token.value,!K(x))throw d({token:x.token,errorMessage:`Expecte
|
|
|
167
167
|
${I(x)}`});if(!Nt(x))throw d({token:x.token,errorMessage:`Expected identifier for export, got:
|
|
168
168
|
${I(x)}`});b=x.token.value}let w=ae(t,b);if(w.length===0)throw d({token:C.token,errorMessage:`Variable "${b}" is not defined in the module.`});let A=w[w.length-1];if(o.fields.findIndex(N=>N.label===b)>=0)throw d({token:C.token,errorMessage:`Variable "${b}" is already exported in the module.`});if(!A.isCompileTimeOnly)throw d({token:C.token,errorMessage:`Variable "${b}" is not a compile-time variable and cannot be exported.`});o.fields.push({label:k,type:A.type,assignedValue:A.isCompileTimeOnly?(u=A.value)==null?void 0:u[0]:void 0,defaultValue:void 0,exprs:{expr:C,labelExpr:void 0,typeExpr:void 0,assignedValueExpr:void 0,defaultValueExpr:void 0}}),s.fields.push((_=A.value)==null?void 0:_[0]),C.$={env:t,type:A.type,value:(c=A.value)==null?void 0:c[0],pathCollection:[]}}}}else{let T=O({expr:v,env:t,context:{...n,expectedType:void 0}});if((f=T.$)!=null&&f.env&&(t=(p=T.$)==null?void 0:p.env),S(T)){if(E(T,":=",2)){let $=T.args[0];K($)&&((m=$.$)!=null&&m.type)&&!$.$.value&&a.push(T)}else if(E(T,"=",2)){let $=T.args[0],C;if(K($))C=$.token.value;else if(S($)&&E($,":",2)){let k=$.args[0];K(k)&&(C=k.token.value)}if(C){let k=ae(t,C),b=k.length>0?k[k.length-1]:void 0;b!=null&&b.isModuleLevel&&a.push(T)}}}if(S(T)&&E(T,":",2)){let $=T.args[0];if(K($)&&((h=$.$)!=null&&h.env)){let C=$.token.value,k=ae(t,C),b=k.length>0?k[k.length-1]:void 0;if(b!=null&&b.isModuleLevel)throw d({token:$.token,errorMessage:`Uninitialized runtime variable "${C}" at module scope.
|
|
169
169
|
Use \`${C} := value;\` or \`(${C} : ${((y=T.args[1])==null?void 0:y.token.value)??"Type"}) = value;\` instead.`})}}}}catch(T){if(r){l=T;break}else throw T}}try{l||(t=Ot(t))}catch(g){if(r)l=g;else throw g}return s.isLoading=!1,s.moduleLevelInitExprs=a.length>0?a:void 0,{moduleValue:s,moduleType:o,env:t,partialModuleError:l}}function vl({functionType:e,specializedEnv:t,SelfType:n}){var g;let r=t.frames[t.frames.length-1],i=new Set(r.variables.map(v=>v.name)),o=lt(e.env,r),a=o,s=e.parametersFrame.variables.filter(v=>e.forallParameters.some(T=>T.label===v.name)&&!i.has(v.name));if(s.length>0){a=lt(o);for(let v of s){let{env:T}=xe({env:a,variable:{...v},allowVariableShadowing:!0});a=T}}let l=e.parameters.map(v=>{var C;if(!v.exprs.typeExpr)return v;let T=_t(v.exprs.typeExpr),$=O({expr:T,env:a,context:{isEvaluatingGenericImplSpecialization:!0,stdPath:"",isEvaluatingFunctionType:!0,SelfType:n}});return W((C=$.$)==null?void 0:C.value)?{...v,type:$.$.value.value,exprs:{...v.exprs}}:v}),u=e.return.type,_=_t(e.return.typeExpr),c=O({expr:_,env:a,context:{isEvaluatingGenericImplSpecialization:!0,stdPath:"",isEvaluatingFunctionType:!0,SelfType:n}});W((g=c.$)==null?void 0:g.value)&&(u=c.$.value.value);let f=e.SelfType;n&&(f=n);let p=e.forallParameters.filter(v=>!i.has(v.label)),m={...e.parametersFrame,variables:e.parametersFrame.variables.map(v=>{let T=l.find(C=>C.label===v.name),$=T?T.type:v.type;return $!==v.type?{...v,type:$}:v})},h=t,y=new Set;for(let v of t.frames)for(let T of v.variables)y.add(T.name);for(let v of e.env.frames)for(let T of v.variables)if(!y.has(T.name)){let{env:$}=xe({env:h,variable:{...T},allowVariableShadowing:!0});h=$,y.add(T.name)}return{...e,env:h,forallParameters:p,parameters:l,parametersFrame:m,return:{...e.return,type:u},SelfType:f}}var qa=new Map;function ph({traitExpr:e,traitType:t}){if(!e||!S(e))return{};let n=e.func;if(S(n)){let r=n.args.map(o=>_t(o)),i;if(t.functionValue&&ne(t.functionValue.type)){let o=t.functionValue.type;o.parameters.length>0?i=o.parameters.map(a=>a.label):o.forallParameters.length>0&&(i=o.forallParameters.map(a=>a.label))}if(i){for(let o of e.args)if(S(o)&&E(o,":",2)){let a=o.args[0],s=o.args[1];if(K(a)){let l=a.token.value,u=t.fields.find(_=>_.label===l);u&&!ne(u.type)&&(r.push(_t(s)),i.push(l))}}}return{traitTypeArgExprs:r,traitFunctionParamNames:i}}if(!t.functionValue){let r=[],i=[];for(let o of e.args)if(S(o)&&E(o,":",2)){let a=o.args[0],s=o.args[1];if(K(a)){let l=a.token.value,u=t.fields.find(_=>_.label===l);u&&!ne(u.type)&&(r.push(_t(s)),i.push(l))}}if(r.length>0)return{traitTypeArgExprs:r,traitFunctionParamNames:i}}return{}}function gc({fieldExprs:e,env:t,context:n,receiverType:r}){var u,_;let i=[],o=vt(t),a=[],s=!1,l=r==null?void 0:r.trait;r!=null&&r.trait&&(r.trait={...r.trait,fields:[...r.trait.fields]}),t=lt(t);for(let c of e){if(S(c)&&E(c,P.begin))throw d({token:c.token,errorMessage:'impl receiverType, ... no longer accepts begin blocks. Use "impl { ... }" for anonymous modules.'});if(S(c)&&(E(c,"::",2)||E(c,":=",2)))throw d({token:c.token,errorMessage:'impl fields must use ":". "::" and ":=" are not allowed here.'});if(S(c)&&E(c,":",2)){let p=c.args[0],m=c.args[1];if(!K(p)||!Nt(p))throw d({token:p.token,errorMessage:`Expected identifier for impl field name, got:
|
|
170
|
-
${I(p)}`});let h=p.token.value,y=O({expr:m,env:t,context:{...n,expectedType:void 0,SelfType:r}});if(!((u=y.$)!=null&&u.type))throw d({token:m.token,errorMessage:`Failed to evaluate impl field value for "${h}".`});t=y.$.env;let g=y.$.type,v=y.$.value;if(!v)throw d({token:m.token,errorMessage:`impl field "${h}" must be a compile-time value.`});
|
|
170
|
+
${I(p)}`});let h=p.token.value,y=O({expr:m,env:t,context:{...n,expectedType:void 0,SelfType:r}});if(!((u=y.$)!=null&&u.type))throw d({token:m.token,errorMessage:`Failed to evaluate impl field value for "${h}".`});t=y.$.env;let g=y.$.type,v=y.$.value;if(!v)throw d({token:m.token,errorMessage:`impl field "${h}" must be a compile-time value.`});ge(v)&&!v.funcName&&(v.funcName=h,v.funcId+=`_${h}`);let{env:T}=xe({env:t,variable:{name:h,type:g,isCompileTimeOnly:!0,value:[v],token:p.token,initializedAtToken:p.token,consumedAtToken:void 0,isOwningTheRcValue:!1}});t=T;let $=(_=n.docCommentLookup)==null?void 0:_.get(ur(p.token));o.fields.push({label:h,type:g,assignedValue:v,defaultValue:void 0,exprs:{expr:c},docComment:$}),a.push(v),s=!0,r!=null&&r.trait&&r.trait.fields.push({label:h,type:g,assignedValue:v,defaultValue:void 0,exprs:{expr:c},docComment:$});continue}let f=O({expr:c,env:t,context:{...n,expectedType:void 0,ReceiverType:r}});if(!f.$||!tn(f.$.value))throw d({token:c.token,errorMessage:`Expected trait value in impl field list, got:
|
|
171
171
|
${I(c)}`});t=f.$.env,i.push({traitValue:f.$.value,sourceExpr:c,isAnonymousTrait:!1})}if(t=Ot(t),r&&(r.trait=l),s){let c=Mo({...o,receiverType:r},a);i.unshift({traitValue:c,sourceExpr:void 0,isAnonymousTrait:!0})}return{env:t,traitEntries:i}}var ti=new Map,Ya=0,Tl=new Map,$o=new Map;function oa(e){for(let[t,n]of ti.entries()){let r=n.filter(i=>i.sourceModulePath!==e);r.length===0?ti.delete(t):ti.set(t,r)}Ya++,Tl.clear()}function dh(e){for(let[t,n]of $o.entries()){let r=n.filter(i=>i.modulePath!==e);r.length===0?$o.delete(t):$o.set(t,r)}}function Ha(){qa.clear(),ti.clear(),$o.clear(),Tl.clear(),Ya=0}function El(e){return e.functionValue?e.functionValue.funcId:e.typeName||e.id}function hc(e){if("functionValue"in e){let t=e.functionValue;if(t)return t.funcId}return e.id}function vc(e,t){if(!t.traitType.typeName){let r=t.traitType.fields.filter(i=>i.label&&ne(i.type)).map(i=>i.label);if(r.length>0){let i=hc(t.receiverTypePattern);if(i){for(let[o,a]of ti.entries())for(let s of a)if(!(s.traitType.typeName||hc(s.receiverTypePattern)!==i)){for(let u of s.traitType.fields)if(u.label&&ne(u.type)&&r.includes(u.label))throw d({token:t.expr.token,errorMessage:`Method "${u.label}" is already defined for type "${M(t.receiverTypePattern)}".
|
|
172
172
|
Cannot define duplicate method names across impl blocks. Use a different name (e.g., "comptime_${u.label}") for the comptime variant.`})}}}}let n=ti.get(e);n||(n=[],ti.set(e,n)),n.push(t),Ya++}function mh({receiverType:e,traitType:t,currentModulePath:n,expr:r}){let i=e.id,a=($o.get(i)||[]).find(s=>s.traitTypeId===t.id);if(a)throw d({token:r.token,errorMessage:`Trait "${t.typeName??t.id}" is already implemented for type "${M(e)}".
|
|
173
173
|
First implementation was in: ${a.modulePath||"unknown"}`})}function yh({receiverType:e,traitType:t,currentModulePath:n,expr:r}){let i=e.id,o=$o.get(i);o||(o=[],$o.set(i,o)),o.push({traitTypeId:t.id,traitTypeName:t.typeName,modulePath:n||"unknown",expr:r})}function gh({receiverType:e,traitType:t,currentModulePath:n,expr:r}){if(!n)return;let i=t.definedInModulePath===n,o=e.definedInModulePath===n,a=n.replace(/\\/g,"/");if(!(a.includes("prelude.yo")||a.includes("std/"))&&!i&&!o)throw d({token:r.token,errorMessage:`Orphan impl: Cannot implement foreign trait "${t.typeName??t.id}" for foreign type "${M(e)}".
|
|
174
174
|
At least one of the trait or the type must be defined in this module.
|
|
175
175
|
Trait defined in: ${t.definedInModulePath||"unknown"}
|
|
176
176
|
Type defined in: ${e.definedInModulePath||"unknown"}
|
|
177
|
-
Current module: ${n}`})}function $l({concreteType:e,traitType:t,env:n}){let r=El(t),i=ti.get(r);if(!(!i||i.length===0)){for(let o of i)if(bl({concreteType:e,impl:o,env:n}).matched)return o}}function Dr({concreteType:e,methodName:t,env:n}){if(z(e)){let l=On(n,e);z(l)||(e=l)}if(!z(e)){let l=e.id+"\0"+t,u=Tl.get(l);if(u&&u.version===Ya)return u.result}let r=[],i=[];for(let[l,u]of ti.entries())for(let _ of u){let c=bl({concreteType:e,impl:_,env:n});if(!c.matched)continue;let f=_.traitType,p=_.traitValue,m=!f.typeName,h=f.fields.findIndex(y=>y.label===t&&ne(y.type));if(h>=0){let y=f.fields[h];if(ne(y.type)){let g=p.fields[h],v=wi(e),T=[...c.substitutions].some(([k,b])=>k!=="Self"&&z(b)),$=_.forallParameters.some(k=>k.kind==="type"&&!c.substitutions.has(k.name)),C=
|
|
177
|
+
Current module: ${n}`})}function $l({concreteType:e,traitType:t,env:n}){let r=El(t),i=ti.get(r);if(!(!i||i.length===0)){for(let o of i)if(bl({concreteType:e,impl:o,env:n}).matched)return o}}function Dr({concreteType:e,methodName:t,env:n}){if(z(e)){let l=On(n,e);z(l)||(e=l)}if(!z(e)){let l=e.id+"\0"+t,u=Tl.get(l);if(u&&u.version===Ya)return u.result}let r=[],i=[];for(let[l,u]of ti.entries())for(let _ of u){let c=bl({concreteType:e,impl:_,env:n});if(!c.matched)continue;let f=_.traitType,p=_.traitValue,m=!f.typeName,h=f.fields.findIndex(y=>y.label===t&&ne(y.type));if(h>=0){let y=f.fields[h];if(ne(y.type)){let g=p.fields[h],v=wi(e),T=[...c.substitutions].some(([k,b])=>k!=="Self"&&z(b)),$=_.forallParameters.some(k=>k.kind==="type"&&!c.substitutions.has(k.name)),C=ge(g)&&(c.valueSubstitutions.size>0||c.substitutions.size>0)&&!v&&!T&&!$;if($)continue;if(C){let k=_.definitionEnv,b=lt(k);for(let[x,V]of c.substitutions){let{env:U}=xe({env:b,variable:{name:x,type:Pt(),isCompileTimeOnly:!0,value:[Te(V)],token:Fe,initializedAtToken:Fe,consumedAtToken:void 0,isOwningTheRcValue:!1}});b=U}for(let[x,V]of c.valueSubstitutions){let{env:U}=xe({env:b,variable:{name:x,type:V.type,isCompileTimeOnly:!0,value:[V],token:Fe,initializedAtToken:Fe,consumedAtToken:void 0,isOwningTheRcValue:!1}});b=U}if(_.traitTypeArgExprs&&_.traitFunctionParamNames&&_.traitTypeArgExprs.length===_.traitFunctionParamNames.length)for(let x=0;x<_.traitTypeArgExprs.length;x++){let V=_.traitTypeArgExprs[x],U=_.traitFunctionParamNames[x],R=O({expr:_t(V),env:b,context:{isEvaluatingGenericImplSpecialization:!0,stdPath:""}});if(R.$&&W(R.$.value)){let{env:D}=xe({env:b,variable:{name:U,type:Pt(),isCompileTimeOnly:!0,value:[R.$.value],token:Fe,initializedAtToken:Fe,consumedAtToken:void 0,isOwningTheRcValue:!1},allowVariableShadowing:!0});b=D}}let w=vl({functionType:y.type,specializedEnv:b,SelfType:c.substitutions.get("Self")});b=lt(b,w.parametersFrame);let A=_t(g.body),L=un({expr:A,env:b,context:{isEvaluatingGenericImplSpecialization:!0,expectedType:{type:w.return.type,env:b},stdPath:"",isEvaluatingFunctionBodyOrAsyncBlock:{kind:"function-body",type:w,value:g,evaluationEnv:b},functionReturnImplConcreteType:[],SelfType:c.substitutions.get("Self")},variablesToAdd:[],isEvaluatingFunctionBodyBeginBlock:!0}),N={...g,specializedType:w,body:L,funcId:`${g.funcId}_specialized_${[...c.substitutions.entries()].map(([x,V])=>`${x}_${M(V)}`).join("_")}_${[...c.valueSubstitutions.entries()].map(([x,V])=>`${x}_${pt(V)}`).join("_")}`,funcName:g.funcName?`${g.funcName}_specialized`:void 0};r.push({type:w,value:N}),i.push(m)}else if(v||T){let k=_.definitionEnv,b=lt(k);for(let[A,L]of c.substitutions){let{env:N}=xe({env:b,variable:{name:A,type:Pt(),isCompileTimeOnly:!0,value:[Te(L)],token:Fe,initializedAtToken:Fe,consumedAtToken:void 0,isOwningTheRcValue:!1}});b=N}for(let[A,L]of c.valueSubstitutions){let{env:N}=xe({env:b,variable:{name:A,type:L.type,isCompileTimeOnly:!0,value:[L],token:Fe,initializedAtToken:Fe,consumedAtToken:void 0,isOwningTheRcValue:!1}});b=N}let w=vl({functionType:y.type,specializedEnv:b,SelfType:c.substitutions.get("Self")});r.push({type:w,value:void 0}),i.push(m)}else if(ge(g)){let k={...g,specializedType:y.type};r.push({type:y.type,value:k}),i.push(m)}else if(!ge(g)&&(c.substitutions.size>0||c.valueSubstitutions.size>0)){let k=_.definitionEnv,b=lt(k);for(let[A,L]of c.substitutions){let{env:N}=xe({env:b,variable:{name:A,type:Pt(),isCompileTimeOnly:!0,value:[Te(L)],token:Fe,initializedAtToken:Fe,consumedAtToken:void 0,isOwningTheRcValue:!1}});b=N}for(let[A,L]of c.valueSubstitutions){let{env:N}=xe({env:b,variable:{name:A,type:L.type,isCompileTimeOnly:!0,value:[L],token:Fe,initializedAtToken:Fe,consumedAtToken:void 0,isOwningTheRcValue:!1}});b=N}let w=vl({functionType:y.type,specializedEnv:b,SelfType:c.substitutions.get("Self")});r.push({type:w,value:g}),i.push(m)}else r.push({type:y.type,value:g}),i.push(m)}}}let o=i.some(l=>l),a=i.some(l=>!l),s=r;if(o&&a&&(s=r.filter((l,u)=>i[u])),!z(e)){let l=e.id+"\0"+t;Tl.set(l,{result:s,version:Ya})}return s}function Cl({concreteType:e,propertyName:t,env:n}){if(z(e)){let r=On(n,e);z(r)||(e=r)}for(let[r,i]of ti.entries())for(let o of i){let a;try{a=bl({concreteType:e,impl:o,env:n})}catch{continue}if(!a.matched)continue;let s=o.traitType,l=s.fields.findIndex(c=>c.label===t&&!ne(c.type));if(l<0)continue;if(o.traitTypeArgExprs&&o.traitFunctionParamNames&&o.traitTypeArgExprs.length===o.traitFunctionParamNames.length){let c=o.definitionEnv,f=lt(c);for(let[p,m]of a.substitutions){let{env:h}=xe({env:f,variable:{name:p,type:Pt(),isCompileTimeOnly:!0,value:[Te(m)],token:Fe,initializedAtToken:Fe,consumedAtToken:void 0,isOwningTheRcValue:!1}});f=h}for(let p=0;p<o.traitTypeArgExprs.length;p++){let m=o.traitTypeArgExprs[p];if(o.traitFunctionParamNames[p]===t)try{let y=_t(m),g=O({expr:y,env:f,context:{stdPath:"",isEvaluatingGenericImplSpecialization:!0}});if(g.$&&W(g.$.value))return{type:g.$.value.type,value:g.$.value}}catch{}}}let u=s.fields[l],_=o.traitValue.fields[l]??u.assignedValue;if(!(!_||!W(_))){if(!z(_.value))return{type:_.type,value:_};for(let c of o.forallParameters)if(c.kind==="type"&&c.someType===_.value){let f=a.substitutions.get(c.name);if(f){let p=Te(f);return{type:p.type,value:p}}}}}}function Tc({concreteType:e,traitType:t,methodName:n,env:r}){let i=El(t),o=ti.get(i);if(!(!o||o.length===0))for(let a of o){let s=bl({concreteType:e,impl:a,env:r});if(!s.matched)continue;let l=a.traitType,u=a.traitValue,_=l.fields.findIndex(c=>c.label===n&&ne(c.type));if(_>=0){let c=l.fields[_];if(ne(c.type)){let f=u.fields[_];if(ge(f)&&(s.valueSubstitutions.size>0||s.substitutions.size>0)){let p=a.definitionEnv,m=lt(p);for(let[T,$]of s.substitutions){let{env:C}=xe({env:m,variable:{name:T,type:Pt(),isCompileTimeOnly:!0,value:[Te($)],token:Fe,initializedAtToken:Fe,consumedAtToken:void 0,isOwningTheRcValue:!1}});m=C}for(let[T,$]of s.valueSubstitutions){let{env:C}=xe({env:m,variable:{name:T,type:$.type,isCompileTimeOnly:!0,value:[$],token:Fe,initializedAtToken:Fe,consumedAtToken:void 0,isOwningTheRcValue:!1}});m=C}let h=vl({functionType:c.type,specializedEnv:m,SelfType:s.substitutions.get("Self")});m=lt(m,h.parametersFrame);let y=_t(f.body),g=un({expr:y,env:m,context:{isEvaluatingGenericImplSpecialization:!0,expectedType:{type:h.return.type,env:m},stdPath:"",isEvaluatingFunctionBodyOrAsyncBlock:{kind:"function-body",type:h,value:f,evaluationEnv:m},functionReturnImplConcreteType:[],SelfType:s.substitutions.get("Self")},variablesToAdd:[],isEvaluatingFunctionBodyBeginBlock:!0}),v={...f,specializedType:h,body:g,funcId:`${f.funcId}_specialized_${[...s.substitutions.entries()].map(([T,$])=>`${T}_${M($)}`).join("_")}_${[...s.valueSubstitutions.entries()].map(([T,$])=>`${T}_${pt($)}`).join("_")}`,funcName:f.funcName?`${f.funcName}_specialized`:void 0};return{type:h,value:v}}else if(ge(f)){let p={...f,specializedType:c.type};return{type:c.type,value:p}}else return{type:c.type,value:f}}}}}function bl({concreteType:e,impl:t,env:n}){let r={matched:!1,substitutions:new Map,valueSubstitutions:new Map};if(z(e)){let o=On(n,e);if(z(o))return r;e=o}let i=lt(n);for(let o of t.forallParameters)if(o.kind==="type"){let{env:a}=xe({env:i,variable:{name:o.name,type:Pt(),isCompileTimeOnly:!0,value:[Te(o.someType)],token:Fe,initializedAtToken:Fe,consumedAtToken:void 0,isOwningTheRcValue:!1},allowVariableShadowing:!0});i=a}else{let{env:a}=xe({env:i,variable:{name:o.name,type:o.type,isCompileTimeOnly:!0,value:[o.unknownValue],token:Fe,initializedAtToken:Fe,consumedAtToken:void 0,isOwningTheRcValue:!1},allowVariableShadowing:!0});i=a}try{let{expectedEnv:o}=Mt({type:t.receiverTypePattern,env:i},{type:e,env:n});if(Ae(e))for(let l of t.forallParameters){if(l.kind!=="type")continue;let u=hl(o,l.someType);if(z(u)){let _=hl(e.env,l.someType);if(!z(_))for(let c=o.frames.length-1;c>=0;c--){let f=o.frames[c],p=f.variables.findIndex(m=>m.name===l.name);if(p>=0){let m=o.frames.slice(),h=f.variables.slice();h[p]={...h[p],value:[Te(_)]},m[c]={...f,variables:h},o={...o,frames:m};break}}}}for(let{someType:l,traitType:u,traitExpr:_}of t.whereConstraints){let c=hl(o,l);if(!c)return r;let f=u;if(_)try{let p=_t(_),m=O({expr:p,env:o,context:{stdPath:"",isEvaluatingGenericImplSpecialization:!0}});m.$&&W(m.$.value)&&ot(m.$.value.value)&&(f=m.$.value.value)}catch{}if(f.isNegatedConstraint){if(z(c)){if(!vh(c,f,n))return r;continue}if(bn({targetType:c,traitType:f,env:n}))return r;continue}if(z(c)){if(!hh(c,f,n))return r;continue}if(!bn({targetType:c,traitType:f,env:o}))return r}let a=new Map,s=new Map;for(let l of t.forallParameters)if(l.kind==="type"){let u=hl(o,l.someType);u&&(!z(u)||u!==l.someType)&&a.set(l.name,u)}else{let u=ae(o,l.name),_=u[u.length-1];if(_&&_.value&&!Ie(_.value[0])){let c={..._.value[0],type:l.type};s.set(l.name,c)}}return a.set("Self",e),{matched:!0,substitutions:a,valueSubstitutions:s}}catch{return r}}function hh(e,t,n){if(!t.typeName)return!1;for(let o of e.requiredTraits)if(o.traitType.id===t.id)return!0;let i=wr(n,e);if(i){for(let o of i.requiredTraits)if(o.id===t.id)return!0}for(let o of e.trait.fields)if(tn(o.assignedValue)&&o.assignedValue.type.id===t.id)return!0;return!1}function vh(e,t,n){if(!t.typeName)return!1;if(e.negativeTraits){for(let o of e.negativeTraits)if(o.traitType.id===t.id)return!0}let i=wr(n,e);if(i){for(let o of i.negativeTraits)if(o.id===t.id)return!0}return!1}function Th({receiverTypePattern:e,traitType:t,whereConstraints:n,env:r,errorToken:i}){if(t.selfConstraints&&t.selfConstraints.length>0)for(let o of t.selfConstraints){if(bn({targetType:e,traitType:o,env:r}))continue;let a=new Set;for(let s of n)s.traitType.typeName===o.typeName&&!s.traitType.isNegatedConstraint&&a.add(s.someType.name);throw d({token:i,errorMessage:`Generic impl receiver type "${M(e)}" does not satisfy constraint "${o.typeName??M(o)}" required by trait "${t.typeName??M(t)}".
|
|
178
178
|
Consider adding "where(T <: ${o.typeName??M(o)})" to the impl.`})}if(t.negativeSelfConstraints&&t.negativeSelfConstraints.length>0){for(let o of t.negativeSelfConstraints)if(bn({targetType:e,traitType:o,env:r}))throw d({token:i,errorMessage:`Generic impl receiver type "${M(e)}" implements "${o.typeName??M(o)}" but trait "${t.typeName??M(t)}" requires it to NOT implement this trait.
|
|
179
179
|
Consider adding "where(T <: !(${o.typeName??M(o)}))" to the impl.`})}}function hl(e,t){for(let n=e.frames.length-1;n>=0;n--){let r=e.frames[n];for(let i of r.variables)if(i.name===t.name&&i.value&&W(i.value[0]))return i.value[0].value}return t}function aa(e){let t=qa.get(e);if(t){for(let n of t)n.fields=n.fields.filter(r=>r.sourceModulePath!==e);qa.delete(e),dh(e)}}function Eh(e,t){let n=qa.get(e);n||(n=new Set,qa.set(e,n)),n.add(t)}function $h(e,t,n){let r=e.type.receiverType;if(!(!r||!r.trait))if(e.type.typeName&&(gh({receiverType:r,traitType:e.type,currentModulePath:n,expr:t}),mh({receiverType:r,traitType:e.type,currentModulePath:n,expr:t}),yh({receiverType:r,traitType:e.type,currentModulePath:n,expr:t})),n&&Eh(n,r.trait),e.type.typeName){let i={label:"",type:dr(1),assignedValue:e,sourceModulePath:n,exprs:{expr:t}};r.trait.fields.push(i)}else for(let i=0;i<e.type.fields.length;i++){let o=e.type.fields[i],a=e.fields[i];if(o.label&&ne(o.type)&&r.trait.fields.find(u=>u.label===o.label&&ne(u.type)))throw d({token:t.token,errorMessage:`Method "${o.label}" is already defined for type "${M(r)}".
|
|
180
180
|
Cannot define duplicate method names across impl blocks. Use a different name (e.g., "comptime_${o.label}") for the comptime variant.`});let s={label:o.label,type:o.type,assignedValue:a,sourceModulePath:n,docComment:o.docComment,exprs:{expr:t}};r.trait.fields.push(s)}}function Ec({expr:e,env:t,context:n}){var $,C;if(!E(e,P.impl))throw d({token:e.token,errorMessage:`Expected "impl", got:
|
|
@@ -185,15 +185,15 @@ This typically happens when a struct/enum/array/tuple contains fields with confl
|
|
|
185
185
|
- Runtime only fields (e.g., *(T), [T], void, C-compatible types)
|
|
186
186
|
|
|
187
187
|
Consider restructuring the type to avoid mixing incompatible field types.`})}function tr(e,t=!0,n){switch(e.tag){case"ComptimeInt":case"ComptimeFloat":case"U8":case"I8":case"U16":case"I16":case"U32":case"I32":case"U64":case"I64":case"F32":case"F64":case"Usize":case"Isize":return e;case"Bool":return e;case"Unit":return e;case"ComptimeString":return e;case"Type":return e;case"Function":return e;case"Expr":return e;case"Unknown":return e;case"Ptr":{if(t)return e;let r=e;if(n){let a=n.get(r.targetValue);if(a)return{...r,targetValue:a,targetIndex:r.targetIndex}}let o=[tr(r.targetValue[0],t,n)];return n&&n.set(r.targetValue,o),{...r,targetValue:o,targetIndex:r.targetIndex}}case"Tuple":{let r=e;return{...r,fields:r.fields.map(i=>tr(i,t,n))}}case"Struct":{let r=e;return{...r,fields:r.fields.map(i=>tr(i,t,n))}}case"Enum":{let r=e;return{...r,fields:r.fields.map(i=>tr(i,t,n))}}case"Array":{let r=e;return{...r,elements:r.elements.map(i=>tr(i,t,n))}}case"Slice":{if(t)return e;let r=e;if(n){let a=n.get(r.sourceArray);if(a)return{...r,sourceArray:a}}let o=[tr(r.sourceArray[0],t,n)];return n&&n.set(r.sourceArray,o),{...r,sourceArray:o}}case"ComptimeList":{let r=e;return{...r,elements:r.elements.map(i=>tr(i,t,n))}}case"Module":{let r=e;return{...r,fields:r.fields.map(i=>i?tr(i,t,n):void 0)}}case"Trait":{let r=e;return{...r,fields:r.fields.map(i=>i?tr(i,t,n):void 0)}}default:return e}}function ku({modulePath:e,inputString:t}){return{functionDeclarationFrameLevel:-1,frames:[],modulePath:e,inputString:t}}function jt(){let e=ku({modulePath:"",inputString:""});return lt(e)}function wu(e){let t=new Map,n=[...e.frames.flatMap(o=>o.variables)];for(let o of n)if(o.value&&!t.has(o.value)){let a=tr(o.value[0],!1,t);t.has(o.value)||t.set(o.value,[a])}let r=o=>{if(!o.value)return{...o};let a=t.get(o.value);if(a)return{...o,value:a};let s=tr(o.value[0],!1,t);return{...o,value:[s]}},i=o=>({...o,variables:o.variables.map(r),whereClauseConstraints:Ch(o.whereClauseConstraints)});return{...e,frames:e.frames.map(i)}}function Ch(e){let t=new Map;for(let[n,r]of e)t.set(n,{someType:r.someType,requiredTraits:[...r.requiredTraits],negativeTraits:[...r.negativeTraits]});return t}function ni({env:e,someType:t,traitType:n,isNegated:r}){let i=e.frames.length-1,o=e.frames[i];if(!o)return e;let a=t.id,s=o.whereClauseConstraints.get(a);s||(s={someType:t,requiredTraits:[],negativeTraits:[]},o.whereClauseConstraints.set(a,s));let l=r?s.negativeTraits:s.requiredTraits;return l.some(u=>u.id===n.id)||l.push(n),e}function wr(e,t){var l;let n=[],r=[],i=new Set,o=new Set,a=!1,s=new Set;for(let u of e.frames)for(let _ of u.variables){let c=(l=_.value)==null?void 0:l[0];W(c)&&z(c.value)&&c.value.id===t.id&&s.add(_.name)}for(let u of e.frames)for(let _ of u.whereClauseConstraints.values())if(!(_.someType.id!==t.id&&!s.has(_.someType.name))){a=!0;for(let c of _.requiredTraits)i.has(c.id)||(i.add(c.id),n.push(c));for(let c of _.negativeTraits)o.has(c.id)||(o.add(c.id),r.push(c))}if(a)return{requiredTraits:n,negativeTraits:r}}function Fc(e){return`typeapp:${e.constructor.id}:${e.args.map(t=>t.id).join(",")}`}function Lc({env:e,typeApp:t,traitType:n,isNegated:r}){let i=e.frames.length-1,o=e.frames[i];if(!o)return e;let a=Fc(t),s=o.whereClauseConstraints.get(a);s||(s={someType:t.constructor,requiredTraits:[],negativeTraits:[]},o.whereClauseConstraints.set(a,s));let l=r?s.negativeTraits:s.requiredTraits;return l.some(u=>u.id===n.id)||l.push(n),e}function bh(e,t){let n=Fc(t),r=[],i=[],o=new Set,a=new Set,s=!1;for(let l of e.frames){let u=l.whereClauseConstraints.get(n);if(u){s=!0;for(let _ of u.requiredTraits)o.has(_.id)||(o.add(_.id),r.push(_));for(let _ of u.negativeTraits)a.has(_.id)||(a.add(_.id),i.push(_))}}if(s)return{requiredTraits:r,negativeTraits:i}}var Ic=null;function Ac(e){Ic=e}function Fu(){Ic=null}var kh="__yo_self";function xe({env:e,variable:t,deltaFrame:n,variableId:r,addToBeginBlockFrame:i,allowVariableShadowing:o}){let a=e.frames.length-1+(n??0),s=Ht(e.modulePath,t.name);if(i){let m=Ih(e);m>=0&&(a=m)}if(t.name!==kh&&!s){let m=ae(e,t.name);if(m.length>0&&!o){let h=m[m.length-1];throw Qt([{token:t.token,errorMessage:`Failed to define variable "${t.name}":`},{token:h.token,errorMessage:`Variable "${t.name}" is already defined here (variable shadowing is not allowed):`}])}}let l=e.frames[a];if(!l)throw console.trace(`Frame at level ${a} does not exist in the environment.`),new Error(`Frame at level ${a} does not exist in the environment.`);let u=s?t.name:r??cn(e.modulePath,t.name),_={...t,frameLevel:a,id:u},c=s?Fh(l,_):wh({frame:l,variable:_}),f=e.frames.slice();return f[a]=c,{env:{functionDeclarationFrameLevel:e.functionDeclarationFrameLevel,frames:f,modulePath:e.modulePath,inputString:e.inputString},variable:_}}function wh({frame:e,variable:t}){if(t.name==="_")return e;if(e.variables.some(r=>r.name===t.name))throw Qt([{token:t.token,errorMessage:`Failed to define variable "${t.name}":`},{token:e.variables.find(r=>r.name===t.name).token,errorMessage:`Variable "${t.name}" is already defined here in the same scope:`}]);let n=e.variables.findIndex(r=>r.name===t.name&&!r.initializedAtToken);if(n>-1){let r=e.variables.slice();return r[n]=t,{id:e.id,variables:r,isBeginBlockFrame:e.isBeginBlockFrame,whereClauseConstraints:new Map(e.whereClauseConstraints)}}return{id:e.id,variables:[...e.variables,t],isBeginBlockFrame:e.isBeginBlockFrame,whereClauseConstraints:new Map(e.whereClauseConstraints)}}function Fh(e,t){return{id:e.id,variables:[...e.variables,t],isBeginBlockFrame:e.isBeginBlockFrame,whereClauseConstraints:e.whereClauseConstraints}}function Lh(e,t,n){let r=e.variables.filter(i=>i.name===t);return n?r.filter(n):r}function ae(e,t,n){let r=[];for(let i=0;i<e.frames.length;i++){let o=e.frames[i],a=Lh(o,t,n);r.push(...a)}return n?r.filter(n):r}function cr(e,t){let n=[];for(let r=0;r<e.frames.length;r++){let o=e.frames[r].variables.filter(t);n.push(...o)}return n}function ja(e,t){for(let n=e.frames.length-1;n>=0;n--)if(e.frames[n].variables.some(t))return n;return-1}function lt(e,t={id:cn(e.modulePath,"frame"),variables:[],isBeginBlockFrame:!1,whereClauseConstraints:new Map},n){let r=n?{...t,isBeginBlockFrame:!0}:t;return{functionDeclarationFrameLevel:e.functionDeclarationFrameLevel,frames:[...e.frames,r],modulePath:e.modulePath,inputString:e.inputString}}function Ot(e,t=!1){let n=e.frames.length-1,r=e.frames[n];if(!t){let i=ia(e),o=r.variables.filter(a=>!a.initializedAtToken);if(i.length>0)throw Qt(i.map(a=>({token:a.token,errorMessage:`Variable "${a.name}" was not consumed. It is supposed to be consumed before going out of scope.
|
|
188
|
-
Typeof "${a.name}": ${M(a.type)}`})));if(o.length>0)throw Qt(o.map(a=>({token:a.token,errorMessage:`Variable "${a.name}" is undefined.`})))}return{functionDeclarationFrameLevel:e.functionDeclarationFrameLevel,frames:e.frames.slice(0,-1),modulePath:e.modulePath,inputString:e.inputString}}function bt(e,t,n){let r=e.frames.map(i=>{let o=i.variables.map(a=>a.id===t.id?n:a);return{...i,variables:o}});return{functionDeclarationFrameLevel:e.functionDeclarationFrameLevel,frames:r,modulePath:e.modulePath,inputString:e.inputString}}function Sc(e){var t,n;return{id:e.id,name:e.name,type:M(e.type),typeId:e.type.id,value:pt((t=e.value)==null?void 0:t[0]),isCompileTimeOnly:e.isCompileTimeOnly,isUndefined:!e.initializedAtToken,isOwningTheRcValue:!!e.isOwningTheRcValue,isOwningTheSameRcValueAs:(n=e.isOwningTheSameRcValueAs)==null?void 0:n.name,isReassignable:!!e.isReassignable,isConsumed:!!e.consumedAtToken}}function Nc({env:e,context:t,methodName:n,type:r}){let i=[];if(!r.trait)return i;let o=r.trait.fields.find(a=>a.label===n&&ne(a.type));if(o&&ne(o.type)){let a=o.assignedValue;Ie(a)&&(a=oe(o.type,{variableName:o.label,env:e,context:t})),i.push({type:o.type,value:a})}for(let a of r.trait.fields)if(a.label===""&&a.assignedValue&&tn(a.assignedValue)){let s=a.assignedValue,l=s.type,u=l.fields.findIndex(_=>_.label===n&&ne(_.type));if(u>=0){let _=l.fields[u];if(ne(_.type)){let c=s.fields[u],f=_.type;he(c)&&c.specializedType&&(f=c.specializedType),i.push({type:f,value:c})}}}if(i.length===0){let a=Dr({concreteType:r,methodName:n,env:e});i.push(...a)}return i}function Lu({env:e,context:t,methodName:n,receiverType:r,isInfixOperatorCall:i}){var f,p;let o=[],a=r;for(;je(a);)a=a.childType;function s(m,h){let y=m.fields.find(g=>g.label===n&&(ne(g.type)||ot(g.type)));if(y){let g;if(ne(y.type)){if(Ie(h))g=oe(y.type,{variableName:y.label,env:e,context:t});else if(tn(h)){let v=m.fields.findIndex(T=>T.label===y.label);g=h.fields[v]}o.push({type:y.type,value:g})}else if(Xe(y.type)){let v=y.assignedValue;wt(v)&&l(v)}}if(!y)for(let g of m.fields)ot(g.type)&&g.assignedValue&&s(g.type,g.assignedValue)}function l(m){let h=m.type.fields.findIndex(y=>y.label==="Call");if(h>=0){let y=m.type.fields[h];if(y.assignedValue){let g=y.assignedValue;Zn(g)?g.fields.forEach(v=>{o.push({type:v.type,value:v})}):o.push({type:g.type,value:g})}}}function u(m){let h=[];for(let y of m)if(ne(y.type)){if(y.type.parameters.length===0)continue;let v=y.type.parameters[0].type;if(!i&&je(v)){let $=v.childType,C=r;if((rn(r)||En(r)||on(r))&&(C=an({type:r,expectedType:void 0,expr:void 0,env:e})),le({type:$,env:y.type.env},{type:C,env:e},!0)){h.push({type:y.type,value:y.value,needsPointerConversion:!0});continue}}if(Me(v)){h.push(y);continue}if(Me(v)&&!Me(r)){h.push(y);continue}if(z(r)&&r.resolvedConcreteType&&!at(r)&&!Me(v)&&le({type:v,env:y.type.env},{type:r.resolvedConcreteType,env:e},!0)){h.push(y);continue}if(!Me(v)&&Me(r))continue;if(rn(r)||En(r)||on(r)){let $=an({type:r,expectedType:void 0,expr:void 0,env:e});if(le({type:v,env:y.type.env},{type:$,env:e},!0)){h.push(y);continue}}if(st(r)&&y.value===void 0){if(y.type.parameters.length>0&&y.type.SelfType){let C=y.type.parameters[0];if(C){let k=C.type;if(!en(k)&&!st(k)&&!je(k))continue}}let $=y.type.return.type;if(_i($,y.type.SelfType))continue}le({type:v,env:y.type.env},{type:r,env:e},!0)&&h.push(y)}else h.push(y);return h}function _(m,h,y=new Set){if(y.has(m.id))return;y.add(m.id);let g=m.fields.find(v=>v.label===h&&ne(v.type));if(g&&ne(g.type)){let v=g.assignedValue;Ie(v)&&(v=oe(g.type,{variableName:g.label,env:e,context:t})),o.push({type:g.type,value:v});return}for(let v of m.fields)ot(v.type)&&v.assignedValue&&s(v.type,v.assignedValue)}if(r!==a&&r.trait){let m=r.trait.fields.find(h=>h.label===n&&ne(h.type));if(m&&ne(m.type)){let h=m.assignedValue;Ie(h)&&(h=oe(m.type,{variableName:m.label,env:e,context:t})),o.push({type:m.type,value:h})}else _(r.trait,n);for(let h of r.trait.fields)if(h.label===""&&h.assignedValue&&tn(h.assignedValue)){let y=h.assignedValue,g=y.type,v=g.fields.findIndex(T=>T.label===n&&ne(T.type));if(v>=0){let T=g.fields[v];if(ne(T.type)){let $=y.fields[v],C=T.type;he($)&&$.specializedType&&(C=$.specializedType),o.push({type:C,value:$})}}}}if(o.length===0&&r!==a){let m=Dr({concreteType:r,methodName:n,env:e});o.push(...m)}let c=z(a)&&a.resolvedConcreteType&&!at(a);if(a.trait&&!st(a)&&!c){let m=a.trait.fields.find(h=>h.label===n&&(ne(h.type)||Xe(h.type)));if(m&&ne(m.type)){let h=m.assignedValue;Ie(h)&&(h=oe(m.type,{variableName:m.label,env:e,context:t})),o.push({type:m.type,value:h})}else if(m&&Xe(m.type)){let h=m.assignedValue;wt(h)&&l(h)}else _(a.trait,n);for(let h of a.trait.fields)if(h.label===""&&h.assignedValue&&tn(h.assignedValue)){let y=h.assignedValue,g=y.type,v=g.fields.findIndex(T=>T.label===n&&ne(T.type));if(v>=0){let T=g.fields[v];if(ne(T.type)){let $=y.fields[v],C=T.type;he($)&&$.specializedType&&(C=$.specializedType),o.push({type:C,value:$})}}}if(o.length===0){let h=Dr({concreteType:a,methodName:n,env:e});o.push(...h)}}if(o.length===0&&Ci(a)){let m=bh(e,a);if(m)for(let h of m.requiredTraits)_(h,n)}if(rn(a)||En(a)||on(a)){let m=an({type:a,expectedType:void 0,expr:void 0,env:e});if(m.trait){let h=m.trait.fields.find(y=>y.label===n&&ne(y.type));if(h&&ne(h.type)){let y=h.assignedValue;Ie(y)&&(y=oe(h.type,{variableName:h.label,env:e,context:t})),o.push({type:h.type,value:y})}else _(m.trait,n);for(let y of m.trait.fields)if(y.label===""&&y.assignedValue&&tn(y.assignedValue)){let g=y.assignedValue,v=g.type,T=v.fields.findIndex($=>$.label===n&&ne($.type));if(T>=0){let $=v.fields[T];if(ne($.type)){let C=g.fields[T],k=$.type;he(C)&&C.specializedType&&(k=C.specializedType),o.push({type:k,value:C})}}}if(o.length===0){let y=Dr({concreteType:m,methodName:n,env:e});o.push(...y)}}}if(z(a)){if((f=a.resolvedConcreteType)!=null&&f.trait&&!at(a)){let m=a.resolvedConcreteType,h=m.trait,y=h==null?void 0:h.fields.find(g=>g.label===n&&ne(g.type));if(y&&ne(y.type)){let g=y.assignedValue||oe(y.type,{variableName:y.label,env:e,context:t});o.push({type:y.type,value:g})}if(o.length===0){let g=new Set;if(z(a)){let v=wr(e,a);if(v)for(let T of v.requiredTraits)g.add(T.id)}for(let v of(h==null?void 0:h.fields)??[])if(v.label===""&&v.assignedValue&&tn(v.assignedValue)){let T=v.assignedValue,$=T.type;if(g.size>0&&!g.has($.id))continue;let C=$.fields.findIndex(k=>k.label===n&&ne(k.type));if(C>=0){let k=$.fields[C];if(ne(k.type)){let b=T.fields[C],w=k.type;he(b)&&b.specializedType&&(w=b.specializedType),o.push({type:w,value:b});break}}}}if(o.length===0){let g=Dr({concreteType:m,methodName:n,env:e});o.push(...g)}}if(!(o.length>0)){let m=[],h=new Set;for(let g of a.requiredTraits??[])h.has(g.traitType.id)||(h.add(g.traitType.id),m.push(g.traitType));let y=wr(e,a);if(y)for(let g of y.requiredTraits)h.has(g.id)||(h.add(g.id),m.push(g));if(z(a))for(let g=e.frames.length-1;g>=0;g--){let v=e.frames[g];for(let T of v.whereClauseConstraints.values())if(le({type:T.someType,env:e},{type:a,env:e},!1))for(let $ of T.requiredTraits)h.has($.id)||(h.add($.id),m.push($))}for(let g of m){let v=g.fields.find(T=>T.label===n&&ne(T.type));if(v&&ne(v.type)){let T={...v.type,SelfType:a},$=!1;if(T.parameters.length>0&&je(T.parameters[0].type)){let b=T.parameters[0].type.childType;(z(b)&&b.name==="Self"||le({type:b,env:T.env},{type:r,env:e},!0))&&($=!0)}let C;if(z(a)){let b=a.definitionFrameLevel;if(b!==void 0&&b>=0){let w=e.frames[b];if(w){let A=w.variables.find(L=>L.name===a.name&&L.value&&W(L.value[0]));if(A!=null&&A.value&&W(A.value[0])){let L=A.value[0].value;if(L!==a&&!z(L)&&L.trait){for(let N of L.trait.fields)if(N.label===""&&N.assignedValue&&tn(N.assignedValue)&&N.assignedValue.type.id===g.id){let x=N.assignedValue.type.fields.findIndex(V=>V.label===n&&ne(V.type));x>=0&&(C=N.assignedValue.fields[x]??((p=N.assignedValue.type.fields[x])==null?void 0:p.assignedValue));break}}}}}}let k=C??oe(T,{variableName:v.label,env:e,context:t});o.push({type:T,value:k,needsPointerConversion:$})}}if(o.length===0){for(let g of a.trait.fields)if(g.label===""&&g.assignedValue&&W(g.assignedValue)&&ot(g.assignedValue.value)){let T=g.assignedValue.value.fields.find($=>$.label===n&&ne($.type));if(T&&ne(T.type)){let $=oe(T.type,{variableName:T.label,env:e,context:t});o.push({type:T.type,value:$})}}}}}if(st(a)){let m=a.trait.fields.find(y=>y.label===n&&(ne(y.type)||ot(y.type)));if(m&&ne(m.type)){let y=m.assignedValue||oe(m.type,{variableName:m.label,env:e,context:t});o.push({type:m.type,value:y})}let h=a.requiredTraits;for(let{traitType:y}of h){let g=y.fields.find(v=>v.label===n&&(ne(v.type)||ot(v.type)));g&&ne(g.type)&&g.type.parameters.length>0&&(Me(g.type.parameters[0].type)||Me(r)||le({type:g.type.parameters[0].type,env:g.type.env},{type:r,env:e},!0))&&o.push({type:g.type,value:void 0})}}return o.length>0,u(o)}function Vc(e){let t=e.frames.map(n=>({...n,variables:n.variables.filter(r=>!r.isImplicit)}));return{...e,frames:t}}function kl(e){let t=e.frames.map((n,r)=>{if(r===0)return n;let i=n.variables.filter(o=>!(!o.isCompileTimeOnly||o.isImplicit));return{...n,variables:i}});return{functionDeclarationFrameLevel:e.functionDeclarationFrameLevel,frames:t,modulePath:e.modulePath,inputString:e.inputString}}function ia(e){return e.frames.length===0?[]:e.frames[e.frames.length-1].variables.filter(r=>{if(r.consumedAtToken||!r.isOwningTheRcValue||!it(r.type)||r.isModuleLevel)return!1;let i=r.type;return!(z(i)&&!i.resolvedConcreteType&&i.requiredTraits.length===0)}).reverse()}function Ih(e){var t;for(let n=e.frames.length-1;n>=0;n--)if((t=e.frames[n])!=null&&t.isBeginBlockFrame)return n;return-1}var Ah=process.env.YO_SKIP_PRELUDE==="1"||process.env.YO_SKIP_PRELUDE==="true";function Sh(e,t){return e.some(n=>(n.type==="single_line_comment"||n.type==="multi_line_comment"||n.type==="doc_line_comment"||n.type==="inner_doc_line_comment"||n.type==="doc_block_comment"||n.type==="inner_doc_block_comment")&&n.value.includes(t))}var Ka=class{constructor({modulePath:t,stdPath:n,loadModule:r,inputString:i,allowPartialModule:o=!1,registerPartialModule:a}){if(this.modulePath=t,this.allowPartialModule=o,this.registerPartialModule=a,!this.modulePath.match(/^file:\/\//))throw new Error(`Invalid file protocol: ${this.modulePath}. Only file:// is supported for now. `);try{if(this.inputString=i??(0,xc.readFileSync)(t.replace(/^file:\/\//,""),"utf-8"),this.parser=new ao({modulePath:t,inputString:this.inputString}),this.program=this.parser.getProgram(),this.tokens=this.parser.getTokens(),!this.allowPartialModule&&this.parser.getParserError())throw this.parser.getParserError();this.evaluateProgram(n,r)}catch(s){throw new Error(`Failed to import module "${t}":
|
|
188
|
+
Typeof "${a.name}": ${M(a.type)}`})));if(o.length>0)throw Qt(o.map(a=>({token:a.token,errorMessage:`Variable "${a.name}" is undefined.`})))}return{functionDeclarationFrameLevel:e.functionDeclarationFrameLevel,frames:e.frames.slice(0,-1),modulePath:e.modulePath,inputString:e.inputString}}function bt(e,t,n){let r=e.frames.map(i=>{let o=i.variables.map(a=>a.id===t.id?n:a);return{...i,variables:o}});return{functionDeclarationFrameLevel:e.functionDeclarationFrameLevel,frames:r,modulePath:e.modulePath,inputString:e.inputString}}function Sc(e){var t,n;return{id:e.id,name:e.name,type:M(e.type),typeId:e.type.id,value:pt((t=e.value)==null?void 0:t[0]),isCompileTimeOnly:e.isCompileTimeOnly,isUndefined:!e.initializedAtToken,isOwningTheRcValue:!!e.isOwningTheRcValue,isOwningTheSameRcValueAs:(n=e.isOwningTheSameRcValueAs)==null?void 0:n.name,isReassignable:!!e.isReassignable,isConsumed:!!e.consumedAtToken}}function Nc({env:e,context:t,methodName:n,type:r}){let i=[];if(!r.trait)return i;let o=r.trait.fields.find(a=>a.label===n&&ne(a.type));if(o&&ne(o.type)){let a=o.assignedValue;Ie(a)&&(a=oe(o.type,{variableName:o.label,env:e,context:t})),i.push({type:o.type,value:a})}for(let a of r.trait.fields)if(a.label===""&&a.assignedValue&&tn(a.assignedValue)){let s=a.assignedValue,l=s.type,u=l.fields.findIndex(_=>_.label===n&&ne(_.type));if(u>=0){let _=l.fields[u];if(ne(_.type)){let c=s.fields[u],f=_.type;ge(c)&&c.specializedType&&(f=c.specializedType),i.push({type:f,value:c})}}}if(i.length===0){let a=Dr({concreteType:r,methodName:n,env:e});i.push(...a)}return i}function Lu({env:e,context:t,methodName:n,receiverType:r,isInfixOperatorCall:i}){var f,p;let o=[],a=r;for(;je(a);)a=a.childType;function s(m,h){let y=m.fields.find(g=>g.label===n&&(ne(g.type)||ot(g.type)));if(y){let g;if(ne(y.type)){if(Ie(h))g=oe(y.type,{variableName:y.label,env:e,context:t});else if(tn(h)){let v=m.fields.findIndex(T=>T.label===y.label);g=h.fields[v]}o.push({type:y.type,value:g})}else if(Xe(y.type)){let v=y.assignedValue;wt(v)&&l(v)}}if(!y)for(let g of m.fields)ot(g.type)&&g.assignedValue&&s(g.type,g.assignedValue)}function l(m){let h=m.type.fields.findIndex(y=>y.label==="Call");if(h>=0){let y=m.type.fields[h];if(y.assignedValue){let g=y.assignedValue;Zn(g)?g.fields.forEach(v=>{o.push({type:v.type,value:v})}):o.push({type:g.type,value:g})}}}function u(m){let h=[];for(let y of m)if(ne(y.type)){if(y.type.parameters.length===0)continue;let v=y.type.parameters[0].type;if(!i&&je(v)){let $=v.childType,C=r;if((rn(r)||En(r)||on(r))&&(C=an({type:r,expectedType:void 0,expr:void 0,env:e})),le({type:$,env:y.type.env},{type:C,env:e},!0)){h.push({type:y.type,value:y.value,needsPointerConversion:!0});continue}}if(Me(v)){h.push(y);continue}if(Me(v)&&!Me(r)){h.push(y);continue}if(z(r)&&r.resolvedConcreteType&&!at(r)&&!Me(v)&&le({type:v,env:y.type.env},{type:r.resolvedConcreteType,env:e},!0)){h.push(y);continue}if(!Me(v)&&Me(r))continue;if(rn(r)||En(r)||on(r)){let $=an({type:r,expectedType:void 0,expr:void 0,env:e});if(le({type:v,env:y.type.env},{type:$,env:e},!0)){h.push(y);continue}}if(st(r)&&y.value===void 0){if(y.type.parameters.length>0&&y.type.SelfType){let C=y.type.parameters[0];if(C){let k=C.type;if(!en(k)&&!st(k)&&!je(k))continue}}let $=y.type.return.type;if(_i($,y.type.SelfType))continue}le({type:v,env:y.type.env},{type:r,env:e},!0)&&h.push(y)}else h.push(y);return h}function _(m,h,y=new Set){if(y.has(m.id))return;y.add(m.id);let g=m.fields.find(v=>v.label===h&&ne(v.type));if(g&&ne(g.type)){let v=g.assignedValue;Ie(v)&&(v=oe(g.type,{variableName:g.label,env:e,context:t})),o.push({type:g.type,value:v});return}for(let v of m.fields)ot(v.type)&&v.assignedValue&&s(v.type,v.assignedValue)}if(r!==a&&r.trait){let m=r.trait.fields.find(h=>h.label===n&&ne(h.type));if(m&&ne(m.type)){let h=m.assignedValue;Ie(h)&&(h=oe(m.type,{variableName:m.label,env:e,context:t})),o.push({type:m.type,value:h})}else _(r.trait,n);for(let h of r.trait.fields)if(h.label===""&&h.assignedValue&&tn(h.assignedValue)){let y=h.assignedValue,g=y.type,v=g.fields.findIndex(T=>T.label===n&&ne(T.type));if(v>=0){let T=g.fields[v];if(ne(T.type)){let $=y.fields[v],C=T.type;ge($)&&$.specializedType&&(C=$.specializedType),o.push({type:C,value:$})}}}}if(o.length===0&&r!==a){let m=Dr({concreteType:r,methodName:n,env:e});o.push(...m)}let c=z(a)&&a.resolvedConcreteType&&!at(a);if(a.trait&&!st(a)&&!c){let m=a.trait.fields.find(h=>h.label===n&&(ne(h.type)||Xe(h.type)));if(m&&ne(m.type)){let h=m.assignedValue;Ie(h)&&(h=oe(m.type,{variableName:m.label,env:e,context:t})),o.push({type:m.type,value:h})}else if(m&&Xe(m.type)){let h=m.assignedValue;wt(h)&&l(h)}else _(a.trait,n);for(let h of a.trait.fields)if(h.label===""&&h.assignedValue&&tn(h.assignedValue)){let y=h.assignedValue,g=y.type,v=g.fields.findIndex(T=>T.label===n&&ne(T.type));if(v>=0){let T=g.fields[v];if(ne(T.type)){let $=y.fields[v],C=T.type;ge($)&&$.specializedType&&(C=$.specializedType),o.push({type:C,value:$})}}}if(o.length===0){let h=Dr({concreteType:a,methodName:n,env:e});o.push(...h)}}if(o.length===0&&Ci(a)){let m=bh(e,a);if(m)for(let h of m.requiredTraits)_(h,n)}if(rn(a)||En(a)||on(a)){let m=an({type:a,expectedType:void 0,expr:void 0,env:e});if(m.trait){let h=m.trait.fields.find(y=>y.label===n&&ne(y.type));if(h&&ne(h.type)){let y=h.assignedValue;Ie(y)&&(y=oe(h.type,{variableName:h.label,env:e,context:t})),o.push({type:h.type,value:y})}else _(m.trait,n);for(let y of m.trait.fields)if(y.label===""&&y.assignedValue&&tn(y.assignedValue)){let g=y.assignedValue,v=g.type,T=v.fields.findIndex($=>$.label===n&&ne($.type));if(T>=0){let $=v.fields[T];if(ne($.type)){let C=g.fields[T],k=$.type;ge(C)&&C.specializedType&&(k=C.specializedType),o.push({type:k,value:C})}}}if(o.length===0){let y=Dr({concreteType:m,methodName:n,env:e});o.push(...y)}}}if(z(a)){if((f=a.resolvedConcreteType)!=null&&f.trait&&!at(a)){let m=a.resolvedConcreteType,h=m.trait,y=h==null?void 0:h.fields.find(g=>g.label===n&&ne(g.type));if(y&&ne(y.type)){let g=y.assignedValue||oe(y.type,{variableName:y.label,env:e,context:t});o.push({type:y.type,value:g})}if(o.length===0){let g=new Set;if(z(a)){let v=wr(e,a);if(v)for(let T of v.requiredTraits)g.add(T.id)}for(let v of(h==null?void 0:h.fields)??[])if(v.label===""&&v.assignedValue&&tn(v.assignedValue)){let T=v.assignedValue,$=T.type;if(g.size>0&&!g.has($.id))continue;let C=$.fields.findIndex(k=>k.label===n&&ne(k.type));if(C>=0){let k=$.fields[C];if(ne(k.type)){let b=T.fields[C],w=k.type;ge(b)&&b.specializedType&&(w=b.specializedType),o.push({type:w,value:b});break}}}}if(o.length===0){let g=Dr({concreteType:m,methodName:n,env:e});o.push(...g)}}if(!(o.length>0)){let m=[],h=new Set;for(let g of a.requiredTraits??[])h.has(g.traitType.id)||(h.add(g.traitType.id),m.push(g.traitType));let y=wr(e,a);if(y)for(let g of y.requiredTraits)h.has(g.id)||(h.add(g.id),m.push(g));if(z(a))for(let g=e.frames.length-1;g>=0;g--){let v=e.frames[g];for(let T of v.whereClauseConstraints.values())if(le({type:T.someType,env:e},{type:a,env:e},!1))for(let $ of T.requiredTraits)h.has($.id)||(h.add($.id),m.push($))}for(let g of m){let v=g.fields.find(T=>T.label===n&&ne(T.type));if(v&&ne(v.type)){let T={...v.type,SelfType:a},$=!1;if(T.parameters.length>0&&je(T.parameters[0].type)){let b=T.parameters[0].type.childType;(z(b)&&b.name==="Self"||le({type:b,env:T.env},{type:r,env:e},!0))&&($=!0)}let C;if(z(a)){let b=a.definitionFrameLevel;if(b!==void 0&&b>=0){let w=e.frames[b];if(w){let A=w.variables.find(L=>L.name===a.name&&L.value&&W(L.value[0]));if(A!=null&&A.value&&W(A.value[0])){let L=A.value[0].value;if(L!==a&&!z(L)&&L.trait){for(let N of L.trait.fields)if(N.label===""&&N.assignedValue&&tn(N.assignedValue)&&N.assignedValue.type.id===g.id){let x=N.assignedValue.type.fields.findIndex(V=>V.label===n&&ne(V.type));x>=0&&(C=N.assignedValue.fields[x]??((p=N.assignedValue.type.fields[x])==null?void 0:p.assignedValue));break}}}}}}let k=C??oe(T,{variableName:v.label,env:e,context:t});o.push({type:T,value:k,needsPointerConversion:$})}}if(o.length===0){for(let g of a.trait.fields)if(g.label===""&&g.assignedValue&&W(g.assignedValue)&&ot(g.assignedValue.value)){let T=g.assignedValue.value.fields.find($=>$.label===n&&ne($.type));if(T&&ne(T.type)){let $=oe(T.type,{variableName:T.label,env:e,context:t});o.push({type:T.type,value:$})}}}}}if(st(a)){let m=a.trait.fields.find(y=>y.label===n&&(ne(y.type)||ot(y.type)));if(m&&ne(m.type)){let y=m.assignedValue||oe(m.type,{variableName:m.label,env:e,context:t});o.push({type:m.type,value:y})}let h=a.requiredTraits;for(let{traitType:y}of h){let g=y.fields.find(v=>v.label===n&&(ne(v.type)||ot(v.type)));g&&ne(g.type)&&g.type.parameters.length>0&&(Me(g.type.parameters[0].type)||Me(r)||le({type:g.type.parameters[0].type,env:g.type.env},{type:r,env:e},!0))&&o.push({type:g.type,value:void 0})}}return o.length>0,u(o)}function Vc(e){let t=e.frames.map(n=>({...n,variables:n.variables.filter(r=>!r.isImplicit)}));return{...e,frames:t}}function kl(e){let t=e.frames.map((n,r)=>{if(r===0)return n;let i=n.variables.filter(o=>!(!o.isCompileTimeOnly||o.isImplicit));return{...n,variables:i}});return{functionDeclarationFrameLevel:e.functionDeclarationFrameLevel,frames:t,modulePath:e.modulePath,inputString:e.inputString}}function ia(e){return e.frames.length===0?[]:e.frames[e.frames.length-1].variables.filter(r=>{if(r.consumedAtToken||!r.isOwningTheRcValue||!it(r.type)||r.isModuleLevel)return!1;let i=r.type;return!(z(i)&&!i.resolvedConcreteType&&i.requiredTraits.length===0)}).reverse()}function Ih(e){var t;for(let n=e.frames.length-1;n>=0;n--)if((t=e.frames[n])!=null&&t.isBeginBlockFrame)return n;return-1}var Ah=process.env.YO_SKIP_PRELUDE==="1"||process.env.YO_SKIP_PRELUDE==="true";function Sh(e,t){return e.some(n=>(n.type==="single_line_comment"||n.type==="multi_line_comment"||n.type==="doc_line_comment"||n.type==="inner_doc_line_comment"||n.type==="doc_block_comment"||n.type==="inner_doc_block_comment")&&n.value.includes(t))}var Ka=class{constructor({modulePath:t,stdPath:n,loadModule:r,inputString:i,allowPartialModule:o=!1,registerPartialModule:a}){if(this.modulePath=t,this.allowPartialModule=o,this.registerPartialModule=a,!this.modulePath.match(/^file:\/\//))throw new Error(`Invalid file protocol: ${this.modulePath}. Only file:// is supported for now. `);try{if(this.inputString=i??(0,xc.readFileSync)(t.replace(/^file:\/\//,""),"utf-8"),this.parser=new ao({modulePath:t,inputString:this.inputString}),this.program=this.parser.getProgram(),this.tokens=this.parser.getTokens(),!this.allowPartialModule&&this.parser.getParserError())throw this.parser.getParserError();this.evaluateProgram(n,r)}catch(s){throw new Error(`Failed to import module "${t}":
|
|
189
189
|
${s instanceof pr||s instanceof Nr?s.toString():s instanceof Error?s.message:String(s)}`)}}getProgram(){return this.program}getTokens(){return this.tokens}evaluateProgram(t,n){var _,c;let r=ku({modulePath:this.modulePath,inputString:this.inputString});if(!Sh(this.tokens,"@skip_prelude")&&!Ah){let f="file://"+Dc.default.join(t,"prelude.yo"),{moduleValue:p,moduleError:m}=n(f);if(m)throw m;if(p&&Xe(p.type)){r=lt(r);for(let h=0;h<p.type.fields.length;h++){let y=p.type.fields[h],g=p.fields[h],{env:v}=xe({env:r,variable:{name:y.label,type:y.type,value:g?[g]:void 0,isCompileTimeOnly:!0,initializedAtToken:((_=y.exprs.labelExpr)==null?void 0:_.token)??y.exprs.expr.token,consumedAtToken:void 0,token:((c=y.exprs.labelExpr)==null?void 0:c.token)??y.exprs.expr.token,isOwningTheRcValue:!1}});r=v}}Ac(r)}let o=cc(this.tokens),a=new Map;for(let f of o.declarations)f.declarationPosition&&a.set(ur({position:f.declarationPosition,modulePath:f.comment.modulePath}),f.comment.content);let{moduleValue:s,env:l,partialModuleError:u}=gl({beginExprs:this.program,env:r,context:{isExecuting:!0,expectedType:void 0,SelfType:void 0,loadModule:n.bind(this),stdPath:t,currentModulePath:this.modulePath,docCommentLookup:a},allowPartialModule:this.allowPartialModule,registerPartialModule:this.registerPartialModule});r=l,this.env=r,this.moduleValue=s,this.moduleError=u}getModuleValue(){if(!this.moduleValue)throw new Error("Module value is not set");return this.moduleValue}getModuleError(){return this.parser.getParserError()??this.moduleError}getEnv(){if(!this.env)throw new Error("Evaluator environment is not set");return this.env}};function Nh(...e){process.env.NODE_ENV!=="production"&&process.env.DEBUG&&console.log(...e)}var hg=require("fs"),ps=Or(require("path"));var zc=Or(require("fs"));function Vh(e){switch(e){case"x86_64":case"aarch64":return 64;case"x86":case"arm":case"wasm32":return 32}}var Mc={darwin:"macos",linux:"linux",win32:"windows",freebsd:"freebsd"},Oc={x64:"x86_64",arm64:"aarch64",ia32:"x86",arm:"arm"},wl;function xh(){if(wl)return wl;let e=Mc[process.platform];if(!e)throw new Error(`Unsupported host platform: ${process.platform}. Supported: ${Object.keys(Mc).join(", ")}`);let t=Oc[process.arch];if(!t)throw new Error(`Unsupported host architecture: ${process.arch}. Supported: ${Object.keys(Oc).join(", ")}`);return wl={platform:e,arch:t},wl}function Dh(){if(process.platform!=="linux")return"gnu";try{if(zc.readdirSync("/lib").some(n=>n.startsWith("ld-musl-")))return"musl"}catch{}return"gnu"}function Bc(e){switch(e){case"linux":return Dh();case"windows":return"msvc";case"wasi":case"emscripten":return"wasm";case"macos":case"freebsd":return}}function Mh(e,t,n){return n?`${e}-${t}-${n}`:`${e}-${t}`}function Gc(e,t,n){return{arch:e,os:t,abi:n,pointerSizeBits:Vh(e),triple:Mh(e,t,n)}}function Xi(){let e=xh(),t=Bc(e.platform);return Gc(e.arch,e.platform,t)}var Rc=new Set(["x86_64","aarch64","x86","arm","wasm32"]),Pc=new Set(["linux","macos","windows","freebsd","wasi","emscripten"]),Uc=new Set(["gnu","musl","msvc","none","wasm"]);function Wc(e){let n=(e.startsWith("wasm-")?`wasm32-${e.slice(5)}`:e).split("-");if(n.length<2||n.length>3)throw new Error(`Invalid target triple "${e}". Expected format: <arch>-<os> or <arch>-<os>-<abi>. Example: x86_64-linux-gnu`);let r=n[0],i=n[1],o=n[2];if(!Rc.has(r))throw new Error(`Unknown architecture "${r}" in target triple "${e}". Supported: ${[...Rc].join(", ")}`);if(!Pc.has(i))throw new Error(`Unknown OS "${i}" in target triple "${e}". Supported: ${[...Pc].join(", ")}`);let a=r,s=i,l;if(o!==void 0)if(o==="none")l=void 0;else if(Uc.has(o))l=o;else throw new Error(`Unknown ABI "${o}" in target triple "${e}". Supported: ${[...Uc].join(", ")}`);else l=Bc(s);return Gc(a,s,l)}var Iu;function Xa(){return Iu||(Iu=Xi()),Iu}function Sn(e){return e.os==="windows"}function bo(e){return e.os==="linux"}function Br(e){return e.os==="macos"}function Gr(e){return e.arch==="wasm32"||e.os==="wasi"||e.os==="emscripten"}function qc(e){return e.os==="wasi"}function Yc(e){for(let t in e.types){let{type:n}=e.types[t];n.cInclude&&e.cIncludes.add(n.cInclude)}for(let t in e.externFunctions){let{type:n}=e.externFunctions[t];n.cInclude&&e.cIncludes.add(n.cInclude)}}function Hc(e){let t=Sn(e.targetInfo);t?(e.emitter.emitHeaderLine("#ifndef WIN32_LEAN_AND_MEAN"),e.emitter.emitHeaderLine("#define WIN32_LEAN_AND_MEAN"),e.emitter.emitHeaderLine("#endif"),e.emitter.emitHeaderLine("#ifndef _WINSOCKAPI_"),e.emitter.emitHeaderLine("#define _WINSOCKAPI_"),e.emitter.emitHeaderLine("#endif")):(e.emitter.emitHeaderLine("#define _DEFAULT_SOURCE"),e.emitter.emitHeaderLine("#define _GNU_SOURCE // Needed for sched_getcpu() on Linux")),e.emitter.emitHeaderLine("");for(let n of e.cIncludes)e.emitter.emitHeaderLine(`#include ${n}`);t?(e.emitter.emitHeaderLine("#include <windows.h>"),e.emitter.emitHeaderLine("#include <bcrypt.h>"),e.emitter.emitHeaderLine("#include <io.h>"),e.emitter.emitHeaderLine("#include <sys/stat.h>")):(e.emitter.emitHeaderLine("#include <unistd.h>"),e.emitter.emitHeaderLine("#include <sys/stat.h>"),e.emitter.emitHeaderLine("#include <sys/random.h>")),e.emitter.emitHeaderLine(""),e.allocator==="mimalloc"?(e.emitter.emitHeaderLine("// Mimalloc compatibility layer - try mimalloc first, fallback to stdlib"),e.emitter.emitHeaderLine("#ifdef __has_include"),e.emitter.emitHeaderLine(" #if __has_include(<mimalloc.h>)"),e.emitter.emitHeaderLine(" #include <mimalloc.h>"),e.emitter.emitHeaderLine(" #define __yo_malloc mi_malloc"),e.emitter.emitHeaderLine(" #define __yo_calloc mi_calloc"),e.emitter.emitHeaderLine(" #define __yo_realloc mi_realloc"),e.emitter.emitHeaderLine(" #define __yo_free mi_free"),e.emitter.emitHeaderLine(" #define __yo_aligned_alloc mi_aligned_alloc"),e.emitter.emitHeaderLine(" #define __yo_aligned_free mi_free"),e.emitter.emitHeaderLine(" #else"),e.emitter.emitHeaderLine(" #define __yo_malloc malloc"),e.emitter.emitHeaderLine(" #define __yo_calloc calloc"),e.emitter.emitHeaderLine(" #define __yo_realloc realloc"),e.emitter.emitHeaderLine(" #define __yo_free free"),t?(e.emitter.emitHeaderLine(" static inline void* __yo_aligned_alloc(size_t alignment, size_t size) { return _aligned_malloc(size, alignment); }"),e.emitter.emitHeaderLine(" #define __yo_aligned_free _aligned_free")):(e.emitter.emitHeaderLine(" #define __yo_aligned_alloc aligned_alloc"),e.emitter.emitHeaderLine(" #define __yo_aligned_free free")),e.emitter.emitHeaderLine(" #endif"),e.emitter.emitHeaderLine("#else"),e.emitter.emitHeaderLine(" // Fallback for older compilers without __has_include"),e.emitter.emitHeaderLine(" #define __yo_malloc malloc"),e.emitter.emitHeaderLine(" #define __yo_calloc calloc"),e.emitter.emitHeaderLine(" #define __yo_realloc realloc"),e.emitter.emitHeaderLine(" #define __yo_free free"),t?(e.emitter.emitHeaderLine(" static inline void* __yo_aligned_alloc(size_t alignment, size_t size) { return _aligned_malloc(size, alignment); }"),e.emitter.emitHeaderLine(" #define __yo_aligned_free _aligned_free")):(e.emitter.emitHeaderLine(" #define __yo_aligned_alloc aligned_alloc"),e.emitter.emitHeaderLine(" #define __yo_aligned_free free")),e.emitter.emitHeaderLine("#endif")):(e.emitter.emitHeaderLine("// Using libc allocator"),e.emitter.emitHeaderLine("#define __yo_malloc malloc"),e.emitter.emitHeaderLine("#define __yo_calloc calloc"),e.emitter.emitHeaderLine("#define __yo_realloc realloc"),e.emitter.emitHeaderLine("#define __yo_free free"),t?(e.emitter.emitHeaderLine("static inline void* __yo_aligned_alloc(size_t alignment, size_t size) { return _aligned_malloc(size, alignment); }"),e.emitter.emitHeaderLine("#define __yo_aligned_free _aligned_free")):(e.emitter.emitHeaderLine("#define __yo_aligned_alloc aligned_alloc"),e.emitter.emitHeaderLine("#define __yo_aligned_free free"))),e.emitter.emitHeaderLine("")}function Ni(e){let{emitter:t,indent:n,resultCode:r,debugLabel:i}=e;r!==void 0&&t.emitLine(`${n}sm->result = ${r};`),i&&t.emitLine(`${n}ASYNC_DEBUG("${i}: Setting state to COMPLETED\\n");`),t.emitLine(`${n}sm->state = -1; // -1 = completed`),t.emitLine(""),t.emitLine(`${n}void (*continuation_fn)(void*) = (void (*)(void*))sm->continuation_fn;`),t.emitLine(`${n}void* continuation_sm = sm->continuation_sm;`),t.emitLine(""),t.emitLine(`${n}if (continuation_fn != NULL) {`),i&&t.emitLine(`${n} ASYNC_DEBUG("${i}: Spawning continuation: resume_fn=%p, sm=%p\\n", (void*)continuation_fn, continuation_sm);`),t.emitLine(""),t.emitLine(`${n} sm->continuation_fn = NULL;`),t.emitLine(`${n} sm->continuation_sm = NULL;`),t.emitLine(""),t.emitLine(`${n} __yo_async_spawn_task(continuation_fn, continuation_sm);`),t.emitLine(`${n}}`),t.emitLine(""),t.emitLine(`${n}__yo_decr_rc((void*)sm);`),t.emitLine(""),t.emitLine(`${n}return;`)}function Ar(e){let{emitter:t,indent:n,resultCode:r,debugLabel:i}=e;r!==void 0&&t.emitLine(`${n}sm->result = ${r};`),i&&t.emitLine(`${n}ASYNC_DEBUG("${i}: Setting state to ESCAPED (effect handler escape)\\n");`),t.emitLine(`${n}sm->state = -2; // -2 = escaped`),t.emitLine(""),t.emitLine(`${n}void (*continuation_fn)(void*) = (void (*)(void*))sm->continuation_fn;`),t.emitLine(`${n}void* continuation_sm = sm->continuation_sm;`),t.emitLine(""),t.emitLine(`${n}if (continuation_fn != NULL) {`),i&&t.emitLine(`${n} ASYNC_DEBUG("${i}: Spawning continuation for escaped future: resume_fn=%p, sm=%p\\n", (void*)continuation_fn, continuation_sm);`),t.emitLine(""),t.emitLine(`${n} sm->continuation_fn = NULL;`),t.emitLine(`${n} sm->continuation_sm = NULL;`),t.emitLine(""),t.emitLine(`${n} __yo_async_spawn_task(continuation_fn, continuation_sm);`),t.emitLine(`${n}}`),t.emitLine(""),t.emitLine(`${n}__yo_decr_rc((void*)sm);`),t.emitLine(""),t.emitLine(`${n}return;`)}var ko=[...F.__yo_op_add,...F.__yo_op_sub,...F.__yo_op_mul,...F.__yo_op_div,...F.__yo_op_mod,...F.__yo_op_neg,...F.__yo_op_eq,...F.__yo_op_neq,...F.__yo_op_lt,...F.__yo_op_lte,...F.__yo_op_gt,...F.__yo_op_gte,...F.__yo_op_not,...F.__yo_op_bit_and,...F.__yo_op_bit_or,...F.__yo_op_bit_xor,...F.__yo_op_bit_complement,...F.__yo_op_bit_left_shift,...F.__yo_op_bit_right_shift,...F.__yo_ptr_add,...F.__yo_ptr_sub,...F.__yo_ptr_diff,...F.__yo_ptr_eq,...F.__yo_ptr_neq,...F.__yo_ptr_lt,...F.__yo_ptr_lte,...F.__yo_ptr_gt,...F.__yo_ptr_gte,...F.__yo_slice_len,...F.__yo_slice_new,...F.__yo_slice_ptr,...F.__yo_as,...F.__yo_getrandom,...F.__yo_arc4random_buf,...F.__yo_bcrypt_gen_random,...F.__yo_getentropy,...F.__yo_maybe_uninit_new,...F.__yo_maybe_uninit_as_ptr,...F.__yo_maybe_uninit_assume_init,...F.__yo_array_index,...F.__yo_slice_index,...F.__yo_array_index_range,...F.__yo_array_index_range_inclusive,...F.__yo_slice_index_range,...F.__yo_slice_index_range_inclusive,...F.__yo_noop,...F.__yo_return_self,...F.__yo_ms_sleep],jc=new Set(["bool","usize","isize","u8","i8","u16","i16","u32","i32","u64","i64","f32","f64","char","short","ushort","int","uint","long","ulong","longlong","ulonglong","longdouble"]);function be(e,t=!1){let n=new Set(["auto","break","case","char","const","continue","default","do","double","else","enum","extern","float","for","goto","if","inline","int","long","register","restrict","return","short","signed","sizeof","static","struct","switch","typedef","union","unsigned","void","volatile","while","_Alignas","_Alignof","_Atomic","_Bool","_Complex","_Generic","_Imaginary","_Noreturn","_Static_assert","_Thread_local","errno","stdin","stdout","stderr","NULL","true","false"]),r=e.replace(/[^a-zA-Z0-9_]/g,i=>`_u${i.charCodeAt(0)}_`);return!t&&n.has(r)&&(r="__yo_c_reserved_"+r),r}function j(e,t){var n,r,i,o,a,s,l;if(!e)return"int32_t";if(e.isExtern&&e.externName)return e.externName;switch(e.tag){case"unit":return"void";case"void":return"void";case"bool":return"bool";case"usize":return"size_t";case"isize":return"intptr_t";case"u8":return"uint8_t";case"i8":return"int8_t";case"u16":return"uint16_t";case"i16":return"int16_t";case"u32":return"uint32_t";case"i32":return"int32_t";case"u64":return"uint64_t";case"i64":return"int64_t";case"f32":return"float";case"f64":return"double";case"comptime_int":return"int32_t";case"comptime_float":return"double";case"comptime_string":for(let u of Object.values(t.types))if(hr(u.type)&&u.type.fields.length===1&&$t(u.type.fields[0].type))return u.cName;return"uint8_t*";case"char":return"char";case"short":return"short";case"ushort":return"unsigned short";case"int":return"int";case"uint":return"unsigned int";case"long":return"long";case"ulong":return"unsigned long";case"longlong":return"long long";case"ulonglong":return"unsigned long long";case"longdouble":return"long double";case"Tuple":case"Struct":case"Union":case"Enum":{if(e.tag==="Enum"){let c=Gn(e);if(c)return j(c,t)}let u;switch(e.tag){case"Tuple":u="tuple";break;case"Struct":u="struct";break;case"Union":u="union";break;case"Enum":u="enum";break;default:throw new Error("Unreachable")}let _=(n=t.types[e.id])==null?void 0:n.cName;if(!_)throw new Error(`No C type name found for ${u} ${M(e)} (id=${e.id})`);return(e.tag==="Struct"||e.tag==="Enum")&&Ae(e)&&e.isReferenceSemantics?`${_}*`:_}case"Function":return"void*";case"Dyn":{let u=(r=t.types[e.id])==null?void 0:r.cName;if(!u)throw new Error(`No C type name found for dynamic dispatch type ${M(e)}`);return u}case"Array":{let u=e,_=u.childType,c=u.length;if(ht(c)){let f=j(_,t),p=`Array_${be(f)}_${c.value}`;return t.arrayStructTypes.has(p)||t.arrayStructTypes.set(p,{childType:f,length:typeof c.value=="bigint"?Number(c.value):c.value}),p}break}case"Slice":{let u=e,c=`Slice_${be(j(u.childType,t))}`;return t.sliceStructTypes.has(c)||t.sliceStructTypes.set(c,{childType:j(u.childType,t)}),c}case"SomeType":{let u=e;if(at(u)){if((i=u.resolvedConcreteType)!=null&&i.isExtern)return`${j(u.resolvedConcreteType,t)}*`;let _=(o=t.types[u.id])==null?void 0:o.cName;if(_)return`${_}*`;if(u.resolvedConcreteType&&z(u.resolvedConcreteType)&&at(u.resolvedConcreteType)){let f=u.resolvedConcreteType,p=(a=t.types[f.id])==null?void 0:a.cName;if(p)return`${p}*`}if(u.resolvedConcreteType&&Ae(u.resolvedConcreteType)){let f=u.resolvedConcreteType.id;for(let[p,m]of Object.entries(t.types))if(z(m.type)&&at(m.type)&&m.type.resolvedConcreteType&&Ae(m.type.resolvedConcreteType)&&m.type.resolvedConcreteType.id===f)return`${m.cName}*`}let c=Ln(u);if(c){let f=(s=t.types[c.id])==null?void 0:s.cName;if(f)return`${f}*`}throw new Error(`Impl(Future) type has no registered concrete type. SomeType ID: ${u.id}, FutureModule: ${(c==null?void 0:c.id)??"none"}. Ensure async blocks are properly analyzed and their state machine types are registered.
|
|
190
190
|
resolvedConcreteType: ${((l=u.resolvedConcreteType)==null?void 0:l.id)??"none"}
|
|
191
|
-
registered type IDs: ${Object.keys(t.types).filter(f=>f.startsWith("sometype")).join(", ")}`)}return zn(u)&&u.resolvedConcreteType||u.resolvedConcreteType?j(u.resolvedConcreteType,t):"void*"}case"Ptr":{let _=e.childType;if($t(_)){let p=j(_.childType,t),m=`Slice_${be(p)}`;return t.sliceStructTypes.has(m)||t.sliceStructTypes.set(m,{childType:p}),`${m}*`}let c=j(_,t);return en(_)?`${c}*`:Be(_)&&Gn(_)?`${c}*`:`${c}*`}case"Iso":{let u=e,_=u.childType,c=j(_,t),f=c.replace(/\*/g,"").trim(),p=`Iso_${be(f)}`;return t.isoTypes||(t.isoTypes=new Map),t.isoTypes.has(p)||t.isoTypes.set(p,{childTypeCName:c,isoType:u}),p}}return`// Unknown type: ${M(e)}`}function Kt(e,t,n){let r=be(t);return`${j(e,n)} ${r}`}function Rn(e,t,n){var i;let r=(i=n.types[e.id])==null?void 0:i.cName;if(!r)throw new Error(`No C type name found for enum ${e.typeName} (${M(e)})`);return`${r.toUpperCase()}_${t.toUpperCase()}`}function Qi(e){return e.type.return.isCompileTimeOnly}function gi(e){let t=e.body,n=null;return S(t)&&E(t,"begin")&&t.args.length===1&&S(t.args[0])&&E(t.args[0],ko)?n=t.args[0].func.token.value:S(t)&&E(t,ko)&&(n=t.func.token.value),n&&F.__yo_as.includes(n)?null:n}function Gn(e){if(e.variants.length!==2)return null;let t=null,n=null;for(let r of e.variants)if(!r.fields||r.fields.length===0){if(t)return null;t=r}else if(r.fields.length===1){let i=r.fields[0].type;if(je(i)){if(n)return null;n=r}else return null}else return null;return t&&n&&n.fields?n.fields[0].type:null}function Fr(e){for(let t of e.variants)if(t.fields&&t.fields.length>0)return!1;return e.variants.length>0}function We(e,t){if(!t)return be(e);let n=ae(t,e);if(n.length>0){let r=n[n.length-1];return be(r.name,r.type.isExtern==="c")}return be(e)}function Fl(e){if(S(e)&&e.args.length>=1){let t=e.args[0];if(t&&K(t))return t.token.value}if(S(e)&&e.args.length===0&&S(e.func)&&E(e.func,".",2)&&K(e.func.args[0])&&K(e.func.args[1])&&e.func.args[1].token.value===F.___dup[0])return e.func.args[0].token.value}function $r(e){if(S(e)&&e.args.length===0&&S(e.func)&&E(e.func,".",2)&&K(e.func.args[1])&&e.func.args[1].token.value===F.___drop[0]&&K(e.func.args[0]))return e.func.args[0].token.value;if(!S(e)||!E(e,F.___drop)||e.args.length<1)return;let t=e.args[0];if(!(!t||!K(t)))return t.token.value}function Qa(e){if(e){if(An(e))return e;if(S(e)){let t=e;for(let n of t.args){let r=Qa(n);if(r)return r}}}}var Au;function Kc(e){Au=e}function q(e,t,n){if(!Au)throw new Error("Internal Error: generateExpr function is not set.");return Au(e,t,n)}function Vi(e,t,n){let r=z(t)&&t.resolvedConcreteType?t.resolvedConcreteType:t;if(!it(r))return"";if(Je(r)){let i=r.length;if(!ht(i))return"/* Error: array has non-constant length */";let o=n.emitter;o.emitLine(`for (size_t i = 0; i < ${i.value}; i++) {`);let a=Vi(`(${e}).data[i]`,r.childType,n);return a&&o.emitLine(` ${a};`),o.emitLine("}"),""}if(ut(r)){let i=n.emitter;for(let o=0;o<r.fields.length;o++){let a=r.fields[o].type,s=z(a)&&a.resolvedConcreteType?a.resolvedConcreteType:a;if(it(s)){let l=Vi(`(${e})._${o}`,a,n);l&&i.emitLine(`${l};`)}}return""}if(st(r))return`__yo_decr_rc((void*)(${e}).data)`;if(oi(r))return`__yo_decr_rc_atomic((void*)(${e}))`;if(en(r))return`__yo_decr_rc((void*)(${e}))`;if(hn(r))return`__yo_decr_rc_atomic((void*)(${e}))`;if(Ae(r)||Be(r)){let i=Wr(r,n);if(i)return`${i}(${e})`}return""}function sa(e,t,n){let r=z(t)&&t.resolvedConcreteType?t.resolvedConcreteType:t;if(Je(r)){let i=r.length;if(!ht(i))return"/* Error: array has non-constant length */";let o=`temp_dup_${mt("")}`,a=`i_${mt("")}`,s=j(r,n),l=n.emitter;l.emitLine(`${s} ${o} = ${e};`),l.emitLine(`for (size_t ${a} = 0; ${a} < ${i.value}; ${a}++) {`);let u=sa(`${o}.data[${a}]`,r.childType,n);return l.emitLine(` ${o}.data[${a}] = ${u};`),l.emitLine("}"),o}if(ut(r)){let i=n.emitter,o=`temp_dup_tuple_${mt("")}`,a=j(r,n);i.emitLine(`${a} ${o} = ${e};`);for(let s=0;s<r.fields.length;s++){let l=r.fields[s].type,u=z(l)&&l.resolvedConcreteType?l.resolvedConcreteType:l;if(it(u)){let _=sa(`${o}._${s}`,l,n);i.emitLine(`${o}._${s} = ${_};`)}}return o}if(st(r))return`((${j(r,n)}){ .data = __yo_incr_rc((void*)(${e}).data), .vtable = (${e}).vtable })`;if(oi(r))return`((${j(r,n)})__yo_incr_rc_atomic((void*)(${e})))`;if(en(r))return`((${j(r,n)})__yo_incr_rc((void*)(${e})))`;if(hn(r))return`((${j(r,n)})__yo_incr_rc_atomic((void*)(${e})))`;if(Ae(r)||Be(r)){let i=fr(r,n);if(i)return`${i}(${e})`}return e}function Wr(e,t){var n;if(Ae(e)||Be(e)||st(e)||z(e)||hn(e)){let r=e.trait.fields.find(i=>i.label===F.___drop[0]);if(r&&r.assignedValue&&
|
|
191
|
+
registered type IDs: ${Object.keys(t.types).filter(f=>f.startsWith("sometype")).join(", ")}`)}return zn(u)&&u.resolvedConcreteType||u.resolvedConcreteType?j(u.resolvedConcreteType,t):"void*"}case"Ptr":{let _=e.childType;if($t(_)){let p=j(_.childType,t),m=`Slice_${be(p)}`;return t.sliceStructTypes.has(m)||t.sliceStructTypes.set(m,{childType:p}),`${m}*`}let c=j(_,t);return en(_)?`${c}*`:Be(_)&&Gn(_)?`${c}*`:`${c}*`}case"Iso":{let u=e,_=u.childType,c=j(_,t),f=c.replace(/\*/g,"").trim(),p=`Iso_${be(f)}`;return t.isoTypes||(t.isoTypes=new Map),t.isoTypes.has(p)||t.isoTypes.set(p,{childTypeCName:c,isoType:u}),p}}return`// Unknown type: ${M(e)}`}function Kt(e,t,n){let r=be(t);return`${j(e,n)} ${r}`}function Rn(e,t,n){var i;let r=(i=n.types[e.id])==null?void 0:i.cName;if(!r)throw new Error(`No C type name found for enum ${e.typeName} (${M(e)})`);return`${r.toUpperCase()}_${t.toUpperCase()}`}function Qi(e){return e.type.return.isCompileTimeOnly}function gi(e){let t=e.body,n=null;return S(t)&&E(t,"begin")&&t.args.length===1&&S(t.args[0])&&E(t.args[0],ko)?n=t.args[0].func.token.value:S(t)&&E(t,ko)&&(n=t.func.token.value),n&&F.__yo_as.includes(n)?null:n}function Gn(e){if(e.variants.length!==2)return null;let t=null,n=null;for(let r of e.variants)if(!r.fields||r.fields.length===0){if(t)return null;t=r}else if(r.fields.length===1){let i=r.fields[0].type;if(je(i)){if(n)return null;n=r}else return null}else return null;return t&&n&&n.fields?n.fields[0].type:null}function Fr(e){for(let t of e.variants)if(t.fields&&t.fields.length>0)return!1;return e.variants.length>0}function We(e,t){if(!t)return be(e);let n=ae(t,e);if(n.length>0){let r=n[n.length-1];return be(r.name,r.type.isExtern==="c")}return be(e)}function Fl(e){if(S(e)&&e.args.length>=1){let t=e.args[0];if(t&&K(t))return t.token.value}if(S(e)&&e.args.length===0&&S(e.func)&&E(e.func,".",2)&&K(e.func.args[0])&&K(e.func.args[1])&&e.func.args[1].token.value===F.___dup[0])return e.func.args[0].token.value}function $r(e){if(S(e)&&e.args.length===0&&S(e.func)&&E(e.func,".",2)&&K(e.func.args[1])&&e.func.args[1].token.value===F.___drop[0]&&K(e.func.args[0]))return e.func.args[0].token.value;if(!S(e)||!E(e,F.___drop)||e.args.length<1)return;let t=e.args[0];if(!(!t||!K(t)))return t.token.value}function Qa(e){if(e){if(An(e))return e;if(S(e)){let t=e;for(let n of t.args){let r=Qa(n);if(r)return r}}}}var Au;function Kc(e){Au=e}function q(e,t,n){if(!Au)throw new Error("Internal Error: generateExpr function is not set.");return Au(e,t,n)}function Vi(e,t,n){let r=z(t)&&t.resolvedConcreteType?t.resolvedConcreteType:t;if(!it(r))return"";if(Je(r)){let i=r.length;if(!ht(i))return"/* Error: array has non-constant length */";let o=n.emitter;o.emitLine(`for (size_t i = 0; i < ${i.value}; i++) {`);let a=Vi(`(${e}).data[i]`,r.childType,n);return a&&o.emitLine(` ${a};`),o.emitLine("}"),""}if(ut(r)){let i=n.emitter;for(let o=0;o<r.fields.length;o++){let a=r.fields[o].type,s=z(a)&&a.resolvedConcreteType?a.resolvedConcreteType:a;if(it(s)){let l=Vi(`(${e})._${o}`,a,n);l&&i.emitLine(`${l};`)}}return""}if(st(r))return`__yo_decr_rc((void*)(${e}).data)`;if(oi(r))return`__yo_decr_rc_atomic((void*)(${e}))`;if(en(r))return`__yo_decr_rc((void*)(${e}))`;if(hn(r))return`__yo_decr_rc_atomic((void*)(${e}))`;if(Ae(r)||Be(r)){let i=Wr(r,n);if(i)return`${i}(${e})`}return""}function sa(e,t,n){let r=z(t)&&t.resolvedConcreteType?t.resolvedConcreteType:t;if(Je(r)){let i=r.length;if(!ht(i))return"/* Error: array has non-constant length */";let o=`temp_dup_${mt("")}`,a=`i_${mt("")}`,s=j(r,n),l=n.emitter;l.emitLine(`${s} ${o} = ${e};`),l.emitLine(`for (size_t ${a} = 0; ${a} < ${i.value}; ${a}++) {`);let u=sa(`${o}.data[${a}]`,r.childType,n);return l.emitLine(` ${o}.data[${a}] = ${u};`),l.emitLine("}"),o}if(ut(r)){let i=n.emitter,o=`temp_dup_tuple_${mt("")}`,a=j(r,n);i.emitLine(`${a} ${o} = ${e};`);for(let s=0;s<r.fields.length;s++){let l=r.fields[s].type,u=z(l)&&l.resolvedConcreteType?l.resolvedConcreteType:l;if(it(u)){let _=sa(`${o}._${s}`,l,n);i.emitLine(`${o}._${s} = ${_};`)}}return o}if(st(r))return`((${j(r,n)}){ .data = __yo_incr_rc((void*)(${e}).data), .vtable = (${e}).vtable })`;if(oi(r))return`((${j(r,n)})__yo_incr_rc_atomic((void*)(${e})))`;if(en(r))return`((${j(r,n)})__yo_incr_rc((void*)(${e})))`;if(hn(r))return`((${j(r,n)})__yo_incr_rc_atomic((void*)(${e})))`;if(Ae(r)||Be(r)){let i=fr(r,n);if(i)return`${i}(${e})`}return e}function Wr(e,t){var n;if(Ae(e)||Be(e)||st(e)||z(e)||hn(e)){let r=e.trait.fields.find(i=>i.label===F.___drop[0]);if(r&&r.assignedValue&&ge(r.assignedValue))return(n=t.functions[r.assignedValue.funcId])==null?void 0:n.cName}}function fr(e,t){var n;if(Ae(e)||Be(e)||st(e)||z(e)||hn(e)){let r=e.trait.fields.find(i=>i.label===F.___dup[0]);if(r&&r.assignedValue&&ge(r.assignedValue))return(n=t.functions[r.assignedValue.funcId])==null?void 0:n.cName}}function fn(e,t,n){var i;let r=n.emitter;if((i=e.$)!=null&&i.deferredDropExpressions)for(let o of e.$.deferredDropExpressions){if(n.shortCircuitHandledDropVarNames){let s=$r(o);if(s&&n.shortCircuitHandledDropVarNames.has(s)){n.shortCircuitHandledDropVarNames.delete(s);continue}}let a=q(o,t,n);a&&r.emitLine(`${t}${a};`)}}function Wt(e,t,n){var i;let r=n.emitter;if((i=e.$)!=null&&i.deferredDupExpressions){for(let o of e.$.deferredDupExpressions)if(S(o)){let a=q(o,t,n);a&&r.emitLine(`${t}${a};`)}}}function Yn(e,t,n){var r,i,o,a,s,l,u,_;if(ht(e)){let c=(typeof e.value=="bigint",e.value.toString());return e.tag==="F32"?(c.includes(".")?c:c+".0")+"f":e.tag==="F64"||e.tag==="ComptimeFloat"?c.includes(".")?c:c+".0":e.tag==="U64"||e.tag==="Usize"?c+"ULL":e.tag==="I64"||e.tag==="Isize"?c+"LL":e.tag==="U32"?c+"U":c}else{if(Ct(e))return e.value?"true":"false";if(tt(e)){let c=((r=n==null?void 0:n.$)==null?void 0:r.convertedRuntimeType)||((i=n==null?void 0:n.$)==null?void 0:i.type);if(c&&hr(c)&&c.fields.length===1){let f=c.fields[0].type;if($t(f)){let p=j(c,t),m=JSON.stringify(e.value),h=Buffer.byteLength(e.value,"utf8");return`(${p}){ .data = (uint8_t*)${m}, .length = ${h} }`}}if(c&&$t(c)){let f=j(c,t),p=JSON.stringify(e.value),m=Buffer.byteLength(e.value,"utf8");return`(${f}){ .data = (uint8_t*)${p}, .length = ${m} }`}if(!c||on(c)){for(let f of Object.values(t.types))if(hr(f.type)&&f.type.fields.length===1&&$t(f.type.fields[0].type)){let p=JSON.stringify(e.value),m=Buffer.byteLength(e.value,"utf8");return`(${f.cName}){ .data = (uint8_t*)${p}, .length = ${m} }`}}return JSON.stringify(e.value)}else if(mn(e)){let c=e.type,f=Gn(c);if(f){let y=c.variants.find(g=>g.name===e.variantName);if(!y)return`// Error: Variant ${e.variantName} not found in enum`;if(!y.fields||y.fields.length===0)return"NULL";if(y.fields.length===1&&e.fields.length===1)return Yn(e.fields[0],t,{$:{type:f,convertedRuntimeType:f}})}if(Fr(c))return Rn(c,e.variantName,t);let m=(o=t.types[c.id])==null?void 0:o.cName;if(!m)return`// Error: No C type name found for enum ${M(c)}`;let h=Rn(c,e.variantName,t);if(!e.fields||e.fields.length===0)return`(${m}){ .tag = ${h} }`;{let y=c.variants.find(v=>v.name===e.variantName);if(!y||!y.fields)return`// Error: Variant ${e.variantName} not found or has no fields`;let g=e.fields.map((v,T)=>{let $=y.fields[T];if($&&!De($.type)){let C=be($.label),k=Yn(v,t);return`.${C} = ${k}`}return null}).filter(v=>v!==null);return g.length===0?`(${m}){ .tag = ${h} }`:`(${m}){ .tag = ${h}, .data = { .${e.variantName} = { ${g.join(", ")} } } }`}}else if(Zn(e)){let c=e.type,f=(a=t.types[c.id])==null?void 0:a.cName;if(!f)return`// Error: No C type name found for tuple ${M(c)}
|
|
192
192
|
`;let p=e.fields.map((m,h)=>{let y=Yn(m,t);return`._${h} = ${y}`});return`(${f}){ ${p.join(", ")} }`}else if(kn(e)){let c=e.type;if(c&&Ae(c)){let f=(s=t.types[c.id])==null?void 0:s.cName;if(!f)return`// Error: No C type name found for struct ${M(c)}
|
|
193
|
-
`;if(c.isNewtype&&c.fields.length===1&&e.fields.length===1){let p=Yn(e.fields[0],t);return`((${f})(${p}))`}if(c.isReferenceSemantics){let p=e.fields.map(h=>Yn(h,t));return`${`__yo_new_${f}`}(${p.join(", ")})`}else{let p=e.fields.map((m,h)=>{let y=m,g=ut(c)?`_${h}`:be(c.fields[h].label),v=Yn(y,t);return`.${g} = ${v}`});return`(${f}){ ${p.join(", ")} }`}}}else if(mr(e)){let c=e.type,f=j(c,t),p=e.elements.map(m=>Yn(m,t));return`(${f}){ .data = { ${p.join(", ")} } }`}else if(
|
|
193
|
+
`;if(c.isNewtype&&c.fields.length===1&&e.fields.length===1){let p=Yn(e.fields[0],t);return`((${f})(${p}))`}if(c.isReferenceSemantics){let p=e.fields.map(h=>Yn(h,t));return`${`__yo_new_${f}`}(${p.join(", ")})`}else{let p=e.fields.map((m,h)=>{let y=m,g=ut(c)?`_${h}`:be(c.fields[h].label),v=Yn(y,t);return`.${g} = ${v}`});return`(${f}){ ${p.join(", ")} }`}}}else if(mr(e)){let c=e.type,f=j(c,t),p=e.elements.map(m=>Yn(m,t));return`(${f}){ .data = { ${p.join(", ")} } }`}else if(ge(e)){let c=(l=t.functions[e.funcId])==null?void 0:l.cName;return c||`// Error: No C function name found for function value with ID ${e.funcId}
|
|
194
194
|
`}else if(W(e)){let c=e.value;if(c)return t.types[c.id]?t.types[c.id].cName:`/* Error: No C type name found for type ${M(c)} */`}else if(Vr(e)){let c=e.targetValue[0];if(c){let f=((u=n==null?void 0:n.$)==null?void 0:u.convertedRuntimeType)||((_=n==null?void 0:n.$)==null?void 0:_.type);if(f&&je(f)){let p=f.childType,m=Yn(c,t,{$:{type:p,convertedRuntimeType:p}});if(m&&!m.startsWith("/*")&&!m.startsWith("//"))return`(&${m})`}}return`/* Error: Cannot generate pointer value ${pt(e)} */`}}return`/* skip generating: ${pt(e)} */`}function la(e,t,n){if(e===t)return!0;if(e.tag==="FnCall"){if(n&&n(e))return!1;if(la(e.func,t,n))return!0;for(let r of e.args)if(la(r,t,n))return!0}return!1}function Oh(e,t,n){for(let r=0;r<t.length;r++)if(la(e,t[r].expr,n))return r;return-1}function Xc(e,t,n){let r=[],i=n==null?void 0:n.shouldSkipBody;if(e.tag!=="FnCall"||!E(e,"begin"))return t.length===0?[{stateNumber:0,expressions:[e],suspensionPoint:null}]:[{stateNumber:0,expressions:[e],suspensionPoint:t[0]??null}];let o=e.args,a=[],s=[];for(let l of o){let u=Oh(l,t,i),_=(n==null?void 0:n.handleReturnStatements)&&(ln(l,"return")||E(l,"return"));if(u!==-1){if(s.push(l),a.push(s),s=[],n!=null&&n.handleSequentialSuspensions)for(let c=u+1;c<t.length&&la(l,t[c].expr,i);c++)a.push([])}else if(_){s.push(l),a.push(s),s=[];break}else s.push(l)}s.length>0&&a.push(s);for(let l=0;l<a.length;l++){let u=a[l],_=l<t.length?t[l]:null;r.push({stateNumber:l,expressions:u,suspensionPoint:_})}return r}function Nu(e,t){let r=Xc(e,t,{shouldSkipBody:An,handleReturnStatements:!0,handleSequentialSuspensions:!0}).map(i=>({stateNumber:i.stateNumber,expressions:i.expressions,awaitPoint:i.suspensionPoint}));return r.length>0&&r[r.length-1].awaitPoint!==null&&r.push({stateNumber:r.length,expressions:[],awaitPoint:null}),r}function Rh(e,t){return la(e,t,An)}function Qc(e,t,n,r=!1){let i=n.emitter;for(let o=0;o<e.expressions.length;o++){let a=e.expressions[o],s=o===e.expressions.length-1,l=e.awaitPoint&&Rh(a,e.awaitPoint.expr),u=e.awaitPoint&&a.tag==="FnCall"&&(E(a,P.while)||E(a,P.cond)||E(a,P.match))&&er(a);if((l||u)&&e.awaitPoint)fa(a,e.awaitPoint,e.stateNumber,t,n);else if(s&&r){let _=q(a,t,n);_&&(i.emitLine(`${t}// Store final expression result`),i.emitLine(`${t}sm->result = ${_};`))}else{let _=q(a,t,n);!_||!a.$||Ht(a.$.env.modulePath,_)||i.emitLine(`${t}${_};`)}}}function fa(e,t,n,r,i){var a,s;let o=i.emitter;if(e.tag==="FnCall"&&_r(e)){let l=e.args[0];if(!l){o.emitLine(`${r}// Error: await without argument`);return}if(t.futureVariableId===void 0){let u=q(l,r,i);o.emitLine(`${r}// Store pattern-matched Future for await ${t.index}`),o.emitLine(`${r}sm->await_future_${t.index} = ${u};`)}else o.emitLine(`${r}// Prepare for await (future already stored in state machine variable)`);return}if(e.tag==="FnCall"&&E(e,":=")){let l=e.args[0],u=e.args[1];if(!l||!u){o.emitLine(`${r}// Error: Invalid assignment expression`);return}if(u.tag==="FnCall"&&_r(u)){let _=u.args[0];if(!_){o.emitLine(`${r}// Error: await without argument`);return}let c=(a=l.token)==null?void 0:a.value;if(!c||!l.$){o.emitLine(`${r}// Error: Invalid variable name`);return}if(t.futureVariableId===void 0){let f=q(_,r,i);o.emitLine(`${r}// Store Future for await (variable: ${c})`),o.emitLine(`${r}sm->await_future_${t.index} = ${f};`)}else o.emitLine(`${r}// Store Future for await (variable: ${c}) - future already in state machine`);return}if(u.tag==="FnCall"&&E(u,P.cond)){let _;if(l.tag==="Atom"&&l.token.type==="identifier"&&l.$){let c=l.token.value,f=ae(l.$.env,c);f.length>0&&(_=f[f.length-1].id)}Za(u,t,r,i,_);return}if(u.tag==="FnCall"&&E(u,P.match)){let _;if(l.tag==="Atom"&&l.token.type==="identifier"&&l.$){let c=l.token.value,f=ae(l.$.env,c);f.length>0&&(_=f[f.length-1].id)}Ja(u,t,r,i,_);return}}if(e.tag==="FnCall"&&E(e,"=")){let l=e.args[0],u=e.args[1];if(l&&u){if(u.tag==="FnCall"&&E(u,P.cond)){let _=q(l,r,i);Za(u,t,r,i,void 0,_||void 0);return}if(u.tag==="FnCall"&&E(u,P.match)){let _=q(l,r,i);Ja(u,t,r,i,void 0,_||void 0);return}}}if(e.tag==="FnCall"&&E(e,P.cond)){Za(e,t,r,i);return}if(e.tag==="FnCall"&&E(e,P.match)){Ja(e,t,r,i);return}if(e.tag==="FnCall"&&E(e,P.while)){Vu(e,t,r,i);return}o.emitLine(`${r}// ERROR: Unsupported pattern for await expression`),o.emitLine(`${r}// Expression type: ${e.tag}, function: ${e.tag==="FnCall"?e.func.tag==="Atom"?(s=e.func.token)==null?void 0:s.value:e.func.tag:"N/A"}`)}function Za(e,t,n,r,i,o){var y,g,v,T,$,C,k,b,w,A,L,N,x,V,U,R;let a=r.emitter;if(e.tag!=="FnCall"||!E(e,P.cond)){a.emitLine(`${n}// Error: Expected cond expression`);return}let s=e.args;if(s.length===0){a.emitLine(`${n}// Error: cond must have at least one branch`);return}let l=[],u=-1;for(let D=0;D<s.length;D++){let H=s[D];if(H.tag==="FnCall"&&E(H,"=>")){let B=H.args[0];if(B&&!(Ct((y=B.$)==null?void 0:y.value)&&B.$.value.value===!1)){u=D;break}}}let _=!1;if(u>=0){let D=s[u];if(D.tag==="FnCall"&&E(D,"=>")){let H=D.args[0];H&&Ct((g=H.$)==null?void 0:g.value)&&H.$.value.value===!0&&(_=!0)}}if(_&&u>=0){let D=s[u],H=S(D)?D.args[1]:void 0;if(H)if(Zi(H)){let Y=ca(H,t,n,r),J=(v=r.asyncWhileLoopInfo)==null?void 0:v.get(t.index);if(J&&Y.length>0){let se=(T=r.asyncCondBranchInfo)==null?void 0:T.get(t.index),ve=(se==null?void 0:se.branches.some(re=>re.hasAwait&&re.remainingExprs&&re.remainingExprs.length>0))??!1;J.condBranchPostWhileExprs={branchIndex:u,condBranchFieldIndex:t.index,exprs:Y,deferredDropExpressions:($=H.$)==null?void 0:$.deferredDropExpressions,skipCondBranchCheck:ve},l.push({index:u,value:H,hasAwait:!0,remainingExprs:[],deferredDropExpressions:(C=H.$)==null?void 0:C.deferredDropExpressions})}else l.push({index:u,value:H,hasAwait:!0,remainingExprs:Y,deferredDropExpressions:(k=H.$)==null?void 0:k.deferredDropExpressions})}else{if(ua(e,H,r,i,o))_a(H,n,r);else if(S(H)&&E(H,P.begin)){let Y=H.args;for(let J=0;J<Y.length;J++){let se=Y[J],ve=q(se,n,r);if(ve==="break"&&t.isInsideWhile)a.emitLine(`${n}sm->while_loop_${t.index}_active = false;`),a.emitLine(`${n}goto while_loop_${t.index}_end;`);else{let re=ve==="break"||ve==="continue"||(ve==null?void 0:ve.includes("return"));ve&&(re||se.$&&!Ht(se.$.env.modulePath,ve))&&a.emitLine(`${n}${ve};`)}}if((b=H.$)!=null&&b.deferredDropExpressions)for(let J of H.$.deferredDropExpressions){let se=q(J,n,r);se&&a.emitLine(`${n}${se};`)}}else{let Y=q(H,n,r);if(Y==="break"&&t.isInsideWhile)a.emitLine(`${n}sm->while_loop_${t.index}_active = false;`),a.emitLine(`${n}goto while_loop_${t.index}_end;`);else{let J=Y==="break"||Y==="continue"||(Y==null?void 0:Y.includes("return"));Y&&(J||H.$&&!Ht(H.$.env.modulePath,Y))&&a.emitLine(`${n}${Y};`)}}l.push({index:u,value:H,hasAwait:!1})}r.asyncCondBranchInfo||(r.asyncCondBranchInfo=new Map);let B=r.asyncCondBranchInfo.get(t.index);((B==null?void 0:B.branches.some(Q=>Q.hasAwait&&Q.remainingExprs&&Q.remainingExprs.length>0))??!1)||r.asyncCondBranchInfo.set(t.index,{branches:l,targetVariableId:i,targetAssignmentCode:o});return}let c=!1,f=0,p=n;for(let D=0;D<s.length;D++){let H=s[D];if(H.tag!=="FnCall"||!E(H,"=>")){a.emitLine(`${p}// Error: Expected => pair in cond`);continue}let B=H.args[0],G=H.args[1];if(!B||!G){a.emitLine(`${p}// Error: Invalid pair in cond`);continue}if(Ct((w=B.$)==null?void 0:w.value)&&B.$.value.value===!1)continue;c&&(a.emitLine(`${p}else {`),f++,p+=" ");let Q=D===s.length-1&&B.tag==="Atom"&&((A=B.token)==null?void 0:A.value)==="true"?null:q(B,p,r);Q?a.emitLine(`${p}if (${Q}) {`):a.emitLine(`${p}{`),c=!0;let Y=`${p} `;if(Zi(G)){a.emitLine(`${Y}sm->cond_branch_${t.index} = ${D};`);let se=ca(G,t,Y,r),ve=(L=r.asyncWhileLoopInfo)==null?void 0:L.get(t.index);if(ve&&se.length>0){let re=(N=r.asyncCondBranchInfo)==null?void 0:N.get(t.index),ce=(re==null?void 0:re.branches.some(we=>we.hasAwait&&we.remainingExprs&&we.remainingExprs.length>0))??!1;ve.condBranchPostWhileExprs={branchIndex:D,condBranchFieldIndex:t.index,exprs:se,deferredDropExpressions:(x=G.$)==null?void 0:x.deferredDropExpressions,skipCondBranchCheck:ce},l.push({index:D,value:G,hasAwait:!0,remainingExprs:[],deferredDropExpressions:(V=G.$)==null?void 0:V.deferredDropExpressions})}else l.push({index:D,value:G,hasAwait:!0,remainingExprs:se,deferredDropExpressions:(U=G.$)==null?void 0:U.deferredDropExpressions})}else{if(ua(e,G,r,i,o))_a(G,Y,r);else if(S(G)&&E(G,P.begin)){let se=G.args;for(let ve=0;ve<se.length;ve++){let re=se[ve],ce=q(re,Y,r);if(ce==="break"&&t.isInsideWhile)a.emitLine(`${Y}sm->while_loop_${t.index}_active = false;`),a.emitLine(`${Y}goto while_loop_${t.index}_end;`);else{let we=ce==="break"||ce==="continue"||(ce==null?void 0:ce.includes("return"));ce&&(we||re.$&&!Ht(re.$.env.modulePath,ce))&&a.emitLine(`${Y}${ce};`)}}if((R=G.$)!=null&&R.deferredDropExpressions)for(let ve of G.$.deferredDropExpressions){let re=q(ve,Y,r);re&&a.emitLine(`${Y}${re};`)}}else{let se=q(G,Y,r);if(se==="break"&&t.isInsideWhile)a.emitLine(`${Y}sm->while_loop_${t.index}_active = false;`),a.emitLine(`${Y}goto while_loop_${t.index}_end;`);else{let ve=se==="break"||se==="continue"||(se==null?void 0:se.includes("return"));se&&(ve||G.$&&!Ht(G.$.env.modulePath,se))&&a.emitLine(`${Y}${se};`)}}l.push({index:D,value:G,hasAwait:!1})}a.emitLine(`${p}}`)}for(let D=0;D<f;D++)p=p.slice(0,-2),a.emitLine(`${p}}`);r.asyncCondBranchInfo||(r.asyncCondBranchInfo=new Map);let m=r.asyncCondBranchInfo.get(t.index);((m==null?void 0:m.branches.some(D=>D.hasAwait&&D.remainingExprs&&D.remainingExprs.length>0))??!1)||r.asyncCondBranchInfo.set(t.index,{branches:l,targetVariableId:i,targetAssignmentCode:o})}function ua(e,t,n,r,i){return!r&&!i&&n.asyncBodyReturnExpr!==void 0&&e===n.asyncBodyReturnExpr&&!!n.inAsyncStateMachine&&!Zc(t)}function _a(e,t,n){var o,a;let r=n.emitter,i=De((o=e.$)==null?void 0:o.type);if(S(e)&&E(e,P.begin)){let s=e.args;for(let u=0;u<s.length-1;u++){let _=s[u],c=q(_,t,n);c&&_.$&&!Ht(_.$.env.modulePath,c)&&r.emitLine(`${t}${c};`)}let l=s[s.length-1];if(l&&!i){let u=q(l,t,n);u&&r.emitLine(`${t}sm->result = ${u};`)}if((a=e.$)!=null&&a.deferredDropExpressions)for(let u of e.$.deferredDropExpressions){let _=q(u,t,n);_&&r.emitLine(`${t}${_};`)}}else if(!i){let s=q(e,t,n);s&&r.emitLine(`${t}sm->result = ${s};`)}if(r.emitLine(`${t}// Drop local variables before early completion`),n.pendingDeferredDrops)for(let s of n.pendingDeferredDrops){let l=q(s,t,n);l&&l.includes("sm->")&&r.emitLine(`${t}${l};`)}Ni({emitter:r,indent:t,resultCode:void 0,debugLabel:n.currentFunctionName}),r.emitLine(`${t}return;`)}function Zi(e){if(e.tag==="FnCall"&&_r(e))return!0;if(e.tag==="FnCall"){for(let t of e.args)if(Zi(t))return!0}return!1}function Zc(e){if(ln(e,"return")||E(e,"return"))return!0;if(e.tag==="FnCall"){for(let t of e.args)if(Zc(t))return!0}return!1}function Ja(e,t,n,r,i,o){var m,h,y,g,v,T;let a=r.emitter;if(e.tag!=="FnCall"||!E(e,P.match)){a.emitLine(`${n}// Error: Expected match expression`);return}let s=e.args[0],l=e.args.slice(1);if(!s||l.length===0){a.emitLine(`${n}// Error: match must have a value and at least one case`);return}let u=q(s,n,r),_=(m=s.$)==null?void 0:m.type;if(!_){a.emitLine(`${n}// Error: match value has no type`);return}if((h=e.$)!=null&&h.isPrimitiveMatch){Uh(e,l,u,t,n,r,i,o);return}if(!Be(_)){a.emitLine(`${n}// Error: match requires an enum type or primitive type`);return}let c=_,f=(y=r.types[c.id])==null?void 0:y.cName;if(!f){a.emitLine(`${n}// Error: enum type has no C name`);return}let p=Gn(c);if(p){let $=-1,C=-1,k;for(let b=0;b<l.length;b++){let w=l[b];if(S(w)&&E(w,"=>",2)){let A=w.args[0];if(A&&S(A)&&E(A,"."))$=b;else if(A&&S(A)){let L=A.func;L&&S(L)&&E(L,".")&&(C=b,A.args.length>0&&K(A.args[0])&&(k=A.args[0].token.value))}}}if(a.emitLine(`${n}if (${u} != NULL) {`),C>=0){let b=l[C];if(!S(b))a.emitLine(`${n} // Error: Expected => in case`);else{let w=b.args[1];if(k){let A=r,L=!1,N;if(A.stateMachineVariables){for(let[x,V]of A.stateMachineVariables)if(V.name===k){L=!0,N=x;break}}if(L&&N){let x=Xn(N,"local",A.stateMachineFieldAliases);a.emitLine(`${n} sm->${x} = ${u};`)}else a.emitLine(`${n} ${j(p,r)} ${k} = ${u};`)}if(a.emitLine(`${n} sm->cond_branch_${t.index} = ${C};`),Zi(w)){let A=ca(w,t,n+" ",r);if(A.length>0){let L=r;L.asyncCondBranchInfo||(L.asyncCondBranchInfo=new Map);let N=L.asyncCondBranchInfo.get(t.index)||{branches:[]};N.branches.push({index:C,value:w,hasAwait:!0,remainingExprs:A,deferredDropExpressions:(g=w.$)==null?void 0:g.deferredDropExpressions}),L.asyncCondBranchInfo.set(t.index,N)}}else if(ua(e,w,r,i,o))_a(w,n+" ",r);else{let A=q(w,n+" ",r);if(i){let L=be(`var_${i}`);A&&a.emitLine(`${n} sm->${L} = ${A};`)}else o?A&&a.emitLine(`${n} ${o} = ${A};`):A&&w.$&&!Ht(w.$.env.modulePath,A)&&a.emitLine(`${n} ${A};`)}}}if(a.emitLine(`${n}} else {`),$>=0){let b=l[$];if(!S(b))a.emitLine(`${n} // Error: Expected => in case`);else{let w=b.args[1];if(a.emitLine(`${n} sm->cond_branch_${t.index} = ${$};`),Zi(w)){let A=ca(w,t,n+" ",r);if(A.length>0){let L=r;L.asyncCondBranchInfo||(L.asyncCondBranchInfo=new Map);let N=L.asyncCondBranchInfo.get(t.index)||{branches:[]};N.branches.push({index:$,value:w,hasAwait:!0,remainingExprs:A,deferredDropExpressions:(v=w.$)==null?void 0:v.deferredDropExpressions}),L.asyncCondBranchInfo.set(t.index,N)}}else if(ua(e,w,r,i,o))_a(w,n+" ",r);else{let A=q(w,n+" ",r);if(i){let L=be(`var_${i}`);A&&a.emitLine(`${n} sm->${L} = ${A};`)}else o?A&&a.emitLine(`${n} ${o} = ${A};`):A&&w.$&&!Ht(w.$.env.modulePath,A)&&a.emitLine(`${n} ${A};`)}}}a.emitLine(`${n}}`)}else{a.emitLine(`${n}switch (${u}.tag) {`);let $=!1;for(let C=0;C<l.length;C++){let k=l[C];if(!S(k)||!E(k,"=>",2))continue;let b=k.args[0],w=k.args[1],A=K(b)&&b.token.value==="_",L;if(!A){if(S(b)&&E(b,".",1))L=b.args[0].token.value;else if(S(b)){let N=b.func;N&&S(N)&&E(N,".",1)&&(L=N.args[0].token.value)}}if(!A&&!L){a.emitLine(`${n} // Error: Could not extract variant name`);continue}if(A)$=!0,a.emitLine(`${n} default: {`);else{let N=`${f.toUpperCase()}_${L.toUpperCase()}`;a.emitLine(`${n} case ${N}: {`)}if(a.emitLine(`${n} sm->cond_branch_${t.index} = ${C};`),S(b)&&b.args.length>=1){let N=b.func;if(N&&S(N)&&E(N,".")){let x=c.variants.find(V=>V.name===L);if(x&&x.fields)for(let V=0;V<Math.min(b.args.length,x.fields.length);V++){let U=b.args[V],R=x.fields[V];if(K(U)&&R){let D=U.token.value,H=be(D),B=r,G=!1,Q;if(B.stateMachineVariables){for(let[se,ve]of B.stateMachineVariables)if(ve.name===D){G=!0,Q=se;break}}let Y=be(R.label,R.type.isExtern==="c"),J=`${u}.data.${L}.${Y}`;if(G&&Q){let se=Xn(Q,"local",B.stateMachineFieldAliases);a.emitLine(`${n} sm->${se} = ${J};`)}else{let se=j(R.type,r);a.emitLine(`${n} ${se} ${H} = ${J};`)}}}}}if(Zi(w)){let N=ca(w,t,n+" ",r);if(N.length>0){let x=r;x.asyncCondBranchInfo||(x.asyncCondBranchInfo=new Map);let V=x.asyncCondBranchInfo.get(t.index)||{branches:[]};V.branches.push({index:C,value:w,hasAwait:!0,remainingExprs:N,deferredDropExpressions:(T=w.$)==null?void 0:T.deferredDropExpressions}),x.asyncCondBranchInfo.set(t.index,V)}}else if(ua(e,w,r,i,o))_a(w,n+" ",r);else{let N=q(w,n+" ",r);if(i){let x=be(`var_${i}`);N&&a.emitLine(`${n} sm->${x} = ${N};`)}else o?N&&a.emitLine(`${n} ${o} = ${N};`):N&&w.$&&!Ht(w.$.env.modulePath,N)&&a.emitLine(`${n} ${N};`)}a.emitLine(`${n} break;`),a.emitLine(`${n} }`)}$||a.emitLine(`${n} default: break;`),a.emitLine(`${n}}`)}}function Ph(e){return S(e)?E(e,"|",2):!1}function Su(e){if(!Ph(e))return[e];if(e.tag!=="FnCall")return[e];let t=e.args[0],n=e.args[1];return[...Su(t),...Su(n)]}function Uh(e,t,n,r,i,o,a,s){var _,c,f;let l=o.emitter,u=[];l.emitLine(`${i}switch (${n}) {`);for(let p=0;p<t.length;p++){let m=t[p];if(!S(m)||!E(m,"=>",2))continue;let h=m.args[0],y=m.args[1];if(ln(h,"_"))l.emitLine(`${i} default:`);else{let g=(_=h.$)==null?void 0:_.primitivePatternValues;if(g&&g.length>0){for(let v of g)if(v!==void 0){let T=Yn(v,o);l.emitLine(`${i} case ${T}:`)}}else{let v=Su(h);for(let T of v){let $=(c=T.$)==null?void 0:c.value;if($!==void 0){let C=Yn($,o);l.emitLine(`${i} case ${C}:`)}}}}if(l.emitLine(`${i} sm->cond_branch_${r.index} = ${p};`),Zi(y)){let g=ca(y,r,i+" ",o);u.push({index:p,value:y,hasAwait:!0,remainingExprs:g,deferredDropExpressions:(f=y.$)==null?void 0:f.deferredDropExpressions})}else{if(ua(e,y,o,a,s))_a(y,i+" ",o);else{let g=q(y,i+" ",o);if(a){let v=be(`var_${a}`);g&&l.emitLine(`${i} sm->${v} = ${g};`)}else s?g&&l.emitLine(`${i} ${s} = ${g};`):g&&y.$&&!Ht(y.$.env.modulePath,g)&&l.emitLine(`${i} ${g};`)}u.push({index:p,value:y,hasAwait:!1})}l.emitLine(`${i} break;`)}l.emitLine(`${i}}`),o.asyncCondBranchInfo||(o.asyncCondBranchInfo=new Map),o.asyncCondBranchInfo.set(r.index,{branches:u,targetVariableId:a,targetAssignmentCode:s})}function ca(e,t,n,r){let i=r.emitter,o=[];if(e.tag!=="FnCall"||!E(e,"begin"))return i.emitLine(`${n}// Error: Expected begin block in cond branch with await`),o;let a=e.args,s=!1;for(let l of a){if(s){o.push(l);continue}if(Zi(l))if(s=!0,l.tag==="FnCall"&&E(l,":=")){let u=l.args[1];if(u&&u.tag==="FnCall"&&_r(u)){let _=u.args[0];if(_){let c=q(_,n,r);i.emitLine(`${n}// Store Future for await ${t.index} (cond branch)`),i.emitLine(`${n}sm->await_future_${t.index} = ${c};`)}}}else if(l.tag==="FnCall"&&_r(l)){let u=l.args[0];if(u)if(t.futureVariableId===void 0){let _=q(u,n,r);i.emitLine(`${n}// Store Future for await ${t.index} (cond branch)`),i.emitLine(`${n}sm->await_future_${t.index} = ${_};`)}else i.emitLine(`${n}// Await will use Future from sm->var_${t.futureVariableId}`)}else if(l.tag==="FnCall"&&E(l,P.cond)){let u=l===a[a.length-1],_=r.asyncBodyReturnExpr;u&&r.asyncBodyReturnExpr!==void 0&&(r.asyncBodyReturnExpr=l),Za(l,t,n,r),r.asyncBodyReturnExpr=_}else if(l.tag==="FnCall"&&E(l,P.match)){let u=l===a[a.length-1],_=r.asyncBodyReturnExpr;u&&r.asyncBodyReturnExpr!==void 0&&(r.asyncBodyReturnExpr=l),Ja(l,t,n,r),r.asyncBodyReturnExpr=_}else l.tag==="FnCall"&&E(l,P.while)&&Vu(l,t,n,r);else{let u=q(l,n,r);u&&l.$&&!Ht(l.$.env.modulePath,u)&&i.emitLine(`${n}${u};`)}}return o}function Vu(e,t,n,r){let i=r.emitter;if(e.tag!=="FnCall"||!E(e,"while")){i.emitLine(`${n}// Error: Expected while expression`);return}let o=e.args;if(o.length<2||o.length>3){i.emitLine(`${n}// Error: while must have 2 or 3 arguments (condition, [step,] body)`);return}let a=o[0],s=o.length===3?o[1]:void 0,l=o.length===3?o[2]:o[1],u=Bh(l),_;u?(_=r.asyncNextWhileLoopIndex??t.index+1,r.asyncNextWhileLoopIndex=_+1):_=t.index,i.emitLine(`${n}sm->while_loop_${_}_active = true;`),i.emitLine(`${n}while_loop_${_}_start:`);let c=q(a,n,r);i.emitLine(`${n}if (!(${c})) {`),i.emitLine(`${n} sm->while_loop_${_}_active = false;`),i.emitLine(`${n} goto while_loop_${_}_end;`),i.emitLine(`${n}}`);let f=zh(l,t,n,r,_);if(i.emitLine(`${n}while_loop_${_}_end:`),r.asyncWhileLoopInfo||(r.asyncWhileLoopInfo=new Map),u){let p=r.asyncWhileLoopInfo.get(t.index);p&&(p.outerWhileLoop={whileLoopIndex:_,conditionExpr:a,stepExpr:s,bodyExpr:l,bodyExprsAfterAwait:f})}else r.asyncWhileLoopInfo.set(t.index,{conditionExpr:a,stepExpr:s,bodyExpr:l,bodyExprsAfterAwait:f})}function zh(e,t,n,r,i){var p;let o=r.emitter,a=[],s=[];e.tag==="FnCall"&&E(e,"begin")?s=e.args:s=[e];let l=-1;for(let m=0;m<s.length;m++){let h=s[m];if(er(h)){l=m;break}}if(l===-1)return o.emitLine(`${n}// Error: Expected await in while loop body but none found`),a;let u=r.smWhileBreakInfo,_=r.smWhileContinueInfo,c=r.smWhileBodyDrops;r.smWhileBreakInfo={label:`while_loop_${i}_end`,activeIndex:i},r.smWhileContinueInfo={label:`while_loop_${i}_start`,emitDropsBeforeGoto:!0},r.smWhileBodyDrops=[...((p=e.$)==null?void 0:p.deferredDropExpressions)??[]];for(let m=0;m<l;m++){let h=s[m],y=q(h,n,r);y&&h.$&&!Ht(h.$.env.modulePath,y)&&o.emitLine(`${n}${y};`)}r.smWhileBreakInfo=u,r.smWhileContinueInfo=_,r.smWhileBodyDrops=c;let f=s[l];if(S(f)&&E(f,P.while)&&er(f)){Vu(f,t,n,r);for(let m=l+1;m<s.length;m++)a.push(s[m]);return a}if(S(f)&&E(f,":=")){let m=f.args[1];if(m&&m.tag==="FnCall"&&_r(m)){let h=m.args[0];if(h){let y=q(h,n,r);o.emitLine(`${n}// Store Future for await ${t.index} (while loop body)`),o.emitLine(`${n}sm->await_future_${t.index} = ${y};`)}}}else if(f.tag==="FnCall"&&_r(f)){let m=f.args[0];if(m&&t.futureVariableId===void 0){let h=q(m,n,r);o.emitLine(`${n}// Store Future for await ${t.index} (while loop body)`),o.emitLine(`${n}sm->await_future_${t.index} = ${h};`)}}else if(S(f)&&E(f,P.cond)){Za(f,t,n,r,void 0);for(let m=l+1;m<s.length;m++)a.push(s[m]);return a}else if(S(f)&&E(f,P.match)){Ja(f,t,n,r);for(let m=l+1;m<s.length;m++)a.push(s[m]);return a}for(let m=l+1;m<s.length;m++)a.push(s[m]);return a}function Bh(e){let t=e.tag==="FnCall"&&E(e,"begin")?e.args:[e];for(let n of t)if(n.tag==="FnCall"&&E(n,P.while)&&er(n))return!0;return!1}function wo(e,t,n){var r,i,o;if(e)switch(e.tag){case"Atom":if(e.$&&e.token.type==="identifier"){let a=e.token.value,s=ae(e.$.env,a);if(s.length>0){let l=s[s.length-1];if(l&&!l.isCompileTimeOnly){let u=n.get(l.id)??l.id,_=l.isOwningTheSameRcValueAs?l.isOwningTheSameRcValueAs.id:u;t.add(_)}}}break;case"FnCall":if(An(e)){if((r=e.$)!=null&&r.deferredDupExpressions)for(let a of e.$.deferredDupExpressions)wo(a,t,n);break}wo(e.func,t,n);for(let a of e.args)wo(a,t,n);if((i=e.$)!=null&&i.deferredDropExpressions)for(let a of e.$.deferredDropExpressions)wo(a,t,n);if((o=e.$)!=null&&o.deferredDupExpressions)for(let a of e.$.deferredDupExpressions)wo(a,t,n);break}}function Il(e,t){var c,f,p,m;let{awaitPoints:n,capturedVariables:r,variableIdRemapping:i}=t;if(n.length===0)return{crossBoundaryIds:new Set,awaitFutureTempVarAliases:new Map,variableSegments:new Map};let o=new Set,a=Nu(e,n);for(let h of a)((c=h.awaitPoint)!=null&&c.isInsideCond||(f=h.awaitPoint)!=null&&f.isInsideWhile)&&o.add(h.stateNumber);let s=new Map;for(let h of a){let y=new Set;for(let g of h.expressions)wo(g,y,i);for(let g of y){let v=s.get(g);v||(v=new Set,s.set(g,v)),v.add(h.stateNumber)}}let l=-1;if((p=e.$)!=null&&p.deferredDropExpressions){let h=new Set;for(let y of e.$.deferredDropExpressions)wo(y,h,i);for(let y of h){let g=s.get(y);g||(g=new Set,s.set(y,g)),g.add(l)}}let u=new Set;for(let h of r){if(h.kind==="outer")continue;let y=s.get(h.id);if(!y)u.add(h.id);else if(y.size>1)u.add(h.id);else if(y.has(l))u.add(h.id);else{let g=y.values().next().value;o.has(g)&&u.add(h.id)}}let _=new Map;for(let h of n){if(h.futureVariableId!==void 0)continue;let y=h.expr;if(!S(y))continue;let g=y.args[0];if(!g)continue;let v=(m=g.$)==null?void 0:m.variableName;if(!v)continue;let T=r.find($=>$.kind==="local"&&($.name===v||$.id===v));T&&(_.set(T.id,`await_future_${h.index}`),u.delete(T.id))}return{crossBoundaryIds:u,awaitFutureTempVarAliases:_,variableSegments:s}}function Al(e,t,n,r,i){let o={slotAliases:new Map,slots:[]},a=n.filter(f=>f.kind==="local"&&e.has(f.id)&&!r.has(f.id)&&!it(f.type));if(a.length<2)return o;let s=new Map;for(let f of a){let p=t.get(f.id);if(!p||p.size===0)continue;let m=[...p].filter(g=>g>=0);if(m.length===0)continue;let h=Math.min(...m),y=Math.max(...m);s.set(f.id,[h,y])}if(s.size<2)return o;let l=new Map;for(let[f]of s){let p=a.find(y=>y.id===f);if(!p)continue;let m=j(p.type,i),h=l.get(m);h||(h=[],l.set(m,h)),h.push(f)}let u=new Map,_=[],c=0;for(let[f,p]of l){if(p.length<2)continue;let m=new Map;for(let g of p)m.set(g,new Set);for(let g=0;g<p.length;g++)for(let v=g+1;v<p.length;v++){let[T,$]=s.get(p[g]),[C,k]=s.get(p[v]);T<=k&&C<=$&&(m.get(p[g]).add(p[v]),m.get(p[v]).add(p[g]))}let h=new Map;for(let g of p){let v=new Set;for(let $ of m.get(g))h.has($)&&v.add(h.get($));let T=0;for(;v.has(T);)T++;h.set(g,T)}let y=new Map;for(let[g,v]of h){let T=y.get(v);T||(T=[],y.set(v,T)),T.push(g)}for(let[,g]of y){if(g.length<2)continue;let v=`slot_${c}`,T=g.map($=>{var C;return((C=a.find(k=>k.id===$))==null?void 0:C.name)??$});for(let $ of g)u.set($,v);_.push({fieldName:v,cType:f,variableNames:T}),c++}}return{slotAliases:u,slots:_}}function xu(e,t){if(e.futureVariableId){let n=t.capturedVariables.find(r=>r.id===e.futureVariableId);if(n)return n.kind==="outer"?n.name:`var_${n.id}`}return`await_future_${e.index}`}function es(e){return!e||!z(e)?!1:e.resolvedConcreteType&&z(e.resolvedConcreteType)&&e.resolvedConcreteType.isExtern?!0:e.requiredTraits.some(t=>gs(t.traitType))}function Xn(e,t,n){if(t==="outer")return`__capture.${be(e)}`;let r=n==null?void 0:n.get(e);return r||be(`var_${e}`)}function ef(e,t,n,r,i,o,a,s){var y,g,v,T,$,C,k,b,w,A,L,N,x,V,U,R,D,H,B,G,Q,Y,J,se,ve,re,ce;let l=s.emitter,_=Ln(o).isFuture.outputType,c=De(_);s.asyncCondBranchInfo=new Map,s.asyncWhileLoopInfo=new Map,s.asyncNextWhileLoopIndex=i.awaitPoints.length;let f=Nu(e,i.awaitPoints),p=e.tag==="FnCall"&&E(e,"begin")?e.args:[e],m=p.length>0?p[p.length-1]:void 0;l.emitLine(`// Resume function for async block ${t}`),l.emitLine(`void ${r}(${n}* sm) {`),l.emitLine(` ASYNC_DEBUG("${t}_resume: state=%d\\n", sm->state);`),l.emitLine(" int __yo_inline_budget = 32; // bounded inline fast-path for sync-completed awaits"),l.emitLine(" switch (sm->state) {");let h=[];for(let we=0;we<f.length;we++){let Se=f[we];if(!Se)continue;let Ve=Se.stateNumber,de=we===f.length-1;if(l.emitLine(`
|
|
195
|
-
state_${Ve}:`),l.emitLine(` case ${Ve}: { // State ${Ve}`),l.emitLine(` ASYNC_DEBUG("${t}: Entering state ${Ve}\\n");`),Ve>0&&i.awaitPoints[Ve-1]){let Ze=i.awaitPoints[Ve-1],Tt=xu(Ze,i);Ze.isInsideCond&&l.emitLine(` if (sm->${Tt} != NULL) {`);let Jt=De(Ze.resultType)||z(Ze.resultType)&&!Ze.resultType.resolvedConcreteType;if(l.emitLine(" // Check if the awaited Future was aborted"),l.emitLine(` if (sm->${Tt}->state == -2) {`),l.emitLine(` __yo_decr_rc((void*)sm->${Tt});`),l.emitLine(` sm->${Tt} = NULL;`),Ar({emitter:l,indent:" ",debugLabel:t}),l.emitLine(" }"),Ze&&!Jt){l.emitLine(` // Extract result from await ${Ve-1}`),l.emitLine(` int state_before_read = sm->${Tt}->state;`),l.emitLine(` ASYNC_DEBUG("${t}: Reading result from await ${Ve-1}, state=%d\\n", state_before_read);`);let gt=!!Ze.isInsideCond,nt;if(gt?nt=`sm->await_result_${Ve-1}`:Ze.targetVariableId&&(nt=`sm->${Xn(Ze.targetVariableId,"local",s.stateMachineFieldAliases)}`),nt)if(it(Ze.resultType)){let Ft=fr(Ze.resultType,s);Ft?l.emitLine(` ${nt} = ${Ft}(sm->${Tt}->result);`):(l.emitLine(" /* Warning: No ___dup function found for result type, shallow copy may cause use-after-free */"),l.emitLine(` ${nt} = sm->${Tt}->result;`))}else l.emitLine(` ${nt} = sm->${Tt}->result;`);if(gt&&Ze.targetVariableId){let Ft=Xn(Ze.targetVariableId,"local",s.stateMachineFieldAliases);l.emitLine(` sm->${Ft} = sm->await_result_${Ve-1};`)}l.emitLine("")}if(!Ze.futureVariableId){let gt=Ze.expr;if(gt.tag==="FnCall"){let nt=gt.args[0],Ft=(y=nt==null?void 0:nt.$)==null?void 0:y.type;Ft&&(z(Ft)||st(Ft))&&(l.emitLine(` if (sm->${Tt} != NULL) { __yo_decr_rc((void*)sm->${Tt}); sm->${Tt} = NULL; }`),l.emitLine(""))}}let At=s;if(Ze){let gt=(g=At.asyncCondBranchInfo)==null?void 0:g.get(Ze.index);if(gt&>.branches.some(Ft=>Ft.hasAwait)){let Ft=gt.condBranchFieldIndex??Ze.index,qt=Ft===-1;l.emitLine(" // Execute remaining code from chosen cond branch"),qt||l.emitLine(` switch (sm->cond_branch_${Ft}) {`);let Et=((v=Se.awaitPoint)==null?void 0:v.isInsideCond)??!1;for(let Lt of gt.branches)if(Lt.hasAwait){if(qt||l.emitLine(` case ${Lt.index}: {`),l.emitLine(` ASYNC_DEBUG("${t}: Executing remaining code from branch ${Lt.index}\\n");`),Lt.remainingExprs&&Lt.remainingExprs.length>0){let nn=s.inAsyncStateMachine,te=s.stateMachineVariables,pe=s.variableIdRemapping,$e=s.pendingDeferredDrops;s.inAsyncStateMachine={futureType:o},s.variableIdRemapping=i.variableIdRemapping;let ie=(T=At.asyncWhileLoopInfo)==null?void 0:T.get(Ze.index);s.pendingDeferredDrops=[...Lt.deferredDropExpressions??[],...(($=ie==null?void 0:ie.bodyExpr.$)==null?void 0:$.deferredDropExpressions)??[],...((C=e.$)==null?void 0:C.deferredDropExpressions)??[]];let _e=new Map;for(let Pe of i.capturedVariables)_e.set(Pe.id,Pe);if(a)for(let Pe of a.fields)_e.set(Pe.label,{id:Pe.label,name:Pe.label,type:Pe.type,kind:"outer",isOwningTheSameRcValueAs:void 0});s.stateMachineVariables=_e;let ye=!1,Re=[],Ke=gt.targetAssignmentCode;for(let Pe=0;Pe<Lt.remainingExprs.length;Pe++){let Z=Lt.remainingExprs[Pe],X=Pe===Lt.remainingExprs.length-1;if(ye){Re.push(Z);continue}if(Et&&er(Z)){ye=!0,Ll(Z,Se.awaitPoint,i," ",s);continue}let ge=q(Z," ",s);!ge||!Z.$||Ht(Z.$.env.modulePath,ge)||(X&&Ke?l.emitLine(` ${Ke} = ${ge};`):l.emitLine(` ${ge};`))}if(Lt.remainingExprs.length===0&&Ke&&l.emitLine(` ${Ke} = sm->await_result_${Ze.index};`),ye&&Se.awaitPoint){let Pe=Se.awaitPoint.index;At.asyncCondBranchInfo||(At.asyncCondBranchInfo=new Map);let Z=At.asyncCondBranchInfo.get(Pe);if(Z)Z.chainedBranches||(Z.chainedBranches=[]),Z.chainedBranches.push({branches:[{index:Lt.index,value:Lt.value,hasAwait:Re.length>0||Re.some(X=>er(X)),remainingExprs:Re,deferredDropExpressions:Lt.deferredDropExpressions}],condBranchFieldIndex:Ft});else{let X={branches:[{index:Lt.index,value:Lt.value,hasAwait:Re.length>0||Re.some(ge=>er(ge)),remainingExprs:Re,deferredDropExpressions:Lt.deferredDropExpressions}],condBranchFieldIndex:Ft};At.asyncCondBranchInfo.set(Pe,X)}}else if(Lt.deferredDropExpressions)for(let Pe of Lt.deferredDropExpressions){let Z=q(Pe," ",s);Z&&Z.includes("sm->")&&l.emitLine(` ${Z};`)}s.inAsyncStateMachine=nn,s.stateMachineVariables=te,s.variableIdRemapping=pe,s.pendingDeferredDrops=$e}qt||(l.emitLine(" break;"),l.emitLine(" }"))}if(qt||l.emitLine(" }"),gt.chainedBranches){for(let Lt of gt.chainedBranches)for(let nn of Lt.branches)if(nn.hasAwait&&nn.remainingExprs&&nn.remainingExprs.length>0){let te=s.inAsyncStateMachine,pe=s.stateMachineVariables,$e=s.variableIdRemapping,ie=s.pendingDeferredDrops;s.inAsyncStateMachine={futureType:o},s.variableIdRemapping=i.variableIdRemapping;let _e=(k=At.asyncWhileLoopInfo)==null?void 0:k.get(Ze.index);s.pendingDeferredDrops=[...nn.deferredDropExpressions??[],...((b=_e==null?void 0:_e.bodyExpr.$)==null?void 0:b.deferredDropExpressions)??[],...((w=e.$)==null?void 0:w.deferredDropExpressions)??[]];let ye=new Map;for(let Z of i.capturedVariables)ye.set(Z.id,Z);if(a)for(let Z of a.fields)ye.set(Z.label,{id:Z.label,name:Z.label,type:Z.type,kind:"outer",isOwningTheSameRcValueAs:void 0});s.stateMachineVariables=ye;let Re=((A=Se.awaitPoint)==null?void 0:A.isInsideCond)??!1,Ke=!1,Pe=[];for(let Z of nn.remainingExprs){if(Ke){Pe.push(Z);continue}if(Re&&er(Z)){Ke=!0,Ll(Z,Se.awaitPoint,i," ",s);continue}let X=q(Z," ",s);!X||!Z.$||Ht(Z.$.env.modulePath,X)||l.emitLine(` ${X};`)}if(Ke&&Se.awaitPoint){let Z=Se.awaitPoint.index;At.asyncCondBranchInfo||(At.asyncCondBranchInfo=new Map);let X=At.asyncCondBranchInfo.get(Z);X?(X.chainedBranches||(X.chainedBranches=[]),X.chainedBranches.push({branches:[{index:nn.index,value:nn.value,hasAwait:Pe.length>0||Pe.some(ge=>er(ge)),remainingExprs:Pe,deferredDropExpressions:nn.deferredDropExpressions}],condBranchFieldIndex:Lt.condBranchFieldIndex})):At.asyncCondBranchInfo.set(Z,{branches:[{index:nn.index,value:nn.value,hasAwait:Pe.length>0||Pe.some(ge=>er(ge)),remainingExprs:Pe,deferredDropExpressions:nn.deferredDropExpressions}],condBranchFieldIndex:Lt.condBranchFieldIndex})}else if(nn.deferredDropExpressions)for(let Z of nn.deferredDropExpressions){let X=q(Z," ",s);X&&X.includes("sm->")&&l.emitLine(` ${X};`)}s.inAsyncStateMachine=te,s.stateMachineVariables=pe,s.variableIdRemapping=$e,s.pendingDeferredDrops=ie}}if(gt.targetVariableId){let Lt=Xn(gt.targetVariableId,"local",s.stateMachineFieldAliases);l.emitLine(" // Assign cond result to target variable"),l.emitLine(` sm->${Lt} = sm->await_result_${Ze.index};`)}l.emitLine("")}Ze.isInsideCond&&l.emitLine(" }");let nt=(L=At.asyncWhileLoopInfo)==null?void 0:L.get(Ze.index);if(nt){let Ft=nt.whileLoopOriginIndex??Ze.index;l.emitLine(" // Execute remaining code from while loop body and continue loop"),l.emitLine(` if (sm->while_loop_${Ft}_active) {`);let qt=!1;if(nt.bodyExprsAfterAwait&&nt.bodyExprsAfterAwait.length>0){let Et=s.inAsyncStateMachine,Lt=s.stateMachineVariables,nn=s.variableIdRemapping,te=s.pendingDeferredDrops;s.inAsyncStateMachine={futureType:o},s.variableIdRemapping=i.variableIdRemapping,s.pendingDeferredDrops=[...((N=nt.bodyExpr.$)==null?void 0:N.deferredDropExpressions)??[],...((x=e.$)==null?void 0:x.deferredDropExpressions)??[]];let pe=new Map;for(let ye of i.capturedVariables)pe.set(ye.id,ye);if(a)for(let ye of a.fields)pe.set(ye.label,{id:ye.label,name:ye.label,type:ye.type,kind:"outer",isOwningTheSameRcValueAs:void 0});s.stateMachineVariables=pe;let $e=s.smWhileBreakInfo,ie=s.smWhileContinueInfo,_e=s.smWhileBodyDrops;s.smWhileBreakInfo={label:`after_while_loop_${Ft}`,activeIndex:Ft},s.smWhileContinueInfo={label:`while_loop_${Ft}_continue`},s.smWhileBodyDrops=[...((V=nt.bodyExpr.$)==null?void 0:V.deferredDropExpressions)??[]];for(let ye=0;ye<nt.bodyExprsAfterAwait.length;ye++){let Re=nt.bodyExprsAfterAwait[ye];if(er(Re)&&Se.awaitPoint){Ll(Re,Se.awaitPoint,i," ",s);let Pe=nt.bodyExprsAfterAwait.slice(ye+1);At.asyncWhileLoopInfo.set(Se.awaitPoint.index,{conditionExpr:nt.conditionExpr,stepExpr:nt.stepExpr,bodyExpr:nt.bodyExpr,bodyExprsAfterAwait:Pe,whileLoopOriginIndex:Ft,isChainedAwait:!0,condBranchPostWhileExprs:nt.condBranchPostWhileExprs,outerWhileLoop:nt.outerWhileLoop}),qt=!0;break}let Ke=q(Re," ",s);!Ke||!Re.$||Ht(Re.$.env.modulePath,Ke)||l.emitLine(` ${Ke};`)}s.smWhileBreakInfo=$e,s.smWhileContinueInfo=ie,s.smWhileBodyDrops=_e,s.inAsyncStateMachine=Et,s.stateMachineVariables=Lt,s.variableIdRemapping=nn,s.pendingDeferredDrops=te}if(qt)l.emitLine(" }"),l.emitLine("");else{l.emitLine(` while_loop_${Ft}_continue:`);{let _e=((U=nt.bodyExpr.$)==null?void 0:U.deferredDropExpressions)??[];if(_e.length>0){let ye=s.inAsyncStateMachine,Re=s.stateMachineVariables,Ke=s.variableIdRemapping;s.inAsyncStateMachine={futureType:o},s.variableIdRemapping=i.variableIdRemapping;let Pe=new Map;for(let Z of i.capturedVariables)Pe.set(Z.id,Z);if(a)for(let Z of a.fields)Pe.set(Z.label,{id:Z.label,name:Z.label,type:Z.type,kind:"outer",isOwningTheSameRcValueAs:void 0});s.stateMachineVariables=Pe;for(let Z of _e){let X=q(Z," ",s);X&&X.includes("sm->")&&l.emitLine(` ${X};`)}s.inAsyncStateMachine=ye,s.stateMachineVariables=Re,s.variableIdRemapping=Ke}}l.emitLine(` ASYNC_DEBUG("${t}: Re-evaluating while loop condition\\n");`);let Et=s.declaredTempVars;if(s.declaredTempVars=void 0,nt.stepExpr){let _e=s.inAsyncStateMachine,ye=s.stateMachineVariables,Re=s.variableIdRemapping;s.inAsyncStateMachine={futureType:o},s.variableIdRemapping=i.variableIdRemapping;let Ke=new Map;for(let Z of i.capturedVariables)Ke.set(Z.id,Z);if(a)for(let Z of a.fields)Ke.set(Z.label,{id:Z.label,name:Z.label,type:Z.type,kind:"outer",isOwningTheSameRcValueAs:void 0});s.stateMachineVariables=Ke;let Pe=q(nt.stepExpr," ",s);Pe&&l.emitLine(` ${Pe};`),s.inAsyncStateMachine=_e,s.stateMachineVariables=ye,s.variableIdRemapping=Re}let Lt=s.inAsyncStateMachine,nn=s.stateMachineVariables,te=s.variableIdRemapping;s.inAsyncStateMachine={futureType:o},s.variableIdRemapping=i.variableIdRemapping;let pe=new Map;for(let _e of i.capturedVariables)pe.set(_e.id,_e);if(a)for(let _e of a.fields)pe.set(_e.label,{id:_e.label,name:_e.label,type:_e.type,kind:"outer",isOwningTheSameRcValueAs:void 0});s.stateMachineVariables=pe;let $e=q(nt.conditionExpr," ",s);s.inAsyncStateMachine=Lt,s.stateMachineVariables=nn,s.variableIdRemapping=te,s.declaredTempVars=Et,l.emitLine(` if (!(${$e})) {`),l.emitLine(` sm->while_loop_${Ft}_active = false;`),l.emitLine(` ASYNC_DEBUG("${t}: While loop condition false, exiting loop\\n");`),l.emitLine(" } else {"),l.emitLine(` ASYNC_DEBUG("${t}: While loop condition true, continuing iteration\\n");`);let ie=Ft;l.emitLine(" // Loop back by transitioning to while loop state"),l.emitLine(` sm->state = ${ie};`),l.emitLine(` goto while_loop_${ie}_start;`),l.emitLine(" }"),l.emitLine(" }"),l.emitLine(""),l.emitLine(` after_while_loop_${Ft}:`)}if(!qt&&nt.condBranchPostWhileExprs){let Et=nt.condBranchPostWhileExprs,Lt=Et.condBranchFieldIndex,nn=Et.branchIndex;Et.skipCondBranchCheck?(l.emitLine(" // Execute post-while-loop code from cond branch (unconditional)"),l.emitLine(" {")):(l.emitLine(" // Execute post-while-loop code from cond branch"),l.emitLine(` if (sm->cond_branch_${Lt} == ${nn}) {`));let te=s.inAsyncStateMachine,pe=s.stateMachineVariables,$e=s.variableIdRemapping,ie=s.pendingDeferredDrops;s.inAsyncStateMachine={futureType:o},s.variableIdRemapping=i.variableIdRemapping,s.pendingDeferredDrops=[...((R=e.$)==null?void 0:R.deferredDropExpressions)??[]];let _e=new Map;for(let Pe of i.capturedVariables)_e.set(Pe.id,Pe);if(a)for(let Pe of a.fields)_e.set(Pe.label,{id:Pe.label,name:Pe.label,type:Pe.type,kind:"outer",isOwningTheSameRcValueAs:void 0});s.stateMachineVariables=_e;let ye=Se.awaitPoint!=null,Re=!1,Ke=[];for(let Pe=0;Pe<Et.exprs.length;Pe++){let Z=Et.exprs[Pe];if(Re){Ke.push(Z);continue}if(ye&&er(Z)){Re=!0,Ll(Z,Se.awaitPoint,i," ",s);continue}let X=q(Z," ",s);!X||!Z.$||Ht(Z.$.env.modulePath,X)||l.emitLine(` ${X};`)}if(Re&&Se.awaitPoint){let Pe=Se.awaitPoint.index;At.asyncCondBranchInfo||(At.asyncCondBranchInfo=new Map);let Z=Et.skipCondBranchCheck?-1:Et.condBranchFieldIndex,X=At.asyncCondBranchInfo.get(Pe);X?(X.chainedBranches||(X.chainedBranches=[]),X.chainedBranches.push({branches:[{index:Et.branchIndex,value:Et.exprs[0],hasAwait:Ke.length>0||Ke.some(ge=>er(ge)),remainingExprs:Ke,deferredDropExpressions:Et.deferredDropExpressions}],condBranchFieldIndex:Z})):At.asyncCondBranchInfo.set(Pe,{branches:[{index:Et.branchIndex,value:Et.exprs[0],hasAwait:Ke.length>0||Ke.some(ge=>er(ge)),remainingExprs:Ke,deferredDropExpressions:Et.deferredDropExpressions}],condBranchFieldIndex:Z})}if(!Re&&Et.deferredDropExpressions)for(let Pe of Et.deferredDropExpressions){let Z=q(Pe," ",s);Z&&Z.includes("sm->")&&l.emitLine(` ${Z};`)}l.emitLine(" }"),s.inAsyncStateMachine=te,s.stateMachineVariables=pe,s.variableIdRemapping=$e,s.pendingDeferredDrops=ie}if(nt.outerWhileLoop){let Et=nt.outerWhileLoop,Lt=Et.whileLoopIndex;if(l.emitLine(" // Execute remaining code from outer while loop body"),l.emitLine(` if (sm->while_loop_${Lt}_active) {`),Et.bodyExprsAfterAwait.length>0){let te=s.inAsyncStateMachine,pe=s.stateMachineVariables,$e=s.variableIdRemapping,ie=s.pendingDeferredDrops;s.inAsyncStateMachine={futureType:o},s.variableIdRemapping=i.variableIdRemapping,s.pendingDeferredDrops=[...((D=Et.bodyExpr.$)==null?void 0:D.deferredDropExpressions)??[],...((H=e.$)==null?void 0:H.deferredDropExpressions)??[]];let _e=new Map;for(let Pe of i.capturedVariables)_e.set(Pe.id,Pe);if(a)for(let Pe of a.fields)_e.set(Pe.label,{id:Pe.label,name:Pe.label,type:Pe.type,kind:"outer",isOwningTheSameRcValueAs:void 0});s.stateMachineVariables=_e;let ye=s.smWhileBreakInfo,Re=s.smWhileContinueInfo,Ke=s.smWhileBodyDrops;s.smWhileBreakInfo={label:`after_while_loop_${Lt}`,activeIndex:Lt},s.smWhileContinueInfo={label:`while_loop_${Lt}_continue`},s.smWhileBodyDrops=[...((B=Et.bodyExpr.$)==null?void 0:B.deferredDropExpressions)??[]];for(let Pe of Et.bodyExprsAfterAwait){let Z=q(Pe," ",s);!Z||!Pe.$||Ht(Pe.$.env.modulePath,Z)||l.emitLine(` ${Z};`)}s.smWhileBreakInfo=ye,s.smWhileContinueInfo=Re,s.smWhileBodyDrops=Ke,s.inAsyncStateMachine=te,s.stateMachineVariables=pe,s.variableIdRemapping=$e,s.pendingDeferredDrops=ie}l.emitLine(` while_loop_${Lt}_continue:`);{let te=((G=Et.bodyExpr.$)==null?void 0:G.deferredDropExpressions)??[];if(te.length>0){let pe=s.inAsyncStateMachine,$e=s.stateMachineVariables,ie=s.variableIdRemapping;s.inAsyncStateMachine={futureType:o},s.variableIdRemapping=i.variableIdRemapping;let _e=new Map;for(let ye of i.capturedVariables)_e.set(ye.id,ye);if(a)for(let ye of a.fields)_e.set(ye.label,{id:ye.label,name:ye.label,type:ye.type,kind:"outer",isOwningTheSameRcValueAs:void 0});s.stateMachineVariables=_e;for(let ye of te){let Re=q(ye," ",s);Re&&Re.includes("sm->")&&l.emitLine(` ${Re};`)}s.inAsyncStateMachine=pe,s.stateMachineVariables=$e,s.variableIdRemapping=ie}}let nn=s.declaredTempVars;if(s.declaredTempVars=void 0,Et.stepExpr){let te=s.inAsyncStateMachine,pe=s.stateMachineVariables,$e=s.variableIdRemapping;s.inAsyncStateMachine={futureType:o},s.variableIdRemapping=i.variableIdRemapping;let ie=new Map;for(let ye of i.capturedVariables)ie.set(ye.id,ye);if(a)for(let ye of a.fields)ie.set(ye.label,{id:ye.label,name:ye.label,type:ye.type,kind:"outer",isOwningTheSameRcValueAs:void 0});s.stateMachineVariables=ie;let _e=q(Et.stepExpr," ",s);_e&&l.emitLine(` ${_e};`),s.inAsyncStateMachine=te,s.stateMachineVariables=pe,s.variableIdRemapping=$e}{let te=s.inAsyncStateMachine,pe=s.stateMachineVariables,$e=s.variableIdRemapping;s.inAsyncStateMachine={futureType:o},s.variableIdRemapping=i.variableIdRemapping;let ie=new Map;for(let ye of i.capturedVariables)ie.set(ye.id,ye);if(a)for(let ye of a.fields)ie.set(ye.label,{id:ye.label,name:ye.label,type:ye.type,kind:"outer",isOwningTheSameRcValueAs:void 0});s.stateMachineVariables=ie;let _e=q(Et.conditionExpr," ",s);s.inAsyncStateMachine=te,s.stateMachineVariables=pe,s.variableIdRemapping=$e,l.emitLine(` if (!(${_e})) {`),l.emitLine(` sm->while_loop_${Lt}_active = false;`),l.emitLine(" } else {"),l.emitLine(` sm->state = ${Ze.index};`),l.emitLine(` goto while_loop_${Lt}_start;`),l.emitLine(" }")}s.declaredTempVars=nn,l.emitLine(" }"),l.emitLine(""),l.emitLine(` after_while_loop_${Lt}:`)}}}}let ee=s.inAsyncStateMachine,fe=s.stateMachineVariables,me=s.variableIdRemapping;s.inAsyncStateMachine={futureType:o},s.variableIdRemapping=i.variableIdRemapping;let Le=new Map;for(let Ze of i.capturedVariables)Le.set(Ze.id,Ze);if(a)for(let Ze of a.fields)Le.set(Ze.label,{id:Ze.label,name:Ze.label,type:Ze.type,kind:"outer",isOwningTheSameRcValueAs:void 0});s.stateMachineVariables=Le;let qe=s.pendingDeferredDrops;s.pendingDeferredDrops=[...((Q=e.$)==null?void 0:Q.deferredDropExpressions)??[]];let dt=de&&!c&&Se.expressions.length>0,kt=Se.expressions.length>0?Se.expressions[Se.expressions.length-1]:void 0,Rt=s.asyncBodyReturnExpr;if(!c&&kt&&m&&kt===m&&Se.awaitPoint?s.asyncBodyReturnExpr=kt:s.asyncBodyReturnExpr=void 0,Qc(Se," ",s,dt),s.asyncBodyReturnExpr=Rt,s.pendingDeferredDrops=qe,l.emitLine(""),Se.awaitPoint){s.inAsyncStateMachine=ee,s.stateMachineVariables=fe,s.variableIdRemapping=me;let Ze=Ve+1;{let Tt=xu(Se.awaitPoint,i),At=(Y=Se.awaitPoint.expr.args)==null?void 0:Y[0],gt=es((J=At==null?void 0:At.$)==null?void 0:J.type),nt=(se=Se.awaitPoint)==null?void 0:se.isInsideCond;nt&&(l.emitLine(" // Only await if the cond branch with await was taken"),l.emitLine(` if (sm->${Tt} != NULL) {`));let Ft=(ve=Se.awaitPoint)==null?void 0:ve.isInsideWhile,qt=Ft?(re=s.asyncWhileLoopInfo)==null?void 0:re.get(Se.awaitPoint.index):void 0;if(Ft&&qt){let Et=qt.whileLoopOriginIndex??Se.awaitPoint.index;l.emitLine(" // Only await if while loop is still active (not broken)"),l.emitLine(` if (sm->while_loop_${Et}_active) {`)}if(l.emitLine(" // Transition to next state after await"),l.emitLine(` sm->state = ${Ze};`),l.emitLine(""),l.emitLine(" // Check if future is ready"),l.emitLine(` int future_state = sm->${Tt}->state;`),l.emitLine(" if (future_state == -1 || future_state == -2) { // -1 = completed, -2 = aborted"),l.emitLine(" // Already complete \u2014 bounded inline fast-path to avoid scheduler round-trip"),l.emitLine(" if (__yo_inline_budget > 0) {"),l.emitLine(" __yo_inline_budget--;"),l.emitLine(` goto state_${Ze};`),l.emitLine(" }"),l.emitLine(" // Budget exhausted \u2014 yield once for fairness (microtask yield)"),l.emitLine(` __yo_async_spawn_task((void (*)(void*))${r}, (void*)sm);`),l.emitLine(" return;"),l.emitLine(" }"),l.emitLine(""),gt?l.emitLine(" // IO future: no extra ref needed (completion handler does not decr_rc)"):(l.emitLine(" // Future not complete \u2014 take event loop reference and start if cold"),l.emitLine(` __yo_incr_rc((void*)sm->${Tt}); // event loop reference`)),gt||(l.emitLine(" if (future_state == 0) { // 0 = cold (not started)"),Wh(Se.awaitPoint.expr,`sm->${Tt}`," ",s),l.emitLine(" // Cold future \u2014 start it via stored resume function pointer"),l.emitLine(` sm->${Tt}->__yo_resume_fn((void*)sm->${Tt});`),l.emitLine(""),l.emitLine(" // Re-check: may have completed synchronously"),l.emitLine(` future_state = sm->${Tt}->state;`),l.emitLine(" if (future_state == -1 || future_state == -2) {"),l.emitLine(" // Completed or aborted synchronously \u2014 yield for fairness"),l.emitLine(` __yo_async_spawn_task((void (*)(void*))${r}, (void*)sm);`),l.emitLine(" return;"),l.emitLine(" }"),l.emitLine(" }")),l.emitLine(""),l.emitLine(" // Still pending \u2014 register continuation and suspend"),l.emitLine(` sm->${Tt}->continuation_fn = (void (*)(void*))${r};`),l.emitLine(` sm->${Tt}->continuation_sm = (void*)sm;`),l.emitLine(" return;"),Ft&&qt){let Et=qt.whileLoopOriginIndex??Se.awaitPoint.index;l.emitLine(" } else {"),l.emitLine(" // While loop was broken, jump to code after loop"),l.emitLine(` goto after_while_loop_${Et};`),l.emitLine(" }")}nt&&(l.emitLine(" } else {"),l.emitLine(" // Non-await cond branch was taken, skip directly to next state"),l.emitLine(` sm->state = ${Ze};`),l.emitLine(` goto state_${Ze};`),l.emitLine(" }"))}}else if(de){if(!Se.expressions.some(Tt=>tf(Tt))){if((ce=e.$)!=null&&ce.deferredDropExpressions){let Tt=new oo,Jt=s.emitter;s.emitter=Tt;for(let gt of e.$.deferredDropExpressions){let nt=q(gt,"",s);nt&&Tt.emitLine(`${nt};`)}s.emitter=Jt;let At=Tt.print().trim();if(At){l.emitLine(" // Drop local variables before completion");for(let gt of At.split(`
|
|
196
|
-
`)){let nt=gt.trim();nt&&(l.emitLine(` ${nt}`),h.push(nt))}l.emitLine("")}}l.emitLine(" // Final state - complete the Future"),Ni({emitter:l,indent:" ",debugLabel:"Future %p completed"})}s.inAsyncStateMachine=ee,s.stateMachineVariables=fe,s.variableIdRemapping=me}else s.inAsyncStateMachine=ee,s.stateMachineVariables=fe,s.variableIdRemapping=me;l.emitLine(" }")}return l.emitLine(" }"),l.emitLine("}"),l.emitLine(""),h}function Ll(e,t,n,r,i){let o=i.emitter,a=xu(t,n);if(e.tag==="FnCall"&&E(e,":=")){let s=e.args[1];if(s&&s.tag==="FnCall"&&_r(s)){let l=s.args[0];if(l){let u=q(l,r,i);o.emitLine(`${r}// Store Future for additional await in cond branch`),o.emitLine(`${r}sm->${a} = ${u};`)}}return}if(e.tag==="FnCall"&&_r(e)){let s=e.args[0];if(s){let l=q(s,r,i);o.emitLine(`${r}// Store Future for additional await in cond branch`),o.emitLine(`${r}sm->${a} = ${l};`)}return}if(e.tag==="FnCall"&&E(e,P.cond)){fa(e,t,0,r,i);return}if(e.tag==="FnCall"&&E(e,P.match)){fa(e,t,0,r,i);return}if(e.tag==="FnCall"&&E(e,P.while)){fa(e,t,0,r,i);return}if(e.tag==="FnCall"&&E(e,P.begin)){fa(e,t,0,r,i);return}o.emitLine(`${r}// Warning: unhandled await pattern in remaining expressions`)}function tf(e){if(ln(e,"return")||E(e,"return"))return!0;if(e.tag==="FnCall"){for(let t of e.args)if(tf(t))return!0}return!1}function Gh(e){let t=[];for(let n of e)if(n.isEffectRowSpread){let r=n.type;z(r)&&r.resolvedConcreteType&&(r=r.resolvedConcreteType),Yt(r)&&t.push(...r.implicitParameters)}else t.push(n);return t}function Wh(e,t,n,r){var u,_,c,f,p;let i=(u=e.args)==null?void 0:u[0];if(!((_=i==null?void 0:i.$)!=null&&_.type))return;let o=Ln(i.$.type);if(!((c=o==null?void 0:o.isFuture.effects)!=null&&c.length))return;let a=Gh(o.isFuture.effects),s=r.emitter,l=(f=e.args)==null?void 0:f.find(m=>S(m)&&E(m,P.using));if(l){let m=l.args;for(let h=0;h<a.length&&h<m.length;h++){let y=a[h],g=m[h];if(ne(y.type)){if(y.type.forallParameters.length>0)continue;let v=q(g,n,r),T=y.label;s.emitLine(`${n}${t}->__capture.${T} = (void*)${v};`)}else Xe(y.type)&&Jc(y.type,t,n,(p=g.$)==null?void 0:p.value,r,e)}}else for(let m of a)if(ne(m.type)){if(m.type.forallParameters.length>0)continue;let h=qh(m.label,r,e);h&&s.emitLine(`${n}${t}->__capture.${m.label} = (void*)${h};`)}else Xe(m.type)&&Jc(m.type,t,n,void 0,r,e)}function Jc(e,t,n,r,i,o){var s,l,u,_;let a=i.emitter;for(let c of e.fields){if(!ne(c.type))continue;let f;if(i.stateMachineVariables){for(let[,p]of i.stateMachineVariables)if(p.name===c.label&&p.kind==="outer"){f=`sm->__capture.${c.label}`;break}}if(!f&&r&&wt(r)){let p=e.fields.indexOf(c),m=r.fields[p];if(m&&he(m)){let h=i.functions[m.funcId];h&&(f=h.cName)}}if(!f&&i.currentEvidenceParams){for(let p of i.currentEvidenceParams.values())if(p.fieldLabel===c.label){f=p.cParamName;break}}if(!f){let p=((s=o.$)==null?void 0:s.env)??((l=o.func.$)==null?void 0:l.env);if(p){let m=cr(p,h=>h.isImplicit===!0);for(let h=m.length-1;h>=0;h--){let y=m[h],g=(u=y.value)==null?void 0:u[y.value.length-1];if(g&&wt(g)){let v=g.type.fields.findIndex(T=>T.label===c.label);if(v>=0){let T=g.fields[v];if(T&&he(T)){let $=(_=i.functions[T.funcId])==null?void 0:_.cName;if($){f=$;break}}}}}}}f&&a.emitLine(`${n}${t}->__capture.${c.label} = (void*)${f};`)}}function qh(e,t,n){if(t.currentEvidenceParams){for(let r of t.currentEvidenceParams.values())if(r.fieldLabel===e)return r.cParamName}if(t.stateMachineVariables){for(let[,r]of t.stateMachineVariables)if(r.name===e&&r.kind==="outer")return`sm->__capture.${e}`}}var Yh=new Set(["__yo_mutex_init","__yo_mutex_destroy","__yo_mutex_lock","__yo_mutex_unlock","__yo_cond_init","__yo_cond_destroy","__yo_cond_wait","__yo_cond_signal","__yo_cond_broadcast","__yo_thread_join","__yo_thread_self"]);function nf(e){var n,r,i,o,a;let t=e.emitter;t.emitDeclarationLine("// Function declarations"),t.emitDeclarationLine("/// Extern functions");for(let s in e.externFunctions){let{cName:l,type:u}=e.externFunctions[s];if(u.isExtern==="yo"){if(Yh.has(l))continue;Du(u,l,!0,e);continue}u.isExtern==="c"&&u.cInclude||l.startsWith("__atomic_")||l.startsWith("__sync_")||Du(u,l,!0,e)}t.emitDeclarationLine(""),e.usesAsync&&(t.emitDeclarationLine("/// Async runtime functions"),t.emitDeclarationLine("static void __yo_async_spawn_task(void (*resume_fn)(void*), void* state_machine);"),t.emitDeclarationLine("")),t.emitDeclarationLine("/// Object constructors"),jh(e),t.emitDeclarationLine(""),t.emitDeclarationLine("/// Closure constructors"),t.emitDeclarationLine(""),t.emitDeclarationLine("/// Capture dispose functions"),Kh(e),t.emitDeclarationLine(""),t.emitDeclarationLine("/// Dyn type constructors"),t.emitDeclarationLine(""),t.emitDeclarationLine("/// Regular functions");for(let s in e.functions){let{cName:l,value:u}=e.functions[s],_=l==="__yo_user_main",c=(r=(n=u.body)==null?void 0:n.$)==null?void 0:r.effectAnalysis,f=c&&c.hasEffects;if(!_&&!u.type.isClosure&&((i=u.specializedFunctionCaches)==null?void 0:i.length)>0||!_&&!f&&!u.isModuleEffectMember&&!u.type.isClosure&&!u.specializedType&&(((o=u.specializedFunctionCaches)==null?void 0:o.length)??0)===0&&pn(u.specializedType??u.type).length===0&&[...u.type.implicitParameters,...u.type.parameters.filter($=>$.isImplicit)].some($=>ne($.type)))continue;let m=u.specializedType??u.type,h=pn(m).length>0;if(!_&&u.isIoAsyncStateMachineClosure||!_&&!f&&!h&&!u.isModuleEffectMember&&(li(u.type)&&!u.type.isClosure||((a=u.specializedFunctionCaches)==null?void 0:a.length)>0&&!u.type.isClosure||Qi(u)||gi(u)||u.isIoAsyncStateMachineClosure))continue;let y=u.specializedType??u.type,g=!f&&!u.isModuleEffectMember&&(y.parameters.some($=>Me($.type))||y.forallParameters.length>0),v=Me(y.return.type),T=z(y.return.type)&&y.return.type.requiredTraits.length>0;g||v&&!T&&!u.isModuleEffectMember||Du(y,l,!1,e,u.isModuleEffectMember?void 0:u.body,u.specializedType&&pn(y).length===0&&pn(u.type).some($=>$.fieldFunctionType.forallParameters&&$.fieldFunctionType.forallParameters.length>0)?u.type:void 0)}t.emitDeclarationLine("/// Closure vtable instances"),t.emitDeclarationLine("")}function pn(e){let t=[],n=Hh(e.implicitParameters);for(let r of n)Xe(r.type)?rf(r.label,r.type,[],t):ne(r.type)&&t.push({implicitLabel:r.label,fieldLabel:r.label,fieldPath:[r.label],fieldFunctionType:r.type,cParamName:be(r.label)});return t}function rf(e,t,n,r){for(let i of t.fields)if(ne(i.type)){let o=[...n,i.label],a=o.join("__");r.push({implicitLabel:e,fieldLabel:a,fieldPath:o,fieldFunctionType:i.type,cParamName:be(`${e}__${a}`)})}else Xe(i.type)&&rf(e,i.type,[...n,i.label],r)}function Hh(e){let t=[];for(let n of e)if(n.isEffectRowSpread){let r=n.type;z(r)&&r.resolvedConcreteType&&(r=r.resolvedConcreteType),Yt(r)&&t.push(...r.implicitParameters)}else t.push(n);return t}function hi(e,t,n,r,i){let o=r||j(e.return.type,n),a=e.parameters.filter(c=>!c.isCompileTimeOnly),s=[];e.isClosure&&s.push("void* closure_context");let l=a.map((c,f)=>{let p=be(c.label||`param${f}`);if(ne(c.type))return hi(c.type,"(*)",n).replace(" (*)(",` (*${p})(`);{let m;return z(c.type)&&at(c.type)?c.type.resolvedConcreteType?m=j(c.type.resolvedConcreteType,n)+"*":m=j(c.type,n):m=j(c.type,n),`${m} ${p}`}});s.push(...l);let u=pn(i??e);for(let c of u)if(c.fieldFunctionType.forallParameters&&c.fieldFunctionType.forallParameters.length>0)s.push(`void* ${c.cParamName}`);else{let f=hi(c.fieldFunctionType,"(*)",n).replace(" (*)(",` (*${c.cParamName})(`);s.push(f)}let _=s.join(", ");return`${o} ${t}(${_})`}function Du(e,t,n,r,i,o){var f,p,m,h;let a;if(i&&at(e.return.type)){let y=Qa(i);(f=y==null?void 0:y.$)!=null&&f.asyncStateMachineStructName?a=`${y.$.asyncStateMachineStructName}*`:(p=i.$)!=null&&p.type&&z(i.$.type)&&at(i.$.type)&&(a=j(i.$.type,r))}if(i&&z(e.return.type)&&!at(e.return.type)&&(m=i.$)!=null&&m.type&&(a=j(i.$.type,r)),!a&&i&&((h=i.$)!=null&&h.type)&&!at(e.return.type)){let y=j(e.return.type,r),g=j(i.$.type,r);y!==g&&(a=g)}let s=a?hi(e,t,r,a,o):hi(e,t,r,void 0,o),l=M(e),u=t==="__yo_user_main"||r.exportedFunctionLabels&&[...r.exportedFunctionLabels.values()].some(y=>be(y)===t),_=!n&&!u&&(t.includes("___drop")||t.includes("___dup")||t.includes("___dispose")),c=n?"extern ":u?"":_?"static inline __attribute__((always_inline)) ":"static inline ";r.emitter.emitDeclarationLine(`${c}${s}; // ${l}`)}function jh(e){let t=e.emitter;t.emitDeclarationLine("static inline void __yo_decr_rc(void* ptr); // Decrement reference count"),t.emitDeclarationLine("static inline void* __yo_incr_rc(void* ptr); // Increment reference count"),t.emitDeclarationLine("static void __yo_gc_register(void* ptr); // Register object for cycle detection"),t.emitDeclarationLine("static void __yo_gc_unregister(void* ptr); // Unregister object from cycle detection"),t.emitDeclarationLine("static void __yo_gc_collect(); // Trigger garbage collection"),t.emitDeclarationLine("static void __yo_gc_init_thread(); // Initialize thread-local GC state (for worker threads)"),t.emitDeclarationLine("static void __yo_cleanup_thread_gc(); // Clean up thread-local GC state"),t.emitDeclarationLine("static void __yo_init_process_cleanup(void); // Initialize process cleanup");for(let n in e.types){let{type:r,cName:i}=e.types[n];if(Ae(r)&&r.isReferenceSemantics){if(r.fields.some(l=>Me(l.type)))continue;let a=`__yo_new_${i}`,s=r.fields.map(l=>{let u=j(l.type,e),_=be(l.label);return`${u} ${_}`}).join(", ");t.emitDeclarationLine(`static ${i}* ${a}(${s}); // Constructor`)}}}function Kh(e){let t=e.emitter;if(e.closureCaptureMap&&e.closureCaptureMap.size>0)for(let[n]of e.closureCaptureMap){let r=`__yo_dispose_closure_${n}`;t.emitDeclarationLine(`static void ${r}(void* closure_ptr);`)}}function of(e){let t=new Set;for(let n in e.functions){let{value:r,cName:i}=e.functions[n],o=r.specializedType;if(Qi(r)||!o||!Rr(r.type)||Rr(o))continue;let a=o.parameters.some(c=>Me(c.type)),s=Me(o.return.type);if(a||s||pn(r.type).some(c=>c.fieldFunctionType.forallParameters&&c.fieldFunctionType.forallParameters.length>0)||t.has(n))continue;t.add(n);let _=i.includes("___drop")||i.includes("___dup")||i.includes("___dispose")?"static inline __attribute__((always_inline)) ":"static inline ";e.emitter.emitDeclarationLine(`${_}${hi(o,i,e)}; // specialized function: ${M(r.type)}`)}}function vi(e,t,n){let r=ae(t,e);return r.length===0?!1:r[r.length-1].frameLevel<=n}function af(e){var t,n;return!!((t=e.$)!=null&&t.closureFunctionValue&&((n=e.$)!=null&&n.type)&&zn(e.$.type))}function Xh(e,t,n,r,i,o=!1){var p;let a=Object.values(i.types).find(m=>m.type===e);if(!a)return i.emitter.emitLine(`${r}/* Error: Capture type not found for closure */`),null;let s=a.cName,l=new Map;if((p=n.$)!=null&&p.deferredDupExpressions)for(let m of n.$.deferredDupExpressions){let h=Fl(m);h&&l.set(h,m)}let u=e.fields.map(m=>{var v,T;if(m.isEffectParam)return"NULL";let h,y=m.exprs.expr;if((T=(v=y.$)==null?void 0:v.deferredDupExpressions)!=null&&T.length&&(h=y.$.deferredDupExpressions[0]),!h){let $=[m.label];K(y)&&$.push(y.token.value);for(let C of $){let k=l.get(C);if(k){h=k;break}}}if(h)return q(h,r,i);let g={tag:"Atom",token:y.token,$:y.$};return q(g,r,i)}),_=`(${s}){ ${u.map((m,h)=>{let y=e.fields[h];return y?`.${y.label} = ${m}`:`/* Error: missing field at index ${h} */`}).join(", ")} }`,c=n.token.position.row!==void 0?`${Date.now()}_${n.token.position.row}`:`${Date.now()}_${Math.random().toString(36).substr(2,9)}`,f=`__capture_${t}_${c}`;return o?i.emitter.emitLine(`${r}${s} ${f} = ${_};`):(i.emitter.emitLine(`${r}${s}* ${f} = (${s}*)__yo_malloc(sizeof(${s}));`),i.emitter.emitLine(`${r}*${f} = ${_};`)),{captureTempVar:f,captureCName:s}}function sf(e,t,n){var m,h;if(!e.$||!e.$.type||!e.$.closureFunctionValue)return"// Error: Missing closure metadata";let r=Kn(e.$.type),i=r.isFn.callType,o=e.$.closureFunctionValue,a=e.$.captureType,s=(m=n.functions[o.funcId])==null?void 0:m.cName;if(!s)return"// Error: Closure implementation function not found in context";let l=st(e.$.type),u;if(l){let y=n.types[e.$.type.id];if(!y)return"// Error: Dyn closure type not found in context";u=y.cName}let _=a&&Ae(a)&&a.fields.length>0,c=j(i.return.type,n),f=i.parameters.map(y=>j(y.type,n)).join(", "),p=`(${c} (*)(void*${f?", "+f:""}))${s}`;if(_&&a&&Ae(a)){let y=!l,g=Xh(a,i.id,e,t,n,y);if(!g)return"// Error: Failed to allocate closure capture";let{captureTempVar:v}=g;if(l){let T=`__yo_create_${u}`,$=`__yo_dispose_${u}`;return`${T}(${v}, ${$}, ${p})`}else return n.implClosureCallMap.set(a.id,{functionCName:s,callTypeId:r.isFn.callType.id,callType:r.isFn.callType,consumedCaptures:(h=o.closureInfo)==null?void 0:h.consumedCaptures}),v}else if(l){let y=`__yo_create_${u}`,g=`__yo_dispose_${u}`;return`${y}(NULL, ${g}, ${p})`}else{if(e.$.type.tag==="SomeType"){let y=e.$.type;if(y.resolvedConcreteType)return n.implClosureCallMap.set(y.resolvedConcreteType.id,{functionCName:s,callTypeId:r.isFn.callType.id,callType:r.isFn.callType}),`(${j(y.resolvedConcreteType,n)}){}`}return"// Error: Impl(Fn(...)) without captures missing resolvedConcreteType"}}function Mu(e,t,n){if(e.pendingDeferredDrops&&e.loopBodyDropsBaselineCount!==void 0){let r=e.loopBodyDropsBaselineCount,i=e.pendingDeferredDrops.length,o=e.pendingDeferredDrops.slice(0,i-r);for(let a of o){let s=q(a,t,n);s&&n.emitter.emitLine(`${t}${s};`)}}}function pa(e,t,n=""){var a,s,l,u,_,c,f,p,m,h,y,g,v,T,$,C,k,b,w,A,L,N,x,V,U,R,D,H,B;let r=t;if(e.token.value==="continue"){if(r.currentContinueLabel)return Mu(r,n,t),`goto ${r.currentContinueLabel}`;if(r.currentLoopLabel)return Mu(r,n,t),"continue";if(r.smWhileContinueInfo){if(r.smWhileContinueInfo.emitDropsBeforeGoto&&r.smWhileBodyDrops&&r.smWhileBodyDrops.length>0){let G=t.emitter;for(let Q of r.smWhileBodyDrops){let Y=q(Q,n,t);Y&&Y.includes("sm->")&&G.emitLine(`${n}${Y};`)}}if(r.smWhileContinueInfo.stepExpr){let G=t.emitter,Q=q(r.smWhileContinueInfo.stepExpr,n,t);Q&&G.emitLine(`${n}${Q};`)}return`goto ${r.smWhileContinueInfo.label}`}return"continue"}if(e.token.value==="break"){if(r.currentLoopLabel)return Mu(r,n,t),r.insideMatch?`goto ${r.currentLoopLabel}`:"break";if(r.smWhileBreakInfo){let{label:G,activeIndex:Q}=r.smWhileBreakInfo;if(r.smWhileBodyDrops&&r.smWhileBodyDrops.length>0){let Y=t.emitter;for(let J of r.smWhileBodyDrops){let se=q(J,n,t);se&&se.includes("sm->")&&Y.emitLine(`${n}${se};`)}}return Q!==void 0?(t.emitter.emitLine(`${n}sm->while_loop_${Q}_active = false;`),`goto ${G}`):`goto ${G}`}return"break"}if(e.token.value==="return"){if(r.inAsyncStateMachine){let G=t.emitter,Q=r.inAsyncStateMachine.futureType,J=Ln(Q).isFuture.outputType,se=De(J);if((a=e.$)!=null&&a.deferredDropExpressions)for(let re of e.$.deferredDropExpressions){let ce=q(re,n,t);ce&&ce.includes("sm->")&&G.emitLine(`${n}${ce};`)}if(r.pendingDeferredDrops&&r.pendingDeferredDrops.length>0){G.emitLine(`${n}// Drop local variables before early completion`);for(let re of r.pendingDeferredDrops){let ce=q(re,n,t);ce&&ce.includes("sm->")&&G.emitLine(`${n}${ce};`)}}G.emitLine(`${n}// Early return - complete the result Future`);let ve=se?void 0:`(${j(J,t)}){0}`;return Ni({emitter:G,indent:n,resultCode:ve,debugLabel:t.currentFunctionName}),""}return"return"}if((s=e.$)!=null&&s.type&&De(e.$.type))return"";if((r.inAsyncStateMachine||r.inEffectStateMachine)&&r.stateMachineVariables){let G=e.token.value;if((l=r.localShadowedVariables)!=null&&l.has(G))return be(G);let Q=!1;if((u=e.$)!=null&&u.env){let Y=ae(e.$.env,G);if(Y.length>0){let J=Y[Y.length-1],se=J.isOwningTheSameRcValueAs?J.isOwningTheSameRcValueAs.id:J.id;(_=r.variableIdRemapping)!=null&&_.has(se)&&(se=r.variableIdRemapping.get(se));let ve=r.stateMachineVariables.get(se);if(ve){let re=(c=r.stateMachineFieldAliases)==null?void 0:c.get(se);if(re)return Q=!0,`sm->${re}`;let ce=ve.kind==="outer"?`__capture.${G}`:`var_${ve.id}`;return Q=!0,`sm->${ce}`}}}if(!Q){for(let[Y,J]of r.stateMachineVariables)if(J.name===G){let se=(f=r.stateMachineFieldAliases)==null?void 0:f.get(Y);if(se)return Q=!0,`sm->${se}`;let ve=J.kind==="outer"?`__capture.${G}`:`var_${Y}`;return Q=!0,`sm->${ve}`}}if((p=e.$)!=null&&p.env){let Y=ae(e.$.env,G);if(Y.length>0){let J=Y[Y.length-1];if(J.isOwningTheSameRcValueAs){let se=J.isOwningTheSameRcValueAs.name,ve=J.isOwningTheSameRcValueAs.id;for(let[re,ce]of r.stateMachineVariables)if(ce.name===se||re===ve)return`sm->${ce.kind==="outer"?`__capture.${se}`:`var_${re}`}`}}}if(r.currentClosureCaptures&&r.currentClosureCaptures.includes(G)&&r.currentClosureCaptureFrameLevel!==void 0){let Y=r.currentClosureCaptureTypeCName;return Y?`((${Y}*)closure_context)->${We(G,(m=e.$)==null?void 0:m.env)}`:`closure_context->${We(G,(h=e.$)==null?void 0:h.env)}`}if((y=e.$)!=null&&y.variableName){if((g=e.$)!=null&&g.env&&((v=e.$)!=null&&v.value)&&!Ie(e.$.value)){let Y=ae(e.$.env,e.$.variableName);if(Y.length>0&&Y[Y.length-1].isCompileTimeOnly)return Yn(e.$.value,t,e)}return We(e.$.variableName,e.$.env)}}if((T=e.$)!=null&&T.variableName){if(($=e.$)!=null&&$.env&&((C=e.$)!=null&&C.value)&&!Ie(e.$.value)){let G=ae(e.$.env,e.$.variableName);if(G.length>0&&G[G.length-1].isCompileTimeOnly)return Yn(e.$.value,t,e)}if(!(r.currentClosureCaptures&&r.currentClosureCaptures.includes(e.token.value)&&((k=e.$)!=null&&k.env)&&r.currentClosureCaptureFrameLevel!==void 0&&vi(e.token.value,e.$.env,r.currentClosureCaptureFrameLevel)))return We(e.$.variableName,(b=e.$)==null?void 0:b.env)}if((w=e.$)!=null&&w.value&&!Ie(e.$.value))return Yn(e.$.value,t,e);let i=(A=e.$)!=null&&A.env&&r.currentClosureCaptureFrameLevel!==void 0?vi(e.token.value,e.$.env,r.currentClosureCaptureFrameLevel):!1;if(r.currentClosureCaptures&&r.currentClosureCaptures.includes(e.token.value)&&r.currentClosureCaptureFrameLevel!==void 0&&(!((L=e.$)!=null&&L.env)||i)){let G=r.currentClosureCaptureTypeCName;return G?`((${G}*)closure_context)->${We(e.token.value,(N=e.$)==null?void 0:N.env)}`:`closure_context->${We(e.token.value,(x=e.$)==null?void 0:x.env)}`}if(r.currentFunctionName&&!r.currentClosureCaptures){let G=Object.values(r.functions).find(Q=>Q.cName===r.currentFunctionName);if(G&&G.value.type.isClosure){let Q=Object.values(r.types).find(Y=>ne(Y.type)&&Y.type.isClosure&&Y.type===G.value.type);if(Q)return`((${`${Q.cName}_capture`}*)closure_context->data)->${We(e.token.value,(V=e.$)==null?void 0:V.env)}`}}if((U=e.$)!=null&&U.env){let G=ae(e.$.env,e.token.value);if(G.length>0){let Q=G[G.length-1];if((R=Q.value)!=null&&R[0]&&he(Q.value[0])){let Y=(D=t.functions[Q.value[0].funcId])==null?void 0:D.cName;if(Y)return Y}else if(ne(Q.type)&&(Ie((H=Q.value)==null?void 0:H[0])||Q.value===void 0)){let Y=Object.entries(t.functions).find(([J,se])=>se.value.funcName===e.token.value);if(Y)return Y[1].cName}}}return We(e.token.value,(B=e.$)==null?void 0:B.env)}function lf(e,t,n){var y,g,v,T,$,C,k,b,w,A,L,N,x,V,U,R,D,H,B,G;let r;if(An(e)){let Q=(g=(y=e.$)==null?void 0:y.runtimeArgExprsInOrder)==null?void 0:g[0],Y=(v=Q==null?void 0:Q.$)==null?void 0:v.closureFunctionValue;Y&&he(Y)&&(r=Y.body)}else r=e.args[0];if(!r)return"/* Error: async requires exactly 1 argument */";let i=(T=e.$)==null?void 0:T.type;if(!i||!at(i))return"/* Error: async block must have Future type */";let o=Ln(i);if(!o)return"/* Error: Could not extract Future module type */";let a=(($=e.$)==null?void 0:$.variableName)||`async_block_${Date.now()}`,s=`${a}_state_t`,l=`${a}_resume`,u=`__yo_new_${a}`,_=`${a}_state_dispose`;n.types[i.id]={type:i,cName:s};let c=(C=e.$)==null?void 0:C.awaitAnalysis;if(!c)throw new Error("Missing await analysis for async block. This should have been computed during evaluation.");let f=o.isFuture.outputType;if(z(f))if(f.resolvedConcreteType)f=f.resolvedConcreteType;else{let Q=(b=(k=e.$)==null?void 0:k.runtimeArgExprsInOrder)==null?void 0:b[0],Y=(w=Q==null?void 0:Q.$)==null?void 0:w.closureFunctionValue;if(Y&&he(Y)){let J=(L=(A=Y.type)==null?void 0:A.return)==null?void 0:L.type;if(J&&z(J)&&J.resolvedConcreteType)f=J.resolvedConcreteType;else if((x=(N=Y.body)==null?void 0:N.$)!=null&&x.type){let se=Y.body.$.type;z(se)&&se.resolvedConcreteType?f=se.resolvedConcreteType:z(se)||(f=se)}}}let p=j(f,n),m=n.emitter;if(m.emitDeclarationLine(`void ${_}(void* sm_ptr); // Dispose function for state machine`),m.emitDeclarationLine(""),m.emitDeclarationLine(`void ${l}(${s}* sm);`),m.emitDeclarationLine(""),(V=e.$)!=null&&V.captureType){let Q=e.$.captureType,Y=Object.values(n.types).find(se=>se.type===Q),J=Y?Y.cName:`async_capture_${Q.id}`;m.emitDeclarationLine(`${s}* ${u}(${J} __capture);`)}else m.emitDeclarationLine(`${s}* ${u}();`);m.emitDeclarationLine(""),n.deferredAsyncBlocks||(n.deferredAsyncBlocks=[]),n.deferredAsyncBlocks.push({bodyExpr:r,asyncBlockId:a,structName:s,resumeFunctionName:l,constructorName:u,disposeFunctionName:_,futureType:i,futureModuleType:o,resultType:f,resultTypeCName:p,captureType:(U=e.$)==null?void 0:U.captureType,analysis:c});let h=(R=e.$)==null?void 0:R.captureType;if(h){let Q=Object.values(n.types).find(Ve=>Ve.type===h),Y=Q?Q.cName:`async_capture_${h.id}`,J=n,se=J.currentClosureCaptures!==void 0||J.inAsyncStateMachine!==void 0||J.inEffectStateMachine!==void 0,ve=!1,re=h.fields.map(Ve=>{var fe,me;if(Ve.isEffectParam)return`.${Ve.label} = NULL`;let de;if(!se&&((fe=e.$)!=null&&fe.deferredDupExpressions))for(let Le of e.$.deferredDupExpressions){let qe;if(S(Le)&&(Le.args.length>0&&K(Le.args[0])?qe=Le.args[0].token.value:Le.args.length===0&&S(Le.func)&&E(Le.func,".")&&Le.func.args.length>=2&&K(Le.func.args[0])&&(qe=Le.func.args[0].token.value)),qe===Ve.label){de=Le;break}}if(de)return ve=!0,(me=de.$)!=null&&me.variableName?(q(de,t,n),`.${Ve.label} = ${de.$.variableName}`):`.${Ve.label} = ${q(de,t,n)}`;let ee={tag:"Atom",token:Ve.exprs.expr.token,$:Ve.exprs.expr.$};return`.${Ve.label} = ${pa(ee,n)}`}).join(", "),ce=`(${Y}){${re}}`;if(!ve){let Ve=fr(h,n);Ve&&(ce=`${Ve}(${ce})`)}let we=((D=e.$)==null?void 0:D.variableName)||"async_result",Se=`${u}(${ce})`;if(we&&((H=e.$)!=null&&H.type)){let Ve=Kt(e.$.type,we,n);return n.emitter.emitLine(`${t}${Ve} = ${Se};`),we}else return Se}else{let Q=((B=e.$)==null?void 0:B.variableName)||"async_result",Y=`${u}()`;if(Q&&((G=e.$)!=null&&G.type)){let J=Kt(e.$.type,Q,n);return n.emitter.emitLine(`${t}${J} = ${Y};`),Q}else return Y}}function uf(e,t){var y;let n=t.emitter,{asyncBlockId:r,structName:i,resultType:o,resultTypeCName:a,captureType:s,analysis:l,crossBoundaryIds:u,awaitFutureTempVarAliases:_,overlappingSlotAliases:c,overlappingSlots:f}=e;if(n.emitDeclarationLine(`// State machine for async block ${r} - implements Future(${M(o)})`),n.emitDeclarationLine(`struct ${i}_struct {`),n.emitDeclarationLine(" __yo_ref_header_t header; // Reference counting header (must be first)"),n.emitDeclarationLine(" int state; // Current state (0 = cold, 1..N = intermediate, -1 = completed, -2 = aborted)"),De(o)?n.emitDeclarationLine(" uint8_t result; // Dummy result for unit type"):n.emitDeclarationLine(` ${a} result; // The result value of type ${M(o)}`),n.emitDeclarationLine(" void (*continuation_fn)(void*); // Resume function of awaiting task"),n.emitDeclarationLine(" void* continuation_sm; // State machine of awaiting task"),n.emitDeclarationLine(""),n.emitDeclarationLine(" void (*__yo_resume_fn)(void*); // Resume function pointer (for lazy start at await/spawn)"),n.emitDeclarationLine(""),s){let g=Object.values(t.types).find(T=>T.type===s),v=g?g.cName:`async_capture_${s.id}`;n.emitDeclarationLine(" // Captured variables from outer scope"),n.emitDeclarationLine(` ${v} __capture;`),n.emitDeclarationLine("")}let p=l.capturedVariables.filter(g=>g.kind!=="outer");if(u&&(p=p.filter(g=>u.has(g.id)&&!(_!=null&&_.has(g.id))&&!(c!=null&&c.has(g.id)))),p.length>0){n.emitDeclarationLine(" // Local variables");for(let g of p){let v=j(g.type,t),T=Xn(g.id,"local");n.emitDeclarationLine(` ${v} ${T}; // ${g.name}`)}n.emitDeclarationLine("")}if(f&&f.length>0){n.emitDeclarationLine(" // Overlapping storage slots (Phase 2)");for(let g of f)n.emitDeclarationLine(` ${g.cType} ${g.fieldName}; // shared: ${g.variableNames.join(", ")}`);n.emitDeclarationLine("")}if(l.awaitPoints.length>0){let g=[];for(let v of l.awaitPoints)if(!(De(v.resultType)||z(v.resultType)&&!v.resultType.resolvedConcreteType)&&v.isInsideCond){let C=v.resultType;if(v.futureType){let b=Ln(v.futureType);b&&(C=b.isFuture.outputType)}let k=j(C,t);g.push(` ${k} await_result_${v.index};`)}if(g.length>0){n.emitDeclarationLine(" // Await result temporaries");for(let v of g)n.emitDeclarationLine(v);n.emitDeclarationLine("")}}if(l.awaitPoints.length>0){let g=l.awaitPoints.filter(v=>v.futureVariableId===void 0);if(g.length>0){n.emitDeclarationLine(" // Future references for awaits");for(let v of g){let T=v.expr;if(T.tag!=="FnCall")continue;let $=T.args[0],C=(y=$==null?void 0:$.$)==null?void 0:y.type;if(!C)throw new Error(`Internal error: await expression missing type info for future argument in async block ${r}`);let k=j(C,t);n.emitDeclarationLine(` ${k} await_future_${v.index};`)}n.emitDeclarationLine("")}}let m=l.awaitPoints.filter(g=>g.needsOwnCondBranchField);if(m.length>0){n.emitDeclarationLine(" // Branch tracking for cond expressions with await");for(let g of m)n.emitDeclarationLine(` int cond_branch_${g.index}; // Which branch was taken in cond with await ${g.index}`);n.emitDeclarationLine("")}let h=l.awaitPoints.filter(g=>g.isInsideWhile);if(h.length>0){n.emitDeclarationLine(" // Loop state tracking for while loops with await");let g=l.awaitPoints.length;for(let v of h){n.emitDeclarationLine(` _Bool while_loop_${v.index}_active; // Whether while loop ${v.index} should continue`);let T=(v.whileNestingDepth??1)-1;for(let $=0;$<T;$++)n.emitDeclarationLine(` _Bool while_loop_${g}_active; // Whether outer while loop ${g} should continue`),g++}n.emitDeclarationLine("")}n.emitDeclarationLine("};"),n.emitDeclarationLine("")}function Qh(e){var l;if(!e.deferredAsyncBlocks||e.deferredAsyncBlocks.length===0)return;let t=e.deferredAsyncBlocks,n=new Map;for(let u of t)n.set(u.structName,u);let r=new Map,i=new Map;for(let u of t)r.set(u.structName,new Set),i.set(u.structName,0);for(let u of t){let _=c=>{let f=r.get(c);f.has(u.structName)||(f.add(u.structName),i.set(u.structName,(i.get(u.structName)??0)+1))};for(let c of u.analysis.capturedVariables){let f;try{f=j(c.type,e)}catch{continue}let p=n.get(f);p&&p.structName!==u.structName&&_(p.structName)}for(let c of u.analysis.awaitPoints){if(c.futureVariableId!==void 0)continue;let f=c.expr;if(f.tag!=="FnCall")continue;let p=f.args[0],m=(l=p==null?void 0:p.$)==null?void 0:l.type;if(!m)continue;let h;try{h=j(m,e)}catch{continue}let y=n.get(h);y&&y.structName!==u.structName&&_(y.structName)}}let o=[];for(let[u,_]of i.entries())_===0&&o.push(u);let a=[];for(;o.length>0;){let u=o.shift();a.push(u);let _=r.get(u);if(_)for(let c of _){let f=(i.get(c)??0)-1;i.set(c,f),f===0&&o.push(c)}}let s=a.length===t.length?a.map(u=>n.get(u)).filter(Boolean):t;for(let u of s){let{crossBoundaryIds:_,awaitFutureTempVarAliases:c,variableSegments:f}=Il(u.bodyExpr,u.analysis),{slotAliases:p,slots:m}=Al(_,f,u.analysis.capturedVariables,c,e);uf({asyncBlockId:u.asyncBlockId,structName:u.structName,resultType:u.resultType,resultTypeCName:u.resultTypeCName,captureType:u.captureType,analysis:u.analysis,crossBoundaryIds:_,awaitFutureTempVarAliases:c,overlappingSlotAliases:p,overlappingSlots:m},e)}}function Zh(e,t,n,r,i,o,a,s,l,u){var c;let _=u.emitter;if(_.emitLine(`// Dispose function for async block ${e} state machine`),_.emitLine("// Called by __yo_decr_rc when refcount hits 0 - do NOT call __yo_free here"),_.emitLine(`void ${n}(void* sm_ptr) {`),_.emitLine(` ${t}* sm = (${t}*)sm_ptr;`),_.emitLine(` ASYNC_DEBUG("${n}: Disposing state machine\\n");`),_.emitLine(""),i&&it(i)){let f=Object.values(u.types).find(p=>p.type===i);if(!f)_.emitLine(" /* Error: capture struct type not found in context */");else{let p=f.cName,m=i.trait.fields.find(h=>h.label===F.___drop[0]);if(m&&m.assignedValue&&he(m.assignedValue)){let h=(c=u.functions[m.assignedValue.funcId])==null?void 0:c.cName;h&&(_.emitLine(' ASYNC_DEBUG(" Dropping capture struct\\n");'),_.emitLine(` ${h}(sm->__capture);`))}else _.emitLine(` /* Warning: ___drop function not found for capture struct ${p} */`)}}if(_.emitLine(""),!De(r)&&it(r)){let f=j(r,u);_.emitLine(" // Drop result field if it was set (state == -1 means completed)"),_.emitLine(" int final_state = sm->state;"),_.emitLine(" if (final_state == -1) {"),_.emitLine(' ASYNC_DEBUG(" Dropping result field\\n");');let p=Wr(r,u);p?_.emitLine(` ${p}(sm->result);`):_.emitLine(` /* Warning: No ___drop function found for result type ${f} */`),_.emitLine(" }")}_.emitLine("");{let f=[];for(let p of o.capturedVariables){if(p.kind!=="local"||!s.has(p.id)||l.has(p.id)||p.isOwningTheSameRcValueAs!==void 0)continue;let h=`sm->${Xn(p.id,"local")}`;if(st(p.type))f.push(` if ((${h}).data != NULL) { __yo_decr_rc((void*)(${h}).data); }`);else if(hn(p.type)||oi(p.type))f.push(` if (${h} != NULL) { __yo_decr_rc_atomic((void*)${h}); }`);else if(en(p.type)||z(p.type)&&rr(p.type)){let y=Wr(p.type,u);y?f.push(` if (${h} != NULL) { ${y}(${h}); }`):f.push(` if (${h} != NULL) { __yo_decr_rc((void*)${h}); }`)}else if(it(p.type)){let y=Wr(p.type,u);y&&f.push(` ${y}(${h});`)}}if(f.length>0){_.emitLine(" // Drop local variables on escape (state == -2)"),_.emitLine(" if (sm->state == -2) {");for(let p of f)_.emitLine(p);_.emitLine(" }")}}_.emitLine(" // Memory freed by __yo_decr_rc after this function returns"),_.emitLine("}")}function Jh(e,t,n,r,i,o,a,s,l,u){let _=u.emitter;if(l){let c=Object.values(u.types).find(p=>p.type===l),f=c?c.cName:`async_capture_${l.id}`;_.emitLine(`${t}* ${r}(${f} __capture) {`)}else _.emitLine(`${t}* ${r}() {`);if(_.emitLine(" // Allocate async block state machine (heap-backed, ref-counted)"),_.emitLine(` ${t}* sm = (${t}*)__yo_malloc(sizeof(${t}));`),_.emitLine(` memset(sm, 0, sizeof(${t}));`),_.emitLine(""),_.emitLine(" // Initialize reference counting header"),_.emitLine(" sm->header.ref_count = 1; // Caller owns initial reference"),_.emitLine(` GC_DEBUG("AsyncBlock ${t}: Created ptr=%p RC=1\\n", (void*)sm);`),u.needsCycleGC&&(_.emitLine(" sm->header.gc_flags = 0;"),_.emitLine(" sm->header.gc_mark = __YO_GC_UNMARKED;"),_.emitLine(" sm->header.gc_next = NULL;"),_.emitLine(" sm->header.gc_prev = NULL;")),u.needsCycleGC)_.emitLine(` sm->header.dispose_fn = (void(*)(void*))${i};`);else{u.disposeTypeIds||(u.disposeTypeIds=new Map,u.nextDisposeTypeId=1);let c=u.disposeTypeIds.get(i);c===void 0&&(c=u.nextDisposeTypeId,u.nextDisposeTypeId=c+1,u.disposeTypeIds.set(i,c)),_.emitLine(` sm->header.type_id = ${c};`)}u.needsCycleGC&&_.emitLine(" sm->header.traverse_fn = NULL; // TODO: Add traverse for cycle detection if needed"),_.emitLine(""),_.emitLine(" sm->state = 0;"),_.emitLine(" sm->continuation_fn = NULL;"),_.emitLine(" sm->continuation_sm = NULL;"),_.emitLine(""),l&&(_.emitLine(" // Initialize captured variables"),_.emitLine(" sm->__capture = __capture;"),_.emitLine("")),_.emitLine(" // Initialize result (will be set when async block completes)"),De(a)?_.emitLine(" // Result is unit type, no initialization needed"):_.emitLine(` memset(&sm->result, 0, sizeof(${s}));`),_.emitLine(""),_.emitLine(` sm->__yo_resume_fn = (void(*)(void*))${n};`),_.emitLine(""),_.emitLine(" return sm;"),_.emitLine("}"),_.emitLine("")}function _f(e){if(!e.deferredAsyncBlocks||e.deferredAsyncBlocks.length===0)return;let t=e.emitter;Qh(e),t.emitLine("// Deferred async block implementations");let n=0;for(;n<e.deferredAsyncBlocks.length;){let r=e.deferredAsyncBlocks[n],i=e.deferredAsyncBlocks.length,{bodyExpr:o,asyncBlockId:a,structName:s,resumeFunctionName:l,constructorName:u,disposeFunctionName:_,futureType:c,resultType:f,resultTypeCName:p,captureType:m,analysis:h}=r,y=e.stateMachineVariables,g=e.currentEvidenceParams,v=new Map,{crossBoundaryIds:T,awaitFutureTempVarAliases:$,variableSegments:C}=Il(o,h),{slotAliases:k}=Al(T,C,h.capturedVariables,$,e),b=h.capturedVariables.filter(x=>x.kind==="outer"||T.has(x.id)||$.has(x.id)||k.has(x.id)),w={...h,capturedVariables:b};for(let x of b)v.set(x.id,x);if(m)for(let x of m.fields)v.set(x.label,{id:x.label,name:x.label,type:x.type,kind:"outer",isOwningTheSameRcValueAs:void 0});e.stateMachineVariables=v;let A=e.stateMachineFieldAliases,L=new Map($);for(let[x,V]of k)L.set(x,V);e.stateMachineFieldAliases=L;let N=ef(o,a,s,l,w,c,m,e);if(e.stateMachineVariables=y,e.currentEvidenceParams=g,e.stateMachineFieldAliases=A,t.emitLine(""),Zh(a,s,_,f,m,w,N,T,$,e),t.emitLine(""),Jh(a,s,l,u,_,c,f,p,m,e),t.emitLine(""),e.deferredAsyncBlocks.length>i){let x=e.deferredAsyncBlocks.slice(i);for(let V of x){let{crossBoundaryIds:U,awaitFutureTempVarAliases:R,variableSegments:D}=Il(V.bodyExpr,V.analysis),{slotAliases:H,slots:B}=Al(U,D,V.analysis.capturedVariables,R,e);uf({asyncBlockId:V.asyncBlockId,structName:V.structName,resultType:V.resultType,resultTypeCName:V.resultTypeCName,captureType:V.captureType,analysis:V.analysis,crossBoundaryIds:U,awaitFutureTempVarAliases:R,overlappingSlotAliases:H,overlappingSlots:B},e)}}n++}}function cf(e){for(let t in e.functions){let{value:n}=e.functions[t];n.body&&ff(n.body,e)}}var ev=["__yo_poll_","__yo_fs_event_","__yo_async_"];function tv(e){return ev.some(t=>e.startsWith(t))}function ff(e,t){var n,r,i,o,a,s,l;if(e&&S(e)){let u=e;if(An(e)){t.usesAsync=!0;let _=(n=e.$)==null?void 0:n.type;if(_&&at(_)&&Ln(_)){let p=`${((r=e.$)==null?void 0:r.variableName)||`async_block_${Date.now()}`}_state_t`;e.$&&(e.$.asyncStateMachineStructName=p),t.types[_.id]={type:_,cName:p},t.emitter.emitDeclarationLine(`typedef struct ${p}_struct ${p}; // Forward declaration for async state machine`)}}if(An(e)){let _=(i=e.$)==null?void 0:i.type;if(_&&at(_)&&Ln(_)){let f=((o=e.$)==null?void 0:o.variableName)||`io_async_block_${Date.now()}`,p=!!((a=e.$)!=null&&a.awaitAnalysis),m=p?`${f}_state_t`:`${f}_sync_fut_t`;e.$&&(e.$.asyncStateMachineStructName=m),t.types[_.id]={type:_,cName:m},t.emitter.emitDeclarationLine(`typedef struct ${m}_struct ${m}; // Forward declaration for io.async ${p?"state machine":"sync future"}`)}}(_r(e)||dl(e))&&(t.usesAsync=!0);{let _=(s=u.func.$)==null?void 0:s.type;_&&"isExtern"in _&&_.isExtern==="yo"&&"externName"in _&&typeof _.externName=="string"&&tv(_.externName)&&(t.usesAsync=!0)}{let _=(l=u.func.$)==null?void 0:l.type;_&&"isExtern"in _&&_.isExtern==="yo"&&"externName"in _&&typeof _.externName=="string"&&(_.externName==="__yo_thread_spawn"||_.externName==="__yo_worker_spawn")&&(t.usesParallelism=!0)}for(let _ of u.args)ff(_,t)}}function pf(e,t,n){var b,w,A,L,N,x,V,U,R,D,H,B;let r=(b=e.$)==null?void 0:b.type;if(!r||!at(r))return"/* Error: io.async must return a Future type */";let i=Ln(r);if(!i)return"/* Error: Could not extract Future module type */";let o=i.isFuture.outputType;if(z(o))if(o.resolvedConcreteType)o=o.resolvedConcreteType;else{let G=(A=(w=e.$)==null?void 0:w.runtimeArgExprsInOrder)==null?void 0:A[0],Q=(L=G==null?void 0:G.$)==null?void 0:L.closureFunctionValue;if(Q&&he(Q)){let Y=(x=(N=Q.type)==null?void 0:N.return)==null?void 0:x.type;if(Y&&z(Y)&&Y.resolvedConcreteType)o=Y.resolvedConcreteType;else if((U=(V=Q.body)==null?void 0:V.$)!=null&&U.type){let J=Q.body.$.type;z(J)&&J.resolvedConcreteType?o=J.resolvedConcreteType:z(J)||(o=J)}}}let a=j(o,n),s=(R=e.$)==null?void 0:R.asyncStateMachineStructName;if(!s)return"/* Error: Missing sync future struct name */";let l=`${s}_dispose`,u=`${s}_resume`,_=n.emitter,c=(H=(D=e.$)==null?void 0:D.runtimeArgExprsInOrder)==null?void 0:H[0];if(!(c!=null&&c.$))return"/* Error: Missing closure argument for io.async */";let f=q(c,t,n),p=c.$.type,m,h;if(z(p)&&p.resolvedConcreteType){let G=p.resolvedConcreteType,Q=n.implClosureCallMap.get(G.id);Q&&(m=Q.functionCName);let Y=n.types[G.id];Y&&(h=Y.cName)}if(!m||!h)return"/* Error: no closure function or capture type for io.async sync path */";_.emitDeclarationLine(`struct ${s}_struct {`),_.emitDeclarationLine(" __yo_ref_header_t header;"),_.emitDeclarationLine(" int state;"),De(o)?_.emitDeclarationLine(" uint8_t result;"):_.emitDeclarationLine(` ${a} result;`),_.emitDeclarationLine(" void (*continuation_fn)(void*);"),_.emitDeclarationLine(" void* continuation_sm;"),_.emitDeclarationLine(" void (*__yo_resume_fn)(void*);"),_.emitDeclarationLine(` ${h} __capture;`),_.emitDeclarationLine("};"),_.emitDeclarationLine("");let y="";for(let G in n.functions){let Q=n.functions[G];if(Q.cName===m){let Y=pn(Q.value.type);Y.length>0&&(y=", "+Y.map(J=>`(void*)sm->__capture.${J.fieldPath.join(".")}`).join(", "));break}}_.emitDeclarationLine(`void ${u}(void* ptr) {`),_.emitDeclarationLine(` ${s}* sm = (${s}*)ptr;`),De(o)?_.emitDeclarationLine(` ${m}(&sm->__capture${y});`):_.emitDeclarationLine(` sm->result = ${m}(&sm->__capture${y});`),y&&(_.emitDeclarationLine(" if (__yo_effect_escaped) {"),_.emitDeclarationLine(" __yo_effect_escaped = 0;"),_.emitDeclarationLine(" sm->state = -2;"),_.emitDeclarationLine(" __yo_decr_rc(ptr);"),_.emitDeclarationLine(" return;"),_.emitDeclarationLine(" }")),_.emitDeclarationLine(" sm->state = -1;"),_.emitDeclarationLine(" void (*continuation)(void*) = sm->continuation_fn;"),_.emitDeclarationLine(" if (continuation) {"),_.emitDeclarationLine(" void* cont_sm = sm->continuation_sm;"),_.emitDeclarationLine(" continuation(cont_sm);"),_.emitDeclarationLine(" }"),_.emitDeclarationLine(" __yo_decr_rc(ptr);"),_.emitDeclarationLine("}"),_.emitDeclarationLine("");let g=c.$.captureType,v=g&&it(g)?Wr(g,n):void 0,T=g&&it(g)?fr(g,n):void 0,$=Wr(o,n);_.emitDeclarationLine(`void ${l}(void* ptr) {`),(v||$)&&(_.emitDeclarationLine(` ${s}* sm = (${s}*)ptr;`),v&&(_.emitDeclarationLine(" // Drop captured variables (future owns its references)"),_.emitDeclarationLine(` ${v}(sm->__capture);`)),$&&(_.emitDeclarationLine(" if (sm->state == -1) {"),_.emitDeclarationLine(` ${$}(sm->result);`),_.emitDeclarationLine(" }"))),_.emitDeclarationLine("}"),_.emitDeclarationLine("");let C=((B=e.$)==null?void 0:B.variableName)||"__io_async_result",k=Kt(r,C,n);if(_.emitLine(`${t}${k} = (${s}*)__yo_malloc(sizeof(${s}));`),_.emitLine(`${t}memset(${C}, 0, sizeof(${s}));`),_.emitLine(`${t}${C}->header.ref_count = 1;`),n.needsCycleGC&&(_.emitLine(`${t}${C}->header.gc_flags = 0;`),_.emitLine(`${t}${C}->header.gc_mark = __YO_GC_UNMARKED;`),_.emitLine(`${t}${C}->header.gc_next = NULL;`),_.emitLine(`${t}${C}->header.gc_prev = NULL;`)),n.needsCycleGC)_.emitLine(`${t}${C}->header.dispose_fn = (void(*)(void*))${l};`);else{n.disposeTypeIds||(n.disposeTypeIds=new Map,n.nextDisposeTypeId=1);let G=n.disposeTypeIds.get(l);G===void 0&&(G=n.nextDisposeTypeId,n.nextDisposeTypeId=G+1,n.disposeTypeIds.set(l,G)),_.emitLine(`${t}${C}->header.type_id = ${G};`)}return n.needsCycleGC&&_.emitLine(`${t}${C}->header.traverse_fn = NULL;`),_.emitLine(`${t}${C}->__capture = ${f};`),T&&_.emitLine(`${t}${C}->__capture = ${T}(${C}->__capture);`),_.emitLine(`${t}${C}->state = 0;`),_.emitLine(`${t}${C}->__yo_resume_fn = ${u};`),_.emitLine(`${t}${C}->continuation_fn = NULL;`),_.emitLine(`${t}${C}->continuation_sm = NULL;`),C}function df(e,t){for(let i=0;i<e.fields.length;i++){let o=e.fields[i];he(o)&&(xi(o.type,t),Ji(o.body,t))}if(t.moduleLevelInitExprs)for(let i of t.moduleLevelInitExprs)Ji(i,t);let n=new Set,r=!0;for(;r;){r=!1;for(let i in t.functions){if(n.has(i))continue;n.add(i),r=!0;let o=t.functions[i];if(xi(o.value.type,t),o.value.specializedType&&xi(o.value.specializedType,t),Ji(o.value.body,t),o.value.calledComptimeFunctionCaches)for(let a of o.value.calledComptimeFunctionCaches)a.value&&a.value.type&&Nn(a.value.type,t),Ji(a.body,t)}}}function xi(e,t){for(let n of e.parameters)Nn(n.type,t);for(let n of e.forallParameters)Nn(n.type,t);Nn(e.return.type,t)}function Ji(e,t){var n;if(e.$&&e.$.type&&Nn(e.$.type,t),e.$&&e.$.value&&he(e.$.value)){let r=e.$.value;r.isControlFunction?(xi(r.type,t),In(r.body,t)):t.functions[r.funcId]||r.type.parameters.map(a=>a.type).some(a=>z(a)&&at(a)&&!a.resolvedConcreteType)||(t.functions[r.funcId]={value:r,cName:be(r.funcId)},xi(r.type,t),In(r.body,t))}if(e.$&&e.$.deferredDropExpressions&&e.$.deferredDropExpressions.length>0)for(let r of e.$.deferredDropExpressions)Ji(r,t);if(e.$&&e.$.macroExpansion&&Ji(e.$.macroExpansion,t),e.$&&e.$.runtimeDestructurings)for(let{type:r}of e.$.runtimeDestructurings)Nn(r,t);if(e.$&&e.$.captureType&&Ae(e.$.captureType)){let r=e.$.captureType;if(!t.types[r.id]){t.types[r.id]={type:r,cName:`__yo_${r.id}`};for(let i of r.fields)Nn(i.type,t);for(let i of r.trait.fields)if(i.assignedValue&&he(i.assignedValue)){let o=i.assignedValue;t.functions[o.funcId]||(t.functions[o.funcId]={value:o,cName:o.funcId},xi(o.type,t),In(o.body,t))}}}switch(e.tag){case"FnCall":if(E(e,P.test))break;Ji(e.func,t);for(let r of e.args)Ji(r,t);break;case"Atom":(n=e.$)!=null&&n.value&&W(e.$.value)&&Nn(e.$.value.value,t);break}}function Nn(e,t){if(!t.types[e.id]){if(z(e)&&zn(e)){if(e.resolvedConcreteType){Nn(e.resolvedConcreteType,t);return}let n=Kn(e);n&&Nn(n,t);return}if(z(e)&&at(e)){let n=Ln(e);n&&Nn(n.isFuture.outputType,t);return}if(z(e)&&e.resolvedConcreteType){Nn(e.resolvedConcreteType,t);return}if(!Me(e)){if(Ae(e)||Bt(e)||Be(e)||ut(e)||st(e)||Xe(e)||ot(e)||$t(e)||hn(e)){let n=$t(e)?j(e,t):e.isExtern==="c"&&e.externName?e.externName:`__yo_${e.id}`;if(t.types[e.id]={type:e,cName:n},Ae(e))for(let r of e.fields)Nn(r.type,t);if(Be(e)){for(let r of e.variants)if(r.fields)for(let i of r.fields)Nn(i.type,t)}if(Bt(e))for(let r of e.fields)Nn(r.type,t);if(st(e)){let r=e;for(let i of r.requiredTraits)Nn(i.traitType,t)}if(hn(e)){let r=e;Nn(r.childType,t),j(r,t)}if($t(e)&&Nn(e.childType,t),Xe(e)||ot(e)){for(let r of e.fields)Nn(r.type,t);for(let r of e.fields)if(r.assignedValue&&he(r.assignedValue)){let i=r.assignedValue,o=i.type;if(o.parameters.every(s=>s.isCompileTimeOnly)&&o.return.isCompileTimeOnly)continue;t.functions[i.funcId]||(t.functions[i.funcId]={value:i,cName:be(i.funcId)},xi(i.type,t),In(i.body,t))}else if(r.assignedValue&&(wt(r.assignedValue)||tn(r.assignedValue))){let i=r.assignedValue;ts(i,t,!1)}}}else if(Je(e)){let n=e,r=n.childType,i=n.length;if(ht(i)){Nn(r,t);let o=j(r,t),a=`Array_${be(o)}_${i.value}`;t.arrayStructTypes.has(a)||t.arrayStructTypes.set(a,{childType:o,length:typeof i.value=="bigint"?Number(i.value):i.value}),t.types[e.id]={type:e,cName:a}}}else if(je(e)){if(Nn(e.childType,t),$t(e.childType)){let r=e.childType.childType;Nn(r,t);let i=j(r,t),o=`Slice_${be(i)}`;t.sliceStructTypes.has(o)||t.sliceStructTypes.set(o,{childType:i})}t.types[e.id]={type:e,cName:j(e,t)}}else jc.has(e.tag)&&(t.types[e.id]={type:e,cName:j(e,t)});e.trait&&Nn(e.trait,t)}}}function Fo(e){var t,n,r;if(e.$&&e.$.value&&Ie(e.$.value)&&!(ne(e.$.type)&&e.$.type.isExtern)){if(!De(e.$.type))return!0}if(S(e)){if(Fo(e.func))return!0;for(let i of e.args)if(!((t=i.$)!=null&&t.type&&De(i.$.type))&&Fo(i))return!0}if(e.$&&e.$.macroExpansion){if(e.$.type&&De(e.$.type))return!1;if(Fo(e.$.macroExpansion))return!0}if((n=e.$)!=null&&n.deferredDupExpressions){for(let i of e.$.deferredDupExpressions)if(Fo(i))return!0}if((r=e.$)!=null&&r.deferredDropExpressions){for(let i of e.$.deferredDropExpressions)if(Fo(i))return!0}return!1}function ts(e,t,n=!0){for(let r=0;r<e.fields.length;r++){let i=e.fields[r],o=e.type.fields[r];if(he(i)){let a=o.label;if(a==="main")t.functions[i.funcId]={value:i,cName:"__yo_user_main"};else if(t.isLibrary)if(n&&t.currentModuleId&&i.funcId.startsWith(`fn_${t.currentModuleId}_`)){let l=be(a);Object.values(t.functions).some(_=>_.cName===l)?t.functions[i.funcId]={value:i,cName:be(i.funcId)}:(t.functions[i.funcId]={value:i,cName:l},t.exportedFunctionLabels||(t.exportedFunctionLabels=new Map),t.exportedFunctionLabels.set(i.funcId,a))}else t.functions[i.funcId]={value:i,cName:be(i.funcId)};else if(n&&t.currentModuleId&&i.funcId.startsWith(`fn_${t.currentModuleId}_`)){let l=be(a);Object.values(t.functions).some(_=>_.cName===l)?t.functions[i.funcId]={value:i,cName:be(i.funcId)}:(t.functions[i.funcId]={value:i,cName:l},t.exportedFunctionLabels||(t.exportedFunctionLabels=new Map),t.exportedFunctionLabels.set(i.funcId,a))}else t.functions[i.funcId]={value:i,cName:be(i.funcId)};In(i.body,t)}}}function mf(e,t){for(let n=0;n<e.fields.length;n++){let r=e.fields[n];r&&he(r)?t.functions[r.funcId]||(r.isModuleEffectMember=!0,t.functions[r.funcId]={value:r,cName:be(r.funcId)},In(r.body,t)):r&&wt(r)&&mf(r,t)}}function In(e,t){var i,o,a,s,l,u,_,c,f,p,m,h;if((i=e.$)!=null&&i.value&&wt(e.$.value)){let y=e.$.value;mf(y,t)}if(S(e)&&E(e,P.test)||S(e)&&E(e,F.comptime_expect_error))return;if(e.$&&e.$.macroExpansion&&In(e.$.macroExpansion,t),(o=e.$)!=null&&o.effectAnalysis){let y=e.$.effectAnalysis.handlerValue;y&&he(y)&&In(y.body,t)}if(e.$&&e.$.closureFunctionValue){let y=e.$.closureFunctionValue;t.functions[y.funcId]||(t.functions[y.funcId]={value:y,cName:be(y.funcId)},In(y.body,t))}if((a=e.$)!=null&&a.indexMethodValue&&he(e.$.indexMethodValue)){let y=e.$.indexMethodValue;t.functions[y.funcId]||(t.functions[y.funcId]={value:y,cName:be(y.funcId)},In(y.body,t))}if(S(e)&&e.$&&e.$.dynCallTraitValues&&e.$.dynCallTraitValues.length>0){let y=e.$.type,g=e.args[0];if(st(y)&&g&&((s=g.$)!=null&&s.type)){let v=g.$.type,T=e.$.dynCallTraitValues;if(T.length>0&&(en(v)||vr(v))){let $=vr(v)?v.fields[0].type:v,C=`${$.id}_${y.id}`;t.dynImpls.set(C,{dynType:y,concreteType:$,dataType:v,traitValues:T})}}}if(S(e)){let y=(l=e.func.$)==null?void 0:l.type,g=(u=e.func.$)==null?void 0:u.value;if(e.func.token.value==="?=")return;if(ne(y)){if(he(g)&&g.isControlFunction){In(g.body,t);for(let v of e.args)In(v,t);return}if(he(g)){if(g.type.return.isCompileTimeOnly||ru(g)&&!g.specializedType)return;if(g.specializedType&&li(g.specializedType)&&pn(g.specializedType).length===0){In(e.func,t);for(let T of e.args)In(T,t);return}if(!t.functions[g.funcId]){let v=!1;if(Fo(g.body)){let T=g.specializedType??g.type;if(v=T.implicitParameters.length>0&&(pn(T).length>0||!li(g.type)&&g.type.implicitParameters.length>0),!v)return}if(!v&&!(pn(g.specializedType??g.type).length>0)&&(g.specializedType??g.type).parameters.map(k=>k.type).some(k=>z(k)&&at(k)&&!k.resolvedConcreteType))return;t.functions[g.funcId]={value:g,cName:be(g.funcId)},In(g.body,t)}}else if(y.isExtern==="c"){let v=y.externName?y.externName:K(e.func)?e.func.token.value:y.id;t.externFunctions[y.id]={type:y,cName:v}}else if(y.isExtern==="yo"){let v=y.externName;if(!(v&&v.startsWith("__yo_"))){let T=v?be(v):K(e.func)?be(e.func.token.value):be(y.id);t.externFunctions[y.id]={type:y,cName:T}}}}In(e.func,t);for(let v of e.args)In(v,t)}let n=(_=e.$)==null?void 0:_.type,r=(c=e.$)==null?void 0:c.value;if(ne(n)){if(he(r)&&r.isControlFunction){if(r.isModuleEffectMember=!0,t.functions[r.funcId]||(t.functions[r.funcId]={value:r,cName:be(r.funcId)}),r.specializedFunctionCaches)for(let y of r.specializedFunctionCaches){let g=y.specializedFunction;g&&!t.functions[g.funcId]&&(g.isModuleEffectMember=!0,t.functions[g.funcId]={value:g,cName:be(g.funcId)},In(g.body,t))}In(r.body,t);return}if(he(r)){if(ru(r)&&!r.specializedFunctionCaches||t.functions[r.funcId])return;if(Fo(r.body))return;t.functions[r.funcId]={value:r,cName:be(r.funcId)},In(r.body,t)}}if(W((f=e.$)==null?void 0:f.value)&&Nn(e.$.value.value,t),(p=e.$)!=null&&p.deferredDupExpressions)for(let y of e.$.deferredDupExpressions)In(y,t);if((m=e.$)!=null&&m.deferredDropExpressions)for(let y of e.$.deferredDropExpressions)In(y,t);if((h=e.$)!=null&&h.dynCallTraitValues)for(let y of e.$.dynCallTraitValues)ts(y,t,!1)}function yf(e){let t=F.dispose[0];for(let n in e.types){let{type:r}=e.types[n];if(!Ae(r)||!r.isReferenceSemantics)continue;let i=Dr({concreteType:r,methodName:t,env:r.env});for(let o of i)if(o.value&&he(o.value)){let a=o.value;if(e.functions[a.funcId])continue;a.funcName||(a.funcName=t),e.functions[a.funcId]={value:a,cName:be(a.funcId)},xi(a.type,e),In(a.body,e)}}}function gf(e){var r;let t=e.emitter,n=new Set;for(let[,i]of e.dynImpls){let o=((r=e.types[i.dynType.id])==null?void 0:r.cName)||`__yo_dyn_${i.dynType.id}`;n.has(o)||(n.add(o),t.emitLine(`${o} __yo_dup_${o}(${o} dyn) {`),t.emitLine(" if (dyn.data) {"),t.emitLine(" __yo_incr_rc(dyn.data);"),t.emitLine(" }"),t.emitLine(" return dyn;"),t.emitLine("}"),t.emitLine(""),t.emitLine(`void __yo_drop_${o}(${o} dyn) {`),t.emitLine(" if (dyn.data) {"),t.emitLine(" __yo_decr_rc(dyn.data);"),t.emitLine(" }"),t.emitLine("}"),t.emitLine(""))}}function hf(e){var r,i,o;let t=e.emitter;if(e.dynImpls.size===0)return;t.emitLine(""),t.emitLine("// === Dyn Box Functions ==="),t.emitLine("// Constructor and dispose functions for dyn boxes"),t.emitLine("");let n=new Set;for(let[,a]of e.dynImpls){let s=z(a.concreteType)&&a.concreteType.resolvedConcreteType?a.concreteType.resolvedConcreteType:a.concreteType,u=`__yo_dyn_box_${((r=e.types[s.id])==null?void 0:r.cName)||`unknown_${s.id}`}`;if(n.has(u))continue;n.add(u);let _=j(s,e);t.emitLine(`static ${u}* __yo_new_${u}(${_} value) {`),t.emitLine(` ${u}* box = (${u}*)__yo_malloc(sizeof(${u}));`),t.emitLine(" box->header.ref_count = 1;"),e.needsCycleGC&&(t.emitLine(" box->header.gc_flags = 0;"),t.emitLine(" box->header.gc_mark = __YO_GC_UNMARKED;"),t.emitLine(" box->header.gc_next = NULL;"),t.emitLine(" box->header.gc_prev = NULL;"));let c=`__yo_dispose_${u}`;if(e.needsCycleGC)t.emitLine(` box->header.dispose_fn = ${c};`);else{e.disposeTypeIds||(e.disposeTypeIds=new Map,e.nextDisposeTypeId=1);let m=e.disposeTypeIds.get(c);m===void 0&&(m=e.nextDisposeTypeId,e.nextDisposeTypeId=m+1,e.disposeTypeIds.set(c,m)),t.emitLine(` box->header.type_id = ${m};`)}e.needsCycleGC&&t.emitLine(" box->header.traverse_fn = NULL; // TODO: Set if value contains GC types"),t.emitLine(" box->value = value;"),t.emitLine(" return box;"),t.emitLine("}"),t.emitLine(""),t.emitLine(`static void __yo_dispose_${u}(void* ptr) {`),t.emitLine(` ${u}* box = (${u}*)ptr;`);let p=(i=(z(a.concreteType)&&a.concreteType.resolvedConcreteType?a.concreteType.resolvedConcreteType:a.concreteType).trait)==null?void 0:i.fields.find(m=>m.label===F.___drop[0]);if(p&&p.assignedValue&&he(p.assignedValue)){let m=(o=e.functions[p.assignedValue.funcId])==null?void 0:o.cName;m&&t.emitLine(` ${m}(box->value);`)}t.emitLine("}"),t.emitLine("")}}function vf(e){var n,r,i,o;let t=e.emitter;if(e.dynImpls.size!==0){t.emitDeclarationLine(""),t.emitDeclarationLine("// === Dyn Wrapper Functions ==="),t.emitDeclarationLine("// Wrappers that unwrap boxed values and call impl methods"),t.emitDeclarationLine("");for(let[a,s]of e.dynImpls){let l=s.dataType,u=new Set([F.___dup[0],F.___drop[0],F.___dispose[0],F.dispose[0]]);for(let{traitType:_}of s.dynType.requiredTraits){if(!gn(_))continue;let c=_.isFn.callType,f=j(c.return.type,e),p=`__yo_wrap_${a}_call`,m=["void* self_ptr"];for(let h=0;h<c.parameters.length;h++){let y=c.parameters[h],g=j(y.type,e);m.push(`${g} arg${h+1}`)}if(t.emitDeclarationLine(`static ${f} ${p}(${m.join(", ")}) {`),vr(l)){let h=((n=e.types[l.id])==null?void 0:n.cName)||`unknown_${l.id}`,y=be(l.fields[0].label);t.emitDeclarationLine(` ${h}* box = (${h}*)self_ptr;`);let g=l.fields[0].type,v=z(g)&&g.resolvedConcreteType?g.resolvedConcreteType:g,T=e.implClosureCallMap.get(v.id),$=(()=>{var k;if(T)return T.functionCName;for(let[,b]of Object.entries(e.functions)){let A=b.value.closureInfo;if(((k=A==null?void 0:A.captureType)==null?void 0:k.id)===v.id)return b.cName}})(),C=[];if($){C.push(`(void*)&box->${y}`);for(let k=0;k<c.parameters.length;k++)C.push(`arg${k+1}`);bi(c.return.type)?t.emitDeclarationLine(` ${$}(${C.join(", ")});`):t.emitDeclarationLine(` return ${$}(${C.join(", ")});`)}else{C.push(`box->${y}.data`);for(let k=0;k<c.parameters.length;k++)C.push(`arg${k+1}`);bi(c.return.type)?t.emitDeclarationLine(` box->${y}.call(${C.join(", ")});`):t.emitDeclarationLine(` return box->${y}.call(${C.join(", ")});`)}}else{t.emitDeclarationLine(" (void)self_ptr; /* Dyn(Fn): expected Box(...) data */");for(let h=0;h<c.parameters.length;h++)t.emitDeclarationLine(` (void)arg${h+1};`);bi(c.return.type)?t.emitDeclarationLine(" return;"):(t.emitDeclarationLine(` ${f} zero = (${f})0;`),t.emitDeclarationLine(" return zero;"))}t.emitDeclarationLine("}"),t.emitDeclarationLine("")}for(let _=0;_<s.dynType.requiredTraits.length;_++){let{traitType:c}=s.dynType.requiredTraits[_];if(gn(c))continue;let f=s.traitValues[_];if(!f){t.emitDeclarationLine(`/* Warning: Module value missing for module ${_} */`);continue}let m=f.type.fields;for(let h=0;h<m.length;h++){let y=m[h];if(y.label==="Self"||u.has(y.label))continue;let g=f.fields[h];if(!g||!he(g)){t.emitDeclarationLine(`/* Warning: Module field ${y.label} is not a function value */`);continue}let v=y.type;if(!ne(v)){t.emitDeclarationLine(`/* Warning: Module field ${y.label} is not a function type */`);continue}let T=g.funcId,$=(r=e.functions[T])==null?void 0:r.cName;if(!$){t.emitDeclarationLine(`/* Warning: Impl function for ${y.label} not found */`);continue}let C=`__yo_wrap_${a}_${y.label}`,k=j(v.return.type,e),b=["void* self_ptr"];for(let N=1;N<v.parameters.length;N++){let x=v.parameters[N],V=j(x.type,e);b.push(`${V} arg${N}`)}t.emitDeclarationLine(`static ${k} ${C}(${b.join(", ")}) {`);let w=(i=v.parameters[0])==null?void 0:i.type,A;if(vr(l)){let N=((o=e.types[l.id])==null?void 0:o.cName)||`unknown_${l.id}`,x=be(l.fields[0].label);t.emitDeclarationLine(` ${N}* box = (${N}*)self_ptr;`),w&&je(w)?A=`&box->${x}`:A=`box->${x}`}else{let N=j(s.concreteType,e);t.emitDeclarationLine(` ${N} concrete_value = (${N})self_ptr;`),w&&je(w)?A="&concrete_value":A="concrete_value"}let L=[A];for(let N=1;N<v.parameters.length;N++)L.push(`arg${N}`);bi(v.return.type)?t.emitDeclarationLine(` ${$}(${L.join(", ")});`):t.emitDeclarationLine(` return ${$}(${L.join(", ")});`),t.emitDeclarationLine("}"),t.emitDeclarationLine("")}}}}}function Tf(e){var r,i,o;let t=e.emitter;if(e.dynImpls.size===0)return;t.emitDeclarationLine(""),t.emitDeclarationLine("// === Dyn TypeId Statics ==="),t.emitDeclarationLine("// Unique static per concrete type \u2014 address is the runtime TypeId"),t.emitDeclarationLine("");let n=new Set;e.typeIdStatics||(e.typeIdStatics=new Map);for(let[,a]of e.dynImpls){let s=z(a.concreteType)&&a.concreteType.resolvedConcreteType?a.concreteType.resolvedConcreteType:a.concreteType,l=((r=e.types[s.id])==null?void 0:r.cName)||`unknown_${s.id}`,u=`__yo_typeid_${l}`;!n.has(u)&&!e.typeIdStatics.has(s.id)&&(n.add(u),e.typeIdStatics.set(s.id,u),t.emitDeclarationLine(`static const char ${u} = 0; // TypeId for ${l}`))}t.emitDeclarationLine(""),t.emitDeclarationLine("// === Dyn Static Vtables ==="),t.emitDeclarationLine("// Static vtables for dynamic dispatch"),t.emitDeclarationLine("");for(let[a,s]of e.dynImpls){let l=((i=e.types[s.dynType.id])==null?void 0:i.cName)||`__yo_dyn_${s.dynType.id}`,u=z(s.concreteType)&&s.concreteType.resolvedConcreteType?s.concreteType.resolvedConcreteType:s.concreteType,_=((o=e.types[u.id])==null?void 0:o.cName)||`unknown_${u.id}`,c=`__yo_vtable_${a}`,f=`${l}_vtable`,p=`__yo_typeid_${_}`;t.emitDeclarationLine(`// Vtable for impl(${_}, ${s.dynType.requiredTraits.map(({traitType:y})=>y.typeName||"?").join(" + ")})`),t.emitDeclarationLine(`static const ${f} ${c} = {`),t.emitDeclarationLine(` .__yo_type_id = (uintptr_t)&${p},`);let m=new Set,h=new Set([F.___dup[0],F.___drop[0],F.___dispose[0],F.dispose[0]]);for(let{traitType:y}of s.dynType.requiredTraits){if(gn(y)){let g=`__yo_wrap_${a}_call`;t.emitDeclarationLine(` .call = ${g},`),m.add("call");continue}for(let g of y.fields)if(g.label!=="Self"&&!h.has(g.label)&&!m.has(g.label)&&(m.add(g.label),ne(g.type))){let v=g.type;if(v.parameters.length>0){let T=v.parameters[0];if(T&&T.label==="self"){let $=`__yo_wrap_${a}_${g.label}`;t.emitDeclarationLine(` .${be(g.label)} = ${$},`)}}}}t.emitDeclarationLine("};"),t.emitDeclarationLine("")}}function Ef(e,t){let r=Sn(t)?"__declspec(thread)":"_Thread_local";e.emitLine(`
|
|
195
|
+
state_${Ve}:`),l.emitLine(` case ${Ve}: { // State ${Ve}`),l.emitLine(` ASYNC_DEBUG("${t}: Entering state ${Ve}\\n");`),Ve>0&&i.awaitPoints[Ve-1]){let Ze=i.awaitPoints[Ve-1],Tt=xu(Ze,i);Ze.isInsideCond&&l.emitLine(` if (sm->${Tt} != NULL) {`);let Jt=De(Ze.resultType)||z(Ze.resultType)&&!Ze.resultType.resolvedConcreteType;if(l.emitLine(" // Check if the awaited Future was aborted"),l.emitLine(` if (sm->${Tt}->state == -2) {`),l.emitLine(` __yo_decr_rc((void*)sm->${Tt});`),l.emitLine(` sm->${Tt} = NULL;`),Ar({emitter:l,indent:" ",debugLabel:t}),l.emitLine(" }"),Ze&&!Jt){l.emitLine(` // Extract result from await ${Ve-1}`),l.emitLine(` int state_before_read = sm->${Tt}->state;`),l.emitLine(` ASYNC_DEBUG("${t}: Reading result from await ${Ve-1}, state=%d\\n", state_before_read);`);let gt=!!Ze.isInsideCond,nt;if(gt?nt=`sm->await_result_${Ve-1}`:Ze.targetVariableId&&(nt=`sm->${Xn(Ze.targetVariableId,"local",s.stateMachineFieldAliases)}`),nt)if(it(Ze.resultType)){let Ft=fr(Ze.resultType,s);Ft?l.emitLine(` ${nt} = ${Ft}(sm->${Tt}->result);`):(l.emitLine(" /* Warning: No ___dup function found for result type, shallow copy may cause use-after-free */"),l.emitLine(` ${nt} = sm->${Tt}->result;`))}else l.emitLine(` ${nt} = sm->${Tt}->result;`);if(gt&&Ze.targetVariableId){let Ft=Xn(Ze.targetVariableId,"local",s.stateMachineFieldAliases);l.emitLine(` sm->${Ft} = sm->await_result_${Ve-1};`)}l.emitLine("")}if(!Ze.futureVariableId){let gt=Ze.expr;if(gt.tag==="FnCall"){let nt=gt.args[0],Ft=(y=nt==null?void 0:nt.$)==null?void 0:y.type;Ft&&(z(Ft)||st(Ft))&&(l.emitLine(` if (sm->${Tt} != NULL) { __yo_decr_rc((void*)sm->${Tt}); sm->${Tt} = NULL; }`),l.emitLine(""))}}let At=s;if(Ze){let gt=(g=At.asyncCondBranchInfo)==null?void 0:g.get(Ze.index);if(gt&>.branches.some(Ft=>Ft.hasAwait)){let Ft=gt.condBranchFieldIndex??Ze.index,qt=Ft===-1;l.emitLine(" // Execute remaining code from chosen cond branch"),qt||l.emitLine(` switch (sm->cond_branch_${Ft}) {`);let Et=((v=Se.awaitPoint)==null?void 0:v.isInsideCond)??!1;for(let Lt of gt.branches)if(Lt.hasAwait){if(qt||l.emitLine(` case ${Lt.index}: {`),l.emitLine(` ASYNC_DEBUG("${t}: Executing remaining code from branch ${Lt.index}\\n");`),Lt.remainingExprs&&Lt.remainingExprs.length>0){let nn=s.inAsyncStateMachine,te=s.stateMachineVariables,pe=s.variableIdRemapping,$e=s.pendingDeferredDrops;s.inAsyncStateMachine={futureType:o},s.variableIdRemapping=i.variableIdRemapping;let ie=(T=At.asyncWhileLoopInfo)==null?void 0:T.get(Ze.index);s.pendingDeferredDrops=[...Lt.deferredDropExpressions??[],...(($=ie==null?void 0:ie.bodyExpr.$)==null?void 0:$.deferredDropExpressions)??[],...((C=e.$)==null?void 0:C.deferredDropExpressions)??[]];let _e=new Map;for(let Pe of i.capturedVariables)_e.set(Pe.id,Pe);if(a)for(let Pe of a.fields)_e.set(Pe.label,{id:Pe.label,name:Pe.label,type:Pe.type,kind:"outer",isOwningTheSameRcValueAs:void 0});s.stateMachineVariables=_e;let ye=!1,Re=[],Ke=gt.targetAssignmentCode;for(let Pe=0;Pe<Lt.remainingExprs.length;Pe++){let Z=Lt.remainingExprs[Pe],X=Pe===Lt.remainingExprs.length-1;if(ye){Re.push(Z);continue}if(Et&&er(Z)){ye=!0,Ll(Z,Se.awaitPoint,i," ",s);continue}let he=q(Z," ",s);!he||!Z.$||Ht(Z.$.env.modulePath,he)||(X&&Ke?l.emitLine(` ${Ke} = ${he};`):l.emitLine(` ${he};`))}if(Lt.remainingExprs.length===0&&Ke&&l.emitLine(` ${Ke} = sm->await_result_${Ze.index};`),ye&&Se.awaitPoint){let Pe=Se.awaitPoint.index;At.asyncCondBranchInfo||(At.asyncCondBranchInfo=new Map);let Z=At.asyncCondBranchInfo.get(Pe);if(Z)Z.chainedBranches||(Z.chainedBranches=[]),Z.chainedBranches.push({branches:[{index:Lt.index,value:Lt.value,hasAwait:Re.length>0||Re.some(X=>er(X)),remainingExprs:Re,deferredDropExpressions:Lt.deferredDropExpressions}],condBranchFieldIndex:Ft});else{let X={branches:[{index:Lt.index,value:Lt.value,hasAwait:Re.length>0||Re.some(he=>er(he)),remainingExprs:Re,deferredDropExpressions:Lt.deferredDropExpressions}],condBranchFieldIndex:Ft};At.asyncCondBranchInfo.set(Pe,X)}}else if(Lt.deferredDropExpressions)for(let Pe of Lt.deferredDropExpressions){let Z=q(Pe," ",s);Z&&Z.includes("sm->")&&l.emitLine(` ${Z};`)}s.inAsyncStateMachine=nn,s.stateMachineVariables=te,s.variableIdRemapping=pe,s.pendingDeferredDrops=$e}qt||(l.emitLine(" break;"),l.emitLine(" }"))}if(qt||l.emitLine(" }"),gt.chainedBranches){for(let Lt of gt.chainedBranches)for(let nn of Lt.branches)if(nn.hasAwait&&nn.remainingExprs&&nn.remainingExprs.length>0){let te=s.inAsyncStateMachine,pe=s.stateMachineVariables,$e=s.variableIdRemapping,ie=s.pendingDeferredDrops;s.inAsyncStateMachine={futureType:o},s.variableIdRemapping=i.variableIdRemapping;let _e=(k=At.asyncWhileLoopInfo)==null?void 0:k.get(Ze.index);s.pendingDeferredDrops=[...nn.deferredDropExpressions??[],...((b=_e==null?void 0:_e.bodyExpr.$)==null?void 0:b.deferredDropExpressions)??[],...((w=e.$)==null?void 0:w.deferredDropExpressions)??[]];let ye=new Map;for(let Z of i.capturedVariables)ye.set(Z.id,Z);if(a)for(let Z of a.fields)ye.set(Z.label,{id:Z.label,name:Z.label,type:Z.type,kind:"outer",isOwningTheSameRcValueAs:void 0});s.stateMachineVariables=ye;let Re=((A=Se.awaitPoint)==null?void 0:A.isInsideCond)??!1,Ke=!1,Pe=[];for(let Z of nn.remainingExprs){if(Ke){Pe.push(Z);continue}if(Re&&er(Z)){Ke=!0,Ll(Z,Se.awaitPoint,i," ",s);continue}let X=q(Z," ",s);!X||!Z.$||Ht(Z.$.env.modulePath,X)||l.emitLine(` ${X};`)}if(Ke&&Se.awaitPoint){let Z=Se.awaitPoint.index;At.asyncCondBranchInfo||(At.asyncCondBranchInfo=new Map);let X=At.asyncCondBranchInfo.get(Z);X?(X.chainedBranches||(X.chainedBranches=[]),X.chainedBranches.push({branches:[{index:nn.index,value:nn.value,hasAwait:Pe.length>0||Pe.some(he=>er(he)),remainingExprs:Pe,deferredDropExpressions:nn.deferredDropExpressions}],condBranchFieldIndex:Lt.condBranchFieldIndex})):At.asyncCondBranchInfo.set(Z,{branches:[{index:nn.index,value:nn.value,hasAwait:Pe.length>0||Pe.some(he=>er(he)),remainingExprs:Pe,deferredDropExpressions:nn.deferredDropExpressions}],condBranchFieldIndex:Lt.condBranchFieldIndex})}else if(nn.deferredDropExpressions)for(let Z of nn.deferredDropExpressions){let X=q(Z," ",s);X&&X.includes("sm->")&&l.emitLine(` ${X};`)}s.inAsyncStateMachine=te,s.stateMachineVariables=pe,s.variableIdRemapping=$e,s.pendingDeferredDrops=ie}}if(gt.targetVariableId){let Lt=Xn(gt.targetVariableId,"local",s.stateMachineFieldAliases);l.emitLine(" // Assign cond result to target variable"),l.emitLine(` sm->${Lt} = sm->await_result_${Ze.index};`)}l.emitLine("")}Ze.isInsideCond&&l.emitLine(" }");let nt=(L=At.asyncWhileLoopInfo)==null?void 0:L.get(Ze.index);if(nt){let Ft=nt.whileLoopOriginIndex??Ze.index;l.emitLine(" // Execute remaining code from while loop body and continue loop"),l.emitLine(` if (sm->while_loop_${Ft}_active) {`);let qt=!1;if(nt.bodyExprsAfterAwait&&nt.bodyExprsAfterAwait.length>0){let Et=s.inAsyncStateMachine,Lt=s.stateMachineVariables,nn=s.variableIdRemapping,te=s.pendingDeferredDrops;s.inAsyncStateMachine={futureType:o},s.variableIdRemapping=i.variableIdRemapping,s.pendingDeferredDrops=[...((N=nt.bodyExpr.$)==null?void 0:N.deferredDropExpressions)??[],...((x=e.$)==null?void 0:x.deferredDropExpressions)??[]];let pe=new Map;for(let ye of i.capturedVariables)pe.set(ye.id,ye);if(a)for(let ye of a.fields)pe.set(ye.label,{id:ye.label,name:ye.label,type:ye.type,kind:"outer",isOwningTheSameRcValueAs:void 0});s.stateMachineVariables=pe;let $e=s.smWhileBreakInfo,ie=s.smWhileContinueInfo,_e=s.smWhileBodyDrops;s.smWhileBreakInfo={label:`after_while_loop_${Ft}`,activeIndex:Ft},s.smWhileContinueInfo={label:`while_loop_${Ft}_continue`},s.smWhileBodyDrops=[...((V=nt.bodyExpr.$)==null?void 0:V.deferredDropExpressions)??[]];for(let ye=0;ye<nt.bodyExprsAfterAwait.length;ye++){let Re=nt.bodyExprsAfterAwait[ye];if(er(Re)&&Se.awaitPoint){Ll(Re,Se.awaitPoint,i," ",s);let Pe=nt.bodyExprsAfterAwait.slice(ye+1);At.asyncWhileLoopInfo.set(Se.awaitPoint.index,{conditionExpr:nt.conditionExpr,stepExpr:nt.stepExpr,bodyExpr:nt.bodyExpr,bodyExprsAfterAwait:Pe,whileLoopOriginIndex:Ft,isChainedAwait:!0,condBranchPostWhileExprs:nt.condBranchPostWhileExprs,outerWhileLoop:nt.outerWhileLoop}),qt=!0;break}let Ke=q(Re," ",s);!Ke||!Re.$||Ht(Re.$.env.modulePath,Ke)||l.emitLine(` ${Ke};`)}s.smWhileBreakInfo=$e,s.smWhileContinueInfo=ie,s.smWhileBodyDrops=_e,s.inAsyncStateMachine=Et,s.stateMachineVariables=Lt,s.variableIdRemapping=nn,s.pendingDeferredDrops=te}if(qt)l.emitLine(" }"),l.emitLine("");else{l.emitLine(` while_loop_${Ft}_continue:`);{let _e=((U=nt.bodyExpr.$)==null?void 0:U.deferredDropExpressions)??[];if(_e.length>0){let ye=s.inAsyncStateMachine,Re=s.stateMachineVariables,Ke=s.variableIdRemapping;s.inAsyncStateMachine={futureType:o},s.variableIdRemapping=i.variableIdRemapping;let Pe=new Map;for(let Z of i.capturedVariables)Pe.set(Z.id,Z);if(a)for(let Z of a.fields)Pe.set(Z.label,{id:Z.label,name:Z.label,type:Z.type,kind:"outer",isOwningTheSameRcValueAs:void 0});s.stateMachineVariables=Pe;for(let Z of _e){let X=q(Z," ",s);X&&X.includes("sm->")&&l.emitLine(` ${X};`)}s.inAsyncStateMachine=ye,s.stateMachineVariables=Re,s.variableIdRemapping=Ke}}l.emitLine(` ASYNC_DEBUG("${t}: Re-evaluating while loop condition\\n");`);let Et=s.declaredTempVars;if(s.declaredTempVars=void 0,nt.stepExpr){let _e=s.inAsyncStateMachine,ye=s.stateMachineVariables,Re=s.variableIdRemapping;s.inAsyncStateMachine={futureType:o},s.variableIdRemapping=i.variableIdRemapping;let Ke=new Map;for(let Z of i.capturedVariables)Ke.set(Z.id,Z);if(a)for(let Z of a.fields)Ke.set(Z.label,{id:Z.label,name:Z.label,type:Z.type,kind:"outer",isOwningTheSameRcValueAs:void 0});s.stateMachineVariables=Ke;let Pe=q(nt.stepExpr," ",s);Pe&&l.emitLine(` ${Pe};`),s.inAsyncStateMachine=_e,s.stateMachineVariables=ye,s.variableIdRemapping=Re}let Lt=s.inAsyncStateMachine,nn=s.stateMachineVariables,te=s.variableIdRemapping;s.inAsyncStateMachine={futureType:o},s.variableIdRemapping=i.variableIdRemapping;let pe=new Map;for(let _e of i.capturedVariables)pe.set(_e.id,_e);if(a)for(let _e of a.fields)pe.set(_e.label,{id:_e.label,name:_e.label,type:_e.type,kind:"outer",isOwningTheSameRcValueAs:void 0});s.stateMachineVariables=pe;let $e=q(nt.conditionExpr," ",s);s.inAsyncStateMachine=Lt,s.stateMachineVariables=nn,s.variableIdRemapping=te,s.declaredTempVars=Et,l.emitLine(` if (!(${$e})) {`),l.emitLine(` sm->while_loop_${Ft}_active = false;`),l.emitLine(` ASYNC_DEBUG("${t}: While loop condition false, exiting loop\\n");`),l.emitLine(" } else {"),l.emitLine(` ASYNC_DEBUG("${t}: While loop condition true, continuing iteration\\n");`);let ie=Ft;l.emitLine(" // Loop back by transitioning to while loop state"),l.emitLine(` sm->state = ${ie};`),l.emitLine(` goto while_loop_${ie}_start;`),l.emitLine(" }"),l.emitLine(" }"),l.emitLine(""),l.emitLine(` after_while_loop_${Ft}:`)}if(!qt&&nt.condBranchPostWhileExprs){let Et=nt.condBranchPostWhileExprs,Lt=Et.condBranchFieldIndex,nn=Et.branchIndex;Et.skipCondBranchCheck?(l.emitLine(" // Execute post-while-loop code from cond branch (unconditional)"),l.emitLine(" {")):(l.emitLine(" // Execute post-while-loop code from cond branch"),l.emitLine(` if (sm->cond_branch_${Lt} == ${nn}) {`));let te=s.inAsyncStateMachine,pe=s.stateMachineVariables,$e=s.variableIdRemapping,ie=s.pendingDeferredDrops;s.inAsyncStateMachine={futureType:o},s.variableIdRemapping=i.variableIdRemapping,s.pendingDeferredDrops=[...((R=e.$)==null?void 0:R.deferredDropExpressions)??[]];let _e=new Map;for(let Pe of i.capturedVariables)_e.set(Pe.id,Pe);if(a)for(let Pe of a.fields)_e.set(Pe.label,{id:Pe.label,name:Pe.label,type:Pe.type,kind:"outer",isOwningTheSameRcValueAs:void 0});s.stateMachineVariables=_e;let ye=Se.awaitPoint!=null,Re=!1,Ke=[];for(let Pe=0;Pe<Et.exprs.length;Pe++){let Z=Et.exprs[Pe];if(Re){Ke.push(Z);continue}if(ye&&er(Z)){Re=!0,Ll(Z,Se.awaitPoint,i," ",s);continue}let X=q(Z," ",s);!X||!Z.$||Ht(Z.$.env.modulePath,X)||l.emitLine(` ${X};`)}if(Re&&Se.awaitPoint){let Pe=Se.awaitPoint.index;At.asyncCondBranchInfo||(At.asyncCondBranchInfo=new Map);let Z=Et.skipCondBranchCheck?-1:Et.condBranchFieldIndex,X=At.asyncCondBranchInfo.get(Pe);X?(X.chainedBranches||(X.chainedBranches=[]),X.chainedBranches.push({branches:[{index:Et.branchIndex,value:Et.exprs[0],hasAwait:Ke.length>0||Ke.some(he=>er(he)),remainingExprs:Ke,deferredDropExpressions:Et.deferredDropExpressions}],condBranchFieldIndex:Z})):At.asyncCondBranchInfo.set(Pe,{branches:[{index:Et.branchIndex,value:Et.exprs[0],hasAwait:Ke.length>0||Ke.some(he=>er(he)),remainingExprs:Ke,deferredDropExpressions:Et.deferredDropExpressions}],condBranchFieldIndex:Z})}if(!Re&&Et.deferredDropExpressions)for(let Pe of Et.deferredDropExpressions){let Z=q(Pe," ",s);Z&&Z.includes("sm->")&&l.emitLine(` ${Z};`)}l.emitLine(" }"),s.inAsyncStateMachine=te,s.stateMachineVariables=pe,s.variableIdRemapping=$e,s.pendingDeferredDrops=ie}if(nt.outerWhileLoop){let Et=nt.outerWhileLoop,Lt=Et.whileLoopIndex;if(l.emitLine(" // Execute remaining code from outer while loop body"),l.emitLine(` if (sm->while_loop_${Lt}_active) {`),Et.bodyExprsAfterAwait.length>0){let te=s.inAsyncStateMachine,pe=s.stateMachineVariables,$e=s.variableIdRemapping,ie=s.pendingDeferredDrops;s.inAsyncStateMachine={futureType:o},s.variableIdRemapping=i.variableIdRemapping,s.pendingDeferredDrops=[...((D=Et.bodyExpr.$)==null?void 0:D.deferredDropExpressions)??[],...((H=e.$)==null?void 0:H.deferredDropExpressions)??[]];let _e=new Map;for(let Pe of i.capturedVariables)_e.set(Pe.id,Pe);if(a)for(let Pe of a.fields)_e.set(Pe.label,{id:Pe.label,name:Pe.label,type:Pe.type,kind:"outer",isOwningTheSameRcValueAs:void 0});s.stateMachineVariables=_e;let ye=s.smWhileBreakInfo,Re=s.smWhileContinueInfo,Ke=s.smWhileBodyDrops;s.smWhileBreakInfo={label:`after_while_loop_${Lt}`,activeIndex:Lt},s.smWhileContinueInfo={label:`while_loop_${Lt}_continue`},s.smWhileBodyDrops=[...((B=Et.bodyExpr.$)==null?void 0:B.deferredDropExpressions)??[]];for(let Pe of Et.bodyExprsAfterAwait){let Z=q(Pe," ",s);!Z||!Pe.$||Ht(Pe.$.env.modulePath,Z)||l.emitLine(` ${Z};`)}s.smWhileBreakInfo=ye,s.smWhileContinueInfo=Re,s.smWhileBodyDrops=Ke,s.inAsyncStateMachine=te,s.stateMachineVariables=pe,s.variableIdRemapping=$e,s.pendingDeferredDrops=ie}l.emitLine(` while_loop_${Lt}_continue:`);{let te=((G=Et.bodyExpr.$)==null?void 0:G.deferredDropExpressions)??[];if(te.length>0){let pe=s.inAsyncStateMachine,$e=s.stateMachineVariables,ie=s.variableIdRemapping;s.inAsyncStateMachine={futureType:o},s.variableIdRemapping=i.variableIdRemapping;let _e=new Map;for(let ye of i.capturedVariables)_e.set(ye.id,ye);if(a)for(let ye of a.fields)_e.set(ye.label,{id:ye.label,name:ye.label,type:ye.type,kind:"outer",isOwningTheSameRcValueAs:void 0});s.stateMachineVariables=_e;for(let ye of te){let Re=q(ye," ",s);Re&&Re.includes("sm->")&&l.emitLine(` ${Re};`)}s.inAsyncStateMachine=pe,s.stateMachineVariables=$e,s.variableIdRemapping=ie}}let nn=s.declaredTempVars;if(s.declaredTempVars=void 0,Et.stepExpr){let te=s.inAsyncStateMachine,pe=s.stateMachineVariables,$e=s.variableIdRemapping;s.inAsyncStateMachine={futureType:o},s.variableIdRemapping=i.variableIdRemapping;let ie=new Map;for(let ye of i.capturedVariables)ie.set(ye.id,ye);if(a)for(let ye of a.fields)ie.set(ye.label,{id:ye.label,name:ye.label,type:ye.type,kind:"outer",isOwningTheSameRcValueAs:void 0});s.stateMachineVariables=ie;let _e=q(Et.stepExpr," ",s);_e&&l.emitLine(` ${_e};`),s.inAsyncStateMachine=te,s.stateMachineVariables=pe,s.variableIdRemapping=$e}{let te=s.inAsyncStateMachine,pe=s.stateMachineVariables,$e=s.variableIdRemapping;s.inAsyncStateMachine={futureType:o},s.variableIdRemapping=i.variableIdRemapping;let ie=new Map;for(let ye of i.capturedVariables)ie.set(ye.id,ye);if(a)for(let ye of a.fields)ie.set(ye.label,{id:ye.label,name:ye.label,type:ye.type,kind:"outer",isOwningTheSameRcValueAs:void 0});s.stateMachineVariables=ie;let _e=q(Et.conditionExpr," ",s);s.inAsyncStateMachine=te,s.stateMachineVariables=pe,s.variableIdRemapping=$e,l.emitLine(` if (!(${_e})) {`),l.emitLine(` sm->while_loop_${Lt}_active = false;`),l.emitLine(" } else {"),l.emitLine(` sm->state = ${Ze.index};`),l.emitLine(` goto while_loop_${Lt}_start;`),l.emitLine(" }")}s.declaredTempVars=nn,l.emitLine(" }"),l.emitLine(""),l.emitLine(` after_while_loop_${Lt}:`)}}}}let ee=s.inAsyncStateMachine,fe=s.stateMachineVariables,me=s.variableIdRemapping;s.inAsyncStateMachine={futureType:o},s.variableIdRemapping=i.variableIdRemapping;let Le=new Map;for(let Ze of i.capturedVariables)Le.set(Ze.id,Ze);if(a)for(let Ze of a.fields)Le.set(Ze.label,{id:Ze.label,name:Ze.label,type:Ze.type,kind:"outer",isOwningTheSameRcValueAs:void 0});s.stateMachineVariables=Le;let qe=s.pendingDeferredDrops;s.pendingDeferredDrops=[...((Q=e.$)==null?void 0:Q.deferredDropExpressions)??[]];let dt=de&&!c&&Se.expressions.length>0,kt=Se.expressions.length>0?Se.expressions[Se.expressions.length-1]:void 0,Rt=s.asyncBodyReturnExpr;if(!c&&kt&&m&&kt===m&&Se.awaitPoint?s.asyncBodyReturnExpr=kt:s.asyncBodyReturnExpr=void 0,Qc(Se," ",s,dt),s.asyncBodyReturnExpr=Rt,s.pendingDeferredDrops=qe,l.emitLine(""),Se.awaitPoint){s.inAsyncStateMachine=ee,s.stateMachineVariables=fe,s.variableIdRemapping=me;let Ze=Ve+1;{let Tt=xu(Se.awaitPoint,i),At=(Y=Se.awaitPoint.expr.args)==null?void 0:Y[0],gt=es((J=At==null?void 0:At.$)==null?void 0:J.type),nt=(se=Se.awaitPoint)==null?void 0:se.isInsideCond;nt&&(l.emitLine(" // Only await if the cond branch with await was taken"),l.emitLine(` if (sm->${Tt} != NULL) {`));let Ft=(ve=Se.awaitPoint)==null?void 0:ve.isInsideWhile,qt=Ft?(re=s.asyncWhileLoopInfo)==null?void 0:re.get(Se.awaitPoint.index):void 0;if(Ft&&qt){let Et=qt.whileLoopOriginIndex??Se.awaitPoint.index;l.emitLine(" // Only await if while loop is still active (not broken)"),l.emitLine(` if (sm->while_loop_${Et}_active) {`)}if(l.emitLine(" // Transition to next state after await"),l.emitLine(` sm->state = ${Ze};`),l.emitLine(""),l.emitLine(" // Check if future is ready"),l.emitLine(` int future_state = sm->${Tt}->state;`),l.emitLine(" if (future_state == -1 || future_state == -2) { // -1 = completed, -2 = aborted"),l.emitLine(" // Already complete \u2014 bounded inline fast-path to avoid scheduler round-trip"),l.emitLine(" if (__yo_inline_budget > 0) {"),l.emitLine(" __yo_inline_budget--;"),l.emitLine(` goto state_${Ze};`),l.emitLine(" }"),l.emitLine(" // Budget exhausted \u2014 yield once for fairness (microtask yield)"),l.emitLine(` __yo_async_spawn_task((void (*)(void*))${r}, (void*)sm);`),l.emitLine(" return;"),l.emitLine(" }"),l.emitLine(""),gt?l.emitLine(" // IO future: no extra ref needed (completion handler does not decr_rc)"):(l.emitLine(" // Future not complete \u2014 take event loop reference and start if cold"),l.emitLine(` __yo_incr_rc((void*)sm->${Tt}); // event loop reference`)),gt||(l.emitLine(" if (future_state == 0) { // 0 = cold (not started)"),Wh(Se.awaitPoint.expr,`sm->${Tt}`," ",s),l.emitLine(" // Cold future \u2014 start it via stored resume function pointer"),l.emitLine(` sm->${Tt}->__yo_resume_fn((void*)sm->${Tt});`),l.emitLine(""),l.emitLine(" // Re-check: may have completed synchronously"),l.emitLine(` future_state = sm->${Tt}->state;`),l.emitLine(" if (future_state == -1 || future_state == -2) {"),l.emitLine(" // Completed or aborted synchronously \u2014 yield for fairness"),l.emitLine(` __yo_async_spawn_task((void (*)(void*))${r}, (void*)sm);`),l.emitLine(" return;"),l.emitLine(" }"),l.emitLine(" }")),l.emitLine(""),l.emitLine(" // Still pending \u2014 register continuation and suspend"),l.emitLine(` sm->${Tt}->continuation_fn = (void (*)(void*))${r};`),l.emitLine(` sm->${Tt}->continuation_sm = (void*)sm;`),l.emitLine(" return;"),Ft&&qt){let Et=qt.whileLoopOriginIndex??Se.awaitPoint.index;l.emitLine(" } else {"),l.emitLine(" // While loop was broken, jump to code after loop"),l.emitLine(` goto after_while_loop_${Et};`),l.emitLine(" }")}nt&&(l.emitLine(" } else {"),l.emitLine(" // Non-await cond branch was taken, skip directly to next state"),l.emitLine(` sm->state = ${Ze};`),l.emitLine(` goto state_${Ze};`),l.emitLine(" }"))}}else if(de){if(!Se.expressions.some(Tt=>tf(Tt))){if((ce=e.$)!=null&&ce.deferredDropExpressions){let Tt=new oo,Jt=s.emitter;s.emitter=Tt;for(let gt of e.$.deferredDropExpressions){let nt=q(gt,"",s);nt&&Tt.emitLine(`${nt};`)}s.emitter=Jt;let At=Tt.print().trim();if(At){l.emitLine(" // Drop local variables before completion");for(let gt of At.split(`
|
|
196
|
+
`)){let nt=gt.trim();nt&&(l.emitLine(` ${nt}`),h.push(nt))}l.emitLine("")}}l.emitLine(" // Final state - complete the Future"),Ni({emitter:l,indent:" ",debugLabel:"Future %p completed"})}s.inAsyncStateMachine=ee,s.stateMachineVariables=fe,s.variableIdRemapping=me}else s.inAsyncStateMachine=ee,s.stateMachineVariables=fe,s.variableIdRemapping=me;l.emitLine(" }")}return l.emitLine(" }"),l.emitLine("}"),l.emitLine(""),h}function Ll(e,t,n,r,i){let o=i.emitter,a=xu(t,n);if(e.tag==="FnCall"&&E(e,":=")){let s=e.args[1];if(s&&s.tag==="FnCall"&&_r(s)){let l=s.args[0];if(l){let u=q(l,r,i);o.emitLine(`${r}// Store Future for additional await in cond branch`),o.emitLine(`${r}sm->${a} = ${u};`)}}return}if(e.tag==="FnCall"&&_r(e)){let s=e.args[0];if(s){let l=q(s,r,i);o.emitLine(`${r}// Store Future for additional await in cond branch`),o.emitLine(`${r}sm->${a} = ${l};`)}return}if(e.tag==="FnCall"&&E(e,P.cond)){fa(e,t,0,r,i);return}if(e.tag==="FnCall"&&E(e,P.match)){fa(e,t,0,r,i);return}if(e.tag==="FnCall"&&E(e,P.while)){fa(e,t,0,r,i);return}if(e.tag==="FnCall"&&E(e,P.begin)){fa(e,t,0,r,i);return}o.emitLine(`${r}// Warning: unhandled await pattern in remaining expressions`)}function tf(e){if(ln(e,"return")||E(e,"return"))return!0;if(e.tag==="FnCall"){for(let t of e.args)if(tf(t))return!0}return!1}function Gh(e){let t=[];for(let n of e)if(n.isEffectRowSpread){let r=n.type;z(r)&&r.resolvedConcreteType&&(r=r.resolvedConcreteType),Yt(r)&&t.push(...r.implicitParameters)}else t.push(n);return t}function Wh(e,t,n,r){var u,_,c,f,p;let i=(u=e.args)==null?void 0:u[0];if(!((_=i==null?void 0:i.$)!=null&&_.type))return;let o=Ln(i.$.type);if(!((c=o==null?void 0:o.isFuture.effects)!=null&&c.length))return;let a=Gh(o.isFuture.effects),s=r.emitter,l=(f=e.args)==null?void 0:f.find(m=>S(m)&&E(m,P.using));if(l){let m=l.args;for(let h=0;h<a.length&&h<m.length;h++){let y=a[h],g=m[h];if(ne(y.type)){if(y.type.forallParameters.length>0)continue;let v=q(g,n,r),T=y.label;s.emitLine(`${n}${t}->__capture.${T} = (void*)${v};`)}else Xe(y.type)&&Jc(y.type,t,n,(p=g.$)==null?void 0:p.value,r,e)}}else for(let m of a)if(ne(m.type)){if(m.type.forallParameters.length>0)continue;let h=qh(m.label,r,e);h&&s.emitLine(`${n}${t}->__capture.${m.label} = (void*)${h};`)}else Xe(m.type)&&Jc(m.type,t,n,void 0,r,e)}function Jc(e,t,n,r,i,o){var s,l,u,_;let a=i.emitter;for(let c of e.fields){if(!ne(c.type))continue;let f;if(i.stateMachineVariables){for(let[,p]of i.stateMachineVariables)if(p.name===c.label&&p.kind==="outer"){f=`sm->__capture.${c.label}`;break}}if(!f&&r&&wt(r)){let p=e.fields.indexOf(c),m=r.fields[p];if(m&&ge(m)){let h=i.functions[m.funcId];h&&(f=h.cName)}}if(!f&&i.currentEvidenceParams){for(let p of i.currentEvidenceParams.values())if(p.fieldLabel===c.label){f=p.cParamName;break}}if(!f){let p=((s=o.$)==null?void 0:s.env)??((l=o.func.$)==null?void 0:l.env);if(p){let m=cr(p,h=>h.isImplicit===!0);for(let h=m.length-1;h>=0;h--){let y=m[h],g=(u=y.value)==null?void 0:u[y.value.length-1];if(g&&wt(g)){let v=g.type.fields.findIndex(T=>T.label===c.label);if(v>=0){let T=g.fields[v];if(T&&ge(T)){let $=(_=i.functions[T.funcId])==null?void 0:_.cName;if($){f=$;break}}}}}}}f&&a.emitLine(`${n}${t}->__capture.${c.label} = (void*)${f};`)}}function qh(e,t,n){if(t.currentEvidenceParams){for(let r of t.currentEvidenceParams.values())if(r.fieldLabel===e)return r.cParamName}if(t.stateMachineVariables){for(let[,r]of t.stateMachineVariables)if(r.name===e&&r.kind==="outer")return`sm->__capture.${e}`}}var Yh=new Set(["__yo_mutex_init","__yo_mutex_destroy","__yo_mutex_lock","__yo_mutex_unlock","__yo_cond_init","__yo_cond_destroy","__yo_cond_wait","__yo_cond_signal","__yo_cond_broadcast","__yo_thread_join","__yo_thread_self"]);function nf(e){var n,r,i,o,a;let t=e.emitter;t.emitDeclarationLine("// Function declarations"),t.emitDeclarationLine("/// Extern functions");for(let s in e.externFunctions){let{cName:l,type:u}=e.externFunctions[s];if(u.isExtern==="yo"){if(Yh.has(l))continue;Du(u,l,!0,e);continue}u.isExtern==="c"&&u.cInclude||l.startsWith("__atomic_")||l.startsWith("__sync_")||Du(u,l,!0,e)}t.emitDeclarationLine(""),e.usesAsync&&(t.emitDeclarationLine("/// Async runtime functions"),t.emitDeclarationLine("static void __yo_async_spawn_task(void (*resume_fn)(void*), void* state_machine);"),t.emitDeclarationLine("")),t.emitDeclarationLine("/// Object constructors"),jh(e),t.emitDeclarationLine(""),t.emitDeclarationLine("/// Closure constructors"),t.emitDeclarationLine(""),t.emitDeclarationLine("/// Capture dispose functions"),Kh(e),t.emitDeclarationLine(""),t.emitDeclarationLine("/// Dyn type constructors"),t.emitDeclarationLine(""),t.emitDeclarationLine("/// Regular functions");for(let s in e.functions){let{cName:l,value:u}=e.functions[s],_=l==="__yo_user_main",c=(r=(n=u.body)==null?void 0:n.$)==null?void 0:r.effectAnalysis,f=c&&c.hasEffects;if(!_&&!u.type.isClosure&&((i=u.specializedFunctionCaches)==null?void 0:i.length)>0||!_&&!f&&!u.isModuleEffectMember&&!u.type.isClosure&&!u.specializedType&&(((o=u.specializedFunctionCaches)==null?void 0:o.length)??0)===0&&pn(u.specializedType??u.type).length===0&&[...u.type.implicitParameters,...u.type.parameters.filter($=>$.isImplicit)].some($=>ne($.type)))continue;let m=u.specializedType??u.type,h=pn(m).length>0;if(!_&&u.isIoAsyncStateMachineClosure||!_&&!f&&!h&&!u.isModuleEffectMember&&(li(u.type)&&!u.type.isClosure||((a=u.specializedFunctionCaches)==null?void 0:a.length)>0&&!u.type.isClosure||Qi(u)||gi(u)||u.isIoAsyncStateMachineClosure))continue;let y=u.specializedType??u.type,g=!f&&!u.isModuleEffectMember&&(y.parameters.some($=>Me($.type))||y.forallParameters.length>0),v=Me(y.return.type),T=z(y.return.type)&&y.return.type.requiredTraits.length>0;g||v&&!T&&!u.isModuleEffectMember||Du(y,l,!1,e,u.isModuleEffectMember?void 0:u.body,u.specializedType&&pn(y).length===0&&pn(u.type).some($=>$.fieldFunctionType.forallParameters&&$.fieldFunctionType.forallParameters.length>0)?u.type:void 0)}t.emitDeclarationLine("/// Closure vtable instances"),t.emitDeclarationLine("")}function pn(e){let t=[],n=Hh(e.implicitParameters);for(let r of n)Xe(r.type)?rf(r.label,r.type,[],t):ne(r.type)&&t.push({implicitLabel:r.label,fieldLabel:r.label,fieldPath:[r.label],fieldFunctionType:r.type,cParamName:be(r.label)});return t}function rf(e,t,n,r){for(let i of t.fields)if(ne(i.type)){let o=[...n,i.label],a=o.join("__");r.push({implicitLabel:e,fieldLabel:a,fieldPath:o,fieldFunctionType:i.type,cParamName:be(`${e}__${a}`)})}else Xe(i.type)&&rf(e,i.type,[...n,i.label],r)}function Hh(e){let t=[];for(let n of e)if(n.isEffectRowSpread){let r=n.type;z(r)&&r.resolvedConcreteType&&(r=r.resolvedConcreteType),Yt(r)&&t.push(...r.implicitParameters)}else t.push(n);return t}function hi(e,t,n,r,i){let o=r||j(e.return.type,n),a=e.parameters.filter(c=>!c.isCompileTimeOnly),s=[];e.isClosure&&s.push("void* closure_context");let l=a.map((c,f)=>{let p=be(c.label||`param${f}`);if(ne(c.type))return hi(c.type,"(*)",n).replace(" (*)(",` (*${p})(`);{let m;return z(c.type)&&at(c.type)?c.type.resolvedConcreteType?m=j(c.type.resolvedConcreteType,n)+"*":m=j(c.type,n):m=j(c.type,n),`${m} ${p}`}});s.push(...l);let u=pn(i??e);for(let c of u)if(c.fieldFunctionType.forallParameters&&c.fieldFunctionType.forallParameters.length>0)s.push(`void* ${c.cParamName}`);else{let f=hi(c.fieldFunctionType,"(*)",n).replace(" (*)(",` (*${c.cParamName})(`);s.push(f)}let _=s.join(", ");return`${o} ${t}(${_})`}function Du(e,t,n,r,i,o){var f,p,m,h;let a;if(i&&at(e.return.type)){let y=Qa(i);(f=y==null?void 0:y.$)!=null&&f.asyncStateMachineStructName?a=`${y.$.asyncStateMachineStructName}*`:(p=i.$)!=null&&p.type&&z(i.$.type)&&at(i.$.type)&&(a=j(i.$.type,r))}if(i&&z(e.return.type)&&!at(e.return.type)&&(m=i.$)!=null&&m.type&&(a=j(i.$.type,r)),!a&&i&&((h=i.$)!=null&&h.type)&&!at(e.return.type)){let y=j(e.return.type,r),g=j(i.$.type,r);y!==g&&(a=g)}let s=a?hi(e,t,r,a,o):hi(e,t,r,void 0,o),l=M(e),u=t==="__yo_user_main"||r.exportedFunctionLabels&&[...r.exportedFunctionLabels.values()].some(y=>be(y)===t),_=!n&&!u&&(t.includes("___drop")||t.includes("___dup")||t.includes("___dispose")),c=n?"extern ":u?"":_?"static inline __attribute__((always_inline)) ":"static inline ";r.emitter.emitDeclarationLine(`${c}${s}; // ${l}`)}function jh(e){let t=e.emitter;t.emitDeclarationLine("static inline void __yo_decr_rc(void* ptr); // Decrement reference count"),t.emitDeclarationLine("static inline void* __yo_incr_rc(void* ptr); // Increment reference count"),t.emitDeclarationLine("static void __yo_gc_register(void* ptr); // Register object for cycle detection"),t.emitDeclarationLine("static void __yo_gc_unregister(void* ptr); // Unregister object from cycle detection"),t.emitDeclarationLine("static void __yo_gc_collect(); // Trigger garbage collection"),t.emitDeclarationLine("static void __yo_gc_init_thread(); // Initialize thread-local GC state (for worker threads)"),t.emitDeclarationLine("static void __yo_cleanup_thread_gc(); // Clean up thread-local GC state"),t.emitDeclarationLine("static void __yo_init_process_cleanup(void); // Initialize process cleanup");for(let n in e.types){let{type:r,cName:i}=e.types[n];if(Ae(r)&&r.isReferenceSemantics){if(r.fields.some(l=>Me(l.type)))continue;let a=`__yo_new_${i}`,s=r.fields.map(l=>{let u=j(l.type,e),_=be(l.label);return`${u} ${_}`}).join(", ");t.emitDeclarationLine(`static ${i}* ${a}(${s}); // Constructor`)}}}function Kh(e){let t=e.emitter;if(e.closureCaptureMap&&e.closureCaptureMap.size>0)for(let[n]of e.closureCaptureMap){let r=`__yo_dispose_closure_${n}`;t.emitDeclarationLine(`static void ${r}(void* closure_ptr);`)}}function of(e){let t=new Set;for(let n in e.functions){let{value:r,cName:i}=e.functions[n],o=r.specializedType;if(Qi(r)||!o||!Rr(r.type)||Rr(o))continue;let a=o.parameters.some(c=>Me(c.type)),s=Me(o.return.type);if(a||s||pn(r.type).some(c=>c.fieldFunctionType.forallParameters&&c.fieldFunctionType.forallParameters.length>0)||t.has(n))continue;t.add(n);let _=i.includes("___drop")||i.includes("___dup")||i.includes("___dispose")?"static inline __attribute__((always_inline)) ":"static inline ";e.emitter.emitDeclarationLine(`${_}${hi(o,i,e)}; // specialized function: ${M(r.type)}`)}}function vi(e,t,n){let r=ae(t,e);return r.length===0?!1:r[r.length-1].frameLevel<=n}function af(e){var t,n;return!!((t=e.$)!=null&&t.closureFunctionValue&&((n=e.$)!=null&&n.type)&&zn(e.$.type))}function Xh(e,t,n,r,i,o=!1){var p;let a=Object.values(i.types).find(m=>m.type===e);if(!a)return i.emitter.emitLine(`${r}/* Error: Capture type not found for closure */`),null;let s=a.cName,l=new Map;if((p=n.$)!=null&&p.deferredDupExpressions)for(let m of n.$.deferredDupExpressions){let h=Fl(m);h&&l.set(h,m)}let u=e.fields.map(m=>{var v,T;if(m.isEffectParam)return"NULL";let h,y=m.exprs.expr;if((T=(v=y.$)==null?void 0:v.deferredDupExpressions)!=null&&T.length&&(h=y.$.deferredDupExpressions[0]),!h){let $=[m.label];K(y)&&$.push(y.token.value);for(let C of $){let k=l.get(C);if(k){h=k;break}}}if(h)return q(h,r,i);let g={tag:"Atom",token:y.token,$:y.$};return q(g,r,i)}),_=`(${s}){ ${u.map((m,h)=>{let y=e.fields[h];return y?`.${y.label} = ${m}`:`/* Error: missing field at index ${h} */`}).join(", ")} }`,c=n.token.position.row!==void 0?`${Date.now()}_${n.token.position.row}`:`${Date.now()}_${Math.random().toString(36).substr(2,9)}`,f=`__capture_${t}_${c}`;return o?i.emitter.emitLine(`${r}${s} ${f} = ${_};`):(i.emitter.emitLine(`${r}${s}* ${f} = (${s}*)__yo_malloc(sizeof(${s}));`),i.emitter.emitLine(`${r}*${f} = ${_};`)),{captureTempVar:f,captureCName:s}}function sf(e,t,n){var m,h;if(!e.$||!e.$.type||!e.$.closureFunctionValue)return"// Error: Missing closure metadata";let r=Kn(e.$.type),i=r.isFn.callType,o=e.$.closureFunctionValue,a=e.$.captureType,s=(m=n.functions[o.funcId])==null?void 0:m.cName;if(!s)return"// Error: Closure implementation function not found in context";let l=st(e.$.type),u;if(l){let y=n.types[e.$.type.id];if(!y)return"// Error: Dyn closure type not found in context";u=y.cName}let _=a&&Ae(a)&&a.fields.length>0,c=j(i.return.type,n),f=i.parameters.map(y=>j(y.type,n)).join(", "),p=`(${c} (*)(void*${f?", "+f:""}))${s}`;if(_&&a&&Ae(a)){let y=!l,g=Xh(a,i.id,e,t,n,y);if(!g)return"// Error: Failed to allocate closure capture";let{captureTempVar:v}=g;if(l){let T=`__yo_create_${u}`,$=`__yo_dispose_${u}`;return`${T}(${v}, ${$}, ${p})`}else return n.implClosureCallMap.set(a.id,{functionCName:s,callTypeId:r.isFn.callType.id,callType:r.isFn.callType,consumedCaptures:(h=o.closureInfo)==null?void 0:h.consumedCaptures}),v}else if(l){let y=`__yo_create_${u}`,g=`__yo_dispose_${u}`;return`${y}(NULL, ${g}, ${p})`}else{if(e.$.type.tag==="SomeType"){let y=e.$.type;if(y.resolvedConcreteType)return n.implClosureCallMap.set(y.resolvedConcreteType.id,{functionCName:s,callTypeId:r.isFn.callType.id,callType:r.isFn.callType}),`(${j(y.resolvedConcreteType,n)}){}`}return"// Error: Impl(Fn(...)) without captures missing resolvedConcreteType"}}function Mu(e,t,n){if(e.pendingDeferredDrops&&e.loopBodyDropsBaselineCount!==void 0){let r=e.loopBodyDropsBaselineCount,i=e.pendingDeferredDrops.length,o=e.pendingDeferredDrops.slice(0,i-r);for(let a of o){let s=q(a,t,n);s&&n.emitter.emitLine(`${t}${s};`)}}}function pa(e,t,n=""){var a,s,l,u,_,c,f,p,m,h,y,g,v,T,$,C,k,b,w,A,L,N,x,V,U,R,D,H,B;let r=t;if(e.token.value==="continue"){if(r.currentContinueLabel)return Mu(r,n,t),`goto ${r.currentContinueLabel}`;if(r.currentLoopLabel)return Mu(r,n,t),"continue";if(r.smWhileContinueInfo){if(r.smWhileContinueInfo.emitDropsBeforeGoto&&r.smWhileBodyDrops&&r.smWhileBodyDrops.length>0){let G=t.emitter;for(let Q of r.smWhileBodyDrops){let Y=q(Q,n,t);Y&&Y.includes("sm->")&&G.emitLine(`${n}${Y};`)}}if(r.smWhileContinueInfo.stepExpr){let G=t.emitter,Q=q(r.smWhileContinueInfo.stepExpr,n,t);Q&&G.emitLine(`${n}${Q};`)}return`goto ${r.smWhileContinueInfo.label}`}return"continue"}if(e.token.value==="break"){if(r.currentLoopLabel)return Mu(r,n,t),r.insideMatch?`goto ${r.currentLoopLabel}`:"break";if(r.smWhileBreakInfo){let{label:G,activeIndex:Q}=r.smWhileBreakInfo;if(r.smWhileBodyDrops&&r.smWhileBodyDrops.length>0){let Y=t.emitter;for(let J of r.smWhileBodyDrops){let se=q(J,n,t);se&&se.includes("sm->")&&Y.emitLine(`${n}${se};`)}}return Q!==void 0?(t.emitter.emitLine(`${n}sm->while_loop_${Q}_active = false;`),`goto ${G}`):`goto ${G}`}return"break"}if(e.token.value==="return"){if(r.inAsyncStateMachine){let G=t.emitter,Q=r.inAsyncStateMachine.futureType,J=Ln(Q).isFuture.outputType,se=De(J);if((a=e.$)!=null&&a.deferredDropExpressions)for(let re of e.$.deferredDropExpressions){let ce=q(re,n,t);ce&&ce.includes("sm->")&&G.emitLine(`${n}${ce};`)}if(r.pendingDeferredDrops&&r.pendingDeferredDrops.length>0){G.emitLine(`${n}// Drop local variables before early completion`);for(let re of r.pendingDeferredDrops){let ce=q(re,n,t);ce&&ce.includes("sm->")&&G.emitLine(`${n}${ce};`)}}G.emitLine(`${n}// Early return - complete the result Future`);let ve=se?void 0:`(${j(J,t)}){0}`;return Ni({emitter:G,indent:n,resultCode:ve,debugLabel:t.currentFunctionName}),""}return"return"}if((s=e.$)!=null&&s.type&&De(e.$.type))return"";if((r.inAsyncStateMachine||r.inEffectStateMachine)&&r.stateMachineVariables){let G=e.token.value;if((l=r.localShadowedVariables)!=null&&l.has(G))return be(G);let Q=!1;if((u=e.$)!=null&&u.env){let Y=ae(e.$.env,G);if(Y.length>0){let J=Y[Y.length-1],se=J.isOwningTheSameRcValueAs?J.isOwningTheSameRcValueAs.id:J.id;(_=r.variableIdRemapping)!=null&&_.has(se)&&(se=r.variableIdRemapping.get(se));let ve=r.stateMachineVariables.get(se);if(ve){let re=(c=r.stateMachineFieldAliases)==null?void 0:c.get(se);if(re)return Q=!0,`sm->${re}`;let ce=ve.kind==="outer"?`__capture.${G}`:`var_${ve.id}`;return Q=!0,`sm->${ce}`}}}if(!Q){for(let[Y,J]of r.stateMachineVariables)if(J.name===G){let se=(f=r.stateMachineFieldAliases)==null?void 0:f.get(Y);if(se)return Q=!0,`sm->${se}`;let ve=J.kind==="outer"?`__capture.${G}`:`var_${Y}`;return Q=!0,`sm->${ve}`}}if((p=e.$)!=null&&p.env){let Y=ae(e.$.env,G);if(Y.length>0){let J=Y[Y.length-1];if(J.isOwningTheSameRcValueAs){let se=J.isOwningTheSameRcValueAs.name,ve=J.isOwningTheSameRcValueAs.id;for(let[re,ce]of r.stateMachineVariables)if(ce.name===se||re===ve)return`sm->${ce.kind==="outer"?`__capture.${se}`:`var_${re}`}`}}}if(r.currentClosureCaptures&&r.currentClosureCaptures.includes(G)&&r.currentClosureCaptureFrameLevel!==void 0){let Y=r.currentClosureCaptureTypeCName;return Y?`((${Y}*)closure_context)->${We(G,(m=e.$)==null?void 0:m.env)}`:`closure_context->${We(G,(h=e.$)==null?void 0:h.env)}`}if((y=e.$)!=null&&y.variableName){if((g=e.$)!=null&&g.env&&((v=e.$)!=null&&v.value)&&!Ie(e.$.value)){let Y=ae(e.$.env,e.$.variableName);if(Y.length>0&&Y[Y.length-1].isCompileTimeOnly)return Yn(e.$.value,t,e)}return We(e.$.variableName,e.$.env)}}if((T=e.$)!=null&&T.variableName){if(($=e.$)!=null&&$.env&&((C=e.$)!=null&&C.value)&&!Ie(e.$.value)){let G=ae(e.$.env,e.$.variableName);if(G.length>0&&G[G.length-1].isCompileTimeOnly)return Yn(e.$.value,t,e)}if(!(r.currentClosureCaptures&&r.currentClosureCaptures.includes(e.token.value)&&((k=e.$)!=null&&k.env)&&r.currentClosureCaptureFrameLevel!==void 0&&vi(e.token.value,e.$.env,r.currentClosureCaptureFrameLevel)))return We(e.$.variableName,(b=e.$)==null?void 0:b.env)}if((w=e.$)!=null&&w.value&&!Ie(e.$.value))return Yn(e.$.value,t,e);let i=(A=e.$)!=null&&A.env&&r.currentClosureCaptureFrameLevel!==void 0?vi(e.token.value,e.$.env,r.currentClosureCaptureFrameLevel):!1;if(r.currentClosureCaptures&&r.currentClosureCaptures.includes(e.token.value)&&r.currentClosureCaptureFrameLevel!==void 0&&(!((L=e.$)!=null&&L.env)||i)){let G=r.currentClosureCaptureTypeCName;return G?`((${G}*)closure_context)->${We(e.token.value,(N=e.$)==null?void 0:N.env)}`:`closure_context->${We(e.token.value,(x=e.$)==null?void 0:x.env)}`}if(r.currentFunctionName&&!r.currentClosureCaptures){let G=Object.values(r.functions).find(Q=>Q.cName===r.currentFunctionName);if(G&&G.value.type.isClosure){let Q=Object.values(r.types).find(Y=>ne(Y.type)&&Y.type.isClosure&&Y.type===G.value.type);if(Q)return`((${`${Q.cName}_capture`}*)closure_context->data)->${We(e.token.value,(V=e.$)==null?void 0:V.env)}`}}if((U=e.$)!=null&&U.env){let G=ae(e.$.env,e.token.value);if(G.length>0){let Q=G[G.length-1];if((R=Q.value)!=null&&R[0]&&ge(Q.value[0])){let Y=(D=t.functions[Q.value[0].funcId])==null?void 0:D.cName;if(Y)return Y}else if(ne(Q.type)&&(Ie((H=Q.value)==null?void 0:H[0])||Q.value===void 0)){let Y=Object.entries(t.functions).find(([J,se])=>se.value.funcName===e.token.value);if(Y)return Y[1].cName}}}return We(e.token.value,(B=e.$)==null?void 0:B.env)}function lf(e,t,n){var y,g,v,T,$,C,k,b,w,A,L,N,x,V,U,R,D,H,B,G;let r;if(An(e)){let Q=(g=(y=e.$)==null?void 0:y.runtimeArgExprsInOrder)==null?void 0:g[0],Y=(v=Q==null?void 0:Q.$)==null?void 0:v.closureFunctionValue;Y&&ge(Y)&&(r=Y.body)}else r=e.args[0];if(!r)return"/* Error: async requires exactly 1 argument */";let i=(T=e.$)==null?void 0:T.type;if(!i||!at(i))return"/* Error: async block must have Future type */";let o=Ln(i);if(!o)return"/* Error: Could not extract Future module type */";let a=(($=e.$)==null?void 0:$.variableName)||`async_block_${Date.now()}`,s=`${a}_state_t`,l=`${a}_resume`,u=`__yo_new_${a}`,_=`${a}_state_dispose`;n.types[i.id]={type:i,cName:s};let c=(C=e.$)==null?void 0:C.awaitAnalysis;if(!c)throw new Error("Missing await analysis for async block. This should have been computed during evaluation.");let f=o.isFuture.outputType;if(z(f))if(f.resolvedConcreteType)f=f.resolvedConcreteType;else{let Q=(b=(k=e.$)==null?void 0:k.runtimeArgExprsInOrder)==null?void 0:b[0],Y=(w=Q==null?void 0:Q.$)==null?void 0:w.closureFunctionValue;if(Y&&ge(Y)){let J=(L=(A=Y.type)==null?void 0:A.return)==null?void 0:L.type;if(J&&z(J)&&J.resolvedConcreteType)f=J.resolvedConcreteType;else if((x=(N=Y.body)==null?void 0:N.$)!=null&&x.type){let se=Y.body.$.type;z(se)&&se.resolvedConcreteType?f=se.resolvedConcreteType:z(se)||(f=se)}}}let p=j(f,n),m=n.emitter;if(m.emitDeclarationLine(`void ${_}(void* sm_ptr); // Dispose function for state machine`),m.emitDeclarationLine(""),m.emitDeclarationLine(`void ${l}(${s}* sm);`),m.emitDeclarationLine(""),(V=e.$)!=null&&V.captureType){let Q=e.$.captureType,Y=Object.values(n.types).find(se=>se.type===Q),J=Y?Y.cName:`async_capture_${Q.id}`;m.emitDeclarationLine(`${s}* ${u}(${J} __capture);`)}else m.emitDeclarationLine(`${s}* ${u}();`);m.emitDeclarationLine(""),n.deferredAsyncBlocks||(n.deferredAsyncBlocks=[]),n.deferredAsyncBlocks.push({bodyExpr:r,asyncBlockId:a,structName:s,resumeFunctionName:l,constructorName:u,disposeFunctionName:_,futureType:i,futureModuleType:o,resultType:f,resultTypeCName:p,captureType:(U=e.$)==null?void 0:U.captureType,analysis:c});let h=(R=e.$)==null?void 0:R.captureType;if(h){let Q=Object.values(n.types).find(Ve=>Ve.type===h),Y=Q?Q.cName:`async_capture_${h.id}`,J=n,se=J.currentClosureCaptures!==void 0||J.inAsyncStateMachine!==void 0||J.inEffectStateMachine!==void 0,ve=!1,re=h.fields.map(Ve=>{var fe,me;if(Ve.isEffectParam)return`.${Ve.label} = NULL`;let de;if(!se&&((fe=e.$)!=null&&fe.deferredDupExpressions))for(let Le of e.$.deferredDupExpressions){let qe;if(S(Le)&&(Le.args.length>0&&K(Le.args[0])?qe=Le.args[0].token.value:Le.args.length===0&&S(Le.func)&&E(Le.func,".")&&Le.func.args.length>=2&&K(Le.func.args[0])&&(qe=Le.func.args[0].token.value)),qe===Ve.label){de=Le;break}}if(de)return ve=!0,(me=de.$)!=null&&me.variableName?(q(de,t,n),`.${Ve.label} = ${de.$.variableName}`):`.${Ve.label} = ${q(de,t,n)}`;let ee={tag:"Atom",token:Ve.exprs.expr.token,$:Ve.exprs.expr.$};return`.${Ve.label} = ${pa(ee,n)}`}).join(", "),ce=`(${Y}){${re}}`;if(!ve){let Ve=fr(h,n);Ve&&(ce=`${Ve}(${ce})`)}let we=((D=e.$)==null?void 0:D.variableName)||"async_result",Se=`${u}(${ce})`;if(we&&((H=e.$)!=null&&H.type)){let Ve=Kt(e.$.type,we,n);return n.emitter.emitLine(`${t}${Ve} = ${Se};`),we}else return Se}else{let Q=((B=e.$)==null?void 0:B.variableName)||"async_result",Y=`${u}()`;if(Q&&((G=e.$)!=null&&G.type)){let J=Kt(e.$.type,Q,n);return n.emitter.emitLine(`${t}${J} = ${Y};`),Q}else return Y}}function uf(e,t){var y;let n=t.emitter,{asyncBlockId:r,structName:i,resultType:o,resultTypeCName:a,captureType:s,analysis:l,crossBoundaryIds:u,awaitFutureTempVarAliases:_,overlappingSlotAliases:c,overlappingSlots:f}=e;if(n.emitDeclarationLine(`// State machine for async block ${r} - implements Future(${M(o)})`),n.emitDeclarationLine(`struct ${i}_struct {`),n.emitDeclarationLine(" __yo_ref_header_t header; // Reference counting header (must be first)"),n.emitDeclarationLine(" int state; // Current state (0 = cold, 1..N = intermediate, -1 = completed, -2 = aborted)"),De(o)?n.emitDeclarationLine(" uint8_t result; // Dummy result for unit type"):n.emitDeclarationLine(` ${a} result; // The result value of type ${M(o)}`),n.emitDeclarationLine(" void (*continuation_fn)(void*); // Resume function of awaiting task"),n.emitDeclarationLine(" void* continuation_sm; // State machine of awaiting task"),n.emitDeclarationLine(""),n.emitDeclarationLine(" void (*__yo_resume_fn)(void*); // Resume function pointer (for lazy start at await/spawn)"),n.emitDeclarationLine(""),s){let g=Object.values(t.types).find(T=>T.type===s),v=g?g.cName:`async_capture_${s.id}`;n.emitDeclarationLine(" // Captured variables from outer scope"),n.emitDeclarationLine(` ${v} __capture;`),n.emitDeclarationLine("")}let p=l.capturedVariables.filter(g=>g.kind!=="outer");if(u&&(p=p.filter(g=>u.has(g.id)&&!(_!=null&&_.has(g.id))&&!(c!=null&&c.has(g.id)))),p.length>0){n.emitDeclarationLine(" // Local variables");for(let g of p){let v=j(g.type,t),T=Xn(g.id,"local");n.emitDeclarationLine(` ${v} ${T}; // ${g.name}`)}n.emitDeclarationLine("")}if(f&&f.length>0){n.emitDeclarationLine(" // Overlapping storage slots (Phase 2)");for(let g of f)n.emitDeclarationLine(` ${g.cType} ${g.fieldName}; // shared: ${g.variableNames.join(", ")}`);n.emitDeclarationLine("")}if(l.awaitPoints.length>0){let g=[];for(let v of l.awaitPoints)if(!(De(v.resultType)||z(v.resultType)&&!v.resultType.resolvedConcreteType)&&v.isInsideCond){let C=v.resultType;if(v.futureType){let b=Ln(v.futureType);b&&(C=b.isFuture.outputType)}let k=j(C,t);g.push(` ${k} await_result_${v.index};`)}if(g.length>0){n.emitDeclarationLine(" // Await result temporaries");for(let v of g)n.emitDeclarationLine(v);n.emitDeclarationLine("")}}if(l.awaitPoints.length>0){let g=l.awaitPoints.filter(v=>v.futureVariableId===void 0);if(g.length>0){n.emitDeclarationLine(" // Future references for awaits");for(let v of g){let T=v.expr;if(T.tag!=="FnCall")continue;let $=T.args[0],C=(y=$==null?void 0:$.$)==null?void 0:y.type;if(!C)throw new Error(`Internal error: await expression missing type info for future argument in async block ${r}`);let k=j(C,t);n.emitDeclarationLine(` ${k} await_future_${v.index};`)}n.emitDeclarationLine("")}}let m=l.awaitPoints.filter(g=>g.needsOwnCondBranchField);if(m.length>0){n.emitDeclarationLine(" // Branch tracking for cond expressions with await");for(let g of m)n.emitDeclarationLine(` int cond_branch_${g.index}; // Which branch was taken in cond with await ${g.index}`);n.emitDeclarationLine("")}let h=l.awaitPoints.filter(g=>g.isInsideWhile);if(h.length>0){n.emitDeclarationLine(" // Loop state tracking for while loops with await");let g=l.awaitPoints.length;for(let v of h){n.emitDeclarationLine(` _Bool while_loop_${v.index}_active; // Whether while loop ${v.index} should continue`);let T=(v.whileNestingDepth??1)-1;for(let $=0;$<T;$++)n.emitDeclarationLine(` _Bool while_loop_${g}_active; // Whether outer while loop ${g} should continue`),g++}n.emitDeclarationLine("")}n.emitDeclarationLine("};"),n.emitDeclarationLine("")}function Qh(e){var l;if(!e.deferredAsyncBlocks||e.deferredAsyncBlocks.length===0)return;let t=e.deferredAsyncBlocks,n=new Map;for(let u of t)n.set(u.structName,u);let r=new Map,i=new Map;for(let u of t)r.set(u.structName,new Set),i.set(u.structName,0);for(let u of t){let _=c=>{let f=r.get(c);f.has(u.structName)||(f.add(u.structName),i.set(u.structName,(i.get(u.structName)??0)+1))};for(let c of u.analysis.capturedVariables){let f;try{f=j(c.type,e)}catch{continue}let p=n.get(f);p&&p.structName!==u.structName&&_(p.structName)}for(let c of u.analysis.awaitPoints){if(c.futureVariableId!==void 0)continue;let f=c.expr;if(f.tag!=="FnCall")continue;let p=f.args[0],m=(l=p==null?void 0:p.$)==null?void 0:l.type;if(!m)continue;let h;try{h=j(m,e)}catch{continue}let y=n.get(h);y&&y.structName!==u.structName&&_(y.structName)}}let o=[];for(let[u,_]of i.entries())_===0&&o.push(u);let a=[];for(;o.length>0;){let u=o.shift();a.push(u);let _=r.get(u);if(_)for(let c of _){let f=(i.get(c)??0)-1;i.set(c,f),f===0&&o.push(c)}}let s=a.length===t.length?a.map(u=>n.get(u)).filter(Boolean):t;for(let u of s){let{crossBoundaryIds:_,awaitFutureTempVarAliases:c,variableSegments:f}=Il(u.bodyExpr,u.analysis),{slotAliases:p,slots:m}=Al(_,f,u.analysis.capturedVariables,c,e);uf({asyncBlockId:u.asyncBlockId,structName:u.structName,resultType:u.resultType,resultTypeCName:u.resultTypeCName,captureType:u.captureType,analysis:u.analysis,crossBoundaryIds:_,awaitFutureTempVarAliases:c,overlappingSlotAliases:p,overlappingSlots:m},e)}}function Zh(e,t,n,r,i,o,a,s,l,u){var c;let _=u.emitter;if(_.emitLine(`// Dispose function for async block ${e} state machine`),_.emitLine("// Called by __yo_decr_rc when refcount hits 0 - do NOT call __yo_free here"),_.emitLine(`void ${n}(void* sm_ptr) {`),_.emitLine(` ${t}* sm = (${t}*)sm_ptr;`),_.emitLine(` ASYNC_DEBUG("${n}: Disposing state machine\\n");`),_.emitLine(""),i&&it(i)){let f=Object.values(u.types).find(p=>p.type===i);if(!f)_.emitLine(" /* Error: capture struct type not found in context */");else{let p=f.cName,m=i.trait.fields.find(h=>h.label===F.___drop[0]);if(m&&m.assignedValue&&ge(m.assignedValue)){let h=(c=u.functions[m.assignedValue.funcId])==null?void 0:c.cName;h&&(_.emitLine(' ASYNC_DEBUG(" Dropping capture struct\\n");'),_.emitLine(` ${h}(sm->__capture);`))}else _.emitLine(` /* Warning: ___drop function not found for capture struct ${p} */`)}}if(_.emitLine(""),!De(r)&&it(r)){let f=j(r,u);_.emitLine(" // Drop result field if it was set (state == -1 means completed)"),_.emitLine(" int final_state = sm->state;"),_.emitLine(" if (final_state == -1) {"),_.emitLine(' ASYNC_DEBUG(" Dropping result field\\n");');let p=Wr(r,u);p?_.emitLine(` ${p}(sm->result);`):_.emitLine(` /* Warning: No ___drop function found for result type ${f} */`),_.emitLine(" }")}_.emitLine("");{let f=[];for(let p of o.capturedVariables){if(p.kind!=="local"||!s.has(p.id)||l.has(p.id)||p.isOwningTheSameRcValueAs!==void 0)continue;let h=`sm->${Xn(p.id,"local")}`;if(st(p.type))f.push(` if ((${h}).data != NULL) { __yo_decr_rc((void*)(${h}).data); }`);else if(hn(p.type)||oi(p.type))f.push(` if (${h} != NULL) { __yo_decr_rc_atomic((void*)${h}); }`);else if(en(p.type)||z(p.type)&&rr(p.type)){let y=Wr(p.type,u);y?f.push(` if (${h} != NULL) { ${y}(${h}); }`):f.push(` if (${h} != NULL) { __yo_decr_rc((void*)${h}); }`)}else if(it(p.type)){let y=Wr(p.type,u);y&&f.push(` ${y}(${h});`)}}if(f.length>0){_.emitLine(" // Drop local variables on escape (state == -2)"),_.emitLine(" if (sm->state == -2) {");for(let p of f)_.emitLine(p);_.emitLine(" }")}}_.emitLine(" // Memory freed by __yo_decr_rc after this function returns"),_.emitLine("}")}function Jh(e,t,n,r,i,o,a,s,l,u){let _=u.emitter;if(l){let c=Object.values(u.types).find(p=>p.type===l),f=c?c.cName:`async_capture_${l.id}`;_.emitLine(`${t}* ${r}(${f} __capture) {`)}else _.emitLine(`${t}* ${r}() {`);if(_.emitLine(" // Allocate async block state machine (heap-backed, ref-counted)"),_.emitLine(` ${t}* sm = (${t}*)__yo_malloc(sizeof(${t}));`),_.emitLine(` memset(sm, 0, sizeof(${t}));`),_.emitLine(""),_.emitLine(" // Initialize reference counting header"),_.emitLine(" sm->header.ref_count = 1; // Caller owns initial reference"),_.emitLine(` GC_DEBUG("AsyncBlock ${t}: Created ptr=%p RC=1\\n", (void*)sm);`),u.needsCycleGC&&(_.emitLine(" sm->header.gc_flags = 0;"),_.emitLine(" sm->header.gc_mark = __YO_GC_UNMARKED;"),_.emitLine(" sm->header.gc_next = NULL;"),_.emitLine(" sm->header.gc_prev = NULL;")),u.needsCycleGC)_.emitLine(` sm->header.dispose_fn = (void(*)(void*))${i};`);else{u.disposeTypeIds||(u.disposeTypeIds=new Map,u.nextDisposeTypeId=1);let c=u.disposeTypeIds.get(i);c===void 0&&(c=u.nextDisposeTypeId,u.nextDisposeTypeId=c+1,u.disposeTypeIds.set(i,c)),_.emitLine(` sm->header.type_id = ${c};`)}u.needsCycleGC&&_.emitLine(" sm->header.traverse_fn = NULL; // TODO: Add traverse for cycle detection if needed"),_.emitLine(""),_.emitLine(" sm->state = 0;"),_.emitLine(" sm->continuation_fn = NULL;"),_.emitLine(" sm->continuation_sm = NULL;"),_.emitLine(""),l&&(_.emitLine(" // Initialize captured variables"),_.emitLine(" sm->__capture = __capture;"),_.emitLine("")),_.emitLine(" // Initialize result (will be set when async block completes)"),De(a)?_.emitLine(" // Result is unit type, no initialization needed"):_.emitLine(` memset(&sm->result, 0, sizeof(${s}));`),_.emitLine(""),_.emitLine(` sm->__yo_resume_fn = (void(*)(void*))${n};`),_.emitLine(""),_.emitLine(" return sm;"),_.emitLine("}"),_.emitLine("")}function _f(e){if(!e.deferredAsyncBlocks||e.deferredAsyncBlocks.length===0)return;let t=e.emitter;Qh(e),t.emitLine("// Deferred async block implementations");let n=0;for(;n<e.deferredAsyncBlocks.length;){let r=e.deferredAsyncBlocks[n],i=e.deferredAsyncBlocks.length,{bodyExpr:o,asyncBlockId:a,structName:s,resumeFunctionName:l,constructorName:u,disposeFunctionName:_,futureType:c,resultType:f,resultTypeCName:p,captureType:m,analysis:h}=r,y=e.stateMachineVariables,g=e.currentEvidenceParams,v=new Map,{crossBoundaryIds:T,awaitFutureTempVarAliases:$,variableSegments:C}=Il(o,h),{slotAliases:k}=Al(T,C,h.capturedVariables,$,e),b=h.capturedVariables.filter(x=>x.kind==="outer"||T.has(x.id)||$.has(x.id)||k.has(x.id)),w={...h,capturedVariables:b};for(let x of b)v.set(x.id,x);if(m)for(let x of m.fields)v.set(x.label,{id:x.label,name:x.label,type:x.type,kind:"outer",isOwningTheSameRcValueAs:void 0});e.stateMachineVariables=v;let A=e.stateMachineFieldAliases,L=new Map($);for(let[x,V]of k)L.set(x,V);e.stateMachineFieldAliases=L;let N=ef(o,a,s,l,w,c,m,e);if(e.stateMachineVariables=y,e.currentEvidenceParams=g,e.stateMachineFieldAliases=A,t.emitLine(""),Zh(a,s,_,f,m,w,N,T,$,e),t.emitLine(""),Jh(a,s,l,u,_,c,f,p,m,e),t.emitLine(""),e.deferredAsyncBlocks.length>i){let x=e.deferredAsyncBlocks.slice(i);for(let V of x){let{crossBoundaryIds:U,awaitFutureTempVarAliases:R,variableSegments:D}=Il(V.bodyExpr,V.analysis),{slotAliases:H,slots:B}=Al(U,D,V.analysis.capturedVariables,R,e);uf({asyncBlockId:V.asyncBlockId,structName:V.structName,resultType:V.resultType,resultTypeCName:V.resultTypeCName,captureType:V.captureType,analysis:V.analysis,crossBoundaryIds:U,awaitFutureTempVarAliases:R,overlappingSlotAliases:H,overlappingSlots:B},e)}}n++}}function cf(e){for(let t in e.functions){let{value:n}=e.functions[t];n.body&&ff(n.body,e)}}var ev=["__yo_poll_","__yo_fs_event_","__yo_async_"];function tv(e){return ev.some(t=>e.startsWith(t))}function ff(e,t){var n,r,i,o,a,s,l;if(e&&S(e)){let u=e;if(An(e)){t.usesAsync=!0;let _=(n=e.$)==null?void 0:n.type;if(_&&at(_)&&Ln(_)){let p=`${((r=e.$)==null?void 0:r.variableName)||`async_block_${Date.now()}`}_state_t`;e.$&&(e.$.asyncStateMachineStructName=p),t.types[_.id]={type:_,cName:p},t.emitter.emitDeclarationLine(`typedef struct ${p}_struct ${p}; // Forward declaration for async state machine`)}}if(An(e)){let _=(i=e.$)==null?void 0:i.type;if(_&&at(_)&&Ln(_)){let f=((o=e.$)==null?void 0:o.variableName)||`io_async_block_${Date.now()}`,p=!!((a=e.$)!=null&&a.awaitAnalysis),m=p?`${f}_state_t`:`${f}_sync_fut_t`;e.$&&(e.$.asyncStateMachineStructName=m),t.types[_.id]={type:_,cName:m},t.emitter.emitDeclarationLine(`typedef struct ${m}_struct ${m}; // Forward declaration for io.async ${p?"state machine":"sync future"}`)}}(_r(e)||dl(e))&&(t.usesAsync=!0);{let _=(s=u.func.$)==null?void 0:s.type;_&&"isExtern"in _&&_.isExtern==="yo"&&"externName"in _&&typeof _.externName=="string"&&tv(_.externName)&&(t.usesAsync=!0)}{let _=(l=u.func.$)==null?void 0:l.type;_&&"isExtern"in _&&_.isExtern==="yo"&&"externName"in _&&typeof _.externName=="string"&&(_.externName==="__yo_thread_spawn"||_.externName==="__yo_worker_spawn")&&(t.usesParallelism=!0)}for(let _ of u.args)ff(_,t)}}function pf(e,t,n){var b,w,A,L,N,x,V,U,R,D,H,B;let r=(b=e.$)==null?void 0:b.type;if(!r||!at(r))return"/* Error: io.async must return a Future type */";let i=Ln(r);if(!i)return"/* Error: Could not extract Future module type */";let o=i.isFuture.outputType;if(z(o))if(o.resolvedConcreteType)o=o.resolvedConcreteType;else{let G=(A=(w=e.$)==null?void 0:w.runtimeArgExprsInOrder)==null?void 0:A[0],Q=(L=G==null?void 0:G.$)==null?void 0:L.closureFunctionValue;if(Q&&ge(Q)){let Y=(x=(N=Q.type)==null?void 0:N.return)==null?void 0:x.type;if(Y&&z(Y)&&Y.resolvedConcreteType)o=Y.resolvedConcreteType;else if((U=(V=Q.body)==null?void 0:V.$)!=null&&U.type){let J=Q.body.$.type;z(J)&&J.resolvedConcreteType?o=J.resolvedConcreteType:z(J)||(o=J)}}}let a=j(o,n),s=(R=e.$)==null?void 0:R.asyncStateMachineStructName;if(!s)return"/* Error: Missing sync future struct name */";let l=`${s}_dispose`,u=`${s}_resume`,_=n.emitter,c=(H=(D=e.$)==null?void 0:D.runtimeArgExprsInOrder)==null?void 0:H[0];if(!(c!=null&&c.$))return"/* Error: Missing closure argument for io.async */";let f=q(c,t,n),p=c.$.type,m,h;if(z(p)&&p.resolvedConcreteType){let G=p.resolvedConcreteType,Q=n.implClosureCallMap.get(G.id);Q&&(m=Q.functionCName);let Y=n.types[G.id];Y&&(h=Y.cName)}if(!m||!h)return"/* Error: no closure function or capture type for io.async sync path */";_.emitDeclarationLine(`struct ${s}_struct {`),_.emitDeclarationLine(" __yo_ref_header_t header;"),_.emitDeclarationLine(" int state;"),De(o)?_.emitDeclarationLine(" uint8_t result;"):_.emitDeclarationLine(` ${a} result;`),_.emitDeclarationLine(" void (*continuation_fn)(void*);"),_.emitDeclarationLine(" void* continuation_sm;"),_.emitDeclarationLine(" void (*__yo_resume_fn)(void*);"),_.emitDeclarationLine(` ${h} __capture;`),_.emitDeclarationLine("};"),_.emitDeclarationLine("");let y="";for(let G in n.functions){let Q=n.functions[G];if(Q.cName===m){let Y=pn(Q.value.type);Y.length>0&&(y=", "+Y.map(J=>`(void*)sm->__capture.${J.fieldPath.join(".")}`).join(", "));break}}_.emitDeclarationLine(`void ${u}(void* ptr) {`),_.emitDeclarationLine(` ${s}* sm = (${s}*)ptr;`),De(o)?_.emitDeclarationLine(` ${m}(&sm->__capture${y});`):_.emitDeclarationLine(` sm->result = ${m}(&sm->__capture${y});`),y&&(_.emitDeclarationLine(" if (__yo_effect_escaped) {"),_.emitDeclarationLine(" __yo_effect_escaped = 0;"),_.emitDeclarationLine(" sm->state = -2;"),_.emitDeclarationLine(" __yo_decr_rc(ptr);"),_.emitDeclarationLine(" return;"),_.emitDeclarationLine(" }")),_.emitDeclarationLine(" sm->state = -1;"),_.emitDeclarationLine(" void (*continuation)(void*) = sm->continuation_fn;"),_.emitDeclarationLine(" if (continuation) {"),_.emitDeclarationLine(" void* cont_sm = sm->continuation_sm;"),_.emitDeclarationLine(" continuation(cont_sm);"),_.emitDeclarationLine(" }"),_.emitDeclarationLine(" __yo_decr_rc(ptr);"),_.emitDeclarationLine("}"),_.emitDeclarationLine("");let g=c.$.captureType,v=g&&it(g)?Wr(g,n):void 0,T=g&&it(g)?fr(g,n):void 0,$=Wr(o,n);_.emitDeclarationLine(`void ${l}(void* ptr) {`),(v||$)&&(_.emitDeclarationLine(` ${s}* sm = (${s}*)ptr;`),v&&(_.emitDeclarationLine(" // Drop captured variables (future owns its references)"),_.emitDeclarationLine(` ${v}(sm->__capture);`)),$&&(_.emitDeclarationLine(" if (sm->state == -1) {"),_.emitDeclarationLine(` ${$}(sm->result);`),_.emitDeclarationLine(" }"))),_.emitDeclarationLine("}"),_.emitDeclarationLine("");let C=((B=e.$)==null?void 0:B.variableName)||"__io_async_result",k=Kt(r,C,n);if(_.emitLine(`${t}${k} = (${s}*)__yo_malloc(sizeof(${s}));`),_.emitLine(`${t}memset(${C}, 0, sizeof(${s}));`),_.emitLine(`${t}${C}->header.ref_count = 1;`),n.needsCycleGC&&(_.emitLine(`${t}${C}->header.gc_flags = 0;`),_.emitLine(`${t}${C}->header.gc_mark = __YO_GC_UNMARKED;`),_.emitLine(`${t}${C}->header.gc_next = NULL;`),_.emitLine(`${t}${C}->header.gc_prev = NULL;`)),n.needsCycleGC)_.emitLine(`${t}${C}->header.dispose_fn = (void(*)(void*))${l};`);else{n.disposeTypeIds||(n.disposeTypeIds=new Map,n.nextDisposeTypeId=1);let G=n.disposeTypeIds.get(l);G===void 0&&(G=n.nextDisposeTypeId,n.nextDisposeTypeId=G+1,n.disposeTypeIds.set(l,G)),_.emitLine(`${t}${C}->header.type_id = ${G};`)}return n.needsCycleGC&&_.emitLine(`${t}${C}->header.traverse_fn = NULL;`),_.emitLine(`${t}${C}->__capture = ${f};`),T&&_.emitLine(`${t}${C}->__capture = ${T}(${C}->__capture);`),_.emitLine(`${t}${C}->state = 0;`),_.emitLine(`${t}${C}->__yo_resume_fn = ${u};`),_.emitLine(`${t}${C}->continuation_fn = NULL;`),_.emitLine(`${t}${C}->continuation_sm = NULL;`),C}function df(e,t){for(let i=0;i<e.fields.length;i++){let o=e.fields[i];ge(o)&&(xi(o.type,t),Ji(o.body,t))}if(t.moduleLevelInitExprs)for(let i of t.moduleLevelInitExprs)Ji(i,t);let n=new Set,r=!0;for(;r;){r=!1;for(let i in t.functions){if(n.has(i))continue;n.add(i),r=!0;let o=t.functions[i];if(xi(o.value.type,t),o.value.specializedType&&xi(o.value.specializedType,t),Ji(o.value.body,t),o.value.calledComptimeFunctionCaches)for(let a of o.value.calledComptimeFunctionCaches)a.value&&a.value.type&&Nn(a.value.type,t),Ji(a.body,t)}}}function xi(e,t){for(let n of e.parameters)Nn(n.type,t);for(let n of e.forallParameters)Nn(n.type,t);Nn(e.return.type,t)}function Ji(e,t){var n;if(e.$&&e.$.type&&Nn(e.$.type,t),e.$&&e.$.value&&ge(e.$.value)){let r=e.$.value;r.isControlFunction?(xi(r.type,t),In(r.body,t)):t.functions[r.funcId]||r.type.parameters.map(a=>a.type).some(a=>z(a)&&at(a)&&!a.resolvedConcreteType)||(t.functions[r.funcId]={value:r,cName:be(r.funcId)},xi(r.type,t),In(r.body,t))}if(e.$&&e.$.deferredDropExpressions&&e.$.deferredDropExpressions.length>0)for(let r of e.$.deferredDropExpressions)Ji(r,t);if(e.$&&e.$.macroExpansion&&Ji(e.$.macroExpansion,t),e.$&&e.$.runtimeDestructurings)for(let{type:r}of e.$.runtimeDestructurings)Nn(r,t);if(e.$&&e.$.captureType&&Ae(e.$.captureType)){let r=e.$.captureType;if(!t.types[r.id]){t.types[r.id]={type:r,cName:`__yo_${r.id}`};for(let i of r.fields)Nn(i.type,t);for(let i of r.trait.fields)if(i.assignedValue&&ge(i.assignedValue)){let o=i.assignedValue;t.functions[o.funcId]||(t.functions[o.funcId]={value:o,cName:o.funcId},xi(o.type,t),In(o.body,t))}}}switch(e.tag){case"FnCall":if(E(e,P.test))break;Ji(e.func,t);for(let r of e.args)Ji(r,t);break;case"Atom":(n=e.$)!=null&&n.value&&W(e.$.value)&&Nn(e.$.value.value,t);break}}function Nn(e,t){if(!t.types[e.id]){if(z(e)&&zn(e)){if(e.resolvedConcreteType){Nn(e.resolvedConcreteType,t);return}let n=Kn(e);n&&Nn(n,t);return}if(z(e)&&at(e)){let n=Ln(e);n&&Nn(n.isFuture.outputType,t);return}if(z(e)&&e.resolvedConcreteType){Nn(e.resolvedConcreteType,t);return}if(!Me(e)){if(Ae(e)||Bt(e)||Be(e)||ut(e)||st(e)||Xe(e)||ot(e)||$t(e)||hn(e)){let n=$t(e)?j(e,t):e.isExtern==="c"&&e.externName?e.externName:`__yo_${e.id}`;if(t.types[e.id]={type:e,cName:n},Ae(e))for(let r of e.fields)Nn(r.type,t);if(Be(e)){for(let r of e.variants)if(r.fields)for(let i of r.fields)Nn(i.type,t)}if(Bt(e))for(let r of e.fields)Nn(r.type,t);if(st(e)){let r=e;for(let i of r.requiredTraits)Nn(i.traitType,t)}if(hn(e)){let r=e;Nn(r.childType,t),j(r,t)}if($t(e)&&Nn(e.childType,t),Xe(e)||ot(e)){for(let r of e.fields)Nn(r.type,t);for(let r of e.fields)if(r.assignedValue&&ge(r.assignedValue)){let i=r.assignedValue,o=i.type;if(o.parameters.every(s=>s.isCompileTimeOnly)&&o.return.isCompileTimeOnly)continue;t.functions[i.funcId]||(t.functions[i.funcId]={value:i,cName:be(i.funcId)},xi(i.type,t),In(i.body,t))}else if(r.assignedValue&&(wt(r.assignedValue)||tn(r.assignedValue))){let i=r.assignedValue;ts(i,t,!1)}}}else if(Je(e)){let n=e,r=n.childType,i=n.length;if(ht(i)){Nn(r,t);let o=j(r,t),a=`Array_${be(o)}_${i.value}`;t.arrayStructTypes.has(a)||t.arrayStructTypes.set(a,{childType:o,length:typeof i.value=="bigint"?Number(i.value):i.value}),t.types[e.id]={type:e,cName:a}}}else if(je(e)){if(Nn(e.childType,t),$t(e.childType)){let r=e.childType.childType;Nn(r,t);let i=j(r,t),o=`Slice_${be(i)}`;t.sliceStructTypes.has(o)||t.sliceStructTypes.set(o,{childType:i})}t.types[e.id]={type:e,cName:j(e,t)}}else jc.has(e.tag)&&(t.types[e.id]={type:e,cName:j(e,t)});e.trait&&Nn(e.trait,t)}}}function Fo(e){var t,n,r;if(e.$&&e.$.value&&Ie(e.$.value)&&!(ne(e.$.type)&&e.$.type.isExtern)){if(!De(e.$.type))return!0}if(S(e)){if(Fo(e.func))return!0;for(let i of e.args)if(!((t=i.$)!=null&&t.type&&De(i.$.type))&&Fo(i))return!0}if(e.$&&e.$.macroExpansion){if(e.$.type&&De(e.$.type))return!1;if(Fo(e.$.macroExpansion))return!0}if((n=e.$)!=null&&n.deferredDupExpressions){for(let i of e.$.deferredDupExpressions)if(Fo(i))return!0}if((r=e.$)!=null&&r.deferredDropExpressions){for(let i of e.$.deferredDropExpressions)if(Fo(i))return!0}return!1}function ts(e,t,n=!0){for(let r=0;r<e.fields.length;r++){let i=e.fields[r],o=e.type.fields[r];if(ge(i)){let a=o.label;if(a==="main")t.functions[i.funcId]={value:i,cName:"__yo_user_main"};else if(t.isLibrary)if(n&&t.currentModuleId&&i.funcId.startsWith(`fn_${t.currentModuleId}_`)){let l=be(a);Object.values(t.functions).some(_=>_.cName===l)?t.functions[i.funcId]={value:i,cName:be(i.funcId)}:(t.functions[i.funcId]={value:i,cName:l},t.exportedFunctionLabels||(t.exportedFunctionLabels=new Map),t.exportedFunctionLabels.set(i.funcId,a))}else t.functions[i.funcId]={value:i,cName:be(i.funcId)};else if(n&&t.currentModuleId&&i.funcId.startsWith(`fn_${t.currentModuleId}_`)){let l=be(a);Object.values(t.functions).some(_=>_.cName===l)?t.functions[i.funcId]={value:i,cName:be(i.funcId)}:(t.functions[i.funcId]={value:i,cName:l},t.exportedFunctionLabels||(t.exportedFunctionLabels=new Map),t.exportedFunctionLabels.set(i.funcId,a))}else t.functions[i.funcId]={value:i,cName:be(i.funcId)};In(i.body,t)}}}function mf(e,t){for(let n=0;n<e.fields.length;n++){let r=e.fields[n];r&&ge(r)?t.functions[r.funcId]||(r.isModuleEffectMember=!0,t.functions[r.funcId]={value:r,cName:be(r.funcId)},In(r.body,t)):r&&wt(r)&&mf(r,t)}}function In(e,t){var i,o,a,s,l,u,_,c,f,p,m,h;if((i=e.$)!=null&&i.value&&wt(e.$.value)){let y=e.$.value;mf(y,t)}if(S(e)&&E(e,P.test)||S(e)&&E(e,F.comptime_expect_error))return;if(e.$&&e.$.macroExpansion&&In(e.$.macroExpansion,t),(o=e.$)!=null&&o.effectAnalysis){let y=e.$.effectAnalysis.handlerValue;y&&ge(y)&&In(y.body,t)}if(e.$&&e.$.closureFunctionValue){let y=e.$.closureFunctionValue;t.functions[y.funcId]||(t.functions[y.funcId]={value:y,cName:be(y.funcId)},In(y.body,t))}if((a=e.$)!=null&&a.indexMethodValue&&ge(e.$.indexMethodValue)){let y=e.$.indexMethodValue;t.functions[y.funcId]||(t.functions[y.funcId]={value:y,cName:be(y.funcId)},In(y.body,t))}if(S(e)&&e.$&&e.$.dynCallTraitValues&&e.$.dynCallTraitValues.length>0){let y=e.$.type,g=e.args[0];if(st(y)&&g&&((s=g.$)!=null&&s.type)){let v=g.$.type,T=e.$.dynCallTraitValues;if(T.length>0&&(en(v)||vr(v))){let $=vr(v)?v.fields[0].type:v,C=`${$.id}_${y.id}`;t.dynImpls.set(C,{dynType:y,concreteType:$,dataType:v,traitValues:T})}}}if(S(e)){let y=(l=e.func.$)==null?void 0:l.type,g=(u=e.func.$)==null?void 0:u.value;if(e.func.token.value==="?=")return;if(ne(y)){if(ge(g)&&g.isControlFunction){In(g.body,t);for(let v of e.args)In(v,t);return}if(ge(g)){if(g.type.return.isCompileTimeOnly||ru(g)&&!g.specializedType)return;if(g.specializedType&&li(g.specializedType)&&pn(g.specializedType).length===0){In(e.func,t);for(let T of e.args)In(T,t);return}if(!t.functions[g.funcId]){let v=!1;if(Fo(g.body)){let T=g.specializedType??g.type;if(v=T.implicitParameters.length>0&&(pn(T).length>0||!li(g.type)&&g.type.implicitParameters.length>0),!v)return}if(!v&&!(pn(g.specializedType??g.type).length>0)&&(g.specializedType??g.type).parameters.map(k=>k.type).some(k=>z(k)&&at(k)&&!k.resolvedConcreteType))return;t.functions[g.funcId]={value:g,cName:be(g.funcId)},In(g.body,t)}}else if(y.isExtern==="c"){let v=y.externName?y.externName:K(e.func)?e.func.token.value:y.id;t.externFunctions[y.id]={type:y,cName:v}}else if(y.isExtern==="yo"){let v=y.externName;if(!(v&&v.startsWith("__yo_"))){let T=v?be(v):K(e.func)?be(e.func.token.value):be(y.id);t.externFunctions[y.id]={type:y,cName:T}}}}In(e.func,t);for(let v of e.args)In(v,t)}let n=(_=e.$)==null?void 0:_.type,r=(c=e.$)==null?void 0:c.value;if(ne(n)){if(ge(r)&&r.isControlFunction){if(r.isModuleEffectMember=!0,t.functions[r.funcId]||(t.functions[r.funcId]={value:r,cName:be(r.funcId)}),r.specializedFunctionCaches)for(let y of r.specializedFunctionCaches){let g=y.specializedFunction;g&&!t.functions[g.funcId]&&(g.isModuleEffectMember=!0,t.functions[g.funcId]={value:g,cName:be(g.funcId)},In(g.body,t))}In(r.body,t);return}if(ge(r)){if(ru(r)&&!r.specializedFunctionCaches||t.functions[r.funcId])return;if(Fo(r.body))return;t.functions[r.funcId]={value:r,cName:be(r.funcId)},In(r.body,t)}}if(W((f=e.$)==null?void 0:f.value)&&Nn(e.$.value.value,t),(p=e.$)!=null&&p.deferredDupExpressions)for(let y of e.$.deferredDupExpressions)In(y,t);if((m=e.$)!=null&&m.deferredDropExpressions)for(let y of e.$.deferredDropExpressions)In(y,t);if((h=e.$)!=null&&h.dynCallTraitValues)for(let y of e.$.dynCallTraitValues)ts(y,t,!1)}function yf(e){let t=F.dispose[0];for(let n in e.types){let{type:r}=e.types[n];if(!Ae(r)||!r.isReferenceSemantics)continue;let i=Dr({concreteType:r,methodName:t,env:r.env});for(let o of i)if(o.value&&ge(o.value)){let a=o.value;if(e.functions[a.funcId])continue;a.funcName||(a.funcName=t),e.functions[a.funcId]={value:a,cName:be(a.funcId)},xi(a.type,e),In(a.body,e)}}}function gf(e){var r;let t=e.emitter,n=new Set;for(let[,i]of e.dynImpls){let o=((r=e.types[i.dynType.id])==null?void 0:r.cName)||`__yo_dyn_${i.dynType.id}`;n.has(o)||(n.add(o),t.emitLine(`${o} __yo_dup_${o}(${o} dyn) {`),t.emitLine(" if (dyn.data) {"),t.emitLine(" __yo_incr_rc(dyn.data);"),t.emitLine(" }"),t.emitLine(" return dyn;"),t.emitLine("}"),t.emitLine(""),t.emitLine(`void __yo_drop_${o}(${o} dyn) {`),t.emitLine(" if (dyn.data) {"),t.emitLine(" __yo_decr_rc(dyn.data);"),t.emitLine(" }"),t.emitLine("}"),t.emitLine(""))}}function hf(e){var r,i,o;let t=e.emitter;if(e.dynImpls.size===0)return;t.emitLine(""),t.emitLine("// === Dyn Box Functions ==="),t.emitLine("// Constructor and dispose functions for dyn boxes"),t.emitLine("");let n=new Set;for(let[,a]of e.dynImpls){let s=z(a.concreteType)&&a.concreteType.resolvedConcreteType?a.concreteType.resolvedConcreteType:a.concreteType,u=`__yo_dyn_box_${((r=e.types[s.id])==null?void 0:r.cName)||`unknown_${s.id}`}`;if(n.has(u))continue;n.add(u);let _=j(s,e);t.emitLine(`static ${u}* __yo_new_${u}(${_} value) {`),t.emitLine(` ${u}* box = (${u}*)__yo_malloc(sizeof(${u}));`),t.emitLine(" box->header.ref_count = 1;"),e.needsCycleGC&&(t.emitLine(" box->header.gc_flags = 0;"),t.emitLine(" box->header.gc_mark = __YO_GC_UNMARKED;"),t.emitLine(" box->header.gc_next = NULL;"),t.emitLine(" box->header.gc_prev = NULL;"));let c=`__yo_dispose_${u}`;if(e.needsCycleGC)t.emitLine(` box->header.dispose_fn = ${c};`);else{e.disposeTypeIds||(e.disposeTypeIds=new Map,e.nextDisposeTypeId=1);let m=e.disposeTypeIds.get(c);m===void 0&&(m=e.nextDisposeTypeId,e.nextDisposeTypeId=m+1,e.disposeTypeIds.set(c,m)),t.emitLine(` box->header.type_id = ${m};`)}e.needsCycleGC&&t.emitLine(" box->header.traverse_fn = NULL; // TODO: Set if value contains GC types"),t.emitLine(" box->value = value;"),t.emitLine(" return box;"),t.emitLine("}"),t.emitLine(""),t.emitLine(`static void __yo_dispose_${u}(void* ptr) {`),t.emitLine(` ${u}* box = (${u}*)ptr;`);let p=(i=(z(a.concreteType)&&a.concreteType.resolvedConcreteType?a.concreteType.resolvedConcreteType:a.concreteType).trait)==null?void 0:i.fields.find(m=>m.label===F.___drop[0]);if(p&&p.assignedValue&&ge(p.assignedValue)){let m=(o=e.functions[p.assignedValue.funcId])==null?void 0:o.cName;m&&t.emitLine(` ${m}(box->value);`)}t.emitLine("}"),t.emitLine("")}}function vf(e){var n,r,i,o;let t=e.emitter;if(e.dynImpls.size!==0){t.emitDeclarationLine(""),t.emitDeclarationLine("// === Dyn Wrapper Functions ==="),t.emitDeclarationLine("// Wrappers that unwrap boxed values and call impl methods"),t.emitDeclarationLine("");for(let[a,s]of e.dynImpls){let l=s.dataType,u=new Set([F.___dup[0],F.___drop[0],F.___dispose[0],F.dispose[0]]);for(let{traitType:_}of s.dynType.requiredTraits){if(!gn(_))continue;let c=_.isFn.callType,f=j(c.return.type,e),p=`__yo_wrap_${a}_call`,m=["void* self_ptr"];for(let h=0;h<c.parameters.length;h++){let y=c.parameters[h],g=j(y.type,e);m.push(`${g} arg${h+1}`)}if(t.emitDeclarationLine(`static ${f} ${p}(${m.join(", ")}) {`),vr(l)){let h=((n=e.types[l.id])==null?void 0:n.cName)||`unknown_${l.id}`,y=be(l.fields[0].label);t.emitDeclarationLine(` ${h}* box = (${h}*)self_ptr;`);let g=l.fields[0].type,v=z(g)&&g.resolvedConcreteType?g.resolvedConcreteType:g,T=e.implClosureCallMap.get(v.id),$=(()=>{var k;if(T)return T.functionCName;for(let[,b]of Object.entries(e.functions)){let A=b.value.closureInfo;if(((k=A==null?void 0:A.captureType)==null?void 0:k.id)===v.id)return b.cName}})(),C=[];if($){C.push(`(void*)&box->${y}`);for(let k=0;k<c.parameters.length;k++)C.push(`arg${k+1}`);bi(c.return.type)?t.emitDeclarationLine(` ${$}(${C.join(", ")});`):t.emitDeclarationLine(` return ${$}(${C.join(", ")});`)}else{C.push(`box->${y}.data`);for(let k=0;k<c.parameters.length;k++)C.push(`arg${k+1}`);bi(c.return.type)?t.emitDeclarationLine(` box->${y}.call(${C.join(", ")});`):t.emitDeclarationLine(` return box->${y}.call(${C.join(", ")});`)}}else{t.emitDeclarationLine(" (void)self_ptr; /* Dyn(Fn): expected Box(...) data */");for(let h=0;h<c.parameters.length;h++)t.emitDeclarationLine(` (void)arg${h+1};`);bi(c.return.type)?t.emitDeclarationLine(" return;"):(t.emitDeclarationLine(` ${f} zero = (${f})0;`),t.emitDeclarationLine(" return zero;"))}t.emitDeclarationLine("}"),t.emitDeclarationLine("")}for(let _=0;_<s.dynType.requiredTraits.length;_++){let{traitType:c}=s.dynType.requiredTraits[_];if(gn(c))continue;let f=s.traitValues[_];if(!f){t.emitDeclarationLine(`/* Warning: Module value missing for module ${_} */`);continue}let m=f.type.fields;for(let h=0;h<m.length;h++){let y=m[h];if(y.label==="Self"||u.has(y.label))continue;let g=f.fields[h];if(!g||!ge(g)){t.emitDeclarationLine(`/* Warning: Module field ${y.label} is not a function value */`);continue}let v=y.type;if(!ne(v)){t.emitDeclarationLine(`/* Warning: Module field ${y.label} is not a function type */`);continue}let T=g.funcId,$=(r=e.functions[T])==null?void 0:r.cName;if(!$){t.emitDeclarationLine(`/* Warning: Impl function for ${y.label} not found */`);continue}let C=`__yo_wrap_${a}_${y.label}`,k=j(v.return.type,e),b=["void* self_ptr"];for(let N=1;N<v.parameters.length;N++){let x=v.parameters[N],V=j(x.type,e);b.push(`${V} arg${N}`)}t.emitDeclarationLine(`static ${k} ${C}(${b.join(", ")}) {`);let w=(i=v.parameters[0])==null?void 0:i.type,A;if(vr(l)){let N=((o=e.types[l.id])==null?void 0:o.cName)||`unknown_${l.id}`,x=be(l.fields[0].label);t.emitDeclarationLine(` ${N}* box = (${N}*)self_ptr;`),w&&je(w)?A=`&box->${x}`:A=`box->${x}`}else{let N=j(s.concreteType,e);t.emitDeclarationLine(` ${N} concrete_value = (${N})self_ptr;`),w&&je(w)?A="&concrete_value":A="concrete_value"}let L=[A];for(let N=1;N<v.parameters.length;N++)L.push(`arg${N}`);bi(v.return.type)?t.emitDeclarationLine(` ${$}(${L.join(", ")});`):t.emitDeclarationLine(` return ${$}(${L.join(", ")});`),t.emitDeclarationLine("}"),t.emitDeclarationLine("")}}}}}function Tf(e){var r,i,o;let t=e.emitter;if(e.dynImpls.size===0)return;t.emitDeclarationLine(""),t.emitDeclarationLine("// === Dyn TypeId Statics ==="),t.emitDeclarationLine("// Unique static per concrete type \u2014 address is the runtime TypeId"),t.emitDeclarationLine("");let n=new Set;e.typeIdStatics||(e.typeIdStatics=new Map);for(let[,a]of e.dynImpls){let s=z(a.concreteType)&&a.concreteType.resolvedConcreteType?a.concreteType.resolvedConcreteType:a.concreteType,l=((r=e.types[s.id])==null?void 0:r.cName)||`unknown_${s.id}`,u=`__yo_typeid_${l}`;!n.has(u)&&!e.typeIdStatics.has(s.id)&&(n.add(u),e.typeIdStatics.set(s.id,u),t.emitDeclarationLine(`static const char ${u} = 0; // TypeId for ${l}`))}t.emitDeclarationLine(""),t.emitDeclarationLine("// === Dyn Static Vtables ==="),t.emitDeclarationLine("// Static vtables for dynamic dispatch"),t.emitDeclarationLine("");for(let[a,s]of e.dynImpls){let l=((i=e.types[s.dynType.id])==null?void 0:i.cName)||`__yo_dyn_${s.dynType.id}`,u=z(s.concreteType)&&s.concreteType.resolvedConcreteType?s.concreteType.resolvedConcreteType:s.concreteType,_=((o=e.types[u.id])==null?void 0:o.cName)||`unknown_${u.id}`,c=`__yo_vtable_${a}`,f=`${l}_vtable`,p=`__yo_typeid_${_}`;t.emitDeclarationLine(`// Vtable for impl(${_}, ${s.dynType.requiredTraits.map(({traitType:y})=>y.typeName||"?").join(" + ")})`),t.emitDeclarationLine(`static const ${f} ${c} = {`),t.emitDeclarationLine(` .__yo_type_id = (uintptr_t)&${p},`);let m=new Set,h=new Set([F.___dup[0],F.___drop[0],F.___dispose[0],F.dispose[0]]);for(let{traitType:y}of s.dynType.requiredTraits){if(gn(y)){let g=`__yo_wrap_${a}_call`;t.emitDeclarationLine(` .call = ${g},`),m.add("call");continue}for(let g of y.fields)if(g.label!=="Self"&&!h.has(g.label)&&!m.has(g.label)&&(m.add(g.label),ne(g.type))){let v=g.type;if(v.parameters.length>0){let T=v.parameters[0];if(T&&T.label==="self"){let $=`__yo_wrap_${a}_${g.label}`;t.emitDeclarationLine(` .${be(g.label)} = ${$},`)}}}}t.emitDeclarationLine("};"),t.emitDeclarationLine("")}}function Ef(e,t){let r=Sn(t)?"__declspec(thread)":"_Thread_local";e.emitLine(`
|
|
197
197
|
// ============================================================================
|
|
198
198
|
// Async/Await Runtime - Per-Thread Cooperative Scheduler
|
|
199
199
|
// ============================================================================
|
|
@@ -10855,7 +10855,7 @@ ${o} __yo_iso_extract_${r}(${r} iso) {
|
|
|
10855
10855
|
result.data.Some.value = iso->value;
|
|
10856
10856
|
}
|
|
10857
10857
|
return result;
|
|
10858
|
-
}`)}i.extractGenerated=!0}}}}function sv(e,t,n){let r=n.emitter;if(e.isNewtype&&e.fields.length===1){let i=e.fields[0].type,o=j(i,n);r.emitDeclarationLine(`typedef ${o} ${t}; // ${e.typeName} : ${M(e)} (newtype - zero-cost abstraction)`),r.emitDeclarationLine("");return}if(e.isReferenceSemantics){let i=e.isAtomicRc?" atomic":"";r.emitDeclarationLine(`struct ${t}_struct { // ${e.typeName} : ${M(e)} (${i?"atomic ":""}reference counted)`),r.emitDeclarationLine(` __yo_ref_header_t header; // ${i?"Atomic r":"R"}eference count header`);for(let o of e.fields){let a=j(o.type,n),s=be(o.label);r.emitDeclarationLine(` ${a} ${s};`)}r.emitDeclarationLine("};")}else{r.emitDeclarationLine(`struct ${t}_struct { // ${e.typeName} : ${M(e)}`);for(let i of e.fields){let o=j(i.type,n),a=be(i.label);r.emitDeclarationLine(` ${o} ${a};`)}r.emitDeclarationLine("};")}r.emitDeclarationLine("")}function lv(e,t,n){let r=n.emitter;if(r.emitDeclarationLine(`typedef struct { // ${e.typeName} : ${M(e)}`),e.fields.length===0)r.emitDeclarationLine(" uint8_t _dummy; // zero-sized type marker");else for(let i=0;i<e.fields.length;i++){let o=e.fields[i],a=j(o.type,n),s=`_${i}`;r.emitDeclarationLine(` ${a} ${s};`)}r.emitDeclarationLine(`} ${t};`),r.emitDeclarationLine("")}function uv(e,t,n){let r=n.emitter;r.emitDeclarationLine(`typedef union { // ${e.typeName} : ${M(e)}`);for(let i of e.fields){let o=j(i.type,n),a=be(i.label);r.emitDeclarationLine(` ${o} ${a};`)}r.emitDeclarationLine(`} ${t};`),r.emitDeclarationLine("")}function Uu(e,t,n){let r=n.emitter,i=Gn(e);if(i){let l=j(i,n);r.emitDeclarationLine(`typedef ${l} ${t}; // ${e.typeName} : ${M(e)} (optimized as nullable pointer)`),r.emitDeclarationLine("");return}if(Fr(e)){r.emitDeclarationLine(`typedef enum { // ${e.typeName} : ${M(e)} (optimized as simple enum)`);for(let l=0;l<e.variants.length;l++){let u=e.variants[l];if(u){let _=Rn(e,u.name,n),c=l<e.variants.length-1?",":"",f=u.discriminant??BigInt(l);r.emitDeclarationLine(` ${_} = ${f}${c}`)}}r.emitDeclarationLine(`} ${t};`),r.emitDeclarationLine("");return}let a=`${t}_tag`;r.emitDeclarationLine("typedef enum {");for(let l=0;l<e.variants.length;l++){let u=e.variants[l];if(u){let _=Rn(e,u.name,n),c=l<e.variants.length-1?",":"",f=u.discriminant??BigInt(l);r.emitDeclarationLine(` ${_} = ${f}${c}`)}}r.emitDeclarationLine(`} ${a};`),r.emitDeclarationLine("");let s=`${t}_data`;r.emitDeclarationLine("typedef union {");for(let l of e.variants)if(l.fields&&l.fields.length>0){let u=l.fields.filter(_=>!De(_.type));if(u.length>0){let _=l.name;r.emitDeclarationLine(" struct {");for(let c of u){let f=j(c.type,n),p=be(c.label);r.emitDeclarationLine(` ${f} ${p};`)}r.emitDeclarationLine(` } ${_};`)}}r.emitDeclarationLine(`} ${s};`),r.emitDeclarationLine(""),r.emitDeclarationLine(`struct ${t}_struct { // ${e.typeName} : ${M(e)}`),r.emitDeclarationLine(` ${a} tag;`),r.emitDeclarationLine(` ${s} data;`),r.emitDeclarationLine("};"),r.emitDeclarationLine("")}function _v(e,t){let n=Ir(t,"Dispose");if(!n)return;let r={...n,receiverType:e};if(e.trait)for(let o of e.trait.fields){if(!o.assignedValue||!tn(o.assignedValue))continue;let a=o.assignedValue,s=a.type;if(le({type:r,env:t},{type:s,env:t}))return a}let i=$l({concreteType:e,traitType:n,env:t});if(i)return i.traitValue}function cv(e,t,n){var s;let r=_v(e,t);if(!r)return;let i=r.type.fields.findIndex(l=>l.label===F.dispose[0]);if(i<0)return;let o=r.fields[i];if(!
|
|
10858
|
+
}`)}i.extractGenerated=!0}}}}function sv(e,t,n){let r=n.emitter;if(e.isNewtype&&e.fields.length===1){let i=e.fields[0].type,o=j(i,n);r.emitDeclarationLine(`typedef ${o} ${t}; // ${e.typeName} : ${M(e)} (newtype - zero-cost abstraction)`),r.emitDeclarationLine("");return}if(e.isReferenceSemantics){let i=e.isAtomicRc?" atomic":"";r.emitDeclarationLine(`struct ${t}_struct { // ${e.typeName} : ${M(e)} (${i?"atomic ":""}reference counted)`),r.emitDeclarationLine(` __yo_ref_header_t header; // ${i?"Atomic r":"R"}eference count header`);for(let o of e.fields){let a=j(o.type,n),s=be(o.label);r.emitDeclarationLine(` ${a} ${s};`)}r.emitDeclarationLine("};")}else{r.emitDeclarationLine(`struct ${t}_struct { // ${e.typeName} : ${M(e)}`);for(let i of e.fields){let o=j(i.type,n),a=be(i.label);r.emitDeclarationLine(` ${o} ${a};`)}r.emitDeclarationLine("};")}r.emitDeclarationLine("")}function lv(e,t,n){let r=n.emitter;if(r.emitDeclarationLine(`typedef struct { // ${e.typeName} : ${M(e)}`),e.fields.length===0)r.emitDeclarationLine(" uint8_t _dummy; // zero-sized type marker");else for(let i=0;i<e.fields.length;i++){let o=e.fields[i],a=j(o.type,n),s=`_${i}`;r.emitDeclarationLine(` ${a} ${s};`)}r.emitDeclarationLine(`} ${t};`),r.emitDeclarationLine("")}function uv(e,t,n){let r=n.emitter;r.emitDeclarationLine(`typedef union { // ${e.typeName} : ${M(e)}`);for(let i of e.fields){let o=j(i.type,n),a=be(i.label);r.emitDeclarationLine(` ${o} ${a};`)}r.emitDeclarationLine(`} ${t};`),r.emitDeclarationLine("")}function Uu(e,t,n){let r=n.emitter,i=Gn(e);if(i){let l=j(i,n);r.emitDeclarationLine(`typedef ${l} ${t}; // ${e.typeName} : ${M(e)} (optimized as nullable pointer)`),r.emitDeclarationLine("");return}if(Fr(e)){r.emitDeclarationLine(`typedef enum { // ${e.typeName} : ${M(e)} (optimized as simple enum)`);for(let l=0;l<e.variants.length;l++){let u=e.variants[l];if(u){let _=Rn(e,u.name,n),c=l<e.variants.length-1?",":"",f=u.discriminant??BigInt(l);r.emitDeclarationLine(` ${_} = ${f}${c}`)}}r.emitDeclarationLine(`} ${t};`),r.emitDeclarationLine("");return}let a=`${t}_tag`;r.emitDeclarationLine("typedef enum {");for(let l=0;l<e.variants.length;l++){let u=e.variants[l];if(u){let _=Rn(e,u.name,n),c=l<e.variants.length-1?",":"",f=u.discriminant??BigInt(l);r.emitDeclarationLine(` ${_} = ${f}${c}`)}}r.emitDeclarationLine(`} ${a};`),r.emitDeclarationLine("");let s=`${t}_data`;r.emitDeclarationLine("typedef union {");for(let l of e.variants)if(l.fields&&l.fields.length>0){let u=l.fields.filter(_=>!De(_.type));if(u.length>0){let _=l.name;r.emitDeclarationLine(" struct {");for(let c of u){let f=j(c.type,n),p=be(c.label);r.emitDeclarationLine(` ${f} ${p};`)}r.emitDeclarationLine(` } ${_};`)}}r.emitDeclarationLine(`} ${s};`),r.emitDeclarationLine(""),r.emitDeclarationLine(`struct ${t}_struct { // ${e.typeName} : ${M(e)}`),r.emitDeclarationLine(` ${a} tag;`),r.emitDeclarationLine(` ${s} data;`),r.emitDeclarationLine("};"),r.emitDeclarationLine("")}function _v(e,t){let n=Ir(t,"Dispose");if(!n)return;let r={...n,receiverType:e};if(e.trait)for(let o of e.trait.fields){if(!o.assignedValue||!tn(o.assignedValue))continue;let a=o.assignedValue,s=a.type;if(le({type:r,env:t},{type:s,env:t}))return a}let i=$l({concreteType:e,traitType:n,env:t});if(i)return i.traitValue}function cv(e,t,n){var s;let r=_v(e,t);if(!r)return;let i=r.type.fields.findIndex(l=>l.label===F.dispose[0]);if(i<0)return;let o=r.fields[i];if(!ge(o))return;let a=(s=n.functions[o.funcId])==null?void 0:s.cName;if(a){let l=o.specializedType??o.type;return{cName:a,selfType:l.SelfType}}for(let l in n.functions){let u=n.functions[l],_=u.value,c=_.specializedType??_.type;if(_.funcName===F.dispose[0]&&c.SelfType&&le({type:c.SelfType,env:t},{type:e,env:t}))return{cName:u.cName,selfType:c.SelfType}}}function Of(e){var t,n,r,i,o,a,s,l;e.emitter.emitLine("// Function implementations"),Af(e.emitter,e.targetInfo),e.usesAsync&&Nf(e.emitter,e.targetInfo,e.debugAsyncAwait,{needsCycleGC:e.needsCycleGC??!1,registerDisposeTypeId:u=>{e.disposeTypeIds||(e.disposeTypeIds=new Map,e.nextDisposeTypeId=1);let _=e.disposeTypeIds.get(u);return _===void 0&&(_=e.nextDisposeTypeId,e.nextDisposeTypeId=_+1,e.disposeTypeIds.set(u,_)),_}}),e.usesParallelism&&Df(e.emitter,e.debugParallelism,e.targetInfo,e.usesAsync??!1),pv(e),gv(e);for(let u in e.functions){let{value:_,cName:c}=e.functions[u],f=c==="__yo_user_main",p=(n=(t=_.body)==null?void 0:t.$)==null?void 0:n.effectAnalysis,m=p&&p.hasEffects;if(!f&&!_.type.isClosure&&((r=_.specializedFunctionCaches)==null?void 0:r.length)>0||!f&&!m&&!_.isModuleEffectMember&&!_.type.isClosure&&!_.specializedType&&(((i=_.specializedFunctionCaches)==null?void 0:i.length)??0)===0&&pn(_.specializedType??_.type).length===0&&[..._.type.implicitParameters,..._.type.parameters.filter(A=>A.isImplicit)].some(A=>ne(A.type)))continue;let y=_.specializedType&&!Rr(_.type),g=_.specializedType??_.type,v=pn(g).length>0,T=_.type.parameters.some(A=>A.isCompileTimeOnly);if(!f&&(!_.isModuleEffectMember||T)&&!_.specializedType&&(((o=_.specializedFunctionCaches)==null?void 0:o.length)??0)===0&&(li(_.type)||Qi(_))||!f&&_.isIoAsyncStateMachineClosure||!f&&!m&&!v&&!_.isModuleEffectMember&&(li(_.type)&&!_.type.isClosure||((a=_.specializedFunctionCaches)==null?void 0:a.length)>0&&!_.type.isClosure||_.specializedType&&!y||Qi(_)||gi(_)||_.isIoAsyncStateMachineClosure))continue;let $=_.specializedType??_.type,C=!m&&!_.isModuleEffectMember&&($.parameters.some(A=>Me(A.type))||$.forallParameters.length>0),k=Me($.return.type),b=z($.return.type)&&$.return.type.requiredTraits.length>0;if(C||k&&!b&&!_.isModuleEffectMember)continue;let w=(l=(s=_.body)==null?void 0:s.$)==null?void 0:l.effectAnalysis;w&&w.hasEffects,Bf(_,c,e)}zu(e)}function Rf(e){var r,i,o,a;let t=e.emitter,n=[];if(!e.moduleLevelInitExprs||e.moduleLevelInitExprs.length===0)return n;for(let s of e.moduleLevelInitExprs){if(!S(s)||s.args.length<2)continue;let l=s.args[0],u=s.args[1],_;if(K(l)&&((r=l.$)!=null&&r.type))_=l;else if(S(l)&&E(l,":",2)){let m=l.args[0];K(m)&&((i=m.$)!=null&&i.type)&&(_=m)}if(!_||!((o=_.$)!=null&&o.type))continue;let c=((a=_.$)==null?void 0:a.variableName)??_.token.value,f=We(c,_.$.env),p=j(_.$.type,e);t.emitDeclarationLine(`static ${p} ${f}; // module-level mutable variable`),n.push({cVarName:f,cTypeStr:p,rhs:u})}return n}function Pf(e,t){if(t.length===0)return;let n=e.emitter;n.emitLine(`
|
|
10859
10859
|
// Library initialization - call before using library functions
|
|
10860
10860
|
void __yo_module_init(void) {`),n.emitLine(" // Initialize module-level mutable variables");for(let{cVarName:r,rhs:i}of t){let o=q(i," ",e);n.emitLine(` ${r} = ${o};`)}n.emitLine(`}
|
|
10861
10861
|
`)}function Uf(e){var a,s,l,u;let t=e.emitter,n=!1,r=null;for(let _ in e.functions){let{cName:c,value:f}=e.functions[_];if(c==="__yo_user_main"){n=!0,r=f;break}}if(!n||!r)return;let i=r.type.return.type;if(!De(i))throw new Error(`main function must return unit , but it returns ${M(i)}. Use 'main :: (fn() -> unit)' instead. For exit codes, use 'exit(code)' from std/libc/stdlib.yo`);{let c=pn(r.type).map(()=>"NULL").join(", "),f=c?`(${c})`:"()",p=e.usesAsync?`
|
|
@@ -11364,7 +11364,7 @@ static void __yo_init_process_cleanup(void) {
|
|
|
11364
11364
|
if (cleanup_initialized) return;
|
|
11365
11365
|
cleanup_initialized = true;
|
|
11366
11366
|
atexit(__yo_process_cleanup);
|
|
11367
|
-
}`}`)}function yv(e){let t=e.emitter;for(let n in e.types){let{type:r,cName:i}=e.types[n];if(Ae(r)&&r.isReferenceSemantics){if(r.isAtomicRc||r.fields.some(s=>Me(s.type)))continue;let a=`__yo_traverse_${i}`;t.emitLine(`static void ${a}(void* ptr, void (*visit)(void*)) {`),t.emitLine(` ${i}* obj = (${i}*)ptr;`);for(let s of r.fields){let l=be(s.label),u=s.type;if(Ae(u)&&u.isReferenceSemantics)t.emitLine(` if (obj->${l}) {`),t.emitLine(` visit(obj->${l});`),t.emitLine(" }");else if(Be(u)){let _=u;if(!Gn(_)){if(!Fr(_)){t.emitLine(` switch (obj->${l}.tag) {`);for(let f of _.variants||[])if(f.fields&&f.fields.length>0){let p=f.fields.filter(m=>Ae(m.type)&&m.type.isReferenceSemantics);if(p.length>0){let m=Rn(_,f.name,e);t.emitLine(` case ${m}:`);for(let h of p)t.emitLine(` if (obj->${l}.data.${f.name}.${be(h.label)}) {`),t.emitLine(` visit(obj->${l}.data.${f.name}.${be(h.label)});`),t.emitLine(" }");t.emitLine(" break;")}}t.emitLine(" }")}}}}t.emitLine("}"),t.emitLine("")}}}function gv(e){var n;let t=e.emitter;e.needsCycleGC&&yv(e);for(let r in e.types){let{type:i,cName:o}=e.types[r];if(Ae(i)&&i.isReferenceSemantics){if(i.fields.some(_=>Me(_.type)))continue;let s=`__yo_new_${o}`,l=i.fields.map(_=>{let c=j(_.type,e),f=be(_.label);return`${c} ${f}`}).join(", ");t.emitLine(`static ${o}* ${s}(${l}) {`),t.emitLine(` ${o}* obj = (${o}*)__yo_malloc(sizeof(${o}));`),t.emitLine(" obj->header.ref_count = 1; // Start with one reference"),e.needsCycleGC&&!i.isAtomicRc&&(t.emitLine(" obj->header.gc_flags = 0;"),t.emitLine(" obj->header.gc_mark = __YO_GC_UNMARKED;"),t.emitLine(" obj->header.gc_next = NULL;"),t.emitLine(" obj->header.gc_prev = NULL;"));let u=i.trait.fields.find(_=>_.label===F.___dispose[0]&&_.assignedValue&&
|
|
11367
|
+
}`}`)}function yv(e){let t=e.emitter;for(let n in e.types){let{type:r,cName:i}=e.types[n];if(Ae(r)&&r.isReferenceSemantics){if(r.isAtomicRc||r.fields.some(s=>Me(s.type)))continue;let a=`__yo_traverse_${i}`;t.emitLine(`static void ${a}(void* ptr, void (*visit)(void*)) {`),t.emitLine(` ${i}* obj = (${i}*)ptr;`);for(let s of r.fields){let l=be(s.label),u=s.type;if(Ae(u)&&u.isReferenceSemantics)t.emitLine(` if (obj->${l}) {`),t.emitLine(` visit(obj->${l});`),t.emitLine(" }");else if(Be(u)){let _=u;if(!Gn(_)){if(!Fr(_)){t.emitLine(` switch (obj->${l}.tag) {`);for(let f of _.variants||[])if(f.fields&&f.fields.length>0){let p=f.fields.filter(m=>Ae(m.type)&&m.type.isReferenceSemantics);if(p.length>0){let m=Rn(_,f.name,e);t.emitLine(` case ${m}:`);for(let h of p)t.emitLine(` if (obj->${l}.data.${f.name}.${be(h.label)}) {`),t.emitLine(` visit(obj->${l}.data.${f.name}.${be(h.label)});`),t.emitLine(" }");t.emitLine(" break;")}}t.emitLine(" }")}}}}t.emitLine("}"),t.emitLine("")}}}function gv(e){var n;let t=e.emitter;e.needsCycleGC&&yv(e);for(let r in e.types){let{type:i,cName:o}=e.types[r];if(Ae(i)&&i.isReferenceSemantics){if(i.fields.some(_=>Me(_.type)))continue;let s=`__yo_new_${o}`,l=i.fields.map(_=>{let c=j(_.type,e),f=be(_.label);return`${c} ${f}`}).join(", ");t.emitLine(`static ${o}* ${s}(${l}) {`),t.emitLine(` ${o}* obj = (${o}*)__yo_malloc(sizeof(${o}));`),t.emitLine(" obj->header.ref_count = 1; // Start with one reference"),e.needsCycleGC&&!i.isAtomicRc&&(t.emitLine(" obj->header.gc_flags = 0;"),t.emitLine(" obj->header.gc_mark = __YO_GC_UNMARKED;"),t.emitLine(" obj->header.gc_next = NULL;"),t.emitLine(" obj->header.gc_prev = NULL;"));let u=i.trait.fields.find(_=>_.label===F.___dispose[0]&&_.assignedValue&&ge(_.assignedValue));if(u&&ge(u.assignedValue)){let _=u.assignedValue,c=((n=e.functions[_.funcId])==null?void 0:n.cName)||_.funcId;if(e.needsCycleGC)t.emitLine(` obj->header.dispose_fn = (void(*)(void*))${c};`);else{e.disposeTypeIds||(e.disposeTypeIds=new Map,e.nextDisposeTypeId=1);let f=e.disposeTypeIds.get(c);f===void 0&&(f=e.nextDisposeTypeId,e.nextDisposeTypeId=f+1,e.disposeTypeIds.set(c,f)),t.emitLine(` obj->header.type_id = ${f};`)}}else e.needsCycleGC?t.emitLine(" obj->header.dispose_fn = NULL;"):t.emitLine(" obj->header.type_id = 0;");if(e.needsCycleGC&&!i.isAtomicRc){let _=`__yo_traverse_${o}`;t.emitLine(` obj->header.traverse_fn = ${_};`)}i.fields.forEach(_=>{let c=be(_.label);t.emitLine(` obj->${c} = ${c};`)}),e.needsCycleGC&&!i.isAtomicRc&&Zr(i,new Set,i.env)&&t.emitLine(" __yo_gc_register(obj);"),t.emitLine(" return obj;"),t.emitLine("}"),t.emitLine("")}}}function Wf(e){var n;let t=e.emitter;if(!(!e.closureCaptureMap||e.closureCaptureMap.size===0)){t.emitLine("// Closure dispose functions - one per closure instance (closure type + capture type)"),t.emitLine("");for(let[r]of e.closureCaptureMap){let i=`__yo_dispose_closure_${r}`;t.emitDeclarationLine(`static void ${i}(void* closure_ptr);`)}for(let[r,{closureCName:i,captureType:o,captureCName:a}]of e.closureCaptureMap){let s=`__yo_dispose_closure_${r}`,l=o.trait.fields.find(c=>c.label===F.___drop[0]);if(!l||!l.assignedValue||!ge(l.assignedValue))continue;let u=l.assignedValue,_=(n=e.functions[u.funcId])==null?void 0:n.cName;_&&(t.emitLine(`static void ${s}(void* closure_ptr) { // Dispose for ${i} with ${a} (Impl closure - value type)`),t.emitLine(" if (closure_ptr) {"),t.emitLine(` ${i}* closure = (${i}*)closure_ptr;`),t.emitLine(" if (closure->data) {"),t.emitLine(` ${_}(*(${a}*)closure->data); // Drop the capture struct (dereference pointer to pass by value)`),t.emitLine(" // Note: capture data is stack-allocated for Impl closures, no __yo_free needed"),t.emitLine(" }"),t.emitLine(" }"),t.emitLine("}"),t.emitLine(""))}}}function qf(e){var n;let t=new Map;for(let[,r]of e.dynImpls){let i=((n=e.types[r.dynType.id])==null?void 0:n.cName)||`__yo_dyn_${r.dynType.id}`,o=z(r.concreteType)&&r.concreteType.resolvedConcreteType?r.concreteType.resolvedConcreteType:r.concreteType,s=`${(()=>{var c,f;let l=(c=e.types[o.id])==null?void 0:c.cName;if(l)return l;let u=Kn(o);return(u?(f=e.types[u.id])==null?void 0:f.cName:void 0)||`unknown_${o.id}`})()}_${i}`;t.set(s,r)}e.dynImpls=t}var Sl=class{constructor(){this.exportedFunctionNames=new Set;this._needsIntelAsmSyntax=!1;this._usesParallelism=!1;this.emitter=new oo}compileModule(t,n,r={}){this.emitter.emitDeclarationLine(`
|
|
11368
11368
|
// Module ${t}`),this.emitter.emitDeclarationLine(`// Module ID: ${Xo(t)}`);let i={functions:{},externFunctions:{},types:{},arrayStructTypes:new Map,sliceStructTypes:new Map([["Slice_uint8_t_u42_",{childType:"uint8_t*"}]]),spawnedFunctionSignatures:new Map,spawnedClosureSignatures:new Map,closureCaptureMap:new Map,implClosureCallMap:new Map,dynImpls:new Map,currentFunctionName:"",emitter:this.emitter,cIncludes:new Set(["<stdbool.h>","<stdint.h>","<stddef.h>","<stdarg.h>","<stdatomic.h>","<stdlib.h>","<stdio.h>","<string.h>","<errno.h>","<fcntl.h>"]),debugGc:r.debugGc??!1,debugParallelism:r.debugParallelism??!1,debugAsyncAwait:r.debugAsyncAwait??!1,targetInfo:Xa(),deferredAsyncBlocks:[],allocator:r.allocator??"libc",isLibrary:r.isLibrary??!1,currentModuleId:Xo(t),moduleLevelInitExprs:r.allModuleLevelInitExprs??n.moduleLevelInitExprs};if(ts(n,i),i.moduleLevelInitExprs)for(let a of i.moduleLevelInitExprs)In(a,i);if(df(n,i),r.isLibrary&&i.exportedFunctionLabels)for(let[a]of i.exportedFunctionLabels){let s=i.functions[a];s&&this.exportedFunctionNames.add(s.cName)}yf(i),Yc(i),Hc(i),this.emitter.emitDeclarationLine(`
|
|
11369
11369
|
// Future state enum - shared by all Future types
|
|
11370
11370
|
typedef enum {
|
|
@@ -11384,7 +11384,7 @@ static void __yo_dispose_dispatch(void* ptr) {
|
|
|
11384
11384
|
switch (header->type_id) {`);for(let[a,s]of i.disposeTypeIds)this.emitter.emitLine(` case ${s}: ${a}(ptr); return;`);this.emitter.emitLine(` default: return;
|
|
11385
11385
|
}
|
|
11386
11386
|
}`)}else i.needsCycleGC||this.emitter.emitLine("static void __yo_dispose_dispatch(void* ptr) { (void)ptr; }");i.needsIntelAsmSyntax&&(this._needsIntelAsmSyntax=!0),i.usesParallelism&&(this._usesParallelism=!0)}print(){return this.emitter.print()}getExportedFunctionNames(){return this.exportedFunctionNames}get needsIntelAsmSyntax(){return this._needsIntelAsmSyntax}get usesParallelism(){return this._usesParallelism}};var Yf=0;function Nl(e){var t,n;if((t=e.$)!=null&&t.variableName)return!0;if(((n=e.$)==null?void 0:n.value)!==void 0)return!1;if(S(e)){for(let r of e.args)if(Nl(r))return!0;if(e.func&&Nl(e.func))return!0}return!1}function ns(e,t){var n;if(S(e)){(n=e.$)!=null&&n.variableName&&t.add(e.$.variableName);let r=e.func,i=r.tag==="Atom"&&(r.token.value==="&&"||r.token.value==="||");if(i)e.args.length>0&&ns(e.args[0],t);else for(let o of e.args)ns(o,t);e.func&&!i&&ns(e.func,t)}}function Hf(e,t,n){let r=n,i=r.pendingDeferredDrops;if(!(!i||e.size===0)){r.shortCircuitHandledDropVarNames||(r.shortCircuitHandledDropVarNames=new Set);for(let o of i){let a=$r(o);if(a&&e.has(a)){let s=q(o,t,n);s&&n.emitter.emitLine(`${t}${s};`),r.shortCircuitHandledDropVarNames.add(a)}}}}function jf(e,t,n){var l;if(e.args.length===0)return"true";if(e.args.length===1)return q(e.args[0],t,n);let r=[];for(let u of e.args){let _=(l=u.$)==null?void 0:l.value;if(Ct(_)){if(_.value===!1)return"false";continue}r.push(u)}if(r.length===0)return"true";if(r.length===1)return q(r[0],t,n);if(!r.slice(1).some(u=>Nl(u)))return`(${r.map(_=>q(_,t,n)).join(" && ")})`;let o=`__yo_sc_${Yf++}`;n.emitter.emitLine(`${t}bool ${o} = false;`);let a=t,s=r.length-1;for(let u=0;u<r.length;u++){let _=q(r[u],a,n);u<r.length-1?(n.emitter.emitLine(`${a}if (${_}) {`),a+=" "):n.emitter.emitLine(`${a}${o} = ${_};`)}for(let u=s-1;u>=0;u--){let _=r[u+1],c=new Set;ns(_,c),Hf(c,a,n),a=a.slice(2),n.emitter.emitLine(`${a}}`)}return o}function Kf(e,t,n){var l;if(e.args.length===0)return"false";if(e.args.length===1)return q(e.args[0],t,n);let r=[];for(let u of e.args){let _=(l=u.$)==null?void 0:l.value;if(Ct(_)){if(_.value===!0)return"true";continue}r.push(u)}if(r.length===0)return"false";if(r.length===1)return q(r[0],t,n);if(!r.slice(1).some(u=>Nl(u)))return`(${r.map(_=>q(_,t,n)).join(" || ")})`;let o=`__yo_sc_${Yf++}`;n.emitter.emitLine(`${t}bool ${o} = true;`);let a=t,s=r.length-1;for(let u=0;u<r.length;u++){let _=q(r[u],a,n);u<r.length-1?(n.emitter.emitLine(`${a}if (!(${_})) {`),a+=" "):n.emitter.emitLine(`${a}${o} = ${_};`)}for(let u=s-1;u>=0;u--){let _=r[u+1],c=new Set;ns(_,c),Hf(c,a,n),a=a.slice(2),n.emitter.emitLine(`${a}}`)}return o}function Xf(e,t,n){var a,s,l,u;let r=(a=e.$)==null?void 0:a.runtimeArgExprsInOrder,i=(s=e.$)==null?void 0:s.type,o=(l=e.$)==null?void 0:l.variableName;if(Je(i)&&r){let _=n,c=r.map(p=>{var h,y;let m=q(p,t,n);if((h=p.$)!=null&&h.deferredDupExpressions&&p.$.deferredDupExpressions.length>0){Wt(p,t,_);let g=p.$.deferredDupExpressions[0];if(S(g)&&((y=g.$)!=null&&y.variableName))return We(g.$.variableName,g.$.env)}return m}).join(", "),f=j(i,n);if(o&&((u=e.$)!=null&&u.type)){let p=`(${f}){ .data = { ${c} } }`,m=Kt(e.$.type,o,n);return n.emitter.emitLine(`${t}${m} = ${p};`),o}else return`(${f}){ .data = { ${c} } }`}}function Qf(e,t,n){var p,m,h;let r=n.emitter,i=e.args[0],o=e.args[1],a=(p=i.$)==null?void 0:p.value;if(!a||!W(a)||!Je(a.value))return"/* ERROR: __yo_array_fill first argument must be an ArrayType */";let s=a.value,l=s.length;if(!ht(l))return"/* ERROR: __yo_array_fill requires compile-time known array length */";let u=j(s,n),_=q(o,t,n),c=((m=e.$)==null?void 0:m.variableName)||`temp_array_${Date.now()}`,f=`i_${mt(((h=e.$)==null?void 0:h.env.modulePath)??"")}`;return r.emitLine(`${t}${u} ${c};`),r.emitLine(`${t}for (int ${f} = 0; ${f} < ${l.value}; ${f}++) {`),r.emitLine(`${t} ${c}.data[${f}] = ${_};`),r.emitLine(`${t}}`),c}function Zf(e,t,n){var l,u,_,c,f,p,m,h,y,g,v,T,$,C,k,b,w,A,L,N,x,V,U;if((l=e.$)!=null&&l.isCompileTimeOnlyAssignment)return"";let r=e.args[0],i=e.args[1],o=!1;if(S(r)&&E(r,":",2)&&(o=!0,r=r.args[0]),o&&K(r)&&((u=r.$)!=null&&u.env)){let R=r.token.value,D=ae(r.$.env,R);if(D.length>0&&D[D.length-1].isModuleLevel)return""}if(S(r)&&E(r,P.comptime)||S(r)&&E(r,P.given))return"";if((_=r.$)!=null&&_.pathCollection&&((c=r.$)==null?void 0:c.pathCollection.length)>0){let R=r.$.pathCollection[0];if(R&&R.length>=2){let D=R[0];if(typeof D=="string"&&((f=r.$)!=null&&f.env)){let H=ae(r.$.env,D);if(H.length>0&&H[H.length-1].isCompileTimeOnly)return""}}}if(K(r)&&((p=r.$)!=null&&p.env)){let R=r.token.value,D=ae(r.$.env,R);if(D.length>0&&D[D.length-1].isCompileTimeOnly)return""}if(!((m=r.$)!=null&&m.type))return`// Error: No type information for left-hand side ${I(r)}
|
|
11387
|
-
`;let a=q(r,t,n),s=!1;if((h=e.$)!=null&&h.variableName){let R=e.$.variableName,D=n;if((D.inAsyncStateMachine||D.inEffectStateMachine)&&a.startsWith("sm->")){let B=(y=D.stateMachineVariables)==null?void 0:y.get(R);if(!B&&D.stateMachineVariables){for(let[,G]of D.stateMachineVariables)if(G.name===R){B=G;break}}if(B&&B.kind!=="outer"){let G=`var_${B.id}`;De(r.$.type)||n.emitter.emitLine(`${t}sm->${G} = ${a}; // Save old value for deferred drop`)}else s=!0}else{let B=Kt(r.$.type,R,n);Je(r.$.type)?n.emitter.emitLine(`${t}${B} = ${a}; // Save old value for later use`):De(r.$.type)||n.emitter.emitLine(`${t}${B} = ${a}; // Save old value for later use`)}}if(Je(r.$.type)){let R=q(i,t,n),D=S(i)&&((g=i.$)==null?void 0:g.closureFunctionValue)&&((v=i.$)==null?void 0:v.type)&&zn(i.$.type),H=n,B=R;if(!D&&((T=i.$)!=null&&T.deferredDupExpressions)&&i.$.deferredDupExpressions.length>0){if(($=i.$)!=null&&$.variableName&&((C=i.$)!=null&&C.type)){let Q=We(i.$.variableName,i.$.env);if(Q!==R.trim()){let Y=i.$.convertedRuntimeType||i.$.type,J=j(Y,n);n.emitter.emitLine(`${t}${J} ${Q} = ${R};`)}}Wt(i,t,H);let G=i.$.deferredDupExpressions[0];S(G)&&((k=G.$)!=null&&k.variableName)&&(B=We(G.$.variableName,G.$.env))}if(o){let G=Kt(r.$.type,q(r,t,n),n);n.emitter.emitLine(`${t}${G} = ${B};`)}else n.emitter.emitLine(`${t}${a} = ${B};`)}else{let R=q(i,t,n),D=S(i)&&((b=i.$)==null?void 0:b.closureFunctionValue)&&((w=i.$)==null?void 0:w.type)&&zn(i.$.type),H=n,B=R;if(!D&&((A=i.$)!=null&&A.deferredDupExpressions)&&i.$.deferredDupExpressions.length>0){if((L=i.$)!=null&&L.variableName&&((N=i.$)!=null&&N.type)){let Q=We(i.$.variableName,i.$.env);if(Q!==R.trim()){let Y=i.$.convertedRuntimeType||i.$.type,J=j(Y,n);n.emitter.emitLine(`${t}${J} ${Q} = ${R};`)}}Wt(i,t,H);let G=i.$.deferredDupExpressions[0];S(G)&&((x=G.$)!=null&&x.variableName)&&(B=We(G.$.variableName,G.$.env))}if(!De(r.$.type)){let G=r.$.type,Q=(V=i.$)==null?void 0:V.type,Y,J=Ht(i.$.env.modulePath,B.trim());J&&n.tempVarAsyncStructNames&&(Y=n.tempVarAsyncStructNames.get(B.trim()));let se=o&&Q&&at(G)&&at(Q),ve;J&&se?Y?ve=`${Y}*`:ve=j(Q,n):se&&Y?ve=`${Y}*`:ve=j(se?Q:G,n);let re=(H.inAsyncStateMachine||H.inEffectStateMachine)&&a.startsWith("sm->");n.emitter.emitLine(`${t}${o&&!re?ve+" ":""}${a} = ${B};`)}}return s?"":((U=e.$)==null?void 0:U.variableName)??""}function ep(e,t,n){var s,l,u,_,c,f,p,m,h,y,g,v;let r=e.args[0];if(!r)return"// Error: await requires exactly 1 argument";let i=(s=r.$)==null?void 0:s.type;if(!i||!at(i))return"// Error: await argument must be a Future type";let o=Ln(i);if(!o)return"// Error: could not extract Future module from type";let a=n;if(a.inAsyncStateMachine||a.inEffectStateMachine)return"";if(_r(e)){let T=q(r,t,n),$=j(i,n),C=o.isFuture.outputType;z(C)&&(C.resolvedConcreteType?C=C.resolvedConcreteType:(l=e.$)!=null&&l.type&&!z(e.$.type)?C=e.$.type:(u=e.$)!=null&&u.type&&z(e.$.type)&&e.$.type.resolvedConcreteType&&(C=e.$.type.resolvedConcreteType));let k=a.emitter,b=De(C)||z(C)&&De(((_=e.$)==null?void 0:_.type)??C),w=(c=e.$)!=null&&c.variableName?`__sync_future_${e.$.variableName}`:"__sync_future",A=(f=e.$)!=null&&f.variableName?`__pre_await_state_${e.$.variableName}`:"__pre_await_state";k.emitLine(`${t}// Synchronous await (io.await outside state machine)`),k.emitLine(`${t}${$} ${w} = ${T};`),k.emitLine(`${t}int ${A} = ${w}->state;`),es((p=r.$)==null?void 0:p.type)||(k.emitLine(`${t}if (${A} == 0 && ${w}->__yo_resume_fn) {`),vv(e,w,t,n),k.emitLine(`${t} __yo_incr_rc((void*)${w}); // event loop reference`),k.emitLine(`${t} ${w}->__yo_resume_fn((void*)${w});`),k.emitLine(`${t}}`)),k.emitLine(`${t}{`),k.emitLine(`${t} int __await_state = ${w}->state;`),k.emitLine(`${t} while (__await_state != -1 && __await_state != -2) {`),k.emitLine(`${t} __yo_async_poll_step();`),k.emitLine(`${t} __await_state = ${w}->state;`),k.emitLine(`${t} }`),k.emitLine(`${t} if (__await_state == -2) {`);let N=Ln(i),x=((m=N==null?void 0:N.isFuture.effects)==null?void 0:m.some(V=>ne(V.type)||Xe(V.type)||V.isEffectRowSpread))??!1;if(x){k.emitLine(`${t} if (${A} == -2) {`),k.emitLine(`${t} fprintf(stderr, "panic: attempted to await an aborted Future\\n");`),k.emitLine(`${t} abort();`),k.emitLine(`${t} }`);let V=a.pendingDeferredDrops;if(V){let D=(h=e.$)==null?void 0:h.variableName;a.pendingDeferredDrops=V.filter(H=>$r(H)!==D)}or(t+" ",a,e),a.pendingDeferredDrops=V;let U=hv(N,a),R=(g=(y=a.currentFunctionType)==null?void 0:y.return)==null?void 0:g.type;if(U)if(k.emitLine(`${t} __yo_effect_escaped = 0;`),R&&!De(R)){let D=j(R,n);D!=="void"?(k.emitLine(`${t} ${D} _esc_result;`),k.emitLine(`${t} memcpy(&_esc_result, __yo_effect_escape_value, sizeof(${D}));`),k.emitLine(`${t} return _esc_result;`)):k.emitLine(`${t} return;`)}else k.emitLine(`${t} return;`);else if(k.emitLine(`${t} __yo_effect_escaped = 1;`),R&&!De(R)){let D=j(R,n);k.emitLine(`${t} return (${D}){0};`)}else k.emitLine(`${t} return;`)}else k.emitLine(`${t} fprintf(stderr, "panic: attempted to await an aborted Future\\n");`),k.emitLine(`${t} abort();`);if(k.emitLine(`${t} }`),k.emitLine(`${t}}`),b)return"";{let V=((v=e.$)==null?void 0:v.variableName)||"__sync_await_result",U=j(C,n),R=Kt(C,V,n);if(x){if(k.emitLine(`${t}${R};`),k.emitLine(`${t}if (${w}->state == -1) {`),it(C)){let D=fr(C,n);D?k.emitLine(`${t} ${V} = ${D}(${w}->result);`):k.emitLine(`${t} ${V} = ${w}->result;`)}else k.emitLine(`${t} ${V} = ${w}->result;`);k.emitLine(`${t}} else {`),k.emitLine(`${t} ${V} = (${U}){0};`),k.emitLine(`${t}}`)}else if(it(C)){let D=fr(C,n);D?k.emitLine(`${t}${R} = ${D}(${w}->result);`):k.emitLine(`${t}${R} = ${w}->result;`)}else k.emitLine(`${t}${R} = ${w}->result;`);return V}}return"// Error: await should only be used inside async blocks"}function tp(e,t,n){var _,c,f;let r=e.args[0];if(!r)return"// Error: io.state requires exactly 1 argument";let i=(_=r.$)==null?void 0:_.type;if(!i||!at(i))return"// Error: io.state argument must be a Future type";let a=n.emitter,s=q(r,t,n),l=(c=e.$)!=null&&c.variableName?`__raw_state_${e.$.variableName}`:"__raw_state",u=((f=e.$)==null?void 0:f.variableName)||"__io_state_result";return a.emitLine(`${t}int ${l} = ${s}->state;`),a.emitLine(`${t}int32_t ${u} = (${l} > 0) ? 1 : ${l};`),u}function np(e,t,n){var C,k,b,w,A;let i=n.emitter,o=S(e.func)?e.func.args[0]:e.args[0];if(!o)return"// Error: JoinHandle.await requires a self argument";let a=q(o,t,n),s=(C=e.$)==null?void 0:C.type;if(!s||!Be(s))return"// Error: JoinHandle.await return type must be Option(T)";let l=j(s,n),u=s.variants.find(L=>L.name==="Some"),_=(b=(k=u==null?void 0:u.fields)==null?void 0:k[0])==null?void 0:b.type,c=!_||De(_),f=c?"uint8_t":_?j(_,n):"uint8_t",p=Rn(s,"Some",n),m=Rn(s,"None",n),h=((w=e.$)==null?void 0:w.variableName)||"jh",y=`__jh_future_${h}`,g=`__jh_header_${h}`,v=((A=e.$)==null?void 0:A.variableName)||"__jh_result",T=`__yo_jh_header_${h}`;i.emitLine(`${t}// JoinHandle.await \u2014 poll spawned task, return Option(T)`);let $=Kt(s,v,n);if(i.emitLine(`${t}${$};`),i.emitLine(`${t}{`),i.emitLine(`${t} void* ${y} = ${a}.__future;`),i.emitLine(`${t} struct ${T} {`),i.emitLine(`${t} __yo_ref_header_t header;`),i.emitLine(`${t} int state;`),i.emitLine(`${t} ${f} result;`),i.emitLine(`${t} void (*continuation_fn)(void*);`),i.emitLine(`${t} void* continuation_sm;`),i.emitLine(`${t} void (*__yo_resume_fn)(void*);`),i.emitLine(`${t} };`),i.emitLine(`${t} struct ${T}* ${g} = (struct ${T}*)${y};`),i.emitLine(`${t} int __jh_state = ${g}->state;`),i.emitLine(`${t} while (__jh_state != -1 && __jh_state != -2) {`),i.emitLine(`${t} __yo_async_poll_step();`),i.emitLine(`${t} __jh_state = ${g}->state;`),i.emitLine(`${t} }`),i.emitLine(`${t} if (__jh_state == -1) {`),c)i.emitLine(`${t} ${v} = (${l}){ .tag = ${p} };`);else if(_&&it(_)){let L=fr(_,n);L?i.emitLine(`${t} ${v} = (${l}){ .tag = ${p}, .data = { .Some = { .value = ${L}(${g}->result) } } };`):i.emitLine(`${t} ${v} = (${l}){ .tag = ${p}, .data = { .Some = { .value = ${g}->result } } };`)}else i.emitLine(`${t} ${v} = (${l}){ .tag = ${p}, .data = { .Some = { .value = ${g}->result } } };`);return i.emitLine(`${t} } else {`),i.emitLine(`${t} __yo_effect_escaped = 0;`),i.emitLine(`${t} ${v} = (${l}){ .tag = ${m} };`),i.emitLine(`${t} }`),i.emitLine(`${t}}`),v}function hv(e,t){let n=e.isFuture.effects;if(!(n!=null&&n.length))return!1;let r=rp(n),i=t.currentEvidenceParams;for(let o of r)if(ne(o.type)){let a=`${o.label}.${o.label}`;if(!(i!=null&&i.has(a)))return!0}else if(Xe(o.type)){let a=!1;if(i){for(let[s]of i)if(s.startsWith(`${o.label}.`)){a=!0;break}}if(!a)return!0}return!1}function rp(e){let t=[];for(let n of e)if(n.isEffectRowSpread){let r=n.type;z(r)&&r.resolvedConcreteType&&(r=r.resolvedConcreteType),Yt(r)&&t.push(...r.implicitParameters)}else t.push(n);return t}function vv(e,t,n,r){var _,c,f;let i=e.args[0];if(!((_=i==null?void 0:i.$)!=null&&_.type))return;let o=Ln(i.$.type);if(!((c=o==null?void 0:o.isFuture.effects)!=null&&c.length))return;let a=rp(o.isFuture.effects),s=r,l=s.emitter,u=e.args.find(p=>S(p)&&E(p,P.using));if(u){let p=u.args;for(let m=0;m<a.length&&m<p.length;m++){let h=a[m],y=p[m];if(ne(h.type)){let g=q(y,n,r),v=h.label;l.emitLine(`${n} ${t}->__capture.${v} = (void*)${g};`)}else Xe(h.type)&&Jf(h.type,t,n,(f=y.$)==null?void 0:f.value,s,e)}}else for(let p of a)if(ne(p.type)){let m=Ev(p.label,s,e);m&&l.emitLine(`${n} ${t}->__capture.${p.label} = (void*)${m};`)}else Xe(p.type)&&Jf(p.type,t,n,void 0,s,e)}function Jf(e,t,n,r,i,o){let a=i.emitter;for(let s of e.fields){if(!ne(s.type))continue;let l;if(i.stateMachineVariables){for(let[,u]of i.stateMachineVariables)if(u.name===s.label&&u.kind==="outer"){l=`sm->__capture.${s.label}`;break}}if(!l&&r&&wt(r)){let u=e.fields.indexOf(s),_=r.fields[u];if(_&&he(_)){let c=i.functions[_.funcId];c&&(l=c.cName)}}if(!l&&i.currentEvidenceParams){for(let u of i.currentEvidenceParams.values())if(u.fieldLabel===s.label){l=u.cParamName;break}}l||(l=Tv(s.label,e,i,o)),l&&a.emitLine(`${n} ${t}->__capture.${s.label} = (void*)${l};`)}}function Tv(e,t,n,r){var a,s,l,u;let i=((a=r.$)==null?void 0:a.env)??((s=r.func.$)==null?void 0:s.env);if(!i)return;let o=cr(i,_=>_.isImplicit===!0);for(let _=o.length-1;_>=0;_--){let c=o[_],f=(l=c.value)==null?void 0:l[c.value.length-1];if(f&&wt(f)){let p=f.type.fields.findIndex(m=>m.label===e);if(p>=0){let m=f.fields[p];if(m&&he(m)){let h=(u=n.functions[m.funcId])==null?void 0:u.cName;if(h)return h}}}}}function Ev(e,t,n){if(t.currentEvidenceParams){for(let r of t.currentEvidenceParams.values())if(r.fieldLabel===e)return r.cParamName}if(t.stateMachineVariables){for(let[,r]of t.stateMachineVariables)if(r.name===e&&r.kind==="outer")return`sm->__capture.${e}`}}function ip(e,t,n){var a,s,l,u,_,c,f,p,m,h,y,g,v,T;let r=(a=e.$)==null?void 0:a.variableName,i=(s=e.$)==null?void 0:s.type,o=n;if(r&&i){!De(i)&&!Gt((l=e.$)==null?void 0:l.controlFlow)&&n.emitter.emitLine(`${t}${j(i,n)} ${r};`),n.emitter.emitLine(`${t}{ // begin block`);let $=o.pendingDeferredDrops,C=((u=e.$)==null?void 0:u.deferredDropExpressions)??[];o.pendingDeferredDrops=[...C,...$??[]];let k=o.consumedVarPendingDrops,b=((_=e.$)==null?void 0:_.consumedVariableDropExpressions)??[];o.consumedVarPendingDrops=[...b,...k??[]];let w=[],A=!De(i)&&!Gt((c=e.$)==null?void 0:c.controlFlow);for(let L=0;L<e.args.length;L++){let N=e.args[L],x=q(N,t+" ",n);w.push(x);let V=L===e.args.length-1;x&&!(V&&A)&&(N.$&&Ht(N.$.env.modulePath,x)||n.emitter.emitLine(`${t} ${x};`))}if(A){let L=e.args[e.args.length-1],N=w[w.length-1];if((f=L.$)!=null&&f.deferredDupExpressions&&L.$.deferredDupExpressions.length>0){if((p=L.$)!=null&&p.variableName){let V=L.$.variableName;L.$.variableName=void 0;let U=q(L,t+" ",n);L.$.variableName=V;let R=j(L.$.type,n),D=We(V,L.$.env);D!==U&&n.emitter.emitLine(`${t} ${R} ${D} = ${U};`),N=D}Wt(L,t+" ",n);let x=L.$.deferredDupExpressions[0];S(x)&&((m=x.$)!=null&&m.variableName)&&(N=We(x.$.variableName,x.$.env))}n.emitter.emitLine(`${t} ${r} = ${N};`)}if((h=e.$)!=null&&h.deferredDropExpressions)for(let L of e.$.deferredDropExpressions){if(o.shortCircuitHandledDropVarNames){let x=$r(L);if(x&&o.shortCircuitHandledDropVarNames.has(x)){o.shortCircuitHandledDropVarNames.delete(x);continue}}let N=q(L,t+" ",n);N&&n.emitter.emitLine(`${t} ${N};`)}return n.emitter.emitLine(`${t}} // end begin block`),o.pendingDeferredDrops=$,o.consumedVarPendingDrops=k,De(i)||Gt((y=e.$)==null?void 0:y.controlFlow)?"":r}else{n.emitter.emitLine(`${t}{ // begin block`);let $=o.pendingDeferredDrops,C=((g=e.$)==null?void 0:g.deferredDropExpressions)??[];o.pendingDeferredDrops=[...C,...$??[]];let k=o.consumedVarPendingDrops,b=((v=e.$)==null?void 0:v.consumedVariableDropExpressions)??[];if(o.consumedVarPendingDrops=[...b,...k??[]],e.args.map(A=>q(A,t+" ",n)).forEach(A=>{A&&n.emitter.emitLine(`${t} ${A};`)}),(T=e.$)!=null&&T.deferredDropExpressions)for(let A of e.$.deferredDropExpressions){if(o.shortCircuitHandledDropVarNames){let N=$r(A);if(N&&o.shortCircuitHandledDropVarNames.has(N)){o.shortCircuitHandledDropVarNames.delete(N);continue}}let L=q(A,t+" ",n);L&&n.emitter.emitLine(`${t} ${L};`)}return n.emitter.emitLine(`${t}} // end begin block`),o.pendingDeferredDrops=$,o.consumedVarPendingDrops=k,""}}function op(e,t,n){var a;let r=e.args[0];if(S(r)&&E(r,P.comptime,1)||S(r)&&E(r,P.given,1))return"";if(!((a=r.$)!=null&&a.type))return`// Error: No type information for left-hand side ${I(r)}
|
|
11387
|
+
`;let a=q(r,t,n),s=!1;if((h=e.$)!=null&&h.variableName){let R=e.$.variableName,D=n;if((D.inAsyncStateMachine||D.inEffectStateMachine)&&a.startsWith("sm->")){let B=(y=D.stateMachineVariables)==null?void 0:y.get(R);if(!B&&D.stateMachineVariables){for(let[,G]of D.stateMachineVariables)if(G.name===R){B=G;break}}if(B&&B.kind!=="outer"){let G=`var_${B.id}`;De(r.$.type)||n.emitter.emitLine(`${t}sm->${G} = ${a}; // Save old value for deferred drop`)}else s=!0}else{let B=Kt(r.$.type,R,n);Je(r.$.type)?n.emitter.emitLine(`${t}${B} = ${a}; // Save old value for later use`):De(r.$.type)||n.emitter.emitLine(`${t}${B} = ${a}; // Save old value for later use`)}}if(Je(r.$.type)){let R=q(i,t,n),D=S(i)&&((g=i.$)==null?void 0:g.closureFunctionValue)&&((v=i.$)==null?void 0:v.type)&&zn(i.$.type),H=n,B=R;if(!D&&((T=i.$)!=null&&T.deferredDupExpressions)&&i.$.deferredDupExpressions.length>0){if(($=i.$)!=null&&$.variableName&&((C=i.$)!=null&&C.type)){let Q=We(i.$.variableName,i.$.env);if(Q!==R.trim()){let Y=i.$.convertedRuntimeType||i.$.type,J=j(Y,n);n.emitter.emitLine(`${t}${J} ${Q} = ${R};`)}}Wt(i,t,H);let G=i.$.deferredDupExpressions[0];S(G)&&((k=G.$)!=null&&k.variableName)&&(B=We(G.$.variableName,G.$.env))}if(o){let G=Kt(r.$.type,q(r,t,n),n);n.emitter.emitLine(`${t}${G} = ${B};`)}else n.emitter.emitLine(`${t}${a} = ${B};`)}else{let R=q(i,t,n),D=S(i)&&((b=i.$)==null?void 0:b.closureFunctionValue)&&((w=i.$)==null?void 0:w.type)&&zn(i.$.type),H=n,B=R;if(!D&&((A=i.$)!=null&&A.deferredDupExpressions)&&i.$.deferredDupExpressions.length>0){if((L=i.$)!=null&&L.variableName&&((N=i.$)!=null&&N.type)){let Q=We(i.$.variableName,i.$.env);if(Q!==R.trim()){let Y=i.$.convertedRuntimeType||i.$.type,J=j(Y,n);n.emitter.emitLine(`${t}${J} ${Q} = ${R};`)}}Wt(i,t,H);let G=i.$.deferredDupExpressions[0];S(G)&&((x=G.$)!=null&&x.variableName)&&(B=We(G.$.variableName,G.$.env))}if(!De(r.$.type)){let G=r.$.type,Q=(V=i.$)==null?void 0:V.type,Y,J=Ht(i.$.env.modulePath,B.trim());J&&n.tempVarAsyncStructNames&&(Y=n.tempVarAsyncStructNames.get(B.trim()));let se=o&&Q&&at(G)&&at(Q),ve;J&&se?Y?ve=`${Y}*`:ve=j(Q,n):se&&Y?ve=`${Y}*`:ve=j(se?Q:G,n);let re=(H.inAsyncStateMachine||H.inEffectStateMachine)&&a.startsWith("sm->");n.emitter.emitLine(`${t}${o&&!re?ve+" ":""}${a} = ${B};`)}}return s?"":((U=e.$)==null?void 0:U.variableName)??""}function ep(e,t,n){var s,l,u,_,c,f,p,m,h,y,g,v;let r=e.args[0];if(!r)return"// Error: await requires exactly 1 argument";let i=(s=r.$)==null?void 0:s.type;if(!i||!at(i))return"// Error: await argument must be a Future type";let o=Ln(i);if(!o)return"// Error: could not extract Future module from type";let a=n;if(a.inAsyncStateMachine||a.inEffectStateMachine)return"";if(_r(e)){let T=q(r,t,n),$=j(i,n),C=o.isFuture.outputType;z(C)&&(C.resolvedConcreteType?C=C.resolvedConcreteType:(l=e.$)!=null&&l.type&&!z(e.$.type)?C=e.$.type:(u=e.$)!=null&&u.type&&z(e.$.type)&&e.$.type.resolvedConcreteType&&(C=e.$.type.resolvedConcreteType));let k=a.emitter,b=De(C)||z(C)&&De(((_=e.$)==null?void 0:_.type)??C),w=(c=e.$)!=null&&c.variableName?`__sync_future_${e.$.variableName}`:"__sync_future",A=(f=e.$)!=null&&f.variableName?`__pre_await_state_${e.$.variableName}`:"__pre_await_state";k.emitLine(`${t}// Synchronous await (io.await outside state machine)`),k.emitLine(`${t}${$} ${w} = ${T};`),k.emitLine(`${t}int ${A} = ${w}->state;`),es((p=r.$)==null?void 0:p.type)||(k.emitLine(`${t}if (${A} == 0 && ${w}->__yo_resume_fn) {`),vv(e,w,t,n),k.emitLine(`${t} __yo_incr_rc((void*)${w}); // event loop reference`),k.emitLine(`${t} ${w}->__yo_resume_fn((void*)${w});`),k.emitLine(`${t}}`)),k.emitLine(`${t}{`),k.emitLine(`${t} int __await_state = ${w}->state;`),k.emitLine(`${t} while (__await_state != -1 && __await_state != -2) {`),k.emitLine(`${t} __yo_async_poll_step();`),k.emitLine(`${t} __await_state = ${w}->state;`),k.emitLine(`${t} }`),k.emitLine(`${t} if (__await_state == -2) {`);let N=Ln(i),x=((m=N==null?void 0:N.isFuture.effects)==null?void 0:m.some(V=>ne(V.type)||Xe(V.type)||V.isEffectRowSpread))??!1;if(x){k.emitLine(`${t} if (${A} == -2) {`),k.emitLine(`${t} fprintf(stderr, "panic: attempted to await an aborted Future\\n");`),k.emitLine(`${t} abort();`),k.emitLine(`${t} }`);let V=a.pendingDeferredDrops;if(V){let D=(h=e.$)==null?void 0:h.variableName;a.pendingDeferredDrops=V.filter(H=>$r(H)!==D)}or(t+" ",a,e),a.pendingDeferredDrops=V;let U=hv(N,a),R=(g=(y=a.currentFunctionType)==null?void 0:y.return)==null?void 0:g.type;if(U)if(k.emitLine(`${t} __yo_effect_escaped = 0;`),R&&!De(R)){let D=j(R,n);D!=="void"?(k.emitLine(`${t} ${D} _esc_result;`),k.emitLine(`${t} memcpy(&_esc_result, __yo_effect_escape_value, sizeof(${D}));`),k.emitLine(`${t} return _esc_result;`)):k.emitLine(`${t} return;`)}else k.emitLine(`${t} return;`);else if(k.emitLine(`${t} __yo_effect_escaped = 1;`),R&&!De(R)){let D=j(R,n);k.emitLine(`${t} return (${D}){0};`)}else k.emitLine(`${t} return;`)}else k.emitLine(`${t} fprintf(stderr, "panic: attempted to await an aborted Future\\n");`),k.emitLine(`${t} abort();`);if(k.emitLine(`${t} }`),k.emitLine(`${t}}`),b)return"";{let V=((v=e.$)==null?void 0:v.variableName)||"__sync_await_result",U=j(C,n),R=Kt(C,V,n);if(x){if(k.emitLine(`${t}${R};`),k.emitLine(`${t}if (${w}->state == -1) {`),it(C)){let D=fr(C,n);D?k.emitLine(`${t} ${V} = ${D}(${w}->result);`):k.emitLine(`${t} ${V} = ${w}->result;`)}else k.emitLine(`${t} ${V} = ${w}->result;`);k.emitLine(`${t}} else {`),k.emitLine(`${t} ${V} = (${U}){0};`),k.emitLine(`${t}}`)}else if(it(C)){let D=fr(C,n);D?k.emitLine(`${t}${R} = ${D}(${w}->result);`):k.emitLine(`${t}${R} = ${w}->result;`)}else k.emitLine(`${t}${R} = ${w}->result;`);return V}}return"// Error: await should only be used inside async blocks"}function tp(e,t,n){var _,c,f;let r=e.args[0];if(!r)return"// Error: io.state requires exactly 1 argument";let i=(_=r.$)==null?void 0:_.type;if(!i||!at(i))return"// Error: io.state argument must be a Future type";let a=n.emitter,s=q(r,t,n),l=(c=e.$)!=null&&c.variableName?`__raw_state_${e.$.variableName}`:"__raw_state",u=((f=e.$)==null?void 0:f.variableName)||"__io_state_result";return a.emitLine(`${t}int ${l} = ${s}->state;`),a.emitLine(`${t}int32_t ${u} = (${l} > 0) ? 1 : ${l};`),u}function np(e,t,n){var C,k,b,w,A;let i=n.emitter,o=S(e.func)?e.func.args[0]:e.args[0];if(!o)return"// Error: JoinHandle.await requires a self argument";let a=q(o,t,n),s=(C=e.$)==null?void 0:C.type;if(!s||!Be(s))return"// Error: JoinHandle.await return type must be Option(T)";let l=j(s,n),u=s.variants.find(L=>L.name==="Some"),_=(b=(k=u==null?void 0:u.fields)==null?void 0:k[0])==null?void 0:b.type,c=!_||De(_),f=c?"uint8_t":_?j(_,n):"uint8_t",p=Rn(s,"Some",n),m=Rn(s,"None",n),h=((w=e.$)==null?void 0:w.variableName)||"jh",y=`__jh_future_${h}`,g=`__jh_header_${h}`,v=((A=e.$)==null?void 0:A.variableName)||"__jh_result",T=`__yo_jh_header_${h}`;i.emitLine(`${t}// JoinHandle.await \u2014 poll spawned task, return Option(T)`);let $=Kt(s,v,n);if(i.emitLine(`${t}${$};`),i.emitLine(`${t}{`),i.emitLine(`${t} void* ${y} = ${a}.__future;`),i.emitLine(`${t} struct ${T} {`),i.emitLine(`${t} __yo_ref_header_t header;`),i.emitLine(`${t} int state;`),i.emitLine(`${t} ${f} result;`),i.emitLine(`${t} void (*continuation_fn)(void*);`),i.emitLine(`${t} void* continuation_sm;`),i.emitLine(`${t} void (*__yo_resume_fn)(void*);`),i.emitLine(`${t} };`),i.emitLine(`${t} struct ${T}* ${g} = (struct ${T}*)${y};`),i.emitLine(`${t} int __jh_state = ${g}->state;`),i.emitLine(`${t} while (__jh_state != -1 && __jh_state != -2) {`),i.emitLine(`${t} __yo_async_poll_step();`),i.emitLine(`${t} __jh_state = ${g}->state;`),i.emitLine(`${t} }`),i.emitLine(`${t} if (__jh_state == -1) {`),c)i.emitLine(`${t} ${v} = (${l}){ .tag = ${p} };`);else if(_&&it(_)){let L=fr(_,n);L?i.emitLine(`${t} ${v} = (${l}){ .tag = ${p}, .data = { .Some = { .value = ${L}(${g}->result) } } };`):i.emitLine(`${t} ${v} = (${l}){ .tag = ${p}, .data = { .Some = { .value = ${g}->result } } };`)}else i.emitLine(`${t} ${v} = (${l}){ .tag = ${p}, .data = { .Some = { .value = ${g}->result } } };`);return i.emitLine(`${t} } else {`),i.emitLine(`${t} __yo_effect_escaped = 0;`),i.emitLine(`${t} ${v} = (${l}){ .tag = ${m} };`),i.emitLine(`${t} }`),i.emitLine(`${t}}`),v}function hv(e,t){let n=e.isFuture.effects;if(!(n!=null&&n.length))return!1;let r=rp(n),i=t.currentEvidenceParams;for(let o of r)if(ne(o.type)){let a=`${o.label}.${o.label}`;if(!(i!=null&&i.has(a)))return!0}else if(Xe(o.type)){let a=!1;if(i){for(let[s]of i)if(s.startsWith(`${o.label}.`)){a=!0;break}}if(!a)return!0}return!1}function rp(e){let t=[];for(let n of e)if(n.isEffectRowSpread){let r=n.type;z(r)&&r.resolvedConcreteType&&(r=r.resolvedConcreteType),Yt(r)&&t.push(...r.implicitParameters)}else t.push(n);return t}function vv(e,t,n,r){var _,c,f;let i=e.args[0];if(!((_=i==null?void 0:i.$)!=null&&_.type))return;let o=Ln(i.$.type);if(!((c=o==null?void 0:o.isFuture.effects)!=null&&c.length))return;let a=rp(o.isFuture.effects),s=r,l=s.emitter,u=e.args.find(p=>S(p)&&E(p,P.using));if(u){let p=u.args;for(let m=0;m<a.length&&m<p.length;m++){let h=a[m],y=p[m];if(ne(h.type)){let g=q(y,n,r),v=h.label;l.emitLine(`${n} ${t}->__capture.${v} = (void*)${g};`)}else Xe(h.type)&&Jf(h.type,t,n,(f=y.$)==null?void 0:f.value,s,e)}}else for(let p of a)if(ne(p.type)){let m=Ev(p.label,s,e);m&&l.emitLine(`${n} ${t}->__capture.${p.label} = (void*)${m};`)}else Xe(p.type)&&Jf(p.type,t,n,void 0,s,e)}function Jf(e,t,n,r,i,o){let a=i.emitter;for(let s of e.fields){if(!ne(s.type))continue;let l;if(i.stateMachineVariables){for(let[,u]of i.stateMachineVariables)if(u.name===s.label&&u.kind==="outer"){l=`sm->__capture.${s.label}`;break}}if(!l&&r&&wt(r)){let u=e.fields.indexOf(s),_=r.fields[u];if(_&&ge(_)){let c=i.functions[_.funcId];c&&(l=c.cName)}}if(!l&&i.currentEvidenceParams){for(let u of i.currentEvidenceParams.values())if(u.fieldLabel===s.label){l=u.cParamName;break}}l||(l=Tv(s.label,e,i,o)),l&&a.emitLine(`${n} ${t}->__capture.${s.label} = (void*)${l};`)}}function Tv(e,t,n,r){var a,s,l,u;let i=((a=r.$)==null?void 0:a.env)??((s=r.func.$)==null?void 0:s.env);if(!i)return;let o=cr(i,_=>_.isImplicit===!0);for(let _=o.length-1;_>=0;_--){let c=o[_],f=(l=c.value)==null?void 0:l[c.value.length-1];if(f&&wt(f)){let p=f.type.fields.findIndex(m=>m.label===e);if(p>=0){let m=f.fields[p];if(m&&ge(m)){let h=(u=n.functions[m.funcId])==null?void 0:u.cName;if(h)return h}}}}}function Ev(e,t,n){if(t.currentEvidenceParams){for(let r of t.currentEvidenceParams.values())if(r.fieldLabel===e)return r.cParamName}if(t.stateMachineVariables){for(let[,r]of t.stateMachineVariables)if(r.name===e&&r.kind==="outer")return`sm->__capture.${e}`}}function ip(e,t,n){var a,s,l,u,_,c,f,p,m,h,y,g,v,T;let r=(a=e.$)==null?void 0:a.variableName,i=(s=e.$)==null?void 0:s.type,o=n;if(r&&i){!De(i)&&!Gt((l=e.$)==null?void 0:l.controlFlow)&&n.emitter.emitLine(`${t}${j(i,n)} ${r};`),n.emitter.emitLine(`${t}{ // begin block`);let $=o.pendingDeferredDrops,C=((u=e.$)==null?void 0:u.deferredDropExpressions)??[];o.pendingDeferredDrops=[...C,...$??[]];let k=o.consumedVarPendingDrops,b=((_=e.$)==null?void 0:_.consumedVariableDropExpressions)??[];o.consumedVarPendingDrops=[...b,...k??[]];let w=[],A=!De(i)&&!Gt((c=e.$)==null?void 0:c.controlFlow);for(let L=0;L<e.args.length;L++){let N=e.args[L],x=q(N,t+" ",n);w.push(x);let V=L===e.args.length-1;x&&!(V&&A)&&(N.$&&Ht(N.$.env.modulePath,x)||n.emitter.emitLine(`${t} ${x};`))}if(A){let L=e.args[e.args.length-1],N=w[w.length-1];if((f=L.$)!=null&&f.deferredDupExpressions&&L.$.deferredDupExpressions.length>0){if((p=L.$)!=null&&p.variableName){let V=L.$.variableName;L.$.variableName=void 0;let U=q(L,t+" ",n);L.$.variableName=V;let R=j(L.$.type,n),D=We(V,L.$.env);D!==U&&n.emitter.emitLine(`${t} ${R} ${D} = ${U};`),N=D}Wt(L,t+" ",n);let x=L.$.deferredDupExpressions[0];S(x)&&((m=x.$)!=null&&m.variableName)&&(N=We(x.$.variableName,x.$.env))}n.emitter.emitLine(`${t} ${r} = ${N};`)}if((h=e.$)!=null&&h.deferredDropExpressions)for(let L of e.$.deferredDropExpressions){if(o.shortCircuitHandledDropVarNames){let x=$r(L);if(x&&o.shortCircuitHandledDropVarNames.has(x)){o.shortCircuitHandledDropVarNames.delete(x);continue}}let N=q(L,t+" ",n);N&&n.emitter.emitLine(`${t} ${N};`)}return n.emitter.emitLine(`${t}} // end begin block`),o.pendingDeferredDrops=$,o.consumedVarPendingDrops=k,De(i)||Gt((y=e.$)==null?void 0:y.controlFlow)?"":r}else{n.emitter.emitLine(`${t}{ // begin block`);let $=o.pendingDeferredDrops,C=((g=e.$)==null?void 0:g.deferredDropExpressions)??[];o.pendingDeferredDrops=[...C,...$??[]];let k=o.consumedVarPendingDrops,b=((v=e.$)==null?void 0:v.consumedVariableDropExpressions)??[];if(o.consumedVarPendingDrops=[...b,...k??[]],e.args.map(A=>q(A,t+" ",n)).forEach(A=>{A&&n.emitter.emitLine(`${t} ${A};`)}),(T=e.$)!=null&&T.deferredDropExpressions)for(let A of e.$.deferredDropExpressions){if(o.shortCircuitHandledDropVarNames){let N=$r(A);if(N&&o.shortCircuitHandledDropVarNames.has(N)){o.shortCircuitHandledDropVarNames.delete(N);continue}}let L=q(A,t+" ",n);L&&n.emitter.emitLine(`${t} ${L};`)}return n.emitter.emitLine(`${t}} // end begin block`),o.pendingDeferredDrops=$,o.consumedVarPendingDrops=k,""}}function op(e,t,n){var a;let r=e.args[0];if(S(r)&&E(r,P.comptime,1)||S(r)&&E(r,P.given,1))return"";if(!((a=r.$)!=null&&a.type))return`// Error: No type information for left-hand side ${I(r)}
|
|
11388
11388
|
`;let i=r.token.value,o=Kt(r.$.type,i,n);return n.emitter.emitLine(`${t}${o};`),""}function ap(e,t,n){var r,i,o,a,s,l,u,_,c,f,p,m,h,y,g,v;if(e.$){let T=e.$.variableName,$=e.$.type,C=$&&De($),k=-1;for(let N=0;N<e.args.length;N++){let x=e.args[N];if(S(x)&&E(x,"=>",2)){let V=x.args[0];if(V&&!(Ct((r=V.$)==null?void 0:r.value)&&V.$.value.value===!1)){k=N;break}}}let b=!1;if(k>=0){let N=e.args[k];if(N&&S(N)&&E(N,"=>",2)){let x=N.args[0];x&&Ct((i=x.$)==null?void 0:i.value)&&x.$.value.value===!0&&(b=!0)}}if(!C&&T&&!b){let N=j($,n);n.emitter.emitLine(`${t}${N} ${T};`)}if(b&&k>=0){let N=e.args[k];if(N&&S(N)&&E(N,"=>",2)){let x=N.args[1];if(x){let V=q(x,t,n);T&&!C&&(V&&V!==""&&!V.startsWith("goto")&&V!=="continue"&&V!=="break"&&!V.includes("return")?n.emitter.emitLine(`${t}${T} = ${V};`):V&&(V.startsWith("goto")||V==="continue"||V==="break"||V.includes("return"))&&n.emitter.emitLine(`${t}${V};`))}}return C?"":T??""}let w=t,A=0,L=!1;for(let N=0;N<e.args.length;N++){let x=e.args[N];if(S(x)&&E(x,"=>",2)){let V=x.args[0],U=x.args[1];if(V&&U){if(Ct((o=V.$)==null?void 0:o.value)&&V.$.value.value===!1)continue;if(L){if(n.emitter.emitLine(`${w}else {`),A++,w+=" ",!(Ct((s=V.$)==null?void 0:s.value)&&V.$.value.value===!0)){let G=q(V,w,n);n.emitter.emitLine(`${w}if (${G}) {`)}}else{if(Ct((a=V.$)==null?void 0:a.value)&&V.$.value.value===!0)n.emitter.emitLine(`${w}{`);else{let B=q(V,w,n);n.emitter.emitLine(`${w}if (${B}) {`)}L=!0}let R=Ct((l=V.$)==null?void 0:l.value)&&V.$.value.value===!0,D=L&&R?w:w+" ";if(S(U)&&E(U,P.begin)){let B=U.args,G=n,Q=G.pendingDeferredDrops,Y=((u=U.$)==null?void 0:u.deferredDropExpressions)??[];G.pendingDeferredDrops=[...Y,...Q??[]];let J=G.consumedVarPendingDrops,se=((_=U.$)==null?void 0:_.consumedVariableDropExpressions)??[];G.consumedVarPendingDrops=[...se,...J??[]];for(let ve=0;ve<B.length-1;ve++){let re=B[ve],ce=q(re,D,n);if(ce&&re.$&&!Ht(re.$.env.modulePath,ce)&&n.emitter.emitLine(`${D}${ce};`),Gt((c=re.$)==null?void 0:c.controlFlow))break}if(B.length>0){let ve=B[B.length-1];if((f=ve.$)!=null&&f.deferredDupExpressions){if((p=ve.$)!=null&&p.variableName){let ce=ve.$.variableName;ve.$.variableName=void 0;let we=q(ve,D,n);ve.$.variableName=ce;let Se=j(ve.$.type,n),Ve=We(ce,ve.$.env);Ve!==we&&n.emitter.emitLine(`${D}${Se} ${Ve} = ${we};`)}Wt(ve,D,n);let re=ve.$.deferredDupExpressions[0];if(S(re)&&((m=re.$)!=null&&m.variableName)){let ce=We(re.$.variableName,re.$.env);T&&!C&&n.emitter.emitLine(`${D}${T} = ${ce};`)}else{let ce=q(ve,D,n);ce&&T&&!C&&n.emitter.emitLine(`${D}${T} = ${ce};`)}}else{let re=q(ve,D,n);re&&(re==="continue"||re==="break"||re.startsWith("goto")||S(ve)&&E(ve,P.return)||re.includes("return")?n.emitter.emitLine(`${D}${re};`):T&&!C&&n.emitter.emitLine(`${D}${T} = ${re};`))}}(h=U.$)!=null&&h.deferredDropExpressions&&fn(U,D,n),G.pendingDeferredDrops=Q,G.consumedVarPendingDrops=J}else if((y=U.$)!=null&&y.deferredDupExpressions&&U.$.deferredDupExpressions.length>0){if((g=U.$)!=null&&g.variableName){let G=U.$.variableName;U.$.variableName=void 0;let Q=q(U,D,n);U.$.variableName=G;let Y=j(U.$.type,n),J=We(G,U.$.env);J!==Q&&n.emitter.emitLine(`${D}${Y} ${J} = ${Q};`)}Wt(U,D,n);let B=U.$.deferredDupExpressions[0];if(S(B)&&((v=B.$)!=null&&v.variableName)){let G=We(B.$.variableName,B.$.env);T&&!C&&n.emitter.emitLine(`${D}${T} = ${G};`)}else{let G=q(U,D,n);G&&T&&!C&&n.emitter.emitLine(`${D}${T} = ${G};`)}}else{let B=q(U,D,n);B==="continue"||B==="break"||B.startsWith("goto")||S(U)&&E(U,P.return)||B.includes("return")?n.emitter.emitLine(`${D}${B};`):B===""||!B||T&&(C||n.emitter.emitLine(`${D}${T} = ${B};`))}!(L&&R)&&n.emitter.emitLine(`${w}}`)}}}for(let N=0;N<A;N++)w=w.slice(0,-2),n.emitter.emitLine(`${w}}`);return C?"":T??""}return'/* "cond" expression is not evaluated */'}function sp(e,t,n){let r=e.args[0];return q(r,t,n)}function lp(e,t,n){var w,A,L,N,x;let r=e.args[0],i=(w=r.$)==null?void 0:w.type;if(!i||!st(i))throw new Error("downcast codegen: expected Dyn type as first argument");let o=q(r,t,n),s=(A=e.args[1].$)==null?void 0:A.value;if(!s||!W(s))throw new Error("downcast codegen: expected TypeValue as second argument");let l=s.value,u=j(l,n),_=((L=n.types[l.id])==null?void 0:L.cName)||u,c=`__yo_typeid_${be(_)}`;n.typeIdStatics||(n.typeIdStatics=new Map),n.typeIdStatics.has(l.id)||(n.typeIdStatics.set(l.id,c),n.emitter.emitDeclarationLine(`static const char ${c} = 0;`)),n.cIncludes.add("<stdint.h>");let f=`${o}.vtable->__yo_type_id == (uintptr_t)&${c}`,p,m=!1,h="",y="";for(let[,V]of n.dynImpls){if(V.dynType.id!==i.id)continue;if((z(V.concreteType)&&V.concreteType.resolvedConcreteType?V.concreteType.resolvedConcreteType:V.concreteType).id===l.id&&vr(V.dataType)){m=!0,h=((N=n.types[V.dataType.id])==null?void 0:N.cName)||`unknown_box_${V.dataType.id}`,y=be(V.dataType.fields[0].label);break}}if(m){let V=`((${h}*)${o}.data)->${y}`,U=fr(l,n);if(en(l)){let R=oi(l)?"__yo_incr_rc_atomic":"__yo_incr_rc";p=`((${u})${R}((void*)${V}))`}else if(U)p=`${U}((${u})${V})`;else{let R=!1,D=!1,H=l;for(;hr(H)&&H.fields.length===1;)H=H.fields[0].type;R=en(H),D=oi(H),R?p=`((${u})${D?"__yo_incr_rc_atomic":"__yo_incr_rc"}((void*)${V}))`:p=`((${u})${V})`}}else p=`((${u})__yo_incr_rc((void*)${o}.data))`;let g=(x=e.$)==null?void 0:x.type;if(!g||!Be(g))throw new Error("downcast codegen: expected Option enum as result type");if(Gn(g))return`((${f}) ? ${p} : NULL)`;let T=j(g,n),$=Rn(g,"Some",n),C=Rn(g,"None",n),k=`(${T}){ .tag = ${$}, .data = { .Some = { .value = ${p} } } }`,b=`(${T}){ .tag = ${C} }`;return`((${f}) ? ${k} : ${b})`}function up(e,t,n){var g,v,T,$,C,k,b,w,A;if(!((g=e.$)!=null&&g.dynCallTraitValues)||e.$.dynCallTraitValues.length===0)return"/* Error: dyn() call missing trait values */";let r=((T=(v=e.$)==null?void 0:v.runtimeArgExprsInOrder)==null?void 0:T[0])??e.args[0];if(!r)return"/* Error: dyn() requires a value argument */";let i=e.$.type;if(!st(i))return"/* Error: dyn() result type is not DynType */";let o=($=r.$)==null?void 0:$.type;if(!o)return"/* Error: dyn() value has no type */";let a=e.$.dynCallTraitValues;if(!a||a.length===0)return"/* Error: dyn() call missing trait values */";if(!en(o)&&!vr(o))return"/* Error: dyn() requires an object type (use box() for value types) */";let s=vr(o)?o.fields[0].type:o,l=z(s)&&s.resolvedConcreteType?s.resolvedConcreteType:s,u=((C=n.types[i.id])==null?void 0:C.cName)||`__yo_dyn_${i.id}`,c=`${(()=>{var V,U;let L=(V=n.types[l.id])==null?void 0:V.cName;if(L)return L;let N=Kn(l);return(N?(U=n.types[N.id])==null?void 0:U.cName:void 0)||`unknown_${l.id}`})()}_${u}`;n.dynImpls.set(c,{dynType:i,concreteType:s,dataType:o,traitValues:a});let f=q(r,t,n);if((k=r.$)!=null&&k.variableName&&f!==r.$.variableName){let L=Kt(r.$.type,r.$.variableName,n);n.emitter.emitLine(`${t}${L} = ${f};`),f=r.$.variableName}if((b=r.$)!=null&&b.deferredDupExpressions&&r.$.deferredDupExpressions.length>0){Wt(r,t,n);let L=r.$.deferredDupExpressions[0];S(L)&&((w=L.$)!=null&&w.variableName)&&(f=We(L.$.variableName,L.$.env))}let p=(A=e.$)==null?void 0:A.variableName;if(!p)return"/* Error: dyn() expression missing temp variable name */";let m=n,h;if(m.inAsyncStateMachine&&m.stateMachineVariables){for(let[,L]of m.stateMachineVariables)if(L.kind==="local"&&L.id===p){h=`sm->${Xn(L.id,"local",m.stateMachineFieldAliases)}`;break}}let y=`__yo_vtable_${c}`;return h?(n.emitter.emitLine(`${t}${h} = (${u}){`),n.emitter.emitLine(`${t} .data = ${f},`),n.emitter.emitLine(`${t} .vtable = &${y}`),n.emitter.emitLine(`${t}};`),h):(n.emitter.emitLine(`${t}${u} ${p} = {`),n.emitter.emitLine(`${t} .data = ${f},`),n.emitter.emitLine(`${t} .vtable = &${y}`),n.emitter.emitLine(`${t}};`),p)}function _p(e,t,n){return e.args.length!==0?"// Error: __yo_gc_collect requires exactly 0 arguments":"__yo_gc_collect()"}function cp(e,t,n){var a,s,l,u,_,c,f,p,m,h,y,g,v,T,$,C,k,b,w;let r=e.args[0],i=e.args[1],o=n;if(S(r)&&E(r,P.comptime,1)||S(r)&&E(r,P.given,1))return"";if((o.inAsyncStateMachine||o.inEffectStateMachine)&&K(r)&&K(i)){let A=r.token.value,L=i.token.value,N=o.stateMachineVariables&&Array.from(o.stateMachineVariables.values()).some(V=>V.name===A),x=o.stateMachineVariables&&Array.from(o.stateMachineVariables.values()).some(V=>V.name===L);if(A===L&&(N||x))return""}if((a=e.$)!=null&&a.runtimeDestructurings){let A=e.$.runtimeDestructurings,L=q(i,t,n),N=(s=i.$)==null?void 0:s.type;return A.forEach(({label:x,type:V,variableName:U})=>{if(U==="_")return;let R=be(U,V.isExtern==="c"),D=Kt(V,R,n);if(N&&Ae(N)&&N.isNewtype&&N.fields.length===1){let G=N.fields[0];if(G&&G.label===x){n.emitter.emitLine(`${t}${D} = ${L}; // Destructuring ${x} (newtype)`);return}}let H=x.match(/^\d+$/)?`_${x}`:be(x,V.isExtern==="c");if(N&&ut(N)&&!x.match(/^\d+$/)){let G=N.fields.findIndex(Q=>Q.label===x);H=G>=0?`_${G}`:H}let B=N&&en(N)?"->":".";n.emitter.emitLine(`${t}${D} = ${L}${B}${H}; // Destructuring ${x}`)}),""}if(K(r)){let A=((l=r.$)==null?void 0:l.variableName)??r.token.value;if(!((u=r.$)!=null&&u.type))return`// Error: No type information for variable ${A}
|
|
11389
11389
|
`;if((_=r.$)!=null&&_.env){let x=ae(r.$.env,A);if(x.length>0&&x[x.length-1].isCompileTimeOnly||x.length>0&&x[x.length-1].isModuleLevel)return""}let L=!1,N;if((o.inAsyncStateMachine||o.inEffectStateMachine)&&o.stateMachineVariables&&((c=r.$)!=null&&c.env)){let x=ae(r.$.env,A);if(x.length>0){let V=x[x.length-1],U=V.isOwningTheSameRcValueAs?V.isOwningTheSameRcValueAs.id:V.id;o.stateMachineVariables.has(U)&&(L=!0,N=U)}}if(Je(r.$.type))if(S(i)&&E(i,P.array)){let x=q(i,t,n);if(L&&N){let V=Xn(N,"local",o.stateMachineFieldAliases);n.emitter.emitLine(`${t}sm->${V} = ${x};`)}else if(!De(r.$.type)){let V=Kt(r.$.type,A,n);n.emitter.emitLine(`${t}${V} = ${x};`)}}else{let x;if((f=i.$)!=null&&f.variableName){let V=We(i.$.variableName,i.$.env),U=q(i,t,n);if(!L){let R=Kt(i.$.type,V,n);V!==U&&n.emitter.emitLine(`${t}${R} = ${U};`)}x=V}else x=q(i,t,n);if(L&&N){let V=Xn(N,"local",o.stateMachineFieldAliases);n.emitter.emitLine(`${t}sm->${V} = ${x};`)}else if(!De(r.$.type)){let V=Kt(r.$.type,A,n);n.emitter.emitLine(`${t}${V} = ${x};`)}}else{let x,V=S(i)&&((p=i.$)==null?void 0:p.closureFunctionValue)&&((m=i.$)==null?void 0:m.type)&&zn(i.$.type),U=S(i)&&An(i);if((h=i.$)!=null&&h.variableName){let R=We(i.$.variableName,i.$.env),D=We(A,r.$.env);if(R===D){if(x=q(i,t,n),!V&&!U&&((y=i.$)!=null&&y.deferredDupExpressions)&&i.$.deferredDupExpressions.length>0){Wt(i,t,o);let H=i.$.deferredDupExpressions[0];S(H)&&((g=H.$)!=null&&g.variableName)&&(x=We(H.$.variableName,H.$.env))}}else if(K(i)&&R===We(i.token.value,i.$.env)){if(x=q(i,t,n),!V&&!U&&((v=i.$)!=null&&v.deferredDupExpressions)&&i.$.deferredDupExpressions.length>0){Wt(i,t,o);let H=i.$.deferredDupExpressions[0];S(H)&&((T=H.$)!=null&&T.variableName)&&(x=We(H.$.variableName,H.$.env))}}else if(K(i)&&o.currentClosureCaptures&&o.currentClosureCaptures.includes(i.token.value)&&(($=i.$)!=null&&$.env)&&o.currentClosureCaptureFrameLevel!==void 0&&vi(i.token.value,i.$.env,o.currentClosureCaptureFrameLevel)){let H=o.currentClosureType;if(H&&H.isClosure){let B=Object.values(o.types).find(G=>G.type===H);B?x=`((${`${B.cName}_capture`}*)closure_context->data)->${We(i.token.value,i.$.env)}`:x=`closure_context->${We(i.token.value,i.$.env)}`}else x=`closure_context->${We(i.token.value,i.$.env)}`}else{let H=q(i,t,n);if(H.trim()!==R){let B=i.$.convertedRuntimeType||i.$.type,G=Kt(B,R,n);n.emitter.emitLine(`${t}${G} = ${H};`)}if(!V&&!U&&((C=i.$)!=null&&C.deferredDupExpressions)&&i.$.deferredDupExpressions.length>0){Wt(i,t,o);let B=i.$.deferredDupExpressions[0];S(B)&&((k=B.$)!=null&&k.variableName)?x=We(B.$.variableName,B.$.env):x=R}else x=R}}else if(x=q(i,t,n),!V&&!U&&((b=i.$)!=null&&b.deferredDupExpressions)&&i.$.deferredDupExpressions.length>0){Wt(i,t,o);let R=i.$.deferredDupExpressions[0];S(R)&&((w=R.$)!=null&&w.variableName)&&(x=We(R.$.variableName,R.$.env))}if($t(r.$.type)){let R=r.$.type;if(L&&N){let D=Xn(N,"local",o.stateMachineFieldAliases);n.emitter.emitLine(`${t}sm->${D} = ${x};`)}else if(!De(R)){let D=Kt(R,A,n);n.emitter.emitLine(`${t}${D} = ${x};`)}}else if(L&&N){let R=Xn(N,"local",o.stateMachineFieldAliases);n.emitter.emitLine(`${t}sm->${R} = ${x};`)}else{let R=Ht(i.$.env.modulePath,x.trim()),D;if(R&&n.tempVarAsyncStructNames){let H=n.tempVarAsyncStructNames.get(x.trim());H?D=`${H}*`:D=j(r.$.type,n)}else D=j(r.$.type,n);De(r.$.type)||n.emitter.emitLine(`${t}${D} ${We(A,r.$.env)} = ${x};`)}}return""}}var $v=0;function rs(e,t,n,r,i=" "){var o,a,s,l,u,_,c,f,p,m;if(F.__yo_op_add.includes(e))return`((${t[0]}) + (${t[1]}))`;if(F.__yo_op_sub.includes(e))return`((${t[0]}) - (${t[1]}))`;if(F.__yo_op_mul.includes(e))return`((${t[0]}) * (${t[1]}))`;if(F.__yo_op_div.includes(e))return`((${t[0]}) / (${t[1]}))`;if(F.__yo_op_mod.includes(e))return`((${t[0]}) % (${t[1]}))`;if(F.__yo_op_neg.includes(e))return`(-(${t[0]}))`;if(F.__yo_op_eq.includes(e))return`((${t[0]}) == (${t[1]}))`;if(F.__yo_op_neq.includes(e))return`((${t[0]}) != (${t[1]}))`;if(F.__yo_op_lt.includes(e))return`((${t[0]}) < (${t[1]}))`;if(F.__yo_op_lte.includes(e))return`((${t[0]}) <= (${t[1]}))`;if(F.__yo_op_gt.includes(e))return`((${t[0]}) > (${t[1]}))`;if(F.__yo_op_gte.includes(e))return`((${t[0]}) >= (${t[1]}))`;if(F.__yo_op_not.includes(e))return`(!(${t[0]}))`;if(F.__yo_op_bit_and.includes(e))return`((${t[0]}) & (${t[1]}))`;if(F.__yo_op_bit_or.includes(e))return`((${t[0]}) | (${t[1]}))`;if(F.__yo_op_bit_xor.includes(e))return`((${t[0]}) ^ (${t[1]}))`;if(F.__yo_op_bit_complement.includes(e))return`(~(${t[0]}))`;if(F.__yo_op_bit_left_shift.includes(e))return`((${t[0]}) << (${t[1]}))`;if(F.__yo_op_bit_right_shift.includes(e))return`((${t[0]}) >> (${t[1]}))`;if(F.__yo_noop.includes(e))return"";if(F.__yo_return_self.includes(e))return`(*${t[0]})`;if(F.__yo_ms_sleep.includes(e))return Sn(r.targetInfo)?`Sleep(${t[0]})`:`usleep((${t[0]}) * 1000)`;if(F.__yo_decr_rc.includes(e))return`__yo_decr_rc((void*)(${t[0]}))`;if(F.__yo_as.includes(e)&&((o=n.$)!=null&&o.type)){let h=j(n.$.type,r),y=(s=(a=n.args[0])==null?void 0:a.$)==null?void 0:s.type;return y&&Be(y)&&!Fr(y)?`((${h})((${t[0]}).tag))`:`((${h})(${t[0]}))`}else{if(F.__yo_ptr_add.includes(e))return`(${t[0]} + ${t[1]})`;if(F.__yo_ptr_sub.includes(e))return`(${t[0]} - ${t[1]})`;if(F.__yo_ptr_diff.includes(e))return`(${t[0]} - ${t[1]})`;if(F.__yo_ptr_eq.includes(e))return`(${t[0]} == ${t[1]})`;if(F.__yo_ptr_neq.includes(e))return`(${t[0]} != ${t[1]})`;if(F.__yo_ptr_lt.includes(e))return`(${t[0]} < ${t[1]})`;if(F.__yo_ptr_lte.includes(e))return`(${t[0]} <= ${t[1]})`;if(F.__yo_ptr_gt.includes(e))return`(${t[0]} > ${t[1]})`;if(F.__yo_ptr_gte.includes(e))return`(${t[0]} >= ${t[1]})`;if(F.__yo_slice_len.includes(e))return`(${t[0]}.length)`;if(F.__yo_slice_ptr.includes(e))return`(${t[0]}.data)`;if(F.__yo_slice_new.includes(e)&&((l=n.$)!=null&&l.type))return`(${j(n.$.type,r)}){ .data = ${t[0]}, .length = ${t[1]} }`;if(F.__yo_getrandom.includes(e))return`getrandom(${t[0]}, ${t[1]}, ${t[2]})`;if(F.__yo_arc4random_buf.includes(e))return`(arc4random_buf(${t[0]}, ${t[1]}), (void)0)`;if(F.__yo_bcrypt_gen_random.includes(e))return`(int32_t)BCryptGenRandom(NULL, ${t[0]}, ${t[1]}, BCRYPT_USE_SYSTEM_PREFERRED_RNG)`;if(F.__yo_getentropy.includes(e))return`getentropy(${t[0]}, ${t[1]})`;if(F.__yo_maybe_uninit_new.includes(e)&&((u=n.$)!=null&&u.type)){let h=j(n.$.type,r),y=`__yo_uninit_${$v++}`;return r.emitter.emitLine(`${i}${h} ${y};`),y}else return F.__yo_maybe_uninit_as_ptr.includes(e)&&((_=n.$)!=null&&_.type)?`((${j(n.$.type,r)})(${t[0]}))`:F.__yo_maybe_uninit_assume_init.includes(e)?`(${t[0]})`:F.__yo_array_index.includes(e)?`(&((${t[0]})->data[${t[1]}]))`:F.__yo_slice_index.includes(e)?`(&((${t[0]})->data[${t[1]}]))`:F.__yo_array_index_range.includes(e)&&((c=n.$)!=null&&c.type)&&je(n.$.type)?`(&(${j(n.$.type.childType,r)}){ .data = &((${t[0]})->data[(${t[1]}).start]), .length = (${t[1]}).end - (${t[1]}).start })`:F.__yo_array_index_range_inclusive.includes(e)&&((f=n.$)!=null&&f.type)&&je(n.$.type)?`(&(${j(n.$.type.childType,r)}){ .data = &((${t[0]})->data[(${t[1]}).start]), .length = (${t[1]}).end - (${t[1]}).start + 1 })`:F.__yo_slice_index_range.includes(e)&&((p=n.$)!=null&&p.type)&&je(n.$.type)?`(&(${j(n.$.type.childType,r)}){ .data = &((${t[0]})->data[(${t[1]}).start]), .length = (${t[1]}).end - (${t[1]}).start })`:F.__yo_slice_index_range_inclusive.includes(e)&&((m=n.$)!=null&&m.type)&&je(n.$.type)?`(&(${j(n.$.type.childType,r)}){ .data = &((${t[0]})->data[(${t[1]}).start]), .length = (${t[1]}).end - (${t[1]}).start + 1 })`:`/* Unhandled operator ${e} */`}}function fp(e,t,n){var _,c,f,p;let r=e.args[0];if(!r)return"// Error: __yo_iso_extract requires exactly 1 argument";let i=q(r,t,n),o=(_=r.$)==null?void 0:_.type;if(!o||!hn(o))return"// Error: __yo_iso_extract requires an Iso type";let a=j(o,n),s=(c=e.$)==null?void 0:c.type;if(s&&((f=n.isoTypes)!=null&&f.has(a))){let m=n.isoTypes.get(a);m.optionTypeCName||(m.optionTypeCName=j(s,n))}let l=`__yo_iso_extract_${a}(${i})`,u=(p=e.$)==null?void 0:p.variableName;return u&&s?(n.emitter.emitLine(`${t}${j(s,n)} ${u} = ${l};`),u):l}function pp(e,t,n){var s;let r=e.args[0];if(!r)return"// Error: __yo_iso_dispose requires exactly 1 argument";let i=q(r,t,n),o=(s=r.$)==null?void 0:s.type;return!o||!hn(o)?"// Error: __yo_iso_dispose requires an Iso type":`__yo_iso_dispose_${j(o,n)}(${i})`}function Bu(e){var n;let t=(n=e.func.$)==null?void 0:n.value;return W(t)&&hn(t.value)&&e.args.length===1}function dp(e,t,n){var _;if(!Bu(e))return"/* Error: generateIsoTypeCall called on non-Iso type call */";let i=((_=e.func.$)==null?void 0:_.value).value,o=i.childType,a=e.args[0],s=q(a,t,n),l=j(i,n),u=j(o,n);return n.isoTypes||(n.isoTypes=new Map),n.isoTypes.has(l)||n.isoTypes.set(l,{childTypeCName:u,isoType:i}),`__yo_create_iso_${l}(${s})`}function Di(e){return e===""||e==="break"||e==="continue"||e.startsWith("goto")||e.includes("return")}function Mi(e,t,n){var r,i,o,a,s,l,u,_;if(S(e)&&E(e,P.begin)){let c=e.args,f=n,p=f.pendingDeferredDrops,m=((r=e.$)==null?void 0:r.deferredDropExpressions)??[];f.pendingDeferredDrops=[...m,...p??[]];let h=f.consumedVarPendingDrops,y=((i=e.$)==null?void 0:i.consumedVariableDropExpressions)??[];f.consumedVarPendingDrops=[...y,...h??[]];for(let v=0;v<c.length-1;v++){let T=c[v],$=q(T,t,n);if($&&n.emitter.emitLine(`${t}${$};`),Gt((o=T.$)==null?void 0:o.controlFlow))break}let g="";if(c.length>0){let v=c[c.length-1];if((a=v.$)!=null&&a.deferredDupExpressions&&v.$.deferredDupExpressions.length>0){if((s=v.$)!=null&&s.variableName){let $=v.$.variableName;v.$.variableName=void 0;let C=q(v,t,n);v.$.variableName=$;let k=j(v.$.type,n),b=We($,v.$.env);b!==C&&n.emitter.emitLine(`${t}${k} ${b} = ${C};`)}Wt(v,t,n);let T=v.$.deferredDupExpressions[0];S(T)&&((l=T.$)!=null&&l.variableName)?g=We(T.$.variableName,T.$.env):g=q(v,t,n)}else g=q(v,t,n)}return(u=e.$)!=null&&u.deferredDropExpressions&&fn(e,t,n),f.pendingDeferredDrops=p,f.consumedVarPendingDrops=h,g}else return(_=e.$)!=null&&_.deferredDupExpressions&&Wt(e,t,n),q(e,t,n)}function yp(e,t,n){var h,y,g,v,T,$,C,k,b,w,A,L,N;if(!e.$)return'/* "match" expression is not evaluated */';let r=e.$.variableName,i=e.$.type,o=i&&De(i);if(!o&&r){let x=j(i,n);n.emitter.emitLine(`${t}${x} ${r};`)}let a=q(e.args[0],t,n),s=(h=e.args[0].$)==null?void 0:h.type;if(!s)return'// Error: "match" expression requires a valid type';if(e.$.isPrimitiveMatch)return bv(e,t,n,a,s,r,o);let l,u;if(je(s)?(u=s.childType,l=s.tag):en(s)?(u=s,l="ref_semantics"):u=s,!Be(u))return'// Error: "match" expression requires an enum type';if(!((y=n.types[u.id])==null?void 0:y.cName))return`// Error: "match" expression enum type ${u.typeName} has no C name`;let c=Gn(u);if(c){let x=e.args.slice(1),V=null,U=null;for(let R of x)if(S(R)&&E(R,"=>",2)){if(!((v=(g=R.args[0])==null?void 0:g.$)!=null&&v.caseExecuted))continue;let D=R.args[0],H=R.args[1];if(D&&H&&S(D)&&E(D,"."))V={caseBody:H};else{let B=D.func;if(B&&S(B)&&E(B,".")){let G=B.args[0];if(G&&K(G)){let Q=G.token.value;U={caseBody:H,variantName:Q,casePattern:D}}}}}if(n.emitter.emitLine(`${t}if (${l&&l!=="ref_semantics"?"*":""}${a} != NULL) {`),U){let R;if(S(U.casePattern)&&U.casePattern.args.length>0){let G=U.casePattern.args[0];if(G&&K(G)){R=be(G.token.value);let Q=c;n.emitter.emitLine(`${t} ${j(Q,n)} ${R} = ${a};`)}}let D=n;R&&(D.inAsyncStateMachine||D.inEffectStateMachine)&&(D.localShadowedVariables||(D.localShadowedVariables=new Set),D.localShadowedVariables.add(R));let H=Mi(U.caseBody,t+" ",n);R&&D.localShadowedVariables&&D.localShadowedVariables.delete(R);let B=Di(H);if(!o&&r&&!B){let G=H||a;n.emitter.emitLine(`${t} ${r} = ${G};`)}else H&&H!==""&&n.emitter.emitLine(`${t} ${H};`)}if(n.emitter.emitLine(`${t}} else {`),V){let R=Mi(V.caseBody,t+" ",n),D=Di(R);!o&&r&&!D?n.emitter.emitLine(`${t} ${r} = ${R};`):R&&R!==""&&n.emitter.emitLine(`${t} ${R};`)}return n.emitter.emitLine(`${t}}`),o?"":r??""}if(Fr(u)){n.emitter.emitLine(`${t}switch (${l&&l!=="ref_semantics"?"*":""}${a}) {`);let x=n.insideMatch;n.insideMatch=!0;let V=e.args.slice(1);for(let U=0;U<V.length;U++){let R=V[U];if(S(R)&&E(R,"=>",2)){if(!(($=(T=R.args[0])==null?void 0:T.$)!=null&&$.caseExecuted))continue;let D=R.args[0],H=R.args[1];if(D&&H&&K(D)&&D.token.value==="_"){n.emitter.emitLine(`${t}default: {`);let B=Mi(H,t+" ",n);!o&&r&&B&&!Di(B)?n.emitter.emitLine(`${t} ${r} = ${B};`):B&&n.emitter.emitLine(`${t} ${B};`),n.emitter.emitLine(`${t} break;`),n.emitter.emitLine(`${t}}`)}else if(D&&H&&S(D)&&E(D,".",1)){let B=D.args[0].token.value,G=Rn(u,B,n);n.emitter.emitLine(`${t}case ${G}: {`);let Q=Mi(H,t+" ",n);!o&&r&&Q&&!Di(Q)?n.emitter.emitLine(`${t} ${r} = ${Q};`):Q&&n.emitter.emitLine(`${t} ${Q};`),n.emitter.emitLine(`${t} break;`),n.emitter.emitLine(`${t}}`)}}}return n.insideMatch=x,n.emitter.emitLine(`${t}}`),o?"":r??""}n.emitter.emitLine(`${t}switch (${l==="ref_semantics"||l?a+"->tag":"("+a+").tag"}) {`);let p=n.insideMatch;n.insideMatch=!0;let m=e.args.slice(1);for(let x=0;x<m.length;x++){let V=m[x];if(S(V)&&E(V,"=>",2)){if(!((k=(C=V.args[0])==null?void 0:C.$)!=null&&k.caseExecuted))continue;let U=V.args[0],R=V.args[1];if(U&&R&&K(U)&&U.token.value==="_"){n.emitter.emitLine(`${t}default: {`);let D=Mi(R,t+" ",n);!o&&r&&D&&!Di(D)?n.emitter.emitLine(`${t} ${r} = ${D};`):D&&n.emitter.emitLine(`${t} ${D};`),n.emitter.emitLine(`${t} break;`),n.emitter.emitLine(`${t}}`)}else if(U&&R&&S(U)&&U.func.tag==="Atom"&&U.func.token.value==="."&&U.args.length>=1){let D=U.args[0].token.value,H=Rn(u,D,n);if(n.emitter.emitLine(`${t}case ${H}: {`),U.args.length>1){let G=u.variants.find(Q=>Q.name===D);if(G&&G.fields){let Q=U.args.slice(1);if(Q.some(J=>S(J)&&E(J,":",2))){for(let J of Q)if(S(J)&&E(J,":",2)){let se=J.args[0],ve=J.args[1];if(!K(se))continue;let re=se.token.value,ce=G.fields.find(we=>we.label===re);if(!ce||De(ce.type))continue;if(K(ve)){let we=ve.token.value;if(we!=="_"){let Se=be(we),Ve=be(re),de=j(ce.type,n),ee=l==="ref_semantics"||l?"->":".";n.emitter.emitLine(`${t} ${de} ${Se} = ${a}${ee}data.${D}.${Ve};`);let fe=n;if((fe!=null&&fe.inAsyncStateMachine||fe!=null&&fe.inEffectStateMachine)&&fe.stateMachineVariables){let me;if((b=ve.$)!=null&&b.env){let Le=ae(ve.$.env,we);Le.length>0&&(me=Le[Le.length-1].id)}if(me&&fe.stateMachineVariables.has(me)){let Le=Xn(me,"local",fe.stateMachineFieldAliases);n.emitter.emitLine(`${t} sm->${Le} = ${Se};`)}}}}}}else for(let J=0;J<Q.length&&J<G.fields.length;J++){let se=Q[J],ve=G.fields[J];if(K(se)&&ve){if(De(ve.type))continue;let re=se.token.value;if(re!=="_"){let ce=be(re),we=be(ve.label),Se=j(ve.type,n),Ve=l==="ref_semantics"||l?"->":".";n.emitter.emitLine(`${t} ${Se} ${ce} = ${a}${Ve}data.${D}.${we};`);let de=n;if((de!=null&&de.inAsyncStateMachine||de!=null&&de.inEffectStateMachine)&&de.stateMachineVariables){let ee;if((w=se.$)!=null&&w.env){let fe=ae(se.$.env,re);fe.length>0&&(ee=fe[fe.length-1].id)}ee&&de.stateMachineVariables.has(ee)&&n.emitter.emitLine(`${t} sm->${Xn(ee,"local",de.stateMachineFieldAliases)} = ${ce};`)}}}}}}if(S(R)&&E(R,"=>",2)){let G=R.args[0];n.emitter.emitLine(`${t} ${j(s,n)} ${be(G.token.value)} = ${a};`),R=R.args[1]}let B=Mi(R,t+" ",n);!o&&r&&B&&!Di(B)?n.emitter.emitLine(`${t} ${r} = ${B};`):B&&n.emitter.emitLine(`${t} ${B};`),n.emitter.emitLine(`${t} break;`),n.emitter.emitLine(`${t}}`)}else if(U&&R&&S(U)&&S(U.func)&&U.func.func.tag==="Atom"&&U.func.func.token.value==="."&&U.func.args.length===1){let D=U.func.args[0].token.value,H=Rn(u,D,n),B=U.args;n.emitter.emitLine(`${t}case ${H}: {`);let G=u.variants.find(Y=>Y.name===D);if(G&&G.fields&&B.length>0)if(B.some(J=>S(J)&&E(J,":",2))){for(let J of B)if(S(J)&&E(J,":",2)){let se=J.args[0],ve=J.args[1];if(!K(se))continue;let re=se.token.value,ce=G.fields.find(we=>we.label===re);if(!ce)continue;if(K(ve)){let we=ve.token.value;if(we!=="_"){let Se=be(we);if(De(ce.type))n.emitter.emitLine(`${t} // ${Se} is unit type (no value)`);else{let Ve=be(re),de=j(ce.type,n),ee=l==="ref_semantics"||l?"->":".";n.emitter.emitLine(`${t} ${de} ${Se} = ${a}${ee}data.${D}.${Ve};`);let fe=n;if((fe!=null&&fe.inAsyncStateMachine||fe!=null&&fe.inEffectStateMachine)&&fe.stateMachineVariables){let me;if((A=ve.$)!=null&&A.env){let Le=ae(ve.$.env,Se);Le.length>0&&(me=Le[Le.length-1].id)}me&&fe.stateMachineVariables.has(me)&&n.emitter.emitLine(`${t} sm->${Xn(me,"local",fe.stateMachineFieldAliases)} = ${Se};`)}}}}}}else for(let J=0;J<Math.min(B.length,G.fields.length);J++){let se=B[J],ve=G.fields[J];if(se.tag==="Atom"&&ve){let re=se.token.value;if(re!=="_"){let ce=be(re);if(De(ve.type))n.emitter.emitLine(`${t} // ${ce} is unit type (no value)`);else{let we=be(ve.label),Se=j(ve.type,n),Ve=l==="ref_semantics"||l?"->":".";n.emitter.emitLine(`${t} ${Se} ${ce} = ${a}${Ve}data.${D}.${we};`);let de=n;if((de!=null&&de.inAsyncStateMachine||de!=null&&de.inEffectStateMachine)&&de.stateMachineVariables){let ee;if((L=se.$)!=null&&L.env){let fe=ae(se.$.env,re);fe.length>0&&(ee=fe[fe.length-1].id)}ee&&de.stateMachineVariables.has(ee)&&n.emitter.emitLine(`${t} sm->${Xn(ee,"local",de.stateMachineFieldAliases)} = ${ce};`)}}}}}if(S(R)&&E(R,"=>",2)){let Y=R.args[0];n.emitter.emitLine(`${t} ${j(s,n)} ${be(Y.token.value)} = ${a};`),R=R.args[1]}let Q=Mi(R,t+" ",n);!o&&r&&Q&&!Di(Q)?n.emitter.emitLine(`${t} ${r} = ${Q};`):Q&&n.emitter.emitLine(`${t} ${Q};`),n.emitter.emitLine(`${t} break;`),n.emitter.emitLine(`${t}}`)}}}return n.insideMatch=p,n.emitter.emitLine(`${t}}`),(N=e.$)!=null&&N.deferredDropExpressions&&fn(e,t,n),o?"":r??""}function Cv(e){return S(e)?E(e,"|",2):!1}function Gu(e){if(!Cv(e))return[e];let t=e,n=t.args[0],r=t.args[1];return[...Gu(n),...Gu(r)]}function mp(e){if(e!==void 0){if(ht(e))return String(e.value);if(Ct(e))return e.value?"true":"false"}}function bv(e,t,n,r,i,o,a){var u,_,c,f,p;let s=n.insideMatch;n.insideMatch=!0,n.emitter.emitLine(`${t}switch (${r}) {`);let l=e.args.slice(1);for(let m=0;m<l.length;m++){let h=l[m];if(S(h)&&E(h,"=>",2)){if(!((_=(u=h.args[0])==null?void 0:u.$)!=null&&_.caseExecuted))continue;let y=h.args[0],g=h.args[1];if(!y||!g)continue;if(K(y)&&y.token.value==="_"){n.emitter.emitLine(`${t}default: {`);let C=Mi(g,t+" ",n);!a&&o&&C&&!Di(C)?n.emitter.emitLine(`${t} ${o} = ${C};`):C&&n.emitter.emitLine(`${t} ${C};`),n.emitter.emitLine(`${t} break;`),n.emitter.emitLine(`${t}}`);continue}let v=Gu(y),T=(c=y.$)==null?void 0:c.primitivePatternValues;if(T&&T.length>0)for(let C of T){let k=mp(C);k!==void 0&&n.emitter.emitLine(`${t}case ${k}:`)}else for(let C of v){let k=(f=C.$)==null?void 0:f.value,b=mp(k);b!==void 0&&n.emitter.emitLine(`${t}case ${b}:`)}n.emitter.emitLine(`${t}{`);let $=Mi(g,t+" ",n);!a&&o&&$&&!Di($)?n.emitter.emitLine(`${t} ${o} = ${$};`):$&&n.emitter.emitLine(`${t} ${$};`),n.emitter.emitLine(`${t} break;`),n.emitter.emitLine(`${t}}`)}}return n.insideMatch=s,n.emitter.emitLine(`${t}}`),(p=e.$)!=null&&p.deferredDropExpressions&&fn(e,t,n),a?"":o??""}function gp(e,t,n){var r,i;if((r=e.$)!=null&&r.runtimeDestructurings&&e.$.runtimeDestructurings.length>0){let o=e.args[0];if(!o||!((i=o.$)!=null&&i.type))return"// Error: open expression has no argument or type";let a=o.$.type,s=o.$.value;if(Ae(a)&&s===void 0){let l=q(o,t,n),u=e.$.runtimeDestructurings;for(let _ of u){let c=j(_.type,n),f=be(_.variableName),p=be(_.label);n.emitter.emitLine(`${t}${c} ${f} = ${l}.${p};`)}}}return""}function hp(e,t,n,r,i,o){let a=t.callType?pn(t.callType):[],s=a.length>0?`, ${a.map(()=>"NULL").join(", ")}`:"",u=`__yo_spawn_wrapper_${mt(o)}`,_="";_+=` ${e}(closure${s});
|
|
11390
11390
|
`;let c=r&&Ae(r)?Wr(r,i):void 0;if(c&&r&&Ae(r)){let f=t.consumedCaptures;if(f&&f.length>0){let p=r;for(let m of f){let h=p.fields.find(y=>y.label===m);h&&it(h.type)&&(_+=` ((${n}*)closure)->${m} = NULL;
|
|
@@ -11393,10 +11393,10 @@ static void __yo_dispose_dispatch(void* ptr) {
|
|
|
11393
11393
|
`,i.emitter.emitDeclarationLine(`
|
|
11394
11394
|
// Spawn wrapper: handles RC cleanup for thread-spawned closures
|
|
11395
11395
|
static void ${u}(void* closure) {
|
|
11396
|
-
${_}}`),u}function vp(e,t,n){var g,v,T,$,C,k;let r=(g=e.$)==null?void 0:g.runtimeArgExprsInOrder;if(!r||r.length!==1)return"/* Error: __yo_thread_spawn requires exactly 1 argument */";let i=r[0],o=(v=i.$)==null?void 0:v.type;if(!o)return"/* Error: __yo_thread_spawn argument has no type */";let a,s;if(z(o)){let b=o;b.resolvedConcreteType&&(a=b.resolvedConcreteType.id,s=b.resolvedConcreteType)}else Ae(o)&&(a=o.id,s=o);if(!a||!s)return"/* Error: __yo_thread_spawn could not determine concrete closure type */";let l=n.implClosureCallMap.get(a);if(!l)return`/* Error: __yo_thread_spawn could not find closure function for type ${a} */`;let u=l.functionCName,_=j(s,n),c=hp(u,l,_,s,n,((T=e.$)==null?void 0:T.env.modulePath)??""),f=q(i,t,n),p=($=i.$)!=null&&$.variableName?We(i.$.variableName,i.$.env):f,m=`_thread_closure_data_${mt(((C=e.$)==null?void 0:C.env.modulePath)??"")}`;n.emitter.emitLine(`${t}${_}* ${m} = (${_}*)__yo_malloc(sizeof(${_}));`),n.emitter.emitLine(`${t}*${m} = ${p};`);let h=fr(s,n);h&&n.emitter.emitLine(`${t}${h}(*${m});`);let y=(k=e.$)==null?void 0:k.variableName;return y?(n.emitter.emitLine(`${t}__yo_thread_t ${y} = __yo_thread_spawn(${c}, ${m});`),y):`__yo_thread_spawn(${c}, ${m})`}function Tp(e,t,n){var y,g,v,T,$;let r=(y=e.$)==null?void 0:y.runtimeArgExprsInOrder;if(!r||r.length!==1)return"/* Error: __yo_worker_spawn requires exactly 1 argument */";let i=r[0],o=(g=i.$)==null?void 0:g.type;if(!o)return"/* Error: __yo_worker_spawn argument has no type */";let a,s;if(z(o)){let C=o;C.resolvedConcreteType&&(a=C.resolvedConcreteType.id,s=C.resolvedConcreteType)}else Ae(o)&&(a=o.id,s=o);if(!a||!s)return"/* Error: __yo_worker_spawn could not determine concrete closure type */";let l=n.implClosureCallMap.get(a);if(!l)return`/* Error: __yo_worker_spawn could not find closure function for type ${a} */`;let u=l.functionCName,_=j(s,n),c=hp(u,l,_,s,n,((v=e.$)==null?void 0:v.env.modulePath)??""),f=q(i,t,n),p=(T=i.$)!=null&&T.variableName?We(i.$.variableName,i.$.env):f,m=`_worker_closure_data_${mt((($=e.$)==null?void 0:$.env.modulePath)??"")}`;n.emitter.emitLine(`${t}${_}* ${m} = (${_}*)__yo_malloc(sizeof(${_}));`),n.emitter.emitLine(`${t}*${m} = ${p};`);let h=fr(s,n);return h&&n.emitter.emitLine(`${t}${h}(*${m});`),n.emitter.emitLine(`${t}__yo_worker_spawn(${c}, ${m});`),""}function Ep(e,t,n){let r=e.args[0];return r?`__yo_thread_set_maximum_threads(${q(r,t,n)})`:"// Error: __yo_thread_set_maximum_threads requires exactly 1 argument"}function $p(e,t){let n=t;if(!(n.inAsyncStateMachine||n.inEffectStateMachine)||!n.stateMachineVariables)return e;for(let[r,i]of n.stateMachineVariables)if(i.name===e)return`sm->${i.kind==="outer"?`__capture.${i.name}`:`var_${r}`}`;return e}function Cr(e,t,n){let r=n;if(!(r.inAsyncStateMachine||r.inEffectStateMachine)||!r.stateMachineVariables)return;let i=r.stateMachineVariables.get(e);if(!i){for(let[,o]of r.stateMachineVariables)if(o.name===e){i=o;break}}if(i&&i.kind!=="outer"){if(i.type&&at(i.type))return;let o=`var_${i.id}`,a=be(e);n.emitter.emitLine(`${t}sm->${o} = ${a};`)}}function kp(e,t,n){var o,a,s,l,u,_,c,f,p,m,h,y,g,v,T,$,C,k,b,w,A,L,N,x,V,U,R,D,H,B,G,Q,Y,J,se,ve,re,ce,we,Se,Ve,de,ee,fe,me,Le,qe,dt,kt,Rt,Ze,Tt,Jt,At,gt,nt,Ft,qt,Et,Lt,nn,te,pe,$e,ie,_e,ye,Re,Ke,Pe,Z;if(((o=e.$)==null?void 0:o.value)!==void 0&&!Ie(e.$.value))return(a=e.$)!=null&&a.deferredDropExpressions&&fn(e,t,n),De(e.$.type)?"":Yn(e.$.value,n,e);let r=(s=e.func.$)==null?void 0:s.value,i=((l=e.func.$)==null?void 0:l.type)??(he(r)?r.specializedType??r.type:void 0);if(ne(i)){let X=(u=e.$)==null?void 0:u.runtimeArgExprsInOrder;if(X){let ge=!1;if(S(e.func)&&E(e.func,".",2)){let Ee=e.func.args[0],Oe=(_=Ee==null?void 0:Ee.$)==null?void 0:_.type;Oe&&st(Oe)&&(ge=!0)}let Ce=X.map((Ee,Oe)=>{var Ue,ze,Qe,Ye,Ne,et,ke,rt,ft;if((Ue=Ee.$)!=null&&Ue.variableName&&((ze=Ee.$)!=null&&ze.type)){let yt=n,Vt=yt.currentClosureCaptures&&yt.currentClosureCaptures.includes(Ee.$.variableName)&&K(Ee)&&Ee.$.env&&yt.currentClosureCaptureFrameLevel!==void 0&&vi(Ee.token.value,Ee.$.env,yt.currentClosureCaptureFrameLevel),xt=q(Ee,t,n),Xt=!1;if(K(Ee)&&Ee.$.env&&Ee.$.variableName){let nr=ae(Ee.$.env,Ee.$.variableName);nr.length>0&&nr[nr.length-1].isCompileTimeOnly&&(Xt=!0)}let _n=(yt.inAsyncStateMachine||yt.inEffectStateMachine)&&xt.startsWith("sm->"),Qn=!1;if(xt&&xt!==Ee.$.variableName&&!Vt&&!_n&&!Xt){let nr=We(Ee.$.variableName,Ee.$.env);if(xt!==nr){let sr=Ee.$.convertedRuntimeType||Ee.$.type,$i=Kt(sr,Ee.$.variableName,n);n.emitter.emitLine(`${t}${$i} = ${xt};`),Qn=!0,Cr(Ee.$.variableName,t,n)}}let Yr=Qn?Ee.$.variableName:xt;if((Qe=Ee.$)!=null&&Qe.deferredDupExpressions&&Ee.$.deferredDupExpressions.length>0){let nr=new Set;(Ye=Ee.$)!=null&&Ye.variableName&&nr.add(We(Ee.$.variableName,Ee.$.env)),xt&&nr.add(xt),K(Ee)&&nr.add(We(Ee.token.value,Ee.$.env));let sr=Ee.$.deferredDupExpressions.find($i=>{var io;let Ui=Fl($i);return Ui?nr.has(We(Ui,(io=$i.$)==null?void 0:io.env)):!1});sr&&(Wt(Ee,t,yt),S(sr)&&((Ne=sr.$)!=null&&Ne.variableName)&&(Yr=We(sr.$.variableName,sr.$.env)))}if(ge&&Oe===0){if(S(e.func)&&E(e.func,".",2)){let sr=e.func.args[0],$i=(et=sr==null?void 0:sr.$)==null?void 0:et.type,Ui=e.func.args[1];if(K(Ui)&&st($i)){let io=Ui.token.value;if($i.trait.fields.find(Zl=>Zl.label===io))return _n?xt:be(Yr,Ee.$.type.isExtern==="c")}}let nr=(ke=Ee.$)==null?void 0:ke.type;return nr&&je(nr)?_n?`${xt}->data`:`${be(Yr,Ee.$.type.isExtern==="c")}->data`:_n?`(${xt}).data`:`(${be(Yr,Ee.$.type.isExtern==="c")}).data`}else return Vt||_n||Xt?xt:be(Yr,Ee.$.type.isExtern==="c")}else if(ge&&Oe===0){let yt=q(Ee,t,n);if(S(e.func)&&E(e.func,".",2)){let xt=e.func.args[0],Xt=(rt=xt==null?void 0:xt.$)==null?void 0:rt.type,_n=e.func.args[1];if(K(_n)&&st(Xt)){let Qn=_n.token.value;if(Xt.trait.fields.find(nr=>nr.label===Qn))return yt}}let Vt=(ft=Ee.$)==null?void 0:ft.type;return Vt&&je(Vt)?`(${yt})->data`:`(${yt}).data`}else return q(Ee,t,n)}),He=Ce.join(", ");if(i.isExtern==="yo"&&i.externName){let Ee=i.externName;return ko.includes(Ee)?rs(Ee,Ce,e,n,t):Ee==="__yo_thread_spawn"?vp(e,t,n):Ee==="__yo_worker_spawn"?Tp(e,t,n):De(i.return.type)?(n.emitter.emitLine(`${t}${Ee}(${He});`),(c=e.$)!=null&&c.deferredDropExpressions&&fn(e,t,n),""):`${Ee}(${He})`}{let Ee=n;if((f=Ee.currentEvidenceParams)!=null&&f.size){let Oe=(p=e.func.token)==null?void 0:p.value,Ue;if(Oe==="."&&S(e.func)&&E(e.func,".",2)){let ze=e.func.args[1];ze&&K(ze)&&(Oe=ze.token.value);let Qe=e.func.args[0];if(Qe&&K(Qe))Ue=Qe.token.value;else if(Qe&&S(Qe)&&E(Qe,".",2)){let Ye=Qe.args[0];Ye&&K(Ye)&&(Ue=Ye.token.value)}}if(Oe&&Oe!=="."){for(let ze of Ee.currentEvidenceParams.values())if(ze.fieldLabel===Oe||ze.implicitLabel===Oe||ze.fieldPath[ze.fieldPath.length-1]===Oe){if(Ue&&Ue!==ze.implicitLabel)continue;return bp(ze.cParamName,i,Ce,X,e,t,Ee,ze)}}}}if(he(r)){let Ee=gi(r);if(Ee)return rs(Ee,Ce,e,n,t);let Oe=r.specializedType??r.type,Ue=n;if(Ue.currentEvidenceParams&&r.isModuleEffectMember){let Qe,Ye=((m=e.func.$)==null?void 0:m.env)??((h=e.$)==null?void 0:h.env);if(Ye)for(let Ne of Ue.currentEvidenceParams.values()){let et=ae(Ye,Ne.implicitLabel),ke=et[et.length-1],rt=(y=ke==null?void 0:ke.value)==null?void 0:y[0];if(rt&&wt(rt)){let ft=rt,yt=!0;for(let Vt=0;Vt<Ne.fieldPath.length-1;Vt++){let xt=Ne.fieldPath[Vt],Xt=ft.type.fields.findIndex(_n=>_n.label===xt);if(Xt>=0&&ft.fields[Xt]&&wt(ft.fields[Xt]))ft=ft.fields[Xt];else{yt=!1;break}}if(yt){let Vt=Ne.fieldPath[Ne.fieldPath.length-1],xt=ft.type.fields.findIndex(Xt=>Xt.label===Vt);if(xt>=0){let Xt=ft.fields[xt];if(Xt&&he(Xt)&&Xt.funcId===r.funcId){Qe=Ne;break}}}}}if(Qe){let Ne=Qe.cParamName;return bp(Ne,Oe,Ce,X,e,t,Ue,Qe)}}let ze=(g=n.functions[r.funcId])==null?void 0:g.cName;if(ze){let Qe=r.specializedType??r.type,Ye=pn(Qe);if(Ye.length===0&&r.specializedType){let ke=pn(r.type);ke.length>0&&ke.some(rt=>rt.fieldFunctionType.forallParameters&&rt.fieldFunctionType.forallParameters.length>0)&&(Ye=ke)}if(Ye.length>0){let{args:ke,isHandlerInstallation:rt}=Wu(Ye,r,e,n);if(ke.length>0){let ft=He?`${He}, ${ke.join(", ")}`:ke.join(", ");return qu(ze,ft,Oe,e,X,t,n,rt)}}let Ne=r.isControlFunction||r.isModuleEffectMember||(($=(T=(v=r.body)==null?void 0:v.$)==null?void 0:T.effectAnalysis)==null?void 0:$.hasEffects),et=!1;if(Ne){if(r.isControlFunction||r.isModuleEffectMember){let ke=((k=(C=e.func)==null?void 0:C.$)==null?void 0:k.env)??((b=e.$)==null?void 0:b.env);if(ke){let rt=ja(ke,ft=>{var yt;return ft.isImplicit===!0&&he((yt=ft.value)==null?void 0:yt[0])&&ft.value[0].funcId===r.funcId});rt>=0&&rt>ke.functionDeclarationFrameLevel&&((w=ke.frames[rt])!=null&&w.isBeginBlockFrame)&&(et=!0)}}else if(r.specializedType){let ke=pn(r.type);if(ke.length>0){let rt=((L=(A=e.func)==null?void 0:A.$)==null?void 0:L.env)??((N=e.$)==null?void 0:N.env);if(rt)for(let ft of ke){let yt=ja(rt,Vt=>Vt.isImplicit===!0&&(Vt.name===ft.implicitLabel||Vt.name===ft.fieldLabel));if(yt>=0&&yt>rt.functionDeclarationFrameLevel&&((x=rt.frames[yt])!=null&&x.isBeginBlockFrame)){et=!0;break}}}}}if(De(Oe.return.type))return n.emitter.emitLine(`${t}${ze}(${He});`),(V=e.$)!=null&&V.deferredDropExpressions&&fn(e,t,n),Ne&&Cp(t,n,et,e),"";{let ke=(U=e.$)==null?void 0:U.variableName;if(ke){let rt=((R=r.specializedType)==null?void 0:R.return.type)??Oe.return.type,ft=(D=e.$)==null?void 0:D.type,yt=ft&&at(ft),Vt=rt&&at(rt),xt;if(yt&&Vt){let _n=r.body;if(_n&&E(_n,"begin")){let Qn=_n.args;if(Qn.length>0){let Yr=Qn[Qn.length-1];An(Yr)&&(_n=Yr)}}if(_n&&An(_n)&&((H=_n.$)!=null&&H.asyncStateMachineStructName)){let Qn=_n.$.asyncStateMachineStructName;xt=`${Qn}*`,n.tempVarAsyncStructNames||(n.tempVarAsyncStructNames=new Map),n.tempVarAsyncStructNames.set(ke,Qn)}else ft&&z(ft)&&ft.resolvedConcreteType?xt=j(ft,n):xt=j(rt,n)}else xt=j(rt??ft,n);let Xt=n;return Xt.declaredTempVars||(Xt.declaredTempVars=new Set),Xt.declaredTempVars.has(ke)||(Xt.declaredTempVars.add(ke),n.emitter.emitLine(`${t}${xt} ${ke} = ${ze}(${He});`)),Cr(ke,t,n),(B=e.$)!=null&&B.deferredDropExpressions&&fn(e,t,n),Ne&&Cp(t,n,et,e),ke}else return`// Error: Regular function call returns ${j(((G=r.specializedType)==null?void 0:G.return.type)??Oe.return.type,n)} but no temp variable assigned`}}}else{let Ee=n.externFunctions[i.id];if(Ee){let Oe=Ee.cName;return(Q=e.$)!=null&&Q.deferredDropExpressions&&fn(e,t,n),`${Oe}(${He})`}else{let Oe=q(e.func,t,n);if(r&&ne(r.type)){let ke=pn(r.type);if(ke.length>0){let{args:rt,isHandlerInstallation:ft}=Wu(ke,r,e,n);if(rt.length>0){let yt=He?`${He}, ${rt.join(", ")}`:rt.join(", ");return qu(Oe,yt,i,e,X,t,n,ft)}}}let Ue=((Y=e.$)==null?void 0:Y.type)??i.return.type,ze=j(Ue,n),Qe=i.parameters.filter(ke=>!ke.isCompileTimeOnly).map(ke=>j(ke.type,n)),Ye=`((${ze} (*)(${Qe.join(", ")}))${Oe})`,Ne=n,et=Oe.includes("__capture.")&&!!Ne.inAsyncStateMachine;if(et&&n.emitter.emitLine(`${t}__yo_effect_escaped = 0;`),De(i.return.type)||De(Ue)){if(n.emitter.emitLine(`${t}${Ye}(${He});`),(J=e.$)!=null&&J.deferredDropExpressions&&fn(e,t,n),et){if(n.emitter.emitLine(`${t}if (__yo_effect_escaped) {`),X){for(let ke of X)if((se=ke.$)!=null&&se.variableName&&((ve=ke.$)!=null&&ve.type)&&it(ke.$.type)){let rt=$p(be(ke.$.variableName),n),ft=Vi(rt,ke.$.type,n);ft&&(n.emitter.emitLine(`${t} ${ft};`),n.emitter.emitLine(`${t} memset(&${rt}, 0, sizeof(${rt}));`))}}Ar({emitter:n.emitter,indent:t+" ",resultCode:void 0,debugLabel:void 0}),n.emitter.emitLine(`${t}}`)}return""}else{let ke=(re=e.$)==null?void 0:re.variableName;if(ke){let rt=i.return.type,ft=(ce=e.$)==null?void 0:ce.type,yt=ft&&rt&&at(ft)&&at(rt)?rt:ft??rt,Vt=n;if(Vt.declaredTempVars||(Vt.declaredTempVars=new Set),Vt.declaredTempVars.has(ke)||(Vt.declaredTempVars.add(ke),n.emitter.emitLine(`${t}${j(yt,n)} ${ke} = ${Ye}(${He});`)),Cr(ke,t,n),(we=e.$)!=null&&we.deferredDropExpressions&&fn(e,t,n),et){if(n.emitter.emitLine(`${t}if (__yo_effect_escaped) {`),X){for(let xt of X)if((Se=xt.$)!=null&&Se.variableName&&((Ve=xt.$)!=null&&Ve.type)&&it(xt.$.type)){let Xt=$p(be(xt.$.variableName),n),_n=Vi(Xt,xt.$.type,n);_n&&(n.emitter.emitLine(`${t} ${_n};`),n.emitter.emitLine(`${t} memset(&${Xt}, 0, sizeof(${Xt}));`))}}Ar({emitter:n.emitter,indent:t+" ",resultCode:void 0,debugLabel:void 0}),n.emitter.emitLine(`${t}}`)}return ke}else return`// Error: Function parameter call returns ${j(i.return.type,n)} but no temp variable assigned`}}}}}else if(i&&zn(i)){let X=i,ge=Kn(X),Ce=st(X);{let He=ge.isFn.callType,Ee=(de=e.$)==null?void 0:de.runtimeArgExprsInOrder;if(Ee){let Oe=n;for(let Ne of Ee)if((ee=Ne.$)!=null&&ee.variableName&&((fe=Ne.$)!=null&&fe.type)){let et=Oe.currentClosureCaptures&&Oe.currentClosureCaptures.includes(Ne.$.variableName)&&K(Ne)&&Ne.$.env&&Oe.currentClosureCaptureFrameLevel!==void 0&&vi(Ne.token.value,Ne.$.env,Oe.currentClosureCaptureFrameLevel),ke=q(Ne,t,n),rt=!1;if(K(Ne)&&Ne.$.env&&Ne.$.variableName){let yt=ae(Ne.$.env,Ne.$.variableName);yt.length>0&&yt[yt.length-1].isCompileTimeOnly&&(rt=!0)}let ft=(Oe.inAsyncStateMachine||Oe.inEffectStateMachine)&&ke.startsWith("sm->");if(ke&&ke!==Ne.$.variableName&&!et&&!ft&&!rt){let yt=Ne.$.convertedRuntimeType||Ne.$.type,Vt=Kt(yt,Ne.$.variableName,n);n.emitter.emitLine(`${t}${Vt} = ${ke};`),Cr(Ne.$.variableName,t,n)}}let Ue=q(e.func,t,n),ze=Ee.map(Ne=>{var et,ke,rt,ft;if((et=Ne.$)!=null&&et.variableName&&((ke=Ne.$)!=null&&ke.type)){if(Oe.currentClosureCaptures&&Oe.currentClosureCaptures.includes(Ne.$.variableName)&&K(Ne)&&Ne.$.env&&Oe.currentClosureCaptureFrameLevel!==void 0&&vi(Ne.token.value,Ne.$.env,Oe.currentClosureCaptureFrameLevel))return q(Ne,t,n);{let Vt=We(Ne.$.variableName,Ne.$.env),xt=(Oe.inAsyncStateMachine||Oe.inEffectStateMachine)&&Vt.startsWith("sm->"),Xt=Vt;if((rt=Ne.$)!=null&&rt.deferredDupExpressions&&Ne.$.deferredDupExpressions.length>0){Wt(Ne,t,Oe);let _n=Ne.$.deferredDupExpressions[0];S(_n)&&((ft=_n.$)!=null&&ft.variableName)&&(Xt=We(_n.$.variableName,_n.$.env))}return xt?Vt:Xt}}else return q(Ne,t,n)}),Qe;if(Ce){let Ne=[`(${Ue}).data`,...ze];Qe=`(${Ue}).vtable->call(${Ne.join(", ")})`}else{let Ne;if(z(X)){let ke=X;ke.resolvedConcreteType&&(Ne=ke.resolvedConcreteType.id)}let et=Ne?n.implClosureCallMap.get(Ne):void 0;if(et){let ke=pn(He);if(ke.length>0){let{args:ft,isHandlerInstallation:yt}=Wu(ke,{},e,Oe);if(ft.length>0){let Vt=[`&(${Ue})`,...ze,...ft];return qu(et.functionCName,Vt.join(", "),He,e,Ee,t,Oe,yt)}}let rt=[`&(${Ue})`,...ze];Qe=`${et.functionCName}(${rt.join(", ")})`}else{let ke=[`(${Ue}).data`,...ze];Qe=`(${Ue}).call(${ke.join(", ")})`}}let Ye=He.return.type;if(De(Ye))return n.emitter.emitLine(`${t}${Qe};`),(me=e.$)!=null&&me.deferredDropExpressions&&fn(e,t,n),"";{let Ne=(Le=e.$)==null?void 0:Le.variableName;return Ne?(n.emitter.emitLine(`${t}${j(Ye,n)} ${Ne} = ${Qe};`),Cr(Ne,t,n),(qe=e.$)!=null&&qe.deferredDropExpressions&&fn(e,t,n),Ne):`// Error: Closure call returns ${j(Ye,n)} but no temp variable assigned`}}else return"// Error: No runtime args found for closure call"}}else if(W(r))if(Ae(r.value)){let X=r.value,ge=(dt=e.$)==null?void 0:dt.runtimeArgExprsInOrder,Ce=(kt=n.types[X.id])==null?void 0:kt.cName,He=X.fields.map(Oe=>Oe.label),Ee=(Rt=e.$)==null?void 0:Rt.variableName;if(ge&&Ce&&He.length===ge.length){if(X.isNewtype&&X.fields.length===1){let Oe=ge[0],Ue=q(Oe,t,n),ze=Ue;if((Ze=Oe.$)!=null&&Ze.deferredDupExpressions&&Oe.$.deferredDupExpressions.length>0){let Ye=n;if((Tt=Oe.$)!=null&&Tt.variableName&&((Jt=Oe.$)!=null&&Jt.type)){let et=We(Oe.$.variableName,Oe.$.env);if(Ue!==et){let ke=Oe.$.type,rt=j(ke,n);n.emitter.emitLine(`${t}${rt} ${et} = ${Ue};`)}}Wt(Oe,t,Ye);let Ne=Oe.$.deferredDupExpressions[0];S(Ne)&&((At=Ne.$)!=null&&At.variableName)&&(ze=We(Ne.$.variableName,Ne.$.env))}let Qe=`((${Ce})(${ze}))`;if(Ee&&((gt=e.$)!=null&>.type)){let Ye=Kt(e.$.type,Ee,n);return n.emitter.emitLine(`${t}${Ye} = ${Qe};`),Cr(Ee,t,n),Ee}else return Qe}if(X.isReferenceSemantics){let Oe=n,Ue=ge.map(Ye=>{var et,ke,rt,ft;let Ne=q(Ye,t,n);if((et=Ye.$)!=null&&et.deferredDupExpressions&&Ye.$.deferredDupExpressions.length>0){if((ke=Ye.$)!=null&&ke.variableName&&((rt=Ye.$)!=null&&rt.type)){let Vt=We(Ye.$.variableName,Ye.$.env);if(Ne!==Vt){let xt=Ye.$.type,Xt=j(xt,n);n.emitter.emitLine(`${t}${Xt} ${Vt} = ${Ne};`)}}Wt(Ye,t,Oe);let yt=Ye.$.deferredDupExpressions[0];if(S(yt)&&((ft=yt.$)!=null&&ft.variableName))return We(yt.$.variableName,yt.$.env)}return Ne}).join(", "),Qe=`${`__yo_new_${Ce}`}(${Ue})`;if(Ee&&((nt=e.$)!=null&&nt.type)){let Ye=Kt(e.$.type,Ee,n);return n.emitter.emitLine(`${t}${Ye} = ${Qe};`),Cr(Ee,t,n),Ee}else return Qe}else{let Oe=n,Ue=ge.map((Qe,Ye)=>{var rt,ft,yt,Vt;let Ne=q(Qe,t,n),et=ut(X)?`_${Ye}`:be(He[Ye],X.isExtern==="c"),ke=Ne;if((rt=Qe.$)!=null&&rt.deferredDupExpressions&&Qe.$.deferredDupExpressions.length>0){if((ft=Qe.$)!=null&&ft.variableName&&((yt=Qe.$)!=null&&yt.type)){let Xt=We(Qe.$.variableName,Qe.$.env),_n=Qe.$.type,Qn=j(_n,n);Ne!==Xt&&n.emitter.emitLine(`${t}${Qn} ${Xt} = ${Ne};`)}Wt(Qe,t,Oe);let xt=Qe.$.deferredDupExpressions[0];S(xt)&&((Vt=xt.$)!=null&&Vt.variableName)&&(ke=We(xt.$.variableName,xt.$.env))}return`.${et} = `+ke}).join(", "),ze=`(${Ce}){ ${Ue} }`;if(Ee&&((Ft=e.$)!=null&&Ft.type)){let Qe=Kt(e.$.type,Ee,n);return n.emitter.emitLine(`${t}${Qe} = ${ze};`),Cr(Ee,t,n),Ee}else return ze}}}else{if(zn(r.value))return"// Error: Closure construction should have been handled by closureFunctionValue check at top of generateFuncCall";if(Bt(r.value)){let X=(qt=e.$)==null?void 0:qt.variableName,ge=e.args[0];if(ge&&S(ge)&&E(ge,":",2)){let Ce=ge.args[0],He=ge.args[1],Ee=(Et=n.types[r.value.id])==null?void 0:Et.cName;if(Ee&&K(Ce)&&He){let Oe=n,Ue=Ce.token.value,ze=We(Ue,(Lt=Ce.$)==null?void 0:Lt.env),Ye=q(He,t,n);if((nn=He.$)!=null&&nn.deferredDupExpressions&&He.$.deferredDupExpressions.length>0){Wt(He,t,Oe);let et=He.$.deferredDupExpressions[0];S(et)&&((te=et.$)!=null&&te.variableName)&&(Ye=We(et.$.variableName,et.$.env))}let Ne=`(${Ee}){ .${ze} = ${Ye} }`;if(X&&((pe=e.$)!=null&&pe.type)){let et=Kt(e.$.type,X,n);return n.emitter.emitLine(`${t}${et} = ${Ne};`),Cr(X,t,n),X}else return Ne}}}else if(Be(r.value)){let X=r.value,ge=($e=e.$)==null?void 0:$e.runtimeArgExprsInOrder,Ce=(ie=n.types[X.id])==null?void 0:ie.cName,He=(_e=e.$)==null?void 0:_e.variableName;if(X.selectedVariantName&&ge&&Ce){if(Gn(X)){let Qe=X.selectedVariantName,Ye=X.variants.find(Ne=>Ne.name===Qe);if(Ye){if(!Ye.fields||Ye.fields.length===0){let Ne="NULL";if(He&&((ye=e.$)!=null&&ye.type)){let et=Kt(e.$.type,He,n);return n.emitter.emitLine(`${t}${et} = ${Ne};`),Cr(He,t,n),He}else return Ne}else if(Ye.fields.length===1){let Ne=q(ge[0],t,n);if(He&&((Re=e.$)!=null&&Re.type)){let et=Kt(e.$.type,He,n);return n.emitter.emitLine(`${t}${et} = ${Ne};`),Cr(He,t,n),He}else return Ne}}}if(Fr(X)){let Qe=X.selectedVariantName,Ye=Rn(X,Qe,n);if(He&&((Ke=e.$)!=null&&Ke.type)){let Ne=Kt(e.$.type,He,n);return n.emitter.emitLine(`${t}${Ne} = ${Ye};`),Cr(He,t,n),He}else return Ye}let Ue=X.selectedVariantName,ze=X.variants.find(Qe=>Qe.name===Ue);if(ze){let Qe=((Pe=ze.fields)==null?void 0:Pe.filter(ke=>!De(ke.type)))||[],Ye=n,Ne=ge.map((ke,rt)=>{var ft,yt,Vt,xt,Xt;if(ze.fields){let _n=ze.fields[rt];if(_n&&!De(_n.type)){let Qn=q(ke,t,n),Yr=We(_n.label,(ft=ke.$)==null?void 0:ft.env),nr=Qn;if((yt=ke.$)!=null&&yt.variableName&&((Vt=ke.$)!=null&&Vt.type)){let sr=Ye.currentClosureCaptures&&Ye.currentClosureCaptures.includes(ke.$.variableName)&&K(ke)&&ke.$.env&&Ye.currentClosureCaptureFrameLevel!==void 0&&vi(ke.token.value,ke.$.env,Ye.currentClosureCaptureFrameLevel),$i=(Ye.inAsyncStateMachine||Ye.inEffectStateMachine)&&Qn.startsWith("sm->"),Ui=!1;if(K(ke)&&ke.$.env&&ke.$.variableName){let Vo=ae(ke.$.env,ke.$.variableName);Vo.length>0&&Vo[Vo.length-1].isCompileTimeOnly&&(Ui=!0)}let io=!1;if(Qn&&Qn!==ke.$.variableName&&!sr&&!$i&&!Ui){let Vo=We(ke.$.variableName,ke.$.env);if(Qn!==Vo){let Zl=Kt(ke.$.type,ke.$.variableName,n);n.emitter.emitLine(`${t}${Zl} = ${Qn};`),io=!0,Cr(ke.$.variableName,t,n)}}io&&(nr=We(ke.$.variableName,ke.$.env))}if((xt=ke.$)!=null&&xt.deferredDupExpressions&&ke.$.deferredDupExpressions.length>0){Wt(ke,t,Ye);let sr=ke.$.deferredDupExpressions[0];S(sr)&&((Xt=sr.$)!=null&&Xt.variableName)&&(nr=We(sr.$.variableName,sr.$.env))}return`.${Yr} = `+nr}return""}else return""}).filter(ke=>ke).join(", "),et=Qe.length>0?`(${Ce}){ .tag = ${Rn(X,Ue,n)}, .data = { .${Ue} = { ${Ne} } } }`:`(${Ce}){ .tag = ${Rn(X,Ue,n)} }`;if(He&&((Z=e.$)!=null&&Z.type)){let ke=Kt(e.$.type,He,n);return n.emitter.emitLine(`${t}${ke} = ${et};`),Cr(He,t,n),He}else return et}}}}else if(Je(i)){let X=e.args[0];if(X&&S(X)&&(E(X,"..")||E(X,"..="))){let He=E(X,"..="),Ee=q(e.func,t,n),Oe=q(X.args[0],t,n),Ue=q(X.args[1],t,n),ze=`Slice_${be(j(i.childType,n))}`;return n.sliceStructTypes.has(ze)||n.sliceStructTypes.set(ze,{childType:j(i.childType,n)}),He?`(${ze}){ .data = &${Ee}.data[${Oe}], .length = (${Ue}) - (${Oe}) + 1 }`:`(${ze}){ .data = &${Ee}.data[${Oe}], .length = (${Ue}) - (${Oe}) }`}let ge=q(e.func,t,n),Ce=q(X,t,n);return`${ge}.data[${Ce}]`}else if($t(i)){let X=e.args[0];if(X&&S(X)&&(E(X,"..")||E(X,"..="))){let He=E(X,"..="),Ee=q(e.func,t,n),Oe=q(X.args[0],t,n),Ue=q(X.args[1],t,n),ze=`Slice_${be(j(i.childType,n))}`;return n.sliceStructTypes.has(ze)||n.sliceStructTypes.set(ze,{childType:j(i.childType,n)}),He?`(${ze}){ .data = &${Ee}.data[${Oe}], .length = (${Ue}) - (${Oe}) + 1 }`:`(${ze}){ .data = &${Ee}.data[${Oe}], .length = (${Ue}) - (${Oe}) }`}let ge=q(e.func,t,n),Ce=q(X,t,n);return`${ge}.data[${Ce}]`}else if(i&&je(i)&&$t(i.childType)){let X=q(e.func,t,n),ge=q(e.args[0],t,n);return`${X}.data[${ge}]`}}function Cp(e,t,n,r){var o,a;let i=t.emitter;if(i.emitLine(`${e}if (__yo_effect_escaped) {`),t.inAsyncStateMachine||(or(e+" ",t,r,!1,!0,!1),qr(e+" ",t,r)),t.inAsyncStateMachine)n&&i.emitLine(`${e} __yo_effect_escaped = 0;`),Ar({emitter:i,indent:e+" ",resultCode:void 0,debugLabel:void 0});else if(n){i.emitLine(`${e} __yo_effect_escaped = 0;`);let s=(o=t.currentFunctionType)==null?void 0:o.return.type;if(s&&!De(s)){let l=j(s,t);l!=="void"?(i.emitLine(`${e} ${l} _esc_result;`),i.emitLine(`${e} memcpy(&_esc_result, __yo_effect_escape_value, sizeof(${l}));`),i.emitLine(`${e} return _esc_result;`)):i.emitLine(`${e} return;`)}else i.emitLine(`${e} return;`)}else{let s=(a=t.currentFunctionType)==null?void 0:a.return.type;if(s&&!De(s)){let l=j(s,t);l!=="void"?i.emitLine(`${e} return (${l}){0};`):i.emitLine(`${e} return;`)}else i.emitLine(`${e} return;`)}i.emitLine(`${e}}`)}function bp(e,t,n,r,i,o,a,s){var p,m,h,y,g,v,T,$,C,k,b,w,A,L;let l=n.join(", "),u=t.return.type,_=a.emitter,c,f=!1;if(s!=null&&s.fieldFunctionType.forallParameters&&s.fieldFunctionType.forallParameters.length>0){let N=s.fieldFunctionType.return.type;f=z(N);let x=f?"void":(p=i.$)!=null&&p.type?j(i.$.type,a):j(u,a),V=[],R=s.fieldFunctionType.parameters.filter(H=>!H.isCompileTimeOnly);for(let H=0;H<R.length;H++){let B=R[H].type,G=z(B)&&((h=(m=r==null?void 0:r[H])==null?void 0:m.$)!=null&&h.type)?r[H].$.type:B,Q=ne(G)?hi(G,"(*)",a):j(G,a);V.push(Q)}let D=V.join(", ");c=`((${x} (*)(${D}))${e})`}else c=e;if(De(u)){if(_.emitLine(`${o}${c}(${l});`),(y=i.$)!=null&&y.deferredDropExpressions&&fn(i,o,a),_.emitLine(`${o}if (__yo_effect_escaped) {`),a.inAsyncStateMachine||(or(o+" ",a,i,!1,!0,!1),qr(o+" ",a,i)),a.inAsyncStateMachine)Ar({emitter:_,indent:o+" ",resultCode:void 0,debugLabel:void 0});else{let N=(g=a.currentFunctionType)==null?void 0:g.return.type;if(N&&!De(N)){let x=j(N,a);x!=="void"?_.emitLine(`${o} return (${x}){0};`):_.emitLine(`${o} return;`)}else _.emitLine(`${o} return;`)}return _.emitLine(`${o}}`),""}else{let N=(v=i.$)==null?void 0:v.variableName;if(N){let x=(T=s==null?void 0:s.fieldFunctionType.forallParameters)!=null&&T.length&&(($=i.$)!=null&&$.type)?i.$.type:u,V=j(x,a);if(V==="void"||De(x)){if(_.emitLine(`${o}${c}(${l});`),(C=i.$)!=null&&C.deferredDropExpressions&&fn(i,o,a),_.emitLine(`${o}if (__yo_effect_escaped) {`),a.inAsyncStateMachine||(or(o+" ",a,i,!1,!0,!1),qr(o+" ",a,i)),a.inAsyncStateMachine)Ar({emitter:_,indent:o+" ",resultCode:void 0,debugLabel:void 0});else{let U=(k=a.currentFunctionType)==null?void 0:k.return.type;if(U&&!De(U)){let R=j(U,a);R!=="void"?_.emitLine(`${o} return (${R}){0};`):_.emitLine(`${o} return;`)}else _.emitLine(`${o} return;`)}return _.emitLine(`${o}}`),""}if(f){if(_.emitLine(`${o}${V} ${N} = (${V}){0};`),_.emitLine(`${o}${c}(${l});`),(b=i.$)!=null&&b.deferredDropExpressions&&fn(i,o,a),_.emitLine(`${o}if (__yo_effect_escaped) {`),a.inAsyncStateMachine||(or(o+" ",a,i,!1,!0,!1),qr(o+" ",a,i)),a.inAsyncStateMachine)Ar({emitter:_,indent:o+" ",resultCode:void 0,debugLabel:void 0});else{let U=(w=a.currentFunctionType)==null?void 0:w.return.type;if(U&&!De(U)){let R=j(U,a);R!=="void"?_.emitLine(`${o} return (${R}){0};`):_.emitLine(`${o} return;`)}else _.emitLine(`${o} return;`)}return _.emitLine(`${o}}`),Cr(N,o,a),N}if(_.emitLine(`${o}${V} ${N} = ${c}(${l});`),(A=i.$)!=null&&A.deferredDropExpressions&&fn(i,o,a),_.emitLine(`${o}if (__yo_effect_escaped) {`),a.inAsyncStateMachine||(or(o+" ",a,i,!1,!0,!1),qr(o+" ",a,i)),a.inAsyncStateMachine)Ar({emitter:_,indent:o+" ",resultCode:void 0,debugLabel:void 0});else{let U=(L=a.currentFunctionType)==null?void 0:L.return.type;if(U&&!De(U)){let R=j(U,a);R!=="void"?_.emitLine(`${o} return (${R}){0};`):_.emitLine(`${o} return;`)}else _.emitLine(`${o} return;`)}return _.emitLine(`${o}}`),N}else return`${c}(${l})`}}function Wu(e,t,n,r){var s,l,u,_,c,f,p,m,h,y,g,v,T,$,C,k,b;let i=[],o=(l=(s=t.body)==null?void 0:s.$)==null?void 0:l.effectAnalysis,a=!1;for(let w of e){let A=`${w.implicitLabel}.${w.fieldLabel}`,L=!1;if(r.currentEvidenceParams){let N=r.currentEvidenceParams.get(A);N&&(i.push(N.cParamName),L=!0)}if(!L){if(o){if(o.effectHandlerInfos)for(let N of o.effectHandlerInfos){if(N.effectParameterName!==w.fieldLabel&&N.effectParameterName!==w.implicitLabel)continue;let x=N.handlerValue;if(x&&he(x)){if((u=x.specializedFunctionCaches)!=null&&u.length){let U=x.specializedFunctionCaches[0].specializedFunction,R=(_=r.functions[U.funcId])==null?void 0:_.cName;if(R){i.push(`(void*)${R}`),L=!0,a=!0;break}}let V=(c=r.functions[x.funcId])==null?void 0:c.cName;if(V){i.push(V),L=!0,a=!0;break}}}if(!L&&o.handlerValue&&e.length===1){let N=o.handlerValue;if(N&&he(N)){if((f=N.specializedFunctionCaches)!=null&&f.length){let x=N.specializedFunctionCaches[0].specializedFunction,V=(p=r.functions[x.funcId])==null?void 0:p.cName;V&&(i.push(`(void*)${V}`),L=!0,a=!0)}if(!L){let x=(m=r.functions[N.funcId])==null?void 0:m.cName;x&&(i.push(x),L=!0,a=!0)}}}}if(!L){let N=((h=n.func.$)==null?void 0:h.env)??((y=n.$)==null?void 0:y.env);if(N){let x=ae(N,w.implicitLabel),V=cr(N,B=>B.isImplicit===!0&&ne(B.type)&&ne(w.fieldFunctionType)&&B.type===w.fieldFunctionType),U=x[x.length-1],R=V[V.length-1],D=R&&R!==U?R:U??R,H=(g=D==null?void 0:D.value)==null?void 0:g[0];if(H&&wt(H)){let B=H,G=!0;for(let Q=0;Q<w.fieldPath.length-1;Q++){let Y=w.fieldPath[Q],J=B.type.fields.findIndex(se=>se.label===Y);if(J>=0&&B.fields[J]&&wt(B.fields[J]))B=B.fields[J];else{G=!1;break}}if(G){let Q=w.fieldPath[w.fieldPath.length-1],Y=B.type.fields.findIndex(J=>J.label===Q);if(Y>=0){let J=B.fields[Y];if(J&&he(J)){if(((v=J.specializedFunctionCaches)==null?void 0:v.length)>0){let se=J.specializedFunctionCaches[0].specializedFunction,ve=(T=r.functions[se.funcId])==null?void 0:T.cName;ve&&(i.push(`(void*)${ve}`),L=!0)}if(!L){let se=($=r.functions[J.funcId])==null?void 0:$.cName;se&&(i.push(se),L=!0)}}}}}else if(H&&he(H)){if((C=H.specializedFunctionCaches)!=null&&C.length){let B=H.specializedFunctionCaches[0].specializedFunction,G=(k=r.functions[B.funcId])==null?void 0:k.cName;G&&(i.push(`(void*)${G}`),L=!0)}if(!L){let B=(b=r.functions[H.funcId])==null?void 0:b.cName;B&&(i.push(B),L=!0)}}L&&(a=!0)}}if(!L&&r.stateMachineVariables){let N=w.fieldPath[w.fieldPath.length-1];for(let[,x]of r.stateMachineVariables)if(x.name===N&&x.kind==="outer"){i.push(`sm->__capture.${N}`),L=!0;break}}if(!L)break}}return{args:i,isHandlerInstallation:a}}function qu(e,t,n,r,i,o,a,s=!1){var _,c,f,p,m;let l=a.emitter,u=n.return.type;if(l.emitLine(`${o}__yo_effect_escaped = 0;`),De(u)){if(l.emitLine(`${o}${e}(${t});`),(_=r.$)!=null&&_.deferredDropExpressions&&fn(r,o,a),l.emitLine(`${o}if (__yo_effect_escaped) {`),a.inAsyncStateMachine||(or(o+" ",a,r,!1,!0,!1),qr(o+" ",a,r)),a.inAsyncStateMachine)Ar({emitter:l,indent:o+" ",resultCode:void 0,debugLabel:void 0});else{let h=(c=a.currentFunctionType)==null?void 0:c.return.type;if(s&&l.emitLine(`${o} __yo_effect_escaped = 0;`),h&&!De(h))if(s){let y=j(h,a);y!=="void"?(l.emitLine(`${o} ${y} _esc_result;`),l.emitLine(`${o} memcpy(&_esc_result, __yo_effect_escape_value, sizeof(${y}));`),l.emitLine(`${o} return _esc_result;`)):l.emitLine(`${o} return;`)}else{let y=j(h,a);y!=="void"?l.emitLine(`${o} return (${y}){0};`):l.emitLine(`${o} return;`)}else l.emitLine(`${o} return;`)}return l.emitLine(`${o}}`),""}else{let h=(f=r.$)==null?void 0:f.variableName;if(h){let y=j(u,a);if(l.emitLine(`${o}${y} ${h} = ${e}(${t});`),Cr(h,o,a),(p=r.$)!=null&&p.deferredDropExpressions&&fn(r,o,a),l.emitLine(`${o}if (__yo_effect_escaped) {`),a.inAsyncStateMachine||(or(o+" ",a,r,!1,!0,!1),qr(o+" ",a,r)),a.inAsyncStateMachine)Ar({emitter:l,indent:o+" ",resultCode:void 0,debugLabel:void 0});else{let g=(m=a.currentFunctionType)==null?void 0:m.return.type;if(s&&g&&!De(g)){let v=j(g,a);l.emitLine(`${o} ${v} _esc_result;`),l.emitLine(`${o} memcpy(&_esc_result, __yo_effect_escape_value, sizeof(${v}));`),l.emitLine(`${o} __yo_effect_escaped = 0;`),l.emitLine(`${o} return _esc_result;`)}else if(g&&!De(g)){let v=j(g,a);v!=="void"?l.emitLine(`${o} return (${v}){0};`):l.emitLine(`${o} return;`)}else s&&l.emitLine(`${o} __yo_effect_escaped = 0;`),l.emitLine(`${o} return;`)}return l.emitLine(`${o}}`),h}else return`${e}(${t})`}}function wp(e,t,n){var a,s,l;let r=n.emitter,i=(a=e.$)==null?void 0:a.type;if(!i)return"// Error: panic() missing type information";if(e.args.length===0)r.emitLine(`${t}abort();`);else if(e.args.length===1){let u=e.args[0];if((s=u.$)!=null&&s.value&&tt(u.$.value)){let _=u.$.value.value;r.emitLine(`${t}fprintf(stderr, "%s\\n", ${JSON.stringify(_)});`),r.emitLine(`${t}abort();`)}else{let _=q(u,t,n),c=(l=u.$)==null?void 0:l.type;c&&Ae(c)&&hr(c)&&c.typeName==="str"?r.emitLine(`${t}fprintf(stderr, "%.*s\\n", (int)${_}.length, ${_}.data);`):r.emitLine(`${t}fprintf(stderr, "%s\\n", ${_});`),r.emitLine(`${t}abort();`)}}else return`// Error: panic accepts 0 or 1 arguments, got ${e.args.length}`;return`(*((${j(i,n)}*)NULL))`}var kv={reg:{x86_64:"r",aarch64:"r",x86:"r",arm:"r"},reg_byte:{x86_64:"q",x86:"q"},reg_abcd:{x86_64:"Q",x86:"Q"},xmm_reg:{x86_64:"x",aarch64:"w"},ymm_reg:{x86_64:"x"},imm:{x86_64:"i",aarch64:"i",x86:"i",arm:"i"},mem:{x86_64:"m",aarch64:"m",x86:"m",arm:"m"}},wv={rax:"a",eax:"a",ax:"a",al:"a",rbx:"b",ebx:"b",bx:"b",bl:"b",rcx:"c",ecx:"c",cx:"c",cl:"c",rdx:"d",edx:"d",dx:"d",dl:"d",rsi:"S",esi:"S",si:"S",rdi:"D",edi:"D",di:"D"},Fv={e:"k",x:"w",l:"b",h:"h",w:"w"};function Lv(e,t){if(!e)return"r";if(e.startsWith("raw:"))return e.slice(4);let n=wv[e];if(n)return n;let r=kv[e];return r?r[t]??r.x86_64??"r":e}function Iv(e,t){let n="",r=0;for(;r<e.length;)if(e[r]==="{"){if(r+1<e.length&&e[r+1]==="{"){n+="{",r+=2;continue}let i=e.indexOf("}",r+1);if(i===-1){n+=e[r],r++;continue}let o=e.slice(r+1,i),a=o.indexOf(":"),s,l;a>=0?(s=o.slice(0,a),l=o.slice(a+1)):s=o;let u=l?Fv[l]??l:void 0,_=parseInt(s,10);isNaN(_)?u?n+=`%${u}[${s}]`:n+=`%[${s}]`:u?n+=`%${u}${_}`:n+=`%${_}`,r=i+1}else e[r]==="}"&&r+1<e.length&&e[r+1]==="}"?(n+="}",r+=2):(n+=e[r],r++);return n}function Av(e,t,n,r){var g,v,T,$,C;let i=e.args,o=n.targetInfo.arch;if(r==="const_val"){let k,b=0;i.length===2&&((g=i[0].$)!=null&&g.value)&&tt(i[0].$.value)&&(k=i[0].$.value.value,b=1);let w=q(i[b],t,n);return{kind:"const_val",name:k,constraint:"",cExpr:w,cType:"",isDiscarded:!1,isVariableTarget:!1}}if(r==="sym"){let k,b=0;i.length===2&&((v=i[0].$)!=null&&v.value)&&tt(i[0].$.value)&&(k=i[0].$.value.value,b=1);let w=q(i[b],t,n);return{kind:"sym",name:k,constraint:"i",cExpr:w,cType:"",isDiscarded:!1,isVariableTarget:!1}}let a,s=0;if(i.length>=2){let k=i[0];(T=k.$)!=null&&T.value&&tt(k.$.value)&&!(k.tag==="Atom"&&Fp(k.token.value))&&(a=k.$.value.value,s=1)}let l=s<i.length-1,u,_;l?(u=Sv(i[s],t,n),_=s+1):(a!==void 0&&(u=a),_=s);let c=Lv(u,o),f=i[_];if(f.tag==="Atom"&&f.token.value==="_")return{kind:r,name:a,constraint:c,cExpr:"",cType:"int32_t",isDiscarded:!0,isVariableTarget:!1};if(($=f.$)!=null&&$.value&&W(f.$.value)){let k=f.$.value.value,b=j(k,n);return{kind:r,name:a,constraint:c,cExpr:"",cType:b,isDiscarded:!1,isVariableTarget:!1}}let p=q(f,t,n),m=j((C=f.$)==null?void 0:C.type,n),y=(r==="out"||r==="lateout")&&f.tag==="Atom";return{kind:r,name:a,constraint:c,cExpr:p,cType:m,isDiscarded:!1,isVariableTarget:y}}function Fp(e){return["reg","reg_byte","reg_abcd","xmm_reg","ymm_reg","imm","mem"].includes(e)}function Sv(e,t,n){var r,i;if(e.tag==="Atom"&&Fp(e.token.value))return e.token.value;if((r=e.$)!=null&&r.value&&tt(e.$.value))return e.$.value.value;if(E(e,"raw",1)){let o=e;if((i=o.args[0].$)!=null&&i.value&&tt(o.args[0].$.value))return`raw:${o.args[0].$.value.value}`}return"r"}function Nv(e,t){var i;let n=[];if((e.func.tag==="Atom"?e.func.token.value:"clobber")==="clobber_abi"){let o=t.targetInfo.arch;if(o==="x86_64")n.push("rax","rcx","rdx","rsi","rdi","r8","r9","r10","r11","xmm0","xmm1","xmm2","xmm3","xmm4","xmm5","xmm6","xmm7","xmm8","xmm9","xmm10","xmm11","xmm12","xmm13","xmm14","xmm15","cc","memory");else if(o==="aarch64"){for(let a=0;a<=18;a++)n.push(`x${a}`);n.push("x30");for(let a=0;a<=31;a++)n.push(`v${a}`);n.push("cc","memory")}return n}for(let o of e.args)(i=o.$)!=null&&i.value&&tt(o.$.value)?n.push(o.$.value.value):o.tag==="Atom"&&n.push(o.token.value);return n}function Vv(e){let t={isVolatile:!0,intelSyntax:!1,noreturn:!1,pure:!1};for(let n of e.args)if(n.tag==="Atom")switch(n.token.value){case"pure":t.pure=!0,t.isVolatile=!1;break;case"intel_syntax":t.intelSyntax=!0;break;case"noreturn":t.noreturn=!0;break;case"volatile":t.isVolatile=!0;break}return t}var Yu=0;function Lp(e,t,n){var N,x;let r=n.emitter,i=(N=e.$)==null?void 0:N.type;if(!i)return"/* Error: asm() missing type information */";if(Gr(n.targetInfo))return r.emitLine(`${t}/* Error: inline assembly is not supported on WebAssembly */`),r.emitLine(`${t}abort();`),`(*((${j(i,n)}*)NULL))`;let o=[],a=0;for(;a<e.args.length;){let V=e.args[a];if(S(V))break;if((x=V.$)!=null&&x.value&&tt(V.$.value))o.push(V.$.value.value),a++;else break}let s=o.join(`
|
|
11397
|
-
`),l=[],u=[],_={isVolatile:!0,intelSyntax:!1,noreturn:!1,pure:!1};for(;a<e.args.length;){let V=e.args[a];if(!S(V)){a++;continue}let U=V.func.tag==="Atom"?V.func.token.value:void 0;if(!U){a++;continue}["in","out","inout","lateout","inlateout","const_val","sym"].includes(U)?l.push(Av(V,t,n,U)):U==="clobber"||U==="clobber_abi"?u.push(...Nv(V,n)):U==="asm_options"&&(_=Vv(V)),a++}let c=new Map;for(let V=0;V<l.length;V++)l[V].name&&c.set(l[V].name,V);let f=s;for(let V=0;V<l.length;V++){let U=l[V];U.kind==="const_val"&&(U.name&&(f=f.replace(new RegExp(`\\{${U.name}(?::[^}]*)?\\}`,"g"),U.cExpr)),f=f.replace(new RegExp(`\\{${V}(?::[^}]*)?\\}`,"g"),U.cExpr))}let p=Iv(f,c),m=[],h=[],y=[];for(let V=0;V<l.length;V++){let U=l[V];if(U.isDiscarded){let R=`__asm_discard_${Yu++}`;y.push({varName:R,cType:U.cType,operandIdx:V}),r.emitLine(`${t}${U.cType} ${R};`)}else if(U.kind==="out"||U.kind==="lateout"){if(!U.isVariableTarget){if(U.cType){let R=`__asm_out_${Yu++}`;m.push({varName:R,cType:U.cType,operandIdx:V}),r.emitLine(`${t}${U.cType} ${R};`)}}}else if(U.kind==="inout"||U.kind==="inlateout"){let R=`__asm_inout_${Yu++}`;h.push({varName:R,cType:U.cType,initExpr:U.cExpr,operandIdx:V}),r.emitLine(`${t}${U.cType} ${R} = ${U.cExpr};`)}}let g=_.isVolatile?" __volatile__":"",v=p;_.intelSyntax&&(n.needsIntelAsmSyntax=!0);let T=JSON.stringify(v),$=[];for(let V=0;V<l.length;V++){let U=l[V];if(U.kind==="in"||U.kind==="const_val"||U.kind==="sym")continue;let R;U.kind==="out"||U.kind==="lateout"?R=U.kind==="lateout"?"=&":"=":R=U.kind==="inlateout"?"+&":"+";let D=`${R}${U.constraint}`,H=U.name?`[${U.name}] `:"",B;U.isDiscarded?B=y.find(Q=>Q.operandIdx===V).varName:U.isVariableTarget?B=U.cExpr:U.kind==="out"||U.kind==="lateout"?B=m.find(Q=>Q.operandIdx===V).varName:B=h.find(Q=>Q.operandIdx===V).varName,$.push(`${H}"${D}" (${B})`)}let C=[];for(let V=0;V<l.length;V++){let U=l[V];if(U.kind!=="in"&&U.kind!=="sym")continue;let R=U.constraint,D=U.name?`[${U.name}] `:"";C.push(`${D}"${R}" (${U.cExpr})`)}let k=u.map(V=>`"${V}"`),b=$.join(", "),w=C.join(", "),A=k.join(", ");if(r.emitLine(`${t}__asm__${g} (`),r.emitLine(`${t} ${T}`),r.emitLine(`${t} : ${b}`),r.emitLine(`${t} : ${w}`),r.emitLine(`${t} : ${A}`),r.emitLine(`${t});`),_.noreturn)return r.emitLine(`${t}__builtin_unreachable();`),`(*((${j(i,n)}*)NULL))`;if(De(i))return"";let L=[];for(let V=0;V<l.length;V++){let U=l[V];if(!(U.isDiscarded||U.isVariableTarget)&&!(U.kind==="in"||U.kind==="const_val"||U.kind==="sym"))if(U.kind==="out"||U.kind==="lateout"){let R=m.find(D=>D.operandIdx===V);R&&L.push(R.varName)}else{let R=h.find(D=>D.operandIdx===V);R&&L.push(R.varName)}}if(L.length===1)return L[0];if(L.length>1){let V=j(i,n),U=L.map((R,D)=>`._${D} = ${R}`).join(", ");return`((${V}){ ${U} })`}return""}function Ip(e,t,n){var i;if(Gr(n.targetInfo))return"/* global_asm skipped: not supported on this target */";let r=e.args[0];if((i=r.$)!=null&&i.value&&tt(r.$.value)){let o=r.$.value.value;n.emitter.emitDeclarationLine(`__asm__(${JSON.stringify(o)});`)}return""}function Ap(e,t,n){var l,u,_,c,f,p,m,h,y,g;if(e.args.length!==2)return"/* ERROR: field access requires exactly 2 arguments */";let r=e.args[0],i=e.args[1];if(!r||!i)return"/* ERROR: invalid field access arguments */";let o=q(r,t,n),a=(l=r.$)==null?void 0:l.type,s=(u=r.$)==null?void 0:u.value;if(K(i)){let v=i.token.value,T=n;if(T.currentEvidenceParams&&K(r)){let C=`${r.token.value}.${v}`,k=T.currentEvidenceParams.get(C);if(k)return k.cParamName}if((_=e.$)!=null&&_.value&&
|
|
11398
|
-
`;let i=e.args[0];if(S(i)){let v=(u=i.func.$)==null?void 0:u.type;if(v&&Je(v)){let T=i.args[0];if(T&&S(T)&&(E(T,"..")||E(T,"..="))){let $=E(T,"..="),C=q(i.func,t,n),k=q(T.args[0],t,n),b=q(T.args[1],t,n),w=`Slice_${be(j(v.childType,n))}`;return n.sliceStructTypes.has(w)||n.sliceStructTypes.set(w,{childType:j(v.childType,n)}),$?`(${w}){ .data = &${C}.data[${k}], .length = (${b}) - (${k}) + 1 }`:`(${w}){ .data = &${C}.data[${k}], .length = (${b}) - (${k}) }`}}else if(v&&($t(v)||je(v)&&$t(v.childType))){let T=$t(v)?v:v.childType,$=i.args[0];if($&&S($)&&(E($,"..")||E($,"..="))){let C=E($,"..="),k=q(i.func,t,n),b=q($.args[0],t,n),w=q($.args[1],t,n),A=`Slice_${be(j(T.childType,n))}`;return n.sliceStructTypes.has(A)||n.sliceStructTypes.set(A,{childType:j(T.childType,n)}),C?`(${A}){ .data = &${k}.data[${b}], .length = (${w}) - (${b}) + 1 }`:`(${A}){ .data = &${k}.data[${b}], .length = (${w}) - (${b}) }`}}}let o=(_=i.$)==null?void 0:_.value,a=(c=i.$)==null?void 0:c.type;if(o!==void 0&&a){if(ht(o)||Ct(o)){let v=q(i,t,n);return`(&(${j(a,n)}){${v}})`}if(tt(o)&&((f=i.$)!=null&&f.convertedRuntimeType))return`(&${q(i,t,n)})`}if((p=e.$)!=null&&p.isIndexTraitAddressOf&&S(i)&&((m=i.$)!=null&&m.indexMethodValue)){let v=i.$.indexMethodValue;if(
|
|
11399
|
-
`}function Kp(e,t,n){let r=e.args[0];return`sizeof(${q(r,t,n)})`}function Xp(e,t,n){var a,s,l,u,_,c,f,p,m;let r=(a=e.$)==null?void 0:a.runtimeArgExprsInOrder,i=(u=n.types[((l=(s=e.$)==null?void 0:s.type)==null?void 0:l.id)??""])==null?void 0:u.cName,o=(_=e.$)==null?void 0:_.variableName;if(r&&i){let h=n,y=r.map((g,v)=>{var C,k;let $=q(g,t,n);if((C=g.$)!=null&&C.deferredDupExpressions&&g.$.deferredDupExpressions.length>0){Wt(g,t,h);let b=g.$.deferredDupExpressions[0];S(b)&&((k=b.$)!=null&&k.variableName)&&($=We(b.$.variableName,b.$.env))}return`._${v} = ${$}`}).join(", ");if(o&&((c=e.$)!=null&&c.type)){let g=`(${i}){ ${y} }`,v=Kt(e.$.type,o,n);return n.emitter.emitLine(`${t}${v} = ${g};`),o}else return`(${i}){ ${y} }`}else{if(e.args.length===0)return"";{let h=r??e.args;if(!i)return`/* Error: tuple type not found - typeId: ${((p=(f=e.$)==null?void 0:f.type)==null?void 0:p.id)??"none"} */`;let y=h.map((g,v)=>{let T=q(g,t,n);return`._${v} = ${T}`}).join(", ");if(o&&((m=e.$)!=null&&m.type)){let g=`(${i}){ ${y} }`,v=Kt(e.$.type,o,n);return n.emitter.emitLine(`${t}${v} = ${g};`),o}else return`(${i}){ ${y} }`}}}function Qp(e,t,n){var u,_;let i=(u=e.args[0].$)==null?void 0:u.value;if(!i||!W(i))throw new Error("typeid codegen: expected TypeValue argument");let o=i.value,a=o.id,s=((_=n.types[a])==null?void 0:_.cName)||j(o,n),l=`__yo_typeid_${be(s)}`;return n.typeIdStatics||(n.typeIdStatics=new Map),n.typeIdStatics.has(a)||(n.typeIdStatics.set(a,l),n.emitter.emitDeclarationLine(`static const char ${l} = 0;`)),n.cIncludes.add("<stdint.h>"),`(uintptr_t)&${l}`}function Dv(e,t){if(S(e)&&E(e,P.begin)){let n=[];for(let r of e.args)if(S(r)&&E(r,"=",2)){let i=r.args[0],o=r.args[1],a=q(i,"",t),s=q(o,"",t);n.push(`${a} = ${s}`)}return n.join(", ")}else if(S(e)&&E(e,"=",2)){let n=e.args[0],r=e.args[1],i=q(n,"",t),o=q(r,"",t);return`${i} = ${o}`}return q(e,"",t)}function Hu(e,t,n){var r,i,o,a;if(S(e)&&E(e,P.begin)){let s=n,l=s.pendingDeferredDrops,u=((r=e.$)==null?void 0:r.deferredDropExpressions)??[],_=new Map;for(let m of u){let h=$r(m);h&&_.set(h,m)}s.pendingDeferredDrops=[...l??[]];let c=s.consumedVarPendingDrops,f=((i=e.$)==null?void 0:i.consumedVariableDropExpressions)??[];s.consumedVarPendingDrops=[...f,...c??[]];let p=new Set;for(let m of e.args){let h=q(m,t,n);if(h&&n.emitter.emitLine(`${t}${h};`),(o=m.$)!=null&&o.env&&_.size>p.size)for(let y of m.$.env.frames)for(let g of y.variables)_.has(g.name)&&!p.has(g.name)&&(p.add(g.name),s.pendingDeferredDrops.unshift(_.get(g.name)))}if((a=e.$)!=null&&a.deferredDropExpressions)for(let m of e.$.deferredDropExpressions){let h=q(m,t,n);h&&n.emitter.emitLine(`${t}${h};`)}s.pendingDeferredDrops=l,s.consumedVarPendingDrops=c}else{let s=q(e,t,n);s&&n.emitter.emitLine(`${t}${s};`)}}function Zp(e,t,n){var i,o,a;if((i=e.$)!=null&&i.comptimeUnrolledBodies){for(let s of e.$.comptimeUnrolledBodies)Hu(s,t,n);return""}let r=e.args;if(r.length===2){let s=r[0],l=r[1],u=n.currentLoopLabel,_=`loop_${Math.random().toString(36).substr(2,9)}`;n.currentLoopLabel=_;let c=n,f=c.loopBodyDropsBaselineCount;c.loopBodyDropsBaselineCount=((o=c.pendingDeferredDrops)==null?void 0:o.length)??0,n.emitter.emitLine(`${t}while (true) {`);let p=q(s,t+" ",n);return n.emitter.emitLine(`${t} if (!(${p})) {`),n.emitter.emitLine(`${t} break;`),n.emitter.emitLine(`${t} }`),Hu(l,t+" ",n),n.emitter.emitLine(`${t}}`),n.emitter.emitLine(`${t}${_}:;`),c.loopBodyDropsBaselineCount=f,n.currentLoopLabel=u,""}else if(r.length===3){let s=r[0],l=r[1],u=r[2],_=n.currentLoopLabel,c=n.currentContinueLabel,f=`loop_${Math.random().toString(36).substr(2,9)}`,p=`continue_${Math.random().toString(36).substr(2,9)}`;n.currentLoopLabel=f,n.currentContinueLabel=p;let m=n,h=m.loopBodyDropsBaselineCount;m.loopBodyDropsBaselineCount=((a=m.pendingDeferredDrops)==null?void 0:a.length)??0,n.emitter.emitLine(`${t}while (true) {`);let y=q(s,t+" ",n);n.emitter.emitLine(`${t} if (!(${y})) {`),n.emitter.emitLine(`${t} break;`),n.emitter.emitLine(`${t} }`),Hu(u,t+" ",n),n.emitter.emitLine(`${t}${p}:;`);let g=Dv(l,n);return n.emitter.emitLine(`${t} ${g};`),n.emitter.emitLine(`${t}}`),n.emitter.emitLine(`${t}${f}:;`),m.loopBodyDropsBaselineCount=h,n.currentLoopLabel=_,n.currentContinueLabel=c,""}else return n.emitter.emitLine(`${t}/* Error: while loop expects 2 or 3 arguments, got ${r.length} */`),""}var Mv=0;function Ov(e){let t=[];for(let n of e)if(n.isEffectRowSpread){let r=n.type;z(r)&&r.resolvedConcreteType&&(r=r.resolvedConcreteType),Yt(r)&&t.push(...r.implicitParameters)}else t.push(n);return t}function Rv(e,t,n){var _,c,f,p,m,h,y,g;let r=(_=e.$)==null?void 0:_.indexMethodValue;if(!r||!he(r))return"/* Error: Index trait method value missing */";let i=e.func,o=q(i,t,n);if(S(i)&&!K(i)&&!E(i,".")&&((c=i.$)!=null&&c.type)&&!(((f=i.$)==null?void 0:f.variableName)&&o===We(i.$.variableName,i.$.env))){let T=j(i.$.type,n),$=`__yo_idx_tmp_${Mv++}`;n.emitter.emitLine(`${t}${T} ${$} = ${o};`),o=$}let a=e.args[0],s=a?q(a,t,n):"0",l,u=gi(r);if(u)if(F.__yo_array_index.includes(u)||F.__yo_slice_index.includes(u))l=`(&((&${o})->data[${s}]))`;else if((F.__yo_array_index_range.includes(u)||F.__yo_slice_index_range.includes(u))&&((p=e.$)!=null&&p.indexTraitPtrType)&&je(e.$.indexTraitPtrType))l=`(&(${j(e.$.indexTraitPtrType.childType,n)}){ .data = &((&${o})->data[(${s}).start]), .length = (${s}).end - (${s}).start })`;else if((F.__yo_array_index_range_inclusive.includes(u)||F.__yo_slice_index_range_inclusive.includes(u))&&((m=e.$)!=null&&m.indexTraitPtrType)&&je(e.$.indexTraitPtrType))l=`(&(${j(e.$.indexTraitPtrType.childType,n)}){ .data = &((&${o})->data[(${s}).start]), .length = (${s}).end - (${s}).start + 1 })`;else{let v=(h=n.functions[r.funcId])==null?void 0:h.cName;if(!v)return`/* Error: Index method ${r.funcId} not found in function registry */`;l=`${v}(&${o}, ${s})`}else{let v=(y=n.functions[r.funcId])==null?void 0:y.cName;if(!v)return`/* Error: Index method ${r.funcId} not found in function registry */`;l=`${v}(&${o}, ${s})`}return(g=e.$)!=null&&g.isIndexTraitAddressOf?l:`(*${l})`}function Pv(e,t,n,r){var c,f,p,m;let i=e.args[0];if(!((c=i==null?void 0:i.$)!=null&&c.type))return;let o=e.args.find(h=>S(h)&&E(h,P.using));if(!o)return;let a=Ln(i.$.type);if(!((f=a==null?void 0:a.isFuture.effects)!=null&&f.length))return;let s=Ov(a.isFuture.effects),l=o.args,u=r,_=u.emitter;for(let h=0;h<s.length&&h<l.length;h++){let y=s[h],g=l[h];if(ne(y.type)){let v=y.label,T;if(u.currentEvidenceParams){for(let $ of u.currentEvidenceParams.values())if($.fieldLabel===v){T=$.cParamName;break}}if(!T&&u.stateMachineVariables){for(let[,$]of u.stateMachineVariables)if($.name===v&&$.kind==="outer"){T=`sm->__capture.${v}`;break}}if(!T){let $=(p=g.$)==null?void 0:p.value;if($&&he($)){let C=r.functions[$.funcId];C&&(T=C.cName)}}T||(T=q(g,n,r)),T&&_.emitLine(`${n} ${t}->__capture.${v} = (void*)${T};`)}else if(Xe(y.type)){let v=y.type;for(let T of v.fields){if(!ne(T.type))continue;let $;if(u.stateMachineVariables){for(let[,C]of u.stateMachineVariables)if(C.name===T.label&&C.kind==="outer"){$=`sm->__capture.${T.label}`;break}}if(!$){let C=(m=g.$)==null?void 0:m.value;if(C&&wt(C)){let k=v.fields.indexOf(T),b=C.fields[k];if(b&&he(b)){let w=r.functions[b.funcId];w&&($=w.cName)}}}if(!$&&u.currentEvidenceParams){for(let C of u.currentEvidenceParams.values())if(C.fieldLabel===T.label){$=C.cParamName;break}}$||($=Uv(T.label,v,u,e)),$&&_.emitLine(`${n} ${t}->__capture.${T.label} = (void*)${$};`)}}}}function Uv(e,t,n,r){var a,s,l,u;let i=((a=r.$)==null?void 0:a.env)??((s=r.func.$)==null?void 0:s.env);if(!i)return;let o=cr(i,_=>_.isImplicit===!0);for(let _=o.length-1;_>=0;_--){let c=o[_],f=(l=c.value)==null?void 0:l[c.value.length-1];if(f&&wt(f)){let p=f.type.fields.findIndex(m=>m.label===e);if(p>=0){let m=f.fields[p];if(m&&he(m)){let h=(u=n.functions[m.funcId])==null?void 0:u.cName;if(h)return h}}}}}function zv(e,t,n){var l,u;let r=n,i=e.args[0],o=(l=r.continuationVariables)==null?void 0:l.get("resume");if(o&&"directReturnVar"in o&&o.directExitLabel){if(i){let _=q(i,t,n);if(r.effectHandlerParamDrops)for(let c of r.effectHandlerParamDrops)r.emitter.emitLine(`${t}${c};`);r.emitter.emitLine(`${t}${o.directReturnVar} = ${_};`),r.emitter.emitLine(`${t}goto ${o.directExitLabel};`)}else{if(r.effectHandlerParamDrops)for(let _ of r.effectHandlerParamDrops)r.emitter.emitLine(`${t}${_};`);r.emitter.emitLine(`${t}goto ${o.directExitLabel};`)}return""}if(r.inAsyncStateMachine){let _=r.emitter;if(i){let c=q(i,t,n);c&&c!=="(void)0"&&_.emitLine(`${t}(void)${c};`)}if(r.effectHandlerParamDrops)for(let c of r.effectHandlerParamDrops)_.emitLine(`${t}${c};`);return or(t,r,e,!1,!0,!0),qr(t,r,e,!0),Ar({emitter:_,indent:t,debugLabel:r.currentFunctionName}),""}if((r.isModuleEffectMemberFunction||r.currentEvidenceParams&&r.currentEvidenceParams.size>0)&&r.emitter.emitLine(`${t}__yo_effect_escaped = 1;`),!i){if(r.effectHandlerParamDrops)for(let _ of r.effectHandlerParamDrops)r.emitter.emitLine(`${t}${_};`);if(or(t,r,e,!1,!0,!0),qr(t,r,e,!0),r.currentFunctionType){let _=r.currentFunctionType.return.type;if(!De(_)){let c=r.overrideReturnTypeStr??j(_,n);if(c!=="void")return`return (${c}){0}`}}return"return"}let s=q(i,t,n);if(r.effectHandlerParamDrops)for(let _ of r.effectHandlerParamDrops)r.emitter.emitLine(`${t}${_};`);if(or(t,r,e,!1,!0,!0),qr(t,r,e,!0),(r.isModuleEffectMemberFunction||r.currentEvidenceParams&&r.currentEvidenceParams.size>0)&&r.currentFunctionType){let _=(u=i.$)==null?void 0:u.type;if(_&&!De(_)){let f=j(_,n);r.emitter.emitLine(`${t}{ ${f} _esc_val = ${s}; memcpy(__yo_effect_escape_value, &_esc_val, sizeof(${f})); }`)}let c=r.currentFunctionType.return.type;if(!De(c)){let f=r.overrideReturnTypeStr??j(c,n);if(f!=="void")return`return (${f}){0}`}return"return"}return`return ${s}`}function Jp(e,t,n){let r;switch(e.tag){case"FnCall":r=Bv(e,t,n);break;case"Atom":r=pa(e,n,t);break}return r}function Bv(e,t,n){var r,i,o,a,s,l,u,_,c,f,p,m,h,y,g;if((r=e.$)!=null&&r.macroExpansion)return q(e.$.macroExpansion,t,n);if(S(e.func)&&E(e.func,".",2)&&e.func.args[1]&&K(e.func.args[1])){let v=e.func.args[1].token.value,T=e.func.args[0],$=(i=T==null?void 0:T.$)==null?void 0:i.type;if($&&z($)&&at($)){if(v===F.___drop[0]){let C=q(T,t,n);return`if (${C} != NULL) { __yo_decr_rc((void*)${C}); }`}if(v===F.___dup[0])return`__yo_incr_rc((void*)${q(T,t,n)})`}}if(af(e))return sf(e,t,n);if(E(e,F.__yo_decr_rc))return Np(e,t,n);if(E(e,F.__yo_incr_rc))return Vp(e,t,n);if(E(e,F.__yo_rc_own))return xp(e,t,n);if(E(e,F.__yo_drop_array_element))return Dp(e,t,n);if(E(e,F.__yo_dup_array_element))return Mp(e,t,n);if(E(e,F.__yo_drop_tuple_element))return Op(e,t,n);if(E(e,F.__yo_dup_tuple_element))return Rp(e,t,n);if(E(e,F.___dup))return Pp(e,t,n);if(E(e,F.___drop))return Up(e,t,n);if(E(e,F.__yo_dyn_drop))return zp(e,t,n);if(E(e,F.__yo_dyn_dup))return Bp(e,t,n);if(E(e,F.__yo_incr_rc_atomic))return Gp(e,t,n);if(E(e,F.__yo_decr_rc_atomic))return Wp(e,t,n);if(E(e,F.__yo_iso_extract))return fp(e,t,n);if(E(e,F.__yo_iso_dispose))return pp(e,t,n);if(Bu(e))return dp(e,t,n);if(E(e,F.__yo_sometype_drop))return qp(e,t,n);if(E(e,F.__yo_sometype_dup))return Yp(e,t,n);if(E(e,F.__yo_gc_collect))return _p(e,t,n);if(E(e,F.rc))return Hp(e,t,n);if(E(e,F.panic))return wp(e,t,n);if(E(e,F.asm))return Lp(e,t,n);if(E(e,F.global_asm))return Ip(e,t,n);if(E(e,P.test))return"/* test declaration skipped */";if(E(e,F.__yo_thread_set_maximum_threads))return Ep(e,t,n);if(E(e,P.op_and))return jf(e,t,n);if(E(e,P.op_or))return Kf(e,t,n);if(An(e))return(o=e.$)!=null&&o.awaitAnalysis?lf(e,t,n):pf(e,t,n);if(E(e,P.dyn))return up(e,t,n);if(_r(e))return ep(e,t,n);if(dc(e))return tp(e,t,n);if(dl(e)){let v=e.args[0];if(!v)return"// Error: spawn requires a Future argument";let $=n.emitter,C=q(v,t,n),k=(a=v.$)==null?void 0:a.type,b=k?j(k,n):"void*",w=(s=e.$)==null?void 0:s.type,A=w?j(w,n):null,L=(l=e.$)!=null&&l.variableName?`__spawn_future_${e.$.variableName}`:"__spawn_future",N=(u=e.$)!=null&&u.variableName?`__spawn_state_${e.$.variableName}`:"__spawn_state";return $.emitLine(`${t}// io.spawn \u2014 start cold Future, return JoinHandle`),$.emitLine(`${t}${b} ${L} = ${C};`),$.emitLine(`${t}int ${N} = ${L}->state;`),$.emitLine(`${t}if (${N} == -2) {`),$.emitLine(`${t} fprintf(stderr, "panic: attempted to spawn an aborted Future\\n");`),$.emitLine(`${t} abort();`),$.emitLine(`${t}}`),es((_=v.$)==null?void 0:_.type)||($.emitLine(`${t}if (${N} == 0 && ${L}->__yo_resume_fn) {`),Pv(e,L,t,n),$.emitLine(`${t} __yo_incr_rc((void*)${L});`),$.emitLine(`${t} ${L}->__yo_resume_fn((void*)${L});`),$.emitLine(`${t}}`)),A?`(${A}){ .__future = (void*)${L} }`:`(void*)${L}`}if(mc(e))return np(e,t,n);if(E(e,P.return))return Vf(e,t,n);if(E(e,P.escape))return zv(e,t,n);if(E(e,F.__yo_array_fill,2))return Qf(e,t,n);if(E(e,"::",2))return"";if(E(e,":",2))return op(e,t,n);if(E(e,":=",2)){let v=cp(e,t,n);if(v!==void 0)return v}else{if(E(e,"=",2))return Zf(e,t,n);if((c=e.$)!=null&&c.value&&!Ie((f=e.$)==null?void 0:f.value)&&!De(e.$.type)&&!Gt((p=e.$)==null?void 0:p.controlFlow))return Yn(e.$.value,n,e);if(E(e,".",2))return Ap(e,t,n);if(E(e,P.begin))return ip(e,t,n);if(E(e,P.cond))return ap(e,t,n);if(E(e,P.match))return yp(e,t,n);if(E(e,F.__yo_address_of,1))return Sp(e,t,n);if(E(e,P.tuple))return Xp(e,t,n);if(E(e,P.array)){let v=Xf(e,t,n);if(v!==void 0)return v}else{if(E(e,P.recur))return jp(e,t,n);if(E(e,P.runtime,1))return q(e.args[0],t,n);if(E(e,F.sizeof,1))return Kp(e,t,n);if(E(e,F.typeid,1))return Qp(e,t,n);if(E(e,F.downcast,2))return lp(e,t,n);if(E(e,ko)){let v=((m=e.$)==null?void 0:m.runtimeArgExprsInOrder)||e.args;if(v){let T=n,$=v.map(C=>{var b,w;let k=q(C,t,n);if((b=C.$)!=null&&b.deferredDupExpressions&&C.$.deferredDupExpressions.length>0){Wt(C,t,T);let A=C.$.deferredDupExpressions[0];if(S(A)&&((w=A.$)!=null&&w.variableName))return We(A.$.variableName,A.$.env)}return k});return rs(e.func.token.value,$,e,n,t)}}else{if(E(e,P.while))return Zp(e,t,n);if(E(e,"->",2)&&S(e.args[0])&&E(e.args[0],P.fn)){let v=(h=e.$)==null?void 0:h.value;return he(v)?Yn(v,n):"// Error: Anonymous function missing function value"}else{if(E(e,F.consume))return sp(e,t,n);if(E(e,F.comptime_expect_error)||E(e,F.comptime_assert)||E(e,F.__yo_var_print_info)||E(e,F.__yo_var_is_owning_the_rc_value)||E(e,F.__yo_var_has_other_aliases))return"";if(E(e,P.open))return gp(e,t,n);if((y=e.$)!=null&&y.indexTraitPtrType&&((g=e.$)!=null&&g.indexMethodType))return Rv(e,t,n);{let v=kp(e,t,n);if(v!==void 0)return v}}}}}if(S(e))throw new Error(`Unhandled function call: ${I(e)}`);return`// Failed to transpile ${I(e)}`}function ed({expr:e,env:t,context:n}){Ge(e,F.alignof,1);let r=e.args[0],i=O({expr:r,env:t,context:{...n}});if(!i.$)throw d({token:r.token,errorMessage:"Failed to evaluate expression."});t=i.$.env;let o;i.$.value&&W(i.$.value)?o=i.$.value.value:o=i.$.type;let a=Xr(o),s;return a===null?s=oe(vn(),{env:t,context:n}):s=qn("Usize",a),e.$={env:t,type:vn(),value:s,pathCollection:[]},e}function td({expr:e,env:t,context:n}){let r=E(e,P.op_and)?"and":"or",i=e.args;if(i.length===0){let u=Zt(r==="and");return e.$={env:t,type:Ut(),value:u,pathCollection:[],isAccessingProperty:!1},e}let o=t,a,s=!1,l=!1;for(let u=0;u<i.length;u++){let _=i[u],c=O({expr:_,env:o,context:{...n}});if(!c.$||!lr(c.$.type))throw d({token:_.token,errorMessage:`Expected bool type for "${r}" argument, got:
|
|
11396
|
+
${_}}`),u}function vp(e,t,n){var g,v,T,$,C,k;let r=(g=e.$)==null?void 0:g.runtimeArgExprsInOrder;if(!r||r.length!==1)return"/* Error: __yo_thread_spawn requires exactly 1 argument */";let i=r[0],o=(v=i.$)==null?void 0:v.type;if(!o)return"/* Error: __yo_thread_spawn argument has no type */";let a,s;if(z(o)){let b=o;b.resolvedConcreteType&&(a=b.resolvedConcreteType.id,s=b.resolvedConcreteType)}else Ae(o)&&(a=o.id,s=o);if(!a||!s)return"/* Error: __yo_thread_spawn could not determine concrete closure type */";let l=n.implClosureCallMap.get(a);if(!l)return`/* Error: __yo_thread_spawn could not find closure function for type ${a} */`;let u=l.functionCName,_=j(s,n),c=hp(u,l,_,s,n,((T=e.$)==null?void 0:T.env.modulePath)??""),f=q(i,t,n),p=($=i.$)!=null&&$.variableName?We(i.$.variableName,i.$.env):f,m=`_thread_closure_data_${mt(((C=e.$)==null?void 0:C.env.modulePath)??"")}`;n.emitter.emitLine(`${t}${_}* ${m} = (${_}*)__yo_malloc(sizeof(${_}));`),n.emitter.emitLine(`${t}*${m} = ${p};`);let h=fr(s,n);h&&n.emitter.emitLine(`${t}${h}(*${m});`);let y=(k=e.$)==null?void 0:k.variableName;return y?(n.emitter.emitLine(`${t}__yo_thread_t ${y} = __yo_thread_spawn(${c}, ${m});`),y):`__yo_thread_spawn(${c}, ${m})`}function Tp(e,t,n){var y,g,v,T,$;let r=(y=e.$)==null?void 0:y.runtimeArgExprsInOrder;if(!r||r.length!==1)return"/* Error: __yo_worker_spawn requires exactly 1 argument */";let i=r[0],o=(g=i.$)==null?void 0:g.type;if(!o)return"/* Error: __yo_worker_spawn argument has no type */";let a,s;if(z(o)){let C=o;C.resolvedConcreteType&&(a=C.resolvedConcreteType.id,s=C.resolvedConcreteType)}else Ae(o)&&(a=o.id,s=o);if(!a||!s)return"/* Error: __yo_worker_spawn could not determine concrete closure type */";let l=n.implClosureCallMap.get(a);if(!l)return`/* Error: __yo_worker_spawn could not find closure function for type ${a} */`;let u=l.functionCName,_=j(s,n),c=hp(u,l,_,s,n,((v=e.$)==null?void 0:v.env.modulePath)??""),f=q(i,t,n),p=(T=i.$)!=null&&T.variableName?We(i.$.variableName,i.$.env):f,m=`_worker_closure_data_${mt((($=e.$)==null?void 0:$.env.modulePath)??"")}`;n.emitter.emitLine(`${t}${_}* ${m} = (${_}*)__yo_malloc(sizeof(${_}));`),n.emitter.emitLine(`${t}*${m} = ${p};`);let h=fr(s,n);return h&&n.emitter.emitLine(`${t}${h}(*${m});`),n.emitter.emitLine(`${t}__yo_worker_spawn(${c}, ${m});`),""}function Ep(e,t,n){let r=e.args[0];return r?`__yo_thread_set_maximum_threads(${q(r,t,n)})`:"// Error: __yo_thread_set_maximum_threads requires exactly 1 argument"}function $p(e,t){let n=t;if(!(n.inAsyncStateMachine||n.inEffectStateMachine)||!n.stateMachineVariables)return e;for(let[r,i]of n.stateMachineVariables)if(i.name===e)return`sm->${i.kind==="outer"?`__capture.${i.name}`:`var_${r}`}`;return e}function Cr(e,t,n){let r=n;if(!(r.inAsyncStateMachine||r.inEffectStateMachine)||!r.stateMachineVariables)return;let i=r.stateMachineVariables.get(e);if(!i){for(let[,o]of r.stateMachineVariables)if(o.name===e){i=o;break}}if(i&&i.kind!=="outer"){if(i.type&&at(i.type))return;let o=`var_${i.id}`,a=be(e);n.emitter.emitLine(`${t}sm->${o} = ${a};`)}}function kp(e,t,n){var o,a,s,l,u,_,c,f,p,m,h,y,g,v,T,$,C,k,b,w,A,L,N,x,V,U,R,D,H,B,G,Q,Y,J,se,ve,re,ce,we,Se,Ve,de,ee,fe,me,Le,qe,dt,kt,Rt,Ze,Tt,Jt,At,gt,nt,Ft,qt,Et,Lt,nn,te,pe,$e,ie,_e,ye,Re,Ke,Pe,Z;if(((o=e.$)==null?void 0:o.value)!==void 0&&!Ie(e.$.value))return(a=e.$)!=null&&a.deferredDropExpressions&&fn(e,t,n),De(e.$.type)?"":Yn(e.$.value,n,e);let r=(s=e.func.$)==null?void 0:s.value,i=((l=e.func.$)==null?void 0:l.type)??(ge(r)?r.specializedType??r.type:void 0);if(ne(i)){let X=(u=e.$)==null?void 0:u.runtimeArgExprsInOrder;if(X){let he=!1;if(S(e.func)&&E(e.func,".",2)){let Ee=e.func.args[0],Oe=(_=Ee==null?void 0:Ee.$)==null?void 0:_.type;Oe&&st(Oe)&&(he=!0)}let Ce=X.map((Ee,Oe)=>{var Ue,ze,Qe,Ye,Ne,et,ke,rt,ft;if((Ue=Ee.$)!=null&&Ue.variableName&&((ze=Ee.$)!=null&&ze.type)){let yt=n,Vt=yt.currentClosureCaptures&&yt.currentClosureCaptures.includes(Ee.$.variableName)&&K(Ee)&&Ee.$.env&&yt.currentClosureCaptureFrameLevel!==void 0&&vi(Ee.token.value,Ee.$.env,yt.currentClosureCaptureFrameLevel),xt=q(Ee,t,n),Xt=!1;if(K(Ee)&&Ee.$.env&&Ee.$.variableName){let nr=ae(Ee.$.env,Ee.$.variableName);nr.length>0&&nr[nr.length-1].isCompileTimeOnly&&(Xt=!0)}let _n=(yt.inAsyncStateMachine||yt.inEffectStateMachine)&&xt.startsWith("sm->"),Qn=!1;if(xt&&xt!==Ee.$.variableName&&!Vt&&!_n&&!Xt){let nr=We(Ee.$.variableName,Ee.$.env);if(xt!==nr){let sr=Ee.$.convertedRuntimeType||Ee.$.type,$i=Kt(sr,Ee.$.variableName,n);n.emitter.emitLine(`${t}${$i} = ${xt};`),Qn=!0,Cr(Ee.$.variableName,t,n)}}let Yr=Qn?Ee.$.variableName:xt;if((Qe=Ee.$)!=null&&Qe.deferredDupExpressions&&Ee.$.deferredDupExpressions.length>0){let nr=new Set;(Ye=Ee.$)!=null&&Ye.variableName&&nr.add(We(Ee.$.variableName,Ee.$.env)),xt&&nr.add(xt),K(Ee)&&nr.add(We(Ee.token.value,Ee.$.env));let sr=Ee.$.deferredDupExpressions.find($i=>{var io;let Ui=Fl($i);return Ui?nr.has(We(Ui,(io=$i.$)==null?void 0:io.env)):!1});sr&&(Wt(Ee,t,yt),S(sr)&&((Ne=sr.$)!=null&&Ne.variableName)&&(Yr=We(sr.$.variableName,sr.$.env)))}if(he&&Oe===0){if(S(e.func)&&E(e.func,".",2)){let sr=e.func.args[0],$i=(et=sr==null?void 0:sr.$)==null?void 0:et.type,Ui=e.func.args[1];if(K(Ui)&&st($i)){let io=Ui.token.value;if($i.trait.fields.find(Zl=>Zl.label===io))return _n?xt:be(Yr,Ee.$.type.isExtern==="c")}}let nr=(ke=Ee.$)==null?void 0:ke.type;return nr&&je(nr)?_n?`${xt}->data`:`${be(Yr,Ee.$.type.isExtern==="c")}->data`:_n?`(${xt}).data`:`(${be(Yr,Ee.$.type.isExtern==="c")}).data`}else return Vt||_n||Xt?xt:be(Yr,Ee.$.type.isExtern==="c")}else if(he&&Oe===0){let yt=q(Ee,t,n);if(S(e.func)&&E(e.func,".",2)){let xt=e.func.args[0],Xt=(rt=xt==null?void 0:xt.$)==null?void 0:rt.type,_n=e.func.args[1];if(K(_n)&&st(Xt)){let Qn=_n.token.value;if(Xt.trait.fields.find(nr=>nr.label===Qn))return yt}}let Vt=(ft=Ee.$)==null?void 0:ft.type;return Vt&&je(Vt)?`(${yt})->data`:`(${yt}).data`}else return q(Ee,t,n)}),He=Ce.join(", ");if(i.isExtern==="yo"&&i.externName){let Ee=i.externName;return ko.includes(Ee)?rs(Ee,Ce,e,n,t):Ee==="__yo_thread_spawn"?vp(e,t,n):Ee==="__yo_worker_spawn"?Tp(e,t,n):De(i.return.type)?(n.emitter.emitLine(`${t}${Ee}(${He});`),(c=e.$)!=null&&c.deferredDropExpressions&&fn(e,t,n),""):`${Ee}(${He})`}{let Ee=n;if((f=Ee.currentEvidenceParams)!=null&&f.size){let Oe=(p=e.func.token)==null?void 0:p.value,Ue;if(Oe==="."&&S(e.func)&&E(e.func,".",2)){let ze=e.func.args[1];ze&&K(ze)&&(Oe=ze.token.value);let Qe=e.func.args[0];if(Qe&&K(Qe))Ue=Qe.token.value;else if(Qe&&S(Qe)&&E(Qe,".",2)){let Ye=Qe.args[0];Ye&&K(Ye)&&(Ue=Ye.token.value)}}if(Oe&&Oe!=="."){for(let ze of Ee.currentEvidenceParams.values())if(ze.fieldLabel===Oe||ze.implicitLabel===Oe||ze.fieldPath[ze.fieldPath.length-1]===Oe){if(Ue&&Ue!==ze.implicitLabel)continue;return bp(ze.cParamName,i,Ce,X,e,t,Ee,ze)}}}}if(ge(r)){let Ee=gi(r);if(Ee)return rs(Ee,Ce,e,n,t);let Oe=r.specializedType??r.type,Ue=n;if(Ue.currentEvidenceParams&&r.isModuleEffectMember){let Qe,Ye=((m=e.func.$)==null?void 0:m.env)??((h=e.$)==null?void 0:h.env);if(Ye)for(let Ne of Ue.currentEvidenceParams.values()){let et=ae(Ye,Ne.implicitLabel),ke=et[et.length-1],rt=(y=ke==null?void 0:ke.value)==null?void 0:y[0];if(rt&&wt(rt)){let ft=rt,yt=!0;for(let Vt=0;Vt<Ne.fieldPath.length-1;Vt++){let xt=Ne.fieldPath[Vt],Xt=ft.type.fields.findIndex(_n=>_n.label===xt);if(Xt>=0&&ft.fields[Xt]&&wt(ft.fields[Xt]))ft=ft.fields[Xt];else{yt=!1;break}}if(yt){let Vt=Ne.fieldPath[Ne.fieldPath.length-1],xt=ft.type.fields.findIndex(Xt=>Xt.label===Vt);if(xt>=0){let Xt=ft.fields[xt];if(Xt&&ge(Xt)&&Xt.funcId===r.funcId){Qe=Ne;break}}}}}if(Qe){let Ne=Qe.cParamName;return bp(Ne,Oe,Ce,X,e,t,Ue,Qe)}}let ze=(g=n.functions[r.funcId])==null?void 0:g.cName;if(ze){let Qe=r.specializedType??r.type,Ye=pn(Qe);if(Ye.length===0&&r.specializedType){let ke=pn(r.type);ke.length>0&&ke.some(rt=>rt.fieldFunctionType.forallParameters&&rt.fieldFunctionType.forallParameters.length>0)&&(Ye=ke)}if(Ye.length>0){let{args:ke,isHandlerInstallation:rt}=Wu(Ye,r,e,n);if(ke.length>0){let ft=He?`${He}, ${ke.join(", ")}`:ke.join(", ");return qu(ze,ft,Oe,e,X,t,n,rt)}}let Ne=r.isControlFunction||r.isModuleEffectMember||(($=(T=(v=r.body)==null?void 0:v.$)==null?void 0:T.effectAnalysis)==null?void 0:$.hasEffects),et=!1;if(Ne){if(r.isControlFunction||r.isModuleEffectMember){let ke=((k=(C=e.func)==null?void 0:C.$)==null?void 0:k.env)??((b=e.$)==null?void 0:b.env);if(ke){let rt=ja(ke,ft=>{var yt;return ft.isImplicit===!0&&ge((yt=ft.value)==null?void 0:yt[0])&&ft.value[0].funcId===r.funcId});rt>=0&&rt>ke.functionDeclarationFrameLevel&&((w=ke.frames[rt])!=null&&w.isBeginBlockFrame)&&(et=!0)}}else if(r.specializedType){let ke=pn(r.type);if(ke.length>0){let rt=((L=(A=e.func)==null?void 0:A.$)==null?void 0:L.env)??((N=e.$)==null?void 0:N.env);if(rt)for(let ft of ke){let yt=ja(rt,Vt=>Vt.isImplicit===!0&&(Vt.name===ft.implicitLabel||Vt.name===ft.fieldLabel));if(yt>=0&&yt>rt.functionDeclarationFrameLevel&&((x=rt.frames[yt])!=null&&x.isBeginBlockFrame)){et=!0;break}}}}}if(De(Oe.return.type))return n.emitter.emitLine(`${t}${ze}(${He});`),(V=e.$)!=null&&V.deferredDropExpressions&&fn(e,t,n),Ne&&Cp(t,n,et,e),"";{let ke=(U=e.$)==null?void 0:U.variableName;if(ke){let rt=((R=r.specializedType)==null?void 0:R.return.type)??Oe.return.type,ft=(D=e.$)==null?void 0:D.type,yt=ft&&at(ft),Vt=rt&&at(rt),xt;if(yt&&Vt){let _n=r.body;if(_n&&E(_n,"begin")){let Qn=_n.args;if(Qn.length>0){let Yr=Qn[Qn.length-1];An(Yr)&&(_n=Yr)}}if(_n&&An(_n)&&((H=_n.$)!=null&&H.asyncStateMachineStructName)){let Qn=_n.$.asyncStateMachineStructName;xt=`${Qn}*`,n.tempVarAsyncStructNames||(n.tempVarAsyncStructNames=new Map),n.tempVarAsyncStructNames.set(ke,Qn)}else ft&&z(ft)&&ft.resolvedConcreteType?xt=j(ft,n):xt=j(rt,n)}else xt=j(rt??ft,n);let Xt=n;return Xt.declaredTempVars||(Xt.declaredTempVars=new Set),Xt.declaredTempVars.has(ke)||(Xt.declaredTempVars.add(ke),n.emitter.emitLine(`${t}${xt} ${ke} = ${ze}(${He});`)),Cr(ke,t,n),(B=e.$)!=null&&B.deferredDropExpressions&&fn(e,t,n),Ne&&Cp(t,n,et,e),ke}else return`// Error: Regular function call returns ${j(((G=r.specializedType)==null?void 0:G.return.type)??Oe.return.type,n)} but no temp variable assigned`}}}else{let Ee=n.externFunctions[i.id];if(Ee){let Oe=Ee.cName;return(Q=e.$)!=null&&Q.deferredDropExpressions&&fn(e,t,n),`${Oe}(${He})`}else{let Oe=q(e.func,t,n);if(r&&ne(r.type)){let ke=pn(r.type);if(ke.length>0){let{args:rt,isHandlerInstallation:ft}=Wu(ke,r,e,n);if(rt.length>0){let yt=He?`${He}, ${rt.join(", ")}`:rt.join(", ");return qu(Oe,yt,i,e,X,t,n,ft)}}}let Ue=((Y=e.$)==null?void 0:Y.type)??i.return.type,ze=j(Ue,n),Qe=i.parameters.filter(ke=>!ke.isCompileTimeOnly).map(ke=>j(ke.type,n)),Ye=`((${ze} (*)(${Qe.join(", ")}))${Oe})`,Ne=n,et=Oe.includes("__capture.")&&!!Ne.inAsyncStateMachine;if(et&&n.emitter.emitLine(`${t}__yo_effect_escaped = 0;`),De(i.return.type)||De(Ue)){if(n.emitter.emitLine(`${t}${Ye}(${He});`),(J=e.$)!=null&&J.deferredDropExpressions&&fn(e,t,n),et){if(n.emitter.emitLine(`${t}if (__yo_effect_escaped) {`),X){for(let ke of X)if((se=ke.$)!=null&&se.variableName&&((ve=ke.$)!=null&&ve.type)&&it(ke.$.type)){let rt=$p(be(ke.$.variableName),n),ft=Vi(rt,ke.$.type,n);ft&&(n.emitter.emitLine(`${t} ${ft};`),n.emitter.emitLine(`${t} memset(&${rt}, 0, sizeof(${rt}));`))}}Ar({emitter:n.emitter,indent:t+" ",resultCode:void 0,debugLabel:void 0}),n.emitter.emitLine(`${t}}`)}return""}else{let ke=(re=e.$)==null?void 0:re.variableName;if(ke){let rt=i.return.type,ft=(ce=e.$)==null?void 0:ce.type,yt=ft&&rt&&at(ft)&&at(rt)?rt:ft??rt,Vt=n;if(Vt.declaredTempVars||(Vt.declaredTempVars=new Set),Vt.declaredTempVars.has(ke)||(Vt.declaredTempVars.add(ke),n.emitter.emitLine(`${t}${j(yt,n)} ${ke} = ${Ye}(${He});`)),Cr(ke,t,n),(we=e.$)!=null&&we.deferredDropExpressions&&fn(e,t,n),et){if(n.emitter.emitLine(`${t}if (__yo_effect_escaped) {`),X){for(let xt of X)if((Se=xt.$)!=null&&Se.variableName&&((Ve=xt.$)!=null&&Ve.type)&&it(xt.$.type)){let Xt=$p(be(xt.$.variableName),n),_n=Vi(Xt,xt.$.type,n);_n&&(n.emitter.emitLine(`${t} ${_n};`),n.emitter.emitLine(`${t} memset(&${Xt}, 0, sizeof(${Xt}));`))}}Ar({emitter:n.emitter,indent:t+" ",resultCode:void 0,debugLabel:void 0}),n.emitter.emitLine(`${t}}`)}return ke}else return`// Error: Function parameter call returns ${j(i.return.type,n)} but no temp variable assigned`}}}}}else if(i&&zn(i)){let X=i,he=Kn(X),Ce=st(X);{let He=he.isFn.callType,Ee=(de=e.$)==null?void 0:de.runtimeArgExprsInOrder;if(Ee){let Oe=n;for(let Ne of Ee)if((ee=Ne.$)!=null&&ee.variableName&&((fe=Ne.$)!=null&&fe.type)){let et=Oe.currentClosureCaptures&&Oe.currentClosureCaptures.includes(Ne.$.variableName)&&K(Ne)&&Ne.$.env&&Oe.currentClosureCaptureFrameLevel!==void 0&&vi(Ne.token.value,Ne.$.env,Oe.currentClosureCaptureFrameLevel),ke=q(Ne,t,n),rt=!1;if(K(Ne)&&Ne.$.env&&Ne.$.variableName){let yt=ae(Ne.$.env,Ne.$.variableName);yt.length>0&&yt[yt.length-1].isCompileTimeOnly&&(rt=!0)}let ft=(Oe.inAsyncStateMachine||Oe.inEffectStateMachine)&&ke.startsWith("sm->");if(ke&&ke!==Ne.$.variableName&&!et&&!ft&&!rt){let yt=Ne.$.convertedRuntimeType||Ne.$.type,Vt=Kt(yt,Ne.$.variableName,n);n.emitter.emitLine(`${t}${Vt} = ${ke};`),Cr(Ne.$.variableName,t,n)}}let Ue=q(e.func,t,n),ze=Ee.map(Ne=>{var et,ke,rt,ft;if((et=Ne.$)!=null&&et.variableName&&((ke=Ne.$)!=null&&ke.type)){if(Oe.currentClosureCaptures&&Oe.currentClosureCaptures.includes(Ne.$.variableName)&&K(Ne)&&Ne.$.env&&Oe.currentClosureCaptureFrameLevel!==void 0&&vi(Ne.token.value,Ne.$.env,Oe.currentClosureCaptureFrameLevel))return q(Ne,t,n);{let Vt=We(Ne.$.variableName,Ne.$.env),xt=(Oe.inAsyncStateMachine||Oe.inEffectStateMachine)&&Vt.startsWith("sm->"),Xt=Vt;if((rt=Ne.$)!=null&&rt.deferredDupExpressions&&Ne.$.deferredDupExpressions.length>0){Wt(Ne,t,Oe);let _n=Ne.$.deferredDupExpressions[0];S(_n)&&((ft=_n.$)!=null&&ft.variableName)&&(Xt=We(_n.$.variableName,_n.$.env))}return xt?Vt:Xt}}else return q(Ne,t,n)}),Qe;if(Ce){let Ne=[`(${Ue}).data`,...ze];Qe=`(${Ue}).vtable->call(${Ne.join(", ")})`}else{let Ne;if(z(X)){let ke=X;ke.resolvedConcreteType&&(Ne=ke.resolvedConcreteType.id)}let et=Ne?n.implClosureCallMap.get(Ne):void 0;if(et){let ke=pn(He);if(ke.length>0){let{args:ft,isHandlerInstallation:yt}=Wu(ke,{},e,Oe);if(ft.length>0){let Vt=[`&(${Ue})`,...ze,...ft];return qu(et.functionCName,Vt.join(", "),He,e,Ee,t,Oe,yt)}}let rt=[`&(${Ue})`,...ze];Qe=`${et.functionCName}(${rt.join(", ")})`}else{let ke=[`(${Ue}).data`,...ze];Qe=`(${Ue}).call(${ke.join(", ")})`}}let Ye=He.return.type;if(De(Ye))return n.emitter.emitLine(`${t}${Qe};`),(me=e.$)!=null&&me.deferredDropExpressions&&fn(e,t,n),"";{let Ne=(Le=e.$)==null?void 0:Le.variableName;return Ne?(n.emitter.emitLine(`${t}${j(Ye,n)} ${Ne} = ${Qe};`),Cr(Ne,t,n),(qe=e.$)!=null&&qe.deferredDropExpressions&&fn(e,t,n),Ne):`// Error: Closure call returns ${j(Ye,n)} but no temp variable assigned`}}else return"// Error: No runtime args found for closure call"}}else if(W(r))if(Ae(r.value)){let X=r.value,he=(dt=e.$)==null?void 0:dt.runtimeArgExprsInOrder,Ce=(kt=n.types[X.id])==null?void 0:kt.cName,He=X.fields.map(Oe=>Oe.label),Ee=(Rt=e.$)==null?void 0:Rt.variableName;if(he&&Ce&&He.length===he.length){if(X.isNewtype&&X.fields.length===1){let Oe=he[0],Ue=q(Oe,t,n),ze=Ue;if((Ze=Oe.$)!=null&&Ze.deferredDupExpressions&&Oe.$.deferredDupExpressions.length>0){let Ye=n;if((Tt=Oe.$)!=null&&Tt.variableName&&((Jt=Oe.$)!=null&&Jt.type)){let et=We(Oe.$.variableName,Oe.$.env);if(Ue!==et){let ke=Oe.$.type,rt=j(ke,n);n.emitter.emitLine(`${t}${rt} ${et} = ${Ue};`)}}Wt(Oe,t,Ye);let Ne=Oe.$.deferredDupExpressions[0];S(Ne)&&((At=Ne.$)!=null&&At.variableName)&&(ze=We(Ne.$.variableName,Ne.$.env))}let Qe=`((${Ce})(${ze}))`;if(Ee&&((gt=e.$)!=null&>.type)){let Ye=Kt(e.$.type,Ee,n);return n.emitter.emitLine(`${t}${Ye} = ${Qe};`),Cr(Ee,t,n),Ee}else return Qe}if(X.isReferenceSemantics){let Oe=n,Ue=he.map(Ye=>{var et,ke,rt,ft;let Ne=q(Ye,t,n);if((et=Ye.$)!=null&&et.deferredDupExpressions&&Ye.$.deferredDupExpressions.length>0){if((ke=Ye.$)!=null&&ke.variableName&&((rt=Ye.$)!=null&&rt.type)){let Vt=We(Ye.$.variableName,Ye.$.env);if(Ne!==Vt){let xt=Ye.$.type,Xt=j(xt,n);n.emitter.emitLine(`${t}${Xt} ${Vt} = ${Ne};`)}}Wt(Ye,t,Oe);let yt=Ye.$.deferredDupExpressions[0];if(S(yt)&&((ft=yt.$)!=null&&ft.variableName))return We(yt.$.variableName,yt.$.env)}return Ne}).join(", "),Qe=`${`__yo_new_${Ce}`}(${Ue})`;if(Ee&&((nt=e.$)!=null&&nt.type)){let Ye=Kt(e.$.type,Ee,n);return n.emitter.emitLine(`${t}${Ye} = ${Qe};`),Cr(Ee,t,n),Ee}else return Qe}else{let Oe=n,Ue=he.map((Qe,Ye)=>{var rt,ft,yt,Vt;let Ne=q(Qe,t,n),et=ut(X)?`_${Ye}`:be(He[Ye],X.isExtern==="c"),ke=Ne;if((rt=Qe.$)!=null&&rt.deferredDupExpressions&&Qe.$.deferredDupExpressions.length>0){if((ft=Qe.$)!=null&&ft.variableName&&((yt=Qe.$)!=null&&yt.type)){let Xt=We(Qe.$.variableName,Qe.$.env),_n=Qe.$.type,Qn=j(_n,n);Ne!==Xt&&n.emitter.emitLine(`${t}${Qn} ${Xt} = ${Ne};`)}Wt(Qe,t,Oe);let xt=Qe.$.deferredDupExpressions[0];S(xt)&&((Vt=xt.$)!=null&&Vt.variableName)&&(ke=We(xt.$.variableName,xt.$.env))}return`.${et} = `+ke}).join(", "),ze=`(${Ce}){ ${Ue} }`;if(Ee&&((Ft=e.$)!=null&&Ft.type)){let Qe=Kt(e.$.type,Ee,n);return n.emitter.emitLine(`${t}${Qe} = ${ze};`),Cr(Ee,t,n),Ee}else return ze}}}else{if(zn(r.value))return"// Error: Closure construction should have been handled by closureFunctionValue check at top of generateFuncCall";if(Bt(r.value)){let X=(qt=e.$)==null?void 0:qt.variableName,he=e.args[0];if(he&&S(he)&&E(he,":",2)){let Ce=he.args[0],He=he.args[1],Ee=(Et=n.types[r.value.id])==null?void 0:Et.cName;if(Ee&&K(Ce)&&He){let Oe=n,Ue=Ce.token.value,ze=We(Ue,(Lt=Ce.$)==null?void 0:Lt.env),Ye=q(He,t,n);if((nn=He.$)!=null&&nn.deferredDupExpressions&&He.$.deferredDupExpressions.length>0){Wt(He,t,Oe);let et=He.$.deferredDupExpressions[0];S(et)&&((te=et.$)!=null&&te.variableName)&&(Ye=We(et.$.variableName,et.$.env))}let Ne=`(${Ee}){ .${ze} = ${Ye} }`;if(X&&((pe=e.$)!=null&&pe.type)){let et=Kt(e.$.type,X,n);return n.emitter.emitLine(`${t}${et} = ${Ne};`),Cr(X,t,n),X}else return Ne}}}else if(Be(r.value)){let X=r.value,he=($e=e.$)==null?void 0:$e.runtimeArgExprsInOrder,Ce=(ie=n.types[X.id])==null?void 0:ie.cName,He=(_e=e.$)==null?void 0:_e.variableName;if(X.selectedVariantName&&he&&Ce){if(Gn(X)){let Qe=X.selectedVariantName,Ye=X.variants.find(Ne=>Ne.name===Qe);if(Ye){if(!Ye.fields||Ye.fields.length===0){let Ne="NULL";if(He&&((ye=e.$)!=null&&ye.type)){let et=Kt(e.$.type,He,n);return n.emitter.emitLine(`${t}${et} = ${Ne};`),Cr(He,t,n),He}else return Ne}else if(Ye.fields.length===1){let Ne=q(he[0],t,n);if(He&&((Re=e.$)!=null&&Re.type)){let et=Kt(e.$.type,He,n);return n.emitter.emitLine(`${t}${et} = ${Ne};`),Cr(He,t,n),He}else return Ne}}}if(Fr(X)){let Qe=X.selectedVariantName,Ye=Rn(X,Qe,n);if(He&&((Ke=e.$)!=null&&Ke.type)){let Ne=Kt(e.$.type,He,n);return n.emitter.emitLine(`${t}${Ne} = ${Ye};`),Cr(He,t,n),He}else return Ye}let Ue=X.selectedVariantName,ze=X.variants.find(Qe=>Qe.name===Ue);if(ze){let Qe=((Pe=ze.fields)==null?void 0:Pe.filter(ke=>!De(ke.type)))||[],Ye=n,Ne=he.map((ke,rt)=>{var ft,yt,Vt,xt,Xt;if(ze.fields){let _n=ze.fields[rt];if(_n&&!De(_n.type)){let Qn=q(ke,t,n),Yr=We(_n.label,(ft=ke.$)==null?void 0:ft.env),nr=Qn;if((yt=ke.$)!=null&&yt.variableName&&((Vt=ke.$)!=null&&Vt.type)){let sr=Ye.currentClosureCaptures&&Ye.currentClosureCaptures.includes(ke.$.variableName)&&K(ke)&&ke.$.env&&Ye.currentClosureCaptureFrameLevel!==void 0&&vi(ke.token.value,ke.$.env,Ye.currentClosureCaptureFrameLevel),$i=(Ye.inAsyncStateMachine||Ye.inEffectStateMachine)&&Qn.startsWith("sm->"),Ui=!1;if(K(ke)&&ke.$.env&&ke.$.variableName){let Vo=ae(ke.$.env,ke.$.variableName);Vo.length>0&&Vo[Vo.length-1].isCompileTimeOnly&&(Ui=!0)}let io=!1;if(Qn&&Qn!==ke.$.variableName&&!sr&&!$i&&!Ui){let Vo=We(ke.$.variableName,ke.$.env);if(Qn!==Vo){let Zl=Kt(ke.$.type,ke.$.variableName,n);n.emitter.emitLine(`${t}${Zl} = ${Qn};`),io=!0,Cr(ke.$.variableName,t,n)}}io&&(nr=We(ke.$.variableName,ke.$.env))}if((xt=ke.$)!=null&&xt.deferredDupExpressions&&ke.$.deferredDupExpressions.length>0){Wt(ke,t,Ye);let sr=ke.$.deferredDupExpressions[0];S(sr)&&((Xt=sr.$)!=null&&Xt.variableName)&&(nr=We(sr.$.variableName,sr.$.env))}return`.${Yr} = `+nr}return""}else return""}).filter(ke=>ke).join(", "),et=Qe.length>0?`(${Ce}){ .tag = ${Rn(X,Ue,n)}, .data = { .${Ue} = { ${Ne} } } }`:`(${Ce}){ .tag = ${Rn(X,Ue,n)} }`;if(He&&((Z=e.$)!=null&&Z.type)){let ke=Kt(e.$.type,He,n);return n.emitter.emitLine(`${t}${ke} = ${et};`),Cr(He,t,n),He}else return et}}}}else if(Je(i)){let X=e.args[0];if(X&&S(X)&&(E(X,"..")||E(X,"..="))){let He=E(X,"..="),Ee=q(e.func,t,n),Oe=q(X.args[0],t,n),Ue=q(X.args[1],t,n),ze=`Slice_${be(j(i.childType,n))}`;return n.sliceStructTypes.has(ze)||n.sliceStructTypes.set(ze,{childType:j(i.childType,n)}),He?`(${ze}){ .data = &${Ee}.data[${Oe}], .length = (${Ue}) - (${Oe}) + 1 }`:`(${ze}){ .data = &${Ee}.data[${Oe}], .length = (${Ue}) - (${Oe}) }`}let he=q(e.func,t,n),Ce=q(X,t,n);return`${he}.data[${Ce}]`}else if($t(i)){let X=e.args[0];if(X&&S(X)&&(E(X,"..")||E(X,"..="))){let He=E(X,"..="),Ee=q(e.func,t,n),Oe=q(X.args[0],t,n),Ue=q(X.args[1],t,n),ze=`Slice_${be(j(i.childType,n))}`;return n.sliceStructTypes.has(ze)||n.sliceStructTypes.set(ze,{childType:j(i.childType,n)}),He?`(${ze}){ .data = &${Ee}.data[${Oe}], .length = (${Ue}) - (${Oe}) + 1 }`:`(${ze}){ .data = &${Ee}.data[${Oe}], .length = (${Ue}) - (${Oe}) }`}let he=q(e.func,t,n),Ce=q(X,t,n);return`${he}.data[${Ce}]`}else if(i&&je(i)&&$t(i.childType)){let X=q(e.func,t,n),he=q(e.args[0],t,n);return`${X}.data[${he}]`}}function Cp(e,t,n,r){var o,a;let i=t.emitter;if(i.emitLine(`${e}if (__yo_effect_escaped) {`),t.inAsyncStateMachine||(or(e+" ",t,r,!1,!0,!1),qr(e+" ",t,r)),t.inAsyncStateMachine)n&&i.emitLine(`${e} __yo_effect_escaped = 0;`),Ar({emitter:i,indent:e+" ",resultCode:void 0,debugLabel:void 0});else if(n){i.emitLine(`${e} __yo_effect_escaped = 0;`);let s=(o=t.currentFunctionType)==null?void 0:o.return.type;if(s&&!De(s)){let l=j(s,t);l!=="void"?(i.emitLine(`${e} ${l} _esc_result;`),i.emitLine(`${e} memcpy(&_esc_result, __yo_effect_escape_value, sizeof(${l}));`),i.emitLine(`${e} return _esc_result;`)):i.emitLine(`${e} return;`)}else i.emitLine(`${e} return;`)}else{let s=(a=t.currentFunctionType)==null?void 0:a.return.type;if(s&&!De(s)){let l=j(s,t);l!=="void"?i.emitLine(`${e} return (${l}){0};`):i.emitLine(`${e} return;`)}else i.emitLine(`${e} return;`)}i.emitLine(`${e}}`)}function bp(e,t,n,r,i,o,a,s){var p,m,h,y,g,v,T,$,C,k,b,w,A,L;let l=n.join(", "),u=t.return.type,_=a.emitter,c,f=!1;if(s!=null&&s.fieldFunctionType.forallParameters&&s.fieldFunctionType.forallParameters.length>0){let N=s.fieldFunctionType.return.type;f=z(N);let x=f?"void":(p=i.$)!=null&&p.type?j(i.$.type,a):j(u,a),V=[],R=s.fieldFunctionType.parameters.filter(H=>!H.isCompileTimeOnly);for(let H=0;H<R.length;H++){let B=R[H].type,G=z(B)&&((h=(m=r==null?void 0:r[H])==null?void 0:m.$)!=null&&h.type)?r[H].$.type:B,Q=ne(G)?hi(G,"(*)",a):j(G,a);V.push(Q)}let D=V.join(", ");c=`((${x} (*)(${D}))${e})`}else c=e;if(De(u)){if(_.emitLine(`${o}${c}(${l});`),(y=i.$)!=null&&y.deferredDropExpressions&&fn(i,o,a),_.emitLine(`${o}if (__yo_effect_escaped) {`),a.inAsyncStateMachine||(or(o+" ",a,i,!1,!0,!1),qr(o+" ",a,i)),a.inAsyncStateMachine)Ar({emitter:_,indent:o+" ",resultCode:void 0,debugLabel:void 0});else{let N=(g=a.currentFunctionType)==null?void 0:g.return.type;if(N&&!De(N)){let x=j(N,a);x!=="void"?_.emitLine(`${o} return (${x}){0};`):_.emitLine(`${o} return;`)}else _.emitLine(`${o} return;`)}return _.emitLine(`${o}}`),""}else{let N=(v=i.$)==null?void 0:v.variableName;if(N){let x=(T=s==null?void 0:s.fieldFunctionType.forallParameters)!=null&&T.length&&(($=i.$)!=null&&$.type)?i.$.type:u,V=j(x,a);if(V==="void"||De(x)){if(_.emitLine(`${o}${c}(${l});`),(C=i.$)!=null&&C.deferredDropExpressions&&fn(i,o,a),_.emitLine(`${o}if (__yo_effect_escaped) {`),a.inAsyncStateMachine||(or(o+" ",a,i,!1,!0,!1),qr(o+" ",a,i)),a.inAsyncStateMachine)Ar({emitter:_,indent:o+" ",resultCode:void 0,debugLabel:void 0});else{let U=(k=a.currentFunctionType)==null?void 0:k.return.type;if(U&&!De(U)){let R=j(U,a);R!=="void"?_.emitLine(`${o} return (${R}){0};`):_.emitLine(`${o} return;`)}else _.emitLine(`${o} return;`)}return _.emitLine(`${o}}`),""}if(f){if(_.emitLine(`${o}${V} ${N} = (${V}){0};`),_.emitLine(`${o}${c}(${l});`),(b=i.$)!=null&&b.deferredDropExpressions&&fn(i,o,a),_.emitLine(`${o}if (__yo_effect_escaped) {`),a.inAsyncStateMachine||(or(o+" ",a,i,!1,!0,!1),qr(o+" ",a,i)),a.inAsyncStateMachine)Ar({emitter:_,indent:o+" ",resultCode:void 0,debugLabel:void 0});else{let U=(w=a.currentFunctionType)==null?void 0:w.return.type;if(U&&!De(U)){let R=j(U,a);R!=="void"?_.emitLine(`${o} return (${R}){0};`):_.emitLine(`${o} return;`)}else _.emitLine(`${o} return;`)}return _.emitLine(`${o}}`),Cr(N,o,a),N}if(_.emitLine(`${o}${V} ${N} = ${c}(${l});`),(A=i.$)!=null&&A.deferredDropExpressions&&fn(i,o,a),_.emitLine(`${o}if (__yo_effect_escaped) {`),a.inAsyncStateMachine||(or(o+" ",a,i,!1,!0,!1),qr(o+" ",a,i)),a.inAsyncStateMachine)Ar({emitter:_,indent:o+" ",resultCode:void 0,debugLabel:void 0});else{let U=(L=a.currentFunctionType)==null?void 0:L.return.type;if(U&&!De(U)){let R=j(U,a);R!=="void"?_.emitLine(`${o} return (${R}){0};`):_.emitLine(`${o} return;`)}else _.emitLine(`${o} return;`)}return _.emitLine(`${o}}`),N}else return`${c}(${l})`}}function Wu(e,t,n,r){var s,l,u,_,c,f,p,m,h,y,g,v,T,$,C,k,b;let i=[],o=(l=(s=t.body)==null?void 0:s.$)==null?void 0:l.effectAnalysis,a=!1;for(let w of e){let A=`${w.implicitLabel}.${w.fieldLabel}`,L=!1;if(r.currentEvidenceParams){let N=r.currentEvidenceParams.get(A);N&&(i.push(N.cParamName),L=!0)}if(!L){if(o){if(o.effectHandlerInfos)for(let N of o.effectHandlerInfos){if(N.effectParameterName!==w.fieldLabel&&N.effectParameterName!==w.implicitLabel)continue;let x=N.handlerValue;if(x&&ge(x)){if((u=x.specializedFunctionCaches)!=null&&u.length){let U=x.specializedFunctionCaches[0].specializedFunction,R=(_=r.functions[U.funcId])==null?void 0:_.cName;if(R){i.push(`(void*)${R}`),L=!0,a=!0;break}}let V=(c=r.functions[x.funcId])==null?void 0:c.cName;if(V){i.push(V),L=!0,a=!0;break}}}if(!L&&o.handlerValue&&e.length===1){let N=o.handlerValue;if(N&&ge(N)){if((f=N.specializedFunctionCaches)!=null&&f.length){let x=N.specializedFunctionCaches[0].specializedFunction,V=(p=r.functions[x.funcId])==null?void 0:p.cName;V&&(i.push(`(void*)${V}`),L=!0,a=!0)}if(!L){let x=(m=r.functions[N.funcId])==null?void 0:m.cName;x&&(i.push(x),L=!0,a=!0)}}}}if(!L){let N=((h=n.func.$)==null?void 0:h.env)??((y=n.$)==null?void 0:y.env);if(N){let x=ae(N,w.implicitLabel),V=cr(N,B=>B.isImplicit===!0&&ne(B.type)&&ne(w.fieldFunctionType)&&B.type===w.fieldFunctionType),U=x[x.length-1],R=V[V.length-1],D=R&&R!==U?R:U??R,H=(g=D==null?void 0:D.value)==null?void 0:g[0];if(H&&wt(H)){let B=H,G=!0;for(let Q=0;Q<w.fieldPath.length-1;Q++){let Y=w.fieldPath[Q],J=B.type.fields.findIndex(se=>se.label===Y);if(J>=0&&B.fields[J]&&wt(B.fields[J]))B=B.fields[J];else{G=!1;break}}if(G){let Q=w.fieldPath[w.fieldPath.length-1],Y=B.type.fields.findIndex(J=>J.label===Q);if(Y>=0){let J=B.fields[Y];if(J&&ge(J)){if(((v=J.specializedFunctionCaches)==null?void 0:v.length)>0){let se=J.specializedFunctionCaches[0].specializedFunction,ve=(T=r.functions[se.funcId])==null?void 0:T.cName;ve&&(i.push(`(void*)${ve}`),L=!0)}if(!L){let se=($=r.functions[J.funcId])==null?void 0:$.cName;se&&(i.push(se),L=!0)}}}}}else if(H&&ge(H)){if((C=H.specializedFunctionCaches)!=null&&C.length){let B=H.specializedFunctionCaches[0].specializedFunction,G=(k=r.functions[B.funcId])==null?void 0:k.cName;G&&(i.push(`(void*)${G}`),L=!0)}if(!L){let B=(b=r.functions[H.funcId])==null?void 0:b.cName;B&&(i.push(B),L=!0)}}L&&(a=!0)}}if(!L&&r.stateMachineVariables){let N=w.fieldPath[w.fieldPath.length-1];for(let[,x]of r.stateMachineVariables)if(x.name===N&&x.kind==="outer"){i.push(`sm->__capture.${N}`),L=!0;break}}if(!L)break}}return{args:i,isHandlerInstallation:a}}function qu(e,t,n,r,i,o,a,s=!1){var _,c,f,p,m;let l=a.emitter,u=n.return.type;if(l.emitLine(`${o}__yo_effect_escaped = 0;`),De(u)){if(l.emitLine(`${o}${e}(${t});`),(_=r.$)!=null&&_.deferredDropExpressions&&fn(r,o,a),l.emitLine(`${o}if (__yo_effect_escaped) {`),a.inAsyncStateMachine||(or(o+" ",a,r,!1,!0,!1),qr(o+" ",a,r)),a.inAsyncStateMachine)Ar({emitter:l,indent:o+" ",resultCode:void 0,debugLabel:void 0});else{let h=(c=a.currentFunctionType)==null?void 0:c.return.type;if(s&&l.emitLine(`${o} __yo_effect_escaped = 0;`),h&&!De(h))if(s){let y=j(h,a);y!=="void"?(l.emitLine(`${o} ${y} _esc_result;`),l.emitLine(`${o} memcpy(&_esc_result, __yo_effect_escape_value, sizeof(${y}));`),l.emitLine(`${o} return _esc_result;`)):l.emitLine(`${o} return;`)}else{let y=j(h,a);y!=="void"?l.emitLine(`${o} return (${y}){0};`):l.emitLine(`${o} return;`)}else l.emitLine(`${o} return;`)}return l.emitLine(`${o}}`),""}else{let h=(f=r.$)==null?void 0:f.variableName;if(h){let y=j(u,a);if(l.emitLine(`${o}${y} ${h} = ${e}(${t});`),Cr(h,o,a),(p=r.$)!=null&&p.deferredDropExpressions&&fn(r,o,a),l.emitLine(`${o}if (__yo_effect_escaped) {`),a.inAsyncStateMachine||(or(o+" ",a,r,!1,!0,!1),qr(o+" ",a,r)),a.inAsyncStateMachine)Ar({emitter:l,indent:o+" ",resultCode:void 0,debugLabel:void 0});else{let g=(m=a.currentFunctionType)==null?void 0:m.return.type;if(s&&g&&!De(g)){let v=j(g,a);l.emitLine(`${o} ${v} _esc_result;`),l.emitLine(`${o} memcpy(&_esc_result, __yo_effect_escape_value, sizeof(${v}));`),l.emitLine(`${o} __yo_effect_escaped = 0;`),l.emitLine(`${o} return _esc_result;`)}else if(g&&!De(g)){let v=j(g,a);v!=="void"?l.emitLine(`${o} return (${v}){0};`):l.emitLine(`${o} return;`)}else s&&l.emitLine(`${o} __yo_effect_escaped = 0;`),l.emitLine(`${o} return;`)}return l.emitLine(`${o}}`),h}else return`${e}(${t})`}}function wp(e,t,n){var a,s,l;let r=n.emitter,i=(a=e.$)==null?void 0:a.type;if(!i)return"// Error: panic() missing type information";if(e.args.length===0)r.emitLine(`${t}abort();`);else if(e.args.length===1){let u=e.args[0];if((s=u.$)!=null&&s.value&&tt(u.$.value)){let _=u.$.value.value;r.emitLine(`${t}fprintf(stderr, "%s\\n", ${JSON.stringify(_)});`),r.emitLine(`${t}abort();`)}else{let _=q(u,t,n),c=(l=u.$)==null?void 0:l.type;c&&Ae(c)&&hr(c)&&c.typeName==="str"?r.emitLine(`${t}fprintf(stderr, "%.*s\\n", (int)${_}.length, ${_}.data);`):r.emitLine(`${t}fprintf(stderr, "%s\\n", ${_});`),r.emitLine(`${t}abort();`)}}else return`// Error: panic accepts 0 or 1 arguments, got ${e.args.length}`;return`(*((${j(i,n)}*)NULL))`}var kv={reg:{x86_64:"r",aarch64:"r",x86:"r",arm:"r"},reg_byte:{x86_64:"q",x86:"q"},reg_abcd:{x86_64:"Q",x86:"Q"},xmm_reg:{x86_64:"x",aarch64:"w"},ymm_reg:{x86_64:"x"},imm:{x86_64:"i",aarch64:"i",x86:"i",arm:"i"},mem:{x86_64:"m",aarch64:"m",x86:"m",arm:"m"}},wv={rax:"a",eax:"a",ax:"a",al:"a",rbx:"b",ebx:"b",bx:"b",bl:"b",rcx:"c",ecx:"c",cx:"c",cl:"c",rdx:"d",edx:"d",dx:"d",dl:"d",rsi:"S",esi:"S",si:"S",rdi:"D",edi:"D",di:"D"},Fv={e:"k",x:"w",l:"b",h:"h",w:"w"};function Lv(e,t){if(!e)return"r";if(e.startsWith("raw:"))return e.slice(4);let n=wv[e];if(n)return n;let r=kv[e];return r?r[t]??r.x86_64??"r":e}function Iv(e,t){let n="",r=0;for(;r<e.length;)if(e[r]==="{"){if(r+1<e.length&&e[r+1]==="{"){n+="{",r+=2;continue}let i=e.indexOf("}",r+1);if(i===-1){n+=e[r],r++;continue}let o=e.slice(r+1,i),a=o.indexOf(":"),s,l;a>=0?(s=o.slice(0,a),l=o.slice(a+1)):s=o;let u=l?Fv[l]??l:void 0,_=parseInt(s,10);isNaN(_)?u?n+=`%${u}[${s}]`:n+=`%[${s}]`:u?n+=`%${u}${_}`:n+=`%${_}`,r=i+1}else e[r]==="}"&&r+1<e.length&&e[r+1]==="}"?(n+="}",r+=2):(n+=e[r],r++);return n}function Av(e,t,n,r){var g,v,T,$,C;let i=e.args,o=n.targetInfo.arch;if(r==="const_val"){let k,b=0;i.length===2&&((g=i[0].$)!=null&&g.value)&&tt(i[0].$.value)&&(k=i[0].$.value.value,b=1);let w=q(i[b],t,n);return{kind:"const_val",name:k,constraint:"",cExpr:w,cType:"",isDiscarded:!1,isVariableTarget:!1}}if(r==="sym"){let k,b=0;i.length===2&&((v=i[0].$)!=null&&v.value)&&tt(i[0].$.value)&&(k=i[0].$.value.value,b=1);let w=q(i[b],t,n);return{kind:"sym",name:k,constraint:"i",cExpr:w,cType:"",isDiscarded:!1,isVariableTarget:!1}}let a,s=0;if(i.length>=2){let k=i[0];(T=k.$)!=null&&T.value&&tt(k.$.value)&&!(k.tag==="Atom"&&Fp(k.token.value))&&(a=k.$.value.value,s=1)}let l=s<i.length-1,u,_;l?(u=Sv(i[s],t,n),_=s+1):(a!==void 0&&(u=a),_=s);let c=Lv(u,o),f=i[_];if(f.tag==="Atom"&&f.token.value==="_")return{kind:r,name:a,constraint:c,cExpr:"",cType:"int32_t",isDiscarded:!0,isVariableTarget:!1};if(($=f.$)!=null&&$.value&&W(f.$.value)){let k=f.$.value.value,b=j(k,n);return{kind:r,name:a,constraint:c,cExpr:"",cType:b,isDiscarded:!1,isVariableTarget:!1}}let p=q(f,t,n),m=j((C=f.$)==null?void 0:C.type,n),y=(r==="out"||r==="lateout")&&f.tag==="Atom";return{kind:r,name:a,constraint:c,cExpr:p,cType:m,isDiscarded:!1,isVariableTarget:y}}function Fp(e){return["reg","reg_byte","reg_abcd","xmm_reg","ymm_reg","imm","mem"].includes(e)}function Sv(e,t,n){var r,i;if(e.tag==="Atom"&&Fp(e.token.value))return e.token.value;if((r=e.$)!=null&&r.value&&tt(e.$.value))return e.$.value.value;if(E(e,"raw",1)){let o=e;if((i=o.args[0].$)!=null&&i.value&&tt(o.args[0].$.value))return`raw:${o.args[0].$.value.value}`}return"r"}function Nv(e,t){var i;let n=[];if((e.func.tag==="Atom"?e.func.token.value:"clobber")==="clobber_abi"){let o=t.targetInfo.arch;if(o==="x86_64")n.push("rax","rcx","rdx","rsi","rdi","r8","r9","r10","r11","xmm0","xmm1","xmm2","xmm3","xmm4","xmm5","xmm6","xmm7","xmm8","xmm9","xmm10","xmm11","xmm12","xmm13","xmm14","xmm15","cc","memory");else if(o==="aarch64"){for(let a=0;a<=18;a++)n.push(`x${a}`);n.push("x30");for(let a=0;a<=31;a++)n.push(`v${a}`);n.push("cc","memory")}return n}for(let o of e.args)(i=o.$)!=null&&i.value&&tt(o.$.value)?n.push(o.$.value.value):o.tag==="Atom"&&n.push(o.token.value);return n}function Vv(e){let t={isVolatile:!0,intelSyntax:!1,noreturn:!1,pure:!1};for(let n of e.args)if(n.tag==="Atom")switch(n.token.value){case"pure":t.pure=!0,t.isVolatile=!1;break;case"intel_syntax":t.intelSyntax=!0;break;case"noreturn":t.noreturn=!0;break;case"volatile":t.isVolatile=!0;break}return t}var Yu=0;function Lp(e,t,n){var N,x;let r=n.emitter,i=(N=e.$)==null?void 0:N.type;if(!i)return"/* Error: asm() missing type information */";if(Gr(n.targetInfo))return r.emitLine(`${t}/* Error: inline assembly is not supported on WebAssembly */`),r.emitLine(`${t}abort();`),`(*((${j(i,n)}*)NULL))`;let o=[],a=0;for(;a<e.args.length;){let V=e.args[a];if(S(V))break;if((x=V.$)!=null&&x.value&&tt(V.$.value))o.push(V.$.value.value),a++;else break}let s=o.join(`
|
|
11397
|
+
`),l=[],u=[],_={isVolatile:!0,intelSyntax:!1,noreturn:!1,pure:!1};for(;a<e.args.length;){let V=e.args[a];if(!S(V)){a++;continue}let U=V.func.tag==="Atom"?V.func.token.value:void 0;if(!U){a++;continue}["in","out","inout","lateout","inlateout","const_val","sym"].includes(U)?l.push(Av(V,t,n,U)):U==="clobber"||U==="clobber_abi"?u.push(...Nv(V,n)):U==="asm_options"&&(_=Vv(V)),a++}let c=new Map;for(let V=0;V<l.length;V++)l[V].name&&c.set(l[V].name,V);let f=s;for(let V=0;V<l.length;V++){let U=l[V];U.kind==="const_val"&&(U.name&&(f=f.replace(new RegExp(`\\{${U.name}(?::[^}]*)?\\}`,"g"),U.cExpr)),f=f.replace(new RegExp(`\\{${V}(?::[^}]*)?\\}`,"g"),U.cExpr))}let p=Iv(f,c),m=[],h=[],y=[];for(let V=0;V<l.length;V++){let U=l[V];if(U.isDiscarded){let R=`__asm_discard_${Yu++}`;y.push({varName:R,cType:U.cType,operandIdx:V}),r.emitLine(`${t}${U.cType} ${R};`)}else if(U.kind==="out"||U.kind==="lateout"){if(!U.isVariableTarget){if(U.cType){let R=`__asm_out_${Yu++}`;m.push({varName:R,cType:U.cType,operandIdx:V}),r.emitLine(`${t}${U.cType} ${R};`)}}}else if(U.kind==="inout"||U.kind==="inlateout"){let R=`__asm_inout_${Yu++}`;h.push({varName:R,cType:U.cType,initExpr:U.cExpr,operandIdx:V}),r.emitLine(`${t}${U.cType} ${R} = ${U.cExpr};`)}}let g=_.isVolatile?" __volatile__":"",v=p;_.intelSyntax&&(n.needsIntelAsmSyntax=!0);let T=JSON.stringify(v),$=[];for(let V=0;V<l.length;V++){let U=l[V];if(U.kind==="in"||U.kind==="const_val"||U.kind==="sym")continue;let R;U.kind==="out"||U.kind==="lateout"?R=U.kind==="lateout"?"=&":"=":R=U.kind==="inlateout"?"+&":"+";let D=`${R}${U.constraint}`,H=U.name?`[${U.name}] `:"",B;U.isDiscarded?B=y.find(Q=>Q.operandIdx===V).varName:U.isVariableTarget?B=U.cExpr:U.kind==="out"||U.kind==="lateout"?B=m.find(Q=>Q.operandIdx===V).varName:B=h.find(Q=>Q.operandIdx===V).varName,$.push(`${H}"${D}" (${B})`)}let C=[];for(let V=0;V<l.length;V++){let U=l[V];if(U.kind!=="in"&&U.kind!=="sym")continue;let R=U.constraint,D=U.name?`[${U.name}] `:"";C.push(`${D}"${R}" (${U.cExpr})`)}let k=u.map(V=>`"${V}"`),b=$.join(", "),w=C.join(", "),A=k.join(", ");if(r.emitLine(`${t}__asm__${g} (`),r.emitLine(`${t} ${T}`),r.emitLine(`${t} : ${b}`),r.emitLine(`${t} : ${w}`),r.emitLine(`${t} : ${A}`),r.emitLine(`${t});`),_.noreturn)return r.emitLine(`${t}__builtin_unreachable();`),`(*((${j(i,n)}*)NULL))`;if(De(i))return"";let L=[];for(let V=0;V<l.length;V++){let U=l[V];if(!(U.isDiscarded||U.isVariableTarget)&&!(U.kind==="in"||U.kind==="const_val"||U.kind==="sym"))if(U.kind==="out"||U.kind==="lateout"){let R=m.find(D=>D.operandIdx===V);R&&L.push(R.varName)}else{let R=h.find(D=>D.operandIdx===V);R&&L.push(R.varName)}}if(L.length===1)return L[0];if(L.length>1){let V=j(i,n),U=L.map((R,D)=>`._${D} = ${R}`).join(", ");return`((${V}){ ${U} })`}return""}function Ip(e,t,n){var i;if(Gr(n.targetInfo))return"/* global_asm skipped: not supported on this target */";let r=e.args[0];if((i=r.$)!=null&&i.value&&tt(r.$.value)){let o=r.$.value.value;n.emitter.emitDeclarationLine(`__asm__(${JSON.stringify(o)});`)}return""}function Ap(e,t,n){var l,u,_,c,f,p,m,h,y,g;if(e.args.length!==2)return"/* ERROR: field access requires exactly 2 arguments */";let r=e.args[0],i=e.args[1];if(!r||!i)return"/* ERROR: invalid field access arguments */";let o=q(r,t,n),a=(l=r.$)==null?void 0:l.type,s=(u=r.$)==null?void 0:u.value;if(K(i)){let v=i.token.value,T=n;if(T.currentEvidenceParams&&K(r)){let C=`${r.token.value}.${v}`,k=T.currentEvidenceParams.get(C);if(k)return k.cParamName}if((_=e.$)!=null&&_.value&&ge(e.$.value)){let $=e.$.value;return((c=n.functions[$.funcId])==null?void 0:c.cName)||$.funcId}if(!((f=e.$)!=null&&f.value)&&(F.___dispose.includes(v)||F.___drop.includes(v)||F.___dup.includes(v))&&a){let $=null;if((Ae(a)||Be(a))&&($=a.trait),$){let C=$.fields.find(k=>k.label===v&&k.assignedValue&&ge(k.assignedValue));if(C&&ge(C.assignedValue)){let k=C.assignedValue;return((p=n.functions[k.funcId])==null?void 0:p.cName)||k.funcId}else return`/* ERROR: Rc method ${v} not found in type module */`}else return`/* ERROR: No module found for Rc method ${v} */`}if(Xe(a)||wt(s)){let $=(m=e.$)==null?void 0:m.value;if($){if(Ie($)){if($.variableName)return We($.variableName,(h=e.$)==null?void 0:h.env);if((T.inAsyncStateMachine||T.inEffectStateMachine)&&T.stateMachineVariables){for(let[,C]of T.stateMachineVariables)if(C.name===v&&C.kind==="outer")return`sm->__capture.${v}`}}else if(!wt($))return Yn($,n,e)}return We(v,(y=e.$)==null?void 0:y.env)}if(hr(a)&&a.fields.length===1){let $=a.fields[0];if($&&$.label===v)return o}if(Be(a)){let $=a;if(Gn($))return o;for(let k of $.variants)if(k.fields){for(let b of k.fields)if(b.label===v){let w=k.name;return`${o}.data.${w}.${be(v)}`}}return`/* ERROR: field ${v} not found in enum ${$.typeName} */`}else if(W(s)&&Be(s.value)){let $=s.value,C=$.variants.find(b=>b.name===v),k=(g=n.types[$.id])==null?void 0:g.cName;if(C&&!C.fields&&k){let b=Rn($,C.name,n);return`(${k}){ .tag = ${b}, .data = { } }`}}else if(je(a)){if(v==="*")return`(*${o})`;if($t(a.childType))return`${o}->${be(v)}`;{let $=0,C=a;for(;je(C);)$++,C=C.childType;if($>0&&Ae(C)&&C.isReferenceSemantics&&$++,hr(C)&&C.fields.length===1){let k=C.fields[0];if(k&&k.label===v)return $===1?`(*${o})`:`${"*".repeat($)}(${o})`}return $>0?$===1?`${o}->${be(v)}`:`${`(${"*".repeat($-1)}${o})`}->${be(v)}`:`${o}.${be(v)}`}}else if(ut(a)){if(v.match(/^\d+$/))return`${o}._${v}`;{let $=a.fields.findIndex(C=>C.label===v);return`${o}._${$}`}}else return st(a)?`${o}.vtable->${be(v)}`:en(a)?`${o}->${be(v)}`:`${o}.${be(v)}`}return"/* ERROR: field name must be an identifier */"}var xv=0;function Sp(e,t,n){var l,u,_,c,f,p,m,h,y,g;if(!((l=e.$)==null?void 0:l.type))return`// Error: No type information for pointer/reference expression ${I(e)}
|
|
11398
|
+
`;let i=e.args[0];if(S(i)){let v=(u=i.func.$)==null?void 0:u.type;if(v&&Je(v)){let T=i.args[0];if(T&&S(T)&&(E(T,"..")||E(T,"..="))){let $=E(T,"..="),C=q(i.func,t,n),k=q(T.args[0],t,n),b=q(T.args[1],t,n),w=`Slice_${be(j(v.childType,n))}`;return n.sliceStructTypes.has(w)||n.sliceStructTypes.set(w,{childType:j(v.childType,n)}),$?`(${w}){ .data = &${C}.data[${k}], .length = (${b}) - (${k}) + 1 }`:`(${w}){ .data = &${C}.data[${k}], .length = (${b}) - (${k}) }`}}else if(v&&($t(v)||je(v)&&$t(v.childType))){let T=$t(v)?v:v.childType,$=i.args[0];if($&&S($)&&(E($,"..")||E($,"..="))){let C=E($,"..="),k=q(i.func,t,n),b=q($.args[0],t,n),w=q($.args[1],t,n),A=`Slice_${be(j(T.childType,n))}`;return n.sliceStructTypes.has(A)||n.sliceStructTypes.set(A,{childType:j(T.childType,n)}),C?`(${A}){ .data = &${k}.data[${b}], .length = (${w}) - (${b}) + 1 }`:`(${A}){ .data = &${k}.data[${b}], .length = (${w}) - (${b}) }`}}}let o=(_=i.$)==null?void 0:_.value,a=(c=i.$)==null?void 0:c.type;if(o!==void 0&&a){if(ht(o)||Ct(o)){let v=q(i,t,n);return`(&(${j(a,n)}){${v}})`}if(tt(o)&&((f=i.$)!=null&&f.convertedRuntimeType))return`(&${q(i,t,n)})`}if((p=e.$)!=null&&p.isIndexTraitAddressOf&&S(i)&&((m=i.$)!=null&&m.indexMethodValue)){let v=i.$.indexMethodValue;if(ge(v)){let T=i.func,$=q(T,t,n);if(S(T)&&!K(T)&&!E(T,".")&&((h=T.$)!=null&&h.type)&&!(((y=T.$)==null?void 0:y.variableName)&&$===We(T.$.variableName,T.$.env))){let L=j(T.$.type,n),N=`__yo_ptr_idx_tmp_${xv++}`;n.emitter.emitLine(`${t}${L} ${N} = ${$};`),$=N}let C=i.args[0],k=C?q(C,t,n):"0",b=gi(v);if(b&&(F.__yo_array_index.includes(b)||F.__yo_slice_index.includes(b)))return`(&((&${$})->data[${k}]))`;let w=(g=n.functions[v.funcId])==null?void 0:g.cName;if(w)return`${w}(&${$}, ${k})`}}return`(&${q(i,t,n)})`}function Np(e,t,n){let r=e.args[0];return r?`__yo_decr_rc(${q(r,t,n)})`:"// Error: __yo_decr_rc requires exactly 1 argument"}function Vp(e,t,n){let r=e.args[0];return r?`__yo_incr_rc(${q(r,t,n)})`:"// Error: __yo_incr_rc requires exactly 1 argument"}function xp(e,t,n){let r=e.args[0];return r?q(r,t,n):"// Error: __yo_rc_own requires exactly 1 argument"}function Dp(e,t,n){var c;let r=e.args[0],i=e.args[1];if(!r||!i)return"// Error: __yo_drop_array_element requires exactly 2 arguments";let o=q(r,t,n),a=q(i,t,n),s=(c=r.$)==null?void 0:c.type;if(!s||!Je(s))return"// Error: __yo_drop_array_element requires an array type";let l=s.childType,u=z(l)&&l.resolvedConcreteType?l.resolvedConcreteType:l;if(Je(u)){let f=u.length;if(!ht(f))return"// Error: array element has non-constant length";let p=`i_${Math.floor(Math.random()*1e6)}`,m=n.emitter;m.emitLine(`for (size_t ${p} = 0; ${p} < ${f.value}; ${p}++) {`);let h=`(${o}).data[${a}].data[${p}]`;m.emitLine(" { // drop nested array element");let y=Vi(h,u.childType,n);return y&&m.emitLine(` ${y};`),m.emitLine(" }"),m.emitLine("}"),""}let _=Wr(u,n);return _?`${_}((${o}).data[${a}])`:"// No drop function for array element type"}function Mp(e,t,n){var c;let r=e.args[0],i=e.args[1];if(!r||!i)return"// Error: __yo_dup_array_element requires exactly 2 arguments";let o=q(r,t,n),a=q(i,t,n),s=(c=r.$)==null?void 0:c.type;if(!s||!Je(s))return"// Error: __yo_dup_array_element requires an array type";let l=s.childType,u=z(l)&&l.resolvedConcreteType?l.resolvedConcreteType:l;if(Je(u)){let f=u.length;if(!ht(f))return"// Error: array element has non-constant length";let p=`temp_array_${Math.floor(Math.random()*1e6)}`,m=`i_${Math.floor(Math.random()*1e6)}`,h=j(u,n),y=n.emitter;y.emitLine(`${h} ${p} = (${o}).data[${a}];`),y.emitLine(`for (size_t ${m} = 0; ${m} < ${f.value}; ${m}++) {`);let g=sa(`${p}.data[${m}]`,u.childType,n);return y.emitLine(` ${p}.data[${m}] = ${g};`),y.emitLine("}"),p}let _=fr(u,n);return _?`${_}((${o}).data[${a}])`:"// No dup function for array element type"}function Op(e,t,n){var f,p;let r=e.args[0],i=e.args[1];if(!r||!i)return"// Error: __yo_drop_tuple_element requires exactly 2 arguments";let o=q(r,t,n);q(i,t,n);let a=(f=r.$)==null?void 0:f.type;if(!a||!ut(a))return"// Error: __yo_drop_tuple_element requires a tuple type";let s=(p=i.$)==null?void 0:p.value;if(!ht(s))return"// Error: __yo_drop_tuple_element requires a constant index";let l=Number(s.value);if(l<0||l>=a.fields.length)return"// Error: __yo_drop_tuple_element index out of bounds";let u=a.fields[l].type,_=z(u)&&u.resolvedConcreteType?u.resolvedConcreteType:u;if(ut(_)){let m=`(${o})._${l}`;return Vi(m,_,n)}let c=Wr(_,n);return c?`${c}((${o})._${l})`:"// No drop function for tuple element type"}function Rp(e,t,n){var f,p;let r=e.args[0],i=e.args[1];if(!r||!i)return"// Error: __yo_dup_tuple_element requires exactly 2 arguments";let o=q(r,t,n);q(i,t,n);let a=(f=r.$)==null?void 0:f.type;if(!a||!ut(a))return"// Error: __yo_dup_tuple_element requires a tuple type";let s=(p=i.$)==null?void 0:p.value;if(!ht(s))return"// Error: __yo_dup_tuple_element requires a constant index";let l=Number(s.value);if(l<0||l>=a.fields.length)return"// Error: __yo_dup_tuple_element index out of bounds";let u=a.fields[l].type,_=z(u)&&u.resolvedConcreteType?u.resolvedConcreteType:u;if(ut(_)){let m=`(${o})._${l}`;return sa(m,_,n)}let c=fr(_,n);return c?`${c}((${o})._${l})`:"// No dup function for tuple element type"}function Pp(e,t,n){var a,s;let r=e.args[0];if(!r)return"// Error: ___dup requires exactly 1 argument";let i=q(r,t,n),o=((a=r.$)==null?void 0:a.type)??((s=e.$)==null?void 0:s.type);return o?sa(i,o,n):i}function Up(e,t,n){var a,s;let r=e.args[0];if(!r)return"// Error: ___drop requires exactly 1 argument";let i=q(r,t,n),o=((a=r.$)==null?void 0:a.type)??((s=e.$)==null?void 0:s.type);return o?Vi(i,o,n):""}function zp(e,t,n){let r=e.args[0];return r?`__yo_decr_rc((void*)(${q(r,t,n)}).data)`:"// Error: __yo_dyn_drop requires exactly 1 argument"}function Bp(e,t,n){let r=e.args[0];return r?`__yo_incr_rc((void*)(${q(r,t,n)}).data)`:"// Error: __yo_dyn_dup requires exactly 1 argument"}function Gp(e,t,n){let r=e.args[0];return r?`__yo_incr_rc_atomic(${q(r,t,n)})`:"// Error: __yo_incr_rc_atomic requires exactly 1 argument"}function Wp(e,t,n){let r=e.args[0];return r?`__yo_decr_rc_atomic(${q(r,t,n)})`:"// Error: __yo_decr_rc_atomic requires exactly 1 argument"}function qp(e,t,n){var o,a,s;let r=e.args[0];if(!r)return"// Error: __yo_sometype_drop requires exactly 1 argument";let i=(o=r.$)==null?void 0:o.type;if(i&&z(i)&&at(i)){let l=q(r,t,n);return`if (${l} != NULL) { __yo_decr_rc((void*)${l}); }`}if(i&&z(i)&&i.resolvedConcreteType){let u=(a=i.resolvedConcreteType.trait)==null?void 0:a.fields.find(_=>_.label===F.___drop[0]);if(u&&u.assignedValue&&ge(u.assignedValue)){let _=(s=n.functions[u.assignedValue.funcId])==null?void 0:s.cName;if(_){let c=q(r,t,n);return`${_}(${c})`}}}return"/* __yo_sometype_drop: no-op */"}function Yp(e,t,n){var o,a,s;let r=e.args[0];if(!r)return"// Error: __yo_sometype_dup requires exactly 1 argument";let i=(o=r.$)==null?void 0:o.type;if(i&&z(i)&&at(i))return`__yo_incr_rc((void*)${q(r,t,n)})`;if(i&&z(i)&&i.resolvedConcreteType){let u=(a=i.resolvedConcreteType.trait)==null?void 0:a.fields.find(_=>_.label===F.___dup[0]);if(u&&u.assignedValue&&ge(u.assignedValue)){let _=(s=n.functions[u.assignedValue.funcId])==null?void 0:s.cName;if(_){let c=q(r,t,n);return`${_}(${c})`}}}return"/* __yo_sometype_dup: no-op */"}function Hp(e,t,n){var a;if(e.args.length!==1)return"// Error: rc requires exactly 1 argument";let r=e.args[0],i=(a=r.$)==null?void 0:a.type;if(!i)return"// Error: rc argument missing type information";let o=q(r,t,n);return rr(i)?oi(i)?`atomic_load_explicit((_Atomic size_t*)&((__yo_ref_header_t*)(${o}))->ref_count, memory_order_acquire)`:`((__yo_ref_header_t*)(${o}))->ref_count`:"1"}function jp(e,t,n){var i;let r=(i=e.$)==null?void 0:i.runtimeArgExprsInOrder;if(r){let o=n,a=r.map(s=>{var u,_;let l=q(s,t,n);if((u=s.$)!=null&&u.deferredDupExpressions&&s.$.deferredDupExpressions.length>0){Wt(s,t,o);let c=s.$.deferredDupExpressions[0];if(S(c)&&((_=c.$)!=null&&_.variableName))return We(c.$.variableName,c.$.env)}return l}).join(", ");return`${n.currentFunctionName}(${a})`}else return`// Error: No arguments for recur call ${I(e)}
|
|
11399
|
+
`}function Kp(e,t,n){let r=e.args[0];return`sizeof(${q(r,t,n)})`}function Xp(e,t,n){var a,s,l,u,_,c,f,p,m;let r=(a=e.$)==null?void 0:a.runtimeArgExprsInOrder,i=(u=n.types[((l=(s=e.$)==null?void 0:s.type)==null?void 0:l.id)??""])==null?void 0:u.cName,o=(_=e.$)==null?void 0:_.variableName;if(r&&i){let h=n,y=r.map((g,v)=>{var C,k;let $=q(g,t,n);if((C=g.$)!=null&&C.deferredDupExpressions&&g.$.deferredDupExpressions.length>0){Wt(g,t,h);let b=g.$.deferredDupExpressions[0];S(b)&&((k=b.$)!=null&&k.variableName)&&($=We(b.$.variableName,b.$.env))}return`._${v} = ${$}`}).join(", ");if(o&&((c=e.$)!=null&&c.type)){let g=`(${i}){ ${y} }`,v=Kt(e.$.type,o,n);return n.emitter.emitLine(`${t}${v} = ${g};`),o}else return`(${i}){ ${y} }`}else{if(e.args.length===0)return"";{let h=r??e.args;if(!i)return`/* Error: tuple type not found - typeId: ${((p=(f=e.$)==null?void 0:f.type)==null?void 0:p.id)??"none"} */`;let y=h.map((g,v)=>{let T=q(g,t,n);return`._${v} = ${T}`}).join(", ");if(o&&((m=e.$)!=null&&m.type)){let g=`(${i}){ ${y} }`,v=Kt(e.$.type,o,n);return n.emitter.emitLine(`${t}${v} = ${g};`),o}else return`(${i}){ ${y} }`}}}function Qp(e,t,n){var u,_;let i=(u=e.args[0].$)==null?void 0:u.value;if(!i||!W(i))throw new Error("typeid codegen: expected TypeValue argument");let o=i.value,a=o.id,s=((_=n.types[a])==null?void 0:_.cName)||j(o,n),l=`__yo_typeid_${be(s)}`;return n.typeIdStatics||(n.typeIdStatics=new Map),n.typeIdStatics.has(a)||(n.typeIdStatics.set(a,l),n.emitter.emitDeclarationLine(`static const char ${l} = 0;`)),n.cIncludes.add("<stdint.h>"),`(uintptr_t)&${l}`}function Dv(e,t){if(S(e)&&E(e,P.begin)){let n=[];for(let r of e.args)if(S(r)&&E(r,"=",2)){let i=r.args[0],o=r.args[1],a=q(i,"",t),s=q(o,"",t);n.push(`${a} = ${s}`)}return n.join(", ")}else if(S(e)&&E(e,"=",2)){let n=e.args[0],r=e.args[1],i=q(n,"",t),o=q(r,"",t);return`${i} = ${o}`}return q(e,"",t)}function Hu(e,t,n){var r,i,o,a;if(S(e)&&E(e,P.begin)){let s=n,l=s.pendingDeferredDrops,u=((r=e.$)==null?void 0:r.deferredDropExpressions)??[],_=new Map;for(let m of u){let h=$r(m);h&&_.set(h,m)}s.pendingDeferredDrops=[...l??[]];let c=s.consumedVarPendingDrops,f=((i=e.$)==null?void 0:i.consumedVariableDropExpressions)??[];s.consumedVarPendingDrops=[...f,...c??[]];let p=new Set;for(let m of e.args){let h=q(m,t,n);if(h&&n.emitter.emitLine(`${t}${h};`),(o=m.$)!=null&&o.env&&_.size>p.size)for(let y of m.$.env.frames)for(let g of y.variables)_.has(g.name)&&!p.has(g.name)&&(p.add(g.name),s.pendingDeferredDrops.unshift(_.get(g.name)))}if((a=e.$)!=null&&a.deferredDropExpressions)for(let m of e.$.deferredDropExpressions){let h=q(m,t,n);h&&n.emitter.emitLine(`${t}${h};`)}s.pendingDeferredDrops=l,s.consumedVarPendingDrops=c}else{let s=q(e,t,n);s&&n.emitter.emitLine(`${t}${s};`)}}function Zp(e,t,n){var i,o,a;if((i=e.$)!=null&&i.comptimeUnrolledBodies){for(let s of e.$.comptimeUnrolledBodies)Hu(s,t,n);return""}let r=e.args;if(r.length===2){let s=r[0],l=r[1],u=n.currentLoopLabel,_=`loop_${Math.random().toString(36).substr(2,9)}`;n.currentLoopLabel=_;let c=n,f=c.loopBodyDropsBaselineCount;c.loopBodyDropsBaselineCount=((o=c.pendingDeferredDrops)==null?void 0:o.length)??0,n.emitter.emitLine(`${t}while (true) {`);let p=q(s,t+" ",n);return n.emitter.emitLine(`${t} if (!(${p})) {`),n.emitter.emitLine(`${t} break;`),n.emitter.emitLine(`${t} }`),Hu(l,t+" ",n),n.emitter.emitLine(`${t}}`),n.emitter.emitLine(`${t}${_}:;`),c.loopBodyDropsBaselineCount=f,n.currentLoopLabel=u,""}else if(r.length===3){let s=r[0],l=r[1],u=r[2],_=n.currentLoopLabel,c=n.currentContinueLabel,f=`loop_${Math.random().toString(36).substr(2,9)}`,p=`continue_${Math.random().toString(36).substr(2,9)}`;n.currentLoopLabel=f,n.currentContinueLabel=p;let m=n,h=m.loopBodyDropsBaselineCount;m.loopBodyDropsBaselineCount=((a=m.pendingDeferredDrops)==null?void 0:a.length)??0,n.emitter.emitLine(`${t}while (true) {`);let y=q(s,t+" ",n);n.emitter.emitLine(`${t} if (!(${y})) {`),n.emitter.emitLine(`${t} break;`),n.emitter.emitLine(`${t} }`),Hu(u,t+" ",n),n.emitter.emitLine(`${t}${p}:;`);let g=Dv(l,n);return n.emitter.emitLine(`${t} ${g};`),n.emitter.emitLine(`${t}}`),n.emitter.emitLine(`${t}${f}:;`),m.loopBodyDropsBaselineCount=h,n.currentLoopLabel=_,n.currentContinueLabel=c,""}else return n.emitter.emitLine(`${t}/* Error: while loop expects 2 or 3 arguments, got ${r.length} */`),""}var Mv=0;function Ov(e){let t=[];for(let n of e)if(n.isEffectRowSpread){let r=n.type;z(r)&&r.resolvedConcreteType&&(r=r.resolvedConcreteType),Yt(r)&&t.push(...r.implicitParameters)}else t.push(n);return t}function Rv(e,t,n){var _,c,f,p,m,h,y,g;let r=(_=e.$)==null?void 0:_.indexMethodValue;if(!r||!ge(r))return"/* Error: Index trait method value missing */";let i=e.func,o=q(i,t,n);if(S(i)&&!K(i)&&!E(i,".")&&((c=i.$)!=null&&c.type)&&!(((f=i.$)==null?void 0:f.variableName)&&o===We(i.$.variableName,i.$.env))){let T=j(i.$.type,n),$=`__yo_idx_tmp_${Mv++}`;n.emitter.emitLine(`${t}${T} ${$} = ${o};`),o=$}let a=e.args[0],s=a?q(a,t,n):"0",l,u=gi(r);if(u)if(F.__yo_array_index.includes(u)||F.__yo_slice_index.includes(u))l=`(&((&${o})->data[${s}]))`;else if((F.__yo_array_index_range.includes(u)||F.__yo_slice_index_range.includes(u))&&((p=e.$)!=null&&p.indexTraitPtrType)&&je(e.$.indexTraitPtrType))l=`(&(${j(e.$.indexTraitPtrType.childType,n)}){ .data = &((&${o})->data[(${s}).start]), .length = (${s}).end - (${s}).start })`;else if((F.__yo_array_index_range_inclusive.includes(u)||F.__yo_slice_index_range_inclusive.includes(u))&&((m=e.$)!=null&&m.indexTraitPtrType)&&je(e.$.indexTraitPtrType))l=`(&(${j(e.$.indexTraitPtrType.childType,n)}){ .data = &((&${o})->data[(${s}).start]), .length = (${s}).end - (${s}).start + 1 })`;else{let v=(h=n.functions[r.funcId])==null?void 0:h.cName;if(!v)return`/* Error: Index method ${r.funcId} not found in function registry */`;l=`${v}(&${o}, ${s})`}else{let v=(y=n.functions[r.funcId])==null?void 0:y.cName;if(!v)return`/* Error: Index method ${r.funcId} not found in function registry */`;l=`${v}(&${o}, ${s})`}return(g=e.$)!=null&&g.isIndexTraitAddressOf?l:`(*${l})`}function Pv(e,t,n,r){var c,f,p,m;let i=e.args[0];if(!((c=i==null?void 0:i.$)!=null&&c.type))return;let o=e.args.find(h=>S(h)&&E(h,P.using));if(!o)return;let a=Ln(i.$.type);if(!((f=a==null?void 0:a.isFuture.effects)!=null&&f.length))return;let s=Ov(a.isFuture.effects),l=o.args,u=r,_=u.emitter;for(let h=0;h<s.length&&h<l.length;h++){let y=s[h],g=l[h];if(ne(y.type)){let v=y.label,T;if(u.currentEvidenceParams){for(let $ of u.currentEvidenceParams.values())if($.fieldLabel===v){T=$.cParamName;break}}if(!T&&u.stateMachineVariables){for(let[,$]of u.stateMachineVariables)if($.name===v&&$.kind==="outer"){T=`sm->__capture.${v}`;break}}if(!T){let $=(p=g.$)==null?void 0:p.value;if($&&ge($)){let C=r.functions[$.funcId];C&&(T=C.cName)}}T||(T=q(g,n,r)),T&&_.emitLine(`${n} ${t}->__capture.${v} = (void*)${T};`)}else if(Xe(y.type)){let v=y.type;for(let T of v.fields){if(!ne(T.type))continue;let $;if(u.stateMachineVariables){for(let[,C]of u.stateMachineVariables)if(C.name===T.label&&C.kind==="outer"){$=`sm->__capture.${T.label}`;break}}if(!$){let C=(m=g.$)==null?void 0:m.value;if(C&&wt(C)){let k=v.fields.indexOf(T),b=C.fields[k];if(b&&ge(b)){let w=r.functions[b.funcId];w&&($=w.cName)}}}if(!$&&u.currentEvidenceParams){for(let C of u.currentEvidenceParams.values())if(C.fieldLabel===T.label){$=C.cParamName;break}}$||($=Uv(T.label,v,u,e)),$&&_.emitLine(`${n} ${t}->__capture.${T.label} = (void*)${$};`)}}}}function Uv(e,t,n,r){var a,s,l,u;let i=((a=r.$)==null?void 0:a.env)??((s=r.func.$)==null?void 0:s.env);if(!i)return;let o=cr(i,_=>_.isImplicit===!0);for(let _=o.length-1;_>=0;_--){let c=o[_],f=(l=c.value)==null?void 0:l[c.value.length-1];if(f&&wt(f)){let p=f.type.fields.findIndex(m=>m.label===e);if(p>=0){let m=f.fields[p];if(m&&ge(m)){let h=(u=n.functions[m.funcId])==null?void 0:u.cName;if(h)return h}}}}}function zv(e,t,n){var l,u;let r=n,i=e.args[0],o=(l=r.continuationVariables)==null?void 0:l.get("resume");if(o&&"directReturnVar"in o&&o.directExitLabel){if(i){let _=q(i,t,n);if(r.effectHandlerParamDrops)for(let c of r.effectHandlerParamDrops)r.emitter.emitLine(`${t}${c};`);r.emitter.emitLine(`${t}${o.directReturnVar} = ${_};`),r.emitter.emitLine(`${t}goto ${o.directExitLabel};`)}else{if(r.effectHandlerParamDrops)for(let _ of r.effectHandlerParamDrops)r.emitter.emitLine(`${t}${_};`);r.emitter.emitLine(`${t}goto ${o.directExitLabel};`)}return""}if(r.inAsyncStateMachine){let _=r.emitter;if(i){let c=q(i,t,n);c&&c!=="(void)0"&&_.emitLine(`${t}(void)${c};`)}if(r.effectHandlerParamDrops)for(let c of r.effectHandlerParamDrops)_.emitLine(`${t}${c};`);return or(t,r,e,!1,!0,!0),qr(t,r,e,!0),Ar({emitter:_,indent:t,debugLabel:r.currentFunctionName}),""}if((r.isModuleEffectMemberFunction||r.currentEvidenceParams&&r.currentEvidenceParams.size>0)&&r.emitter.emitLine(`${t}__yo_effect_escaped = 1;`),!i){if(r.effectHandlerParamDrops)for(let _ of r.effectHandlerParamDrops)r.emitter.emitLine(`${t}${_};`);if(or(t,r,e,!1,!0,!0),qr(t,r,e,!0),r.currentFunctionType){let _=r.currentFunctionType.return.type;if(!De(_)){let c=r.overrideReturnTypeStr??j(_,n);if(c!=="void")return`return (${c}){0}`}}return"return"}let s=q(i,t,n);if(r.effectHandlerParamDrops)for(let _ of r.effectHandlerParamDrops)r.emitter.emitLine(`${t}${_};`);if(or(t,r,e,!1,!0,!0),qr(t,r,e,!0),(r.isModuleEffectMemberFunction||r.currentEvidenceParams&&r.currentEvidenceParams.size>0)&&r.currentFunctionType){let _=(u=i.$)==null?void 0:u.type;if(_&&!De(_)){let f=j(_,n);r.emitter.emitLine(`${t}{ ${f} _esc_val = ${s}; memcpy(__yo_effect_escape_value, &_esc_val, sizeof(${f})); }`)}let c=r.currentFunctionType.return.type;if(!De(c)){let f=r.overrideReturnTypeStr??j(c,n);if(f!=="void")return`return (${f}){0}`}return"return"}return`return ${s}`}function Jp(e,t,n){let r;switch(e.tag){case"FnCall":r=Bv(e,t,n);break;case"Atom":r=pa(e,n,t);break}return r}function Bv(e,t,n){var r,i,o,a,s,l,u,_,c,f,p,m,h,y,g;if((r=e.$)!=null&&r.macroExpansion)return q(e.$.macroExpansion,t,n);if(S(e.func)&&E(e.func,".",2)&&e.func.args[1]&&K(e.func.args[1])){let v=e.func.args[1].token.value,T=e.func.args[0],$=(i=T==null?void 0:T.$)==null?void 0:i.type;if($&&z($)&&at($)){if(v===F.___drop[0]){let C=q(T,t,n);return`if (${C} != NULL) { __yo_decr_rc((void*)${C}); }`}if(v===F.___dup[0])return`__yo_incr_rc((void*)${q(T,t,n)})`}}if(af(e))return sf(e,t,n);if(E(e,F.__yo_decr_rc))return Np(e,t,n);if(E(e,F.__yo_incr_rc))return Vp(e,t,n);if(E(e,F.__yo_rc_own))return xp(e,t,n);if(E(e,F.__yo_drop_array_element))return Dp(e,t,n);if(E(e,F.__yo_dup_array_element))return Mp(e,t,n);if(E(e,F.__yo_drop_tuple_element))return Op(e,t,n);if(E(e,F.__yo_dup_tuple_element))return Rp(e,t,n);if(E(e,F.___dup))return Pp(e,t,n);if(E(e,F.___drop))return Up(e,t,n);if(E(e,F.__yo_dyn_drop))return zp(e,t,n);if(E(e,F.__yo_dyn_dup))return Bp(e,t,n);if(E(e,F.__yo_incr_rc_atomic))return Gp(e,t,n);if(E(e,F.__yo_decr_rc_atomic))return Wp(e,t,n);if(E(e,F.__yo_iso_extract))return fp(e,t,n);if(E(e,F.__yo_iso_dispose))return pp(e,t,n);if(Bu(e))return dp(e,t,n);if(E(e,F.__yo_sometype_drop))return qp(e,t,n);if(E(e,F.__yo_sometype_dup))return Yp(e,t,n);if(E(e,F.__yo_gc_collect))return _p(e,t,n);if(E(e,F.rc))return Hp(e,t,n);if(E(e,F.panic))return wp(e,t,n);if(E(e,F.asm))return Lp(e,t,n);if(E(e,F.global_asm))return Ip(e,t,n);if(E(e,P.test))return"/* test declaration skipped */";if(E(e,F.__yo_thread_set_maximum_threads))return Ep(e,t,n);if(E(e,P.op_and))return jf(e,t,n);if(E(e,P.op_or))return Kf(e,t,n);if(An(e))return(o=e.$)!=null&&o.awaitAnalysis?lf(e,t,n):pf(e,t,n);if(E(e,P.dyn))return up(e,t,n);if(_r(e))return ep(e,t,n);if(dc(e))return tp(e,t,n);if(dl(e)){let v=e.args[0];if(!v)return"// Error: spawn requires a Future argument";let $=n.emitter,C=q(v,t,n),k=(a=v.$)==null?void 0:a.type,b=k?j(k,n):"void*",w=(s=e.$)==null?void 0:s.type,A=w?j(w,n):null,L=(l=e.$)!=null&&l.variableName?`__spawn_future_${e.$.variableName}`:"__spawn_future",N=(u=e.$)!=null&&u.variableName?`__spawn_state_${e.$.variableName}`:"__spawn_state";return $.emitLine(`${t}// io.spawn \u2014 start cold Future, return JoinHandle`),$.emitLine(`${t}${b} ${L} = ${C};`),$.emitLine(`${t}int ${N} = ${L}->state;`),$.emitLine(`${t}if (${N} == -2) {`),$.emitLine(`${t} fprintf(stderr, "panic: attempted to spawn an aborted Future\\n");`),$.emitLine(`${t} abort();`),$.emitLine(`${t}}`),es((_=v.$)==null?void 0:_.type)||($.emitLine(`${t}if (${N} == 0 && ${L}->__yo_resume_fn) {`),Pv(e,L,t,n),$.emitLine(`${t} __yo_incr_rc((void*)${L});`),$.emitLine(`${t} ${L}->__yo_resume_fn((void*)${L});`),$.emitLine(`${t}}`)),A?`(${A}){ .__future = (void*)${L} }`:`(void*)${L}`}if(mc(e))return np(e,t,n);if(E(e,P.return))return Vf(e,t,n);if(E(e,P.escape))return zv(e,t,n);if(E(e,F.__yo_array_fill,2))return Qf(e,t,n);if(E(e,"::",2))return"";if(E(e,":",2))return op(e,t,n);if(E(e,":=",2)){let v=cp(e,t,n);if(v!==void 0)return v}else{if(E(e,"=",2))return Zf(e,t,n);if((c=e.$)!=null&&c.value&&!Ie((f=e.$)==null?void 0:f.value)&&!De(e.$.type)&&!Gt((p=e.$)==null?void 0:p.controlFlow))return Yn(e.$.value,n,e);if(E(e,".",2))return Ap(e,t,n);if(E(e,P.begin))return ip(e,t,n);if(E(e,P.cond))return ap(e,t,n);if(E(e,P.match))return yp(e,t,n);if(E(e,F.__yo_address_of,1))return Sp(e,t,n);if(E(e,P.tuple))return Xp(e,t,n);if(E(e,P.array)){let v=Xf(e,t,n);if(v!==void 0)return v}else{if(E(e,P.recur))return jp(e,t,n);if(E(e,P.runtime,1))return q(e.args[0],t,n);if(E(e,F.sizeof,1))return Kp(e,t,n);if(E(e,F.typeid,1))return Qp(e,t,n);if(E(e,F.downcast,2))return lp(e,t,n);if(E(e,ko)){let v=((m=e.$)==null?void 0:m.runtimeArgExprsInOrder)||e.args;if(v){let T=n,$=v.map(C=>{var b,w;let k=q(C,t,n);if((b=C.$)!=null&&b.deferredDupExpressions&&C.$.deferredDupExpressions.length>0){Wt(C,t,T);let A=C.$.deferredDupExpressions[0];if(S(A)&&((w=A.$)!=null&&w.variableName))return We(A.$.variableName,A.$.env)}return k});return rs(e.func.token.value,$,e,n,t)}}else{if(E(e,P.while))return Zp(e,t,n);if(E(e,"->",2)&&S(e.args[0])&&E(e.args[0],P.fn)){let v=(h=e.$)==null?void 0:h.value;return ge(v)?Yn(v,n):"// Error: Anonymous function missing function value"}else{if(E(e,F.consume))return sp(e,t,n);if(E(e,F.comptime_expect_error)||E(e,F.comptime_assert)||E(e,F.__yo_var_print_info)||E(e,F.__yo_var_is_owning_the_rc_value)||E(e,F.__yo_var_has_other_aliases))return"";if(E(e,P.open))return gp(e,t,n);if((y=e.$)!=null&&y.indexTraitPtrType&&((g=e.$)!=null&&g.indexMethodType))return Rv(e,t,n);{let v=kp(e,t,n);if(v!==void 0)return v}}}}}if(S(e))throw new Error(`Unhandled function call: ${I(e)}`);return`// Failed to transpile ${I(e)}`}function ed({expr:e,env:t,context:n}){Ge(e,F.alignof,1);let r=e.args[0],i=O({expr:r,env:t,context:{...n}});if(!i.$)throw d({token:r.token,errorMessage:"Failed to evaluate expression."});t=i.$.env;let o;i.$.value&&W(i.$.value)?o=i.$.value.value:o=i.$.type;let a=Xr(o),s;return a===null?s=oe(vn(),{env:t,context:n}):s=qn("Usize",a),e.$={env:t,type:vn(),value:s,pathCollection:[]},e}function td({expr:e,env:t,context:n}){let r=E(e,P.op_and)?"and":"or",i=e.args;if(i.length===0){let u=Zt(r==="and");return e.$={env:t,type:Ut(),value:u,pathCollection:[],isAccessingProperty:!1},e}let o=t,a,s=!1,l=!1;for(let u=0;u<i.length;u++){let _=i[u],c=O({expr:_,env:o,context:{...n}});if(!c.$||!lr(c.$.type))throw d({token:_.token,errorMessage:`Expected bool type for "${r}" argument, got:
|
|
11400
11400
|
${I(_)}`});o=c.$.env;let f=c.$.value;if(Ie(f)){s=!0;continue}if(Ct(f)){let p=f.value;if(r==="and"){if(!p){a=Zt(!1);break}!s&&!l&&(a=Zt(!0))}else{if(p){a=Zt(!0);break}!s&&!l&&(a=Zt(!1))}}else l=!0}return Ct(a)||(l||s)&&(l?a=void 0:a=oe(Ut(),{env:o,context:n})),e.$={env:o,type:Ut(),value:a,pathCollection:[],isAccessingProperty:!1},e}function nd({expr:e,env:t,context:n}){var h,y,g,v,T;Ge(e,F.__yo_array_fill,2);let r=e.args[0],i=e.args[1],o=O({expr:r,env:t,context:{...n}});(h=o.$)!=null&&h.env&&(t=o.$.env);let a=(y=o.$)==null?void 0:y.value;if(!W(a)||!Je(a.value))throw d({token:r.token,errorMessage:`__yo_array_fill expects first argument to be an ArrayType, got ${a?pt(a):"undefined"}`});let s=a.value,l=O({expr:i,env:t,context:{...n,expectedType:{type:s.childType,env:t}}});(g=l.$)!=null&&g.env&&(t=l.$.env);let u=(v=l.$)==null?void 0:v.type,_=(T=l.$)==null?void 0:T.value;if(!u)throw d({token:i.token,errorMessage:"Failed to evaluate fill value"});if(!_)throw d({token:i.token,errorMessage:"__yo_array_fill expects second argument to be a compile-time known value, got runtime value"});if(!le({type:s.childType,env:t},{type:u,env:t}))throw d({token:i.token,errorMessage:`Fill value type ${M(u)} is not compatible with array element type ${M(s.childType)}`});let c=s.length;if(Ie(c)){let $=oe(s,{env:t,context:n});return e.$={env:t,type:s,value:$,pathCollection:[]},e}let f;if(ht(c)){let $=c.value;if(f=typeof $=="bigint"?Number($):$,!Number.isInteger(f)||f<0)throw d({token:i.token,errorMessage:`Array length must be a non-negative integer, got ${f}`})}else throw d({token:i.token,errorMessage:`Array length must be a compile-time known integer, got ${pt(c)}`});let p=[];if(Ie(_)){let $=oe(s,{env:t,context:n});return e.$={env:t,type:s,value:$,pathCollection:[]},e}for(let $=0;$<f;$++)p.push(_);let m=zi(s,p);return e.$={env:t,type:s,value:m,pathCollection:[]},e}function rd({expr:e,env:t,context:n}){var s,l,u;if(n.isValidatingFunctionDefinition||!n.isExecuting){let _=((s=n.expectedType)==null?void 0:s.type)??ue.type;return e.$={env:t,type:_,value:De(_)?ue:oe(_,{env:t,context:n}),pathCollection:[]},e}let r=e.args[0],i=e.args[1],o=O({expr:r,env:t,context:{...n}});if(!o.$||!Ct(o.$.value))throw d({token:r.token,errorMessage:`Expected bool value for "comptime_assert", got:
|
|
11401
11401
|
${I(r)}
|
|
11402
11402
|
|
|
@@ -11406,7 +11406,7 @@ ${I(r)}`,isAssertionError:!0})}function id({expr:e,env:t,context:n}){if(E(e,F.__
|
|
|
11406
11406
|
${I(r)}`});t=r.$.env;let i;if(E(e,F.__yo_comptime_bool_not))Ct(r.$.value)?i=Zt(!r.$.value.value):i=oe(Ut(),{env:t,context:n});else if(E(e,F.__yo_comptime_bool_to_comptime_string))Ct(r.$.value)?i=wn(r.$.value.value.toString()):i=oe(Fn(),{env:t,context:n});else throw d({token:e.token,errorMessage:`Unexpected function call for "${e.func.token.value}", expected "__yo_comptime_bool_not" or "__yo_comptime_bool_to_comptime_string" function`});e.$={env:t,type:i.type,value:i,pathCollection:[]}}else{let r=O({expr:e.args[0],env:t,context:{...n}});if(!r.$||!lr(r.$.type)||!r.$.value)throw d({token:r.token,errorMessage:`Expected bool type for "${e.func.token.value}" first argument, got:
|
|
11407
11407
|
${I(r)}`});t=r.$.env;let i=O({expr:e.args[1],env:t,context:{...n}});if(!i.$||!lr(i.$.type)||!i.$.value)throw d({token:i.token,errorMessage:`Expected bool type for "${e.func.token.value}" second argument, got:
|
|
11408
11408
|
${I(i)}`});t=i.$.env;let o=r.$.value,a=i.$.value,s;if(E(e,F.__yo_comptime_bool_and))Ct(o)&&Ct(a)?s=Zt(o.value&&a.value):s=oe(Ut(),{env:t,context:n});else if(E(e,F.__yo_comptime_bool_or))Ct(o)&&Ct(a)?s=Zt(o.value||a.value):s=oe(Ut(),{env:t,context:n});else if(E(e,F.__yo_comptime_bool_eq))Ct(o)&&Ct(a)?s=Zt(o.value===a.value):s=oe(Ut(),{env:t,context:n});else if(E(e,F.__yo_comptime_bool_neq))Ct(o)&&Ct(a)?s=Zt(o.value!==a.value):s=oe(Ut(),{env:t,context:n});else throw d({token:e.token,errorMessage:`Unexpected function call for comptime_bool operations: ${I(e)}`});e.$={env:t,type:s.type,value:s,pathCollection:[]}}return e}function od({expr:e,env:t,context:n}){var o;let r=_t(e.args[0]),i=e.args[1]?_t(e.args[1]):void 0;try{O({expr:r,env:t,context:{...n}})}catch{return e.$={env:t,type:ue.type,value:ue,pathCollection:[]},e}if(i){let a=O({expr:i,env:t,context:{...n}});if((o=a.$)!=null&&o.value)throw d({token:e.token,errorMessage:tt(a.$.value)?a.$.value.value:pt(a.$.value)})}throw d({token:e.token,errorMessage:`Expected compile error, but the expression was evaluated successfully:
|
|
11409
|
-
${I(r)}`})}function Gv(e){return{...e,forallParameters:e.forallParameters.map(t=>({...t,isCompileTimeOnly:!0})),parameters:e.parameters.map(t=>({...t,isCompileTimeOnly:!0})),return:{...e.return,isCompileTimeOnly:!0}}}function da(e,t,n){var i;if(e.type.return.isCompileTimeOnly||e.type.isExtern||e.type.forallParameters.length>0)return;for(let o of e.type.parameters)if(fi(o.type,t))return;if(fi(e.type.return.type,t))return;let r=Gv(e.type);try{let o=_t(e.body),a=lt(r.env);for(let u of r.parameters){let{env:_}=xe({env:a,variable:{name:u.label,type:u.type,isCompileTimeOnly:!0,value:[oe(u.type,{variableName:u.label,env:a,context:n})],token:Fe,initializedAtToken:Fe,consumedAtToken:void 0,isOwningTheRcValue:!1}});a=_}let s={tag:"Function",type:r,body:o,frameLevel:e.frameLevel,funcName:e.funcName?`${e.funcName}_comptime`:void 0,funcId:`${e.funcId}_comptime`,definitionSiteEnclosingFunctionType:e.definitionSiteEnclosingFunctionType,calledComptimeFunctionCaches:[],specializedFunctionCaches:[]},l=un({expr:o,env:a,context:{...n,isExecuting:!0,forceCompileTimeBindings:!0,isAnalyzingCtfeCapability:!0,isEvaluatingFunctionBodyOrAsyncBlock:{kind:"function-body",type:r,value:s,evaluationEnv:a},expectedType:{type:r.return.type,env:a}},variablesToAdd:[],isEvaluatingFunctionBodyBeginBlock:!0});if(((i=l.$)==null?void 0:i.value)!==void 0)return s.body=l,Ot(a,!0),s;Ot(a,!0);return}catch{return}}function ad({expr:e,env:t,context:n}){let r=e.args[0];if(!r)throw d({token:e.token,errorMessage:"comptime_fn requires exactly one argument (a function)"});let i=O({expr:r,env:t,context:n});if(!i.$)throw d({token:r.token,errorMessage:"Failed to evaluate argument to comptime_fn"});let o=i.$.value;if(!
|
|
11409
|
+
${I(r)}`})}function Gv(e){return{...e,forallParameters:e.forallParameters.map(t=>({...t,isCompileTimeOnly:!0})),parameters:e.parameters.map(t=>({...t,isCompileTimeOnly:!0})),return:{...e.return,isCompileTimeOnly:!0}}}function da(e,t,n){var i;if(e.type.return.isCompileTimeOnly||e.type.isExtern||e.type.forallParameters.length>0)return;for(let o of e.type.parameters)if(fi(o.type,t))return;if(fi(e.type.return.type,t))return;let r=Gv(e.type);try{let o=_t(e.body),a=lt(r.env);for(let u of r.parameters){let{env:_}=xe({env:a,variable:{name:u.label,type:u.type,isCompileTimeOnly:!0,value:[oe(u.type,{variableName:u.label,env:a,context:n})],token:Fe,initializedAtToken:Fe,consumedAtToken:void 0,isOwningTheRcValue:!1}});a=_}let s={tag:"Function",type:r,body:o,frameLevel:e.frameLevel,funcName:e.funcName?`${e.funcName}_comptime`:void 0,funcId:`${e.funcId}_comptime`,definitionSiteEnclosingFunctionType:e.definitionSiteEnclosingFunctionType,calledComptimeFunctionCaches:[],specializedFunctionCaches:[]},l=un({expr:o,env:a,context:{...n,isExecuting:!0,forceCompileTimeBindings:!0,isAnalyzingCtfeCapability:!0,isEvaluatingFunctionBodyOrAsyncBlock:{kind:"function-body",type:r,value:s,evaluationEnv:a},expectedType:{type:r.return.type,env:a}},variablesToAdd:[],isEvaluatingFunctionBodyBeginBlock:!0});if(((i=l.$)==null?void 0:i.value)!==void 0)return s.body=l,Ot(a,!0),s;Ot(a,!0);return}catch{return}}function ad({expr:e,env:t,context:n}){let r=e.args[0];if(!r)throw d({token:e.token,errorMessage:"comptime_fn requires exactly one argument (a function)"});let i=O({expr:r,env:t,context:n});if(!i.$)throw d({token:r.token,errorMessage:"Failed to evaluate argument to comptime_fn"});let o=i.$.value;if(!ge(o))throw d({token:r.token,errorMessage:`comptime_fn requires a function argument, got: ${pt(o)}`});if(o.type.return.isCompileTimeOnly)return e.$={env:t,type:o.type,value:o,pathCollection:[]},e;let a=da(o,t,n);if(a)return e.$={env:t,type:a.type,value:a,pathCollection:[]},e;throw d({token:r.token,errorMessage:"comptime_fn: Failed to create compile-time version of function. The function body cannot be evaluated at compile time."})}function sd({expr:e,env:t,context:n}){Ge(e,F.__yo_comptime_list_car,1);let r=e.args[0],i=O({expr:r,env:t,context:{...n}});if(!i.$)throw d({token:r.token,errorMessage:`Failed to evaluate the argument expression for "${e.func.token.value}":
|
|
11410
11410
|
${I(r)}`});if(!sn(i.$.type))throw d({token:r.token,errorMessage:`Expected ComptimeList type for "${e.func.token.value}" argument, got:
|
|
11411
11411
|
${I(r)}`});let o=i.$.type,a=i.$.value;if(!a)throw d({token:r.token,errorMessage:`Expected ComptimeList value for "${e.func.token.value}" argument, got:
|
|
11412
11412
|
${I(r)}`});if(e.$={env:i.$.env,type:o.childType,value:oe(o.childType,{variableName:`__comptime_list_car_${mt(t.modulePath)}`,env:i.$.env,context:n}),pathCollection:[],isAccessingProperty:!1},Tr(a)){let s=a.elements;if(s.length>0)e.$.value=s[0];else throw d({token:r.token,errorMessage:`Unexpected empty ComptimeList for "${e.func.token.value}" argument`})}return e}function ld({expr:e,env:t,context:n}){Ge(e,F.__yo_comptime_list_cdr,1);let r=e.args[0],i=O({expr:r,env:t,context:{...n}});if(!i.$)throw d({token:r.token,errorMessage:`Failed to evaluate the argument expression for "${e.func.token.value}":
|
|
@@ -11440,7 +11440,7 @@ ${I(r)}`});t=r.$.env;let i=O({expr:e.args[1],env:t,context:{...n}});if(!i.$||!rn
|
|
|
11440
11440
|
${I(i)}`});t=i.$.env;let o;if(e.args.length===3){if(o=O({expr:e.args[2],env:t,context:{...n}}),!o.$||!rn(o.$.type)||!o.$.value)throw d({token:o.token,errorMessage:`Expected comptime_int type for "${e.func.token.value}" end argument, got:
|
|
11441
11441
|
${I(o)}`});t=o.$.env}let a;if(tt(r.$.value)&&yr(i.$.value)){let s=r.$.value.value,l=i.$.value.value,u=typeof l=="bigint"?Number(l):l,_=s.length;if(o&&o.$&&o.$.value&&yr(o.$.value)){let c=o.$.value.value;_=typeof c=="bigint"?Number(c):c}a=wn(s.slice(u,_))}else a=oe(Fn(),{env:t,context:n});e.$={env:t,type:a.type,value:a,pathCollection:[]}}else{let r=O({expr:e.args[0],env:t,context:{...n}});if(!r.$||!on(r.$.type)||!r.$.value)throw d({token:r.token,errorMessage:`Expected comptime_string type for "${e.func.token.value}" first argument, got:
|
|
11442
11442
|
${I(r)}`});t=r.$.env;let i=O({expr:e.args[1],env:t,context:{...n}});if(!i.$||!on(i.$.type)||!i.$.value)throw d({token:i.token,errorMessage:`Expected comptime_string type for "${e.func.token.value}" second argument, got:
|
|
11443
|
-
${I(i)}`});t=i.$.env;let o=r.$.value,a=i.$.value,s;if(E(e,F.__yo_comptime_string_concat))tt(o)&&tt(a)?s=wn(o.value+a.value):s=oe(Fn(),{env:t,context:n});else if(E(e,F.__yo_comptime_string_eq))tt(o)&&tt(a)?s=Zt(o.value===a.value):s=oe(Ut(),{env:t,context:n});else if(E(e,F.__yo_comptime_string_neq))tt(o)&&tt(a)?s=Zt(o.value!==a.value):s=oe(Ut(),{env:t,context:n});else if(E(e,F.__yo_comptime_string_lt))tt(o)&&tt(a)?s=Zt(o.value<a.value):s=oe(Ut(),{env:t,context:n});else if(E(e,F.__yo_comptime_string_lte))tt(o)&&tt(a)?s=Zt(o.value<=a.value):s=oe(Ut(),{env:t,context:n});else if(E(e,F.__yo_comptime_string_gt))tt(o)&&tt(a)?s=Zt(o.value>a.value):s=oe(Ut(),{env:t,context:n});else if(E(e,F.__yo_comptime_string_gte))tt(o)&&tt(a)?s=Zt(o.value>=a.value):s=oe(Ut(),{env:t,context:n});else throw d({token:e.token,errorMessage:`Unexpected function call for comptime_string operations: ${I(e)}`});e.$={env:t,type:s.type,value:s,pathCollection:[]}}return e}function Lo(e){return typeof e=="bigint"?Number(e):e}function Ml(e,t){let n=e.fields[0],r=e.fields[1];if(!n||!r||!ht(n)||!ht(r))return;let i=Lo(n.value),o=Lo(r.value);return t&&(o+=1),{start:i,end:o}}function vd({expr:e,env:t,context:n,isSlice:r}){let i=e.args[0],o=e.args[1],a=O({expr:i,env:t,context:{...n}});if(!a.$)throw d({token:i.token,errorMessage:"Failed to evaluate self for comptime index"});t=a.$.env;let s=O({expr:o,env:t,context:{...n}});if(!s.$)throw d({token:o.token,errorMessage:"Failed to evaluate index for comptime index"});t=s.$.env;let l=a.$.value;if(r&&l&&lo(l)){let c=l,f=c.type.childType;if(s.$.value&&ht(s.$.value)){let p=Lo(s.$.value.value),m=c.endIndex-c.startIndex;if(p<0||p>=m)throw d({token:o.token,errorMessage:`Slice index out of bounds: ${p}. Expected index in range [0, ${m-1}].`});let h=c.startIndex+p,y=c.sourceArray[0],g=y.elements[h];return e.$={env:t,type:f,value:g,pathCollection:[],comptimeRef:{kind:"array",arrayValue:y,index:h}},e}return e.$={env:t,type:f,value:oe(f,{env:t,context:n}),pathCollection:[]},e}if(!r&&l&&mr(l)){let c=l,f=c.type.childType;if(s.$.value&&ht(s.$.value)){let p=Lo(s.$.value.value);if(p<0||p>=c.elements.length)throw d({token:o.token,errorMessage:`Array index out of bounds: ${p}. Expected index in range [0, ${c.elements.length-1}].`});let m=c.elements[p];return e.$={env:t,type:f,value:m,pathCollection:[],comptimeRef:{kind:"array",arrayValue:c,index:p}},e}return e.$={env:t,type:f,value:oe(f,{env:t,context:n}),pathCollection:[]},e}let u=a.$.type,_=Cd(u);return e.$={env:t,type:_,value:void 0,pathCollection:[]},e}function Cd(e){if(je(e)){let t=e.childType;if(Je(t))return yn(t.childType);if($t(t))return yn(t.childType);if(sn(t))return yn(t.childType)}return Je(e)?yn(e.childType):$t(e)?yn(e.childType):sn(e)?yn(e.childType):e}function Qv({expr:e,env:t,context:n}){let r=e.args[0],i=e.args[1],o=O({expr:r,env:t,context:{...n}});if(!o.$)throw d({token:r.token,errorMessage:"Failed to evaluate self for comptime list index"});t=o.$.env;let a=O({expr:i,env:t,context:{...n}});if(!a.$)throw d({token:i.token,errorMessage:"Failed to evaluate index for comptime list index"});t=a.$.env;let s=o.$.value,l;if(Tr(s)?l=s:s&&Vr(s)&&Tr(s.targetValue[0])&&(l=s.targetValue[0]),l){let c=l.type.childType;if(a.$.value&&ht(a.$.value)){let f=Lo(a.$.value.value);if(f<0||f>=l.elements.length)throw d({token:i.token,errorMessage:`ComptimeList index out of bounds: ${f}. Expected index in range [0, ${l.elements.length-1}].`});let p=l.elements[f];return e.$={env:t,type:c,value:p,pathCollection:[],comptimeRef:{kind:"comptime_list",listValue:l,index:f}},e}return e.$={env:t,type:c,value:oe(c,{env:t,context:n}),pathCollection:[]},e}let u=o.$.type,_=Cd(u);return e.$={env:t,type:_,value:oe(_,{env:t,context:n}),pathCollection:[]},e}function Td({expr:e,env:t,context:n,isInclusive:r}){let i=e.args[0],o=e.args[1],a=O({expr:i,env:t,context:{...n}});if(!a.$)throw d({token:i.token,errorMessage:"Failed to evaluate self for comptime list range index"});t=a.$.env;let s=O({expr:o,env:t,context:{...n}});if(!s.$)throw d({token:o.token,errorMessage:"Failed to evaluate range for comptime list range index"});t=s.$.env;let l=a.$.value,u=s.$.value;if(!u||Ie(u)||!kn(u)){let y=a.$.type,g=Ed(y);return e.$={env:t,type:g,value:oe(g,{env:t,context:n}),pathCollection:[]},e}let _=Ml(u,r);if(!_)throw d({token:o.token,errorMessage:"Expected numeric start/end in Range for comptime list range index"});let{start:c,end:f}=_,p;if(Tr(l)?p=l:l&&Vr(l)&&Tr(l.targetValue[0])&&(p=l.targetValue[0]),p){let y=p.type.childType,g=ki(y);if(c<0||c>p.elements.length)throw d({token:o.token,errorMessage:`ComptimeList range start out of bounds: ${c}. Expected in range [0, ${p.elements.length}].`});if(f<c||f>p.elements.length)throw d({token:o.token,errorMessage:`ComptimeList range end out of bounds: ${f}. Expected in range [${c}, ${p.elements.length}].`});let v=p.elements.slice(c,f),T=Jn(y,v);return e.$={env:t,type:g,value:T,pathCollection:[]},e}let m=a.$.type,h=Ed(m);return e.$={env:t,type:h,value:oe(h,{env:t,context:n}),pathCollection:[]},e}function Ed(e){if(je(e)){let t=e.childType;if(sn(t))return yn(t)}return sn(e)?yn(e):e}function Dl({expr:e,env:t,context:n,isSlice:r,isInclusive:i}){let o=e.args[0],a=e.args[1],s=O({expr:o,env:t,context:{...n}});if(!s.$)throw d({token:o.token,errorMessage:"Failed to evaluate self for comptime range index"});t=s.$.env;let l=O({expr:a,env:t,context:{...n}});if(!l.$)throw d({token:a.token,errorMessage:"Failed to evaluate range index for comptime index"});t=l.$.env;let u=s.$.value,_=l.$.value;if(!_||Ie(_)||!kn(_)){let y=s.$.type,g=$d(y);return e.$={env:t,type:g,value:void 0,pathCollection:[]},e}let c=Ml(_,i);if(!c)throw d({token:a.token,errorMessage:"Expected numeric start/end in Range for comptime range index"});let{start:f,end:p}=c;if(!r&&u&&mr(u)){let y=u,g=y.type.childType,v=Ii(g);if(f<0||f>y.elements.length)throw d({token:a.token,errorMessage:`Slice start index out of bounds: ${f}. Expected index in range [0, ${y.elements.length}].`});if(p<f||p>y.elements.length)throw d({token:a.token,errorMessage:`Slice end index out of bounds: ${p}. Expected index in range [${f}, ${y.elements.length}].`});let T=Oo(v,[y],f,p);return e.$={env:t,type:v,value:T,pathCollection:[]},e}if(r&&u&&lo(u)){let y=u,g=y.type.childType,v=Ii(g),T=y.endIndex-y.startIndex;if(f<0||f>T)throw d({token:a.token,errorMessage:`Slice start index out of bounds: ${f}. Expected index in range [0, ${T}].`});if(p<f||p>T)throw d({token:a.token,errorMessage:`Slice end index out of bounds: ${p}. Expected index in range [${f}, ${T}].`});let $=y.startIndex+f,C=y.startIndex+p,k=Oo(v,y.sourceArray,$,C);return e.$={env:t,type:v,value:k,pathCollection:[]},e}let m=s.$.type,h=$d(m);return e.$={env:t,type:h,value:void 0,pathCollection:[]},e}function $d(e){if(je(e)){let t=e.childType;if(Je(t)){let n=t.childType;return yn(Ii(n))}if($t(t))return e}if(Je(e)){let t=e.childType;return yn(Ii(t))}return $t(e)?yn(e):e}function Ku({expr:e,env:t,context:n,isRange:r,isInclusive:i}){let o=e.args[0],a=e.args[1],s=O({expr:o,env:t,context:{...n}});if(!s.$)throw d({token:o.token,errorMessage:"Failed to evaluate self for comptime string index"});t=s.$.env;let l=O({expr:a,env:t,context:{...n}});if(!l.$)throw d({token:a.token,errorMessage:"Failed to evaluate index for comptime string index"});t=l.$.env;let u=s.$.value,_=s.$.type;if(!u||!tt(u))return e.$={env:t,type:_,value:void 0,pathCollection:[]},e;let c=u.value;if(!r){let y=l.$.value;if(!y||Ie(y)||!yr(y))return e.$={env:t,type:_,value:void 0,pathCollection:[]},e;let g=Lo(y.value);if(g<0||g>=c.length)throw d({token:a.token,errorMessage:`String index out of bounds: ${g}. Expected index in range [0, ${c.length-1}].`});return e.$={env:t,type:_,value:wn(c[g]),pathCollection:[]},e}let f=l.$.value;if(!f||Ie(f)||!kn(f))return e.$={env:t,type:_,value:void 0,pathCollection:[]},e;let p=Ml(f,i);if(!p)throw d({token:a.token,errorMessage:"Expected numeric start/end in Range for comptime string range index"});let{start:m,end:h}=p;if(m<0||m>c.length)throw d({token:a.token,errorMessage:`String slice start index out of bounds: ${m}. Expected index in range [0, ${c.length}].`});if(h<m||h>c.length)throw d({token:a.token,errorMessage:`String slice end index out of bounds: ${h}. Expected index in range [${m}, ${c.length}].`});return e.$={env:t,type:_,value:wn(c.slice(m,h)),pathCollection:[]},e}function bd({expr:e,env:t,context:n}){if(E(e,F.__yo_comptime_array_index))return vd({expr:e,env:t,context:n,isSlice:!1});if(E(e,F.__yo_comptime_slice_index))return vd({expr:e,env:t,context:n,isSlice:!0});if(E(e,F.__yo_comptime_list_index))return Qv({expr:e,env:t,context:n});if(E(e,F.__yo_comptime_list_index_range))return Td({expr:e,env:t,context:n,isInclusive:!1});if(E(e,F.__yo_comptime_list_index_range_inclusive))return Td({expr:e,env:t,context:n,isInclusive:!0});if(E(e,F.__yo_comptime_array_index_range))return Dl({expr:e,env:t,context:n,isSlice:!1,isInclusive:!1});if(E(e,F.__yo_comptime_array_index_range_inclusive))return Dl({expr:e,env:t,context:n,isSlice:!1,isInclusive:!0});if(E(e,F.__yo_comptime_slice_index_range))return Dl({expr:e,env:t,context:n,isSlice:!0,isInclusive:!1});if(E(e,F.__yo_comptime_slice_index_range_inclusive))return Dl({expr:e,env:t,context:n,isSlice:!0,isInclusive:!0});if(E(e,F.__yo_comptime_string_index))return Ku({expr:e,env:t,context:n,isRange:!1,isInclusive:!1});if(E(e,F.__yo_comptime_string_index_range))return Ku({expr:e,env:t,context:n,isRange:!0,isInclusive:!1});if(E(e,F.__yo_comptime_string_index_range_inclusive))return Ku({expr:e,env:t,context:n,isRange:!0,isInclusive:!0});throw d({token:e.token,errorMessage:`Unexpected comptime index builtin: ${I(e)}`})}function kd({strValue:e,argValue:t,token:n,isRange:r,isInclusive:i}){if(Ie(t))return wn("");if(!r){if(!yr(t))throw d({token:n,errorMessage:"Expected comptime_int index for comptime string index"});let l=Lo(t.value);if(l<0||l>=e.length)throw d({token:n,errorMessage:`String index out of bounds: ${l}. Expected index in range [0, ${e.length-1}].`});return wn(e[l])}if(!kn(t))throw d({token:n,errorMessage:"Expected comptime Range value for comptime string range index"});let o=Ml(t,i);if(!o)throw d({token:n,errorMessage:"Expected numeric start/end in Range for comptime string range index"});let{start:a,end:s}=o;if(a<0||a>e.length)throw d({token:n,errorMessage:`String slice start index out of bounds: ${a}. Expected index in range [0, ${e.length}].`});if(s<a||s>e.length)throw d({token:n,errorMessage:`String slice end index out of bounds: ${s}. Expected index in range [${a}, ${e.length}].`});return wn(e.slice(a,s))}function wd({expr:e,env:t,context:n}){Ge(e,F.consume,1);let r=e.args[0],i=O({expr:r,env:t,context:{...n}});if(!i.$)throw d({token:r.token,errorMessage:"Failed to evaluate expression."});return t=i.$.env,t=kr(i,t),e.$={env:t,type:ue.type,value:ue,pathCollection:[]},e}function Oi({functionCalleeExpr:e,functionType:t,functionValue:n,argValues:r,callerEnv:i,calleeEnv:o,context:a}){if(a.isAnalyzingCtfeCapability)return{value:oe(t.return.type,{variableName:"ctfe_analysis_result_"+mt(i.modulePath),env:t.env,context:a}),callerEnv:i,calleeEnv:o};let s=[...r.forallArgs.map(T=>T.value),...r.args.map(T=>T.value),...r.variadicArgs.map(T=>T.value)];if(s.some(T=>!T))throw d({token:(e==null?void 0:e.token)??Fe,errorMessage:"Failed to call the function for compile-time. Some arguments are not compile-time evaluated correctly."});let l=s,u=t.return.type,_=St(u),c=n.funcId,f=n.calledComptimeFunctionCaches,p=_?f.find(T=>T.argValues.length===l.length&&T.argValues.every(($,C)=>{let k=l[C];return W($)&&W(k)?z($.value)&&z(k.value)||Me($.value)||Me(k.value)?$.value.id===k.value.id:z($.value)&&!z(k.value)?!1:le({type:$.value,env:T.env},{type:k.value,env:i},!0):Cn({value:$,env:T.env},{value:k,env:i})})):void 0;if(p)return{callerEnv:i,calleeEnv:o,value:p.value};let m=n.body,h={funcId:c,argValues:l,value:oe(t.return.type,{variableName:t.return.label,recursiveTypeRef:{functionValue:n,argValues:l},env:o,context:a}),env:o,body:_t(m)};n.calledComptimeFunctionCaches.push(h);let y=n.calledComptimeFunctionCaches.length-1,g;try{g=un({expr:h.body,env:o,context:{...a,isEvaluatingFunctionBodyOrAsyncBlock:{kind:"function-body",type:t,value:n,evaluationEnv:o},isEvaluatingLoopBody:void 0,capturedVariables:void 0,isExecuting:!a.isValidatingFunctionDefinition,functionReturnImplConcreteType:[],SelfType:t.SelfType??a.SelfType,forceCompileTimeBindings:!0},variablesToAdd:[]})}catch(T){throw n.calledComptimeFunctionCaches.splice(y,1),T}if(!g.$)throw d({token:n.body.token,errorMessage:"Function body is not evaluated correctly"});let v=g.$.value;if(!v)throw d({token:n.body.token,errorMessage:"Function body is not evaluated correctly. Expected to return a compile-time known value."});if(o=g.$.env,W(v)){let T=v.value;!T.typeName&&n.funcName&&(T.typeName=n.funcName+`(${l.map($=>pt($)).join(", ")})`),(Ae(T)||Be(T)||Bt(T)||Xe(T)||ot(T))&&(T.functionValue||(T.functionValue=n))}return _?n.calledComptimeFunctionCaches[y]={funcId:c,argValues:l,value:v,env:g.$.env,body:g}:n.calledComptimeFunctionCaches.splice(y,1),{value:v,callerEnv:i,calleeEnv:o,comptimeRef:g.$.comptimeRef}}function Xu(e,t,n){var p;let i=ae(t,"Option").find(m=>{var h;return((h=m.value)==null?void 0:h[0])&&he(m.value[0])&&ne(m.type)});if(!i||!((p=i.value)!=null&&p[0])||!he(i.value[0]))throw new Error("Cannot find Option type constructor in environment");let o=i.value[0],a=o.type,s=a.parameters[0],l=Te(e),u=lt(a.env),{env:_}=xe({env:u,variable:{name:s.label,token:Fe,type:l.type,isCompileTimeOnly:!0,initializedAtToken:Fe,consumedAtToken:void 0,value:[l],isOwningTheRcValue:!1}}),{value:c,callerEnv:f}=Oi({functionCalleeExpr:void 0,functionType:a,functionValue:o,argValues:{forallArgs:[],args:[{value:l,parameterType:s.type,argType:Pt()}],variadicArgs:[]},callerEnv:t,calleeEnv:_,context:n});if(!W(c))throw new Error("Option type constructor did not return a type value");return{optionType:c.value,env:f}}function Fd({expr:e,env:t,context:n}){Ge(e,[F.__yo_decr_rc[0]],1);let r=e.args[0],i=O({expr:r,env:t,context:{...n}});if(!i.$)throw d({token:r.token,errorMessage:`Failed to evaluate the argument expression for "${F.__yo_decr_rc[0]}":
|
|
11443
|
+
${I(i)}`});t=i.$.env;let o=r.$.value,a=i.$.value,s;if(E(e,F.__yo_comptime_string_concat))tt(o)&&tt(a)?s=wn(o.value+a.value):s=oe(Fn(),{env:t,context:n});else if(E(e,F.__yo_comptime_string_eq))tt(o)&&tt(a)?s=Zt(o.value===a.value):s=oe(Ut(),{env:t,context:n});else if(E(e,F.__yo_comptime_string_neq))tt(o)&&tt(a)?s=Zt(o.value!==a.value):s=oe(Ut(),{env:t,context:n});else if(E(e,F.__yo_comptime_string_lt))tt(o)&&tt(a)?s=Zt(o.value<a.value):s=oe(Ut(),{env:t,context:n});else if(E(e,F.__yo_comptime_string_lte))tt(o)&&tt(a)?s=Zt(o.value<=a.value):s=oe(Ut(),{env:t,context:n});else if(E(e,F.__yo_comptime_string_gt))tt(o)&&tt(a)?s=Zt(o.value>a.value):s=oe(Ut(),{env:t,context:n});else if(E(e,F.__yo_comptime_string_gte))tt(o)&&tt(a)?s=Zt(o.value>=a.value):s=oe(Ut(),{env:t,context:n});else throw d({token:e.token,errorMessage:`Unexpected function call for comptime_string operations: ${I(e)}`});e.$={env:t,type:s.type,value:s,pathCollection:[]}}return e}function Lo(e){return typeof e=="bigint"?Number(e):e}function Ml(e,t){let n=e.fields[0],r=e.fields[1];if(!n||!r||!ht(n)||!ht(r))return;let i=Lo(n.value),o=Lo(r.value);return t&&(o+=1),{start:i,end:o}}function vd({expr:e,env:t,context:n,isSlice:r}){let i=e.args[0],o=e.args[1],a=O({expr:i,env:t,context:{...n}});if(!a.$)throw d({token:i.token,errorMessage:"Failed to evaluate self for comptime index"});t=a.$.env;let s=O({expr:o,env:t,context:{...n}});if(!s.$)throw d({token:o.token,errorMessage:"Failed to evaluate index for comptime index"});t=s.$.env;let l=a.$.value;if(r&&l&&lo(l)){let c=l,f=c.type.childType;if(s.$.value&&ht(s.$.value)){let p=Lo(s.$.value.value),m=c.endIndex-c.startIndex;if(p<0||p>=m)throw d({token:o.token,errorMessage:`Slice index out of bounds: ${p}. Expected index in range [0, ${m-1}].`});let h=c.startIndex+p,y=c.sourceArray[0],g=y.elements[h];return e.$={env:t,type:f,value:g,pathCollection:[],comptimeRef:{kind:"array",arrayValue:y,index:h}},e}return e.$={env:t,type:f,value:oe(f,{env:t,context:n}),pathCollection:[]},e}if(!r&&l&&mr(l)){let c=l,f=c.type.childType;if(s.$.value&&ht(s.$.value)){let p=Lo(s.$.value.value);if(p<0||p>=c.elements.length)throw d({token:o.token,errorMessage:`Array index out of bounds: ${p}. Expected index in range [0, ${c.elements.length-1}].`});let m=c.elements[p];return e.$={env:t,type:f,value:m,pathCollection:[],comptimeRef:{kind:"array",arrayValue:c,index:p}},e}return e.$={env:t,type:f,value:oe(f,{env:t,context:n}),pathCollection:[]},e}let u=a.$.type,_=Cd(u);return e.$={env:t,type:_,value:void 0,pathCollection:[]},e}function Cd(e){if(je(e)){let t=e.childType;if(Je(t))return yn(t.childType);if($t(t))return yn(t.childType);if(sn(t))return yn(t.childType)}return Je(e)?yn(e.childType):$t(e)?yn(e.childType):sn(e)?yn(e.childType):e}function Qv({expr:e,env:t,context:n}){let r=e.args[0],i=e.args[1],o=O({expr:r,env:t,context:{...n}});if(!o.$)throw d({token:r.token,errorMessage:"Failed to evaluate self for comptime list index"});t=o.$.env;let a=O({expr:i,env:t,context:{...n}});if(!a.$)throw d({token:i.token,errorMessage:"Failed to evaluate index for comptime list index"});t=a.$.env;let s=o.$.value,l;if(Tr(s)?l=s:s&&Vr(s)&&Tr(s.targetValue[0])&&(l=s.targetValue[0]),l){let c=l.type.childType;if(a.$.value&&ht(a.$.value)){let f=Lo(a.$.value.value);if(f<0||f>=l.elements.length)throw d({token:i.token,errorMessage:`ComptimeList index out of bounds: ${f}. Expected index in range [0, ${l.elements.length-1}].`});let p=l.elements[f];return e.$={env:t,type:c,value:p,pathCollection:[],comptimeRef:{kind:"comptime_list",listValue:l,index:f}},e}return e.$={env:t,type:c,value:oe(c,{env:t,context:n}),pathCollection:[]},e}let u=o.$.type,_=Cd(u);return e.$={env:t,type:_,value:oe(_,{env:t,context:n}),pathCollection:[]},e}function Td({expr:e,env:t,context:n,isInclusive:r}){let i=e.args[0],o=e.args[1],a=O({expr:i,env:t,context:{...n}});if(!a.$)throw d({token:i.token,errorMessage:"Failed to evaluate self for comptime list range index"});t=a.$.env;let s=O({expr:o,env:t,context:{...n}});if(!s.$)throw d({token:o.token,errorMessage:"Failed to evaluate range for comptime list range index"});t=s.$.env;let l=a.$.value,u=s.$.value;if(!u||Ie(u)||!kn(u)){let y=a.$.type,g=Ed(y);return e.$={env:t,type:g,value:oe(g,{env:t,context:n}),pathCollection:[]},e}let _=Ml(u,r);if(!_)throw d({token:o.token,errorMessage:"Expected numeric start/end in Range for comptime list range index"});let{start:c,end:f}=_,p;if(Tr(l)?p=l:l&&Vr(l)&&Tr(l.targetValue[0])&&(p=l.targetValue[0]),p){let y=p.type.childType,g=ki(y);if(c<0||c>p.elements.length)throw d({token:o.token,errorMessage:`ComptimeList range start out of bounds: ${c}. Expected in range [0, ${p.elements.length}].`});if(f<c||f>p.elements.length)throw d({token:o.token,errorMessage:`ComptimeList range end out of bounds: ${f}. Expected in range [${c}, ${p.elements.length}].`});let v=p.elements.slice(c,f),T=Jn(y,v);return e.$={env:t,type:g,value:T,pathCollection:[]},e}let m=a.$.type,h=Ed(m);return e.$={env:t,type:h,value:oe(h,{env:t,context:n}),pathCollection:[]},e}function Ed(e){if(je(e)){let t=e.childType;if(sn(t))return yn(t)}return sn(e)?yn(e):e}function Dl({expr:e,env:t,context:n,isSlice:r,isInclusive:i}){let o=e.args[0],a=e.args[1],s=O({expr:o,env:t,context:{...n}});if(!s.$)throw d({token:o.token,errorMessage:"Failed to evaluate self for comptime range index"});t=s.$.env;let l=O({expr:a,env:t,context:{...n}});if(!l.$)throw d({token:a.token,errorMessage:"Failed to evaluate range index for comptime index"});t=l.$.env;let u=s.$.value,_=l.$.value;if(!_||Ie(_)||!kn(_)){let y=s.$.type,g=$d(y);return e.$={env:t,type:g,value:void 0,pathCollection:[]},e}let c=Ml(_,i);if(!c)throw d({token:a.token,errorMessage:"Expected numeric start/end in Range for comptime range index"});let{start:f,end:p}=c;if(!r&&u&&mr(u)){let y=u,g=y.type.childType,v=Ii(g);if(f<0||f>y.elements.length)throw d({token:a.token,errorMessage:`Slice start index out of bounds: ${f}. Expected index in range [0, ${y.elements.length}].`});if(p<f||p>y.elements.length)throw d({token:a.token,errorMessage:`Slice end index out of bounds: ${p}. Expected index in range [${f}, ${y.elements.length}].`});let T=Oo(v,[y],f,p);return e.$={env:t,type:v,value:T,pathCollection:[]},e}if(r&&u&&lo(u)){let y=u,g=y.type.childType,v=Ii(g),T=y.endIndex-y.startIndex;if(f<0||f>T)throw d({token:a.token,errorMessage:`Slice start index out of bounds: ${f}. Expected index in range [0, ${T}].`});if(p<f||p>T)throw d({token:a.token,errorMessage:`Slice end index out of bounds: ${p}. Expected index in range [${f}, ${T}].`});let $=y.startIndex+f,C=y.startIndex+p,k=Oo(v,y.sourceArray,$,C);return e.$={env:t,type:v,value:k,pathCollection:[]},e}let m=s.$.type,h=$d(m);return e.$={env:t,type:h,value:void 0,pathCollection:[]},e}function $d(e){if(je(e)){let t=e.childType;if(Je(t)){let n=t.childType;return yn(Ii(n))}if($t(t))return e}if(Je(e)){let t=e.childType;return yn(Ii(t))}return $t(e)?yn(e):e}function Ku({expr:e,env:t,context:n,isRange:r,isInclusive:i}){let o=e.args[0],a=e.args[1],s=O({expr:o,env:t,context:{...n}});if(!s.$)throw d({token:o.token,errorMessage:"Failed to evaluate self for comptime string index"});t=s.$.env;let l=O({expr:a,env:t,context:{...n}});if(!l.$)throw d({token:a.token,errorMessage:"Failed to evaluate index for comptime string index"});t=l.$.env;let u=s.$.value,_=s.$.type;if(!u||!tt(u))return e.$={env:t,type:_,value:void 0,pathCollection:[]},e;let c=u.value;if(!r){let y=l.$.value;if(!y||Ie(y)||!yr(y))return e.$={env:t,type:_,value:void 0,pathCollection:[]},e;let g=Lo(y.value);if(g<0||g>=c.length)throw d({token:a.token,errorMessage:`String index out of bounds: ${g}. Expected index in range [0, ${c.length-1}].`});return e.$={env:t,type:_,value:wn(c[g]),pathCollection:[]},e}let f=l.$.value;if(!f||Ie(f)||!kn(f))return e.$={env:t,type:_,value:void 0,pathCollection:[]},e;let p=Ml(f,i);if(!p)throw d({token:a.token,errorMessage:"Expected numeric start/end in Range for comptime string range index"});let{start:m,end:h}=p;if(m<0||m>c.length)throw d({token:a.token,errorMessage:`String slice start index out of bounds: ${m}. Expected index in range [0, ${c.length}].`});if(h<m||h>c.length)throw d({token:a.token,errorMessage:`String slice end index out of bounds: ${h}. Expected index in range [${m}, ${c.length}].`});return e.$={env:t,type:_,value:wn(c.slice(m,h)),pathCollection:[]},e}function bd({expr:e,env:t,context:n}){if(E(e,F.__yo_comptime_array_index))return vd({expr:e,env:t,context:n,isSlice:!1});if(E(e,F.__yo_comptime_slice_index))return vd({expr:e,env:t,context:n,isSlice:!0});if(E(e,F.__yo_comptime_list_index))return Qv({expr:e,env:t,context:n});if(E(e,F.__yo_comptime_list_index_range))return Td({expr:e,env:t,context:n,isInclusive:!1});if(E(e,F.__yo_comptime_list_index_range_inclusive))return Td({expr:e,env:t,context:n,isInclusive:!0});if(E(e,F.__yo_comptime_array_index_range))return Dl({expr:e,env:t,context:n,isSlice:!1,isInclusive:!1});if(E(e,F.__yo_comptime_array_index_range_inclusive))return Dl({expr:e,env:t,context:n,isSlice:!1,isInclusive:!0});if(E(e,F.__yo_comptime_slice_index_range))return Dl({expr:e,env:t,context:n,isSlice:!0,isInclusive:!1});if(E(e,F.__yo_comptime_slice_index_range_inclusive))return Dl({expr:e,env:t,context:n,isSlice:!0,isInclusive:!0});if(E(e,F.__yo_comptime_string_index))return Ku({expr:e,env:t,context:n,isRange:!1,isInclusive:!1});if(E(e,F.__yo_comptime_string_index_range))return Ku({expr:e,env:t,context:n,isRange:!0,isInclusive:!1});if(E(e,F.__yo_comptime_string_index_range_inclusive))return Ku({expr:e,env:t,context:n,isRange:!0,isInclusive:!0});throw d({token:e.token,errorMessage:`Unexpected comptime index builtin: ${I(e)}`})}function kd({strValue:e,argValue:t,token:n,isRange:r,isInclusive:i}){if(Ie(t))return wn("");if(!r){if(!yr(t))throw d({token:n,errorMessage:"Expected comptime_int index for comptime string index"});let l=Lo(t.value);if(l<0||l>=e.length)throw d({token:n,errorMessage:`String index out of bounds: ${l}. Expected index in range [0, ${e.length-1}].`});return wn(e[l])}if(!kn(t))throw d({token:n,errorMessage:"Expected comptime Range value for comptime string range index"});let o=Ml(t,i);if(!o)throw d({token:n,errorMessage:"Expected numeric start/end in Range for comptime string range index"});let{start:a,end:s}=o;if(a<0||a>e.length)throw d({token:n,errorMessage:`String slice start index out of bounds: ${a}. Expected index in range [0, ${e.length}].`});if(s<a||s>e.length)throw d({token:n,errorMessage:`String slice end index out of bounds: ${s}. Expected index in range [${a}, ${e.length}].`});return wn(e.slice(a,s))}function wd({expr:e,env:t,context:n}){Ge(e,F.consume,1);let r=e.args[0],i=O({expr:r,env:t,context:{...n}});if(!i.$)throw d({token:r.token,errorMessage:"Failed to evaluate expression."});return t=i.$.env,t=kr(i,t),e.$={env:t,type:ue.type,value:ue,pathCollection:[]},e}function Oi({functionCalleeExpr:e,functionType:t,functionValue:n,argValues:r,callerEnv:i,calleeEnv:o,context:a}){if(a.isAnalyzingCtfeCapability)return{value:oe(t.return.type,{variableName:"ctfe_analysis_result_"+mt(i.modulePath),env:t.env,context:a}),callerEnv:i,calleeEnv:o};let s=[...r.forallArgs.map(T=>T.value),...r.args.map(T=>T.value),...r.variadicArgs.map(T=>T.value)];if(s.some(T=>!T))throw d({token:(e==null?void 0:e.token)??Fe,errorMessage:"Failed to call the function for compile-time. Some arguments are not compile-time evaluated correctly."});let l=s,u=t.return.type,_=St(u),c=n.funcId,f=n.calledComptimeFunctionCaches,p=_?f.find(T=>T.argValues.length===l.length&&T.argValues.every(($,C)=>{let k=l[C];return W($)&&W(k)?z($.value)&&z(k.value)||Me($.value)||Me(k.value)?$.value.id===k.value.id:z($.value)&&!z(k.value)?!1:le({type:$.value,env:T.env},{type:k.value,env:i},!0):Cn({value:$,env:T.env},{value:k,env:i})})):void 0;if(p)return{callerEnv:i,calleeEnv:o,value:p.value};let m=n.body,h={funcId:c,argValues:l,value:oe(t.return.type,{variableName:t.return.label,recursiveTypeRef:{functionValue:n,argValues:l},env:o,context:a}),env:o,body:_t(m)};n.calledComptimeFunctionCaches.push(h);let y=n.calledComptimeFunctionCaches.length-1,g;try{g=un({expr:h.body,env:o,context:{...a,isEvaluatingFunctionBodyOrAsyncBlock:{kind:"function-body",type:t,value:n,evaluationEnv:o},isEvaluatingLoopBody:void 0,capturedVariables:void 0,isExecuting:!a.isValidatingFunctionDefinition,functionReturnImplConcreteType:[],SelfType:t.SelfType??a.SelfType,forceCompileTimeBindings:!0},variablesToAdd:[]})}catch(T){throw n.calledComptimeFunctionCaches.splice(y,1),T}if(!g.$)throw d({token:n.body.token,errorMessage:"Function body is not evaluated correctly"});let v=g.$.value;if(!v)throw d({token:n.body.token,errorMessage:"Function body is not evaluated correctly. Expected to return a compile-time known value."});if(o=g.$.env,W(v)){let T=v.value;!T.typeName&&n.funcName&&(T.typeName=n.funcName+`(${l.map($=>pt($)).join(", ")})`),(Ae(T)||Be(T)||Bt(T)||Xe(T)||ot(T))&&(T.functionValue||(T.functionValue=n))}return _?n.calledComptimeFunctionCaches[y]={funcId:c,argValues:l,value:v,env:g.$.env,body:g}:n.calledComptimeFunctionCaches.splice(y,1),{value:v,callerEnv:i,calleeEnv:o,comptimeRef:g.$.comptimeRef}}function Xu(e,t,n){var p;let i=ae(t,"Option").find(m=>{var h;return((h=m.value)==null?void 0:h[0])&&ge(m.value[0])&&ne(m.type)});if(!i||!((p=i.value)!=null&&p[0])||!ge(i.value[0]))throw new Error("Cannot find Option type constructor in environment");let o=i.value[0],a=o.type,s=a.parameters[0],l=Te(e),u=lt(a.env),{env:_}=xe({env:u,variable:{name:s.label,token:Fe,type:l.type,isCompileTimeOnly:!0,initializedAtToken:Fe,consumedAtToken:void 0,value:[l],isOwningTheRcValue:!1}}),{value:c,callerEnv:f}=Oi({functionCalleeExpr:void 0,functionType:a,functionValue:o,argValues:{forallArgs:[],args:[{value:l,parameterType:s.type,argType:Pt()}],variadicArgs:[]},callerEnv:t,calleeEnv:_,context:n});if(!W(c))throw new Error("Option type constructor did not return a type value");return{optionType:c.value,env:f}}function Fd({expr:e,env:t,context:n}){Ge(e,[F.__yo_decr_rc[0]],1);let r=e.args[0],i=O({expr:r,env:t,context:{...n}});if(!i.$)throw d({token:r.token,errorMessage:`Failed to evaluate the argument expression for "${F.__yo_decr_rc[0]}":
|
|
11444
11444
|
${I(r)}`});return t=i.$.env,e.$={env:t,type:ue.type,value:ue,pathCollection:[]},e}function Ld({expr:e,env:t,context:n}){Ge(e,[F.__yo_incr_rc[0]]);let r=e.args[0],i=O({expr:r,env:t,context:{...n}});if(!i.$)throw d({token:r.token,errorMessage:`Failed to evaluate the argument expression for "${F.__yo_incr_rc[0]}":
|
|
11445
11445
|
${I(r)}`});return t=i.$.env,e.$={env:t,type:ue.type,value:ue,pathCollection:[]},e}function Id({expr:e,env:t,context:n}){Ge(e,[F.__yo_incr_rc_atomic[0]]);let r=e.args[0],i=O({expr:r,env:t,context:{...n}});if(!i.$)throw d({token:r.token,errorMessage:`Failed to evaluate the argument expression for "${F.__yo_incr_rc_atomic[0]}":
|
|
11446
11446
|
${I(r)}`});return t=i.$.env,e.$={env:t,type:ue.type,value:ue,pathCollection:[]},e}function Ad({expr:e,env:t,context:n}){Ge(e,[F.__yo_decr_rc_atomic[0]]);let r=e.args[0],i=O({expr:r,env:t,context:{...n}});if(!i.$)throw d({token:r.token,errorMessage:`Failed to evaluate the argument expression for "${F.__yo_decr_rc_atomic[0]}":
|
|
@@ -11506,7 +11506,7 @@ ${I(h)}`});g=h.token.value}{let v=O({expr:y,env:t,context:{...n,SelfType:o}});if
|
|
|
11506
11506
|
- Expected: ${M(t.isFn.callType.return.type)}
|
|
11507
11507
|
- Given : ${M(p)}`});if(t.isFn.callType.return.isCompileTimeOnly&&!c.$.value)throw d({token:t.isFn.callType.return.typeExpr.token,errorMessage:"Expected to return a compile-time value, but got runtime value."});l=Ot(l,!0);let m=f&&f.size>0?Ul({capturedVariables:f,env:r}):void 0,h=r,{capturedVariableDupExpressions:y,env:g}=zl({capturedVariablesWithValues:m,env:r,context:i});h=g;let{captureType:v}=Pl({expectedCaptureType:void 0,capturedVariablesWithValues:m,env:h,closureToken:e.token,context:{...i}}),T=_.ownConsumedCaptures?Array.from(_.ownConsumedCaptures):void 0;u.closureInfo={closureType:t,captureType:v,consumedCaptures:T!=null&&T.length?T:void 0},z(n)&&v&&Rl({wrapperType:n,captureType:v,env:h,errorToken:e.token});let $;return z(n)?(n.resolvedConcreteType=v,$={...n,resolvedConcreteType:v}):st(n)?$=n:$=t,e.$={env:h,value:void 0,type:$,pathCollection:f&&f.size>0?ga(f):[],deferredDupExpressions:y&&y.length>0?y:void 0,captureType:v,closureFunctionValue:u},st(n)&&It(e,!0),e}function em({expr:e,comptimeListType:t,argExprs:n,callerEnv:r,context:i}){let o=[],a=r,s=t.childType;for(let u=0;u<n.length;u++){let _=n[u],c=O({expr:_,env:a,context:{...i,expectedType:{type:s,env:a}}});if(!c.$)throw d({token:_.token,errorMessage:`Failed to evaluate ComptimeList element at index ${u}.`});if(Bn(c,i),a=c.$.env,!le({type:s,env:a},{type:c.$.type,env:a}))throw d({token:_.token,errorMessage:`ComptimeList element at index ${u} has incompatible type:
|
|
11508
11508
|
- Expected: ${M(s)}
|
|
11509
|
-
- Given : ${M(c.$.type)}`});if(c.$.value!==void 0)o.push(c.$.value);else throw d({token:_.token,errorMessage:`Expected compile-time known value for ComptimeList element at index ${u}, got ${M(c.$.type)}`})}let l=Jn(t.childType,o);return e.$={env:a,value:l,type:t,pathCollection:[]},e}function rm(e,t,n,r=!1,i){let o=ne(n)?n:void 0,s=pl(e,{detect(u,_,c){var p,m,h;if(u.tag!=="FnCall")return;if(tm(u,t,i,!0)){let y=[];for(let v of u.args)(p=v.$)!=null&&p.type&&y.push(v.$.type);if(y.length===0&&o)for(let v of o.parameters)v.isCompileTimeOnly||y.push(v.type);let g=((m=u.$)==null?void 0:m.type)??(o==null?void 0:o.return.type);if(y.length>0&&g){let v=Ba(_);c.push({index:c.length,expr:u,operationArgTypes:y,operationResultType:g,targetVariableId:v})}}if(r&&!tm(u,t,i)){let y=tT(u,t);if(y){let g=n,v=g.parameters.filter($=>!$.isCompileTimeOnly).map($=>$.type),T=y.viaClosure?g.return.type:(h=u.$)==null?void 0:h.type;if(v.length>0&&T){let $=Ba(_);c.push({index:c.length,expr:u,operationArgTypes:v,operationResultType:T,targetVariableId:$,isTransitiveEffectCall:!0,isTransitiveClosureCall:y.viaClosure})}}}},shouldSkipBody(u){return An(u)}}),l=s.capturedVariables.map(u=>({id:u.id,name:u.name,type:u.type,isOwningTheSameRcValueAs:void 0}));return{effectCallPoints:s.suspensionPoints,capturedVariables:l,hasEffects:s.hasSuspensions,variableIdRemapping:s.variableIdRemapping,effectParameterName:t,effectParameterType:n,effectFieldPath:i}}function tm(e,t,n,r=!1){var l,u;if(e.tag!=="FnCall")return!1;let i=e.func;if(!n||n.length===0){if(i.tag!=="Atom"||i.token.value!==t)return!1;let _=(l=i.$)==null?void 0:l.type;return!(!r&&(!_||!ne(_))||r&&_&&!ne(_))}let o=[],a=i;for(;a.tag==="FnCall"&&E(a,".")&&a.args.length>=2;){let _=a.args[1];if(!_||_.tag!=="Atom")return!1;o.unshift(_.token.value),a=a.args[0]}if(a.tag!=="Atom"||a.token.value!==t||o.length!==n.length)return!1;for(let _=0;_<o.length;_++)if(o[_]!==n[_])return!1;let s=(u=i.$)==null?void 0:u.type;return!(!r&&(!s||!ne(s))||r&&s&&!ne(s))}function tT(e,t){var i,o,a;if(e.tag!=="FnCall")return;let n=(i=e.func.$)==null?void 0:i.type;if(!n)return;if(ne(n)){if(!n.implicitParameters)return;for(let s of n.implicitParameters){if(s.label===t&&(ne(s.type)||Xe(s.type)))return{matched:!0,viaClosure:!1};if(s.isEffectRowSpread&&nm(s,t,(o=e.func.$)==null?void 0:o.env))return{matched:!0,viaClosure:!1}}return}let r=Kn(n);if(r){let s=r.isFn.callType;if(s.implicitParameters)for(let l of s.implicitParameters){if(l.label===t&&(ne(l.type)||Xe(l.type)))return{matched:!0,viaClosure:!0};if(l.isEffectRowSpread&&nm(l,t,(a=e.func.$)==null?void 0:a.env))return{matched:!0,viaClosure:!0}}}}function nm(e,t,n){var o,a;if(!n)return!1;let r=e.type,i;if(z(r)&&r.isEffectsRow){let l=(a=(o=ae(n,e.label).at(-1))==null?void 0:o.value)==null?void 0:a[0];if(l&&W(l)&&Yt(l.value))i=l.value;else{let u=On(n,r);Yt(u)&&(i=u)}}else Yt(r)&&(i=r);if(i){for(let s of i.implicitParameters)if(s.label===t&&(ne(s.type)||Xe(s.type)))return!0}return!1}function om(e,t){for(let n=0;n<e.fields.length;n++){let r=e.fields[n];if(ne(r.type)){let i=t==null?void 0:t.fields[n];if(i&&
|
|
11509
|
+
- Given : ${M(c.$.type)}`});if(c.$.value!==void 0)o.push(c.$.value);else throw d({token:_.token,errorMessage:`Expected compile-time known value for ComptimeList element at index ${u}, got ${M(c.$.type)}`})}let l=Jn(t.childType,o);return e.$={env:a,value:l,type:t,pathCollection:[]},e}function rm(e,t,n,r=!1,i){let o=ne(n)?n:void 0,s=pl(e,{detect(u,_,c){var p,m,h;if(u.tag!=="FnCall")return;if(tm(u,t,i,!0)){let y=[];for(let v of u.args)(p=v.$)!=null&&p.type&&y.push(v.$.type);if(y.length===0&&o)for(let v of o.parameters)v.isCompileTimeOnly||y.push(v.type);let g=((m=u.$)==null?void 0:m.type)??(o==null?void 0:o.return.type);if(y.length>0&&g){let v=Ba(_);c.push({index:c.length,expr:u,operationArgTypes:y,operationResultType:g,targetVariableId:v})}}if(r&&!tm(u,t,i)){let y=tT(u,t);if(y){let g=n,v=g.parameters.filter($=>!$.isCompileTimeOnly).map($=>$.type),T=y.viaClosure?g.return.type:(h=u.$)==null?void 0:h.type;if(v.length>0&&T){let $=Ba(_);c.push({index:c.length,expr:u,operationArgTypes:v,operationResultType:T,targetVariableId:$,isTransitiveEffectCall:!0,isTransitiveClosureCall:y.viaClosure})}}}},shouldSkipBody(u){return An(u)}}),l=s.capturedVariables.map(u=>({id:u.id,name:u.name,type:u.type,isOwningTheSameRcValueAs:void 0}));return{effectCallPoints:s.suspensionPoints,capturedVariables:l,hasEffects:s.hasSuspensions,variableIdRemapping:s.variableIdRemapping,effectParameterName:t,effectParameterType:n,effectFieldPath:i}}function tm(e,t,n,r=!1){var l,u;if(e.tag!=="FnCall")return!1;let i=e.func;if(!n||n.length===0){if(i.tag!=="Atom"||i.token.value!==t)return!1;let _=(l=i.$)==null?void 0:l.type;return!(!r&&(!_||!ne(_))||r&&_&&!ne(_))}let o=[],a=i;for(;a.tag==="FnCall"&&E(a,".")&&a.args.length>=2;){let _=a.args[1];if(!_||_.tag!=="Atom")return!1;o.unshift(_.token.value),a=a.args[0]}if(a.tag!=="Atom"||a.token.value!==t||o.length!==n.length)return!1;for(let _=0;_<o.length;_++)if(o[_]!==n[_])return!1;let s=(u=i.$)==null?void 0:u.type;return!(!r&&(!s||!ne(s))||r&&s&&!ne(s))}function tT(e,t){var i,o,a;if(e.tag!=="FnCall")return;let n=(i=e.func.$)==null?void 0:i.type;if(!n)return;if(ne(n)){if(!n.implicitParameters)return;for(let s of n.implicitParameters){if(s.label===t&&(ne(s.type)||Xe(s.type)))return{matched:!0,viaClosure:!1};if(s.isEffectRowSpread&&nm(s,t,(o=e.func.$)==null?void 0:o.env))return{matched:!0,viaClosure:!1}}return}let r=Kn(n);if(r){let s=r.isFn.callType;if(s.implicitParameters)for(let l of s.implicitParameters){if(l.label===t&&(ne(l.type)||Xe(l.type)))return{matched:!0,viaClosure:!0};if(l.isEffectRowSpread&&nm(l,t,(a=e.func.$)==null?void 0:a.env))return{matched:!0,viaClosure:!0}}}}function nm(e,t,n){var o,a;if(!n)return!1;let r=e.type,i;if(z(r)&&r.isEffectsRow){let l=(a=(o=ae(n,e.label).at(-1))==null?void 0:o.value)==null?void 0:a[0];if(l&&W(l)&&Yt(l.value))i=l.value;else{let u=On(n,r);Yt(u)&&(i=u)}}else Yt(r)&&(i=r);if(i){for(let s of i.implicitParameters)if(s.label===t&&(ne(s.type)||Xe(s.type)))return!0}return!1}function om(e,t){for(let n=0;n<e.fields.length;n++){let r=e.fields[n];if(ne(r.type)){let i=t==null?void 0:t.fields[n];if(i&&ge(i)&&i.isControlFunction)return!0}if(Xe(r.type)){let i=t==null?void 0:t.fields[n];if(om(r.type,i&&wt(i)?i:void 0))return!0}}return!1}function nT({variablesToDrop:e,env:t,context:n}){var o;let r=[],i=t;for(let a of e){let s=Dt(`${F.___drop[0]}(${a.name})`),l=O({expr:s,env:i,context:{...n,expectedType:void 0}});if(r.push(l),(o=l.$)!=null&&o.env)i=l.$.env;else throw d({token:s.token,errorMessage:`Failed to evaluate "___drop" expression for variable "${a.name}":
|
|
11510
11510
|
${I(s)}`})}return{deferredDropExpressions:r.length>0?r:void 0,env:i}}function rT({functionType:e,definitionSiteEnclosingFunctionType:t,parameter:n,argExprs:r,argIndex:i,calleeEnv:o,callerEnv:a,context:s,isMethodCall:l,runtimeArgExprsInOrder:u}){var b,w,A,L,N,x,V,U,R,D,H;let _=r[i],c;if(_&&S(_)&&E(_,":",2)){if(c=_.args[0],_=_.args[1],!K(c))throw d({token:c.token,errorMessage:`Expected identifier for label, got:
|
|
11511
11511
|
${I(c)}`});let B=c.token.value;if(n.label==="")throw d({token:c.token,errorMessage:"Named argument call is not allowed for this parameter (it has no label)."});if(n.label!==B)throw d({token:c.token,errorMessage:`Named argument is not supported. Label is only used for readibility.
|
|
11512
11512
|
Expected ${n?`label "${n.label}"`:"no label"} at the argument position, but got "${B}".`})}let{parameterType:f,calleeEnv:p}=ss({functionType:e,definitionSiteEnclosingFunctionType:t,parameter:n,calleeEnv:o,context:{...s,isEvaluatingFunctionType:!0}});o=p;let m;if(!_||K(_)&&ln(_,P.undefined))if(n.exprs.defaultValueExpr)m=O({expr:_t(n.exprs.defaultValueExpr),env:o,context:{...s,expectedType:{type:f,env:o}}}),(b=m.$)!=null&&b.env&&(o=(w=m.$)==null?void 0:w.env),_&&(_.$=m.$),n.isCompileTimeOnly||u.push(m);else throw d({token:(_==null?void 0:_.token)??Fe,errorMessage:`Expected default value for parameter "${n.label}"`});else if(n.isQuote)if($n(f))m=_t(_),m.$={type:Mn(),value:Hn(_),env:a,pathCollection:[]};else throw d({token:_.token,errorMessage:`Expected "Expr" type for "quote" parameter "${n.label}", got:
|
|
@@ -11517,30 +11517,30 @@ Got: ${pt(m.$.value)}`});let y=m.$.value;if(!n.isCompileTimeOnly&&_o(h,m.$.env
|
|
|
11517
11517
|
${I(m)}`});let g=n.isCompileTimeOnly||s.forceCompileTimeBindings===!0,T=!g&&z(f)&&(((H=(D=wr(o,f))==null?void 0:D.requiredTraits)==null?void 0:H.length)??0)>0?{...f,resolvedConcreteType:h}:h,{env:$}=xe({env:o,variable:{name:n.label,type:T,isCompileTimeOnly:g,value:y?[y]:void 0,token:(_==null?void 0:_.token)??Fe,initializedAtToken:(_==null?void 0:_.token)??Fe,consumedAtToken:void 0,isOwningTheRcValue:n.isOwningTheRcValue}});if(o=$,y&&W(y)&&z(y.value)){let B=y.value,G=wr(a,B);if(G){for(let Q of G.requiredTraits){let Y={...Q,receiverType:B};o=ni({env:o,someType:B,traitType:Y,isNegated:!1})}for(let Q of G.negativeTraits){let Y={...Q,receiverType:B};o=ni({env:o,someType:B,traitType:Y,isNegated:!0})}}}try{let{expectedEnv:B}=Mt({type:f,env:o},{type:h,env:a});o=B}catch(B){throw d({token:(_==null?void 0:_.token)??Fe,errorMessage:`Failed to synthesize types for parameter "${n.label}":
|
|
11518
11518
|
${B.message}`})}let{parameterType:C,calleeEnv:k}=ss({functionType:e,definitionSiteEnclosingFunctionType:t,parameter:n,calleeEnv:o,context:{...s,isEvaluatingFunctionType:!0}});if(o=k,!le({type:C,env:o},{type:h,env:a},i===0&&l))throw d({token:(_==null?void 0:_.token)??Fe,errorMessage:`Type mismatch for parameter "${n.label}":
|
|
11519
11519
|
Expected: ${M(C)}
|
|
11520
|
-
Got: ${M(h)}`});return{calleeEnv:o,callerEnv:a,context:{...s},argValue:y,argType:h,parameterType:C}}function va(e){if(e&&
|
|
11520
|
+
Got: ${M(h)}`});return{calleeEnv:o,callerEnv:a,context:{...s},argValue:y,argType:h,parameterType:C}}function va(e){if(e&&ge(e))return e}function Bl(e){let t=process.env[e];return t==="1"||(t==null?void 0:t.toLowerCase())==="true"}var Wl=Bl("YO_DEBUG_CALL")||Bl("YO_DEBUG_CALL_PROFILE")||Bl("YO_DEBUG_EVAL")||Bl("YO_DEBUG_EVAL_PROFILE"),im=globalThis,Ti=im.__yoCallProfilerState??(im.__yoCallProfilerState={tryCallCount:0,specializeCount:0,cacheHitCount:0,cacheMissCount:0,specializeNames:new Map,tryCallNames:new Map});function to({expr:e,functionValue:t,functionType:n,functionCalleeExpr:r,argExprs:i,callerEnv:o,context:a,isMethodCall:s,skipSpecialization:l,skipCtfeExecution:u}){var we,Se,Ve,de,ee,fe,me,Le,qe,dt,kt,Rt,Ze,Tt,Jt,At,gt,nt,Ft,qt,Et,Lt,nn,te,pe,$e,ie,_e,ye,Re,Ke,Pe;if(Wl){Ti.tryCallCount++;let Z="(unknown)";t&&"funcName"in t&&t.funcName?Z=t.funcName:t&&"funcId"in t?Z=String(t.funcId):r&&(Z=I(r).slice(0,60)),Ti.tryCallNames.set(Z,(Ti.tryCallNames.get(Z)??0)+1),Ti.tryCallCount<=5&&console.log(`[DEBUG tryCall] #${Ti.tryCallCount}: name=${Z}, hasFuncValue=${!!t}, hasFuncCalleeExpr=${!!r}`)}t&&(t.specializedType?n=t.specializedType:n=t.type);let _,c=[],f=[],p=[],m=t==null?void 0:t.definitionSiteEnclosingFunctionType,h=0;i.length>0&&S(i[0])&&E(i[0],P.forall)?(_=i[0],h=1):s&&i.length>1&&S(i[1])&&E(i[1],P.forall)&&(_=i[1],i=[i[0],...i.slice(2)]);let y,g=i.slice(h),v=g.findIndex(Z=>S(Z)&&E(Z,P.using));if(v!==-1){let Z=g.findIndex((X,he)=>he>v&&S(X)&&E(X,P.using));if(Z!==-1)throw d({token:g[Z].token,errorMessage:'Only one "using(...)" is allowed per function call. Combine all implicit arguments into a single using(), e.g.: func(..., using(a, b))'});y=g[v],g=[...g.slice(0,v),...g.slice(v+1)]}let T=n.parameters.length,$=g;if(!n.variadicParameter){if($.length>T){let Z=n.parameters.at(-1);if(!(Z&&Z.isQuote&&so(Z.type)))throw d({token:(r==null?void 0:r.token)??Fe,errorMessage:`Too many arguments for function call:
|
|
11521
11521
|
Expected: ${T} arguments
|
|
11522
11522
|
Got: ${$.length} arguments`})}else if($.length<T&&!n.parameters.slice($.length).every(X=>X.exprs.defaultValueExpr!==void 0))throw d({token:(r==null?void 0:r.token)??Fe,errorMessage:`Too few arguments for function call:
|
|
11523
11523
|
Expected: ${T} arguments
|
|
11524
|
-
Got: ${$.length} arguments`})}let C=g.slice(0,T),k=g.slice(T);i=C,o=lt(o);let b=lt(n.env);if(n.SelfType){let Z=Te(n.SelfType),{env:X}=xe({env:b,variable:{name:"Self",token:Fe,type:Z.type,isCompileTimeOnly:!0,initializedAtToken:Fe,consumedAtToken:void 0,value:[Z],isOwningTheRcValue:!1},allowVariableShadowing:!0});b=X}for(let Z=0;Z<n.forallParameters.length;Z++){let X=n.forallParameters[Z],
|
|
11524
|
+
Got: ${$.length} arguments`})}let C=g.slice(0,T),k=g.slice(T);i=C,o=lt(o);let b=lt(n.env);if(n.SelfType){let Z=Te(n.SelfType),{env:X}=xe({env:b,variable:{name:"Self",token:Fe,type:Z.type,isCompileTimeOnly:!0,initializedAtToken:Fe,consumedAtToken:void 0,value:[Z],isOwningTheRcValue:!1},allowVariableShadowing:!0});b=X}for(let Z=0;Z<n.forallParameters.length;Z++){let X=n.forallParameters[Z],he;if(X.exprs.labelExpr&&X.label){let He=St(X.type)&&X.type.level===1&&S(X.exprs.expr)&&E(X.exprs.expr,"...",1)?Te(To(X.label,b)):oe(X.type,{variableName:X.label,env:b,context:a}),{env:Ee,variable:Oe}=xe({env:b,variable:{name:X.label,type:X.type,isCompileTimeOnly:!0,value:[He],token:X.exprs.labelExpr.token,initializedAtToken:X.exprs.labelExpr.token,consumedAtToken:void 0,isOwningTheRcValue:!1}});b=Ee,he=Oe}if(_){let Ce=_.args[Z],He;if(S(Ce)&&E(Ce,":",2)){if(He=Ce.args[0],Ce=Ce.args[1],!K(He))throw d({token:He.token,errorMessage:`Expected identifier for type parameter label, got:
|
|
11525
11525
|
${I(He)}`});if(X.label!==He.token.value)throw d({token:He.token,errorMessage:`Expected type parameter label "${X.label}", got "${He.token.value}".`})}let Ee;if(K(Ce)&&Ce.token.value==="_")continue;if(!Ce||K(Ce)&&ln(Ce,P.undefined))if(X.exprs.defaultValueExpr){let ze=O({expr:_t(X.exprs.defaultValueExpr),env:b,context:{...a}});if((we=ze.$)!=null&&we.env&&(o=ze.$.env),Ce&&(Ce.$=ze.$),!W((Se=ze.$)==null?void 0:Se.value))throw d({token:(Ce==null?void 0:Ce.token)??(r==null?void 0:r.token)??Fe,errorMessage:Ce?`Expected type for default value, got:
|
|
11526
|
-
${I(Ce)}`:"Expected type for default value."});Ee=(Ve=ze.$)==null?void 0:Ve.value}else throw d({token:(Ce==null?void 0:Ce.token)??(r==null?void 0:r.token)??Fe,errorMessage:"Type parameter does not have default value."});else{let ze=O({expr:Ce,env:o,context:{...a,expectedType:{type:X.type,env:b}}});if((de=ze.$)!=null&&de.env&&(o=ze.$.env),ne(X.type)){if(!
|
|
11526
|
+
${I(Ce)}`:"Expected type for default value."});Ee=(Ve=ze.$)==null?void 0:Ve.value}else throw d({token:(Ce==null?void 0:Ce.token)??(r==null?void 0:r.token)??Fe,errorMessage:"Type parameter does not have default value."});else{let ze=O({expr:Ce,env:o,context:{...a,expectedType:{type:X.type,env:b}}});if((de=ze.$)!=null&&de.env&&(o=ze.$.env),ne(X.type)){if(!ge((ee=ze.$)==null?void 0:ee.value))throw d({token:Ce.token,errorMessage:`Expected type constructor for HKT parameter "${X.label}", got:
|
|
11527
11527
|
${I(Ce)}`});Ee=(fe=ze.$)==null?void 0:fe.value}else{if(!W((me=ze.$)==null?void 0:me.value))throw d({token:Ce.token,errorMessage:`Expected type for argument, got:
|
|
11528
11528
|
${I(Ce)}`});Ee=(Le=ze.$)==null?void 0:Le.value}}He&&(He.$={env:b,type:Ee.type,value:Ee,pathCollection:[]});let Oe=ne(X.type),Ue=X.type;if(!Oe){let{parameterType:ze,calleeEnv:Qe}=ss({parameter:X,calleeEnv:b,definitionSiteEnclosingFunctionType:m,context:{...a,isEvaluatingFunctionType:!0},functionType:n});b=Qe,Ue=ze;let{expectedEnv:Ye,givenEnv:Ne}=Mt({type:Ue,env:b},{type:Ee.type,env:o});if(b=Ye,o=Ne,!le({type:Ue,env:b},{type:Ee.type,env:o}))throw d({token:(Ce==null?void 0:Ce.token)??(r==null?void 0:r.token)??Fe,errorMessage:`Type mismatch for type parameter "${X.label}":
|
|
11529
11529
|
Expected: ${M(Ue)}
|
|
11530
|
-
Got: ${M(Ee.type)}`})}if(X.label)if(
|
|
11531
|
-
${I(X)}`});o=
|
|
11530
|
+
Got: ${M(Ee.type)}`})}if(X.label)if(he)b=bt(b,he,{...he,value:[Ee]});else{let ze=(Ce==null?void 0:Ce.token)??(r==null?void 0:r.token)??Fe,{env:Qe}=xe({env:b,variable:{name:X.label,type:Ee.type,isCompileTimeOnly:!0,value:[Ee],token:ze,initializedAtToken:ze,consumedAtToken:void 0,isOwningTheRcValue:!1}});b=Qe}c.push({value:Ee,argType:Ee.type,parameterType:Ue})}}if(a.expectedType&&!_&&n.forallParameters.length>0&&!n.return.isUnquote)try{let{returnType:Z,calleeEnv:X}=Io({functionType:n,calleeEnv:b,context:{...a,isEvaluatingFunctionType:!0},functionCalleeExpr:r}),{expectedEnv:he}=Mt({type:Z,env:X},{type:a.expectedType.type,env:a.expectedType.env});b=he}catch{}if(y&&n.implicitParameters.length>0&&n.implicitParameters.some(X=>X.isEffectRowSpread)){let he=n.implicitParameters.filter(He=>!He.isEffectRowSpread).length,Ce=y.args.slice(he);if(Ce.length>0){let He=[];for(let Ue of Ce){if(!K(Ue))throw d({token:Ue.token,errorMessage:`Expected identifier for using() argument in effect row spread, got ${I(Ue)}`});let ze=Ue.token.value,Ye=ae(o,ze).at(-1);if(!Ye)throw d({token:Ue.token,errorMessage:`Variable "${ze}" not found for using() argument in effect row spread.`});Ue.$={env:o,type:Ye.type,value:(qe=Ye.value)==null?void 0:qe[0],variableName:ze,pathCollection:[]},He.push({label:ze,type:Ye.type,isCompileTimeOnly:!0,isImplicit:!0,isOwningTheRcValue:!1,isQuote:!1,exprs:{expr:Ue,labelExpr:Ue,typeExpr:void 0,defaultValueExpr:void 0}})}let Ee=Si(He),Oe=Te(Ee);for(let Ue of n.implicitParameters){if(!Ue.isEffectRowSpread)continue;let ze=Ue.label,Ye=ae(b,ze).at(-1);Ye&&(b=bt(b,Ye,{...Ye,value:[Oe]})),z(Ue.type)&&Ue.type.isEffectsRow&&(Ue.type.resolvedConcreteType=Ee)}}}if(n.ioBuiltin==="io_async"&&(a={...a,isInsideIoAsyncCall:!0}),(dt=n.whereClauseExprs)!=null&&dt.length&&n.whereClauseExprs.every(X=>{if(!S(X)||!E(X,"<:"))return!1;let he=X.args[0];if(!he)return!1;let Ce=he.tag==="Atom"?he.token.value:void 0;return Ce?ae(b,Ce).length>0:!1})){let X=n.whereClauseExprs.map(Ce=>_t(Ce));b=Ri({constraintExprs:X,env:b,context:{...a,isEvaluatingFunctionType:!0}}).env}let w=n.parameters.length;for(let Z=0;Z<w;Z++){let X=n.parameters[Z],{calleeEnv:he,callerEnv:Ce,context:He,argValue:Ee,argType:Oe,parameterType:Ue}=rT({functionType:n,definitionSiteEnclosingFunctionType:m,parameter:X,argExprs:i,argIndex:Z,callerEnv:o,calleeEnv:b,context:a,isMethodCall:s,runtimeArgExprsInOrder:p});b=he,o=Ce,a=He,f.push({value:Ee,parameterType:Ue,argType:Oe})}if(!_&&n.forallParameters.length>0){for(let Z of n.forallParameters)if(Z.label){let he=ae(b,Z.label).at(-1);if((kt=he==null?void 0:he.value)!=null&&kt[0]&&W(he.value[0])){let Ce=he.value[0];if(z(Ce.value)&&Ce.value.resolvedConcreteType&&(!Ce.value.requiredTraits||Ce.value.requiredTraits.length===0)){let He=Te(Ce.value.resolvedConcreteType);b=bt(b,he,{...he,value:[He]})}}}}if(!_&&n.forallParameters.length>0){for(let Z of n.forallParameters)if(Z.label){let he=ae(b,Z.label).at(-1);(Rt=he==null?void 0:he.value)!=null&&Rt[0]&&W(he.value[0])&&c.push({value:he.value[0],argType:he.value[0].type,parameterType:Z.type})}}if((Ze=n.whereClauseExprs)!=null&&Ze.length){let Z=n.whereClauseExprs.map(he=>_t(he));b=Ri({constraintExprs:Z,env:b,context:{...a,isEvaluatingFunctionType:!0}}).env}let{returnType:A,calleeEnv:L}=Io({functionType:n,calleeEnv:b,context:{...a,isEvaluatingFunctionType:!0},functionCalleeExpr:r});if(b=L,a.expectedType&&!n.return.isUnquote){let{expectedEnv:Z}=Mt({type:A,env:b},{type:a.expectedType.type,env:a.expectedType.env});b=Z;let X=Io({functionType:n,calleeEnv:b,context:{...a,isEvaluatingFunctionType:!0},functionCalleeExpr:r});A=X.returnType,b=X.calleeEnv,le({type:a.expectedType.type,env:a.expectedType.env},{type:A,env:b})&&!Me(a.expectedType.type)&&(A=a.expectedType.type)}let N=[];if(n.variadicParameter){for(let Z=0;Z<k.length;Z++){let X=k[Z],he;if(n.variadicParameter.isQuote)he=_t(X),he.$={type:Mn(),value:Hn(X),env:o,pathCollection:[]},N.push({value:he.$.value,argType:he.$.type});else{if(he=O({expr:X,env:o,context:{...a}}),!((Tt=he.$)!=null&&Tt.env))throw d({token:X.token,errorMessage:`Failed to evaluate the expression:
|
|
11531
|
+
${I(X)}`});o=he.$.env,N.push({value:he.$.value,argType:he.$.type}),n.variadicParameter.isCompileTimeOnly||p.push(X)}}if(n.variadicParameter.label!=="..."){if(n.variadicParameter.isQuote){let Z=Jn(Mn(),N.map(he=>he.value)),{env:X}=xe({env:b,variable:{name:n.variadicParameter.label,type:Z.type,isCompileTimeOnly:n.variadicParameter.isCompileTimeOnly,value:[Z],token:n.variadicParameter.exprs.expr.token,initializedAtToken:n.variadicParameter.exprs.expr.token,consumedAtToken:void 0,isOwningTheRcValue:!1}});b=X}else if(n.variadicParameter.isCompileTimeOnly&&sn(n.variadicParameter.type)){let Z=n.variadicParameter.type.childType,X=Jn(Z,N.map(Ce=>Ce.value)),{env:he}=xe({env:b,variable:{name:n.variadicParameter.label,type:X.type,isCompileTimeOnly:!0,value:[X],token:n.variadicParameter.exprs.expr.token,initializedAtToken:n.variadicParameter.exprs.expr.token,consumedAtToken:void 0,isOwningTheRcValue:!1}});b=he}}}let x=[],V=[];if(n.implicitParameters.length>0)for(let Z=0;Z<n.implicitParameters.length;Z++){let X=n.implicitParameters[Z],he=!1;if(X.isEffectRowSpread){let Ee=[],Ue=(At=(Jt=ae(b,X.label).at(-1))==null?void 0:Jt.value)==null?void 0:At[0],ze;if(Ue&&W(Ue)&&Yt(Ue.value))ze=Ue.value;else if(z(X.type)&&X.type.isEffectsRow){let Qe=On(b,X.type);Yt(Qe)&&(ze=Qe)}else Yt(X.type)&&(ze=X.type);if(!ze&&z(X.type)&&X.type.isEffectsRow){let Qe=cr(o,et=>et.isImplicit===!0&&et.isCompileTimeOnly===!0&&(ne(et.type)||Xe(et.type))),Ye=new Set(n.implicitParameters.filter(et=>!et.isEffectRowSpread).map(et=>et.label)),Ne=Qe.filter(et=>!Ye.has(et.name));if(Ne.length>0){for(let yt of Ne){let Vt=(gt=yt.value)==null?void 0:gt[0];if(Vt){V.push({value:Vt,parameterType:yt.type,argType:yt.type});let{env:xt}=xe({env:b,variable:{name:yt.name,type:yt.type,isCompileTimeOnly:!0,isImplicit:!0,isFromEffectSpread:!0,value:[Vt],token:Fe,initializedAtToken:Fe,consumedAtToken:void 0,isOwningTheRcValue:!1},allowVariableShadowing:!0});b=xt}}let et=Si(Ne.map(yt=>({label:yt.name,type:yt.type,isCompileTimeOnly:!0,isQuote:!1,isOwningTheRcValue:!1,isImplicit:!0,exprs:{expr:void 0,labelExpr:void 0,typeExpr:void 0}}))),ke=Te(et),ft=ae(b,X.label).at(-1);ft&&(b=bt(b,ft,{...ft,value:[ke],type:et})),he=!0;continue}}Ee=(ze==null?void 0:ze.implicitParameters)??[];for(let Qe of Ee){let Ye=Qe.type,et=cr(o,ke=>ke.isImplicit===!0&&ke.isCompileTimeOnly===!0&&ke.name===Qe.label&&le({type:Ye,env:b},{type:ke.type,env:o})).at(-1);if((nt=et==null?void 0:et.value)!=null&&nt[0]){let ke=et.value[0];V.push({value:ke,parameterType:Ye,argType:et.type});let{env:rt}=xe({env:b,variable:{name:Qe.label,type:Ye,isCompileTimeOnly:!0,isImplicit:!0,isFromEffectSpread:!0,value:[ke],token:Fe,initializedAtToken:Fe,consumedAtToken:void 0,isOwningTheRcValue:!1},allowVariableShadowing:!0});b=rt}else{let rt=cr(o,Vt=>Vt.isImplicit===!0&&Vt.isCompileTimeOnly===!0&&le({type:Ye,env:b},{type:Vt.type,env:o})).at(-1);if(!((Ft=rt==null?void 0:rt.value)!=null&&Ft[0]))throw d({token:(r==null?void 0:r.token)??(e==null?void 0:e.token)??Fe,errorMessage:`No "given" variable found for effect row parameter "${Qe.label}" of type ${M(Ye)} (expanded from effect row ...(${X.label})).
|
|
11532
11532
|
Please ensure a given variable of matching type is in scope.`});let ft=rt.value[0];V.push({value:ft,parameterType:Ye,argType:rt.type});let{env:yt}=xe({env:b,variable:{name:Qe.label,type:Ye,isCompileTimeOnly:!0,isImplicit:!0,isFromEffectSpread:!0,value:[ft],token:Fe,initializedAtToken:Fe,consumedAtToken:void 0,isOwningTheRcValue:!1},allowVariableShadowing:!0});b=yt}}continue}let{parameterType:Ce,calleeEnv:He}=ss({parameter:X,calleeEnv:b,definitionSiteEnclosingFunctionType:m,context:{...a,isEvaluatingFunctionType:!0},functionType:n});if(b=He,y){let Ee=y.args[Z],Oe=Ee&&K(Ee)&&ln(Ee,P.undefined);if(Ee&&!Oe){let Ue=O({expr:Ee,env:o,context:{...a}});if(!Ue.$)throw d({token:Ee.token,errorMessage:`Failed to evaluate using() argument: ${I(Ee)}`});o=Ue.$.env;let ze=Ue.$.value,Qe=Ue.$.type;if(!ze)throw d({token:Ee.token,errorMessage:`Expected compile-time value for using() argument, got runtime value: ${I(Ee)}`});if(!le({type:Ce,env:b},{type:Qe,env:o}))throw d({token:Ee.token,errorMessage:`Incompatible type for implicit parameter "${X.label}":
|
|
11533
11533
|
Expected: ${M(Ce)}
|
|
11534
|
-
Got: ${M(Qe)}`});V.push({value:ze,parameterType:Ce,argType:Qe});let Ye=ae(b,X.label);if(Ye.length>0){let Ne=Ye[Ye.length-1];b=bt(b,Ne,{...Ne,type:Ce,isImplicit:!0,value:[ze]})}else{let{env:Ne}=xe({env:b,variable:{name:X.label,type:Ce,isCompileTimeOnly:!0,isImplicit:!0,value:[ze],token:((qt=X.exprs.labelExpr)==null?void 0:qt.token)??Fe,initializedAtToken:((Et=X.exprs.labelExpr)==null?void 0:Et.token)??Fe,consumedAtToken:void 0,isOwningTheRcValue:!1},allowVariableShadowing:!0});b=Ne}
|
|
11534
|
+
Got: ${M(Qe)}`});V.push({value:ze,parameterType:Ce,argType:Qe});let Ye=ae(b,X.label);if(Ye.length>0){let Ne=Ye[Ye.length-1];b=bt(b,Ne,{...Ne,type:Ce,isImplicit:!0,value:[ze]})}else{let{env:Ne}=xe({env:b,variable:{name:X.label,type:Ce,isCompileTimeOnly:!0,isImplicit:!0,value:[ze],token:((qt=X.exprs.labelExpr)==null?void 0:qt.token)??Fe,initializedAtToken:((Et=X.exprs.labelExpr)==null?void 0:Et.token)??Fe,consumedAtToken:void 0,isOwningTheRcValue:!1},allowVariableShadowing:!0});b=Ne}he=!0}}if(!he){let Ee=cr(o,Ne=>Ne.isImplicit===!0&&Ne.isCompileTimeOnly===!0&&le({type:Ce,env:b},{type:Ne.type,env:o}));if(Ee.length===0)throw d({token:(r==null?void 0:r.token)??(e==null?void 0:e.token)??Fe,errorMessage:`No "given" variable found for implicit parameter "${X.label}" of type ${M(Ce)}.
|
|
11535
11535
|
Please declare a given variable with a compatible type, e.g.:
|
|
11536
11536
|
given(${X.label}) := <value>;
|
|
11537
11537
|
Or pass it explicitly:
|
|
11538
11538
|
${(t==null?void 0:t.funcName)??"func"}(..., using(<value>))`});if(Ee[Ee.length-1].isFromEffectSpread&&!(()=>{if(!r||!K(r))return!1;let et=r.token.value,ke=a.isEvaluatingFunctionBodyOrAsyncBlock;return!ke||ke.kind!=="function-body"?!1:ke.type.parameters.some(ft=>ft.label===et)})())throw d({token:(r==null?void 0:r.token)??(e==null?void 0:e.token)??Fe,errorMessage:`Effect "${X.label}" of type ${M(Ce)} is available through an effect row spread but not explicitly declared in the function's using clause.
|
|
11539
11539
|
Add it explicitly:
|
|
11540
11540
|
using(${X.label} : ${M(Ce)}, ...(E))`});let Ue=Ee;if(Ue.length>1){let Ne=ja(o,et=>et.isImplicit===!0&&et.isCompileTimeOnly===!0&&le({type:Ce,env:b},{type:et.type,env:o}));if(Ne>=0){let ke=o.frames[Ne].variables.filter(rt=>rt.isImplicit===!0&&rt.isCompileTimeOnly===!0&&le({type:Ce,env:b},{type:rt.type,env:o}));ke.length>0&&(Ue=ke)}}if(Ue.length>1)throw d({token:(r==null?void 0:r.token)??(e==null?void 0:e.token)??Fe,errorMessage:`Ambiguous implicit parameter "${X.label}": found ${Ue.length} "given" variables with compatible type ${M(Ce)} in the same scope.
|
|
11541
|
-
Please use explicit using() to disambiguate.`});let ze=Ue[Ue.length-1],Qe=(Lt=ze.value)==null?void 0:Lt[0];if(!Qe)throw d({token:(r==null?void 0:r.token)??(e==null?void 0:e.token)??Fe,errorMessage:`The "given" variable "${ze.name}" has no compile-time value.`});V.push({value:Qe,parameterType:Ce,argType:ze.type});let{env:Ye}=xe({env:b,variable:{name:X.label,type:Ce,isCompileTimeOnly:!0,isImplicit:!0,value:[Qe],token:((nn=X.exprs.labelExpr)==null?void 0:nn.token)??Fe,initializedAtToken:((te=X.exprs.labelExpr)==null?void 0:te.token)??Fe,consumedAtToken:void 0,isOwningTheRcValue:!1},allowVariableShadowing:!0});b=Ye}}let U={args:f,forallArgs:c,implicitArgs:V,variadicArgs:N},R;if(n.return.isCompileTimeOnly)if(u)R=oe(A,{variableName:n.return.label,env:n.env,context:a});else if(he(t)){let{value:Z,callerEnv:X,calleeEnv:ge}=Oi({functionCalleeExpr:r,functionType:n,functionValue:t,argValues:U,callerEnv:o,calleeEnv:b,context:{...a}});R=Z,A=Z.type,o=X,b=ge}else{let Z=St(A)&&A.level===0,X=`${n.id}_return_sometype`;if(Z)if((pe=a.expectedType)!=null&&pe.type)R=Te(a.expectedType.type);else if(a.isEvaluatingFunctionType){let ge=Er(A,n.return.label,{id:X,env:b,context:a});ge.functionApplication=e;let Ce=On(b,ge);R=Te(Ce)}else throw d({token:(e==null?void 0:e.token)??(r==null?void 0:r.token)??Fe,errorMessage:"Cannot infer comptime return type. Please provide the expected type."});else R=oe(A,{variableName:n.return.label,env:n.env,context:a})}sT({returnType:A,env:b,expr:e,context:a});let D,H=(($e=a.isEvaluatingFunctionBodyOrAsyncBlock)==null?void 0:$e.kind)==="function-body"&&a.isEvaluatingFunctionBodyOrAsyncBlock.value&&he(a.isEvaluatingFunctionBodyOrAsyncBlock.value)&&t&&he(t)&&a.isEvaluatingFunctionBodyOrAsyncBlock.value.funcId===t.funcId,B=(ie=U.implicitArgs)==null?void 0:ie.some(Z=>Ie(Z.value)),G=B&&!((_e=U.implicitArgs)!=null&&_e.some(Z=>Ie(Z.value)&&!Xe(Z.parameterType))),Q=U.args.some(Z=>Z.argType&&z(Z.argType)),Y=G&&Q,J=(()=>{if(!B||!n.implicitParameters.some(Ce=>Ce.isEffectRowSpread))return!1;let X=0;for(let Ce of n.implicitParameters)Ce.isEffectRowSpread||X++;let ge=U.implicitArgs??[];for(let Ce=0;Ce<X&&Ce<ge.length;Ce++)if(Ie(ge[Ce].value))return!1;return!0})(),ve=Rr(n)&&!li(n)&&n.implicitParameters.some(Z=>Xe(Z.type)?Z.type.fields.some(X=>ne(X.type)&&X.type.forallParameters.length===0):!!Z.isEffectRowSpread);if(!l&&!ve&&t&&he(t)&&!t.isControlFunction&&Rr(n)&&!H&&(!B||Y||J)){if(D=oT({originalFunction:t,argValues:U,calleeEnv:b,callerEnv:o,context:a}),D&&z(A)){let Z=(Re=(ye=D.body)==null?void 0:ye.$)==null?void 0:Re.type;Z&&!z(Z)&&(A=Z,D.specializedType&&(D.specializedType={...D.specializedType,return:{...D.specializedType.return,type:Z}}))}if(D){let Z=new Set,X=0;for(let ge=0;ge<n.parameters.length;ge++)if(!n.parameters[ge].isCompileTimeOnly){let He=U.args[ge],Ee=He==null?void 0:He.value;Ee&&he(Ee)&&Ee.type.implicitParameters.some(Oe=>ne(Oe.type)||Xe(Oe.type))&&Z.add(X),X++}if(Z.size>0)for(let ge=p.length-1;ge>=0;ge--)Z.has(ge)&&p.splice(ge,1)}}if(H&&!D&&a.currentlySpecializingFunction&&t&&he(t)){let Z=a.currentlySpecializingFunction;D={...t,funcId:Z.specializedFuncId,specializedType:{...n,return:{...n.return,type:Z.specializedReturnType}}},z(A)&&(A=Z.specializedReturnType)}if(!l&&t&&he(t)&&t.isControlFunction&&n.forallParameters.length>0&&!D&&(D=aT({originalFunction:t,argValues:U,calleeEnv:b,callerEnv:o,context:a}),D&&z(A))){let Z=(Pe=(Ke=D.body)==null?void 0:Ke.$)==null?void 0:Pe.type;Z&&!z(Z)&&(A=Z,D.specializedType&&(D.specializedType={...D.specializedType,return:{...D.specializedType.return,type:Z}}))}let re=ia(o),ce;if(re.length>0){let Z=nT({variablesToDrop:re,env:o,context:a});ce=Z.deferredDropExpressions,o=Z.env}return{returnType:A,calleeEnv:b,callerEnv:o,pathCollection:x,argValues:U,returnValue:R,specializedFunctionValue:D,runtimeArgExprsInOrder:p,deferredDropExpressions:ce}}function Gl(e){if(W(e)){let t=e.value;if(t.id)return`${pt(e)}_id${t.id}`}return he(e)?`fn_${e.funcId}`:pt(e)}function iT({functionType:e,argValues:t,calleeEnv:n,runtimeParameters:r}){let i=[];return e.forallParameters.forEach((o,a)=>{var s,l;if(a<t.forallArgs.length){let u=t.forallArgs[a];i.push(be(Gl(u.value)))}else{let u=o.label,_=ae(n,u);_.length>0&&((l=(s=_[_.length-1])==null?void 0:s.value)!=null&&l[0])?i.push(be(Gl(_[_.length-1].value[0]))):i.push("unknown")}}),e.parameters.forEach((o,a)=>{if(o.isCompileTimeOnly&&a<t.args.length){let s=t.args[a];s?i.push(be(Gl(s.value))):i.push("unknown")}}),t.implicitArgs&&t.implicitArgs.forEach(o=>{i.push(be(Gl(o.value)))}),r.forEach((o,a)=>{let s=o.type;(s.id||Me(s))&&i.push(`rtparam${a}_${be(M(s))}_id${s.id}`)}),i.join("_")}function oT({originalFunction:e,argValues:t,calleeEnv:n,callerEnv:r,context:i}){var x,V,U,R,D,H,B,G,Q,Y,J,se,ve;if(Wl){Ti.specializeCount++;let re=e.funcName??e.funcId;Ti.specializeNames.set(re,(Ti.specializeNames.get(re)??0)+1)}let o=e.specializedType??e.type,a=[],s=[];t.forallArgs&&a.push(...t.forallArgs.map(re=>re.value)),t.implicitArgs&&a.push(...t.implicitArgs.map(re=>re.value)),o.parameters.forEach((re,ce)=>{let we=t.args[ce];if(re.isCompileTimeOnly)we.value&&a.push(we.value);else if(we.value&&he(we.value)&&we.value.type.implicitParameters.some(Ve=>ne(Ve.type)||Xe(Ve.type)))we.value&&a.push(we.value);else{let de=z(we.argType)&&we.argType.resolvedConcreteType&&!at(we.argType)?we.argType.resolvedConcreteType:we.argType;s.push({...re,type:de})}});let l=s.map(re=>re.type),u=e.specializedFunctionCaches.find(re=>re.compileTimeArgValues.length===a.length&&re.compileTimeArgValues.every((Se,Ve)=>{let de=a[Ve];return Cn({value:Se,env:re.env},{value:de,env:r})})?re.runtimeParameterTypes.length===l.length&&re.runtimeParameterTypes.every((Se,Ve)=>{let de=l[Ve];return le({type:Se,env:re.env},{type:de,env:r},!0)}):!1);if(u)return Wl&&Ti.cacheHitCount++,u.specializedFunction;Wl&&Ti.cacheMissCount++;let _=n;for(let re of r.frames)for(let ce of re.variables){if(!ce.isCompileTimeOnly||ae(_,ce.name).length>0)continue;let{env:Se}=xe({env:_,variable:{...ce},allowVariableShadowing:!0});_=Se}for(let re of s){let ce=ae(_,re.label);if(ce.length>0){let we=ce[ce.length-1],Se={...we,value:void 0};_=bt(_,we,Se)}}let c=_t(e.body),{returnType:f,calleeEnv:p}=Io({functionType:o,calleeEnv:_,context:{...i,isEvaluatingFunctionType:!0},functionCalleeExpr:void 0});_=p;let m=i.enclosingFunctionReturnType,h=((x=t.implicitArgs)==null?void 0:x.some(re=>he(re.value)&&re.value.isControlFunction||wt(re.value)&&om(re.value.type,re.value)))??!1,y=iT({functionType:o,argValues:t,calleeEnv:n,runtimeParameters:s}),g=`${e.funcId}_${y}`,v=i.currentlySpecializingFunction;i.currentlySpecializingFunction={originalFuncId:e.funcId,specializedFuncId:g,specializedReturnType:f,originalFunction:e};let T=un({expr:c,env:_,context:{...i,expectedType:{type:f,env:_},isEvaluatingFunctionBodyOrAsyncBlock:{kind:"function-body",type:{...o,return:{...o.return,type:f}},value:e,evaluationEnv:_},isEvaluatingLoopBody:void 0,capturedVariables:void 0,functionReturnImplConcreteType:[],hasControlFunctionImplicitParams:h,...m?{enclosingFunctionReturnType:m}:{}},variablesToAdd:[],isEvaluatingFunctionBodyBeginBlock:!0});if(i.currentlySpecializingFunction=v,!T.$)throw d({token:e.body.token,errorMessage:"Failed to evaluate function body for specialization."});let $=[],C=0;for(let re=0;re<o.implicitParameters.length;re++){let ce=o.implicitParameters[re];if(ne(ce.type)){let we=(V=t.implicitArgs)==null?void 0:V[C],Se=we&&he(we.value)?we.value:void 0;Se!=null&&Se.isControlFunction&&$.push({handlerArgIndex:C,label:ce.label,type:ce.type,fromSpread:!1}),C+=1}else if(ce.isEffectRowSpread){let we=ce.type;if(z(we)){let Ve=(R=(U=ae(_,ce.label).at(-1))==null?void 0:U.value)==null?void 0:R[0];if(Ve&&W(Ve)&&Yt(Ve.value))we=Ve.value;else{let de=On(_,we);de&&(we=de)}}if(Yt(we)){for(let Se=0;Se<we.implicitParameters.length;Se++){let Ve=we.implicitParameters[Se];if(ne(Ve.type)){let de=(D=t.implicitArgs)==null?void 0:D[C+Se],ee=de&&he(de.value)?de.value:void 0;ee!=null&&ee.isControlFunction&&$.push({handlerArgIndex:C+Se,label:Ve.label,type:Ve.type,fromSpread:!0})}else if(Xe(Ve.type)){let de=(H=t.implicitArgs)==null?void 0:H[C+Se],ee=de&&wt(de.value)?de.value:void 0,fe=[],me=(Le,qe,dt)=>{for(let kt=0;kt<Le.fields.length;kt++){let Rt=Le.fields[kt];if(ne(Rt.type)){let Ze=dt==null?void 0:dt.fields[kt];if(Ze&&he(Ze)&&Ze.isControlFunction){let Tt=Ze.specializedType??Rt.type;fe.push({path:[...qe,Rt.label],type:Tt})}}else if(Xe(Rt.type)){let Ze=dt==null?void 0:dt.fields[kt];me(Rt.type,[...qe,Rt.label],Ze&&wt(Ze)?Ze:void 0)}}};me(Ve.type,[],ee);for(let Le of fe)$.push({handlerArgIndex:C+Se,label:Ve.label,type:Le.type,fromSpread:!0,effectFieldPath:Le.path})}}C+=we.implicitParameters.length}else C+=1}else if(Xe(ce.type)){let we=[],Se=(B=t.implicitArgs)==null?void 0:B[C],Ve=(de,ee,fe)=>{for(let me=0;me<de.fields.length;me++){let Le=de.fields[me];if(ne(Le.type)){let qe=fe==null?void 0:fe.fields[me];if(qe&&he(qe)&&qe.isControlFunction){let dt=qe.specializedType??Le.type;we.push({path:[...ee,Le.label],type:dt})}}else if(Xe(Le.type)){let qe=fe==null?void 0:fe.fields[me];Ve(Le.type,[...ee,Le.label],qe&&wt(qe)?qe:void 0)}}};Ve(ce.type,[],Se&&wt(Se.value)?Se.value:void 0);for(let de of we)$.push({handlerArgIndex:C,label:ce.label,type:de.type,fromSpread:!1,effectFieldPath:de.path});C+=1}else C+=1}let k=[];for(let re of $){let ce=rm(T,re.label,re.type,!0,re.effectFieldPath);if(ce.hasEffects){let we=(G=t.implicitArgs)==null?void 0:G[re.handlerArgIndex],Se,Ve=re.effectFieldPath;if(we&&he(we.value))Se=we.value;else if(we&&wt(we.value)&&Ve&&Ve.length>0){let de=we.value;for(let ee of Ve){if(!wt(de)){de=void 0;break}let fe=de.type.fields.findIndex(me=>me.label===ee);if(fe<0||!de.fields[fe]){de=void 0;break}de=de.fields[fe]}de&&he(de)&&(Se=de)}if(Se){let de=Se,ee=re.type,fe=!de.body.$;if(!fe&&de.isControlFunction&&S(de.body)&&de.body.args.length>0&&!((Q=de.body.args[0])!=null&&Q.$)&&(fe=!0),fe&&ne(ee)&&ee.forallParameters.length>0&&ce.effectCallPoints.length>0){let me=new Map,Le=ee.return.type,qe=ce.effectCallPoints[0].operationResultType;if(z(Le)&&me.set(Le.name,qe),me.size===0&&ee.forallParameters.length===1){let Jt=ee.forallParameters[0];me.set(Jt.label,qe)}let dt=_t(de.body),kt=((Y=de.body.$)==null?void 0:Y.env)??_;kt=lt(kt);for(let Jt of ee.forallParameters){let At=me.get(Jt.label);At&&(kt=xe({env:kt,variable:{name:Jt.label,type:Jt.type,isCompileTimeOnly:!0,value:[Te(At)],token:Fe,initializedAtToken:Fe,consumedAtToken:void 0,isOwningTheRcValue:!1},allowVariableShadowing:!0}).env)}let Rt=de.specializedType??de.type,Ze=((J=de.definitionSiteEnclosingFunctionType)==null?void 0:J.return.type)??xr(),Tt={...i,expectedType:void 0,enclosingFunctionReturnType:Ze,isEvaluatingFunctionBodyOrAsyncBlock:{kind:"function-body",type:Rt,value:de,evaluationEnv:kt}};try{let Jt=no({expr:dt,env:kt,context:Tt}),At=Rt.parameters.map(qt=>{if(qt.isCompileTimeOnly)return qt;if(z(qt.type)){let Et=me.get(qt.type.name);if(Et)return{...qt,type:Et}}return qt}),gt=Rt.return.type;if(z(gt)){let qt=me.get(gt.name);qt&&(gt=qt)}let nt={...Rt,parameters:At,return:{...Rt.return,type:gt}},Ft={...de,body:Jt,specializedType:nt};ce.handlerValue=Ft,ce.effectParameterType=nt;for(let qt of ce.effectCallPoints)qt.isTransitiveEffectCall&&(qt.operationArgTypes=qt.operationArgTypes.map(Et=>z(Et)?me.get(Et.name)??Et:Et))}catch(Jt){if(S(de.body)&&de.body.args.length>0&&!((se=de.body.args[0])!=null&&se.$))throw Jt;ce.handlerValue=de}}else ce.handlerValue=de}else we&&(ce.handlerValue=we.value);k.push({analysis:ce,ctlParam:re})}}if(k.length===1)T.$.effectAnalysis=k[0].analysis;else if(k.length>1){let re=[],ce=new Map,we=new Map,Se=[];for(let ee=0;ee<k.length;ee++){let{analysis:fe}=k[ee];Se.push({effectParameterName:fe.effectParameterName,effectParameterType:fe.effectParameterType,effectFieldPath:fe.effectFieldPath,handlerValue:fe.handlerValue,operationArgTypes:fe.effectCallPoints.length>0?fe.effectCallPoints[0].operationArgTypes:[],operationResultType:fe.effectCallPoints.length>0?fe.effectCallPoints[0].operationResultType:{tag:"unit"}});for(let me of fe.effectCallPoints)re.push({...me,effectIndex:ee});for(let me of fe.capturedVariables)ce.has(me.id)||ce.set(me.id,me);for(let[me,Le]of fe.variableIdRemapping)we.set(me,Le)}if(S(T)&&E(T,P.begin)){let ee=T.args,fe=new Map;for(let Le=0;Le<ee.length;Le++)fe.set(ee[Le],Le);let me=Le=>{for(let qe=0;qe<ee.length;qe++)if(t_(ee[qe],Le.expr))return qe;return 999};re.sort((Le,qe)=>me(Le)-me(qe))}for(let ee=0;ee<re.length;ee++)re[ee].index=ee;let Ve=k[0].analysis,de={effectCallPoints:re,capturedVariables:Array.from(ce.values()),hasEffects:!0,variableIdRemapping:we,effectParameterName:Ve.effectParameterName,effectParameterType:Ve.effectParameterType,effectFieldPath:Ve.effectFieldPath,handlerValue:Ve.handlerValue,effectHandlerInfos:Se};T.$.effectAnalysis=de}let b=y,w=[];for(let re of o.implicitParameters)if(re.isEffectRowSpread){let ce=re.type;if(z(ce)){if(t.forallArgs){for(let we=0;we<o.forallParameters.length;we++)if(o.forallParameters[we].label===ce.name&&we<t.forallArgs.length){let Ve=t.forallArgs[we].value;W(Ve)&&Yt(Ve.value)&&(ce=Ve.value);break}}if(z(ce)&&ce.resolvedConcreteType&&Yt(ce.resolvedConcreteType)&&(ce=ce.resolvedConcreteType),z(ce)){let we=ae(_,ce.name);if(we.length>0){let Ve=(ve=we[we.length-1].value)==null?void 0:ve[0];Ve&&W(Ve)&&Yt(Ve.value)&&(ce=Ve.value)}}}Yt(ce)&&w.push(...ce.implicitParameters)}else Xe(re.type)&&w.push(re);let A=Ai({forallParameters:[],parameters:s,implicitParameters:w.length>0?w:void 0,variadicParameter:void 0,return_:{...o.return,type:f},parametersFrame:_.frames[_.frames.length-1],env:o.env,SelfType:o.SelfType}),L={...e,specializedType:A,body:T,isControlFunction:e.isControlFunction||ei(T),funcId:`${e.funcId}_${b}`,funcName:`${e.funcName}_${b}`,calledComptimeFunctionCaches:[],specializedFunctionCaches:[]},N={funcId:e.funcId,compileTimeArgValues:a,runtimeParameterTypes:l,specializedFunction:L,env:T.$.env};return e.specializedFunctionCaches=[...e.specializedFunctionCaches,N],L}function aT({originalFunction:e,calleeEnv:t,callerEnv:n,context:r}){var g,v,T;let i=e.type,o=((g=r.isEvaluatingFunctionBodyOrAsyncBlock)==null?void 0:g.kind)==="function-body"?r.isEvaluatingFunctionBodyOrAsyncBlock.type.return.type:i.return.type,a=((v=e.definitionSiteEnclosingFunctionType)==null?void 0:v.return.type)??xr(),s=be(M(o)),l=e.specializedFunctionCaches.find($=>$.specializedFunction.funcId===`${e.funcId}_ctl_${s}`);if(l)return l.specializedFunction;let u=lt(t);for(let $ of n.frames)for(let C of $.variables){if(!C.isCompileTimeOnly||ae(u,C.name).length>0)continue;let{env:b}=xe({env:u,variable:{...C},allowVariableShadowing:!0});u=b}for(let $ of i.forallParameters){let C=o,{env:k}=xe({env:u,variable:{name:$.label,type:$.type,isCompileTimeOnly:!0,value:[Te(C)],token:Fe,initializedAtToken:Fe,consumedAtToken:void 0,isOwningTheRcValue:!1},allowVariableShadowing:!0});u=k}let _=_t(e.body),c={...r,expectedType:void 0,enclosingFunctionReturnType:a,isEvaluatingFunctionBodyOrAsyncBlock:{kind:"function-body",type:i,value:e,evaluationEnv:u},functionReturnImplConcreteType:[]},f=no({expr:_,env:u,context:c}),p={...e,body:f,isControlFunction:e.isControlFunction||ei(f),funcId:`${e.funcId}_ctl_${s}`,funcName:`${e.funcName??e.funcId}_ctl_${s}`,calledComptimeFunctionCaches:[],specializedFunctionCaches:[]},m=new Set(i.forallParameters.map($=>$.type)),h=$=>z($)&&m.has($)?o:$,y=Ai({forallParameters:[],parameters:i.parameters.map($=>({...$,type:h($.type)})),implicitParameters:i.implicitParameters.length>0?i.implicitParameters:void 0,variadicParameter:void 0,return_:{...i.return,type:h(i.return.type)},parametersFrame:u.frames[u.frames.length-1],env:i.env,SelfType:i.SelfType});return p.specializedType=y,e.specializedFunctionCaches=[...e.specializedFunctionCaches,{funcId:e.funcId,compileTimeArgValues:[],runtimeParameterTypes:[],specializedFunction:p,env:((T=f.$)==null?void 0:T.env)??u}],p}function sT({returnType:e,expr:t,env:n,context:r}){var o;if(r.isEvaluatingFunctionType||r.expectedType)return;let i=ou(e);for(let a of i){if(at(a)||zn(a)||a.resolvedConcreteType||a.requiredTraits&&a.requiredTraits.length>0)continue;if(!ae(n,a.name).length){let l=cr(n,()=>!0),u=!1;for(let _ of l)if(W((o=_.value)==null?void 0:o[0])){let c=_.value[0].value,f=ou(c);for(let p of f)if(p.name===a.name){u=!0;break}if(u)break}if(u)continue;throw d({token:(t==null?void 0:t.token)??Fe,errorMessage:`Failed to infer the function call return type.
|
|
11542
|
-
Please consider providing the expected type.`})}}}function t_(e,t){if(e===t)return!0;if(e.tag==="FnCall"){if(t_(e.func,t))return!0;for(let n of e.args)if(t_(n,t))return!0}return!1}function n_({concreteType:e,env:t}){let n=[];if(e.trait)for(let i of e.trait.fields){if(i.label===""&&i.assignedValue&&tn(i.assignedValue)){let o=i.assignedValue,a=o.type,s=a.fields.findIndex(l=>l.label==="index"&&ne(l.type));if(s>=0){let l=a.fields[s];if(ne(l.type)){let u=o.fields[s],_=l.type;
|
|
11543
|
-
${I(a)}`});i=c.$.env;let f=c.$.type,p=ql({concreteType:t,argType:f,env:i});if(!p)throw d({token:e.func.token,errorMessage:`Type "${M(t)}" does not implement Index(${M(f)}).`});let m=p.type,h=m.return.type;if(!je(h))throw d({token:e.func.token,errorMessage:`Index method must return a pointer type, got: ${M(h)}`});let y=h.childType,g=oe(y,{env:i,context:o});return Ie(g)&&(g.isRuntimeOnly=!0),{value:g,type:y,ptrType:h,indexMethodType:m,indexMethodValue:p.value,callerEnv:i}}function am({concreteType:e,argExpr:t,callerEnv:n,context:r}){try{let i=O({expr:t,env:n,context:{...r,expectedType:void 0}});if(!i.$)return;let o=ql({concreteType:e,argType:i.$.type,env:i.$.env});return o?{fnType:o.type,value:o.value}:void 0}catch{return}}function lT({concreteType:e,argType:t,env:n}){let r=n_({concreteType:e,env:n});for(let i of r){let o=i.type;if(o.parameters.length!==2)continue;let a=o.parameters[0],s=o.parameters[1];if(je(a.type)&&le({type:s.type,env:n},{type:t,env:n})&&je(o.return.type)&&a.isCompileTimeOnly&&s.isCompileTimeOnly)return i}}function uT({expr:e,argExpr:t,selfValue:n,valueType:r,callerEnv:i,context:o}){let a=O({expr:t,env:i,context:{...o,expectedType:void 0}});if(!a.$||!a.$.value)return;let s=a.$.type,l=a.$.value;i=a.$.env;let u=lT({concreteType:r,argType:s,env:i});if(!u||!
|
|
11541
|
+
Please use explicit using() to disambiguate.`});let ze=Ue[Ue.length-1],Qe=(Lt=ze.value)==null?void 0:Lt[0];if(!Qe)throw d({token:(r==null?void 0:r.token)??(e==null?void 0:e.token)??Fe,errorMessage:`The "given" variable "${ze.name}" has no compile-time value.`});V.push({value:Qe,parameterType:Ce,argType:ze.type});let{env:Ye}=xe({env:b,variable:{name:X.label,type:Ce,isCompileTimeOnly:!0,isImplicit:!0,value:[Qe],token:((nn=X.exprs.labelExpr)==null?void 0:nn.token)??Fe,initializedAtToken:((te=X.exprs.labelExpr)==null?void 0:te.token)??Fe,consumedAtToken:void 0,isOwningTheRcValue:!1},allowVariableShadowing:!0});b=Ye}}let U={args:f,forallArgs:c,implicitArgs:V,variadicArgs:N},R;if(n.return.isCompileTimeOnly)if(u)R=oe(A,{variableName:n.return.label,env:n.env,context:a});else if(ge(t)){let{value:Z,callerEnv:X,calleeEnv:he}=Oi({functionCalleeExpr:r,functionType:n,functionValue:t,argValues:U,callerEnv:o,calleeEnv:b,context:{...a}});R=Z,A=Z.type,o=X,b=he}else{let Z=St(A)&&A.level===0,X=`${n.id}_return_sometype`;if(Z)if((pe=a.expectedType)!=null&&pe.type)R=Te(a.expectedType.type);else if(a.isEvaluatingFunctionType){let he=Er(A,n.return.label,{id:X,env:b,context:a});he.functionApplication=e;let Ce=On(b,he);R=Te(Ce)}else throw d({token:(e==null?void 0:e.token)??(r==null?void 0:r.token)??Fe,errorMessage:"Cannot infer comptime return type. Please provide the expected type."});else R=oe(A,{variableName:n.return.label,env:n.env,context:a})}sT({returnType:A,env:b,expr:e,context:a});let D,H=(($e=a.isEvaluatingFunctionBodyOrAsyncBlock)==null?void 0:$e.kind)==="function-body"&&a.isEvaluatingFunctionBodyOrAsyncBlock.value&&ge(a.isEvaluatingFunctionBodyOrAsyncBlock.value)&&t&&ge(t)&&a.isEvaluatingFunctionBodyOrAsyncBlock.value.funcId===t.funcId,B=(ie=U.implicitArgs)==null?void 0:ie.some(Z=>Ie(Z.value)),G=B&&!((_e=U.implicitArgs)!=null&&_e.some(Z=>Ie(Z.value)&&!Xe(Z.parameterType))),Q=U.args.some(Z=>Z.argType&&z(Z.argType)),Y=G&&Q,J=(()=>{if(!B||!n.implicitParameters.some(Ce=>Ce.isEffectRowSpread))return!1;let X=0;for(let Ce of n.implicitParameters)Ce.isEffectRowSpread||X++;let he=U.implicitArgs??[];for(let Ce=0;Ce<X&&Ce<he.length;Ce++)if(Ie(he[Ce].value))return!1;return!0})(),ve=Rr(n)&&!li(n)&&n.implicitParameters.some(Z=>Xe(Z.type)?Z.type.fields.some(X=>ne(X.type)&&X.type.forallParameters.length===0):!!Z.isEffectRowSpread);if(!l&&!ve&&t&&ge(t)&&!t.isControlFunction&&Rr(n)&&!H&&(!B||Y||J)){if(D=oT({originalFunction:t,argValues:U,calleeEnv:b,callerEnv:o,context:a}),D&&z(A)){let Z=(Re=(ye=D.body)==null?void 0:ye.$)==null?void 0:Re.type;Z&&!z(Z)&&(A=Z,D.specializedType&&(D.specializedType={...D.specializedType,return:{...D.specializedType.return,type:Z}}))}if(D){let Z=new Set,X=0;for(let he=0;he<n.parameters.length;he++)if(!n.parameters[he].isCompileTimeOnly){let He=U.args[he],Ee=He==null?void 0:He.value;Ee&&ge(Ee)&&Ee.type.implicitParameters.some(Oe=>ne(Oe.type)||Xe(Oe.type))&&Z.add(X),X++}if(Z.size>0)for(let he=p.length-1;he>=0;he--)Z.has(he)&&p.splice(he,1)}}if(H&&!D&&a.currentlySpecializingFunction&&t&&ge(t)){let Z=a.currentlySpecializingFunction;D={...t,funcId:Z.specializedFuncId,specializedType:{...n,return:{...n.return,type:Z.specializedReturnType}}},z(A)&&(A=Z.specializedReturnType)}if(!l&&t&&ge(t)&&t.isControlFunction&&n.forallParameters.length>0&&!D&&(D=aT({originalFunction:t,argValues:U,calleeEnv:b,callerEnv:o,context:a}),D&&z(A))){let Z=(Pe=(Ke=D.body)==null?void 0:Ke.$)==null?void 0:Pe.type;Z&&!z(Z)&&(A=Z,D.specializedType&&(D.specializedType={...D.specializedType,return:{...D.specializedType.return,type:Z}}))}let re=ia(o),ce;if(re.length>0){let Z=nT({variablesToDrop:re,env:o,context:a});ce=Z.deferredDropExpressions,o=Z.env}return{returnType:A,calleeEnv:b,callerEnv:o,pathCollection:x,argValues:U,returnValue:R,specializedFunctionValue:D,runtimeArgExprsInOrder:p,deferredDropExpressions:ce}}function Gl(e){if(W(e)){let t=e.value;if(t.id)return`${pt(e)}_id${t.id}`}return ge(e)?`fn_${e.funcId}`:pt(e)}function iT({functionType:e,argValues:t,calleeEnv:n,runtimeParameters:r}){let i=[];return e.forallParameters.forEach((o,a)=>{var s,l;if(a<t.forallArgs.length){let u=t.forallArgs[a];i.push(be(Gl(u.value)))}else{let u=o.label,_=ae(n,u);_.length>0&&((l=(s=_[_.length-1])==null?void 0:s.value)!=null&&l[0])?i.push(be(Gl(_[_.length-1].value[0]))):i.push("unknown")}}),e.parameters.forEach((o,a)=>{if(o.isCompileTimeOnly&&a<t.args.length){let s=t.args[a];s?i.push(be(Gl(s.value))):i.push("unknown")}}),t.implicitArgs&&t.implicitArgs.forEach(o=>{i.push(be(Gl(o.value)))}),r.forEach((o,a)=>{let s=o.type;(s.id||Me(s))&&i.push(`rtparam${a}_${be(M(s))}_id${s.id}`)}),i.join("_")}function oT({originalFunction:e,argValues:t,calleeEnv:n,callerEnv:r,context:i}){var x,V,U,R,D,H,B,G,Q,Y,J,se,ve;if(Wl){Ti.specializeCount++;let re=e.funcName??e.funcId;Ti.specializeNames.set(re,(Ti.specializeNames.get(re)??0)+1)}let o=e.specializedType??e.type,a=[],s=[];t.forallArgs&&a.push(...t.forallArgs.map(re=>re.value)),t.implicitArgs&&a.push(...t.implicitArgs.map(re=>re.value)),o.parameters.forEach((re,ce)=>{let we=t.args[ce];if(re.isCompileTimeOnly)we.value&&a.push(we.value);else if(we.value&&ge(we.value)&&we.value.type.implicitParameters.some(Ve=>ne(Ve.type)||Xe(Ve.type)))we.value&&a.push(we.value);else{let de=z(we.argType)&&we.argType.resolvedConcreteType&&!at(we.argType)?we.argType.resolvedConcreteType:we.argType;s.push({...re,type:de})}});let l=s.map(re=>re.type),u=e.specializedFunctionCaches.find(re=>re.compileTimeArgValues.length===a.length&&re.compileTimeArgValues.every((Se,Ve)=>{let de=a[Ve];return Cn({value:Se,env:re.env},{value:de,env:r})})?re.runtimeParameterTypes.length===l.length&&re.runtimeParameterTypes.every((Se,Ve)=>{let de=l[Ve];return le({type:Se,env:re.env},{type:de,env:r},!0)}):!1);if(u)return Wl&&Ti.cacheHitCount++,u.specializedFunction;Wl&&Ti.cacheMissCount++;let _=n;for(let re of r.frames)for(let ce of re.variables){if(!ce.isCompileTimeOnly||ae(_,ce.name).length>0)continue;let{env:Se}=xe({env:_,variable:{...ce},allowVariableShadowing:!0});_=Se}for(let re of s){let ce=ae(_,re.label);if(ce.length>0){let we=ce[ce.length-1],Se={...we,value:void 0};_=bt(_,we,Se)}}let c=_t(e.body),{returnType:f,calleeEnv:p}=Io({functionType:o,calleeEnv:_,context:{...i,isEvaluatingFunctionType:!0},functionCalleeExpr:void 0});_=p;let m=i.enclosingFunctionReturnType,h=((x=t.implicitArgs)==null?void 0:x.some(re=>ge(re.value)&&re.value.isControlFunction||wt(re.value)&&om(re.value.type,re.value)))??!1,y=iT({functionType:o,argValues:t,calleeEnv:n,runtimeParameters:s}),g=`${e.funcId}_${y}`,v=i.currentlySpecializingFunction;i.currentlySpecializingFunction={originalFuncId:e.funcId,specializedFuncId:g,specializedReturnType:f,originalFunction:e};let T=un({expr:c,env:_,context:{...i,expectedType:{type:f,env:_},isEvaluatingFunctionBodyOrAsyncBlock:{kind:"function-body",type:{...o,return:{...o.return,type:f}},value:e,evaluationEnv:_},isEvaluatingLoopBody:void 0,capturedVariables:void 0,functionReturnImplConcreteType:[],hasControlFunctionImplicitParams:h,...m?{enclosingFunctionReturnType:m}:{}},variablesToAdd:[],isEvaluatingFunctionBodyBeginBlock:!0});if(i.currentlySpecializingFunction=v,!T.$)throw d({token:e.body.token,errorMessage:"Failed to evaluate function body for specialization."});let $=[],C=0;for(let re=0;re<o.implicitParameters.length;re++){let ce=o.implicitParameters[re];if(ne(ce.type)){let we=(V=t.implicitArgs)==null?void 0:V[C],Se=we&&ge(we.value)?we.value:void 0;Se!=null&&Se.isControlFunction&&$.push({handlerArgIndex:C,label:ce.label,type:ce.type,fromSpread:!1}),C+=1}else if(ce.isEffectRowSpread){let we=ce.type;if(z(we)){let Ve=(R=(U=ae(_,ce.label).at(-1))==null?void 0:U.value)==null?void 0:R[0];if(Ve&&W(Ve)&&Yt(Ve.value))we=Ve.value;else{let de=On(_,we);de&&(we=de)}}if(Yt(we)){for(let Se=0;Se<we.implicitParameters.length;Se++){let Ve=we.implicitParameters[Se];if(ne(Ve.type)){let de=(D=t.implicitArgs)==null?void 0:D[C+Se],ee=de&&ge(de.value)?de.value:void 0;ee!=null&&ee.isControlFunction&&$.push({handlerArgIndex:C+Se,label:Ve.label,type:Ve.type,fromSpread:!0})}else if(Xe(Ve.type)){let de=(H=t.implicitArgs)==null?void 0:H[C+Se],ee=de&&wt(de.value)?de.value:void 0,fe=[],me=(Le,qe,dt)=>{for(let kt=0;kt<Le.fields.length;kt++){let Rt=Le.fields[kt];if(ne(Rt.type)){let Ze=dt==null?void 0:dt.fields[kt];if(Ze&&ge(Ze)&&Ze.isControlFunction){let Tt=Ze.specializedType??Rt.type;fe.push({path:[...qe,Rt.label],type:Tt})}}else if(Xe(Rt.type)){let Ze=dt==null?void 0:dt.fields[kt];me(Rt.type,[...qe,Rt.label],Ze&&wt(Ze)?Ze:void 0)}}};me(Ve.type,[],ee);for(let Le of fe)$.push({handlerArgIndex:C+Se,label:Ve.label,type:Le.type,fromSpread:!0,effectFieldPath:Le.path})}}C+=we.implicitParameters.length}else C+=1}else if(Xe(ce.type)){let we=[],Se=(B=t.implicitArgs)==null?void 0:B[C],Ve=(de,ee,fe)=>{for(let me=0;me<de.fields.length;me++){let Le=de.fields[me];if(ne(Le.type)){let qe=fe==null?void 0:fe.fields[me];if(qe&&ge(qe)&&qe.isControlFunction){let dt=qe.specializedType??Le.type;we.push({path:[...ee,Le.label],type:dt})}}else if(Xe(Le.type)){let qe=fe==null?void 0:fe.fields[me];Ve(Le.type,[...ee,Le.label],qe&&wt(qe)?qe:void 0)}}};Ve(ce.type,[],Se&&wt(Se.value)?Se.value:void 0);for(let de of we)$.push({handlerArgIndex:C,label:ce.label,type:de.type,fromSpread:!1,effectFieldPath:de.path});C+=1}else C+=1}let k=[];for(let re of $){let ce=rm(T,re.label,re.type,!0,re.effectFieldPath);if(ce.hasEffects){let we=(G=t.implicitArgs)==null?void 0:G[re.handlerArgIndex],Se,Ve=re.effectFieldPath;if(we&&ge(we.value))Se=we.value;else if(we&&wt(we.value)&&Ve&&Ve.length>0){let de=we.value;for(let ee of Ve){if(!wt(de)){de=void 0;break}let fe=de.type.fields.findIndex(me=>me.label===ee);if(fe<0||!de.fields[fe]){de=void 0;break}de=de.fields[fe]}de&&ge(de)&&(Se=de)}if(Se){let de=Se,ee=re.type,fe=!de.body.$;if(!fe&&de.isControlFunction&&S(de.body)&&de.body.args.length>0&&!((Q=de.body.args[0])!=null&&Q.$)&&(fe=!0),fe&&ne(ee)&&ee.forallParameters.length>0&&ce.effectCallPoints.length>0){let me=new Map,Le=ee.return.type,qe=ce.effectCallPoints[0].operationResultType;if(z(Le)&&me.set(Le.name,qe),me.size===0&&ee.forallParameters.length===1){let Jt=ee.forallParameters[0];me.set(Jt.label,qe)}let dt=_t(de.body),kt=((Y=de.body.$)==null?void 0:Y.env)??_;kt=lt(kt);for(let Jt of ee.forallParameters){let At=me.get(Jt.label);At&&(kt=xe({env:kt,variable:{name:Jt.label,type:Jt.type,isCompileTimeOnly:!0,value:[Te(At)],token:Fe,initializedAtToken:Fe,consumedAtToken:void 0,isOwningTheRcValue:!1},allowVariableShadowing:!0}).env)}let Rt=de.specializedType??de.type,Ze=((J=de.definitionSiteEnclosingFunctionType)==null?void 0:J.return.type)??xr(),Tt={...i,expectedType:void 0,enclosingFunctionReturnType:Ze,isEvaluatingFunctionBodyOrAsyncBlock:{kind:"function-body",type:Rt,value:de,evaluationEnv:kt}};try{let Jt=no({expr:dt,env:kt,context:Tt}),At=Rt.parameters.map(qt=>{if(qt.isCompileTimeOnly)return qt;if(z(qt.type)){let Et=me.get(qt.type.name);if(Et)return{...qt,type:Et}}return qt}),gt=Rt.return.type;if(z(gt)){let qt=me.get(gt.name);qt&&(gt=qt)}let nt={...Rt,parameters:At,return:{...Rt.return,type:gt}},Ft={...de,body:Jt,specializedType:nt};ce.handlerValue=Ft,ce.effectParameterType=nt;for(let qt of ce.effectCallPoints)qt.isTransitiveEffectCall&&(qt.operationArgTypes=qt.operationArgTypes.map(Et=>z(Et)?me.get(Et.name)??Et:Et))}catch(Jt){if(S(de.body)&&de.body.args.length>0&&!((se=de.body.args[0])!=null&&se.$))throw Jt;ce.handlerValue=de}}else ce.handlerValue=de}else we&&(ce.handlerValue=we.value);k.push({analysis:ce,ctlParam:re})}}if(k.length===1)T.$.effectAnalysis=k[0].analysis;else if(k.length>1){let re=[],ce=new Map,we=new Map,Se=[];for(let ee=0;ee<k.length;ee++){let{analysis:fe}=k[ee];Se.push({effectParameterName:fe.effectParameterName,effectParameterType:fe.effectParameterType,effectFieldPath:fe.effectFieldPath,handlerValue:fe.handlerValue,operationArgTypes:fe.effectCallPoints.length>0?fe.effectCallPoints[0].operationArgTypes:[],operationResultType:fe.effectCallPoints.length>0?fe.effectCallPoints[0].operationResultType:{tag:"unit"}});for(let me of fe.effectCallPoints)re.push({...me,effectIndex:ee});for(let me of fe.capturedVariables)ce.has(me.id)||ce.set(me.id,me);for(let[me,Le]of fe.variableIdRemapping)we.set(me,Le)}if(S(T)&&E(T,P.begin)){let ee=T.args,fe=new Map;for(let Le=0;Le<ee.length;Le++)fe.set(ee[Le],Le);let me=Le=>{for(let qe=0;qe<ee.length;qe++)if(t_(ee[qe],Le.expr))return qe;return 999};re.sort((Le,qe)=>me(Le)-me(qe))}for(let ee=0;ee<re.length;ee++)re[ee].index=ee;let Ve=k[0].analysis,de={effectCallPoints:re,capturedVariables:Array.from(ce.values()),hasEffects:!0,variableIdRemapping:we,effectParameterName:Ve.effectParameterName,effectParameterType:Ve.effectParameterType,effectFieldPath:Ve.effectFieldPath,handlerValue:Ve.handlerValue,effectHandlerInfos:Se};T.$.effectAnalysis=de}let b=y,w=[];for(let re of o.implicitParameters)if(re.isEffectRowSpread){let ce=re.type;if(z(ce)){if(t.forallArgs){for(let we=0;we<o.forallParameters.length;we++)if(o.forallParameters[we].label===ce.name&&we<t.forallArgs.length){let Ve=t.forallArgs[we].value;W(Ve)&&Yt(Ve.value)&&(ce=Ve.value);break}}if(z(ce)&&ce.resolvedConcreteType&&Yt(ce.resolvedConcreteType)&&(ce=ce.resolvedConcreteType),z(ce)){let we=ae(_,ce.name);if(we.length>0){let Ve=(ve=we[we.length-1].value)==null?void 0:ve[0];Ve&&W(Ve)&&Yt(Ve.value)&&(ce=Ve.value)}}}Yt(ce)&&w.push(...ce.implicitParameters)}else Xe(re.type)&&w.push(re);let A=Ai({forallParameters:[],parameters:s,implicitParameters:w.length>0?w:void 0,variadicParameter:void 0,return_:{...o.return,type:f},parametersFrame:_.frames[_.frames.length-1],env:o.env,SelfType:o.SelfType}),L={...e,specializedType:A,body:T,isControlFunction:e.isControlFunction||ei(T),funcId:`${e.funcId}_${b}`,funcName:`${e.funcName}_${b}`,calledComptimeFunctionCaches:[],specializedFunctionCaches:[]},N={funcId:e.funcId,compileTimeArgValues:a,runtimeParameterTypes:l,specializedFunction:L,env:T.$.env};return e.specializedFunctionCaches=[...e.specializedFunctionCaches,N],L}function aT({originalFunction:e,calleeEnv:t,callerEnv:n,context:r}){var g,v,T;let i=e.type,o=((g=r.isEvaluatingFunctionBodyOrAsyncBlock)==null?void 0:g.kind)==="function-body"?r.isEvaluatingFunctionBodyOrAsyncBlock.type.return.type:i.return.type,a=((v=e.definitionSiteEnclosingFunctionType)==null?void 0:v.return.type)??xr(),s=be(M(o)),l=e.specializedFunctionCaches.find($=>$.specializedFunction.funcId===`${e.funcId}_ctl_${s}`);if(l)return l.specializedFunction;let u=lt(t);for(let $ of n.frames)for(let C of $.variables){if(!C.isCompileTimeOnly||ae(u,C.name).length>0)continue;let{env:b}=xe({env:u,variable:{...C},allowVariableShadowing:!0});u=b}for(let $ of i.forallParameters){let C=o,{env:k}=xe({env:u,variable:{name:$.label,type:$.type,isCompileTimeOnly:!0,value:[Te(C)],token:Fe,initializedAtToken:Fe,consumedAtToken:void 0,isOwningTheRcValue:!1},allowVariableShadowing:!0});u=k}let _=_t(e.body),c={...r,expectedType:void 0,enclosingFunctionReturnType:a,isEvaluatingFunctionBodyOrAsyncBlock:{kind:"function-body",type:i,value:e,evaluationEnv:u},functionReturnImplConcreteType:[]},f=no({expr:_,env:u,context:c}),p={...e,body:f,isControlFunction:e.isControlFunction||ei(f),funcId:`${e.funcId}_ctl_${s}`,funcName:`${e.funcName??e.funcId}_ctl_${s}`,calledComptimeFunctionCaches:[],specializedFunctionCaches:[]},m=new Set(i.forallParameters.map($=>$.type)),h=$=>z($)&&m.has($)?o:$,y=Ai({forallParameters:[],parameters:i.parameters.map($=>({...$,type:h($.type)})),implicitParameters:i.implicitParameters.length>0?i.implicitParameters:void 0,variadicParameter:void 0,return_:{...i.return,type:h(i.return.type)},parametersFrame:u.frames[u.frames.length-1],env:i.env,SelfType:i.SelfType});return p.specializedType=y,e.specializedFunctionCaches=[...e.specializedFunctionCaches,{funcId:e.funcId,compileTimeArgValues:[],runtimeParameterTypes:[],specializedFunction:p,env:((T=f.$)==null?void 0:T.env)??u}],p}function sT({returnType:e,expr:t,env:n,context:r}){var o;if(r.isEvaluatingFunctionType||r.expectedType)return;let i=ou(e);for(let a of i){if(at(a)||zn(a)||a.resolvedConcreteType||a.requiredTraits&&a.requiredTraits.length>0)continue;if(!ae(n,a.name).length){let l=cr(n,()=>!0),u=!1;for(let _ of l)if(W((o=_.value)==null?void 0:o[0])){let c=_.value[0].value,f=ou(c);for(let p of f)if(p.name===a.name){u=!0;break}if(u)break}if(u)continue;throw d({token:(t==null?void 0:t.token)??Fe,errorMessage:`Failed to infer the function call return type.
|
|
11542
|
+
Please consider providing the expected type.`})}}}function t_(e,t){if(e===t)return!0;if(e.tag==="FnCall"){if(t_(e.func,t))return!0;for(let n of e.args)if(t_(n,t))return!0}return!1}function n_({concreteType:e,env:t}){let n=[];if(e.trait)for(let i of e.trait.fields){if(i.label===""&&i.assignedValue&&tn(i.assignedValue)){let o=i.assignedValue,a=o.type,s=a.fields.findIndex(l=>l.label==="index"&&ne(l.type));if(s>=0){let l=a.fields[s];if(ne(l.type)){let u=o.fields[s],_=l.type;ge(u)&&u.specializedType&&(_=u.specializedType),n.push({type:_,value:u})}}}i.label==="index"&&ne(i.type)&&n.push({type:i.type,value:i.assignedValue})}let r=Dr({concreteType:e,methodName:"index",env:t});return n.push(...r),n}function ql({concreteType:e,argType:t,env:n}){let r=n_({concreteType:e,env:n});if(r.length!==0)for(let i of r){let o=i.type;if(o.parameters.length!==2)continue;let a=o.parameters[0],s=o.parameters[1];if(je(a.type)&&le({type:s.type,env:n},{type:t,env:n})&&je(o.return.type))return i}}function um({expr:e,valueType:t,selfValue:n,argExprs:r,callerEnv:i,context:o}){if(r.length!==1)throw d({token:e.func.token,errorMessage:`Index trait expects exactly 1 argument, got ${r.length}.`});let a=r[0],s=n&&mr(n)?n:void 0,l=n&&lo(n)?n:void 0,u=n&&tt(n)?n.value:void 0;if(!!(s||l||u!==void 0)&&(s||l)&&(Je(t)||$t(t))){let v=cT({argExpr:a,arrayValue:s,sliceValue:l,arrayType:t,env:i,context:o});if(v){let T=am({concreteType:t,argExpr:a,callerEnv:i,context:o});return T&&(v.indexMethodType=T.fnType,v.indexMethodValue=T.value),v}}if(u!==void 0){let v=dT({argExpr:a,strValue:u,env:i,context:o}),T=am({concreteType:t,argExpr:a,callerEnv:i,context:o});return T&&(v.indexMethodType=T.fnType,v.indexMethodValue=T.value),v}if(n&&!Ie(n)&&!s&&!l&&u===void 0){let v=uT({expr:e,argExpr:a,selfValue:n,valueType:t,callerEnv:i,context:o});if(v)return v}let c=O({expr:a,env:i,context:{...o,expectedType:void 0}});if(!c.$)throw d({token:a.token,errorMessage:`Failed to evaluate index argument:
|
|
11543
|
+
${I(a)}`});i=c.$.env;let f=c.$.type,p=ql({concreteType:t,argType:f,env:i});if(!p)throw d({token:e.func.token,errorMessage:`Type "${M(t)}" does not implement Index(${M(f)}).`});let m=p.type,h=m.return.type;if(!je(h))throw d({token:e.func.token,errorMessage:`Index method must return a pointer type, got: ${M(h)}`});let y=h.childType,g=oe(y,{env:i,context:o});return Ie(g)&&(g.isRuntimeOnly=!0),{value:g,type:y,ptrType:h,indexMethodType:m,indexMethodValue:p.value,callerEnv:i}}function am({concreteType:e,argExpr:t,callerEnv:n,context:r}){try{let i=O({expr:t,env:n,context:{...r,expectedType:void 0}});if(!i.$)return;let o=ql({concreteType:e,argType:i.$.type,env:i.$.env});return o?{fnType:o.type,value:o.value}:void 0}catch{return}}function lT({concreteType:e,argType:t,env:n}){let r=n_({concreteType:e,env:n});for(let i of r){let o=i.type;if(o.parameters.length!==2)continue;let a=o.parameters[0],s=o.parameters[1];if(je(a.type)&&le({type:s.type,env:n},{type:t,env:n})&&je(o.return.type)&&a.isCompileTimeOnly&&s.isCompileTimeOnly)return i}}function uT({expr:e,argExpr:t,selfValue:n,valueType:r,callerEnv:i,context:o}){let a=O({expr:t,env:i,context:{...o,expectedType:void 0}});if(!a.$||!a.$.value)return;let s=a.$.type,l=a.$.value;i=a.$.env;let u=lT({concreteType:r,argType:s,env:i});if(!u||!ge(u.value))return;let _=u.type,c=u.value,f=yn(r),p=Bi(f,[n]),m=lt(_.env),h=_.parameters[0],y=_.parameters[1],g=e.func.token??Fe;({env:m}=xe({env:m,variable:{name:h.label,type:h.type,value:[p],isCompileTimeOnly:!0,isOwningTheRcValue:!1,initializedAtToken:g,consumedAtToken:void 0,token:g}})),{env:m}=xe({env:m,variable:{name:y.label,type:y.type,value:[l],isCompileTimeOnly:!0,isOwningTheRcValue:!1,initializedAtToken:g,consumedAtToken:void 0,token:g}});let v={...o,isValidatingFunctionDefinition:void 0},T=Oi({functionCalleeExpr:e.func,functionType:_,functionValue:c,argValues:{forallArgs:[],args:[{value:p,parameterType:h.type,argType:f},{value:l,parameterType:y.type,argType:s}],variadicArgs:[]},callerEnv:i,calleeEnv:m,context:v}),$=T.value,C=_.return.type;if(!je(C))return;let k=C.childType;if(Vr($)){let w=$.targetValue[0],A,L;mr(w)?(A=w.elements[$.targetIndex],L={kind:"array",arrayValue:w,index:$.targetIndex}):kn(w)?(A=w.fields[$.targetIndex]??w,L={kind:"struct",structValue:w,fieldIndex:$.targetIndex}):Zn(w)?(A=w.fields[$.targetIndex]??w,L={kind:"tuple",tupleValue:w,fieldIndex:$.targetIndex}):A=w;let N=ql({concreteType:r,argType:s,env:i});return{value:A,type:k,ptrType:C,indexMethodType:N==null?void 0:N.type,indexMethodValue:N==null?void 0:N.value,callerEnv:i,comptimeRef:L}}let b=ql({concreteType:r,argType:s,env:i});return{value:$,type:k,ptrType:C,indexMethodType:b==null?void 0:b.type,indexMethodValue:b==null?void 0:b.value,callerEnv:i,comptimeRef:T.comptimeRef}}function _m({concreteType:e,argExprs:t,callerEnv:n,_context:r}){if(t.length!==1)return!1;if(Je(e)||$t(e))return!0;try{return n_({concreteType:e,env:n}).length>0}catch{return!1}}function sm(e,t,n){var l;let i=ae(t,e).find(u=>{var _;return((_=u.value)==null?void 0:_[0])&&ge(u.value[0])&&ne(u.type)});if(!i||!((l=i.value)!=null&&l[0])||!ge(i.value[0]))return;let o=i.value[0],a=o.type,s=Te(vn());try{let{value:u}=Oi({functionCalleeExpr:void 0,functionType:a,functionValue:o,argValues:{forallArgs:[],args:[{value:s,parameterType:a.parameters[0].type,argType:s.type}],variadicArgs:[]},callerEnv:t,calleeEnv:t,context:n});if(W(u)&&Ae(u.value))return u.value}catch{}}var lm=new WeakMap;function _T(e,t){let n=e.frames[0],r=lm.get(n);return r||(r={range:sm("Range",e,t),rangeInclusive:sm("RangeInclusive",e,t)},lm.set(n,r)),r}function cm(e,t,n){if(!Ae(e))return{isRange:!1,isInclusive:!1};let{range:r,rangeInclusive:i}=_T(t,n);return i&&le({type:i,env:t},{type:e,env:t})?{isRange:!0,isInclusive:!0}:r&&le({type:r,env:t},{type:e,env:t})?{isRange:!0,isInclusive:!1}:{isRange:!1,isInclusive:!1}}function cT({argExpr:e,arrayValue:t,sliceValue:n,arrayType:r,env:i,context:o}){let a=O({expr:e,env:i,context:{...o,expectedType:void 0}});if(!a.$)throw d({token:e.token,errorMessage:`Failed to evaluate argument expression:
|
|
11544
11544
|
${I(e)}`});let s=a.$.env,l=a.$.type,u=a.$.value,{isRange:_,isInclusive:c}=cm(l,i,o);return _?fT({argExpr:e,argValue:u,isInclusive:c,arrayValue:t,sliceValue:n,arrayType:r,callerEnv:s}):pT({argExpr:e,argValue:u,arrayValue:t,sliceValue:n,arrayType:r,callerEnv:s,context:o})}function fT({argExpr:e,argValue:t,isInclusive:n,arrayValue:r,sliceValue:i,arrayType:o,callerEnv:a}){let s=Ii(o.childType);if(!kn(t))return;let l=t.fields[0],u=t.fields[1];if(!l||!u||!ht(l)||!ht(u))return;let _=l.value,c=u.value,f=typeof _=="bigint"?Number(_):_,p=(typeof c=="bigint"?Number(c):c)+(n?1:0);if(r){if(f<0||f>r.elements.length)throw d({token:e.token,errorMessage:`Slice start index out of bounds: ${f}. Expected index in range [0, ${r.elements.length}].`});if(p<f||p>r.elements.length)throw d({token:e.token,errorMessage:`Slice end index out of bounds: ${p}. Expected index in range [${f}, ${r.elements.length}].`});return{value:Oo(s,[r],f,p),type:s,ptrType:yn(s),indexMethodType:void 0,indexMethodValue:void 0,callerEnv:a}}if(i){let m=i.endIndex-i.startIndex;if(f<0||f>m)throw d({token:e.token,errorMessage:`Slice start index out of bounds: ${f}. Expected index in range [0, ${m}].`});if(p<f||p>m)throw d({token:e.token,errorMessage:`Slice end index out of bounds: ${p}. Expected index in range [${f}, ${m}].`});let h=i.startIndex+f,y=i.startIndex+p;return{value:Oo(s,i.sourceArray,h,y),type:s,ptrType:yn(s),indexMethodType:void 0,indexMethodValue:void 0,callerEnv:a}}}function pT({argExpr:e,argValue:t,arrayValue:n,sliceValue:r,arrayType:i,callerEnv:o,context:a}){let s=i.childType;if(ht(t)){let l=t.value,u=typeof l=="bigint"?Number(l):l;if(n){if(u<0||u>=n.elements.length)throw d({token:e.token,errorMessage:`Array index out of bounds: ${u}. Expected index in range [0, ${n.elements.length-1}].`});return{value:n.elements[u],type:s,ptrType:yn(s),indexMethodType:void 0,indexMethodValue:void 0,callerEnv:o,index:u,comptimeRef:{kind:"array",arrayValue:n,index:u}}}if(r){let _=r.endIndex-r.startIndex;if(u<0||u>=_)throw d({token:e.token,errorMessage:`Slice index out of bounds: ${u}. Expected index in range [0, ${_-1}].`});let c=r.startIndex+u,f=r.sourceArray[0];return{value:f.elements[c],type:s,ptrType:yn(s),indexMethodType:void 0,indexMethodValue:void 0,callerEnv:o,index:u,comptimeRef:{kind:"array",arrayValue:f,index:c}}}}else return t?{value:oe(s,{env:o,context:a}),type:s,ptrType:yn(s),indexMethodType:void 0,indexMethodValue:void 0,callerEnv:o}:{value:void 0,type:an({type:s,env:o}),ptrType:yn(s),indexMethodType:void 0,indexMethodValue:void 0,callerEnv:o}}function dT({argExpr:e,strValue:t,env:n,context:r}){let i=O({expr:e,env:n,context:{...r,expectedType:void 0}});if(!i.$||!i.$.value)throw d({token:e.token,errorMessage:"Failed to evaluate index argument for comptime string indexing"});let o=i.$.type,a=i.$.value,s=i.$.env,{isRange:l,isInclusive:u}=cm(o,n,r),_=kd({strValue:t,argValue:a,token:e.token,isRange:l,isInclusive:u}),c=_.type,f=yn(c);return{value:_,type:c,ptrType:f,indexMethodType:void 0,indexMethodValue:void 0,callerEnv:s}}function fm({expr:e,env:t,context:n}){let r=e.args[0],i=O({expr:r,env:t,context:{...n}});if(!i.$)throw d({token:r.token,errorMessage:`Failed to evaluate the argument expression for Iso:
|
|
11545
11545
|
${I(r)}`});if(t=i.$.env,!W(i.$.value))throw d({token:r.token,errorMessage:`Iso expects a type as argument, but got:
|
|
11546
11546
|
${I(r)}`});let a=i.$.value.value,s=rc(a,t);t=O_({isoType:s,env:t,context:n});let l=Te(s);return e.$={env:t,type:l.type,value:l,pathCollection:[]},e}function pm({expr:e,env:t,context:n,isoType:r}){var s;let i=e.args[0],o=O({expr:i,env:t,context:{...n,expectedType:{type:r.childType,env:t}}});if(!o.$)throw d({token:i.token,errorMessage:`Failed to evaluate the argument expression for Iso value constructor:
|
|
@@ -11550,7 +11550,7 @@ ${I(T)}`});y=T.token.value}else throw d({token:v.token,errorMessage:`Expected me
|
|
|
11550
11550
|
${I(v)}`});if(!t.fields.find($=>$.label===y))throw d({token:T.token,errorMessage:`Module member with label "${y}" does not exist in the module type.`});if(m.label===y){if(h=!0,m.assignedValue)throw d({token:v.token,errorMessage:`Module member "${m.label}" already has a assigned value:
|
|
11551
11551
|
${pt(m.assignedValue)}`});let $,C=m.exprs.typeExpr,k=m.exprs.defaultValueExpr;if(C){let N=(l=O({expr:_t(C),env:lt(t.env,r.frames[r.frames.length-1]),context:{...i,expectedType:void 0,ReceiverType:void 0,SelfType:void 0,SelfModuleType:t}}).$)==null?void 0:l.value;if(!W(N))throw d({token:v.token,errorMessage:`Failed to evaluate the module member "${y}"`});$=N.value}else if(k){let N=(u=O({expr:_t(k),env:lt(t.env,r.frames[r.frames.length-1]),context:{...i,expectedType:void 0,ReceiverType:void 0,SelfType:void 0}}).$)==null?void 0:u.value;if(!N)throw d({token:v.token,errorMessage:`Failed to evaluate the module member "${y}"`});$=N.type}else throw d({token:v.token,errorMessage:`Module member "${y}" has no type or default value or assigned value.`});let b=O({expr:v,env:r,context:{...i,expectedType:{type:$,env:r},ReceiverType:void 0,SelfType:void 0}}),w=(_=b.$)==null?void 0:_.type;if(!w)throw d({token:v.token,errorMessage:`Failed to evaluate the module member "${y}"`});if((c=b.$)!=null&&c.env&&(r=b.$.env),!le({type:$,env:r},{type:w,env:r}))throw d({token:v.token,errorMessage:`Type mismatch for the module member "${y}":
|
|
11552
11552
|
Expected: ${M($)}
|
|
11553
|
-
Got: ${M(w)}`});let A=(f=b.$)==null?void 0:f.value;w.ioBuiltin&&(t.fields[p].type.ioBuiltin=w.ioBuiltin),
|
|
11553
|
+
Got: ${M(w)}`});let A=(f=b.$)==null?void 0:f.value;w.ioBuiltin&&(t.fields[p].type.ioBuiltin=w.ioBuiltin),ge(A)&&(A.funcId+=`_${m.label}`,!A.specializedType&&ne($)&&(A.specializedType={...$,parameters:A.type.parameters,parametersFrame:A.type.parametersFrame})),o[p]=A,a.fields[p].assignedValue=A,v.$={env:r,type:w,value:A,pathCollection:[]},T&&(T.$=v.$);break}}if(!h){let g=m.defaultValue,v=m.assignedValue,T=v;if(!v&&g&&(T=g),!T)throw d({token:e.token,errorMessage:`Module member "${m.label}" is not provided and has no required/default value.`});o[p]=T,a.fields[p].assignedValue=T}}return{moduleValue:F_({...t},o),callerEnv:r}}function mm({targetType:e,argExpr:t,expr:n,callerEnv:r,context:i}){if(!je(e))return;let o=O({expr:t,env:r,context:{...i,expectedType:void 0}});if(!o.$)throw d({token:t.token,errorMessage:`Failed to evaluate argument: ${I(t)}`});let a=o.$.env,s=o.$.type;if(on(s)&&(jr(e.childType)||Do(e.childType))){let u=an({type:s,expectedType:e,expr:o,env:a});return o.$={...o.$,type:u,convertedRuntimeType:u},Object.assign(n,o),n.$=o.$,{expr:n,env:a}}if(!je(s))throw d({token:t.token,errorMessage:`Cannot cast ${M(s)} to ${M(e)}. Expected a pointer type or comptime_string.`});let l={tag:"FnCall",func:{tag:"Atom",token:{...n.token,value:F.__yo_as[0],type:"identifier"},$:void 0},args:[o,n.func],token:n.token,$:{env:a,type:e,value:void 0,pathCollection:o.$.pathCollection,runtimeArgExprsInOrder:[o]}};return Fs(n,l),{expr:n,env:a}}function ym({traitType:e,argExprs:t,callerEnv:n,context:r}){let i=[];for(let a of t){if(!S(a)||!E(a,":=",2))throw d({token:a.token,errorMessage:`Expected ":=" for trait specialization (binding associated types), got:
|
|
11554
11554
|
${I(a)}`});let s=a.args[0],l=a.args[1];if(!K(s))throw d({token:s.token,errorMessage:`Expected identifier for associated type label, got:
|
|
11555
11555
|
${I(s)}`});let u=s.token.value,_=e.fields.find(f=>f.label===u);if(!_)throw d({token:s.token,errorMessage:`Field "${u}" not found in trait "${e.typeName??"unknown"}".`});if(!_.unassignedSomeType&&!St(_.type))throw d({token:s.token,errorMessage:`Field "${u}" is not an associated type. Only associated type fields can be constrained with ":=".`});let c=O({expr:l,env:n,context:{...r}});if(!c.$||!W(c.$.value))throw d({token:l.token,errorMessage:`Expected type for associated type constraint "${u}", got:
|
|
11556
11556
|
${I(l)}`});n=c.$.env,i.push({label:u,constraintType:c.$.value.value})}return{specializedTraitType:{...e,associatedTypeConstraints:i},callerEnv:n}}function gm({traitExpr:e,traitType:t,argExprs:n,callerEnv:r,context:i}){var c,f,p,m,h,y,g,v;if(n.length>t.fields.length)throw d({token:e.token,errorMessage:"Failed to implement the trait. Too many fields provided."});let o=Array(t.fields.length).fill(void 0),a={...t,fields:t.fields.map((T,$)=>({...T,assignedValue:o[$]}))},s=i.ReceiverType,l=i.ReceiverType??a;if(!s)throw d({token:e.token,errorMessage:`Receiver type is undefined when implementing trait.
|
|
@@ -11565,17 +11565,17 @@ ${I(A)}`});k=A.token.value}else throw d({token:w.token,errorMessage:`Expected me
|
|
|
11565
11565
|
${I(w)}`});if(!t.fields.find(L=>L.label===k))throw d({token:A.token,errorMessage:`Trait member with label "${k}" does not exist in the trait type.`});if($.label===k){if(C=!0,$.assignedValue)throw d({token:w.token,errorMessage:`Trait member "${$.label}" already has a assigned value:
|
|
11566
11566
|
${pt($.assignedValue)}`});let L,N=$.exprs.typeExpr,x=$.exprs.defaultValueExpr;if(N){let H=(c=O({expr:_t(N),env:lt(t.env,r.frames[r.frames.length-1]),context:{...i,expectedType:void 0,ReceiverType:void 0,SelfType:l,SelfTraitType:t}}).$)==null?void 0:c.value;if(!W(H))throw d({token:w.token,errorMessage:`Failed to evaluate the trait member "${k}"`});L=H.value}else if(x){let H=(f=O({expr:_t(x),env:lt(t.env,r.frames[r.frames.length-1]),context:{...i,expectedType:void 0,ReceiverType:void 0,SelfType:l,SelfTraitType:t}}).$)==null?void 0:f.value;if(!H)throw d({token:w.token,errorMessage:`Failed to evaluate the trait member "${k}"`});L=H.type}else throw d({token:w.token,errorMessage:`Trait member "${k}" has no type or default value or assigned value.`});let V=O({expr:w,env:r,context:{...i,expectedType:{type:L,env:r},ReceiverType:void 0,SelfType:l}}),U=(p=V.$)==null?void 0:p.type;if(!U)throw d({token:w.token,errorMessage:`Failed to evaluate the trait member "${k}"`});if((m=V.$)!=null&&m.env&&(r=V.$.env),!le({type:L,env:r},{type:U,env:r}))throw d({token:w.token,errorMessage:`Type mismatch for the trait member "${k}":
|
|
11567
11567
|
Expected: ${M(L)}
|
|
11568
|
-
Got: ${M(U)}`});let R=(h=V.$)==null?void 0:h.value;
|
|
11568
|
+
Got: ${M(U)}`});let R=(h=V.$)==null?void 0:h.value;ge(R)&&(R.funcId+=`_${$.label}`,!R.specializedType&&ne(L)&&(R.specializedType={...L,parameters:R.type.parameters,parametersFrame:R.type.parametersFrame})),o[T]=R,a.fields[T].assignedValue=R,s&&s.trait&&(s.trait.fields[T].assignedValue=R),w.$={env:r,type:U,value:R,pathCollection:[]},A&&(A.$=w.$);break}}if(!C){let b=$.exprs.typeExpr,w=$.exprs.defaultValueExpr,A=$.defaultValue,L=$.assignedValue,N=L;if(!L&&w)try{let x;if(b){let R=(y=O({expr:_t(b),env:lt(t.env,r.frames[r.frames.length-1]),context:{...i,expectedType:void 0,ReceiverType:void 0,SelfType:l,SelfTraitType:t}}).$)==null?void 0:y.value;W(R)&&(x=R.value)}N=(g=O({expr:_t(w),env:lt(t.env,r.frames[r.frames.length-1]),context:{...i,expectedType:x?{type:x,env:r}:void 0,ReceiverType:void 0,SelfType:l,SelfTraitType:t}}).$)==null?void 0:g.value,N&&ge(N)&&(N.funcId+=`_${$.label}`,!N.specializedType&&x&&ne(x)&&(N.specializedType={...x,parameters:N.type.parameters,parametersFrame:N.type.parametersFrame}))}catch{N=A}if(!N&&A&&(N=A),!N)throw d({token:e.token,errorMessage:`Trait member "${$.label}" is not provided and has no required/default value.`});o[T]=N,a.fields[T].assignedValue=N}}s&&u&&(s.trait=u);for(let T=0;T<t.fields.length;T++){let $=t.fields[T];if(!$.unassignedSomeType)continue;let C=$.unassignedSomeType,k=o[T];if(!k||!W(k))continue;let b=k.value;if(!Me(b))for(let{traitType:w}of C.requiredTraits){let A=w;if(w.associatedTypeConstraints){let N=w.associatedTypeConstraints.map(x=>{let V=x.constraintType;if(z(V)){for(let U=0;U<t.fields.length;U++)if(t.fields[U].unassignedSomeType===V){let D=o[U];D&&W(D)&&(V=D.value);break}}return{...x,constraintType:V}});A={...w,associatedTypeConstraints:N}}if(!bn({targetType:b,traitType:A,env:r}))throw d({token:e.token,errorMessage:`Where clause constraint not satisfied: ${M(b)} does not implement ${A.typeName??"trait"}(${((v=A.associatedTypeConstraints)==null?void 0:v.map(N=>`${N.label} := ${M(N.constraintType)}`).join(", "))??""}).
|
|
11569
11569
|
Field "${$.label}" must satisfy the trait's where clause.`})}}return{traitValue:Mo({...t,receiverType:s},o),callerEnv:r}}function Yl({typeFields:e,functionCalleeExpr:t,argExprs:n,callerEnv:r,context:i,isUnionType:o}){var _;if(n.length>e.length)throw d({token:t.token,errorMessage:`Failed to call the type. Too many members provided. Expected ${e.length} arguments, got ${n.length}.`});if(o&&n.length!==1)throw d({token:t.token,errorMessage:`Failed to call the union type. Expected exactly one argument, got ${n.length}.`});let a=new Set,s=Array(e.length).fill(void 0),l=[];for(let c=0;c<e.length;c++){let f=e[c],p=n[c];if(!p)break;let m;if(S(p)&&E(p,":",2)&&(m=p.args[0],p=p.args[1],!K(m)))throw d({token:m.token,errorMessage:`Expected identifier for label, got:
|
|
11570
11570
|
${I(m)}`});if(m){let v=m.token.value,T=e.find($=>$.label===v);if(T){if(T.assignedValue)throw d({token:p.token,errorMessage:`Cannot use label "${v}" for already assigned value:
|
|
11571
11571
|
${jo(T)}`});f=T}else throw d({token:p.token,errorMessage:`Failed to find "${v}" in the type.`})}if(a.has(f))throw d({token:p.token,errorMessage:`Type member "${f.label}" is already implemented.`});let h=e.indexOf(f),y=O({expr:p,env:r,context:{...i,expectedType:{type:f.type,env:r}}});if(!y.$)throw d({token:p.token,errorMessage:`Failed to evaluate argument expression:
|
|
11572
11572
|
${I(p)}`});Bn(y,i),r=y.$.env;let g=y.$.type;if(_o(f.type,r)||(g=an({type:g,expectedType:f.type,expr:y,env:r})),m&&(m.$=y.$),!le({type:f.type,env:r},{type:g,env:r}))throw d({token:p.token,errorMessage:`Type mismatch for type member "${f.label}":
|
|
11573
11573
|
Expected: ${M(f.type)}
|
|
11574
11574
|
Got: ${M(g)}`});s[h]=(_=y.$)==null?void 0:_.value,l[h]=y,a.add(f)}if(!o)for(let c=0;c<e.length;c++){let f=e[c];if(!a.has(f)){if(!f.defaultValue&&!f.assignedValue)throw d({token:t.token,errorMessage:`Type member "${f.label}" is not provided and has no default value or assigned value.`});s[c]=f.defaultValue??f.assignedValue,l[c]=f.exprs.defaultValueExpr??f.exprs.assignedValueExpr}}return{values:s,pathCollection:[],callerEnv:r,runtimeArgExprsInOrder:l}}function mT(e,t,n){if(!e.recursiveTypeRef)return;let{functionValue:r,argValues:i}=e.recursiveTypeRef,o=r.calledComptimeFunctionCaches.find(s=>s.argValues.length===i.length&&s.argValues.every((l,u)=>{let _=i[u];return W(l)&&W(_)?le({type:l.value,env:s.env},{type:_.value,env:t},!0):Cn({value:l,env:s.env},{value:_,env:t})}));if(o&&W(o.value)&&!(z(o.value.value)&&o.value.value.recursiveTypeRef))return o.value.value;if(n!=null&&n.SelfType&&en(n.SelfType)||n!=null&&n.SelfType&&Ae(n.SelfType))return n.SelfType;let a=r.calledComptimeFunctionCaches.find(s=>!(!W(s.value)||z(s.value.value)&&s.value.value.recursiveTypeRef));if(a&&W(a.value))return a.value.value}function Mr({expr:e,env:t,context:n,givenFunc:r,forMacroExpansion:i}){var v,T,$,C,k,b,w,A,L,N,x,V,U,R,D,H,B,G,Q,Y,J,se,ve,re,ce,we,Se,Ve,de,ee,fe,me,Le,qe,dt,kt,Rt,Ze,Tt,Jt,At,gt,nt,Ft,qt,Et,Lt,nn;let o=e.func,a=e.args,s,l=[];if(r)l=[r];else if(S(o)){let te=E(o,"."),pe=O({expr:o,env:t,context:te?{...n}:{...n,expectedType:void 0}});if(o=pe,(v=o.$)!=null&&v.env&&(t=o.$.env),(T=pe.$)!=null&&T.type)l=[{type:pe.$.type,value:pe.$.value}];else if(S(pe)&&E(pe,".",2)){let $e=pe.args[0];s=pe.args[1];let ie=($=$e.$)==null?void 0:$.type;if(!ie)throw d({token:$e.token,errorMessage:"Expected to be evaluated."});let _e=(C=$e.$)==null?void 0:C.value,ye=W(_e);if(K(s)){let Re=s.token.value;if(ye){let Ke=_e.value;l=Nc({env:t,context:n,methodName:Re,type:Ke}).map(Z=>({type:Z.type,value:Z.value,args:a}))}else l=Lu({env:t,context:n,methodName:Re,receiverType:ie,isInfixOperatorCall:!1}).map(Pe=>{let Z;if(Pe.needsPointerConversion){let X={tag:"Atom",token:$e.token,$:void 0};X.token={...$e.token,value:"&",type:"identifier"},Z=[{tag:"FnCall",func:X,args:[$e],token:$e.token,$:void 0},...a]}else Z=[$e,...a];return{type:Pe.type,value:Pe.value,needsPointerConversion:Pe.needsPointerConversion,args:Z}})}else{let Re=O({expr:s,env:t,context:{...n}});(k=Re.$)!=null&&k.env&&(t=(b=Re.$)==null?void 0:b.env),s=Re;let Ke=(w=s.$)==null?void 0:w.type,Pe=(A=s.$)==null?void 0:A.value;if(!Ke)throw d({token:s.token,errorMessage:"Expected to be a function."});l=[{type:Ke,value:Pe}],a=[$e,...a]}}else throw d({token:o.token,errorMessage:`Expected type for function call, got ${I(pe)}`})}else{let te=o.token.value;if(te==="_"){let pe=n.expectedType;if(!pe||z(pe.type))return Kd({expr:e,env:t,context:n});l=[{type:dn(pe.type),value:Te(pe.type)}],o.$={env:t,type:l[0].type,value:l[0].value,pathCollection:[]}}else if(Hr(te)&&e.isInfix){let pe=a[0];if(!pe)throw d({token:o.token,errorMessage:`Expected first argument for operator, got:
|
|
11575
|
-
${I(o)}`});let ie=(L=O({expr:pe,env:t,context:{...n,expectedType:void 0}}).$)==null?void 0:L.type;if(!ie)throw d({token:pe.token,errorMessage:"Expected to be evaluated."});let _e=te;s=o,l=Lu({env:t,context:n,methodName:_e,receiverType:ie,isInfixOperatorCall:!0}).map(Re=>({type:Re.type,value:Re.value,needsPointerConversion:Re.needsPointerConversion}))}else if(te==="Call"&&n.SelfType){let pe=Te(n.SelfType);l=[{type:pe.type,value:pe}]}else{let pe=O({expr:o,env:t,context:{...n}});if(o=pe,!pe.$)throw d({token:o.token,errorMessage:"Failed to evaluate the callee:"});if(Xe(pe.$.type)){let $e=pe.$.type,ie=$e.fields.findIndex(ye=>ye.label==="Call");if(ie<0)throw d({token:o.token,errorMessage:'Calling a module value which does not have "Call" element is not allowed.'});let _e=$e.fields[ie];if(_e.assignedValue){let ye=_e.assignedValue;Zn(ye)?l=ye.fields.map(Re=>({type:Re.type,value:Re})):l=[{type:ye.type,value:ye}]}else throw d({token:o.token,errorMessage:`Calling a module value whose "Call" element doesn't have assigned value is not allowed.`})}else l=[{type:pe.$.type,value:pe.$.value}]}}if(a.some(pe=>K(pe)&&pe.token.value==="_")&&l.length===1&&
|
|
11575
|
+
${I(o)}`});let ie=(L=O({expr:pe,env:t,context:{...n,expectedType:void 0}}).$)==null?void 0:L.type;if(!ie)throw d({token:pe.token,errorMessage:"Expected to be evaluated."});let _e=te;s=o,l=Lu({env:t,context:n,methodName:_e,receiverType:ie,isInfixOperatorCall:!0}).map(Re=>({type:Re.type,value:Re.value,needsPointerConversion:Re.needsPointerConversion}))}else if(te==="Call"&&n.SelfType){let pe=Te(n.SelfType);l=[{type:pe.type,value:pe}]}else{let pe=O({expr:o,env:t,context:{...n}});if(o=pe,!pe.$)throw d({token:o.token,errorMessage:"Failed to evaluate the callee:"});if(Xe(pe.$.type)){let $e=pe.$.type,ie=$e.fields.findIndex(ye=>ye.label==="Call");if(ie<0)throw d({token:o.token,errorMessage:'Calling a module value which does not have "Call" element is not allowed.'});let _e=$e.fields[ie];if(_e.assignedValue){let ye=_e.assignedValue;Zn(ye)?l=ye.fields.map(Re=>({type:Re.type,value:Re})):l=[{type:ye.type,value:ye}]}else throw d({token:o.token,errorMessage:`Calling a module value whose "Call" element doesn't have assigned value is not allowed.`})}else l=[{type:pe.$.type,value:pe.$.value}]}}if(a.some(pe=>K(pe)&&pe.token.value==="_")&&l.length===1&&ge(l[0].value)&&ne(l[0].type)&&l[0].type.return.isCompileTimeOnly){let pe=l[0].value,$e=l[0].type,ie=$e.parameters;if(a.length!==ie.length)throw d({token:o.token,errorMessage:`Partial application: expected ${ie.length} argument(s), got ${a.length}`});let _e=lt(t),ye=`__pa_fn_${mt(t.modulePath)}`;{let{env:Ce}=xe({env:_e,variable:{name:ye,type:$e,isCompileTimeOnly:!0,value:[pe],token:o.token,initializedAtToken:o.token,consumedAtToken:void 0,isOwningTheRcValue:!1}});_e=Ce}let Re=[],Ke=[];for(let Ce=0;Ce<a.length;Ce++){let He=a[Ce],Ee=ie[Ce];if(K(He)&&He.token.value==="_"){let Oe=`__pa_${Ce}_${mt(t.modulePath)}`;Re.push({...Ee,label:Oe}),Ke.push({tag:"Atom",token:{type:"identifier",value:Oe,position:He.token.position,modulePath:t.modulePath,inputString:t.inputString}})}else{let Oe=`__pa_cap_${Ce}_${mt(t.modulePath)}`,Ue=O({expr:He,env:_e,context:{...n}});if(!Ue.$)throw d({token:He.token,errorMessage:"Failed to evaluate partial application argument"});_e=Ue.$.env;let{env:ze}=xe({env:_e,variable:{name:Oe,type:Ue.$.type,isCompileTimeOnly:!0,value:Ue.$.value?[Ue.$.value]:void 0,token:He.token,initializedAtToken:He.token,consumedAtToken:void 0,isOwningTheRcValue:!1}});_e=ze,Ke.push({tag:"Atom",token:{type:"identifier",value:Oe,position:He.token.position,modulePath:t.modulePath,inputString:t.inputString}})}}let Pe={tag:"FnCall",func:{tag:"Atom",token:{type:"identifier",value:ye,position:o.token.position,modulePath:t.modulePath,inputString:t.inputString}},args:Ke,token:o.token},Z={id:`pa_frame_${mt(t.modulePath)}`,variables:Re.map(Ce=>({id:`pa_var_${mt(t.modulePath)}`,name:Ce.label,type:Ce.type,isCompileTimeOnly:!0,value:void 0,token:Fe,initializedAtToken:Fe,consumedAtToken:void 0,isOwningTheRcValue:!1,frameLevel:_e.frames.length})),isBeginBlockFrame:!1,whereClauseConstraints:new Map},X=Ai({parameters:Re,forallParameters:[],variadicParameter:void 0,return_:{...$e.return},env:_e,parametersFrame:Z}),he={tag:"Function",type:X,body:Pe,frameLevel:_e.frames.length-1,funcName:`partial_${pe.funcName??"anon"}`,funcId:`partial_${mt(t.modulePath)}`,calledComptimeFunctionCaches:[],specializedFunctionCaches:[]};return e.$={env:t,type:X,value:he,pathCollection:[]},e}let u=l.length===1&&ne(l[0].type)&&l[0].type.return.isCompileTimeOnly&&!l[0].type.return.isUnquote&&!St(l[0].type.return.type)&&l[0].type.forallParameters.length===0,f=l.length===1&&(ne(l[0].type)||(z(l[0].type)||st(l[0].type))&&!!Kn(l[0].type))?l.map(te=>({...te,result:{kind:"function",result:void 0}})):l.map(te=>{let pe=te.args??a;if(ne(te.type))try{let $e=to({functionValue:va(te.value),functionType:te.type,expr:_t(e),functionCalleeExpr:o,argExprs:pe.map(ie=>_t(ie)),callerEnv:wu(t),context:{...n,isInFunctionCallCheckingPhase:!0},isMethodCall:!!s,skipSpecialization:!0,skipCtfeExecution:!0});return{...te,result:{kind:"function",result:$e}}}catch($e){if($e instanceof pr&&$e.kind==="overflow")throw Qt([{token:e.token,errorMessage:`Failed to call the function:
|
|
11576
11576
|
`},...$e.tokenAndErrorList],$e.isAssertionError);return{...te,result:{kind:"error",error:$e}}}else if((z(te.type)||st(te.type))&&Kn(te.type)){let $e=Kn(te.type);try{let ie=to({functionValue:va(te.value),functionType:$e.isFn.callType,expr:_t(e),functionCalleeExpr:o,argExprs:pe.map(_e=>_t(_e)),callerEnv:wu(t),context:{...n,isInFunctionCallCheckingPhase:!0},isMethodCall:!!s,skipSpecialization:!0,skipCtfeExecution:!0});return{...te,result:{kind:"function",result:ie}}}catch(ie){if(ie instanceof pr&&ie.kind==="overflow")throw Qt([{token:e.token,errorMessage:`Failed to call the function:
|
|
11577
|
-
`},...ie.tokenAndErrorList],ie.isAssertionError);return{...te,result:{kind:"error",error:ie}}}}else{let $e=te.value;if(W($e)&&z($e.value)&&$e.value.recursiveTypeRef){let ie=mT($e.value,t,n);ie&&($e=Te(ie),te.value=$e,te.type=$e.type)}if(W($e)&&Ae($e.value))try{let ie=Yl({typeFields:$e.value.fields,functionCalleeExpr:o,argExprs:pe,callerEnv:t,context:{...n}});return{...te,result:{kind:"type",result:ie}}}catch(ie){return{...te,result:{kind:"error",error:ie}}}else if(W($e)&&Be($e.value)){let ie=$e.value,_e=ie.variants.find(ye=>ye.name===ie.selectedVariantName);if(_e)try{let ye=Yl({typeFields:_e.fields||[],functionCalleeExpr:o,argExprs:pe,callerEnv:t,context:{...n}});return{...te,result:{kind:"type",result:ye}}}catch(ye){return{...te,result:{kind:"error",error:ye}}}else return{...te,result:{kind:"error",error:d({token:e.token,errorMessage:"Enum variant not selected for enum type"})}}}else if(W($e)&&Bt($e.value))try{let ie=Yl({typeFields:$e.value.fields,functionCalleeExpr:o,argExprs:pe,callerEnv:t,context:{...n},isUnionType:!0});return{...te,result:{kind:"type",result:ie}}}catch(ie){return{...te,result:{kind:"error",error:ie}}}else if(W($e)&&Xe($e.value)){let ie=$e.value;try{let _e=dm({moduleExpr:o,moduleType:ie,argExprs:pe,callerEnv:t,context:{...n}});return{...te,result:{kind:"module-type",result:_e}}}catch(_e){return{...te,result:{kind:"error",error:_e}}}}else if(W($e)&&ot($e.value)){let ie=$e.value;if(pe.some(ye=>S(ye)&&E(ye,":=",2)))try{let ye=ym({traitExpr:o,traitType:ie,argExprs:pe,callerEnv:t,context:{...n}});return{...te,result:{kind:"trait-specialization",result:ye}}}catch(ye){return{...te,result:{kind:"error",error:ye}}}try{let ye=gm({traitExpr:o,traitType:ie,argExprs:pe,callerEnv:t,context:{...n}});return{...te,result:{kind:"trait-type",result:ye}}}catch(ye){return{...te,result:{kind:"error",error:ye}}}}else if(W($e)&&ne($e.value)){let ie=$e.value;try{return Zd({expr:e,functionType:ie,callerEnv:t,context:{...n}}),{...te,result:{kind:"function-type"}}}catch(_e){return{...te,result:{kind:"error",error:_e}}}}else if(W($e)&&Je($e.value)){let ie=$e.value;try{return Xd({expr:e,arrayType:ie,argExprs:pe,callerEnv:t,context:{...n}}),{...te,result:{kind:"array-type"}}}catch(_e){return{...te,result:{kind:"error",error:_e}}}}else if(W($e)&&sn($e.value)){let ie=$e.value;try{return em({expr:e,comptimeListType:ie,argExprs:pe,callerEnv:t,context:{...n}}),{...te,result:{kind:"array-type"}}}catch(_e){return{...te,result:{kind:"error",error:_e}}}}else if(W($e)&&(z($e.value)||st($e.value))){let ie=$e.value,_e=Kn(ie);if(_e)try{return Jd({expr:e,fnModuleType:_e,wrapperType:ie,callerEnv:t,context:{...n}}),{...te,result:{kind:"closure-type"}}}catch(ye){return{...te,result:{kind:"error",error:ye}}}else if(z(ie)&&ie.kindFunctionType)try{let ye=ie.kindFunctionType,Re=[];if(pe.length!==ye.parameters.length)throw d({token:o.token,errorMessage:`Type constructor "${ie.name}" expects ${ye.parameters.length} argument(s), got ${pe.length}`});for(let Z=0;Z<pe.length;Z++){let X=pe[Z],
|
|
11578
|
-
${I(X)}`});Re.push(
|
|
11577
|
+
`},...ie.tokenAndErrorList],ie.isAssertionError);return{...te,result:{kind:"error",error:ie}}}}else{let $e=te.value;if(W($e)&&z($e.value)&&$e.value.recursiveTypeRef){let ie=mT($e.value,t,n);ie&&($e=Te(ie),te.value=$e,te.type=$e.type)}if(W($e)&&Ae($e.value))try{let ie=Yl({typeFields:$e.value.fields,functionCalleeExpr:o,argExprs:pe,callerEnv:t,context:{...n}});return{...te,result:{kind:"type",result:ie}}}catch(ie){return{...te,result:{kind:"error",error:ie}}}else if(W($e)&&Be($e.value)){let ie=$e.value,_e=ie.variants.find(ye=>ye.name===ie.selectedVariantName);if(_e)try{let ye=Yl({typeFields:_e.fields||[],functionCalleeExpr:o,argExprs:pe,callerEnv:t,context:{...n}});return{...te,result:{kind:"type",result:ye}}}catch(ye){return{...te,result:{kind:"error",error:ye}}}else return{...te,result:{kind:"error",error:d({token:e.token,errorMessage:"Enum variant not selected for enum type"})}}}else if(W($e)&&Bt($e.value))try{let ie=Yl({typeFields:$e.value.fields,functionCalleeExpr:o,argExprs:pe,callerEnv:t,context:{...n},isUnionType:!0});return{...te,result:{kind:"type",result:ie}}}catch(ie){return{...te,result:{kind:"error",error:ie}}}else if(W($e)&&Xe($e.value)){let ie=$e.value;try{let _e=dm({moduleExpr:o,moduleType:ie,argExprs:pe,callerEnv:t,context:{...n}});return{...te,result:{kind:"module-type",result:_e}}}catch(_e){return{...te,result:{kind:"error",error:_e}}}}else if(W($e)&&ot($e.value)){let ie=$e.value;if(pe.some(ye=>S(ye)&&E(ye,":=",2)))try{let ye=ym({traitExpr:o,traitType:ie,argExprs:pe,callerEnv:t,context:{...n}});return{...te,result:{kind:"trait-specialization",result:ye}}}catch(ye){return{...te,result:{kind:"error",error:ye}}}try{let ye=gm({traitExpr:o,traitType:ie,argExprs:pe,callerEnv:t,context:{...n}});return{...te,result:{kind:"trait-type",result:ye}}}catch(ye){return{...te,result:{kind:"error",error:ye}}}}else if(W($e)&&ne($e.value)){let ie=$e.value;try{return Zd({expr:e,functionType:ie,callerEnv:t,context:{...n}}),{...te,result:{kind:"function-type"}}}catch(_e){return{...te,result:{kind:"error",error:_e}}}}else if(W($e)&&Je($e.value)){let ie=$e.value;try{return Xd({expr:e,arrayType:ie,argExprs:pe,callerEnv:t,context:{...n}}),{...te,result:{kind:"array-type"}}}catch(_e){return{...te,result:{kind:"error",error:_e}}}}else if(W($e)&&sn($e.value)){let ie=$e.value;try{return em({expr:e,comptimeListType:ie,argExprs:pe,callerEnv:t,context:{...n}}),{...te,result:{kind:"array-type"}}}catch(_e){return{...te,result:{kind:"error",error:_e}}}}else if(W($e)&&(z($e.value)||st($e.value))){let ie=$e.value,_e=Kn(ie);if(_e)try{return Jd({expr:e,fnModuleType:_e,wrapperType:ie,callerEnv:t,context:{...n}}),{...te,result:{kind:"closure-type"}}}catch(ye){return{...te,result:{kind:"error",error:ye}}}else if(z(ie)&&ie.kindFunctionType)try{let ye=ie.kindFunctionType,Re=[];if(pe.length!==ye.parameters.length)throw d({token:o.token,errorMessage:`Type constructor "${ie.name}" expects ${ye.parameters.length} argument(s), got ${pe.length}`});for(let Z=0;Z<pe.length;Z++){let X=pe[Z],he=O({expr:X,env:t,context:{...n}});if(!he.$)throw d({token:X.token,errorMessage:"Failed to evaluate HKT argument"});if(t=he.$.env,!W(he.$.value))throw d({token:X.token,errorMessage:`Expected type argument for type constructor "${ie.name}", got:
|
|
11578
|
+
${I(X)}`});Re.push(he.$.value.value)}let Ke=oc(ie,Re,ye.return.type,t),Pe=Te(Ke);return e.$={env:t,type:dn(Ke),value:Pe,pathCollection:[]},{...te,result:{kind:"type",result:{values:[Pe],pathCollection:[],runtimeArgExprsInOrder:[],callerEnv:t}}}}catch(ye){return{...te,result:{kind:"error",error:ye}}}else if(z(ie)&&ie.recursiveTypeRef)try{let ye=[];for(let Re of pe){let Ke=O({expr:Re,env:t,context:{...n}});if(!Ke.$)throw d({token:Re.token,errorMessage:"Failed to evaluate argument"});t=Ke.$.env,ye.push(Ke)}return{...te,result:{kind:"type",result:{values:ye.map(Re=>Re.$.value),pathCollection:[],runtimeArgExprsInOrder:ye,callerEnv:t}}}}catch(ye){return{...te,result:{kind:"error",error:ye}}}else return{...te,result:{kind:"error",error:d({token:o.token,errorMessage:`Invalid function call on type:
|
|
11579
11579
|
${W($e)?M($e.value):M(te.type)}`})}}}else if(Je(te.type)||$t(te.type)||!W($e)&&_m({concreteType:te.type,argExprs:pe,callerEnv:t,_context:n})){try{let ie=um({expr:e,valueType:te.type,selfValue:te.value,argExprs:pe,callerEnv:t,context:{...n}});return{...te,result:{kind:"index",result:ie}}}catch{}if(Je(te.type)||$t(te.type)){let _e=te.type.childType;return{...te,result:{kind:"index",result:{value:void 0,type:_e,ptrType:yn(_e),indexMethodType:void 0,indexMethodValue:void 0,callerEnv:t}}}}return{...te,result:{kind:"error",error:d({token:o.token,errorMessage:`Index trait dispatch failed for type: ${M(te.type)}`})}}}else if(W($e)&&is($e.value)){let ie=$e.value;if(pe.length!==1)return{...te,result:{kind:"error",error:d({token:o.token,errorMessage:`Numeric type conversion expects exactly 1 argument, got ${pe.length}`})}};try{let _e=md({targetType:ie,argExpr:pe[0],expr:e,callerEnv:t,context:{...n}});return _e?{...te,result:{kind:"numeric-type",result:_e}}:{...te,result:{kind:"error",error:d({token:o.token,errorMessage:`Failed to convert to numeric type ${M(ie)}`})}}}catch(_e){return{...te,result:{kind:"error",error:_e}}}}else if(W($e)&&je($e.value)){let ie=$e.value;if(pe.length!==1)return{...te,result:{kind:"error",error:d({token:o.token,errorMessage:`Pointer type casting expects exactly 1 argument, got ${pe.length}`})}};try{let _e=mm({targetType:ie,argExpr:pe[0],expr:e,callerEnv:t,context:{...n}});return _e?{...te,result:{kind:"pointer-type",result:_e}}:{...te,result:{kind:"error",error:d({token:o.token,errorMessage:`Failed to cast to pointer type ${M(ie)}`})}}}catch(_e){return{...te,result:{kind:"error",error:_e}}}}else if(W($e)&&hn($e.value)){let ie=$e.value;if(pe.length!==1)return{...te,result:{kind:"error",error:d({token:o.token,errorMessage:`Iso value constructor expects exactly 1 argument, got ${pe.length}`})}};try{let _e=pm({expr:e,env:t,context:{...n},isoType:ie});return{...te,result:{kind:"iso-value",result:_e}}}catch(_e){return{...te,result:{kind:"error",error:_e}}}}else return{...te,result:{kind:"error",error:d({token:o.token,errorMessage:`Invalid function call on type:
|
|
11580
11580
|
${W($e)?M($e.value):M(te.type)}`})}}}}),p=f.filter(te=>te.result.kind!=="error"),m=a.some(te=>{var pe;return((pe=te.$)==null?void 0:pe.value)&&Ie(te.$.value)&&te.$.value.isRuntimeOnly}),h=p.filter(te=>ne(te.type)&&te.type.return.isCompileTimeOnly);if(m&&h.length>0?p=p.filter(te=>!h.includes(te)):h.length===1&&(p=h),p.length>1){let te=p.filter(pe=>ne(pe.type)?pe.type.parameters.some(ie=>rn(ie.type)||En(ie.type)||on(ie.type)):!1);te.length===1&&(p=te)}if(p.length===0){if(f.length===1&&f[0].result.kind==="error"){let te=f[0].result.error;throw te instanceof pr?Qt([{token:e.token,errorMessage:`Failed to call the function:
|
|
11581
11581
|
|
|
@@ -11593,8 +11593,8 @@ ${I(e)}
|
|
|
11593
11593
|
Found ${p.length} matching calls:
|
|
11594
11594
|
${p.map(te=>`${M(te.type)}`).join(`
|
|
11595
11595
|
`)}
|
|
11596
|
-
`});let y=p[0];if(n.isInFunctionCallCheckingPhase&&u){let te=y.type,{returnType:pe}=Io({functionType:te,calleeEnv:te.env,context:{...n,isEvaluatingFunctionType:!0},functionCalleeExpr:o});return t=Ot(t),e.$={env:t,type:pe,value:oe(pe,{variableName:"checking_phase_placeholder_"+mt(t.modulePath),env:t,context:n}),pathCollection:[]},e}if(i)if(ne(y.type)&&y.type.return.isUnquote){let{returnValue:te,callerEnv:pe,pathCollection:$e,deferredDropExpressions:ie}=to({functionValue:va(y.value),functionType:y.type,expr:e,functionCalleeExpr:o,argExprs:y.args??a,callerEnv:t,context:n,isMethodCall:!!s});return t=Ot(pe),e.$={env:t,type:Mn(),value:te,originType:Mn(),pathCollection:$e,deferredDropExpressions:ie},e}else throw d({token:o.token,errorMessage:"Expected macro function call for macro_expand."});if(ne(y.type)){let te=y.type;{let{returnType:pe,returnValue:$e,callerEnv:ie,pathCollection:_e,specializedFunctionValue:ye,runtimeArgExprsInOrder:Re,deferredDropExpressions:Ke}=to({functionValue:va(y.value),functionType:y.type,expr:e,functionCalleeExpr:o,argExprs:y.args??a,callerEnv:t,context:n,isMethodCall:!!s});if(t=Ot(ie),te.return.isUnquote)if(Dn($e)){let
|
|
11597
|
-
${pt($e)}`});let Pe=(B=e.$)==null?void 0:B.variableName,Z=pe;if(z(pe))if(y.value&&
|
|
11596
|
+
`});let y=p[0];if(n.isInFunctionCallCheckingPhase&&u){let te=y.type,{returnType:pe}=Io({functionType:te,calleeEnv:te.env,context:{...n,isEvaluatingFunctionType:!0},functionCalleeExpr:o});return t=Ot(t),e.$={env:t,type:pe,value:oe(pe,{variableName:"checking_phase_placeholder_"+mt(t.modulePath),env:t,context:n}),pathCollection:[]},e}if(i)if(ne(y.type)&&y.type.return.isUnquote){let{returnValue:te,callerEnv:pe,pathCollection:$e,deferredDropExpressions:ie}=to({functionValue:va(y.value),functionType:y.type,expr:e,functionCalleeExpr:o,argExprs:y.args??a,callerEnv:t,context:n,isMethodCall:!!s});return t=Ot(pe),e.$={env:t,type:Mn(),value:te,originType:Mn(),pathCollection:$e,deferredDropExpressions:ie},e}else throw d({token:o.token,errorMessage:"Expected macro function call for macro_expand."});if(ne(y.type)){let te=y.type;{let{returnType:pe,returnValue:$e,callerEnv:ie,pathCollection:_e,specializedFunctionValue:ye,runtimeArgExprsInOrder:Re,deferredDropExpressions:Ke}=to({functionValue:va(y.value),functionType:y.type,expr:e,functionCalleeExpr:o,argExprs:y.args??a,callerEnv:t,context:n,isMethodCall:!!s});if(t=Ot(ie),te.return.isUnquote)if(Dn($e)){let he=O({expr:$e.value,env:t,context:{...n}});return e.$={env:((N=he.$)==null?void 0:N.env)||t,type:((x=he.$)==null?void 0:x.type)||pe,value:(V=he.$)==null?void 0:V.value,originType:((U=he.$)==null?void 0:U.originType)||((R=he.$)==null?void 0:R.type)||pe,pathCollection:((D=he.$)==null?void 0:D.pathCollection)||[],macroExpansion:he,variableName:(H=he.$)==null?void 0:H.variableName},e}else throw d({token:e.token,errorMessage:`Expected macro function to return an Expr value, got:
|
|
11597
|
+
${pt($e)}`});let Pe=(B=e.$)==null?void 0:B.variableName,Z=pe;if(z(pe))if(y.value&&ge(y.value)){let he=y.value.body;if((G=he.$)!=null&&G.type){let Ce=he.$.type;z(Ce)&&Ce.resolvedConcreteType&&(Ce=Ce.resolvedConcreteType),Z={...pe,resolvedConcreteType:Ce}}}else ne(y.type)&&((Q=y.type.return)!=null&&Q.type)&&!z(y.type.return.type)&&(Z={...pe,resolvedConcreteType:y.type.return.type});if(e.$={env:t,type:Z,value:$e,originType:Z,pathCollection:_e,runtimeArgExprsInOrder:Re,deferredDropExpressions:Ke,variableName:Pe},te.ioBuiltin==="io_async"&&Re[0]){let he=Re[0],Ce=(Y=he.$)==null?void 0:Y.closureFunctionValue;if((se=(J=Ce==null?void 0:Ce.body)==null?void 0:J.$)!=null&&se.awaitAnalysis){e.$.awaitAnalysis=Ce.body.$.awaitAnalysis,e.$.captureType=(ve=he.$)==null?void 0:ve.captureType,e.$.deferredDupExpressions=(re=he.$)==null?void 0:re.deferredDupExpressions,(ce=he.$)!=null&&ce.deferredDupExpressions&&(he.$.deferredDupExpressions=void 0);let Ee=(we=he.$)==null?void 0:we.captureType;if(Ee&&e.$.awaitAnalysis){let Oe=new Set(Ee.fields.map(Ue=>Ue.label));e.$.awaitAnalysis={...e.$.awaitAnalysis,capturedVariables:e.$.awaitAnalysis.capturedVariables.map(Ue=>Oe.has(Ue.name)?{...Ue,kind:"outer"}:Ue)}}Ce.isIoAsyncStateMachineClosure=!0}else(Se=he.$)!=null&&Se.deferredDupExpressions&&(he.$.deferredDupExpressions=void 0);let He=(Ve=he.$)==null?void 0:Ve.variableName;if(He&&e.$.env){let Ee=ae(e.$.env,He),Oe=Ee[Ee.length-1];Oe&&(e.$.env=bt(e.$.env,Oe,{...Oe,consumedAtToken:e.token}))}}It(e,!0);let X=S(o);o.$={env:t,type:y.type,value:ye||y.value,pathCollection:[],runtimeArgExprsInOrder:(de=o.$)==null?void 0:de.runtimeArgExprsInOrder,deferredDropExpressions:(ee=o.$)==null?void 0:ee.deferredDropExpressions,variableName:X?(fe=o.$)==null?void 0:fe.variableName:void 0},s&&(s.$={env:t,type:y.type,value:ye||y.value,pathCollection:[]})}return e}else if((z(y.type)||st(y.type))&&Kn(y.type)){let te=Kn(y.type),{returnType:pe,returnValue:$e,callerEnv:ie,pathCollection:_e,specializedFunctionValue:ye,runtimeArgExprsInOrder:Re,deferredDropExpressions:Ke}=to({functionValue:va(y.value),functionType:te.isFn.callType,expr:e,functionCalleeExpr:o,argExprs:y.args??a,callerEnv:t,context:n,isMethodCall:!!s});if(t=Ot(ie),te.isFn.callType.return.isUnquote)if(Dn($e)){let Z=O({expr:$e.value,env:t,context:{...n}});return e.$={env:((me=Z.$)==null?void 0:me.env)||t,type:((Le=Z.$)==null?void 0:Le.type)||pe,value:(qe=Z.$)==null?void 0:qe.value,originType:((dt=Z.$)==null?void 0:dt.originType)||((kt=Z.$)==null?void 0:kt.type)||pe,pathCollection:((Rt=Z.$)==null?void 0:Rt.pathCollection)||[],macroExpansion:Z},e}else throw d({token:e.token,errorMessage:`Expected macro closure to return an Expr value, got:
|
|
11598
11598
|
${pt($e)}`});e.$={env:t,type:pe,value:$e,originType:pe,pathCollection:_e,runtimeArgExprsInOrder:Re,deferredDropExpressions:Ke},It(e,!0);let Pe=S(o);return o.$={env:t,type:y.type,value:ye||y.value,pathCollection:[],runtimeArgExprsInOrder:(Ze=o.$)==null?void 0:Ze.runtimeArgExprsInOrder,deferredDropExpressions:(Tt=o.$)==null?void 0:Tt.deferredDropExpressions,variableName:Pe?(Jt=o.$)==null?void 0:Jt.variableName:void 0},s&&(s.$={env:t,type:y.type,value:ye||y.value,pathCollection:[]}),e}else{let te=y.value;if(W(te)&&Ae(te.value)){let pe=te.value;e.$={env:t,type:pe,originType:pe,pathCollection:[]};let{values:$e,pathCollection:ie,callerEnv:_e,runtimeArgExprsInOrder:ye}=as(y);if(t=_e,!$e)throw d({token:o.token,errorMessage:"Error evaluating struct call."});let Re=$e.some(Ke=>!Ke||Ie(Ke)&&Ke.isRuntimeOnly)?void 0:Ur(pe,$e);return e.$.value=en(pe)?void 0:Re,e.$.pathCollection=ie,e.$.env=t,e.$.runtimeArgExprsInOrder=ye,It(e,!0),o.$={env:t,type:te.type,value:te,pathCollection:[]},e}else if(W(te)&&Be(te.value)){let pe=te.value;e.$={env:t,type:pe,originType:pe,pathCollection:[]};let $e=pe.variants.find(Ke=>Ke.name===pe.selectedVariantName);if(!$e)throw d({token:e.token,errorMessage:"Enum variant not selected for enum type"});let{values:ie,pathCollection:_e,callerEnv:ye,runtimeArgExprsInOrder:Re}=as(y);if(t=ye,ie.every(Ke=>!!Ke&&!(Ie(Ke)&&Ke.isRuntimeOnly))){let Ke=uo(pe,$e.name,ie);e.$.value=Ke}return e.$.pathCollection=_e,e.$.env=t,e.$.runtimeArgExprsInOrder=Re,It(e,!0),o.$={env:t,type:te.type,value:te,pathCollection:[]},e}else if(W(te)&&Bt(te.value)){let pe=te.value;e.$={env:t,type:pe,originType:pe,pathCollection:[]};let{pathCollection:$e,callerEnv:ie,runtimeArgExprsInOrder:_e}=as(y);return t=ie,e.$.value=void 0,e.$.pathCollection=$e,e.$.env=t,e.$.runtimeArgExprsInOrder=_e,It(e,!0),o.$={env:t,type:te.type,value:te,pathCollection:[]},e}else if(W(te)&&Xe(te.value)){let{moduleValue:pe,callerEnv:$e}=Gd(y);return t=$e,e.$={env:t,type:pe.type,value:pe,originType:pe.type,pathCollection:[]},o.$={env:t,type:te.type,value:te,pathCollection:[]},e}else if(W(te)&&ot(te.value)){if(y.result.kind==="trait-specialization"){let ie=y.result.result;t=ie.callerEnv;let _e=Te(ie.specializedTraitType);return e.$={env:t,type:_e.type,value:_e,pathCollection:[]},o.$={env:t,type:te.type,value:te,pathCollection:[]},e}let{traitValue:pe,callerEnv:$e}=Wd(y);return t=$e,e.$={env:t,type:pe.type,value:pe,originType:pe.type,pathCollection:[]},o.$={env:t,type:te.type,value:te,pathCollection:[]},e}else{if(W(te)&&ne(te.value))return e;if(W(te)&&Je(te.value))return e;if(W(te)&&sn(te.value))return e;if(W(te)&&(z(te.value)||st(te.value))){if(y.result.kind==="type"&&z(te.value)&&te.value.recursiveTypeRef){let pe=te.value;e.$={env:t,type:pe,originType:pe,pathCollection:[]};let{pathCollection:$e,callerEnv:ie,runtimeArgExprsInOrder:_e}=as(y);return t=ie,e.$.value=void 0,e.$.pathCollection=$e,e.$.env=t,e.$.runtimeArgExprsInOrder=_e,It(e,!0),o.$={env:t,type:te.type,value:te,pathCollection:[]},e}return e}else{if(W(te)&&is(te.value))return e;if(W(te)&&je(te.value))return e;if(W(te)&&hn(te.value))return e;if(y.result.kind==="index"){let{value:pe,type:$e,ptrType:ie,indexMethodType:_e,indexMethodValue:ye,callerEnv:Re,index:Ke,comptimeRef:Pe}=qd(y),Z=((At=o.$)==null?void 0:At.pathCollection)??[];return a.length===1&&typeof Ke=="number"&&(Z.length>0?Z=Z.map(X=>[...X,Ke.toString()]):(gt=o.$)!=null&>.variableName&&(Z=[[o.$.variableName,Ke.toString()]])),e.$={env:Re,type:$e,value:pe,originType:((nt=o.$)==null?void 0:nt.originType)??y.type,pathCollection:Z,sourceVariable:(Ft=o.$)==null?void 0:Ft.sourceVariable,indexTraitPtrType:ie,indexMethodType:_e,indexMethodValue:ye,comptimeRef:Pe,isAccessingProperty:!0},o.$={env:t,type:y.type,value:y.value,pathCollection:((qt=o.$)==null?void 0:qt.pathCollection)??[],isAccessingProperty:!0,runtimeArgExprsInOrder:(Et=o.$)==null?void 0:Et.runtimeArgExprsInOrder,deferredDropExpressions:(Lt=o.$)==null?void 0:Lt.deferredDropExpressions,variableName:(nn=o.$)==null?void 0:nn.variableName},It(e,!1),e}}}}throw d({token:e.token,errorMessage:`Function call is not implemented yet:
|
|
11599
11599
|
${I(e)}`})}function yT(e){var i;if(!((i=e.$)!=null&&i.type)||!ut(e.$.type))throw d({token:e.token,errorMessage:`Expected tuple type for drop generation:
|
|
11600
11600
|
${I(e)}`});if(!e.$.variableName)throw d({token:e.token,errorMessage:`Expected variable name for drop generation:
|
|
@@ -11656,7 +11656,7 @@ ${I(m)}`});if(so(h.$.type)){let y=h.$.value;w_(y)&&y.elements.every(g=>Dn(g))&&(
|
|
|
11656
11656
|
${I(m)}`})}else a.push(ls({expr:u,env:t,context:{...n}}))}return{...e,func:o,args:a}}}}function Im({expr:e,env:t,context:n}){Ge(e,P.quote,1);let r=ls({expr:e.args[0],env:t,context:{...n}}),i=Hn(r);return e.$={env:t,type:i.type,value:i,pathCollection:[]},e}function Am({expr:e,env:t,context:n}){if(e.args.length!==1&&e.args.length!==2)throw d({token:e.token,errorMessage:`"macro_expand" expects 1 or 2 arguments, but got ${e.args.length}`});let r=e.args[0],i=O({expr:r,env:t,context:{...n}});if(!i.$)throw d({token:r.token,errorMessage:`Failed to evaluate the argument expression for "macro_expand":
|
|
11657
11657
|
${r.toString()}`});if(t=i.$.env,!$n(i.$.type))throw d({token:r.token,errorMessage:`The argument expression for "macro_expand" must be an Expr value, but got: ${M(i.$.type)}`});let o=null;if(e.args.length===2){let s=e.args[1],l=O({expr:s,env:t,context:{...n}});if(!l.$)throw d({token:s.token,errorMessage:`Failed to evaluate the level argument expression for "macro_expand":
|
|
11658
11658
|
${s.toString()}`});if(!rn(l.$.type))throw d({token:s.token,errorMessage:`The level argument for "macro_expand" must be a comptime_int value, but got: ${M(l.$.type)}`});if(!yr(l.$.value))throw d({token:s.token,errorMessage:'The level argument for "macro_expand" must be a comptime_int value'});let u=l.$.value.value;if(o=typeof u=="bigint"?Number(u):u,o<0)throw d({token:s.token,errorMessage:`The level argument for "macro_expand" must be non-negative, but got: ${o}`})}let a=i.$.value;if(Dn(a)){let s=a.value,l=t,u=0;for(;S(s)&&(o===null||u<o);)try{let _=Mr({expr:s,env:l,context:{...n},forMacroExpansion:!0});if(!_.$)break;if(l=_.$.env,Dn(_.$.value)){let c=_.$.value.value;if(I(c)===I(s))break;s=c,u++}else break}catch(_){if(_ instanceof pr&&_.isAssertionError)throw _;break}s=ls({expr:s,env:l,context:{...n}}),e.$={env:l,type:Mn(),value:Hn(s),pathCollection:i.$.pathCollection}}else e.$={env:t,type:i.$.type,value:i.$.value,pathCollection:i.$.pathCollection};return e}function Sm({expr:e,env:t,context:n}){var i,o;if(((i=n.isEvaluatingFunctionBodyOrAsyncBlock)==null?void 0:i.kind)!=="function-body"&&((o=n.isEvaluatingFunctionBodyOrAsyncBlock)==null?void 0:o.kind)!=="test-block")throw d({token:e.token,errorMessage:"panic() can only be called inside a function body or test block"});if(n.isAnalyzingCtfeCapability)throw d({token:e.token,errorMessage:'Cannot use "panic" during compile-time function evaluation analysis. Functions containing "panic" cannot be evaluated at compile time.'});let r=n.isEvaluatingFunctionBodyOrAsyncBlock.kind==="function-body"?n.isEvaluatingFunctionBodyOrAsyncBlock.type.return.type:ue.type;if(e.args.length>0){let a=e.args[0],s=O({expr:a,env:t,context:{...n}});if(!s.$)throw d({token:a.token,errorMessage:"Failed to evaluate panic message"});let l=s.$.type,u=s.$.value,_=l&&hr(l)&&l.typeName==="str",c=u&&(tt(u)||Ie(u)&&on(u.type));if(!_&&!c)throw d({token:a.token,errorMessage:"panic message must be a comptime_string or str"})}return e.$={env:t,type:r,value:void 0,pathCollection:[]},e}var xm=new Set(["reg","reg_byte","reg_abcd","xmm_reg","ymm_reg","imm","mem"]),i_=new Set(["in"]),o_=new Set(["out","lateout"]),Dm=new Set(["inout","inlateout"]),Mm=new Set(["const_val","sym"]),TT=new Set([...i_,...o_,...Dm,...Mm,"clobber","clobber_abi","asm_options"]),Nm=new Set(["pure","nomem","readonly","nostack","preserves_flags","att_syntax","intel_syntax","volatile","noreturn"]);function r_(e){return ai(e)||si(e)||je(e)||lr(e)}function ET(e){return e.tag==="Atom"&&xm.has(e.token.value)}function $T(e){return!S(e)||e.func.tag!=="Atom"?!1:TT.has(e.func.token.value)}function Vm(e){return e.tag==="Atom"&&e.token.value==="_"}function CT(e,t,n){var i,o;if(e.tag==="Atom"&&xm.has(e.token.value))return e.token.value;let r=O({expr:e,env:t,context:{...n}});if((i=r.$)!=null&&i.value&&tt(r.$.value))return r.$.value.value;if(E(e,"raw",1)){let s=e.args[0],l=O({expr:s,env:t,context:{...n}});if((o=l.$)!=null&&o.value&&tt(l.$.value))return`raw:${l.$.value.value}`}throw d({token:e.token,errorMessage:'Invalid asm constraint. Expected a register class (reg, imm, mem, ...), an explicit register name string, or raw("constraint").'})}function bT(e,t,n,r){var h,y;let i=e.args;if(r==="const_val"||r==="sym")return kT(e,t,n,r);if(i.length<1||i.length>3)throw d({token:e.token,errorMessage:`asm ${r}() expects 1 to 3 arguments, got ${i.length}.`});let o,a;if(i.length>=2){let g=i[0];if(ET(g))a=0;else if(Vm(g))a=0;else{let v=O({expr:g,env:t,context:{...n}});(h=v.$)!=null&&h.value&&tt(v.$.value)?(o=v.$.value.value,a=1):a=0}}else a=0;let s=a<i.length-1,l,u;s?(l=CT(i[a],t,n),u=a+1):(o!==void 0&&(l=o),u=a);let _=i[u];if(!_)throw d({token:e.token,errorMessage:`asm ${r}() is missing its value/type argument.`});let c=i_.has(r);if(o_.has(r)){if(Vm(_))return{kind:r,name:o,constraint:l,valueExpr:void 0,outputType:void 0,targetVarName:void 0,discarded:!0};if(_.tag==="Atom"){let v=_.token.value,T=ae(t,v);if(T.length>0){let $=T[T.length-1];if(!($.value&&W($.value[0]))){let C=$.type;if(!r_(C))throw d({token:_.token,errorMessage:`asm ${r}() target variable '${v}' has type that is not valid for inline assembly. Must be a primitive numeric, pointer, or bool type.`});let k;return $.initializedAtToken?k=O({expr:_,env:t,context:{...n}}):(k=_,k.$={env:t,type:C,value:void 0,pathCollection:[]}),{kind:r,name:o,constraint:l,valueExpr:k,outputType:C,targetVarName:v,discarded:!1}}}}let g=O({expr:_,env:t,context:{...n}});if((y=g.$)!=null&&y.value&&W(g.$.value)){let v=g.$.value.value;if(!r_(v))throw d({token:_.token,errorMessage:`asm ${r}() output type must be a primitive numeric, pointer, or bool type.`});return{kind:r,name:o,constraint:l,valueExpr:void 0,outputType:v,targetVarName:void 0,discarded:!1}}throw d({token:_.token,errorMessage:`asm ${r}() last argument must be a type, variable, or _ (discard).`})}let p=O({expr:_,env:t,context:{...n}});if(!p.$)throw d({token:_.token,errorMessage:`Failed to evaluate asm ${r}() value expression.`});let m=p.$.type;if(!r_(m))throw d({token:_.token,errorMessage:`asm ${r}() value type is not valid for inline assembly. Must be a primitive numeric, pointer, or bool type.`});return c?{kind:r,name:o,constraint:l,valueExpr:p,outputType:void 0,targetVarName:void 0,discarded:!1}:{kind:r,name:o,constraint:l,valueExpr:p,outputType:m,targetVarName:void 0,discarded:!1}}function kT(e,t,n,r){var u;let i=e.args;if(i.length<1||i.length>2)throw d({token:e.token,errorMessage:`asm ${r}() expects 1 or 2 arguments, got ${i.length}.`});let o,a=0;if(i.length===2){let _=O({expr:i[0],env:t,context:{...n}});(u=_.$)!=null&&u.value&&tt(_.$.value)&&(o=_.$.value.value,a=1)}let s=i[a],l=O({expr:s,env:t,context:{...n}});return{kind:r,name:o,constraint:void 0,valueExpr:l,outputType:void 0,targetVarName:void 0,discarded:!1}}function wT(e,t,n){let r={noreturn:!1};for(let i of e.args)if(i.tag==="Atom"){let o=i.token.value;if(!Nm.has(o))throw d({token:i.token,errorMessage:`Unknown asm_options flag: '${o}'. Valid flags: ${[...Nm].join(", ")}.`});o==="noreturn"&&(r.noreturn=!0)}else throw d({token:e.token,errorMessage:"asm_options() arguments must be flag identifiers (e.g., pure, nomem, noreturn)."});return r}function Om({expr:e,env:t,context:n}){var m,h,y,g,v,T;if(((m=n.isEvaluatingFunctionBodyOrAsyncBlock)==null?void 0:m.kind)!=="function-body"&&((h=n.isEvaluatingFunctionBodyOrAsyncBlock)==null?void 0:h.kind)!=="test-block")throw d({token:e.token,errorMessage:"asm() can only be called inside a function body or test block."});if(n.isAnalyzingCtfeCapability)throw d({token:e.token,errorMessage:'Cannot use "asm" during compile-time function evaluation analysis.'});if(e.args.length===0)throw d({token:e.token,errorMessage:"asm() requires at least one argument (the assembly template string)."});let r=[],i=0;for(;i<e.args.length;){let $=e.args[i];if($T($))break;let C=O({expr:$,env:t,context:{...n}});if((y=C.$)!=null&&y.value&&tt(C.$.value))r.push(C.$.value.value),i++;else if((g=C.$)!=null&&g.value&&Ie(C.$.value)&&on(C.$.value.type))r.push(""),i++;else break}if(r.length===0)throw d({token:e.args[0].token,errorMessage:"First argument to asm() must be a compile-time string (the assembly template)."});let o=[],a={noreturn:!1};for(;i<e.args.length;){let $=e.args[i];if(!S($))throw d({token:$.token,errorMessage:"asm() arguments after the template must be operand or option calls (in, out, inout, clobber, asm_options, etc.)."});let C=$.func.tag==="Atom"?$.func.token.value:void 0;if(!C)throw d({token:$.token,errorMessage:"asm() operand must be a named call like in(...), out(...), etc."});if(i_.has(C)||o_.has(C)||Dm.has(C)||Mm.has(C))o.push(bT($,t,n,C));else if(C==="clobber"||C==="clobber_abi")for(let k of $.args){if(k.tag==="Atom"&&(k.token.value==="memory"||k.token.value==="cc"))continue;let b=O({expr:k,env:t,context:{...n}});if((!((v=b.$)!=null&&v.value)||!tt(b.$.value))&&!(k.tag==="Atom"&&k.token.value==="memory")&&!(k.tag==="Atom"&&k.token.value==="cc"))throw d({token:k.token,errorMessage:`${C}() arguments must be compile-time strings (e.g., "memory", "cc", "rax").`})}else if(C==="asm_options")a=wT($,t,n);else throw d({token:$.token,errorMessage:`Unknown asm() operand or option: '${C}'. Expected: in, out, inout, lateout, inlateout, const_val, sym, clobber, clobber_abi, asm_options.`});i++}let s=t;for(let $ of o){if($.targetVarName===void 0||$.kind!=="out"&&$.kind!=="lateout")continue;let C=ae(s,$.targetVarName);if(C.length>0){let k=C[C.length-1];k.initializedAtToken||(s=bt(s,k,{...k,initializedAtToken:e.token}))}}t=s;let l=[];for(let $ of o)$.discarded||$.targetVarName===void 0&&($.kind==="const_val"||$.kind==="sym"||$.kind!=="in"&&$.outputType&&l.push($.outputType));let u;if(a.noreturn)u=((T=n.isEvaluatingFunctionBodyOrAsyncBlock)==null?void 0:T.kind)==="function-body"?n.isEvaluatingFunctionBodyOrAsyncBlock.type.return.type:ue.type;else if(l.length===0)u=ue.type;else if(l.length===1)u=l[0];else{let $=l.map((C,k)=>({label:k.toString(),type:C,exprs:{expr:e,labelExpr:void 0,typeExpr:void 0,defaultValueExpr:void 0,assignedValueExpr:void 0}}));u=ta($)}let _=r.join(`
|
|
11659
|
-
`),c=/\{([^}:]+)(?::[^}]*)?\}/g,f,p=new Set;for(let $=0;$<o.length;$++)if(o[$].name){if(p.has(o[$].name))throw d({token:e.token,errorMessage:`Duplicate asm operand name: '${o[$].name}'.`});p.add(o[$].name)}for(;(f=c.exec(_))!==null;){let $=f[1];if($==="{"||$==="}")continue;let C=parseInt($,10);if(isNaN(C)){if(!p.has($))throw d({token:e.token,errorMessage:`asm template references undefined operand '{${$}}'.`})}else if(C<0||C>=o.length)throw d({token:e.token,errorMessage:`asm template references positional operand {${C}} but only ${o.length} operands are defined.`})}return e.$={env:t,type:u,value:void 0,pathCollection:[]},e}function Rm({expr:e,env:t,context:n}){var o;if(e.args.length===0)throw d({token:e.token,errorMessage:"global_asm() requires at least one argument (the assembly string)."});let r=e.args[0],i=O({expr:r,env:t,context:{...n}});if(!((o=i.$)!=null&&o.value)||!tt(i.$.value)&&!(Ie(i.$.value)&&on(i.$.value.type)))throw d({token:r.token,errorMessage:"global_asm() argument must be a compile-time string."});return e.$={env:t,type:ue.type,value:void 0,pathCollection:[]},e}function Pm({expr:e,env:t}){if(E(e,F.__yo_process_platform)){if(e.args.length!==0)throw d({token:e.token,errorMessage:`__yo_process_platform expects 0 arguments, got ${e.args.length}`});let n=Xa(),r=n.os,i=wn(r);return e.$={env:t,type:Fn(),value:i,pathCollection:[]},e}if(E(e,F.__yo_process_arch)){if(e.args.length!==0)throw d({token:e.token,errorMessage:`__yo_process_arch expects 0 arguments, got ${e.args.length}`});let n=Xa(),r=n.arch,i=wn(r);return e.$={env:t,type:Fn(),value:i,pathCollection:[]},e}if(E(e,F.__yo_pointer_size_bits)){if(e.args.length!==0)throw d({token:e.token,errorMessage:`__yo_pointer_size_bits expects 0 arguments, got ${e.args.length}`});let n=Qr(),r=Pr(BigInt(n));return e.$={env:t,type:ui(),value:r,pathCollection:[]},e}throw d({token:e.token,errorMessage:`Unknown process function: ${e.func.token.value}`})}var s_=class{constructor(){this.artifacts=[];this.testSuites=[];this.runSteps=[];this.steps=[];this.dependencies=[];this.pathDependencies=[];this.systemLibraries=[];this.dependencyArtifacts=[];this.modules=[];this.docConfigs=[];this.cliOptions=new Map;this.declaredOptions=new Map}setCliOptions(t){this.cliOptions=t}registerExecutable(t){this.checkDuplicateArtifactName(t.name),this.artifacts.push({kind:"executable",...t})}registerStaticLibrary(t){this.checkDuplicateArtifactName(t.name),this.artifacts.push({kind:"static_library",...t})}registerSharedLibrary(t){this.checkDuplicateArtifactName(t.name),this.artifacts.push({kind:"shared_library",...t})}registerTest(t){this.testSuites.push(t)}registerRun(t,n){let r=`run:${t}`;this.runSteps.push({name:r,artifactName:t,args:n})}registerStep(t,n,r=[]){this.steps.push({name:t,description:n,dependencyNames:r})}addStepDependency(t,n){let r=this.findStep(t);r&&(r.dependencyNames.includes(n)||r.dependencyNames.push(n))}registerDependency(t){this.dependencies.push(t)}registerPathDependency(t){this.pathDependencies.push(t)}registerSystemLibrary(t){this.systemLibraries.push(t)}registerDependencyArtifact(t){this.dependencyArtifacts.some(n=>n.dependencyName===t.dependencyName&&n.artifactName===t.artifactName)||this.dependencyArtifacts.push(t)}registerModule(t){this.modules.some(n=>n.name===t.name)||this.modules.push(t)}registerModuleLink(t,n){let r=this.modules.find(i=>i.name===t);r&&!r.linkedSystemLibraries.includes(n)&&r.linkedSystemLibraries.push(n)}registerImportedModule(t,n){let r=this.findArtifact(t);if(r){if(r.importedModules.some(i=>i.importName===n.importName))return;r.importedModules.push(n)}}findModule(t){return this.modules.find(n=>n.name===t)}registerLink(t,n){let r=this.findArtifact(t);r&&(r.linkedArtifacts.includes(n)||r.linkedArtifacts.push(n))}findArtifact(t){return this.artifacts.find(n=>n.name===t)}findTest(t){return this.testSuites.find(n=>n.name===t)}findRunStep(t){return this.runSteps.find(n=>n.name===t)}findStep(t){return this.steps.find(n=>n.name===t)}findDocumentation(t){return this.docConfigs.find(n=>n.name===t)}registerDocumentation(t){this.docConfigs.push(t)}checkDuplicateArtifactName(t){let n=this.artifacts.find(r=>r.name===t);if(n)throw new Error(`Build error: Artifact "${t}" already registered as ${n.kind}. Use a unique name for each artifact.`)}findDependency(t){return this.dependencies.find(n=>n.name===t)}findPathDependency(t){return this.pathDependencies.find(n=>n.name===t)}findSystemLibrary(t){return this.systemLibraries.find(n=>n.name===t)}getStepNames(){return this.steps.map(t=>t.name)}resolveDependency(t){let n=this.findArtifact(t);if(n)return{kind:"artifact",value:n};let r=this.findTest(t);if(r)return{kind:"test",value:r};let i=this.findRunStep(t);if(i)return{kind:"run",value:i};let o=this.findDocumentation(t);if(o)return{kind:"doc",value:o};let a=this.findStep(t);if(a)return{kind:"step",value:a}}resolveDependencies(t){let n=[],r=[],i=[];for(let o of t.dependencyNames){let a=this.resolveDependency(o);if(a)switch(a.kind){case"artifact":n.some(s=>s.name===a.value.name)||n.push(a.value);break;case"test":r.some(s=>s.name===a.value.name)||r.push(a.value);break;case"run":i.some(s=>s.name===a.value.name)||i.push(a.value);{let s=this.findArtifact(a.value.artifactName);s&&!n.some(l=>l.name===s.name)&&n.push(s)}break;case"step":{let s=this.resolveDependencies(a.value);for(let l of s.artifacts)n.some(u=>u.name===l.name)||n.push(l);for(let l of s.tests)r.some(u=>u.name===l.name)||r.push(l);for(let l of s.runs)i.some(u=>u.name===l.name)||i.push(l);break}}}return{artifacts:n,tests:r,runs:i}}clear(){this.artifacts=[],this.testSuites=[],this.runSteps=[],this.steps=[],this.dependencies=[],this.pathDependencies=[],this.systemLibraries=[],this.dependencyArtifacts=[],this.modules=[]}},a_,FT,LT=new Map;function Um(){return FT}function zm(e){return LT.get(e)}function l_(){return a_||(a_=new s_),a_}function ct(e,t,n){if(!tt(e))throw d({token:n,errorMessage:`Build function: expected comptime_string for "${t}", got ${e?"non-string":"undefined"}`});return e.value}function ar(e,t){return e.$={env:t,type:xr(),value:ue,pathCollection:[]},e}function Ta(e,t,n){return e.$={env:t,type:Fn(),value:wn(n),pathCollection:[]},e}function IT(e){var t;for(let n of e.args){if(n===void 0)continue;let r=(t=n.$)==null?void 0:t.value;if(r===void 0||Ie(r))return!0}return!1}function Bm({expr:e,env:t}){var r,i,o,a,s,l,u,_,c,f,p,m,h,y,g,v,T,$,C,k,b,w,A,L,N,x,V,U,R,D,H,B,G,Q,Y,J,se,ve,re,ce,we,Se,Ve,de,ee,fe,me,Le,qe,dt,kt,Rt,Ze,Tt,Jt,At,gt,nt,Ft,qt,Et,Lt,nn,te,pe,$e;if(IT(e)){if(E(e,F.__yo_build_target_host)){let ie=Xi();return Ta(e,t,ie.triple)}return E(e,F.__yo_build_option)?Ta(e,t,""):ar(e,t)}let n=l_();if(E(e,F.__yo_build_executable)){if(e.args.length<2)throw d({token:e.token,errorMessage:`__yo_build_executable expects at least 2 arguments (name, root), got ${e.args.length}`});let ie=ct((r=e.args[0].$)==null?void 0:r.value,"name",e.token),_e=ct((i=e.args[1].$)==null?void 0:i.value,"root",e.token),ye=e.args.length>2?ct((o=e.args[2].$)==null?void 0:o.value,"target",e.token):Xi().triple,Re=e.args.length>3?ct((a=e.args[3].$)==null?void 0:a.value,"optimize",e.token):"debug",Ke=e.args.length>4?ct((s=e.args[4].$)==null?void 0:s.value,"allocator",e.token):"mimalloc",Pe=e.args.length>5?ct((l=e.args[5].$)==null?void 0:l.value,"sanitize",e.token):"none";return n.registerExecutable({name:ie,root:_e,target:ye,optimize:Re,allocator:Ke,sanitize:Pe,linkLibraries:[],includePaths:[],libraryPaths:[],cSources:[],cFlags:[],defines:[],strip:!1,staticLink:!1,runtimeFiles:[],linkedArtifacts:[],linkedSystemLibraries:[],importedModules:[]}),ar(e,t)}if(E(e,F.__yo_build_static_library)){if(e.args.length<2)throw d({token:e.token,errorMessage:`__yo_build_static_library expects at least 2 arguments (name, root), got ${e.args.length}`});let ie=ct((u=e.args[0].$)==null?void 0:u.value,"name",e.token),_e=ct((_=e.args[1].$)==null?void 0:_.value,"root",e.token),ye=e.args.length>2?ct((c=e.args[2].$)==null?void 0:c.value,"target",e.token):Xi().triple,Re=e.args.length>3?ct((f=e.args[3].$)==null?void 0:f.value,"optimize",e.token):"debug";return n.registerStaticLibrary({name:ie,root:_e,target:ye,optimize:Re,allocator:"libc",sanitize:"none",linkLibraries:[],includePaths:[],libraryPaths:[],cSources:[],cFlags:[],defines:[],strip:!1,staticLink:!1,runtimeFiles:[],linkedArtifacts:[],linkedSystemLibraries:[],importedModules:[]}),ar(e,t)}if(E(e,F.__yo_build_shared_library)){if(e.args.length<2)throw d({token:e.token,errorMessage:`__yo_build_shared_library expects at least 2 arguments (name, root), got ${e.args.length}`});let ie=ct((p=e.args[0].$)==null?void 0:p.value,"name",e.token),_e=ct((m=e.args[1].$)==null?void 0:m.value,"root",e.token),ye=e.args.length>2?ct((h=e.args[2].$)==null?void 0:h.value,"target",e.token):Xi().triple,Re=e.args.length>3?ct((y=e.args[3].$)==null?void 0:y.value,"optimize",e.token):"debug";return n.registerSharedLibrary({name:ie,root:_e,target:ye,optimize:Re,allocator:"libc",sanitize:"none",linkLibraries:[],includePaths:[],libraryPaths:[],cSources:[],cFlags:[],defines:[],strip:!1,staticLink:!1,runtimeFiles:[],linkedArtifacts:[],linkedSystemLibraries:[],importedModules:[]}),ar(e,t)}if(E(e,F.__yo_build_link)){if(e.args.length<2)throw d({token:e.token,errorMessage:`__yo_build_link expects 2 arguments (artifact_name, library_name), got ${e.args.length}`});let ie=ct((g=e.args[0].$)==null?void 0:g.value,"artifact_name",e.token),_e=ct((v=e.args[1].$)==null?void 0:v.value,"library_name",e.token);if(n.findSystemLibrary(_e)){let ye=n.findArtifact(ie);ye&&(ye.linkedSystemLibraries.includes(_e)||ye.linkedSystemLibraries.push(_e))}else n.registerLink(ie,_e);return ar(e,t)}if(E(e,F.__yo_build_link_system_library)){if(e.args.length<2)throw d({token:e.token,errorMessage:`__yo_build_link_system_library expects 2 arguments (artifact_name, system_lib_name), got ${e.args.length}`});let ie=ct((T=e.args[0].$)==null?void 0:T.value,"artifact_name",e.token),_e=ct(($=e.args[1].$)==null?void 0:$.value,"system_lib_name",e.token),ye=n.findArtifact(ie);return ye&&(ye.linkedSystemLibraries.includes(_e)||ye.linkedSystemLibraries.push(_e)),ar(e,t)}if(E(e,F.__yo_build_test)){if(e.args.length<2)throw d({token:e.token,errorMessage:`__yo_build_test expects at least 2 arguments (name, root), got ${e.args.length}`});let ie=ct((C=e.args[0].$)==null?void 0:C.value,"name",e.token),_e=ct((k=e.args[1].$)==null?void 0:k.value,"root",e.token),ye=e.args.length>2?ct((b=e.args[2].$)==null?void 0:b.value,"target",e.token):Xi().triple;return n.registerTest({name:ie,root:_e,target:ye,verbose:!1,bail:!1,parallel:1}),ar(e,t)}if(E(e,F.__yo_build_run)){if(e.args.length<1)throw d({token:e.token,errorMessage:`__yo_build_run expects at least 1 argument (artifact_name), got ${e.args.length}`});let ie=ct((w=e.args[0].$)==null?void 0:w.value,"artifact_name",e.token);return n.registerRun(ie,[]),ar(e,t)}if(E(e,F.__yo_build_step)){if(e.args.length<2)throw d({token:e.token,errorMessage:`__yo_build_step expects 2 arguments (name, description), got ${e.args.length}`});let ie=ct((A=e.args[0].$)==null?void 0:A.value,"name",e.token),_e=ct((L=e.args[1].$)==null?void 0:L.value,"description",e.token);return n.registerStep(ie,_e),ar(e,t)}if(E(e,F.__yo_build_doc)){if(e.args.length<10)throw d({token:e.token,errorMessage:`__yo_build_doc expects 10 arguments, got ${e.args.length}`});let ie=ct((N=e.args[0].$)==null?void 0:N.value,"name",e.token),_e=ct((x=e.args[1].$)==null?void 0:x.value,"root",e.token),ye=ct((V=e.args[2].$)==null?void 0:V.value,"output",e.token),Re=ct((U=e.args[3].$)==null?void 0:U.value,"format",e.token),Ke=!!((R=e.args[4].$)!=null&&R.value),Pe=!!((D=e.args[5].$)!=null&&D.value),Z=ct((H=e.args[6].$)==null?void 0:H.value,"title",e.token),X=ct((B=e.args[7].$)==null?void 0:B.value,"logo",e.token),ge=ct((G=e.args[8].$)==null?void 0:G.value,"favicon",e.token),Ce=ct((Q=e.args[9].$)==null?void 0:Q.value,"version",e.token);return n.registerDocumentation({name:ie,root:_e,outputDir:ye,format:Re,includePrivate:Ke,includeDeps:Pe,title:Z,logo:X,favicon:ge,version:Ce}),ar(e,t)}if(E(e,F.__yo_build_step_depend_on)){if(e.args.length<3)throw d({token:e.token,errorMessage:`__yo_build_step_depend_on expects 3 arguments (step_name, dep_name, dep_kind), got ${e.args.length}`});let ie=ct((Y=e.args[0].$)==null?void 0:Y.value,"step_name",e.token),_e=ct((J=e.args[1].$)==null?void 0:J.value,"dep_name",e.token),ye=(se=e.args[2].$)==null?void 0:se.value,Re=_e;return ye&&mn(ye)&&ye.variantName==="Run"&&(Re=`run:${_e}`),n.addStepDependency(ie,Re),ar(e,t)}if(E(e,F.__yo_build_target_host)){let ie=Xi();return Ta(e,t,ie.triple)}if(E(e,F.__yo_build_target_parse)){if(e.args.length!==1)throw d({token:e.token,errorMessage:`__yo_build_target_parse expects 1 argument (triple), got ${e.args.length}`});let ie=ct((ve=e.args[0].$)==null?void 0:ve.value,"triple",e.token),_e=Wc(ie);return Ta(e,t,_e.triple)}if(E(e,F.__yo_build_dependency)){if(e.args.length<2)throw d({token:e.token,errorMessage:`__yo_build_dependency expects at least 2 arguments (name, url), got ${e.args.length}`});let ie=ct((re=e.args[0].$)==null?void 0:re.value,"name",e.token),_e=ct((ce=e.args[1].$)==null?void 0:ce.value,"url",e.token),ye=e.args.length>2?ct((we=e.args[2].$)==null?void 0:we.value,"ref",e.token):"HEAD",Re=e.args.length>3?ct((Se=e.args[3].$)==null?void 0:Se.value,"path",e.token):"";return n.registerDependency({name:ie,url:_e,ref:ye,path:Re}),ar(e,t)}if(E(e,F.__yo_build_path_dependency)){if(e.args.length!==2)throw d({token:e.token,errorMessage:`__yo_build_path_dependency expects 2 arguments (name, path), got ${e.args.length}`});let ie=ct((Ve=e.args[0].$)==null?void 0:Ve.value,"name",e.token),_e=ct((de=e.args[1].$)==null?void 0:de.value,"path",e.token);return n.registerPathDependency({name:ie,path:_e}),ar(e,t)}if(E(e,F.__yo_build_system_library)){if(e.args.length<1)throw d({token:e.token,errorMessage:`__yo_build_system_library expects at least 1 argument (name), got ${e.args.length}`});let ie=ct((ee=e.args[0].$)==null?void 0:ee.value,"name",e.token),_e=e.args.length>1?ct((fe=e.args[1].$)==null?void 0:fe.value,"fallback_include",e.token):"",ye=e.args.length>2?ct((me=e.args[2].$)==null?void 0:me.value,"fallback_lib",e.token):"",Re=e.args.length>3?ct((Le=e.args[3].$)==null?void 0:Le.value,"fallback_link",e.token):"",Ke=e.args.length>4?ct((qe=e.args[4].$)==null?void 0:qe.value,"defines",e.token).split(/\s+/).filter(Boolean):[];return n.registerSystemLibrary({name:ie,fallbackInclude:_e,fallbackLib:ye,fallbackLink:Re,defines:Ke}),ar(e,t)}if(E(e,F.__yo_build_option)){if(e.args.length<3)throw d({token:e.token,errorMessage:`__yo_build_option expects 3 arguments (name, description, default), got ${e.args.length}`});let ie=ct((dt=e.args[0].$)==null?void 0:dt.value,"name",e.token),_e=ct((kt=e.args[1].$)==null?void 0:kt.value,"description",e.token),ye=ct((Rt=e.args[2].$)==null?void 0:Rt.value,"default",e.token);n.declaredOptions.set(ie,{description:_e,defaultValue:ye});let Re=n.cliOptions.get(ie)??ye;return Ta(e,t,Re)}if(E(e,F.__yo_build_dep_artifact)){if(e.args.length<2)throw d({token:e.token,errorMessage:`__yo_build_dep_artifact expects 2 arguments (dependency_name, artifact_name), got ${e.args.length}`});let ie=ct((Ze=e.args[0].$)==null?void 0:Ze.value,"dependency_name",e.token),_e=ct((Tt=e.args[1].$)==null?void 0:Tt.value,"artifact_name",e.token);return n.registerDependencyArtifact({dependencyName:ie,artifactName:_e}),ar(e,t)}if(E(e,F.__yo_build_module)){if(e.args.length<2)throw d({token:e.token,errorMessage:`__yo_build_module expects 2 arguments (name, root), got ${e.args.length}`});let ie=ct((Jt=e.args[0].$)==null?void 0:Jt.value,"name",e.token),_e=ct((At=e.args[1].$)==null?void 0:At.value,"root",e.token);return n.registerModule({name:ie,root:_e,linkedSystemLibraries:[]}),ar(e,t)}if(E(e,F.__yo_build_module_link)){if(e.args.length<2)throw d({token:e.token,errorMessage:`__yo_build_module_link expects 2 arguments (module_name, system_library_name), got ${e.args.length}`});let ie=ct((gt=e.args[0].$)==null?void 0:gt.value,"module_name",e.token),_e=ct((nt=e.args[1].$)==null?void 0:nt.value,"system_library_name",e.token);return n.registerModuleLink(ie,_e),ar(e,t)}if(E(e,F.__yo_build_add_import)){if(e.args.length<4)throw d({token:e.token,errorMessage:`__yo_build_add_import expects 4 arguments (artifact_name, import_name, module_name, dependency_name), got ${e.args.length}`});let ie=ct((Ft=e.args[0].$)==null?void 0:Ft.value,"artifact_name",e.token),_e=ct((qt=e.args[1].$)==null?void 0:qt.value,"import_name",e.token),ye=ct((Et=e.args[2].$)==null?void 0:Et.value,"module_name",e.token),Re=ct((Lt=e.args[3].$)==null?void 0:Lt.value,"dependency_name",e.token),Ke=n.findArtifact(ie);if(Ke){let Pe=Ke.importedModules.find(Z=>Z.importName===_e);if(Pe)throw d({token:e.token,errorMessage:`Duplicate import name "${_e}" on artifact "${ie}". Already imported from module "${Pe.moduleName}".`})}return n.registerImportedModule(ie,{importName:_e,moduleName:ye,dependencyName:Re}),ar(e,t)}if(E(e,F.__yo_build_add_cflags)){if(e.args.length<2)throw d({token:e.token,errorMessage:`__yo_build_add_cflags expects 2 arguments (artifact_name, flags), got ${e.args.length}`});let ie=ct((nn=e.args[0].$)==null?void 0:nn.value,"artifact_name",e.token),_e=ct((te=e.args[1].$)==null?void 0:te.value,"flags",e.token),ye=n.findArtifact(ie);if(ye){let Re=_e.trim().split(/\s+/).filter(Ke=>Ke.length>0);ye.cFlags.push(...Re)}return ar(e,t)}if(E(e,F.__yo_build_dep_module)){if(e.args.length<2)throw d({token:e.token,errorMessage:`__yo_build_dep_module expects 2 arguments (dependency_name, module_name), got ${e.args.length}`});let ie=ct((pe=e.args[0].$)==null?void 0:pe.value,"dependency_name",e.token),_e=ct(($e=e.args[1].$)==null?void 0:$e.value,"module_name",e.token);return Ta(e,t,`${ie}\0${_e}`)}throw d({token:e.token,errorMessage:`Unknown build function: ${e.func.token.value}`})}function Gm({expr:e,env:t,context:n}){Ge(e,F.__yo_address_of,1);let r=e.args[0],i=n.expectedType;i&&je(i.type)&&(i={...i,type:i.type.childType});let o=O({expr:r,env:t,context:{...n,expectedType:i}});if(!o.$)throw d({token:r.token,errorMessage:`Failed to evaluate the argument expression for reference:
|
|
11659
|
+
`),c=/\{([^}:]+)(?::[^}]*)?\}/g,f,p=new Set;for(let $=0;$<o.length;$++)if(o[$].name){if(p.has(o[$].name))throw d({token:e.token,errorMessage:`Duplicate asm operand name: '${o[$].name}'.`});p.add(o[$].name)}for(;(f=c.exec(_))!==null;){let $=f[1];if($==="{"||$==="}")continue;let C=parseInt($,10);if(isNaN(C)){if(!p.has($))throw d({token:e.token,errorMessage:`asm template references undefined operand '{${$}}'.`})}else if(C<0||C>=o.length)throw d({token:e.token,errorMessage:`asm template references positional operand {${C}} but only ${o.length} operands are defined.`})}return e.$={env:t,type:u,value:void 0,pathCollection:[]},e}function Rm({expr:e,env:t,context:n}){var o;if(e.args.length===0)throw d({token:e.token,errorMessage:"global_asm() requires at least one argument (the assembly string)."});let r=e.args[0],i=O({expr:r,env:t,context:{...n}});if(!((o=i.$)!=null&&o.value)||!tt(i.$.value)&&!(Ie(i.$.value)&&on(i.$.value.type)))throw d({token:r.token,errorMessage:"global_asm() argument must be a compile-time string."});return e.$={env:t,type:ue.type,value:void 0,pathCollection:[]},e}function Pm({expr:e,env:t}){if(E(e,F.__yo_process_platform)){if(e.args.length!==0)throw d({token:e.token,errorMessage:`__yo_process_platform expects 0 arguments, got ${e.args.length}`});let n=Xa(),r=n.os,i=wn(r);return e.$={env:t,type:Fn(),value:i,pathCollection:[]},e}if(E(e,F.__yo_process_arch)){if(e.args.length!==0)throw d({token:e.token,errorMessage:`__yo_process_arch expects 0 arguments, got ${e.args.length}`});let n=Xa(),r=n.arch,i=wn(r);return e.$={env:t,type:Fn(),value:i,pathCollection:[]},e}if(E(e,F.__yo_pointer_size_bits)){if(e.args.length!==0)throw d({token:e.token,errorMessage:`__yo_pointer_size_bits expects 0 arguments, got ${e.args.length}`});let n=Qr(),r=Pr(BigInt(n));return e.$={env:t,type:ui(),value:r,pathCollection:[]},e}throw d({token:e.token,errorMessage:`Unknown process function: ${e.func.token.value}`})}var s_=class{constructor(){this.artifacts=[];this.testSuites=[];this.runSteps=[];this.steps=[];this.dependencies=[];this.pathDependencies=[];this.systemLibraries=[];this.dependencyArtifacts=[];this.modules=[];this.docConfigs=[];this.cliOptions=new Map;this.declaredOptions=new Map}setCliOptions(t){this.cliOptions=t}registerExecutable(t){this.checkDuplicateArtifactName(t.name),this.artifacts.push({kind:"executable",...t})}registerStaticLibrary(t){this.checkDuplicateArtifactName(t.name),this.artifacts.push({kind:"static_library",...t})}registerSharedLibrary(t){this.checkDuplicateArtifactName(t.name),this.artifacts.push({kind:"shared_library",...t})}registerTest(t){this.testSuites.push(t)}registerRun(t,n){let r=`run:${t}`;this.runSteps.push({name:r,artifactName:t,args:n})}registerStep(t,n,r=[]){this.steps.push({name:t,description:n,dependencyNames:r})}addStepDependency(t,n){let r=this.findStep(t);r&&(r.dependencyNames.includes(n)||r.dependencyNames.push(n))}registerDependency(t){this.dependencies.push(t)}registerPathDependency(t){this.pathDependencies.push(t)}registerSystemLibrary(t){this.systemLibraries.push(t)}registerDependencyArtifact(t){this.dependencyArtifacts.some(n=>n.dependencyName===t.dependencyName&&n.artifactName===t.artifactName)||this.dependencyArtifacts.push(t)}registerModule(t){this.modules.some(n=>n.name===t.name)||this.modules.push(t)}registerModuleLink(t,n){let r=this.modules.find(i=>i.name===t);r&&!r.linkedSystemLibraries.includes(n)&&r.linkedSystemLibraries.push(n)}registerImportedModule(t,n){let r=this.findArtifact(t);if(r){if(r.importedModules.some(i=>i.importName===n.importName))return;r.importedModules.push(n)}}findModule(t){return this.modules.find(n=>n.name===t)}registerLink(t,n){let r=this.findArtifact(t);r&&(r.linkedArtifacts.includes(n)||r.linkedArtifacts.push(n))}findArtifact(t){return this.artifacts.find(n=>n.name===t)}findTest(t){return this.testSuites.find(n=>n.name===t)}findRunStep(t){return this.runSteps.find(n=>n.name===t)}findStep(t){return this.steps.find(n=>n.name===t)}findDocumentation(t){return this.docConfigs.find(n=>n.name===t)}registerDocumentation(t){this.docConfigs.push(t)}checkDuplicateArtifactName(t){let n=this.artifacts.find(r=>r.name===t);if(n)throw new Error(`Build error: Artifact "${t}" already registered as ${n.kind}. Use a unique name for each artifact.`)}findDependency(t){return this.dependencies.find(n=>n.name===t)}findPathDependency(t){return this.pathDependencies.find(n=>n.name===t)}findSystemLibrary(t){return this.systemLibraries.find(n=>n.name===t)}getStepNames(){return this.steps.map(t=>t.name)}resolveDependency(t){let n=this.findArtifact(t);if(n)return{kind:"artifact",value:n};let r=this.findTest(t);if(r)return{kind:"test",value:r};let i=this.findRunStep(t);if(i)return{kind:"run",value:i};let o=this.findDocumentation(t);if(o)return{kind:"doc",value:o};let a=this.findStep(t);if(a)return{kind:"step",value:a}}resolveDependencies(t){let n=[],r=[],i=[];for(let o of t.dependencyNames){let a=this.resolveDependency(o);if(a)switch(a.kind){case"artifact":n.some(s=>s.name===a.value.name)||n.push(a.value);break;case"test":r.some(s=>s.name===a.value.name)||r.push(a.value);break;case"run":i.some(s=>s.name===a.value.name)||i.push(a.value);{let s=this.findArtifact(a.value.artifactName);s&&!n.some(l=>l.name===s.name)&&n.push(s)}break;case"step":{let s=this.resolveDependencies(a.value);for(let l of s.artifacts)n.some(u=>u.name===l.name)||n.push(l);for(let l of s.tests)r.some(u=>u.name===l.name)||r.push(l);for(let l of s.runs)i.some(u=>u.name===l.name)||i.push(l);break}}}return{artifacts:n,tests:r,runs:i}}clear(){this.artifacts=[],this.testSuites=[],this.runSteps=[],this.steps=[],this.dependencies=[],this.pathDependencies=[],this.systemLibraries=[],this.dependencyArtifacts=[],this.modules=[]}},a_,FT,LT=new Map;function Um(){return FT}function zm(e){return LT.get(e)}function l_(){return a_||(a_=new s_),a_}function ct(e,t,n){if(!tt(e))throw d({token:n,errorMessage:`Build function: expected comptime_string for "${t}", got ${e?"non-string":"undefined"}`});return e.value}function ar(e,t){return e.$={env:t,type:xr(),value:ue,pathCollection:[]},e}function Ta(e,t,n){return e.$={env:t,type:Fn(),value:wn(n),pathCollection:[]},e}function IT(e){var t;for(let n of e.args){if(n===void 0)continue;let r=(t=n.$)==null?void 0:t.value;if(r===void 0||Ie(r))return!0}return!1}function Bm({expr:e,env:t}){var r,i,o,a,s,l,u,_,c,f,p,m,h,y,g,v,T,$,C,k,b,w,A,L,N,x,V,U,R,D,H,B,G,Q,Y,J,se,ve,re,ce,we,Se,Ve,de,ee,fe,me,Le,qe,dt,kt,Rt,Ze,Tt,Jt,At,gt,nt,Ft,qt,Et,Lt,nn,te,pe,$e;if(IT(e)){if(E(e,F.__yo_build_target_host)){let ie=Xi();return Ta(e,t,ie.triple)}return E(e,F.__yo_build_option)?Ta(e,t,""):ar(e,t)}let n=l_();if(E(e,F.__yo_build_executable)){if(e.args.length<2)throw d({token:e.token,errorMessage:`__yo_build_executable expects at least 2 arguments (name, root), got ${e.args.length}`});let ie=ct((r=e.args[0].$)==null?void 0:r.value,"name",e.token),_e=ct((i=e.args[1].$)==null?void 0:i.value,"root",e.token),ye=e.args.length>2?ct((o=e.args[2].$)==null?void 0:o.value,"target",e.token):Xi().triple,Re=e.args.length>3?ct((a=e.args[3].$)==null?void 0:a.value,"optimize",e.token):"debug",Ke=e.args.length>4?ct((s=e.args[4].$)==null?void 0:s.value,"allocator",e.token):"mimalloc",Pe=e.args.length>5?ct((l=e.args[5].$)==null?void 0:l.value,"sanitize",e.token):"none";return n.registerExecutable({name:ie,root:_e,target:ye,optimize:Re,allocator:Ke,sanitize:Pe,linkLibraries:[],includePaths:[],libraryPaths:[],cSources:[],cFlags:[],defines:[],strip:!1,staticLink:!1,runtimeFiles:[],linkedArtifacts:[],linkedSystemLibraries:[],importedModules:[]}),ar(e,t)}if(E(e,F.__yo_build_static_library)){if(e.args.length<2)throw d({token:e.token,errorMessage:`__yo_build_static_library expects at least 2 arguments (name, root), got ${e.args.length}`});let ie=ct((u=e.args[0].$)==null?void 0:u.value,"name",e.token),_e=ct((_=e.args[1].$)==null?void 0:_.value,"root",e.token),ye=e.args.length>2?ct((c=e.args[2].$)==null?void 0:c.value,"target",e.token):Xi().triple,Re=e.args.length>3?ct((f=e.args[3].$)==null?void 0:f.value,"optimize",e.token):"debug";return n.registerStaticLibrary({name:ie,root:_e,target:ye,optimize:Re,allocator:"libc",sanitize:"none",linkLibraries:[],includePaths:[],libraryPaths:[],cSources:[],cFlags:[],defines:[],strip:!1,staticLink:!1,runtimeFiles:[],linkedArtifacts:[],linkedSystemLibraries:[],importedModules:[]}),ar(e,t)}if(E(e,F.__yo_build_shared_library)){if(e.args.length<2)throw d({token:e.token,errorMessage:`__yo_build_shared_library expects at least 2 arguments (name, root), got ${e.args.length}`});let ie=ct((p=e.args[0].$)==null?void 0:p.value,"name",e.token),_e=ct((m=e.args[1].$)==null?void 0:m.value,"root",e.token),ye=e.args.length>2?ct((h=e.args[2].$)==null?void 0:h.value,"target",e.token):Xi().triple,Re=e.args.length>3?ct((y=e.args[3].$)==null?void 0:y.value,"optimize",e.token):"debug";return n.registerSharedLibrary({name:ie,root:_e,target:ye,optimize:Re,allocator:"libc",sanitize:"none",linkLibraries:[],includePaths:[],libraryPaths:[],cSources:[],cFlags:[],defines:[],strip:!1,staticLink:!1,runtimeFiles:[],linkedArtifacts:[],linkedSystemLibraries:[],importedModules:[]}),ar(e,t)}if(E(e,F.__yo_build_link)){if(e.args.length<2)throw d({token:e.token,errorMessage:`__yo_build_link expects 2 arguments (artifact_name, library_name), got ${e.args.length}`});let ie=ct((g=e.args[0].$)==null?void 0:g.value,"artifact_name",e.token),_e=ct((v=e.args[1].$)==null?void 0:v.value,"library_name",e.token);if(n.findSystemLibrary(_e)){let ye=n.findArtifact(ie);ye&&(ye.linkedSystemLibraries.includes(_e)||ye.linkedSystemLibraries.push(_e))}else n.registerLink(ie,_e);return ar(e,t)}if(E(e,F.__yo_build_link_system_library)){if(e.args.length<2)throw d({token:e.token,errorMessage:`__yo_build_link_system_library expects 2 arguments (artifact_name, system_lib_name), got ${e.args.length}`});let ie=ct((T=e.args[0].$)==null?void 0:T.value,"artifact_name",e.token),_e=ct(($=e.args[1].$)==null?void 0:$.value,"system_lib_name",e.token),ye=n.findArtifact(ie);return ye&&(ye.linkedSystemLibraries.includes(_e)||ye.linkedSystemLibraries.push(_e)),ar(e,t)}if(E(e,F.__yo_build_test)){if(e.args.length<2)throw d({token:e.token,errorMessage:`__yo_build_test expects at least 2 arguments (name, root), got ${e.args.length}`});let ie=ct((C=e.args[0].$)==null?void 0:C.value,"name",e.token),_e=ct((k=e.args[1].$)==null?void 0:k.value,"root",e.token),ye=e.args.length>2?ct((b=e.args[2].$)==null?void 0:b.value,"target",e.token):Xi().triple;return n.registerTest({name:ie,root:_e,target:ye,verbose:!1,bail:!1,parallel:1}),ar(e,t)}if(E(e,F.__yo_build_run)){if(e.args.length<1)throw d({token:e.token,errorMessage:`__yo_build_run expects at least 1 argument (artifact_name), got ${e.args.length}`});let ie=ct((w=e.args[0].$)==null?void 0:w.value,"artifact_name",e.token);return n.registerRun(ie,[]),ar(e,t)}if(E(e,F.__yo_build_step)){if(e.args.length<2)throw d({token:e.token,errorMessage:`__yo_build_step expects 2 arguments (name, description), got ${e.args.length}`});let ie=ct((A=e.args[0].$)==null?void 0:A.value,"name",e.token),_e=ct((L=e.args[1].$)==null?void 0:L.value,"description",e.token);return n.registerStep(ie,_e),ar(e,t)}if(E(e,F.__yo_build_doc)){if(e.args.length<10)throw d({token:e.token,errorMessage:`__yo_build_doc expects 10 arguments, got ${e.args.length}`});let ie=ct((N=e.args[0].$)==null?void 0:N.value,"name",e.token),_e=ct((x=e.args[1].$)==null?void 0:x.value,"root",e.token),ye=ct((V=e.args[2].$)==null?void 0:V.value,"output",e.token),Re=ct((U=e.args[3].$)==null?void 0:U.value,"format",e.token),Ke=!!((R=e.args[4].$)!=null&&R.value),Pe=!!((D=e.args[5].$)!=null&&D.value),Z=ct((H=e.args[6].$)==null?void 0:H.value,"title",e.token),X=ct((B=e.args[7].$)==null?void 0:B.value,"logo",e.token),he=ct((G=e.args[8].$)==null?void 0:G.value,"favicon",e.token),Ce=ct((Q=e.args[9].$)==null?void 0:Q.value,"version",e.token);return n.registerDocumentation({name:ie,root:_e,outputDir:ye,format:Re,includePrivate:Ke,includeDeps:Pe,title:Z,logo:X,favicon:he,version:Ce}),ar(e,t)}if(E(e,F.__yo_build_step_depend_on)){if(e.args.length<3)throw d({token:e.token,errorMessage:`__yo_build_step_depend_on expects 3 arguments (step_name, dep_name, dep_kind), got ${e.args.length}`});let ie=ct((Y=e.args[0].$)==null?void 0:Y.value,"step_name",e.token),_e=ct((J=e.args[1].$)==null?void 0:J.value,"dep_name",e.token),ye=(se=e.args[2].$)==null?void 0:se.value,Re=_e;return ye&&mn(ye)&&ye.variantName==="Run"&&(Re=`run:${_e}`),n.addStepDependency(ie,Re),ar(e,t)}if(E(e,F.__yo_build_target_host)){let ie=Xi();return Ta(e,t,ie.triple)}if(E(e,F.__yo_build_target_parse)){if(e.args.length!==1)throw d({token:e.token,errorMessage:`__yo_build_target_parse expects 1 argument (triple), got ${e.args.length}`});let ie=ct((ve=e.args[0].$)==null?void 0:ve.value,"triple",e.token),_e=Wc(ie);return Ta(e,t,_e.triple)}if(E(e,F.__yo_build_dependency)){if(e.args.length<2)throw d({token:e.token,errorMessage:`__yo_build_dependency expects at least 2 arguments (name, url), got ${e.args.length}`});let ie=ct((re=e.args[0].$)==null?void 0:re.value,"name",e.token),_e=ct((ce=e.args[1].$)==null?void 0:ce.value,"url",e.token),ye=e.args.length>2?ct((we=e.args[2].$)==null?void 0:we.value,"ref",e.token):"HEAD",Re=e.args.length>3?ct((Se=e.args[3].$)==null?void 0:Se.value,"path",e.token):"";return n.registerDependency({name:ie,url:_e,ref:ye,path:Re}),ar(e,t)}if(E(e,F.__yo_build_path_dependency)){if(e.args.length!==2)throw d({token:e.token,errorMessage:`__yo_build_path_dependency expects 2 arguments (name, path), got ${e.args.length}`});let ie=ct((Ve=e.args[0].$)==null?void 0:Ve.value,"name",e.token),_e=ct((de=e.args[1].$)==null?void 0:de.value,"path",e.token);return n.registerPathDependency({name:ie,path:_e}),ar(e,t)}if(E(e,F.__yo_build_system_library)){if(e.args.length<1)throw d({token:e.token,errorMessage:`__yo_build_system_library expects at least 1 argument (name), got ${e.args.length}`});let ie=ct((ee=e.args[0].$)==null?void 0:ee.value,"name",e.token),_e=e.args.length>1?ct((fe=e.args[1].$)==null?void 0:fe.value,"fallback_include",e.token):"",ye=e.args.length>2?ct((me=e.args[2].$)==null?void 0:me.value,"fallback_lib",e.token):"",Re=e.args.length>3?ct((Le=e.args[3].$)==null?void 0:Le.value,"fallback_link",e.token):"",Ke=e.args.length>4?ct((qe=e.args[4].$)==null?void 0:qe.value,"defines",e.token).split(/\s+/).filter(Boolean):[];return n.registerSystemLibrary({name:ie,fallbackInclude:_e,fallbackLib:ye,fallbackLink:Re,defines:Ke}),ar(e,t)}if(E(e,F.__yo_build_option)){if(e.args.length<3)throw d({token:e.token,errorMessage:`__yo_build_option expects 3 arguments (name, description, default), got ${e.args.length}`});let ie=ct((dt=e.args[0].$)==null?void 0:dt.value,"name",e.token),_e=ct((kt=e.args[1].$)==null?void 0:kt.value,"description",e.token),ye=ct((Rt=e.args[2].$)==null?void 0:Rt.value,"default",e.token);n.declaredOptions.set(ie,{description:_e,defaultValue:ye});let Re=n.cliOptions.get(ie)??ye;return Ta(e,t,Re)}if(E(e,F.__yo_build_dep_artifact)){if(e.args.length<2)throw d({token:e.token,errorMessage:`__yo_build_dep_artifact expects 2 arguments (dependency_name, artifact_name), got ${e.args.length}`});let ie=ct((Ze=e.args[0].$)==null?void 0:Ze.value,"dependency_name",e.token),_e=ct((Tt=e.args[1].$)==null?void 0:Tt.value,"artifact_name",e.token);return n.registerDependencyArtifact({dependencyName:ie,artifactName:_e}),ar(e,t)}if(E(e,F.__yo_build_module)){if(e.args.length<2)throw d({token:e.token,errorMessage:`__yo_build_module expects 2 arguments (name, root), got ${e.args.length}`});let ie=ct((Jt=e.args[0].$)==null?void 0:Jt.value,"name",e.token),_e=ct((At=e.args[1].$)==null?void 0:At.value,"root",e.token);return n.registerModule({name:ie,root:_e,linkedSystemLibraries:[]}),ar(e,t)}if(E(e,F.__yo_build_module_link)){if(e.args.length<2)throw d({token:e.token,errorMessage:`__yo_build_module_link expects 2 arguments (module_name, system_library_name), got ${e.args.length}`});let ie=ct((gt=e.args[0].$)==null?void 0:gt.value,"module_name",e.token),_e=ct((nt=e.args[1].$)==null?void 0:nt.value,"system_library_name",e.token);return n.registerModuleLink(ie,_e),ar(e,t)}if(E(e,F.__yo_build_add_import)){if(e.args.length<4)throw d({token:e.token,errorMessage:`__yo_build_add_import expects 4 arguments (artifact_name, import_name, module_name, dependency_name), got ${e.args.length}`});let ie=ct((Ft=e.args[0].$)==null?void 0:Ft.value,"artifact_name",e.token),_e=ct((qt=e.args[1].$)==null?void 0:qt.value,"import_name",e.token),ye=ct((Et=e.args[2].$)==null?void 0:Et.value,"module_name",e.token),Re=ct((Lt=e.args[3].$)==null?void 0:Lt.value,"dependency_name",e.token),Ke=n.findArtifact(ie);if(Ke){let Pe=Ke.importedModules.find(Z=>Z.importName===_e);if(Pe)throw d({token:e.token,errorMessage:`Duplicate import name "${_e}" on artifact "${ie}". Already imported from module "${Pe.moduleName}".`})}return n.registerImportedModule(ie,{importName:_e,moduleName:ye,dependencyName:Re}),ar(e,t)}if(E(e,F.__yo_build_add_cflags)){if(e.args.length<2)throw d({token:e.token,errorMessage:`__yo_build_add_cflags expects 2 arguments (artifact_name, flags), got ${e.args.length}`});let ie=ct((nn=e.args[0].$)==null?void 0:nn.value,"artifact_name",e.token),_e=ct((te=e.args[1].$)==null?void 0:te.value,"flags",e.token),ye=n.findArtifact(ie);if(ye){let Re=_e.trim().split(/\s+/).filter(Ke=>Ke.length>0);ye.cFlags.push(...Re)}return ar(e,t)}if(E(e,F.__yo_build_dep_module)){if(e.args.length<2)throw d({token:e.token,errorMessage:`__yo_build_dep_module expects 2 arguments (dependency_name, module_name), got ${e.args.length}`});let ie=ct((pe=e.args[0].$)==null?void 0:pe.value,"dependency_name",e.token),_e=ct(($e=e.args[1].$)==null?void 0:$e.value,"module_name",e.token);return Ta(e,t,`${ie}\0${_e}`)}throw d({token:e.token,errorMessage:`Unknown build function: ${e.func.token.value}`})}function Gm({expr:e,env:t,context:n}){Ge(e,F.__yo_address_of,1);let r=e.args[0],i=n.expectedType;i&&je(i.type)&&(i={...i,type:i.type.childType});let o=O({expr:r,env:t,context:{...n,expectedType:i}});if(!o.$)throw d({token:r.token,errorMessage:`Failed to evaluate the argument expression for reference:
|
|
11660
11660
|
${I(r)}`});if(t=o.$.env,W(o.$.value))throw d({token:r.token,errorMessage:`Cannot create a pointer to a type. Did you mean to use "*"?
|
|
11661
11661
|
${I(r)}`});{let a=o.$.type;if(rn(a)||En(a)||on(a)){let _=an({type:a,expectedType:i==null?void 0:i.type,expr:o,env:t});o.$.type=_,o.$.convertedRuntimeType=_,a=_}let s=yn(a),l=o.$.sourceVariable,u=o.$.comptimeRef;if(u){let _;switch(u.kind){case"array":_=Bi(s,[u.arrayValue],u.index);break;case"comptime_list":_=Bi(s,[u.listValue],u.index);break;case"struct":_=Bi(s,[u.structValue],u.fieldIndex);break;case"tuple":_=Bi(s,[u.tupleValue],u.fieldIndex);break}e.$={env:t,type:s,value:_,pathCollection:o.$.pathCollection,comptimeRef:u}}else if(l&&l.value){let _=Bi(s,l.value);e.$={env:t,type:s,value:_,pathCollection:o.$.pathCollection}}else{let _=o.$.indexTraitPtrType;if(_)e.$={env:t,type:_,value:void 0,pathCollection:o.$.pathCollection,isIndexTraitAddressOf:!0};else if(Ie(o.$.value)){let c=oe(s,{env:t,context:n});e.$={env:t,type:s,value:c,pathCollection:o.$.pathCollection}}else e.$={env:t,type:s,value:void 0,pathCollection:o.$.pathCollection}}return It(e,!1),e}}function Wm({expr:e,env:t,context:n}){Ge(e,F.rc,1);let r=e.args[0],i=O({expr:r,env:t,context:{...n}});if(!i.$)throw d({token:r.token,errorMessage:"Failed to evaluate expression."});return t=i.$.env,rr(i.$.type)?e.$={env:t,type:vn(),value:void 0,pathCollection:[]}:e.$={env:t,type:vn(),value:qn("Usize",1),pathCollection:[]},e}function qm({expr:e,env:t,context:n}){Ge(e,F.sizeof,1);let r=e.args[0],i=O({expr:r,env:t,context:{...n}});if(!i.$)throw d({token:r.token,errorMessage:"Failed to evaluate expression."});t=i.$.env;let o;i.$.value&&W(i.$.value)?o=i.$.value.value:o=i.$.type;let a=Yi(o),s;return a===null?s=oe(vn(),{env:t,context:n}):s=qn("Usize",Math.ceil(a/8)),e.$={env:t,type:vn(),value:s,pathCollection:[]},e}function Pi({expr:e,type:t,env:n,context:r}){var i,o,a,s,l,u,_,c,f,p;if(ut(t)&&S(e)&&E(e,P.tuple)){if(t.fields.length!==e.args.length)throw d({token:e.token,errorMessage:`Tuple size mismatch: expected ${t.fields.length} fields, got ${e.args.length}`});for(let m=0;m<t.fields.length;m++){let h=t.fields[m].type,y=e.args[m],{env:g}=Pi({expr:y,type:h,env:n,context:{...r}});n=g}return e.$={env:n,type:t,pathCollection:[]},{expr:e,type:t,env:n}}else if(S(e)&&E(e,"_"))if(Ae(t)||Bt(t)||Xe(t)||ot(t)){let m=Mr({expr:e,env:n,givenFunc:{type:dn(t),value:Te(t)},context:{...r}});if(!((i=m.$)!=null&&i.type)||!((o=m.$)!=null&&o.env))throw d({token:e.token,errorMessage:`Failed to evaluate expr and type for struct:
|
|
11662
11662
|
${I(e)}`});return{expr:m,type:(a=m.$)==null?void 0:a.type,env:(s=m.$)==null?void 0:s.env}}else throw d({token:e.token,errorMessage:`Cannot use _ with type ${M(t)}. Only supported with struct types.`});else if(S(e)&&E(e,".",1))if(Be(t)){let m=e.args[0];if(!K(m))throw d({token:e.token,errorMessage:`Expected identifier for enum variant, got ${I(m)}`});let h=m.token.value;if(!t.variants.find(v=>v.name===h))throw d({token:e.token,errorMessage:`Enum variant "${h}" not found in ${M(t)}`});let g={...t,selectedVariantName:h};return e.$={type:g,env:n,pathCollection:[]},{expr:e,type:g,env:n}}else throw d({token:e.token,errorMessage:`Cannot use . with type ${M(t)}. Only supported with enum types.`});else if(S(e)&&S(e.func)&&E(e.func,".",1))if(Be(t)){let m=e.func,h=m.args[0];if(!K(h))throw d({token:m.token,errorMessage:`Expected identifier for enum variant, got ${I(h)}`});let y=h.token.value;if(!t.variants.find($=>$.name===y))throw d({token:e.token,errorMessage:`Enum variant "${y}" not found in ${M(t)}`});let v={...t,selectedVariantName:y},T=Mr({expr:e,env:n,givenFunc:{type:dn(v),value:Te(v)},context:{...r}});if(!((l=T.$)!=null&&l.type)||!((u=T.$)!=null&&u.env))throw d({token:e.token,errorMessage:`Failed to evaluate expr and type for enum variant:
|
|
@@ -11679,9 +11679,9 @@ ${I(r)}`});let i=r.$.value;if(!i||!W(i))throw d({token:r.token,errorMessage:`Exp
|
|
|
11679
11679
|
${I(r)}`});t=r.$.env;let o=i.value,a=O({expr:e.args[1],env:t,context:{...n}});if(!a.$)throw d({token:a.token,errorMessage:`Failed to evaluate the trait argument for "${e.func.token.value}":
|
|
11680
11680
|
${I(a)}`});let s;if(W(a.$.value)){let u=a.$.value;if(!ot(u.value))throw d({token:a.token,errorMessage:`Expected trait type for second argument of "${e.func.token.value}", got a non-trait type`});s=u.value}else if(ot(a.$.type))s=a.$.type;else{if(St(a.$.type))return e.$={env:a.$.env,type:Ut(),value:oe(Ut(),{env:a.$.env,context:n}),pathCollection:[],isAccessingProperty:!1},e;throw d({token:a.token,errorMessage:`Expected trait type for second argument of "${e.func.token.value}", got:
|
|
11681
11681
|
${I(a)}`})}t=a.$.env;let l=Zt(bn({targetType:o,traitType:s,env:t}));return e.$={env:t,type:l.type,value:l,pathCollection:[],isAccessingProperty:!1},e}function AT({expr:e,env:t,context:n,builtinName:r}){let i=O({expr:e.args[0],env:t,context:{...n}});if(!i.$||!W(i.$.value))throw d({token:e.args[0].token,errorMessage:`${r}: expected a Type argument, got: ${I(e.args[0])}`});return{type:i.$.value.value,env:i.$.env}}function ST(e){switch(e){case"unit":return"Unit";case"bool":return"Bool";case"usize":return"Usize";case"isize":return"Isize";case"u8":return"U8";case"i8":return"I8";case"u16":return"U16";case"i16":return"I16";case"u32":return"U32";case"i32":return"I32";case"u64":return"U64";case"i64":return"I64";case"f32":return"F32";case"f64":return"F64";case"comptime_int":return"ComptimeInt";case"comptime_float":return"ComptimeFloat";case"comptime_string":return"ComptimeString";case"char":return"Char";case"short":return"Short";case"ushort":return"UShort";case"int":return"Int";case"uint":return"UInt";case"long":return"Long";case"ulong":return"ULong";case"longlong":return"LongLong";case"ulonglong":return"ULongLong";case"longdouble":return"LongDouble";case"void":return"Void";case"Type":return"Type";case"Array":return"Array";case"Tuple":return"Tuple";case"Struct":return"Struct";case"Enum":return"Enum";case"Union":return"Union";case"Function":return"Function";case"SomeType":return"Some";case"Slice":return"Slice";case"Module":return"Module";case"Trait":return"Trait";case"Ptr":return"Ptr";case"Iso":return"Iso";case"Dyn":return"Dyn";case"Expr":return"Expr";case"ComptimeList":return"ComptimeList";case"EffectsRow":return"EffectsRow";case"TypeApplication":return"TypeApplication";default:throw new Error(`Unknown TypeTag: ${e}`)}}function ey({expr:e,env:t,context:n}){let{type:r,env:i}=AT({expr:e,env:t,context:n,builtinName:"__yo_type_get_info"});if(z(r)){let u=Dt("TypeInfo.Unit"),_=O({expr:u,env:i,context:{...n,forceCompileTimeBindings:!0}});if(_.$){let c=oe(_.$.type,{env:i,context:n});e.$={env:i,type:c.type,value:c,pathCollection:[]}}return e}let o,a=i;switch(r.tag){case"unit":case"bool":case"usize":case"isize":case"u8":case"i8":case"u16":case"i16":case"u32":case"i32":case"u64":case"i64":case"f32":case"f64":case"comptime_int":case"comptime_float":case"comptime_string":case"char":case"short":case"ushort":case"int":case"uint":case"long":case"ulong":case"longlong":case"ulonglong":case"longdouble":case"void":case"Expr":case"EffectsRow":case"TypeApplication":{o=`TypeInfo.${ST(r.tag)}`;break}case"Array":{let u=r,_=Sr(a,u.childType,n);a=_.env;let c=u.length,f;ht(c)?f=String(c.value):f="0",o=`TypeInfo.Array(${_.name}, ${f})`;break}case"Slice":{let _=Sr(a,r.childType,n);a=_.env,o=`TypeInfo.Slice(${_.name})`;break}case"Ptr":{let _=Sr(a,r.childType,n);a=_.env,o=`TypeInfo.Ptr(${_.name})`;break}case"Iso":{let _=Sr(a,r.childType,n);a=_.env,o=`TypeInfo.Iso(${_.name})`;break}case"ComptimeList":{let _=Sr(a,r.childType,n);a=_.env,o=`TypeInfo.ComptimeList(${_.name})`;break}case"Type":{o=`TypeInfo.Type(${r.level})`;break}case"Struct":{let u=r,_=_s(a,u.fields,n);a=_.env;let c;u.isNewtype?c="StructKind.NewType":u.isAtomicRc?c="StructKind.AtomicObject":u.isReferenceSemantics?c="StructKind.Object":c="StructKind.Struct",o=`TypeInfo.Struct(${_.name}, ${c})`;break}case"Enum":{let _=VT(a,r,n);a=_.env,o=`TypeInfo.Enum(${_.name})`;break}case"Union":{let _=_s(a,r.fields,n);a=_.env,o=`TypeInfo.Union(${_.name})`;break}case"Tuple":{let _=_s(a,r.fields,n);a=_.env,o=`TypeInfo.Tuple(${_.name})`;break}case"Function":{let _=ty(a,r,n);a=_.env,o=`TypeInfo.Function(${_.name})`;break}case"Module":{let _=OT(a,r.fields,n);a=_.env,o=`TypeInfo.Module(${_.name})`;break}case"Trait":{let u=r,_=RT(a,u,n);a=_.env;let c=PT(a,u,n);a=c.env,o=`TypeInfo.Trait(${_.name}, ${c.name})`;break}case"Dyn":{let u=r,_=us(a,u.requiredTraits.map(f=>f.traitType),n,"req");a=_.env;let c=us(a,u.negativeTraits.map(f=>f.traitType),n,"neg");a=c.env,o=`TypeInfo.Dyn(${_.name}, ${c.name})`;break}case"SomeType":{let u=r,_=JSON.stringify(u.name),c=us(a,u.requiredTraits.map(m=>m.traitType),n,"req");a=c.env;let f=us(a,u.negativeTraits.map(m=>m.traitType),n,"neg");a=f.env;let p;u.resolvedConcreteType?p=Sr(a,u.resolvedConcreteType,n):p={name:"unit",env:a},a=p.env,o=`TypeInfo.SomeType(${_}, ${c.name}, ${f.name}, ${p.name})`;break}default:throw d({token:e.token,errorMessage:`__yo_type_get_info: unsupported type tag: ${r.tag}`})}let s=Dt(o),l=O({expr:s,env:a,context:{...n,forceCompileTimeBindings:!0}});if(!l.$||!l.$.value)throw d({token:e.token,errorMessage:`__yo_type_get_info: failed to create TypeInfo for type tag: ${r.tag}`});return e.$={env:i,type:l.$.type,value:l.$.value,pathCollection:[]},e}function Sr(e,t,n){let r=`__ti_t_${cn(e.modulePath,"tit")}`,i=Te(t);return e=Ei({env:e,name:r,type:i.type,value:i}),{name:r,env:e}}function _s(e,t,n){let r=[];for(let i of t){let o=NT(e,i,n);e=o.env,r.push(o.value)}return Ao(e,r,"TypeFieldInfo","fl",n)}function NT(e,t,n){let r=`__ti_fi_${cn(e.modulePath,"tifi")}`,i=Sr(e,t.type,n);e=i.env;let a=`TypeFieldInfo(${JSON.stringify(t.label)}, ${i.name})`,s=Dt(a),l=O({expr:s,env:e,context:{...n,forceCompileTimeBindings:!0}});if(!l.$||!l.$.value)throw new Error(`Failed to create TypeFieldInfo for field "${t.label}"`);let u=l.$.value;return e=Ei({env:e,name:r,type:l.$.type,value:u}),{name:r,env:e,value:u}}function VT(e,t,n){let r=[];for(let i=0;i<t.variants.length;i++){let o=t.variants[i],a=sy(e,o.name,o.fields??[],t,i,n);e=a.env,r.push(a.value)}return Ao(e,r,"VariantInfo","vl",n)}function ty(e,t,n){let r=`__ti_fni_${cn(e.modulePath,"tifni")}`,i=xT(e,t.parameters,t.variadicParameter,n);e=i.env;let o=Sr(e,t.return.type,n);e=o.env;let a=DT(e,t.forallParameters,n);e=a.env;let s=MT(e,t.implicitParameters,n);e=s.env;let l=t.isClosure?"true":"false",u=`FunctionInfo(${i.name}, ${o.name}, ${a.name}, ${s.name}, ${l})`,_=Dt(u),c=O({expr:_,env:e,context:{...n,forceCompileTimeBindings:!0}});if(!c.$||!c.$.value)throw new Error("Failed to create FunctionInfo");return e=Ei({env:e,name:r,type:c.$.type,value:c.$.value}),{name:r,env:e}}function xT(e,t,n,r){let i=[],o=n?[...t,n]:t;for(let a of o){let s=Sr(e,a.type,r);e=s.env;let l=JSON.stringify(a.label),u=a.isCompileTimeOnly?"true":"false",_=a.isQuote?"true":"false",c=a===n?"true":"false",f=`ParamInfo(${l}, ${s.name}, ${u}, ${_}, ${c})`,p=Dt(f),m=O({expr:p,env:e,context:{...r,forceCompileTimeBindings:!0}});if(!m.$||!m.$.value)throw new Error(`Failed to create ParamInfo for param "${a.label}"`);e=m.$.env,i.push(m.$.value)}return Ao(e,i,"ParamInfo","pl",r)}function DT(e,t,n){let r=[];for(let i of t){let o=Sr(e,i.type,n);e=o.env;let s=`ForallParamInfo(${JSON.stringify(i.label)}, ${o.name})`,l=Dt(s),u=O({expr:l,env:e,context:{...n,forceCompileTimeBindings:!0}});if(!u.$||!u.$.value)throw new Error(`Failed to create ForallParamInfo for param "${i.label}"`);e=u.$.env,r.push(u.$.value)}return Ao(e,r,"ForallParamInfo","fpl",n)}function MT(e,t,n){let r=[];for(let i of t){let o=Sr(e,i.type,n);e=o.env;let s=`ImplicitParamInfo(${JSON.stringify(i.label)}, ${o.name})`,l=Dt(s),u=O({expr:l,env:e,context:{...n,forceCompileTimeBindings:!0}});if(!u.$||!u.$.value)throw new Error(`Failed to create ImplicitParamInfo for param "${i.label}"`);e=u.$.env,r.push(u.$.value)}return Ao(e,r,"ImplicitParamInfo","ipl",n)}function OT(e,t,n){let r=t.map(i=>({type:i.type,label:i.label}));return _s(e,r,n)}function RT(e,t,n){let r=[];for(let i of t.fields){let o=Sr(e,i.type,n);e=o.env;let a=JSON.stringify(i.label),s=i.unassignedSomeType?"true":"false",l=`TraitFieldInfo(${a}, ${o.name}, ${s})`,u=Dt(l),_=O({expr:u,env:e,context:{...n,forceCompileTimeBindings:!0}});if(!_.$||!_.$.value)throw new Error(`Failed to create TraitFieldInfo for field "${i.label}"`);e=_.$.env,r.push(_.$.value)}return Ao(e,r,"TraitFieldInfo","tfl",n)}function PT(e,t,n){let r=`__ti_tk_${cn(e.modulePath,"titk")}`,i;if(t.isFuture){let s=Sr(e,t.isFuture.outputType,n);e=s.env;let l=t.isFuture.effects.map(_=>_.type),u=us(e,l,n,"eff");e=u.env,i=`TraitKind.Future(${s.name}, ${u.name})`}else if(t.isFn){let s=ty(e,t.isFn.callType,n);e=s.env,i=`TraitKind.Fn(${s.name})`}else i="TraitKind.Normal";let o=Dt(i),a=O({expr:o,env:e,context:{...n,forceCompileTimeBindings:!0}});if(!a.$||!a.$.value)throw new Error("Failed to create TraitKind");return e=Ei({env:e,name:r,type:a.$.type,value:a.$.value}),{name:r,env:e}}function us(e,t,n,r){let i=[];for(let o of t){let a=Sr(e,o,n);e=a.env;let s=`TraitInfo(${a.name})`,l=Dt(s),u=O({expr:l,env:e,context:{...n,forceCompileTimeBindings:!0}});if(!u.$||!u.$.value)throw new Error("Failed to create TraitInfo");e=u.$.env,i.push(u.$.value)}return Ao(e,i,"TraitInfo","trl_"+r,n)}function ny({expr:e,env:t,context:n}){let r=O({expr:e.args[0],env:t,context:{...n}});if(!r.$)throw d({token:e.args[0].token,errorMessage:"comptime_eval: failed to evaluate argument"});if(!tt(r.$.value))return e.$={env:r.$.env,type:ue.type,value:ue,pathCollection:[]},e;let i=r.$.value.value;t=r.$.env;let o=nu(i);for(let a of o){let s=O({expr:a,env:t,context:{...n,forceCompileTimeBindings:!1}});if(!s.$)throw d({token:e.args[0].token,errorMessage:`comptime_eval: failed to evaluate code:
|
|
11682
|
-
${i}`});t=s.$.env}return e.$={env:t,type:ue.type,value:ue,pathCollection:[]},e}function ry({expr:e,env:t,context:n}){var s;Ge(e,F.__yo_comptime_string_to_expr,1);let r=O({expr:e.args[0],env:t,context:{...n}});if(!r.$||!tt(r.$.value)){if((s=r.$)!=null&&s.value&&tt(r.$.value)===!1){let l=oe(Mn(),{env:r.$.env,context:n});return e.$={env:r.$.env,type:l.type,value:l,pathCollection:[]},e}throw d({token:e.args[0].token,errorMessage:"__yo_comptime_string_to_expr: expected a comptime_string argument"})}let i=r.$.value.value,o=Dt(i),a=Hn(o);return e.$={env:r.$.env,type:a.type,value:a,pathCollection:[]},e}function Ei({env:e,name:t,type:n,value:r}){return xe({env:e,variable:{name:t,type:n,value:[r],isCompileTimeOnly:!0,isOwningTheRcValue:!1,initializedAtToken:Fe,consumedAtToken:void 0,token:Fe}}).env}function Ao(e,t,n,r,i){let o;if(t.length>0)o=t[0].type;else{let l=Dt(n),u=O({expr:l,env:e,context:{...i,forceCompileTimeBindings:!0}});if(!u.$||!u.$.value||!W(u.$.value))throw new Error(`Failed to resolve type "${n}" for empty ComptimeList`);o=u.$.value.value}let a=`__ti_${r}_${cn(e.modulePath,"ti"+r)}`,s=Jn(o,t);return e=Ei({env:e,name:a,type:s.type,value:s}),{name:a,env:e}}function UT(e,t,n,r){let i=`__derive_ft_${cn(e.modulePath,"dft")}`;e=Ei({env:e,name:i,type:Te(n).type,value:Te(n)});let a=`FieldInfo(${JSON.stringify(t)}, ${i})`,s=Dt(a),l=O({expr:s,env:e,context:{...r,forceCompileTimeBindings:!0}});if(!l.$||!l.$.value)throw new Error(`Failed to create FieldInfo for field "${t}"`);return{value:l.$.value,env:l.$.env}}function iy({env:e,context:t,mapperVarName:n,argValue:r,argType:i,token:o}){let a=`__derive_arg_${cn(e.modulePath,"da")}`;e=Ei({env:e,name:a,type:i,value:r});let s=`${n}(${a})`,l=Dt(s),u=O({expr:l,env:e,context:{...t,forceCompileTimeBindings:!0}});if(!u.$||!Dn(u.$.value))throw d({token:o,errorMessage:`derive mapper function must return comptime(Expr), got: ${u.$?I(u):"nothing"}`});return{exprValue:u.$.value.value,env:u.$.env}}function zT(e,t){if(e.length===0)throw new Error("combineExprsWithOperator: empty exprs list");if(e.length===1)return e[0];let n=e[0];for(let r=1;r<e.length;r++)n={tag:"FnCall",func:{tag:"Atom",token:t.token},args:[n,e[r]],isInfix:!0,token:t.token};return n}function oy({expr:e,env:t,context:n}){Ge(e,F.__yo_type_join_fields,3);let r=O({expr:e.args[0],env:t,context:{...n}});if(!r.$||!W(r.$.value))throw d({token:e.args[0].token,errorMessage:"__yo_type_join_fields: first argument must be a Type"});t=r.$.env;let i=r.$.value.value;if(z(i)){let m=oe(Mn(),{env:t,context:n});return e.$={env:t,type:m.type,value:m,pathCollection:[]},e}if(!Ae(i))throw d({token:e.args[0].token,errorMessage:`__yo_type_join_fields: expected a struct type, got: ${M(i)}`});let o=O({expr:e.args[1],env:t,context:{...n}});if(!o.$||!
|
|
11683
|
-
${I(r[i])}`});t=l.$.env;let u=l.$.value.value;if(i++,r[i]&&S(r[i])&&E(r[i],P.where)){if(!o)throw d({token:r[i].token,errorMessage:"derive where(...) requires forall(...)."});if(a)throw d({token:r[i].token,errorMessage:"derive supports only a single where(...) clause."});a=r[i],i++}if(!Ae(u)&&!Be(u))throw d({token:r[0].token,errorMessage:`derive only works on struct and enum types. Got: ${M(u)}`});let _=r.slice(i);if(_.length===0)throw d({token:e.token,errorMessage:"derive requires at least one trait argument after the target type."});let c=t;o&&(t=Ot(t));let f=t;for(let m of _)t=BT({traitArgExpr:m,targetType:u,env:f,envForTraitEval:o?c:f,context:n,forallArg:o,whereArg:a,targetTypeExpr:s});return e.$={env:t,type:ue.type,value:ue,pathCollection:[]},e}function BT({traitArgExpr:e,targetType:t,env:n,envForTraitEval:r,context:i,forallArg:o,whereArg:a,targetTypeExpr:s}){var u,_;let l=O({expr:e,env:r,context:{...i}});if(!l.$)throw d({token:e.token,errorMessage:`derive: failed to evaluate trait argument: ${I(e)}`});if(ot(l.$.type)){let c=l.$.type,f=c.deriveRule??((u=c.functionValue)==null?void 0:u.deriveRule);if(f){let p=ly(e);return u_({deriveRule:f,targetType:t,env:n,context:i,token:e.token,traitParams:p,forallArg:o,whereArg:a,targetTypeExpr:s})}throw d({token:e.token,errorMessage:`derive: trait '${M(c)}' does not have a derive rule. Use derive_rule() to register one, or provide a derive function.`})}if(W(l.$.value)&&ot(l.$.value.value)){let c=l.$.value.value,f=c.deriveRule??((_=c.functionValue)==null?void 0:_.deriveRule);if(f){let p=ly(e);return u_({deriveRule:f,targetType:t,env:n,context:i,token:e.token,traitParams:p,forallArg:o,whereArg:a,targetTypeExpr:s})}throw d({token:e.token,errorMessage:`derive: trait '${M(c)}' does not have a derive rule. Use derive_rule() to register one, or provide a derive function.`})}if(
|
|
11684
|
-
${s}`});return u.$.env}function ly(e){return S(e)?e.args??[]:[]}function u_({deriveRule:e,targetType:t,env:n,context:r,token:i,traitParams:o,forallArg:a,whereArg:s,targetTypeExpr:l}){n=lt(n);let u=`__derive_T_${cn(n.modulePath,"dT")}`,_=Te(t);n=ri(n,u,_.type,_);let c=`__derive_rule_${cn(n.modulePath,"dr")}`;n=ri(n,c,e.type,e);let f=Hn(l),p=`__derive_te_${cn(n.modulePath,"dte")}`;n=ri(n,p,f.type,f);let m=`__derive_fp_${cn(n.modulePath,"dfp")}`;{let N=`__derive_fp_tmp_${cn(n.modulePath,"dfpt")}`,x;if(a){let R=Hn(a),D=`__derive_fpe_${cn(n.modulePath,"dfpe")}`;n=ri(n,D,R.type,R),x=`((${N} : Option(Expr)) = .Some(${D}))`}else x=`((${N} : Option(Expr)) = .None)`;let V=Dt(x),U=O({expr:V,env:n,context:{...r,forceCompileTimeBindings:!0}});if(U.$){n=U.$.env;let R=ae(n,N),D=R[R.length-1];D&&D.value&&D.value[0]&&(n=ri(n,m,D.type,D.value[0]))}}let h=`__derive_wp_${cn(n.modulePath,"dwp")}`;{let N=`__derive_wp_tmp_${cn(n.modulePath,"dwpt")}`,x;if(s){let R=Hn(s),D=`__derive_wpe_${cn(n.modulePath,"dwpe")}`;n=ri(n,D,R.type,R),x=`((${N} : Option(Expr)) = .Some(${D}))`}else x=`((${N} : Option(Expr)) = .None)`;let V=Dt(x),U=O({expr:V,env:n,context:{...r,forceCompileTimeBindings:!0}});if(U.$){n=U.$.env;let R=ae(n,N),D=R[R.length-1];D&&D.value&&D.value[0]&&(n=ri(n,h,D.type,D.value[0]))}}let y=`__derive_ctx_${cn(n.modulePath,"dctx")}`,g=`DeriveContext(${p}, ${m}, ${h})`,v=Dt(g),T=O({expr:v,env:n,context:{...r,forceCompileTimeBindings:!0}});if(!T.$||!T.$.value)throw d({token:i,errorMessage:"derive: failed to create DeriveContext"});n=T.$.env,n=ri(n,y,T.$.type,T.$.value);let $=[];for(let N=0;N<o.length;N++){let x=Hn(o[N]),V=`__derive_tp_${cn(n.modulePath,"dtp")}`;n=ri(n,V,x.type,x),$.push(V)}let C=`__derive_tps_${cn(n.modulePath,"dtps")}`;if($.length>0){let N=`comptime_list(${$.join(", ")})`,x=Dt(N),V=O({expr:x,env:n,context:{...r,forceCompileTimeBindings:!0}});if(!V.$||!V.$.value)throw d({token:i,errorMessage:"derive: failed to create trait params list"});n=V.$.env,n=ri(n,C,V.$.type,V.$.value)}else{let N=Mn(),x=Jn(N,[]);n=ri(n,C,x.type,x)}let k=`${c}(${u}, ${y}, ${C})`,b=Dt(k),w=O({expr:b,env:n,context:{...r,forceCompileTimeBindings:!0}});if(!w.$||!w.$.value)throw d({token:i,errorMessage:"derive: derive rule function failed"});if(n=w.$.env,!Dn(w.$.value))throw d({token:i,errorMessage:"derive: derive rule must return comptime(Expr), got something else"});let A=w.$.value.value;n=Ot(n,!0);let L=O({expr:A,env:n,context:{...r,forceCompileTimeBindings:!1}});if(!L.$)throw d({token:i,errorMessage:"derive: failed to evaluate derive rule output"});return L.$.env}function ri(e,t,n,r){return xe({env:e,variable:{name:t,type:n,value:[r],isCompileTimeOnly:!0,isOwningTheRcValue:!1,initializedAtToken:Fe,consumedAtToken:void 0,token:Fe}}).env}function _y({expr:e,env:t,context:n}){Ge(e,F.derive_rule,2);let r=O({expr:e.args[0],env:t,context:{...n}});if(!r.$)throw d({token:e.args[0].token,errorMessage:`derive_rule: failed to evaluate trait argument: ${I(e.args[0])}`});t=r.$.env;let i=O({expr:e.args[1],env:t,context:{...n}});if(!i.$)throw d({token:e.args[1].token,errorMessage:`derive_rule: failed to evaluate derive function: ${I(e.args[1])}`});if(t=i.$.env,!
|
|
11682
|
+
${i}`});t=s.$.env}return e.$={env:t,type:ue.type,value:ue,pathCollection:[]},e}function ry({expr:e,env:t,context:n}){var s;Ge(e,F.__yo_comptime_string_to_expr,1);let r=O({expr:e.args[0],env:t,context:{...n}});if(!r.$||!tt(r.$.value)){if((s=r.$)!=null&&s.value&&tt(r.$.value)===!1){let l=oe(Mn(),{env:r.$.env,context:n});return e.$={env:r.$.env,type:l.type,value:l,pathCollection:[]},e}throw d({token:e.args[0].token,errorMessage:"__yo_comptime_string_to_expr: expected a comptime_string argument"})}let i=r.$.value.value,o=Dt(i),a=Hn(o);return e.$={env:r.$.env,type:a.type,value:a,pathCollection:[]},e}function Ei({env:e,name:t,type:n,value:r}){return xe({env:e,variable:{name:t,type:n,value:[r],isCompileTimeOnly:!0,isOwningTheRcValue:!1,initializedAtToken:Fe,consumedAtToken:void 0,token:Fe}}).env}function Ao(e,t,n,r,i){let o;if(t.length>0)o=t[0].type;else{let l=Dt(n),u=O({expr:l,env:e,context:{...i,forceCompileTimeBindings:!0}});if(!u.$||!u.$.value||!W(u.$.value))throw new Error(`Failed to resolve type "${n}" for empty ComptimeList`);o=u.$.value.value}let a=`__ti_${r}_${cn(e.modulePath,"ti"+r)}`,s=Jn(o,t);return e=Ei({env:e,name:a,type:s.type,value:s}),{name:a,env:e}}function UT(e,t,n,r){let i=`__derive_ft_${cn(e.modulePath,"dft")}`;e=Ei({env:e,name:i,type:Te(n).type,value:Te(n)});let a=`FieldInfo(${JSON.stringify(t)}, ${i})`,s=Dt(a),l=O({expr:s,env:e,context:{...r,forceCompileTimeBindings:!0}});if(!l.$||!l.$.value)throw new Error(`Failed to create FieldInfo for field "${t}"`);return{value:l.$.value,env:l.$.env}}function iy({env:e,context:t,mapperVarName:n,argValue:r,argType:i,token:o}){let a=`__derive_arg_${cn(e.modulePath,"da")}`;e=Ei({env:e,name:a,type:i,value:r});let s=`${n}(${a})`,l=Dt(s),u=O({expr:l,env:e,context:{...t,forceCompileTimeBindings:!0}});if(!u.$||!Dn(u.$.value))throw d({token:o,errorMessage:`derive mapper function must return comptime(Expr), got: ${u.$?I(u):"nothing"}`});return{exprValue:u.$.value.value,env:u.$.env}}function zT(e,t){if(e.length===0)throw new Error("combineExprsWithOperator: empty exprs list");if(e.length===1)return e[0];let n=e[0];for(let r=1;r<e.length;r++)n={tag:"FnCall",func:{tag:"Atom",token:t.token},args:[n,e[r]],isInfix:!0,token:t.token};return n}function oy({expr:e,env:t,context:n}){Ge(e,F.__yo_type_join_fields,3);let r=O({expr:e.args[0],env:t,context:{...n}});if(!r.$||!W(r.$.value))throw d({token:e.args[0].token,errorMessage:"__yo_type_join_fields: first argument must be a Type"});t=r.$.env;let i=r.$.value.value;if(z(i)){let m=oe(Mn(),{env:t,context:n});return e.$={env:t,type:m.type,value:m,pathCollection:[]},e}if(!Ae(i))throw d({token:e.args[0].token,errorMessage:`__yo_type_join_fields: expected a struct type, got: ${M(i)}`});let o=O({expr:e.args[1],env:t,context:{...n}});if(!o.$||!ge(o.$.value))throw d({token:e.args[1].token,errorMessage:"__yo_type_join_fields: second argument must be a function"});t=o.$.env;let a=o.$.value,s=`__derive_mapper_${cn(t.modulePath,"dm")}`,l=O({expr:e.args[2],env:t,context:{...n}});if(!l.$||!Dn(l.$.value))throw d({token:e.args[2].token,errorMessage:"__yo_type_join_fields: third argument must be a quoted expression (e.g., quote(&&))"});t=l.$.env;let u=l.$.value.value;t=lt(t),t=Ei({env:t,name:s,type:o.$.type,value:a});let _=[],c=i;for(let m=0;m<c.fields.length;m++){let h=c.fields[m],{value:y,env:g}=UT(t,h.label,h.type,n);t=g;let{exprValue:v,env:T}=iy({env:t,context:{...n,expectedType:void 0},mapperVarName:s,argValue:y,argType:y.type,token:e.args[1].token});t=T,_.push(v)}if(t=Ot(t,!0),_.length===0)throw d({token:e.token,errorMessage:"__yo_type_join_fields: struct has no fields"});let f=zT(_,u),p=Hn(f);return e.$={env:t,type:p.type,value:p,pathCollection:[]},e}function ay({expr:e,env:t,context:n}){Ge(e,F.__yo_type_map_variants,2);let r=O({expr:e.args[0],env:t,context:{...n}});if(!r.$||!W(r.$.value))throw d({token:e.args[0].token,errorMessage:"__yo_type_map_variants: first argument must be a Type"});t=r.$.env;let i=r.$.value.value;if(z(i)){let c=Hm([]),f=oe(c.type,{env:t,context:n});return e.$={env:t,type:f.type,value:f,pathCollection:[]},e}if(!Be(i))throw d({token:e.args[0].token,errorMessage:`__yo_type_map_variants: expected an enum type, got: ${M(i)}`});let o=O({expr:e.args[1],env:t,context:{...n}});if(!o.$||!ge(o.$.value))throw d({token:e.args[1].token,errorMessage:"__yo_type_map_variants: second argument must be a function"});t=o.$.env;let a=o.$.value,s=`__derive_vmap_${cn(t.modulePath,"dvm")}`,l=i;t=lt(t),t=Ei({env:t,name:s,type:o.$.type,value:a});let u=[];for(let c=0;c<l.variants.length;c++){let f=l.variants[c],{value:p,env:m}=sy(t,f.name,f.fields??[],i,c,n);t=m;let{exprValue:h,env:y}=iy({env:t,context:{...n,expectedType:void 0},mapperVarName:s,argValue:p,argType:p.type,token:e.args[1].token});t=y,u.push(Hn(h))}t=Ot(t,!0);let _=Hm(u);return e.$={env:t,type:_.type,value:_,pathCollection:[]},e}function sy(e,t,n,r,i,o){let a=`__derive_et_${cn(e.modulePath,"det")}`;e=Ei({env:e,name:a,type:Te(r).type,value:Te(r)});let s=_s(e,n,o);e=s.env;let u=`VariantInfo(${JSON.stringify(t)}, ${s.name}, ${a}, usize(${i}))`,_=Dt(u),c=O({expr:_,env:e,context:{...o,forceCompileTimeBindings:!0}});if(!c.$||!c.$.value)throw new Error(`Failed to create VariantInfo for variant "${t}"`);return{value:c.$.value,env:c.$.env}}function Hm(e){return Jn(Mn(),e)}function uy({expr:e,env:t,context:n}){var p;if(n.isValidatingFunctionDefinition||!n.isExecuting)return e.$={env:t,type:ue.type,value:ue,pathCollection:[]},e;if(e.args.length<2)throw d({token:e.token,errorMessage:`derive requires at least 2 arguments: derive(Type, Trait1, ...). Got ${e.args.length}.`});let r=e.args,i=0,o,a;if(r[i]&&S(r[i])&&E(r[i],P.forall)){o=r[i],i++,t=lt(t);for(let m of o.args){let h,y;if(S(m)&&E(m,":",2)){let C=m.args[0];if(!K(C))throw d({token:C.token,errorMessage:`Expected identifier for forall parameter name, got: ${I(C)}`});h=C.token.value,y=m.args[1]}else if(K(m))h=m.token.value;else throw d({token:m.token,errorMessage:`Expected parameter name for forall parameter, got: ${I(m)}`});let g;if(y){let C=O({expr:y,env:t,context:{...n}});(p=C.$)!=null&&p.env&&(t=C.$.env),C.$&&W(C.$.value)&&(g=C.$.value.value)}let v=g||Pt(),T=oe(v,{variableName:h,env:t,context:n}),{env:$}=xe({env:t,variable:{name:h,type:v,isCompileTimeOnly:!0,value:[T],token:m.token,initializedAtToken:m.token,consumedAtToken:void 0,isOwningTheRcValue:!1}});t=$}}if(r[i]&&S(r[i])&&E(r[i],P.where)){if(!o)throw d({token:r[i].token,errorMessage:"derive where(...) requires forall(...)."});a=r[i],i++}if(!r[i])throw d({token:e.token,errorMessage:"derive requires a target type."});let s=r[i],l=O({expr:r[i],env:t,context:{...n}});if(!l.$||!W(l.$.value))throw d({token:r[i].token,errorMessage:`derive: expected a type, got:
|
|
11683
|
+
${I(r[i])}`});t=l.$.env;let u=l.$.value.value;if(i++,r[i]&&S(r[i])&&E(r[i],P.where)){if(!o)throw d({token:r[i].token,errorMessage:"derive where(...) requires forall(...)."});if(a)throw d({token:r[i].token,errorMessage:"derive supports only a single where(...) clause."});a=r[i],i++}if(!Ae(u)&&!Be(u))throw d({token:r[0].token,errorMessage:`derive only works on struct and enum types. Got: ${M(u)}`});let _=r.slice(i);if(_.length===0)throw d({token:e.token,errorMessage:"derive requires at least one trait argument after the target type."});let c=t;o&&(t=Ot(t));let f=t;for(let m of _)t=BT({traitArgExpr:m,targetType:u,env:f,envForTraitEval:o?c:f,context:n,forallArg:o,whereArg:a,targetTypeExpr:s});return e.$={env:t,type:ue.type,value:ue,pathCollection:[]},e}function BT({traitArgExpr:e,targetType:t,env:n,envForTraitEval:r,context:i,forallArg:o,whereArg:a,targetTypeExpr:s}){var u,_;let l=O({expr:e,env:r,context:{...i}});if(!l.$)throw d({token:e.token,errorMessage:`derive: failed to evaluate trait argument: ${I(e)}`});if(ot(l.$.type)){let c=l.$.type,f=c.deriveRule??((u=c.functionValue)==null?void 0:u.deriveRule);if(f){let p=ly(e);return u_({deriveRule:f,targetType:t,env:n,context:i,token:e.token,traitParams:p,forallArg:o,whereArg:a,targetTypeExpr:s})}throw d({token:e.token,errorMessage:`derive: trait '${M(c)}' does not have a derive rule. Use derive_rule() to register one, or provide a derive function.`})}if(W(l.$.value)&&ot(l.$.value.value)){let c=l.$.value.value,f=c.deriveRule??((_=c.functionValue)==null?void 0:_.deriveRule);if(f){let p=ly(e);return u_({deriveRule:f,targetType:t,env:n,context:i,token:e.token,traitParams:p,forallArg:o,whereArg:a,targetTypeExpr:s})}throw d({token:e.token,errorMessage:`derive: trait '${M(c)}' does not have a derive rule. Use derive_rule() to register one, or provide a derive function.`})}if(ge(l.$.value)){let c=l.$.value;return c.deriveRule?u_({deriveRule:c.deriveRule,targetType:t,env:n,context:i,token:e.token,traitParams:[],forallArg:o,whereArg:a,targetTypeExpr:s}):GT({funcValue:c,targetType:t,env:n,context:i,token:e.token})}throw d({token:e.token,errorMessage:`derive: expected a trait or derive function, got: ${I(e)}`})}function GT({funcValue:e,targetType:t,env:n,context:r,token:i}){let o=t.typeName??M(t),a=e.funcName;if(!a)throw d({token:i,errorMessage:"derive: user-defined derive function must be a named function."});let s=`${a}(${o})`,l=Dt(s),u=O({expr:l,env:n,context:{...r,forceCompileTimeBindings:!1}});if(!u.$)throw d({token:i,errorMessage:`derive: user-defined derive function failed:
|
|
11684
|
+
${s}`});return u.$.env}function ly(e){return S(e)?e.args??[]:[]}function u_({deriveRule:e,targetType:t,env:n,context:r,token:i,traitParams:o,forallArg:a,whereArg:s,targetTypeExpr:l}){n=lt(n);let u=`__derive_T_${cn(n.modulePath,"dT")}`,_=Te(t);n=ri(n,u,_.type,_);let c=`__derive_rule_${cn(n.modulePath,"dr")}`;n=ri(n,c,e.type,e);let f=Hn(l),p=`__derive_te_${cn(n.modulePath,"dte")}`;n=ri(n,p,f.type,f);let m=`__derive_fp_${cn(n.modulePath,"dfp")}`;{let N=`__derive_fp_tmp_${cn(n.modulePath,"dfpt")}`,x;if(a){let R=Hn(a),D=`__derive_fpe_${cn(n.modulePath,"dfpe")}`;n=ri(n,D,R.type,R),x=`((${N} : Option(Expr)) = .Some(${D}))`}else x=`((${N} : Option(Expr)) = .None)`;let V=Dt(x),U=O({expr:V,env:n,context:{...r,forceCompileTimeBindings:!0}});if(U.$){n=U.$.env;let R=ae(n,N),D=R[R.length-1];D&&D.value&&D.value[0]&&(n=ri(n,m,D.type,D.value[0]))}}let h=`__derive_wp_${cn(n.modulePath,"dwp")}`;{let N=`__derive_wp_tmp_${cn(n.modulePath,"dwpt")}`,x;if(s){let R=Hn(s),D=`__derive_wpe_${cn(n.modulePath,"dwpe")}`;n=ri(n,D,R.type,R),x=`((${N} : Option(Expr)) = .Some(${D}))`}else x=`((${N} : Option(Expr)) = .None)`;let V=Dt(x),U=O({expr:V,env:n,context:{...r,forceCompileTimeBindings:!0}});if(U.$){n=U.$.env;let R=ae(n,N),D=R[R.length-1];D&&D.value&&D.value[0]&&(n=ri(n,h,D.type,D.value[0]))}}let y=`__derive_ctx_${cn(n.modulePath,"dctx")}`,g=`DeriveContext(${p}, ${m}, ${h})`,v=Dt(g),T=O({expr:v,env:n,context:{...r,forceCompileTimeBindings:!0}});if(!T.$||!T.$.value)throw d({token:i,errorMessage:"derive: failed to create DeriveContext"});n=T.$.env,n=ri(n,y,T.$.type,T.$.value);let $=[];for(let N=0;N<o.length;N++){let x=Hn(o[N]),V=`__derive_tp_${cn(n.modulePath,"dtp")}`;n=ri(n,V,x.type,x),$.push(V)}let C=`__derive_tps_${cn(n.modulePath,"dtps")}`;if($.length>0){let N=`comptime_list(${$.join(", ")})`,x=Dt(N),V=O({expr:x,env:n,context:{...r,forceCompileTimeBindings:!0}});if(!V.$||!V.$.value)throw d({token:i,errorMessage:"derive: failed to create trait params list"});n=V.$.env,n=ri(n,C,V.$.type,V.$.value)}else{let N=Mn(),x=Jn(N,[]);n=ri(n,C,x.type,x)}let k=`${c}(${u}, ${y}, ${C})`,b=Dt(k),w=O({expr:b,env:n,context:{...r,forceCompileTimeBindings:!0}});if(!w.$||!w.$.value)throw d({token:i,errorMessage:"derive: derive rule function failed"});if(n=w.$.env,!Dn(w.$.value))throw d({token:i,errorMessage:"derive: derive rule must return comptime(Expr), got something else"});let A=w.$.value.value;n=Ot(n,!0);let L=O({expr:A,env:n,context:{...r,forceCompileTimeBindings:!1}});if(!L.$)throw d({token:i,errorMessage:"derive: failed to evaluate derive rule output"});return L.$.env}function ri(e,t,n,r){return xe({env:e,variable:{name:t,type:n,value:[r],isCompileTimeOnly:!0,isOwningTheRcValue:!1,initializedAtToken:Fe,consumedAtToken:void 0,token:Fe}}).env}function _y({expr:e,env:t,context:n}){Ge(e,F.derive_rule,2);let r=O({expr:e.args[0],env:t,context:{...n}});if(!r.$)throw d({token:e.args[0].token,errorMessage:`derive_rule: failed to evaluate trait argument: ${I(e.args[0])}`});t=r.$.env;let i=O({expr:e.args[1],env:t,context:{...n}});if(!i.$)throw d({token:e.args[1].token,errorMessage:`derive_rule: failed to evaluate derive function: ${I(e.args[1])}`});if(t=i.$.env,!ge(i.$.value))throw d({token:e.args[1].token,errorMessage:`derive_rule: second argument must be a function, got: ${I(e.args[1])}`});let o=i.$.value;if(ge(r.$.value))r.$.value.deriveRule=o;else if(ot(r.$.type))r.$.type.deriveRule=o;else if(W(r.$.value)&&ot(r.$.value.value))r.$.value.value.deriveRule=o;else throw d({token:e.args[0].token,errorMessage:`derive_rule: first argument must be a trait constructor or trait type, got: ${I(e.args[0])}`});return e.$={env:t,type:ue.type,value:ue,pathCollection:[]},e}function cy({expr:e,env:t,context:n}){Ge(e,F.typeid,1);let r=e.args[0],i=O({expr:r,env:t,context:{...n}});if(!i.$)throw d({token:r.token,errorMessage:"Failed to evaluate expression for typeid."});if(t=i.$.env,!i.$.value||!W(i.$.value))throw d({token:r.token,errorMessage:`typeid expects a type argument, got ${i.$.type?M(i.$.type):"unknown"}. Use is() or downcast() for runtime type checks on Dyn values.`});let o=oe(vn(),{env:t,context:n});return e.$={env:t,type:vn(),value:o,pathCollection:[]},e}function fy({expr:e,env:t}){Ge(e,F.va_start);for(let n=0;n<e.args.length;n++){let r=e.args[n];if(!K(r)||!Nt(r))throw d({token:r.token,errorMessage:`Invalid argument for va_start. Expected identifier, got:
|
|
11685
11685
|
${I(r)}`});if(n===0){let i=r.token.value,o=ae(t,i);if(o.length===0)throw d({token:r.token,errorMessage:`Variable '${i}' not found in the environment.`});let a=o[o.length-1];t=bt(t,a,{...a,initializedAtToken:r.token})}if(n===1){let i=r.token.value;if(ae(t,i).length===0)throw d({token:r.token,errorMessage:`Variable '${i}' not found in the environment.`})}}return e.$={type:ue.type,value:ue,env:t,pathCollection:[]},e}function py({expr:e,env:t,context:n}){var a;Ge(e,F.__yo_var_print_info,1);let r=e.args[0],i=O({expr:r,env:t,context:n});i.$&&(t=i.$.env);let o=(a=i.$)==null?void 0:a.variableName;if(o){let s=ae(t,o);if(s.length>0){let l=s.at(-1);console.log(Sc(l))}}return e.$={env:t,type:ue.type,value:ue,pathCollection:[]},e}function dy({expr:e,env:t,context:n}){var s;Ge(e,F.__yo_var_is_owning_the_rc_value,1);let r=e.args[0],i=O({expr:r,env:t,context:n});i.$&&(t=i.$.env);let o=(s=i.$)==null?void 0:s.variableName,a=!1;if(o){let l=ae(t,o);l.length>0&&(a=l.at(-1).isOwningTheRcValue)}return e.$={env:t,type:Ut(),value:Zt(a),pathCollection:[]},e}function my({expr:e,env:t,context:n}){var s;Ge(e,F.__yo_var_has_other_aliases,1);let r=e.args[0],i=O({expr:r,env:t,context:n});i.$&&(t=i.$.env);let o=(s=i.$)==null?void 0:s.variableName,a=!1;if(o){let l=ae(t,o);if(l.length>0){let u=l.at(-1);if(u.isOwningTheSameRcValueAs)a=!0;else{let c=u.id;for(let f=t.frames.length-1;f>=0;f--){let p=t.frames[f];for(let m=0;m<p.variables.length;m++){let h=p.variables[m];if(h.isOwningTheSameRcValueAs&&h.isOwningTheSameRcValueAs.id===c){a=!0;break}}}}}}return e.$={env:t,type:Ut(),value:Zt(a),pathCollection:[]},e}function yy({expr:e,env:t,context:n}){let r=e.args[0],i=n.expectedType;i&&je(i.type)&&(i={...i,type:i.type.childType});let o=O({expr:r,env:t,context:{...n,expectedType:i}});if(!o.$)throw d({token:r.token,errorMessage:`Failed to evaluate the argument expression for pointer:
|
|
11686
11686
|
${I(r)}`});if(t=o.$.env,W(o.$.value)){let s=o.$.value.value,l=yn(s),u=Te(l);return e.$={env:t,type:u.type,value:u,pathCollection:[]},e}else throw d({token:r.token,errorMessage:`Cannot create a pointer to a value. Use "&" to create a pointer to a value:
|
|
11687
11687
|
${I(r)}`})}function gy({expr:e,env:t,context:n}){if(!E(e,P.Array,2))throw d({token:e.token,errorMessage:`Expected "Array(comptime(Type), comptime(usize))" with 2 arguments, like "Array(i32, 10)"
|
|
@@ -11756,14 +11756,14 @@ ${M(r)}${st(r)?`
|
|
|
11756
11756
|
Use 'dyn((x) => expr)' for dynamic dispatch`:""}`});let l=o?"=>":"->",u=o?"closure":"function";if(!E(e,l,2))throw d({token:e.token,errorMessage:`Expected ${l} for anonymous ${u}, got:
|
|
11757
11757
|
${I(e)}`});let _=e.args[0],c=e.args[1],f=[];S(_)&&E(_,P.tuple)?f=_.args:f=[_];let p=[],m=[],h=[];for(let ee=0;ee<f.length;ee++){let fe=f[ee];if(S(fe)&&E(fe,P.forall)){if(ee!==0)throw d({token:fe.token,errorMessage:"forall(...) must be the first parameter expression"});p=fe.args}else S(fe)&&E(fe,P.using)?m=fe.args:h.push(fe)}if(h.length!==i.parameters.length)throw d({token:e.token,errorMessage:`Expected ${i.parameters.length} regular parameters, got ${h.length}`});let y=t;t=lt(Vc(t));for(let ee=0;ee<p.length;ee++){let fe=p[ee],me=i.forallParameters[ee];if(!K(fe))throw d({token:fe.token,errorMessage:`Expected parameter name for forall parameter, got ${I(fe)}`});let Le=fe.token.value;if(Le!==me.label)throw d({token:fe.token,errorMessage:`Forall parameter name must match expected name.
|
|
11758
11758
|
Expected: "${me.label}"
|
|
11759
|
-
Got: "${Le}"`})}for(let ee=0;ee<i.forallParameters.length;ee++){let fe=p[ee],me=i.forallParameters[ee],{env:Le}=xe({env:t,variable:{name:me.label,type:me.type,isCompileTimeOnly:me.isCompileTimeOnly,value:[oe(me.type,{variableName:me.label,env:t,context:n})],token:(fe==null?void 0:fe.token)??Fe,initializedAtToken:(fe==null?void 0:fe.token)??Fe,consumedAtToken:void 0,isOwningTheRcValue:!1},allowVariableShadowing:!0});t=Le,fe&&(fe.$={env:t,type:me.type,value:oe(me.type,{variableName:me.label,env:t,context:n}),pathCollection:[]})}let g=i.implicitParameters.some(ee=>ee.isEffectRowSpread),v,T;if(g&&m.length>0){v=[];for(let ee of m)if(S(ee)&&E(ee,":",2)){let fe=ee.args[0],me=ee.args[1];if(!K(fe))throw d({token:fe.token,errorMessage:`Expected identifier for effect name, got ${I(fe)}`});let Le=fe.token.value,qe=O({expr:_t(me),env:y,context:{...n,isEvaluatingFunctionType:!0}});if(!((Y=qe.$)!=null&&Y.value)||!W(qe.$.value))throw d({token:me.token,errorMessage:`Expected a type for effect parameter "${Le}", got ${I(me)}`});let dt=qe.$.value.value;v.push({label:Le,type:dt,isCompileTimeOnly:!0,isImplicit:!0,isOwningTheRcValue:!1,isQuote:!1,exprs:{expr:ee,labelExpr:fe,typeExpr:me,defaultValueExpr:void 0}})}else if(K(ee)){let fe=ee.token.value,Le=ae(y,fe).at(-1);if(!Le)throw d({token:ee.token,errorMessage:`Variable "${fe}" not found. Cannot infer type for using() parameter.`});v.push({label:fe,type:Le.type,isCompileTimeOnly:!0,isImplicit:!0,isOwningTheRcValue:!1,isQuote:!1,exprs:{expr:ee,labelExpr:ee,typeExpr:ee,defaultValueExpr:void 0}})}else throw d({token:ee.token,errorMessage:`Expected "name : Type" or identifier in using(), got ${I(ee)}`});T=Si(v);for(let ee of i.implicitParameters)ee.isEffectRowSpread&&z(ee.type)&&ee.type.isEffectsRow&&(ee.type.resolvedConcreteType=T)}else if(m.length>0){let ee=[];for(let me of m)if(S(me)&&E(me,":",2)){let Le=me.args[0],qe=me.args[1];if(!K(Le))throw d({token:Le.token,errorMessage:`Expected identifier for effect name, got ${I(Le)}`});let dt=O({expr:_t(qe),env:y,context:{...n,isEvaluatingFunctionType:!0}});if(!((J=dt.$)!=null&&J.value)||!W(dt.$.value))throw d({token:qe.token,errorMessage:`Expected a type for effect parameter "${Le.token.value}", got ${I(qe)}`});ee.push({name:Le.token.value,type:dt.$.value.value,nameExpr:Le})}else if(K(me))ee.push({name:me.token.value,type:void 0,nameExpr:me});else throw d({token:me.token,errorMessage:`Expected "name : Type" or identifier in using(), got ${I(me)}`});if(ee.some(me=>me.type!==void 0)){if(ee.length!==i.implicitParameters.length)throw d({token:e.token,errorMessage:`Effect row mismatch: closure declares ${ee.length} effects, but call site resolved ${i.implicitParameters.length} effects.`});let me=new Set,Le=[];for(let qe=0;qe<ee.length;qe++){let dt=ee[qe];if(!dt.type){Le.push({...i.implicitParameters[qe],label:dt.name,exprs:{...i.implicitParameters[qe].exprs,expr:dt.nameExpr,labelExpr:dt.nameExpr}}),me.add(qe);continue}let kt=!1;for(let Rt=0;Rt<i.implicitParameters.length;Rt++){if(me.has(Rt))continue;let Ze=i.implicitParameters[Rt];if(le({type:dt.type,env:y},{type:Ze.type,env:y})){Le.push({...Ze,label:dt.name,exprs:{...Ze.exprs,expr:dt.nameExpr,labelExpr:dt.nameExpr}}),me.add(Rt),kt=!0;break}}if(!kt)throw d({token:dt.nameExpr.token,errorMessage:`Effect row type mismatch for "${dt.name}": closure declares ${M(dt.type)}, but no matching resolved effect found.`})}v=Le,T=Si(v)}else{if(m.length!==i.implicitParameters.length)throw d({token:e.token,errorMessage:`Expected ${i.implicitParameters.length} implicit parameters in using(...), got ${m.length}`});v=i.implicitParameters}}else v=i.implicitParameters;let $=[];for(let ee=0;ee<v.length;ee++){let fe=v[ee],me=T?(se=fe.exprs)==null?void 0:se.labelExpr:m[ee],Le=fe.label;me&&K(me)&&(Le=me.token.value);let qe;if(ne(fe.type)){let Tt=(ve=i.implicitParameters[ee])==null?void 0:ve.label,Jt=[fe.label];Tt&&Tt!==fe.label&&Jt.push(Tt);for(let At of Jt){let gt=ae(y,At),nt=gt[gt.length-1];if(nt!=null&&nt.value&&nt.value.length>0){let Ft=nt.value[0];if(Ft&&
|
|
11759
|
+
Got: "${Le}"`})}for(let ee=0;ee<i.forallParameters.length;ee++){let fe=p[ee],me=i.forallParameters[ee],{env:Le}=xe({env:t,variable:{name:me.label,type:me.type,isCompileTimeOnly:me.isCompileTimeOnly,value:[oe(me.type,{variableName:me.label,env:t,context:n})],token:(fe==null?void 0:fe.token)??Fe,initializedAtToken:(fe==null?void 0:fe.token)??Fe,consumedAtToken:void 0,isOwningTheRcValue:!1},allowVariableShadowing:!0});t=Le,fe&&(fe.$={env:t,type:me.type,value:oe(me.type,{variableName:me.label,env:t,context:n}),pathCollection:[]})}let g=i.implicitParameters.some(ee=>ee.isEffectRowSpread),v,T;if(g&&m.length>0){v=[];for(let ee of m)if(S(ee)&&E(ee,":",2)){let fe=ee.args[0],me=ee.args[1];if(!K(fe))throw d({token:fe.token,errorMessage:`Expected identifier for effect name, got ${I(fe)}`});let Le=fe.token.value,qe=O({expr:_t(me),env:y,context:{...n,isEvaluatingFunctionType:!0}});if(!((Y=qe.$)!=null&&Y.value)||!W(qe.$.value))throw d({token:me.token,errorMessage:`Expected a type for effect parameter "${Le}", got ${I(me)}`});let dt=qe.$.value.value;v.push({label:Le,type:dt,isCompileTimeOnly:!0,isImplicit:!0,isOwningTheRcValue:!1,isQuote:!1,exprs:{expr:ee,labelExpr:fe,typeExpr:me,defaultValueExpr:void 0}})}else if(K(ee)){let fe=ee.token.value,Le=ae(y,fe).at(-1);if(!Le)throw d({token:ee.token,errorMessage:`Variable "${fe}" not found. Cannot infer type for using() parameter.`});v.push({label:fe,type:Le.type,isCompileTimeOnly:!0,isImplicit:!0,isOwningTheRcValue:!1,isQuote:!1,exprs:{expr:ee,labelExpr:ee,typeExpr:ee,defaultValueExpr:void 0}})}else throw d({token:ee.token,errorMessage:`Expected "name : Type" or identifier in using(), got ${I(ee)}`});T=Si(v);for(let ee of i.implicitParameters)ee.isEffectRowSpread&&z(ee.type)&&ee.type.isEffectsRow&&(ee.type.resolvedConcreteType=T)}else if(m.length>0){let ee=[];for(let me of m)if(S(me)&&E(me,":",2)){let Le=me.args[0],qe=me.args[1];if(!K(Le))throw d({token:Le.token,errorMessage:`Expected identifier for effect name, got ${I(Le)}`});let dt=O({expr:_t(qe),env:y,context:{...n,isEvaluatingFunctionType:!0}});if(!((J=dt.$)!=null&&J.value)||!W(dt.$.value))throw d({token:qe.token,errorMessage:`Expected a type for effect parameter "${Le.token.value}", got ${I(qe)}`});ee.push({name:Le.token.value,type:dt.$.value.value,nameExpr:Le})}else if(K(me))ee.push({name:me.token.value,type:void 0,nameExpr:me});else throw d({token:me.token,errorMessage:`Expected "name : Type" or identifier in using(), got ${I(me)}`});if(ee.some(me=>me.type!==void 0)){if(ee.length!==i.implicitParameters.length)throw d({token:e.token,errorMessage:`Effect row mismatch: closure declares ${ee.length} effects, but call site resolved ${i.implicitParameters.length} effects.`});let me=new Set,Le=[];for(let qe=0;qe<ee.length;qe++){let dt=ee[qe];if(!dt.type){Le.push({...i.implicitParameters[qe],label:dt.name,exprs:{...i.implicitParameters[qe].exprs,expr:dt.nameExpr,labelExpr:dt.nameExpr}}),me.add(qe);continue}let kt=!1;for(let Rt=0;Rt<i.implicitParameters.length;Rt++){if(me.has(Rt))continue;let Ze=i.implicitParameters[Rt];if(le({type:dt.type,env:y},{type:Ze.type,env:y})){Le.push({...Ze,label:dt.name,exprs:{...Ze.exprs,expr:dt.nameExpr,labelExpr:dt.nameExpr}}),me.add(Rt),kt=!0;break}}if(!kt)throw d({token:dt.nameExpr.token,errorMessage:`Effect row type mismatch for "${dt.name}": closure declares ${M(dt.type)}, but no matching resolved effect found.`})}v=Le,T=Si(v)}else{if(m.length!==i.implicitParameters.length)throw d({token:e.token,errorMessage:`Expected ${i.implicitParameters.length} implicit parameters in using(...), got ${m.length}`});v=i.implicitParameters}}else v=i.implicitParameters;let $=[];for(let ee=0;ee<v.length;ee++){let fe=v[ee],me=T?(se=fe.exprs)==null?void 0:se.labelExpr:m[ee],Le=fe.label;me&&K(me)&&(Le=me.token.value);let qe;if(ne(fe.type)){let Tt=(ve=i.implicitParameters[ee])==null?void 0:ve.label,Jt=[fe.label];Tt&&Tt!==fe.label&&Jt.push(Tt);for(let At of Jt){let gt=ae(y,At),nt=gt[gt.length-1];if(nt!=null&&nt.value&&nt.value.length>0){let Ft=nt.value[0];if(Ft&&ge(Ft)){qe=Ft;break}}}if(!qe){let gt=cr(y,nt=>{var Ft;return nt.isImplicit===!0&&nt.isCompileTimeOnly===!0&&ge((Ft=nt.value)==null?void 0:Ft[0])&&le({type:fe.type,env:y},{type:nt.type,env:y})}).at(-1);(re=gt==null?void 0:gt.value)!=null&&re[0]&&ge(gt.value[0])&&(qe=gt.value[0])}}let dt=qe||oe(fe.type,{variableName:Le,env:t,context:n}),kt=n.isInsideIoAsyncCall&&o&&ne(fe.type)&&!qe;if(kt&&$.push({name:Le,type:fe.type,token:(me==null?void 0:me.token)??Fe}),!kt&&n.isInsideIoAsyncCall&&o&&Xe(fe.type)&&!qe){let Tt=fe.type;for(let Jt of Tt.fields)ne(Jt.type)&&$.push({name:Jt.label,type:Jt.type,token:(me==null?void 0:me.token)??Fe})}let{env:Ze}=xe({env:t,variable:{name:Le,type:fe.type,isCompileTimeOnly:!kt,isImplicit:!0,value:kt?void 0:[dt],token:(me==null?void 0:me.token)??Fe,initializedAtToken:(me==null?void 0:me.token)??Fe,consumedAtToken:void 0,isOwningTheRcValue:!1,isEffectParam:kt||void 0},allowVariableShadowing:!0});t=Ze,me&&(me.$={env:t,type:fe.type,value:kt?void 0:dt,pathCollection:[]})}for(let ee=0;ee<h.length;ee++){let fe=h[ee],me=i.parameters[ee];if(me.isCompileTimeOnly){if(!K(fe))throw d({token:fe.token,errorMessage:`Expected parameter name for compile-time parameter, got ${I(fe)}`});let kt=fe.token.value;if(kt!=="_"&&kt!==me.label)throw d({token:fe.token,errorMessage:`Compile-time parameter name must match expected name.
|
|
11760
11760
|
Expected: "${me.label}"
|
|
11761
11761
|
Got: "${kt}"`})}let Le=fe.token.value,qe=me.label,{env:dt}=xe({env:t,variable:{name:Le,type:me.type,isCompileTimeOnly:me.isCompileTimeOnly,value:me.isCompileTimeOnly?[oe(me.type,{variableName:me.label,env:t,context:n})]:void 0,token:fe.token,initializedAtToken:fe.token,consumedAtToken:void 0,isOwningTheRcValue:me.isOwningTheRcValue,parameterAlias:Le!==qe?qe:void 0}});t=dt,fe.$={env:t,type:me.type,value:me.isCompileTimeOnly?oe(me.type,{variableName:me.label,env:t,context:n}):void 0,pathCollection:[]}}let C=t.frames[t.frames.length-1],k={...i,forallParameters:i.forallParameters,implicitParameters:T?v:v.map((ee,fe)=>{let me=m[fe];if(me&&K(me)){let Le=me.token.value;if(Le!==ee.label)return{...ee,label:Le}}return ee}),parameters:i.parameters.map((ee,fe)=>{if(ee.isCompileTimeOnly)return ee;{let me=h[fe];return{...ee,label:K(me)?me.token.value:ee.label,exprs:{...ee.exprs,expr:me,labelExpr:me,typeExpr:ee.exprs.typeExpr,defaultValueExpr:void 0}}}}),return:{...i.return,typeExpr:i.return.typeExpr},parametersFrame:C,env:kl(i.env)};if((ce=k.whereClauseExprs)!=null&&ce.length){let ee=k.whereClauseExprs.map(me=>_t(me));t=Ri({constraintExprs:ee,env:t,context:{...n,isEvaluatingFunctionType:!0}}).env}let b={tag:"Function",type:k,body:c,frameLevel:t.frames.length-1,funcId:`fn_${mt(t.modulePath)}`,definitionSiteEnclosingFunctionType:((we=n.isEvaluatingFunctionBodyOrAsyncBlock)==null?void 0:we.kind)==="function-body"?n.isEvaluatingFunctionBodyOrAsyncBlock.type:void 0,calledComptimeFunctionCaches:[],specializedFunctionCaches:[]},w=!!a,A=p.length>0||i.parameters.some(ee=>Me(ee.type))||i.SelfType&&Me(i.SelfType),L,N;if(A)e_({functionBodyExpr:c,functionType:i,functionValue:b,env:t,context:n}),c.$={env:t,type:i.return.type,value:i.return.isCompileTimeOnly?oe(i.return.type,{variableName:"function_body",env:t,context:n}):void 0,pathCollection:[]},L={...n,isExecuting:!1,capturedVariables:new Map},N=c;else{let{evaluationContext:ee}=ha({...n,isExecuting:!1,isValidatingFunctionDefinition:!1},i,b,t);if(L=ee,n.isInsideIoAsyncCall&&o&&(L={...L,isEvaluatingFunctionBodyOrAsyncBlock:{kind:"async-block",evaluationEnv:t}}),N=un({expr:c,env:t,context:L,variablesToAdd:[],isEvaluatingFunctionBodyBeginBlock:!0}),!N.$)throw d({token:c.token,errorMessage:"Failed to evaluate the function body."});t=N.$.env}let x=L.capturedVariables;if(ei(N)&&(b.isControlFunction=!0),N.$&&(i.implicitParameters.some(ee=>Xe(ee.type))||n.isInsideIoAsyncCall)){let ee=pc(N);ee.hasAwaits&&(N.$.awaitAnalysis=ee)}let V=(Se=N.$)==null?void 0:Se.type;if(z(i.return.type)&&!i.return.type.resolvedConcreteType&&V){let ee=V;if(z(ee)&&ee.resolvedConcreteType&&(ee=ee.resolvedConcreteType),!z(ee)){let fe=an({type:ee,expectedType:void 0,expr:N,env:t});i.return.type.resolvedConcreteType=fe}}if(!z(i.return.type)&&Me(i.return.type)&&V&&!z(V)&&!Me(V)&&(Mt({type:i.return.type,env:t},{type:V,env:t},[],{setResolvedConcreteType:!0}),i.return.type=V,k.return.type=V),!b.isControlFunction&&V&&!le({type:i.return.type,env:t},{type:V,env:t}))throw d({token:c.token,errorMessage:`Incompatible return type:
|
|
11762
11762
|
- Expected: ${M(i.return.type)}
|
|
11763
11763
|
- Got : ${M(V)}`});(Ve=N.$)!=null&&Ve.env&&(t=(de=N.$)==null?void 0:de.env),t=Ot(t,!0),t=y;let U;if(w&&x&&x.size>0&&(U=Ul({capturedVariables:x,env:t})),w&&$.length>0){U||(U=new Map);for(let ee of $)U.set(ee.name,{frameLevel:0,usageType:"read",token:ee.token,value:void 0,type:ee.type,isEffectParam:!0})}let R,D,H,B,G=b;if((n.isAnalyzingCtfeCapability||n.forceCompileTimeBindings)&&!o){let ee=da(b,t,n);ee&&(G=ee)}if(o&&a&&s){B=Pl({expectedCaptureType:void 0,capturedVariablesWithValues:U,env:t,closureToken:e.token,context:{...n}}).captureType;let fe=ic(k,t),{capturedVariableDupExpressions:me,env:Le}=zl({capturedVariablesWithValues:U,env:t,context:n});H=me,t=Le,b.funcId=`closure_${mt(t.modulePath)}`;let qe=L.ownConsumedCaptures?Array.from(L.ownConsumedCaptures):void 0;b.closureInfo={closureType:fe,captureType:B,effectParamNames:$.length>0?$.map(dt=>dt.name):void 0,consumedCaptures:qe!=null&&qe.length?qe:void 0},z(s)&&B&&Rl({wrapperType:s,captureType:B,env:t,errorToken:e.token}),s.resolvedConcreteType=B,R={...s,resolvedConcreteType:B},D=void 0}else R=G.type,D=G;return e.$={env:t,type:R,value:D,pathCollection:w&&x?ga(x):[],deferredDupExpressions:o&&H?H:void 0,captureType:o?B:void 0,closureFunctionValue:o?G:void 0,isAnonymousFunctionDefinition:!0},w&&It(e,!0),e}function Vy({expr:e,env:t,context:n}){let r=e.args;if(r.length===0)throw d({token:e.token,errorMessage:`Expected at least one element in array, got ${r.length}`});let i=r.length,o,a;n.expectedType&&Je(n.expectedType.type)&&(a=n.expectedType.type.childType);let s=[],l=[];for(let c=0;c<r.length;c++){let f=r[c],p=O({expr:f,env:t,context:{...n,expectedType:a?{type:a,env:t}:void 0}});if(Bn(p,n),!p.$)throw d({token:f.token,errorMessage:`Failed to evaluate array element: ${I(f)}`});if(t=p.$.env,s.push(p.$.value),!o)o=a||p.$.type;else if(!le({type:o,env:t},{type:p.$.type,env:t}))if(le({type:an({type:o,expectedType:void 0,expr:void 0,env:t}),env:t},{type:p.$.type,env:t}))o=p.$.type;else throw d({token:f.token,errorMessage:`Array element type mismatch:
|
|
11764
11764
|
Expected type: ${M(o)}
|
|
11765
11765
|
Given type: ${M(p.$.type)}`});l.push(p)}let u=mi(o,qn("Usize",i)),_=s.every(c=>!!c)?zi(u,s):void 0;return e.$={env:t,type:u,value:_,pathCollection:[],runtimeArgExprsInOrder:l},It(e,!0),e}function xy(e,t){if(e.token.type==="bool"){let n=e.token.value==="true",r=Zt(n);return e.$={env:t,value:r,type:r.type,pathCollection:[]},e}else throw d({token:e.token,errorMessage:`Expected bool literal, got ${e.tag}`})}function Dy(e,t){if(e.token.type==="char"){let n=XT(e.token.value),r=Pr(BigInt(n));return e.$={env:t,value:r,type:r.type,pathCollection:[]},e}else throw d({token:e.token,errorMessage:`Expected char literal, got ${e.tag}`})}function XT(e){let t=e.slice(1,-1);if(t.length===1)return t.charCodeAt(0);if(t.length===2&&t[0]==="\\"){let n=t[1];switch(n){case"n":return 10;case"t":return 9;case"r":return 13;case"\\":return 92;case"'":return 39;case'"':return 34;case"0":return 0;case"a":return 7;case"b":return 8;case"f":return 12;case"v":return 11;default:throw new Error(`Unknown escape sequence: \\${n}`)}}else throw new Error(`Invalid char literal: ${e}`)}function My({expr:e,env:t,context:n}){let r=[],i=e.args;if(i.length===0)throw d({token:e.token,errorMessage:`Expected at least one element in comptime_list, got ${i.length}`});let o;n.expectedType&&sn(n.expectedType.type)&&(o=n.expectedType.type.childType);for(let s=0;s<i.length;s++){let l=i[s],u=O({expr:l,env:t,context:{...n}});if(!u.$||!u.$.value)throw d({token:l.token,errorMessage:`Failed to evaluate expr_list element. Expected compile-time known value:
|
|
11766
|
-
${I(l)}`});t=u.$.env;let _=u.$.value;if(r.push(_),!o)o=u.$.type;else if(!le({type:o,env:t},{type:u.$.type,env:t}))throw d({token:l.token,errorMessage:`Mismatched element types in comptime_list. Expected element of type ${M(o)}, got ${M(u.$.type)}`})}let a=Jn(o,r);return e.$={env:t,type:a.type,value:a,pathCollection:[]},e}function Oy(e,t,n){let i=ae(t,"Box").find(p=>p.value&&
|
|
11766
|
+
${I(l)}`});t=u.$.env;let _=u.$.value;if(r.push(_),!o)o=u.$.type;else if(!le({type:o,env:t},{type:u.$.type,env:t}))throw d({token:l.token,errorMessage:`Mismatched element types in comptime_list. Expected element of type ${M(o)}, got ${M(u.$.type)}`})}let a=Jn(o,r);return e.$={env:t,type:a.type,value:a,pathCollection:[]},e}function Oy(e,t,n){let i=ae(t,"Box").find(p=>p.value&&ge(p.value[0])&&ne(p.type));if(!i||!i.value||!ge(i.value[0]))throw new Error("Cannot find Box type constructor in environment");let o=i.value[0],a=o.type,s=a.parameters[0],l=Te(e),u=lt(a.env),{env:_}=xe({env:u,variable:{name:s.label,token:Fe,type:l.type,isCompileTimeOnly:!0,initializedAtToken:Fe,consumedAtToken:void 0,value:[l],isOwningTheRcValue:!1}}),{value:c,callerEnv:f}=Oi({functionCalleeExpr:void 0,functionType:a,functionValue:o,argValues:{forallArgs:[],args:[{value:l,parameterType:s.type,argType:Pt()}],variadicArgs:[]},callerEnv:t,calleeEnv:_,context:n});if(!W(c)||!en(c.value))throw new Error("Box type constructor did not return a type value");return{boxType:c.value,env:f}}function QT(e,t,n){var r;try{let i=O({expr:e,env:t,context:n});if(!i.$)return!1;let o=i.$.value;if(ge(o))return!!ae(t,"box").find(l=>l.value&&ge(l.value[0])&&l.value[0]===o);if(W(o)){let s=o.value;return!!((r=s==null?void 0:s.typeName)!=null&&r.startsWith("Box("))}else return!1}catch{return!1}}function Ry({expr:e,env:t,context:n}){Ge(e,P.dyn,1);let r=e.args[0],i=n.expectedType,o;if(n.expectedType&&st(n.expectedType.type)){let y=n.expectedType.type;if(o=Er(Pt(),"",{requiredTraits:y.requiredTraits.map(g=>g.traitType),negativeTraits:y.negativeTraits.map(g=>g.traitType),env:t,context:n}),S(r)&&QT(r.func,t,{...n})&&E(r.args[0],"=>")){let{boxType:g,env:v}=Oy(o,t,n);t=v,i={type:g,env:t}}else i={type:o,env:n.expectedType.env}}else i=void 0;let a=O({expr:r,env:t,context:{...n,expectedType:i}});if(!a.$)throw d({token:r.token,errorMessage:`Failed to evaluate the value expression for 'dyn':
|
|
11767
11767
|
${I(r)}`});let s=a.$.type,l=s,u=a;if(!en(l)&&!(z(l)&&at(l))){let{boxType:y,env:g}=Oy(l,t,{...n});t=g;let v={tag:"Atom",token:{...r.token,value:"box",type:"identifier"},$:void 0},T={tag:"FnCall",func:v,args:[a],token:r.token,$:void 0},$=O({expr:T,env:t,context:{...n,expectedType:{type:y,env:t}}});if(!$.$)throw d({token:r.token,errorMessage:`Failed to auto-box value for 'dyn':
|
|
11768
11768
|
${I(r)}`});t=$.$.env,l=$.$.type,u=$,e.args[0]=$}else t=a.$.env;Bn(u,n),t=u.$.env;let _=[],c=[],f=new Set,p;if(n.expectedType&&st(n.expectedType.type))p=n.expectedType.type;else if(vr(l)){let y=l.fields[0].type;if(y.trait){let g=[];for(let v of y.trait.fields)v.assignedValue&&tn(v.assignedValue)&&g.push(v.assignedValue.type);p=za({requiredTraits:g,negativeTraits:[],env:t}),t=Ra({dynType:p,env:t,context:n})}else throw d({token:e.token,errorMessage:`'${P.dyn}' with Box(T) requires T to have a trait. Got boxed type: ${M(y)}`})}else if(l.trait){let y=[];for(let g of l.trait.fields)g.assignedValue&&tn(g.assignedValue)&&y.push(g.assignedValue.type);p=za({requiredTraits:y,negativeTraits:[],env:t}),t=Ra({dynType:p,env:t,context:n})}else throw d({token:e.token,errorMessage:`'${P.dyn}' requires either an expected Dyn type context, a SomeType (Impl) value, or a type with a trait. Got value type: ${M(l)}`});let m=[];if(vr(l)){let y=l.fields[0].type;(z(y)||st(y))&&m.push(...y.negativeTraits.map(g=>g.traitType)??[])}for(let{traitType:y}of p.requiredTraits)for(let g of m)if(le({type:y,env:t},{type:g,env:t}))throw d({token:e.token,errorMessage:`Required trait ${M(y)} is in the negative traits list and cannot be used.`});for(let{traitType:y}of p.requiredTraits)if(!f.has(y))if(vr(l)&&(z(l.fields[0].type)||st(l.fields[0].type))){let g=l.fields[0].type,v=!1,T=z(g)&&g.resolvedConcreteType?g.resolvedConcreteType:s!==l?s:void 0;if(T!=null&&T.trait){for(let $ of T.trait.fields)if($.assignedValue&&tn($.assignedValue)&&le({type:y,env:t},{type:$.assignedValue.type,env:t})){c.push($.assignedValue),_.push($.assignedValue.type),f.add(y),v=!0;break}}if(!v){let $=g.requiredTraits.map(C=>C.traitType);for(let C of $)if(le({type:y,env:t},{type:C,env:t})){let k=[];for(let w=0;w<y.fields.length;w++){let A=y.fields[w],L=C.fields.findIndex(N=>N.label===A.label);L===-1?k.push(void 0):k.push(C.fields[L].assignedValue)}let b=Mo(y,k);c.push(b),_.push(b.type),f.add(y),v=!0;break}if(!v)throw d({token:e.token,errorMessage:`Required trait ${M(y)} not found in SomeType's requiredTraits.`})}}else{let g=vr(l)?l.fields[0].type:l;if(g.trait){let v=!1;for(let T of g.trait.fields)if(T.assignedValue&&tn(T.assignedValue)&&le({type:y,env:t},{type:T.assignedValue.type,env:t})){c.push(T.assignedValue),_.push(T.assignedValue.type),f.add(y),v=!0;break}if(!v)throw d({token:e.token,errorMessage:`Required trait ${M(y)} is not implemented by type ${M(l)}.`})}else throw d({token:e.token,errorMessage:`Cannot find trait ${M(y)} for value type ${M(l)}.`})}let h=[];for(let{traitType:y}of p.requiredTraits){let g=_.findIndex(v=>le({type:y,env:t},{type:v,env:t}));if(g===-1)throw d({token:e.token,errorMessage:`No trait value found for expected trait type ${M(y)}.`});h.push(c[g])}return e.$={env:t,value:void 0,type:p,pathCollection:a.$.pathCollection,dynCallTraitValues:h},It(e,!0),e}function Py(e,t,n){if(e.token.type==="float"){let r=parseFloat(e.token.value),i="ComptimeFloat";if(n.expectedType){let a=n.expectedType.type;xa(a)?i="F32":Da(a)&&(i="F64")}let o=qn(i,r);return e.$={env:t,value:o,type:o.type,pathCollection:[]},e}else throw d({token:e.token,errorMessage:`Expected float literal, got ${e.tag}`})}function Uy(e,t,n){if(e.token.type==="integer"){let r=e.token.value.replace(/_/g,""),i=10;r.match(/^0x/i)?(i=16,r=r.slice(2)):r.match(/^0b/i)?(i=2,r=r.slice(2)):r.match(/^0o/i)&&(i=8,r=r.slice(2));let o="ComptimeInt";if(n.expectedType){let u=n.expectedType.type;ka(u)?o="Usize":wa(u)?o="Isize":jr(u)?o="U8":Fa(u)?o="I8":La(u)?o="U16":Ia(u)?o="I16":Aa(u)?o="U32":Sa(u)?o="I32":Na(u)?o="U64":Va(u)&&(o="I64")}let a=o==="U64"||o==="I64"||o==="Usize"||o==="Isize",s;a||o==="ComptimeInt"?i===16?s=BigInt("0x"+r):i===8?s=BigInt("0o"+r):i===2?s=BigInt("0b"+r):s=BigInt(r):s=parseInt(r,i);let l=qn(o,s);return e.$={env:t,value:l,type:l.type,pathCollection:[]},e}else throw d({token:e.token,errorMessage:`Expected integer literal, got ${e.tag}`})}function zy(e,t){if(e.token.type==="string"){let n=wn(JSON.parse(e.token.value));return e.$={env:t,value:n,type:n.type,pathCollection:[]},e}else throw d({token:e.token,errorMessage:`Expected string literal, got ${e.tag}`})}function ZT({expr:e,tupleFieldIndex:t,env:n,context:r,elementIndex:i,runtimeArgExprsInOrder:o}){var p;let a=e,s=e,l;if(S(a)&&E(a,":",2)){let m=a.args[0];throw d({token:m.token,errorMessage:"Labelled field is not allowed in tuple value."})}let u=(p=r.expectedType)==null?void 0:p.type,_;if(u){if(!ut(u))throw d({token:e.token,errorMessage:`(2) Failed to evaluate the tuple fields. Expected type to be:
|
|
11769
11769
|
${M(u)}`});let m=u.fields[t];if(!m)throw d({token:e.token,errorMessage:`Failed to get the tuple field at index ${t}`});_=m.type}let c=O({expr:s,env:n,context:{...r,expectedType:_?{type:_,env:n}:void 0}});if(Bn(c,r),!c.$)throw d({token:s.token,errorMessage:`Failed to evaluate the tuple field: ${I(s)}`});n=c.$.env;let f=c.$.value;if(f&&W(c.$.value))throw d({token:s.token,errorMessage:`Cannot store a type value in tuple, please use module instead:
|
|
@@ -11783,7 +11783,7 @@ ${Y}`})}if(L.isCompileTimeOnly||(x=an({type:x,expectedType:L.type,expr:i,env:t})
|
|
|
11783
11783
|
- Expected: ${M(L.type)}
|
|
11784
11784
|
- Given : ${M(x)}`})}else throw d({token:r.token,errorMessage:`Incompatible types:
|
|
11785
11785
|
- Expected: ${M(L.type)}
|
|
11786
|
-
- Given : ${M(x)}`});let V=ae(t,w),U=V[V.length-1],R=(u=i.$)==null?void 0:u.value;W(R)&&!R.value.typeName?(R.value!==n.SelfType&&(R.value.typeName=w),St(U.type)&&!U.type.baseType&&(U.type.baseType=R.value)):
|
|
11786
|
+
- Given : ${M(x)}`});let V=ae(t,w),U=V[V.length-1],R=(u=i.$)==null?void 0:u.value;W(R)&&!R.value.typeName?(R.value!==n.SelfType&&(R.value.typeName=w),St(U.type)&&!U.type.baseType&&(U.type.baseType=R.value)):ge(R)&&!R.funcName?(R.funcName=w,R.funcId+=`_${r.token.value}`):(wt(R)||tn(R))&&!R.type.typeName&&R.type!==n.SelfType&&(R.type.typeName=w);let D=U.type;Be(D)&&Be(x)&&D.selectedVariantName!==x.selectedVariantName&&(D={...D,selectedVariantName:x.selectedVariantName}),z(D)&&z(x)&&x.resolvedConcreteType&&(D={...D,resolvedConcreteType:x.resolvedConcreteType});let H=!1,B=L.isOwningTheSameRcValueAs;if(L.initializedAtToken){if(z(D)&&D.resolvedConcreteType!==void 0)throw Qt([{token:r.token,errorMessage:`Cannot reassign variable "${w}" of type Impl(...).
|
|
11787
11787
|
Impl(...) uses static dispatch and the concrete type is fixed at first assignment.
|
|
11788
11788
|
Consider using Dyn(...) for dynamic dispatch if you need to reassign to different implementations.`},{token:L.initializedAtToken??L.token,errorMessage:"First assigned here:"}]);if(((c=n.isEvaluatingFunctionBodyOrAsyncBlock)==null?void 0:c.kind)==="function-body"&&n.capturedVariables&&n.isEvaluatingFunctionBodyOrAsyncBlock.evaluationEnv){let re=n.isEvaluatingFunctionBodyOrAsyncBlock.evaluationEnv.frames.length;L.frameLevel<re&&ya(L.name,L.frameLevel,"own",r.token,n)}let Y=L.isCompileTimeOnly&&R?tr(R):void 0,J=cn(t.modulePath,w),se=Ga(i,t,t.modulePath),ve=se;se!=null&&se.consumedAtToken&&(ve=void 0),t=bt(t,L,{...L,id:J,value:Y?[Y]:void 0,type:D,isOwningTheRcValue:it(D),isOwningTheSameRcValueAs:ve}),H=!0}else{if(n.isEvaluatingLoopBody&&L.frameLevel<n.isEvaluatingLoopBody.env.frames.length)throw Qt([{token:r.token,errorMessage:"Cannot initialize a variable that is defined outside the while loop."},{token:L.token,errorMessage:"Defined here:"}]);if(((_=n.isEvaluatingFunctionBodyOrAsyncBlock)==null?void 0:_.kind)==="function-body"&&L.frameLevel<n.isEvaluatingFunctionBodyOrAsyncBlock.type.env.frames.length)throw Qt([{token:r.token,errorMessage:"Cannot initialize a variable that is defined outside the function body."},{token:L.token,errorMessage:"Defined here:"}]);let Y=L.isCompileTimeOnly&&R?tr(R):void 0,J=Ga(i,t,t.modulePath),se=J;J!=null&&J.consumedAtToken&&(se=void 0),t=bt(t,L,{...L,initializedAtToken:r.token,value:Y?[Y]:void 0,type:D,isOwningTheRcValue:it(D),isOwningTheSameRcValueAs:se})}let G=ae(t,w),Q=G[G.length-1];return r.$={env:t,type:Q.type,value:Q.isCompileTimeOnly?R:void 0,pathCollection:[[w]]},H?N?e.$={env:t,value:ue,type:ue.type,pathCollection:[],isCompileTimeOnlyAssignment:L.isCompileTimeOnly}:(e.$={env:t,value:(f=L.value)==null?void 0:f[0],type:L.type,pathCollection:[],isCompileTimeOnlyAssignment:L.isCompileTimeOnly},It(e,!0,(B==null?void 0:B.frameLevel)===t.frames.length-1?B:void 0)):e.$={env:t,value:ue,type:ue.type,pathCollection:[],isCompileTimeOnlyAssignment:L.isCompileTimeOnly},e}else{let w=O({expr:r,env:t,context:{...n,expectedType:void 0,isLhsOfAssignment:!0}});if(!w.$)throw d({token:r.token,errorMessage:`Failed to evaluate left-hand side of assignment: ${I(r)}`});if(((p=n.isEvaluatingFunctionBodyOrAsyncBlock)==null?void 0:p.kind)==="function-body"&&w.$.pathCollection){for(let R of w.$.pathCollection)if(R.length>0){let D=R[0];if(typeof D=="string"){let H=ae(t,D);if(H.length>0){let B=H[H.length-1];ya(D,B.frameLevel,"write",r.token,n)}}}}let A=w.$.type;if(i=O({expr:i,env:t,context:{...n,expectedType:{type:A,env:t}}}),!i.$)throw d({token:i.token,errorMessage:`Failed to evaluate right-hand side of assignment: ${I(i)}`});t=i.$.env,po(i,t),Ki(i),Bn(i,n),t=i.$.env;let L=(m=i.$)==null?void 0:m.type;if(!L)try{let{expr:R,type:D,env:H}=Pi({expr:i,type:A,env:t,context:{...n}});i=R,L=D,t=H}catch(R){throw d({token:i.token,errorMessage:`(evaluateAssignment) Failed to synthesize type for expression: ${I(i)}
|
|
11789
11789
|
${R}`})}if(!rn(A)&&!En(A)&&!on(A)&&(L=an({type:L,expectedType:A,expr:i,env:t})),!le({type:A,env:t},{type:L,env:t}))throw d({token:r.token,errorMessage:`Incompatible types:
|
|
@@ -11825,7 +11825,7 @@ ${I(e)}
|
|
|
11825
11825
|
|
|
11826
11826
|
Type:
|
|
11827
11827
|
${M(l.$.type)}`});if(C&&fi(l.$.type,t))throw d({token:e.token,errorMessage:`Expected ":=" instead of "::" for value type "${M(l.$.type)}" which can only be used at the runtime:
|
|
11828
|
-
${I(e)}`});let w=(T=a.$)==null?void 0:T.value;if(W(w)&&!w.value.typeName&&w.value!==n.SelfType?w.value.typeName=l.token.value:
|
|
11828
|
+
${I(e)}`});let w=(T=a.$)==null?void 0:T.value;if(W(w)&&!w.value.typeName&&w.value!==n.SelfType?w.value.typeName=l.token.value:ge(w)&&!w.funcName?(w.funcName=l.token.value,w.funcId+=`_${l.token.value}`):(wt(w)||tn(w))&&!w.type.typeName&&w.type!==n.SelfType&&(w.type.typeName=l.token.value),s&&ge(w)&&(w.isModuleEffectMember=!0),!w&&C)throw d({token:l.token,errorMessage:`Expected compile-time value for "${l.token.value}".
|
|
11829
11829
|
Got runtime value. Please consider using ":=" instead of "::":
|
|
11830
11830
|
${I(a)}`});l.$={...l.$,env:t,type:l.$.type,value:C?w?tr(w):oe(l.$.type,{variableName:l.token.value,env:t,context:n}):void 0,pathCollection:[]};let A=l.$.type;z(A)&&b&&z(b)&&b.resolvedConcreteType&&(A={...A,resolvedConcreteType:b.resolvedConcreteType},l.$.type=A);let L=Ga(a,t,t.modulePath),N=L;L!=null&&L.consumedAtToken&&(N=void 0);let x=l.token.value==="_"?ws(t.modulePath):l.token.value;if(!C&&!n.isEvaluatingFunctionBodyOrAsyncBlock&&n.isInsideImplBlock)throw d({token:l.token,errorMessage:`Mutable runtime variable "${x}" is not allowed inside an impl block.
|
|
11831
11831
|
Use \`::\` for compile-time definitions inside impl.`});let V=!C&&!n.isEvaluatingFunctionBodyOrAsyncBlock,U=($=n.docCommentLookup)==null?void 0:$.get(ur(l.token)),{env:R}=xe({env:t,variable:{name:x,type:A,isCompileTimeOnly:C,value:l.$.value?[l.$.value]:void 0,token:l.token,initializedAtToken:l.token,consumedAtToken:void 0,isOwningTheRcValue:it(A),isOwningTheSameRcValueAs:N,isReassignable:!s,isImplicit:s,isModuleLevel:V,docComment:U}});return t=R,l.token.value==="_"&&(l.$.variableName=x),l.$.env=t,s&&(o.$={env:t,value:ue,type:ue.type,pathCollection:[]}),e.$={env:t,value:ue,type:ue.type,pathCollection:[],isCompileTimeOnlyAssignment:C},e}else{let C=s||r,{env:k,runtimeDestructurings:b}=ig({lhs:l,rhs:a,env:t,isCompileTimeOnly:s||r,context:{...n}});return t=k,e.$={env:t,value:ue,type:ue.type,pathCollection:[],runtimeDestructurings:b,isCompileTimeOnlyAssignment:C},e}}function yE(e){return S(e)?E(e,"|",2):!1}function y_(e){if(!yE(e))return[e];let t=e,n=t.args[0],r=t.args[1];return[...y_(n),...y_(r)]}function ag(e,t,n){if(z(e))for(let r=0;r<t.length;r++){let i=t[r];if(i&&z(i)&&e.id===i.id){let o=n[r];if(o)return o}}return e}function m_(e,t){if(!e.isGadt||!t.gadtReturnTypeArgs||!e.typeConstructorArgs)return!0;for(let n=0;n<e.typeConstructorArgs.length;n++){let r=e.typeConstructorArgs[n],i=t.gadtReturnTypeArgs[n];if(r&&i&&!z(r)&&!le({type:r,env:e.env},{type:i,env:e.env}))return!1}return!0}function gE(e){return ai(e)||si(e)||Kr(e)||lr(e)||rn(e)||En(e)||on(e)}function sg({expr:e,env:t,context:n}){var k,b,w,A,L,N,x,V,U,R,D,H,B;if(!E(e,P.match))throw d({token:e.token,errorMessage:`Expected "match", got ${e.tag}`});let r=e.args;if(r.length<2)throw d({token:e.token,errorMessage:`Expected at least 2 arguments for "match", got ${r.length}`});let i=r[0],o=K(i)?O({expr:i,env:t,context:{...n,expectedType:void 0}}):un({expr:i,env:t,context:{...n,expectedType:void 0},variablesToAdd:[]});if(!o.$||!o.$.variableName)throw d({token:i.token,errorMessage:`Failed to evaluate the match scrutinee expression: ${I(i)}`});t=o.$.env;let a=o.$.type,s=o.$.value,l,u;if(je(a)?(u=a.childType,l=a.tag):u=a,gE(u))return hE({expr:e,env:t,context:n,scrutineeExpr:o,scrutineeType:u,scrutineeValue:s});if(!Be(u))throw d({token:i.token,errorMessage:`Expected enum type or primitive type (integer, bool) for match expression, got ${a?M(a):"unknown type"}`});let _=u,c=_.isGadt===!0&&((k=n.expectedType)==null?void 0:k.type)!==void 0&&_.typeConstructorArgs!==void 0&&_.typeConstructorArgs.length>0,f=r.slice(1),p=[],m,h=new Set,y=!1,g=!1,v=[],T=[],$=-1;for(let G=0;G<f.length;G++){let Q=f[G],Y=t;if(!S(Q)||!E(Q,"=>",2))throw d({token:Q.token,errorMessage:`Expected ":" for match pattern, got ${I(Q)}`});let J=Q.args[0],se=Q.args[1];if(S(J)&&E(J,".",1)||ln(J,"_")){if(g)throw d({token:J.token,errorMessage:'Wildcard pattern "_" can only be used once and must be the last match arm in a "match" expression.'});let ve;if(S(J)){if(ve=J.args[0],!K(ve))throw d({token:J.token,errorMessage:`Expected identifier for enum variant, got ${I(ve)}`})}else g=!0,ve=J;let re=ve.token.value,ce=_.variants.find(fe=>fe.name===re);if(!ce&&re!=="_")throw d({token:J.token,errorMessage:`Enum variant "${re}" not found in ${M(_)}`});if(ce&&ce.fields&&ce.fields.length>0)throw d({token:J.token,errorMessage:`Enum variant "${re}" has ${ce.fields.length} field(s) and must be destructured. Use .${re}(...) instead of .${re}`});if(h.add(re),ce&&!m_(_,ce)||re!=="_"&&mn(s)&&s.variantName!==re)continue;let we={..._,selectedVariantName:re==="_"?void 0:re};ve.$={env:Y,type:we,value:void 0,pathCollection:[]};let Se=we;l&&l==="Ptr"&&(Se=yn(we));let Ve=se;Y=lt(Y),J.$={env:Y,type:Se,value:void 0,pathCollection:[],caseExecuted:!0};let de=un({expr:Ve,env:Y,context:{...n,isExecuting:mn(s)&&s.variantName===re},variablesToAdd:[]});if(!((b=de.$)!=null&&b.type))throw d({token:Ve.token,errorMessage:`Expected type for match result expression, got ${I(Ve)}`});let ee=Ot(de.$.env,!0);if(Y=ee,de.$={...de.$,env:ee},Y=fo(de,Y),de.$.env=Y,s===void 0&&de.$&&(de.$.value=void 0),Gt(de.$.controlFlow))v.push(de.$.controlFlow),zt(de.$.controlFlow,"return")&&T.push(de),s&&!Ie(s)&&mn(s)?e.$={env:de.$.env,type:(w=n.expectedType)!=null&&w.type&&!Me(n.expectedType.type)?n.expectedType.type:de.$.type,value:de.$.value,pathCollection:de.$.pathCollection,controlFlow:de.$.controlFlow}:s===void 0&&(e.$={env:de.$.env,type:(A=n.expectedType)!=null&&A.type&&!Me(n.expectedType.type)?n.expectedType.type:de.$.type,value:void 0,pathCollection:de.$.pathCollection,controlFlow:de.$.controlFlow});else if(y=!0,n.expectedType&&!le(n.expectedType,{type:de.$.type,env:de.$.env}))throw d({token:de.token,errorMessage:`Incompatible type with expected type:
|
|
@@ -11866,13 +11866,13 @@ ${I(e)}`});let r=e.args[0],i=e.args[1];if(r=O({expr:r,env:t,context:{...n,expect
|
|
|
11866
11866
|
${I(i)}`});{let L=i.token.value,N=C.value.trait.fields.find(x=>x.label===L);if(N)return e.$={env:t,type:N.type,value:N.assignedValue,pathCollection:[],isAccessingProperty:!0},i.$=e.$,e}let k=i.token.value,b=C.value,w=b.variants.find(L=>L.name===k);if(!w){let L=Dr({concreteType:C.value,methodName:k,env:t});if(L.length===1){let N=L[0];return e.$={env:t,type:N.type,value:N.value,pathCollection:[],isAccessingProperty:!0},i.$=e.$,e}if(L.length>1)return e.$=void 0,e;throw d({token:i.token,errorMessage:`Enum variant "${k}" not found in enum`})}let A={...b,selectedVariantName:k};if(!w.fields)e.$={env:t,type:A,value:uo(A,k,[]),isAccessingProperty:!0,pathCollection:[]},i.$=e.$;else{let L=Te(A);e.$={env:t,type:L.type,value:L,isAccessingProperty:!0,pathCollection:[]},i.$=e.$}return e}else if(C.value.trait){if(!Nt(i))throw d({token:i.token,errorMessage:`Expected identifier for type method, got:
|
|
11867
11867
|
${I(i)}`});let k=i.token.value,b=C.value.trait.fields.findLast(w=>w.label===k);if(b){if(b.assignedValue){let w=b.assignedValue.type;return e.$={env:t,type:w,value:b.assignedValue,pathCollection:[],isAccessingProperty:!0},i.$=e.$,e}if(b.unassignedSomeType){let w=Te(b.unassignedSomeType);return e.$={env:t,type:w.type,value:w,pathCollection:[],isAccessingProperty:!0},i.$=e.$,e}return e.$={env:t,type:b.type,value:void 0,pathCollection:[],isAccessingProperty:!0},i.$=e.$,e}else{for(let L of C.value.trait.fields)if(L.label===""&&L.assignedValue&&tn(L.assignedValue)){let N=L.assignedValue,x=N.type,V=x.fields.findIndex(U=>U.label===k);if(V>=0){let U=x.fields[V],R=N.fields[V];if(ne(U.type))continue;if(R)return e.$={env:t,type:R.type,value:R,pathCollection:[],isAccessingProperty:!0},i.$=e.$,e;if(U.unassignedSomeType){let D=Te(U.unassignedSomeType);return e.$={env:t,type:D.type,value:D,pathCollection:[],isAccessingProperty:!0},i.$=e.$,e}}}let w=Dr({concreteType:C.value,methodName:k,env:t});if(w.length===1){let L=w[0];return e.$={env:t,type:L.type,value:L.value,pathCollection:[],isAccessingProperty:!0},i.$=e.$,e}if(n.isEvaluatingGenericImplSpecialization){let L=ae(t,k);if(L.length>0){let N=L[L.length-1];if(N.value&&N.value.length>0&&W(N.value[0]))return e.$={env:t,type:N.value[0].type,value:N.value[0],pathCollection:[],isAccessingProperty:!0},i.$=e.$,e}}let A=Cl({concreteType:C.value,propertyName:k,env:t});return A?(e.$={env:t,type:A.type,value:A.value,pathCollection:[],isAccessingProperty:!0},i.$=e.$,e):(e.$=void 0,e)}}else if(Xe(C.value)){if(!Nt(i))throw d({token:i.token,errorMessage:`Expected identifier for type method, got:
|
|
11868
11868
|
${I(i)}`});let k=i.token.value,w=C.value.fields.find(A=>A.label===k);return w?(e.$={env:t,type:w.type,value:w.assignedValue??oe(w.type,{variableName:w.label,env:t,context:n}),pathCollection:[],isAccessingProperty:!0},i.$=e.$,e):(e.$=void 0,e)}else if(ot(C.value)){if(!Nt(i))throw d({token:i.token,errorMessage:`Expected identifier for type method, got:
|
|
11869
|
-
${I(i)}`});let k=i.token.value,b=C.value;if(b.receiverType&&b.receiverType.trait){for(let L of b.receiverType.trait.fields)if(L.label===""&&L.assignedValue&&tn(L.assignedValue)){let N=L.assignedValue,x=N.type;if(!le({type:b,env:t},{type:x,env:t}))continue;let V=x.fields.findIndex(U=>U.label===k&&ne(U.type));if(V>=0){let U=x.fields[V];if(ne(U.type)){let R=N.fields[V];if(R){let D=U.type;return
|
|
11869
|
+
${I(i)}`});let k=i.token.value,b=C.value;if(b.receiverType&&b.receiverType.trait){for(let L of b.receiverType.trait.fields)if(L.label===""&&L.assignedValue&&tn(L.assignedValue)){let N=L.assignedValue,x=N.type;if(!le({type:b,env:t},{type:x,env:t}))continue;let V=x.fields.findIndex(U=>U.label===k&&ne(U.type));if(V>=0){let U=x.fields[V];if(ne(U.type)){let R=N.fields[V];if(R){let D=U.type;return ge(R)&&R.specializedType&&(D=R.specializedType),e.$={env:t,type:D,value:R,pathCollection:[],isAccessingProperty:!0},i.$=e.$,e}}}}let A=Tc({concreteType:b.receiverType,traitType:b,methodName:k,env:t});if(A)return e.$={env:t,type:A.type,value:A.value,pathCollection:[],isAccessingProperty:!0},i.$=e.$,e}let w=b.fields.find(A=>A.label===k);return w?(e.$={env:t,type:w.type,value:w.assignedValue??oe(w.type,{variableName:w.label,env:t,context:n}),pathCollection:[],isAccessingProperty:!0},i.$=e.$,e):(e.$=void 0,e)}}let o=(p=r.$)==null?void 0:p.type,a=(m=r.$)==null?void 0:m.type;for(;o&&je(o);)o=o.childType;if(ut(o)||Ae(o)||Bt(o)){let C=o.fields,k=r.$.value;if(K(i)){if(i.token.type==="integer"){if(!ut((h=r.$)==null?void 0:h.type))throw d({token:i.token,errorMessage:"Accessing tuple field by index is only allowed for tuples."});let b=parseInt(i.token.value,10);if(isNaN(b))throw d({token:i.token,errorMessage:`Expected integer for tuple index, got:
|
|
11870
11870
|
${I(i)}`});let w=C.length;if(b<0||b>=w)throw d({token:i.token,errorMessage:`Index out of bounds: ${b} for accessing field in:
|
|
11871
11871
|
${M((y=r.$)==null?void 0:y.type)}`});let A=C[b],L=r.$.originType||a,N=r.$.pathCollection&&r.$.pathCollection.length>0?r.$.pathCollection.map(x=>[...x,i.token.value]):[[r.$.variableName??"?",i.token.value]];if(e.$={env:t,type:A.type,originType:L,isAccessingProperty:!0,pathCollection:N},i.$=e.$,k){let x=[];(Zn(k)||kn(k))&&(x=k.fields),e.$.value=x==null?void 0:x[b]}return It(e,!1),e}else if(Nt(i)){let b=i.token.value;{let w=C.findIndex(x=>x.label===b);if(w<0){if(Xe((g=r.$)==null?void 0:g.type))throw d({token:i.token,errorMessage:`Module field "${b}" not found in module type`});return e.$=void 0,e}let A=C[w],L=((v=r.$)==null?void 0:v.originType)||a,N=r.$.pathCollection&&r.$.pathCollection.length>0?r.$.pathCollection.map(x=>[...x,i.token.value]):[[r.$.variableName??"?",i.token.value]];if(e.$={env:t,type:A.type,originType:L,isAccessingProperty:!0,pathCollection:N},i.$=e.$,k)if(Ie(k)){let x=oe(A.type,{env:t,context:n});k.isRuntimeOnly&&Ie(x)&&(x.isRuntimeOnly=!0),e.$.value=x}else{let x=k;if(Vr(k)){let R=k.targetValue[0];mr(R)?x=R.elements[k.targetIndex]:x=R}let V=[];(Zn(x)||kn(x))&&(V=x.fields);let U=V==null?void 0:V[w];U||(U=oe(A.type,{env:t,context:n})),e.$.value=U,Vr(k)&&(kn(x)?e.$.comptimeRef={kind:"struct",structValue:x,fieldIndex:w}:Zn(x)&&(e.$.comptimeRef={kind:"tuple",tupleValue:x,fieldIndex:w}))}return It(e,!1),e}}}}else if(Xe(o)){let C=o.fields,k=r.$.value;if(K(i)){if(i.token.type==="integer")throw d({token:i.token,errorMessage:`Accessomg module field by index is not allowed, got:
|
|
11872
11872
|
${I(i)}`});if(Nt(i)){let b=i.token.value;{let w=C.findIndex(N=>N.label===b);if(w<0){if(Xe((T=r.$)==null?void 0:T.type))throw k&&wt(k)&&k.isLoading?d({token:i.token,errorMessage:`Field "${b}" is not yet available from this module. In a circular import, only fields exported before the import of the current module are accessible. Reorder your exports or break the cycle.`}):d({token:i.token,errorMessage:`Module field "${b}" not found in module type`});return e.$=void 0,e}let A=C[w],L=r.$.pathCollection&&r.$.pathCollection.length>0?r.$.pathCollection.map(N=>[...N,i.token.value]):[[r.$.variableName??"?",i.token.value]];if(e.$={env:t,type:A.type,isAccessingProperty:!0,pathCollection:L},i.$=e.$,k)if(Ie(k)){let N=oe(A.type,{env:t,context:n});k.isRuntimeOnly&&Ie(N)&&(N.isRuntimeOnly=!0),e.$.value=N}else{let N=[];wt(k)&&(N=k.fields);let x=N==null?void 0:N[w];x||(x=oe(A.type,{env:t,context:n})),e.$.value=x}return e}}}}else if(Be(o)&&K(i)){if(!Nt(i))throw d({token:i.token,errorMessage:`Expected identifier for enum variant property, got:
|
|
11873
11873
|
${I(i)}`});let C=i.token.value,k=o.variants.find(b=>b.name===o.selectedVariantName);if(k){let b=(k.fields??[]).findIndex(L=>L.label===C);if(b<0)return e.$=void 0,e;let w=(k.fields??[])[b];e.$={env:t,type:w.type,value:void 0,pathCollection:[[r.$.variableName??"?",i.token.value]],isAccessingProperty:!0};let A=($=r.$)==null?void 0:$.value;return A&&mn(A)&&A.variantName===k.name&&(e.$.value=A.fields[b]),i.$=e.$,e}}return e.$=void 0,e}function _g({expr:e,env:t,context:n}){var o;if(((o=n.isEvaluatingFunctionBodyOrAsyncBlock)==null?void 0:o.kind)!=="function-body")throw d({token:e.token,errorMessage:`Expected a function type for recur, got:
|
|
11874
11874
|
${I(e)}`});let r=n.isEvaluatingFunctionBodyOrAsyncBlock.type;if(!E(e,P.recur))throw d({token:e.token,errorMessage:`Expected recur, got:
|
|
11875
|
-
${I(e)}`});if(n.isAnalyzingCtfeCapability||n.isValidatingFunctionDefinition){let a=n.isEvaluatingFunctionBodyOrAsyncBlock.value,{returnType:s,runtimeArgExprsInOrder:l,callerEnv:u}=to({functionValue:
|
|
11875
|
+
${I(e)}`});if(n.isAnalyzingCtfeCapability||n.isValidatingFunctionDefinition){let a=n.isEvaluatingFunctionBodyOrAsyncBlock.value,{returnType:s,runtimeArgExprsInOrder:l,callerEnv:u}=to({functionValue:ge(a)?a:void 0,functionType:r,expr:e,functionCalleeExpr:e.func,argExprs:e.args,callerEnv:t,context:n,isMethodCall:!1,skipSpecialization:!0,skipCtfeExecution:!0});return t=Ot(u),e.$={type:s,value:oe(s,{variableName:"recur_result_"+mt(t.modulePath),env:t,context:n}),env:t,pathCollection:[],runtimeArgExprsInOrder:l},e}return Mr({expr:e,env:t,givenFunc:{type:r,value:n.isEvaluatingFunctionBodyOrAsyncBlock.value??void 0},context:{...n}})}function cg({expr:e,env:t,context:n}){var a;if(!E(e,P.runtime,1))throw d({token:e.token,errorMessage:`Expected runtime(expr), got:
|
|
11876
11876
|
${I(e)}`});if(n.isAnalyzingCtfeCapability)throw d({token:e.token,errorMessage:'Cannot use "runtime" during compile-time function evaluation analysis. The "runtime" keyword forces runtime evaluation and prevents CTFE.'});let r=e.args[0],i=O({expr:r,env:t,context:{...n}});if(!((a=i.$)!=null&&a.type))throw d({token:i.token,errorMessage:`Failed to evaluate runtime argument:
|
|
11877
11877
|
${I(i)}`});let o=an({type:i.$.type,expectedType:void 0,expr:i,env:i.$.env??t});return e.$={type:o,value:void 0,env:i.$.env??t,pathCollection:i.$.pathCollection??[]},e}function fg({expr:e,env:t,context:n}){Ge(e,"<:",2);let r=e.args[0],i=e.args[1],o=O({expr:r,env:t,context:{...n}});if(!o.$||!o.$.value||!W(o.$.value))throw d({token:r.token,errorMessage:"Expected type for left-hand side expression."});t=o.$.env;let a=o.$.value;if(n.isInsideWhereClause&&!z(a.value))throw d({token:r.token,errorMessage:`In a where clause, the left-hand side of <: must be a type parameter (SomeType), got: ${I(r)} of type ${M(a.value)}`});let s=[];if(S(i)&&E(i,P.tuple))for(let p of i.args)S(p)&&E(p,"!")&&p.args.length===1?s.push({expr:p.args[0],isNegated:!0}):s.push({expr:p,isNegated:!1});else S(i)&&E(i,"!")&&i.args.length===1?s.push({expr:i.args[0],isNegated:!0}):s.push({expr:i,isNegated:!1});let l=[];for(let{expr:p,isNegated:m}of s){let h=O({expr:p,env:t,context:{...n}});if(!h.$||!h.$.value||!W(h.$.value)||!ot(h.$.value.value))throw d({token:p.token,errorMessage:"Expected trait type for right-hand side expression."});t=h.$.env;let y=h.$.value.value;if(y.receiverType)throw d({token:p.token,errorMessage:"Expected trait type already has a receiver type assigned."});if(m&&!n.isInsideWhereClause)throw d({token:p.token,errorMessage:"Negated trait constraints !(Trait) are only allowed in where clauses."});l.push({traitType:y,expr:p,isNegated:m})}if(n.isInsideWhereClause&&z(a.value)){let p=a.value;for(let{traitType:m,isNegated:h}of l){let y={...m,receiverType:p};t=ni({env:t,someType:p,traitType:y,isNegated:h})}return e.$={env:t,value:a,type:a.type,pathCollection:[]},e}if(l.length>1)throw d({token:i.token,errorMessage:"Multiple trait constraints (tuple form) are only allowed in where clauses."});let{traitType:u}=l[0],_=a.value;if(!z(_)&&!bn({targetType:_,traitType:u,env:t}))throw d({token:e.token,errorMessage:`Type "${M(_)}" does not implement trait "${u.typeName??M(u)}".`});let c={...u,receiverType:a.value},f=Te(c);return e.$={env:t,value:f,type:f.type,pathCollection:[]},e}function pg({expr:e,env:t,context:n}){if(!E(e,P.test))throw d({token:e.token,errorMessage:`Expected test, got ${e.tag}`});if(e.args.length!==2)throw d({token:e.token,errorMessage:`test expects 2 arguments (name, body), got ${e.args.length}. IO is implicitly available via "io" \u2014 no using clause needed.`});let r=e.args[0],i=e.args[1],o=O({expr:r,env:t,context:{...n}});if(!o.$||!o.$.value)throw d({token:r.token,errorMessage:`Failed to evaluate test name: ${I(r)}`});if(t=o.$.env,!tt(o.$.value))throw d({token:r.token,errorMessage:`Expected string for test name, got ${I(r)}`});let a=ae(t,"IO"),s=a[a.length-1];if(!s)throw d({token:e.token,errorMessage:"IO module not found in environment. Is the prelude loaded?"});let l=Array.isArray(s.value)?s.value[0]:s.value,u=l&&W(l)?l.value:s.type,_=lt(t),c=oe(u,{variableName:"io",env:_,context:n}),f={name:"io",type:u,value:[c],isCompileTimeOnly:!0,isOwningTheRcValue:!1,isImplicit:!0,isReassignable:!1,initializedAtToken:e.token,consumedAtToken:void 0,token:e.token};_=xe({env:_,variable:f,allowVariableShadowing:!0}).env;let m=_t(i),h=O({expr:i,env:_,context:{...n,isEvaluatingFunctionBodyOrAsyncBlock:{kind:"test-block",evaluationEnv:_}}});if(!h.$)throw d({token:i.token,errorMessage:`Failed to evaluate test body: ${I(i)}`});if(!De(h.$.type))throw d({token:i.token,errorMessage:`Test body must have 'unit' type, got ${M(h.$.type)}`});return h.$.originalExpr=m,e.$={env:t,type:ue.type,value:ue,pathCollection:[]},e}function dg({expr:e,env:t,context:n}){var s,l;if(!E(e,F.typeof,1))throw d({token:e.token,errorMessage:`Expected "typeof" with 1 argument, got:
|
|
11878
11878
|
${I(e)}`});let r=e.args[0],i=O({expr:r,env:t,context:{...n}});if((s=i.$)!=null&&s.env&&(t=i.$.env),!((l=i.$)!=null&&l.type))throw d({token:r.token,errorMessage:`Expected type for expression, got:
|