Home

Awesome

GachiC

Gachimuchi-themed programming language (Work in progress)

Table of Contents

Build

Dependencies

POSIX
Windows

Instructions

POSIX
$ mkdir build
$ cd build
$ cmake ..
$ make
Windows
mkdir build
cd build
cmake .. -Thost=x64 -G "Visual Studio 16 2019" -A x64 -DCMAKE_PREFIX_PATH=path\to\llvm -DCMAKE_BUILD_TYPE=Release
msbuild -p:Configuration=Release ALL_BUILD.vcxproj 

Usage

First, compile source files into object files

$ gc -c file.gc

Then link them

$ clang++ file.o helper.o -o program

Run

$ ./program

That's all

Features

While the language is being developed, some features may change

Functions

For convenience, there is no "main" function, there is only "master", for which you do not need to describe function declaration ("slave" for others)

extern swallow(x:*i8) cum nothing;
master() cum i32
{
  swallow("Hello, Gym\n");
  cumming(0);
};

To return a value from a function, you must use the unary operator (!) "cumming"

If you can describe a function in one line, then there is no need for a block declaration

slave Bob(x: i32) cum i32
  cumming(-x);

Variable initialization

When a variable is declared, it does not need to be assigned a type, its type will be determined automatically depending on the value assigned to it.

  // i32
  var h = 123;
  // f32
  var e = 123.123;
  // [4]i32
  var l = [1, 2, 3, 4];
  // *i8
  var p = "it's your job to cook for me";
  // Foo
  var m = Foo{e: 123, b: 123.123, a: "string"};
  // [3]*i8
  var e_ = ["what the hell", "where is my breakfast", "don't get smart with me"]; 

If you want to set the type of a variable explicitly, then use the casting operator "ass"

  // i64
  var h64 = 123 ass i64;
  // f64
  var h64 = 123 ass f64;
  // i32
  var e_  = 123.123 ass i32;
  // *i8
  var ptr_ = 1234 ass *i8;

Loops

Syntax:

  while(cond) |step|
    body;

Example:

  while(i < 5) |i = i + 1|
    swallow("dupl\n");

Сonditional statements

Syntax:

  if(cond){
    true_block
  } else {
    false_block
  };

  if(cond)
    true_block;

Example:

  if(n % 2 == 0)
    print("That's good\n")
  else
    print("Try again\n");

Structure types

Declaration syntax:

struct struct_name{
  field_name: type;
  field_name_1 : type;
  ...
}

Initialization syntax:

  var struct_var = struct_name{ field_name: value, field_name_1: value, ...};

Example:

extern printInt(x: i32) cum nothing;
struct Poo{
  a : i32;
};

struct Foo{
  a : *i32;
  b : Poo;
};

master() cum i32
{
  var i = 10;
  var e = Foo{a: &i, b: Poo{a: i}};

  printInt(e.b.a);
  printInt(*(e.a));
  cumming(0);
};

Arrays

Example:

  var i = [1, 2, 3, 4];
  printInt(i[2]);

The type of array elements determines the type of its first element

  var i = [123 ass i8, 2, 3, 4];
  printInt(i[0]);

Memory management

Pointers:

  var x = 100 ass i32;
  // *i32
  var y = &x;
  var z = *y;

Dynamic memory allocation: To allocate, operate and free memory

  stick your i32 in my val;
  val = 66;
  stick out val;

Example: extern printInt(x: i32) cum nothing;

struct Foo{
  a: *i32;
};

master() cum i32
{
  var tmp = 96;
  var y = Foo{a : &tmp};
  var n = &(y.a);
  **(n ass **i32) = 69;

  printInt(*(y.a));
  printInt((1 + **n));

  cumming(0);
};

License

Distributed under the MIT License. See LICENSE for more information.

Mates