Support for byteplay3

60 views
Skip to first unread message

Igor Machado

unread,
Feb 15, 2018, 10:25:12 PM2/15/18
to brython
Dear brython developers,
first of all, your project is quite amazing!
I used it some time ago and was impressed by how easy it was to integrate python in a browser...
My new challenge involving python and js depends on byteplay3 library for python. It is a very low level library that depends on stuff that is intended for python 3.5 (I guess).
I spent almost a month dealing with low level details of python 3.5, and it seems to have changed a lot since 3.3, so I wonder how Brython developers are intending to move on this direction (supporting 3.5 or byteplay3).

Thanks a lot and congratulations for the nice work so far!

Igor M. Coelho

Kiko

unread,
Feb 16, 2018, 2:13:06 AM2/16/18
to bry...@googlegroups.com
2018-02-16 4:25 GMT+01:00 Igor Machado <igor.m...@gmail.com>:
Dear brython developers,
first of all, your project is quite amazing!
I used it some time ago and was impressed by how easy it was to integrate python in a browser...
My new challenge involving python and js depends on byteplay3 library for python. It is a very low level library that depends on stuff that is intended for python 3.5 (I guess).
I spent almost a month dealing with low level details of python 3.5, and it seems to have changed a lot since 3.3, so I wonder how Brython developers are intending to move on this direction (supporting 3.5 or byteplay3).

I don't think it has much sense to use byteplay with brython. Brython doesn't generate bytecode and doesn't follow the same internals than CPython. Brython is a transpiler of Python to Javascript on the fly.
Also, some libs imported by byteplay3 are coded in C in CPython (array, opcode,...) and they are not yet ported to Brython.

I hope it helps.


Thanks a lot and congratulations for the nice work so far!

Igor M. Coelho

--
You received this message because you are subscribed to the Google Groups "brython" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brython+unsubscribe@googlegroups.com.
To post to this group, send email to bry...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/brython/466fb14b-9f94-4644-91d6-cec1544dce6b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Igor Machado

unread,
Feb 18, 2018, 6:25:12 PM2/18/18
to bry...@googlegroups.com
Thanks for the reply. Do you think there could be another way to do it? For example, I tried a lot to deal with emscripten and somehow from python 3.4 onwards, things got really complicated...
I am part of a big project that envolves using python to convert itself to another byte code language. We have funding to give in this direction and if things worked out with Brython that would be a very nice project to support. 

I really got to this point where array and opcode were needed (in fact "array"  was not needed for our functions, somehow I made without it), so question is:  is it possible to port opcode? Or i am looking at a illogical and impossible task? :-)


You received this message because you are subscribed to a topic in the Google Groups "brython" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/brython/oQtJjHyaHdw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to brython+unsubscribe@googlegroups.com.

To post to this group, send email to bry...@googlegroups.com.

Joao S. O. Bueno

unread,
Feb 19, 2018, 7:46:10 AM2/19/18
to bry...@googlegroups.com
On 18 February 2018 at 20:25, Igor Machado <igor.m...@gmail.com> wrote:
> Thanks for the reply. Do you think there could be another way to do it? For
> example, I tried a lot to deal with emscripten and somehow from python 3.4
> onwards, things got really complicated...
> I am part of a big project that envolves using python to convert itself to
> another byte code language. We have funding to give in this direction and if
> things worked out with Brython that would be a very nice project to support.
>
> I really got to this point where array and opcode were needed (in fact
> "array" was not needed for our functions, somehow I made without it), so
> question is: is it possible to port opcode? Or i am looking at a illogical
> and impossible task? :-)

Porting opcode is as close to "ilogical and impossible task" as it
can be, in the case of
Brython. Saying in other words what Kiko wrote: Brython does not use
opcodes at all -
Python opcodes or otherwise. So, while it would be possible to "port"
a module to deal
with Python opcodes (it is likely Pypy should have a Python version of
it) , it would not be able to
work with Brython code itself. (You could have, however,a brython
program operating on
Python code uploaded to it somehow - but that is less useful than
simply having a plain
Python CLI or GUI program). So,if you can a Brython class never have
a "code object" for its body,
(even if the attribute may be implementeed for compatibility purposes)
- it is instead tranformed
into a Javascript object that have the (transpiled) methods it would have.

I don't know what modern javascript engines use internally - (maybe
the "webasm" thing is
used internally as javascript bytecode) But you would be much more on
track transforming
CPython opcode into this Javascript internal dialect (or explicit
webasm, regardless
of the javascript engine), than lookng at Brython for that.
What Brython have of great is seamless integration with the webbrowser APIs
being able to call javascript methods of documents, and changing the DOM
just as javascript code does - if you get something compiling Python
to Webasm, it would be
interesting having some modules that could provide an interface to do the same.

