tag:blogger.com,1999:blog-43015450622117144012024-03-13T11:10:21.683-07:00Rusthonsimplifying Javascript, C++, Go and Rust with a Python inspired language.raptorhttp://www.blogger.com/profile/14287416587600419675noreply@blogger.comBlogger37125tag:blogger.com,1999:blog-4301545062211714401.post-82368878135747822032015-10-02T22:45:00.000-07:002015-10-02T22:45:32.638-07:00Richards Benchmark<div dir="ltr" style="text-align: left;" trbidi="on">
<br /></div>
<h3>baseline</h3>
<p>
javascript backend: 0.012 seconds
</p>
<a href="http://1.bp.blogspot.com/-eW1UhrIDiws/Vg9khWqT5hI/AAAAAAAACTY/PUfkQGVZ0bA/s1600/richards-without-v8-natives.py.png" imageanchor="1" ><img border="0" src="http://1.bp.blogspot.com/-eW1UhrIDiws/Vg9khWqT5hI/AAAAAAAACTY/PUfkQGVZ0bA/s400/richards-without-v8-natives.py.png" /></a>
<h3>with manual pre-jitting</h3>
<p>
javascript backend + JIT Natives: 0.0106 seconds
</p>
<a href="http://3.bp.blogspot.com/-Q5Dlbp-dbDo/Vg9khvNXKVI/AAAAAAAACTc/cHQUQW3dka4/s1600/richards.py.png" imageanchor="1" ><img border="0" src="http://3.bp.blogspot.com/-Q5Dlbp-dbDo/Vg9khvNXKVI/AAAAAAAACTc/cHQUQW3dka4/s400/richards.py.png" /></a>
<p>
The Chrome V8 JIT is already optimized for the Richards benchmark, so its harder to make it run any faster. Using a V8 native JIT call to force a method to be optimized before the benchmark timer, it is possible to get a tiny 1/50th of a second more speed. It would be interesting if V8 exposed other native calls that could improve performance. This is enabled with the command line option `--v8-natives`, and the syntax `v8->(F(args))` where `F(args)` is a function or method called with dummy arguments that will warm up the function so V8 can infer its static types.
</p>
<h4><a href="https://github.com/rusthon/Rusthon/blob/master/regtests/bench/richards.py">richards.py</a></h4>
<h4><a href="https://github.com/rusthon/Rusthon/releases/download/0.9.9q/rusthon_0.9.4_all.deb">rusthon_0.9.4_all.deb</a></h4>
raptorhttp://www.blogger.com/profile/14287416587600419675noreply@blogger.com0tag:blogger.com,1999:blog-4301545062211714401.post-42780297096202616122015-09-23T23:53:00.000-07:002015-09-24T02:32:01.184-07:00Benchmarks updated<div dir="ltr" style="text-align: left;" trbidi="on">
<br /></div>
<h4>add.py</h4>
<a href="http://1.bp.blogspot.com/-gz4J5jfJrqw/VgObkPglrOI/AAAAAAAACLY/kLoZN4mfdNI/s1600/add.py.png" imageanchor="1" ><img border="0" src="http://1.bp.blogspot.com/-gz4J5jfJrqw/VgObkPglrOI/AAAAAAAACLY/kLoZN4mfdNI/s320/add.py.png" /></a>
<h4>fannkuch.py</h4>
<a href="http://4.bp.blogspot.com/-MP58dXMznow/VgObjzSUikI/AAAAAAAACLU/U1_6CK_Lq70/s1600/fannkuch.py.png" imageanchor="1" ><img border="0" src="http://4.bp.blogspot.com/-MP58dXMznow/VgObjzSUikI/AAAAAAAACLU/U1_6CK_Lq70/s320/fannkuch.py.png" /></a>
<h5>fannkuch old version vs fast setslice</h5>
<a href="http://1.bp.blogspot.com/-T-8iyLm7Rfs/VgPAVTW9fOI/AAAAAAAACMM/W0gZVYHO8-4/s1600/after-optimized.png" imageanchor="1" ><img border="0" src="http://1.bp.blogspot.com/-T-8iyLm7Rfs/VgPAVTW9fOI/AAAAAAAACMM/W0gZVYHO8-4/s400/after-optimized.png" /></a>
<br/>
<h6>old profile</h6>
<ul>
<li>__jsdict_pop replaced by direct call to __array_insert</li>
<li>__array_getslice replaced by __array_getslice_lowerstep: 200ms faster</li>
<li>__array_setslice 90ms faster</li>
</ul>
<a href="http://2.bp.blogspot.com/-gTVLX0gIVa8/VgPAVc0zWyI/AAAAAAAACMQ/MmYrt9wW0BY/s1600/before-setsliceopt.png" imageanchor="1" ><img border="0" src="http://2.bp.blogspot.com/-gTVLX0gIVa8/VgPAVc0zWyI/AAAAAAAACMQ/MmYrt9wW0BY/s400/before-setsliceopt.png" /></a>
<h4>float.py</h4>
<a href="http://1.bp.blogspot.com/-I7eae0a4JeU/VgObjtscr-I/AAAAAAAACLc/W4YHPJPyJEg/s1600/float.py.png" imageanchor="1" ><img border="0" src="http://1.bp.blogspot.com/-I7eae0a4JeU/VgObjtscr-I/AAAAAAAACLc/W4YHPJPyJEg/s320/float.py.png" /></a>
<h4>nbody.py</h4>
<a href="http://2.bp.blogspot.com/-CflevBLkE-w/VgObk-_UsII/AAAAAAAACL0/LTk_5h46Zrg/s1600/nbody.py.png" imageanchor="1" ><img border="0" src="http://2.bp.blogspot.com/-CflevBLkE-w/VgObk-_UsII/AAAAAAAACL0/LTk_5h46Zrg/s320/nbody.py.png" /></a>
<h4>operator_overloading_functor.py</h4>
<a href="http://1.bp.blogspot.com/-3IRDWTMp2_8/VgObk3cvq4I/AAAAAAAACLg/LjUTdqqFksI/s1600/operator_overloading_functor.py.png" imageanchor="1" ><img border="0" src="http://1.bp.blogspot.com/-3IRDWTMp2_8/VgObk3cvq4I/AAAAAAAACLg/LjUTdqqFksI/s320/operator_overloading_functor.py.png" /></a>
<h4>pystone.py</h4>
<a href="http://2.bp.blogspot.com/-IFDXyloMV1E/VgOblHepanI/AAAAAAAACLk/cidU7gQFrQ0/s1600/pystone.py.png" imageanchor="1" ><img border="0" src="http://2.bp.blogspot.com/-IFDXyloMV1E/VgOblHepanI/AAAAAAAACLk/cidU7gQFrQ0/s320/pystone.py.png" /></a>
<h3><a href="https://github.com/rusthon/Rusthon/releases/download/0.9.9P/rusthon_0.9.3_all.deb">rusthon_0.9.3_all.deb</a></h3>raptorhttp://www.blogger.com/profile/14287416587600419675noreply@blogger.com0tag:blogger.com,1999:blog-4301545062211714401.post-87368034249637456142015-09-22T00:31:00.002-07:002015-09-22T00:31:49.080-07:00Pystone Benchmark<div dir="ltr" style="text-align: left;" trbidi="on">
<br /></div>
<a href="http://1.bp.blogspot.com/-mBL_WdKgEn8/VgED0Hj_PpI/AAAAAAAACKo/X3MmXLRVEWU/s1600/pystone.py.png" imageanchor="1" ><img border="0" src="http://1.bp.blogspot.com/-mBL_WdKgEn8/VgED0Hj_PpI/AAAAAAAACKo/X3MmXLRVEWU/s320/pystone.py.png" /></a>raptorhttp://www.blogger.com/profile/14287416587600419675noreply@blogger.com0tag:blogger.com,1999:blog-4301545062211714401.post-74472352642709334012015-09-21T15:46:00.002-07:002015-09-21T15:46:31.079-07:00Operator Overloading Benchmark<div dir="ltr" style="text-align: left;" trbidi="on">
<br /></div>
<p>
JavaScript has no support for operator overloading, and this is generally a good thing; because in languages that do support it, programmers often abuse it and create code that is harder to read. The only real exception is with math libraries, where having operator overloading for vectors, matrices, and complex number classes can be very helpful, and make code more readable.
</p>
<p>
Emulation of operator overloading in JavaScript has a very high performance overhead, so much so that it is simply unusable if used traditionally with no extra syntax. Both Rusthon and <a href="http://www.rapydscript.com/">RapydScript</a>, after careful consideration, have adopted many of the same optimization patterns: and first is no direct support for operator overloading.
</p>
<p>
Brython, on the other hand, has attempted to fully support all of the dynamic features of Python, including operator overloading.
As you will see in this benchmark, the price is very fucking high, Brython is 50 times slower than regular CPython3, and 295 times slower than Rusthon.
</p>
<h4><a href="https://github.com/rusthon/Rusthon/blob/master/regtests/bench/operator_overloading.py">operator_overloading.py</a></h4>
<a href="http://3.bp.blogspot.com/-DuTtyDg2R-Y/VgCEtgA8DAI/AAAAAAAACJU/m0ZYOB0C-xc/s1600/operator_overloading.py.png" imageanchor="1" ><img border="0" src="http://3.bp.blogspot.com/-DuTtyDg2R-Y/VgCEtgA8DAI/AAAAAAAACJU/m0ZYOB0C-xc/s320/operator_overloading.py.png" /></a>
<p>
The Brython <a href="http://brython.info/static_doc/en/faq.html">FAQ</a> states that Brython is "somewhere between 3 to 5 times slower", nice try guys, that should be updated to say something like: "Brython is a toy, and can not actually be used for anything".
</p>
<h3>with oo:</h3>
<pre>
def benchmark(n):
a = [ Vector(i*0.09,i*0.05, i*0.01) for i in range(n)]
b = [ Vector(i*0.08,i*0.04, i*0.02) for i in range(n)]
c = []
d = []
for j in range(n):
with oo:
u = a[j]
v = b[j]
c.append( u+v )
d.append( u*v )
return [c,d]
</pre>
<p>
Above is a snippet of code from the benchmark, the special syntax <b>with oo:</b> enables operator overloading for just those statements under it in Rusthon. If you hate this syntax, you can also use <b>with operator_overloading:</b>, or fore go operator overloading and directly use the method names like this:
</p>
<pre>
def benchmark(n):
a = [ Vector(i*0.09,i*0.05, i*0.01) for i in range(n)]
b = [ Vector(i*0.08,i*0.04, i*0.02) for i in range(n)]
c = []
d = []
for j in range(n):
u = a[j]
v = b[j]
c.append( u.__add__(v) )
d.append( u.__mul__(v) )
return [c,d]
</pre>raptorhttp://www.blogger.com/profile/14287416587600419675noreply@blogger.com0tag:blogger.com,1999:blog-4301545062211714401.post-53109057907285939982015-09-21T13:12:00.000-07:002015-09-21T13:12:50.853-07:00Functor Benchmark<div dir="ltr" style="text-align: left;" trbidi="on">
<br /></div>
<h4><a href="https://github.com/rusthon/Rusthon/blob/master/regtests/bench/operator_overloading_functor.py">operator_overloading_functor.py</a></h4>
<a href="http://4.bp.blogspot.com/-ble5YKR5jf0/VgBR1x3AZvI/AAAAAAAACIU/50zoKUgh6VE/s1600/operator_overloading_functor_old.py.png" imageanchor="1" ><img border="0" src="http://4.bp.blogspot.com/-ble5YKR5jf0/VgBR1x3AZvI/AAAAAAAACIU/50zoKUgh6VE/s320/operator_overloading_functor_old.py.png" /></a>
<p>
Above is the result of my first implementation of <b>__call__</b> in the Rusthon JavaScript backend. Why is it so much slower than regular CPython? The Chrome V8 JIT is very sensitive to dynamic behavior, and it will not be able to optimize a function if it is too dynamic. What is happening in this implementation is the method <b>__call__</b> becomes a nested function in the class constructor, which dynamically rebinds its calling context to <b>this</b>, copies all attributes and methods from <b>this</b> to <b>__call__</b>, and then returns <b>__call__</b>. See my commit <a href="https://github.com/rusthon/Rusthon/commit/4bfb36006e43819bd00d2ad8280bd74b416a8388">here</a> that enabled this syntax.
</p>
<a href="http://2.bp.blogspot.com/-MrLj4hpCVD0/VgBYQ9oGDAI/AAAAAAAACIk/1M-4YIr2C9s/s1600/operator_overloading_functor.py.png" imageanchor="1" ><img border="0" src="http://2.bp.blogspot.com/-MrLj4hpCVD0/VgBYQ9oGDAI/AAAAAAAACIk/1M-4YIr2C9s/s320/operator_overloading_functor.py.png" /></a>
<p>
Above is the result of my second implementation. The difference is huge, what did i <a href="https://github.com/rusthon/Rusthon/commit/1a991b8e74ad75ac1481b7a06d5885419d15786a">change?</a> Instead of running <b>this.__init__(args)</b> in the constructor, the <b>__init__</b> method (and all other methods) gets attached to the nested function <b>__call__</b> and not rebound, then when calling <b>__call__.__init__(args)</b> the calling context of <b>this</b> is already <b>__call__</b>, and so we can skip coping values from <b>this</b>. This allows the V8 JIT to know that <b>__call__</b> is not so dynamic, and to optimize it however it can. The only performance question now is, what is the overhead of returning a function object, rather than a normal object from the class constructor? Lets compare to another version of the benchmark where <b>__call__</b> gets replaced by a normal method named <b>call</b>
</p>
<h4><a href="https://github.com/rusthon/Rusthon/blob/master/regtests/bench/operator_overloading_nonfunctor.py">operator_overloading_nonfunctor.py</a></h4>
<a href="http://1.bp.blogspot.com/-dAWblOp0pq0/VgBbNMpF-6I/AAAAAAAACIw/QBk6X89TznU/s1600/operator_overloading_nonfunctor.py.png" imageanchor="1" ><img border="0" src="http://1.bp.blogspot.com/-dAWblOp0pq0/VgBbNMpF-6I/AAAAAAAACIw/QBk6X89TznU/s320/operator_overloading_nonfunctor.py.png" /></a>
<p>
Above is the result of the same benchmark but without using the special method <b>__call__</b>, here it is replaced by a normal method <b>call</b>. The class constructor returns a regular object, not a function-object like above. This is less dynamic, and the V8 JIT is able to optimize it even more. In conclusion, there is indeed a price to pay for having callable objects, the cost being about six times slower.
</p>
<h3>What about Brython?</h3>
<p>
As you have seen above, the implementation details of a transpiler can have a huge impact on performance, if not carefully designed, tuned and tested, performance can quickly become many times slower then CPython. Let's take a look at a project that made all the wrong decisions, <a href="http://brython.info">Brython</a>. By wrong decisions, i mean trying to emulate all the dynamic features of CPython in JavaScript.
</p>
<a href="http://4.bp.blogspot.com/-_a3mqq6nGTk/VgBhn4QCSxI/AAAAAAAACJA/QJ8Q0enADs8/s1600/brython_operator_overloading_functor.py.png" imageanchor="1" ><img border="0" src="http://4.bp.blogspot.com/-_a3mqq6nGTk/VgBhn4QCSxI/AAAAAAAACJA/QJ8Q0enADs8/s320/brython_operator_overloading_functor.py.png" /></a>
<p>
Above are the absolutely terrible results of Brython running the same benchmark. In this test, Brython is 80 times slower than CPython, and 88 times slower than Rusthon.
</p>
raptorhttp://www.blogger.com/profile/14287416587600419675noreply@blogger.com0tag:blogger.com,1999:blog-4301545062211714401.post-12475852819309348632015-09-20T14:33:00.000-07:002015-09-20T16:46:45.653-07:00Benchmarks2<div dir="ltr" style="text-align: left;" trbidi="on">
<br /></div>
<p>
What is killing <a href="http://www.rapydscript.com">RapydScript</a> in the Fannkuch benchmark? I am not sure, looking over the output from RapydScript, it looks almost the same as Rusthon, except for the way it performs array slicing, could that be the cause of the slow down? See the transpiled code here: <a href="http://pastebin.com/reKBZSGk">RapydScript output</a> and <a href="http://pastebin.com/sHv8MQcE">Rusthon output</a>
</p>
<a href="http://2.bp.blogspot.com/-Ubz6j7jAG_A/Vf8k6J2vGWI/AAAAAAAACHk/hz13OwM1wRs/s1600/fannkuch.py.png" imageanchor="1" ><img border="0" src="http://2.bp.blogspot.com/-Ubz6j7jAG_A/Vf8k6J2vGWI/AAAAAAAACHk/hz13OwM1wRs/s320/fannkuch.py.png" /></a>
<br/>
<a href="https://github.com/rusthon/Rusthon/blob/master/regtests/bench/fannkuch.py">fannkuch.py</a>
<br/>
<a href="http://1.bp.blogspot.com/-LEgBoy2sdQ4/Vf8lDJ6ijbI/AAAAAAAACHs/R7RwI7HjyQ4/s1600/add.py.png" imageanchor="1" ><img border="0" src="http://1.bp.blogspot.com/-LEgBoy2sdQ4/Vf8lDJ6ijbI/AAAAAAAACHs/R7RwI7HjyQ4/s320/add.py.png" /></a>
<br/>
<a href="https://github.com/rusthon/Rusthon/blob/master/regtests/bench/add.py">add.py</a>
<br/>
<a href="http://1.bp.blogspot.com/-QWXDgq0H5Po/Vf8lDBpJZfI/AAAAAAAACHw/o81zTPER-Gc/s1600/float.py.png" imageanchor="1" ><img border="0" src="http://1.bp.blogspot.com/-QWXDgq0H5Po/Vf8lDBpJZfI/AAAAAAAACHw/o81zTPER-Gc/s320/float.py.png" /></a>
<br/>
<a href="https://github.com/rusthon/Rusthon/blob/master/regtests/bench/float.py">float.py</a>
<br/>
<br/>
<h3>What about Brython?</h3>
<p>
<a href="http://brython.info">Brython</a> is another python to javascript transpiler that claims to be fast, see their <a href="http://brython.info/static_doc/en/faq.html">FAQ</a> here, there they claim it is "somewhere between 3 to 5 times slower"... this is complete bullshit, nice try guys. I wanted to include Brython in these benchmarks, but Brython is so fucking slow, it is not even practical to run benchmarks on it. I ran the fannkuch benchmark using Brython, and waited, and waited, and after a really long time, it finally finished, with an average time of 170seconds. Recall that Python3 completes fannkuch in 0.3seconds. Brython is about 560 times slower than regular CPython3, and 850 times slower than Rusthon.
</p>
<p><i>update:</i> I ran the Fannkuch benchmark again in Brython, this time unchecking the "debug" box, but the results were not much better, Brython still takes 150seconds. That makes it 500 times slower than CPython3.
</p>raptorhttp://www.blogger.com/profile/14287416587600419675noreply@blogger.com0tag:blogger.com,1999:blog-4301545062211714401.post-3337010573594973972015-09-20T00:31:00.000-07:002015-09-20T00:31:00.208-07:00First Benchmarks<div dir="ltr" style="text-align: left;" trbidi="on">
<br /></div>
<a href="http://3.bp.blogspot.com/-1tvZwuMkcnQ/Vf5fRTzp9bI/AAAAAAAACGA/aBpw0Qpn7hs/s1600/add.py.png" imageanchor="1" ><img border="0" src="http://3.bp.blogspot.com/-1tvZwuMkcnQ/Vf5fRTzp9bI/AAAAAAAACGA/aBpw0Qpn7hs/s320/add.py.png" /></a>
<br/>
<a href="https://github.com/rusthon/Rusthon/tree/master/regtests/bench/add.py">add.py</a>
<br/>
<a href="http://4.bp.blogspot.com/-JIkn4nLO4tE/Vf5fRb4WUUI/AAAAAAAACF8/8JlgRg01Pnc/s1600/fannkuch.py.png" imageanchor="1" ><img border="0" src="http://4.bp.blogspot.com/-JIkn4nLO4tE/Vf5fRb4WUUI/AAAAAAAACF8/8JlgRg01Pnc/s320/fannkuch.py.png" /></a>
<br/>
<a href="https://github.com/rusthon/Rusthon/tree/master/regtests/bench/fannkuch.py">fannkuch.py</a>
<br/>
<a href="http://1.bp.blogspot.com/-d5PJOMpk1HY/Vf5fRcFyQEI/AAAAAAAACGE/vvX1-dqe49g/s1600/float.py.png" imageanchor="1" ><img border="0" src="http://1.bp.blogspot.com/-d5PJOMpk1HY/Vf5fRcFyQEI/AAAAAAAACGE/vvX1-dqe49g/s320/float.py.png" /></a>
<br/>
<a href="https://github.com/rusthon/Rusthon/tree/master/regtests/bench/float.py">float.py</a>
<br/>
raptorhttp://www.blogger.com/profile/14287416587600419675noreply@blogger.com0tag:blogger.com,1999:blog-4301545062211714401.post-20240428214624443302015-09-15T16:56:00.000-07:002015-09-15T16:56:03.110-07:00Rusthon 1.0 Release Comming Soon<div dir="ltr" style="text-align: left;" trbidi="on">
<br /></div>
<a href="http://1.bp.blogspot.com/-yvJm4JSXb-U/Vfis73YKw7I/AAAAAAAACBw/y1n-NTqxo0E/s1600/rusthon-alpha.png" imageanchor="1" ><img border="0" src="http://1.bp.blogspot.com/-yvJm4JSXb-U/Vfis73YKw7I/AAAAAAAACBw/y1n-NTqxo0E/s640/rusthon-alpha.png" /></a>
<p>
After almost two years of development, Rusthon is nearing the stable 1.0 release. The project originally began with my fork of <a href="https://github.com/hartsantler/PythonScript">PythonScript</a> by <a href="https://github.com/amirouche">Amirouche</a>, who had written a two-pass transpiler that was easy to understand and modify. PythonScript was then renamed to <a href="https://github.com/PythonJS/PythonJS">PythonJS</a>, and optimized for speed. Early <a href="http://pythonjs.blogspot.com/2014/06/pythonjs-faster-than-cpython-part2.html">benchmarks tests</a> showed that many dynamic pythonic features would have to be thrown away, because of the high performance overhead. The minimal python syntax that evolved over several months, ended up having many of the same <a href="http://blog.pyjeon.com/2014/01/18/what-is-pythonic/">behavior and rules</a> that Alexander Tsepkov's <a href="http://www.rapydscript.com/">RapydScript</a> also had.
</p>
<p>
Rusthon is now fully regression tested, you can see the source and output of the tests that transpile and execute without errors below. The syntax has been almost fully unified for each of the backends, the syntax developed for the Go and C++ backends has made its way back into the JavaScript backend to provide the same kind of <a href="https://github.com/rusthon/Rusthon/wiki/JavaScript-Static-Types">type safety</a> and <a href="https://github.com/rusthon/Rusthon/wiki/JavaScript-DOM-Syntax">new features</a>.
</p>
<h3>JavaScript Regression Test Results</h3>
<ul>
<li><a href="https://github.com/rusthon/Rusthon/blob/master/regtests/regtest-report-js-calling.md">function calls</a></li>
<li><a href="https://github.com/rusthon/Rusthon/blob/master/regtests/regtest-report-js-dict.md">dictionary</a></li>
<li><a href="https://github.com/rusthon/Rusthon/blob/master/regtests/regtest-report-js-lang.md">general syntax tests</a></li>
<li><a href="https://github.com/rusthon/Rusthon/blob/master/regtests/regtest-report-js-list.md">list</a></li>
<li><a href="https://github.com/rusthon/Rusthon/blob/master/regtests/regtest-report-js-loop.md">loop types</a></li>
<li><a href="https://github.com/rusthon/Rusthon/blob/master/regtests/regtest-report-js-set.md">set</a></li>
<li><a href="https://github.com/rusthon/Rusthon/blob/master/regtests/regtest-report-js-str.md">string</a></li>
</ul>
<h3>Native Backend Regression Test Results</h3>
<ul>
<li><a href="https://github.com/rusthon/Rusthon/blob/master/regtests/regtest-report-c%2B%2B.md">c++</a></li>
<li><a href="https://github.com/rusthon/Rusthon/blob/master/regtests/regtest-report-go.md">go</a></li>
<li><a href="https://github.com/rusthon/Rusthon/blob/master/regtests/regtest-report-rust.md">rust</a></li>
</ul>
raptorhttp://www.blogger.com/profile/14287416587600419675noreply@blogger.com1tag:blogger.com,1999:blog-4301545062211714401.post-62138530291517198962015-09-06T18:07:00.000-07:002015-09-06T18:07:48.962-07:00js backend: typed maps<div dir="ltr" style="text-align: left;" trbidi="on">
<br /></div>
<p>
There was alot of hype on <a href="https://github.com/dart-lang/sdk">Dart</a> not long ago, but already it has faded away into the trash bin of so many other failed languages, with over 33,000 commits and less than 400 github stars, nobody gives a fuck, nice try Google+.
</p>
<p>
The Dart developers made some really bad choices early on when implementing hash-maps, like keeping the order of items <a href="https://groups.google.com/a/dartlang.org/forum/#!topic/misc/oCrZFh-E49c">[fuckup #1]</a>, and not optimizing for translation to Javascript <a href="https://github.com/dart-lang/sdk/issues/9255">[fuckup #2]</a>. And things get even worse, we can also give up on the Dart VM as part of Chrome in the future, see <a href="http://www.infoworld.com/article/2902074/javascript/google-dart-will-not-replace-in-browser-javascript.html">here.</a>
</p>
<p>
A major drawback in JavaScript is the lack of typed hash maps, and object keys always being coerced into strings. Objects in JavaScript are unfortunately just associative arrays whose keys are always strings. This can lead to bugs that are hard to trace down. Dart tried to solve this problem with compile time type checking; but this fails in the real world where your code is interfacing with huge amounts of external JavaScript which can not be compile time checked, so you still have to deal with runtime errors.
</p>
<p>
Typed hashmaps in Rusthon are checked at runtime when you transpile your project without the <b>--release</b> command line option. This allows you to debug your code with runtime errors that make sense, and enforce static types even when working with external JavaScript libraries.
</p>
<h3>map[K]V{}</h3>
<p>
Above is the syntax for typed hashmaps in Rusthon, it is directly inspired by the hashmap syntax in Golang.
Where <b>K</b> is the key type, and <b>V</b> is the value type. Note this the same syntax used for the Rust, C++ and Go backends.
See this example: <a href="https://github.com/rusthon/Rusthon/blob/master/examples/javascript_typed_dict.md">javascript_typed_dict.md</a>
</p>
raptorhttp://www.blogger.com/profile/14287416587600419675noreply@blogger.com0tag:blogger.com,1999:blog-4301545062211714401.post-65033123570887911122015-09-06T13:32:00.000-07:002015-09-06T13:32:17.595-07:00FullStack NoSQL on SQL<div dir="ltr" style="text-align: left;" trbidi="on">
<br /></div>
<p>
There are several full-stack frameworks for python like: Django, Web2Py, and CherryPy. This PDF from the Web2Py docs has a pretty good overview of these frameworks, see <a href="http://www.web2py.com/examples/static/web2py_vs_others.pdf">web2py_vs_others.pdf</a>. What you will notice with these frameworks is they each have their own fucked up way of embedding code and logic into HTML templates. These huge frameworks try to hide the details of the object relational mapping and database, but in doing so force you to use their HTML template language.
Andy Shora has some interesting insights on full-stack dev, check out
<a href="http://andyshora.com/full-stack-developers.html">
http://andyshora.com/full-stack-developers.html
</a>
</p>
<p>
Writing a full-stack system in Rusthon is pretty simple, this demo is just 300 lines and includes: backend, database, and frontend.
See source code <a href="https://github.com/rusthon/Rusthon/blob/master/examples/fullstack_nosql_onsql.md">here.</a> The HTML is raw and can be easily integrated with modern solutions like Angular.js. By not having some huge framework in your way, you can directly code the server to send data in the way you want, with whatever ad-hoc protocol you choose. In this demo all data is moved around over a websocket, and both clients are kept in sync with the server and database in realtime.
</p>
<iframe width="560" height="315" src="https://www.youtube.com/embed/oBUUkZopZvc" frameborder="0" allowfullscreen></iframe>
<p>
The Python library <a href="https://github.com/pudo/dataset">Dataset</a> is used to hide all the SQL, and provides a NoSQL like solution in combination with property getter/setters on the client side, you never have to worry about directly writing SQL code.
</p>raptorhttp://www.blogger.com/profile/14287416587600419675noreply@blogger.com0tag:blogger.com,1999:blog-4301545062211714401.post-40323332836069025172015-08-10T14:53:00.000-07:002015-08-10T14:53:14.432-07:00Elm Frontend<div dir="ltr" style="text-align: left;" trbidi="on">
<br /></div>
<p>Today I implemented a front-end for <a href="http://elm-lang.org/">Elm</a>, a language that touts itself as <b>"the best of functional programming in your browser".</b>
Integration is simple, you just include Elm code in its own fenced code block inside your markdown file, see this example <a href="">hello_elm.md</a>.
This works the same way as the other JS transpiler frontends, Rusthon calls the other transpiler in a subprocess, and inserting its output into the final html. Checkout the other frontends in Rusthon for: <a href="https://github.com/rusthon/Rusthon/blob/master/examples/hello_coffee.md">CoffeeScript</a> and <a href="https://github.com/rusthon/Rusthon/blob/master/examples/hello_rapydscript.md">Rapydscript</a>.
</p>
<h3>Elm first impressions</h3>
<a href="http://2.bp.blogspot.com/-AkykKRvg97M/VckYlT0gIbI/AAAAAAAAB8I/W5bLeJpFlys/s1600/elm-sucks.png" imageanchor="1" ><img border="0" src="http://2.bp.blogspot.com/-AkykKRvg97M/VckYlT0gIbI/AAAAAAAAB8I/W5bLeJpFlys/s400/elm-sucks.png" /></a>
<p>
My first try with Elm was a big disappointment. Things look bad starting with the install <a href="http://elm-lang.org/install">page</a>, there it lists packages for "OSX", "Windows" and "Anywhere". First off I dont give a fuck if you have packages for OSX and Windows, support the NPM "Anywhere" package and make it work well. Next problem, the <a href="https://www.npmjs.com/package/elm">NPM package</a>, at the bottom of the page it says, "Also, set the ELM_HOME environment variable to /usr/local/lib/node_modules/elm/share or the corresponding directory created on your machine." What the fuck is your problem Kevin MÃ¥rtensson? Do you really think i am going to play around with my environment variables just try out a transpiler.
</p>
<p>
Next problem, i run <i>elm-make</i> on my test and it asks me if i want to download some extra bullshit, it then drops this bullshit into the current directory i am running the command in! What the fuck, cache that in ~/.elm or something, do not just start junking up my file system.
</p>
<h3>first test code fails</h3>
<pre>
import Text
myfunc a =
Text.plainText a
</pre>
<p>
I was pretty sure that was going to work, i took it pretty much right from chapter1 of the Elm guide <a href="http://elm-by-example.org/Chapter1HelloWorld.html">here.</a> Searching around i found that <b>Text.plainText</b> is deprecated, and this pisses me off. The problem with Elm and some other transpiled languages (like Dart) is they try to define a standard library of modules and functions, often this grows into some huge mess, which then gets refactored and parts deprecated. A language that transpiles to JavaScript does not need to reinvent all these things, there are plenty of JS libraries out there already. So why did Elm go down the wrong path? Probably because it has such shitty JS interop using <a href="http://elm-lang.org/guide/interop#ports">ports</a>, and so needs its own fat standard library because it is such a pain for the user to simply call a JavaScript function.
</p>raptorhttp://www.blogger.com/profile/14287416587600419675noreply@blogger.com0tag:blogger.com,1999:blog-4301545062211714401.post-46310591013299643662015-08-05T16:30:00.000-07:002015-08-05T18:44:28.645-07:00JavaScript backend: Debugger<div dir="ltr" style="text-align: left;" trbidi="on">
<br /></div>
<a href="http://3.bp.blogspot.com/-jqD7zmDiTOs/VcKValSgKnI/AAAAAAAAB5g/NswusZOuq_4/s1600/chrome-sucks1.png" imageanchor="1" ><img border="0" src="http://3.bp.blogspot.com/-jqD7zmDiTOs/VcKValSgKnI/AAAAAAAAB5g/NswusZOuq_4/s400/chrome-sucks1.png" /></a>
<p>
This first reason why people give up when trying to learn JavaScript and HTML, they load up their test page in Google Chrome, and then see this fucking bullshit. It can be a blank white page, or your page half drawn with missing elements...
</p>
<a href="http://2.bp.blogspot.com/-jWYQJcbAD3I/VcKVagP21jI/AAAAAAAAB5c/y9MQX9WBC2w/s1600/chrome-sucks2.png" imageanchor="1" ><img border="0" src="http://2.bp.blogspot.com/-jWYQJcbAD3I/VcKVagP21jI/AAAAAAAAB5c/y9MQX9WBC2w/s400/chrome-sucks2.png" /></a>
<p>
This second reason why people give up on JavaScript and HTML, they have to press <b>Ctrl+Alt+J</b> to open the god forsaken Google Chrome Developer Tools window. They see some error message in red and then have to click to the far right of it to jump to that point in the code.
</p>
<a href="http://1.bp.blogspot.com/-QB9y8MxtkHA/VcKVaoLCSbI/AAAAAAAAB5Y/Wya0tdEveTc/s1600/chrome-sucks3.png" imageanchor="1" ><img border="0" src="http://1.bp.blogspot.com/-QB9y8MxtkHA/VcKVaoLCSbI/AAAAAAAAB5Y/Wya0tdEveTc/s400/chrome-sucks3.png" /></a>
<p>
Then the user sees the interface above and runs outside to puke. The line that caused the error is highlighted in yellow, for a split second, and then fades out so fast your eye can easily miss it. What the fuck?
<p>
</p>
Maybe then they give the FireFox debugger and try and see something even more hideous. Then they decide it is time to give up on JavaScript and HTML forever.
</p>
<hr/>
<h3>A Real JavaScript Debugger</h3>
<ul>
<li>
<a href="https://github.com/rusthon/Rusthon/wiki/JavaScript-Debugger">wiki:JavaScript-Debugger</a>
</li>
<li>
<a href="https://github.com/rusthon/Rusthon/blob/master/examples/javascript_debugger.md">example source code</a>
</li>
</ul>
<a href="http://4.bp.blogspot.com/-2mV3vn-135M/VcKbGBCaIHI/AAAAAAAAB6A/nWEa3bgTjNs/s1600/jsdebugger-ace.png" imageanchor="1" ><img border="0" src="http://4.bp.blogspot.com/-2mV3vn-135M/VcKbGBCaIHI/AAAAAAAAB6A/nWEa3bgTjNs/s640/jsdebugger-ace.png" /></a>
<p>
This is the new debugger that is built into the JavaScript backend of Rusthon. When you transpile your project without using the <b>--release</b> command line option, it will insert runtime code to catch any uncaught errors, it parses the trace-back, and generates an HTML interface, with human readable error messages, and editable code that updates without recompile or reload.
</p>
<iframe width="560" height="315" src="https://www.youtube.com/embed/G6x5r4098Q8" frameborder="0" allowfullscreen></iframe>
<p>
note: if you do not include Ace.js in your HTML, then the debugger falls back to using a regular HTML <b>TextArea</b>, which looks like this.
</p>
<a href="http://2.bp.blogspot.com/-y-FdEFaeyd4/VcKZvPpkSmI/AAAAAAAAB50/013hTsqIkpM/s1600/jsdebugger-textarea.png" imageanchor="1" ><img border="0" src="http://2.bp.blogspot.com/-y-FdEFaeyd4/VcKZvPpkSmI/AAAAAAAAB50/013hTsqIkpM/s400/jsdebugger-textarea.png" /></a>
raptorhttp://www.blogger.com/profile/14287416587600419675noreply@blogger.com0tag:blogger.com,1999:blog-4301545062211714401.post-61763161655144961742015-07-30T17:39:00.000-07:002015-07-30T18:17:02.676-07:00Javascript backend: Static Type Syntax<div dir="ltr" style="text-align: left;" trbidi="on">
<br /></div>
<p>
Every fucking time i see this error message in my chrome js console, <b>Uncaught TypeError: Cannot read property `position` of undefined</b> makes me want to walk into Google's head office and beat every mother fucker down. It is time for Lars Bak and Kasper Lund at Google to give up on <a href="https://en.wikipedia.org/wiki/Dart_%28programming_language%29">Dart</a>, and provide a real debugger for Chrome.
</p>
<p>
Programmers can get into heated debates about syntax and static typing. Sure, it is nice to have a compiler check the types of every variable at compile time, and then throw errors for any typing mistakes you have made, and this works well for native apps written in a statically typed language, but not in the web browser.
</p>
<p>
Dart and TypeScript compile to JavaScript, and try to offer the same safety that static types provide.
However, this is not actually useful because JavaScript is itself not typed, and the type of a variable can change at anytime.
</p>
<p>
The reality is that in any real web application, you are going to be interfacing with many external JavaScript libraries,
and most of your type errors are going to happen at runtime when using those libraries. So you really need a good runtime type checker that will provide useful errors so you can debug your code quickly. JavaScript without runtime type checking, is very hard to debug, because many types of errors are silent, and often this causes later code to break with confusing error messages about something being undefined, forcing you to manually trace the logic back to the original thing that was wrong and caused the whole chain of problems.
</p>
<h3>Runtime Type Checking Syntax</h3>
<p><a href="https://github.com/rusthon/Rusthon/blob/master/examples/threejs_static_types.md">
example source code
</a>
</p>
<pre>
def setup_camera_untyped( c ):
c.position.z = 60
c.position.x = 5
</pre>
<a href="http://2.bp.blogspot.com/-x9m-kJBnvxo/VbrCnsc7llI/AAAAAAAAB34/Go_3HHRd3FM/s1600/rusthon-untyped-error-threejs-camera.png" imageanchor="1" ><img border="0" src="http://2.bp.blogspot.com/-x9m-kJBnvxo/VbrCnsc7llI/AAAAAAAAB34/Go_3HHRd3FM/s1600/rusthon-untyped-error-threejs-camera.png" /></a>
<p>
The function above expects the argument <b>c</b> to be an instance of THREE.PerspectiveCamera.
However, if you make a mistake and call the function and pass <b>undefined</b> or some other type,
it will fail at runtime with this error message which is almost completely useless.
</p>
<h4>typed version</h4>
<pre>
def setup_camera( c:THREE.PerspectiveCamera ):
c.position.z = 60
c.position.x = 5
</pre>
<a href="http://2.bp.blogspot.com/-8sGwFB-Ohoc/VbrDR6i8O2I/AAAAAAAAB4A/0tIqCULnN6c/s1600/rusthon-typed-error-threejs-camera.png" imageanchor="1" ><img border="0" src="http://2.bp.blogspot.com/-8sGwFB-Ohoc/VbrDR6i8O2I/AAAAAAAAB4A/0tIqCULnN6c/s1600/rusthon-typed-error-threejs-camera.png" /></a>
<p>
Above is the same function with <b>c</b> typed as THREE.PerspectiveCamera,
this instructs the transpiler to inject runtime type checking code, that when fails,
throws and error message you can actually use to fix the problem, like what is the function and variable name.
</p>
<p>
For more info see the wiki page, <a href="https://github.com/rusthon/Rusthon/wiki/JavaScript-Static-Types">here.</a>
</p>
</p>
raptorhttp://www.blogger.com/profile/14287416587600419675noreply@blogger.com0tag:blogger.com,1999:blog-4301545062211714401.post-4876160630408749752015-07-27T18:45:00.002-07:002015-07-27T18:45:51.564-07:00Javascript Backend: NodeJS Tornado Web<div dir="ltr" style="text-align: left;" trbidi="on">
<br /></div>
<p>
NodeJS allows you easily move code back and forth from the client to server, and use the same libraries client-side and server-side. Python3 offers nothing new: still GIL locked, no JIT, and no new syntax worth even mentioning. The only thing Python3 is good for is wasting CPU cycles, and <a href="http://rusthon-lang.blogspot.com/2015/01/python-burning.html">increasing the rate of climate change.</a>
</p>
<p>
Its nice to have the option to move your server code to NodeJS without having to manually rewrite it. Rusthon now includes a <i>fake</i> <a href="http://www.tornadoweb.org">Tornado</a> web module, that emulates the basic features of Tornado by wrapping the NodeJS modules: <b>http</b>, <b>url</b>, and <b>ws</b>.
The wrapper source code is in <a href="https://github.com/rusthon/Rusthon/blob/master/src/runtime/nodejs_tornado.py">nodejs_tornado.py</a>. You load this with <b>from nodejs.tornado import *</b>.
</p>
<h3>example</h3>
<a href="https://github.com/rusthon/Rusthon/blob/master/examples/nodejs_tornado.md">example source code</a>
<pre>
#backend:javascript
from runtime import *
from nodejs import *
from nodejs.tornado import *
PORT = 8000
class MainHandler( tornado.web.RequestHandler ):
def get(self, path=None):
print('path', path)
if path == 'favicon.ico' or path.endswith('.map'):
self.write('')
else:
self.write( open('index.html').read() )
Handlers = [
('/', MainHandler),
]
def main():
print('<starting tornado server>')
app = new(tornado.web.Application( Handlers ))
app.listen( PORT )
tornado.ioloop.IOLoop.instance().start()
## start main ##
main()
</pre>raptorhttp://www.blogger.com/profile/14287416587600419675noreply@blogger.com0tag:blogger.com,1999:blog-4301545062211714401.post-14564165804372379382015-07-04T18:58:00.001-07:002015-07-04T19:20:57.081-07:00Javascript Backend: timeout syntax<div dir="ltr" style="text-align: left;" trbidi="on">
<br /></div>
<p>
Performance critical games and web applications often need to maintain consistent and high frame rates.
In this situation it is better to drop some of the logic update rather than dropping render frames.
This way the rendering frame rate can maintain some target like 60fps, while the logic updates at a variable rate.
</p>
<p>
Ian Webster has an article about a technique he calls <a href="http://www.ianww.com/blog/2012/11/04/optimizing-three-dot-js-performance-simulating-tens-of-thousands-of-independent-moving-objects/">Timed Array Processing</a>, which is able to drop logic and maintain consistent a frame rate regardless of the number of objects in the scene. It works by taking the current time, and when looping over the scene objects, it only updates objects while under the time limit. This automatically spreads the logic computation load over multiple frames. This highly useful feature should actually be abstracted to the language syntax level, so it can be used in a clear and consistent way.
</p>
<p>
Rusthon has a smallish code base written in Python, maintained entirely by me, so it only takes me a few days to add a feature like <i>Timed Processing</i>. The new syntax to mark a block of code for timed processing is: <b>with timeout(<i>ms</i>):</b>, where <i>ms</i> is the time to finish in milliseconds. The Rusthon JavaScript transpiler will insert time checking code after each function-calling-expression and inside for/while-loops within that indented block.
Runtime execution of the code block will then suspend if the time limit is reached.
This allows the programmer to write scaleable code, and not scrafice readabity or maintainablity.
</p>
<h3>Rusthon Input</h3>
<pre>
q = []
with timeout( 10 ):
i = 0
while True:
q.append( CalcFib(i) )
i += 1
</pre>
<h3>JavaScript Output</h3>
<pre>
q = [];
var __clk__ = (new Date()).getTime();
while (true) { /* timeout: 10 */
i = 0;
while (true)
{
if ( (new Date()).getTime() - __clk__ >= 10 ) { break; }
q.append(CalcFib(i));
i ++;
}
break;
}
</pre>
<p>
The example above computes the Fibonaci series for up to 10 milliseconds, on my laptop it reaches the 28th place in that time,
<a href="https://github.com/rusthon/Rusthon/blob/master/examples/javascript_timeout_loops.md">example source code</a>.
Timed processing is useful when used together with the <b>sleep</b> builtin and the <b>select</b> statement, see <a href="https://github.com/rusthon/Rusthon/blob/master/examples/javascript_timeout_webworkers.md">this example</a> for more.
</p>raptorhttp://www.blogger.com/profile/14287416587600419675noreply@blogger.com0tag:blogger.com,1999:blog-4301545062211714401.post-40098187410365434502015-06-21T11:35:00.001-07:002015-06-26T08:46:05.386-07:00JavaScript Backend: WebWorkers<a href="http://4.bp.blogspot.com/-HIzj4gejQzo/VY1zTO61uAI/AAAAAAAAB2M/ufLqbauFtII/s1600/jsbackend-webworker.png" imageanchor="1" ><img border="0" src="http://4.bp.blogspot.com/-HIzj4gejQzo/VY1zTO61uAI/AAAAAAAAB2M/ufLqbauFtII/s400/jsbackend-webworker.png" /></a>
<p>
Generation of async callbacks at transpilation time, from simple blocking logic, into <a href="http://stackoverflow.com/questions/25098066/what-is-callback-hell-and-how-and-why-rx-solves-it">callback-hell</a>.
</p>
<h3>Async Transform</h3>
<p>
Using WebWorkers directly requires you define functions for <i>postMessage</i> and <i>onmessage</i>, split your JavaScript into two files, and load libraries in the worker with <i>importScripts</i>. Only low-level-chumps think dealing with these API's directly is a good idea. All these API details are easily abstracted away with syntax inspired from Golang. One of the best things about Golang is the message passing syntax: it makes code more readable, and it prevents a library-war by having this syntax builtin.
</p>
<pre name="code" class="go">
result1 = <- mychannel
print result1
result2 = <- mychannel
print result2
</pre>
<p>
The code above gets the result of <i>mychannel</i> that computes something in a WebWorker. This requires waiting for the result, so if written directly by hand in JavaScript, you would need to write a mess of async callbacks. Rusthon automatically translates above into async code, and deals with routing messages to each channel.
</p>
<pre name="code" class="javascript">
__workerpool__.recv( mychannel, function (result1) {
console.log(result1);
__workerpool__.recv( mychannel, function (result2) {
console.log(result2);
});
});
</pre>
<p><b><a href="https://github.com/rusthon/Rusthon/blob/master/examples/javascript_webworkers.md">source code</a></b></p>
<h3>Channel Select Syntax</h3>
<p>
Select syntax inspired by Golang, works pretty much the same as Golangs select statement.
</p>
<pre name="code" class="go">
for i in range(n):
print 'trying to select on workers'
select:
case res = <- worker1:
show('case-worker1:' + res)
case res = <- worker2:
show('case-worker2:' + res)
</pre>
<p><b><a href="https://github.com/rusthon/Rusthon/blob/master/examples/javascript_webworkers_advanced.md">example source code</a></b></p>
raptorhttp://www.blogger.com/profile/14287416587600419675noreply@blogger.com1tag:blogger.com,1999:blog-4301545062211714401.post-12847231352670371172015-06-15T10:46:00.001-07:002015-06-15T10:46:16.515-07:00Rusthon Overview<div dir="ltr" style="text-align: left;" trbidi="on">
<br /></div>
<h3>The Old Way</h3>
<a href="http://4.bp.blogspot.com/-2elBZdgmiQ4/VX8Nzs74ALI/AAAAAAAAB1Y/eS-OrrFQ5CA/s1600/RusthonVsOldStyle.png" imageanchor="1" ><img border="0" src="http://4.bp.blogspot.com/-2elBZdgmiQ4/VX8Nzs74ALI/AAAAAAAAB1Y/eS-OrrFQ5CA/s400/RusthonVsOldStyle.png" /></a>
<p>
Above is the traditional way software gets developed. It is a slow and complex process, it creates extra work for the coder, because they must manage files, folders, and multiple build tools. This is a headache and it is not secure.
</p>
<h3>The New Way</h3>
<a href="http://1.bp.blogspot.com/-26M3efXRMCc/VX8N56fpzlI/AAAAAAAAB1g/cwN_lCOH3gE/s1600/RusthonStyle.png" imageanchor="1" ><img border="0" src="http://1.bp.blogspot.com/-26M3efXRMCc/VX8N56fpzlI/AAAAAAAAB1g/cwN_lCOH3gE/s400/RusthonStyle.png" /></a>
<p>
Above the new way of software development using Rusthon. Its simple and more secure using only a single markdown file that combines all config files, and source code in multiple languages. Rusthon also includes a powerful Python to Javascript transpiler, so you can do almost everything from Python syntax if you want.
</p>raptorhttp://www.blogger.com/profile/14287416587600419675noreply@blogger.com1tag:blogger.com,1999:blog-4301545062211714401.post-77215891391148812242015-05-10T17:43:00.000-07:002015-05-10T20:56:51.498-07:00WebGL CSS3D UI Prototype<div dir="ltr" style="text-align: left;" trbidi="on">
<br /></div>
<iframe width="600" height="315" src="https://www.youtube.com/embed/MmVBubFNuxw" frameborder="0" allowfullscreen></iframe>
<p>
I have updated this prototype to work with the latest <a href="http://threejs.org/">THREE.js</a> and only use one CSS3DRenderer layer, you can view the live demo on heroku <a href="https://rusthon.herokuapp.com">rusthon.herokuapp.com</a>.
The shading over the CSS3D windows is done with the bloom fx in THREE.js, some of the stock fx are compatible with RGBA targets, and able to render overtop of the interactive HTML layer.
</p>
<p>
You can drag and drop Collada (dae) files from your desktop onto the view and they will be loaded and attached to the 3D window. See the source code,
<a href="https://github.com/rusthon/Rusthon/blob/master/examples/threejs_webglcss3d_simple_editor.md">here</a>. The prototype works in Google Chrome, Safari, new iphones and androids, but not very well in Firefox see this bug <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1163475">webgl alpha overlay css3d bug</a>
</p>raptorhttp://www.blogger.com/profile/14287416587600419675noreply@blogger.com6tag:blogger.com,1999:blog-4301545062211714401.post-40212965270323150782015-04-18T15:00:00.000-07:002015-04-18T15:34:21.537-07:00Unreal Engine4 - CPython Plugin<div dir="ltr" style="text-align: left;" trbidi="on">
<br /></div>
<img src="http://rusthon.github.io/Rusthon/images/UnrealPython.svg">
<p>
Rusthon has special syntax for directly using PyObject's from the <a href="https://docs.python.org/2.7/c-api/index.html">CPython CAPI.</a>
The <b>-></b> operator is used on PyObject's, and is transpiled into: <b>PyObject_GetAttrString(ob,name)</b>, for more info see this <a href="https://github.com/rusthon/Rusthon/wiki/CPython-Integration">wiki page</a>. This allows you to directly manage calling CPython functions, cast and move data back and forth from C++ to the CPython interpreter. This makes using complex libraries simple and safer, you do not need to depend on complex wrapper generators, or depend on C++ reflection to dynamically bind CPython to C++.
</p>
<p>
Unreal has a C++ reflection system, and this can be used to generate bindings to a scripting language. Unreal users want scripting support, see this <a href="https://news.ycombinator.com/item?id=7585186">thread</a>, and this one asking about <a href="http://www.reddit.com/r/unrealengine/comments/30a808/any_way_to_use_python_in_ue4/">CPython in Unreal.</a>
</p>
<p>
Scripting is great when you have a command-prompt and can type code at runtime, or write quick scripts and simply run them. Scripting fails when you need to do something complex and use multiple threads, for this you need C++. Rusthon allows you to write in a Python-like language and create fast glue code that bridges CPython together with any other C++ library, no reflection or generated bindings required.
</p>
<p>
This example: <a href="https://github.com/rusthon/Rusthon/blob/master/examples/unreal_cpython.md">unreal_cpython.md</a> shows you how to connect CPython2.7 with Unreal. The example contains no handwritten C++, instead the code is transpiled to C++ at compile time. The embedded Python script is also inlined into the final binary.
</p>raptorhttp://www.blogger.com/profile/14287416587600419675noreply@blogger.com0tag:blogger.com,1999:blog-4301545062211714401.post-70568392875784613002015-04-17T23:48:00.000-07:002015-04-17T23:51:52.229-07:00C++ Backend Part3<div dir="ltr" style="text-align: left;" trbidi="on">
<br /></div>
<p>
Calling into C++ from another language normally requires an <a href="http://en.wikipedia.org/wiki/Foreign_function_interface">FFI</a> and writing extra broiler plate code and having to worry about garbage collection and threading issues. Just take a look at how fucked up interfacing <a href="http://dlang.org/cpp_interface.html">D is with C++.</a> Don't miss the bottom of that doc on C++ Templates, from the doc: <i>"D templates have little in common with C++ templates, and it is very unlikely that any sort of reasonable method could be found to express C++ templates in a link-compatible way with D.
This means that the C++ STL, and C++ Boost, likely will never be accessible from D."</i> There are many other system languages, like Rust, that want to kill off C++, but do not have a good way of interfacing with C++.
</p>
<p>
C++ is deeply entrenched, its not going anywhere. Rusthon transpiles to human readable C++, and you can configure the transpiler to use regular or smart pointers. Interfacing with an external C++ library is simple and requires no FFI, you can use C++ namespaces, template classes (via macros) and directly handle memory, passing the address of some variable or returning a pointer.
</p>
<h3>Caffe Deep Learning</h3>
<a href="http://2.bp.blogspot.com/-M1Ok7PKJ6QA/VTH6imrXX9I/AAAAAAAABsE/XaSvIviePMA/s1600/hello_caffe.png" imageanchor="1" ><img border="0" src="http://2.bp.blogspot.com/-M1Ok7PKJ6QA/VTH6imrXX9I/AAAAAAAABsE/XaSvIviePMA/s400/hello_caffe.png" /></a>
<p>
<a href="http://caffe.berkeleyvision.org/">Caffe</a> is a large deep learning framework with many different types of neural networks. Getting it to compile and working on Fedora took me a couple of days, along the way I had to make lots of notes on the build and defines it required. The notes, build script, and code is all put into a single markdown file, see <a href="https://github.com/rusthon/Rusthon/blob/master/examples/hello_caffe.md">hello_caffe.md</a>.
</p>
<p>
Testing Caffe with Rusthon has given me the chance to iron out the last details for working with external C++. Some functions in Caffe need to be passed the address of a variable, not the value or a pointer to it, the new builtin <b>addr(X)</b> takes the address of <b>X</b> and passes it to the function. If you need to initialize an array of template classes you can now use this trick.
</p>
<pre name="code" class="python">
with MyType as "some_template<float>":
x = new( MyType() )
y = []MyType()
y.append( x )
</pre>
raptorhttp://www.blogger.com/profile/14287416587600419675noreply@blogger.com1tag:blogger.com,1999:blog-4301545062211714401.post-75965129177926493902015-04-08T07:57:00.000-07:002015-04-08T07:57:49.609-07:00C++ Backend Part2<div dir="ltr" style="text-align: left;" trbidi="on">
<br /></div>
<p>
New syntax and built-in functions have been added to Rusthon's C++ transpiler to make interfacing with external C++ libraries as simple as possible. Namespace syntax is supported using <b>::</b>, just like in normal C++, more info <a href="https://github.com/rusthon/Rusthon/wiki/Namespaces">here.</a> Macro syntax is support with the <b>macro</b> function (to inline simple macros) and new with statement <b>with T as "foo<bar>(%s)":</b> that makes <i>T</i> a callable macro, this is useful for calling template functions from external libraries, more info see <a href="https://github.com/rusthon/Rusthon/wiki/Macro-Functions">here</a>.
</p>
<p>
Functions can also now use C++ type syntax to define the function return type. This allows you to override the default behavior of returning shared pointers (to objects, arrays, and maps).
<ul>
<li><b>def f()->T*</b> returns a pointer to T</li>
<li><b>def f()->T&</b> returns a reference to T</li>
</ul>
</p>
<p>
Calling methods on strings has now been fixed and always works, before there was the problem of pointers|references (which the transpiler had to keep track of). This has been fixed with a c++ template class function, the transpiler when it is not sure what the type of something is will use this template function to properly wrap the value. This also solves the general problem of working with objects from external c++ libs, where you are not sure if something is a pointer, or a pointer to something.
</p>
raptorhttp://www.blogger.com/profile/14287416587600419675noreply@blogger.com0tag:blogger.com,1999:blog-4301545062211714401.post-76960052059141898832015-04-07T20:58:00.004-07:002015-04-14T19:14:14.221-07:00Unreal Engine4 Test Plugin<div dir="ltr" style="text-align: left;" trbidi="on">
<br /></div>
<a href="http://3.bp.blogspot.com/-XV8fu4R01rM/VSSlz9cP51I/AAAAAAAABrU/j3-RLk8TGKU/s1600/unreal-testplugin.png" imageanchor="1" ><img border="0" src="http://3.bp.blogspot.com/-XV8fu4R01rM/VSSlz9cP51I/AAAAAAAABrU/j3-RLk8TGKU/s400/unreal-testplugin.png" /></a>
<p>
Above, screen shot of Unreal Editor being opened by the installer script in Fedora21, and starting the compile process. <i>update: april 14: got the plugin to compile and load</i>, fixed a bug in the Unreal source code (3dluvr's version), get my fork of Unreal4.7 <a href="https://github.com/rusthon/UnrealEngine">here</a> that is compatible with Rusthon.
The command below will compile the plugin and launch Unreal Editor.
</p>
<p>
./rusthon.py ./examples/unreal_plugin.md --run=install-plugin.py --output-dir=~/Documents/Unreal\ Projects/MyProject/
</p>
<h4>source code</h4>
<a href="https://github.com/rusthon/Rusthon/blob/master/examples/unreal_plugin.md">https://github.com/rusthon/Rusthon/blob/master/examples/unreal_plugin.md</a>raptorhttp://www.blogger.com/profile/14287416587600419675noreply@blogger.com0tag:blogger.com,1999:blog-4301545062211714401.post-86244855892870147662015-04-03T13:07:00.000-07:002015-04-03T13:10:55.445-07:00Custom C++ Types<div dir="ltr" style="text-align: left;" trbidi="on">
<br /></div>
<img src="http://rusthon.github.io/Rusthon/images/RusthonCustomTypes.svg">
<a href="https://github.com/rusthon/Rusthon/wiki/Custom-Type-Templates">custom types wiki page</a>
<p>
Which is the best smart pointer library for C++, that works everywhere and is fast? The standard smart pointers in C++11 can raise exceptions for some operations and this adds performance overhead. High performance libraries often use custom smart pointers because of this. Each custom smart pointer library has a similar API and behavior, and sometimes it is just the method names that differ. These implementation details get in the way of clear and readable code.
</p>
<p>
Rusthon solves this problem by allowing you to configure which smart pointers to use, for each block of code. This allows you to write code at a higher level, and control the low level details of translation using a single line <b>with syntax('mytypes.json')</b>. Code in that block will use the custom types and methods you define for: vectors, maps, shared and weak references. Outside of the block it defaults back to standard C++11 types.
</p>
<h3>Unreal Engine4</h3>
<p>
This <a href="https://github.com/rusthon/Rusthon/blob/master/examples/unreal_cyclic_weakptr.md">example</a> shows you how to configure the translator to use Unreal Engine smart pointers, string type, and template arrays. The translator configuration is at the top of the markdown, and redefines template and method names. Here is the output of main:
</p>
<pre name="code" class="c++">
int main() {
TArray<TSharedRef<Child>> children = {};
auto p = TSharedRef<Parent>(
(new Parent())->__init__(1000, children)
);
std::cout << TEXT("parent:");
std::cout << p;std::cout << std::endl;
auto c1 = make_child(p, 1);
auto c2 = make_child(p, 20);
auto c3 = make_child(p, 300);
std::cout << TEXT("children:") << std::endl;
std::cout << c1 << std::endl;
std::cout << c2 << std::endl;
std::cout << c3 << std::endl;
std::cout << TEXT("calling foo") << std::endl;
std::cout << c1->foo() << std::endl;
std::cout << TEXT("calling bar") << std::endl;
c1->bar();
p.Reset();
std::cout << c1->foo() << std::endl;
c1->bar();
return 0;
}
</pre>raptorhttp://www.blogger.com/profile/14287416587600419675noreply@blogger.com0tag:blogger.com,1999:blog-4301545062211714401.post-9021017309654473302015-03-14T16:56:00.001-07:002015-03-25T15:26:46.778-07:00CPython inside Rusthon<div dir="ltr" style="text-align: left;" trbidi="on">
<br /></div>
<a href="http://rusthon.github.io/Rusthon/images/CPythonRusthonC++.svg">
<img src="http://rusthon.github.io/Rusthon/images/CPythonRusthonC++.svg">
</a>
<p>
Normally when mixing C++ with CPython you compile your C++ code and load it as an extension module. Sometimes, but less often CPython is embedded inside a C++ program. To interact with the Python interpreter from C++ requires writing verbose C-API calls all over the place. Rusthon simplifies using the C-API with special syntax <b>-></b>, dedicated to PyObjects, that will generate the required PyObject_XXX calls for you.
</p>
<h4>simple tutorial: <a href="https://github.com/rusthon/Rusthon/blob/master/examples/cpython_embed.md">cpython_embed.md</a></h4>
<p>
The simple tutorial above shows you how to call methods on PyObject's and convert the return value to a C++ native type.
Below shows how to use Go style channels to send PyObject's around to different threads created with <b>spawn</b> <i>(c++11 std::thread)</i>.
</p>
<h4>multi-threaded GIL example: <a href="https://github.com/rusthon/Rusthon/blob/master/examples/cpython_multithreaded.md">cpython_multithreaded.md</a></h4>
<pre name="code" class="python">
with gil:
value = pyob->pymethod( cppob.cppmethod() as pyint ) as int
</pre>
above example shows different calling styles for the PyObject and C++ object. note: <b>as pyint</b> becomes <i>PyInt_FromLong</i> from the CPython C-API, this is used to convert the return value of `cppmethod` to a <b>PyObject</b>.raptorhttp://www.blogger.com/profile/14287416587600419675noreply@blogger.com0tag:blogger.com,1999:blog-4301545062211714401.post-52794126405602329762015-03-01T17:17:00.000-08:002015-03-01T19:20:49.650-08:00Literate Programming<div dir="ltr" style="text-align: left;" trbidi="on">
<br /></div>
<p>
<a href="http://en.wikipedia.org/wiki/Literate_programming">Literate Programming</a>, invented by <a href="http://en.wikipedia.org/wiki/Donald_Knuth">Donald Knuth</a>, makes programs human readable, secure and of higher quality.
</p>
<p>
Rusthon's multi-language markdown allows you use literate programming for mixing: python, c++, c, java, nim, rust, go, javascript and html. The transpiler/markdown-parser also acts as a compiler frontend to: gcc, g++, java, rustc, and go. This allows you to create multiple compiled executeables from a single markdown.
</p>
<p>
The source code of Rusthon itself is now mostly written in markdown, the main modules are:
<ul>
<li><a href="https://github.com/rusthon/Rusthon/blob/master/src/main.md">main.md</a></li>
<li><a href="https://github.com/rusthon/Rusthon/blob/master/src/cpptranslator.md">cpptranslator.md</a></li>
<li><a href="https://github.com/rusthon/Rusthon/blob/master/src/rusttranslator.md">rusttranslator.md</a></li>
<li><a href="https://github.com/rusthon/Rusthon/blob/master/src/gotranslator.md">gotranslator.md</a></li>
<li><a href="https://github.com/rusthon/Rusthon/blob/master/src/jstranslator.md">jstranslator.md</a></li>
<li><a href="https://github.com/rusthon/Rusthon/blob/master/src/typedpython.md">typedpython.md</a></li>
<li><a href="https://github.com/rusthon/Rusthon/blob/master/src/intermediateform.md">intermediateform.md</a></li>
</ul>
</p>raptorhttp://www.blogger.com/profile/14287416587600419675noreply@blogger.com0