diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-01-26 17:28:52 +0000 |
---|---|---|
committer | Philip Herron <herron.philip@googlemail.com> | 2021-01-27 10:42:43 +0000 |
commit | 244c2d2ea1a5a69ab6f7f50902512c1a7daa29c9 (patch) | |
tree | 6e7cd01cd95637ad9606570e5ee92d549bd85594 /gcc/rust/backend/rust-compile-expr.h | |
parent | 8578c61be5061fab91fe679a15fd68ab5fad987c (diff) | |
download | gcc-244c2d2ea1a5a69ab6f7f50902512c1a7daa29c9.zip gcc-244c2d2ea1a5a69ab6f7f50902512c1a7daa29c9.tar.gz gcc-244c2d2ea1a5a69ab6f7f50902512c1a7daa29c9.tar.bz2 |
Support binding functions to LetStmts.
This supports basic function pointers in rust most of the code was already
there to infer this but this has now helped tidy it up and make it work.
Fixes #184
Diffstat (limited to 'gcc/rust/backend/rust-compile-expr.h')
-rw-r--r-- | gcc/rust/backend/rust-compile-expr.h | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h index 7c2f32d..81d7786 100644 --- a/gcc/rust/backend/rust-compile-expr.h +++ b/gcc/rust/backend/rust-compile-expr.h @@ -127,20 +127,28 @@ public: return; } - // this could be a constant reference - if (ctx->lookup_const_decl (ref, &translated)) - return; - - // must be an identifier + Bfunction *fn = nullptr; Bvariable *var = nullptr; - if (!ctx->lookup_var_decl (ref, &var)) + if (ctx->lookup_const_decl (ref, &translated)) { - rust_fatal_error (expr.get_locus (), - "failed to lookup compiled variable"); return; } - - translated = ctx->get_backend ()->var_expression (var, expr.get_locus ()); + else if (ctx->lookup_function_decl (ref, &fn)) + { + translated + = ctx->get_backend ()->function_code_expression (fn, + expr.get_locus ()); + } + else if (ctx->lookup_var_decl (ref, &var)) + { + translated + = ctx->get_backend ()->var_expression (var, expr.get_locus ()); + } + else + { + rust_fatal_error (expr.get_locus (), + "failed to lookup compiled reference"); + } } void visit (HIR::LiteralExpr &expr) |