Skip to content

chemicallang/chemical

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chemical logo

The Chemical Programming Language

Website | Docs | Changelog | Speed | Contributing & compiler design

Sponsor Patreon Discord X

Chemical is an innovative, performant, typesafe user-friendly programming language with a low memory footprint.

Chemical Programming Language brings language tooling by default & is customisable by the end developer and not a library author. It focuses on reusing and adding more to what's already built. It allows you to rethink how programming languages mix and share concepts to create solutions that are tailored to syntax preferred by the project you are working on !

Syntax

It's similar to golang, typescript & c++ but there's a lot that cannot be explained about syntax here.

import "file.ch"
var x : int = 5;
for(var i = 0; i < 5; i++){
    var arr : int[5] // array of five integer elements, uninitialized
    if(i == 3) {
        x += 2;
    }
    if(i == 6) break;
    x++;
}
// while and do while loops are also similar
// a function, requires types, primitive values are pass by value
func add(a : int, b : int) : int {
    return a + b;
}
// supports : struct, interface, implementation
// semicolons are optional
// supports lambdas, switch statements & pointers

Installation

1 - Download the ZIP file (in assets) from the releases page
2 - Extract the ZIP file, put the path of the folder in the PATH environment variable
3 - Check it works chemical -v
4 - Run chemical configure will configure chemical (so it's ready for your OS)

Features

  • So easy that you can learn it in a week !
  • Great IDE support
  • Compile Time Evaluation
  • Low memory footprint
  • LLVM Backend, C Backend (both fully functional)
  • Translate C to Chemical
  • Translate Chemical to C
  • Import C System Headers
  • No Garbage Collection
  • Compile time memory checks
  • Tiny executables
  • Native language
  • Use as an embedder language
  • Custom Flexible Build System
    • with our own language

Progress

A lot of unexplained things in this list, Trust me when I say, very innovative things are planned.

  • Lexer
  • Parser
  • LSP
    • Syntax Highlighting
    • Completion items
    • Diagnostics
    • Imported Files support
    • Resolve symbol support
    • Improved diagnostics support
    • Semantic highlighting
    • Member access completion items
    • Hover doc support
    • Inlay Hints
    • Find usages support
    • Refactor rename
    • Formatting
    • Codelens support
  • Native Codegen (LLVM)
  • Necessary C Translation (can import system headers)
  • Translate to C (all tests passing)
  • Just In Time Compilation using Tiny CC
  • Custom Build System
  • Multi Threaded Compiler
    • Planned work on performance
    • Currently, stability and MVP are being preferred
  • Improved support for Comp Time
  • Improved support for Type Aliases
  • Memory Management
    • C++ like constructors & destructors
    • Strict checks for undefined behaviour
    • Better API for Memory control
  • Compile time Interpreted Plugins
    • Compiler Binding Interface (CBI)
    • Syntax Modifier Plugins (SMP)
    • AST Transformation Plugins (ATP)
    • Annotation / Symbol Processing
  • Build System based on Chemical
    • Compile single / multiple root file as modules
    • Link multiple modules
    • Work with both TCC and Clang based
    • Translate Files to C (currently only TCC based)
    • Generate llvm ir / assembly / bitcode / object files
    • Directory module automatic compilation
    • Can import other modules
    • Run executables after building them
    • Can generate shared objects / dll
    • Can generate static libraries
    • Can compile and link C module
    • Github modules
    • Watch mode, so files can be compiled incrementally
    • Configure compile / link parameters
  • Maintenance Phase
    • Eliminate bugs, Stabilize
    • Standard Library
    • Documentation
    • Support proper C Translation
    • Workspace Tooling
  • Experiment & Research
    • Embeddable Foreign Language Syntax
    • Web Support
  • Language Growth
    • Mobile : Android, iOS Support
    • More platforms

Language Features

  • C like Syntax
  • Structs, no Classes
  • C++ like Namespaces
  • C like Arrays
  • C++ Enums (int storage by default)
  • C Unions (raw)
  • Native Lambda Support
    • Capturing lambda also supported (though requires a little bit of work)
  • Macros support (so powerful, that you can embed another compiler)
  • C like implicit and explicit casting
  • Java / Kotlin like Annotations
  • Kotlin's extension functions
  • Raw pointers
  • Full support for constructors (including comptime)
  • Destructors in Structs
  • Type Aliases (like typedef)
  • Pass struct to functions (passes a pointer as param)
  • Return structs from functions (passes a pointer, memcpy like C++)
  • Explicit copying, there's no implicit copying, you must call .copy()
  • Const Function Params, cannot change value of parameter
  • Comptime Support
  • Same name function overloading
  • Variants
  • Generics
    • Generics in inheritance require polishing
  • C++ like Inheritance (Non-Multi)
  • Rust like Trait and Impl
    • Dynamic dispatch requires polishing
  • Top Level Symbol Conflict Detection
  • Name mangling

As you can see, our language features promote insane code generation, Type Safety with Power, Guaranteed Performance with ease of use, A heaven for Library Developers. But there's one thing that isn't being reflected which is IDE interaction. Because that's the most powerful feature.

Build

Requirements

These requirements are for people who've never set up a C++ / Boost / LLVM Project

  • A PC with at least 8 - 16 GB of RAM
  • CLion IDE (I use CLion)
  • Toolchain (Visual Studio / Other)
  • LLVM (Optional -> only if you are working on compiler)
  • Patience with build errors (open an issues for fast response)

Instructions

The project generates these executables (and maybe more)

  • Compiler (source code to executables) (requires llvm & clang)
  • TCC Compiler (a compiler based on Tiny CC compiler)
  • LSP Server (for IDE experience) (requires boost)

To work on LSP Server

  • Please install Boost
    • open an issue, if you fail
  • clone a repo inside this organization named chemical-vscode

To work on Compiler

  • clone a repo present in this organization named chemical-bootstrap
  • create a folder inside chemical-bootstrap, name it chemical
  • clone this repo inside chemical
  • build llvm, chemical-bootstrap has build scripts (build.bat or build)
  • open an issue, if you fail

Vision & Design goals

  • Chemical will never be bootstrapped. At least not in a traditional sense.
  • Don't want to waste time writing features again and again.
  • Want to keep it simple, Language plugins instead of syntactic sugar.
  • Won't provide multiple ways of doing things.
  • Will provide a very easy way to write compiler plugins.
  • No package manager, instead command line Git Interface with modules & shallow clones.

Contributing

Chemical Programming Language is an open source work, It also allows you to completely customize it. It requires a lot of contributions to support the large number of features that need to be supported, so we not just welcome contributions but encourage everybody to contribute. So we can bring our vision to life.

Licensing

Qinetik owns Chemical, Qinetik is a for-profit company. But we will always keep Chemical as an open source programming language.

Qinetik intends to make products and apps and intends to develop Chemical as an open source work with community effort to improve app development process.

Chemical's Compiler is open source and MIT licensed and will always remain open source and MIT licensed, You can use Chemical's compiler however you like. You don't even need to give credits. But if you do, we'd really appreciate it.