$addr = $self->process($addr) if ref $addr eq 'ARRAY';
die 'Addr of toplevel is not atom: ', Dumper($addr), "\n" unless scalarp($addr);
+ my ($comment_type, $comment_addr) = ($type, $addr);
+
unless (looks_like_number $addr) { # is symbol
unless (exists $self->{symbols}{$addr}) {
$self->{symbols}{$addr} = $self->{nsymbols};
$location = $self->{freeptr}
}
$self->{memory}[$location] = $result;
+ $self->{comment}[$location] = "$comment_type $comment_addr";
$location
}
sub finish {
my ($self) = @_;
$self->{memory}[5] = $self->{memory}[$self->{freeptr}];
+ $self->{comment}[5] = $self->{comment}[$self->{freeptr}];
$self->{memory}[4] = $self->{freeptr};
delete $self->{memory}[$self->{freeptr}]
}
$args{symbols}{NIL} = 0;
$args{symbols}{T} = 1;
$args{nsymbols} = 2;
+ $args{comment} = ['(cdr part of NIL)', '(car part of NIL)', '(cdr part of T)', '(car part of T)', '(free storage pointer)', '', '(result of computation)'];
bless \%args, $class
}
$fh //= \*STDOUT;
my $bits = $self->{type_bits} + $self->{addr_bits};
+ my $index_length = length $#{$self->{memory}};
+ my $index_format = '%' . $index_length . 'd';
for my $index (0 .. $#{$self->{memory}}) {
my $val = $self->{memory}[$index];
+ my $comment = $self->{comment}[$index];
if ($index == 4) {
$val = "${bits}'d$val"
} else {
$val = $val ? sprintf "%d'b%0${bits}b", $bits, $val : '0';
}
- say $fh "mem[$index] <= $val;"
+ my $spaces = ' ' x ($bits + 5 - (length $val));
+ $index = sprintf $index_format, $index;
+ say $fh "mem[$index] <= $val;$spaces // $comment"
}
}