# The Tungsten programming language
**2. Compiling the project:** Here I'm using vcpkg: ```bash cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE='VCPKG_DIR\scripts\buildsystems\vcpkg.cmake' -DVCPKG_TARGET_TRIPLET=x64-windows-static -DLLVM_DIR='VCPKG_DIR/installed/x64-windows-static/share/llvm/' -Dzstd_DIR='VCPKG_DIR/installed/x64-windows-static/share/zstd' cmake --build build --config Release ``` replace `VCPKG_DIR` with the vcpkg directory
**2. Compiling the project:** *the default compiler and CMake generator on linux (gcc and Make) don't support modules, so I'll be using Clang and Ninja in the example below* ```bash cmake -S . -B build -GNinja -DCMAKE_CXX_COMPILER=clang++ cmake --build build --config Release ```
# Syntax
## Variables declaration
Tungsten has a similar naming convention to Rust, where base types are written in **camelCase** and structs and classes
are written in **PascalCase**
| Type | Alignment (Bytes) |
|----------|-------------------|
| `void` | N/A |
| `char` | 2 |
| `bool` | 1 |
| `String` | N/A |
| `num` | 8 |
> [!IMPORTANT]
> `num` is a `double` so to use functions like `print` and `input` you need to use the `%lf` format
> specifier
Tungsten has also a variadic type called `ArgPack` which is just like `...` in C
### Stack allocation
```c++
num myVariable = 247;
num myVariable{247};
```
## Control flow statements
### If
If statements are written just like in C++
```cpp
if (condition) {
// do stuff
} else {
// do other stuff
}
```
And just like in C++ you can avoid using braces for single instructions
```cpp
if (condition)
// do stuff
else
// do other stuff
```
### While
Unlike in C++, while statements require braces to work
```cpp
while (condition) {
// do stuff
}
```
### Do while
Do whiles instead are just like in C++
```cpp
do {
// do stuff
} while(condition);
```
### For
For statements just like while statements require braces to work
```c++
for (num i = 0; i < 10; ++i) {
// do stuff
}
```
## Functions
Rather than a C++ aproach, functions are more similar to Rust's:
```c++
fun myFunction() -> num {
ret 247;
}
```
### Extern Functions
There are two types of extern functions
- C functions
- tungsten functions
You can import C functions with
```cpp
extern "C" fun myCFun() -> void;
```
and tungsten functions with
```cpp
extern fun myFun() -> void;
```
### Main Function
The `main` function can return either `int` or `int32`. Command line arguments are passed as a `String` array.
If no return value is provided, `0` will be returned by default.
```c++
fun main(String[] args) -> num {
/* your code */
ret CodeSuccess;
}
```
### integrated Core Functions
Tungsten has a reduced number of integrated core functions
| Type | Name | Arguments | functionality |
|----------|-------------------|-----------------------|----------------------------------------------|
| `num` | shell | (String cmd) | same function as `system()` in C |
| `void` | print | (String fmt, ArgPack) | same function as `printf()` in C |
| `void` | input | (String fmt, ArgPack) | same function as `scanf()` in C |
| `String` | __builtinFile | no arguments | returns the name of the file |
| `String` | __builtinFunction | no arguments | returns the name of the function |
| `num` | __builtinColumn | no arguments | returns the number of the column |
| `num` | __builtinLine | no arguments | returns the number of the line |
| `String` | nameof | (any variable) | returns the name of the variable |
| `String` | typeof | (any variable) | returns the type of the variable |
| `num` | sizeof | (any variable) | returns the size of the type of the variable |
## Building a project
To build a project, you can either compile via cmd by calling the `tungsten` compiler or you can make a `build.tgs` file
and use the integrated buildsystem
### Compiling via cmd
> [!IMPORTANT]
> Tungsten currently uses *clang* to compile the generated llvm ir to an executable, so you need to have it installed
> for the compiler to work
```shell
cd projectDirectory
tungsten