Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Work in Progress / OOP in DBP!

Author
Message
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 13th Nov 2007 21:23 Edited at: 13th Nov 2007 21:24
I am currently (whenever not updating Box2D or ViewGUI) developing a precompiler in VB.net to allow the use of OOP in DBP.

Currently, the precompiler takes in two parts: The class definitions and the actual code.
Here is a small demonstration of what it will do:

Class definition:


Source:


Output:


I have tried to keep the syntax the same as DBP as much as possible (Case insensitive, endclass as one word, no 'dim' before a member, etc.

Currently, the precompiler can't even do as much as UDTs (members can only be of the standard types), but eventually I hope to expand the functionality to inherited classes, function members and arrays in classes.

This was partially inspired by Milkman's attempt at an OOP precompiler, which was sadly never finished

Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 13th Nov 2007 21:27
This is looking good! I'm guessing it need some sort of plugin to work, right?

"It's like floating a boat on a liquid that I don't know, but I'm quite happy to drink it if I'm thirsty enough" - Me being a good programmer but sucking at computers
Blobby 101
18
Years of Service
User Offline
Joined: 17th Jun 2006
Location: England, UK
Posted: 13th Nov 2007 21:31
i'm probably being n00bish but what's an OOP?


thanks to deathead for the sig! please Click on it!
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 13th Nov 2007 21:45
@Zotoaster
Hopefully, the only plugin it will need is IanM's peek/poke plugin, and in the future, his function pointer plugin as well.

@blobby 101
OOP - Object Oriented Programming is basically a way of making programming much more powerful, and regular. Wikipedia has a good definition. All .net languages use OOP. One example of OOP is inheritance (The ability to create a new class which contains all the contents of another class, but with stuff added/removed/changed) For a better definition see wikipedia again

RPDan
17
Years of Service
User Offline
Joined: 29th Apr 2007
Location:
Posted: 13th Nov 2007 21:55
I'm sure everyone can read my mind. I was going to use UDTs as classes with function pointers until I remembered functions can't return UDTs, so now I'm doing the peek/poke method, which was my plan before finding function pointers. I'll probably stop working on it in favor of another project though, if someone else is doing it - too much effort to get the features I really want (functions returning classes, operator overloading, classes as class members). Good luck!
n008
17
Years of Service
User Offline
Joined: 18th Apr 2007
Location: Chernarus
Posted: 13th Nov 2007 22:06 Edited at: 13th Nov 2007 22:40
Quote: "i'm probably being n00bish but what's an OOP?"


OOP is Object Oriented Programming. It is a Programming Paradigm that uses classes to define objects with members, and is used to organize your code better. Here is a C++ example:



See how much more flexible it makes your code? Plus, it makes it more readable, as opposed to hundreds of different variables.

@Diggsey: I have never used DBpro types, but from what i have seen they act a lot like classes do, so what would the benefits of a class command be over the type command?

Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 13th Nov 2007 22:30
OOP uses classes, which are just like types that support functions, and some extra features like inheritance, encapsulation and polymorphism.

"It's like floating a boat on a liquid that I don't know, but I'm quite happy to drink it if I'm thirsty enough" - Me being a good programmer but sucking at computers
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 13th Nov 2007 22:33
@n008
UDTs cannot be returned from functions, my classes can, UDTs cannot contain arrays, mine will be able to, UDTs can only contain data, and only in the simplest form, my classes will be able to have function members, properties, etc. UDTs cannot be inherited, my classes will be able to be inherited!

Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 13th Nov 2007 22:40
Just to nitpick:



That should be void

"It's like floating a boat on a liquid that I don't know, but I'm quite happy to drink it if I'm thirsty enough" - Me being a good programmer but sucking at computers
n008
17
Years of Service
User Offline
Joined: 18th Apr 2007
Location: Chernarus
Posted: 13th Nov 2007 22:43
Oh, so those are type limitations .

Quote: "Just to nitpick:

+ Code Snippet

int getnumbers( int num, int num2)
{
num3 = num + num2;
cout << num3 << endl;
}



That should be void "


Or a return statement?

John Y
Synergy Editor Developer
22
Years of Service
User Offline
Joined: 4th Sep 2002
Location: UK
Posted: 14th Nov 2007 12:44
How does the precompiler work, does it replace the dbp compiler and then call it afterwards, or does it do it's job and then quit.

The reason I am asking is that Synergy Editor supports precompilers natively. You just add the exe to the list, and then it will automatically invoke and then wait for the precompiler before compiling the (modified) source.

Synergy Editor will pass you the project file filename (and path), perhaps you would be willing to make it compatible with Synergy Editor?

Synergy Editor - Available in the WIP forum
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 14th Nov 2007 18:08
@John Y
My precompiler is called by command line with the three filenames, each enclosed in '""'s. It then brings up the console while it is running, in which it displays compile information, and then waits for a key press and quits. It would be awesome to have it compatible with Synergy Editor, but at the moment, it's not ready to actually be used. I am also in the process of rewriting part of it to make it cleaner, and also to support class members with the type of another class, and so on. When it is ready, I will of course try to make it compatible with Synergy Editor.

Aaron Miller
18
Years of Service
User Offline
Joined: 25th Feb 2006
Playing: osu!
Posted: 15th Nov 2007 00:03
So.... Much.... OOP.....
DOOP (Dark Basic Object Oriented Programming)
DBP++: A Precompiler
Object Oriented DBP


Cheers,

-naota

"I'd newbie slap here, but I've no idea how far I'd need slap before they'd come back with a clue." - VanB
Aex.Uni forums
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 15th Nov 2007 17:36
@Aaron
Milkman's OOP precompiler is the only one similar to this, and he never finished it, which is why I started my own one

RPDan
17
Years of Service
User Offline
Joined: 29th Apr 2007
Location:
Posted: 15th Nov 2007 20:16
Have you got a design document or a list of planned features? This looks like a really interesting project.
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 15th Nov 2007 20:42
@RPDan
Not really. I basically have a working version at the moment which does only what UDTs can do, (and a tiny bit extra) and I work on adding one more feature at a time. (At the moment I am working on allowing variables defined as these types to be passed to functions. After that I will properly distinguish between local and global variables, and then I will work on arrays.

Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 15th Nov 2007 21:50
Beta release!
(You will need IanM's Matrix1Utils plugin pack)

This version supports all of the features of UDTs except for these:
Declaring an array as one

But it also supports these features that UDTs don't:
Returning values*
Copying a reference
Can convert any types

*You must store return values in a temporary variable of standard type because DBP doesn't allow code after the endfunction or exitfunction commands (only variables or literals)

To use:
Select these three files in this order, holding the controlkey for the last two:
The class definitions file
The source code file
The output file

And drag them onto the .exe

OR

Call the .exe from the command line with the filenames of the three files.

The .exe and an example is attached

Attachments

Login to view attachments
Mr Z
17
Years of Service
User Offline
Joined: 27th Oct 2007
Location:
Posted: 26th Nov 2007 10:09
Awsome! It´s an pitty milkmans precompiler was never finished, I was looking forward for it.

Can´t really test it now, since I´m not in windows, but I´ll try it later. And please don´t give up, man. This would just be great if it´s finished.

Darknes, you haunt me. If I give in, I would be an monster beyond imagining. Light, you guide me. Thanks to you, I see past the nothingness. Life, I choose to live in the light.
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 26th Nov 2007 17:44
@Mr Z
If I do ever give up, I will be sure to make it open-source first

Mr Z
17
Years of Service
User Offline
Joined: 27th Oct 2007
Location:
Posted: 26th Nov 2007 19:17
Good . But I really hope you won´t.

Darknes, you haunt me. If I give in, I would be an monster beyond imagining. Light, you guide me. Thanks to you, I see past the nothingness. Life, I choose to live in the light.
Hobgoblin Lord
19
Years of Service
User Offline
Joined: 29th Oct 2005
Location: Fall River, MA USA
Posted: 28th Nov 2007 11:12
sounds interesting Diggsey. UDT's can use inheritence and multiple inheritence however. The biggest benefit to OOP in DBP would be being able to create methods for them, the other drawbacks have pretty easy work arounds.




RPDan
17
Years of Service
User Offline
Joined: 29th Apr 2007
Location:
Posted: 28th Nov 2007 17:20
Quote: "UDT's can use inheritence and multiple inheritence however"

Do you mean they can already use inheritance? I'm certain that they can't.
Hobgoblin Lord
19
Years of Service
User Offline
Joined: 29th Oct 2005
Location: Fall River, MA USA
Posted: 28th Nov 2007 19:59
Take a look at the code snippet I posted above. Using it would be like so.




there are just no methods that can be inherited (since you can't define methods for a UDT) the Structs though can be inherited natively in DBP.

Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 28th Nov 2007 20:09 Edited at: 28th Nov 2007 20:10
Not sure if you mean this (edit: after seeing your post I see you do):



... But this isn't inheritance.

Tempest (DBP/DBCe)
Multisync V1 (DBP/DBCe)
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 28th Nov 2007 20:10
@Hobgoblin Lord
That is not inheritance Although in reality, that is how the data is stored, inheritance means that (for that example) you could use Name and Size directly without the '.Base' part.

Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 28th Nov 2007 20:13
Quote: "Although in reality, that is how the data is stored, inheritance means that (for that example) you could use Name and Size directly without the '.Base' part"

And more importantly, using a pointer you can access the base members of a class that has inherited from it.

Tempest (DBP/DBCe)
Multisync V1 (DBP/DBCe)
Mr Z
17
Years of Service
User Offline
Joined: 27th Oct 2007
Location:
Posted: 30th Nov 2007 19:03
How is it going with the project, Diggsey?

Darknes, you haunt me. If I give in, I would be an monster beyond imagining. Light, you guide me. Thanks to you, I see past the nothingness. Life, I choose to live in the light.
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 30th Nov 2007 19:20
I'm waiting for IanM to add a realloc command to his plugin set (And I have a few other projects which need working on) Only ten days of school left now though, and I get loads done during the holidays

Mr Z
17
Years of Service
User Offline
Joined: 27th Oct 2007
Location:
Posted: 30th Nov 2007 21:41
Ok. Know the feeling . Goodluck with everything.

Darknes, you haunt me. If I give in, I would be an monster beyond imagining. Light, you guide me. Thanks to you, I see past the nothingness. Life, I choose to live in the light.

Login to post a reply

Server time is: 2024-11-24 04:24:06
Your offset time is: 2024-11-24 04:24:06