get basic wiring of a value through the compiler

This commit is contained in:
Brendan Hansknecht 2023-03-22 22:26:02 -07:00
parent 5354637cec
commit f4411afbbc
No known key found for this signature in database
GPG key ID: 0EA784685083E75B
8 changed files with 22 additions and 5 deletions

View file

@ -729,6 +729,9 @@ pub fn canonicalize_expr<'a>(
ast::Expr::Str(literal) => flatten_str_literal(env, var_store, scope, literal),
// TODO: is this where we should finally load the file?
ast::Expr::IngestedFile(literal) => flatten_str_literal(env, var_store, scope, literal),
ast::Expr::SingleQuote(string) => {
let mut it = string.chars().peekable();
if let Some(char) = it.next() {

View file

@ -138,6 +138,7 @@ pub fn desugar_expr<'a>(arena: &'a Bump, loc_expr: &'a Loc<Expr<'a>>) -> &'a Loc
| PrecedenceConflict { .. }
| Tag(_)
| OpaqueRef(_)
| IngestedFile(_)
| Crash => loc_expr,
TupleAccess(sub_expr, paths) => {

View file

@ -44,6 +44,7 @@ impl<'a> Formattable for Expr<'a> {
| MalformedClosure
| Tag(_)
| OpaqueRef(_)
| IngestedFile(_)
| Crash => false,
// These expressions always have newlines
@ -477,6 +478,7 @@ impl<'a> Formattable for Expr<'a> {
}
MalformedClosure => {}
PrecedenceConflict { .. } => {}
IngestedFile(_) => {}
}
}
}

View file

@ -658,6 +658,7 @@ impl<'a> RemoveSpaces<'a> for Expr<'a> {
is_negative,
},
Expr::Str(a) => Expr::Str(a.remove_spaces(arena)),
Expr::IngestedFile(a) => Expr::Str(a.remove_spaces(arena)),
Expr::RecordAccess(a, b) => Expr::RecordAccess(arena.alloc(a.remove_spaces(arena)), b),
Expr::AccessorFunction(a) => Expr::AccessorFunction(a),
Expr::TupleAccess(a, b) => Expr::TupleAccess(arena.alloc(a.remove_spaces(arena)), b),

View file

@ -5582,7 +5582,7 @@ fn parse<'a>(arena: &'a Bump, header: ModuleHeader<'a>) -> Result<Msg<'a>, Loadi
let parse_start = Instant::now();
let source = header.parse_state.original_bytes();
let parse_state = header.parse_state;
let parsed_defs = match module_defs().parse(arena, parse_state.clone(), 0) {
let mut parsed_defs = match module_defs().parse(arena, parse_state.clone(), 0) {
Ok((_, success, _state)) => success,
Err((_, fail)) => {
return Err(LoadingProblem::ParsingFailed(
@ -5590,6 +5590,10 @@ fn parse<'a>(arena: &'a Bump, header: ModuleHeader<'a>) -> Result<Msg<'a>, Loadi
));
}
};
for value in header.defined_values.into_iter() {
// TODO: should these have a region?
parsed_defs.push_value_def(value, Region::zero(), &[], &[]);
}
// Record the parse end time once, to avoid checking the time a second time
// immediately afterward (for the beginning of canonicalization).
@ -5691,8 +5695,7 @@ fn value_def_from_imports<'a>(
ann_type: arena.alloc(typed_ident.ann),
comment: None,
body_pattern: ident,
// This should load the file, not just use the file name.
body_expr: arena.alloc(entry.with_value(Expr::Str(file_name.to_owned()))),
body_expr: arena.alloc(entry.with_value(Expr::IngestedFile(file_name.to_owned()))),
})
}
}

View file

@ -263,6 +263,9 @@ pub enum Expr<'a> {
Tuple(Collection<'a, &'a Loc<Expr<'a>>>),
// The name of a file to be ingested directly into a variable.
IngestedFile(StrLiteral<'a>),
// Lookups
Var {
module_name: &'a str, // module_name will only be filled if the original Roc code stated something like `5 + SomeModule.myVar`, module_name will be blank if it was `5 + myVar`
@ -1469,6 +1472,9 @@ impl<'a> Malformed for Expr<'a> {
Str(inner) => inner.is_malformed(),
// TODO: what is the scope of Malformed? Would this not being a real file make it malformed?
IngestedFile(inner) => inner.is_malformed(),
RecordAccess(inner, _) |
TupleAccess(inner, _) => inner.is_malformed(),

View file

@ -1906,7 +1906,8 @@ fn expr_to_pattern_help<'a>(arena: &'a Bump, expr: &Expr<'a>) -> Result<Pattern<
is_negative,
},
// These would not have parsed as patterns
Expr::AccessorFunction(_)
Expr::IngestedFile(_)
| Expr::AccessorFunction(_)
| Expr::RecordAccess(_, _)
| Expr::TupleAccess(_, _)
| Expr::List { .. }

View file

@ -4,4 +4,4 @@ app "helloWorld"
provides [main] to pf
main =
Stdout.line "Hello, World!"
Stdout.line file