imxc 0.6.6 → 0.6.8
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/dist/emitter.js +9 -3
- package/dist/init.js +1 -1
- package/dist/ir.d.ts +1 -1
- package/dist/lowering.js +57 -3
- package/dist/templates/custom.js +1 -1
- package/dist/templates/hotreload.js +1 -1
- package/dist/templates/index.js +1 -1
- package/package.json +1 -1
package/dist/emitter.js
CHANGED
|
@@ -1346,8 +1346,14 @@ function emitBeginContainer(node, lines, indent) {
|
|
|
1346
1346
|
}
|
|
1347
1347
|
case 'ID': {
|
|
1348
1348
|
const scope = node.props['scope'] ?? '""';
|
|
1349
|
-
|
|
1350
|
-
|
|
1349
|
+
const scopeType = node.props['_scopeType'] ?? (scope.startsWith('"') ? 'string' : 'number');
|
|
1350
|
+
if (scopeType === 'string') {
|
|
1351
|
+
if (scope.startsWith('"') || scope.endsWith('.c_str()')) {
|
|
1352
|
+
lines.push(`${indent}ImGui::PushID(${scope});`);
|
|
1353
|
+
}
|
|
1354
|
+
else {
|
|
1355
|
+
lines.push(`${indent}ImGui::PushID((${scope}).c_str());`);
|
|
1356
|
+
}
|
|
1351
1357
|
}
|
|
1352
1358
|
else {
|
|
1353
1359
|
lines.push(`${indent}ImGui::PushID(static_cast<int>(${scope}));`);
|
|
@@ -1642,7 +1648,7 @@ function emitText(node, lines, indent) {
|
|
|
1642
1648
|
function emitButton(node, lines, indent, depth) {
|
|
1643
1649
|
emitLocComment(node.loc, 'Button', lines, indent);
|
|
1644
1650
|
const title = asCharPtr(node.title);
|
|
1645
|
-
const disabledArg = node.disabled ?
|
|
1651
|
+
const disabledArg = node.disabled !== undefined ? `, {}, ${node.disabled}` : '';
|
|
1646
1652
|
const pressedVar = node.action.length > 0 ? nextWidgetTemp('button_pressed') : undefined;
|
|
1647
1653
|
const resultVar = emitBoolWidgetCall(`imx::renderer::button(${title}${disabledArg})`, node.item, lines, indent, pressedVar);
|
|
1648
1654
|
if (node.action.length > 0 && resultVar) {
|
package/dist/init.js
CHANGED
|
@@ -39,7 +39,7 @@ export function addToProject(projectDir) {
|
|
|
39
39
|
console.log(' include(FetchContent)');
|
|
40
40
|
console.log(' FetchContent_Declare(imx');
|
|
41
41
|
console.log(' GIT_REPOSITORY https://github.com/bgocumlu/imx.git');
|
|
42
|
-
console.log(' GIT_TAG v0.6.
|
|
42
|
+
console.log(' GIT_TAG v0.6.8');
|
|
43
43
|
console.log(' )');
|
|
44
44
|
console.log(' FetchContent_MakeAvailable(imx)');
|
|
45
45
|
console.log(' include(ImxCompile)');
|
package/dist/ir.d.ts
CHANGED
package/dist/lowering.js
CHANGED
|
@@ -316,6 +316,54 @@ export function exprToCpp(node, ctx) {
|
|
|
316
316
|
// Fallback: use text representation
|
|
317
317
|
return node.getText();
|
|
318
318
|
}
|
|
319
|
+
function isStringLikeExpr(expr, ctx) {
|
|
320
|
+
if (ts.isStringLiteral(expr) || ts.isNoSubstitutionTemplateLiteral(expr) || ts.isTemplateExpression(expr)) {
|
|
321
|
+
return true;
|
|
322
|
+
}
|
|
323
|
+
if (ts.isConditionalExpression(expr)) {
|
|
324
|
+
return isStringLikeExpr(expr.whenTrue, ctx) || isStringLikeExpr(expr.whenFalse, ctx);
|
|
325
|
+
}
|
|
326
|
+
if (ts.isBinaryExpression(expr) && expr.operatorToken.kind === ts.SyntaxKind.PlusToken) {
|
|
327
|
+
return isStringLikeExpr(expr.left, ctx) || isStringLikeExpr(expr.right, ctx)
|
|
328
|
+
|| inferExprType(expr.left, ctx) === 'string'
|
|
329
|
+
|| inferExprType(expr.right, ctx) === 'string';
|
|
330
|
+
}
|
|
331
|
+
return inferExprType(expr, ctx) === 'string';
|
|
332
|
+
}
|
|
333
|
+
function coerceExprToCppString(expr, ctx) {
|
|
334
|
+
if (ts.isStringLiteral(expr) || ts.isNoSubstitutionTemplateLiteral(expr)) {
|
|
335
|
+
return JSON.stringify(expr.text);
|
|
336
|
+
}
|
|
337
|
+
if (ts.isConditionalExpression(expr)) {
|
|
338
|
+
const condition = exprToCpp(expr.condition, ctx);
|
|
339
|
+
const whenTrue = coerceExprToCppString(expr.whenTrue, ctx);
|
|
340
|
+
const whenFalse = coerceExprToCppString(expr.whenFalse, ctx);
|
|
341
|
+
return `${condition} ? ${whenTrue} : ${whenFalse}`;
|
|
342
|
+
}
|
|
343
|
+
const cppExpr = exprToCpp(expr, ctx);
|
|
344
|
+
if (isStringLikeExpr(expr, ctx)) {
|
|
345
|
+
return cppExpr.startsWith('"') ? `std::string(${cppExpr})` : cppExpr;
|
|
346
|
+
}
|
|
347
|
+
if (inferExprType(expr, ctx) === 'bool') {
|
|
348
|
+
return `${cppExpr} ? std::string("true") : std::string("false")`;
|
|
349
|
+
}
|
|
350
|
+
return `std::to_string(${cppExpr})`;
|
|
351
|
+
}
|
|
352
|
+
function normalizeIdScopeAttrs(attrs, rawAttrs, ctx) {
|
|
353
|
+
const normalized = { ...attrs };
|
|
354
|
+
const scopeExpr = rawAttrs.get('scope');
|
|
355
|
+
if (!scopeExpr)
|
|
356
|
+
return normalized;
|
|
357
|
+
if (isStringLikeExpr(scopeExpr, ctx)) {
|
|
358
|
+
normalized['scope'] = coerceExprToCppString(scopeExpr, ctx);
|
|
359
|
+
normalized['_scopeType'] = 'string';
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
normalized['scope'] = exprToCpp(scopeExpr, ctx);
|
|
363
|
+
normalized['_scopeType'] = 'number';
|
|
364
|
+
}
|
|
365
|
+
return normalized;
|
|
366
|
+
}
|
|
319
367
|
function stmtToCpp(stmt, ctx) {
|
|
320
368
|
if (ts.isExpressionStatement(stmt)) {
|
|
321
369
|
return exprToCpp(stmt.expression, ctx) + ';';
|
|
@@ -444,8 +492,11 @@ function lowerJsxElement(node, body, ctx) {
|
|
|
444
492
|
}
|
|
445
493
|
if (isHostComponent(name)) {
|
|
446
494
|
const def = HOST_COMPONENTS[name];
|
|
447
|
-
|
|
495
|
+
let attrs = getAttributes(node.openingElement.attributes, ctx);
|
|
448
496
|
const rawAttrs = getRawAttributes(node.openingElement.attributes);
|
|
497
|
+
if (name === 'ID') {
|
|
498
|
+
attrs = normalizeIdScopeAttrs(attrs, rawAttrs, ctx);
|
|
499
|
+
}
|
|
449
500
|
if (name === 'Table') {
|
|
450
501
|
lowerTableElement(node, body, ctx, attrs, rawAttrs, getLoc(node, ctx));
|
|
451
502
|
return;
|
|
@@ -630,8 +681,11 @@ function lowerJsxSelfClosing(node, body, ctx) {
|
|
|
630
681
|
}
|
|
631
682
|
return;
|
|
632
683
|
}
|
|
633
|
-
|
|
684
|
+
let attrs = getAttributes(node.attributes, ctx);
|
|
634
685
|
const rawAttrs = getRawAttributes(node.attributes);
|
|
686
|
+
if (name === 'ID') {
|
|
687
|
+
attrs = normalizeIdScopeAttrs(attrs, rawAttrs, ctx);
|
|
688
|
+
}
|
|
635
689
|
const loc = getLoc(node, ctx);
|
|
636
690
|
switch (name) {
|
|
637
691
|
case 'Table': {
|
|
@@ -991,7 +1045,7 @@ function lowerButton(attrs, rawAttrs, body, ctx, loc) {
|
|
|
991
1045
|
if (onPressExpr) {
|
|
992
1046
|
action = extractActionStatements(onPressExpr, ctx);
|
|
993
1047
|
}
|
|
994
|
-
const disabled = attrs['disabled']
|
|
1048
|
+
const disabled = attrs['disabled'];
|
|
995
1049
|
const style = attrs['style'];
|
|
996
1050
|
const item = lowerItemInteraction(attrs, rawAttrs, ctx);
|
|
997
1051
|
body.push({ kind: 'button', title, action, disabled, style, item, loc });
|
package/dist/templates/custom.js
CHANGED
package/dist/templates/index.js
CHANGED