The Perfect OS Programming Language

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
whyme_t

Re:The Perfect OS Programming Language

Post by whyme_t »

or even just to be able to define a single bit ;)

I would like to develop an object oriented language, but at a much more lower level. Lower than C, but higher than Asm. So you could mix 16bit and 32bit code, you could use the normal return from function, or the return from interrupt. It would support all the things you can't do in C and are forced to do in ASM, so effectively, you could write the whole os in my new language :)
but then, I'm just a dreamer ;)
Tom

Re:The Perfect OS Programming Language

Post by Tom »

you Can make a single byte in C...

typedef char byte;

makes a byte ;)
Tom

Re:The Perfect OS Programming Language

Post by Tom »

just today I had a prob with NASM...

In nasm I had to do a:

GLOBAL ErrNum
ErrNum db 0

but I mis read my code and put a
ErrNum dw 0 ; <--- dw not db

and in my c code I did a:
extern char ErrNum;

and Because ErrNum was a dw and not a db...I had a long time of trying to figure out the bug :-[

So...a good mod for NASM would be another name way to make data!
Curufir

Re:The Perfect OS Programming Language

Post by Curufir »

If you want to avoid that kind of error why not just set yourself up some nice easy to remember macros that declare things the way you want every time.

For example:

Code: Select all

%macro  char_ 1

    %1: db 0

%endmacro 
You can then use it as so:

Code: Select all

char_ ErrWord
Which has the Nasm syntax equivalent of:

Code: Select all

ErrWord: db 0
You could even go so far as to add a second variable so you can declare it with a value like this:

Code: Select all

%macro  string_ 2 

    %1: db      %2, 0

%endmacro 
And use like:

Code: Select all

string_ TestString, {'This is my test string', 13, 10}
Which is equivalent to:

Code: Select all

TestString: db 'This is my test string',13,10,0
So you see you can go a good way in nasm just by using some well placed macros.

Note: I deliberately put an underscore there because if you reach integers.... :)

