Author Topic: 123 basic - HTML5 for GLBasic  (Read 122998 times)

Offline metzzo

  • Mr. Polyvector
  • ***
  • Posts: 140
  • Coolo ist cool!
    • View Profile
    • programming with design
123 basic - HTML5 for GLBasic
« on: 2012-May-05 »
GLBScript (now called 123basic)


I proudly present the first video preview of the new GLBasic to HTML5 compiler, GLBScript! The compiler is fully self hosting
and works awesome. The compiler produces high quality JavaScript code which runs amazingly fast! Surprisingly
the JavaScript compiler runs even faster than the native GLBasic compiler, isn't that great?

Further I want to say, that EVERY GLBasic syntax element is now fully working. PROTOTYPEs, "FUNCTION in TYPEs",
CALLBACK or even GOTO is doing its job wonderfull!

2 years ago, I wrote the first post about GLBScript (formerly GLScriptBasic) in the german forum Originally it was just considered as a scripting language
for GLBasic with the exact syntax of GLBasic. Development was rapid and with no minor problems. UNTIL there
was a bug - I call it "THE BUG". This little bastard stopped the whole development. I spent hours or hours
hunting the bug... But after two weeks I gave up and suspended development of GLScriptBasic...
One year passed and finally I got myself together and started working on "GLBScript". This time there
was no big surprise... I knew what went wrong and how to avoid this again. So I programmed until september.
I had a lot of syntax elements of GLBasic running in GLBScript and it was quite usable. ALIAS and BYREF
were implemented and some extra goodies! But then school started...

Development slowed down a lot. I had only 5 hours a week time for GLBScript. But i didn't give up and continued
steadily. I tried to make the compiler self hosting (compiles its own source code), which was a hard taks to achieve.
Finally in the end of march I've implemented enough functions and fixed bugs to get this working. I was really happy about this,
because this meant the compiler is stable, fast and the features are also working together. Then easter holidays began and I
was very procuctive... I've implemented the last missing syntax element - goto and I have also reprogrammed the whole filesystem
API. After easter holidays I just started to port some of the included samples of GLBasic... during that I fixed a lot of bugs.

Yep! I've managed to get this beast working in JavaScript and it's quite stable. To get this monster working
in JavaScript I had to reimplement all flow control structures (IF, WHILE, FOR, FOREACH, REPEAT, ...) in a
more machine code like structure. Of course as soon as you use a single GOTO in a scope the whole scope gets
transformed into this, but I think that's quite reasonable.

The next monster I had to kill was the low level filesystem API of GLBasic. The main problem is, in HTML5
there is no filesystem alike API available (except for Google Chrome, but this was no choice, because I want
GLBScript running in every browser!). There is only a Key - Value storage available in every browser. So I
had to implement a beast I call "Virtual File System". It basically wraps the whole Filesystem into an abstract
persistent file storage across every browser. Even old browsers with no "Localstorage API" this works fine (just
representation in JavaScript. When a file gets saved, I simply serialize this into a string and voilá we have
with less available memory), because as a second choice it uses cookies to save the data. Quite flexible i think!

So all Filesystem functions are available (WRITE... READ... INI... and many more)

I've also ported ALL String and Math functions to JavaScript. And of course a lot of minor problems were fixed (see changelog).
I also spent some time on improving the 2D engine of GLBScript. It is fully capable of converting the "Blocks", "Arkanoid", "FourInARow",
"Pong" and "JumpFrog" samples to HTML5 with literally no changes in the source code (except the GLB_ON_LOOP modification)

Self hosting!
As already mentioned, the compiler is fully self hosting. That means it is capable of compiling itself and produce executable
JavaScript within JavaScript

So what's the goal of this?
 - It's a good self test whether the compiler compiles accurate code. Compiling a compiler is not a trivial task.
 - EVAL() would be a possible function, and maybe I will include it.
 - Online development enviroment is possible. Developing your GLBasic Apps on the web. I already started a simple online IDE!

 One thing I want to mention is, that suprisingly the JavaScript compiler compiles _faster_ than the native one. I have no idea why,
 but I am quite happy about this.

Improved Debugging!
If an error occurs you see the current line of execution, a detailed stacktrace and of course the error message. The whole API does a lot more
saftey checks. You are able to get the current stacktrace in GLBasic with the new command "STACKTRACE$".

