Compare commits
	
		
			No commits in common. "6e37e3a5dd9b8d7c60f5c7dac264808e79711be3" and "309149c7dde4f576998d811a236d007c9b9492cf" have entirely different histories.
		
	
	
		
			6e37e3a5dd
			...
			309149c7dd
		
	
		
| @ -16,8 +16,8 @@ pub enum Either<L, R> | |||||||
|     Right(R) |     Right(R) | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| pub impl Functor[*T] for Option<T> | pub inst Functor[*T] for Option<T> | ||||||
|     fn <U> map(ftu: fn (t: &*T) -> U) -> Self<U> |     impl fn <U> map(ftu: fn (t: T) -> U) -> Self<U> | ||||||
|         if self is Some(t) then |         if self is Some(t) then | ||||||
|             Some(ftu(t)) |             Some(ftu(t)) | ||||||
|         else |         else | ||||||
| @ -26,20 +26,20 @@ pub impl Functor[*T] for Option<T> | |||||||
|     end |     end | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| pub impl Functor[*R] for Either<_, *R> | pub inst Functor[*T] for Either<_, *T> | ||||||
|     fn <U> map(f: fn (t: &*R) -> U) -> Self<_, U> |     impl fn <U> map(ftu: fn (t: *T) -> U) -> Self<U> | ||||||
|         if self is Right(t) then |         if self is Right(t) then | ||||||
|             Right(f(t)) |             Right(ftu(t)) | ||||||
|         else |         else | ||||||
|             self |             self | ||||||
|         end |         end | ||||||
|     end |     end | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| pub impl Functor[*L -> *R] for Either<L, R> | pub inst Functor[*L -> *R] for Either<L, R> | ||||||
|     fn mapLeft(f: fn (l: &*L) -> *R) -> Self<*L, *R> |     impl fn mapLeft(flr: fn (l: *L) -> *R) -> Self<*L, *R> | ||||||
|         if self is Left(l) then |         if self is Left(l) then | ||||||
|             Right(f(l)) |             Right(flr(l)) | ||||||
|         else |         else | ||||||
|             self |             self | ||||||
|         end |         end | ||||||
| @ -48,94 +48,46 @@ end | |||||||
| 
 | 
 | ||||||
| pub trait Monad[*T] | pub trait Monad[*T] | ||||||
|     static fn lift(t: *T) -> Self<*T> |     static fn lift(t: *T) -> Self<*T> | ||||||
|     fn <U> flatMap(f: fn (t: &*T) -> Self<U>) -> Self<U> |     fn <U> flatMap(f: fn (t: *T) -> Self<U>) -> Self<U> | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| pub trait Default | pub trait Default | ||||||
|     static fn default() -> Self |     static fn default() -> Self | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| pub trait Empty[*T] | pub trait Empty[*T] where *T has Default | ||||||
|     static fn empty() -> Self<*T> |     static fn empty() -> Self<*T> | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| pub trait Semigroup[*T] | pub trait Semigroup[*T] | ||||||
|     type Other<*T> |     fn concat(other: &Self<*T>) -> Self<&*T> | ||||||
| 
 |     cons fn consConcat(other: Self<*T>) -> Self<*T> | ||||||
|     fn concat(other: &Other<*T>) -> Self<&*T> |  | ||||||
|     cons fn consConcat(other: Other<*T>) -> Self<*T> |  | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| pub int Iterable<T> | pub int Iterable<T> | ||||||
|     fn iter() -> Iterator<T> ref self |     fn iter() -> Iterator<T> | ||||||
|     cons fn consIter() -> ConsIterator<T> |     cons fn consIter() -> ConsIterator<T> | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| pub int Iterator<T> | pub int Iterator<T> | ||||||
|     fn next() -> Option<&T ref self> |     fn next() -> Option<&T> | ||||||
|  |     fn withIndex() -> Iterator<Option<(Int, &T)>> | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| pub int ConsIterator<T> | pub int ConsIterator<T> | ||||||
|     fn next() -> Option<T> |     fn next() -> Option<T> | ||||||
|  |     fn withIndex() -> Iterator<Option<(Int, T)>> | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| pub impl Semigroup[*T] for Iterable<*T> | pub int List<T> : Iterable<T> req Monad, Functor, Semigroup, Empty | ||||||
|     type Other = Iterable<*T> |  | ||||||
| 
 |  | ||||||
