Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable type conversions #63

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Enable type conversions #63

wants to merge 11 commits into from

Conversation

AprupKale
Copy link
Contributor

Fixes #56

@AprupKale AprupKale added the enhancement New feature or request label Jan 21, 2025
@AprupKale AprupKale self-assigned this Jan 21, 2025
Copy link

github-actions bot commented Jan 21, 2025

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
74% (+0.05% 🔼)
7259/9809
🟡 Branches
60.43% (+0.04% 🔼)
2410/3988
🟡 Functions
69.55% (+0.1% 🔼)
1293/1859
🟡 Lines
74.97% (+0.04% 🔼)
6844/9129
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🟢
... / assignmentExpression.test.ts
100% 100% 100% 100%
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟢
... / code-generator.ts
91.51% (-2.9% 🔻)
77.45% (-7.2% 🔻)
93.62% (+0.44% 🔼)
91.75% (-2.99% 🔻)

Test suite run success

1136 tests passing in 63 suites.

Report generated by 🧪jest coverage report action from 2a2cc0b

@AprupKale AprupKale requested a review from 1001mei January 28, 2025 07:51
Comment on lines +213 to +215
if (areClassTypesCompatible(fromType, toType) || fromType === '') {
return 0;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When will fromType be empty?

Comment on lines +768 to +772
const methodInfo = symbolInfos[symbolInfos.length - 1] as MethodInfos
if (!methodInfo || methodInfo.length === 0) {
throw new Error(`No method information found for ${n.identifier}`)
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps can rename methodInfo to methodInfos, then can remove the methodInfos in line 796 to remove duplication

Comment on lines +773 to +789
const fullDescriptor = methodInfo[0].typeDescriptor // Full descriptor, e.g., "(Ljava/lang/String;C)V"
const paramDescriptor = fullDescriptor.slice(1, fullDescriptor.indexOf(')')) // Extract "Ljava/lang/String;C"
const params = paramDescriptor.match(/(\[+[BCDFIJSZ])|(\[+L[^;]+;)|[BCDFIJSZ]|L[^;]+;/g)

// Parse individual parameter types
if (params && params.length !== n.argumentList.length) {
throw new Error(
`Parameter mismatch: expected ${params?.length || 0}, got ${n.argumentList.length}`
)
}

n.argumentList.forEach((x, i) => {
const argCompileResult = compile(x, cg)
maxStack = Math.max(maxStack, i + 1 + argCompileResult.stackSize)

const expectedType = params?.[i] // Expected parameter type
const stackSizeChange = handleImplicitTypeConversion(argCompileResult.resultType, expectedType ?? '', cg)
maxStack = Math.max(maxStack, i + 1 + argCompileResult.stackSize + stackSizeChange)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i assume your scope are not supporting method overloading? otherwise might have issues of converting type unnecessary because here it's always converted to match the first method in methodInfo array.

cg.code.push(typeConversionsImplicit[conversionKeyRight])
finalType = 'D';
} else if (leftType !== 'F' && rightType === 'F') {
// handleImplicitTypeConversion(leftType, 'F', cg);
Copy link
Contributor

@1001mei 1001mei Feb 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can remove this commented out line~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compiler: type conversion
2 participants