Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/ast-parser' into helix-compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
Ze7111 committed Jul 25, 2024
2 parents 6f542fe + fa3e6b6 commit f0e90ff
Show file tree
Hide file tree
Showing 16 changed files with 258 additions and 218 deletions.
Empty file added helix/check_hashes.py
Empty file.
3 changes: 3 additions & 0 deletions helix/hi.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
() {
std::cout << "hello" << std::endl;
}
5 changes: 5 additions & 0 deletions helix/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <iostream>

int main() {
std::cout << "hello world using mingw64" << "\n";
}
9 changes: 9 additions & 0 deletions helix/mods/core/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Helix Compiler Prelude

This folder contains essential source files and modules for the Helix language, automatically included in every Helix project without the need for an explicit import statement.

## Overview

- **Automatic Inclusion**: The modules in this folder are included by default in all Helix projects, providing fundamental functionalities and definitions.
- **Essential Prelude**: This prelude is imported implicitly, ensuring that every Helix project has access to the necessary basic components and utilities.
- **Runtime Support**: The folder also includes the `libcxx` and `libunwind` runtime libraries, crucial for compiling the Intermediate Representation (IR) of Helix programs.
61 changes: 61 additions & 0 deletions helix/mods/core/out.hlx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/// std::io::out - this is the internal code for print

ffi "c++" priv import <iostream> as cpp__io;

interface StringConvert {
fn to_string() -> string;
}

// Monomorphized generic
fn print(...args: T | U, sep: T = " ", end: T = "\n", flush: bool = false)
requires <T, U> if T is StringConvert {
let out: string = "";

for arg in args {
if arg is T {
out += arg.to_string();
} else {
out += f"<Non-StringConvert at {*arg as hex}>";
}
}

out = out.strip(*sep) + *end;

ffi "C++" {
cpp__io::std::cout << out;

if flush {
cpp__io::std::cout.flush();
}
}
}

/* ---------------------------------- usage --------------------------------- */

/*
Deriving from `StringConvert` is optional as long as `Foo` implements all
methods of the interface. This allows `Foo` to satisfy generic constraints:

- `Foo` will pass a generic constraint like `T: StringConvert`.
- However, `Foo` will fail a direct type check for the interface, e.g.,
`if foo is StringConvert`. If `Foo` does not explicitly derive `StringConvert`,
it will fail this check.
- Conversely, `Foo` will pass type-based checks such as:
`type StringConvertType requires <T> if StringConvert;`
`let foo: StringConvertType<Foo> = Foo{};`

In this case, `Foo` would be valid because it contains all the methods of
`StringConvert` without necessarily deriving from it.
*/
struct Foo : StringConvert {
fn to_string() -> string {
return "Foo";
}
}

class Bar {}

fn main() {
print("Hello, ", Foo(), "World!", end="\n"); // Hello, Foo World!
print("Hello, ", Bar(), "World!"); // Hello, <Non-StringConvert at 0x...> World!
}
48 changes: 0 additions & 48 deletions helix/mods/dyn_type.hlx

This file was deleted.

3 changes: 0 additions & 3 deletions helix/mods/io/io.hlx

This file was deleted.

128 changes: 0 additions & 128 deletions helix/mods/io/out.hlx

This file was deleted.

6 changes: 0 additions & 6 deletions helix/mods/lib.hlx

This file was deleted.

102 changes: 102 additions & 0 deletions helix/scripts/install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import os
import sys
import platform
try:
import requests
from tqdm import tqdm
except ImportError:
os.system(sys.executable + " -m pip install requests tqdm")
import requests
from tqdm import tqdm
import tarfile
import shutil
import zipfile

def download_file(url, local_filename):
response = requests.get(url, stream=True)
response.raise_for_status()
total_size = int(response.headers.get('content-length', 0))
block_size = 1024*100 # 100 kb

with open(local_filename, 'wb') as file, tqdm(
desc=local_filename,
total=total_size,
unit='iB',
unit_scale=True,
unit_divisor=1024,
) as bar:
for chunk in response.iter_content(chunk_size=block_size):
file.write(chunk)
bar.update(len(chunk))
return local_filename

def extract_file(file_path, extract_to):
if file_path.endswith('.zip'):
with zipfile.ZipFile(file_path, 'r') as zip_ref:
zip_ref.extractall(extract_to)
elif file_path.endswith('.tar.xz'):
with tarfile.open(file_path, 'r:xz') as tar_ref:
tar_ref.extractall(extract_to)
else:
raise ValueError("Unsupported file format")

def move_files(src_dir, dest_dir):
for item in os.listdir(src_dir):
s = os.path.join(src_dir, item)
d = os.path.join(dest_dir, item)
if os.path.isdir(s):
shutil.move(s, d)
else:
shutil.move(s, d)

def main():
base_url = "https://github.com/mstorsjo/llvm-mingw/releases/download/20240619/"
files = [
"llvm-mingw-20240619-msvcrt-i686.zip",
"llvm-mingw-20240619-msvcrt-ubuntu-20.04-x86_64.tar.xz",
"llvm-mingw-20240619-msvcrt-x86_64.zip",
"llvm-mingw-20240619-ucrt-aarch64.zip",
"llvm-mingw-20240619-ucrt-armv7.zip",
"llvm-mingw-20240619-ucrt-i686.zip",
"llvm-mingw-20240619-ucrt-macos-universal.tar.xz",
"llvm-mingw-20240619-ucrt-ubuntu-20.04-aarch64.tar.xz",
"llvm-mingw-20240619-ucrt-ubuntu-20.04-x86_64.tar.xz",
"llvm-mingw-20240619-ucrt-x86_64.zip"
]

# Select the appropriate file based on the platform
system = platform.system()
arch = platform.machine()

if system == 'Windows':
file_to_download = "llvm-mingw-20240619-ucrt-x86_64.zip" if arch == 'AMD64' else "llvm-mingw-20240619-ucrt-i686.zip"
elif system == 'Darwin':
file_to_download = "llvm-mingw-20240619-ucrt-macos-universal.tar.xz"
elif system == 'Linux':
if 'aarch64' in arch:
file_to_download = "llvm-mingw-20240619-ucrt-ubuntu-20.04-aarch64.tar.xz"
else:
file_to_download = "llvm-mingw-20240619-ucrt-ubuntu-20.04-x86_64.tar.xz"
else:
raise ValueError("Unsupported operating system")

# Construct download URL
download_url = base_url + file_to_download

# Define local file path
local_file = os.path.join(os.getcwd(), file_to_download)

# Download the file
download_file(download_url, local_file) if not os.path.exists(local_file) and os.stat(local_file).st_size != int(requests.get(download_url, stream=True).headers.get('content-length', 0)) else None

# Extract the file
extract_dir = os.path.abspath(os.path.join(sys.path[0], "..", "core"))
os.makedirs(extract_dir, exist_ok=True)
print(f"Extracting {file_to_download} to {extract_dir}")
extract_file(local_file, extract_dir)
move_files(os.path.join(extract_dir, local_file.split('.')[0]), extract_dir)

print("Download and extraction complete.")

if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion source/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ int main(int argc, char **argv) {
// print the preprocessed tokens

if (parsed_args.emit_ast) {
auto ast = std::make_shared<parser::ast::node::Literals>(std::make_shared<TokenList>(tokens));
auto ast = std::make_shared<parser::ast::node::Literals>(std::make_shared<TokenList>(tokens)); // for testing only change to parse an entire program when done with ast
u64 num_parsed_tokens = ast->parse().value_or(0);
print(ast->to_json());
}
Expand Down
Loading

0 comments on commit f0e90ff

Please sign in to comment.