Skip to content

Commit

Permalink
Added the utility and parametric submodules.
Browse files Browse the repository at this point in the history
  • Loading branch information
Goubermouche committed Feb 13, 2024
1 parent e249fa2 commit 2d2065e
Show file tree
Hide file tree
Showing 49 changed files with 159 additions and 192 deletions.
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "source/utility"]
path = source/utility
url = https://github.com/Goubermouche/utility
[submodule "source/parametric"]
path = source/parametric
url = https://github.com/Goubermouche/parametric
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Sigma is a compiled, statically typed, C-like, data oriented language with a foc
Get started by running:
```shell
# Download Sigma's source code
$ git clone https://github.com/Goubermouche/sigma.git
$ git clone https://github.com/Goubermouche/sigma.git --recursive
$ cd sigma

# Generate project files
Expand Down
72 changes: 22 additions & 50 deletions premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,6 @@ workspace "sigma"
runtime "Debug"
defines { "DEBUG", "_DEBUG" }

-- utility
project "utility"
kind "StaticLib"
location "source/utility"

files {
"source/utility/**.h",
"source/utility/**.cpp"
}

includedirs {
"source"
}

-- output directories
targetdir "output/compiler/bin/%{cfg.buildcfg}"
objdir "output/compiler/obj/%{cfg.buildcfg}"

-- tokenizer
project "tokenizer"
kind "StaticLib"
Expand All @@ -55,11 +37,8 @@ project "tokenizer"
}

includedirs {
"source"
}

links {
"utility"
"source",
"source/utility"
}

-- output directories
Expand All @@ -77,11 +56,8 @@ project "abstract_syntax_tree"
}

includedirs {
"source"
}

links {
"utility"
"source",
"source/utility"
}

-- output directories
Expand All @@ -99,12 +75,12 @@ project "parser"
}

includedirs {
"source"
"source",
"source/utility"
}

links {
"abstract_syntax_tree",
"utility"
"abstract_syntax_tree"
}

-- output directories
Expand All @@ -122,12 +98,12 @@ project "type_checker"
}

includedirs {
"source"
"source",
"source/utility"
}

links {
"abstract_syntax_tree",
"utility"
"abstract_syntax_tree"
}

-- output directories
Expand All @@ -145,11 +121,8 @@ project "intermediate_representation"
}

includedirs {
"source"
}

links {
"utility"
"source",
"source/utility"
}

-- output directories
Expand All @@ -167,13 +140,13 @@ project "ir_translator"
}

includedirs {
"source"
"source",
"source/utility"
}

links {
"abstract_syntax_tree",
"intermediate_representation",
"utility"
"intermediate_representation"
}

-- output directories
Expand All @@ -193,7 +166,9 @@ project "compiler"
}

includedirs {
"source"
"source",
"source/utility",
"source/parametric"
}

links {
Expand All @@ -202,8 +177,7 @@ project "compiler"
"type_checker",
"parser",
"abstract_syntax_tree",
"tokenizer",
"utility"
"tokenizer"
}

-- output directories
Expand Down Expand Up @@ -268,11 +242,9 @@ project "tests"
debugargs { "run", "../../tests", "..\\..\\output\\compiler\\bin\\Debug\\compiler.exe" }

includedirs {
"source"
}

links {
"utility"
"source",
"source/utility",
"source/parametric"
}

-- output directories
Expand Down
2 changes: 1 addition & 1 deletion source/abstract_syntax_tree/node.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "node.h"
#include "utility/macros.h"
#include "util/macros.h"

namespace sigma::ast {
node_type::node_type(underlying type) : type(type) {}
Expand Down
6 changes: 3 additions & 3 deletions source/abstract_syntax_tree/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#include <compiler/compiler/type_system/namespace_list.h>
#include <compiler/compiler/type_system/type.h>

#include "utility/containers/property.h"
#include "utility/containers/handle.h"
#include "utility/containers/slice.h"
#include "util/property.h"
#include "util/handle.h"
#include "util/containers/slice.h"

namespace sigma::ast {
struct node_type {
Expand Down
6 changes: 3 additions & 3 deletions source/abstract_syntax_tree/tree.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "tree.h"
#include "utility/containers/stack.h"
#include "util/containers/stack.h"

namespace sigma::ast {
tree::tree() : m_allocator(1024) {}
Expand Down Expand Up @@ -34,11 +34,11 @@ namespace sigma::ast {
return { m_allocator, count };
}

auto tree::get_nodes() -> utility::contiguous_container<handle<node>>& {
auto tree::get_nodes() -> utility::contiguous_buffer<handle<node>>& {
return m_nodes;
}

auto tree::get_nodes() const -> const utility::contiguous_container<handle<node>>& {
auto tree::get_nodes() const -> const utility::contiguous_buffer<handle<node>>& {
return m_nodes;
}

Expand Down
10 changes: 5 additions & 5 deletions source/abstract_syntax_tree/tree.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once
#include "abstract_syntax_tree/node.h"

#include <utility/containers/allocators/block_allocator.h>
#include <utility/containers/contiguous_container.h>
#include <util/block_allocator.h>
#include <util/containers/contiguous_buffer.h>

namespace sigma::ast {
class tree {
Expand All @@ -14,8 +14,8 @@ namespace sigma::ast {
void add_node(handle<node> node);
auto allocate_node_list(u16 count) -> utility::slice<handle<node>, u16>;

auto get_nodes() -> utility::contiguous_container<handle<node>>&;
auto get_nodes() const -> const utility::contiguous_container<handle<node>>&;
auto get_nodes() -> utility::contiguous_buffer<handle<node>>&;
auto get_nodes() const -> const utility::contiguous_buffer<handle<node>>&;
auto get_allocator() -> utility::block_allocator&;

template<typename extra_type = utility::empty_property>
Expand All @@ -33,7 +33,7 @@ namespace sigma::ast {
}
private:
// handles pointing to the main nodes (functions and globals)
utility::contiguous_container<handle<node>> m_nodes;
utility::contiguous_buffer<handle<node>> m_nodes;

// the actual node data is stored in a block allocator
utility::block_allocator m_allocator;
Expand Down
5 changes: 2 additions & 3 deletions source/compiler/compiler/compilation_context.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "compilation_context.h"
#include <utility/string_helper.h>

namespace sigma {
backend_context::backend_context(sigma::syntax& syntax, ir::target target)
Expand Down Expand Up @@ -67,7 +66,7 @@ namespace sigma {
std::string symbol_value;
// check if the token has a string value associated with it
if (syntax.strings.contains(info.symbol_key)) {
symbol_value = utility::detail::escape_string(syntax.strings.get(info.symbol_key));
symbol_value = utility::escape_string(syntax.strings.get(info.symbol_key));
}

utility::console::print(
Expand Down Expand Up @@ -154,7 +153,7 @@ namespace sigma {
}
case ast::node_type::STRING_LITERAL: {
const auto& property = node->get<ast::named_type_expression>();
utility::console::print("[\"{}\"]", utility::detail::escape_string(strings.get(property.key)));
utility::console::print("[\"{}\"]", utility::escape_string(strings.get(property.key)));
break;
}
case ast::node_type::BOOL_LITERAL: {
Expand Down
2 changes: 1 addition & 1 deletion source/compiler/compiler/compilation_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <abstract_syntax_tree/tree.h>
#include <intermediate_representation/builder.h>
#include <utility/containers/string_table.h>
#include <util/string/string_table.h>
#include <tokenizer/token_buffer.h>

// TODO: add support for emitting to .dot files
Expand Down
4 changes: 1 addition & 3 deletions source/compiler/compiler/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
#include <type_checker/type_checker.h>
#include <ir_translator/ir_translator.h>

#include <utility/string_helper.h>

#define LANG_FILE_EXTENSION ".s"

namespace sigma {
Expand Down Expand Up @@ -85,7 +83,7 @@ namespace sigma {
}

void compiler::emit_object_file(ir::module& module, const filepath& path) {
utility::fs::file<utility::contiguous_container<utility::byte>>::save(path, module.generate_object_file());
utility::fs::file<utility::contiguous_buffer<utility::byte>>::save(path, module.generate_object_file());
}

auto compiler::get_emit_target_from_path(const filepath& path) const -> utility::result<emit_target> {
Expand Down
6 changes: 3 additions & 3 deletions source/compiler/compiler/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

#pragma once
#include <intermediate_representation/target/target.h>
#include <utility/parametric/parametric.h>
#include <utility/diagnostics.h>
#include <utility/filesystem/file.h>
#include <parametric/parametric.h>
#include <util/diagnostics.h>
#include <util/filesystem/filesystem.h>

namespace sigma {
using namespace utility::types;
Expand Down
4 changes: 2 additions & 2 deletions source/compiler/compiler/type_system/namespace_list.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include <utility/containers/string_table.h>
#include "utility/containers/slice.h"
#include <util/string/string_table.h>
#include "util/containers/slice.h"

namespace sigma {
using namespace utility::types;
Expand Down
2 changes: 1 addition & 1 deletion source/compiler/compiler/type_system/scope.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include <intermediate_representation/builder.h>
#include <utility/containers/string_table.h>
#include <util/string/string_table.h>
#include <abstract_syntax_tree/node.h>

#include "compiler/compiler/type_system/type.h"
Expand Down
2 changes: 1 addition & 1 deletion source/compiler/compiler/type_system/semantic_context.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include <utility/containers/string_table.h>
#include <util/string/string_table.h>

#include "compiler/compiler/type_system/scope.h"

Expand Down
2 changes: 1 addition & 1 deletion source/compiler/compiler/type_system/type.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "type.h"

#include <utility/macros.h>
#include <util/macros.h>

namespace sigma {
named_data_type::named_data_type(sigma::type type, utility::string_table_key identifier_key)
Expand Down
2 changes: 1 addition & 1 deletion source/compiler/compiler/type_system/type.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include <compiler/compiler/type_system/namespace_list.h>
#include <utility/containers/slice.h>
#include <util/containers/slice.h>
#include <tokenizer/token.h>

namespace sigma {
Expand Down
2 changes: 1 addition & 1 deletion source/compiler/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "compiler/compiler.h"
#include <utility/shell.h>
#include <util/shell.h>

using namespace utility::types;

Expand Down
2 changes: 0 additions & 2 deletions source/compiler/test/main.s
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
// - more info related to numerical errors (hex etc)
// - add namespaces to messages, whenever applicable (ie. x::y::test)
// - BUGS:
// - type parameters do not take namespaces into account (just identifiers/base/ptr)
// - copying structs

struct nested {
u8 a;
Expand Down
1 change: 0 additions & 1 deletion source/intermediate_representation/builder.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "builder.h"
#include <utility/string_helper.h>

// #define DEBUG_PRINT_BUILDER

Expand Down
4 changes: 1 addition & 3 deletions source/intermediate_representation/codegen/codegen_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
#include "intermediate_representation/codegen/control_flow_graph.h"
#include "intermediate_representation/target/target.h"

#include <utility/containers/allocator_based_containers/linked_list.h>

namespace sigma::ir {
struct codegen_context {
/**
Expand Down Expand Up @@ -93,7 +91,7 @@ namespace sigma::ir {
work_list& work;

std::vector<u64> basic_block_order;
utility::contiguous_container<phi_value> phi_values;
utility::contiguous_buffer<phi_value> phi_values;

// live intervals which represent value lifetimes
std::vector<live_interval> intervals;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace sigma::ir {
return {};
}

auto codegen_target::disassemble(const utility::byte_buffer& bytecode, const codegen_context& context) const -> utility::string {
auto codegen_target::disassemble(const utility::byte_buffer& bytecode, const codegen_context& context) const -> std::stringstream {
ASSERT(m_disassembler != nullptr, "target is not initialized");
return m_disassembler->disassemble(bytecode, context);
}
Expand Down
Loading

0 comments on commit 2d2065e

Please sign in to comment.