|     fn concat(other: &Other<*T>) -> Self<*T> |  | ||||||
|         let result: Self<*T> = ArrayList(count()) |  | ||||||
|         for t in self do |  | ||||||
|             result.add(t) |  | ||||||
|         end |  | ||||||
|         for t in other do |  | ||||||
|             result.add(t) |  | ||||||
|         end |  | ||||||
|         result |  | ||||||
|     end |  | ||||||
| 
 |  | ||||||
|     cons fn consConcat(other: Other<*T>) -> Self<*T> |  | ||||||
|         let result: Self<*T> = ArrayList(count()) |  | ||||||
|         for t in self do |  | ||||||
|             result.add(t) |  | ||||||
|         end |  | ||||||
|         for t in other do |  | ||||||
|             result.add(t) |  | ||||||
|         end |  | ||||||
|         result |  | ||||||
|     end |  | ||||||
| end |  | ||||||
| 
 |  | ||||||
| pub int List<T> : Iterable<T> |  | ||||||
|     fn add(t: T) -> Void |     fn add(t: T) -> Void | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| pub impl Functor[*T] for List<*T> | pub inst Functor[*T] for List<*T> where *T has Default | ||||||
|     fn <U> map(f: (t: &*T) -> U) -> Self<U> |     impl fn <U> map(ftu: (t: *T) -> U) -> Self<U> | ||||||
|         let mut result: Self<U> = ArrayList(count()) |         let mut result: Self<U> = Self::empty() | ||||||
|         for t in self do |         for t in self do | ||||||
|             result.add(f(t)) |             result += Self::lift(ftu(t)) | ||||||
|         end |  | ||||||
|         result |  | ||||||
|     end |  | ||||||
| end |  | ||||||
| 
 |  | ||||||
| pub impl Empty[*T] for List<*T> |  | ||||||
|     static fn empty() -> List<*T> = ArrayList() |  | ||||||
| end |  | ||||||
| 
 |  | ||||||
| pub inst Monad[*T] for List<*T> |  | ||||||
|     static fn lift(t: *T) -> List<*T> |  | ||||||
|         let result: List<*T> = ArrayList() |  | ||||||
|         result.add(t) |  | ||||||
|         result |  | ||||||
|     end |  | ||||||
| 
 |  | ||||||
|     fn <U> flatMap(f: fn (t: &*T) -> List<U>) -> List<U> |  | ||||||
|         let result: List<U> = ArrayList(count()) |  | ||||||
|         for t in self do |  | ||||||
|             for u in f(t).consIter() do |  | ||||||
|                 result.add(u) |  | ||||||
|             end |  | ||||||
|         end |         end | ||||||
|         result |         result | ||||||
|     end |     end | ||||||
| @ -143,52 +95,29 @@ end | |||||||
| 
 | 
 | ||||||
| pub class ArrayList<T> : List<T> | pub class ArrayList<T> : List<T> | ||||||
| 
 | 
 | ||||||
|  |     let init: fn () -> T // ?: sugar for Option<fn () -> T> | ||||||
|     let capacity: USize |     let capacity: USize | ||||||
|     let mut ts: Array<Option<T>> |     let mut ts: Array<T> | ||||||
|     let count: USize = 0 |     let count: USize = 0 | ||||||
| 
 | 
 | ||||||
|     pub ctor(startCapacity: USize = 10) |     pub ctor(startCapacity: USize = 10, init: fn () -> T = Default::default) where T has Default | ||||||
|  |         := init | ||||||
|  |         capacity = startCapacity  // ?= sugar for Some(expr) | ||||||
|  |         ts = array(startCapacity, init) | ||||||
|  |     end | ||||||
|  | 
 | ||||||
|  |     pub ctor(init: fn () -> T, startCapacity: USize = 10) | ||||||
|  |         := init | ||||||
|         capacity = startCapacity |         capacity = startCapacity | ||||||
|         ts = array(startCapacity, None) |         ts = array(startCapacity, init) | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|     class ArrayListIterator<T>(owner: &ArrayList<T>) /* ref owner (implied by constructor) */ : Iterator<T> |     impl fn iter() -> Iterator<T> | ||||||
|         let i: USize = 0 |         todo() | ||||||
| 
 |  | ||||||
