aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-compile-expr.h
diff options
context:
space:
mode:
authorSimplyTheOther <simplytheother@gmail.com>2021-01-08 15:09:08 +0800
committerSimplyTheOther <simplytheother@gmail.com>2021-01-08 15:09:08 +0800
commit238a31b33f79cddfaa40c5fd748495a5f2b34630 (patch)
treebc217d37b5e3ee41b0a69265341945389d1f4dfb /gcc/rust/backend/rust-compile-expr.h
parentb5f86dca7e6b53ca3701ef01ae36070a760dff78 (diff)
parentaf04ea2222b6407fb3e83759ae332d600495380c (diff)
downloadgcc-238a31b33f79cddfaa40c5fd748495a5f2b34630.zip
gcc-238a31b33f79cddfaa40c5fd748495a5f2b34630.tar.gz
gcc-238a31b33f79cddfaa40c5fd748495a5f2b34630.tar.bz2
Merge branch 'master' of https://github.com/redbrain/gccrs
Diffstat (limited to 'gcc/rust/backend/rust-compile-expr.h')
-rw-r--r--gcc/rust/backend/rust-compile-expr.h57
1 files changed, 56 insertions, 1 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h
index 5c3206a..9081000 100644
--- a/gcc/rust/backend/rust-compile-expr.h
+++ b/gcc/rust/backend/rust-compile-expr.h
@@ -23,6 +23,7 @@
#include "rust-compile-tyty.h"
#include "rust-compile-resolve-path.h"
#include "rust-compile-block.h"
+#include "rust-compile-struct-field-expr.h"
namespace Rust {
namespace Compile {
@@ -56,7 +57,7 @@ public:
void visit (HIR::CallExpr &expr)
{
- Bexpression *fn = ResolvePath::Compile (expr.get_fnexpr (), ctx);
+ Bexpression *fn = ResolvePathRef::Compile (expr.get_fnexpr (), ctx);
rust_assert (fn != nullptr);
std::vector<Bexpression *> args;
@@ -105,6 +106,11 @@ public:
return;
}
+ // this could be a constant reference
+ if (ctx->lookup_const_decl (ref, &translated))
+ return;
+
+ // must be an identifier
Bvariable *var = nullptr;
if (!ctx->lookup_var_decl (ref, &var))
{
@@ -149,6 +155,36 @@ public:
}
return;
+ case HIR::Literal::FLOAT: {
+ printf ("FLOATY BOYO: [%s]\n", expr.as_string ().c_str ());
+
+ mpfr_t fval;
+ if (mpfr_init_set_str (fval, expr.as_string ().c_str (), 10,
+ MPFR_RNDN)
+ != 0)
+ {
+ rust_fatal_error (expr.get_locus (),
+ "bad float number in literal");
+ return;
+ }
+
+ TyTy::TyBase *tyty = nullptr;
+ if (!ctx->get_tyctx ()->lookup_type (
+ expr.get_mappings ().get_hirid (), &tyty))
+ {
+ rust_fatal_error (expr.get_locus (),
+ "did not resolve type for this literal expr");
+ return;
+ }
+
+ printf ("tyty float is [%s]\n", tyty->as_string ().c_str ());
+
+ Btype *type = TyTyResolveCompile::compile (ctx, tyty);
+ translated
+ = ctx->get_backend ()->float_constant_expression (type, fval);
+ }
+ return;
+
default:
rust_fatal_error (expr.get_locus (), "unknown literal");
return;
@@ -350,6 +386,25 @@ public:
ctx->add_statement (block_stmt);
}
+ void visit (HIR::StructExprStructFields &struct_expr)
+ {
+ Btype *type
+ = ResolvePathType::Compile (&struct_expr.get_struct_name (), ctx);
+
+ // this assumes all fields are in order from type resolution and if a base
+ // struct was specified those fields are filed via accesors
+ std::vector<Bexpression *> vals;
+ struct_expr.iterate ([&] (HIR::StructExprField *field) mutable -> bool {
+ Bexpression *expr = CompileStructExprField::Compile (field, ctx);
+ vals.push_back (expr);
+ return true;
+ });
+
+ translated
+ = ctx->get_backend ()->constructor_expression (type, vals,
+ struct_expr.get_locus ());
+ }
+
private:
CompileExpr (Context *ctx) : HIRCompileBase (ctx), translated (nullptr) {}