Merge branch 'trunk' of /rtfeldman/roc into copy_paste

This commit is contained in:
Anton-4 2021-01-30 12:30:18 +01:00
commit c9dca76222
6 changed files with 137 additions and 43 deletions

View file

@ -16,6 +16,10 @@ use roc_module::low_level::LowLevel;
use roc_module::operator::CalledVia;
use roc_module::symbol::{IdentIds, ModuleId, ModuleIds, Symbol};
use roc_parse::ast::StrLiteral;
use roc_parse::ast::{self, Attempting};
use roc_parse::blankspace::space0_before;
use roc_parse::expr::expr;
use roc_parse::parser::{loc, Fail, Parser, State};
use roc_problem::can::{Problem, RuntimeError};
use roc_region::all::{Located, Region};
use roc_types::subs::{VarStore, Variable};
@ -222,6 +226,23 @@ pub fn to_expr_id<'a>(
(env.add(expr, region), output)
}
pub fn str_to_expr2<'a>(
arena: &'a Bump,
input: &'a str,
env: &mut Env<'a>,
scope: &mut Scope,
region: Region,
) -> Result<(Expr2, self::Output), Fail> {
let state = State::new(input.trim().as_bytes(), Attempting::Module);
let parser = space0_before(loc(expr(0)), 0);
let parse_res = parser.parse(&arena, state);
parse_res
.map(|(loc_expr, _)| arena.alloc(loc_expr.value))
.map(|loc_expr_val_ref| to_expr2(env, scope, loc_expr_val_ref, region))
.map_err(|(fail, _)| fail)
}
pub fn to_expr2<'a>(
env: &mut Env<'a>,
scope: &mut Scope,

View file

@ -1,9 +1,9 @@
pub mod ast;
mod def;
mod expr;
pub mod expr;
mod module;
mod pattern;
mod pool;
pub mod pool;
pub mod roc_file;
mod scope;
pub mod scope;
mod types;

View file

