OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 12:29 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 36 posts ]  Go to page Previous  1, 2, 3
Author Message
 Post subject: Re: Oh PLEASE! Remove crappy forum "features"
PostPosted: Thu Jan 29, 2009 3:11 pm 
Offline
Member
Member
User avatar

Joined: Wed Jan 28, 2009 4:30 pm
Posts: 72
JJeronimo wrote:
Quote:
If anyone would be willing to give me some pointers on getting GDC to work successfully so I can program my OS in D, I'd really appreciate that.

Looks like you were the first one that tried something like that.

JJ


Nope, we actually have one...it was a *****. GDC isn't the way to go, though... ldc is.

http://www.dsource.org/projects/ldc

The ldc developers have said that making our os compile is a priority of their project, so I'm sure it'll be suitable for yours.

JohnnyTheDon wrote:
This is what D tried to do. It actually declares itself as a systems programming language, but kind of falls short. IMHO, anything with a GC is going to be unreliable for systems programming, at least in the kernel.


GC is easily turned off, and you can still use C malloc(). In the kernel you're not really using a run time anyway, so...

earlz wrote:
Is there any way to do this in your precious D? I didn't see any replacement for such a macro in that C preprocessor vs. D link...


Did we read the same link?
Quote:
Lightweight inline functions:
The C Preprocessor Way

#define X(i) ((i) = (i) / 3)

The D Way

int X(ref int i) { return i = i / 3; }

The compiler optimizer will inline it; no efficiency is lost.


Or do you mean __LINE__ and __FILE__?


Top
 Profile  
 
 Post subject: Re: Oh PLEASE! Remove crappy forum "features"
PostPosted: Thu Jan 29, 2009 3:20 pm 
Offline
Member
Member

Joined: Thu Jul 07, 2005 11:00 pm
Posts: 1546
I meant __LINE__ and friends

_________________
My new NEW blag


Top
 Profile  
 
 Post subject: Re: Oh PLEASE! Remove crappy forum "features"
PostPosted: Thu Jan 29, 2009 3:50 pm 
Offline
Member
Member
User avatar

Joined: Wed Jan 28, 2009 4:30 pm
Posts: 72
Yes.

http://www.digitalmars.com/d/2.0/lex.html#specialtokens

EDIT: Better link.


Top
 Profile  
 
 Post subject: Re: Oh PLEASE! Remove crappy forum "features"
PostPosted: Thu Jan 29, 2009 10:08 pm 
Offline
Member
Member

Joined: Thu Jul 07, 2005 11:00 pm
Posts: 1546
What about compilation times for identical code?
I know there is a considerable delay for C++ compared to C(with gcc/g++)
what about code optimizations and density?

I know with g++, features like exceptions took a very large chunk of time in a loop with many function calls. (according to profile information)

_________________
My new NEW blag


Top
 Profile  
 
 Post subject: Re: Oh PLEASE! Remove crappy forum "features"
PostPosted: Fri Jan 30, 2009 8:50 am 
Offline
Member
Member

Joined: Wed Oct 18, 2006 3:29 pm
Posts: 202
earlz wrote:
What about using the preprocessor to increase speed of the program, and ease on the developer?
I discovered the C preprocessor was capable of this nifty little thing earlier yesterday.
Code:
#define PANIC(x)\
   epbp_panic(x,__FILE__,__FUNCTION__,__LINE__)
With this, I get where the panic occured in my code, and the code(x) for the panic. Before I knew of this, I had to either type that huge long line, or just use codes, which didn't tell me exact information.

Oh yeah! And what if you want to add a string argument explaining the reason for the panic? In no time at all, you'll be dealing with the almost useless C99 variadic macros and such. (because I believe you want format strings). For details read:
http://groups.google.pt/group/comp.lang ... 27f5202340

Quote:
the preprocessor is very handy in the hands of those that know how to use it. But, it can be easily abused too.

The C preprocessor is plain dumb. It drives you into hackish stuff very very quick. Those "that know how to use it" are those who are able to cope with the limitations of string pasting and aren't afraid to pay the price for the extra dirty hacks to work around those limitations.

The limitations of string pasting mean that the fact that you are able to "extend" the language is just the product of some happy co-incidences. As long as those happy co-incidences last, you don't have to employ dirty hacks. At the point that the co-incidences end, the dirty hacks become increasingly necessary, and the preprocessor becomes a mass destruction weapon. :-) Some time ago, I read something in the ReactOS wiki that summarized this quite well. It said something like string pasting is evil because it gives you a wrong sense of flexibility.

For example, consider the usual C approach to function "inlining". This works for some functions because of a happy co-incidence, that is, those functions are composed of only one expression, so they don't rely on the return keyword. However, if the function has to use loops, you cannot convert it into a macro, because that functions:
1 - use something that is NOT an expression
2 - and thus have to use return
And so, because of 1, you need to use a compound statement in your macro, and compound statements cannot return values (only functions can return values).

Quote:
Is there any way to do this in your precious D? I didn't see any replacement for such a macro in that C preprocessor vs. D link...

I don't know D very well, but I doubt there isn't, if anything, some predefined syntax to accomplish the same goal as your macro.
As about a way for defining yourself the syntax to do this, in fact I believe you cannot. But I already explained you why I believe macro expansion to be the wrong way to extend a language.

JJ


Top
 Profile  
 
 Post subject: Re: Oh PLEASE! Remove crappy forum "features"
PostPosted: Fri Jan 30, 2009 10:14 am 
Offline
Member
Member

Joined: Wed Oct 18, 2006 3:29 pm
Posts: 202
JJeronimo wrote:
As about a way for defining yourself the syntax to do this, in fact I believe you cannot. But I already explained you why I believe macro expansion to be the wrong way to extend a language.

That said, I can agree that some languages in fact need mechanisms to define new syntactic constructs. But please, do NOT use a preprocessor for this kind of stuff, instead delegate the responsibility of parsing and applying the syntax definitions to the compiler proper. Only the compiler is able to enforce syntax checking and avoid the unsafeness that is inherent to string pasting.

I can see a mostly complete way to do this for a C-like language. Consider the following syntax (I think it's obvious):
Code:
syntax ("do", instr i1, "while", expr e1) means
{
i1; while (e1) i1;
}

This could be a definition of the do (...) while loop in therms of the basic while loop.
If the syntax-definition mechanism is powerful enough to define some of the basic language constructs, then it is likely to be future-proof.

A mechanism like this could be used to define, in a safe way, a syntax for SEH infrastructures, or a syntax for coroutines.
Presently, the preprocessor only allows to do this with a bunch of dirty hacks, and the resulting syntax will most likely look strange. Again, the fact the it is even possible to do something like this with string pasting is only the product of a bunch of happy coincidences.

JJ


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 36 posts ]  Go to page Previous  1, 2, 3

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group