summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ast/crate.cpp38
-rw-r--r--src/hir/from_ast.cpp4
-rw-r--r--src/hir/hir.hpp16
-rw-r--r--src/hir/type.hpp9
-rw-r--r--src/hir_expand/vtable.cpp11
-rw-r--r--src/hir_typeck/expr_visit.cpp7
-rw-r--r--src/include/span.hpp3
-rw-r--r--src/macro_rules/parse.cpp6
-rw-r--r--src/mir/from_hir.cpp1
-rw-r--r--src/mir/mir.cpp1
-rw-r--r--src/mir/mir.hpp2
-rw-r--r--src/rc_string.cpp1
12 files changed, 79 insertions, 20 deletions
diff --git a/src/ast/crate.cpp b/src/ast/crate.cpp
index e788f6e0..19a19381 100644
--- a/src/ast/crate.cpp
+++ b/src/ast/crate.cpp
@@ -12,7 +12,12 @@
#include <hir/hir.hpp> // HIR::Crate
#include <hir/main_bindings.hpp> // HIR_Deserialise
#include <fstream>
-#include <dirent.h>
+#ifdef _WIN32
+# define NOGDI // prevent ERROR from being defined
+# include <Windows.h>
+#else
+# include <dirent.h>
+#endif
::std::vector<::std::string> AST::g_crate_load_dirs = { };
::std::map<::std::string, ::std::string> AST::g_crate_overrides;
@@ -167,6 +172,17 @@ RcString Crate::load_extern_crate(Span sp, const RcString& name, const ::std::st
path = "";
// Search for `p+"/lib"+name+"-*.rlib" (which would match e.g. libnum-0.11.rlib)
+#ifdef _WIN32
+ WIN32_FIND_DATA find_data;
+ auto mask = p + "\\*";
+ HANDLE find_handle = FindFirstFile( mask.c_str(), &find_data );
+ if( find_handle == INVALID_HANDLE_VALUE ) {
+ continue ;
+ }
+ do
+ {
+ const auto* fname = find_data.cFileName;
+#else
auto dp = opendir(p.c_str());
if( !dp ) {
continue ;
@@ -174,12 +190,15 @@ RcString Crate::load_extern_crate(Span sp, const RcString& name, const ::std::st
struct dirent *ent;
while( (ent = readdir(dp)) != nullptr && path == "" )
{
+ const auto* fname = ent->d_name;
+#endif
+
// AND the start is "lib"+name
- size_t len = strlen(ent->d_name);
- if( len > (sizeof(RLIB_SUFFIX)-1) && strcmp(ent->d_name + len - (sizeof(RLIB_SUFFIX)-1), RLIB_SUFFIX) == 0 )
+ size_t len = strlen(fname);
+ if( len > (sizeof(RLIB_SUFFIX)-1) && strcmp(fname + len - (sizeof(RLIB_SUFFIX)-1), RLIB_SUFFIX) == 0 )
{
}
- else if( len > (sizeof(RDYLIB_SUFFIX)-1) && strcmp(ent->d_name + len - (sizeof(RDYLIB_SUFFIX)-1), RDYLIB_SUFFIX) == 0 )
+ else if( len > (sizeof(RDYLIB_SUFFIX)-1) && strcmp(fname + len - (sizeof(RDYLIB_SUFFIX)-1), RDYLIB_SUFFIX) == 0 )
{
}
else
@@ -187,14 +206,19 @@ RcString Crate::load_extern_crate(Span sp, const RcString& name, const ::std::st
continue ;
}
- DEBUG(ent->d_name << " vs " << name_prefix);
+ DEBUG(fname << " vs " << name_prefix);
// Check if the entry ends with .rlib
- if( strncmp(name_prefix.c_str(), ent->d_name, name_prefix.size()) != 0 )
+ if( strncmp(name_prefix.c_str(), fname, name_prefix.size()) != 0 )
continue ;
- paths.push_back( p + "/" + ent->d_name );
+ paths.push_back( p + "/" + fname );
+#ifdef _WIN32
+ } while( FindNextFile(find_handle, &find_data) );
+ FindClose(find_handle);
+#else
}
closedir(dp);
+#endif
if( paths.size() > 0 )
break;
}
diff --git a/src/hir/from_ast.cpp b/src/hir/from_ast.cpp
index 54644806..4cde40fc 100644
--- a/src/hir/from_ast.cpp
+++ b/src/hir/from_ast.cpp
@@ -31,10 +31,10 @@ const ::AST::Crate* g_ast_crate_ptr;
// --------------------------------------------------------------------
HIR::LifetimeRef LowerHIR_LifetimeRef(const ::AST::LifetimeRef& r)
{
- return HIR::LifetimeRef {
+ return HIR::LifetimeRef(
// TODO: names?
r.binding()
- };
+ );
}
::HIR::GenericParams LowerHIR_GenericParams(const ::AST::GenericParams& gp, bool* self_is_sized)
diff --git a/src/hir/hir.hpp b/src/hir/hir.hpp
index bdfc8d0b..8b718b4f 100644
--- a/src/hir/hir.hpp
+++ b/src/hir/hir.hpp
@@ -323,6 +323,22 @@ public:
(Named, t_struct_fields)
);
+ Struct(GenericParams params, Repr repr, Data data)
+ :m_params(mv$(params))
+ ,m_repr(mv$(repr))
+ ,m_data(mv$(data))
+ {
+ }
+ Struct(GenericParams params, Repr repr, Data data, unsigned align, TraitMarkings tm, StructMarkings sm)
+ :m_params(mv$(params))
+ ,m_repr(mv$(repr))
+ ,m_data(mv$(data))
+ ,m_forced_alignment(align)
+ ,m_markings(mv$(tm))
+ ,m_struct_markings(mv$(sm))
+ {
+ }
+
GenericParams m_params;
Repr m_repr;
Data m_data;
diff --git a/src/hir/type.hpp b/src/hir/type.hpp
index fe28deed..cbc2e94a 100644
--- a/src/hir/type.hpp
+++ b/src/hir/type.hpp
@@ -93,6 +93,15 @@ struct LifetimeRef
// Values below 2^16 are parameters/static, values above are per-function region IDs allocated during region inferrence.
uint32_t binding = UNKNOWN;
+ LifetimeRef()
+ :binding(UNKNOWN)
+ {
+ }
+ LifetimeRef(uint32_t binding)
+ :binding(binding)
+ {
+ }
+
static LifetimeRef new_static() {
LifetimeRef rv;
rv.binding = STATIC;
diff --git a/src/hir_expand/vtable.cpp b/src/hir_expand/vtable.cpp
index cd7b3413..d2afff5d 100644
--- a/src/hir_expand/vtable.cpp
+++ b/src/hir_expand/vtable.cpp
@@ -231,12 +231,11 @@ namespace {
}
}
// TODO: Would like to have access to the publicity marker
- auto item_path = m_new_type(true, RcString::new_interned(FMT(p.get_name() << "#vtable")), ::HIR::Struct {
- mv$(args),
- ::HIR::Struct::Repr::Rust,
- ::HIR::Struct::Data(mv$(fields)),
- {}
- });
+ auto item_path = m_new_type(
+ true,
+ RcString::new_interned(FMT(p.get_name() << "#vtable")),
+ ::HIR::Struct(mv$(args), ::HIR::Struct::Repr::Rust, ::HIR::Struct::Data(mv$(fields)))
+ );
tr.m_vtable_path = item_path;
DEBUG("Vtable structure created - " << item_path);
::HIR::GenericPath path( mv$(item_path), mv$(params) );
diff --git a/src/hir_typeck/expr_visit.cpp b/src/hir_typeck/expr_visit.cpp
index c655bc52..df27b7d7 100644
--- a/src/hir_typeck/expr_visit.cpp
+++ b/src/hir_typeck/expr_visit.cpp
@@ -65,6 +65,12 @@ namespace typeck {
TU_ARMA(Function, e) {
m_item_generics = &e.m_params;
}
+ TU_ARMA(Constant, e) {
+ m_item_generics = &e.m_params;
+ }
+ TU_ARMA(Static, e) {
+ m_item_generics = nullptr;
+ }
}
}
else if( ip.parent->ty )
@@ -91,6 +97,7 @@ namespace typeck {
}
TU_ARMA(StructConstant, _e) BUG(sp, ip << " is StructConstant");
TU_ARMA(StructConstructor, _e) BUG(sp, ip << " is StructConstructor");
+ TU_ARMA(Import, _e) BUG(sp, ip << " is Import");
}
}
}
diff --git a/src/include/span.hpp b/src/include/span.hpp
index 68d6bfdf..51c3440c 100644
--- a/src/include/span.hpp
+++ b/src/include/span.hpp
@@ -29,8 +29,9 @@ struct ProtoSpan
unsigned int start_line;
unsigned int start_ofs;
};
-struct Span
+class Span
{
+public:
::std::shared_ptr<Span> outer_span; // Expansion target for macros
RcString filename;
diff --git a/src/macro_rules/parse.cpp b/src/macro_rules/parse.cpp
index 97e1f8f9..43ffb097 100644
--- a/src/macro_rules/parse.cpp
+++ b/src/macro_rules/parse.cpp
@@ -58,7 +58,9 @@ public:
switch( GET_TOK(tok, lex) )
{
// TODO: Allow any reserved word
- case TOK_RWORD_PUB ... TOK_RWORD_UNSIZED:
+ default:
+ if( !(TOK_RWORD_PUB <= tok.type() && tok.type() <= TOK_RWORD_UNSIZED) )
+ throw ParseError::Unexpected(lex, tok);
case TOK_IDENT: {
auto name = tok.type() == TOK_IDENT ? tok.istr() : RcString::new_interned(FMT(tok));
GET_CHECK_TOK(tok, lex, TOK_COLON);
@@ -123,8 +125,6 @@ public:
throw ParseError::Unexpected(lex, tok);
}
break; }
- default:
- throw ParseError::Unexpected(lex, tok);
}
break;
case TOK_EOF:
diff --git a/src/mir/from_hir.cpp b/src/mir/from_hir.cpp
index 4ab1bf00..697f8141 100644
--- a/src/mir/from_hir.cpp
+++ b/src/mir/from_hir.cpp
@@ -19,6 +19,7 @@
#include <mir/visit_crate_mir.hpp>
#include <hir/expr_state.hpp>
#include <trans/target.hpp> // Target_GetSizeAndAlignOf - for `box`
+#include <cctype> // isdigit
namespace {
diff --git a/src/mir/mir.cpp b/src/mir/mir.cpp
index 8e3045d6..a0def040 100644
--- a/src/mir/mir.cpp
+++ b/src/mir/mir.cpp
@@ -6,6 +6,7 @@
* - MIR (Middle Intermediate Representation) definitions
*/
#include <mir/mir.hpp>
+#include <algorithm> // std::min
namespace MIR {
::std::ostream& operator<<(::std::ostream& os, const Constant& v) {
diff --git a/src/mir/mir.hpp b/src/mir/mir.hpp
index f3d61dfa..99698134 100644
--- a/src/mir/mir.hpp
+++ b/src/mir/mir.hpp
@@ -655,7 +655,7 @@ public:
~EnumCachePtr();
EnumCachePtr(EnumCachePtr&& x): p(x.p) { x.p = nullptr; }
EnumCachePtr& operator=(EnumCachePtr&& x) { this->~EnumCachePtr(); p = x.p; x.p = nullptr; return *this; }
- operator bool() { return p; }
+ operator bool() { return p != nullptr; }
const EnumCache& operator*() const { return *p; }
const EnumCache* operator->() const { return p; }
};
diff --git a/src/rc_string.cpp b/src/rc_string.cpp
index 38f6b15d..260ba90a 100644
--- a/src/rc_string.cpp
+++ b/src/rc_string.cpp
@@ -9,6 +9,7 @@
#include <cstring>
#include <string>
#include <iostream>
+#include <algorithm> // std::max
RcString::RcString(const char* s, unsigned int len):
m_ptr(nullptr)