|         impl fn next() -> Option<&T ref self> |  | ||||||
|             if owner.ts[i] is Some(t) then |  | ||||||
|                 i++ |  | ||||||
|                 Some(t) |  | ||||||
|             else |  | ||||||
|                 None |  | ||||||
|             end |  | ||||||
|         end |  | ||||||
|     end |  | ||||||
| 
 |  | ||||||
|     class ConsArrayListIterator<T>(ts: Array<Option<T>>) : ConsIterator<T> |  | ||||||
|         let i: USize = 0 |  | ||||||
| 
 |  | ||||||
|         impl fn next() -> Option<T> |  | ||||||
|             if ts[i] is Some then |  | ||||||
|                 let wrappedT = mem::take(ts[i], None) |  | ||||||
|                 i++ |  | ||||||
|                 wrappedT |  | ||||||
|             else |  | ||||||
|                 None |  | ||||||
|             end |  | ||||||
|         end |  | ||||||
|     end |  | ||||||
| 
 |  | ||||||
|     impl fn iter() -> Iterator<&T> ref self |  | ||||||
|         ArrayListIterator(&self) |  | ||||||
|     end |  | ||||||
| 
 |  | ||||||
|     impl cons fn consIter() -> Iterator<T> |  | ||||||
|         ConsArrayListIterator(mem::take(ts, arrays::empty())) |  | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|     impl fn add(t: T) -> Void |     impl fn add(t: T) -> Void | ||||||
|         ts[count] = Some(t) |         ts[count] = t | ||||||
|         count++ |         count++ | ||||||
|         if count == capacity then |         if count == capacity then | ||||||
|             resize() |             resize() | ||||||
| @ -196,14 +125,52 @@ pub class ArrayList<T> : List<T> | |||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|     fn resize() -> Void |     fn resize() -> Void | ||||||
|         let oldTs = mem::take(&ts, array(capacity * 2, None)) |         let oldTs = mem::take(&ts, array(capacity * 2, init)) | ||||||
|         for (i, wrappedT) in oldTs.consIter() do |         for (i, t) in oldTs.consIter().withIndex() do | ||||||
|             ts[i] = wrappedT |             ts[i] = t | ||||||
|         end |         end | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
|  | pub inst Empty[*T] for ArrayList<*T> | ||||||
|  |     where *T has Default | ||||||
|  |     impl static fn empty() -> List<*T> = Self() | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | pub inst Semigroup[*T] for ArrayList<*T> | ||||||
|  |     where *T has Default | ||||||
|  |     impl fn concat(other: List<*T>) -> List<*T> | ||||||
|  |         let result = Self() | ||||||
|  |         for t in self do | ||||||
|  |             result.add(t) | ||||||
|  |         end | ||||||
|  |         for t in other do | ||||||
|  |             result.add(t) | ||||||
|  |         end | ||||||
|  |         result | ||||||
|  |     end | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | pub inst Monad[*T] for ArrayList<*T> | ||||||
|  |     where T has Default | ||||||
|  |     impl static fn lift(t: *T) -> List<*T> | ||||||
|  |         let result: List<*T> = Self() | ||||||
|  |         result.add(t) | ||||||
|  |         result | ||||||
|  |     end | ||||||
|  | 
 | ||||||
|  |     impl fn <U> flatMap(f: fn (t: *T) -> List<U>) -> List<U> | ||||||
|  |         let result: List<U> = Self() | ||||||
|  |         for t in self do | ||||||
|  |             for u in f(t) do | ||||||
|  |                 result.add(u) | ||||||
|  |             end | ||||||
|  |         end | ||||||
|  |         result | ||||||
|  |     end | ||||||
|  | end | ||||||
|  | 
 | ||||||
| pub mod std::core | pub mod std::core | ||||||
| 
 | 
 | ||||||
|     pub mod mem |     pub mod mem | ||||||
| @ -214,8 +181,8 @@ pub mod std::core | |||||||
| 
 | 
 | ||||||
|     pub native fn <T> array(capacity: USize) -> Array<T> where T has Default |     pub native fn <T> array(capacity: USize) -> Array<T> where T has Default | ||||||
| 
 | 
 | ||||||
