diff --git a/impls/awk/core.awk b/impls/awk/core.awk index e7dc0b98fb..93a18ec759 100644 --- a/impls/awk/core.awk +++ b/impls/awk/core.awk @@ -19,11 +19,14 @@ function core_eq_sub(lhs, rhs, i, len) } else if (lhs ~ /^\{/ && rhs ~ /^\{/) { lhs = substr(lhs, 2) rhs = substr(rhs, 2) - if (length(types_heap[lhs]) != length(types_heap[rhs])) { + if ( length(types_heap[lhs]) - ("meta" in types_heap[lhs]) != \ + length(types_heap[rhs]) - ("meta" in types_heap[rhs]) ) + { return 0 } for (i in types_heap[lhs]) { - if (types_heap[lhs][i] ~ /^["':+#([{?&$%]/ && + if ( i != "meta" && + types_heap[lhs][i] ~ /^["':+#([{?&$%]/ && !core_eq_sub(types_heap[lhs][i], types_heap[rhs][i])) { return 0 } diff --git a/impls/chuck/types/subr/MalDissoc.ck b/impls/chuck/types/subr/MalDissoc.ck index d25990dceb..1c89842e3b 100644 --- a/impls/chuck/types/subr/MalDissoc.ck +++ b/impls/chuck/types/subr/MalDissoc.ck @@ -6,11 +6,11 @@ public class MalDissoc extends MalSubr MalObject.slice(args, 1) @=> MalObject ks[]; MalObject result[0]; - int cachedKeys[0]; + string cachedKeys[0]; for( 0 => int i; i < ks.size(); i++ ) { - true => cachedKeys[ks[i].stringValue]; + ks[i].type => cachedKeys[ks[i].stringValue]; } for( 0 => int i; i < map.size(); 2 +=> i ) @@ -18,7 +18,8 @@ public class MalDissoc extends MalSubr map[i] @=> MalObject key; map[i+1] @=> MalObject value; - if( !cachedKeys[key.stringValue] ) + if ( cachedKeys[key.stringValue] == null + || cachedKeys[key.stringValue] != key.type ) { result << key; result << value; diff --git a/impls/chuck/types/subr/MalGet.ck b/impls/chuck/types/subr/MalGet.ck index 5ff909056f..6d95072444 100644 --- a/impls/chuck/types/subr/MalGet.ck +++ b/impls/chuck/types/subr/MalGet.ck @@ -20,7 +20,7 @@ public class MalGet extends MalSubr map[i] @=> mapKey; map[i+1] @=> mapValue; - if( keyName == mapKey.stringValue ) + if( keyName == mapKey.stringValue && args[1].type == mapKey.type ) { true => isKeyPresent; } diff --git a/impls/chuck/types/subr/MalIsContains.ck b/impls/chuck/types/subr/MalIsContains.ck index 73c366f129..10c5105a44 100644 --- a/impls/chuck/types/subr/MalIsContains.ck +++ b/impls/chuck/types/subr/MalIsContains.ck @@ -14,7 +14,7 @@ public class MalIsContains extends MalSubr { map[i] @=> mapKey; - if( keyName == mapKey.stringValue ) + if( keyName == mapKey.stringValue && args[1].type == mapKey.type ) { true => isKeyPresent; } diff --git a/impls/vhdl/core.vhdl b/impls/vhdl/core.vhdl index 2b6523671a..b904dc0c12 100644 --- a/impls/vhdl/core.vhdl +++ b/impls/vhdl/core.vhdl @@ -260,9 +260,13 @@ package body core is end procedure fn_vector_q; procedure fn_hash_map(args: inout mal_val_ptr; result: out mal_val_ptr; err: out mal_val_ptr) is + variable new_map: mal_val_ptr; begin - args.val_type := mal_hashmap; - result := args; + new_empty_hashmap(new_map); + for i in 0 to args.seq_val'length / 2 - 1 loop + hashmap_put(new_map, args.seq_val(2*i), args.seq_val(2*i+1)); + end loop; + result := new_map; end procedure fn_hash_map; procedure fn_map_q(args: inout mal_val_ptr; result: out mal_val_ptr; err: out mal_val_ptr) is diff --git a/impls/vhdl/reader.vhdl b/impls/vhdl/reader.vhdl index f057fb7efb..f8f07d2356 100644 --- a/impls/vhdl/reader.vhdl +++ b/impls/vhdl/reader.vhdl @@ -273,6 +273,22 @@ package body reader is new_seq_obj(list_type, seq, result); end procedure read_sequence; + procedure read_map(r: inout reader_class; result: out mal_val_ptr; err: out mal_val_ptr) is + variable sub_seq, sub_err, new_map: mal_val_ptr; + begin + read_sequence(mal_hashmap, "}", r, sub_seq, sub_err); + if sub_err = null then + new_empty_hashmap(new_map); + for i in 0 to sub_seq.seq_val'length / 2 - 1 loop + hashmap_put(new_map, sub_seq.seq_val(2*i), sub_seq.seq_val(2*i + 1)); + end loop; + result := new_map; + else + err := sub_err; + result := null; + end if; + end procedure read_map; + procedure reader_macro(r: inout reader_class; result: out mal_val_ptr; err: out mal_val_ptr; sym_name: in string) is variable token, sym_line: line; variable seq: mal_seq_ptr; @@ -343,7 +359,7 @@ package body reader is when ')' => new_string("unexcepted ')'", err); when '[' => read_sequence(mal_vector, "]", r, result, err); when ']' => new_string("unexcepted ']'", err); - when '{' => read_sequence(mal_hashmap, "}", r, result, err); + when '{' => read_map(r, result, err); when '}' => new_string("unexcepted '}'", err); when others => read_atom(r, result, err); end case;