Author Topic: Braces  (Read 13902 times)

0 Members and 1 Guest are viewing this topic.

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Braces
« on: June 26, 2010, 12:41:43 am »
I don't really understand Axe's indirection function yet. {L1} and {L1+12} compile to the same amount of memory, so I'm guessing the compiler substitutes the actual value of L1 or L1+12, but that's all I can figure out. Can anyone answer these questions for me?

1. Can I use a variable inside the braces (e.g. {L1+Z*4+12})?
2. If the answer to #1 is YES, would it be more optimized to do {Z*4+L1+12} instead?
3. Can I use braces within braces (e.g. {L1+{L1+12}+24})?
4. If the answer to #3 is YES, do the nested braces act as parentheses (i.e., it's read as {L1+({L1+12})+24})?

Thanks.

EDIT: Just realized that I should have titled this topic "Braces".
« Last Edit: June 26, 2010, 06:11:23 pm by SirCmpwn »




Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: Brackets
« Reply #1 on: June 26, 2010, 12:46:07 am »
{} gets the byte the pointer points to.  0->{L1}:Disp {L1}>Dec. 0 would be displayed.
1. yes.
2. depends on your order of operations.
3. i think so, yes.
4. i think so, yes


Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55941
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Brackets
« Reply #2 on: June 26, 2010, 12:47:22 am »
I personally am more used to brackets for that stuff. I guess people might get the idea providing they check in which section the topic was posted in

_player1537

  • Guest
Re: Brackets
« Reply #3 on: June 26, 2010, 12:50:15 am »
1. yes, but its not the same size as {L1+12}
2. depends on order of operations, the example in one would do this: {((L1+Z)*4)+12}, the second one would do {((Z*4)+L1)+12}
3. yes
4. yes

also, {L1+1} is the exact same size as A, as in, these two examples will be the exact same size when compiled
{L1+1}+2->{L1+1}
A+2->A
« Last Edit: June 26, 2010, 12:52:33 am by _player1537 »

Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: Brackets
« Reply #4 on: June 26, 2010, 12:52:35 am »
wait.. i'm lost by what you guys mean by "size". all expressions within braces ({}) are one byte... and {}r is two bytes..


_player1537

  • Guest
Re: Brackets
« Reply #5 on: June 26, 2010, 12:54:54 am »
that's not what we mean by size, we mean size when compiled.  umm... not sure how to explain it...

like the larger the size, the larger the executable is
« Last Edit: June 26, 2010, 12:55:18 am by _player1537 »

Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: Brackets
« Reply #6 on: June 26, 2010, 12:57:27 am »
ohhh i got you. yeah i think it's because each paranthesis/brackets/braces counts as a certain amount of memory in the stack. so {L1} and {L1+12} take up the same amount of memory in the stack and therefore are equal in size.


Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Brackets
« Reply #7 on: June 26, 2010, 12:59:46 am »
2. depends on order of operations, the example in one would do this: {((L1+Z)*4)+12}, the second one would do

Order of operations ... forgot about that ... again :o That's why my program didn't work ... it has nothing to do with nested braces....

Thanks!
« Last Edit: June 26, 2010, 01:00:21 am by Deep Thought »




_player1537

  • Guest
Re: Brackets
« Reply #8 on: June 26, 2010, 01:01:38 am »
umm... not so much.  They take up the same size because... well, look at this
say L1 is equal to 1337
if you say {L1} you are really saying {1337}
so, if you say {L1+1} you are really saying {1338}
that said, the compiler auto detects that you are saying {1338} and changes it to that.  That is why {L1} and {L1+1} are the same size.

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Brackets
« Reply #9 on: June 26, 2010, 01:02:40 am »
It sounds like you have the right idea.  Since L1-L6 are just numbers, it makes sense for the compiler to add/subtract/multiply/divide etc. to create a single number BEFORE parsing so that the program doesn't have to do it during runtime.  However, if you have any variables or non-constants then the compiler can not make this optimization and the size will increase.

Your 2 examples {L1+Z*4+12} and {Z*4+L1+12} would return different values as some people have said due to strict left-to-right order of operations.  However, I assume you are asking about the difference between {L1+(Z*4)+12} and {Z*4+L1+12} and in that case, YES, the second one is more optimized since L1 and 12 are combined to form a single number that will get added to the variable part.

You can use as many braces inside of braces as the stack can handle and yes, they act like parenthesis when you use them that way.  You can read from expressions with nested braces and store to them.  But of course, the less parenthesis you need, the more optimized it is.  If its possible try to put all that stuff at the front. {{L1+12}+L1+24} is more optimized than {L1+{L1+12}+24} for the reason above in addition to the fewer acting "parenthesis".
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Brackets
« Reply #10 on: June 26, 2010, 01:03:50 am »
Oh, so Axe detects whether or not there's external data within the brackets. That's pretty smart.




Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55941
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Brackets
« Reply #11 on: June 26, 2010, 01:06:28 am »
Yup. It can be rather useful for some complicated RPGs. In TI-BASIC, I often did stuff like L3(A+L3(Z)), for example. If I remember, ROL2 required a lot of those

Keep in mind it can eventually make your code hard to read, though, especially if you decide to put a project on hold for a while.

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Brackets
« Reply #12 on: June 26, 2010, 01:13:06 am »
That's exactly what's happening now. I'm afraid that in two months, my code will be completely illegible to myself (I've used statements containing 16 or more L1's.




Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Brackets
« Reply #13 on: June 26, 2010, 01:15:21 am »
That's what comments are for ;D  You should see Runer's Sprite Editor source, more than half of the size of the program was indents and comments.  That's another paradigm that BASIC programmers are too used to, commenting in the code doesn't affect the final executable at all since they are all ignored when compiling.  In BASIC however, its seen as wasteful since it becomes part of the program.
« Last Edit: June 26, 2010, 01:17:23 am by Quigibo »
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55941
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Brackets
« Reply #14 on: June 26, 2010, 01:18:43 am »
True, altough when you got several KB of data, you need to tone down on the comments a lot D:

I guess one advantage of TI-BASIC programming is that we learn to code without commenting ;D but in more complex languages, this could be a bad practice x.x (like ASM)
« Last Edit: June 26, 2010, 01:20:01 am by DJ Omnimaga »