editor folder reorganization

This commit is contained in:
Anton-4 2021-01-01 15:02:31 +01:00
parent c420893fe2
commit df5661541c
28 changed files with 93 additions and 92 deletions

View file

@ -1,8 +1,7 @@
// Adapted from https://github.com/sotrh/learn-wgpu
// by Benjamin Hansen, licensed under the MIT license
use crate::rect::Rect;
use crate::util::size_of_slice;
use crate::vertex::Vertex;
use crate::graphics::lowlevel::vertex::Vertex;
use crate::graphics::primitives::rect::Rect;
use bumpalo::collections::Vec as BumpVec;
use wgpu::util::{BufferInitDescriptor, DeviceExt};
@ -149,3 +148,9 @@ impl StagingBuffer {
encoder.copy_buffer_to_buffer(&self.buffer, 0, other, 0, self.size)
}
}
// Taken from https://github.com/sotrh/learn-wgpu
// by Benjamin Hansen, licensed under the MIT license
pub fn size_of_slice<T: Sized>(slice: &[T]) -> usize {
std::mem::size_of::<T>() * slice.len()
}

View file

@ -0,0 +1,3 @@
pub mod buffer;
pub mod ortho;
pub mod vertex;

View file

@ -0,0 +1,3 @@
pub mod colors;
pub mod lowlevel;
pub mod primitives;

View file

@ -0,0 +1,2 @@
pub mod rect;
pub mod text;

View file

@ -1,7 +1,7 @@
// Adapted from https://github.com/sotrh/learn-wgpu
// by Benjamin Hansen, licensed under the MIT license
use crate::rect::Rect;
use crate::graphics::primitives::rect::Rect;
use ab_glyph::{FontArc, Glyph, InvalidFont};
use cgmath::{Vector2, Vector4};
use itertools::Itertools;
@ -108,13 +108,7 @@ pub fn build_glyph_brush(
gpu_device: &wgpu::Device,
render_format: wgpu::TextureFormat,
) -> Result<GlyphBrush<()>, InvalidFont> {
let inconsolata = FontArc::try_from_slice(include_bytes!("../Inconsolata-Regular.ttf"))?;
let inconsolata = FontArc::try_from_slice(include_bytes!("../../../Inconsolata-Regular.ttf"))?;
Ok(GlyphBrushBuilder::using_font(inconsolata).build(&gpu_device, render_format))
}
pub fn is_newline(char_ref: &char) -> bool {
let newline_codes = vec!['\u{d}'];
newline_codes.contains(char_ref)
}

View file