|     pub fn <T> list(...items: Array<T>) -> List<T> |     pub fn <T> list(...items: Array<T>) -> List<T> where T has Default | ||||||
|         let result = ArrayList(items.capacity()) |         let result = ArrayList(items.capacity(), Default[T]::default) | ||||||
|         for item in items.consIter() do |         for item in items.consIter() do | ||||||
|             result.add(item) |             result.add(item) | ||||||
|         end |         end | ||||||
| @ -224,7 +191,8 @@ pub mod std::core | |||||||
| 
 | 
 | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| // Other file | // other file | ||||||
|  | use std::collections::List | ||||||
| use std::hkt::{Functor[List], Monad[List]} | use std::hkt::{Functor[List], Monad[List]} | ||||||
| 
 | 
 | ||||||
| fn main() | fn main() | ||||||
|  | |||||||
| @ -1,10 +1,10 @@ | |||||||
| mod name_analysis; | // mod name_analysis;
 | ||||||
| mod p3; | mod p3; | ||||||
| // mod unparse;
 | // mod unparse;
 | ||||||
| 
 | 
 | ||||||
| use std::path::PathBuf; | use std::path::PathBuf; | ||||||
| 
 | 
 | ||||||
| use crate::name_analysis::name_analysis; | // use crate::name_analysis::name_analysis;
 | ||||||
| use crate::p3::pretty_print_parse; | use crate::p3::pretty_print_parse; | ||||||
| // use crate::unparse::unparse;
 | // use crate::unparse::unparse;
 | ||||||
