ccontinue

所属分类:编程语言基础
开发工具:Python
文件大小:0KB
下载次数:0
上传日期:2024-03-27 22:25:04
上 传 者sh-1993
说明:  一种转发器,它将C编程语言的OOP扩展转换回C
(A transpiler that translates an OOP-extension for the C programming language back to C)

文件列表:
examples/
.clang-format
LICENSE
Makefile
ccc.py

# CContinue Transpiler *A transpiler that translates an OOP-extension for the C programming language back to C* I like C and I like C++, both are powerful languages in there own right. But C++ is quite complicated and sometimes I just want to create some classes with inheritance in my C project. So I've created the weird hacky Python transpiler that can translate a custom syntax inspired by C++ and Java back to C code. ## The syntax *The documentation is bad I know* ### A basic class You can create a class with some fields with this syntax: ``` class Person { String *name; int age; } ``` All classes are structs that inherit from the root `Object` class which is heap allocated. A `new` and `free` method are automatically generated for you and you can use the fields just like a struct: ``` int main(void) { Person *person = person_new(); person->name = "Bastiaan"; person->age = 21; person_free(person); } ``` ### Field attributes You can add attributes with the `@attribute` syntax before a class field to generated methods. This is usefull because it saves a lot of typing work, we can extend the `Person` class with the following attributes: ``` class Person { @prop @init @free String *name; @prop int age; } ``` This will inturn generated the following methods for us: ``` class Person { // ... void init(String *name, int32_t age); virtual void free(); String * get_name(); int32_t get_age(); void set_age(int32_t age); } ``` You can use the following attributes: - `@get` Generate a getter method for this field - `@set` Generate a setter method for this field - `@prop` Short cut for `@get` and `@set` - `@init(init_function)` Use this field as an argument for the generated `init` method - `@free(free_function)` Free this field in the generated `free` method ### Class inheritance Classes can inherit from other classes with the `extends` keyword and classes can be made `abstract`: ``` abstract class Animal { @prop @init(strdup) @free char *name; virtual void greet(); } class Dog extends Animal { void greet(); } void Dog::greet() { printf("The dog %s greets you!\n", this->name); } class Cat extends Animal { void Greet(); } void Cat::greet() { printf("The cat %s greets you!\n", this->name); } ``` See the code examples in [examples/](https://github.com/bplaat/ccontinue/blob/master/examples/) for more info ## TODO - Add support for separate code and header files - Add interfaces that work like Java interfaces or like Rust traits ## License Copyright (c) 2021 - 2024 Bastiaan van der Plaat Licensed under the [MIT](https://github.com/bplaat/ccontinue/blob/master/LICENSE) license.

近期下载者

相关文件


收藏者