2012年1月

2012年2月

2012年3月

2012年4月

2012年5月

2012年6月

2012年7月

2012年8月

2012年9月

2012年10月

2013年1月

2013年2月

2013年3月

2013年4月

2013年10月

2013年11月

2014年3月

2015年3月

2015年4月

2015年7月

2016年4月

2017年3月

2017年4月

2017年5月

2017年9月

2017年11月

2018年3月

2018年5月

2018年9月

2020年6月

2023年4月

tcl=tclsh8.6
files='20120831 20120930 20130127 20130225 20130330 20160430'
files="$files 20150325 20150430 20150731
20170331 20170430 20170531 20170930 20171130 20180531 20180930
20200630 20230429"
url=http://natal.web.fc2.com/tcl
wget $url/pre.tcl
wget $url/kopipe.tcl
for x in $files; do
  wget $url/$x.html
  $tcl pre.tcl $x.html >> kopipe.tcl
done
$tcl kopipe.tcl
$tcl LuaLib.tcl > LuaLib.ml
$tcl Std.tcl > Std.ml
$tcl recompile.tcl > recompile.ml
ocamlopt.opt -o tcl2ml Dynamic.ml LL.ml Global.ml LuaLib.ml Std.ml recompile.ml

cat <<'EOF' > example.tcl
source compile.tcl

:main {
  :require Std
  :import tostring print type select error
  :import unpack assert
  :import list
  :import string math io table


  # Global.ml

  : { assert( tostring(10) == "10." ) }

  : { print("t", "e", "s", "t") }

  :var t
  :tab t

  : { assert( type(nil)   == "nil"      ) }
  : { assert( type(true)  == "boolean"  ) }
  : { assert( type(0)     == "number"   ) }
  : { assert( type("")    == "string"   ) }
  : { assert( type(t)     == "table"    ) }
  : { assert( type(print) == "function" ) }

  : { assert( select("#", 1, 2, 3) == 3 ) }
  : { assert( select(2, "a", "b", "c") == "b" ) }

  :var cmp
  :fun cmp {
    :var a n
    : {a = list(...)}
    : {n = #a}
    :var f
    :fun f {
      :var b
      : {b = list(...)}
      : {assert(#b == n)}
      :var i
      : {i = 1}
      :loop {
        :if {i > n} :break
        : {assert(a[i] == b[i])}
        : {i = i+1}
      }
    }
    :ret f
  }

  : { assert( string.byte("abc")    == 97 ) }
  : { assert( string.byte("abc", 2) == 98 ) }
  : { cmp( string.byte("abc", -2, -1) )( 98, 99 ) }

  : { assert( string.sub("abc", -2) == "bc" ) }
  : { assert( string.sub("abc", 2, 1) == "" ) }

  : { assert( string.char(97, 98) == "ab" ) }

  # : { error("error: test") }

  : { assert( math.ceil(-0.5) == 0 ) }

  : { assert( math.floor(-0.5) == -1 ) }

  # : { print(io.stdin:read()) }


  # LuaLib.tcl

  :do {
    :var a
    : {a = list("a", "b", "c")}
    : { cmp( unpack(a)       )( "a", "b", "c" )  }
    : { cmp( unpack(a, 2)    )(      "b", "c" )  }
    : { cmp( unpack(a, 1, 2) )( "a", "b"      )  }
  }

  : { cmp( string.find("abc", "b")  )( 2, 2 ) }
  : { cmp( string.find("abc", "^a") )( 1, 1 ) }
  : { cmp( string.find("abc", "^b") )( nil  ) }
  : { cmp( string.find("abc", "c$") )( 3, 3 ) }
  : { cmp( string.find("abc", "b$") )( nil  ) }
  : { cmp( string.find("abc", "b$") )( nil  ) }
  : { cmp( string.find("abc", "..") )( 1, 2 ) }
  : { cmp( string.find("abc", ".*") )( 1, 3 ) }
  : { cmp( string.find(""   , ".*") )( 1, 0 ) }
  : { cmp( string.find("abc", ".+") )( 1, 3 ) }
  : { cmp( string.find(""   , ".+") )( nil  ) }
  : { cmp( string.find("abc", ".?") )( 1, 1 ) }
  : { cmp( string.find(""   , ".?") )( 1, 0 ) }

  : { cmp( string.find("abb", ".-")  )( 1, 0 ) }
  : { cmp( string.find("abb", ".-a") )( 1, 1 ) }
  : { cmp( string.find("abb", ".-b") )( 1, 2 ) }
  : { cmp( string.find("abb", ".*b") )( 1, 3 ) }

  : { cmp( string.find(".", "%.") )( 1, 1 ) }
  : { cmp( string.find("a", "%.") )( nil  ) }

  : { cmp( string.find("x"  , "[a-z]") )( 1, 1 ) }
  : { cmp( string.find("abc", "[^ac]") )( 2, 2 ) }

  : { cmp( string.find("index.html", "([^%.]+)%.html") )( 1, 10, "index" ) }
  : { cmp( string.find("index.html", "[^%.]+()%.html") )( 1, 10, 6       ) }

  # isalpha
  : { cmp( string.find("Ab3", "%a+") )( 1, 2 ) }
  : { cmp( string.find("Ab3", "%A+") )( 3, 3 ) }
  # iscntrl
  : { cmp( string.find("xset -b\n", "%c+") )( 8, 8 ) }
  # isdigit
  : { cmp( string.find("Ab3", "%d+") )( 3, 3 ) }
  # islower
  : { cmp( string.find("Ab3", "%l+") )( 2, 2 ) }
  # ispunct
  : { cmp( string.find("xset -b\n", "%p+") )( 6, 6 ) }
  # isspace
  : { cmp( string.find(" \n", "%s+") )( 1, 2 ) }
  # isupper
  : { cmp( string.find("Ab3", "%u+") )( 1, 1 ) }
  # isalnum
  : { cmp( string.find("Ab3", "%w+") )( 1, 3 ) }
  # isxdigit
  : { cmp( string.find("GFE012efg", "%x+") )( 2, 8 ) }

  : { cmp( string.find(string.char(0), "%z+") )( 1, 1 ) }

  : { cmp( string.match("index.html", "([%w]+)%.html") )( "index"     ) }
  : { cmp( string.match("index.html", "[%w]+%.htm"   ) )( "index.htm" ) }

  # : { assert(false, "assert: test") }

  :do {
    :var a
    : {a = list("a", "b", "c")}
    : { assert( table.concat(a, " ", 1, 3) == "a b c" ) }
    : { assert( table.concat(a, " ", 2, 1) == ""      ) }
    : { assert( table.concat(a, " ", 2)    == "b c"   ) }
    : { assert( table.concat(a, " ")       == "a b c" ) }
    : { assert( table.concat(a)            == "abc"   ) }
  }
}
EOF
./tcl2ml < example.tcl > example.ml &&
$tcl example.tcl | cmp - example.ml &&
ocamlopt.opt -o example Dynamic.ml LL.ml Global.ml LuaLib.ml Std.ml example.ml &&
./example

todo:

20120831.html:
-1が最後、-2が最後から2番目の位置を表す機能がある場合もあるがない場合もある。

inserted by FC2 system