Skip to content

Commit

Permalink
* the 55th language: Nickle
Browse files Browse the repository at this point in the history
  • Loading branch information
mame committed Nov 9, 2014
1 parent e905d0d commit 4ba79e4
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 142 deletions.
40 changes: 24 additions & 16 deletions Makefile
Expand Up @@ -373,27 +373,35 @@ QR.neko: QR.asm
ld -m elf_i386 -o QR QR.o
./QR > QR.neko

QR.js: QR.neko
QR.5c: QR.neko
@echo
@echo "##########################"
@echo "## 41: Neko -> NodeJS ##"
@echo "## 41: Neko -> Nickle ##"
@echo "##########################"
@echo
nekoc QR.neko
neko QR.n > QR.js
neko QR.n > QR.5c

QR.js: QR.5c
@echo
@echo "############################"
@echo "## 42: Nickle -> NodeJS ##"
@echo "############################"
@echo
nickle QR.5c > QR.js

QR.m: QR.js
@echo
@echo "#################################"
@echo "## 42: NodeJS -> Objective-C ##"
@echo "## 43: NodeJS -> Objective-C ##"
@echo "#################################"
@echo
$(NODE) QR.js > QR.m

QR.ml: QR.m
@echo
@echo "################################"
@echo "## 43: Objective-C -> OCaml ##"
@echo "## 44: Objective-C -> OCaml ##"
@echo "################################"
@echo
gcc -o QR QR.m
Expand All @@ -402,31 +410,31 @@ QR.ml: QR.m
QR.octave: QR.ml
@echo
@echo "###########################"
@echo "## 44: OCaml -> Octave ##"
@echo "## 45: OCaml -> Octave ##"
@echo "###########################"
@echo
ocaml QR.ml > QR.octave

QR.pasm: QR.octave
@echo
@echo "################################"
@echo "## 45: Octave -> Parrot asm ##"
@echo "## 46: Octave -> Parrot asm ##"
@echo "################################"
@echo
octave -qf QR.octave > QR.pasm

QR.pas: QR.pasm
@echo
@echo "################################"
@echo "## 46: Parrot asm -> Pascal ##"
@echo "## 47: Parrot asm -> Pascal ##"
@echo "################################"
@echo
parrot QR.pasm > QR.pas

QR.pl: QR.pas
@echo
@echo "##########################"
@echo "## 47: Pascal -> Perl ##"
@echo "## 48: Pascal -> Perl ##"
@echo "##########################"
@echo
fpc QR.pas
Expand All @@ -435,55 +443,55 @@ QR.pl: QR.pas
QR.php: QR.pl
@echo
@echo "#######################"
@echo "## 48: Perl -> PHP ##"
@echo "## 49: Perl -> PHP ##"
@echo "#######################"
@echo
perl QR.pl > QR.php

QR.pike: QR.php
@echo
@echo "#######################"
@echo "## 49: PHP -> Pike ##"
@echo "## 50: PHP -> Pike ##"
@echo "#######################"
@echo
php QR.php > QR.pike

QR.prolog: QR.pike
@echo
@echo "##########################"
@echo "## 50: Pike -> Prolog ##"
@echo "## 51: Pike -> Prolog ##"
@echo "##########################"
@echo
pike QR.pike > QR.prolog

QR.py: QR.prolog
@echo
@echo "############################"
@echo "## 51: Prolog -> Python ##"
@echo "## 52: Prolog -> Python ##"
@echo "############################"
@echo
swipl -q -t qr -f QR.prolog > QR.py

QR.R: QR.py
@echo
@echo "#######################"
@echo "## 52: Python -> R ##"
@echo "## 53: Python -> R ##"
@echo "#######################"
@echo
python QR.py > QR.R

QR.rexx: QR.R
@echo
@echo "#####################"
@echo "## 53: R -> REXX ##"
@echo "## 54: R -> REXX ##"
@echo "#####################"
@echo
R --slave < QR.R > QR.rexx

QR2.rb: QR.rexx
@echo
@echo "########################"
@echo "## 54: REXX -> Ruby ##"
@echo "## 55: REXX -> Ruby ##"
@echo "########################"
@echo
rexx ./QR.rexx > QR2.rb
Expand Down
108 changes: 54 additions & 54 deletions QR.rb
@@ -1,54 +1,54 @@
eval$s=%q(eval(%w(B=92.chr;g=32.chr;puts(eval(%q(N=10.chr;n=0;e=->s{Q[Q[s,B],?"].K(N,B+?n)};E=->s{'("'+e[s]+'
")'};d=->s,t=?"{s.K(t){t+t}};Q=->s,t=?${s.K(t){B+$&}};M=->s{"<stdio.h>#{N}!t~mX{puts#{E[s]};return~0;}"};V=->
s,a,z{s.K(/(#{B*4})+/){a+"#{$&.size/2}"+ z}};$D= "program ~QR";%(object~QR~extends~App{Z#{E[%((display~"#{e
[%(Zf~%s~"#{Q[e["Transcript~sho w:~'# {d[% (pro c~f~{n}~{sJ~repeat~"Y"~$n}~;puts~[reK~-all~{.}~"#{
V[Q[e[%[!t~mX{sJ~s=#{E[%(with ~Ad a .Text_Io;procedure~qr~is~beg!~Ada.Text_Io
.Put_L!e("#{d[%(Z("#{ d[%(B E GIN{s=#{E[%(f={n~as~!t|'Y'*n};a=0;s=#{V[Q[
E["#!clude"+M["#!clu de< iostream>`n!t~mX{std::cout<<#{E[
%(class~Program{pub l ic~static~void~MX{System.Console.
Write(#{E[%((doseq [s(lazy-cat["IDENTIFICATIO
N~DIVISION.""PROG RAM-ID.~QR.""PROCEDURE~DIVI
SION."'DISPLA`x5 9](map~#(str"~~~~^""(.
replace%1"^"""^ "^"")"^"&")(re-seq~#".{
1,45}""#{e[%( (f=(n)->A rray(n+1).jo!~"Y");
console.log ("%s",#{V[E[%((H-l!e"#{e[ %(~:~A~."#{g*9}"~;~:
~B~A~."~WR ITE(*,*)'"~A~;~:~C~B~T`x59PE~."~'" ~CR~;~:~D~S"~#$D"~C
~S^"~Z~^ "(&"~C~S^"~#{e[%(package~ma!;import"fmt"; func~mX{fmt.Pr!t#
{E[%(Z' #{e[("ma!=putStr"+E[%(procedure~mX;i:=c:=0;s:= #{E[%(.class~pub
lic~QR `n.super~#{$T="java/io/Pr!tStream"}`n.method~publi c~static~ma!([L
#{S=" java/lang/"}SJ;)V~;]`n.limit~stack~2`ngetstatic~#{S}S ystem/out~L#$T
;`nl dc~"#{e[%(class~QR{public~static~void~ma!(SJ[]v){SJ~c[]= new~SJ[8000],
y=" ",z=y,s="#{z=t=(0..r =q=126).map{|n|[n,[]]};a="";b=->n{a<<( n%78+55)%84+4
2}; (%(@s=global[#{i=(s= %(PR~"`x48AI^~1.2~PR~"VISIBLE^~"#{Q["Z" +E[%(all:`n`
t@ echo~'#{d[Q["l!el:99 9 99;Z#{E[%(.assembly~t{}.method~static~v oid~MX{.ent
ry po!t~ldstr"#{e[%(m:d b`x 60#{e[s="$Z#{E["require('util').Z#{E[" #import"+M[
"Z _s J"+E["Zf"+E[%(say"#{ e["#$ D(output);beg!~H(#{((p="eval";%($_="#{ s=%(<?php~
fu nction~f($n){return~ str_rep eat("Y",$n);};$f="f";echo#{V[Q[E["!t~m X{H#{E["qr
:-H ('#{Q[e[ %(for~l~!#{E[e[d[%(eval$s =%q(#$s))]
]]}. spl it("Yn"):Z ('cat(" say~Y"'+l+'Y" Yn")')) ],?']}')."]};return~0;}"]], "{$f(",")}
"]}?> );(s+N*(-s.size% 6)).u npack("B*")[0]. K(/.{ 6}/){n=$&.to_i~2;((n+14)/26* 6+n+47).ch
r}}";s|. |$n=ord$&;substr~u npa ck(B8,chr$n-!t($n /32 )*6-41),2|eg;Z~pack"B*",$_).s can(/[~,-:
A-z]+|(.)/){p= "s++#{$1?"chr~# { $1.ord}+e":$&+?+};" + p};p)).K(/.{1,255}/){|s|"'#{s} ',"}}'')en
d."]}"`nend)+N ]]]]}"+N]};"+N]} `x60`nglobal~_start`n _start:mov~edx,#{s.size}`nmov~e cx,m`nmov~
ebx,1`nmov~eax ,4`n!t~128`nmov ~ ebx,0`nmov~eax,1`n! t ~128)]}"call~void~[mscor l ib]System.
Console::Write (sJ)ret})]};q uit ();",B],?$].K(?') {%( '"'"')}}')]. K ( /[:"]/,"
:^0"),/[~Y`t;"( ){}`[`]]/]}" ~PR~" `x4bT`x48`x58B` x59E~ B`x59E)) . s ize+1}x
~i8]c"#{s.K(/[^ "]/){"^%`x 58"%$&. ord}}^00"decl are~i32 @puts(i8*)def! e ~ i32@mX
{%1=call~i32@put s(i8*gete lementptr([# { i }x~i8
]*@s,i32~0,i32~0 ))ret~i32~0})).bytes{ |n|r,z= z[n]||(b[r/78];b[r];q<608 3&&z[n]= [ q +=1,[
]];t[n])};b[r/78] ;b[r]}";!t~i=0,n=0,q= 0;for (;++n<126;)c[n]=""+(char)n;for(;i< s . leng
th();){q=q*78+(s.c harAt(i)-13)%84;if(i+ +%2 >0){y=q<n?c[q]:y;c[n++]=z+y.charAt(0 ) ;Sys
tem.out.Z(z=c[q]);q =0;}}}})]}"`n!vokevir t ual~#$T/Zln(L#{S}SJ;)V`nreturn`n.end ~ meth
od)+N]};H("DO,1<-#"| |*s);s?while~t:=ord( move(1))do{i+:=1;u:=-i;every~0to~7d o {u:
=u*2+t%2;t/:=2};H("PL EASE")^(i%4/3);H("DO ,1SUB#"||i||"<-#"||((c-u)%256));c:= u ;};
H("PLEASEREADOUT,1^nPL EASEGIVEUP");end)]).tr(B,?&)]}'.tr('&','YY');)]};})] }"~DUP~ FOR
~S"~&A,&"~C~NE`x58T~S^"~ &A)^",&"~C~0~DO~B~."~&char("~COUNT~.~."~),&'"~CR ~LOOP~S^" ~&^
"^""~C~S"~end~#$D"~C~A~." ~STOP"~CR~A~."~END"~CR~B`x59E~;~D~)]}"))], '#{f(',')}']}))]}") )["
~~~~^"~^".""STOP~RUN."])](Z ln(str"#{g*8}"s)))).tr~B,?`x7e]}.Rep lace("`x7e","Y"));}})] };
}"]]],"$(f(","))"]};for~i~!~ra nge(len(s)):b~as~!t=s[i];a-= b;Z(('+'*-a~if~0>a~else' -'
*a)+'.');a=b;).tr~B,?`x21]};K(/` x21/,"Y",s);Z ~s})]}"))]}");end~qr;)]};!t~i,j
;Z("module~QR;!itial~beg!~");for(i=0 ;i<s.length;i++){Z("$H(^"~~~");for
(j=6;j>=0;j--)Z((s[i]>>j)%2>0?"Yt":"~"); Z("YnYtYn~~^`");");}Z("$display(^"YnYn^
");end~endmodule");return~0;}].reverse],/[`[`]$ ]/],"[f~",?]]}"~^x60.&]k),?']}';cr"]]}")]}"))]
};})).gsub(/[!HJKXYZ^`~]/){[B*2,:write,B,:tring,:gsub,"ain()",B*4,:print,g,:in][$&.ord%47%12]})))*"")#_buffer
################## Quine Relay -- Copyright (c) 2013 Yusuke Endoh (@mametter), @hirekoke #################)
eval$s=%q(eval(%w(B=92.chr;g=32.chr;puts(eval(%q(N=10.chr;n=0;e=->s{Q[Q[s,B],?"].K(N,B+?n)};E=->s{'("'+e[s]+'")
'};d=->s,t=?"{s.K(t){t+t}};Q=->s,t=?${s.K(t){B+$&}};M=->s{"<stdio.h>#{N}!t~mX{puts#{E[s]};return~0;}"};V=->s,a,
z{s.K(/(#{B*4})+/){a+"#{$&.size/2}"+z}};$ D="prog ram~QR"; %(object~QR~extends~App{Z#{E[%((display~"#{e[%(Zf~
%s~"#{Q[e["Transcript~show:~'#{d [%(pr oc~f ~{n} ~{sJ~repeat~"Y"~$n}~;puts~[reK~-all~{.}~"#{V[Q[e[%[
!t~mX{sJ~s=#{E[%(with~Ada.Text _Io ; procedure~qr~is~beg!~Ada.Text_Io.Put_L!e("
#{d[%(Z("#{d[%(BEGIN{s =#{E[ % (f={n~as~!t|'Y'*n};a=0;s=#{V[Q[E["#!clude"+
M["#!clude<iostream>` n!t ~mX{std::cout<<#{E[%(class~Progra
m{public~static~void ~ MX{System.Console.Write(#{E[%((dos
eq[s(lazy-cat["IDEN TIFICATION~DIVISION.""PROGR
AM-ID.~QR.""PROCED URE~DIVISION."'DISPLA`x59](m
ap~#(str"~~~~^""( .replace%1"^"""^"^"")"^
"&")(re-seq~#".{ 1,45}""#{e[%((f=(n)->Arr
ay(n+1).jo!~"Y ");consol e.log("%s",#{V[E[%((
H-l!e"#{e[%( ~:~A~."#{g*9}"~;~:~B~A~." ~WRITE(*,*)'"~A~;~:~C
~B~T`x59PE~ ."~'"~CR~;~:~D~S"~#$D"~C~S^"~Z~^"( &"~C~S^"~#{e[%(packa
ge~ma!;im port"fmt";func~mX{fmt.Pr!t#{E[%(Z'#{e[("m a!=putStr"+E[%(pro
cedure~m X;i:=c:=0;s:=#{E[%(.class~public~QR`n.super~#{ $T="java/io/Pr!tS
tream"} `n.method~public~static~ma!([L#{S="java/lang/"}SJ; )V~;]`n.limit~st
ack~2` ngetstatic~#{S}System/out~L#$T;`nldc~"#{e[%(class~QR{ public~static~v
oid~m a!(SJ[]v){SJ~c[]=new~SJ[8000],y="",z=y,s="#{z=t=(0..r=q= 126).map{|n|[n
,[]] };a="";b=->n{a<<(n%7 8+55)%84+42};(%(@s=global[#{i=(s=%(PR~ "`x48AI^~1.2~P
R~"V ISIBLE^~"#{Q["Z"+E[% (all:`n`t@echo~'#{d[Q["l!el:99999;Z#{E[ %(.assembly~t
{}. method~static~void~M X {.entrypo!t~ldstr"#{e[%(m:db`x60#{e[s=" $Z#{E[%(Zf#{
E[" require('util').Z#{E ["# import"+M["Z_sJ"+E["Zf"+E[%(say"#{e["# $D(output);b
eg! ~H (#{((p="eval";%($_=" #{s=% (<?php~function~f($n){return~str_repea t("Y",$n);}
;$f ="f";echo#{V[Q[E["!t ~mX{H#{ E["qr:-H('#{Q[e[%(for~l~!#{E[e[d[%(eva l$s=%q(#$s)
)]]] }.split( "Yn"):Z('cat("say~Y"'+l+' Y"Yn")'))],
?']}' )." ]};return~ 0;}"]], "{$f(",")}"]} ?>);(s+ N*(-s.size%6)).unpack("B*") [0].K(/.{6}
/){n=$ &.to_i~2;((n+14) /26*6 +n+47).chr}}";s |.|$n =ord$&;substr~unpack(B8,chr$ n-!t($n/32)
*6-41),2| eg;Z~pack"B*",$_). sca n(/[~,-:A-z]+|(.) /){ p="s++#{$1?"chr~#{$1.ord}+e": $&+?+};"+p}
;p)).K(/.{1,255 }/){|s|"'#{s}', " }}'')end."]}"`nend) + N]]]]}"]})+N]};"+N]}`x60`nglob al~_start`n
_start:mov~edx, #{s.size}`nmov~e cx,m`nmov~ebx,1`nmov~ eax,4`n!t~128`nmov~ebx,0`nmov~e ax,1`n!t~12
8)]}"call~void~ [mscorlib]Syste m .Console::Write(sJ) r et})]};quit();",B],?$].K ( ?'){%('"'"'
)}}')].K(/[:"]/ ,":^0"),/[~Y` t;" (){}`[`]]/]}"~PR~ "`x 4bT`x48`x58B ` x 59E~B`x59
E)).size+1}x~i8] c"#{s.K(/[^" ]/){" ^%`x58"%$&.ord} }^00" declare~ i 3 2@puts(i
8*)def!e~i32@mX{ %1=call~i3 2@puts( i8*getelement ptr([#{ i}x~i8]*@s,i32 ~ 0 ,i32~0)
)ret~i32~0})).byt es{|n|r,z =z[n]||(b[r/ 7 8 ];b[r]
;q<6083&&z[n]=[q+ =1,[]];t[n])};b[r/78] ;b[r]}" ;!t~i=0,n=0,q=0;for(;++n< 126;)c[n ] = ""+(ch
ar)n;for(;i<s.leng th();){q=q*78+(s.char At(i) -13)%84;if(i++%2>0){y=q<n?c[q]:y;c [ n ++]=z
+y.charAt(0);System .out.Z(z=c[q]);q=0;}} }}) ]}"`n!vokevirtual~#$T/Zln(L#{S}SJ;)V ` nretu
rn`n.end~method)+N]} ;H("DO,1<-#"||*s);s?w h ile~t:=ord(move(1))do{i+:=1;u:=-i;ev e ry~0t
o~7do{u:=u*2+t%2;t/:= 2};H("PLEASE")^(i%4/ 3);H("DO,1SUB#"||i||"<-#"||((c-u)%2 5 6));
c:=u;};H("PLEASEREADOU T,1^nPLEASEGIVEUP"); end)]).tr(B,?&)]}'.tr('&','YY');)]} ; })]}
"~DUP~FOR~S"~&A,&"~C~NE `x58T~S^"~&A)^",&"~C~0~DO~B~."~&char("~COUNT~.~."~), &'"~CR~ LOOP
~S^"~&^"^""~C~S"~end~#$D" ~C~A~."~STOP"~CR~A~."~END"~CR~B`x59E~;~D~)]}"))] ,'#{f(',' )}']
}))]}"))["~~~~^"~^".""STOP ~RUN."])](Zln(str"#{g*8}"s)))).tr~B,?`x7e] }.Replace("`x7e","Y "));
}})]};}"]]],"$(f(","))"]};fo r~i~!~range(len(s)):b~as~!t=s[i];a-= b;Z(('+'*-a~if~0>a~els e'-
'*a)+'.');a=b;).tr~B,?`x21]};K( /`x21/,"Y",s);Z~s})]}"))]}") ;end~qr;)]};!t~i,j;Z("mo dul
e~QR;!itial~beg!~");for(i=0;i<s.l ength;i++){Z( "$H(^"~~~");for(j=6;j>=0;j--)Z((
s[i]>>j)%2>0?"Yt":"~");Z("YnYtYn~~^`" );");}Z("$display(^"YnYn^");end~end
module");return~0;}].reverse],/[`[`]$]/], "[f~",?]]}"~^x60.&]k),?']}';cr"]]}")]}")
)]};})).gsub(/[!HJKXYZ^`~]/){[B*2,:write,B,:trin g,:gsub,"ain()",B*4,:print,g,:in][$&.ord%47%12]
})))*"")#_buffer_for_future_bug_fixes_#_buffer_for_future_bug_fixes_#_buffer_for_future_bug_fixes_#_buffer_for_
################### Quine Relay -- Copyright (c) 2013 Yusuke Endoh (@mametter), @hirekoke ##################)
38 changes: 20 additions & 18 deletions README.md
Expand Up @@ -5,7 +5,7 @@
This is a Ruby program that generates
Scala program that generates
Scheme program that generates
...(through 54 languages in total)...
...(through 55 languages in total)...
REXX program that generates
the original Ruby code again.

Expand All @@ -26,9 +26,9 @@ First, you have to type the following apt-get command to install all of them.
coffeescript f2c fp-compiler g++ gauche gawk gcc gforth gfortran ghc \
gnat gnu-smalltalk gobjc golang groovy icont iconx intercal iverilog \
jasmin-sable llvm lua5.2 make maxima mono-devel mono-mcs nasm neko \
nodejs ocaml octave open-cobol openjdk-6-jdk parrot perl php5-cli \
pike7.8 python r-base regina-rexx ruby2.0 scala swi-prolog tcl ucblogo \
valac
nickle nodejs ocaml octave open-cobol openjdk-6-jdk parrot perl \
php5-cli pike7.8 python r-base regina-rexx ruby2.0 scala swi-prolog \
tcl ucblogo valac

Then, you have to build the bundled interpreters.

Expand Down Expand Up @@ -85,7 +85,8 @@ If you could do it, please let me know. Good luck.
$ maxima -q --init-mac=QR.mac > QR.il
$ ilasm QR.il && mono QR.exe > QR.asm
$ nasm -felf QR.asm && ld -m elf_i386 -o QR QR.o && ./QR > QR.neko
$ nekoc QR.neko && neko QR.n > QR.js
$ nekoc QR.neko && neko QR.n > QR.5c
$ nickle QR.5c > QR.js
$ nodejs QR.js > QR.m
$ gcc -o QR QR.m && ./QR > QR.ml
$ ocaml QR.ml > QR.octave
Expand Down Expand Up @@ -161,19 +162,20 @@ For other languages, I used the following deb packages:
39 |MSIL |mono-devel |3.2.8+dfsg-4ubuntu1
40 |NASM |nasm |2.10.09-1
41 |Neko |neko |2.0.0-3
42 |NodeJS |nodejs |0.10.25~dfsg2-2ubuntu1
43 |Objective-C |gobjc |4:4.8.2-1ubuntu6
44 |OCaml |ocaml |4.01.0-3ubuntu3
45 |Octave |octave |3.8.1-1ubuntu1
46 |Parrot asm |parrot |5.9.0-1build1
47 |Pascal |fp-compiler |2.6.2-8
48 |Perl |perl |5.18.2-2ubuntu1
49 |PHP |php5-cli |5.5.9+dfsg-1ubuntu4.4
50 |Pike |pike7.8 |7.8.700-7
51 |Prolog |swi-prolog |6.6.4-2ubuntu1
52 |Python |python |2.7.5-5ubuntu3
53 |R |r-base |3.0.2-1ubuntu1
54 |REXX |regina-rexx |3.6-2
42 |Nickle |nickle |2.77-1
43 |NodeJS |nodejs |0.10.25~dfsg2-2ubuntu1
44 |Objective-C |gobjc |4:4.8.2-1ubuntu6
45 |OCaml |ocaml |4.01.0-3ubuntu3
46 |Octave |octave |3.8.1-1ubuntu1
47 |Parrot asm |parrot |5.9.0-1build1
48 |Pascal |fp-compiler |2.6.2-8
49 |Perl |perl |5.18.2-2ubuntu1
50 |PHP |php5-cli |5.5.9+dfsg-1ubuntu4.4
51 |Pike |pike7.8 |7.8.700-7
52 |Prolog |swi-prolog |6.6.4-2ubuntu1
53 |Python |python |2.7.5-5ubuntu3
54 |R |r-base |3.0.2-1ubuntu1
55 |REXX |regina-rexx |3.6-2

Note: `CC=tcc ick -bfO` may be used to compile INTERCAL sources
with less memory.
Expand Down
Binary file modified langs.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions src/code-gen.rb
Expand Up @@ -167,6 +167,13 @@ class NodeJS < CodeGen
Code = %q("require('util').print#{E[PREV]}")
end

class Nickle < CodeGen
File = "QR.5c"
Cmd = "nickle QR.5c > OUTFILE"
Apt = "nickle"
Code = %q(%(printf#{E[PREV]}))
end

class Neko < CodeGen
File = "QR.neko"
Cmd = "nekoc QR.neko && neko QR.n > OUTFILE"
Expand Down

0 comments on commit 4ba79e4

Please sign in to comment.