@ -1,6 +1,6 @@
use crate::pattern::{Pattern2, PatternId};
use crate::pool::{NodeId, PoolStr, PoolVec, ShallowClone};
use crate::types::{Type2, TypeId};
use crate::lang::pattern::{Pattern2, PatternId};
use crate::lang::pool::{NodeId, PoolStr, PoolVec, ShallowClone};
use crate::lang::types::{Type2, TypeId};
use arraystring::{typenum::U30, ArrayString};
use roc_can::expr::Recursive;
use roc_module::low_level::LowLevel;
@ -298,7 +298,7 @@ pub type ExprId = NodeId<Expr2>;
#[test]
fn size_of_expr() {
assert_eq!(std::mem::size_of::<Expr2>(), crate::pool::NODE_BYTES);
assert_eq!(std::mem::size_of::<Expr2>(), crate::lang::pool::NODE_BYTES);
}
impl ShallowClone for Rigids {

View file

@ -12,15 +12,15 @@
// };
// use crate::pattern::{bindings_from_patterns, canonicalize_pattern, Pattern};
// use crate::procedure::References;
use crate::ast::{Expr2, FunctionDef, Rigids, ValueDef};
use crate::expr::Output;
use crate::expr::{to_expr2, to_expr_id, Env};
use crate::pattern::{
use crate::lang::ast::{Expr2, FunctionDef, Rigids, ValueDef};
use crate::lang::expr::Output;
use crate::lang::expr::{to_expr2, to_expr_id, Env};
use crate::lang::pattern::{
symbols_and_variables_from_pattern, symbols_from_pattern, to_pattern_id, Pattern2, PatternId,
};
use crate::pool::{NodeId, Pool, PoolStr, PoolVec, ShallowClone};
use crate::scope::Scope;
use crate::types::{to_annotation2, Alias, Annotation2, Signature, Type2, TypeId};
use crate::lang::pool::{NodeId, Pool, PoolStr, PoolVec, ShallowClone};
use crate::lang::scope::Scope;
use crate::lang::types::{to_annotation2, Alias, Annotation2, Signature, Type2, TypeId};
use roc_collections::all::{default_hasher, ImMap, MutMap, MutSet, SendMap};
use roc_module::ident::Lowercase;
use roc_module::symbol::Symbol;
@ -35,10 +35,7 @@ use ven_graph::{strongly_connected_components, topological_sort_into_groups};
#[derive(Debug)]
pub enum Def {
AnnotationOnly {
rigids: crate::ast::Rigids,
annotation: TypeId,
},
AnnotationOnly { rigids: Rigids, annotation: TypeId },
Value(ValueDef),
Function(FunctionDef),
}
@ -127,7 +124,7 @@ fn to_pending_def<'a>(
match def {
Annotation(loc_pattern, loc_ann) => {
// This takes care of checking for shadowing and adding idents to scope.
let (output, loc_can_pattern) = crate::pattern::to_pattern_id(
let (output, loc_can_pattern) = crate::lang::pattern::to_pattern_id(
env,
scope,
pattern_type,
@ -142,7 +139,7 @@ fn to_pending_def<'a>(
}
Body(loc_pattern, loc_expr) => {
// This takes care of checking for shadowing and adding idents to scope.
let (output, loc_can_pattern) = crate::pattern::to_pattern_id(
let (output, loc_can_pattern) = crate::lang::pattern::to_pattern_id(
env,
scope,
pattern_type,

View file

@ -1,12 +1,12 @@
#![allow(clippy::all)]
#![allow(dead_code)]
#![allow(unused_imports)]
use crate::ast::{Expr2, ExprId, FloatVal, IntStyle, IntVal};
use crate::def::References;
use crate::pattern::to_pattern2;
use crate::pool::{NodeId, Pool, PoolStr, PoolVec, ShallowClone};
use crate::scope::Scope;
use crate::types::{Type2, TypeId};
use crate::lang::ast::{ClosureExtra, Expr2, ExprId, FloatVal, IntStyle, IntVal, WhenBranch};
use crate::lang::def::References;
use crate::lang::pattern::to_pattern2;
use crate::lang::pool::{NodeId, Pool, PoolStr, PoolVec, ShallowClone};
use crate::lang::scope::Scope;
use crate::lang::types::{Alias, Type2, TypeId};
use bumpalo::Bump;
use inlinable_string::InlinableString;
use roc_can::expr::Recursive;
@ -22,9 +22,9 @@ use roc_types::subs::{VarStore, Variable};
#[derive(Clone, Default, Debug, PartialEq)]
pub struct Output {
pub references: crate::def::References,
pub references: References,
pub tail_call: Option<Symbol>,
pub aliases: MutMap<Symbol, NodeId<crate::types::Alias>>,
pub aliases: MutMap<Symbol, NodeId<Alias>>,
pub non_closures: MutSet<Symbol>,
}
@ -216,7 +216,7 @@ pub fn to_expr_id<'a>(
scope: &mut Scope,
parse_expr: &'a roc_parse::ast::Expr<'a>,
region: Region,
) -> (crate::ast::ExprId, Output) {
) -> (ExprId, Output) {
let (expr, output) = to_expr2(env, scope, parse_expr, region);
(env.add(expr, region), output)
@ -227,7 +227,7 @@ pub fn to_expr2<'a>(
scope: &mut Scope,
parse_expr: &'a roc_parse::ast::Expr<'a>,
region: Region,
) -> (crate::ast::Expr2, self::Output) {
) -> (Expr2, self::Output) {
use roc_parse::ast::Expr::*;
match parse_expr {
Float(string) => {
@ -646,7 +646,7 @@ pub fn to_expr2<'a>(
let captured_symbols = PoolVec::new(captured_symbols.into_iter(), env.pool);
let extra = crate::ast::ClosureExtra {
let extra = ClosureExtra {
return_type: env.var_store.fresh(), // 4B
captured_symbols, // 8B
closure_type: env.var_store.fresh(), // 4B
@ -1091,7 +1091,7 @@ fn canonicalize_when_branch<'a>(
scope: &mut Scope,
branch: &'a roc_parse::ast::WhenBranch<'a>,
output: &mut Output,
) -> (crate::ast::WhenBranch, References) {
) -> (WhenBranch, References) {
let patterns = PoolVec::with_capacity(branch.patterns.len() as u32, env.pool);
let original_scope = scope;
@ -1149,7 +1149,7 @@ fn canonicalize_when_branch<'a>(
output.union(branch_output);
(
crate::ast::WhenBranch {
WhenBranch {
patterns,
body: value_id,
guard,

9
editor/src/lang/mod.rs Normal file
View file

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

View file

@ -2,14 +2,14 @@
#![allow(dead_code)]
#![allow(unused_imports)]
#![allow(unused_variables)]
use crate::ast::{FunctionDef, ValueDef};
use crate::def::{canonicalize_defs, sort_can_defs, Declaration, Def};
use crate::expr::Env;
use crate::expr::Output;
use crate::pattern::Pattern2;
use crate::pool::{NodeId, Pool, PoolStr, PoolVec, ShallowClone};
use crate::scope::Scope;
use crate::types::Alias;
use crate::lang::ast::{FunctionDef, ValueDef};
use crate::lang::def::{canonicalize_defs, sort_can_defs, Declaration, Def};
use crate::lang::expr::Env;
use crate::lang::expr::Output;
use crate::lang::pattern::Pattern2;
use crate::lang::pool::{NodeId, Pool, PoolStr, PoolVec, ShallowClone};
use crate::lang::scope::Scope;
use crate::lang::types::Alias;
use bumpalo::Bump;
use roc_can::operator::desugar_def;
use roc_collections::all::{default_hasher, ImMap, ImSet, MutMap, MutSet, SendMap};
@ -176,7 +176,7 @@ pub fn canonicalize_module_defs<'a>(
match sort_can_defs(&mut env, defs, Output::default()) {
(Ok(mut declarations), output) => {
use crate::def::Declaration::*;
use Declaration::*;
for decl in declarations.iter() {
match decl {

View file

@ -1,10 +1,10 @@
#![allow(clippy::all)]
#![allow(dead_code)]
#![allow(unused_imports)]
use crate::ast::{ExprId, FloatVal, IntVal};
use crate::expr::{to_expr_id, Env, Output};
use crate::pool::{NodeId, Pool, PoolStr, PoolVec, ShallowClone};
use crate::scope::Scope;
use crate::lang::ast::{ExprId, FloatVal, IntVal};
use crate::lang::expr::{to_expr_id, Env, Output};
use crate::lang::pool::{NodeId, Pool, PoolStr, PoolVec, ShallowClone};
use crate::lang::scope::Scope;
use roc_can::expr::unescape_char;
use roc_can::num::{finish_parsing_base, finish_parsing_float, finish_parsing_int};
use roc_module::symbol::Symbol;

View file

@ -1,8 +1,8 @@
#![allow(clippy::all)]
#![allow(dead_code)]
#![allow(unused_imports)]
use crate::pool::{Pool, PoolStr, PoolVec, ShallowClone};
use crate::types::{Alias, TypeId};
use crate::lang::pool::{Pool, PoolStr, PoolVec, ShallowClone};
use crate::lang::types::{Alias, TypeId};
use roc_collections::all::{MutMap, MutSet};
use roc_module::ident::{Ident, Lowercase};
use roc_module::symbol::{IdentIds, ModuleId, Symbol};

View file

@ -1,9 +1,9 @@
#![allow(clippy::all)]
#![allow(dead_code)]
#![allow(unused_imports)]
use crate::expr::Env;
use crate::pool::{NodeId, Pool, PoolStr, PoolVec, ShallowClone};
use crate::scope::Scope;
use crate::lang::expr::Env;
use crate::lang::pool::{NodeId, Pool, PoolStr, PoolVec, ShallowClone};
use crate::lang::scope::Scope;
// use roc_can::expr::Output;
use roc_collections::all::{MutMap, MutSet};
use roc_module::ident::{Ident, TagName};

View file

@ -8,14 +8,15 @@
// See this link to learn wgpu: https://sotrh.github.io/learn-wgpu/
use crate::buffer::create_rect_buffers;
use crate::error::print_err;
use crate::ortho::{init_ortho, update_ortho_buffer, OrthoResources};
use crate::rect::Rect;
use crate::graphics::lowlevel::buffer::create_rect_buffers;
use crate::graphics::lowlevel::ortho::{init_ortho, update_ortho_buffer, OrthoResources};
use crate::graphics::lowlevel::vertex::Vertex;
use crate::graphics::primitives::rect::Rect;
use crate::graphics::primitives::text::{build_glyph_brush, queue_text_draw, Text};
use crate::selection::create_selection_rects;
use crate::tea::{model, update};
use crate::text::{build_glyph_brush, is_newline, Text};
use crate::vertex::Vertex;
use crate::util::is_newline;
use bumpalo::Bump;
use model::Position;
use std::error::Error;
@ -26,27 +27,14 @@ use winit::event;
use winit::event::{Event, ModifiersState};
use winit::event_loop::ControlFlow;
pub mod ast;
mod buffer;
mod colors;
mod def;
pub mod error;
pub mod expr;
pub mod file;
pub mod graphics;
mod keyboard_input;
mod module;
mod ortho;
mod pattern;
pub mod pool;
mod rect;
mod scope;
pub mod lang;
mod selection;
mod tea;
pub mod text;
mod types;
mod util;
mod vec_result;
mod vertex;
/// The editor is actually launched from the CLI if you pass it zero arguments,
/// or if you provide it 1 or more files or directories to open on launch.
@ -315,8 +303,8 @@ fn make_rect_pipeline(
&pipeline_layout,
swap_chain_descr.format,
&[Vertex::DESC],
wgpu::include_spirv!("shaders/rect.vert.spv"),
wgpu::include_spirv!("shaders/rect.frag.spv"),
wgpu::include_spirv!("graphics/shaders/rect.vert.spv"),
wgpu::include_spirv!("graphics/shaders/rect.frag.spv"),
);
(pipeline, ortho)
@ -399,11 +387,11 @@ fn queue_all_text(
..Default::default()
};
text::queue_text_draw(&main_label, glyph_brush);
queue_text_draw(&main_label, glyph_brush);
text::queue_text_draw(&caret_pos_label, glyph_brush);
queue_text_draw(&caret_pos_label, glyph_brush);
text::queue_text_draw(&code_text, glyph_brush)
queue_text_draw(&code_text, glyph_brush)
}
fn update_text_state(ed_model: &mut model::Model, received_char: &char) {

View file

@ -1,6 +1,6 @@
use crate::colors;
use crate::error::{EdResult, InvalidSelection};
use crate::rect::Rect;
use crate::graphics::colors;
use crate::graphics::primitives::rect::Rect;
use crate::tea::model::RawSelection;
use crate::vec_result::get_res;
use bumpalo::collections::Vec as BumpVec;

View file

@ -1,5 +1,5 @@
use crate::tea::model::{Position, RawSelection};
use crate::text::is_newline;
use crate::util::is_newline;
use std::cmp::{max, min};
pub fn move_caret_left(

View file

@ -1,5 +1,5 @@
// Taken from https://github.com/sotrh/learn-wgpu
// by Benjamin Hansen, licensed under the MIT license
pub fn size_of_slice<T: Sized>(slice: &[T]) -> usize {
std::mem::size_of::<T>() * slice.len()
pub fn is_newline(char_ref: &char) -> bool {
let newline_codes = vec!['\u{d}'];
newline_codes.contains(char_ref)
}

View file

@ -6,7 +6,7 @@ extern crate indoc;
#[cfg(test)]
mod test_file {
use bumpalo::Bump;
use roc_editor::file::File;
use roc_editor::lang::file::File;
use std::path::Path;
#[test]