Skip to content

Commit

Permalink
Merge branch 'helix-compiler' into preprocessor
Browse files Browse the repository at this point in the history
  • Loading branch information
Ze7111 committed Aug 8, 2024
2 parents 5ce4431 + e4cc4e5 commit f543ef4
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 33 deletions.
32 changes: 32 additions & 0 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,38 @@ Helix is an experimental language designed for seamless interoperability with Py
- **Rich Standard Library**: Extensive libraries to handle various programming tasks out of the box.
- **Object-Oriented Programming**: Support for classes and objects, enabling encapsulation, inheritance, and polymorphism for modular and reusable code.

## Why Not Use Rust or Zig?

At Helix, we believe there's a gap in the programming language space that neither Rust nor Zig fully addresses. While both languages have their strengths, they also have limitations that we aim to overcome with Helix.

### Limitations of Both Rust and Zig

- **Lack of OOP Support**: Both Rust and Zig lack comprehensive object-oriented programming (OOP) support. This can make certain types of applications, like AI development and game development, more cumbersome to implement.
- **Complex Syntax**: Both languages have syntaxes that can be verbose and complex, increasing the learning curve and potentially slowing down development.

### Specific Limitations of Rust

- **Strict Safety Mechanisms**: Rust’s borrow checker is often too strict, making it difficult for developers to write complex programs without extensive refactoring.
- **Verbosity**: The syntax of Rust can be cumbersome and verbose, which can slow down development and increase the learning curve.

### Specific Limitations of Zig

- **Limited Features**: While Zig is simple and performant, it lacks features like a preprocessor, which can limit its flexibility and control over the code compilation process.
- **Less Focus on Safety**: Zig does not emphasize safety to the same extent as Rust, which can lead to potential issues in memory management and concurrency.

### Advantages of Helix

Helix draws inspiration from the best parts of Rust, Python, Zig, and other modern languages, combining their strengths while addressing their weaknesses.

- **Balanced Safety**: Helix includes a borrow checker for pointers and references, but it's less strict. Code that fails the borrow checker emits a severe warning instead of an error, allowing developers to proceed while being aware of potential issues.
- **Simpler Syntax**: Helix offers a syntax that is both modern and easy to use, inspired by Python’s simplicity. Variable/Paramater types are strict but flexiable, resembling Python’s syntax, making it more accessible to a broader range of developers.
- **OOP Support**: Unlike Rust, Zig, and Mojo, Helix supports OOP, which is crucial for certain domains like AI development and game development. This allows for more intuitive code organization and reuse through classes and inheritance.
- **Preprocessor**: Helix includes a preprocessor, providing additional flexibility and control over code compilation.

Helix aims to offer the right balance between safety, simplicity, and flexibility, while also trying to be a better cross paltfrom C++, unlike Zig and Rust which both try to be a better C.

Helix aims to extract the cleanest and best parts of C++ without the bloat and unreadablity of it, as said by Bjarne Stroustrup, "Within C++, there is a much smaller and cleaner language struggling to get out". Helix aims to be the smaller and cleaner langauge thats getting out.

## Helix Syntax Examples

### Unique Type System
Expand Down
1 change: 1 addition & 0 deletions libs/llvm-18.1.9-src
Submodule llvm-18.1.9-src added at 0edafc
108 changes: 75 additions & 33 deletions xmake.lua
Original file line number Diff line number Diff line change
@@ -1,60 +1,102 @@
-- FIXME: rename main.cc to helix.cc
set_project("helix-lang")
set_version("0.0.1", {soname = true})
add_rules("mode.debug", "mode.release")
add_rules("plugin.vsxmake.autoupdate")

target("helix")
set_kind("binary")
set_warnings("all")

add_files("source/**.cc") -- add all files in the source directory

