From 382c3553bb1c44f86d6cdbc7a7a76d54350d5694 Mon Sep 17 00:00:00 2001 From: Yusuke Endoh Date: Tue, 22 Oct 2019 02:44:36 +0900 Subject: [PATCH] Restore Scilab :tada: --- src/code-gen.rb | 64 ++++++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/src/code-gen.rb b/src/code-gen.rb index dd9bfd38..360284e1 100644 --- a/src/code-gen.rb +++ b/src/code-gen.rb @@ -1417,16 +1417,16 @@ class Smalltalk < CodeGen Code = %q("Transcript show: '#{d[PREV,?']}';cr") end -class Scheme_Sed_Shakespeare_SLang < CodeGen - Name = ["Scheme", "sed", "Shakespeare", "S-Lang"] - File = ["QR.scm", "QR.sed", "QR.spl", "QR.sls"] +class Scilab_Sed_Shakespeare_SLang < CodeGen + Name = ["Scilab", "sed", "Shakespeare", "S-Lang"] + File = ["QR.sci", "QR.sed", "QR.spl", "QR.sl"] Cmd = [ - "$(SCHEME) QR.scm > OUTFILE", + "scilab-cli -nb -f QR.sci > OUTFILE", "sed -E -f QR.sed QR.sed > OUTFILE", "./vendor/local/bin/spl2c < QR.spl > QR.spl.c && gcc -o QR -I ./vendor/local/include -L ./vendor/local/lib QR.spl.c -lspl -lm && ./QR > OUTFILE", - "slsh QR.sls > OUTFILE", + "slsh QR.sl > OUTFILE", ] - Apt = ["guile-2.0", "sed", nil, "slsh"] + Apt = ["scilab-cli", "sed", nil, "slsh"] def code # NOTE: This code does not work for a short or simple text. # This assumes the input is so complex enough that @@ -1437,7 +1437,7 @@ def code # * The S-Lang program includes 8-bit characters and decompress the compression. <<-'END'.lines.map {|l| l.strip }.join %( - (display" + printf(" 1d; s/.//; s/1/ the sum of a son and0/g; @@ -1451,32 +1451,42 @@ def code #Scene i: Relay.\\n #[Enter Ajax and Ford]\\n #Ajax:\\n - #") - (define(f n m) - (if(= n 1) - (display(+(* m 10)3)) - (f(quotient n 2)(+(* m 10)(modulo n 2))))) - (define(g _ n) - (if(> n 0) - (g(f(modulo n 256)2)(quotient n 256)))) - (g 0(string->number"#{ + #"); + function[]=f(s); + for i=1:2:length(s), + printf("2%s3",part(dec2bin(hex2dec(part(s,i:i+1))),$:-1:2)), + end; + endfunction\n + #{ s,v=rp[PREV,127..255]; - %( - variable s=`#{s.gsub(/.{1,234}/){$&+"`+\n`"}}`,i; - for(i=0;i<129;i++) - s=strreplace( - s, - pack(`C`,255-i), - substrbytes(`#{v[0,99]}`+\n`#{v[99..-1]}`,i*2+1,2)); - printf(`%s`,s) - ).reverse.unpack1("H*") - }"16)) - (display"\\n#[Exeunt]") + f( + %( + variable s=`#{s.gsub(/.{1,234}/){$&.gsub("`",%(`+"`"+`))+"`+\n`"}}`,i; + for(i=0;i<129;i++) + s=strreplace( + s, + pack("C",255-i), + substrbytes(`#{v[0,99]}`+\n`#{v[99..-1]}`,i*2+1,2)); + printf("%s",s) + ),7 + ){ + "f('%s')\n"%$s.unpack("H*") + } + } + printf("\\n#[Exeunt]"); + quit ) END end end +class Scheme < CodeGen + File = "QR.scm" + Cmd = "$(SCHEME) QR.scm > OUTFILE" + Apt = "guile-2.0" + Code = %q(%((display "#{e[PREV]}"))) +end + class Scala < CodeGen File = "QR.scala" Cmd = "scalac QR.scala && scala QR > OUTFILE"