Topic:   Gan's Runtime & Script Interpreter   (Read 32758 times)


0 Members and 5 Guests are viewing this topic.

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Gan's Runtime & Script Interpreter
« on: March 13, 2011, 01:53:53 PM »
Version 2:
Runtime Download
Videos:
Demo Video - 14 min long
Graphic Bouncing demo
Command List
  • Print(text) - Prints text
  • Str$(number) - Turns a number to a string
  • Ticks - Gets the amount of ticks since program opened
  • Key - Returns the ascii value of the last key pressed or depressed
  • LoadImage(Image Name, Identification name) - Loads an image from outside.
  • CreateSprite(Identification Name) - Makes a sprite from a loaded image, returns sprite num
  • MoveSprite(SpriteNum, X, Y) - Moves a sprite
  • SpriteX(SpriteNum) - Gets X position of a sprite
  • SpriteY(SpriteNum) - Gets Y position of a sprite
  • KeyIsPressed(Ascii Value of Key) - Determines if that key is pressed, returns True or false
  • KeyUp - Returns ascii value for the up arrow key
  • KeyDown - Returns ascii value for the down arrow key
  • KeyLeft - Returns ascii value for the left arrow key
  • KeyRight - Returns ascii value for the right arrow key
Mini manual:
Making Variables
Code: [Select]
//Either form can be use
Let x = 1
or
x = 1

Let x$ = "test"
or
x$ = "test"
Variable Equations
Code: [Select]
//+=, -=, *=, and /= are supported
x = x + 5
or
x += 5
Complex Equations
Code: [Select]
//Complex equations are handled with ease.
x = (5 * (3 + 1) / 6 * 18) - 3
If Statement
Code: [Select]
//If statements and nested if statements work well.
If  x < 5 Then
x+=1
End If
For Statement
Code: [Select]
//For and nested for statements work.
For i = 1 to 5
x+=1
next


Version 1:
Quote
Gan's Runtime Video Demo

Hey guys, this is my top secret incredibly confidential my-eyes-only project.
Started this last weekend, spent 2 days thinking about it, 1 night dreaming about it, and 2 days making it. Then I procrastinated all week long.
Finally this weekend I got it into a useable state.

Yeah I cloned the Sc language. Mainly cause of people's familiarity with it.
So how about some details of this runtime:
  • Supports number and string variables
  • Can do complex equations of both strings and numbers. Especially with lots of parenthesis
  • Supports if statements that can also do complex equations and compare strings and numbers
  • Allows the use of AND and OR in if statements
  • Isn't case sensitive. You can write things in all caps if you want
  • So far two commands work. STR$(5) which makes "5" and print("test") which outputs text
  • If statement clusters work perfectly

How it works:
Three main things. The first is the parser.
It takes the code as a string, separates it into smart keywords, cleans out unnecessary stuff, lowercases the code, then compares each keyword string and attaches an identifier number to it.
Then there's the runtime.
The smart keywords go straight to the runtime that goes line by line running stuff. To detect what it's suppose to do, it looks at the number identifiers. It doesn't use any unreliable slow string comparisons when running code.
Finally, probably the most important part is the solver. When the runtime comes upon something that needs solved, it sends those keywords to the solver. The solver will go through, solve parenthesis, */+-, true/false equations, commands, and anything that gets in it's way. It was the hardest thing to make and is just like a large calculator. It can handle numbers, strings, and variables.

Surprisingly this whole thing isn't very large, is fairly readable, and incredibly versatile. Of course, I think there's a lot optimizations and cleaning I can do. Also there isn't any bug detection. If you aren't a perfect coder then the code's not gonna run. Though I think I can add something that'll tell you which line contains a bug.


Now before you guys get certain thoughts, I just gotta say.
I made this cause I thought it would be fun. At the moment I have no plans.
If you guys want I can open source it or something. Otherwise I'll probably just stick it in some folder until I make something that can make use of it.

So what are your thoughts?


EDIT: Pics!
The project in Xcode 4.

The coding and output window:

Complex equations!
« Last Edit: July 22, 2011, 01:08:16 AM by Gandolf »

Charlo


  • GMG-er

  • **


  • Posts: 451
Re: Gan's Runtime & Script Interpreter
« Reply #1 on: March 13, 2011, 02:55:31 PM »
Cool!  You could make another GameMaker clone with this as a base (provided you changed some syntax so as to not be a total SC ripoff).   ;D

