Blockly create C++ code? Does BlockyDuino? If so could normal Blockly do so?

2,430 views
Skip to first unread message

Jack Woolford

unread,
Sep 29, 2014, 1:21:16 PM9/29/14
to blo...@googlegroups.com
Hello,

I just noticed Neil Fraser was actually answering questions in this forum which is great! I tried to send him an email but he hasn't replied so hopefully he see's this.

So basically my question is seeing as BlockDuino produces Arduino code does that mean it produces C or C++ code? As Arduino is programmed in C or C++, right? If not, well, would that be possible with Blockly? How does one get started in making Blockly create syntactically correct C++ code?

Sorry I have so many questions and a lack of answers at the moment. The only reason I care about C++ code is due to speed reasons really, so if there is a better option well I'm all ears. Mainly due to the fact people seem to still convert there Python code to C++ code for performance. For example I'm interested in machine learning and everyone seems to prefer to convert it to C++ code from what I've seen, if only running on the CPU that is. Quite often they use CUDA as well... 

The other question I had was could Blockly be used to create Java code, mainly because I need to learn it for uni (currently on a deferment due to life issues) so having Blockly generate code from my block code would be awesome. As I've been using App Inventor 2 to make an Android app at the moment and find it so easy to use, and easier to understand. Than say learning a programming language, it just seems to take far more time learning a new language than diving in with for example App Inventor. Plus I can then learn Java by browsing the code it produces from my Blockly blocks. Although I wouldn't really see any point in programming in text ever again really if I could do everything from within Blockly, if everything was eventually built in. And with App Inventor 2 I thought I had managed to turn the .apk files back into .java files by decompiling them but the decompilation process hasn't been perfected and thus produces a lot of errors. Sure I can get .smali code from the java class files and edit and recompile those but smali code isn't great to work with...

Anyway you guys have done an amazing job with Blockly and before that App Inventor as that was a Google project too right? Blockly is a Google project right? As I can't seem to work out if it is or isn't...

Thanks.

Jack Woolford

unread,
Sep 29, 2014, 1:25:38 PM9/29/14
to blo...@googlegroups.com
Hmm I forgot something, there is another project called Waterbear which is generating JavaScript code but seems to have far more block modules already made. Is there any plans to add more block modules? And if so would you be interested in using Waterbear's code that has already implemented some of these extra features already? As Waterbear is open source I believe so... Although I guess if you are trying to create perfect JavaScript Waterbear's implementation might not be, I'm not sure to be honest.

Odd I'm sure I used to have the option to edit my posts in Google Group Forums but now don't seem to, not sure what happened.

Mark Friedman

unread,
Sep 29, 2014, 5:58:38 PM9/29/14
to blo...@googlegroups.com
On Mon, Sep 29, 2014 at 10:21 AM, Jack Woolford <woolfo...@gmail.com> wrote:
Hello,

I just noticed Neil Fraser was actually answering questions in this forum which is great! I tried to send him an email but he hasn't replied so hopefully he see's this.

So basically my question is seeing as BlockDuino produces Arduino code does that mean it produces C or C++ code?

Looking at https://github.com/admitrievsky/blockduino/tree/master/blockly/generators/c, it appears that BlockDuino does generate some C code.
 
As Arduino is programmed in C or C++, right? If not, well, would that be possible with Blockly? How does one get started in making Blockly create syntactically correct C++ code?

If you wanted to add the ability to generate C/C++ or Java using Blockly, a good place to start would be https://code.google.com/p/blockly/wiki/CustomBlocks

If you wanted to see if other people have already done such work I would start by doing a search for "C++" or "Java" in the Blockly Google Group.  There do appear to be some folks who have tried or are trying to do such things.

-Mark


Sorry I have so many questions and a lack of answers at the moment. The only reason I care about C++ code is due to speed reasons really, so if there is a better option well I'm all ears. Mainly due to the fact people seem to still convert there Python code to C++ code for performance. For example I'm interested in machine learning and everyone seems to prefer to convert it to C++ code from what I've seen, if only running on the CPU that is. Quite often they use CUDA as well... 

The other question I had was could Blockly be used to create Java code, mainly because I need to learn it for uni (currently on a deferment due to life issues) so having Blockly generate code from my block code would be awesome. As I've been using App Inventor 2 to make an Android app at the moment and find it so easy to use, and easier to understand. Than say learning a programming language, it just seems to take far more time learning a new language than diving in with for example App Inventor. Plus I can then learn Java by browsing the code it produces from my Blockly blocks. Although I wouldn't really see any point in programming in text ever again really if I could do everything from within Blockly, if everything was eventually built in. And with App Inventor 2 I thought I had managed to turn the .apk files back into .java files by decompiling them but the decompilation process hasn't been perfected and thus produces a lot of errors. Sure I can get .smali code from the java class files and edit and recompile those but smali code isn't great to work with...

