diff options
author | John Hodge <tpg@mutabah.net> | 2016-09-25 13:42:34 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-09-25 13:42:34 +0800 |
commit | a5be00d4761d314badc1dc4e9d0b63bb53eae07e (patch) | |
tree | 1eec4a8ad1abac79115ea74235d6c636e2e10830 /src | |
parent | 423327162381b78599ffee6d200198665deaff26 (diff) | |
download | mrust-a5be00d4761d314badc1dc4e9d0b63bb53eae07e.tar.gz |
HIR - Support float patterns
Diffstat (limited to 'src')
-rw-r--r-- | src/hir/from_ast.cpp | 19 | ||||
-rw-r--r-- | src/hir/pattern.cpp | 15 | ||||
-rw-r--r-- | src/hir/pattern.hpp | 9 | ||||
-rw-r--r-- | src/hir/visitor.cpp | 2 | ||||
-rw-r--r-- | src/hir_typeck/expr_cs.cpp | 7 |
5 files changed, 46 insertions, 6 deletions
diff --git a/src/hir/from_ast.cpp b/src/hir/from_ast.cpp index 17bbb2c3..e723d26b 100644 --- a/src/hir/from_ast.cpp +++ b/src/hir/from_ast.cpp @@ -361,6 +361,16 @@ BUG(sp, "Unknown type for integer literal in pattern - " << ct ); } } + static ::HIR::CoreType get_float_type(const Span& sp, const ::eCoreType ct) { + switch(ct) + { + case CORETYPE_ANY: return ::HIR::CoreType::Str; + case CORETYPE_F32: return ::HIR::CoreType::F32; + case CORETYPE_F64: return ::HIR::CoreType::F64; + default: + BUG(sp, "Unknown type for float literal in pattern - " << ct ); + } + } static ::HIR::Pattern::Value lowerhir_pattern_value(const Span& sp, const ::AST::Pattern::Value& v) { TU_MATCH(::AST::Pattern::Value, (v), (e), (Invalid, @@ -373,11 +383,10 @@ }); ), (Float, - TODO(sp, "Floating point patterns"); - //return ::HIR::Pattern::Value::make_Float({ - // H::get_int_type(sp, e.type), - // e.value - // }); + return ::HIR::Pattern::Value::make_Float({ + H::get_float_type(sp, e.type), + e.value + }); ), (String, return ::HIR::Pattern::Value::make_String(e); diff --git a/src/hir/pattern.cpp b/src/hir/pattern.cpp index c5c2ef93..a2c9ef27 100644 --- a/src/hir/pattern.cpp +++ b/src/hir/pattern.cpp @@ -1,10 +1,20 @@ - +/* + * MRustC - Rust Compiler + * - By John Hodge (Mutabah/thePowersGang) + * + * hir/pattern.cpp + * - HIR Representation of patterns + */ #include "pattern.hpp" namespace HIR { ::std::ostream& operator<<(::std::ostream& os, const Pattern::Value& x) { TU_MATCH(Pattern::Value, (x), (e), (Integer, + // TODO: Print with type (and signed-ness) + os << e.value; + ), + (Float, // TODO: Print with type os << e.value; ), @@ -147,6 +157,9 @@ namespace { (Integer, return ::HIR::Pattern::Value::make_Integer(e); ), + (Float, + return ::HIR::Pattern::Value::make_Float(e); + ), (String, return ::HIR::Pattern::Value::make_String(e); ), diff --git a/src/hir/pattern.hpp b/src/hir/pattern.hpp index 205acfcb..17f06a29 100644 --- a/src/hir/pattern.hpp +++ b/src/hir/pattern.hpp @@ -1,4 +1,9 @@ /* + * MRustC - Rust Compiler + * - By John Hodge (Mutabah/thePowersGang) + * + * hir/pattern.hpp + * - HIR Representation of patterns */ #pragma once @@ -50,6 +55,10 @@ struct Pattern enum ::HIR::CoreType type; // Str == _ uint64_t value; // Signed numbers are encoded as 2's complement }), + (Float, struct { + enum ::HIR::CoreType type; // Str == _ + double value; + }), (String, ::std::string), (Named, struct { Path path; diff --git a/src/hir/visitor.cpp b/src/hir/visitor.cpp index 96c3a1d1..55cc9e66 100644 --- a/src/hir/visitor.cpp +++ b/src/hir/visitor.cpp @@ -387,6 +387,8 @@ void ::HIR::Visitor::visit_pattern_val(::HIR::Pattern::Value& val) TU_MATCH(::HIR::Pattern::Value, (val), (e), (Integer, ), + (Float, + ), (String, ), (Named, diff --git a/src/hir_typeck/expr_cs.cpp b/src/hir_typeck/expr_cs.cpp index 9d412cba..670c52b9 100644 --- a/src/hir_typeck/expr_cs.cpp +++ b/src/hir_typeck/expr_cs.cpp @@ -2798,6 +2798,13 @@ void Context::add_binding(const Span& sp, ::HIR::Pattern& pat, const ::HIR::Type static void handle_value(Context& context, const Span& sp, const ::HIR::TypeRef& type, const ::HIR::Pattern::Value& val) { TU_MATCH(::HIR::Pattern::Value, (val), (v), (Integer, + // TODO: Apply an ivar bound? (Require that this ivar be an integer?) + if( v.type != ::HIR::CoreType::Str ) { + context.equate_types(sp, type, ::HIR::TypeRef(v.type)); + } + ), + (Float, + // TODO: Apply an ivar bound? (Require that this ivar be a float?) if( v.type != ::HIR::CoreType::Str ) { context.equate_types(sp, type, ::HIR::TypeRef(v.type)); } |