From 967be9e750221ab2ab783f95df79bb26d290a45e Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:07:58 +0200 Subject: add: added projects --- tiger-compiler/src/combine/binder.cc | 17 +++++++ tiger-compiler/src/combine/binder.hh | 16 +++++++ tiger-compiler/src/combine/libcombine.cc | 26 +++++++++++ tiger-compiler/src/combine/libcombine.hh | 44 ++++++++++++++++++ tiger-compiler/src/combine/local.am | 6 +++ tiger-compiler/src/combine/tasks.cc | 74 ++++++++++++++++++++++++++++++ tiger-compiler/src/combine/tasks.hh | 56 ++++++++++++++++++++++ tiger-compiler/src/combine/type-checker.cc | 14 ++++++ tiger-compiler/src/combine/type-checker.hh | 20 ++++++++ 9 files changed, 273 insertions(+) create mode 100644 tiger-compiler/src/combine/binder.cc create mode 100644 tiger-compiler/src/combine/binder.hh create mode 100644 tiger-compiler/src/combine/libcombine.cc create mode 100644 tiger-compiler/src/combine/libcombine.hh create mode 100644 tiger-compiler/src/combine/local.am create mode 100644 tiger-compiler/src/combine/tasks.cc create mode 100644 tiger-compiler/src/combine/tasks.hh create mode 100644 tiger-compiler/src/combine/type-checker.cc create mode 100644 tiger-compiler/src/combine/type-checker.hh (limited to 'tiger-compiler/src/combine') diff --git a/tiger-compiler/src/combine/binder.cc b/tiger-compiler/src/combine/binder.cc new file mode 100644 index 0000000..c5fc66e --- /dev/null +++ b/tiger-compiler/src/combine/binder.cc @@ -0,0 +1,17 @@ +/** + ** \file combine/combine-binder.cc + ** \brief Implementation of combine::Binder. + */ + +#include +#include + +namespace combine +{ + /*---------------. + | Visiting Dec. | + `---------------*/ + + // FIXME: Some code was deleted here. + +} // namespace combine diff --git a/tiger-compiler/src/combine/binder.hh b/tiger-compiler/src/combine/binder.hh new file mode 100644 index 0000000..1789b47 --- /dev/null +++ b/tiger-compiler/src/combine/binder.hh @@ -0,0 +1,16 @@ +/** + ** \file combine/binder.hh + ** \brief Declaration of combine::Binder. + **/ + +#pragma once + +#include +#include + +namespace combine +{ + /// \brief Compute bindings with support for objects and overload. + // FIXME: Some code was deleted here (class Binder inheriting from object::Binder and overload::Binder). + +} // namespace combine diff --git a/tiger-compiler/src/combine/libcombine.cc b/tiger-compiler/src/combine/libcombine.cc new file mode 100644 index 0000000..29834de --- /dev/null +++ b/tiger-compiler/src/combine/libcombine.cc @@ -0,0 +1,26 @@ +/** + ** \file combine/libcombine.cc + ** \brief Define exported combine functions. + */ + +#include + +// FIXME: Some code was deleted here. + +namespace combine +{ + std::pair + combine_bind(ast::Ast& tree, bool overloads_enabled) + { + // FIXME: Some code was deleted here. + } + + misc::error + combine_types_check(ast::Ast& tree, + const overload::overfun_bindings_type& combine_bindings, + bool overloads_enabled) + { + // FIXME: Some code was deleted here. + } + +} // namespace combine diff --git a/tiger-compiler/src/combine/libcombine.hh b/tiger-compiler/src/combine/libcombine.hh new file mode 100644 index 0000000..66f3c4c --- /dev/null +++ b/tiger-compiler/src/combine/libcombine.hh @@ -0,0 +1,44 @@ +/** + ** \file combine/libcombine.hh + ** \brief Declare functions and variables exported by combine module. + */ + +#pragma once + +#include +#include +#include + +namespace combine +{ + /*-------. + | Bind. | + `-------*/ + + /** \brief Bind identifier uses to their definition, allowing + function overloading, and return a list of potential definition + sites for each function call. + + \param tree AST to bind. + + \return a pair whose first element is the potential function + bindings, and the second element the error status. */ + std::pair + combine_bind(ast::Ast& tree, bool overloads_enabled); + + /*------------------------------. + | Compute types with overload. | + `------------------------------*/ + + /** \brief Check types allowing function overloading. + + \param tree abstract syntax tree's root. + \param combine_bindings potential function bindings. + + \return success of the type-checking. */ + misc::error + combine_types_check(ast::Ast& tree, + const overload::overfun_bindings_type& combine_bindings, + bool overloads_enabled); + +} // namespace combine diff --git a/tiger-compiler/src/combine/local.am b/tiger-compiler/src/combine/local.am new file mode 100644 index 0000000..7fd348c --- /dev/null +++ b/tiger-compiler/src/combine/local.am @@ -0,0 +1,6 @@ +src_libtc_la_SOURCES += \ + %D%/libcombine.hh %D%/libcombine.cc \ + %D%/binder.hh %D%/binder.cc \ + %D%/type-checker.hh %D%/type-checker.cc + +TASKS += %D%/tasks.hh %D%/tasks.cc diff --git a/tiger-compiler/src/combine/tasks.cc b/tiger-compiler/src/combine/tasks.cc new file mode 100644 index 0000000..48470ac --- /dev/null +++ b/tiger-compiler/src/combine/tasks.cc @@ -0,0 +1,74 @@ +/** + ** \file combine/tasks.cc + ** \brief Combine module related tasks' implementation. + */ + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include +#define DEFINE_TASKS 1 +#include +#undef DEFINE_TASKS + +namespace combine::tasks +{ + std::unique_ptr the_overfun_bindings = + nullptr; + + void combine_bindings_compute() + { + auto result = + ::combine::combine_bind(*ast::tasks::the_program, c_overload_p); + ::combine::tasks::the_overfun_bindings = + std::make_unique( + std::move(result.first)); + + task_error() << result.second << &misc::error::exit_on_error; + } + + void combine_types_compute() + { + task_error() << ::combine::combine_types_check( + *ast::tasks::the_program, *::combine::tasks::the_overfun_bindings, + c_overload_p); + the_overfun_bindings.reset(); + task_error().exit_on_error(); + } + + void combine_rename() + { + // FIXME: Some code was deleted here (Call appropriate renaming tasks). + } + + void combine_desugar() + { + if (c_object_p) + ::object::tasks::object_desugar(); + + if (c_desugar_p) + ::desugar::tasks::desugar(); + + if (c_bounds_p) + astclone::apply(::desugar::bounds_checks_add, ast::tasks::the_program); + + if (c_inline_p) + astclone::apply(::inlining::inline_expand, ast::tasks::the_program); + + if (c_prune_p) + astclone::apply(::inlining::prune, ast::tasks::the_program); + + if (c_escapes_p) + ::escapes::tasks::escapes_compute(); + } + +} // namespace combine::tasks diff --git a/tiger-compiler/src/combine/tasks.hh b/tiger-compiler/src/combine/tasks.hh new file mode 100644 index 0000000..67cc169 --- /dev/null +++ b/tiger-compiler/src/combine/tasks.hh @@ -0,0 +1,56 @@ +/** + ** \file combine/tasks.hh + ** \brief Combine module related tasks. + */ + +#pragma once + +#include +#include + +namespace combine::tasks +{ + TASK_GROUP("Combine"); + + BOOLEAN_TASK_DECLARE("c-object", "combine objects", c_object_p, "object"); + BOOLEAN_TASK_DECLARE("c-bounds", "combine bounds checking", c_bounds_p, ""); + BOOLEAN_TASK_DECLARE("c-escapes", "combine escapes", c_escapes_p, ""); + BOOLEAN_TASK_DECLARE("c-desugar", + "combine for and string comparison desugaring", + c_desugar_p, + "desugar-for desugar-string-cmp"); + BOOLEAN_TASK_DECLARE("c-inline", "combine inlining", c_inline_p, ""); + BOOLEAN_TASK_DECLARE("c-prune", "combine pruning", c_prune_p, ""); + BOOLEAN_TASK_DECLARE("c-overload", "combine overloading", c_overload_p, ""); + + BOOLEAN_TASK_DECLARE( + "a|c-all", + "combine all compiler options", + c_all_p, + "c-object c-bounds c-escapes c-desugar c-inline c-prune c-overload"); + + TASK_DECLARE("combine-bindings-compute", + "bind the identifiers, " + "allowing various compiler options", + combine_bindings_compute, + "parse"); + + TASK_DECLARE("combine-types-compute", + "check for type violations, " + "allowing various compiler options", + combine_types_compute, + "combine-bindings-compute"); + + TASK_DECLARE("combine-rename", + "rename identifiers to unique names, " + "allowing various compiler options", + combine_rename, + "combine-types-compute"); + + TASK_DECLARE("c|combine-desugar", + "remove object and complex constructs from the program" + "allowing various compiler options", + combine_desugar, + "combine-rename"); + +} // namespace combine::tasks diff --git a/tiger-compiler/src/combine/type-checker.cc b/tiger-compiler/src/combine/type-checker.cc new file mode 100644 index 0000000..67cbfbc --- /dev/null +++ b/tiger-compiler/src/combine/type-checker.cc @@ -0,0 +1,14 @@ +/** + ** \file combine/type-checker.cc + ** \brief Implementation for combine/type-checker.hh. + */ + +#include +#include +#include + +namespace combine +{ + // FIXME: Some code was deleted here. + +} // namespace combine diff --git a/tiger-compiler/src/combine/type-checker.hh b/tiger-compiler/src/combine/type-checker.hh new file mode 100644 index 0000000..02370d2 --- /dev/null +++ b/tiger-compiler/src/combine/type-checker.hh @@ -0,0 +1,20 @@ +/** + ** \file combine/type-checker.hh + ** \brief Declaration of combine::TypeChecker. + */ + +#pragma once + +#include +#include +#include +#include +#include + +namespace combine +{ + /// Perform type checking, allowing objects, and compute + /// the bindings of the object's methods and fields. + // FIXME: Some code was deleted here (class TypeChecker inheriting from overload::TypeChecker and object::TypeChecker). + +} // namespace combine -- cgit v1.2.3