Google Closure is also used. In release mode Closure optimizes and minimizes the output code and in debug mode it cleans the code and indents. Google Closure is
a really nice tool and it's quite lightweight!

Yeah that's right! GLBScript supports inheritance and ABSTRACT methods. That means you can program in basic OOP. But I want to keep it simple and not too overloaded.
Implementing this feature was not that difficult. But of course I had to reimplement FUNCTION in types to get "late binding" working.

Automatic media management!
As you know, audio is a pain when trying to be cross platform... Of course in HTML5 it's the same problem. Different browsers support different sound formats. So I wrote an automatic converter for this issue. It takes your audio file and converts it automatically into .ogg and .mp3 files. You have to do nothing as a programmer. GLBScript takes care and converts - a pretty handy feature I think. For converting to mp3 I use LAME and for .ogg SOX.

Programming a little game:
Deep look into the compiler itself!

Debug mode is on in every demo, so it's probably a little slow. But at the moment it just matters THAT it works...
My programming philsophy is "First make it run, then make it run fast".

Self hosting compiler (wait a few seconds until it has compiled itself. After waiting you see the code of GLBScript in
JavaScript. This was compiled a few weeks ago so the actual code of the compiler looks different!
Arkanoid sample
Blocks sample
FourInARow sample
JumpFrog sample
Memory sample
OneMore sample
Pong sample
XML reader

BIG Changelog:
Code: (glbasic) [Select]
Fixed: FOR had strange behaviour in recursion
Fixed: "FOR i = 0 TO 0" executes correctly
Fixed: "4 - 5 + 6" or "TRUE OR FALSE AND FALSE" do not throw a syntax error
Fixed: i% = 4; STDOUT i% works (the %)
Fixed: Line numbering is now (almost) correct
Fixed: (multidimensional) arrays are more robust
Fixed: Type cloning works with references properly (JavaScript)
Fixed: floats like ".5" implemented
Fixed: Some problems with references fixed
Fixed: Uninitialized arrays have now correct default values
Fixed: TRY - CATCH works in GOTO scope properly
Fixed: "GETTIMERALL" returns milliseconds since page loaded instead of unix timestamp
Fixed: "NOT" returned a boolean instead of an integer
Fixed: GETFILELIST: uses the filter$ parameter
Fixed: Hex values fixed
Fixed: RGB returned incorrect number
Fixed: Now the compiler seperates the generated html file from the javascript file (one big JavaScript file vs. one small html file). So it's easier to distribute your program.
Fixed: 2D uses and context.restore()
Fixed: Unexpected "gotocounter exception" fixed.
Fixed: Unnecessary unref(), tryClone() and CAST2INT()/CAST2FLOAT() calls are removed, in the generated JavaScript file. => Execution is faster
Fixed: Compiler error messages display correct line number, path and character where the error happened
Fixed: KEY uses GLB Scancodes
Fixed: REPLACE$ works as expected (uses own implementation instead of the native JavaScript one)
Fixed: Some safety checks in the file API
Fixed: Codefolding is supported properly
Fixed: Array position screwed up in 3 or 4 dimensional arrays...
Fixed: Wrong dereferencing when calling a NATIVE function
Fixed: CONSTANT with multiple identifiers (CONSTANT IS_A = 0, IS_B = 1, IS_C = 2)
Fixed: Width and Height from the .gbap file
Fixed: Sound in Opera and IE
Fixed: RGB returned sometimes wrong value
Fixed: SETTRANSPARENCY: Implementation is a weird hack, please use only if there are no other possibilities
Fixed: STRETCHSPRITE stretches the sprite properly
Fixed: Wrong behaviour when performing "IF" with floats
Fixed: STRETCHSPRITE with width = 0 or height = 0 does not crash Firefox anymore
Fixed: Implicit defintion of arrays if there is a []
Fixed: No infinite loop while trying to load a non existing image or sound
Fixed: Array access optimized.
Fixed: Preprocessor screwed around with ?ELSE...
Fixed: \f in strings are not compiled into \n anymore
Fixed: CAST2INT() cuts decimals correctly
Fixed: Numbers beginning with 0 does not throw a syntax error anymore (040 for example)
Fixed: STARTDATA data:\n DATA functCall()\n ENDDATA <- Works now with function calls
Fixed: RND should work as expected
Fixed: CALLBYNAME("10") throws no syntax error when executed...
Fixed: Touch support for Android
Fixed: No context menu on right click onto the canvas
Fixed: Callbacks and function in types are functioning together
Fixed: MOUSEAXIS with mouse wheel support!

Added: FOREACH with multidimensional arrays
Added: ?BLACKLIST "file" - For Blacklisting Files/Folders (are not included in the final .html file), "?BLACKLIST ALL" blacklists all files => no file is included!
Added: "_" symbol for ignoring the newline token
Added: BOUNDS(array, dimension)
Added: Fully functional GOTO - still needs some debugging
Added: "GOTO on demand" overhead reduction: goto overhead (a big switch - case monster) is only inserted when it's really necessary
Added: "Virtual File System" Engine: Flexible managing of your (persistent and non persistent) data in a nice filesystem like enviroment.
Added: MIN/MAX
Added: DEBUG
Added: ABS
Added: SWAP
Added: SGN
Added: SIN
Added: COS
Added: TAN
Added: ASIN
Added: ACOS
Added: ATAN
Added: ASL
Added: ASR
Added: bOR
Added: bXOR
Added: bAND
Added: bNOT
Added: FMOD
Added: LOGN
Added: POW
Added: SQR
Added: STDERR (calls STDOUT with "Error: " prefix)
Added: END
Added: SHELLCMD (executes javascript - eval)
Added: SLEEP
Added: SHELLEND (calls SHELLCMD and END)
Added: LCASE$
Added: UCASE$
Added: DECRYPT$/ENCRYPT$: does not use blowfish...
Added: PUTENV (just a key - value storage)
Added: FORCEFEEDBACK (basic support, api is not very flexible...)
Added: GETCOMMANDLINE (returns the url parameter)
Added: INIGET$
Added: PUSHLOOP loop$ (new command: pushes a new Renderloop onto the stack)
Added: POPLOOP (new command: pops the last renderloop from the stack)
Added: GETCURRENTLOOP$ (new command: returns the current name of the renderloop)
Added: RETURNTOLOOP: loop$ (new command: "walks" through the loopstack until it gets to the given loopname)
Added: ANYKEY: (new command: instead of KEYWAIT, returns true if a key is pressed if not it returns false)
Added: Google Closure compatibility (compilation_level = ADVANCED_OPTIMIZATIONS): Now the JavaScript code is perfectly optimized by Google Closure (a wonderful JavaScript Optimizer) It optimizes the file size but the code gets a little slower...
Added: Useful debug information (if a error occurs) in debugmode: Stacktrace (prints the complete function call history and its parameters) and the current line of execution
Added: ?OPTIMIZE NONE | SIMPLE | AGGRESSIVE - How much should be optimized? None does nothing, Simple does very little optimzation and aggressive does nearly everything (problem with aggressive is, that it runs sometimes slower than the other techniques)
Added: Implicit variable declaration (Use variables without their declaration)
Added: STACKTRACE$ (new command: returns the current stacktrace in debug mode)
Added: HUSH
Added: Automatic audio converting to the common HTML5 audio formats (.mp3 and .ogg) - A very handy feature!
Added: Improved lexing speed: Uses now Hashmaps (In future I will rewrite the "identifier search engine" to use hashmaps, at the moment the native GLB arrays are used for this...)
Added: "Compile to HTML5" macro for GLBasic IDE - compile to HTML5 easily from the IDE.
Added: GOTO checks are now performed: You are only able to jump to defined labels.
Added: IIF(condition%, onTrue%, onFalse%)
Added: GLB_ON_LOADING: As long as GLBScript is loading data, this sub is callen... to check whether a sprite is loaded or not, use GETSPRITESIZE!
Added: GETMOUSECOUNT (mult touch support, need some bugfixing on Android/iOS...)
Added: Experimental inheritance feature, FUNCTION in types reprogrammed...
Added: Experimental ABSTRACT feature

* This function is just a dummy, because it is not possible to implement this feature and/or it's not worth it.

Not yet available... but soon you are able to test it on your own!

Future goals!
 - Optimize compiler speed (At the moment the compiler is really slow...)
 - Implement missing functions!
 - Bug fixing!
 - Fix all TODOs in code
 - Compile every 2D game and execute it properly (after the GLB_ON_LOOP change)
 - Get 3D commands working and implement a WebGL driver (that will take a lot of work...)
« Last Edit: 2013-Nov-20 by coolo »
That's no Bug, that's my project!

Offline Ruidesco

  • Mr. Polyvector
  • ***
  • Posts: 236
    • View Profile
Re: GLBScript - HTML5 for GLBasic
« Reply #1 on: 2012-May-05 »

Offline Hark0

  • Prof. Inline
  • *****
  • Posts: 1020
  • Geek Developer
    • View Profile
    • LitioPixel - Desarrollo de videojuegos con GLBasic | Videogame development with GLBasic
Re: GLBScript - HTML5 for GLBasic
« Reply #2 on: 2012-May-05 »

 :D - Desarrollo videojuegos Indie · Pixel-Art · Retroinformática · Electrónica Development Indie Videogames · Pixel-Art · Retrocomputing · Electronic

Offline kaotiklabs

  • Dr. Type
  • ****
  • Posts: 313
  • Spain is diferent
    • View Profile
Re: GLBScript - HTML5 for GLBasic
« Reply #3 on: 2012-May-05 »
Amazing work!!
Cant wait to test it!
Vote Cthulhu! Because the stars are right!!!!
Ia Ia Cthulhu F' tang!

Offline Hark0

  • Prof. Inline
  • *****
  • Posts: 1020
  • Geek Developer
    • View Profile
    • LitioPixel - Desarrollo de videojuegos con GLBasic | Videogame development with GLBasic
Re: GLBScript - HTML5 for GLBasic
« Reply #4 on: 2012-May-05 »
I tried demo Four in a Row on iPad with Atomic Web Browser... and LOAD!


I want my game project "online"  ;)

