Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions impls/awk/core.awk
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
7 changes: 4 additions & 3 deletions impls/chuck/types/subr/MalDissoc.ck
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@ 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 )
{
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;
Expand Down
2 changes: 1 addition & 1 deletion impls/chuck/types/subr/MalGet.ck
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion impls/chuck/types/subr/MalIsContains.ck
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 6 additions & 2 deletions impls/vhdl/core.vhdl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 17 additions & 1 deletion impls/vhdl/reader.vhdl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down