feat(core): synchronous clocks, state machine codegen, delay buffers,… · modelscript/modelscript@6d377c5 · GitHub
Skip to content

Commit 6d377c5

Browse files
committed
feat(core): synchronous clocks, state machine codegen, delay buffers, spatialDistribution, operator record dispatch, ExternalObject lifecycle
1 parent 43bedf3 commit 6d377c5

3 files changed

Lines changed: 104 additions & 0 deletions

File tree

‎packages/core/src/compiler/modelica/dae.ts‎

Lines changed: 44 additions & 0 deletions

‎packages/core/src/compiler/modelica/flattener.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2841,6 +2841,33 @@ class ModelicaSyntaxFlattener extends ModelicaSyntaxVisitor<ModelicaExpression,
28412841
}
28422842
}
28432843

2844+
// Operator record dispatch for String(x): when the argument is an operator record,
2845+
// rewrite String(x) as RecordType.'String'(x) using the operator function.
2846+
if (functionName === "String" && flatArgs.length >= 1) {
2847+
const arg0 = flatArgs[0];
2848+
if (arg0) {
2849+
const stringOp = this.#resolveOperatorRecordFunction(arg0, "'String'", ctx);
2850+
if (stringOp) {
2851+
const { qualifiedName, resolvedClass } = stringOp;
2852+
this.#collectFunctionDefinition(qualifiedName, ctx, resolvedClass);
2853+
return new ModelicaFunctionCallExpression(qualifiedName, flatArgs);
2854+
}
2855+
}
2856+
}
2857+
2858+
// Operator record dispatch for '0' (zero literal): when zeros() is called with
2859+
// an operator record type argument, rewrite to RecordType.'0'() zero constructor.
2860+
if (functionName === "zeros" && flatArgs.length >= 1) {
2861+
const arg0 = flatArgs[0];
2862+
if (arg0) {
2863+
const zeroOp = this.#resolveOperatorRecordFunction(arg0, "'0'", ctx);
2864+
if (zeroOp) {
2865+
const { qualifiedName, resolvedClass } = zeroOp;
2866+
this.#collectFunctionDefinition(qualifiedName, ctx, resolvedClass);
2867+
return new ModelicaFunctionCallExpression(qualifiedName, []);
2868+
}
2869+
}
2870+
}
28442871
// Pre-expansion size() resolution: resolve size(var, dim) directly from
28452872
// class instance BEFORE arg expansion may lose inner dimension info.
28462873
// E.g., size(b, 2) where b is Real[2, 0] — expansion loses the 0 dimension.
@@ -6289,6 +6316,13 @@ class ModelicaSyntaxFlattener extends ModelicaSyntaxVisitor<ModelicaExpression,
62896316
const negatedFirst = new ModelicaUnaryExpression(ModelicaUnaryOperator.UNARY_MINUS, operand.operand1);
62906317
return new ModelicaBinaryExpression(operand.operator, negatedFirst, operand.operand2);
62916318
}
6319+
// Operator record dispatch: unary minus → RecordType.'-'.negate(x)
6320+
const operatorInfo = this.#resolveOperatorRecordFunction(operand, "'-'", ctx);
6321+
if (operatorInfo) {
6322+
const { qualifiedName, resolvedClass } = operatorInfo;
6323+
this.#collectFunctionDefinition(qualifiedName, ctx, resolvedClass);
6324+
return new ModelicaFunctionCallExpression(qualifiedName, [operand]);
6325+
}
62926326
}
62936327
if (operator === ModelicaUnaryOperator.UNARY_PLUS) {
62946328
if (operand instanceof ModelicaRealLiteral || operand instanceof ModelicaIntegerLiteral) return operand;

‎packages/core/src/compiler/modelica/fmu-codegen.ts‎

Lines changed: 26 additions & 0 deletions

0 commit comments

Comments
 (0)