Open Turing - 20-40% Faster Open Source Version of Turing With New Features
Author |
Message |
Insectoid
|
Posted: Sat Nov 19, 2011 8:32 am Post subject: RE:Open Turing - 20-40% Faster Open Source Version of Turing With New Features |
|
|
Quote: eginner turing programmers often using pic.screenload every frame in their games, which is slow.
You shouldn't reward them for doing this though. This is bad programming. Because it is slow, they have to find another (usually better) way to do it. Not to say caching images is bad at all (it's awesome!). This is just a poor justification.
I wouldn't mind delving into this. People have been waiting for years for open-source Turing. Hopefully, we can convince teachers who still use Turing (it's still not a bad language to learn on) to move on to this updated version. This has the potential to completely revive the language.
Would it be too much to ask for code to be re-written with platform portability in mind? I know this is far, far away from compiling into an OS X binary but if Windows-specific code is encountered that isn't too difficult to modify to run on other OSs, why not? Maybe I'll make that my project. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
DemonWasp
|
Posted: Sat Nov 19, 2011 11:20 am Post subject: RE:Open Turing - 20-40% Faster Open Source Version of Turing With New Features |
|
|
The use of maps (and lists, sets, etc) can and should be a lot easier:
Turing: |
var map1 : map from string to int
var map2 : map from string to my_record_type
var map3 : map from string to list of array 0..2 of int
% Two main possibilities for operations. First, the "Turing" way, which is pretty much the C way:
Map.Put ( map1, "key", value )
Map.Get ( map1, "key" )
Map.Remove ( map3, "key" )
Map.RemoveValue ( map3, value )
Map.Contains ( map2, "key" )
Map.ContainsValue ( map1, 5 )
% ...etc
% Second, we use notation seen elsewhere, largely in arrays, but also in integers; comparisons use subject-verb-object order, like English:
map1 ( "key" ) := value
map1 ( "key" ) % like an array
map3 remove "key"
map3 -= "key"
map3 removeValue value
map2 contains "key"
map1 containsValue 5
% E.g.
if player_map contains "foo" then
dead_player_map put "foo"
end if
|
|
|
|
|
|
|
trishume
|
Posted: Sun Nov 20, 2011 1:59 pm Post subject: Re: Open Turing - 20-40% Faster Open Source Version of Turing With New Features |
|
|
Yes, HashMaps do suck right now. For the pass by reference, I (or someone else) could add a version that returns zero for nonexistent keys and an exists function.
In terms of syntax. I know there could be a nice syntax, but that would require heavy modification of machine generated code.
For commenting the VM and parser, I don't think it is worth it.
It would be more worthwhile to just use a JIT library to create a readable, friggin fast, cross platform VM.
The current VM is technically cross-platform but there is so much device dependent grapics and other code that would have to be rewritten. |
|
|
|
|
|
trishume
|
Posted: Sun Nov 20, 2011 2:08 pm Post subject: Re: RE:Open Turing - 20-40% Faster Open Source Version of Turing With New Features |
|
|
Insectoid @ Sat Nov 19, 2011 8:32 am wrote: Quote: eginner turing programmers often using pic.screenload every frame in their games, which is slow.
You shouldn't reward them for doing this though. This is bad programming. Because it is slow, they have to find another (usually better) way to do it. Not to say caching images is bad at all (it's awesome!). This is just a poor justification.
I wouldn't mind delving into this. People have been waiting for years for open-source Turing. Hopefully, we can convince teachers who still use Turing (it's still not a bad language to learn on) to move on to this updated version. This has the potential to completely revive the language.
Would it be too much to ask for code to be re-written with platform portability in mind? I know this is far, far away from compiling into an OS X binary but if Windows-specific code is encountered that isn't too difficult to modify to run on other OSs, why not? Maybe I'll make that my project.
I'm not rewarding them, it just makes it easier for beginners. The compsci teacher at our school doesn't teach the faster method and few people find it in the docs.
Yes, beginners would be better off with Pic.FileNew but try would also be better off using test driven development and factory patterns and whatnot. It's just too complicated.
If you want to work on porting it, use Qt, it's amazing. Check out my turing-editor-Qt project. Porting the actual interpreter would mostly involve rewriting all the files with an mdio prefix to use Qt or some other cross-platform thing (SDL,OpenGL) |
|
|
|
|
|
mirhagk
|
Posted: Sun Nov 20, 2011 6:07 pm Post subject: RE:Open Turing - 20-40% Faster Open Source Version of Turing With New Features |
|
|
I'm actually working on porting this to C# right now. Kinda the opposite direction, but I figure if it's not platform independent might as well be clean and efficient code for what platforms it does work on.
I started this because I was trying to alter some code to add support for as many images as memory could hold, but it was WAY too difficult to work with, as the code is very inconsistent and messed up. I started rewriting some of it, but since C doesn't have native support for a lot of the normal constructs, and because the code uses strings in some places and character pointers in others, I decided using a cleaner language might be a good idea. I'm like 30% of the way through converting the MIO project to C#, it's going pretty quickly.
If anyone is interested in the code when it's done (it's A LOT cleaner) let me know. I'll also release the program, and I'm looking into making a web based interface for it as it's easy to do in C#. |
|
|
|
|
|
trishume
|
Posted: Mon Nov 21, 2011 5:57 pm Post subject: Re: RE:Open Turing - 20-40% Faster Open Source Version of Turing With New Features |
|
|
mirhagk @ Sun Nov 20, 2011 6:07 pm wrote: I'm actually working on porting this to C# right now. Kinda the opposite direction, but I figure if it's not platform independent might as well be clean and efficient code for what platforms it does work on.
I started this because I was trying to alter some code to add support for as many images as memory could hold, but it was WAY too difficult to work with, as the code is very inconsistent and messed up. I started rewriting some of it, but since C doesn't have native support for a lot of the normal constructs, and because the code uses strings in some places and character pointers in others, I decided using a cleaner language might be a good idea. I'm like 30% of the way through converting the MIO project to C#, it's going pretty quickly.
If anyone is interested in the code when it's done (it's A LOT cleaner) let me know. I'll also release the program, and I'm looking into making a web based interface for it as it's easy to do in C#.
Are you planning on porting the compiler/VM to C# as well? Otherwise I don't see the point.
It can run in mono on other systems. The bad thing is that the VM will likely be slightly slower than normal turing.
The best way to improve turing's speed would be to use something like libjit: http://www.gnu.org/software/dotgnu/libjit-doc/libjit_3.html
That would give a massive speed increase but would take a lot of effort. |
|
|
|
|
|
trishume
|
Posted: Mon Nov 21, 2011 6:01 pm Post subject: Re: Open Turing - 20-40% Faster Open Source Version of Turing With New Features |
|
|
Or even use LLVM to do JIT, or even full compilation. See this:
http://llvm.org/docs/tutorial/index.html |
|
|
|
|
|
mirhagk
|
Posted: Mon Nov 28, 2011 3:26 pm Post subject: RE:Open Turing - 20-40% Faster Open Source Version of Turing With New Features |
|
|
The code is SOOOO terrible. Is it common practice in C to allocate memory for a string, then change one of the characters to a 0 to create a substring? (specifically getting the name without the .t). What it means is that when free is called, only up until the 0 will be freed correct? So a few bytes would be lost each time it's run. It's minor, but memory leaks like this sometimes add up. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
DemonWasp
|
Posted: Mon Nov 28, 2011 4:08 pm Post subject: RE:Open Turing - 20-40% Faster Open Source Version of Turing With New Features |
|
|
@mirhagk: No, free() doesn't check the values of the entries in the array (by strlen() or otherwise). I gather that information is tracked by malloc()/calloc()/realloc() for later use ( see http://stackoverflow.com/questions/1518711/c-programming-how-does-free-know-how-much-to-free ). Creating substrings by assigning '\0' to an element is not uncommon -- I've seen evidence of it in serialized data structures used in professional games. As long as you know nobody cares about the original data, you may as well work on it in-place. |
|
|
|
|
|
mirhagk
|
Posted: Mon Nov 28, 2011 7:21 pm Post subject: RE:Open Turing - 20-40% Faster Open Source Version of Turing With New Features |
|
|
alright lol just making sure. I did however note it took about 20 lines of code to do what would essentially be two or three in a modern language. The code did waste a lot of variables for temporary variables which were only used once, right after being found (they could've just put it on one line, and not created an extra variable) |
|
|
|
|
|
Tony
|
Posted: Mon Nov 28, 2011 7:39 pm Post subject: RE:Open Turing - 20-40% Faster Open Source Version of Turing With New Features |
|
|
linecount doesn't directly map to performance, as it largely depends on what a compiler does with them. A good enough compiler might crunch out those 20 and 2 line versions into identical op codes. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
mirhagk
|
Posted: Mon Nov 28, 2011 7:42 pm Post subject: RE:Open Turing - 20-40% Faster Open Source Version of Turing With New Features |
|
|
Yes that is true, and while 20 lines of code may be just as efficient to run, it makes it WAY less efficient to develop. So unless those 20 lines of code are more efficient it'd be better to go with the cleaner solution. |
|
|
|
|
|
Tony
|
Posted: Mon Nov 28, 2011 8:05 pm Post subject: RE:Open Turing - 20-40% Faster Open Source Version of Turing With New Features |
|
|
Yup, you're right there. Though considering that the project comes with unreadable machine generated code, there are more crippling problems than "long to read" implementations. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
mirhagk
|
Posted: Mon Nov 28, 2011 8:26 pm Post subject: RE:Open Turing - 20-40% Faster Open Source Version of Turing With New Features |
|
|
Lol yes that sure is true. Almost makes ya wonder whether it'd be faster/better to just rewrite it from scratch lol. I actually added support for expanding lists of resources (pictures,sprites etc), but because they code was so ugly, my contribution became even uglier, and I didn't want to even look at the beast I had created lol. |
|
|
|
|
|
ttm
|
Posted: Mon Nov 28, 2011 8:51 pm Post subject: Re: Open Turing - 20-40% Faster Open Source Version of Turing With New Features |
|
|
Of course it'd be better; almost everything turns out better/faster when you rewrite it a decade later. |
|
|
|
|
|
|
|