@ -8,9 +8,16 @@ use roc_module::ident::{Ident, Lowercase};
use roc_module::symbol::{IdentIds, ModuleId, Symbol};
use roc_problem::can::RuntimeError;
use roc_region::all::{Located, Region};
use roc_types::subs::{VarStore, Variable};
use roc_types::{
solved_types::{FreeVars, SolvedType},
subs::{VarStore, Variable},
};
fn solved_type_to_type_id() -> TypeId {
fn solved_type_to_type_id(
_solved_type: &SolvedType,
_free_vars: &mut FreeVars,
_var_store: &mut VarStore,
) -> TypeId {
todo!()
}
@ -33,45 +40,45 @@ pub struct Scope {
}
impl Scope {
pub fn new(home: ModuleId, pool: &mut Pool, _var_store: &mut VarStore) -> Scope {
pub fn new(home: ModuleId, _pool: &mut Pool, _var_store: &mut VarStore) -> Scope {
use roc_types::solved_types::{BuiltinAlias, FreeVars};
let solved_aliases = roc_types::builtin_aliases::aliases();
let mut aliases = MutMap::default();
let _solved_aliases = roc_types::builtin_aliases::aliases();
let aliases = MutMap::default();
for (symbol, builtin_alias) in solved_aliases {
// let BuiltinAlias { region, vars, typ } = builtin_alias;
let BuiltinAlias { vars, .. } = builtin_alias;
// for (symbol, builtin_alias) in solved_aliases {
// // let BuiltinAlias { region, vars, typ } = builtin_alias;
// let BuiltinAlias { vars, typ, .. } = builtin_alias;
let free_vars = FreeVars::default();
let typ = solved_type_to_type_id();
// roc_types::solved_types::to_type(&typ, &mut free_vars, var_store);
// let mut free_vars = FreeVars::default();
// let typ = solved_type_to_type_id(&typ, &mut free_vars, var_store);
// // roc_types::solved_types::to_type(&typ, &mut free_vars, var_store);
// make sure to sort these variables to make them line up with the type arguments
let mut type_variables: Vec<_> = free_vars.unnamed_vars.into_iter().collect();
type_variables.sort();
// // make sure to sort these variables to make them line up with the type arguments
// let mut type_variables: Vec<_> = free_vars.unnamed_vars.into_iter().collect();
// type_variables.sort();
debug_assert_eq!(vars.len(), type_variables.len());
let variables = PoolVec::with_capacity(vars.len() as u32, pool);
// debug_assert_eq!(vars.len(), type_variables.len());
// let variables = PoolVec::with_capacity(vars.len() as u32, pool);
let it = variables
.iter_node_ids()
.zip(vars.iter())
.zip(type_variables);
for ((node_id, loc_name), (_, var)) in it {
// TODO region is ignored, but "fake" anyway. How to resolve?
let name = PoolStr::new(loc_name.value.as_str(), pool);
pool[node_id] = (name, var);
}
// let it = variables
// .iter_node_ids()
// .zip(vars.iter())
// .zip(type_variables);
// for ((node_id, loc_name), (_, var)) in it {
// // TODO region is ignored, but "fake" anyway. How to resolve?
// let name = PoolStr::new(loc_name.value.as_str(), pool);
// pool[node_id] = (name, var);
// }
let alias = Alias {
actual: typ,
/// We know that builtin aliases have no hiddden variables (e.g. in closures)
hidden_variables: PoolVec::empty(pool),
targs: variables,
};
// let alias = Alias {
// actual: typ,
// /// We know that builtin aliases have no hiddden variables (e.g. in closures)
// hidden_variables: PoolVec::empty(pool),
// targs: variables,
// };
aliases.insert(symbol, alias);
}
// aliases.insert(symbol, alias);
// }
let idents = Symbol::default_in_scope();
let idents: MutMap<_, _> = idents.into_iter().collect();

View file

@ -25,13 +25,18 @@ use crate::graphics::style::CODE_FONT_SIZE;
use crate::graphics::style::CODE_TXT_XY;
use crate::mvc::app_model::AppModel;
use crate::mvc::ed_model::EdModel;
use crate::mvc::{app_update, ed_model, ed_view};
use crate::resources::strings::NOTHING_OPENED;
use crate::mvc::{ed_model, ed_view, app_update};
//use crate::resources::strings::NOTHING_OPENED;
use crate::vec_result::get_res;
use bumpalo::Bump;
use cgmath::Vector2;
use ed_model::Position;
use lang::{ast::Expr2, pool::Pool, scope::Scope};
use pipelines::RectResources;
use roc_collections::all::MutMap;
use roc_module::symbol::{IdentIds, ModuleIds};
use roc_region::all::Region;
use roc_types::subs::VarStore;
use std::error::Error;
use std::io;
use std::path::Path;
@ -269,7 +274,35 @@ fn run_event_loop(file_path_opt: Option<&Path>) -> Result<(), Box<dyn Error>> {
&mut glyph_brush,
);
} else {
queue_no_file_text(&size, NOTHING_OPENED, CODE_TXT_XY.into(), &mut glyph_brush);
// queue_no_file_text(&size, NOTHING_OPENED, CODE_TXT_XY.into(), &mut glyph_brush);
let mut pool = Pool::with_capacity(12);
let mut var_store = VarStore::default();
let dep_idents = MutMap::default();
let mut module_ids = ModuleIds::default();
let exposed_ident_ids = IdentIds::default();
let home = module_ids.get_or_insert(&"Home".into());
let mut env = crate::lang::expr::Env::new(
home,
&arena,
&mut pool,
&mut var_store,
dep_idents,
&module_ids,
exposed_ident_ids,
);
let mut scope = Scope::new(home, env.pool, env.var_store);
let region = Region::new(0, 0, 0, 0);
let (ast, _) =
crate::lang::expr::str_to_expr2(&arena, "1", &mut env, &mut scope, region)
.unwrap();
render_node(&size, &ast, CODE_TXT_XY.into(), &mut glyph_brush);
}
match draw_all_rects(
@ -368,6 +401,39 @@ fn begin_render_pass<'a>(
})
}
fn render_node(
size: &PhysicalSize<u32>,
ast: &Expr2,
position: Vector2<f32>,
glyph_brush: &mut GlyphBrush<()>,
) {
use Expr2::*;
let area_bounds = (size.width as f32, size.height as f32).into();
match ast {
SmallInt {
number,
..
// text,
// style, pretending always decimal for now
// var,
} => {
let code_text = Text {
position,
area_bounds,
color: CODE_COLOR.into(),
text: format!("{:?}", number),
size: CODE_FONT_SIZE,
..Default::default()
};
queue_code_text_draw(&code_text, glyph_brush);
}
rest => panic!("implement {:?} render", rest)
};
}
// returns bounding boxes for every glyph
fn queue_editor_text(
size: &PhysicalSize<u32>,
@ -401,7 +467,7 @@ fn queue_editor_text(
queue_code_text_draw(&code_text, glyph_brush);
}
fn queue_no_file_text(
fn _queue_no_file_text(
size: &PhysicalSize<u32>,
text: &str,
text_coords: Vector2<f32>,

View file

@ -1 +1 @@
pub const NOTHING_OPENED: &str = "Execute `cargo run edit <filename>` to open a file.";
// pub const NOTHING_OPENED: &str = "Execute `cargo run edit <filename>` to open a file.";

View file

@ -8,10 +8,10 @@ in with {
# Look here for information about how pin version of nixpkgs
# → https://nixos.wiki/wiki/FAQ/Pinning_Nixpkgs
pkgs = import (builtins.fetchGit {
name = "nixpkgs-2021-01-05";
name = "nixpkgs-2021-01-07";
url = "https://github.com/nixos/nixpkgs/";
ref = "refs/heads/nixpkgs-unstable";
rev = "f53c431645da8e6760268092aa10f736b5cfb117";
rev = "4a580eb51bce94cae356e841f3f5303d31afbaf1";
}) { };
isMacOS = currentOS == "darwin";