# 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
Types follow the ***PascalCase*** convention, they are:
| 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 brackets for single instructions
```cpp
if (condition)
// do stuff
else
// do other stuff
```
### While
Unlike in C++, while statements require brackets 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 brackets to work
```Java
for(Num i = 0; i < 10; ++i) {
// do stuff
}
```
## Functions
Just like in C++, functions are declared like this:
```c++
Num myFunction() {
return 247;
}
```
### Extern Functions
There are two types of extern functions
- C functions
- tungsten functions
You can import C functions with
```cpp
extern "C" Void myCFun();
```
and tungsten functions with
```cpp
extern Void myFun();
```
### 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++
Num main() {
/* your code */
return 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