mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 06:44:46 +00:00
add Alias expression
This commit is contained in:
parent
c18bbe9a63
commit
dab00f2e2d
2 changed files with 8 additions and 1 deletions
|
@ -260,6 +260,7 @@ pub fn build_exp_expr<'a, 'ctx, 'env>(
|
||||||
|
|
||||||
match expr {
|
match expr {
|
||||||
Literal(literal) => build_exp_literal(env, layout_ids, scope, parent, literal),
|
Literal(literal) => build_exp_literal(env, layout_ids, scope, parent, literal),
|
||||||
|
Alias(symbol) => load_symbol(env, scope, symbol),
|
||||||
RunLowLevel(op, symbols) => {
|
RunLowLevel(op, symbols) => {
|
||||||
let mut args = Vec::with_capacity_in(symbols.len(), env.arena);
|
let mut args = Vec::with_capacity_in(symbols.len(), env.arena);
|
||||||
|
|
||||||
|
|
|
@ -384,6 +384,10 @@ pub enum CallType {
|
||||||
pub enum Expr<'a> {
|
pub enum Expr<'a> {
|
||||||
Literal(Literal<'a>),
|
Literal(Literal<'a>),
|
||||||
|
|
||||||
|
/// A symbol will alias this symbol
|
||||||
|
/// in the long term we should get rid of this using copy propagation
|
||||||
|
Alias(Symbol),
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
FunctionPointer(Symbol, Layout<'a>),
|
FunctionPointer(Symbol, Layout<'a>),
|
||||||
FunctionCall {
|
FunctionCall {
|
||||||
|
@ -465,6 +469,7 @@ impl<'a> Expr<'a> {
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
Literal(lit) => lit.to_doc(alloc, false),
|
Literal(lit) => lit.to_doc(alloc, false),
|
||||||
|
Alias(symbol) => alloc.text("alias ").append(symbol_to_doc(alloc, *symbol)),
|
||||||
|
|
||||||
FunctionPointer(symbol, _) => symbol_to_doc(alloc, *symbol),
|
FunctionPointer(symbol, _) => symbol_to_doc(alloc, *symbol),
|
||||||
|
|
||||||
|
@ -1927,7 +1932,7 @@ fn store_pattern<'a>(
|
||||||
env: &mut Env<'a, '_>,
|
env: &mut Env<'a, '_>,
|
||||||
can_pat: &Pattern<'a>,
|
can_pat: &Pattern<'a>,
|
||||||
outer_symbol: Symbol,
|
outer_symbol: Symbol,
|
||||||
_layout: Layout<'a>,
|
layout: Layout<'a>,
|
||||||
stored: &mut Vec<'a, (Symbol, Layout<'a>, Expr<'a>)>,
|
stored: &mut Vec<'a, (Symbol, Layout<'a>, Expr<'a>)>,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
use Pattern::*;
|
use Pattern::*;
|
||||||
|
@ -1935,6 +1940,7 @@ fn store_pattern<'a>(
|
||||||
match can_pat {
|
match can_pat {
|
||||||
Identifier(symbol) => {
|
Identifier(symbol) => {
|
||||||
// TODO surely something should happen here?
|
// TODO surely something should happen here?
|
||||||
|
stored.push((*symbol, layout, Expr::Alias(outer_symbol)));
|
||||||
}
|
}
|
||||||
Underscore => {
|
Underscore => {
|
||||||
// Since _ is never read, it's safe to reassign it.
|
// Since _ is never read, it's safe to reassign it.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue