Can Python be written in FreeBASIC?

General discussion for topics related to the FreeBASIC project or its community.
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: Can Python be written in FreeBASIC?

Post by caseih »

BasicCoder2 wrote:That was the main question as in practice I understand the Python interpreter to be written in languages like C and Java.
The version of Python most used is written in C. There are versions written in c# (ironpython) and Java (jython).
I have no need to extend Python only to translate FreeBASIC programs to a Python equivalent. In theory this requires learning Python and any imports required to duplicate FreeBasic graphics.

I think translating a Python program into a FreeBASIC program would require a lot more work and the ability of FreeBASIC to use any of the import libraries used in the Python program. For this reason it seems to me there is no choice but to forget FreeBASIC as an option as only Python provides the libraries required in the hardware projects.

Really I hate Python as my projects haven't required all that list stuff and wished there were libraries for plain old C which I used to use back on the old DOS machines..
Yes it is a different but capable language. If you haven't required "all that list stuff" then I take it you haven't needed to use arrays yet? I use lists all the time. For lots of things they are equivalent to arrays. Anyway it there's something in particular tripping you up, I can try to help.
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: Can Python be written in FreeBASIC?

Post by BasicCoder2 »

caseih wrote:What is this hardware project you're writing on, basiccoder?
Different projects involving Raspberry Pi or Android phones and so on that I read about in books, magazines or on the internet.
If you haven't required "all that list stuff" then I take it you haven't needed to use arrays yet? I use lists all the time. For lots of things they are equivalent to arrays. Anyway it there's something in particular tripping you up, I can try to help.
Well I use arrays all the time in FreeBASIC but Python has idiosyncratic ways of doing things so I can't rely on what I already know instead having to learn another way of doing the same thing. I feel like a beginner learning a completely new language and my ability to remember new ways isn't what it used to be. I still remember how annoying it was when I had to remember if it was rts or ret for two different microchips. With C I always forget the semi colon and with Python they added a colon which in my opinion negated removing easy to see block symbols.
.
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: Can Python be written in FreeBASIC?

Post by caseih »

Yeah I always forget the semicolons too. They are nice in that they allow lines to continue without having to have a special character like FB requires (_) or Python (\) but generally I could do without. And after programming in Python for quite a while I now despise braces. They look so ugly to me now! The colon is a bit odd in Python. I understand why it's there, and it does look right to me, but it could be dropped and the blocks would still be readable.

Python is definitely different and picky about certain things. Once you get used to that I don't think you'll have any problems with using lists and dictionaries. They are such versatile types. I can pretty much make any data structure from linked lists to binary trees with those two structures (often used together). I find it's helpful to play around with the python interactive prompt for trying out simple things like list operations.

QuickBasic and QBasic have an interactive mode that's very powerful, and you could even stop a program's execution and then go inspect variables by running commands in that window. A neat concept. Interpreters do have their place.
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Re: Can Python be written in FreeBASIC?

Post by anonymous1337 »

datwill310 wrote:
sancho2 wrote:
datwill310 wrote:Isn't that illegal?
This is a terrible way to phrase it.
No it is not illegal. Nowhere is it illegal.
Does it violate the PB EULA, possibly. But that does not make it "illegal".
I am sorry to have used this phrase: I'm not all too educated in that area (I didn't know that most copyright law infringements were not illegal). I was wrong in bringing in a whole other language into this forum as well.
Copyright infringement is illegal and can result in legal action against an organization. At the very least, site takedown requests can be executed through formal legal channels. That being said, Python is licensed under the Python Software Foundation License, which is BSD-compatible. The same goes for CPython, the most widely used production Python compiler and reference implementation of the Python language and runtime.

The BSD license is very permissive, and nothing mentioned in this thread would be illegal under BSD license terms. Generally speaking, if something is licensed under BSD or MIT licenses, you can pretty much do anything with that intellectual property, including building proprietary extensions and binaries.

As far as building Python in FreeBASIC, I don't see why this would be a difficult thing to do. Just take CPython's source, which is available here: https://github.com/python/cpython or official: https://hg.python.org/cpython

And translate that to FreeBASIC.

Here are instructions for getting CPython and starting development: https://docs.python.org/devguide/setup.html

You could possibly even just send the source of CPython along the distributions and worry only about header translations. You could include binaries for Windows distributions, while Linux and Mac OS users would be able to compile CPython out-of-the-box. (Thanks to Chocolatey and other tools now available on Windows, Windows users might only need a shell script to install Chocolatey and then everything else is automated.)

The rest could be done via an interface between FreeBASIC and Python.

I don't know much about Cython, but that would be something else worth looking into: http://cython.org/

A motivation I could see for the community wanting to do this is embeddable FreeBASIC, although I thought some community members had already done work on getting FreeBASIC to run in interpreted / JIT environments (like in a web browser). Python is a vastly different language from FreeBASIC, however, so serious modifications would be necessary to produce FreeBASIC or even a near-equivalent from a pre-existing Python compiler and bytecode interpreter.

