got redo working
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
use std::{cell::RefCell, clone};
|
use std::cell::RefCell;
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct IdGenerator {
|
pub struct IdGenerator {
|
||||||
@@ -118,7 +118,7 @@ impl TypeUsage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn replace_type(&self, old: &str, new: &Identifier) -> TypeUsage {
|
pub fn replace_type(&self, old: &str, new: &Identifier) -> TypeUsage {
|
||||||
return match &self {
|
match &self {
|
||||||
TypeUsage::Function(function) => {
|
TypeUsage::Function(function) => {
|
||||||
return TypeUsage::Function(FunctionTypeUsage {
|
return TypeUsage::Function(FunctionTypeUsage {
|
||||||
arguments: function.arguments.iter().map(|arg| arg.replace_type(old, new)).collect(),
|
arguments: function.arguments.iter().map(|arg| arg.replace_type(old, new)).collect(),
|
||||||
@@ -126,7 +126,7 @@ impl TypeUsage {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
TypeUsage::Named(named) => {
|
TypeUsage::Named(named) => {
|
||||||
let name = if (named.name.name.value == old) {
|
let name = if named.name.name.value == old {
|
||||||
new.clone()
|
new.clone()
|
||||||
} else {
|
} else {
|
||||||
named.name.clone()
|
named.name.clone()
|
||||||
@@ -138,7 +138,7 @@ impl TypeUsage {
|
|||||||
}
|
}
|
||||||
TypeUsage::Namespace(namespace) => return TypeUsage::Namespace(namespace.clone()),
|
TypeUsage::Namespace(namespace) => return TypeUsage::Namespace(namespace.clone()),
|
||||||
TypeUsage::Unknown(unkown) => return TypeUsage::Unknown(unkown.clone()),
|
TypeUsage::Unknown(unkown) => return TypeUsage::Unknown(unkown.clone()),
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -413,7 +413,7 @@ impl TreeWalkInterpreter {
|
|||||||
}
|
}
|
||||||
ast::Subexpression::VariableUsage(variable_usage) => {
|
ast::Subexpression::VariableUsage(variable_usage) => {
|
||||||
if !ctx.environment.contains_key(&variable_usage.name.name.value) {
|
if !ctx.environment.contains_key(&variable_usage.name.name.value) {
|
||||||
panic!(variable_usage.name.name.value.clone());
|
panic!("{}", variable_usage.name.name.value.clone());
|
||||||
}
|
}
|
||||||
let variable_value = match &ctx.environment[&variable_usage.name.name.value] {
|
let variable_value = match &ctx.environment[&variable_usage.name.name.value] {
|
||||||
NamedEntity::Variable(v) => v.clone(),
|
NamedEntity::Variable(v) => v.clone(),
|
||||||
|
|||||||
@@ -32,9 +32,6 @@ fn main() {
|
|||||||
.get_matches();
|
.get_matches();
|
||||||
let input = matches.value_of("INPUT").unwrap();
|
let input = matches.value_of("INPUT").unwrap();
|
||||||
|
|
||||||
let default_output = input.rsplitn(2, ".").collect::<Vec<&str>>().last().unwrap().clone();
|
|
||||||
let _output = matches.value_of("OUTPUT").unwrap_or(default_output);
|
|
||||||
|
|
||||||
let contents = fs::read_to_string(input).expect("input file not found");
|
let contents = fs::read_to_string(input).expect("input file not found");
|
||||||
let unknown_id_gen = ast::IdGenerator::new("S");
|
let unknown_id_gen = ast::IdGenerator::new("S");
|
||||||
let module_ast = grammar::ModuleParser::new().parse(&unknown_id_gen, &contents).unwrap(); //TODO: convert to error
|
let module_ast = grammar::ModuleParser::new().parse(&unknown_id_gen, &contents).unwrap(); //TODO: convert to error
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ impl TraitChecker {
|
|||||||
for impl_function in impl_.functions.iter() {
|
for impl_function in impl_.functions.iter() {
|
||||||
let mut found = false;
|
let mut found = false;
|
||||||
for trait_item in trait_declaration.functions.iter() {
|
for trait_item in trait_declaration.functions.iter() {
|
||||||
let declaration = match trait_item {
|
match trait_item {
|
||||||
ast::TraitItem::FunctionDeclaration(declaration) => {
|
ast::TraitItem::FunctionDeclaration(declaration) => {
|
||||||
if impl_function.declaration.name.name.value == declaration.name.name.value {
|
if impl_function.declaration.name.name.value == declaration.name.name.value {
|
||||||
found = true;
|
found = true;
|
||||||
|
|||||||
@@ -536,12 +536,12 @@ impl Context {
|
|||||||
fn add_impl(&self, impl_: &ast::Impl, traits: &HashMap<String, ast::TraitTypeDeclaration>) -> Result<Context> {
|
fn add_impl(&self, impl_: &ast::Impl, traits: &HashMap<String, ast::TraitTypeDeclaration>) -> Result<Context> {
|
||||||
let mut functions = HashMap::new();
|
let mut functions = HashMap::new();
|
||||||
for func in impl_.functions.iter() {
|
for func in impl_.functions.iter() {
|
||||||
if (func.declaration.arguments.len() == 0) {
|
if func.declaration.arguments.len() == 0 {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
match &func.declaration.arguments[0].type_ {
|
match &func.declaration.arguments[0].type_ {
|
||||||
ast::TypeUsage::Named(named) => {
|
ast::TypeUsage::Named(named) => {
|
||||||
if (named.name.name.value != "Self") {
|
if named.name.name.value != "Self" {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user