Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add C3 language support #7148

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/linguist/languages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,20 @@ C2hs Haskell:
codemirror_mode: haskell
codemirror_mime_type: text/x-haskell
language_id: 45
C3:
type: programming
color: "#555555"
extensions:
- ".c3"
- ".c3i"
- ".c3l"
- ".c3d"
tm_scope: source.c3
ace_mode: c_cpp
language_id: 1000000
aliases:
- c3lang
group: C3
CAP CDS:
type: programming
tm_scope: source.cds
Expand Down
95 changes: 95 additions & 0 deletions samples/C3/example.c3
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
module example;

import std::io;
import std::math;

def Callback = fn int(char* text);

enum Status : int
{
IDLE,
BUSY,
DONE,
}

struct MyData
{
char* name;
Callback open;
Status status;

struct other
{
int value;
int status;
}

union
{
int* number;
char* text;
}
}

fault MathError
{
DIVISION_BY_ZERO
}

fn double! divide(int a, int b)
{
if (b == 0) return MathError.DIVISION_BY_ZERO?;
return (double)a / (double)b;
}

<*
@param foo "the number of foos"
@require foo > 0, foo < 1000
@return "number of foos x 10"
@ensure return < 10000, return > 0
*>
fn int testFoo(int foo)
{
return foo * 10;
}

fn void example_foreach(float[] values)
{
foreach (index, value : values)
{
io::printfn("%d: %f", index, value);
}
}

fn void demo_switch(Status s)
{
switch (s)
{
case IDLE:
io::printn("Idle");
case BUSY:
io::printn("Busy");
nextcase;
case DONE:
io::printn("Done");
}
}

fn void test_defer(int x)
{
defer io::printn();
defer io::print("A");
if (x == 1) return;
{
defer io::print("B");
if (x == 0) return;
}
io::print("!");
}

fn int main()
{
MyData data = { .name = "test", .status = Status.IDLE };
test_defer(1);
return 0;
}