summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-05-11 13:25:20 +0800
committerJohn Hodge <tpg@mutabah.net>2016-05-11 13:25:20 +0800
commit8e9e3a395f211dc871c3abc816b1cc892ed74312 (patch)
tree54efa6d90a427c2a5e0488da9fe8d59b91a325a7 /src
parent1ac071bb74b47a0904e080f1343b31142da9da90 (diff)
downloadmrust-8e9e3a395f211dc871c3abc816b1cc892ed74312.tar.gz
HIR - Start on conversion
Diffstat (limited to 'src')
-rw-r--r--src/hir/crate_ptr.cpp20
-rw-r--r--src/hir/crate_ptr.hpp23
-rw-r--r--src/hir/from_ast.cpp9
-rw-r--r--src/hir/hir.hpp6
-rw-r--r--src/hir/path.hpp4
-rw-r--r--src/include/main_bindings.hpp4
-rw-r--r--src/main.cpp7
7 files changed, 63 insertions, 10 deletions
diff --git a/src/hir/crate_ptr.cpp b/src/hir/crate_ptr.cpp
new file mode 100644
index 00000000..bc0287b3
--- /dev/null
+++ b/src/hir/crate_ptr.cpp
@@ -0,0 +1,20 @@
+/*
+ */
+#include "crate_ptr.hpp"
+#include "hir.hpp"
+
+::HIR::CratePtr::CratePtr():
+ m_ptr(nullptr)
+{
+}
+::HIR::CratePtr::CratePtr(HIR::Crate c):
+ m_ptr( new ::HIR::Crate(mv$(c)) )
+{
+}
+::HIR::CratePtr::~CratePtr()
+{
+ if( m_ptr ) {
+ delete m_ptr, m_ptr = nullptr;
+ }
+}
+
diff --git a/src/hir/crate_ptr.hpp b/src/hir/crate_ptr.hpp
new file mode 100644
index 00000000..ca95074d
--- /dev/null
+++ b/src/hir/crate_ptr.hpp
@@ -0,0 +1,23 @@
+/*
+ * High-level intermediate representation
+ */
+#pragma once
+
+namespace HIR {
+
+class Crate;
+
+class CratePtr
+{
+ Crate* m_ptr;
+
+public:
+ CratePtr();
+ CratePtr(Crate c);
+ CratePtr(CratePtr&&) = default;
+ CratePtr& operator=(CratePtr&&) = default;
+ ~CratePtr();
+};
+
+} // namespace HIR
+
diff --git a/src/hir/from_ast.cpp b/src/hir/from_ast.cpp
index 4da703f9..72654efd 100644
--- a/src/hir/from_ast.cpp
+++ b/src/hir/from_ast.cpp
@@ -1,5 +1,6 @@
#include "hir.hpp"
+#include <main_bindings.hpp>
#include <ast/ast.hpp>
#include <ast/crate.hpp>
@@ -8,17 +9,17 @@
/// \brief Converts the AST into HIR format
///
/// - Removes all possibility for unexpanded macros
-/// - Performs name resolution and partial UFCS conversion?
/// - Performs desugaring of for/if-let/while-let/...
-::HIR::Crate LowerHIR_FromAST(::AST::Crate crate)
+::HIR::CratePtr LowerHIR_FromAST(::AST::Crate crate)
{
::std::unordered_map< ::std::string, MacroRules > macros;
auto rootmod = LowerHIR_Module( mv$(crate.m_root_module), ::HIR::SimplePath("") );
- return { mv$(rootmod), mv$(macros) };
+ return ::HIR::CratePtr( ::HIR::Crate { mv$(rootmod), mv$(macros) } );
}
::HIR::Module LowerHIR_Module(::AST::Module module, ::HIR::SimplePath path)
{
- throw ::std::runtime_error("");
+ ::HIR::Module mod { };
+ throw ::std::runtime_error("TODO: LowerHIR_Module");
}
diff --git a/src/hir/hir.hpp b/src/hir/hir.hpp
index 7633d916..5743e24a 100644
--- a/src/hir/hir.hpp
+++ b/src/hir/hir.hpp
@@ -110,14 +110,12 @@ public:
::std::unordered_map< ::std::string, ::std::unique_ptr<VisEnt<ValueItem>> > m_value_items;
// Contains types, traits, and modules
::std::unordered_map< ::std::string, ::std::unique_ptr<VisEnt<TypeItem>> > m_mod_items;
- // Glob imports
- ::std::vector< VisEnt<::HIR::Path> > m_glob_imports;
};
// --------------------------------------------------------------------
TAGGED_UNION(TypeItem, Import,
- (Import, ::HIR::Path),
+ (Import, ::HIR::SimplePath), // `pub use` statements (no globs)
(Module, Module),
(TypeAlias, TypeAlias), // NOTE: These don't introduce new values
(Enum, Enum),
@@ -125,7 +123,7 @@ TAGGED_UNION(TypeItem, Import,
(Trait, Trait)
);
TAGGED_UNION(ValueItem, Import,
- (Import, ::HIR::Path),
+ (Import, ::HIR::SimplePath),
(Static, Static),
(StructConstant, struct { ::HIR::TypeRef ty; }),
(Function, Function),
diff --git a/src/hir/path.hpp b/src/hir/path.hpp
index e51e3c50..561ddc83 100644
--- a/src/hir/path.hpp
+++ b/src/hir/path.hpp
@@ -12,6 +12,10 @@ class TypeRef;
/// Simple path - Absolute with no generic parameters
struct SimplePath
{
+ SimplePath():
+ m_crate_name("")
+ {
+ }
SimplePath(::std::string crate):
m_crate_name( mv$(crate) )
{
diff --git a/src/include/main_bindings.hpp b/src/include/main_bindings.hpp
index 8f1c605d..299ec94f 100644
--- a/src/include/main_bindings.hpp
+++ b/src/include/main_bindings.hpp
@@ -4,6 +4,8 @@
#define _MAIN_BINDINGS_HPP_
#include <string>
+#include <memory>
+#include <hir/crate_ptr.hpp>
namespace AST {
class Crate;
@@ -23,6 +25,8 @@ extern void Resolve_Use(::AST::Crate& crate);
extern void Resolve_Index(::AST::Crate& crate);
extern void Resolve_Absolutise(::AST::Crate& crate);
+extern ::HIR::CratePtr LowerHIR_FromAST(::AST::Crate crate);
+
/// Resolve all in-text paths to absolute variants
extern void ResolvePaths(AST::Crate& crate);
/// Check that generic bounds are valid
diff --git a/src/main.cpp b/src/main.cpp
index 74e5e7f1..74e92f76 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -54,9 +54,11 @@ template <typename Rv, typename Fcn>
Rv CompilePhase(const char *name, Fcn f) {
::std::cout << name << ": V V V" << ::std::endl;
g_cur_phase = name;
+ auto start = clock();
auto rv = f();
+ auto end = clock();
g_cur_phase = "";
- ::std::cout << name << ": DONE" << ::std::endl;
+ ::std::cout << name << ": DONE (" << static_cast<double>(end - start) / static_cast<double>(CLOCKS_PER_SEC) << " s)" << ::std::endl;
return rv;
}
template <typename Fcn>
@@ -130,8 +132,9 @@ int main(int argc, char *argv[])
Dump_Rust( FMT(params.outfile << "_1_res.rs").c_str(), crate );
});
+ ::HIR::CratePtr hir_crate;
CompilePhaseV("HIR Lower", [&]() {
- //hir_crate = LowerHIR_FromAST(mv$( crate ));
+ hir_crate = LowerHIR_FromAST(mv$( crate ));
});
// Replace type aliases (`type`) into the actual type