add_headerfiles("source/**.hh") -- add all headers in the source directory
add_includedirs("source")
set_languages("c++23") -- set the standard C++ version to C++23
-- set up config
local function configure_runtime()
if is_kind("binary") then
if is_tool("cc", "cl") or is_tool("cxx", "cl") then
return "MT"
elseif is_tool("cc", "clang") or is_tool("cxx", "clang") then
return "c++_static"
elseif is_tool("cc", "gcc") or is_tool("cxx", "g++") then
return "stdc++_static"
end
end
return ""
end

local use_runtime = configure_runtime()

if is_mode("debug") then
if is_plat("windows") then
set_runtimes("$(use_runtime)d")
end
set_symbols("debug") -- Generate debug symbols
set_optimize("none") -- Disable optimization
add_defines("DEBUG") -- Define DEBUG macro
set_runtimes("MDd") -- Use the debug version of the runtime library
else
set_runtimes("$(use_runtime)")
set_symbols("hidden") -- Hide symbols
set_optimize("fastest") -- Enable maximum optimization
add_defines("NDEBUG") -- Define NDEBUG macro
set_runtimes("MD") -- Use the release version of the runtime library
end

if is_plat("macosx") then
add_syslinks("z", "c++", "System")
add_files("source/**.cc") -- add all files in the source directory
add_headerfiles("source/**.hh") -- add all headers in the source directory
add_includedirs("source")
set_languages("c++23") -- set the standard C++ version to C++23
set_warnings("all")
set_kind("binary")
set_targetdir("$(buildir)/$(mode)/$(arch)-unknown-$(plat)/bin")
set_objectdir("$(buildir)/.resolver")
set_dependir("$(buildir)/.shared")
set_policy("build.across_targets_in_parallel", true) -- optimization


add_cxxflags("-stdlib=libc++", "-static-libgcc", "-static", {tools = "clang"})

add_linkdirs("/usr/lib/")
add_links("z", "c++", "System")
end
-- end config

target("tests")
set_kind("binary")
set_warnings("all")

add_files("tests/**.cc") -- add all files in the tests directory
add_files("source/**.cc") -- add all .cc files in the source directory and its subdirectories
remove_files("source/main.cc") -- exclude main.cc from the source directory

add_headerfiles("source/**.hh") -- add all headers in the source directory

add_headerfiles("tests/**.hh") -- add all headers in the tests directory

add_includedirs("source")
add_includedirs("tests/lib")
set_languages("c++23") -- set the standard C++ version to C++23

set_symbols("debug") -- Generate debug symbols
set_optimize("none") -- Disable optimization
add_defines("DEBUG") -- Define DEBUG macro
set_runtimes("MDd") -- Use the debug version of the runtime library
target_end()

target("helix")
target_end()

target("helix-api")
set_kind("static")
set_targetdir("$(buildir)/$(mode)/$(arch)-unknown-$(plat)")

after_build(function (target) -- make the helix library with all the appropriate header files
import("core.project.task")

-- Determine the target output directory
local target_dir = path.directory(target:targetfile())

-- Create directories for library and headers
os.mkdir(path.join(target_dir, "api/lib"))
os.mkdir(path.join(target_dir, "api/include"))

-- Move the compiled library to the 'lib' folder
os.cp(target:targetfile(), path.join(target_dir, "api/lib/"))
os.rm(target:targetfile())

-- Copy header files to the 'include' folder
local headers = os.files("source/**.hh")
for _, header in ipairs(headers) do
local rel_path = path.relative(header, "source")
os.mkdir(path.join(target_dir, "api/include", path.directory(rel_path)))
os.cp(header, path.join(target_dir, "api/include", rel_path))
end

if is_mode("debug") then
set_runtimes("MDd")
else
set_runtimes("MD")
end
local file = io.open(path.join(target_dir, "api", "xmake.lua"), "w")
file:write([[
target("helix-api")
set_kind("static")
add_files("lib/*.a")
add_includedirs("include")
add_headerfiles("include/**.hh")
]])
file:close()
end)
target_end()

0 comments on commit f543ef4

Please sign in to comment.