It's not something that I thought of doing myself, but then again I'm only using assembly language (Not for any snobby, holier than thou, "I spit on all you HLL people because I can write better code than the optimiser (Sure, keep dreaming ;D)" mode of thought. I just use it because I like programming in assembly and I'm doing this for fun) and flat binaries, so I just look down the page for the variable.

Curufir
Berserk

Re:The Perfect OS Programming Language

Post by Berserk »

how would u make a compiler?? got any sample c/c++ source code?? i've been thinking of making a new language, but i have no experience in making compilers?? i'm clueless?? Where would i start, maybe this is off the topic, But seriously?? where would someone start to make a compiler??

DAMN i am SOOOOOOO curious,

;D
Tom

Re:The Perfect OS Programming Language

Post by Tom »

Berserk, you are getting too much into too much stuff.

Just worry about learning to program well, and make your OS from the simple start ( I.E. no splash screen ).

I know you want your OS to be cool, but what if it's cool like WinXP and doesn't run perfectly all the time? ( No Offence, just wanted you to know that )
elias

Re:The Perfect OS Programming Language

Post by elias »

make a compiler!!! thats a whole new message baord!!! i read a tiny bit about compiler theory, and it gets pretty complicated. ant btw, you cant really have a low level OOP language, well u can, any langauge can be OOP, its jsut a style of coding, but you cant really have a fast one. its a trade-off. design and flexibility vs. speed. you cant have both. C++ is slower than C, cuz of all the extra code needed to be generated to make it OOP. im soryr but you cant have both, and please dont bother wiht a cpompiler right now unless your really good with asm, cuz thats what your gonna have to do. basically jsut translate some syntax you created into asm. you coudl still read up on compilers and theory, cuz it is pretty interested, btu dont bother attmepting a real language until your an experienced and knowledgable asm programmer.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:The Perfect OS Programming Language

Post by Pype.Clicker »

if you want to code in OO language and can't find one that perfectly fit your needs, you still can try to define a /preprocessor/ that will translate your new language into pure C code. this is just text manipulation: no optimisation needed or other things like that. Perl will be a very good choice to implement that kind of tool ...

now the problem with custom language is that you'll probably experience difficulties to find people to help/support/port your OS because they'll fall in a completely unknown environment
elias

Re:The Perfect OS Programming Language

Post by elias »

wow, use the preprocessor, i never even thought of that. but would that actually slow it down a lot, if you want to get it as clean and nicely OOP(couldnt think of a better term) as java?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:The Perfect OS Programming Language

Post by Pype.Clicker »

slowing down ? not much: you only preprocess at compile-time and your preprocessor will probably be a lot faster than GCC compiler (which has a *lot* of job to do) for the same source file. In Clicker, i have such preprocessor to handle dynamic linking in a smarter way ... it doesn't take more than 1% of the compile time for the kernel and something about 5 to 10% for a module (which has fewer lines for GCC thus it reduces the global cost for a roughly constant preprocessing cost....

most OOP technique can be implemented in C, such as interfaces through function pointers, setjmp/longjmp for try/catch/throw, etc. once your object model is defined, all you need is a small grammar for the declarations and substitution rules for the code itself ...
whyme_t

Re:The Perfect OS Programming Language

Post by whyme_t »

Pype, this is exactly what I was thinking about. Although I was thinking of outputting ASM instead of C. Otherwise I'm limiting myself to the same problems with C, I was thinking of something more flexible, closer to ASM. I was originally thinking of using Java to implement a Preprocessor, but I could see the benefits of using Perl. :)
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:The Perfect OS Programming Language

Post by Pype.Clicker »

i don't recommend you to output ASM, unless you think you can do registers allocation and optimizations better than C compiler ...

and the reason why i recommend perl as compiler-writing language is that i know no other language that could do

Code: Select all

(/class ([A-Z][a-ZA-Z_0-9]*) \{/) && do {
   push @class_name, $1;
   push @block_type, "CLASS_DEFINITION";
}
as efficiently as perl ...

and finally, what could (imho) be the best programming language would be a language where classes can control the syntax they allow ... for instance, the LIST class could come with a

foreach $varname in $list { ... } block which would expand in a loop sweeping the list and call the instruction block with every item of the list ...

the constructor/destructor overloading is also a must while it allow compile-time garbage collection (decrementing the reference counter and freeing the item is no reference is left) ...

finally, interfaces definition and support must be built in the language. Nowadays programmers *do* use OOP design, so if your compiled code is fast enough and if your language allow enough control to avoid automatic generation of useless overhead, i see no reason not to make it an OOP language ...

a last delirium about pointers: try to have something between C and Java : you'll need a raw access to byte/long/... arrays at some times (relocations, stack manipulation, etc.) where you will need pointers arithmetics, but try to avoid generic pointers arithmetics (forging a pointer from an int, for instance, shouldn't be allowed ...)
Nice

Re:The Perfect OS Programming Language

Post by Nice »

perl is nice. Also look at bison and it's derivatives, if you are more comfortable in c (or c++ or java or whatever flavour of bison you find)

Programming languages often have nice features that things could borrow. Here are the things I'd want to borrow from everywhere:

pascal: strings, calling convention, nested functions, interface/implementation in same sourcefile, and it is easy to read after you leave the code for a few months/years

c: the maths (+= ++ etc), pointer arithmetic and, err, that is about it.

c++: operator overloading; friend classes/functions, multiple inheritence and templates migt be useful

java: garbage collection (cool in userland), implicit pointers (but I like explict pointers too; nice to have both? Default is implicit, but a prefix can indicate you want explicit manipulation). It has a pretty complete library, although the graphics suck; and bytecode is a bit of a slowdown

basic: garbage collection :-) (and you thought it was all-bad?)

objective-c and IIRC python: mixins

Java has a neat thing whereby some implementing interfaces are actually keywords to the compiler (eg serialisation); you could (natively compile) java and define such keywords to mark things; consider the following snippet:

Code: Select all

public class NVidiaDriver implements VideoAccelorator, Ring0, NotMigratable {
pskyboy

Re:The Perfect OS Programming Language

Post by pskyboy »

I wish id seen this post when it was posted first oh well.

I would like to see bit manipulation on any data type. A standard set of types which are all objects and then the size is specified, so you can have types of any size.

I would also like to see automatic memory managment through garbage collection but that is linked in sequentially with the code rather then seperate thread so you can compile native code.


Anyway ill be including all this in the language spec im going to write which i will post when i have doen it.

Peter
Post Reply