wonder Expert Licensed User Longtime User Aug 2, 2016 #1 Can we have it the "old-school" way (| & ^ >> << ~)? Take for example this expression: Code: Copy int rgb = ((r & 0x0ff) << 16) | ((g & 0x0ff) << 8) | (b & 0x0ff); The B4X equivalent is terribly long: Code: Copy Dim rgb = Bit.Or(Bit.Or(Bit.ShiftLeft(Bit.And(r, 0x0ff), 16), Bit.ShiftLeft(Bit.And(g, 0x0ff), 8)), Bit.And(b, 0x0ff)) As Int I'm not even sure if I got it right, such is the reduced readability... Can we do something about it? Many thanks in advance! PS: It would be nice to have, at least, a parser. Something like this: Code: Copy Dim rgb = Bit.ParseString("((r & 0x0ff) << 16) | ((g & 0x0ff) << 8) | (b & 0x0ff)") As Int Last edited: Aug 2, 2016
Can we have it the "old-school" way (| & ^ >> << ~)? Take for example this expression: Code: Copy int rgb = ((r & 0x0ff) << 16) | ((g & 0x0ff) << 8) | (b & 0x0ff); The B4X equivalent is terribly long: Code: Copy Dim rgb = Bit.Or(Bit.Or(Bit.ShiftLeft(Bit.And(r, 0x0ff), 16), Bit.ShiftLeft(Bit.And(g, 0x0ff), 8)), Bit.And(b, 0x0ff)) As Int I'm not even sure if I got it right, such is the reduced readability... Can we do something about it? Many thanks in advance! PS: It would be nice to have, at least, a parser. Something like this: Code: Copy Dim rgb = Bit.ParseString("((r & 0x0ff) << 16) | ((g & 0x0ff) << 8) | (b & 0x0ff)") As Int
ggpanta Member Licensed User Longtime User Aug 8, 2016 #2 I have had the same issue numerous times, the B4A notation is making simple expressions really convoluted, and unreadable. I wish the standard C notation was implemented since most other languages follow it. Try to write this in B4A please and you will understand: int binary = ((hash[offset] & 0x7f) << 24) | ((hash[offset + 1] & 0xff) << 16) | ((hash[offset + 2] & 0xff) << 8) | (hash[offset + 3] & 0xff);
I have had the same issue numerous times, the B4A notation is making simple expressions really convoluted, and unreadable. I wish the standard C notation was implemented since most other languages follow it. Try to write this in B4A please and you will understand: int binary = ((hash[offset] & 0x7f) << 24) | ((hash[offset + 1] & 0xff) << 16) | ((hash[offset + 2] & 0xff) << 8) | (hash[offset + 3] & 0xff);
stanmiller Active Member Licensed User Longtime User Aug 18, 2016 #3 wonder said: Can we have it the "old-school" way (| & ^ >> << ~)? PS: It would be nice to have, at least, a parser. Something like this: Code: Copy Dim rgb = Bit.ParseString("((r & 0x0ff) << 16) | ((g & 0x0ff) << 8) | (b & 0x0ff)") As Int Click to expand... Like this? Code: Copy Dim cb as Codeblock cb.Compile("{|r,g,b|((r & 0x0ff) << 16) | ((g & 0x0ff) << 8) | (b & 0x0ff)}") rgb1 = cb.Eval2( Array( 96, 53, 36 ) ) rgb2 = cb.Eval2( Array( 36, 37, 96 ) )
wonder said: Can we have it the "old-school" way (| & ^ >> << ~)? PS: It would be nice to have, at least, a parser. Something like this: Code: Copy Dim rgb = Bit.ParseString("((r & 0x0ff) << 16) | ((g & 0x0ff) << 8) | (b & 0x0ff)") As Int Click to expand... Like this? Code: Copy Dim cb as Codeblock cb.Compile("{|r,g,b|((r & 0x0ff) << 16) | ((g & 0x0ff) << 8) | (b & 0x0ff)}") rgb1 = cb.Eval2( Array( 96, 53, 36 ) ) rgb2 = cb.Eval2( Array( 36, 37, 96 ) )
wonder Expert Licensed User Longtime User Aug 19, 2016 #4 Wow!! Nice!!! But tell me... where is that "CodeBlock" coming from?
stanmiller Active Member Licensed User Longtime User Aug 19, 2016 #5 It's from our soon to be released MTEEVAL library (w/ full source). MTEEVAL implements a stack based expression compiler. Modifying the source you can support any expression your project needs like the hypothetical bitwise op example above.
It's from our soon to be released MTEEVAL library (w/ full source). MTEEVAL implements a stack based expression compiler. Modifying the source you can support any expression your project needs like the hypothetical bitwise op example above.
wonder Expert Licensed User Longtime User Aug 19, 2016 #6 That's great!! I'm looking forward into it!!!
NJDude Expert Licensed User Longtime User Aug 19, 2016 #7 Before you release it, better correct that typo: It should be: DoModulus not Modulous.
stanmiller Active Member Licensed User Longtime User Aug 19, 2016 #8 NJDude said: Before you release it, better correct that typo: It should be: DoModulus not Modulous. Click to expand... Oops! Actually it should be DoModulo. Modulo Operation https://en.wikipedia.org/wiki/Modulo_operation
NJDude said: Before you release it, better correct that typo: It should be: DoModulus not Modulous. Click to expand... Oops! Actually it should be DoModulo. Modulo Operation https://en.wikipedia.org/wiki/Modulo_operation
stanmiller Active Member Licensed User Longtime User Aug 23, 2016 #9 I'm working on the decompiler as we speak, but we should have the library posted later today. Source code will be maintained here: https://github.com/macthomasengineering/mteeval-b4x-library Currently the compiler supports basic math operators +-*/ but you could add bit shifting without too much drama. You would tuck it in around here. And then add the instructions to the machine. Last edited: Aug 23, 2016
I'm working on the decompiler as we speak, but we should have the library posted later today. Source code will be maintained here: https://github.com/macthomasengineering/mteeval-b4x-library Currently the compiler supports basic math operators +-*/ but you could add bit shifting without too much drama. You would tuck it in around here. And then add the instructions to the machine.
wonder Expert Licensed User Longtime User Aug 23, 2016 #10 How do you get stuff compiled into machine code with B4A?
stanmiller Active Member Licensed User Longtime User Aug 23, 2016 #11 wonder said: How do you get stuff compiled into machine code with B4A? Click to expand... When you own the CPU, anything is possible. Decompiler is done too. I'm meeting a client soon. When I get back, I'll package all this up and post the library and source.
wonder said: How do you get stuff compiled into machine code with B4A? Click to expand... When you own the CPU, anything is possible. Decompiler is done too. I'm meeting a client soon. When I get back, I'll package all this up and post the library and source.
wonder Expert Licensed User Longtime User Aug 23, 2016 #12 Wow!! So did you use B4A to create a virtual machine that runs on the Dalvik virtual machine, which in turn, can also run in my Android virtual machine on my real x86 machine PC???? I can't wait to give it a test drive!!
Wow!! So did you use B4A to create a virtual machine that runs on the Dalvik virtual machine, which in turn, can also run in my Android virtual machine on my real x86 machine PC???? I can't wait to give it a test drive!!
stanmiller Active Member Licensed User Longtime User Aug 24, 2016 #13 Yes, the blue pill is chosen. Library and demo posted here: https://www.b4x.com/android/forum/t...-compiler-and-eval-library-open-source.70299/ Source for all platforms at Github https://github.com/macthomasengineering/mteeval-b4x-library
Yes, the blue pill is chosen. Library and demo posted here: https://www.b4x.com/android/forum/t...-compiler-and-eval-library-open-source.70299/ Source for all platforms at Github https://github.com/macthomasengineering/mteeval-b4x-library
wonder Expert Licensed User Longtime User Nov 24, 2016 #14 @Erel, will you take this request into consideration? Using Bit.Something() is fine for simple operations, but when you need to read "a few" bits and combine "a few" bytes, it becomes a nightmare, in terms of readability.
@Erel, will you take this request into consideration? Using Bit.Something() is fine for simple operations, but when you need to read "a few" bits and combine "a few" bytes, it becomes a nightmare, in terms of readability.
Erel B4X founder Staff member Licensed User Longtime User Nov 24, 2016 #15 It might be added. The & operator is already used in B4X which makes it a bit problematic.
wonder Expert Licensed User Longtime User Nov 24, 2016 #16 Thank you! I'm not asking for a replacement, only for an alternative syntax... This way, I believe beginners and experts would be both happy. Regarding the "&" operator, hopefully it can be segregated into bitwise or string concatenation, depending on context, something like: If betweenStrings or betweenChars Then IsConcatenator = TRUE
Thank you! I'm not asking for a replacement, only for an alternative syntax... This way, I believe beginners and experts would be both happy. Regarding the "&" operator, hopefully it can be segregated into bitwise or string concatenation, depending on context, something like: If betweenStrings or betweenChars Then IsConcatenator = TRUE