From: Marius Gavrilescu Date: Sat, 10 Feb 2018 18:25:29 +0000 (+0000) Subject: Comments X-Git-Tag: 0.001001~4 X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=34073a4a81787bd2934f5a82ab6ef7ed261c9451;p=app-scheme79asm.git Comments --- diff --git a/lib/App/Scheme79asm.pm b/lib/App/Scheme79asm.pm index e0bec36..c971c2c 100644 --- a/lib/App/Scheme79asm.pm +++ b/lib/App/Scheme79asm.pm @@ -58,6 +58,8 @@ sub process { $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}; @@ -83,6 +85,7 @@ sub process { $location = $self->{freeptr} } $self->{memory}[$location] = $result; + $self->{comment}[$location] = "$comment_type $comment_addr"; $location } @@ -101,6 +104,7 @@ sub parse { 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}] } @@ -114,6 +118,7 @@ sub new { $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 } @@ -122,14 +127,19 @@ sub print { $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" } }