LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-20-2013, 08:53 AM   #16
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454

Quote:
Originally Posted by PTrenholme View Post
Well, my current favorite language is pure, which compiles to LLVM "portable" code. With that approach, you could do your development on an existing system, and, when you decided on your target hardware, all you'd need was a LLVM interpreter for that hardware and you'd be "good-to-go." I suspect that it could be done, but I'm 73 years old now and I don't think I'd be interested in trying to do it in the time I've got left to play with such things.

If you're interested, pure is a pure functional language, using (preferentially) "curried" functions. (Both haskell and curry are named to commemorate Haskell Curry. pure could, with some lack of precision, be thought of as a "mild" curry.)

<edit>
A pure example:
Code:
$ pure

 __ \  |   |  __| _ \    Pure 0.57 (x86_64-redhat-linux-gnu)
 |   | |   | |    __/    Copyright (c) 2008-2013 by Albert Graef
 .__/ \__,_|_|  \___|    (Type 'help' for help, 'help copying'
_|                       for license information.)

Loaded prelude from /usr/lib64/pure/prelude.pure.
> fact n = 1 if n==1; fact n =  n * fact (n - 1) if n>1;
> map fact (1..10);
[1,2,6,24,120,720,5040,40320,362880,3628800]
> fact 100L;
93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000L
</edit>

This all is very interesting, but how do you write to/read from an absolute memory location and/or HW port ? Without being able to do it you can't write a device driver and hence an OS kernel.
 
Old 05-20-2013, 08:59 AM   #17
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by Sergei Steshenko View Post
I am no fan of C++, but as a system programming language it's better than "C" because of better type strictness. C++ is almost exactly a superset of "C".
Maybe this indicates a difference in our idea of what "system programming" is. But I think type strictness is a poor feature for a system programming language.

For OS's (and similar style projects) inheritance (including multiple inheritance) is a very useful feature.

You frequently have a structure X, part of which is a sub structure Y. In system programming (as in many other kinds of programming) you often what to be able to access members of Y using a pointer to X without the distraction (or maintenance problem) of specifying that those members are in the Y part of X.

In system programming (much more than in other kinds of programming) you often want to use a pointer to Y combined with outside knowledge that this particular Y is specific substructure of X, and from those compute the pointer to X. In C++ if that Y is any base class of X, you just static cast it. In C or C++, if Y is a named substructure of X, you can use some ugly address arithmetic and casting to get the X pointer. In C++ you could cleanly hide the ugly parts of that in a template. In C, you would need a less clean macro to hide the ugly parts.

Templating is a powerful feature in system programming. In what I called "extreme C programming" above, one tends to use a lot of macros for things that should look and act like functions, but need some flexibility or efficiency that a function can't provide. In C++, you almost never need to use a macro for that. Instead you use a template. The general advantages of templates over macros for such purposes are too varied, large and significant to do justice to them here.

Polymorphism by virtual functions are also a powerful tool for system programming that is syntactically clean in C++, and needs a syntactically ugly "roll your own" approach in C.

Quote:
Originally Posted by Sergei Steshenko View Post
This all is very interesting, but how do you write to/read from an absolute memory location and/or HW port ? Without being able to do it you can't write a device driver and hence an OS kernel.
At the lowest level of that kind of thing, there are always a few stubborn spots where you need to drop to assembly code.

C and C++ have more flexible pointer type casts (than most languages), which eliminates a few places where you might have needed to drop to assembly. Gnu extensions to C and C++ also have powerful syntax for dropping to assembly level inline, rather than calling a function written in pure assembly.