Anyway you guys have done an amazing job with Blockly and before that App Inventor as that was a Google project too right? Blockly is a Google project right? As I can't seem to work out if it is or isn't...

Thanks.

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Blake

unread,
Sep 29, 2014, 10:39:10 PM9/29/14
to blo...@googlegroups.com
Jack,

Another place to start (for java anyway) is my fork of the Blockly project on github[1] its kind of specific to java for FRC robots but some of the basics are there.

Its definitley not turing complete, but give it a go: http://easyj.team5122.com/

If you are interested in the path I took to impliment java, you can checkout the commit log. It starts here


Hope that helps
Blake

Jack Woolford

unread,
Sep 30, 2014, 2:06:26 AM9/30/14
to blo...@googlegroups.com
Howdy Mark and Blake!

So I had already discovered your project Blake and was quite intrigued, although have run into an issue it is reporting "Error: Closure not found.  Read this: http://code.google.com/p/blockly/wiki/Closure" So of course I read that page. Now what I ended up doingmaynot have been correct... See I have also found https://github.com/zrdev/zrdev.github.io which generates C++ code, so I copy pasted the closure-library-read-only to my EasyJ4FRC folder and tried running the build.py again. That just reported back the same error.

I was also wondering if I just add the generator folder from https://github.com/zrdev/zrdev.github.io and from EasyJ4FRC to my Blockly fork folder and re-build it will that suddenly have the necessary files to produce C++ or Java code as well as the default JavaScript/Python/Dart? If not I assume I have to edit quite a lot of files to get that to work right?

Anyway thank you all for the help so far. Sorry if this is a pain as I'm not the most experienced programmer so I will probably need a fair bit of help getting my ideas to work.

Thanks again,

Jack.

Jack Woolford

unread,
Sep 30, 2014, 2:41:53 AM9/30/14
to blo...@googlegroups.com
So I just tried building the https://github.com/zrdev/zrdev.github.io  source code and it seemed to work but when I try and open the index page that doesn't work... It just forever loads. Although it did just seem to load a bit of the page and it seems to be trying to load the ZeroRobotics webpage from here: http://zerorobotics.mit.edu/ which isn't exactly what I want it to do I just want to load the Blockly development environment... 

Also I discovered a project called Minibloq just now that seems to have a lot of features, whether it would be useful for my purposes is yet to be seen. Seeing as it isn't implemented in the Blockly format would probably take more effort to convert it to working with Blockly although it uses it's own block format. It is also mainly based around the idea of programming Arduino boards... So yeah zrdev might still be the best option available for C++ code.

Thanks,

Jack.

Jack Woolford

unread,
Sep 30, 2014, 8:41:49 AM9/30/14
to blo...@googlegroups.com
Sorry for the flood of posts but...I've come up with another idea that you guys might be interested in. So first off have you heard of Light Table the IDE? It can do live code evaluation which is great when making graphical programs: http://www.lighttable.com/ . Now I have a couple options first I could stick with JavaScript as Light Table already support JavaScript and so does Blockly although I'm not sure full JavaScript is implemented in Blockly though, or is it? Or I could work implement C++ in Blockly using the source code from: https://github.com/zrdev/zrdev.github.io to give me a head start and then implement C++ in Light Table (which I'm not sure is possible but think it might be mainly the live code evaluation that is using say CLING: http://root.cern.ch/drupal/content/cling a repl for C++). So then I would want to combine Light Table with Blockly somehow so one screen you switch to you can code in Blockly, it produces JavaScript, and you can run it inside Light Table all in the one application or so is the idea. Basically creating something I think could be amazing and revolutionary even (probably an exaggeration) as I think learning to program would become immensely easier and more interactive this way.

Now not saying any of this would be easy just an idea I had and would love to implement if possible. Although I think there might be a slight problem if you edit the JavaScript or C++ code while using Blockly as it wouldn't translate back into Blockly blocks would it?

Blake

unread,
Sep 30, 2014, 2:41:08 PM9/30/14
to blo...@googlegroups.com
Hey Jack,