(Remembering that _there_are_ projects out there that do just that:
build the CPython
in low level javascript - the resulting code can run Python code in an
amulated screen inside
the browser, but it can't as easily interact with the HTML DOM, which
makes Brython more
useful than that (I don't recall the name right now))


>
>
> Em 16 de fev de 2018 5:13 AM, "Kiko" <kikoco...@gmail.com> escreveu:
>>
>>
>>
>> 2018-02-16 4:25 GMT+01:00 Igor Machado <igor.m...@gmail.com>:
>>>
>>> Dear brython developers,
>>> first of all, your project is quite amazing!
>>> I used it some time ago and was impressed by how easy it was to integrate
>>> python in a browser...
>>> My new challenge involving python and js depends on byteplay3 library for
>>> python. It is a very low level library that depends on stuff that is
>>> intended for python 3.5 (I guess).
>>> I spent almost a month dealing with low level details of python 3.5, and
>>> it seems to have changed a lot since 3.3, so I wonder how Brython developers
>>> are intending to move on this direction (supporting 3.5 or byteplay3).
>>
>>
>> I don't think it has much sense to use byteplay with brython. Brython
>> doesn't generate bytecode and doesn't follow the same internals than
>> CPython. Brython is a transpiler of Python to Javascript on the fly.
>> Also, some libs imported by byteplay3 are coded in C in CPython (array,
>> opcode,...) and they are not yet ported to Brython.
>>
>> I hope it helps.
>>
>>>
>>> Thanks a lot and congratulations for the nice work so far!
>>>
>>> Igor M. Coelho
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "brython" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an
>>> email to brython+u...@googlegroups.com.
>>> To post to this group, send email to bry...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/brython/466fb14b-9f94-4644-91d6-cec1544dce6b%40googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "brython" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/brython/oQtJjHyaHdw/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> brython+u...@googlegroups.com.
>> To post to this group, send email to bry...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/brython/CAB-sx604KdRc6Zb%2BzD48-56f_oPaZ%3DMzn7TAVVFkdF4aZdYcpQ%40mail.gmail.com.
>> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "brython" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to brython+u...@googlegroups.com.
> To post to this group, send email to bry...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/brython/CALdJCQWKpJNq2-h5e0ypFqji6qs3UXFm%3DbxScotihuo4G_cj3g%40mail.gmail.com.

Igor Machado

unread,
Feb 19, 2018, 10:30:50 PM2/19/18
to bry...@googlegroups.com
Ok Joao, now you made the point Crystal Clear.
Sadly for me, I think I have tried all the possibilities (and documented my three attempts here: https://github.com/igormcoelho/neo-boa), and Brython was my last bet.

Well, I still believe Brython is an amazing project, mainly in this easy html interaction... Then I just hope I can use that together with another "low level CPython javascript" to have both lowlevel opcodes and easy html integration :)



>>> To post to this group, send email to bry...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/brython/466fb14b-9f94-4644-91d6-cec1544dce6b%40googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "brython" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/brython/oQtJjHyaHdw/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to

>> To post to this group, send email to bry...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/brython/CAB-sx604KdRc6Zb%2BzD48-56f_oPaZ%3DMzn7TAVVFkdF4aZdYcpQ%40mail.gmail.com.
>> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "brython" group.
> To unsubscribe from this group and stop receiving emails from it, send an

> To post to this group, send email to bry...@googlegroups.com.
> To view this discussion on the web visit
>
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "brython" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/brython/oQtJjHyaHdw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to brython+unsubscribe@googlegroups.com.

To post to this group, send email to bry...@googlegroups.com.

Glenn Linderman

unread,
Feb 19, 2018, 10:52:42 PM2/19/18
to bry...@googlegroups.com
On 2/19/2018 7:30 PM, Igor Machado wrote:
Ok Joao, now you made the point Crystal Clear.
Sadly for me, I think I have tried all the possibilities (and documented my three attempts here: https://github.com/igormcoelho/neo-boa), and Brython was my last bet.

Well, I still believe Brython is an amazing project, mainly in this easy html interaction... Then I just hope I can use that together with another "low level CPython javascript" to have both lowlevel opcodes and easy html integration :)

So I looked at your page, and I can't say I understand exactly what you are trying to do; I'm only generally familiar with what blockchain is, and know nothing about neo.

But it seems that you are trying to implement a virtual machine based on the Python virtual machine, borrowing its opcodes, etc., as well as borrowing its syntax (or a subset).  I'm not sure why you are trying to reuse the Python opcodes, to do something else (presuming that neo needs different opcodes). It is inefficient to have one virtual machine interpreted by another virtual machine, so you need to compile to the lowest-level virtual machine you find.  This is (presumably) why the Brython developers did not implement the Python virtual machine in Javascript (which is implemented by its own virtual machine), but rather transpiled Python to Javascript, and let Javascript transpile to its virtual machine, and then things run at the speed of the Javascript virtual machine, instead of at the speed of one virtual machine emulating another.

You seem to want it to run in a browser (client side).

It would seem to me that perhaps a more effective approach than those you have tried, would be to implement the neo virtual machine using webasm... that is what webasm is for, is to implement virtual machines. So you define the various operations needed for neo in terms of op codes or functions written using webasm operations.

Then, to achieve a high-level compiler, you write your subset of Python-for-neo to translate that subset of Python into sequences of those webasm operations. I'm told that crossing the javascript (or Brython) boundary to webasm can be expensive, so you probably want to compile the things that require speed directly to webasm, and things for user interface can be left in Python/Brython.

It might be that it would make sense, at some point, for Brython to transpile performance critical large sections of code to webasm, as it seems to be faster than the javascript virtual machine.

Good luck in your project.

Jonathan Verner

unread,
Feb 20, 2018, 2:28:00 AM2/20/18
to brython
Have you looked at Batavia? They are implementing a virtual machine for executing python bytecode in javascript...

Cheers,

Jonathan

>>> To post to this group, send email to bry...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/brython/466fb14b-9f94-4644-91d6-cec1544dce6b%40googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "brython" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/brython/oQtJjHyaHdw/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to

>> To post to this group, send email to bry...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/brython/CAB-sx604KdRc6Zb%2BzD48-56f_oPaZ%3DMzn7TAVVFkdF4aZdYcpQ%40mail.gmail.com.
>> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "brython" group.
> To unsubscribe from this group and stop receiving emails from it, send an

> To post to this group, send email to bry...@googlegroups.com.
> To view this discussion on the web visit
>
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "brython" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/brython/oQtJjHyaHdw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to brython+u...@googlegroups.com.

To post to this group, send email to bry...@googlegroups.com.

Igor Machado

unread,
Feb 22, 2018, 2:04:33 PM2/22/18
to bry...@googlegroups.com
Thanks Jonathan, I'll take a look at this project.

Dear Glenn, sorry about my impreciseness, it's because I'm not the actual developer of neo-boa (the subset of python). The concept of blockchain is not necessary here, in fact, I'm only dealing with the smart contract programming aspect of neo.
The idea is quite simple... NEO team defined a very small set of opcodes for their virtual machine (called AVM), it's very simple stack based implementation, mainly jumps, simple integer arithmetic, no floating  point, and some invokes (external function calls). When you have an avm (you can code directly in opcodes without python, for instance) you can run that in NEO smart contract interpreter, that works.
Some time ago, some guys used C# MSIL reflection to self transform a simple (very limited) C# code in a avm. That os better than writing avm manually.
After that another team created neo-boa, with the same idea, you write a simple python code (very limited), it invokes the python load module capability and byteplay3 returns the opcodes associated to each python operation. Later, they convert these python opcodes in neo opcodes.
What is needed now is to put this neo-boa online in a browser, running in client side (I already have this working using backend computations in neocompiler.io, but scalability is terrible). I tried in many ways, tried to convert it using emscripten, tried to convert  pypy3 using emscripten, but I only manage to do these things with python2, python3 always breaks. What amazed me in Brython is that it worked online with python3, but then I discovered that python3.5 what needed for byteplay3 and the friendly "opcodes" import :-)

It is possible to build a js-to-neo compiler, and there is a team working on this, but not making many progress. Python has the advantage of having lots of programs already written for neo, what js does not have. That is why I  thought it would be easier to get some python3 in js directly to achieve that (python3 to python opcode, to js).

OK, thanks anyway, I'll keep trying :-)

Regards, 
Igor 

--
You received this message because you are subscribed to a topic in the Google Groups "brython" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/brython/oQtJjHyaHdw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to brython+unsubscribe@googlegroups.com.
To post to this group, send email to bry...@googlegroups.com.

Igor Machado

unread,
Oct 4, 2019, 6:06:16 AM10/4/19
to bry...@googlegroups.com
Hello all,
I just noticed brython has python 3.7 version, and "import opcode" and "import array" doesnt break immediately now... any hopes that proposal on byteplay will work now (or still impossible xD).
Just for curiosity on brython advances :)

Regards
Igor

To unsubscribe from this group and all its topics, send an email to brython+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages