This seems very interesting. It's how win32 exes are structured, and can come in handy for people who are making compilers:
http://www.madchat.org/vxdevl/papers...ile/pefile.htm
Printable View
This seems very interesting. It's how win32 exes are structured, and can come in handy for people who are making compilers:
http://www.madchat.org/vxdevl/papers...ile/pefile.htm
Have you considered just converting the code from your language into ASM and having an ASM compiler do the work for you?
Dare I say that would be much easier than writing another compiler CornedBee :p
chem
would this language be platform indepentent, or just run on Win32?
As I said, the thing emitted Alpha Assembly and expected the user to manually feed it to the assembler and linker.Quote:
Originally Posted by chemicalNova
Well I could make it to where you can compile it to use on any computer (Mac for example), but that would be double the work.Quote:
Originally Posted by tr333
Oh, once again we're at the language/library boundary. Making a language platform-independent is easy. The only problem is that you need more than compiler - but if you, for example, write the compiler as a GCC front-end, you get that for free.
The libraries, however, need to interface with the OS to do anything meaningful, so yes, there platform-independence would be a lot of work.
On the other hand, it's not necessarily you who must do the work. If you simply design the libraries so that they don't clearly favour one OS, you can then implement them for the OS you're using and leave the porting to other people.
Take a look at C#, for example. Porting C# itself was simple and done in the Mono project within a few weeks, I think. Writing the CLR wasn't too hard either. The real issue is porting the .Net framework, especially the System.Windows.Forms namespace, which is extremely clearly modeled after the Win32 model, thus making implementation on top of X Windows all but impossible - the Mono project uses the WINE WinAPI implementation for this namespace.
Syntax idea
What about functions?
Function data type in the header and -of course- return using 'return'Code:public float Dist( int x, int y )
{
return ( x*x + y*y ) ^ 0.5
}
// Usage:
float d = Dist( 10, 20 )
I don't know a language that supports this, but it would make many things easier...Code:public int, int NegPos( int x, int y )
{
return -x, -y
}
// Usage:
int x = 10
int y = 10
x, y = NegPos( x, y )
Python can more or less do it. It is a great future I often miss. But using references or structs can solve the problem too.
- ØØ -
Yeah but it blows up code... in PHP I use arrays to return multiple values, that would also be a way (better support arrays AND the sample above ;)
Code:public int, int NegPos( int x, int y )
{
return array( -x, -y )
}
// Usage:
int pos[1] = array( 13, 37 )
pos = NegPos( pos[0], pos[1] )
Functional programming languages all support this through tuples. I'm not convinced it's worth its code complexity in imperative languages, though.
Guess it would be easier to do this:
Code:struct POINTL {
int x
int y
}
POINTL NegPos(int x, int y)
{
return new POINTL(-x, -y)
}
That was my point two three posts up though...;)
Or
Code:public void NegPos(ref int x, ref int y){
x = -x;
y = -y;
}
- ØØ -
Multiple assignment :D
Consider this
now this:Code:x = x * 2;
y = y * 2;
z = z * 2;
(! = Insert appropriate symbol to represent each item).Code:x, y, z = ! * 2;
Now that is a nice idea!Quote:
Originally Posted by penagate
Going back to the abovepost about
x, y = blah()
You can do this in .net anyway (sort of) using out params (in c#) and byref in VB.
Quote:
Originally Posted by wossname
Ehhh...byref is the reference way...:)...
I found this book right here:
http://www.bookpool.com/sm/0471113530
After Labor Day, I'm gonna go check it out over at Barns & Noble, and see how good it is.
Your point being?Quote:
Originally Posted by NoteMe
Quote:
Originally Posted by wossname
That it has been said many times now..:)
- ØØ -
Quote:
Originally Posted by penagate
Valid C++. Operator overloading rules.Code:struct Point3D
{
int x, y, z;
Point3D & operator *=(int val) {
x *= val;
y *= val;
z *= val;
return *this;
}
};
Point3D pt;
// ...
pt *= 3;
Hehe...never thought about that..:D:D:D hehe...you can do that in C# too the..:D And soon VB.NET too..:)
[Edit]The funniest thing is that I have all ready done it many places like in my Vector class and not even thought about it before...:)
- ØØ -
Ok, so just incase I didn't hint at it enough, I am going to state it clearly: I have to back out of this project. I realized I can't afford to even be posting here often (after school starts) and really can't afford to be making a compiler and a new language. But I will definitely stay ontop of this thread and whats going on.
I'm going to upload the full text of the first post as a .txt and let JR copy paste that into the first reply so he can edit it as things progress.
Must have been one of those days I read something and remember what I want.Quote:
Originally Posted by CornedBee
:rolleyes:
chem
Don't worry. Leave the compiler stuff to me. I'm gonna pick me up a book on it sometime soon. ;)Quote:
Originally Posted by eyeRmonkey
that mass multiplication thing is a good idea, 1 line of code like that, i'm a fan of that
But that, too, can be solved using templates and operator overloading. I could write something in C++ that would allow this syntax:
Code:mass, a, b, c *= 4;
What about this one?
Totally silly example, but it shows (if I'm correct) that you'd need to write an operator for each expression. This would just be a compiler substitution.Code:a, b, c = sin(1 - !) + (! / 100);
Seeing the ! made me think that we should probably have some advanced math functions on the library (! = factorial - brush up on your pre-calc).
I love the idea of mass equations (on multiple variables).
Well, find some other symbol for it then :p Anyway, in the library you'd give it a function name, factorial() or something.
Oops, forgot you don't like semicolons.... sorry :DCode:int factorial(int n)
{
int val=n;
for (int i=(n-1); i=2; --i) {
val = val * i;
}
return val;
}
Oh yeah, I meant to mention, it would be nice if we did our For loops like penagate just posted.
[code]for ([assignment of counter variable], [rule], [increment]) {
And I like doing returns like that also instead ofCode:}
I likeCode:Private Sub Factorial() {
Factorial = blah
}
I think it increases readability a lot.Code:Private Sub Factorial() {
return = blah
}
We also definitley need single increment and single decrement operaters. I miss those a lot in VB.
Code:a = a + 1 // is the same as
a++
// same applies to --
My code I posted doesn't work (it goes into an infinite loop). But, the flip side is, I just coded my first working piece of assembly... w00t :D :D
Code:int factorial(int n)
{
__asm {
mov eax, n ; number n
mov ecx, eax ; initial multiplier
LoopStart: ; loop through numbers
sub ecx, 1 ; reduce by one (n*(n-1))
imul eax, ecx ; multiply number (n*(n-i))
cmp ecx, 2 ; loop down to 2
jne LoopStart
}
}
Nice penagate. Are you interested in actually joining the project? Or are you just going to help from time to time.
I'll help out as much as I can in this thread. Don't know that I'll actually have the time to knuckle down and write a lot of code at once, at least not until mid November or so when my exams are over. Plus I have a few other things I am doing.
Tell you what, I'll write you ASM-optimised functions for your library :D
The loop was infinite because you wrote = instead of == in the condition.
I suddenly feel very small and stupid :blush:Quote:
Originally Posted by CornedBee
Too much VB :D
Great to have you! :thumb:Quote:
Originally Posted by penagate
You'll probably be more active than me after tomorrow (when I start school).
I gave up on the For loop, it always returned the input number for some reason. I used a While loop instead
A few things from that to add to the Lightfusion collection. While() block, *= operator (I like all these shorthand operators) and -- which eyeRmonkey alrady mentioned above.Code:int __stdcall factorial(int n)
{
int i = (n - 1);
while (i > 1) {
n *= i;
--i;
}
return n;
}
Edit: Oh and maybe the ability to pick calling convention :)
I'm thinking of adding the ! operator for factorials. There might be a faster way to do it in assembly.
I do not think that factorial is an operation common enough to warrant an operator. Preserving ! for its C use of logical NOT seems to make more sense.
You could always use VBs version..:D..
<>
or
Not
:D
You have to add IsNot()