One Line of Spin Code On Two Lines
kt88seamp
Posts: 112
I have one heck of a long line of SPIN code. I like to make my code presentable when I print it. It will travel off the edge of an 8.5 x 11 sheet of paper. Is there a way, like in most progamming languages, to place the following line of code so it takes up two lines?
Registers[noparse][[/noparse]Instructions[noparse][[/noparse]Registers[noparse][[/noparse]0]] & 255] := Registers[noparse][[/noparse](Instructions[noparse][[/noparse]Registers[noparse][[/noparse]0]] & 16711680) >> 16] 'Copy source to destination.
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
Thanks, JonnyMac!
Rewriting your expression in a more readable fashion takes up exactly the same amount of Program, Var space leaving the same Stack/Free.
For example:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
If you can't figure out what code does at a glance, it's probably not very reader friendly.
I will not read code that "makes my eyes bleed" for very long even if it was written by a genius.
Long symbol names (registers, instructions, etc...) can make the task harder.
Some people like 20 letter symbols, but that's really overboard to me at least.
Use meaningful abbreviations if possible. Single letter index variables help readability
for small segments of code, but longer more descriptive variable names are better if
your code spans several screens of the editor ... which begs the question "why so long?".
PASM code may require longer names, but Spin usually does not.
The {} thing is good to know of course. You can find this and many other ideas reading posted code.
Good luck.
--Steve
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Short answers? Not available at this time since I think you deserve more information than you requested.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Signature space for rent!
Send $1 to CannibalRobotics.com.
to:
Notice also that I got rid of all the zero subscripts (they're redundant) and changed the decimal literals to hex. If a number makes more semantic sense in hex than in decimal, use hex. And always use hex or binary for a literal involved in a bitwise Boolean operation, unless it can be expressed as a single decimal digit.
But I'd take this simplification even further if it were my program:
Now it's readable!
-Phil
Better:
The precedence of shift is confusing between spin and other languages ... parens add clarity.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Short answers? Not available at this time since I think you deserve more information than you requested.
-Phil
They're also slower. The compiler is not smart enough to know that Regs[noparse][[/noparse]0] == Regs, so it generates the code for an indexed variable causing an extra stack push and pop for each iteration.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You only ever need two tools in life. If it moves and it shouldn't use Duct Tape. If it does not move and it should use WD40.
Post Edited (BradC) : 3/15/2010 11:56:01 PM GMT
Then you would really hate to see my code (which is one reason why I never post anything in the OBEX): my variable names read like short obituaries in the New York Times. And I am continuously being forced to condense the originals down to something that the Propeller can SPIN on.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Short answers? Not available at this time since I think you deserve more information than you requested.
CON
· NEXT_BLK = 0
· BLK_SIZE = 1
PRI PrintList(list)
· repeat while (list)
··· c.printf2(STRING("%8x %d\n"), list, word[noparse][[/noparse]list][noparse][[/noparse]BLK_SIZE])
··· list := word[noparse][[/noparse]list]{NEXT_BLK}
The next pointer is the first word in the header, and the block size is the second word.· I think the meaning of the last line of the function is clearer when written with the zero index then if it were just "list := word[noparse][[/noparse]list]".· By using the braces instead of brackets I don't add any extra program size or compute cycles.
Dave
That's very clever! And probably one of the few times you get anything with braces for free -- ask any orthodontist!
-Phil
All the comments are good info and I am in total agreement.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:
· Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
· Prop Tools under Development or Completed (Index)
· Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)·
· Prop OS: SphinxOS·, PropDos , PropCmd··· Search the Propeller forums·(uses advanced Google search)
My cruising website is: ·www.bluemagic.biz·· MultiBlade Props: www.cluso.bluemagic.biz