Re: [stella] Reflex: Source of PAIN!

Subject: Re: [stella] Reflex: Source of PAIN!
From: "B. Watson" <atari@xxxxxxxxxxxxxx>
Date: Mon, 5 Apr 2004 14:35:20 -0400 (EDT)

On Mon, 5 Apr 2004 KirkIsrael@xxxxxxxxxxxxx wrote:

> Can anyone think of a good way of automagically (maybe macro based?)
> finding instances of of using something that's "obviously" a Constant
> as a variable, i.e. the ubiquitous newbie mistake of leaving out the
> "#"?

Well... not really.

>
> I can think of 2 or 3 ways, but I'm not sure what's automatable inside
> of DASM or a text editor:
>
> * a pseudohungarian notation for constants would be easy to find in
>   an editor: do a text search for " CONST" -- that's an error, but
>   the use of CONST_ or whatever prefix is a bit inelegant.

Just C_ maybe? This is probably the best of the 3 ideas.. could test for
it with a perl script:

#!/usr/bin/perl -w

$a = $ARGV[0];

while(<>) {
	warn "$a:$.: Dubious use of constant: $_" if /\sC_/;
}

__END__

(actually, if you have perl installed & on your PATH, you can just save
a copy of this email and run `perl -x email.txt filename.asm' to test
the script.)

The script spits out errors in the format:

foo.asm:16: Dubious use of constant:  lda C_BLAH

...which is standard enough that editors like vim and emacs can parse
it and position the cursor at the right line (16, in the example) where
the error/warning is. I dunno what editors in the Windows world might
know how to parse this, but any good editor on any platform should be
scriptable enough to implement it.

If you're using a Makefile to build your bin, you could add a rule like:

test:
	perl test.pl foo.asm

...and then make `test' a dependency for your `all' rule.

> * Any argument that is all in caps should probably be proceeded by
>   a #, always. Is there a way of DASM macroing that? (and are there
>   exceptions to that rule, assuming non-cowboy programming?)

Plenty of exceptions: The TIA/RIOT constants in vcs.h are always CAPS,
and when you want to read a register (LDA INTIM, for example), you *don't*
use a # in front.

Also (if I get a vote) I vote for never forcing people to use a
particular coding style (including capitalization schemes). Some people
find ALL_UPPER or camelCase highly annoying (I do, even though I use
the latter in Java every day).

Yes, using the standard vcs.h `forces' everyone to capitalize the labels
defined there, but that's part of vcs.h, not built into the assembler
itself. Even the Java compiler will accept all-lowercase names.

> * optionally, I could see some rule where a comment proceeds and follows
>   the "constants section", any reference defined in there without the
>   "#" is likely a problem. This would be easy to make a perl script for,
>   don't know if it's any easier for DASM.

What would be nice would be to have DASM *not* allow the # where it
doesn't make sense. Stuff like `byte #%10101010' is accepted, and
shouldn't be. Having DASM be strict about this would help newbies
understand what the # is actually for, IMO.

Just my $0.02 worth...

--
B.
----------------------------------------------------------------------------------------------
Archives (includes files) at http://www.biglist.com/lists/stella/archives/
Unsub & more at http://www.biglist.com/lists/stella/


Current Thread