Sorry you had trouble building EasyJ4FRC. I've included some instructions below, let me know if those help.
  1. Create a directory to work in I'll call mine `working`
  2. Download a copy of Easyj4FRC and unzip it into a folder in working, I'll call mine `EasyJ4FRC`
  3. Download a copy of the Closure library and unzip it into a folder in working, it must be called `closure-library-read-only`
  4. Go into the EasyJ4FRC folder and try running the build script now.
I messed around with the zero robotics code just enough to get it to work locally on my system. They use AngularJS as a front end framework which adds complexity for those unfamiliar with it.

The java generator in EasyJ4FRC isn't feature complete at the moment. But you should be able to take it and integrate it into Blockly.

Have you mentioned what you are trying to accomplish?

Hope this helps
Blake

On Tue, Sep 30, 2014 at 8:41 AM, Jack Woolford <woolfo...@gmail.com> wrote:
Sorry for the flood of posts but...I've come up with another idea that you guys might be interested in. So first off have you heard of Light Table the IDE? It can do live code evaluation which is great when making graphical programs: http://www.lighttable.com/ . Now I have a couple options first I could stick with JavaScript as Light Table already support JavaScript and so does Blockly although I'm not sure full JavaScript is implemented in Blockly though, or is it? Or I could work implement C++ in Blockly using the source code from: https://github.com/zrdev/zrdev.github.io to give me a head start and then implement C++ in Light Table (which I'm not sure is possible but think it might be mainly the live code evaluation that is using say CLING: http://root.cern.ch/drupal/content/cling a repl for C++). So then I would want to combine Light Table with Blockly somehow so one screen you switch to you can code in Blockly, it produces JavaScript, and you can run it inside Light Table all in the one application or so is the idea. Basically creating something I think could be amazing and revolutionary even (probably an exaggeration) as I think learning to program would become immensely easier and more interactive this way.

Now not saying any of this would be easy just an idea I had and would love to implement if possible. Although I think there might be a slight problem if you edit the JavaScript or C++ code while using Blockly as it wouldn't translate back into Blockly blocks would it?

--

Jack Woolford

unread,
Oct 1, 2014, 5:08:31 AM10/1/14
to blo...@googlegroups.com
Hi again,

So it turns out something has changed with the Blockly/Easyj4FRC build script and what is in the zrdev build script. And I think it may all relate to the fact I'm doing things on Windows and on a folder on my desktop not directly in C:/ .  So zrdev builds but doesn't entirely work because of my not having AngularJS but the Blockly/Easyj4FRC build script doesn't work at all due to the build script being slightly different. Have a look for youself: https://www.diffchecker.com/lvavaon0 that is a diff of the zrdev build.py and Blockly build.py.

Now just to work out what needs to be changed, shouldn't be too difficult.

Now Blake on to the other question of what I want to accomplish. Basically I would like to combine Light Table and Blockly so you have live code evaluation of Blockly code which also produces syntactically correct code from Blockly code as well. I've done a lot of searches for different builds of Blockly recently and found some interesting projects such as Easyj4FRC but also https://github.com/kumavis/node-blockly-js-editor which can turn some Javascript back into Blockly code, needs a bit of work to be finished though. I also found: https://github.com/bollwyvl/blockd3 which has some nice UI options for Blockly that could be incorporated. As well as an alternative to using Light Table for live code evaluation here: https://github.com/Khan/live-editor .

Anyway I think I just thought of a way to add the generators from zrdev and Easyj4FRC to the base Blockly code, so off to try that out and modify the build.py for Blocklyso that works.

I'm guessing this will be a big project so any help is appreciated with updating anything say Easyj4FRC to work with more Java code etc. As I found there is a REPL for Java as well so incorporating that into Light Table would allow live code evaluation of Java code too.

Oh before I forget, I asked Chris Granger on Twitter about using CLING a REPL for C++ in Light Table and he said it was possible for live code evaluation with CLING so another project if I want to create Blockly with Light Table that makes C++ code... So much work!

Thanks,

Jack.

Jack Woolford

unread,
Oct 1, 2014, 6:35:06 AM10/1/14
to blo...@googlegroups.com
Okay so I got build.py to work in my Blockly source code. Oh and it is attached basically two lines needed to be changed to not use this command: os.path.pardir whenever closure-library-read-only is searched for as it is in the same folder.

Now I have another question though I added both Easyj4FRC java generator and zrdev's C++ generator to the def run(self) function problem being there seems to be to it than that to get it to appear in the index page under code as a tab that will generate java or C++ code... So any help with that would also be appreciated, I've downloaded WinMerge to look at what files are different but for whatever reason it keeps telling me different JavaScript files are different and then I open them and they are the same.

