Skip to content

Th6uD1nk/CHigh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

CHIGH

CHigh is a C-derived LLM code generation language designed for structured program synthesis and semantic compilation into a requested target stack language.

Core Philosophy

CHigh is C, extended. Every rule of C syntax remains valid without exception: types, structs, enums, functions, control flow, arithmetic, assignments, pointers, arrays. A CHigh file that contains no narrative blocks is just C.

The extension is a single new syntactic primitive: the narrative block {...}. It can appear anywhere a C expression or statement can appear, and it carries natural language that the LLM compiles into concrete target-language code. Narrative blocks can also be assigned to a typed variable of type Narrative, making them first-class values that can be passed, stored, and processed like any other data.

CHigh programs favor describing processes in narrative wherever prose is clearer than code, while keeping the full expressive power of C available at all times. A function can freely mix C statements, narrative blocks, and Narrative variable operations in any order and combination.

Standard C library functions are available and valid. Any behavior they provide can alternatively be described as a narrative, but there is no rule against using them directly.

Syntax Reference

1. Target Declaration

Declared at the top of every .chigh file. The syntax mirrors a C designated struct initializer, the closest valid C form. Each field is a unique identifier prefixed with ., assigned a narrative value. Replacing every {...} with a string literal yields a valid C designated initializer body.

struct Target target {
    .language = {`Javascript ES2022, no bundler, single inline file`},
    .markup   = {`HTML5 semantic single page`},
    .graphics = {`Three.js r128 via CDN`},
    .output   = {`single self-contained HTML file`},
};

Every field name must be unique. Every value is a narrative wrapped in {...}.

2. Narrative Blocks

{...} is a narrative block. It contains natural language and can appear anywhere a C statement or expression is valid. The LLM compiles it into concrete target-language code during generation.

void update_physics(Kart kart, InputState input, float dt)
{
    {`if forward input is active, accelerate kart toward maxSpeed`}

    float dirX = sin(kart.rotationY);
    float dirZ = cos(kart.rotationY);
    kart.posX += dirX * kart.speed * dt;
    kart.posZ += dirZ * kart.speed * dt;

    {`apply friction to decay kart.speed toward zero when no input is active`}

    float tiltTarget = input.left ? 0.13 : input.right ? -0.13 : 0.0;
    kart.lateralTilt += (tiltTarget - kart.lateralTilt) * 8.0 * dt;
}

A function body can also be a single narrative when no C is needed:

void init_environment(Environment env)
{`
    Create a flat green ground plane, scattered cloud groups in the sky,
    distant mountain silhouettes on the horizon, and a few trees outside the circuit.
`}

3. Narrative Variables

A narrative block can be assigned to a variable of type Narrative. This gives a semantic description a name so it can be referenced, passed to functions, stored in arrays, and operated on. Narrative variables integrate naturally with C code and other narratives in any order:

void build_level(Level level)
{
    Narrative layout  = {`open arena with a central platform and four ramps`};
    Narrative hazards = {`rotating spike traps placed at the base of each ramp`};

    level.width  = 200;
    level.height = 200;

    {`generate the geometry described by layout`}
    {`place the hazards described by hazards at the ramp bases`}

    level.spawnX = 0;
    level.spawnZ = 0;
}

Arrays of Narrative can be iterated with standard C loops:

Narrative enemies[4] = {
    {`fast but fragile scout`},
    {`slow heavy tank`},
    {`ranged sniper that retreats when approached`},
    {`healer that buffs nearby allies`},
};

int i = 0;
while (i < 4) {
    generate_enemy_class(enemies[i]);
    i++;
}

4. Structs, Enums, and Functions

Full C syntax. No restrictions. Functions may mix C and narratives freely:

enum TileType { STRAIGHT, TURN_LEFT, TURN_RIGHT }

struct Tile {
    TileType type;
    float    length;
};

void place_tile(Tile tile, float cursorX, float cursorZ, float heading, float trackWidth)
{
    if (tile.type == STRAIGHT) {
        {`place straight road segments along heading for tile.length units from cursor`}
    } else {
        float arcLen = (trackWidth * 1.6) * (PI / 2.0);
        {`place curved road segments along the arc, turning left or right based on tile.type`}
    }
}

5. POST_GENERATION Block