By the way, whatever happened to Titanium Forge?

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: Gan's Runtime & Script Interpreter
« Reply #2 on: March 13, 2011, 03:20:46 PM »
Quote
Cool!  You could make another GameMaker clone with this as a base (provided you changed some syntax so as to not be a total SC ripoff).   ;D

By the way, whatever happened to Titanium Forge?
I could make a GM clone but unless it was incredibly fast and had superior features, it'd be useless. I haven't done speed tests yet but I don't know if I could keep interest long enough to make a GM.

Titanium Forge was a game maker made in Java that took your code and put it in a Java app. Had no actual runtime. Was as slow as Java, and I wasn't very happy with it. I don't like Java, especially the IDE Netbeans.

GMG Mike


  • Administrator

  • GMG-er

  • *****

  • no avatar

  • Posts: 536
    • mikerichardson.name
Re: Gan's Runtime & Script Interpreter
« Reply #3 on: March 13, 2011, 09:06:19 PM »
Can you send me the code? I'd like to study it. Thanks.

mike (at) silvernetworks (dot) net

Would it work in Xcode 3 or does it use some kind of new language features? I can install Xcode 4 on the laptop I suppose. I want to keep Xcode 3 on the Mac Pro in case I ever decide to use it (because I'd want to support at least 10.5 and PPC. I probably wouldn't support 10.4 because I'd want garbage collection).
« Last Edit: March 13, 2011, 09:07:50 PM by Mike_Richardson »

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: Gan's Runtime & Script Interpreter
« Reply #4 on: March 13, 2011, 09:54:24 PM »
Sent.

Should work just fine in Xcode 3. In Xcode 4 it just uses the new LLVM compiler and the more advanced debugging features are nice.
I tried to make this very well memory managed, at the moment I don't have garbage collection enabled.
If you want to keep Xcode 3, recopy the developer folder and name it Developer Xcode 3. Then install Xcode 4.
Thanks for being interested.
« Last Edit: March 13, 2011, 09:55:41 PM by Gandolf »

GMG Mike


  • Administrator

  • GMG-er

  • *****

  • no avatar

  • Posts: 536
    • mikerichardson.name
Re: Gan's Runtime & Script Interpreter
« Reply #5 on: March 14, 2011, 01:28:25 AM »
I'm interested in a speed test. Can you support a ticks function? Just add a bit of code in your variable handler. Then we can run a standardized speed test.

Code: [Select]
LET x = ticks
FOR i = 1 to 100000
   LET q = q + 1
NEXT
PRINT STR$(ticks-x)

Use the latest build of SilverCreator to run the test on your Mac. Do it from a real built program, not the "Run" menu. The standalone runtime is slightly faster (it does not record some information such as line numbers which are used by SC to help you debug). Compile yours as well.

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: Gan's Runtime & Script Interpreter
« Reply #6 on: March 14, 2011, 12:34:37 PM »
Yeah sure.
Ticks are in milliseconds right?
« Last Edit: March 14, 2011, 02:20:15 PM by Gandolf »

Silverwind


  • ^ This guy is amazing.

  • ****


  • Posts: 2805

  • For the glory of my maker
Re: Gan's Runtime & Script Interpreter
« Reply #7 on: March 15, 2011, 03:36:15 AM »
Hehe, remember the last time you, me and TD debated that? I think we were all wrong.

Come to think of it, TD's been even less active than I have lately. I wonder what he's up to...
I survived the spammage of 2007

GMG Mike


  • Administrator

  • GMG-er

  • *****

  • no avatar

  • Posts: 536
    • mikerichardson.name
Re: Gan's Runtime & Script Interpreter
« Reply #8 on: March 15, 2011, 03:40:22 AM »
Quote
Yeah sure.
Ticks are in milliseconds right?


There are 60 ticks to a second.

The "ticks" function as defined by REALbasic (and SilverCreator) returns the number of ticks since the computer was turned on.

GabrielCA


  • GMG-er

  • **

  • no avatar

  • Posts: 224
Re: Gan's Runtime & Script Interpreter
« Reply #9 on: March 17, 2011, 09:33:07 AM »
It's great to see someone making a script interpreter.

Does it support operator precedence ?
Did you use known algorithms or "reinvent the wheel" ?
Do you plan to add arrays, while() ?

It would be nice to see the source code (can it be posted here ?)

I've been working on a similar project myself (clown/SDL_clown). It is very fun but after some time I realized it is really best to use known algorithms. To the best of my knowledge, the "science" of making compilers has existed for at least 30 years, and a lot of research has gone into developing efficient algorithms and techniques.

[EDIT] it would be nice if you could make a manual or something that would give a clear list of the script interpreter's features
« Last Edit: March 17, 2011, 09:39:08 AM by GabrielCA »
Creator of the deprecated plugin KeyDetect (2005)

Connors


  • ^ This guy is amazing.

  • ****


  • Posts: 2374

  • It's a secret to everyone...
Re: Gan's Runtime & Script Interpreter
« Reply #10 on: March 17, 2011, 11:52:48 AM »
Does it have to use LET? I think it looks a bit cleaner and it's easier to type the code without LET. You can just say
x = 8
Warning: The above post may have been modified multiple times.

"In a great game, the character must never perfectly obey the user's command"
 - Tim Rogers

http://connorspuzzles.tumblr.com/

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: Gan's Runtime & Script Interpreter
« Reply #11 on: March 17, 2011, 04:06:27 PM »
Quote
There are 60 ticks to a second.
 
The "ticks" function as defined by REALbasic (and SilverCreator) returns the number of ticks since the computer was turned on.
Thanks. I should have ticks and the for loop code in by this weekend.

Quote
Does it support operator precedence ?
Yes. In this order: (), * or /, + or -, < or > or <= or >= or =, And or Or.

Quote
Did you use known algorithms or "reinvent the wheel" ?
I've made it all from scratch.

Quote
Do you plan to add arrays, while() ?
I had no plans to add anything new. Then Mike wanted to do speed tests. So I'll add for statements and the ticks function. Arrays and a while loop wouldn't be hard to add but it's not on my list of todo.

Quote
It would be nice to see the source code (can it be posted here ?)
I'm going to clean, add for loops and the ticks function, then do a speed test first. After that I'll probably post the source up.

Quote
I've been working on a similar project myself (clown/SDL_clown). It is very fun but after some time I realized it is really best to use known algorithms. To the best of my knowledge, the "science" of making compilers has existed for at least 30 years, and a lot of research has gone into developing efficient algorithms and techniques.
Nice, I'd enjoy discussing compiler techniques or even checking out your project.

Quote
[EDIT] it would be nice if you could make a manual or something that would give a clear list of the script interpreter's features
Not much to post. It just supports if statements, making variables and two commands: STR$() and print()
It can also handle complex equations.

Quote
Does it have to use LET? I think it looks a bit cleaner and it's easier to type the code without LET. You can just say
x = 8
At the moment it has to but it would be fairly easy to get rid of the LET. I really only have the LET so it'll resemble Sc's language more.

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: Gan's Runtime & Script Interpreter
« Reply #12 on: March 20, 2011, 11:03:05 PM »
First I'd like to apologize for my lateness.
Fortunately it is still the weekend by a few hours so technically I'm still sorta on time.

Second, I'd like to say that you'll be shocked by the results of the speed test.

Here's the video:
SilverCreator VS Gan's Runtime SPEED TEST

So a few details of why I'm so late:
I actually finished adding the for statement and TICKS command Thursday. Without telling any of you guys I did my own speed tests. I was so disappointed by the tests I refused to post them up. So because I set the deadline for the weekend, I spent my time thinking of how to speed up my runtime. I fell asleep with the problem and woke with the solution. Then I started implementing. Took a ton of work, moved and edited a crap load of code. Cleaned a bunch, got rid of unnecessary stuff and did lots of debugging and testing.
Finally it produced these results. I was so happy I nearly screamed and cried with joy. Nearly.

So how bad did my runtime do before?
SilverCreator: 33 ticks
Gan's Runtime: 64 ticks

On more advanced equations:
SilverCreator: 70 ticks
Gan's Runtime: 500 ticks

Yeah, it sucked.

So this whole recode I did to boost performance was essentially just moving a ton of code from the solver into the parser. So all the hard work was handled before any script executed. Therefore making it incredibly faster.

In case you didn't watch the video or just like spoilers, the final results are:
SilverCreator: 33.5
Gan's Runtime: 2.5

My runtime was able to achieve speeds of 10-16 times faster than SilverCreator.
Meaning, my runtime could do a FOR loop 1 million times and still beat Sc if it did a 100,000 FOR loop.

Pretty sweet, eh?

EDIT:
Here's the download:
Gan's Runtime Download
Compiled for 10.5-10.6. Sorry if it doesn't work on your machine, haven't spent time testing on various machines.
« Last Edit: March 20, 2011, 11:12:38 PM by Gandolf »

GMG Mike


  • Administrator

  • GMG-er

  • *****

  • no avatar

  • Posts: 536
    • mikerichardson.name
Re: Gan's Runtime & Script Interpreter
« Reply #13 on: March 20, 2011, 11:17:56 PM »
Quote
So this whole recode I did to boost performance was essentially just moving a ton of code from the solver into the parser. So all the hard work was handled before any script executed. Therefore making it incredibly faster.

In case you didn't watch the video or just like spoilers, the final results are:
SilverCreator: 33.5
Gan's Runtime: 2.5

My runtime was able to achieve speeds of 10-16 times faster than SilverCreator.
Meaning, my runtime could do a FOR loop 1 million times and still beat Sc if it did a 100,000 FOR loop.

Pretty sweet, eh?


I deleted the triple posts. I don't know why you did that.

Anyway, it sounds to me like the initial version was more of a straight interpreter (like the old SC) and the new version is pre-interpreted (like the current SC).

Please send me the new source so I can take a look at it. You may have used a better technique than I did.

I'd also like you to run your test again with the runtime compile for 32 bits ONLY. It is well known that 64 bit Intel programs have an advantage over 32 bit Intel programs, due to a greater number of registers. For the fairest comparison, your program should be using 32 bits (or run both tests on a PPC Mac).

Also keep in mind that SilverCreator supports a far greater number of instructions. Your runtime has almost no instructions. Each new instruction supported in the language slows down the execution of each instruction slightly. This is why SilverCreator got massively faster when the old monolithic ExecuteScript function was broken down into numerous sub-functions with each one dealing with a common set of instructions (one for sprite instructions, etc). The compiler was able to optimize each sub-function independently in regards to the use of CPU registers, etc. Even adding instructions to a sub-function causes a small slowdown because it is one additional check somewhere that must be made. I think I tried breaking down the sub-functions even more but found diminishing returns.

Garbage collection also slows down SilverCreator compared to other languages. Objects are used extensively in the pre-interpreted (byte code) representation of scripts. REALbasic wastes some time incrementing and decrementing reference counters. Experiments are planned in the future where some objects may be replaced with simple structs.

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: Gan's Runtime & Script Interpreter
« Reply #14 on: March 20, 2011, 11:39:08 PM »
Quote
I deleted the triple posts. I don't know why you did that.
I was trying to get my post on page 2.  ;D

Quote
Anyway, it sounds to me like the initial version was more of a straight interpreter (like the old SC) and the new version is pre-interpreted (like the current SC).
Yeah.

Quote
Please send me the new source so I can take a look at it. You may have used a better technique than I did.
Sent.

Quote
I'd also like you to run your test again with the runtime compile for 32 bits ONLY. It is well known that 64 bit Intel programs have an advantage over 32 bit Intel programs, due to a greater number of registers. For the fairest comparison, your program should be using 32 bits (or run both tests on a PPC Mac).
http://www.youtube.com/watch?v=glqlORHLbdY
I think that's 32 bit but I'm not use to Xcode 4 at all. May have done completely different compiler settings as well.

Quote
Also keep in mind that SilverCreator supports a far greater number of instructions. Your runtime has almost no instructions. Each new instruction supported in the language slows down the execution of each instruction slightly. This is why SilverCreator got massively faster when the old monolithic ExecuteScript function was broken down into numerous sub-functions with each one dealing with a common set of instructions (one for sprite instructions, etc). The compiler was able to optimize each sub-function independently in regards to the use of CPU registers, etc. Even adding instructions to a sub-function causes a small slowdown because it is one additional check somewhere that must be made. I think I tried breaking down the sub-functions even more but found diminishing returns.
A boat load of new commands could be added to my script interpreter and this speed test would produce the same results. Commands don't influence the speed of equations or the language structure. Though a negligible slow down would occur when calling a command.

Quote
Garbage collection also slows down SilverCreator compared to other languages. Objects are used extensively in the pre-interpreted (byte code) representation of scripts. REALbasic wastes some time incrementing and decrementing reference counters. Experiments are planned in the future where some objects may be replaced with simple structs.
Yeah, that could definitely be costly. I've tried to make my runtime well memory managed and to not allocate resource while running code.