Thanks again,

Jack.
build.py

Jack Woolford

unread,
Oct 2, 2014, 5:46:06 AM10/2/14
to blo...@googlegroups.com
I am incredibly confused, doesn't help I don't know HTML/CSS/JavaScript... So I've tried a couple things myself to get the other generators to work in the base Blockly build in the Apps/Code/ index.html file when opened. I've tried editing code.js and template.soy which so far doesn't seem to be working, not even just adding the tabs for the other languages has worked. I've tried working out what this is referring to edit: https://code.google.com/p/blockly/wiki/LanguageGenerators and editing some files to include the java_compressed.js and zr_cpp_compressed.js . Keep in mind I have actually successfully generated both those compressed files.

I hear new documentation is in the works and will be here by the end of the week, which hopefully might be useful for this situation. So maybe this issue might also be helpful to Neil for adding new documentation as well with modifying Blockly. Although I guess I'm in over my head with this and it would be recommended I learn HTML/CSS/JavaScript I assume anyway.

Also stupid me didn't realise there is already a JavaScript live evaluator in Blockly but it just isn't on the Code page.

Oh before I forget I also discovered:   https://github.com/bollwyvl/blockd3 and was wondering what has been added specifically that add the extra UI options? 

Anyway thank you all for your help, and again sorry if this is annoying considering I hadn't checked all of the features/documentation yet myself.

Jack Woolford

unread,
Oct 4, 2014, 12:52:03 PM10/4/14
to blo...@googlegroups.com
So I decided to try and work this out again tonight and still can't make sense of it... I tried https://code.google.com/p/blockly/wiki/LanguageGenerators but I'm not sure where to add this:   var code = Blockly.JavaScript.workspaceToCode(); to get Java or C++ output from my java_compressed.js and cpp_compressed.js files. Or where to add this:  <script type="text/javascript" src="blockly/javascript_compressed.js"></script> .

Plus I also did some searches through the forum to see if other people have asked what to add and to what file so there generators would load. I found this: https://groups.google.com/forum/#!searchin/blockly/generators/blockly/ReRGa539iU4/g_qLTLiqk_IJ and a couple others but there wasn't enough detail to allow me to work out what I'm meant to be doing.

Hopefully that documentation is on it's way! Would really appreciate it.

Blake

unread,
Oct 4, 2014, 12:59:25 PM10/4/14
to blo...@googlegroups.com
Jack,

Did you see the demo at the bottom of the Language Generators Wiki Page? 

It is a simple working example, hopefully will give you an idea of the basic structure.

--

Jack Woolford

unread,
Oct 4, 2014, 1:19:03 PM10/4/14
to blo...@googlegroups.com
Wow I feel really stupid now haha. I think I get it, although the https://blockly-demo.appspot.com/static/apps/code/index.html is sort of what I wanted to add tabs to along with generating in real time java or C++ but now I think I have enough information to work it out, hopefully.

THANKS!

Jack Woolford

unread,
Oct 5, 2014, 6:19:10 AM10/5/14
to blo...@googlegroups.com
Okay so now I have the demos/generators html page generating JavaScript (and runnable), Python (not runnable), Dart (not runnable), and Java (not runnable).The only one I can't get to produce code appears to be zr_cpp_compressed.js itmaybe because the equivalent code from Blockly to C++ isn't there or it could be because I'm not importing it correctly. Was able to add buttons for each of them which is nice. Now also need to look into adding other blocks for the languages that support them, probably only JavaScript/Python/Dart for now as I don't think your Java implementation Blake supports all the current blocks in Blockly does it?

Also setting up Cling on Windows (what a nightmare that is) which is a C++ REPL to test out. 

Now hopefully assuming correctly it would be possible to use IDLE for Python as a REPL also? Or is that just an interpreter? Not sure about Dart so not going to ask about that one. There is a REPL for Java I believe I could download, might be worth getting that up and running too. 

Regarding the current JavaScript REPL is that in written in JavaScript and then compressed? So if I wanted to add IDLE I would have to translate it to JavaScript? If so damn, if not good how could I import IDLE for example?

Also thinking I should just learn JavaScript at this point as everything is already setup for JavaScript...And then it will allow me to add more to Blockly and App Inventor 2 later. Thought?

Thanks again guys for all the help.
Reply all
Reply to author
Forward
0 new messages