Skip to content

C Numbers #1684

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

C Numbers #1684

wants to merge 3 commits into from

Conversation

tothambrus11
Copy link
Collaborator

This is a draft PR yet, I still need to write tests for it and the API probably needs to be revised.

Capabilities:

  • They are Equatable, Movable, Copiable, ExpressibleByIntegerLiteral and ForeignConvertible.
  • The C Hylo types can be directly used in FFI bindings thanks to being ForeignConvertible to their corresponding builtin types.
@ffi("hash")
fun hash(_ a: CLong, _ b: CChar,_ c: CInt,_ d: CShort,_ e: CLongLong,_ f: CULong, _ g: CSChar) -> CLongLong

public fun main() {
    print(Int(fromC: hash(1, 2, 3, 4, 5, 6, 7)))
    print(Int(fromC: hash(6, 5, 4, 3, 2, 1, 0)))
    print(Int(fromC: hash(0, 0, 0, 0, 0, 0, 0)))
    print(Int(fromC: hash(-1, -1, -1, -1, -1, 1, -1)))
    print(Int(fromC: hash(-2147483647, -127, -32767, -32767, -9223372036854775807, 4294967295, -128)))
}
// a complicated C hashing function with a lot of parameters of different numeric types
long long hash(long a, char b, int c, short d, long long e, unsigned long f, signed char g) {
    return a * 31 + b * 7 + c * 3 + d * 2 + e * 5 + f * 11 - g * 13;
}

I would welcome feedback on:

  • Naming of builtin functions and types
  • Naming of Hylo C types.
  • Whether to enable assertions in conversions
  • API design of C integer <-> Hylo conversions
    • Currently, constructors are available like Int64(fromC:) and CLongLong(_:) convert to and from C types.

Copy link

codecov bot commented May 4, 2025

Codecov Report

Attention: Patch coverage is 66.58354% with 134 lines in your changes missing coverage. Please review.

Project coverage is 88.19%. Comparing base (0951941) to head (6b81433).

Files with missing lines Patch % Lines
Sources/CodeGen/LLVM/Transpilation.swift 42.01% 69 Missing ⚠️
Sources/FrontEnd/Types/BuiltinType.swift 50.00% 34 Missing ⚠️
Sources/IR/Mangling/Demangler.swift 18.18% 9 Missing ⚠️
Sources/IR/BuiltinCNumericTypes+Extensions.swift 86.79% 7 Missing ⚠️
.../GenerateHyloFileTests/GenerateHyloFileTests.swift 0.00% 6 Missing ⚠️
Sources/IR/Operands/Instruction/UnionSwitch.swift 0.00% 4 Missing ⚠️
Sources/FrontEnd/BuiltinFunction.swift 92.30% 3 Missing ⚠️
Sources/FrontEnd/TypeChecking/TypeChecker.swift 83.33% 1 Missing ⚠️
Sources/IR/Module.swift 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1684      +/-   ##
==========================================
- Coverage   88.38%   88.19%   -0.20%     
==========================================
  Files         382      383       +1     
  Lines       31592    31896     +304     
==========================================
+ Hits        27924    28130     +206     
- Misses       3668     3766      +98     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Successfully merging this pull request may close these issues.

1 participant