Placed at the bottom of every .chigh file. Same syntax as target: a designated struct initializer form where each field is a unique identifier naming the test, assigned a narrative describing the expected behavior.

struct PostGeneration POST_GENERATION {
    .kart_acceleration = {`TEST: kart accelerates when forward input is held`},
    .camera_follow     = {`TEST: camera follows kart with smooth damping`},
    .loop_closed       = {`TEST: all circuit tiles are placed and the loop closes without gap`},
};

The agent must report each entry as PASSED or FAILED as comments at the end of the generated file.

Compilation Rules

  1. CHigh is C. All valid C syntax is translated into equivalent target-language code.
  2. Every {...} narrative block is resolved by semantic interpretation into concrete target-language code.
  3. Narrative variables are materialized into whatever concrete artifacts their descriptions imply, appropriate to the target.
  4. The target block defines the full output stack. All generated code must conform to it.
  5. Emit exactly one file. Multi-file output is forbidden.
  6. Report every POST_GENERATION entry as PASSED or FAILED as comments at the end of the output file.

Prompt

You are a CHigh LLM code generation agent.
CHigh is C extended by one new primitive: the narrative block.
Every rule of C syntax remains valid without exception.
A CHigh file with no narrative blocks is plain C.
Your task is to read a .chigh file and emit a single output file in the target stack.

Reading a .chigh file, in order:

1. TARGET BLOCK
   Located at the top of the file.
   Syntax: struct Target target { .key = {`narrative`}, ... };
   Mirrors a C designated struct initializer. Each field name is unique.
   Defines the full output stack: language, libraries, constraints, output format.
   All generated code must strictly conform to every field declared here.

2. BODY
   The rest of the file is C, extended by two primitives:

   NARRATIVE BLOCK
   Syntax: {`natural language text`}
   Can appear anywhere a C statement or expression is valid.
   Describes intent, behavior, or process in natural language.
   Compile it into concrete target-language code.
   A function body may freely mix C statements and narrative blocks in any order,
   or consist entirely of a single narrative block.

   NARRATIVE VARIABLE
   Syntax: Narrative name = {`...`};
   Can be declared anywhere a C variable can be declared.
   Can be passed to functions, stored in arrays, combined with C code and other narratives.
   Materialize it into concrete generated artifacts appropriate to the target stack.
   Arrays of Narrative may be iterated with standard C loops.

   Standard C library functions are valid and may be used freely.

3. POST_GENERATION BLOCK
   Located at the bottom of the file.
   Syntax: struct PostGeneration POST_GENERATION { .key = {`TEST: ...`}, ... };
   Same form as the target block. Each field name is unique and names the test.
   After generating the output file, report each entry as PASSED or FAILED
   as comments at the end of the output file.

Output rules:
- Produce exactly one output file. Multi-file output is not allowed.
- Do not emit any explanation or commentary outside the generated file,
  except for the POST_GENERATION report at the end.

You must now wait for a .chigh file input.

Example Snippet

struct Target target {
    .language = {`Javascript ES2022, no bundler`},
    .output   = {`single self-contained HTML file`},
};

struct Player {
    float x;
    float y;
    float vy;
    float speed;
    int   jumpsLeft;
};

void update_player(Player p, InputState input, float dt)
{
    Narrative ground_rule = {`ground level is y = 0, landing resets vy to 0 and restores jumpsLeft to 2`};

    p.x += p.speed * dt;
    if (p.x < 0.0)      p.x = 0.0;
    if (p.x > SCREEN_W) p.x = SCREEN_W;

    {`apply gravity to p.vy each frame and update p.y accordingly`}

    if (input.jump && p.jumpsLeft > 0) {
        {`trigger a jump impulse on p.vy`}
        p.jumpsLeft--;
    }

    {`apply ground_rule`}
}

struct PostGeneration POST_GENERATION {
    .horizontal_clamp = {`TEST: player moves horizontally and is clamped to screen bounds`},
    .gravity          = {`TEST: gravity pulls the player down each frame`},
    .double_jump      = {`TEST: double jump is available before landing`},
    .landing_reset    = {`TEST: landing resets jumpsLeft to 2`},
};

About

CHigh (.chigh) is an experimental LLM C-derivated Code Generation Language designed for structured program synthesis and semantic compilation into requested target stack language.

Topics

Resources

License

Stars

Watchers

Forks

Contributors