CONGRATS! - Desarrollo videojuegos Indie · Pixel-Art · Retroinformática · Electrónica Development Indie Videogames · Pixel-Art · Retrocomputing · Electronic

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1793
    • View Profile
    • Homepage
Re: GLBScript - HTML5 for GLBasic
« Reply #5 on: 2012-May-05 »
Great work! I want this! What are the terms? :-)

Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3375
  • Integrated Brain
    • View Profile
Re: GLBScript - HTML5 for GLBasic
« Reply #6 on: 2012-May-05 »
 :blink: :blink: :blink: :blink:

Awesoming... this it´s another great quantum leap in GLbasic, firts iPhone, after the others devices now this... GLbasic don´t have end?¿....


 :'( :'( :'( :'( :'( de alegría XDXD

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4176
  • On the shoulders of giants.
    • View Profile
    • My Apps
Re: GLBScript - HTML5 for GLBasic
« Reply #7 on: 2012-May-06 »
 :booze: :good: :nw:
I came. I saw. I played.


  • Guest
Re: GLBScript - HTML5 for GLBasic
« Reply #8 on: 2012-May-06 »
Its looking good!

Offline Moebius

  • Dr. Type
  • ****
  • Posts: 315
    • View Profile
Re: GLBScript - HTML5 for GLBasic
« Reply #9 on: 2012-May-06 »
Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
- Random Shack Data Processing Dictionary

Offline Falstaff

  • Mr. Polyvector
  • ***
  • Posts: 148
    • View Profile
Re: GLBScript - HTML5 for GLBasic
« Reply #10 on: 2012-May-06 »
When do we get to play with it :D

Offline erico

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4453
    • View Profile
    • FUED
Re: GLBScript - HTML5 for GLBasic
« Reply #11 on: 2012-May-06 »
gasp! cough! outstanding!  :booze: :good: :nw:

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2796
    • View Profile
Re: GLBScript - HTML5 for GLBasic
« Reply #12 on: 2012-May-06 »
Some one buy this man a drink! :booze:


“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)

Offline matchy

  • Prof. Inline
  • *****
  • Posts: 1545
    • View Profile
Re: GLBScript - HTML5 for GLBasic
« Reply #13 on: 2012-May-06 »
 :nw: :booze: :good: :-* :happy:

Offline Jonás Perusquía

  • Mr. Polyvector
  • ***
  • Posts: 170
    • View Profile
    • Ditrabox
Re: GLBScript - HTML5 for GLBasic
« Reply #14 on: 2012-May-06 »
REALLY! impresive!   :nw:
Be free and do good things