mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 06:14:46 +00:00
make things compile, base64 has a memory leak
This commit is contained in:
parent
c6a8bdfdbe
commit
94e8c62613
12 changed files with 99 additions and 104 deletions
|
@ -768,7 +768,7 @@ pub fn dictWalk(
|
||||||
const key = dict.getKey(i, alignment, key_width, value_width);
|
const key = dict.getKey(i, alignment, key_width, value_width);
|
||||||
const value = dict.getValue(i, alignment, key_width, value_width);
|
const value = dict.getValue(i, alignment, key_width, value_width);
|
||||||
|
|
||||||
caller(data, key, value, b2, b1);
|
caller(data, b2, key, value, b1);
|
||||||
|
|
||||||
std.mem.swap([*]u8, &b1, &b2);
|
std.mem.swap([*]u8, &b1, &b2);
|
||||||
},
|
},
|
||||||
|
|
|
@ -560,7 +560,7 @@ pub fn listWalk(
|
||||||
const size = list.len();
|
const size = list.len();
|
||||||
while (i < size) : (i += 1) {
|
while (i < size) : (i += 1) {
|
||||||
const element = source_ptr + i * element_width;
|
const element = source_ptr + i * element_width;
|
||||||
caller(data, element, b2, b1);
|
caller(data, b2, element, b1);
|
||||||
|
|
||||||
std.mem.swap([*]u8, &b1, &b2);
|
std.mem.swap([*]u8, &b1, &b2);
|
||||||
}
|
}
|
||||||
|
@ -607,7 +607,7 @@ pub fn listWalkBackwards(
|
||||||
while (i > 0) {
|
while (i > 0) {
|
||||||
i -= 1;
|
i -= 1;
|
||||||
const element = source_ptr + i * element_width;
|
const element = source_ptr + i * element_width;
|
||||||
caller(data, element, b2, b1);
|
caller(data, b2, element, b1);
|
||||||
|
|
||||||
std.mem.swap([*]u8, &b1, &b2);
|
std.mem.swap([*]u8, &b1, &b2);
|
||||||
}
|
}
|
||||||
|
@ -658,7 +658,7 @@ pub fn listWalkUntil(
|
||||||
inc_n_data(data, 1);
|
inc_n_data(data, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
caller(data, element, bytes_ptr, bytes_ptr);
|
caller(data, bytes_ptr, element, bytes_ptr);
|
||||||
|
|
||||||
// [ Continue ..., Stop ]
|
// [ Continue ..., Stop ]
|
||||||
const tag_id = has_tag_id(0, bytes_ptr);
|
const tag_id = has_tag_id(0, bytes_ptr);
|
||||||
|
|
|
@ -793,7 +793,7 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
|
||||||
list_type(flex(TVAR1)),
|
list_type(flex(TVAR1)),
|
||||||
flex(TVAR2),
|
flex(TVAR2),
|
||||||
closure(
|
closure(
|
||||||
vec![flex(TVAR1), flex(TVAR2)],
|
vec![flex(TVAR2), flex(TVAR1)],
|
||||||
TVAR3,
|
TVAR3,
|
||||||
Box::new(until_type(flex(TVAR2))),
|
Box::new(until_type(flex(TVAR2))),
|
||||||
),
|
),
|
||||||
|
@ -1173,13 +1173,13 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
|
||||||
Box::new(set_type(flex(TVAR1))),
|
Box::new(set_type(flex(TVAR1))),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Set.walk : Set a, (a, b -> b), b -> b
|
// Set.walk : Set a, (b, a -> b), b -> b
|
||||||
add_top_level_function_type!(
|
add_top_level_function_type!(
|
||||||
Symbol::SET_WALK,
|
Symbol::SET_WALK,
|
||||||
vec![
|
vec![
|
||||||
set_type(flex(TVAR1)),
|
set_type(flex(TVAR1)),
|
||||||
closure(vec![flex(TVAR1), flex(TVAR2)], TVAR3, Box::new(flex(TVAR2))),
|
|
||||||
flex(TVAR2),
|
flex(TVAR2),
|
||||||
|
closure(vec![flex(TVAR2), flex(TVAR1)], TVAR3, Box::new(flex(TVAR2))),
|
||||||
],
|
],
|
||||||
Box::new(flex(TVAR2)),
|
Box::new(flex(TVAR2)),
|
||||||
);
|
);
|
||||||
|
|
|
@ -2550,7 +2550,7 @@ fn set_contains(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||||
dict_contains(symbol, var_store)
|
dict_contains(symbol, var_store)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set.walk : Set k, (k, accum -> accum), accum -> accum
|
/// Set.walk : Set k, (accum, k -> accum), accum -> accum
|
||||||
fn set_walk(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
fn set_walk(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||||
let dict_var = var_store.fresh();
|
let dict_var = var_store.fresh();
|
||||||
let func_var = var_store.fresh();
|
let func_var = var_store.fresh();
|
||||||
|
@ -2560,7 +2560,7 @@ fn set_walk(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||||
|
|
||||||
let user_function = Box::new((
|
let user_function = Box::new((
|
||||||
func_var,
|
func_var,
|
||||||
no_region(Var(Symbol::ARG_2)),
|
no_region(Var(Symbol::ARG_3)),
|
||||||
var_store.fresh(),
|
var_store.fresh(),
|
||||||
accum_var,
|
accum_var,
|
||||||
));
|
));
|
||||||
|
@ -2568,8 +2568,8 @@ fn set_walk(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||||
let call_func = Call(
|
let call_func = Call(
|
||||||
user_function,
|
user_function,
|
||||||
vec![
|
vec![
|
||||||
(key_var, no_region(Var(Symbol::ARG_5))),
|
(accum_var, no_region(Var(Symbol::ARG_5))),
|
||||||
(accum_var, no_region(Var(Symbol::ARG_6))),
|
(key_var, no_region(Var(Symbol::ARG_6))),
|
||||||
],
|
],
|
||||||
CalledVia::Space,
|
CalledVia::Space,
|
||||||
);
|
);
|
||||||
|
@ -2581,11 +2581,11 @@ fn set_walk(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||||
return_type: accum_var,
|
return_type: accum_var,
|
||||||
name: Symbol::SET_WALK_USER_FUNCTION,
|
name: Symbol::SET_WALK_USER_FUNCTION,
|
||||||
recursive: Recursive::NotRecursive,
|
recursive: Recursive::NotRecursive,
|
||||||
captured_symbols: vec![(Symbol::ARG_2, func_var)],
|
captured_symbols: vec![(Symbol::ARG_3, func_var)],
|
||||||
arguments: vec![
|
arguments: vec![
|
||||||
(key_var, no_region(Pattern::Identifier(Symbol::ARG_5))),
|
(accum_var, no_region(Pattern::Identifier(Symbol::ARG_5))),
|
||||||
|
(key_var, no_region(Pattern::Identifier(Symbol::ARG_6))),
|
||||||
(Variable::EMPTY_RECORD, no_region(Pattern::Underscore)),
|
(Variable::EMPTY_RECORD, no_region(Pattern::Underscore)),
|
||||||
(accum_var, no_region(Pattern::Identifier(Symbol::ARG_6))),
|
|
||||||
],
|
],
|
||||||
loc_body: Box::new(no_region(call_func)),
|
loc_body: Box::new(no_region(call_func)),
|
||||||
};
|
};
|
||||||
|
@ -2594,8 +2594,8 @@ fn set_walk(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||||
op: LowLevel::DictWalk,
|
op: LowLevel::DictWalk,
|
||||||
args: vec![
|
args: vec![
|
||||||
(dict_var, Var(Symbol::ARG_1)),
|
(dict_var, Var(Symbol::ARG_1)),
|
||||||
|
(accum_var, Var(Symbol::ARG_2)),
|
||||||
(wrapper_var, wrapper),
|
(wrapper_var, wrapper),
|
||||||
(accum_var, Var(Symbol::ARG_3)),
|
|
||||||
],
|
],
|
||||||
ret_var: accum_var,
|
ret_var: accum_var,
|
||||||
};
|
};
|
||||||
|
@ -2604,8 +2604,8 @@ fn set_walk(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||||
symbol,
|
symbol,
|
||||||
vec![
|
vec![
|
||||||
(dict_var, Symbol::ARG_1),
|
(dict_var, Symbol::ARG_1),
|
||||||
(func_var, Symbol::ARG_2),
|
(accum_var, Symbol::ARG_2),
|
||||||
(accum_var, Symbol::ARG_3),
|
(func_var, Symbol::ARG_3),
|
||||||
],
|
],
|
||||||
var_store,
|
var_store,
|
||||||
body,
|
body,
|
||||||
|
|
|
@ -4501,7 +4501,7 @@ fn run_higher_order_low_level<'a, 'ctx, 'env>(
|
||||||
match list_layout {
|
match list_layout {
|
||||||
Layout::Builtin(Builtin::EmptyList) => default,
|
Layout::Builtin(Builtin::EmptyList) => default,
|
||||||
Layout::Builtin(Builtin::List(element_layout)) => {
|
Layout::Builtin(Builtin::List(element_layout)) => {
|
||||||
let argument_layouts = &[**element_layout, *default_layout];
|
let argument_layouts = &[*default_layout, **element_layout];
|
||||||
|
|
||||||
let roc_function_call = roc_function_call(
|
let roc_function_call = roc_function_call(
|
||||||
env,
|
env,
|
||||||
|
@ -4872,7 +4872,7 @@ fn run_higher_order_low_level<'a, 'ctx, 'env>(
|
||||||
panic!("key type unknown")
|
panic!("key type unknown")
|
||||||
}
|
}
|
||||||
Layout::Builtin(Builtin::Dict(key_layout, value_layout)) => {
|
Layout::Builtin(Builtin::Dict(key_layout, value_layout)) => {
|
||||||
let argument_layouts = &[**key_layout, **value_layout, *default_layout];
|
let argument_layouts = &[*default_layout, **key_layout, **value_layout];
|
||||||
|
|
||||||
let roc_function_call = roc_function_call(
|
let roc_function_call = roc_function_call(
|
||||||
env,
|
env,
|
||||||
|
|
|
@ -641,7 +641,7 @@ fn call_spec(
|
||||||
match op {
|
match op {
|
||||||
DictWalk => {
|
DictWalk => {
|
||||||
let dict = env.symbols[&call.arguments[0]];
|
let dict = env.symbols[&call.arguments[0]];
|
||||||
let default = env.symbols[&call.arguments[1]];
|
let state = env.symbols[&call.arguments[1]];
|
||||||
let closure_env = env.symbols[&call.arguments[3]];
|
let closure_env = env.symbols[&call.arguments[3]];
|
||||||
|
|
||||||
let bag = builder.add_get_tuple_field(block, dict, DICT_BAG_INDEX)?;
|
let bag = builder.add_get_tuple_field(block, dict, DICT_BAG_INDEX)?;
|
||||||
|
@ -653,16 +653,16 @@ fn call_spec(
|
||||||
let val = builder.add_get_tuple_field(block, first, 1)?;
|
let val = builder.add_get_tuple_field(block, first, 1)?;
|
||||||
|
|
||||||
let argument = if closure_env_layout.is_none() {
|
let argument = if closure_env_layout.is_none() {
|
||||||
builder.add_make_tuple(block, &[key, val, default])?
|
builder.add_make_tuple(block, &[state, key, val])?
|
||||||
} else {
|
} else {
|
||||||
builder.add_make_tuple(block, &[key, val, default, closure_env])?
|
builder.add_make_tuple(block, &[state, key, val, closure_env])?
|
||||||
};
|
};
|
||||||
builder.add_call(block, spec_var, module, name, argument)?;
|
builder.add_call(block, spec_var, module, name, argument)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
ListWalk | ListWalkBackwards | ListWalkUntil => {
|
ListWalk | ListWalkBackwards | ListWalkUntil => {
|
||||||
let list = env.symbols[&call.arguments[0]];
|
let list = env.symbols[&call.arguments[0]];
|
||||||
let default = env.symbols[&call.arguments[1]];
|
let state = env.symbols[&call.arguments[1]];
|
||||||
let closure_env = env.symbols[&call.arguments[3]];
|
let closure_env = env.symbols[&call.arguments[3]];
|
||||||
|
|
||||||
let bag = builder.add_get_tuple_field(block, list, LIST_BAG_INDEX)?;
|
let bag = builder.add_get_tuple_field(block, list, LIST_BAG_INDEX)?;
|
||||||
|
@ -671,9 +671,9 @@ fn call_spec(
|
||||||
let first = builder.add_bag_get(block, bag)?;
|
let first = builder.add_bag_get(block, bag)?;
|
||||||
|
|
||||||
let argument = if closure_env_layout.is_none() {
|
let argument = if closure_env_layout.is_none() {
|
||||||
builder.add_make_tuple(block, &[first, default])?
|
builder.add_make_tuple(block, &[state, first])?
|
||||||
} else {
|
} else {
|
||||||
builder.add_make_tuple(block, &[first, default, closure_env])?
|
builder.add_make_tuple(block, &[state, first, closure_env])?
|
||||||
};
|
};
|
||||||
builder.add_call(block, spec_var, module, name, argument)?;
|
builder.add_call(block, spec_var, module, name, argument)?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4039,9 +4039,12 @@ pub fn with_hole<'a>(
|
||||||
ListWalk | ListWalkUntil | ListWalkBackwards | DictWalk => {
|
ListWalk | ListWalkUntil | ListWalkBackwards | DictWalk => {
|
||||||
debug_assert_eq!(arg_symbols.len(), 3);
|
debug_assert_eq!(arg_symbols.len(), 3);
|
||||||
|
|
||||||
let closure_index = 2;
|
const LIST_INDEX: usize = 0;
|
||||||
let closure_data_symbol = arg_symbols[closure_index];
|
const DEFAULT_INDEX: usize = 1;
|
||||||
let closure_data_var = args[closure_index].0;
|
const CLOSURE_INDEX: usize = 2;
|
||||||
|
|
||||||
|
let closure_data_symbol = arg_symbols[CLOSURE_INDEX];
|
||||||
|
let closure_data_var = args[CLOSURE_INDEX].0;
|
||||||
|
|
||||||
let stmt = match_on_closure_argument!(
|
let stmt = match_on_closure_argument!(
|
||||||
env,
|
env,
|
||||||
|
@ -4050,7 +4053,7 @@ pub fn with_hole<'a>(
|
||||||
closure_data_symbol,
|
closure_data_symbol,
|
||||||
closure_data_var,
|
closure_data_var,
|
||||||
op,
|
op,
|
||||||
[arg_symbols[0], arg_symbols[1]],
|
[arg_symbols[LIST_INDEX], arg_symbols[DEFAULT_INDEX]],
|
||||||
layout,
|
layout,
|
||||||
assigned,
|
assigned,
|
||||||
hole
|
hole
|
||||||
|
@ -4062,47 +4065,35 @@ pub fn with_hole<'a>(
|
||||||
// actual closure, and the default is either the number 1 or 0
|
// actual closure, and the default is either the number 1 or 0
|
||||||
// this can be removed when we define builtin modules as proper modules
|
// this can be removed when we define builtin modules as proper modules
|
||||||
|
|
||||||
let stmt = {
|
let stmt = assign_to_symbol(
|
||||||
const ARG_INDEX: usize = 0;
|
env,
|
||||||
|
procs,
|
||||||
|
layout_cache,
|
||||||
|
args[LIST_INDEX].0,
|
||||||
|
Located::at_zero(args[LIST_INDEX].1.clone()),
|
||||||
|
arg_symbols[LIST_INDEX],
|
||||||
|
stmt,
|
||||||
|
);
|
||||||
|
|
||||||
assign_to_symbol(
|
let stmt = assign_to_symbol(
|
||||||
env,
|
env,
|
||||||
procs,
|
procs,
|
||||||
layout_cache,
|
layout_cache,
|
||||||
args[ARG_INDEX].0,
|
args[DEFAULT_INDEX].0,
|
||||||
Located::at_zero(args[ARG_INDEX].1.clone()),
|
Located::at_zero(args[DEFAULT_INDEX].1.clone()),
|
||||||
arg_symbols[ARG_INDEX],
|
arg_symbols[DEFAULT_INDEX],
|
||||||
stmt,
|
stmt,
|
||||||
)
|
);
|
||||||
};
|
|
||||||
|
|
||||||
let stmt = {
|
assign_to_symbol(
|
||||||
const ARG_INDEX: usize = 1;
|
env,
|
||||||
|
procs,
|
||||||
assign_to_symbol(
|
layout_cache,
|
||||||
env,
|
args[CLOSURE_INDEX].0,
|
||||||
procs,
|
Located::at_zero(args[CLOSURE_INDEX].1.clone()),
|
||||||
layout_cache,
|
arg_symbols[CLOSURE_INDEX],
|
||||||
args[ARG_INDEX].0,
|
stmt,
|
||||||
Located::at_zero(args[ARG_INDEX].1.clone()),
|
)
|
||||||
arg_symbols[ARG_INDEX],
|
|
||||||
stmt,
|
|
||||||
)
|
|
||||||
};
|
|
||||||
|
|
||||||
{
|
|
||||||
const ARG_INDEX: usize = 2;
|
|
||||||
|
|
||||||
assign_to_symbol(
|
|
||||||
env,
|
|
||||||
procs,
|
|
||||||
layout_cache,
|
|
||||||
args[ARG_INDEX].0,
|
|
||||||
Located::at_zero(args[ARG_INDEX].1.clone()),
|
|
||||||
arg_symbols[ARG_INDEX],
|
|
||||||
stmt,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ListMap2 => {
|
ListMap2 => {
|
||||||
debug_assert_eq!(arg_symbols.len(), 3);
|
debug_assert_eq!(arg_symbols.len(), 3);
|
||||||
|
|
|
@ -3405,7 +3405,7 @@ mod solve_expr {
|
||||||
else
|
else
|
||||||
Ok { position, cost: 0.0 }
|
Ok { position, cost: 0.0 }
|
||||||
|
|
||||||
Set.walk model.openSet folder (Ok { position: boom {}, cost: 0.0 })
|
Set.walk model.openSet (Ok { position: boom {}, cost: 0.0 }) folder
|
||||||
|> Result.map (\x -> x.position)
|
|> Result.map (\x -> x.position)
|
||||||
|
|
||||||
astar : Model position -> Result position [ KeyNotFound ]*
|
astar : Model position -> Result position [ KeyNotFound ]*
|
||||||
|
@ -3689,7 +3689,7 @@ mod solve_expr {
|
||||||
List.walkBackwards
|
List.walkBackwards
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
"List a, (a, b -> b), b -> b",
|
"List a, b, (a, b -> b) -> b",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3702,7 +3702,7 @@ mod solve_expr {
|
||||||
empty =
|
empty =
|
||||||
[]
|
[]
|
||||||
|
|
||||||
List.walkBackwards empty (\a, b -> a + b) 0
|
List.walkBackwards empty 0 (\a, b -> a + b)
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
"I64",
|
"I64",
|
||||||
|
|
|
@ -191,7 +191,7 @@ fn from_list_with_fold() {
|
||||||
myDict : Dict I64 I64
|
myDict : Dict I64 I64
|
||||||
myDict =
|
myDict =
|
||||||
[1,2,3]
|
[1,2,3]
|
||||||
|> List.walk (\value, accum -> Dict.insert accum value value) Dict.empty
|
|> List.walk Dict.empty (\accum, value -> Dict.insert accum value value)
|
||||||
|
|
||||||
Dict.values myDict
|
Dict.values myDict
|
||||||
"#
|
"#
|
||||||
|
@ -214,7 +214,7 @@ fn from_list_with_fold() {
|
||||||
myDict =
|
myDict =
|
||||||
# 25 elements (8 + 16 + 1) is guaranteed to overflow/reallocate at least twice
|
# 25 elements (8 + 16 + 1) is guaranteed to overflow/reallocate at least twice
|
||||||
range 0 25 []
|
range 0 25 []
|
||||||
|> List.walk (\value, accum -> Dict.insert accum value value) Dict.empty
|
|> List.walk Dict.empty (\accum, value -> Dict.insert accum value value)
|
||||||
|
|
||||||
Dict.values myDict
|
Dict.values myDict
|
||||||
|> List.len
|
|> List.len
|
||||||
|
@ -373,7 +373,7 @@ fn intersection() {
|
||||||
indoc!(
|
indoc!(
|
||||||
r#"
|
r#"
|
||||||
dict1 : Dict I64 {}
|
dict1 : Dict I64 {}
|
||||||
dict1 =
|
dict1 =
|
||||||
Dict.empty
|
Dict.empty
|
||||||
|> Dict.insert 1 {}
|
|> Dict.insert 1 {}
|
||||||
|> Dict.insert 2 {}
|
|> Dict.insert 2 {}
|
||||||
|
@ -382,14 +382,14 @@ fn intersection() {
|
||||||
|> Dict.insert 5 {}
|
|> Dict.insert 5 {}
|
||||||
|
|
||||||
dict2 : Dict I64 {}
|
dict2 : Dict I64 {}
|
||||||
dict2 =
|
dict2 =
|
||||||
Dict.empty
|
Dict.empty
|
||||||
|> Dict.insert 0 {}
|
|> Dict.insert 0 {}
|
||||||
|> Dict.insert 2 {}
|
|> Dict.insert 2 {}
|
||||||
|> Dict.insert 4 {}
|
|> Dict.insert 4 {}
|
||||||
|
|
||||||
Dict.intersection dict1 dict2
|
Dict.intersection dict1 dict2
|
||||||
|> Dict.len
|
|> Dict.len
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
2,
|
2,
|
||||||
|
@ -403,7 +403,7 @@ fn intersection_prefer_first() {
|
||||||
indoc!(
|
indoc!(
|
||||||
r#"
|
r#"
|
||||||
dict1 : Dict I64 I64
|
dict1 : Dict I64 I64
|
||||||
dict1 =
|
dict1 =
|
||||||
Dict.empty
|
Dict.empty
|
||||||
|> Dict.insert 1 1
|
|> Dict.insert 1 1
|
||||||
|> Dict.insert 2 2
|
|> Dict.insert 2 2
|
||||||
|
@ -412,14 +412,14 @@ fn intersection_prefer_first() {
|
||||||
|> Dict.insert 5 5
|
|> Dict.insert 5 5
|
||||||
|
|
||||||
dict2 : Dict I64 I64
|
dict2 : Dict I64 I64
|
||||||
dict2 =
|
dict2 =
|
||||||
Dict.empty
|
Dict.empty
|
||||||
|> Dict.insert 0 100
|
|> Dict.insert 0 100
|
||||||
|> Dict.insert 2 200
|
|> Dict.insert 2 200
|
||||||
|> Dict.insert 4 300
|
|> Dict.insert 4 300
|
||||||
|
|
||||||
Dict.intersection dict1 dict2
|
Dict.intersection dict1 dict2
|
||||||
|> Dict.values
|
|> Dict.values
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
RocList::from_slice(&[4, 2]),
|
RocList::from_slice(&[4, 2]),
|
||||||
|
@ -433,7 +433,7 @@ fn difference() {
|
||||||
indoc!(
|
indoc!(
|
||||||
r#"
|
r#"
|
||||||
dict1 : Dict I64 {}
|
dict1 : Dict I64 {}
|
||||||
dict1 =
|
dict1 =
|
||||||
Dict.empty
|
Dict.empty
|
||||||
|> Dict.insert 1 {}
|
|> Dict.insert 1 {}
|
||||||
|> Dict.insert 2 {}
|
|> Dict.insert 2 {}
|
||||||
|
@ -442,14 +442,14 @@ fn difference() {
|
||||||
|> Dict.insert 5 {}
|
|> Dict.insert 5 {}
|
||||||
|
|
||||||
dict2 : Dict I64 {}
|
dict2 : Dict I64 {}
|
||||||
dict2 =
|
dict2 =
|
||||||
Dict.empty
|
Dict.empty
|
||||||
|> Dict.insert 0 {}
|
|> Dict.insert 0 {}
|
||||||
|> Dict.insert 2 {}
|
|> Dict.insert 2 {}
|
||||||
|> Dict.insert 4 {}
|
|> Dict.insert 4 {}
|
||||||
|
|
||||||
Dict.difference dict1 dict2
|
Dict.difference dict1 dict2
|
||||||
|> Dict.len
|
|> Dict.len
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
3,
|
3,
|
||||||
|
@ -463,7 +463,7 @@ fn difference_prefer_first() {
|
||||||
indoc!(
|
indoc!(
|
||||||
r#"
|
r#"
|
||||||
dict1 : Dict I64 I64
|
dict1 : Dict I64 I64
|
||||||
dict1 =
|
dict1 =
|
||||||
Dict.empty
|
Dict.empty
|
||||||
|> Dict.insert 1 1
|
|> Dict.insert 1 1
|
||||||
|> Dict.insert 2 2
|
|> Dict.insert 2 2
|
||||||
|
@ -472,14 +472,14 @@ fn difference_prefer_first() {
|
||||||
|> Dict.insert 5 5
|
|> Dict.insert 5 5
|
||||||
|
|
||||||
dict2 : Dict I64 I64
|
dict2 : Dict I64 I64
|
||||||
dict2 =
|
dict2 =
|
||||||
Dict.empty
|
Dict.empty
|
||||||
|> Dict.insert 0 100
|
|> Dict.insert 0 100
|
||||||
|> Dict.insert 2 200
|
|> Dict.insert 2 200
|
||||||
|> Dict.insert 4 300
|
|> Dict.insert 4 300
|
||||||
|
|
||||||
Dict.difference dict1 dict2
|
Dict.difference dict1 dict2
|
||||||
|> Dict.values
|
|> Dict.values
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
RocList::from_slice(&[5, 3, 1]),
|
RocList::from_slice(&[5, 3, 1]),
|
||||||
|
@ -493,7 +493,7 @@ fn walk_sum_keys() {
|
||||||
indoc!(
|
indoc!(
|
||||||
r#"
|
r#"
|
||||||
dict1 : Dict I64 I64
|
dict1 : Dict I64 I64
|
||||||
dict1 =
|
dict1 =
|
||||||
Dict.empty
|
Dict.empty
|
||||||
|> Dict.insert 1 1
|
|> Dict.insert 1 1
|
||||||
|> Dict.insert 2 2
|
|> Dict.insert 2 2
|
||||||
|
|
|
@ -399,13 +399,13 @@ fn list_walk_backwards_empty_all_inline() {
|
||||||
fn list_walk_backwards_with_str() {
|
fn list_walk_backwards_with_str() {
|
||||||
assert_evals_to!(
|
assert_evals_to!(
|
||||||
r#"List.walkBackwards [ "x", "y", "z" ] "<" Str.concat"#,
|
r#"List.walkBackwards [ "x", "y", "z" ] "<" Str.concat"#,
|
||||||
RocStr::from("xyz<"),
|
RocStr::from("<zyx"),
|
||||||
RocStr
|
RocStr
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_evals_to!(
|
assert_evals_to!(
|
||||||
r#"List.walkBackwards [ "Second", "Third", "Fourth" ] "First" Str.concat"#,
|
r#"List.walkBackwards [ "Second", "Third", "Fourth" ] "First" Str.concat"#,
|
||||||
RocStr::from("ThirdSecondFirstFourth"),
|
RocStr::from("FirstFourthThirdSecond"),
|
||||||
RocStr
|
RocStr
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -441,7 +441,7 @@ fn list_walk_backwards_with_record() {
|
||||||
fn list_walk_with_str() {
|
fn list_walk_with_str() {
|
||||||
assert_evals_to!(
|
assert_evals_to!(
|
||||||
r#"List.walk [ "x", "y", "z" ] "<" Str.concat"#,
|
r#"List.walk [ "x", "y", "z" ] "<" Str.concat"#,
|
||||||
RocStr::from("zyx<"),
|
RocStr::from("<xyz"),
|
||||||
RocStr
|
RocStr
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -454,7 +454,7 @@ fn list_walk_with_str() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn list_walk_subtraction() {
|
fn list_walk_subtraction() {
|
||||||
assert_evals_to!(r#"List.walk [ 1, 2 ] 1 Num.sub"#, 2, i64);
|
assert_evals_to!(r#"List.walk [ 1, 2 ] 1 Num.sub"#, (1 - 1) - 2, i64);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -471,11 +471,11 @@ fn list_walk_until_even_prefix_sum() {
|
||||||
assert_evals_to!(
|
assert_evals_to!(
|
||||||
r#"
|
r#"
|
||||||
helper = \a, b ->
|
helper = \a, b ->
|
||||||
if Num.isEven a then
|
if Num.isEven b then
|
||||||
Continue (a + b)
|
Continue (a + b)
|
||||||
|
|
||||||
else
|
else
|
||||||
Stop b
|
Stop a
|
||||||
|
|
||||||
List.walkUntil [ 2, 4, 8, 9 ] 0 helper"#,
|
List.walkUntil [ 2, 4, 8, 9 ] 0 helper"#,
|
||||||
2 + 4 + 8,
|
2 + 4 + 8,
|
||||||
|
|
|
@ -163,7 +163,7 @@ fn walk_sum() {
|
||||||
assert_evals_to!(
|
assert_evals_to!(
|
||||||
indoc!(
|
indoc!(
|
||||||
r#"
|
r#"
|
||||||
Set.walk (Set.fromList [1,2,3]) (\x, y -> x + y) 0
|
Set.walk (Set.fromList [1,2,3]) 0 (\x, y -> x + y)
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
6,
|
6,
|
||||||
|
|
|
@ -101,13 +101,17 @@ astar = \costFn, moveFn, goal, model ->
|
||||||
newNeighbors =
|
newNeighbors =
|
||||||
Set.difference neighbors modelPopped.evaluated
|
Set.difference neighbors modelPopped.evaluated
|
||||||
|
|
||||||
|
modelWithNeighbors : Model position
|
||||||
modelWithNeighbors =
|
modelWithNeighbors =
|
||||||
{ modelPopped &
|
{ modelPopped &
|
||||||
openSet: Set.union modelPopped.openSet newNeighbors
|
openSet: Set.union modelPopped.openSet newNeighbors
|
||||||
}
|
}
|
||||||
|
|
||||||
|
walker : Model position, position -> Model position
|
||||||
|
walker = \amodel, n -> updateCost current n amodel
|
||||||
|
|
||||||
modelWithCosts =
|
modelWithCosts =
|
||||||
Set.walk newNeighbors (\n, m -> updateCost current n m) modelWithNeighbors
|
Set.walk newNeighbors modelWithNeighbors walker
|
||||||
|
|
||||||
astar costFn moveFn goal modelWithCosts
|
astar costFn moveFn goal modelWithCosts
|
||||||
|
|
||||||
|
@ -117,17 +121,17 @@ astar = \costFn, moveFn, goal, model ->
|
||||||
# openSet: Set.remove model.openSet current,
|
# openSet: Set.remove model.openSet current,
|
||||||
# evaluated: Set.insert model.evaluated current,
|
# evaluated: Set.insert model.evaluated current,
|
||||||
# }
|
# }
|
||||||
#
|
#
|
||||||
# neighbors = moveFn current
|
# neighbors = moveFn current
|
||||||
#
|
#
|
||||||
# newNeighbors = Set.difference neighbors modelPopped.evaluated
|
# newNeighbors = Set.difference neighbors modelPopped.evaluated
|
||||||
#
|
#
|
||||||
# modelWithNeighbors = { modelPopped & openSet: Set.union modelPopped.openSet newNeighbors }
|
# modelWithNeighbors = { modelPopped & openSet: Set.union modelPopped.openSet newNeighbors }
|
||||||
#
|
#
|
||||||
# # a lot goes wrong here
|
# # a lot goes wrong here
|
||||||
# modelWithCosts =
|
# modelWithCosts =
|
||||||
# Set.walk newNeighbors (\n, m -> updateCost current n m) modelWithNeighbors
|
# Set.walk newNeighbors modelWithNeighbors (\n, m -> updateCost current n m)
|
||||||
#
|
#
|
||||||
# modelWithCosts
|
# modelWithCosts
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue