projects
/
app-scheme79asm.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
4a9c3fa
)
Comments
author
Marius Gavrilescu
<marius@ieval.ro>
Sat, 10 Feb 2018 18:25:29 +0000
(18:25 +0000)
committer
Marius Gavrilescu
<marius@ieval.ro>
Sat, 10 Feb 2018 18:25:29 +0000
(18:25 +0000)
lib/App/Scheme79asm.pm
patch
|
blob
|
blame
|
history
diff --git
a/lib/App/Scheme79asm.pm
b/lib/App/Scheme79asm.pm
index e0bec36c64c32388335bd625fbacf63b36c6b0ed..c971c2cd2930905b25f284aef796d6934a135b6c 100644
(file)
--- 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);
$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};
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;
$location = $self->{freeptr}
}
$self->{memory}[$location] = $result;
+ $self->{comment}[$location] = "$comment_type $comment_addr";
$location
}
$location
}
@@
-101,6
+104,7
@@
sub parse {
sub finish {
my ($self) = @_;
$self->{memory}[5] = $self->{memory}[$self->{freeptr}];
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}]
}
$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{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
}
bless \%args, $class
}
@@
-122,14
+127,19
@@
sub print {
$fh //= \*STDOUT;
my $bits = $self->{type_bits} + $self->{addr_bits};
$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];
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';
}
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"
}
}
}
}
This page took
0.01173 seconds
and
4
git commands to generate.