C to PureBasic Transpiler

Everything else that doesn't fall into one of the other PB categories.
User avatar
fsw
Addict
Addict
Posts: 1572
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

C to PureBasic Transpiler

Post by fsw »

Does anyone know if there is a C to PB transpiler?

A long, long, long, long, long time ago we talked about it on the forum (maybe 15 years ago) but I don’t remember if someone actually coded one.

Thank you

I am to provide the public with beneficial shocks.
Alfred Hitshock
User avatar
skywalk
Addict
Addict
Posts: 4003
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: C to PureBasic Transpiler

Post by skywalk »

Given the recent developments of PB v6, does this request still matter?
I am more interested including and compiling the many, many C lib's such as idle has presented in another topic.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
BarryG
Addict
Addict
Posts: 3330
Joined: Thu Apr 18, 2019 8:17 am

Re: C to PureBasic Transpiler

Post by BarryG »

Why wouldn't it matter? It's about converting C sources to PureBasic sources, isn't it? That would be fantastic!
User avatar
fsw
Addict
Addict
Posts: 1572
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: C to PureBasic Transpiler

Post by fsw »

Hi skywalk,
this is a fair question to ask, especially now that PB compiles to C.

I have a specialized graphical app that is coded in plain 32-bit C for Windows.
This app is complex (but the code is easy to read) and I'm thinking of achieving 2 goals:
1. Make it 64-bit
2. Make it multi platform

Surely, a C to PB transpiler would help to get things going faster than doing everything manually...

I found C to Go transpilers, but the graphical portion of the code would still be hard to make multi platform.
(maybe starting out with the Walk UI lib for Go on Windows, and then go from there... but where, which UI?)
That's where PureBasic would come in handy...

BTW: I know transpilers are not the 'holy grail' but still they could cut the time a lot...

I am to provide the public with beneficial shocks.
Alfred Hitshock
User avatar
skywalk
Addict
Addict
Posts: 4003
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: C to PureBasic Transpiler

Post by skywalk »

Yes, I wrote a C header to PB prototyper for external C libs but it still required corner cases for macros and complex syntax. Going full C source would be quite a lot more work. But I do see the advantage. If your code is well defined, you could create an equally controlled parser.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: C to PureBasic Transpiler

Post by davido »

@fsw,
I don't recall seeing a transpiler, however I think it would be very useful, should one be made available.
DE AA EB
User avatar
Tenaja
Addict
Addict
Posts: 1949
Joined: Tue Nov 09, 2010 10:15 pm

Re: C to PureBasic Transpiler

Post by Tenaja »

Sure, it would be nice. But I will be pleasantly surprised if it happens. Just look at how long it has taken Fred to convert PB to C...and he's on it full time.

Now to go the other way (C to PB), with C having so many more features and options for doing the same thing, and it will take even longer. Strings will not get translated to strings, because in C they are arrays. Pointers will be a mess. Case statements with fall-through (i.e. no "break") will be impossible without adding GoTo's everywhere. I'm not saying it would be impossible, but certainly more difficult than PB to C.

It kind of seems like it would be pointless, since you can now include C files into your PB project. What would be the point?
Marc56us
Addict
Addict
Posts: 1479
Joined: Sat Feb 08, 2014 3:26 pm

Re: C to PureBasic Transpiler

Post by Marc56us »

Agree: Transcompiling from C to PB would be like trying to put the toothpaste back in the tube. Don't even think about it. Even with very well written C code (which does not exist :D )
I've already rewritten programs. It has always been easier and more viable to start from the analyst's work (Diagram and Pseudo code) and never from the programmer's code whatever language (except for some algorithms)
:wink:
User avatar
idle
Always Here
Always Here
Posts: 5097
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: C to PureBasic Transpiler

Post by idle »

It's not really practical as you'd only get a subset of c and it'd be 10 times harder to write than it was to write a c target

you can of course embed c into your program and work with it but it's clunky. The auto c importer I'm working on will eventually facilitate us to just include a c header to import a library and use it in PB with 100% compatibility but it only works with symbols to inform the pb compiler and ide of the c symbols, it doesn't even touch the c syntax as it works directly off of the AST. so it's verbose enough to work with but it still has a number of issues to contend with and I don't have time to work on it at the moment. it's a job for winter and will likely take 1 to 3 months to do.
User avatar
fsw
Addict
Addict
Posts: 1572
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: C to PureBasic Transpiler

Post by fsw »

Thank you all for your comments as it gave me some things to think about.

Idle,
Winter in New Zealand?
And all this time I thought New Zealand as almost paradise :P

Anyway, first things first...
...where is my toothpaste?

Live long and prosper...

I am to provide the public with beneficial shocks.
Alfred Hitshock
User avatar
idle
Always Here
Always Here
Posts: 5097
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: C to PureBasic Transpiler

Post by idle »

It's relative, it gets wet and a little bit chilly for 3 months it's still a sunny 26c today with a light breeze.
User avatar
StarBootics
Addict
Addict
Posts: 984
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: C to PureBasic Transpiler

Post by StarBootics »

Hello everyone,

Sorry to be later on this topic but there is take on this subject. Remember when I have published a code about RabbitCipher which was written in C originally. Take time to review this code to understand how complicated it can be when you deal with C code that uses unsigned long integers while PureBasic does not. The tactic I have used to solve the problem was to use the positive part of a Quad to simulate the unsigned long integer. Basically I'm using a 64bit variables but only the considering the first 32bit of it. I'm wasting 32bit of memory for each variables for absolutely nothing. Even if it is working it is not memory efficient.

If both language supports all possible types a transpiller would be possible but as you know PureBasic don't support all standard C types. This doesn't mean it can't be done to partially work on some codes.

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
User avatar
NicTheQuick
Addict
Addict
Posts: 1227
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: C to PureBasic Transpiler

Post by NicTheQuick »

StarBootics wrote: Thu Mar 31, 2022 6:44 am Hello everyone,

Sorry to be later on this topic but there is take on this subject. Remember when I have published a code about RabbitCipher which was written in C originally. Take time to review this code to understand how complicated it can be when you deal with C code that uses unsigned long integers while PureBasic does not. The tactic I have used to solve the problem was to use the positive part of a Quad to simulate the unsigned long integer. Basically I'm using a 64bit variables but only the considering the first 32bit of it. I'm wasting 32bit of memory for each variables for absolutely nothing. Even if it is working it is not memory efficient.

If both language supports all possible types a transpiller would be possible but as you know PureBasic don't support all standard C types. This doesn't mean it can't be done to partially work on some codes.

Best regards
StarBootics
Since the word size of todays operating systems and CPU is 64 bit you are not wasting anything except you are using unpadded structures with fields smaller than 64 bit. I mean, even booleans use 64 bit. ;-)
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
juergenkulow
Enthusiast
Enthusiast
Posts: 557
Joined: Wed Sep 25, 2019 10:18 am

Re: C to PureBasic Transpiler

Post by juergenkulow »

Could Fred do that?
User avatar
idle
Always Here
Always Here
Posts: 5097
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: C to PureBasic Transpiler

Post by idle »

You can use unsigned types now in c backend but you need to redefine the variables in c.
https://www.purebasic.fr/english/viewtopic.php?t=78386
Post Reply