Skip to content

Home‐Introduction

客串一回 edited this page Apr 13, 2026 · 1 revision

"Fèng" is a new programming language extended from C, designed to provide object-oriented features and memory safety mechanisms while maintaining similarity to C, making it easier for developers to get started. Its design goal is to replace some of C's functions in system development, improving development efficiency and code safety. By introducing features such as automatic memory management, type safety checking, and reference mechanisms, Fèng reduces potential risks caused by memory errors. Currently, the project has implemented capabilities for syntax parsing, semantic analysis, and partial target code generation, primarily by generating C++ code as an intermediate step for final output.

Main Features

  1. Memory Safety Mechanism Design:

    • Automatic Memory Management: Fèng enforces that pointers can only point to an object or be null. When an object is no longer referenced by any pointer, it is automatically released. This mechanism is similar to garbage collection but supports immediate or deferred reclamation.
    • Safe Pointer Usage: Pointers cannot be generated through arithmetic operations, nor can arbitrary integers be converted to pointer values, thereby preventing issues such as dangling pointers and out-of-bounds access.
    • Mandatory Bounds and Type Checking: Bounds are enforced during array and buffer operations. Type conversions must be checked for legality, reducing type-related errors.
    • Phantom Reference Mechanism: "Phantom references" replace C's address-of operator (&), ensuring that references remain valid within an object's lifetime and preventing dangling references.
  2. Object-Oriented Features:

    • Provides core object-oriented programming functionality including classes, inheritance, polymorphism, and interface abstraction.
    • Supports resource classes, designed with reference to C++ destructors, for managing underlying resources (such as file handles, memory, etc.) and handling circular reference issues.
  3. Syntax and Type System:

    • Supports value type variables, where the variable itself is directly the instance without requiring additional heap allocation.
    • Allows free type conversion between structs and unions.
    • Supports modular code management, allowing symbols to be shared between modules through export and import mechanisms (this feature is not yet fully implemented).
  4. Semantic Analysis Capabilities:

    • Implements symbol checking, constant folding, type checking, inheritance and interface implementation verification, variable lifetime checking, reference immutability checking, and more.
    • Supports checking of generic type parameters as well as runtime type checking to ensure type safety.
  5. Target Code Generation:

    • Currently primarily supports converting Fèng source code to C++ code, which can then be compiled using a C++20 compiler.
    • Completed features include class definitions, expressions, variables, polymorphic calls, runtime type checking, generics, variable cleanup, and reference management.
    • Incomplete features include exception handling, string formatting, certain expressions (such as exponentiation), and modular support.
  6. Tool Building and Usage:

    • The project is built using Maven and relies on ANTLR4 for syntax parsing.
    • Supports compiling a single source file or module, generating corresponding C++ files.
    • Provides a command-line tool; users can run the compiler directly via a JAR package. The generated C++ files require further compilation with a C++20 compiler.

Summary

Fèng is a language project aimed at system programming and high-performance development. Its core objectives are to improve development efficiency and reduce common memory errors by introducing memory safety mechanisms and object-oriented features. Currently, it has relatively complete semantic analysis and code generation capabilities and can produce C++ code for further compilation. The project is still under active development, with some features (such as modularization and exception handling) not yet completed.

Clone this wiki locally