Fixing multi argument Constructors. Adding a layout system! Flex and fixed within a column

This commit is contained in:
Dustin Swan 2026-04-01 16:00:11 -06:00
parent ef48a4f468
commit 6656b90717
No known key found for this signature in database
GPG key ID: 30D46587E2100467
2 changed files with 66 additions and 5 deletions

View file

@ -43,13 +43,28 @@ export function compile(ast: AST, ctx: CompileCtx = defaultCtx): string {
}
case 'apply':
// Constructor
if (ast.func.kind === 'constructor') {
const ctorName = ast.func.name;
const arg = compile(ast.args[0], ctx);
return `({ _tag: "${ctorName}", _0: ${arg} })`;
// Collect constructor args from nested applie
let node: AST = ast;
const ctorArgs: AST[] = [];
while (node.kind === 'apply' && node.func.kind !== 'constructor') {
// Check if inner func is a constructor chain
if (node.func.kind === 'apply') {
ctorArgs.unshift(node.args[0]);
node = node.func;
} else {
break;
}
}
// Constructor
if (node.kind === 'apply' && node.func.kind === 'constructor') {
ctorArgs.unshift(node.args[0]);
const ctorName = node.func.name;
const compiledArgs = ctorArgs.map((a, i) => `_${i}: ${compile(a, ctx)}`).join(', ');
return `({ _tag: "${ctorName}", ${compiledArgs} })`;
}
// Function application
const args = ast.args.map(a => compile(a, ctx)).join(')(');
return `${compile(ast.func, ctx)}(${args})`;