Anyone write compilers?

Community Forums/General Help/Anyone write compilers?

JoshK(Posted 2010) [#1]
I'm interested in designing a new language that's a cross between BlitzMax, C++, and Lua. Even if all we get is some simple examples, it would still be a neat exercise.

My initial ideas are:

-No garbage collection. GC was implemented in BlitzMax because C# and Java were getting popular. It adds ambiguity to the code execution and causes problems when interfacing with other languages. It causes the BlitzMax multithread implementation to run slow.

-The equivalent of BlitzMax "Superstrict" mode is used, always.

-Language is case-sensitive. Often times you want a variable and a class name to be the same, and case sensitivity is the only way to do that, i.e. book:Book.

-C++ style constructors, i.e. book = Book(pages).


If you've done any work with compilers, let's talk.


_Skully(Posted 2010) [#2]
Talk to Mark... He's making a new one as we speak (MAX2)

If you get these ideas in now he might implement them.


JoshK(Posted 2010) [#3]
I am not interested in Mark's plan.


gosse(Posted 2010) [#4]
If you've done any work with compilers, let's talk.

As in "I'm looking for advice, pointers and textbooks" or as in "I want to pay you to write this compiler I'm designing" ?
I'm not looking for a job or side project, but I have some experience with compilers, tokenizers and formal grammars (& code generators). I could definitely give some pointers if one needed help...


_Skully(Posted 2010) [#5]
OK, Curiousity killed the Cat:

If there is no garbage collection how is memory managed? Or do you mean just no automated GC? in other words...deconstructors

I'm curious to know what you mean by a cross between MAX/C++/Lua


puki(Posted 2010) [#6]
"danjamwoo" designed a small language and wrote a compiler and interpreter for it - he has changed his name since (the rotter) - took me ages to find it:
http://www.blitzbasic.com/Community/posts.php?topic=78054#874727

"Jedive" also wrote a compiler:
http://www.blitzbasic.com/Community/posts.php?topic=52190#604847

"RocketGnome" has written compilers in the past:
I haven't written a compiler since college, but it was always a favorite subject.

"Kev" has also mentioned that he wrote a compiler using B+ (about 4-5 years ago).


Gabriel(Posted 2010) [#7]
If there is no garbage collection how is memory managed?

The same way it is in Blitz3D, native C++ or any of the other unmanaged languages. By manually destroying objects when you don't want them any more. And then dealing with all those "whoopsie daisy, you just tried to call a method on an object which was destroyed five minutes ago" issues.

Or do you mean just no automated GC? in other words...deconstructors

Destructors (I assume that's what you mean?) are nothing to do with automated garbage collection or indeed non-automated garbage collecton. Destructors are just methods which get called automatically when an object is destroyed. How they are destroyed and/or managed is not pertinent, except to precisely when they get called. C++, for example, has destructors but does not have a garbage collector.


Nate the Great(Posted 2010) [#8]
I scanned over this
http://compilers.iecc.com/crenshaw/

looks promising but no idea if its what you are looking for


JoshK(Posted 2010) [#9]
Well, would it be wisest to write a compiler, or to run it through something like minGW, the way BlitzMax does?

Yeah, I think objects should be manually deleted. There's so many problems GC has caused BlitzMax (and Lua, for that matter):
-Slow execution in multithread mode.
-Lua needs intermittent pauses to clean up memory.
-Causes problems with DLL compilation, lots of undocumented nuances.
-Problems interfacing with C++ due to this.
-Probably holds BlitzMax back from being supported on more platforms.
-Memory leaks still occur, but now they are much harder to track down.

I'd much rather deal with the possibility of an invalid pointer than have GC doing who knows what behind the scenes.


EOF(Posted 2010) [#10]
I would like to see such a hybrid language which takes a large dose of Lua with a sprinkling of C++

I tried to fathom Marks demo code but never could unravel all that ParseFact(), ParseTerm(), ParseLeaf() terminology

Equally, I tried to cover all possible syntax coding errors as well as allowing for flexibility. In the end it got too complex


Exanding on your thoughts and ideas:

1> All commands and functiions are lower-case. Eliminates the confusion on whether a command should be "DrawImage", "drawImage" , "Drawimage"

2> Interpreted with the option to compile once the code is good
There really is NOTHING like seeing instant results after changing script code. No need to recompile

3> Syntax must follow rigid rules. For example, the then cannot be omitted in an if then [else] end block
Mostly to make life easier for the parser

4> end terminates any type of block (as used in Lua). Easy life

5> All variables must be declared first (via C++ methods)
int aaa=356
float bb=56.3
for c=1 to 10  <-- ERROR (c not delcared)


5. Brackets around functions = yes. Brackets around commands? Not sure whether this should be forced, but my old-skool brain tells me comands do not return anything therefore should not require brackets

General code example



Yasha(Posted 2010) [#11]
I'm writing a compiler, as it happens. Although given that it's GC'd and dynamically typed... probably not of much interest to you. Would be happy to share my findings though.


Canardian(Posted 2010) [#12]
I'm writing the Human language at some point, it will precompile into C++ or optionally C# code, so it will work on all platforms.


JoshK(Posted 2010) [#13]
1> All commands and functiions are lower-case. Eliminates the confusion on whether a command should be "DrawImage", "drawImage" , "Drawimage"

Isn't that a matter of coding? Why would the compiler care what the capitalization was? I prefer DrawImage, myself, because it's easy to read.

2> Interpreted with the option to compile once the code is good
There really is NOTHING like seeing instant results after changing script code. No need to recompile

I am doing exactly this in Leadwerks Editor. Although convenient, it can cause confusion. It would be interesting to see another implementation. I think maybe this is one of those things like GC that people pursue just because it's interesting and challenging, then find out it isn't really a good idea after all.

3> Syntax must follow rigid rules. For example, the then cannot be omitted in an if then [else] end block
Mostly to make life easier for the parser

One of the mistakes Blitz makes is allowing too many different ways of doing things, so I agree. Not sure if the Then keyword is really necessary, but if included, it should be required.

4> end terminates any type of block (as used in Lua). Easy life

My experience with Lua is this can cause confusion because you can't as easily see what kind of block is being terminated. I do prefer the BASIC if/endif and even lua if/end to C++ brackets{}, which are unreadable.

5> All variables must be declared first (via C++ methods)

What do variables and methods have to do with each other?

Basically, my goal here is C++ with less BS and no header files. There are lots of slow GC languages and scripts made for bad programmers, and I don't think another one is needed.


JoshK(Posted 2010) [#14]
Here's one possible concept:

Class Image

	Field data:Ptr

	Method Draw(x:Int,y:Int)
		glDrawPixels(x,y,Self.data) //Self is required!
	EndMethod

	Method Draw() //Overloading allowed, yay
		glDrawPixels(0,0,Self.data) //Self is required!
	EndMethod

EndClass

Local image:Image = New Image( data )

image.Draw(20,30)


Local a:Int=3
a++
Print(a) //prints "4"


I do like this one quite a lot, too:
-- demo 1

int a=42
for int b=0 until 4 ; print b ; end

-- two ways to use color()
if c=45 then
  color RED ; line 30,50,100,200
  color 200,10,4 ; line 30,10,50,80
end

boolean isPositive(val)
   if val>0 then return true
  return false
end


Maybe something like this?:
Class Image

	Ptr data

	void Draw(x:Int,y:Int)
		glDrawPixels(x,y,Self.data) //Self is required!
	End

	void Draw() //Overloading allowed, yay
		glDrawPixels(0,0,Self.data) //Self is required!
	End

End

Image image=Image(data)

image.Draw()



_Skully(Posted 2010) [#15]
Ya... Overloading would be really nice!

Class Image
	Field data:Ptr

	Method Draw(x:Int,y:Int)
		glDrawPixels(x,y,Self.data) //Self is required!
	EndMethod

	Method Draw() //Overloading allowed, yay
		glDrawPixels(0,0,Self.data) //Self is required!
	EndMethod

	' Constructors!
	Method New(data:Ptr)     ' I don't like the class name being used as the constructor... prefer "New"
		Self.data=data
	End Method
EndClass

Local image:Image = New Image( data )

image.Draw(20,30)




JoshK(Posted 2010) [#16]
I actually do like the Lua-style End terminator that was suggested, now that I think about it. It's nicer than having all these EndMethod statements all over, and it's also more readable than {}:
Class Image

	Ptr data

	Method Draw(Int x,Int y)
		glDrawPixels(x,y,Self.data) //Self is required!
	End

	Method Draw() //Overloading allowed, yay
		glDrawPixels(0,0,Self.data) //Self is required!
	End

	//Constructors!
	Method New( Ptr data )     // I don't like the class name being used as the constructor... prefer "New"
		Self.data=data
	End
End

Image image = New Image( data )

image.Draw(20,30)



*(Posted 2010) [#17]
Josh: I would parse everything written into GCC compilable code and run it through that, GCC is available on almost everything.


Who was John Galt?(Posted 2010) [#18]
Well, would it be wisest to write a compiler, or to run it through something like minGW, the way BlitzMax does?
BlitzMax implements a BlitzMax compiler. The compiler spits out FASM (flat assembler) code that is compiled by the excellent and free FASM. MingW is just used to compile the C code that is in some of the modules.

As to which is the best way forward, going the FASM route gives you the ultimate control over the optimisation of the final code produced and would probably be faster to compile, whereas generating intermediate C (ala BMax2) would probably be somewhat easier and gives you access to a large number of platforms via existing C compilers.

Hate the idea of case sensitive variables, but I love the idea of Blitzmax minus the annoying garbage collector!

You might take a look at Ken 'Duke Nukem' Silverman's EvalDraw for some inspiration.
http://www.advsys.net/ken/download.htm#evaldraw

Oh, and don't get too smart with your syntax... you and I both know the BlitzMax template it just about perfect!

Good luck with this!!!


JoshK(Posted 2010) [#19]
Josh: I would parse everything written into GCC compilable code and run it through that, GCC is available on almost everything.

It would be easy to translate code into C++, but how would you get errors and debug info back from the compiler in any meaningful way?


_Skully(Posted 2010) [#20]
One of the mistakes Blitz makes is allowing too many different ways of doing things, so I agree. Not sure if the Then keyword is really necessary, but if included, it should be required.


I have to disagree here. All you have to do to support "Then" is to remove it during the pre-compile... Programming language structure is there to make unreadable computer jibberish into a human readable version. Including things like the word THEN in some cases makes it more readable... just like EndIf, Wend vs {}

Making a language that adheres to only your style of programming would probably spell an end to it... at least a new one anyway.


Who was John Galt?(Posted 2010) [#21]
Whilst I agree with Skully on general principle, 'then' HAS TO DIE.


Dabhand(Posted 2010) [#22]
I actually prefer {} over End[Something]... It makes a lot more sense to me as you can just close a block of code and jobs a good'un, well, as long as you indent your code so you can easily follow the nesting of each {} block.

I also like splitting the class declaration and the body of each class method, so I suppose, if I had my way, it'll resemble something like:-

Class Image {

	Ptr data

	Method Draw(Int x,Int y)
	Method Draw()

	//Constructor - Declare if programmer needs to incorporate their own constructor body code, otherwise, let C++ (if going that route) create a default one.
	Method New( Ptr data )     // I don't like the class name being used as the constructor... prefer "New"
	//Destructor - Same as constructor
	Method Delete()
}

Method Image::Draw(Int x,Int y)
{
	glDrawPixels(x,y,Self.data) //Self is required!
}

Method Image::Draw() //Overloading allowed, yay
{
	glDrawPixels(0,0,Self.data) //Self is required!
}

//Constructor!
Method Image::New( Ptr data )     // I don't like the class name being used as the constructor... prefer "New"
{
	Self.data=data
}

//Destructor!
Method Image::Delete()     
{
	Self.data=Null
}


Obviously, I would treat them in a traditional header/body files way within the project.

Dabz


taumel(Posted 2010) [#23]
So let me get this straight, you're ashamed of BlitzMax because no one knows it but now you're trying to come up with your own non gb collector but still easy to use language which exactly is known by how many people?


_Skully(Posted 2010) [#24]
Do you have some kind of need to critique Josh no matter what he posts?

He's not ashamed of BlitzMax, its just not known well enough to use it as a selling point with LE... despite that he still has BlitzMax related information on his web.

Ugh.


*(Posted 2010) [#25]

It would be easy to translate code into C++, but how would you get errors and debug info back from the compiler in any meaningful way?


I do believe that
g++ "myfile.cpp" 2> "output.txt"

is what your looking for, basically ALL output is sent to output.txt


Who was John Galt?(Posted 2010) [#26]
@Dabs, there's a language works just like you want. It's called C++. :b


JoshK(Posted 2010) [#27]
EdzUp, your proposed approach is interesting. It would retain the power of C++, and even the ability to translate the final code to that language, while avoiding the choices I believe are problematic for BMX2.


_Skully(Posted 2010) [#28]
Josh: I would parse everything written into GCC compilable code and run it through that, GCC is available on almost everything.

Isn't this basically the approach that Mark is taking? Takes the code and translates that to a bunch of different languages?


JoshK(Posted 2010) [#29]
Yeah, but he is cutting out essential language functionality.


JoshK(Posted 2010) [#30]
Following Ed's advice, I put together a simple package that compiles a cpp program:
http://www.leadwerks.com/post/compile.zip


_Skully(Posted 2010) [#31]
Yeah, but he is cutting out essential language functionality.

Did I miss the memo? I didn't know Mark had released anything yet...


Tommo(Posted 2010) [#32]
You can use "#line" in C++ code to modify debuginfo generated by GCC to match actual source code. After that, you can use gdb for debugging.

http://blogs.ethz.ch/copton/2009/11/09/meta-level-debugging/


JoshK(Posted 2010) [#33]
Wow, cool info.

I got this:
Print "Hello!"
Print "This is my awesome programming language."
RuntimeError "Here is an error!"
Print "Do you like it?"


To translate into this and compile:
#include <stdio.h>
#include <String>
#include <math.h>
#include <process.h>

void Print(const std::string& s)
{
	printf("%s\n", s.c_str());
}

void End()
{
	exit(EXIT_SUCCESS);
}

void RuntimeError(const std::string& s)
{
	printf("%s\n", s.c_str());
	exit(EXIT_FAILURE);
}

int main(int argc, char* argv[])
{
	Print("Hello!");
	Print("This is my awesome programming language.");
	RuntimeError("Here is an error!");
	Print("Do you like it?");
}



_Skully(Posted 2010) [#34]
Yup.. I have C++ vertigo

that second listing literally makes me want to hurl


Dabhand(Posted 2010) [#35]

@Dabs, there's a language works just like you want. It's called C++. :b



Yeah, I like a bit of C++, so a C++/BASIC type hybrid would be lovely in my eyes! :D

Dabz


JoshK(Posted 2010) [#36]
If the translator was open-source, you could use whatever symbols you want. And if anyone else gives you a hard time, just hand them the exported C++ project.

I'm hoping someone who has already written code parsers will take this up. I can help with the C++ end.


Tommo(Posted 2010) [#37]
If you just want a new language, maybe ooc is a nice choice.
Its syntax is compact and nice, and it supports a bunch of advanced feature.
It compiles into C99 source. The whole project is opensource, so I think there's quite a lot you can learn from it.
http://www.ooc-lang.org/


*(Posted 2010) [#38]
Some modifications to make it C++ compliant :) C++ cout is more powerful than printf
#include <iostream>
#include <string>
#include <math.h>

void Print(const std::string& s )
{
        cout << s << endl;
}

void End()
{
	exit(EXIT_SUCCESS);
}

void RuntimeError(const std::string& s )
{
        cout << s << endl;
	exit(EXIT_FAILURE);
}

int main(int argc, char* argv[])
{
	Print("Hello!");
	Print("This is my awesome programming language.");
	RuntimeError("Here is an error!");
	Print("Do you like it?");
}



Roger(Posted 2010) [#39]
I must say Josh (and I sure many will cane me for this), but your language requirements seem to me almost met to a T by Delphi.

Delphi 2011 is going to be Windows/OSX and possibly Linux(?), admitting than it would have to be a better crossover than the mess that was Kylix (Delphis short lived old foray into cross platorm linux development).

Look at the language in Delphi 2010

Good UI integration (via the VCL)
Properties
Function Overloading (don't think it has operator overloading)
Inheritence (not multiple)

Components up the wazoo for almost any task (included and 3rd party)

Componentised examples of integrated 3d engines (i.e. Ogre) to give you a walk up start to embedding existing Leadwerks Engine

And a pascal syntax that is really much more spirited towards Blitz style syntax than C++

Win32 native/not GC'd

Product also comes (in RAD studio guise) with C++ compiler/options (handy for 3rd party code integration)

I've always thought it an extremely productive environement/elegant language albeit that its a little wordy.

With ide addons like castalia it's also a seriously productive IDE.

So many people bash Delphi, and yep Borland/Embarcadero have made many misteps but for someone that wants a clean non GC'd non virtual machine native compiled language with good compilation speed and a really nice integration with forms/form designer, to this day I say Delphi is really hard to beat.

Advice would be to evaluate either Delphi 7 (old) or Delphi 2010 (latest), as the versions in the middle lost their way significantly in terms of QA/IDE reliability.

The professional/base version would be all you need (The enterprise/architect version comes with UML/DBDrivers/Bunch of very non game centric business app type carry on, professional (I think) still has the source code of the entire component library (VCL) which is good for learning, and any tweaking/subclassing for your specific needs.

Regards,

Roger.


Canardian(Posted 2010) [#40]
@EdzUp: printf() is faster and has much easier formatting control. And you should not remove "const string& s", since it's the right way to do. A simple "string s" would take a copy of the memory and be much slower also.


*(Posted 2010) [#41]
Ah I see :) being a old C hack coming to C++ has quite more to learn like Classes, Vectors etc :)


JoshK(Posted 2010) [#42]
I must say Josh (and I sure many will cane me for this), but your language requirements seem to me almost met to a T by Delphi.

I actually really like the idea of translating to C++ and treating it as an intermediate format. The thing is, in today's world if code isn't C++, it is worthless.

I've already looked into auto-generating header files and lua bindings, so this isn't that different. I get tired of declaring functions three times each.

C++ isn't really a programming language, it's more a file format.


_Skully(Posted 2010) [#43]
Yeah, but he is cutting out essential language functionality.

Josh, Are you talking about the pointer removal?


JoshK(Posted 2010) [#44]
Josh, Are you talking about the pointer removal?

Yes, along with the inability to use external libraries, and whatever else we don't know about yet. In general, it sounds like BMX2 is a step back to a Blitz Basic type thing.


plash(Posted 2010) [#45]
Yes, along with the inability to use external libraries, and whatever else we don't know about yet. In general, it sounds like BMX2 is a step back to a Blitz Basic type thing.
Not really. It's just not for desktops.


Canardian(Posted 2010) [#46]
BMX2 is different, it's not clearly better or worse than BMX1, but since BMX1 is quite useless since there is C++, I would say even at its first stage BMX2 is better than BMX1.

When BMX2 is further developed to include more commands and features, it will be much clearer that it's indeed better than BMX1.


JoshK(Posted 2010) [#47]
This is going pretty well. I got this:
Function func:String()
	Return "Here is a string."
EndFunction

Function func2:Int()
	Return 2
EndFunction

Print func()
Print func2()
Print 2.8+func2()


Translating to this:
#include <stdio.h>
#include <String>
#include <math.h>
#include <process.h>
#include <sstream>

void Print(const std::string& s)
{
	printf("%s\n", s.c_str());
}

std::string String( int i ) {
	std::stringstream out;
	out << i;
	return out.str();
}

std::string String( double f ) {
	std::stringstream out;
	out << f;
	return out.str();
}

void End()
{
	exit(EXIT_SUCCESS);
}

void RuntimeError(const std::string& s)
{
	printf("%s\n", s.c_str());
	exit(EXIT_FAILURE);
}

float Float( int i )
{
	return float(i);
}

float Sign( float f )
{
	if (f<0.0) {
		return -1.0;
	}
	else {
		return 1.0;
	}
}

int Int( float f )
{
	return int(f+0.5*Sign(f));
}

#line 1 "test.txt"
std::string func() {
#line 2 "test.txt"
return "Here is a string.";
#line 3 "test.txt"
}

#line 5 "test.txt"
int func2() {
#line 6 "test.txt"
return 2;
#line 7 "test.txt"
}

int main(int argc, char* argv[])
{
#line 9 "test.txt"
	Print(func());
#line 10 "test.txt"
	Print(String(func2()));
#line 11 "test.txt"
	Print(String(2.8 + func2()));
}



Canardian(Posted 2010) [#48]
Function myfunc1
...
EndFunction
is redundant, since End would be enough to indicate the end of the block.

I would be cleaner like this:
Function myfunc1
...
End
or to make it more coherent:
Begin myfunc1
...
End
You don't really need to say function, procedure, method, since they all can be functions which either return a value or don't, that's what you must specify in their declaration.

But the need to type such long words like Begin and End, can also destroy the fun in programming, since most programmers get a motivation boost when they can just type { and } - it feels good, cool, professional, academic, effective, and fun of course. So your language should allow pure C++ code besides the BASIC code (like BMX1 does). The parser would then just pass the C++ as-is, and not convert it, not even need to recognize it, it would just compile.


Who was John Galt?(Posted 2010) [#49]
IMO, having 'Function' at the beginning of the line is the best for readability. The differentiation between functions and methods is also useful.


JoshK(Posted 2010) [#50]
I'm going to follow the BMX syntax until I come across something I am sure I want different. So far I have:

-Math operations with correct order (not just copying BMX code to C++)
-String, float, and integer variables
-Functions
-Automatic conversion between variable types (partial)

Not bad for less than one day:
Function Min:Float(a:Float,b:Float)
	If a<b
		Return a
	Else
		Return b
	EndIf
EndFunction

Local a:Int=3
Local b:Int=2

Print Min(b,a)



D4NM4N(Posted 2010) [#51]
I would like c++ but with less ways of doing things (ie 100 ways as opposed to 100000s ) and without the need to prototype and pre-declare everything in headers.


JoshK(Posted 2010) [#52]
The auto-conversion of variables is the biggest time saver. My code:
Local a:Int=3
Local b:Int=2
Print Min(b,a)
C++:
float a = 3.0;
int b = 2;
Print(String(Min(Float(b),a)));



Who was John Galt?(Posted 2010) [#53]
I'm going to follow the BMX syntax until I come across something I am sure I want different. So far I have:

-Math operations with correct order (not just copying BMX code to C++)
-String, float, and integer variables
-Functions
-Automatic conversion between variable types (partial)
So far, I love where you are going with this. Can you explain the correct order math a little more? C++ has different evaluation precedence to Max?

Have you given any consideration to structs and static (inline and not via pointer) arrays? Although I love the simplicity of the Blitz type system, the lack of these can be a real pain when interfacing with external code.


JoshK(Posted 2010) [#54]
Woot, this is going pretty fast. This actually works:
Function Min:Float(a:Float,b:Float)
	If a<b
		Return a
	Else
		Return b
	EndIf
EndFunction

Local a:Float=3
Local b:Int=2
Local c:String="0.5"
Local d:Float = Min(a,b)

Print "d = "+d
Print Min(d,c)
Print "Part" + " " + b


For operation order, I'll just show some examples of the BMX code and the C++ equivalent:

a = 1 + 2 + 3
a = ( 1 + 2 ) + 3;

a = ( 1 + 2 ) * 3
a = ( 1 + 2 ) * 3;

a = 1 + 2 * 3
a = 1 + ( 2 * 3 );

a = 1 * 2 / 3
a = ( 1 * 2 ) / 3;

a = 1 + 2 / MyFunc()
a = 1 + ( 2 / MyFunc() );

I don't know what C++ does by default. I just did it following mathematics rules of first * and /, then + and -, left to right. I haven't added ^ yet, but that goes before anything else.

Have you given any consideration to structs and static (inline and not via pointer) arrays?

I don't know, I will deal with it when it comes up.

I think We definitely need this:
Type Vec3
Field x:Float
Field y:Float
Field z:Float

Method Add(v:Vec3)
self.x = self.x + v.x
self.y = self.x + v.y
self.z = self.x + v.z
EndMethod

EndType

a=Vec3(1)
a=Vec3(2)

c = a + b



Russell(Posted 2010) [#55]
Writing compilers is advanced stuff, as I'm sure you know. I seem to remember seeing several books on this subject at my local Barnes & Noble a few years ago. I opened one authoritative looking book to page 1237 (about half way through the book...), eyed the sample code and slammed that puppy shut! LOL!

It would be an excellent learning exercize, but... Do we really need yet another programming language? Ok, maybe so. Good luck! :)

Russell


JoshK(Posted 2010) [#56]
Here's a new example you can play with:
http://www.leadwerks.com/post/compile.zip

myprog.txt is the program source. The .bat files should be pretty self-explanatory. The translator will generate myprog.cpp and myprog.h, which you can then compile into myprog.exe with the g++ compiler.

Surprisingly, this pretty formidable example works. The pre-processor performs two passes so you can put globals and functions anywhere you like:
Function Min:Float(a:Float,b:Float)
	If a<b
		Return a
	Else
		Return b
	EndIf
EndFunction

Local a:Float=3
Local b:Int=2
Local c:String="0.5"
Local d:Float = Min(a,b)

Print "d = "+d
Print Min(d,c)
Print "Part" + " " + b+"!"
Print test
Print 3+func()
Print aa()
Print test3

Function aa:Int()
	Return bb()
EndFunction

Function bb:Int()
	Return 1
EndFunction

Function func:Int()
	Return test
EndFunction

Global test:Int=5
Global test2:Int=test
Global test3:Int=aa()



*(Posted 2010) [#57]
excellent stuff :)


Robert Cummings(Posted 2010) [#58]
Basically, my goal here is C++ with less BS and no header files. There are lots of slow GC languages and scripts made for bad programmers, and I don't think another one is needed.


Thats what I want too. C++ syntax and structure without the bullshit.


JoshK(Posted 2010) [#59]
Can someone look into debugging the EXE? It would save me some time so I can focus on the preprocessor. I don't know what to do besides add the -g flag to the g++ command line.


Canardian(Posted 2010) [#60]
There's no point debugging an exe, it would be so cryptic due to all the compiler optimizations that you wouldn't understand one instruction. The bugs should be fixed in the nassi-shneidermann diagram, or if it's not made, then in the C++ source code.


Gabriel(Posted 2010) [#61]
Not to rain on anyone's parade, but the GCC compiler is very unoptimized, as C++ compilers go. Many of those "slow GC languages" which were "made for bad programmers" are still significantly faster than C++ compiled with GCC.


Canardian(Posted 2010) [#62]
Actually it's not that bad if you find the right compiler options. A C++ test program ran first 2.5 times slower than with Visual C++, but after some playing around with the options, I got it to run slightly faster than Visual C++. I think the secret option was -O6, which is not documented anywhere, but it makes insane fast code :)

I saw somewhere mark saying that BMX1 is using -O2, so if there was a way to change it to -O3 or -O6 (not sure which was the magical option, have to find my example again), then BlitzMax programs could also run over 2.5 times faster than they do now. I tried also to find the place where BMX1 compiles the C++ code, but couldn't find it.


JoshK(Posted 2010) [#63]
Well, you can compile the intermediate C++ code with anything. G++ is convenient for seamless translation / running. Maybe the final build would be done with MS Visual Studio, with an exported project file.


Gabriel(Posted 2010) [#64]
I saw somewhere mark saying that BMX1 is using -O2, so if there was a way to change it to -O3 or -O6 (not sure which was the magical option, have to find my example again), then BlitzMax programs could also run over 2.5 times faster than they do now.

As has been stated several times already on this thread alone, BlitzMax is its own compiler. Hence, adjust the compiler settings will only affect C++ code which is linked to BlitzMax. BlitzMax code would not be affected.

Maybe the final build would be done with MS Visual Studio, with an exported project file.

It would be nice to have that option, particularly with Visual Studio coming to Mac.


JoshK(Posted 2010) [#65]
I've got include files (not import) working, and implemented blocks with variables, so stuff like this works:
if a=1
	Local b=3
	Print b
EndIf

'This does not work:
Print b
The precompiler detects what type of data a variable is, and automatically converts values, which is how you are able to do stuff like Print(3) or "Hello"+1.

Global variables and user-defined functions are 100% working, as is the "=" (C++: ==) operator.

Classes are the really good stuff, but I would like to make some progress with the debugger before starting that. Can anyone help?


Canardian(Posted 2010) [#66]
Visual Studio has a working C++ debugger, you don't need anything else. On Linux there is CodeBlocks, which is also on Windows though, and it can use the GNU C++ compiler, even MinGW.


Who was John Galt?(Posted 2010) [#67]
Visual Studio has a working C++ debugger, you don't need anything else.
That's all well and good if you have Visual Studio AND you're a reasonable C++ programmer AND you're happy to debug in a different language than you wrote the code in. I guess what I'm really saying is, that's not at all well and good for the majority of people.

I think building a proper LeadMax(TM) debugger could be the toughest part of this project.


*(Posted 2010) [#68]
There are things like the 'stacktrace' library that will do stack checking and other libraries that will do it for other platforms. On the whole its more of a 'conversion from error log' to 'something useful' thats the tricky bit :)


Canardian(Posted 2010) [#69]
The best debugger is still the printf() command. It works also from the command line. And you should learn not to make mistakes, and you will learn it much better when debugging is harder.


Who was John Galt?(Posted 2010) [#70]
The best debugger is still the printf() command. It works also from the command line. And you should learn not to make mistakes, and you will learn it much better when debugging is harder.
I suspect you are saying this tongue somewhat in cheek. People who get some perverted thrill from debugging with printf() will be writing their games in C++ or pure assembly, not LeadMax.


Canardian(Posted 2010) [#71]
No, it's a viable way to debug. I use sometimes debug mode code with Visual Studio, but it's not really easier than using printf() statements, since when the code does a lot of iterations and runs fast, then printf() is by far the easier and faster way to debug things. I just run my program as usually, and then check the stdout log what happened with my variables.


JoshK(Posted 2010) [#72]
I was able to compile a DLL and a static library yesterday. Class definitions (types) are working. Now to get object variables, fields, and methods accessible.

The last uncertain bit of this is to see how well it can interface with external C++ code. If that works, this could be an enormous time saver.


EOF(Posted 2010) [#73]
Good work and progressing nicely

What's your thoughts on how flexible your parser should be?
What I mean by that, should you insist that a command be separated by one space only? I know coders like to use tabs and open brackets. Taking that into consideration would the following code lines break the parser?
Print"hello"      <--- No space between command and args although " is valid
Print    "help"   <---- Tabbed char used instead of space
Print(13245)    <---- Again, no space here although brackets are commonly used


One other thing, I see the current parser splits the line at // but that would break a literal string if it happened to contain the same double-slash
Also, if command-like words are used in a literal string does it affect parsing?

Example:
Print "The End // Or Not?"     <-- Commands End Or Not and comment // in the string



N(Posted 2010) [#74]
Don't know how useful this would be to anyone, but I have a lexer up here for BlitzMax. Might be easy to modify (if you know enough C) if you want to target something syntactically similar to BlitzMax, and you don't want to deal with writing the lexer yourself.


JoshK(Posted 2010) [#75]
Jim Brown. don't worry, I'm not being lazy with the parser.

Nilium, can you explain more what your lexer does?


N(Posted 2010) [#76]
It's a lexer. It breaks BlitzMax source code into tokens (e.g., number literals, hex literals, string literals, identifiers, various keywords, etc.) and handles a few extra bits like keyword pairs ("End Method" and "endmethod" are a single token, despite them being separate by whitespace). It also includes my own additions to the syntax which can be disabled easily (see the README for that), although they serve as a good example of how to expand upon the lexer (with one exception- again, the README).

It doesn't handle parsing of the tokens, but breaking them up into tokens makes it all a good deal easier to parse source code.


JoshK(Posted 2010) [#77]
Cool. My tokenizer records variable types and will auto-convert between them, i.e. you can do this:
Local s:String = "Hello "+1
Local n:Int="2"

There's probably a way to override the + operator in C++ and get the same behavior, so I am not sure if it is necessary.

It also detects errors before compiling, so it will catch mistakes like calling a function or variable that hasn't been declared. A line-by-line converter certainly would have been easier, but I am not sure if it is possible.


Canardian(Posted 2010) [#78]
Looks like it's gonna be a smart compiler, perfect for game development. And I hope you can always escape to literal C++, you can make a tag for it.


JoshK(Posted 2010) [#79]
This works now:
Type Vec3
	Field x:Float
	Field y:Float
	Field z:Float
EndType


Local v:Vec3

v.x = v.x + 1
v.y = 2
v.z = 3

Print v.x+", "+v.y+", "+v.z

I think I am going to divide the types up into two kinds for pointers and references. References are things like a Vec3, where they are pretty much like a variable. You wouldn't want to code this:
Local n:Int=New Int
n=1
Delete n

Instead you just do this:
Local n:Int
n=1

Same goes for Vectors and stuff like that.

Pointers, on the other hand, are for classes that get created and deleted:
mesh=LoadMesh()
Delete mesh

The difference could be indicated in the Type declaration like this:
Type Vec3 {cantthinkofatermtouse}
EndType



JoshK(Posted 2010) [#80]
This is wonderful:
Type Vec3
	Field x:Float
	Field y:Float
	Field z:Float
EndType


Local a:Vec3
Local b:Vec3

a.x = 1
a.y = 2
a.z = 3

b=a

b.x=6

Print a.x+", "+a.y+", "+a.z
Print b.x+", "+b.y+", "+b.z

Here's the output:
1, 2, 3
6, 2, 3



_Skully(Posted 2010) [#81]
How about
Type Vec3 {Var}    ' declares it as a variable type?
	Field x:Float
	Field y:Float
	Field z:Float
EndType


If this:
Local a:Vec3
Local b:Vec3

Causes an instance then how do we make a null declaration

local a:Vec3=null

?


JoshK(Posted 2010) [#82]
Option 1:
Type Vec3 {Var}
	Field x:Float
	Field y:Float
	Field z:Float
EndType

Local a:Vec3
a.x=1
'nothing to clean up, no garbage collection needed.  It's just a variable.

Option 2:
Type Vec3
	Field x:Float
	Field y:Float
	Field z:Float
EndType

Local a:Vec3 'a is Null at this point!
a=New Vec3
a.x=1
Delete a 'a has to be manually deleted



*(Posted 2010) [#83]
TBH Option one would be more user friendly as it doesnt require initialisation, coming from C++ etc most variables you create are initialised.


degac(Posted 2010) [#84]
What about a sort ot 'auto-initialization' for objects-type?
Type Vec3
	Field x:Float
	Field y:Float
	Field z:Float
EndType

Local a:Vec3 'it is nothing, just a declaration
a.x=1 'the compiler 'creates' a NEW 'a' object and its field 'x' is now 1
Delete a 'a has to be manually deleted


The problem is when you dont' set any fields and you make something like

if a=NULL then...

the compiler should create 'on-the-fly' the object and set it to NULL... and then? Delete at ENDIF? Or keep it alive?
Or simply raise an error of 'not-defined-object'(the wiser solution)?
I dont'know how it should be efficient in a language that should not have a GC in it (as seen in the firts post)


Who was John Galt?(Posted 2010) [#85]
No... you either have to create AND delete it, or the compiler creates and deletes it. Auto creation combined with manual deletion is a recipe for disaster.


JoshK(Posted 2010) [#86]
I didn't mean those as options you have to choose between now. They can BOTH be used.

Some things you want to create and delete manually, like an image. With auto-initilization, the variable can never be set to Null, which if you compare it to a regular float or integer, it makes sense:
Local a:Int
a=1
a=Null 'what the hell are you trying to do?

Likewise, this would not work:
Local a:Vec3
a.x=1
a=Null 'what the hell are you trying to do?

The other mode uses pointers, so the variable can equal Null:
Image img=LoadImage("test.bmp")
If img=Null
Notify "Failed to load image!"
Else
Delete img
EndIf

In C++ you choose between these options with the variable itself, and it involves a lot of */& crap. This makes no sense to me. Some Types are something you want to create and delete manually, and others like vectors are just fancy variables that are useful for doing stuff. So I think the difference should be defined in the Type declaration, and the precompiler will generate consistent code for either.

The "variable" mode has the advantages of garbage collection. You would not want to manually delete a bunch of Vec3 objects. However, it has no CPU overhead, no more than just using a local int or float or something. The pointer mode that requires manual deletion of course does not require GC either. In fact, GC would offer absolutely nothing to improve this scenario.


Canardian(Posted 2010) [#87]
You can also set auto-initialized variables to "null", if you load the image in scope, so when the scope ends, the variable is deleted from memory.
I hope your bmx3 supports scopes, since they are one of the most powerful and useful tools in C++.


JoshK(Posted 2010) [#88]
Maybe the two modes of types should be called different things. Here are some possible names to choose from:
Type
Class
Structure
Frame

Any other ideas?


Canardian(Posted 2010) [#89]
Dynamic Image img=LoadImage("test.bmp")
If img=Null
	Notify "Failed to load image!"
Else
	Delete img
EndIf



Zeke(Posted 2010) [#90]
Graphics 800,600
Drawtext "Hello World",0,0
Flip
Waitkey()

how you compile this?


Who was John Galt?(Posted 2010) [#91]
Well, the Blitz-esque type that can accept NULL should be called a type.

The other version looks a lot like a structure, so I would call it a struct, unless it is not a struct behind the scenes?


Gabriel(Posted 2010) [#92]
The other version looks a lot like a structure, so I would call it a struct, unless it is not a struct behind the scenes?


Structs and Classes in C++ are identical except for the default access modifier (which is public in a struct and private in a class.) So I think they could be either. I think the distinction Josh is making is whether you create objects on the stack or on the heap. In C++, objects created on the heap call new, making it clear that it has been created and must be destroyed. Objects created on the stack do not use the new keyword and are destroyed automatically when they lose scope.

I think that's right. It's been quite a long time since I did any C++. Anyway, my point would be that - if you're going to have both - which I personally think is dangerous for inexperienced programmers to use - then a clear distinction is needed and the C++ style of calling new when creating on the heap is probably the most obvious distinction you could have. Even then, it's not immediately obvious what functions are doing. If I call LoadImage, it would have to create a new image on the heap, but I haven't used the new keyword myself. Am I, as an inexperienced programmer going to realize that I need to manually destroy this?


Yasha(Posted 2010) [#93]
I would say the best option is to make automatic (stack) allocation of structures another option to add to the class definition, in the same place where you might normally find "Abstract" or "Final" - so you could say "Auto Type ... End Type". That way inexperienced programmers can just ignore it, the same way they can ignore "Abstract" in BlitzMax or Java. "Auto" or "Value" strike me as the best keywords for this usage.

Alternatively, you could draw the distinction between "Type" and "Class" or a similar pair... but I think this has a higher risk of causing confusion.

Either way, as long as the compiler's able to emit a clear error message if someone tries to use New on an automatic structure, it should be clear enough what's going on.


JoshK(Posted 2010) [#94]
Graphics 800,600
Drawtext "Hello World",0,0
Flip
Waitkey()

how you compile this?

You write your own graphics module and import it into the code. All those nice neat modules BlitzMax has, I don't care about.

The other version looks a lot like a structure, so I would call it a struct, unless it is not a struct behind the scenes?

They're actually both classes, and can both have methods. One mode uses pointers, the other uses references. I find it extremely confusing how C++ uses the variable declaration to define how the class should act.

Structs and Classes in C++ are identical except for the default access modifier (which is public in a struct and private in a class.) So I think they could be either. I think the distinction Josh is making is whether you create objects on the stack or on the heap. In C++, objects created on the heap call new, making it clear that it has been created and must be destroyed. Objects created on the stack do not use the new keyword and are destroyed automatically when they lose scope.

You are correct.

If I call LoadImage, it would have to create a new image on the heap, but I haven't used the new keyword myself. Am I, as an inexperienced programmer going to realize that I need to manually destroy this?

It makes sense to me. In Blitz3D you had LoadMesh() and FreeEntity(). In this, you would use LoadMesh() and Delete(mesh), with a deconstructor in the class.

I like the term "Structure" because it sounds more like what a Vec3 class would be, even through internally they are both using C++ classes.


Who was John Galt?(Posted 2010) [#95]
Ah okay, I'm only fluent in C and you guys are talking C++.

Yeah, I think either Gabriel/Yashas method of differentiating the two are fine. I don't think it will generate confusion for experienced programmers, but it will for newbies. I think the only way to get around it is to make structures an advanced topic, not because it is any more complicated than a type, but because the differentiation between the two will confuse newbies, and you can do anything with a type that you can do with a structure.

The problem there is that this would mean keeping structures out of your basic examples. Don't underestimate the amount of confusion this subject could cause a new programmer. I suspect it's the reason Mark never implemented something similar.


JoshK(Posted 2010) [#96]
The only use I can think of for structures is for multidimensional math, i.e. vectors, matrices, quaterions, etc., but it's EXTREMELY nice to be able to do stuff like this:
a = Vec3(5)
b = a + Vec3(1,2,3)
b = b.Normalize()

...and not have any clean-up to worry about.


_Skully(Posted 2010) [#97]
Yup that would be cool...

How would you control the constructor signatures?


JoshK(Posted 2010) [#98]
Maybe like this:
Type Vec3

Method New(x:Float)
self.x=x
self.y=x
self.z=x
EndMethod

Method New(x:Float,y:Float)
self.x=x
self.y=y
self.z=y
EndMethod

Method New(x:Float,y:Float,z:Float)
self.x=x
self.y=y
self.z=z
EndMethod

EndType



_Skully(Posted 2010) [#99]
I don't know I'm not convinced

Basically, no matter what you are referencing an instance of that structure/type... we seem to just be talking about different ways to interact with it via short-hand code. One way or another you need to know the type definition to know what methods it has.

local v1:Vec3=Vec3(2,3,4) ' instance of type Vec3 with params 2,3,4
local v2:Vec3             ' of type Vec3 but null referenced
local v3:Vec3=New Vec3    ' instance of type Vec3 with 0'ized params
local v4:vec3(2,3,4)      ' instance of type Vec3 with params 2,3,4



Who was John Galt?(Posted 2010) [#100]
I wouldn't call the initialisation method 'new'. It is misleading if it can be declared for structures as well as types. Call it init() or somesuch.


JoshK(Posted 2010) [#101]
One way or another you need to know the type definition to know what methods it has.

So?

Call it init() or somesuch.

I won't ever abbreviate words like that. But feel free to suggest a scheme, I am pretty open to ideas for the constructors.


Perturbatio(Posted 2010) [#102]
Why not just call the constructor "construct"?


Ian Thompson(Posted 2010) [#103]
Have a close look at Delphi's Object Pascal, it's probably the best language I know. The syntax is a work of art. It was so well done, Microsoft stole the head designer to create C#, which is just Object Pascal+C++


N(Posted 2010) [#104]
https://gist.github.com/97862bbdf561e31d49e9 (Warning: horrifying generated code inside)

^ This is kind of fun. (Note: the class_t and such stuff is here, if you want more horror.) I doubt if I'll take the parsing/etc. much farther, but it's kind of neat. Might add parsing for something like a Struct type or something, at least, so I can flesh out some idea for by-value types...


Winni(Posted 2010) [#105]
It was so well done, Microsoft stole the head designer to create C#, which is just Object Pascal+C++.


I'm pretty sure that Mr Hejlsberg makes a ton of money at Microsoft and probably also enjoy his freedom and influence there. "Stealing" is not the right word here. He simply chose to go to the top.

If you want to talk about stealing in the context of Pascal, then maybe you should rather mention Niklas Wirth and his original creations Pascal, Modula and Oberon of which everybody else "borrowed" design concepts.


Ian Thompson(Posted 2010) [#106]
'stealing' was used, with more than a hint of sarcasm.... It sounded better, to me, than 'Selling out'.... :P


Winni(Posted 2010) [#107]
It's okay, I'm sure he sold himself very willingly - The Bill probably made him an offer he couldn't refuse. ;-)

I liked what Anders did with C# 1.0. Actually, I liked it more than his Object Pascal. But just like the Java guys, he's been drowning his language in featuritis ever since. Somebody should tell them that less is more and that simplicity is the way to perfection.

"A designer knows that he's reached perfection not when there is nothing left to add, but when there is nothing left to take away."

Whoever wants to design and implement yet another all purpose programming language should keep that in mind. And they should document it very well, if people are supposed to actually use it.


Ian Thompson(Posted 2010) [#108]
I agree, C# is a great language, I used it when it was on version 2. If it was available for more platforms, it would be a killer language.


Roger(Posted 2010) [#109]
Via Mono it's available on

Linux
Mac
Windows
Some Nokia devices
iPhone (via CocoaTouch)

Some of these are commercial, but C#/A good degree of the .Net stack is available for a plethora of devices/platforms.

Good to see someone else still loves the Delphi syntax apart from just me BTW :)


JoshK(Posted 2010) [#110]
I am leaning towards making this a private tool for my own use, and not selling any kind of programming language. Is there a demand for something like this?


Mr. Write Errors Man(Posted 2010) [#111]
Depends what it is in the end.

If I'd have to choose a scenario with highest success potential, I'd choose a BASIC language that allows hassle-free wrapping/porting/whatever of C++ libraries. If BlitzMax would have had Qt, Ogre etc libraries running five years ago, the scene would be very different.

Though we have had Wx, Irrlicht etc libraries for years, and all we got is us. :D


Who was John Galt?(Posted 2010) [#112]
Depends where it goes, but very interested.


Czar Flavius(Posted 2010) [#113]
Method Add(v:Vec3)
 self.x = self.x + v.x
 self.y = self.x + v.y
 self.z = self.x + v.z 
EndMethod

Please make your language flexible. I like to use then on one line if statements to make them more readable. I hate self but understand others might like it. I'll put it this way though, the two incorrect parts are difficult to see because the two vital characters are hidden by ten redundant characters.


D4NM4N(Posted 2010) [#114]
.DFP!


D4NM4N(Posted 2010) [#115]
Via Mono it's available on

Linux
Mac
Windows
Some Nokia devices
iPhone (via CocoaTouch)
Dont forget monodroid for android (wip) and monotouch for iphone too :)

Yes C# is cross platform (not a lot of people know that) at least the core and all the bits covered by the MS "community promise" (and more that is not available for MS C#, although that is vice versa too)


JoshK(Posted 2010) [#116]
I uploaded my current version here:
http://www.leadwerks.com/post/codewerks.rar

The example program is myprog.txt. You can use the included Code Editor, or just run the .bat file.

Here is my current test program:
Structure Vec3
	
	Field x:Float
	Field y:Float
	Field z:Float
	
	Method Normalize:Vec3()
		Local v:Vec3
		Local m:Float
		m=Sqrt( Self.x*Self.x + Self.y*Self.y + Self.z*Self.z )
		v.x = Self.x / m
		v.y = Self.y / m
		v.z = Self.z / m
		Return v
	EndMethod
	
	Method Length:Float()
		Return Sqrt( Self.x*Self.x + Self.y*Self.y + Self.z*Self.z )
	EndMethod
	
	Method Dot:Float( v:Vec3 )
		Return Self.x*v.x + Self.y*v.y + Self.z*v.z
	EndMethod
	
	Method ToString:String()
		Return Self.x+", "+Self.y+", "+Self.z
	EndMethod
	
	Method Add:Vec3(v:Vec3)
		v.x=v.x+Self.x
		v.y=v.y+Self.y
		v.z=v.z+Self.z
		Return v
	EndMethod
	
	Method Subtract:Vec3(v:Vec3)
		v.x=Self.x-v.x
		v.y=Self.y-v.y
		v.z=Self.z-v.z
		Return v
	EndMethod
	
	Method Add:Vec3(f:Float)
		Local v:Vec3
		v.x=Self.x+f
		v.y=Self.y+f
		v.z=Self.z+f
		Return v
	EndMethod
	
EndStructure


Class Entity
	
	Field position:Vec3
	Field rotation:Vec3
	Field scale:Vec3	
	Field parent:Entity
	
EndClass

Local a:Vec3
Local b:Vec3

a.x=3

b=a.Normalize()

Print a
Print b

'Produce divide by zero error:
'Local n:Int
'n=n/0



EOF(Posted 2010) [#117]
Fails to compile on my system. I have CygWin installed. Anything else needed?


I'm not sure if you considered any shortcut programming already but, what are your thoughts on:

1< Eliminating the need for 'Self.'
2> Using : after a variable to repeat the variable name. So, mystock=mystock+150 becomes mystock:+150
3> Using $ instead of :String (and similar Max variable type shortcuts)
' standard code

	Method Add:Vec3(v:Vec3)
		v.x=v.x+Self.x
		v.y=v.y+Self.y
		v.z=v.z+Self.z
		Return v
	EndMethod

' shortcut version

	Method Add:Vec3(v:Vec3)
		v.x:+x ; v.y:+y ; v.z:+z
		Return v
	EndMethod



One other feature I liked in Blitz 2 was the way in which you could assign multiple values into variables. Again, another small time saver:
Structure Alien
	Field x:Int , y:Int , Name$ , Points:Int , Size:Float
End Structure

Local a:Alien , b:Alien
a.x=40,80,"Slime",500,15.4
b.Name="Moby",100,4.0



Alberto(Posted 2010) [#118]
Just out of curiosity
What's the advantage of having a brand new programming language ?

I mean,for general purpose applications I doubt that a small development team can design something better than C++ or C# or VisualBasic or JavaScript or Phyton etc despite all the flaws which these programms may have

This project makes sense, in my opinion, just in the case the new language is specifically designed for game programming or even better for a specific game engine such as Leadwerks
In other word if the new engine contain libraries, variables, structures , methods which make easier the use of the engine
If so
What specific features should the new laguage have ?

This topic has been discussed some time ago about BlitzMax
I dont mean that BlitzMax is a bad product but one thing had been made very clear at the time
Even the most BlitzMax fanatic supporter was not able to provide any reason for using BlitzMax instead of an other language as far as game programming is concerned


_Skully(Posted 2010) [#119]
a.x=40,80,"Slime",500,15.4
b.Name="Moby",100,4.0



Please don't. That is very confusing. better to use constructors for that.

Type Alien
	Field x:Int=0 , y:Int=0 , Name$ , Points:Int , Size:Float

	Method Alien(x:int,y:int,Name$, Points:int,Size:float)
		self.x=x
		self.y=y
		self.name=name
		self.Points=points
		self.Size=size
	End
	Method Alien(Name$,Points:int,Size:int)
		self.Name=Name
		self.Points=Points
		self.Size=size
	End
End

A:Alien=New Alien(40,80,"Slime",500,15.4)
B:Alien=New Alien("Moby",100,4.0)



EOF(Posted 2010) [#120]
That takes much more coding than my 'shortcut' example. You would need to write constructors for all variations. Also, my examples are changing variables after creation so constructors would be useless
Other than that, how is:

a.x=14 , 5 , "Slug" , 200 , 5.0

more confusing than

a=New Alien(14 , 5 , "Slug" , 200 , 5.0)


One neat trick which Lua has is allowing the use of multiple returns. I am not sure how this could be implemented:
Function MousePos:Int,Int()
    Return MouseX(),MouseY()
End Function
..
Local x:Int , y:Int
x,y=MousePos()



_Skully(Posted 2010) [#121]
I suppose a shortcut for the constructor would be:
Type Alien
	Field x:Int=0 , y:Int=0 , Name$ , Points:Int , Size:Float

	Method Alien(x:int,y:int,Name$, Points:int,Size:float)
	Method Alien(Name$,Points:int,Size:int)

	' or

	Method Alien(Name$,Points:int,Size:int)
		' Additional constructor code
	End
End

A:Alien 40,80,"Slime",500,15.4
B:Alien "Moby",100,4.0


The "signature" for the constructor would have to match the type fields/globals to make that work.


JoshK(Posted 2010) [#122]
Even the most BlitzMax fanatic supporter was not able to provide any reason for using BlitzMax instead of an other language as far as game programming is concerned

They give their reasons over and over, but you don't think compact syntax is important.

1. This produces the exact same C++ code with about 20% the size of the code you have to work with.
2. The syntax isn't filled with as many symbols as possible.
3. MS Visual Studio takes forever to compile and GCC is fast.

If I have one source code that is 500 kb and another that is 2000, that means the second one will take roughly four times as long to produce. So a project that could be done in 6 months now takes 2 years.


JoshK(Posted 2010) [#123]
Has anyone done any work with GNU makefiles?


_Skully(Posted 2010) [#124]
Even the most BlitzMax fanatic supporter was not able to provide any reason for using BlitzMax instead of an other language as far as game programming is concerned



If everyone didn't think it was necessary to have alternate language choices then why are there so many? I code in Java, C#, Javascript, VB etc.. and I still choose to use Blitz because I like the language structure, hate {}'s


Alberto(Posted 2010) [#125]
If everyone didn't think it was necessary to have alternate language choices then why are there so many?

Did I say that ?

I said that I dont see any reason why a game engine developer should take care also of the programming language

" Sutor,ne ultra crepidam"

Simply , allow the end user to use his favourite and professional programming language
As simple as that


JoshK(Posted 2010) [#126]
I'm not locking Leadwerks Engine into one language, if that's what you mean.


JoshK(Posted 2010) [#127]
I'm using GNU makefile now to distribute a build across multiple files. It's analogous to BlitzMax's Import system. You can also import plain .cpp files. I understand why BlitzMax uses "Extern"...it tells the compiler those commands exist and can be used.


_Skully(Posted 2010) [#128]
JoshK,

Aren't you supposed to be developing LE? whats all this Programming Language shtuff ;)


EOF(Posted 2010) [#129]
The error I get when compiling is

"g++.exe installation problem, cannot exec 'cc1plus' : no such file or directory"

Any ideas? Like I said above, I have Cygwin installed, and have addedan entry to the environmental PATH variable pointing to Cygwins folder:

C:\cygnus\cygwin-b20\H-i586-cygwin32\bin;


Canardian(Posted 2010) [#130]
LE API has been always super easy, but there hasn't been a super easy language yet. So when that comes true, the language barrier is beaten too, and should make it into Leadwerks 3.0.


Alberto(Posted 2010) [#131]
They give their reasons over and over, but you don't think compact syntax is important....So a project that could be done in 6 months now takes 2 years.


Pushing your reasoning to the limits , I should come to the conclusion that in your opinion BlitzMax or the language you have in mind is better than C++, Java ect not only for game programming but in general...even to code an automatic control system for a nuclear power plan... let me express my serious doubts

Apart from that, nobody answered my question

Is it possible ( worth ) to develop a game , taylor made , programming language ?

I make an example
Lite-C , the script language of 3dgs , supplies the pointer "You"
You points at a structure containing all the data of the closest entity
The end user is therefore relieved from coding his own routine to achieve this task

Also the Torque programming language supplies some features which are dedicated to game programming

In this case only , it makes sense, in my opinion, to develop a new programming language


Canardian(Posted 2010) [#132]
@Jim: You need to install MinGW, not Cygwin.


JoshK(Posted 2010) [#133]
I should come to the conclusion that in your opinion BlitzMax or the language you have in mind is better than C++, Java ect not only for game programming but in general...even to code an automatic control system for a nuclear power plan

Yes, that's correct, but not for BlitzMax. What I propose has all the advantages of the C++ compilers, which I love, and all the advantages of BlitzMax-like syntax. BlitzMax itself also lacks things like function and operation overloading, and I think garbage collection is awful.

A new language with its own compiler would be pointless, unless you have the means to write a compiler for every system out there, even ones that haven't been invented yet. Plus, if you want to license code to others, you have to give them a C++ source.


Who was John Galt?(Posted 2010) [#134]
Pushing your reasoning to the limits , I should come to the conclusion that in your opinion BlitzMax or the language you have in mind is better than C++, Java ect not only for game programming but in general...even to code an automatic control system for a nuclear power plan... let me express my serious doubts
I write mission critical software for a living and I have some knowledge of the requirements of safety critical software. Personally I think a language syntax like Blitz would be superior to, say C for such a task. There is certainly no reason why it would be unsuitable.

The bottom line is that you don't like the syntax of BlitzMax, so you will never see the reason for implementing something similar. Paradoxically, it seems you like the identical syntax of B3D.


_Skully(Posted 2010) [#135]
Whoa this is getting long... time for thread #2?


EOF(Posted 2010) [#136]
@Jim: You need to install MinGW, not Cygwin.

Thanks. Except now when I hit complie either two things happen:

1> a CMD window opens and cc1plus.exe seems to hang (for myprog.txt example)

2> The simplist of examples throws many many errors. See example log below

Does this basic example look right in terms of code translation?

SAMPLE
Print "Hello!"


*.h file


*.cpp file




ERROR LOG



Canardian(Posted 2010) [#137]
Seems you didn't install mingw correctly or used some old version.
You should install this one, and install it under c:\mingw
http://sourceforge.net/projects/mingw/files/Automated%20MinGW%20Installer/MinGW%205.1.6/MinGW-5.1.6.exe/download


EOF(Posted 2010) [#138]
I followed Ziggy's guide in BlitzMax Programming - http://www.blitzmax.com/Community/posts.php?topic=90964

I have v5.1.6 installed here with path/env variables set. Do I need to add other components such as MinGW Make?


JoshK(Posted 2010) [#139]
I have msys installed as well, but I don't think it is needed for the last version I posted:
http://sourceforge.net/projects/mingw/files/MSYS/BaseSystem/msys-core/msys-1.0.11/MSYS-1.0.11.exe/download


JoshK(Posted 2010) [#140]
I have the makefile system almost automated, so you can do stuff like this:


Import "myfile.bmx"
Import "myfile.cpp"
Import "myfile.o"

Instead of using Extern like BlitzMax does to tell the compiler what functions are allowed, I created .i files that are basically just header files:
Class Object
Method ToString:String()
.
Function End()
Function RuntimeError(s:String)
Function Print(text:String)
Function String:String(i:Int)
Function String:String(f:Float)
Function String:String(o:Object)
Function Float:Float(s:String)
Function Float:Float(i:Int)
Function Int:Int(s:String)
Function Int:Int(f:Float)
Function Sign:Float(f:Float)
Function Sqrt:Float(f:Float)


To import a C++ library, just write the .i file as above and call Import "mylib.cpp" or "mylib.o".


slenkar(Posted 2010) [#141]
could you import GTK or wxwidgets??


JoshK(Posted 2010) [#142]
Yes.


slenkar(Posted 2010) [#143]
pretty cool,

how are you converting between ints and strings?

the boost library?


JoshK(Posted 2010) [#144]
No, there is some command like atoi or something. I just wrote a String() function once and now I don't worry about it. The precompiler automatically converts them.


Alberto(Posted 2010) [#145]
There is certainly no reason why it would be unsuitable...The bottom line is that you don't like the syntax of BlitzMax

Nope I dont have any preference,I am not an expert
I wonder why MS and all the other big software houses need a big team and plenty of time to develop programming languages which are slower, more redundant and as safety as BlitzMax even for critical applications
Just a matter of common sense.


slenkar(Posted 2010) [#146]
i dont think the atoi command works on linux, i dont know if you care though :)


Canardian(Posted 2010) [#147]
Of course it works on Linux, it's a standard C++ cross-platform command:
http://www.cplusplus.com/reference/clibrary/cstdlib/atoi/


JoshK(Posted 2010) [#148]
I've got Import working so you can compile across multiple files, and even .c and .cpp files. It's easy to import a single .cpp file, but when you have multiple .cpp files with their own makefiles or project files, it gets very messy. This is probably why BlitzMax can only import a single .cpp file.

For complex C++ libraries, would it be a good idea to just have the user compile an .o file, some way or some how, and import that? What is the difference between an .o file, an .a file, and a .lib file? They are all precompiled .cpp code that you can include in a program, right?


Canardian(Posted 2010) [#149]
Basically .o (Object Code), .lib (Library) and .a (Archive) are the same thing, but .lib is the recommended way of using precompiled C/C++ code, as it's more cross-compiler compatible. However, I think that .o files link a bit faster through the Link Editor (the final step before the executable), so if you're preparing one compiler for maximum compiling speed, then you should perhaps use .o files instead. They are also easier to produce and handle.


*(Posted 2010) [#150]

Of course it works on Linux, it's a standard C++ cross-platform command:
http://www.cplusplus.com/reference/clibrary/cstdlib/atoi/



I do agree with you, BUT some of the conversion commands arent present on iPhone SDK in XCode I had to write me own ones. For me they were 'standard' C commands the handle conversion between different variables formats but sometimes its 'easier' to use sprintf or something like that.


Canardian(Posted 2010) [#151]
I thought iPhone is using Objective C, which is even more horrible and even more further away from C/C++ than C#. I'd rather be a Microsoft fanboy than a Apple fanboy. At least Microsoft works on every PC legally and has the best games.


JoshK(Posted 2010) [#152]
I could just make the translator output Objective C code, if it has the same basic functionality as C++.


Who was John Galt?(Posted 2010) [#153]
I wonder why MS and all the other big software houses need a big team and plenty of time to develop programming languages which are slower, more redundant and as safety as BlitzMax even for critical applications
Inertia, an it takes a lot of effort to certify a compiler for safety critical. Plus, basic syntax would be seen as 'childish' although for no good reason.


JoshK(Posted 2010) [#154]
Plus, basic syntax would be seen as 'childish' although for no good reason.

I might change the EndIf statements to {} precisely for that reason. It's pretty silly.


Sledge(Posted 2010) [#155]
It's pretty silly.

//endif -- job done.


Who was John Galt?(Posted 2010) [#156]
I might change the EndIf statements to {} precisely for that reason. It's pretty silly.
No it's not... you're still reelling from that 'cereal packet' comment! ;)


AnthonyB(Posted 2010) [#157]
Just thought I would add my project to this endless list of posts. I'm writing a compiler for a language I am designing, which I call E. It is a regular compiler, meaning it translates the source language to good opitmized assembly code. The reason I write this compiler is mainly to learn, but also because it's really really fun to write this kind of thing.

My lanugage is based on C++, but a stricter version of it. Everything has to be declared before it can be defined. This might change in the future, with special syntax, but the reason I do this with my language is because I have been in countless situations where only declaring something before defining something would solve alot of problems. For example, say you're doing the following in a program:

typeA.h:

#include "typeB.h"

class typeA
{
	typeB memberName;
}


typeB.h:

#include "typeA.h"

class typeB
{
	typeA memberName;
}


Such situations can happen. What I do with my language to solve this is to put the definitions of the classes in the regular source files, and not in the header files. Instead I just put the declarations of the classes into the headerfiles, like this:

typeA.h:

class typeA;


typeB.h:

class typeB;


typeA.e:

#include "typeB.h"

class typeA
{
	typeB memberName;
}


typeB.e:

#include "typeA.h"

class typeB
{
	typeA memberName;
}


Or, if you want everything in the same file, just do:

class typeA;
class typeB;

class typeA
{
	typeB memberName;
}

class typeB
{
	typeA memberName;
}


This is one of the rules I put in my language.

Another thing I do is I add the auto datatype. It is the same concept as the C++0x auto keyword. It can basically contain any datatype, but cannot mix two datatypes that cannot be implicitly casted. This will take care of alot of template work, so that templates wont be needed as much. It will be a bit slower than templates though, but it will take much less space than templates.

I have alot of things planned for this language, but I am starting out simple. What I have currently done with my compiler is the basic preprocessor, the lexical analyser, the parser, and half of the syntactical analyser. I have also worked a bit on the middle end, so some of the optimizations are already in place.

What I do in my compiler is my front end produce an intermediate language that I call CIRL, which my middle end then optimize alot. So this is why I can work on my middle end before my front end is finished, and do alot of optimization work beforehand, whenever I feel like.

As the language is not intended for general use, unless people do express interest in the language, I will only make it the way I feel like it should be, personally. But if you guys have any useful suggestions that would be very interesting in a very C++ like language, don't hesitate to spit them out, so to speak, hehe. That would also mean you would express interest, and thus, I would actually feel encouraged to implement a suggested feature, if I like it.

The compiler is written entirely in BlitzMax btw, and as soon as it can compile a simple program, I will release it as open source, so that anyone interested in compilers can watch how I did what I did. I will also release the binaries for people to try out.

I am going the GCC rout, meaning I have a driver, which I call LCC, hehe, and that driver calls the preprocessor (called epp), and then the preprocessed file is forwarded to the front end (called ec1), which produces a CIRL output, which is then passed to the middle end, which produces RTL output (an intermediate language that is very very very close to assembly code, except it is almost machine-independent), that can be passed to the backend, that produces valid assembly code, which can be passed to NASM, the netwide assembler, which is the assembly language I love the most.

If anyone would like to alpha-test the language as soon as there is a finished alpha version, just let me know. I need people to find bugs, etc.

Regards,
Anthony


AnthonyB(Posted 2010) [#158]

Even the most BlitzMax fanatic supporter was not able to provide any reason for using BlitzMax instead of an other language as far as game programming is concerned



The one reason that comes to mind is that you don't need a good framework to start with. BlitzMax gets the project going faster than C++, if you don't already have a great C++ framework to start with, for the particular application you're working with.


Alberto(Posted 2010) [#159]
all the game engines using C++, or C# , or JavaScript or etc supply also a framework to work with
The only reasonable explanation for using BlitzMax was given by Joshk and John Galt
Apparently you have only advantages vs C++ etc and no drawbacks
Even though I am not an expert thus I can not argue with them let me say that I have still some doubts

The world is crazy but I refuse to accept that it is that crazy
It is hard to me to believe that MS or other big softwarw houses spent milion dollars a year in R@D while single even if smart programmers can achieve the same or even better results
Up to a certain extent I agree with John Galt
It is true that professional people tend to go for complicated solution just to show up how smart they are
Well...up to a certain extent
If BlitzMax can really cut off developing time most of the companies , sooner or later,will switch to it or to a similar scripting languages instead of using c/c++
Time is money



I remain of the opinion that a dedicated programming language make sense if it is designed for a specific engine, otherwise use a standard one

Take for example the Torque programming language
It comes with a client / server architecture which makes it suitable for Multi player games ( and a nightmare for everything else )


AnthonyB(Posted 2010) [#160]

all the game engines using C++, or C# , or JavaScript or etc supply also a framework to work with



Yes, but those frameworks take alot of time to write in the first place. Unless they buy the game engines, they won't get them without writing them. And even if they do buy the game engines, they have to spend months just getting into the code, knowing how everything works, and plan which routs to take. That is why I say that BlitzMax IS a time saver, when you don't already have a framework complete with good BOOST, OpenGL and OpenAL functionality, etc.


JoshK(Posted 2010) [#161]
Codewerks can compile straight to Android now.


John G(Posted 2010) [#162]
For me, the main appeal of BlitzMax is that it has a BASIC front-end and attempts to be Cross-Platform. No interest in learning C, Java, etc.


slenkar(Posted 2010) [#163]
why has noone done this before????


EOF(Posted 2010) [#164]
I got this working now. Not sure what was wrong before. Anyhow, I am pointing my Laptop towards Mecca until further notice

What is there left to implement in your language at this stage?
Have you for instance implemented:
Repeat .. Until
While .. Wend
For .. To .. [Step] .. Next
For .. Until .. [Step] .. Next

Also, which of these variable types are you supporting? - Int , Float, Double, Boolean, String, Char


I see from the generated *.cpp file that you have a fair bit of wrapping code going on. For example:
float Sqrt( float f )
{
	return sqrt(f);
}
In this case, and for raw optimization purposes why not simply convert all references of "Sqrt(" in the code to "sqrt(" thus avoiding having to call the extra wrapped function?


_Skully(Posted 2010) [#165]
What would be really interesting would be to be able to do this:

For local a:Somesuch=Eachin Sumsuches WHERE ID=15 AND x<100
    a.x:+1
Next



GrahamK(Posted 2010) [#166]


For local a:Somesuch=Eachin Sumsuches WHERE ID=15 AND x<100
    a.x:+1
Next



I don't normally post anymore, but I have something like this in Cobra, and it's really handy (so to keep on topic, it's really handy and worth including in a language).

I have a loop construct which can work though a list of user defined types.
e.g.
// define a type
type  mytype = record
    i : integer
    s : string
endtype 

var
    alist : list of mytype // the list we will be using

.... some code stuff

// step through the list
loop mt through alist where (mt.i mod 2 = 0) 
    .. only execute code here where condition is true
endloop



_Skully(Posted 2010) [#167]
Wow.. haven't heard Cobra for quite some time.

Ya it would be great....

I don't think one needs to specify mt... ie, the instance would be in effect inside the WHERE clause.


JoshK(Posted 2010) [#168]
My Visual Studio build times, with precompiled headers enabled, are around 19-24 seconds, for a pretty small project. It will be interesting to see whether the GCC compiler in this is faster.


Canardian(Posted 2010) [#169]
The real GNU C++ compiler, like seen on Linux is insane fast and produces around 5 times faster code than VC++. I also thought that MinGW was slow, but then I managed to optimize the compiler settings to get the same code running slightly faster than with VC++. Compile times are faster on MinGW too than with VC++. I haven't measured yet how much times faster the compiling times are, so I can't say any absolute value.


Czar Flavius(Posted 2010) [#170]
Skully that's a great idea! But I don't like where and and being caps, it seems inconsitant (and brings back bad memories of sql)


_Skully(Posted 2010) [#171]
I just capped the where clause for effect LOL

could use "when" or "and" but "where" is better known for filtering

For local a:Somesuch=Eachin Sumsuches WHEN ID=15 AND x<100
    a.x:+1
Next


or

For local a:Somesuch=Eachin Sumsuches AND ID=15 AND x<100
    a.x:+1
Next


I still think:

For local a:Somesuch=Eachin Sumsuches where ID=15 AND x<100
    a.x:+1
Next



JoshK(Posted 2010) [#172]
How do I compile a .lib file with GCC? I can do an .a file, but everyone wants .lib.


Gabriel(Posted 2010) [#173]
Is it C or C++? If it's C, it should work by simply renaming. If it's C++, you can't do it because GCC and Visual C++ name mangling is incompatible.

EDIT: Corrected typo.


JoshK(Posted 2010) [#174]
So you are saying there is no standard format for static libraries for C++?

Can MS load .a or .o files made by GCC?


*(Posted 2010) [#175]
I always thought when you create libs (with a header file) it would compile on anything :s


Gabriel(Posted 2010) [#176]
So you are saying there is no standard format for static libraries for C++?

Well I wasn't using static libraries much when I was doing it, so I can't say for certain, but I can't see why static libraries would have a different name mangling convention than dynamic ones.

Can MS load .a or .o files made by GCC?

In my experience, only if you export a pure C API. Which means exporting flat functions, not classes, methods, etc. and it means prefacing your functions with something like

extern c __declspec (dllexport)


(Doing this from memory, I'd have to check my backup drive for a definitive code snippet.)

My information could be out of date though. It was a cpuple years back, but I invested a ton of time and picked some of the best brains I could find, and we never came up with a solution. If you really need one, and the flat C API won't work, I wish you the best of luck.


JoshK(Posted 2010) [#177]
That seems very odd because .lib and .a files are routinely distributed, and I thought MSVC and GCC were both widely used.


Gabriel(Posted 2010) [#178]
They are, but not typically with any degree of integration. Of course, that could be said for many things Microsoft. I'm not really clear on what you're doing here. Is this for your purposes or is this something all your users will need to do as well? Can you not just output code which compiles in both VS and GCC, and let people use choose the compiler? Or just compile both in their native compiler, if it's something only you need to do?


JoshK(Posted 2010) [#179]
I need to distribute a .dll, .o, .a, or .lib file that will work with all popular C++ compilers.


marksibly(Posted 2010) [#180]
Hi,

Moving this here as it's become more of a Q&A session on gcc/libs etc.

Also, if you want to host a discussion about development of a specific product, please take it elsewhere as this isn't really a project hosting style site.


Gabriel(Posted 2010) [#181]
I'm sorry, but I know of no way to produce one dll, object file, a or lib which works on both Visual C++ and GCC unless it's pure C.


Chroma(Posted 2010) [#182]
You guys are geniuses and have seemed to create a new super language in less than a couple weeks. My hat off to you, but is that even possible?

Also, this is like having a huge task at hand like rowing across the Pacific Ocean (writing a game) but complaining about what color the oars are (stalling?)... /shrug


*(Posted 2010) [#183]
wont compiler directives work in a lib, I always thought that libs meant that only the functions required where compiled in the final exe file. So with compiler directives it should be possible.


Who was John Galt?(Posted 2010) [#184]
For local a:Somesuch=Eachin Sumsuches WHEN ID=15 AND x<100
    a.x:+1
Next
Doesn't add anything in my book.

For local a:Somesuch=Eachin Sumsuches
    if (ID=15 AND x<100)
       a.x:+1
    endif
Next
Although a few extra characters to type, is more readable, IMO....

or even....

For local a:Somesuch=Eachin Sumsuches
    if (ID=15 AND x<100) a.x:+1
Next



_Skully(Posted 2010) [#185]
anything happening with this?


JoshK(Posted 2011) [#186]
I've put this on hold for the immediate future, but with what I have learned about C++ everything I supposed is definitely possible. I do hope to pick this back up one day.


Bobysait(Posted 2012) [#187]
a bit old, but this topic is quit interesting

In your sample, You use #pragma once
I'm not sure it is portable
You might use #ifndef/#define instead (?)

One other point :

You probably already know it, but if not, there it is :

You can't export the "gcc.exe" like this (as you did in your "compile.zip") as all machines that does not have gcc installed (I suppose this one comes from mingw gcc), it won't probably compile at all (searching for cc1plus.exe or something else) and for those who have gcc installed, it will use it instead the one you provide

But you can export both gcc and cc1plus/cc1 with your embedded IDE/SDK/Interpreter
You'll just have to update the environment variable "Path" to search for your directory to find cc1plus.exe

In blitz3D, it would be as simple as :
SetEnv ( "Path", GetEnv("Path") + String(";",Len(GetEnv("Path"))>0) + Chr(34)+Your_cc1_Dir+Chr(34))

(it will just update it temporarily while your application is running, but it is enough to compile)

Then it will be a more "lite" version (instead of a 1Go of disk space for mingw installation, you 'll just provide 40-50 Mo of libraries with your application - depends on what you need to export)

But, of course, remember you'll have to join the libraries as well as the gcc binaries and link them in your bat file, cause gcc without the libs is useless until you don't need libraries like stdio or string etc ...

for eg : Let's call your directory for the compiler "C:\MyCompiler"
You 'll have something like this:

("+" is a directory, "-" is a file)
+ ...\MyCompiler\
	- MyCompiler.exe
	+ bin\
		- Translator.exe (your exe that translate from "txt" to "cpp+hpp"
		- gcc.exe ; copy from bin directory (of your mingw installation)
		- cc1plus.exe ; copy from bin directory (of your mingw installation)
		[- cc1.exe (if you want to compile c files as well)]
	+ lib\
		+ copy the lib directory from gcc here (perhaps from mingw) (should be about 20-30Mo)
	+ include
		+ copy include directory from gcc here
		+ copy your sdk headers for conversion from "Your Format" to "Cpp" here


Si in your bat file, you can all link from inside your application using -L -I or -idirafter parameter to add your application directories
for eg :
C:\MyCompiler\bin\gcc.exe -L "C:\MyCompiler\lib" -I "C:\MyCompiler\include" -g -Wall "E:\Cpp\Compile\opengl.c" -o "D:\Bigbang\debug\OutFileName.exe" > "C:\MyCompiler\OutDebug.log" 2>"D:\Bigbang\debug\OutErrors.log"



If you manage to create big projects, you probably should better compile as "o" instead of exe
then compile the "o" to exe
(like this, you'll save lot of compile-time not re-compiling the same libraries again each time you export as exe)

Last edited 2012


Captain Wicker (crazy hillbilly)(Posted 2012) [#188]
I think Xaron is working on something like this called Bits Basic
http://www.bitsbasic.com/


Yasha(Posted 2012) [#189]
I think Xaron is working on something like this called Bits Basic


I haven't kept up with what Xaron is doing, but I am very, very slowly continuing to work on my own version of a Blitz3D-compatible compiler. The features are a superset of what is discussed in that thread. It is still alive, although it's kinda on life-support. The idea is to be 100% compatible with all permissible B3D code (including weird edge cases), with precisely one documented exception.


Adam Novagen(Posted 2012) [#190]
Just a thought, since I read half of JoshK's post before scrolling down to the bottom of the thread:

Garbage collection. Point of much contention. On the one hand, very useful, takes a load off your mind, prevents a lot of potential memory leaks. On the other hand, some languages trigger it at unwanted intervals during program execution, and it arguably encourages "lazy" coding by removing the idea of keeping track of all your resources.

So, two questions: what are people's thoughts on the whole GC issue, and moreover, is there any reason whatsoever that a language couldn't have a simple on/off toggle to allow garbage collection to be either enabled or disabled depending on the preference of the coder?

GarbageCollect True

GarbageCollect False

CollectGarbage


Last edited 2012


Yasha(Posted 2012) [#191]
is there any reason whatsoever that a language couldn't have a simple on/off toggle to allow garbage collection to be either enabled or disabled depending on the preference of the coder?


Most languages with GCs have this. BlitzMax does, among others.

My Bits fork mentioned above has it as an option that can be toggled on and off for specific data types too (off by default to preserve compatibility).


it arguably encourages "lazy" coding by removing the idea of keeping track of all your resources


Strong disagreement. It encourages focused coding by removing the completely irrelevant technicality of keeping track of resources from business logic. Manual memory management requires the programmer to waste brain cycles thinking about a second, completely unrelated issue.

The fact is, the machine can do the job better than 99% of human programmers. The goal of programming is to automate everything that can be automated: therefore, within programming itself, as much of writing a program as possible should also be automated. So if you can possibly get away with not keeping track of your resources, good, you are approaching enlightenment.

Garbage collection implementations can cause problems and often need to be left out of very-high-performance or realtime code (they do not as a rule have any noticeable effect on application code). Garbage collection as an idea should be considered the default style of program design: manual memory management is just a hack to compensate for the fact that most collectors aren't perfectly suited to the task yet; in the same way that fixed-width and floating-point numbers are just a hack to take advantage of hardware arithmetic performance (high-level languages don't usually offer ints/floats/doubles, instead offering "numbers" and silently switching between hardware numbers and bignums behind the scenes, as the math requires).

The problems that are mere implementation details of imperfect GC algorithms are also disappearing by the hour: Apple's ARC is just as performant as the manual alternative or in many cases better, with just a couple of weaknesses. (Note by the way that reference-counting GCs like ARC or the BlitzMax default have more or less identical performance characteristics to manually-managed memory; the tradeoff is the circular reference bug. Pauses are a characteristic of "true" scanning GCs.) Many compilers also bundle advanced prediction systems to write most of the management code in advance, to avoid GCing any object that doesn't actually need it. And the pauses themselves are generally greatly overrated as problems go: for most games they'll easily fit into the gaps between frames.

In other words, unless you're writing a high-performance realtime system (JoshK is one of a tiny minority who actually do this), there is no good reason not to accept garbage collection as an objective improvement over manually managed memory. There is certainly no excuse for leaving it out of a "modern" application-level language or making it anything other than the default.

Not to say that it isn't good to know how to manage memory. But it's rapidly going the same way as knowing how to allocate registers: it's a system implementation detail that the machine can almost always handle better than you (there's serious talk of completely removing the "register" keyword from the C standard simply because we're now at a point where the compiler will do the best possible job without assistance, and the only change the keyword could make would be to damage performance; memory will go the same way in future. Doubly so for the holy grail of system-level or hardware-level GCing like in .NET or a Lisp machine).

Last edited 2012


Adam Novagen(Posted 2012) [#192]
Fair enough, but I do personally find a degree of distaste in increased automation within code itself. It's true that you shouldn't have to "reinvent the wheel" all the time, but I still find that it's wise to understand how a wheel works. As automation increases, adding additional layers upon layers of machine processing to remove the work from the hands of Humans, I worry about a potential "informational collapse" in the future, a theoretical point at which the amount of data and information processed by any computer is too great for any one Human mind to comprehend, thereby causing a drop in performance as opposed to potential and ultimately halting forward movement.


Yasha(Posted 2012) [#193]
Garbage collection is just an abstraction layer. And as long as you approach it from the right angle, abstraction layers simplify design in order to make it more comprehensible, by reducing the number of factors the designer needs to consider at once. This is good for understanding, not bad!

Consider: do you write whole programs in machine code? You can if you want, but personally I think it's a waste of time. Operating on the machine's level means you need to remember a thousand steps for loading each piece of data, ten thousand for processing it, and a hundred thousand for linking these into anything useful. Or, you could abstract this behind a machine language and simply remember what you're actually trying to do. There is no requirement to ever have to understand the whole program in its low-level representation, and if there is something went horribly, horribly wrong with your design process. Again, this is a good thing because it raises the chances of you ever actually understanding the whole design.

The dangerous element you've probably got in mind is when people with a complete lack of understanding of the system don't fully understand what it's capable of (look up famous article "the perils of Java schools" for abstraction gone bad). But as long as you;re aware of this, you can counter it yourself. Write some assembly code. Learn what the C code generates. Write in C. Then add macros. Then go up a level. Implement a garbage collector (not hard at all). Then, you can code for the rest of your life without worrying about memory because you know exactly what is happening, and you still have the enhanced power of not having to make it happen yourself. The complexity and power of your program is like an unfolding tree fractal: every time you add a layer of abstraction you can raise the complexity by an order of magnitude for the same amount of work. And if you trace down any one branch of the tree fractal, you'll reach the root and the basis of your knowledge and your productivity... but you don't need to work at that root level all the time as long as from any given point you can remember how to get there. This is what having a full understanding of your program actually means (because gods know you'll never write anything complex to understand in the first place without using abstraction layers).

Incidentally...

n the future, a theoretical point at which the amount of data and information processed by any computer is too great for any one Human mind to comprehend


Dude we passed that decades ago. There is no one person alive on Earth who can hold in mind at once the complete architecture of your computer at the base level, or likely even two or three abstraction levels up (Intel are rather proud of this). It's not even remotely possible, which is why trying to work like that is a waste of time.


*(Posted 2012) [#194]
Its simply keeping a log on what is using an piece of media or whatever once the usage is at 0 and its no longer needed then remove it.


Bobysait(Posted 2012) [#195]
The matter is :
Who will use a non-GC compiler ?
only persons that think they can do better.
In fact, they are not a lot, and the developper has to keep that in mind to sell his product to the largest public. And the fact is : This public just want to code the fastest and the funniest way they can. For this purpose, the GC is one of the most convinient tool a language can offer.
For sure, purists will say "Hey ! I don't need this, I'm better than the machine" ... but what is sure is that, you, me, and most of the people will not only sell programs, they also will test a lot af amators stuff.
For each time you test a amator program that is not compiled with GC, you take the risk to crash your PC :)
For all those non-professional programmers, GC is just the Saint-Graahl.


Adam Novagen(Posted 2012) [#196]
So... Why do you program in Blitz3D, then? :/


Yasha(Posted 2012) [#197]
The most important reason of all...

...fun!

(Remember, all my comments above are based on the assumption of a world with perfect compiler and memory management systems already available. c.f. "Consider a perfectly spherical cow...")

Last edited 2012


Bobysait(Posted 2012) [#198]
So... Why do you program in Blitz3D, then? :/

Because we don't have to care about the internal stuff to build a camera, a graphics context or many other functions like this that do it for you.
IMHO, blitz3d miss a good GC, so everything initialized with a "New ..." must be manually released with an implicit "Delete", it's not that bad except in core of functions where local "New" object are not deleted at the end of the function scope.

For me, it's one of the most annoying things in blitz3d.
we can't for exemple use objects in an implicit way like we could in blitzmax or any other language using GC.

Just imagine :
Type Vector Field x#,y# End Type

Function NewVector.Vector(x#,y#):Local v.Vector=New Vector:v\x=x:v\y=y:Return v:End Function
Function Add.Vector (v1.Vector,v2.Vector) : Return NewVector(v1\x+v2\x, v1\y+v2\y):End Function

Local v1.Vector = NewVector(+1,+2)
Local v2.Vector = NewVector(+3,-1)
Local v3.Vector = Add(v1,v2)
Delete v1
Delete v2
Print v3\x+" "+v3\y
WaitKey
End


with GC we could have used
Type Vector Field x#,y# End Type

Function NewVector.Vector(x#,y#):Local v.Vector=New Vector:v\x=x:v\y=y:Return v:End Function
Function Add.Vector (v1.Vector,v2.Vector) : Return NewVector(v1\x+v2\x, v1\y+v2\y):End Function

Local v.Vector = Add(NewVector(+1,+2),NewVector(+3,-1))
Print v\x+" "+v\y
WaitKey
End


Where the two arguments are local objects and are released at end of scope thanks to the garbage collector.

At the Moment, blitz3D does not support this, and it's a big waste of time.

Last edited 2012


Yasha(Posted 2012) [#199]
To be honest Blitz3D does also mitigate the problem since you can always do things like "Delete Each Vector" after a short block of vector maths. And of course you can separate out a second type for safe storage of vector objects.

For larger things, it's perfectly possible (with a little imagination) to set up a retain/release/autorelease system like the once from Objective-C 1. While it's tedious to type out, it can provide the same sort of provable memory safety as a real GC, if the program is written consistently.


Dabhand(Posted 2012) [#200]

Because we don't have to care about the internal stuff to build a camera, a graphics context or many other functions like this that do it for you.



But, sorry if I'm missing something, but... This sorta stuff is splattered everywhere on the internet and, to be fair nowadays, you could probably rustle a Blitz3D engine up with no problem what's so ever, so, I cannot really understand why people use this argument when demanding more advanced features language wise then B3D provides... Just use C++, wrap any complicated code up, and get on with it... Or am I still missing something?

Dabz


Bobysait(Posted 2012) [#201]
Ok, so according to your point of view, everything c++ does you can do it with more tweaks in asm. So stop coding c/c++ and go asm ?

I use to code in c++
It requires at least twice the time we need in blitz3d just to compile something trivial.

the way we have to declare variables
the way we have to care about the order of includes and declarations
(eg : you can't use a pointer to a class that is defined after, so you have to define it before to use... blitz3d do this stuff for you)
the way you have to write header and cpp at the time
the need for a clear and neat memory management ...

Sorry but, "why blitz3d" is an evidence for me.

It's just many many times faster to code with it, and this, with or without a 3D engine.
The language itself is smart, and for sure, it is a "basic-style" language.


All we can do wit blitz can be done in another language, the only matters are :
How many time do you need to write your program and, is it efficient enough for you ?
Just answering this will explain why we would like some little improvements in blitz3d.
Because we want the same syntax, we want our compiler to do most part of the management (for memory, dependencies, order etc ...)

Open blitz3d and tell me you prefer the "holy" c++


ps : and you ... why "You" are here ? isn't it because you like blitz3d ? could you tell us why ?

Last edited 2012