Might be better to find a minimal compiler + bytecode interpreter project and adapt FreeBASIC to that instead. Python is fairly evolved and even depends a lot on its own evolutions. An example is the Global Interpreter Lock (https://en.wikipedia.org/wiki/Global_interpreter_lock) which could be seen by some FreeBASIC users as extremely limiting (although both Python and Ruby have one and are doing just fine).
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Re: Can Python be written in FreeBASIC?

Post by anonymous1337 »

caseih wrote:QuickBasic and QBasic have an interactive mode that's very powerful, and you could even stop a program's execution and then go inspect variables by running commands in that window. A neat concept. Interpreters do have their place.
You can do this in pretty much any language with a decent debugger, honestly. This includes programs written in C and C++ in Visual Studio, for example.
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: Can Python be written in FreeBASIC?

Post by caseih »

Yes visual studio does have a very powerful debugger and you can recompile sections of code while it's still running. Replace running code. I don't know of any other debugger that can do that.

But a debugger isn't what I was talking about with qb. Intermediate mode is not just about inspecting variables and the normal stuff debuggers do. In QB, code is live as you type it. You can call functions and run loops and stuff from the intermediate prompt. It's very much like the Python interactive prompt.
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Re: Can Python be written in FreeBASIC?

Post by anonymous1337 »

caseih wrote:Yes visual studio does have a very powerful debugger and you can recompile sections of code while it's still running. Replace running code. I don't know of any other debugger that can do that.

But a debugger isn't what I was talking about with qb. Intermediate mode is not just about inspecting variables and the normal stuff debuggers do. In QB, code is live as you type it. You can call functions and run loops and stuff from the intermediate prompt. It's very much like the Python interactive prompt.
Sure, the nature of old-school QB was that it was strictly interpreted, like a lot of Python or Ruby code is. I don't necessarily see that as valuable to the user, to the extent that it justifies interpreters over JIT'd or compiled code. IMO, seems like the strongest use case for interpreters is that they are easy to write and play around with.

But as a user, if you have something which can evaluate expressions at runtime, but still perform really well, great! You can do this with just about any language and popular toolset using the console and an immediate mode evaluator.
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: Can Python be written in FreeBASIC?

Post by caseih »

QB was both an interpreter and a compiler. By default it ran as an interpreter in the IDE, and code was live as you developed, which was a super great way to do things. Then you could have it crank out an EXE that was either an interpreter bound to a parsed version of your BASIC code (PCODE I think they called it), or it could emit a true compiled exe.

The interactive console of an interpreter like python or ruby is an incredibly powerful tool for the programmer. I'm not really sure who this "user" is that you speak of. And I'm not really sure what your point is in context of what BasicCoder and I were talking about. BasicCoder was talking about his experiences learning Python and I am merely trying to assist in that by pointing out features like the interactive mode that can help him learn. It's an essential tool when exploring the structure of classes and objects in a new module, or to quickly figure out what a particular slicing syntax does to a list or string.
marcov
Posts: 3455
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: Can Python be written in FreeBASIC?

Post by marcov »

caseih wrote:QB was both an interpreter and a compiler. By default it ran as an interpreter in the IDE, and code was live as you developed, which was a super great way to do things. Then you could have it crank out an EXE that was either an interpreter bound to a parsed version of your BASIC code (PCODE I think they called it), or it could emit a true compiled exe.
"The" pcode is the bytecode of UCSD Pascal, but since it is the first popular bytecode (+/- 1980), the term is used generically. Some ancient bytecode compilers are compilable with FPC.

Java 1.4 (or older) bytecode is basically "a" Pcode (logical, since it was modeled after it).

Such a bytecode is more or less producing an exe for the assembler of a simple virtual processor, to be interpreted by an interpreter, and close to assembler in philosophy.

IIRC Java switched to a newer bytecode type in 1.5 which requires a JIT and is not interpretable in the old ways. (the type info has been removed making it more dense, but requiring a separate type interference step by the JIT compiler)

Many Basics however, store sources in tokenized form, which is a representation that is equal or nearly equal to the source. This was done to save space, keywords are tokenized, and whitespace often disappears. Keep in mind that Basic had a stronghold in very memory constrained 8-bit micros in the past .
It's an essential tool when exploring the structure of classes and objects in a new module, or to quickly figure out what a particular slicing syntax does to a list or string.
You don't need an interpreter for that. Many more advanced debuggers could do this too, by selectively recompiling parts, and/or storing pcode-like representations of expressions or even whole functions in the debuginfo. Many debuggers can evaluate expressions to some degree. This style went out of fashion, though some C/C++ compilers use it for stepping through properties, inline functions and some forms of templates/generics. Unfortunately most open source toolchains are not very deeply integrated, so often miss more advanced features

But even GDB supports some of it.
Last edited by marcov on Dec 21, 2016 17:13, edited 3 times in total.
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Re: Can Python be written in FreeBASIC?

Post by anonymous1337 »

caseih wrote:I'm not really sure who this "user" is that you speak of.
The developer.
figosdev
Posts: 18
Joined: Jan 06, 2017 7:24

Re: Can Python be written in FreeBASIC?

Post by figosdev »

BasicCoder2 wrote:With C I always forget the semi colon and with Python they added a colon which in my opinion negated removing easy to see block symbols.
.
There's got to be an IDE that helps with this sort of thing so you don't have to bother. I don't typically go for that sort of thing, but it can help with new languages.
Post Reply