Can ruby replace c?

C

cmk128

Hi
Can ruby replace c ? Or no, because ruby is a high level language !!
Can ruby write inline assembly?
Does ruby have linker script, so i can link any piece to a specific
address, i need this often in driver programming.
In c, if i declare char[100], it consume 100 bytes, if in ruby, does
it have a datatype that represent one byte? I heard everything in ruby
is object, no exception, so the answer should be no.
Does ruby have pointer? a cpu-specific pointer? In 32 bit CPU,
pointer is 32 bits, in 16 bit CPU, pointer is 16 bits.

thanks
from Peter ([email protected])
 
K

Kevin Brown

Ruby is an interpreted high level language. You can do a lot of C-like things
in Ruby, but due to performance reasons, Ruby won't replace C, at least until
we have an extremely efficient compiler. It is a perfect language for many
things however.
 
R

Robert Klemme

Hi
Can ruby replace c ? Or no, because ruby is a high level language !!
Can ruby write inline assembly?

IIRC there is a project that allows incline C or assembly code. Someone
with more specific memory out there?
Does ruby have linker script, so i can link any piece to a specific
address, i need this often in driver programming.

Well, you can write C extensions. And there you can do pretty much
everything C allows (if you respect some caveats, as mem allocation etc.).
In c, if i declare char[100], it consume 100 bytes, if in ruby, does
it have a datatype that represent one byte? I heard everything in ruby
is object, no exception, so the answer should be no.

This is the closest you can get

s = "\000" * 100
Does ruby have pointer? a cpu-specific pointer? In 32 bit CPU,
pointer is 32 bits, in 16 bit CPU, pointer is 16 bits.

No. And you don't need them and cannot use them in Ruby. You would have
to deal with this in an extension.

Kind regards

robert
 
N

Nikolai Weibull

Can ruby replace c ?

irb(main):001:0> i =3D 0; "c".upto("ruby"){ i +=3D 1 }; p i
330639

So there are quite a few iterations left before C will become Ruby (and,
given that D has been around for quite some time and hasn=E2=80=99t becom=
e even
close to finished, I=E2=80=99m guessing that the answer is =E2=80=9Cno=E2=
=80=9D),
nikolai

--=20
Nikolai Weibull: now available free of charge at http://bitwi.se/!
Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}
 
A

Ara.T.Howard

Windows is problematic since you'll need the compiler you built Ruby with
for the RubyInline stuff to work.

It's just fine on Mac's and other unix/linux boxen though.

'just fine' is an understatement though- this is a seriously under-rated
project!

cheers.

-a
--
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| Your life dwells amoung the causes of death
| Like a lamp standing in a strong breeze. --Nagarjuna
===============================================================================
 
C

Christophe Grandsire

En r=C3=A9ponse =C3=A0 Nikolai Weibull :
=20
=20
=20
irb(main):001:0> i =3D 0; "c".upto("ruby"){ i +=3D 1 }; p i
330639
=20
So there are quite a few iterations left before C will become Ruby (and= ,
given that D has been around for quite some time and hasn=E2=80=99t bec= ome even
close to finished, I=E2=80=99m guessing that the answer is =E2=80=9Cno=E2= =80=9D),
nikolai
=20

This one really cracked me up! The first time I see a joke written in a=20
programming language!!!
--=20
Christophe Grandsire.

http://rainbow.conlang.free.fr

You need a straight mind to invent a twisted conlang.
 
M

Mitch

Which D language?

The improvement to c++?
http://en.wikipedia.org/wiki/D_programming_language

Or Sun's (very useful right now) dtrace language also called D?
http://docs.sun.com/app/docs/doc/817-6223

I am starting to wonder what languages will look like when we hit the
Z programming language. Theoretically it is all over then, I mean we
are out of letters unless we start using Greek or Russian or Japanese
characters.

Although would you really want to program in the beta language? Or
alpha for that matter?

Mitch
 
D

David A. Black

Hi --

I am starting to wonder what languages will look like when we hit the
Z programming language. Theoretically it is all over then, I mean we
are out of letters unless we start using Greek or Russian or Japanese
characters.

$ ruby -e 'p "Z".succ'
"AA"

:)


David
 
S

Sean O'Halpin

No, it should work on Windows too provided you built your own Ruby.
You may need to set some ENV vars as well (like HOME or INLINE_DIR).
I was wrong - it almost works with the One-Click Installer version. I
just didn't try hard enough.

The problem appears to be that it isn't picking up msvcrt-ruby18.lib
on the LINK step. It compiles when I copy the cl command line from the
error output and add the lib like so:

cl -nologo -LD -MD -Zi -O2b2xg- -G6 -I
c:/ruby/lib/ruby/1.8/i386-mswin32 -o Inline_MyTest_cb89.so
Inline_MyTest_cb89.c msvcrt-ruby18.lib -link /INCREMENTAL:no
/EXPORT:Init_Inline_MyTest_cb89

