| Jackson Marie (450) | |
| Nobody? Is there any method which can do better than the method "converting to int"??? | |
|
|
|
| helios (10126) | |||
|
Well, bitwise operations only make sense when performed on integer values. "1.5 XOR 2.3" is as meaningful as "the integer whose double is 1". EDIT: You could do something like this:
| |||
|
Last edited on
|
|||
| Jackson Marie (450) | |||
|
I've tried finding & performing lots of bitwise operators and modulus commands by many methods. And finally I've found the solution!!!!! You'll need to insert a temporary variable (unsigned) among the conversion expressions (integer or decimal). It doesn't affect the result and help the computer fixing the decimal calculation errors. And, that solution will completely solve the (bit) float-double problem and improve the accuracy of decimal calculation. In short it's very efficiency and you... should try it! :) How to do this : - Define a magnification power value. (10x - 100x - 1000x - ....x) Note : The decimal accuracy is dependent of the magnification power. - Multiply both two expressions. (Note : convert to unsigned) - Zoom!!! - Calculate!!! - Finally you will need to recovery the original value. (Zoom out) And, an example code (modulus) :
What do you think? Is this a good idea? :) | |||
|
Last edited on
|
|||
| hamsterman (4325) | |
| So you need http://cplusplus.com/reference/cmath/modf/ ? | |
|
|
|
| Jackson Marie (450) | |
|
No no...modf doesn't perform my expected command (modulus a decimal value) But, can I apply this method above for bitwise operator commands? | |
|
Last edited on
|
|
| helios (10126) | ||||
The function is fmod(), not modf() (who came up with that?).
fmod(d,(double)5);If for some strange reason you still don't want to use fmod(), this is a better hand-coded solution:
What the eff does this have to do with implementing a language, anyway? | ||||
|
|
||||
| Jackson Marie (450) | |||
Here, take my interpreter code as an example :
Any suggestion? | |||
|
Last edited on
|
|||
| Jackson Marie (450) | |
| See my general interpreter code structure above... | |
|
|
|
| Jackson Marie (450) | |
| Oh.. I'm very tired.. (=.=) | |
|
|
|
| helios (10126) | |
|
I see code. I don't see interpreter code. And your style sucks ass. This may be relevant later on. You should at least be able to get some ideas out of it: http://www.cplusplus.com/forum/lounge/11845/ | |
|
|
|
| EssGeEich (681) | |||
+1. You're not probably even on the right way to get everything optimized easily - But besides that you will have big troubles expanding the project. Also redefining Null to a negative floating-point value? Woah. Macros? You're on C++. You probably need to learn some more things on the world of C++ and assembly before jumping into it - But it's also good to learn on-the-way. The most useful thing you must be able to do is calling a function from an external module (for Win32: LoadLibrary, GetProcAddress and FreeLibrary) and calling it with a number of parameters chosen at runtime. Quite impossible unless you have some asm experience. Also you will have to store the return value. You can do them both by asm inlining. Sure you can , I did my own interpreter a couple months ago which allowed for memory handling, heap memory and pointers handling, basic math operations, floating point handling, asm-like calling of external functions, jump/call/ret "emulation" and so on, all from a interactive console with the ability to load an external script file... (By the way it also has localized informations about errors, in case you push too many/too few parameters) | |||
|
Last edited on
|
|||
| Jackson Marie (450) | |
| If there any method which can call a function indirectly (especially Unlimited function parameters (printf, sprintf,...)) Does asm C++ support this feature? And how to do this? | |
|
Last edited on
|
|
| EssGeEich (681) | |
|
Well you need to understand calling conventions, there are four main calling conventions: stdcall: http://www.nynaeve.net/?p=53 cdecl: http://www.nynaeve.net/?p=41 thiscall: http://www.nynaeve.net/?p=73 fastcall: http://www.nynaeve.net/?p=63 Everything you need to know is in the C/C++ header files, and is different for each function. I'd say printf is cdecl on MSVS10. Be sure to support both cdecl and stdcall at least: Windows API uses stdcall. C Stdlib uses cdecl - At least vs10's does. | |
|
|
|
| Jackson Marie (450) | |
|
To call a function I know I have push the variable object or with a register value buffer, then call it, then check the ESP value (I'm not sure)... I have no idea how to call a function by assemmbly C++... Do you know how? | |
|
|
|
| chrisname (5896) | |
| You can (edit: probably) do it with C++11's variadic templates and brace initialisers. I'd figure out how to actually write it, but my compiler (cygwin-g++ 4.5.3) doesn't fully support variadic templates yet. | |
|
Last edited on
|
|
| Jackson Marie (450) | |
|
I think your method is very convenient. :) A command in general is very different (Function name, parameter list type, number of parameters, returning value...) So, the only method is using assembly (I'm sure that C++ asm should support?) So it's really a main problem. | |
|
Last edited on
|
|
| chrisname (5896) | |
| Why do you want to use assembly? It's not a good idea if you don't need it. | |
|
|
|
| Jackson Marie (450) | |
| Yes, I'm confused - means I want to call a function which supports unlimited parameters (printf, sprintf). But, is there any class which can do this? It's valid when you know exactly the number of parameters that the program will call, and otherwise? 5 - 9 - 35??? Any solution? | |
|
Last edited on
|
|
| Jackson Marie (450) | |
|
@EssGeIsh Can you tell me some programs which are done by your interpreter... I'd like to see them XDXD... Now I realized that nothing is impossible... | |
|
|
|
| TheIdeasMan (1562) | |||
|
@JM With reference to your Code style thread and this one, I hope you can see that I am not the only one who thinks that your style is bad, and knowledge lacking. I sincerely hope you take on board what I said to you - especially about giving advice to others. Another problem I think you have, is you don't understand enough C++ to understand the code in links given to you - like helios's link above. So if you still insist (rather stubbornly IMO) on trying this interpreter, why don't you start with something really easy, get it working, then add more functionality incrementally, instead of jumping straight into something complex like variable length argument lists, and dozens of other potentially tricky things. This is a main concept for software development, along with the "Divide & Conquer" concept. For example you need to define what the syntax is going to look like, what are the types & operators going to look like? Try to get this working first:
This obviously uses C operators, which probably the easiest thing, instead of inventing your own. However you do have do something to separate your language from others - there is no point otherwise. So this example only has 'Integer' instead of 'int' as a type, and the display function, instead of cout. Edit: This is trickier than it looks, you have to handle negative numbers, errors like non declaration and non initialisation, missing semicolons, poorly formed tokens (types & variable names), varying amounts of white space etc. If you want something much easier, try implementing a Reverse Polish Notation (RPN) calculator. It uses a stack. The algorithm is: If it is a number push onto stack, if it is an operator, pop the stack and do the calculation. Do some research of your own and see if you can come with some code. | |||
|
Last edited on
|
|||