Coder Social home page Coder Social logo

crust's Introduction

Crust

CRUST

This is a hobby project to learn about compilers and language design. I've designed the language to be similar to C and Rust.

Heavily inspired by https://github.com/DoctorWkt/acwj

Features

  • Global Variables
  • Functions
  • Arrays
  • Integers (signed and unsigned)
  • Strings
  • Binary Operations
  • Code Generation (GNU Assembly)
  • Print to Console (integers & ascii characters)
  • If Statements
  • While Statements
  • For Statements
  • Function Parameters
  • Function Arguments
  • Local Variables (Scopes)
  • Function Hoisting
  • Reading from console
  • Dynamic Arrays
  • Structs
  • Unions
  • Enums
  • Break & Continue
  • Variable Initialization
  • Casting
  • Sizeof
  • Static
  • Struct Methods
  • Struct Traits
  • LLVM

How to use

cargo run <input-file> # Compile the crust language to assembly, which will be written to out.s
cc -no-pie -z noexecstack -o bin out.s # Use the GNU C compiler to compile and link the assembly code to an executable file
./bin # Execute the produced binary

Run tests

./runtests.sh

Examples

Some examples of the language

let c: char;
let str: *char;

fn main(): u8 {
  c= '\n'; printint(c);

  for (str= "Hello world\n"; *str != 0; str= str + 1) {
    printchar(*str);
  }
  return 0;
}
let a: u8;
let b: u8[25];

fn main(): u32 {
  b[3]= 12; a= b[3];
  printint(a);
  return 0;
}

crust's People

Contributors

almontasser avatar deepsource-autofix[bot] avatar deepsource-io[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

crust's Issues

Linking example assembly fails when using PIE

Great work on this repo, it's quite motivating to see local devs taking on such cool and challenging projects, would love to contribute some day if I get the chance to

According to the README file, it is mentioned that the command cc -o bin out.s can be used to link the assembly to a binary, but it always fails without passing the -no-pie flag (at least in my env)

Maybe consider adding it in the docs to avoid confusion?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.