From: Erich W. <ew....@na...> - 2012-10-11 19:24:45
|
Hi Enoch, On 10/11/2012 09:03 PM, Enoch wrote: > This brings me to a more fundamental question which you, as Amforth's > BDFL, I feel, need to address. > > Amforth-shell.py turns the use of frt "&34 constant PORTA" definitions > in the code unnecessary as the shell script does these substitutions for > you (and saves flash memory). It is great for educational purposes but > it creates dependence on loading of the code through amforth-shell.py > only. I think Forth tradition is against that, it was supposed to be > self contained and operated through a simple terminal... > > What is your recommended practice? I'm having a similar opinion. amforth-shell.py is impressive, no question. However, IMHO it blurs the line between "what _I_ know" and "what the machine knows for me", a state which I'm not too fond of. Your mileage may vary. So according to "make one programm do one thing well" I have created two little perl filters, one will recursively expand all "include"s in a file and produce the expanded code, the other is stripping comments and empty lines, just to reduce the number of transferred bytes (it may destroy ." ..." strings though). The I use amforth-upload.py to transfer the stripped file. Since I'm very lazy, I have hacked up a Makefile snippet to do this for me: --- Makefile ----------------------------------------------------- ... TARGET=main CONSOLE=/dev/ttyUSB0 ... upload_file: cat $(TARGET).fs | unfold_fs > $(TARGET).fs.unfold trim_fs $(TARGET).fs.unfold > $(TARGET).fs.upload upload: upload_file amforth-upload.py -t $(CONSOLE) $(TARGET).fs.upload --- unfold_fs ----------------------------------------------------- #!/usr/bin/perl # 2007-12-08 EW # # filter, read all input, expand lines like # "^include filename$" # with the content found in filename # # this is written unfold amforth projects before # transferring them to the target controller. use warnings; use strict; my $Prog=$0; my $file=""; my $pattern='^[#]*include\s+(\S+)'; my $comment='\ ---'; my $verbose=0; while (<>) { if (m/$pattern/) { $file = "$1"; print STDERR " $file\n" if ($verbose); if (not -r $file) { print STDERR "$Prog: file $file not found!\n"; exit 2; } print "$comment include begin $file\n"; system("$Prog $file") == 0 or die "failed.\n"; print "$comment include end $file\n"; } else { print $_; } } --- trim_fs ------------------------------------------------------- #!/usr/bin/perl # 2007-12-08 EW # trim_fs # # filter, remove comments, leading and trailing whitespace and empty lines # # this is written to trim unfolded amforth projects use warnings; use strict; while (<>) { chomp; s/\\[ \t].*$//; # remove line comments s/\( .* \)//; # remove inline comments #s/^\s+//; # delete leading whitespace / well no, keep indendation s/\s+$//; # delete trailing whitespace s/\b\s+/ /g; # compress white space after first word next if /^$/; # delete empty lines print "$_\n"; } ------------------------------------------------------------------- If you or anyone on the list likes this, feel free to use or adapt it to your needs. Cheers, Erich |