| use clap::{Parser, Subcommand}; | use clap::{Parser, Subcommand}; | ||||||
| @ -44,12 +44,12 @@ fn main() { | |||||||
|                 pretty_print_parse(&path) |                 pretty_print_parse(&path) | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         Commands::NameAnalysis { paths } => { |         // Commands::NameAnalysis { paths } => {
 | ||||||
|             let result = name_analysis(&paths); |         //     let result = name_analysis(&paths);
 | ||||||
|             if let Err(e) = result { |         //     if let Err(e) = result {
 | ||||||
|                 eprintln!("{}", e) |         //         eprintln!("{}", e)
 | ||||||
|             } |         //     }
 | ||||||
|         } |         // }
 | ||||||
|         _ => todo!(), |         _ => todo!(), | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -20,7 +20,8 @@ pub fn name_analysis(paths: &Vec<PathBuf>) -> Result<(), Box<dyn std::error::Err | |||||||
| 
 | 
 | ||||||
|         match parse_result { |         match parse_result { | ||||||
|             Ok(mut pairs) => { |             Ok(mut pairs) => { | ||||||
|                 let compilation_unit = build_ast(file_id, &mut pairs); |                 let compilation_unit_pair = pairs.next().unwrap(); | ||||||
|  |                 let compilation_unit = build_ast(&path.display().to_string(), file_id, compilation_unit_pair); | ||||||
|                 compilation_units.push(compilation_unit); |                 compilation_units.push(compilation_unit); | ||||||
|                 Ok::<(), Box<dyn std::error::Error>>(()) |                 Ok::<(), Box<dyn std::error::Error>>(()) | ||||||
|             } |             } | ||||||
| @ -31,10 +32,7 @@ pub fn name_analysis(paths: &Vec<PathBuf>) -> Result<(), Box<dyn std::error::Err | |||||||
|     let mut symbol_table = SymbolTable::new(); |     let mut symbol_table = SymbolTable::new(); | ||||||
|     add_std_core_symbols(&mut symbol_table).expect("Failed to add std::core symbols."); |     add_std_core_symbols(&mut symbol_table).expect("Failed to add std::core symbols."); | ||||||
|     
 |     
 | ||||||
|     let diagnostics = analyze_names( |     let diagnostics = analyze_names(&mut compilation_units, &mut symbol_table); | ||||||
|         &mut compilation_units.iter().map(Box::as_mut), |  | ||||||
|         &mut symbol_table |  | ||||||
|     ); |  | ||||||
|     if diagnostics.is_empty() { |     if diagnostics.is_empty() { | ||||||
|         println!("Name analysis complete."); |         println!("Name analysis complete."); | ||||||
|         println!("Symbol table\n-------\n{}", symbol_table); |         println!("Symbol table\n-------\n{}", symbol_table); | ||||||
| @ -5,7 +5,7 @@ extern crate core; | |||||||
| pub mod ast; | pub mod ast; | ||||||
| pub mod diagnostic; | pub mod diagnostic; | ||||||
| pub mod module; | pub mod module; | ||||||
| pub mod name_analysis; | // pub mod name_analysis;
 | ||||||
| pub mod object_file; | pub mod object_file; | ||||||
| pub mod parser; | pub mod parser; | ||||||
| pub mod std_core; | pub mod std_core; | ||||||
|  | |||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										1320
									
								
								src/name_analysis/gather.rs.bak
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1320
									
								
								src/name_analysis/gather.rs.bak
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @ -32,7 +32,7 @@ pub mod symbol; | |||||||
| pub mod symbol_table; | pub mod symbol_table; | ||||||
| 
 | 
 | ||||||
| pub fn analyze_names( | pub fn analyze_names( | ||||||
|     compilation_units: &mut [CompilationUnit], |     compilation_units: &mut Vec<CompilationUnit>, | ||||||
|     symbol_table: &mut SymbolTable, |     symbol_table: &mut SymbolTable, | ||||||
| ) -> Vec<DmDiagnostic> { | ) -> Vec<DmDiagnostic> { | ||||||
|     let mut diagnostics = vec![]; |     let mut diagnostics = vec![]; | ||||||
| @ -1,9 +1,11 @@ | |||||||
|  | use crate::ast::node::named::Named; | ||||||
| use crate::ast::node::*; | use crate::ast::node::*; | ||||||
| use crate::diagnostic::DmDiagnostic; | use crate::diagnostic::DmDiagnostic; | ||||||
| use crate::name_analysis::symbol::Symbol; | use crate::name_analysis::symbol::Symbol; | ||||||
| use crate::name_analysis::symbol_table::{SymbolLookupError, SymbolTable}; | use crate::name_analysis::symbol_table::{SymbolLookupError, SymbolTable}; | ||||||
| use codespan_reporting::diagnostic::{Diagnostic, Label}; | use codespan_reporting::diagnostic::{Diagnostic, Label}; | ||||||
| use std::range::Range; | use std::range::Range; | ||||||
|  | /* Type Use */ | ||||||
| 
 | 
 | ||||||
| fn resolve_type_use( | fn resolve_type_use( | ||||||
|     type_use: &mut TypeUse, |     type_use: &mut TypeUse, | ||||||
| @ -1,4 +1,3 @@ | |||||||
| use crate::ast::node::Identifier; |  | ||||||
| use std::cell::RefCell; | use std::cell::RefCell; | ||||||
| use std::fmt::{Debug, Display, Formatter}; | use std::fmt::{Debug, Display, Formatter}; | ||||||
| use std::ops::Deref; | use std::ops::Deref; | ||||||
| @ -1,14 +1,14 @@ | |||||||
| use crate::name_analysis::symbol::{FunctionSymbol, ParameterSymbol}; | // use crate::name_analysis::symbol::{FunctionSymbol, ParameterSymbol};
 | ||||||
| use crate::name_analysis::symbol_table::{SymbolInsertError, SymbolTable}; | // use crate::name_analysis::symbol_table::{SymbolInsertError, SymbolTable};
 | ||||||
| 
 | //
 | ||||||
| pub fn add_std_core_symbols(symbol_table: &mut SymbolTable) -> Result<(), SymbolInsertError> { | // pub fn add_std_core_symbols(symbol_table: &mut SymbolTable) -> Result<(), SymbolInsertError> {
 | ||||||
|     symbol_table.insert_function_symbol( | //     symbol_table.insert_function_symbol(
 | ||||||
|         FunctionSymbol::new("std::core::println", "println", true, true, None) | //         FunctionSymbol::new("std::core::println", "println", true, true, None)
 | ||||||
|             .with_parameters(vec![ParameterSymbol::new("msg", None)]), | //             .with_parameters(vec![ParameterSymbol::new("msg", None)]),
 | ||||||
|     )?; | //     )?;
 | ||||||
|     symbol_table.insert_function_symbol( | //     symbol_table.insert_function_symbol(
 | ||||||
|         FunctionSymbol::new("std::core::print", "print", true, true, None) | //         FunctionSymbol::new("std::core::print", "print", true, true, None)
 | ||||||
|             .with_parameters(vec![ParameterSymbol::new("msg", None)]), | //             .with_parameters(vec![ParameterSymbol::new("msg", None)]),
 | ||||||
|     )?; | //     )?;
 | ||||||
|     Ok(()) | //     Ok(())
 | ||||||
| } | // }
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user