Implement C interop foundation: AST, parser, and type system#4
Draft
Implement C interop foundation: AST, parser, and type system#4
Conversation
- Add c_include, c_import, c_from_import, c_struct_decl, c_callback_reg node types - Add corresponding data structures to extra union - Implement helper methods for all new node types - Update deinit to properly free new node types - Update toString method for new node types Co-authored-by: igorgue <7014+igorgue@users.noreply.github.com>
- Implement parseCStructDecl for parsing $struct declarations - Implement parseCType for parsing C types ($int, $char*, $int[10]) - Implement parseCFunctionCall for parsing C function calls - Hook up $ token handling in parseDeclaration and parsePrimaryExpression - Support opaque struct declarations and struct field parsing Co-authored-by: igorgue <7014+igorgue@users.noreply.github.com>
- Implement parseCRegisterDecl for callback registration - Add handling for $register in dollar token processing - Create comprehensive test suite for C interop parser - Tests cover $load, $include, $struct, C function calls, C types, and $register Co-authored-by: igorgue <7014+igorgue@users.noreply.github.com>
- Create c_types.zig module for C to Shortcake type mapping - Implement CPrimitiveType enum with toShortcakeType and toMLIRType methods - Implement CType union for representing all C types (primitive, pointer, array, etc.) - Add CTypeMapping for parsing and converting C type strings - Add basic codegen support for C load, struct declarations, and function calls - Add mapCTypeToMLIR helper in codegen for type conversion Co-authored-by: igorgue <7014+igorgue@users.noreply.github.com>
- Add c_math_example.sho demonstrating C math library usage - Add c_structs_example.sho showing struct declarations and usage - Create CINTEROP_STATUS.md documenting implementation progress - Document all completed phases and remaining work - Include syntax examples and architecture overview Co-authored-by: igorgue <7014+igorgue@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Implement CInterop system in Shortcake
Implement C interop foundation: AST, parser, and type system
Nov 16, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements the C interoperability foundation per
docs/CINTEROP.md, enabling Shortcake to call C functions, declare C structs, and load C libraries.Changes
AST Layer
c_load,c_include,c_import,c_from_import,c_struct_decl,c_callback_regextraunion with helper methodsdeinit()for new node typesParser Layer (
src/parser.zig)parseCStructDecl(): Parse$struct $Name do ... endwith field declarationsparseCType(): Parse C types ($int,$char*,$int[10])parseCFunctionCall(): Parse C function invocationsparseCRegisterDecl(): Parse callback registrationparseDeclaration()andparsePrimaryExpression()Type System (
src/c_types.zig)CPrimitiveType: 19 C primitive types with Shortcake/MLIR mappingsCType: Union type supporting primitive, pointer, array, function pointer, struct, customCTypeMapping: Parse C type strings, convert to Shortcake/MLIR types, compatibility checkingCodegen (
src/codegen.zig)generateExpr()switch$load,$struct, C function callsmapCTypeToMLIR(): Type conversion helperTests & Examples
c_math_example.sho,c_structs_example.shoExample Usage
Scope
Parser and type system are complete. MLIR codegen and runtime (dlopen/dlsym, symbol registry, callbacks) deferred to future PRs.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
ziglang.orgcurl -L REDACTED -o /tmp/zig.tar.xz(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.