Those are convenience features of C and C++ when coding an OS or a device driver. But ultimately, most of an OS or device driver is higher level code and doesn't need that. If some other language needs to be supplemented with a few pure assemble functions, that doesn't make it a bad system programming language. (If it can't even call pure assembly functions, that does make it a bad system programming language).

Last edited by johnsfine; 05-20-2013 at 09:05 AM.
 
Old 05-20-2013, 09:05 AM   #18
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by johnsfine View Post
Maybe this indicates a difference in our idea of what "system programming" is. But I think type strictness is a poor feature for a system programming language.

For OS's (and similar style projects) inheritance (including multiple inheritance) is a very useful feature.

You frequently have a structure X, part of which is a sub structure Y. In system programming (as in many other kinds of programming) you often what to be able to access members of Y using a pointer to X without the distraction (or maintenance problem) of specifying that those members are in the Y part of X.

In system programming (much more than in other kinds of programming) you often want to use a pointer to Y combined with outside knowledge that this particular Y is specific substructure of X, and from those compute the pointer to X. In C++ if that Y is any base class of X, you just static cast it. In C or C++, if Y is a named substructure of X, you can use some ugly address arithmetic and casting to get the X pointer. In C++ you could cleanly hide the ugly parts of that in a template. In C, you would need a less clean macro to hide the ugly parts.

Templating is a powerful feature in system programming. In what I called "extreme C programming" above, one tends to use a lot of macros for things that should look and act like functions, but need some flexibility or efficiency that a function can't provide. In C++, you almost never need to use a macro for that. Instead you use a template. The general advantages of templates over macros for such purposes are too varied, large and significant to do justice to them here.

Polymorphism by virtual functions are also a powerful tool for system programming that is syntactically clean in C++, and needs a syntactically ugly "roll your own" approach in C.

We have already discussed this to death, but templates are essentially undebuggable because C++ standard does not prescribe any means of debugging them. IMO undebuggability of templates is a great feature for C++ programmers job security, but it's a different issue.

OTOH, type strictness in general allows to catch more errors at compile time.
 
Old 05-20-2013, 10:43 AM   #19
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Quote:
Originally Posted by hydraMax View Post
@PTrenholme: Thanks! I'm installing it now from source.

Question: Can you explain a little bit about what kind of type system it has, or how it works? I am not quite clear on this: the intro page on its site stated that it is an "essentially typeless" language, but the wikipedia page said that it is a "dynamically typed" language. (I'm coming from a Haskell/GHC background, if that helps with the explanation.)
First, please understand that my comment was NOT a recommendation of a language to be used for an OS project. My point only was that your choice of language was almost irrelevant: almost any language could be made to work - with enough effort.

That being said, data "type" is inferred from the type of data passed to the function. Consider the example in my post: The factorial function "fact" was defined as a simple recursion. Then it was passed the first ten integers, and the values collected in a vector that was printed. I then passed in a "bigint" value (100L) which has a much bigger range that a simple int, and the function used, and returned, a "bigint" result.

One can define functions with different actions for different types of arguments. (The "::" qualifier is used for this.) For example:
Code:
/* When converting to an mpfr value, you can either specify a pair (x,p) or
   triple (x,p,r) where p denotes the desired precision (an int) and r denotes
   the desired rounding mode (one of the MPFR_RND constants), or just the
   value x to be converted, in which case the current default precision and
   rounding mode is used. Note that converting an mpfr number to an mpfr
   number creates a *new* mpfr number with the given (or current default)
   precision. */

mpfr x::real | mpfr x::string =
  mpfr (x,mpfr_get_default_prec);
mpfr (x::real,p::int) | mpfr (x::string,p::int) =
  mpfr (x,p,mpfr_get_default_rounding_mode);

mpfr (x::bigint,p::int,r::int) = mpfr_from_bigint x p r;
mpfr (x::double,p::int,r::int) = mpfr_from_double x p r;
mpfr (x::bigint % y::bigint,p::int,r::int) = mpfr (x,p,r) / mpfr (y,p,r);
mpfr (x::real,p::int,r::int) = mpfr_from_double (double x) p r;
mpfr (x::mpfr,p::int,r::int) = mpfr_from_mpfr x p r;
mpfr (s::string,p::int,r::int) = x if typep mpfr x when
  x = mpfr_from_str s p r;
end;
is a fragment from the multiple precision floating point library definition of the mpfr data type, where this part is describing the conversion to mpfr values of various standard data types. (Oh, it may be worth noting that this library is just an interface to the standard mpfr library, and the, e.g., mpfr_from_double, etc., functions are just pointers to (or, if you wish, calls to) the library functions defined (in part) like this:
Code:
using "lib:mpfr";

extern int    mpfr_tag();
extern void   mpfr_free(mpfr*);
extern expr*  mpfr_from_double(double, int, int);
extern expr*  mpfr_from_mpfr(mpfr*, int, int);
extern expr*  mpfr_from_bigint(void*, int, int);
extern expr*  mpfr_from_str(char*, int, int);
extern double mpfr_to_double(mpfr*);
extern int    mpfr_to_int(mpfr*);
extern expr*  mpfr_to_bigint(mpfr*);
...
From this you can see a suggestion of how pure could be used with pointers to specific memory locations.

Oh, F.Y.I., pure is available in the Fedora repositories as an RPM. (Well, the Fedora 19 repo - I haven't checked the older ones.)
 
Old 05-20-2013, 12:45 PM   #20
hydraMax
Member
 
Registered: Jul 2010
Location: Skynet
Distribution: Debian + Emacs
Posts: 467

Original Poster
Blog Entries: 60

Rep: Reputation: 51
Quote:
Originally Posted by H_TeXMeX_H View Post
Is there anyone still running a Lisp machine? The impression given by the wiki article is that the last attempts died out in the 80s.

I think a Lisp machine would be cool if there was one that could be used remotely, or one that I could afford to buy.
 
Old 05-20-2013, 05:38 PM   #21
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by PTrenholme View Post
...
From this you can see a suggestion of how pure could be used with pointers to specific memory locations.
...
From the above examples I see that the language can have "C" stuff bindings. I do not see a way to use pointers pointing to an absolute location directly in the language.

There are languages (e.g. Modula-2, probably Modula-3) that do have pointers. In Modula-2 there is a special module (IIRC called "System") for the "dangerous" stuff related to untyped direct memory access.
 
Old 05-20-2013, 05:42 PM   #22
Pearlseattle
Member
 
Registered: Aug 2007
Location: Zurich, Switzerland
Distribution: Gentoo
Posts: 999

Rep: Reputation: 142Reputation: 142
Going back to the original question...
Quote:
Originally Posted by hydraMax View Post
C - simple, elegant, low-level, incredibly portable. But, if you had to write a new operating system or O.S. kernel, and you couldn't use C, which language would you pick?
...and trying to be a bit realistic I would say as well "C++" and nothing else.
The requirements of "low-level" and "incredibly portable" might be a conflict and you probably cannot have both. Maybe the understanding of "low-level" is different from person to person... .
 
Old 05-22-2013, 12:32 PM   #23
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Does the alternative language have to be one that already exists? It seems to me that the OP is asking essentially the same question Dennis Ritchie asked himself when he crafted his solution to the same problem. Being the adventurous sort in these kinds of things, I'd be tempted to follow Ritchie's lead, and try to write my own. I'm not as smart as he, and have too much C in my DNA to come up with anything that would be a significant departure from C, so I'd probably fail. If I could hire someone to accomplish the job for me, the spec would probably look a lot like C, but with a small-ish number of runtime safety nets built in, such as null/uninitialized pointer dereference checks, array bounds checking, etc. I might be tempted to make these optional at compile time, so many pointer bugs can be quickly killed, and the resulting code optimized to not include the safety nets. I'd probably make it have the ability to specify unambiguously how primitive data types are arranged, and how they behave, and their sizes. The idea would be to make the data types exactly match the target native architecture. This probably flies in the face of portability; see, I told you I wasn't smart enough to get it right.
I wonder if anyone else can add to the shopping list...

--- rod.
 
Old 05-22-2013, 12:40 PM   #24
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,997

Rep: Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338
Just a comment: think about Commodore 64 or ZX Spectrum, you can now simulate all those things and you can write that simulation in (almost) any language you want. So you can implement those OSs for example in MS Visual Basic...
 
Old 05-22-2013, 01:32 PM   #25
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Quote:
Originally Posted by pan64 View Post
Just a comment: think about Commodore 64 or ZX Spectrum, you can now simulate all those things and you can write that simulation in (almost) any language you want. So you can implement those OSs for example in MS Visual Basic...
Hold on, there. A lot of languages rely on services provided by the OS's on which they run. Extrapolating from a simulator running on an OS, to an actual OS seems like a huge leap. I don't disagree that some languages (Forth, as mentioned earlier) are capable of producing/becoming an OS, but Visual BASIC doesn't seem like on of them.
Sun workstations used Forth for their bootloader/ROM monitor. From that, I conclude that it could probably have been expanded to be a full-on OS.
--- rod.
 
Old 05-22-2013, 02:03 PM   #26
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by pan64 View Post
... you can implement those OSs for example in MS Visual Basic...
Show me how in Visual Basic you read a disk sector. You don't have an OS yet, i.e. for ypur point to be valid you need to be able to do this not performing any system call.

Also, show me how in Visual Basic you perform task switching.
 
Old 05-22-2013, 02:09 PM   #27
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,997

Rep: Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338
Hey Sergei, why did you take it so serious? C64 and the Spectrum was not able to perform task switches and there was no disk to read those sectors (just some serial-like i/o line). So if you want to think about my post just please define what does really the word OS mean? And those simulators exist and able to run those quite old programs....
 
Old 05-22-2013, 02:51 PM   #28
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by pan64 View Post
... what does really the word OS mean? ...
https://en.wikipedia.org/wiki/Operating_system .
 
Old 05-22-2013, 03:30 PM   #29
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Quote:
Originally Posted by theNbomr View Post
[...] It seems to me that the OP is asking essentially the same question Dennis Ritchie asked himself [...] I'd be tempted to follow Ritchie's lead, and try to write my own. [...]
--- rod.
If you really want to follow Ritchie's lead, I'd suggest starting, as he did, with B or BCPL. But it is a non-trivial task.
 
Old 05-22-2013, 06:00 PM   #30
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Quote:
Originally Posted by PTrenholme View Post
If you really want to follow Ritchie's lead, I'd suggest starting, as he did, with B or BCPL. But it is a non-trivial task.
What?! Heavens No!. I'd write an assembler in machine code toggled in with switches, so I could use the assembler to write a compiler! In the cold. And wind. Up hill. Both ways...

--- rod.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Google Unleashes Go: A Brand New Systems Programming Language LXer Syndicated Linux News 0 11-12-2009 12:10 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration