flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > High Level Languages > Idlewild-Lang (2D game programming language)

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
ProphetOfDoom



Joined: 08 Aug 2008
Posts: 120
Location: UK
Idlewild-Lang (2D game programming language)
Hi,

So this is what I've been working on in my spare time over the last year.

Idlewild-Lang is a free (as in freedom), 64-bit, cross-platform (Linux/Windows) BASIC compiler that functions as a game programming language and also as a general-purpose language. It uses FASM or NASM as the backend.

This project started as a fork of my toy compiler Bubble BASIC (I posted that under another user name), but, although the build system and file names are similar, everything internally has changed. It's now more or less source-compatible with Blitz BASIC from Blitz Research Limited (if you're not familiar with Blitz, it was an advanced C-like BASIC dialect popular in the Amiga and early PC years).

It is suitable for writing simple 2D games (with 3D acceleration for masking, scaling and rotation), providing you are sensible - it's an alpha software so don't be surprised if, when you forget to load a font, you get a segmentation fault instead of a friendly error message!

The following BASIC keywords/operators are supported:

After, And, Before, Case, Const, Data, Default, Delete, Dim, Each, Else, Else If, End, End If, Exit, False, Field, First, Float, For, Forever, Function, Global, Gosub, Goto, If,, Insert, Int, Last, Local, Mod, New, Next, Not, Null, Or, Pi, Read, Repeat, Restore, Return, Sar, Select, Shl, Shr, Step, Str, Then, To, True, Type, Until, Wend, While, Xor, Include, On*

+ (unary)
- (unary)
~
^
*
/
+
-
>
<
>=
<=
<>

The following Blitz BASIC functions are supported:

Graphics, SetBuffer, BackBuffer, Cls, ClsColor, Color, Flip, Origin, Line, SetScale*, SetOrientation*, GetScaleX*, GetScaleY*, LoadImage, MaskImage, HandleImage, ImageXHandle, ImageYHandle, ImageWidth, ImageHeight, MidHandle, AutoMidHandle, DrawImage, DrawImageRect, Oval, Rect, LoadFont, SetFont, Text, StringWidth, StringHeight, LoadSound, PlaySound, LoopSound, StopChannel, ChannelPlaying, KeyDown, KeyHit, SetPrecision*, Abs, Sin, Cos, ATan2, ATan, Tan, Sgn, Exp, Log, Sqr, SeedRnd, Rnd, Rand, CreateTimer, WaitTimer, LSet, RSet, Len, Mid, Left, Right, Uni*, Asc, Chr, Upper, Lower, Print, Write, Input, DebugLog, Millisecs

I'd be very grateful if some other forum members could build this under Linux (for example, Ubuntu/Debian/Mint) and run some test programs and report any issues. I think there is a high chance of success with the build because I was able to build the language on a vanilla Ubuntu 14.04 virtual machine (I don't recommend this though as 3D graphics don't seem to work reliably in VirtualBox/VMWare). Ideally, if someone could throw together a little game with these functions I'd love to see it and include it in future versions of the language! I have included some simple example programs. Most of them are console apps ported from Bubble BASIC but there is a 3D-accelerated particles example in there.

Download from github (click "releases" at the top of the page for precompiled binary packages):

https://github.com/clockworkdevstudio/Idlewild-Lang

Thanks


Last edited by ProphetOfDoom on 04 Dec 2015, 23:19; edited 1 time in total
Post 11 Nov 2015, 01:28
View user's profile Send private message Reply with quote
ProphetOfDoom



Joined: 08 Aug 2008
Posts: 120
Location: UK
Re: Idlewild-Lang (2D game programming language)
This is an asteroid shooter game I wrote in Blitz BASIC and ported to Idlewild-Lang. Once you've installed the compiler it should be a simple matter to build and run the game; just type "idlewild-lang skyghost.bb" then "./a.out".