(with c:\ruby\lib added to the LIB environment variable) but how do I
get RubyInline to do this?

Any pointers anyone? (I'd love to play with this)

Sean
 
J

Jon A. Lambert

R

Ryan Davis

I was wrong - it almost works with the One-Click Installer version. I
just didn't try hard enough.

The problem appears to be that it isn't picking up msvcrt-ruby18.lib
on the LINK step. It compiles when I copy the cl command line from the
error output and add the lib like so:

cl -nologo -LD -MD -Zi -O2b2xg- -G6 -I
c:/ruby/lib/ruby/1.8/i386-mswin32 -o Inline_MyTest_cb89.so
Inline_MyTest_cb89.c msvcrt-ruby18.lib -link /INCREMENTAL:no
/EXPORT:Init_Inline_MyTest_cb89
(with c:\ruby\lib added to the LIB environment variable) but how do I
get RubyInline to do this?

The C builder has API to do this:

class X
inline:)C) do |builder|
builder.add_link_flags "whatever"
# ...
end
end

It is fairly well documented. Just generate the rdoc and poke around.

The better route to go is to build your own ruby and it'll pick up
all the things it needs automatically.

Read rbconfig.rb for where we get all our building information.
 
C

Christophe Grandsire

Selon Mitch said:
I am starting to wonder what languages will look like when we hit the
Z programming language. Theoretically it is all over then, I mean we
are out of letters unless we start using Greek or Russian or Japanese
characters.

Some have already started with Hebrew letters:
http://en.wikipedia.org/wiki/Alef_programming_language
(and http://en.wikipedia.org/wiki/Afnix_programming_language used to be c=
alled
Aleph)

:)
Although would you really want to program in the beta language?

Some people would, it seems:
http://en.wikipedia.org/wiki/BETA

Or
alpha for that matter?

Can't find Alpha but Alphard exists:
http://en.wikipedia.org/wiki/Alphard_programming_language

Anyway, since we have Unicode we shouldn't feel limited to the Latin alph=
abet.
Let's make a language named after a Tibetan letter! ;)
--
Christophe.

http://rainbow.conlang.free.fr

It takes a straight mind to create a twisted conlang.
 
S

Sean O'Halpin

The C builder has API to do this:

class X
inline:)C) do |builder|
builder.add_link_flags "whatever"
# ...
end
end

It is fairly well documented. Just generate the rdoc and poke around.

The better route to go is to build your own ruby and it'll pick up
all the things it needs automatically.

Read rbconfig.rb for where we get all our building information.

Thanks - those are just the pointers I needed.

Sean
 
P

Patrick Gundlach

Hi,
Although would you really want to program in the beta language?


Yes, it is actually very nice. If it were more widespread, I'd
probably still program in it. It has some nice syntactic sugar.

Patrick
 
L

Lothar Scholz

Hello Mitch,

M> Which D language?

M> The improvement to c++?
M> http://en.wikipedia.org/wiki/D_programming_language

M> Or Sun's (very useful right now) dtrace language also called D?
M> http://docs.sun.com/app/docs/doc/817-6223

M> I am starting to wonder what languages will look like when we hit the
M> Z programming language. Theoretically it is all over then, I mean we
M> are out of letters unless we start using Greek or Russian or Japanese
M> characters.

Z does exist but is a program specification language, a terrible thing
that you learn in university. Eiffel is a real language based on Z. So
we are just adding one or two more letters to the language name.
 
K

Kev Jackson

Z does exist but is a program specification language, a terrible thing
that you learn in university.

second that! The painful memories of Z (only two lectures, but it was
awful)
Kev
 
C

Christophe Grandsire

Selon Lothar Scholz said:
Z does exist but is a program specification language, a terrible thing
that you learn in university. Eiffel is a real language based on Z. So
we are just adding one or two more letters to the language name.

So *that's* why I found Eiffel so awful when I looked at it!

For what is worth, I'm looking at Sather right now. It is inspired from E=
iffel
(up to its name, referring to the Sather tower of Berkeley :) ), but has
derived away from it, and adopted many nice ideas like iterator methods,
closures, etc... that make it look a bit like Ruby. Actually, Sather look=
s
quite a bit like Ruby, with the main difference being that it is statisti=
cally
typed. I often find conventions used by Ruby that are used by Sather too,
although not always for the same use (for instance, Sather uses the ! cha=
racter
at the end of some methods, but it uses it for iterators rather than for
destructive methods). Method names are often similar to those used in Rub=
y.

All in all Sather is quite an interesting language from a Ruby point of v=
iew.
Too bad that its community is non-existent (although the official compile=
r, GNU
Sather, is still reasonably supported, last update being in June of this =
year).
--
Christophe.

http://rainbow.conlang.free.fr

It takes a straight mind to create a twisted conlang.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,184
Messages
2,570,975
Members
47,532
Latest member
SunnyGarve

Latest Threads

Top