{"id":24280917,"url":"https://github.com/JakkuSakura/FerroPhase","last_synced_at":"2025-09-25T01:30:30.444Z","repository":{"id":60046905,"uuid":"524581368","full_name":"JakkuSakura/SHLL","owner":"JakkuSakura","description":"An experiment of high level code optimization","archived":false,"fork":false,"pushed_at":"2025-01-08T17:34:36.000Z","size":1093,"stargazers_count":29,"open_issues_count":1,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-08T18:34:49.739Z","etag":null,"topics":["compiler","programming-language"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JakkuSakura.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-08-14T05:28:17.000Z","updated_at":"2025-01-08T17:35:02.000Z","dependencies_parsed_at":"2023-11-07T15:31:37.708Z","dependency_job_id":"a38a9550-d537-4eb8-8599-ce583380a54f","html_url":"https://github.com/JakkuSakura/SHLL","commit_stats":null,"previous_names":["jakkusakura/shll"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JakkuSakura%2FSHLL","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JakkuSakura%2FSHLL/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JakkuSakura%2FSHLL/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JakkuSakura%2FSHLL/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JakkuSakura","download_url":"https://codeload.github.com/JakkuSakura/SHLL/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234142660,"owners_count":18786019,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["compiler","programming-language"],"created_at":"2025-01-16T02:50:46.199Z","updated_at":"2025-09-25T01:30:30.423Z","avatar_url":"https://github.com/JakkuSakura.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FerroPhase: Meta-Compilation Framework with Advanced Const Evaluation\n\nA meta-compilation framework that extends Rust with powerful compile-time computation and metaprogramming capabilities.\n\n## Overview\n\nFerroPhase is a **meta-compilation framework** that enhances Rust with:\n\n- **Rich compile-time introspection** - `sizeof!()`, `hasfield!()`, `field_count!()`\n- **Dynamic type generation** - declarative `type T = { ... }` syntax\n- **Structural metaprogramming** - conditional fields and type inheritance\n- **Multiple compilation targets** - Rust transpiler, interpreter, future LLVM support\n\n## Quick Start\n\n### Installation\n\n```bash\ngit clone https://github.com/your-org/FerroPhase\ncd FerroPhase\ncargo build --release\nexport PATH=\"$PATH:$(pwd)/target/release\"\n```\n\n### Create Your First Project\n\n```bash\nfp init my-project --template basic\ncd my-project\nfp compile src/main.fp --target rust --run\n```\n\n### Example: Advanced Type Generation\n\n```rust\n#!/usr/bin/env fp run\n\nfn main() {\n    // Future FerroPhase syntax - parametric type creation\n    const fn create_api_handler\u003cconst METHODS: \u0026'static [\u0026'static str]\u003e() -\u003e Type {\n        type Handler = {\n            base_url: String,\n            timeout: u64,\n            \n            // Generate methods based on parameter\n            for method in METHODS {\n                field!(format!(\"{}_endpoint\", method)): String,\n                \n                fn method!(method)(\u0026self, path: \u0026str) -\u003e Result\u003cResponse, Error\u003e {\n                    generate_http_method!(method, self.base_url, path)\n                }\n            }\n            \n            // Conditional optimization fields\n            if METHODS.len() \u003e 5 {\n                connection_pool: ConnectionPool,\n                \n                fn batch_request(\u0026self, requests: Vec\u003cRequest\u003e) -\u003e Vec\u003cResponse\u003e {\n                    generate_batch_handler!(METHODS)\n                }\n            }\n        };\n        Handler\n    }\n    \n    // Generate specialized API handlers\n    type RestApi = create_api_handler\u003c\u0026[\"GET\", \"POST\", \"PUT\", \"DELETE\"]\u003e();\n    type GraphqlApi = create_api_handler\u003c\u0026[\"QUERY\", \"MUTATION\", \"SUBSCRIPTION\"]\u003e();\n    \n    // Compile-time validation and analysis\n    const REST_SIZE: usize = sizeof!(RestApi);\n    const GRAPHQL_SIZE: usize = sizeof!(GraphqlApi);\n    const REST_HAS_BATCH: bool = hasmethod!(RestApi, \"batch_request\");\n    \n    if REST_SIZE \u003e 1024 {\n        compile_warning!(\"REST API handler is getting large\");\n    }\n    \n    println!(\"REST API: {} bytes, batch: {}\", REST_SIZE, REST_HAS_BATCH);\n    println!(\"GraphQL API: {} bytes\", GRAPHQL_SIZE);\n}\n```\n\n## Key Features\n\n### Compile-time Introspection\n\n```rust\nconst SIZE: usize = sizeof!(MyStruct);\nconst FIELDS: usize = field_count!(MyStruct);\nconst HAS_FIELD: bool = hasfield!(MyStruct, \"name\");\n```\n\n### Parametric Type Generation\n\n```rust\nconst fn create_entity\u003cconst FEATURES: EntityFeatures\u003e() -\u003e Type {\n    type Entity = {\n        id: u64,\n        created_at: u64,\n        \n        if FEATURES.has_metadata {\n            metadata: HashMap\u003cString, Value\u003e,\n        }\n        \n        if FEATURES.has_permissions {\n            permissions: Vec\u003cPermission\u003e,\n            \n            fn can_access(\u0026self, resource: \u0026str) -\u003e bool {\n                generate_permission_check!(resource)\n            }\n        }\n        \n        if FEATURES.is_auditable {\n            audit_log: Vec\u003cAuditEntry\u003e,\n            \n            fn log_action(\u0026mut self, action: Action) {\n                generate_audit_logger!(action)\n            }\n        }\n    };\n    Entity\n}\n\n// Generate different entity types\ntype User = create_entity\u003cEntityFeatures { \n    has_metadata: true, \n    has_permissions: true, \n    is_auditable: false \n}\u003e();\n\ntype AdminUser = create_entity\u003cEntityFeatures { \n    has_metadata: true, \n    has_permissions: true, \n    is_auditable: true \n}\u003e();\n```\n\n### Advanced Type Composition\n\n```rust\n// Type inheritance with conditional extensions\ntype Employee = {\n...User,  // Inherit all User fields and methods\ndepartment: String,\nsalary: u64,\n\n// Conditional mixins based on department\nif department == \"Engineering\" {\n...DeveloperMixin,  // Git access, code review permissions\ngithub_username: String,\n}\n\nif department == \"Management\" {\n...ManagerMixin,    // Team management, budget access\ndirect_reports: Vec \u003c UserId \u003e,\nbudget_limit: u64,\n}\n\n// Generate department-specific methods\nfn get_role_permissions( \u0026 self ) -\u003e Vec \u003c Permission\u003e {\nmatch_department ! ( self.department, {\n\"Engineering\" =\u003e generate_dev_permissions ! (),\n\"Management\" =\u003e generate_mgmt_permissions! (),\n_ =\u003e generate_default_permissions ! ()\n})\n}\n};\n\n// Automatic validation\nconst EMPLOYEE_SIZE: usize = sizeof!(Employee);\nconst MAX_ROLES: usize = count_conditional_fields!(Employee);\n\nif MAX_ROLES \u003e 10 {\ncompile_error ! (\"Too many role variants - consider refactoring\");\n}\n```\n\n## CLI Commands\n\n| Command             | Description             |\n|---------------------|-------------------------|\n| `fp init \u003cname\u003e`    | Create new project      |\n| `fp compile \u003cfile\u003e` | Compile FerroPhase code |\n| `fp eval \u003cexpr\u003e`    | Evaluate expressions    |\n| `fp check \u003cpath\u003e`   | Validate code           |\n| `fp format \u003cfiles\u003e` | Format code             |\n\n### Project Templates\n\n- `basic` - Simple project with examples\n- `library` - Library with advanced features\n- `binary` - CLI application template\n\n## Project Structure\n\n```\nFerroPhase/\n├── crates/\n│   ├── fp-core/           # Core AST and operations\n│   ├── fp-optimize/       # Optimization passes\n│   ├── fp-rust/      # Rust frontend\n│   └── fp-cli/            # Command-line interface\n├── examples/              # Example programs\n└── docs/                  # Documentation\n```\n\n## Implementation Status\n\n### ✅ Current Features\n\n- Core AST infrastructure\n- Const evaluation with 15+ intrinsics\n- Rust transpiler\n- Professional CLI with project templates\n- Declarative type syntax examples\n\n### 🚧 In Progress\n\n- Enhanced parser for macro syntax\n- Side effect tracking system\n- 3-phase const evaluation\n\n### 📋 Planned\n\n- LLVM backend\n- WebAssembly output\n- Language server support\n\n## Meta-Compilation Philosophy\n\n**FerroPhase** acts as a meta-compilation layer that:\n\n- **Complements Rust** rather than replacing it\n- **Generates clean, idiomatic Rust code** from enhanced syntax\n- **Provides compile-time computation** beyond Rust's const capabilities\n- **Enables structural metaprogramming** for code generation\n\n## Examples\n\nSee `examples/` directory for advanced FerroPhase capabilities:\n\n### 1. Parametric Struct Generation (`05_parametric_structs.fp`)\n\n```rust\n// Generate vector types with dimension-based methods\nconst fn create_vector_type\u003cconst DIM: usize, T\u003e() -\u003e Type {\n    type Vector = {\n        match DIM {\n            2 =\u003e { x: T, y: T },\n            3 =\u003e { x: T, y: T, z: T },\n            _ =\u003e {\n                for i in 0..DIM {\n                    field!(format!(\"dim_{}\", i)): T,\n                }\n            }\n        }\n        \n        if DIM \u003e= 2 {\n            fn dot(\u0026self, other: \u0026Self) -\u003e T {\n                generate_dot_product!(DIM, T)\n            }\n        }\n        \n        if DIM == 3 {\n            fn cross(\u0026self, other: \u0026Self) -\u003e Self {\n                generate_cross_product!(T)\n            }\n        }\n    };\n    Vector\n}\n\ntype Vector3D = create_vector_type\u003c3, f64\u003e();\ntype Vector8D = create_vector_type\u003c8, f32\u003e();\n```\n\n### 2. Generic Specialization (`08_generic_specialization.fp`)\n\n```rust\n// Automatic container optimization based on type properties\nconst fn create_container\u003cT\u003e() -\u003e Type {\n    type Container = {\n        data: Vec\u003cT\u003e,\n        \n        if is_copy!(T) \u0026\u0026 sizeof!(T) \u003c= 8 {\n            inline_buffer: [T; 16],  // Small type optimization\n        }\n        \n        if implements!(T, Hash) {\n            hash_cache: u64,\n            \n            fn hash_all(\u0026self) -\u003e u64 {\n                generate_hash_aggregator!(T)\n            }\n        }\n        \n        if is_numeric!(T) \u0026\u0026 sizeof!(T) == 4 {\n            fn sum_simd(\u0026self) -\u003e T {\n                generate_simd_sum!(T)  // SIMD acceleration\n            }\n        }\n    };\n    Container\n}\n```\n\n### 3. Database ORM Generation (`10_metaprogramming_patterns.fp`)\n\n```rust\n// Generate complete ORM from schema definition\nconst SCHEMA = {\n    table_name: \"users\",\n    fields: [\n        (\"id\", \"u64\", \"PRIMARY KEY\"),\n        (\"name\", \"String\", \"NOT NULL\"),\n        (\"email\", \"String\", \"UNIQUE\"),\n    ]\n};\n\ntype User = {\n    id: u64,\n    name: String,\n    email: String,\n    \n    // Auto-generated CRUD methods\n    fn save(\u0026self) -\u003e Result\u003c(), DbError\u003e {\n        execute_sql!(\"INSERT INTO users (name, email) VALUES (?, ?)\", \n                    self.name, self.email)\n    }\n    \n    fn find_by_id(id: u64) -\u003e Result\u003cUser, DbError\u003e {\n        query_one!(\"SELECT * FROM users WHERE id = ?\", id)\n    }\n};\n```\n\nRun examples:\n\n```bash\n# Direct execution with shebang\n./examples/05_parametric_structs.fp\n./examples/08_generic_specialization.fp\n./examples/10_metaprogramming_patterns.fp\n\n# Or via CLI\nfp run examples/05_parametric_structs.fp\nfp compile examples/08_generic_specialization.fp --target rust\n```\n\n## Contributing\n\nFerroPhase welcomes contributions in:\n\n- Language design and syntax\n- Optimization passes\n- Type system features\n- Tooling and IDE support\n\n## License\n\n[Insert License Here]","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJakkuSakura%2FFerroPhase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FJakkuSakura%2FFerroPhase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJakkuSakura%2FFerroPhase/lists"}