Here is a video of me playing the game (it's best viewed in portrait on a tablet):

https://youtu.be/xourmxqPcEc


Description:
Download
Filename: skyghost.tar.gz
Filesize: 263.38 KB
Downloaded: 169 Time(s)

Post 11 Nov 2015, 01:32
View user's profile Send private message Reply with quote
borbonhause



Joined: 18 Oct 2015
Posts: 23
libsdl2-dev package isn't found on my Ubuntu 12.04's package manager, I'll try to do something about that later. This looks pretty intriguing.
Post 11 Nov 2015, 06:28
View user's profile Send private message Reply with quote
ProphetOfDoom



Joined: 08 Aug 2008
Posts: 120
Location: UK
Thanks borbonhause. That's so typically Linux. Rolling Eyes I don't know how it can annoy me so much yet still be my favourite OS. Has anyone else had any success building the compiler/game? Extra points if it was on Windows. I'd like to provide binaries at some point but it's not a massive priority.
Post 11 Nov 2015, 13:50
View user's profile Send private message Reply with quote
borbonhause



Joined: 18 Oct 2015
Posts: 23
Tried running make anyway, and this is what I got:


Code:

$ make
ghc Main.hs -o idlewild-lang -DLINUX=1 -O3

Linker.hs:46:8:
    Could not find module `Control.Monad.Identity'
    Use -v to see a list of the files searched for.



Should I install some package, or my ghc is just that old?
Post 12 Nov 2015, 06:07
View user's profile Send private message Reply with quote
TmX



Joined: 02 Mar 2006
Posts: 790
Location: Jakarta, Indonesia
something like:

Code:

sudo apt-get install libghc6-mtl-dev



maybe?
hmm maybe I should setup GHC on Windows as well...
Post 12 Nov 2015, 08:01
View user's profile Send private message Reply with quote
ProphetOfDoom



Joined: 08 Aug 2008
Posts: 120
Location: UK
Hi borbonhause,

I just installed Ubuntu 12.04 on a virtual machine and ran an apt-cache search; it seems that your version of Ubuntu simply doesn't have SDL2 in its repositories (except possibly the ttf module, weirdly). So you're stuck unless you want to try to build SDL2 from source, which I've never tried but it doesn't sound like much fun. It would probably be easier to install a newer version of Ubuntu. Oh btw, the error regarding Control.Monad.Identity can easily be fixed by just commenting out "import Control.Monad.Identity" in Linker.hs. Then the compiler builds (but it's useless without its standard libraries). I have no idea why I imported that package in the first place. libghc-mtl-dev IS available on Ubuntu 12.04 (thanks TmX) but that doesn't help much.
Post 12 Nov 2015, 13:33
View user's profile Send private message Reply with quote
ProphetOfDoom



Joined: 08 Aug 2008
Posts: 120
Location: UK
Okay I found a solution for Ubuntu 12.04 but it's not pretty.

Go to https://www.libsdl.org/download-2.0.php
Download SDL2-2.0.3.tar.gz

Go to https://www.libsdl.org/projects/SDL_ttf/
Download SDL2_ttf-2.0.12.tar.gz

Go to https://www.libsdl.org/projects/SDL_mixer/
Download SDL2_mixer-2.0.0.tar.gz

Go to https://www.libsdl.org/projects/SDL_image/
Download SDL2_image-2.0.0.tar.gz

Go to http://glm.g-truc.net/0.9.7/index.html
Click Download GLM 0.9.7.1 2015-09-07

All the above SDL libraries can be compiled and installed simply by:

./configure
make
sudo make install

Now use apt-get to install all dependencies listed in the README file EXCEPT (Edit: GLM and) the failed SDL ones (you may also need libglew1.5-dev).

Extract GLM then run:

sudo mkdir /usr/include/glm
sudo cp -r glm/* /usr/include/glm

"make" should now work.
Post 12 Nov 2015, 14:48
View user's profile Send private message Reply with quote
borbonhause



Joined: 18 Oct 2015
Posts: 23
So yeah, I compiled it. And learned that I have a 32-bit OS. Dispite having a processor that supports an x64 instructions. I'm sorry for everything.

Ok, I'm reinstalling my OS and backuping everything I have, shouldn't take more than a week if I'm lucky, which I'm not.


Code:
idlewild-lang: /usr/bin/ldi386:x86-64 architecture of input file `Examples/array_multi.o' is incompatible with i386 output

Post 14 Nov 2015, 06:47
View user's profile Send private message Reply with quote
ProphetOfDoom



Joined: 08 Aug 2008
Posts: 120
Location: UK
Hi borbonhause,

It's okay not your fault - I think Ubuntu was still recommending the 32-bit .ISO back in 2012. Thanks for all your efforts. I'm still wondering how the other 8 people who downloaded it got on though. Confused
Post 14 Nov 2015, 14:16
View user's profile Send private message Reply with quote
ProphetOfDoom



Joined: 08 Aug 2008
Posts: 120
Location: UK
Binaries for Windows and Linux
I've just updated this project with binary packages and install scripts. It means the language and all its dependencies can be installed on Windows with one single command from an admin terminal:

install-windows-bin.bat

Linux users have it nearly as good with just three commands to install the compiler. I also edited the README to give much more information about the cool features of the language.

The source code is here (click "releases" at the top of the page and download the zip file for your chosen OS).

https://github.com/clockworkdevstudio/Idlewild-Lang

There is also a copy of my asteroids game Skyghost with both source and binaries bundled in the same download.

Any feedback would be much appreciated.
Post 04 Dec 2015, 23:15
View user's profile Send private message Reply with quote
ProphetOfDoom



Joined: 08 Aug 2008
Posts: 120
Location: UK
New version
Hi,
This project lives on!
I just uploaded version 0.0.3. The main news is that it now runs on MacOS (with nasm), so the same sources can now be compiled on all three major platforms, Windows 10, Linux and MacOS! (64 bit only, though).
There are also many bug fixes. Importantly, all memory leaks I could discover in generated executables have been fixed. In the graphics department, I fixed some matrix multiplications that were being done in the wrong order. Also there was a critical bug related to aspect ratio which I never noticed because I was using a monitor with an almost square aspect ratio. When I ran the demo games on a 16:9 screen I got a horrible shock as everything was stretched horizontally. All fixed now though. The only caveat is that currently the graphics library only supports aspect ratios where X > Y (i.e., most laptops). I plan to address this issue in future. Also the install/uninstall scripts are generally a lot more well behaved now.
There is a new demo game called Donjuan, based on the classic 80s game Gauntlet. Here is a video of me playing it:
https://youtu.be/wFsrEJNcTPQ
Please download and play with these projects and report bugs make suggestions whatever.
https://github.com/clockworkdevstudio/Idlewild-Lang
https://github.com/clockworkdevstudio/DonJuan
Post 16 Aug 2017, 02:44
View user's profile Send private message Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 186
Hello, install-windows-bin.bat seems to copy dll into windows/system32, can you instead keep them in the bin folder? I will never get them out, my system32 is a terrible mess. I'd rather add that bin folder into the PATH envvar.

Forgive me this shameless plug, but can you look at this? Also a language, but I have nothing to show yet. https://board.flatassembler.net/topic.php?p=199776#199776
Post 15 Sep 2017, 09:21
View user's profile Send private message Reply with quote
ProphetOfDoom



Joined: 08 Aug 2008
Posts: 120
Location: UK
Hi vivik,
Really sorry I took two weeks to reply to your post. I just got so used to people ignoring my topic that i stopped checking it.
I will take on board your advice about leaving system32 alone. Those scripts are placeholders really for a GUI installer I will write some time. The project is only on version 0.0.3 so don't expect too much! IIRC the uninstall script removes the correct .DLLs, though this could be problematic if other applications rely on them.
That's cool that you're creating your own language. Not sure what advice I can add but I'll have a look. I think we have very different goals though. In particular, you said you want to generate code as efficient as hand-written assembly. It was a design decision of mine not to do this. In my experiments an optimising compiler is about 3 times as large (in terms of source code) and much harder to understand and modify than a non-optimising compiler. So good luck with that! My compiler has taken me three years to write (working on it about 20 hours a week) and a C compiler (conformant) is a much bigger challenge.
Post 04 Oct 2017, 16:25
View user's profile Send private message Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 186
>I think we have very different goals though. In particular, you said you want to generate code as efficient as hand-written assembly. It was a design decision of mine not to do this. In my experiments an optimising compiler is about 3 times as large (in terms of source code) and much harder to understand and modify than a non-optimising compiler. So good luck with that!

hmm... You know, ideally, it would be possible to strip away parts of program by just turning one variable into constant, and letting an ide to hide (or remove completely) no longer relevant code. If this will work, it will be possible to turn an optimising compiler into a much simplier version with minimal effort. Kinda like those tools that allow solving #ifdef for you, but smarter.

I'm a huge fan of simple programs myself, or rather, programs I can strip most of functionality from if I need to. It may not look like that, but I pretty much want to simplify programming. Assembly programming, without compromising code quality like other languages do, but still simplify.

Different languages seem to go somewhere in this direction, limiting use of preprocessor. C did that by introducing const variables and inline functions. Golang did that by just hardcoding into their build system that "_linux.go files are for linux only". Ziglang introduced "comptime" keyword, not sure yet what exactly it does. Maybe I'll go as far as make an ide that can simplify code without changing it, or ide with some advanced refactoring functionality.

>and a C compiler (conformant) is a much bigger challenge.
I'm not going for a full C standard, I can't even read thas beast. I'll go for something simplier like golang instead. I just meant that I'll take C compiler as a base, and start working from that, their code generation is pretty good.

At this point in time, I did some research on winapi, x86 assembly, writing text editors, writing debuggers. If you'll ever need any of that, I may be of help, maybe.

What I'd like to get help with... Well, first I'll try to get Idlewild-Lang working, I'll ask a lot of questions just about that, now that you're here. Also I need to learn how to do actual code generation, how symbol table looks like, how type definitions look like (especially something like "pointer to pointer to struct"), how abstract syntax tree looks like.

I'll also need to study gcc or clang internals, at least to some extent.
Post 04 Oct 2017, 19:41
View user's profile Send private message Reply with quote
ProphetOfDoom



Joined: 08 Aug 2008
Posts: 120
Location: UK

Quote:
hmm... You know, ideally, it would be possible to strip away parts of program by just turning one variable into constant, and letting an ide to hide (or remove completely) no longer relevant code. If this will work, it will be possible to turn an optimising compiler into a much simplier version with minimal effort. Kinda like those tools that allow solving #ifdef for you, but smarter.



That sounds very much analogous to what Haskell's monad transformers provide (though they hide the code rather than remove it completely). State is hidden within the monad transformer so the programmer can focus on the higher level task. It allowed me to write my number scanning function very simply and with the assumption that nothing went wrong:


Code:
matchConstant :: CodeTransformation ()
matchConstant =

    do consume integral
               LEX_PENDING LEX_PENDING []
               TOKEN_INT_CONSTANT

       consume decimalPoint
               LEX_PENDING LEX_DONE []
               TOKEN_FLOAT_CONSTANT

       consume fractional
               LEX_PENDING LEX_ERROR "Expecting fractional part of floating point number."
               TOKEN_FLOAT_CONSTANT

       consume e
               LEX_PENDING LEX_DONE []
               TOKEN_FLOAT_CONSTANT

       consume negative
               LEX_PENDING LEX_PENDING []
               TOKEN_FLOAT_CONSTANT

       consume exponent_
               LEX_DONE LEX_ERROR "Expecting integer exponent."
               TOKEN_FLOAT_CONSTANT

       store

    where integral = span isDigit
          decimalPoint s = extractCharacterFromSet "." s
          fractional = span isDigit
          e s = extractAnyCharacterFromSet "eE" s
          negative s = extractCharacterFromSet "-" s
          exponent_ = span isDigit



The above code can lex both integers and fractionals, including those with E notation. The "consume" function is just told how to consume, what to do on success, what to do on failure, and what kind of token has been "consumed".

With some skill I suppose in Haskell you could write a normal looking compiler and hide the optimisations in a monad transformer.

I think you'll find the clang code much more educational tbh as my compiler is rather "thrown together". Some sections I am very proud of (like the linked list and array code in libkoshka_core.c) and some sections are a frightful mess (for example, most of the opengl code looks like it was written by a not very talented 14 year old - the file Parser.hs was written in a hurry too).


Quote:
At this point in time, I did some research on winapi, x86 assembly, writing text editors, writing debuggers. If you'll ever need any of that, I may be of help, maybe.



That's cool! I tend to lose patience with the WinAPI because of its sheer complexity. It gives you a lot of freedom, but that means you tend to have to read a lot more documentation.
I'm currently struggling to write a debugger for MacOS and Linux but MacOS is being very uncooperative.


Quote:
What I'd like to get help with... Well, first I'll try to get Idlewild-Lang working, I'll ask a lot of questions just about that, now that you're here. Also I need to learn how to do actual code generation, how symbol table looks like, how type definitions look like (especially something like "pointer to pointer to struct"), how abstract syntax tree looks like.



Thanks. It bothers me that my language doesn't "just work". Aargh! Someone on another forum said the Windows version crashed immediately on opening. The only thing I didn't mention in the documentation is that you need to add C:\Program Files\Idlewild-Lang\ to your PATH. Maybe there is some development tool on my computer that I forgot about, that's causing it to work locally and crash elsewhere. Confused

A symbol table is just a bunch of keys and their values. I used Haskell's Data.Map which I believe is some kind of horribly complicated binary tree (which I'm glad I didn't have to implement myself). They can also be hash tables though (i.e. arrays of linked lists). In an OOP language you'd have an abstract symbol class, then derived classes, some of which themselves contain symbol tables. For example, Int, Float and String classes which are all "leaf objects", and structs and functions which have symbol tables of their own, although eventually everything ends with leaf objects which are your language's fundamental types.

To represent a "pointer to a pointer to a struct" I would just have an integer field in my symbol object describing its level of indirection. An ordinary struct would be the value 0, a pointer would have 1 and the "pointer to pointer" would have 2. Then you could check if an assignment operation was potentially dangerous simply by comparing two integers - obviously your language's "expression" objects would need to have a similar field so you could, for instance, check the return value of a function call against a local variable.
Post 04 Oct 2017, 22:00
View user's profile Send private message Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 186
>Maybe there is some development tool on my computer that I forgot about, that's causing it to work locally and crash elsewhere.

Dependency walker is good for this. Or open it in ollydbg and open log, it will show all dlls loaded.

Trying to install haskell now.
Post 06 Oct 2017, 16:30
View user's profile Send private message Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 186
Okay, how to install it on windows, lazy description, use at your risk:

Install 64bit things only.
http://www.msys2.org/
https://www.haskell.org/platform/
cabal install mtl
Maybe add C:\msys64\mingw64\bin and C:\msys64\usr\bin in your PATH
pacman -S mingw-w64-x86_64-gcc
pacman -S mingw-w64-x86_64-glib2
pacman -S mingw-w64-x86_64-SDL2_ttf
pacman -S mingw-w64-x86_64-SDL2_mixer
pacman -S mingw-w64-x86_64-SDL2_image
pacman -S mingw-w64-x86_64-glew
pacman -S mingw-w64-x86_64-glm
pacman -S mingw-w64-x86_64-freeglut
make windows-release

Now you have 3 files:
idlewild-lang.exe
libkoshka.core.dll
libkoshka.mm.dll
Post 07 Oct 2017, 17:17
View user's profile Send private message Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 186
idlewild-lang.exe donjuan.bb --backend=fasm
idlewild-lang.exe: C:\\Program Files\Idlewild-Lang\fasm.exe: readCreateProcessWithExitCode: does not exist (No such file or directory)

What does it mean? My fasm.exe is in path, and I even copied it in the folder with donjuan.bb

Also notice "C:\\", maybe extra, maybe other slashes should be doubled.
Post 07 Oct 2017, 17:21
View user's profile Send private message Reply with quote
ProphetOfDoom



Joined: 08 Aug 2008
Posts: 120
Location: UK

vivik wrote:
idlewild-lang.exe donjuan.bb --backend=fasm
idlewild-lang.exe: C:\\Program Files\Idlewild-Lang\fasm.exe: readCreateProcessWithExitCode: does not exist (No such file or directory)

What does it mean? My fasm.exe is in path, and I even copied it in the folder with donjuan.bb

Also notice "C:\\", maybe extra, maybe other slashes should be doubled.



Hi,
It wants to find a copy of fasm in the actual Idlewild-Lang folder... not just anywhere in your PATH. It's hard coded that way because in future when I add "User-friendliness" (LOL) I won't get newbs having to download fasm themselves. Just stick a copy of fasm in the folder mentioned by the error message and you should be good to go. Fingers crossed. Sorry for the confusion.
The corresponding compiler source should shed light on this too:

Code:
case optionAssembler options  of
          "fasm" ->
            do
#if LINUX==1
               let fasmPath = "/usr/bin/fasm"
#elif MAC_OS==1
               let fasmPath = "/usr/local/bin/fasm"
#elif WINDOWS==1
               let fasmPath = "C:\\\\Program Files\\Idlewild-Lang\\fasm.exe" 
#endif
               verboseCommentary ("fasm " ++ asmFileName ++ "\n"verbose
               (exitstdoutstderr) <- liftIO $ readProcessWithExitCode fasmPath [asmFileName""
               case exit of
                    (ExitFailure n) -> do liftIO $ putStrLn (stderr ++ "\nAssembler error (fasm, code " ++ (show n) ++ ").")
                                          liftIO $ exitFailure
                    _ -> return ()



Thanks for taking the time to compile this from source! Really grateful!
Post 07 Oct 2017, 18:09
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.