{"commit":"44bb46dda5c22bc84ab4c667d4a6c69f59dc0b1c","subject":"Updating: initiating projects\/DREACH","message":"Updating: initiating projects\/DREACH\n","repos":"bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib","old_file":"projects\/LARGE\/DREACH\/SCRATCH\/bouncing_ball.dats","new_file":"projects\/LARGE\/DREACH\/SCRATCH\/bouncing_ball.dats","new_contents":"(*\n** Bouncing ball\n*)\n\n(* ****** ****** *)\n\/\/\n\/\/ Author: Hongwei Xi\n\/\/ Authoremail: gmhwxiATgmailDOTedu\n\/\/\n(* ****** ****** *)\n\ndatasort real = \/\/ abs\n\n(* ****** ****** *)\n\nabstype real(real)\n\n(* ****** ****** *)\n\nstacst g : real\nstacst dt : real\n\n(* ****** ****** *)\n\nstacst\nint2real : (int) -> real\nstadef i2r = int2real\n\n(* ****** ****** *)\n\nstacst\nneg_real : (real) -> real\nstadef ~ = neg_real\n\n(* ****** ****** *)\n\nstacst\nadd_real_real : (real, real) -> real\nstadef + = add_real_real\nstacst\nsub_real_real : (real, real) -> real\nstadef - = sub_real_real\n\n(* ****** ****** *)\n\nstacst\nmul_real_real : (real, real) -> real\nstadef * = mul_real_real\n\n(* ****** ****** *)\n\nstacst\ngt_real_int : (real, int) -> bool\nstadef > = gt_real_int\n\n(* ****** ****** *)\n\nstacst\neq_real_int : (real, int) -> bool\nstadef == = eq_real_int\n\n(* ****** ****** *)\n\/\/\nextern\nfun\ngt_real_int\n {x:real;i:int}\n (real(x), int(i)): bool(x > i)\n\/\/\noverload > with gt_real_int\n\/\/\n(* ****** ****** *)\n\ndatasort mode = M1 | M2\n\n(* ****** ****** *)\n\nabsvtype\nstate (mode, x:real, v:real)\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nstate_get_x{m:mode}{x,v:real}(!state(m, x, v)): real(x)\nand\nstate_get_v{m:mode}{x,v:real}(!state(m, x, v)): real(v)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nupdate1: {x,v:real | x > 0}\n state(M1, x, v) -> state(M1, x+v*dt, v+g*dt)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nupdate1_jump\n : {x,v:real | x == 0} state(M1, x, v) -> state(M2, x, ~v)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nupdate2: {x,v:real | v > 0}\n state(M2, x, v) -> state(M2, x+v*dt, v-g*dt)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nupdate2_jump\n : {x,v:real | v == 0} state(M2, x, v) -> state(M1, x, i2r(0))\n\/\/\n(* ****** ****** *)\n\nfun\nloop1{x,v:real}\n (state: state(M1, x, v)): void = let\n val x = state_get_x(state)\nin\n if x > 0\n then loop1(update1(state)) else loop2(update1_jump(state))\n \/\/ end of [if]\nend \/\/ end of [loop1]\n\nand\nloop2{x,v:real}\n (state: state(M2, x, v)): void = let\n val v = state_get_v(state)\nin\n if v > 0\n then loop2(update2(state)) else loop1(update2_jump(state))\n \/\/ end of [if]\nend \/\/ end of [loop2]\n\n(* ****** ****** *)\n\n(* end of [bouncing_ball.dats] *)\n","old_contents":"(*\n** Bouncing ball\n*)\n\n(* ****** ****** *)\n\/\/\n\/\/ Author: Hongwei Xi\n\/\/ Authoremail: gmhwxiATgmailDOTedu\n\/\/\n(* ****** ****** *)\n\ndatasort real = \/\/ abs\n\n(* ****** ****** *)\n\nabstype real(real)\n\n(* ****** ****** *)\n\nstacst g : real\nstacst dt : real\n\n(* ****** ****** *)\n\nstacst\nint2real : (int) -> real\nstadef i2r = int2real\n\n(* ****** ****** *)\n\nstacst\nneg_real : (real) -> real\nstadef ~ = neg_real\n\n(* ****** ****** *)\n\nstacst\nadd_real_real : (real, real) -> real\nstadef + = add_real_real\nstacst\nsub_real_real : (real, real) -> real\nstadef - = sub_real_real\n\n(* ****** ****** *)\n\nstacst\nmul_real_real : (real, real) -> real\nstadef * = mul_real_real\n\n(* ****** ****** *)\n\nstacst\ngt_real_int : (real, int) -> bool\nstadef > = gt_real_int\n\n(* ****** ****** *)\n\nstacst\neq_real_int : (real, int) -> bool\nstadef == = eq_real_int\n\n(* ****** ****** *)\n\/\/\nextern\nfun\ngt_real_int\n {x:real;i:int}\n (real(x), int(i)): bool(x > i)\n\/\/\noverload > with gt_real_int\n\/\/\n(* ****** ****** *)\n\ndatasort mode = M1 | M2\n\n(* ****** ****** *)\n\nabsvtype\nstate (mode, x:real, v:real)\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nstate_get_x{m:mode}{x,v:real}(!state(m, x, v)): real(x)\nand\nstate_get_v{m:mode}{x,v:real}(!state(m, x, v)): real(v)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nupdate1: {x,v:real | x > 0}\n state(M1, x, v) -> state(M1, x+v*dt, v+g*dt)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nupdate1_jump\n : {x,v:real | x == 0} state(M1, x, v) -> state(M2, x, ~v)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nupdate2: {x,v:real | v > 0}\n state(M2, x, v) -> state(M2, x+v*dt, v-g*dt)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nupdate2_jump\n : {x,v:real | v == 0} state(M2, x, v) -> state(M1, x, i2r(0))\n\/\/\n(* ****** ****** *)\n\nfun\nloop1{x,v:real}\n (state: state(M1, x, v)): void = let\n val x = state_get_x(state)\nin\n if x > 0 then loop1(update1(state)) else loop2(update1_jump(state))\nend \/\/ end of [loop1]\n\nand\nloop2{x,v:real}\n (state: state(M2, x, v)): void = let\n val v = state_get_v(state)\nin\n if v > 0 then loop2(update2(state)) else loop1(update2_jump(state))\nend \/\/ end of [loop2]\n\n(* ****** ****** *)\n\n(* end of [bouncing_ball.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"899dfd51741151af477c73db85f6e57f9a09651b","subject":"Updating: very minorly","message":"Updating: very minorly\n","repos":"bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib","old_file":"contrib\/libatscc\/libatscc2scm\/basics_scm.sats","new_file":"contrib\/libatscc\/libatscc2scm\/basics_scm.sats","new_contents":"(*\n** For writing ATS code\n** that translates into Scheme\n*)\n\n(* ****** ****** *)\n\/\/\n\/\/ HX-2015-06:\n\/\/ prefix for external names\n\/\/\n#define\nATS_EXTERN_PREFIX \"ats2erlpre_\"\n\/\/\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_define.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\n#include \"{$LIBATSCC}\/basics.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nabstype SCMval_type\ntypedef SCMval = SCMval_type\n\/\/\n(* ****** ****** *)\n\/\/\nfun\ncloref0_app{b:t0p}(cfun0(b)): b = \"mac#%\"\n\/\/\nfun\ncloref1_app\n {a:t0p}{b:t0p}(cfun1(a, b), a): b = \"mac#%\"\n\/\/\nfun\ncloref2_app\n {a1,a2:t0p}{b:t0p}\n (cfun2(a1, a2, b), a1, a2): b = \"mac#%\"\nfun\ncloref3_app\n {a1,a2,a3:t0p}{b:t0p}\n (cfun3(a1, a2, a3, b), a1, a2, a3): b = \"mac#%\"\n\/\/\noverload cloref_app with cloref0_app\noverload cloref_app with cloref1_app\noverload cloref_app with cloref2_app\noverload cloref_app with cloref3_app\n\/\/\n(* ****** ****** *)\n\n(* end of [basics_scm.sats] *)\n","old_contents":"(*\n** For writing ATS code\n** that translates into Scheme\n*)\n\n(* ****** ****** *)\n\/\/\n\/\/ HX-2015-06:\n\/\/ prefix for external names\n\/\/\n#define\nATS_EXTERN_PREFIX \"ats2erlpre_\"\n\/\/\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_define.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\n#include \"{$LIBATSCC}\/basics.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nfun\ncloref0_app{b:t0p}(cfun0(b)): b = \"mac#%\"\n\/\/\nfun\ncloref1_app\n {a:t0p}{b:t0p}(cfun1(a, b), a): b = \"mac#%\"\n\/\/\nfun\ncloref2_app\n {a1,a2:t0p}{b:t0p}\n (cfun2(a1, a2, b), a1, a2): b = \"mac#%\"\nfun\ncloref3_app\n {a1,a2,a3:t0p}{b:t0p}\n (cfun3(a1, a2, a3, b), a1, a2, a3): b = \"mac#%\"\n\/\/\noverload cloref_app with cloref0_app\noverload cloref_app with cloref1_app\noverload cloref_app with cloref2_app\noverload cloref_app with cloref3_app\n\/\/\n(* ****** ****** *)\n\n(* end of [basics_scm.sats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"262567b22131eeb2934500a4c2c25e02dfe5794a","subject":"Updating: adding M-Check\/Peterson","message":"Updating: adding M-Check\/Peterson\n","repos":"bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib","old_file":"projects\/MEDIUM\/M-Check\/SCRATCH\/Peterson.dats","new_file":"projects\/MEDIUM\/M-Check\/SCRATCH\/Peterson.dats","new_contents":"(* ****** ****** *)\n\/\/\n\/\/ Author: Hongwei Xi\n\/\/ Authoremail: gmhwxiATgmailDOTcom\n\/\/ Start time: December, 2015\n\/\/\n(* ****** ****** *)\n\n(*\n\/\/\n\/\/ the shared variables, booleans\nbool turn, flag[2];\nbyte ncrit; \/\/ number of procs in critical section\n\/\/\n*)\n\n(* ****** ****** *)\n\n(*\n\/\/\n\/\/ two processes\n\/\/\nactive[2]\nproctype user()\n{\n assert(_pid == 0 || _pid == 1);\n again:\n flag[_pid] = 1; turn = _pid;\n (flag[1 - _pid] == 0 || turn == 1 - _pid);\n\/\/\n ncrit++;\n assert(ncrit == 1); \/\/ critical section\n ncrit--;\n\/\/\n flag[_pid] = 0; goto again\n}\n*)\n\n(* ****** ****** *)\n\/\/\nabstype\npid_type(i:int)\n\/\/\ntypedef\npid(i:int) = pid_type(i)\n\/\/\ntypedef pid = [i:nat] pid(i)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\npid2int{i:nat}(pid(i)): int(i)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\npromela$self_get_pid(): pid\n\/\/\nextern\nfun\npromela$assert{b:bool}(bool(b)): [b==true] void\n\/\/\n(* ****** ****** *)\n \nextern\nfun\npromela$wait_until(() -> bool): void\n \n(* ****** ****** *)\n\/\/\nextern\nfun\nproc$user(): void\n\/\/\n\/\/\nsortdef two = {a:nat | a < 2}\n\/\/\nextern\nfun\nflag_get{i:two}(pid(i), int(1-i)): bool\nand\nflag_set{i:two}(pid(i), int( i ), bool): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun turn_get(): natLt(2)\nextern\nfun turn_set{i:two}(pid(i), int(1-i)): void\n\/\/\n(* ****** ****** *)\n\nimplement\nproc$user() = let\n\/\/\nval pid =\n promela$self_get_pid()\n\/\/\nval i = pid2int(pid)\n\/\/\nval ((*void*)) =\n promela$assert((i = 0) + (i = 1))\n\/\/\nfun\nloop\n(\n\/\/ argless\n) : void = loop() where\n{\n val i0 = i\n val i1 = 1 - i\n val () = turn_set(pid, i1)\n val () = flag_set(pid, i0, true)\n val () = promela$wait_until(lam() => (flag_get(pid, i1)=false)+(turn_get()=i0))\n\/\/\n\/\/ This is a critial section\n\/\/\n val () = flag_set(pid, i0, false)\n}\n\/\/\nin\n loop()\nend \/\/ end of [proce$user]\n\n(* ****** ****** *)\n\n(* end of [Peterson.dats] *)\n","old_contents":"(* ****** ****** *)\n\n(*\n\/\/\n\/\/ the shared variables, booleans\nbool turn, flag[2];\nbyte ncrit; \/\/ number of procs in critical section\n\/\/\n*)\n\n(* ****** ****** *)\n\n(*\n\/\/\n\/\/ two processes\n\/\/\nactive[2]\nproctype user()\n{\n assert(_pid == 0 || _pid == 1);\n again:\n flag[_pid] = 1; turn = _pid;\n (flag[1 - _pid] == 0 || turn == 1 - _pid);\n\/\/\n ncrit++;\n assert(ncrit == 1); \/\/ critical section\n ncrit--;\n\/\/\n flag[_pid] = 0; goto again\n}\n*)\n\n(* ****** ****** *)\n\/\/\nabstype\npid_type(i:int)\n\/\/\ntypedef\npid(i:int) = pid_type(i)\n\/\/\ntypedef pid = [i:nat] pid(i)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\npid2int{i:nat}(pid(i)): int(i)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\npromela$self_get_pid(): pid\n\/\/\nextern\nfun\npromela$assert{b:bool}(bool(b)): [b==true] void\n\/\/\n(* ****** ****** *)\n \nextern\nfun\npromela$wait_until(() -> bool): void\n \n(* ****** ****** *)\n\/\/\nextern\nfun\nproc$user(): void\n\/\/\n\/\/\nsortdef two = {a:nat | a < 2}\n\/\/\nextern\nfun\nflag_get{i:two}(pid(i), int(1-i)): bool\nand\nflag_set{i:two}(pid(i), int( i ), bool): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun turn_get(): natLt(2)\nextern\nfun turn_set{i:two}(pid(i), int(1-i)): void\n\/\/\n(* ****** ****** *)\n\nimplement\nproc$user() = let\n\/\/\nval pid =\n promela$self_get_pid()\n\/\/\nval i = pid2int(pid)\n\/\/\nval ((*void*)) =\n promela$assert((i = 0) + (i = 1))\n\/\/\nfun\nloop\n(\n\/\/ argless\n) : void = loop() where\n{\n val i0 = i\n val i1 = 1 - i\n val () = turn_set(pid, i1)\n val () = flag_set(pid, i0, true)\n val () = promela$wait_until(lam() => (flag_get(pid, i1)=false)+(turn_get()=i0))\n\/\/\n\/\/ This is a critial section\n\/\/\n val () = flag_set(pid, i0, false)\n}\n\/\/\nin\n loop()\nend \/\/ end of [proce$user]\n\n(* ****** ****** *)\n\n(* end of [Peterson.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"929481925e43b55c4afce0aaa83ea996ea1c6adf","subject":"Small improvements.","message":"Small improvements.\n","repos":"bbarker\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib","old_file":"projects\/MEDIUM\/ATS-parse-emit\/CIL\/atsparemit_emit_cil.dats","new_file":"projects\/MEDIUM\/ATS-parse-emit\/CIL\/atsparemit_emit_cil.dats","new_contents":"(* ****** ****** *)\n\/\/\n\/\/ ATS-parse-emit-python\n\/\/\n(* ****** ****** *)\n\/\/\n\/\/ AS-2014-08-17: start\n\/\/\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_staload.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\nUN = \"prelude\/SATS\/unsafe.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/atsparemit.sats\"\nstaload \".\/atsparemit_syntax.sats\"\nstaload \".\/atsparemit_syntax_cil.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/atsparemit_emit.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/atsparemit_typedef.dats\"\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_ENDL (out) = emit_text (out, \"\\n\")\n\n(* ****** ****** *)\n\nimplement\nemit_SPACE (out) = emit_text (out, \" \")\n\n(* ****** ****** *)\n\nimplement\nemit_SHARP (out) = emit_text (out, \"#\")\n\n(* ****** ****** *)\n\nimplement\nemit_COLON (out) = emit_text (out, \":\")\n\n(* ****** ****** *)\n\nimplement\nemit_LPAREN (out) = emit_text (out, \"(\")\nimplement\nemit_RPAREN (out) = emit_text (out, \")\")\n\n(* ****** ****** *)\n\nimplement\nemit_LBRACE (out) = emit_text (out, \"{\")\nimplement\nemit_RBRACE (out) = emit_text (out, \"}\")\n\n\n(* ****** ****** *)\n\nimplement\nemit_LBRACKET (out) = emit_text (out, \"[\")\nimplement\nemit_RBRACKET (out) = emit_text (out, \"]\")\n\n(* ****** ****** *)\n\nimplement\nemit_flush (out) = fileref_flush (out)\nimplement\nemit_newline (out) = fprint_newline (out)\n\n(* ****** ****** *)\n\/\/\nimplement\nemit_int (out, x) = fprint_int (out, x)\n\/\/\nimplement\nemit_text (out, x) = fprint_string (out, x)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nemit_symbol (out, x) =\n fprint_string (out, symbol_get_name (x))\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_PMVint\n (out, tok) = let\n\/\/\nval-T_INT(base, rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVint]\n\n(* ****** ****** *)\n\nimplement\nemit_PMVi0nt\n (out, tok) = let\n\/\/\nval-T_INT(base, rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVi0nt]\n\n(* ****** ****** *)\n\/\/\nimplement\nemit_PMVbool\n (out, tfv) =\n(\n emit_text (out, if tfv then \"1\" else \"0\")\n) (* end of [emit_PMVbool] *)\n\/\/\n(* ****** ****** *)\nimplement\nemit_PMVstring\n (out, tok) = let\n\/\/\nval-T_STRING(rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVstring]\n\n(* ****** ****** *)\n\/\/\nimplement\nemit_i0de\n (out, id) = emit_symbol (out, id.i0de_sym)\nimplement\nemit_label\n (out, lab) = emit_symbol (out, lab.i0de_sym)\nfun\nemit_label_mark\n (out, lab) =\n {\n val () = emit_label (out, lab)\n val () = emit_COLON (out)\n val () = emit_ENDL (out)\n }\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_extcode\n (out, toks) = let\n\/\/\nfun\nauxtok\n(\n out: FILEref, tok: token\n) : void =\n(\ncase+\ntok.token_node of\n\/\/\n| T_KWORD _ => ()\n\/\/\n| T_ENDL () => emit_ENDL (out)\n| T_SPACES (cs) => emit_text (out, cs)\n\/\/\n| T_COMMENT_line () =>\n emit_text (out, \"\/\/ COMMENT_line\\n\")\n| T_COMMENT_block () => ((*ignored*))\n\/\/\n| T_INT (_, rep) => emit_text (out, rep)\n\/\/\n| T_STRING (str) => emit_text (out, str)\n\/\/\n| T_IDENT_alp (name) => emit_text (out, name)\n| T_IDENT_srp (name) => emit_text (out, name) \/\/ FIXME?\n\/\/\n| T_IDENT_sym (name) => emit_text (out, name)\n\/\/\n| T_LPAREN () => emit_LPAREN (out)\n| T_RPAREN () => emit_RPAREN (out)\n\/\/\n| T_LBRACKET () => emit_LBRACKET (out)\n| T_RBRACKET () => emit_RBRACKET (out)\n\/\/\n| T_LBRACE () => emit_LBRACE (out)\n| T_RBRACE () => emit_RBRACE (out)\n\/\/\n| T_LT () => emit_text (out, \"<\")\n| T_GT () => emit_text (out, \">\")\n\/\/\n| T_MINUS () => emit_text (out, \"-\")\n\/\/\n| T_COLON () => emit_text (out, \":\")\n\/\/\n| T_COMMA () => emit_text (out, \",\")\n| T_SEMICOLON () => emit_text (out, \";\")\n\/\/\n| T_SLASH () => emit_text (out, \"\/\")\n\/\/\n| _ (*unrecognized*) =>\n {\n val () = fprint! (out, \"TOKERR(\", tok, \")\")\n }\n) (* end of [auxtok] *)\n\/\/\nin\n\/\/\ncase+ toks of\n| list_nil () => ()\n| list_cons (tok, toks) =>\n (\n auxtok (out, tok); emit_extcode (out, toks)\n ) (* end of [list_cons] *)\n\/\/\nend \/\/ end of [emit_extcode]\n\n(* ****** ****** *)\n\/\/\nextern\nfun emit_instrlst\n (out: FILEref, inss: instrlst, labbeg: label, labend: label) : void\n\/\/\nextern\nfun\nemit_s0exp : emit_type (s0exp)\nextern\nfun\nemit_s0explst : emit_type (s0explst)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nemit_s0exp\n (out, s0e) = let\n\/\/\n\/\/\nin\n\/\/\ncase+\ns0e.s0exp_node of\n\/\/\n| S0Eide (id) => emit_symbol (out, id)\n| S0Elist (s0es) => () \/\/ shouldn't happen? marked as \"temp\"\n| S0Eappid (id, s0es) =>\n \/\/ FIXME: what about other types? e.g. array types? struct types?\n () where {\n val () = emit_i0de (out, id)\n val () = emit_LPAREN (out)\n val () = emit_s0explst (out, s0es)\n val () = emit_RPAREN (out)\n }\n\/\/\nend \/\/ end of [emit_s0exp]\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_s0explst\n (out, s0es) = let\n\/\/\nfun\nloop\n(\n out: FILEref, s0es: s0explst, i: int\n) : void =\n(\ncase+ s0es of\n| list_nil () => ()\n| list_cons (s0e, s0es) => let\n val () =\n if i > 0 then emit_text (out, \", \")\n \/\/ end of [val]\n in\n emit_s0exp (out, s0e); loop (out, s0es, i+1)\n end \/\/ end of [list_cons]\n)\n\/\/\nin\n loop (out, s0es, 0)\nend \/\/ end of [emit_s0explst]\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nfunlab_get_index (fl: label): int\nextern\nfun\ntmplab_get_index (lab: label): int\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_f0arglst_get (): f0arglst\nextern\nfun\nthe_f0arglst_set (f0as: f0arglst): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_tmpdeclst_get (): tmpdeclst\nextern\nfun\nthe_tmpdeclst_set (tds: tmpdeclst): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_funbodylst_get (): instrlst\nextern\nfun\nthe_funbodylst_set (inss: instrlst): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_branchlablst_get (): labelist\nextern\nfun\nthe_branchlablst_set (labs: labelist): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_caseofseqlst_get (): instrlst\nextern\nfun\nthe_caseofseqlst_set (inss: instrlst): void\n\/\/\n(* ****** ****** *)\n\nlocal\n\/\/\nval the_f0arglst = ref (list_nil)\nval the_tmpdeclst = ref (list_nil)\n\/\/\nval the_funbodylst = ref (list_nil)\n\/\/\nval the_branchlablst = ref (list_nil)\nval the_caseofseqlst = ref (list_nil)\n\/\/\nin (* in-of-local *)\n\nimplement\nthe_f0arglst_get () = !the_f0arglst\nimplement\nthe_f0arglst_set (xs) = !the_f0arglst := xs\n\nimplement\nthe_tmpdeclst_get () = !the_tmpdeclst\nimplement\nthe_tmpdeclst_set (xs) = !the_tmpdeclst := xs\n\nimplement\nthe_funbodylst_get () = !the_funbodylst\nimplement\nthe_funbodylst_set (xs) = !the_funbodylst := xs\n\nimplement\nthe_branchlablst_get () = !the_branchlablst\nimplement\nthe_branchlablst_set (xs) = !the_branchlablst := xs\n\nimplement\nthe_caseofseqlst_get () = !the_caseofseqlst\nimplement\nthe_caseofseqlst_set (xs) = !the_caseofseqlst := xs\n\nend \/\/ end of [local]\n\n(* ******* ****** *)\n\nlocal\n\nfun\nloop\n(\n out: FILEref, d0es: d0explst, i: int\n) : void =\n(\ncase+ d0es of\n| list_nil () => ()\n| list_cons (d0e, d0es) => let\n val () =\n if i > 0 then emit_newline (out)\n \/\/ end of [val]\n in\n emit_d0exp (out, d0e);\n emit_newline (out);\n loop (out, d0es, i+1)\n end \/\/ end of [list_cons]\n)\n\nin (* in-of-local *)\n\nimplement\nemit_d0explst (out, d0es) = loop (out, d0es, 0)\nimplement\nemit_d0explst_1 (out, d0es) = loop (out, d0es, 1)\n\nend \/\/ end of [local]\n\n(* ******* ****** *)\n\nimplement\nemit_d0exp\n (out, d0e) = let\nin\n\/\/\ncase+\nd0e.d0exp_node of\n\/\/\n| D0Eide (id) =>\n {\n val () =\n if tmpvar_is_arg (id)\n then emit_text (out, \"ldarg\")\n else emit_text (out, \"ldloc\")\n \/\/ end of [val]\n val () = emit_SPACE (out)\n val () = emit_symbol (out, id)\n }\n\/\/\n| D0Eappid (id, d0es) =>\n {\n val () = emit_d0explst (out, d0es)\n val () = emit_text (out, \"call\")\n val () = emit_SPACE (out)\n val () = emit_i0de (out, id) \/\/ FIXME: need also type of [id]!\n }\n\/\/\n\/\/\n| ATSPMVint (tok) =>\n {\n val () = emit_text (out, \"ldc.i4\")\n val () = emit_SPACE (out)\n val () = emit_PMVint (out, tok)\n } (* end of [ATSPMVint] *)\n| ATSPMVi0nt (tok) =>\n {\n val () = emit_text (out, \"ldc.i4\")\n val () = emit_SPACE (out)\n val () = emit_PMVi0nt (out, tok)\n } (* end of [ATSPMVi0nt] *)\n\/\/\n| ATSPMVbool (tfv) =>\n {\n val () = emit_text (out, \"ldc.i4\")\n val () = emit_SPACE (out)\n val () = emit_PMVbool (out, tfv)\n } (* end of [ATSPMVbool] *)\n\/\/\n| ATSPMVstring (tok) =>\n {\n val () = emit_text (out, \"ldstr\")\n val () = emit_SPACE(out)\n val () = emit_PMVstring (out, tok)\n } (* end of [ATSPMVstring] *)\n\/\/\n| ATSPMVf0loat (tok) => emit_text (out, \"ATSPMVf0loat(...)\")\n\/\/\n| _ => ()\n\/\/\nend \/\/ end of [emit_d0exp]\n\n(* ****** ****** *)\n\/\/\nextern\nfun emit_f0arg : emit_type (f0arg)\nextern\nfun emit_f0marg : emit_type (f0marg)\nextern\nfun emit_f0head : emit_type (f0head)\n\/\/\nextern\nfun emit_f0body : emit_type (f0body)\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_f0arg\n (out, f0a) = let\nin\n\/\/\ncase+\nf0a.f0arg_node of\n\/\/\n| F0ARGnone s0e => emit_text (out, \"__NONE__\") \/\/ FIXME: how to emit type decl?\n| F0ARGsome (id, s0e) =>\n {\n val () = emit_s0exp (out, s0e)\n val () = emit_SPACE (out)\n val () = emit_i0de (out, id)\n } (* end of [F0ARGsome] *)\n\/\/\nend \/\/ end of [emit_f0arg]\n\n(* ****** ****** *)\n\nimplement\nemit_f0marg\n (out, f0ma) = let\n\/\/\nfun\nloop\n(\n out: FILEref, f0as: f0arglst, i: int\n) : void =\n(\ncase+ f0as of\n| list_nil () => ()\n| list_cons (f0a, f0as) => let\n val () =\n if i > 0 then emit_text (out, \", \")\n \/\/ end of [val]\n in\n emit_f0arg (out, f0a); loop (out, f0as, i+1)\n end \/\/ end of [list_cons]\n)\n\/\/\nin\n loop (out, f0ma.f0marg_node, 0)\nend \/\/ end of [emit_f0marg]\n\n(* ****** ****** *)\n\nimplement\nemit_f0head\n (out, fhd) = let\n\/\/\nval f0as =\n f0head_get_f0arglst (fhd)\n\/\/\nval () = the_f0arglst_set (f0as)\n\/\/\nin\n\/\/\ncase+\nfhd.f0head_node of\n| F0HEAD\n (id(*name of function*), f0ma(*list of arguments*), res(*result type*)) =>\n {\n val () = emit_s0exp (out, res)\n val () = emit_SPACE (out)\n val () = emit_i0de (out, id)\n val () = emit_LPAREN (out)\n val () = emit_f0marg (out, f0ma)\n val () = emit_RPAREN (out)\n }\n\/\/\nend \/\/ end of [emit_f0head]\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit_tmpdeclst\n (out: FILEref, tds: tmpdeclst): void\n\/\/\nimplement\nemit_tmpdeclst\n (out, tds) = let\n\/\/\nfun auxlst\n(\n out: FILEref, tds: tmpdeclst, i: int\n) : void =\n(\ncase+ tds of\n| list_nil () => ()\n| list_cons (td, tds) =>\n (\n case+ td.tmpdec_node of\n | TMPDECnone\n (tmp) => auxlst (out, tds, i) \/\/ probably ATStmpdec_void()\n | TMPDECsome\n (tmp, s0e) => let\n val () =\n if i > 0 then\n emit_text(out, \", \")\n \/\/ end of [val]\n val () = emit_s0exp (out, s0e)\n val () = emit_SPACE (out)\n val () = emit_i0de (out, tmp)\n val () = emit_newline (out)\n in\n auxlst (out, tds, i+1)\n end \/\/ end of [TMPDECsome]\n ) (* end of [list_cons] *)\n)\n\/\/\nin\n auxlst (out, tds, 0)\nend \/\/ end of [emit_tmpdeclst_initize]\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun emit_instr_0\n (out: FILEref, ins: instr): void\n\/\/\nimplement\nemit_instr_0\n (out, ins0) = let\nin\n\/\/\ncase+\nins0.instr_node of\n\/\/\n| ATSreturn (tmp) =>\n {\n val () =\n if tmpvar_is_arg (tmp.i0de_sym)\n then emit_text (out, \"ldarg\")\n else emit_text (out, \"ldloc\")\n \/\/ end of [val]\n val () = emit_SPACE (out)\n val () = emit_i0de (out, tmp)\n val () = emit_newline (out)\n val () = emit_text (out, \"ret\")\n }\n\/\/\n| ATSreturn_void (tmp) =>\n {\n val () = emit_text (out, \"ret\")\n }\n\/\/\n| _ => emit_text (out, \"**INSTR**\")\n\/\/\nend \/\/ end of [emit_instr_0]\n\/\/\nextern\nfun emit_instr\n (out: FILEref, ins: instr, labthis: label, labnext: label) : void\n\/\/\nimplement\nemit_instr\n (out, ins0, labthis, labnext) = let\nin\n\/\/\ncase+\nins0.instr_node of\n\/\/\n| ATSif\n (\n d0e(*test*), inss(*then*), inssopt(*else*)\n ) =>\n (\n emit_d0exp (out, d0e);\n emit_newline (out);\n \n case+ inssopt of\n | Some (inss2) =>\n {\n val () = emit_text (out, \"brfalse\")\n val () = emit_SPACE (out)\n val L1 = label_for_instrlst (inss2)\n val () = emit_label (out, L1)\n val () = emit_ENDL (out)\n val L0 = label_for_instrlst (inss)\n val brlab = make_label (ins0.instr_loc)\n val () = emit_instrlst (out, inss, L0, brlab)\n val () = emit_label_mark (out, brlab)\n val () = emit_text (out, \"br\")\n val () = emit_SPACE (out)\n val () = emit_label (out, labnext)\n val () = emit_ENDL (out)\n val () = emit_instrlst (out, inss2, L1, labnext)\n }\n | None () =>\n {\n val () = emit_text (out, \"brfalse\")\n val () = emit_SPACE (out)\n val () = emit_label (out, labnext)\n val () = emit_ENDL (out)\n val () = emit_instrlst (out, inss, labthis, labnext)\n }\n )\n\/\/ TODO: ATSifthen, ATSifnthen, ATScaseofseq, ATSbranchseq\n\/\/ TODO: ATSlinepragma\n\/\/\n| ATSreturn (tmp) =>\n {\n val () =\n if tmpvar_is_arg (tmp.i0de_sym)\n then emit_text (out, \"ldarg\")\n else emit_text (out, \"ldloc\")\n \/\/ end of [val]\n val () = emit_SPACE (out)\n val () = emit_i0de (out, tmp)\n val () = emit_newline (out)\n val () = emit_text (out, \"ret\")\n }\n\/\/\n| ATSreturn_void (tmp) =>\n {\n val () = emit_text (out, \"ret\")\n }\n\/\/\n(*\n| ATSlinepragma (line, file) =>\n {\n val () = emit_text (out, \".line\")\n val () = emit_SPACE (out)\n val-T_INT(_, lpos) = line.token_node\n val () = emit_text (out, lpos)\n val () = emit_SPACE (out)\n val-T_STRING(filnam) = file.token_node\n val () = emit_text (out, filnam)\n }\n*)\n\/\/\n(*\n| ATSINSlab (lab) =>\n {\n val () = emit_label_mark (out, lab)\n }\n*)\n\/\/\n| ATSINSgoto (lab) =>\n {\n val () = emit_text (out, \"br\")\n val () = emit_SPACE (out)\n val () = emit_label (out, lab)\n }\n\/\/\n(*\n| ATSINSflab (flab) =>\n {\n val () = emit_label_mark (out, flab)\n }\n*)\n\/\/\n| ATSINSfgoto (flab) =>\n {\n val () = emit_text (out, \"br\")\n val () = emit_SPACE (out)\n val () = emit_label (out, flab)\n }\n\/\/\n| ATSINSmove (tmp, d0e) =>\n {\n val () = emit_d0exp (out, d0e)\n val () = emit_newline (out)\n val () =\n if tmpvar_is_arg (tmp.i0de_sym)\n then emit_text (out, \"starg\")\n else emit_text (out, \"stloc\")\n \/\/ end of [val] \n val () = emit_SPACE (out)\n val () = emit_i0de (out, tmp)\n } (* end of [ATSINSmove] *)\n| ATSINSmove_void (_, d0e) =>\n {\n val () = emit_d0exp (out, d0e)\n } (* end of [ATSINSmove_void] *)\n\/\/ TODO: ATSdynload0, ATSdynload1, ATSdynloadset\n\/\/\n| _ =>\n {\n val () = emit_text (out, \"**INSTR**\")\n }\n\/\/\nend \/\/ end of [emit_instr]\n\n(* ****** ****** *)\nimplement\nemit_instrlst\n(\n out, inss, labthis, lablast\n) = (\n\/\/\ncase+ inss of\n| list_nil () => ()\n| list_cons (ins0, inss) => let\n \/\/\n \/\/\n in\n case+ ins0.instr_node of\n | ATSINSlab (label) =>\n (\n emit_instrlst (out, inss, label, lablast)\n )\n | ATSINSflab (label) =>\n (\n emit_instrlst (out, inss, label, lablast)\n )\n | ATSlinepragma (line, file) =>\n {\n val () = emit_text (out, \".line\")\n val () = emit_SPACE (out)\n val-T_INT(_, lpos) = line.token_node\n val () = emit_text (out, lpos)\n val () = emit_SPACE (out)\n val-T_STRING(filnam) = file.token_node\n val () = emit_text (out, filnam)\n val () = emit_ENDL (out)\n val () = emit_instrlst (out, inss, labthis, lablast)\n }\n | _(*other*) =>\n {\n val () = emit_label_mark (out, labthis)\n val labnext =\n (\n case+ inss of\n | list_nil () => lablast\n | _ => label_for_instrlst (inss)\n ) (* end of [val] *)\n val () = emit_instr (out, ins0, labthis, labnext)\n val () = emit_ENDL (out)\n val () = emit_instrlst (out, inss, labnext, lablast)\n }\n end \/\/ end of [let]\n\/\/\n) (* end of [emit_instrlst] *)\n\n(* ****** ****** *)\n\/\/\nextern\nfun emit_ATSfunbodyseq\n (out: FILEref, ins: instr, labnext: label) : void\n\/\/\nimplement\nemit_ATSfunbodyseq\n (out, ins, labnext) = let\n\/\/\nval-ATSfunbodyseq (inss) = ins.instr_node\nval L1 = label_for_instrlst (inss)\n\/\/\nin\n emit_instrlst (out, inss, L1, labnext)\nend \/\/ end of [emit_ATSfunbodyseq]\n\n(* ****** ****** *)\n\/\/\nextern\nfun emit_f0body_0 : emit_type (f0body)\n\/\/\nimplement\nemit_f0body_0\n (out, fbody) = let\n\/\/\nfun\nauxlst\n(\n out: FILEref, inss: instrlst\n) : void =\n(\ncase+ inss of\n| list_nil () => ()\n| list_cons\n (ins0, inss1) => let\n val-list_cons (ins1, inss2) = inss1\n val labnext = label_for_instrlst (inss1)\n val () = emit_ATSfunbodyseq (out, ins0, labnext)\n val () = emit_label_mark (out, labnext)\n \/\/ FIXME: inss2 is EMPTY! what now?\n val lablast =\n (\n case+ inss2 of\n | list_nil () => i0de_make_string (location_dummy, \"LASTLABEL\")\n | _ => label_for_instrlst (inss2)\n )\n val () = emit_instr (out, ins1, labnext, lablast)\n in\n auxlst (out, inss2)\n end \/\/ end of [list_cons]\n) (* end of [auxlst] *)\n\/\/\nin\n\/\/\ncase+\nfbody.f0body_node of\n\/\/\n| F0BODY (tds, inss) => let\n val () = label_reset ()\n in\n auxlst (out, inss)\n end \/\/ end of [auxlst]\n\/\/\nend \/\/ end of [emit_f0body_0]\n\n(* ****** ****** *)\nimplement\nemit_f0body\n (out, fbody) = let\n\/\/\nval tmpdecs =\n f0body_get_tmpdeclst (fbody)\n\/\/\nval () = the_tmpdeclst_set (tmpdecs)\nval () = emit_LBRACE (out)\nval () = emit_newline (out)\n\/\/ TODO: how to compute maxstack?\nval () = emit_text (out, \".maxstack 16\")\nval () = emit_newline (out)\n\/\/ emit locals\nval () = emit_text (out, \".locals\")\nval () = emit_SPACE (out)\n(*\nval () = emit_text (out, \"init\")\nval () = emit_SPACE (out)\n*)\nval () = emit_LPAREN (out)\nval () = emit_newline (out)\nval () = emit_tmpdeclst (out, tmpdecs)\nval () = emit_RPAREN (out)\nval () = emit_newline (out)\n\nval () = emit_f0body_0 (out, fbody)\nval () = emit_newline (out)\nval () = emit_RBRACE (out)\nin\n\/\/\n\/\/\nend \/\/ end of [emit_f0body]\n\n(* ****** ****** *)\n\nimplement\nemit_f0decl\n (out, fdec) = let\nin\n\/\/\ncase+\nfdec.f0decl_node of\n| F0DECLnone (fhd) =>\n \/\/ does this actually mean function declaration (e.g. forward function decl)?\n ()\n| F0DECLsome (fhd, fbody) =>\n {\n val () = emit_text (out, \".method\")\n val () = emit_SPACE (out)\n val () = emit_text (out, \"static\")\n \/\/ TODO: public\/private?\n \/\/ static -> private\n val () = emit_SPACE (out)\n val () = emit_text (out, \"public\")\n val () = emit_SPACE (out)\n \/\/ FIXME: where is the type of this function??\n \/\/ TODO: use \n val () = emit_f0head (out, fhd)\n val () = emit_SPACE (out) \n val () = emit_text (out, \"cil\")\n val () = emit_SPACE (out)\n val () = emit_text (out, \"managed\")\n val () = emit_newline (out)\n val () = emit_f0body (out, fbody)\n val () = emit_newline (out)\n } (* end of [F0DECLsome] *)\n\/\/\nend \/\/ end of [emit_f0decl]\n\n(* ****** ****** *)\n\n\/\/\nextern\nfun\ntyrec_labsel\n (tyrec: tyrec, lab: symbol): int\n\/\/\nimplement\ntyrec_labsel\n (tyrec, lab) = let\n\/\/\nfun loop\n(\n xs: tyfldlst, i: int\n) : int =\n(\ncase+ xs of\n| list_cons (x, xs) => let\n val TYFLD (id, s0e) = x.tyfld_node\n in\n if lab = id.i0de_sym then i else loop (xs, i+1)\n end \/\/ end of [list_cons\n| list_nil ((*void*)) => ~1(*error*)\n)\n\/\/\nin\n loop (tyrec.tyrec_node, 0)\nend \/\/ end of [tyrec_labsel]\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_SELcon\n (out, d0e) = let\n\/\/\nval-ATSSELcon\n (d0rec, s0e, id) = d0e.d0exp_node\nval-S0Eide (name) = s0e.s0exp_node\nval-~Some_vt (s0rec) = typedef_search_opt (name)\n\/\/\nval index = tyrec_labsel (s0rec, id.i0de_sym)\n\/\/\nval () =\n emit_d0exp (out, d0rec)\n\/\/\nval () = emit_LBRACKET (out)\nval () = emit_int (out, index)\nval () = emit_RBRACKET (out)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit_SELcon]\n\n(* ****** ****** *)\n\nimplement\nemit_SELboxrec\n (out, d0e) = let\n\/\/\nval-ATSSELboxrec\n (d0rec, s0e, id) = d0e.d0exp_node\nval-S0Eide (name) = s0e.s0exp_node\nval-~Some_vt (s0rec) = typedef_search_opt (name)\n\/\/\nval index = tyrec_labsel (s0rec, id.i0de_sym)\n\/\/\nval () =\n emit_d0exp (out, d0rec)\n\/\/\nval () = emit_LBRACKET (out)\nval () = emit_int (out, index)\nval () = emit_RBRACKET (out)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit_SELboxrec]\n\n(* ****** ****** *)\n\/\/\n#define\nATSEXTCODE_BEG \"\/*\\nATSextcode_beg()\\n*\/\"\n#define\nATSEXTCODE_END \"\/*\\nATSextcode_end()\\n*\/\"\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_d0ecl\n (out, d0c) = let\nin\n\/\/\ncase+\nd0c.d0ecl_node of\n\/\/\n| D0Cinclude include =>\n {\n val () = emit_text (out, \"#include\")\n val () = emit_SPACE (out)\n val-T_STRING(filnam) = include.token_node\n val () = emit_text (out, filnam)\n val () = emit_newline (out)\n }\n\/\/\n| D0Cifdef (i0de, d0eclist) =>\n {\n val () = emit_text (out, \"#ifdef\")\n val () = emit_SPACE (out)\n val () = emit_newline (out)\n val () = emit_text (out, \"#endif\")\n val () = emit_newline (out)\n }\n| D0Cifndef (i0de, d0eclist) =>\n {\n val () = emit_text (out, \"#ifndef\")\n val () = emit_SPACE (out)\n val () = emit_newline (out)\n val () = emit_text (out, \"#endif\")\n val () = emit_newline (out)\n }\n\/\/\n| D0Ctypedef (id, def) =>\n {\n val () = typedef_insert (id.i0de_sym, def)\n \/\/ TODO: insert type (class) declaration\n } (* end of [D0Ctypedef] *)\n\/\/\n| D0Cdyncst_mac ide =>\n {\n val () = emit_text (out, \"dyncst_mac\")\n val () = emit_SPACE (out)\n val filnam = ide.i0de_sym\n val () = emit_symbol (out, filnam)\n val () = emit_ENDL (out)\n }\n| D0Cdyncst_extfun (i0de, s0explst, s0exp) =>\n {\n }\n| D0Cextcode (toks) =>\n {\n val () = emit_text (out, ATSEXTCODE_BEG)\n val () = emit_extcode (out, toks)\n val () = emit_text (out, ATSEXTCODE_END)\n }\n| D0Cclosurerize (_, _, _, _) => ()\n\/\/\n| D0Cfundecl (fk, f0d) => emit_f0decl (out, f0d)\n\/\/\nend \/\/ end of [emit_d0ecl]\n\n(* ****** ****** *)\n\nimplement\nemit_toplevel\n (out, d0cs) = let\n\/\/\nfun\nloop\n(\n out: FILEref, d0cs: d0eclist\n) : void =\n(\n\/\/\ncase+ d0cs of\n| list_nil () => ()\n| list_cons\n (d0c, d0cs) => let\n in\n emit_d0ecl (out, d0c); loop (out, d0cs)\n end \/\/ end of [list_cons]\n\/\/\n)\n\/\/\nin\n \/\/ TODO:\n \/\/ - emit assembly references\n \/\/ - emit .corflags, .subsystem\n \/\/ - emit .module \n \/\/ - where is the name of the source file (e.g. foo.dats)\n loop (out, d0cs)\nend \/\/ end of [emit_toplevel]\n\n(* ****** ****** *)\n\n(* end of [atsparemit_emit_cil.dats] *)\n","old_contents":"(* ****** ****** *)\n\/\/\n\/\/ ATS-parse-emit-python\n\/\/\n(* ****** ****** *)\n\/\/\n\/\/ AS-2014-08-17: start\n\/\/\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_staload.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\nUN = \"prelude\/SATS\/unsafe.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/atsparemit.sats\"\nstaload \".\/atsparemit_syntax.sats\"\nstaload \".\/atsparemit_syntax_cil.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/atsparemit_emit.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/atsparemit_typedef.dats\"\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_ENDL (out) = emit_text (out, \"\\n\")\n\n(* ****** ****** *)\n\nimplement\nemit_SPACE (out) = emit_text (out, \" \")\n\n(* ****** ****** *)\n\nimplement\nemit_SHARP (out) = emit_text (out, \"#\")\n\n(* ****** ****** *)\n\nimplement\nemit_COLON (out) = emit_text (out, \":\")\n\n(* ****** ****** *)\n\nimplement\nemit_LPAREN (out) = emit_text (out, \"(\")\nimplement\nemit_RPAREN (out) = emit_text (out, \")\")\n\n(* ****** ****** *)\n\nimplement\nemit_LBRACE (out) = emit_text (out, \"{\")\nimplement\nemit_RBRACE (out) = emit_text (out, \"}\")\n\n\n(* ****** ****** *)\n\nimplement\nemit_LBRACKET (out) = emit_text (out, \"[\")\nimplement\nemit_RBRACKET (out) = emit_text (out, \"]\")\n\n(* ****** ****** *)\n\nimplement\nemit_flush (out) = fileref_flush (out)\nimplement\nemit_newline (out) = fprint_newline (out)\n\n(* ****** ****** *)\n\/\/\nimplement\nemit_int (out, x) = fprint_int (out, x)\n\/\/\nimplement\nemit_text (out, x) = fprint_string (out, x)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nemit_symbol (out, x) =\n fprint_string (out, symbol_get_name (x))\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_PMVint\n (out, tok) = let\n\/\/\nval-T_INT(base, rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVint]\n\n(* ****** ****** *)\n\nimplement\nemit_PMVi0nt\n (out, tok) = let\n\/\/\nval-T_INT(base, rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVi0nt]\n\n(* ****** ****** *)\n\/\/\nimplement\nemit_PMVbool\n (out, tfv) =\n(\n emit_text (out, if tfv then \"1\" else \"0\")\n) (* end of [emit_PMVbool] *)\n\/\/\n(* ****** ****** *)\nimplement\nemit_PMVstring\n (out, tok) = let\n\/\/\nval-T_STRING(rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVstring]\n\n(* ****** ****** *)\n\/\/\nimplement\nemit_i0de\n (out, id) = emit_symbol (out, id.i0de_sym)\nimplement\nemit_label\n (out, lab) = emit_symbol (out, lab.i0de_sym)\nfun\nemit_label_mark\n (out, lab) =\n {\n val () = emit_label (out, lab)\n val () = emit_COLON (out)\n val () = emit_ENDL (out)\n }\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_extcode\n (out, toks) = let\n\/\/\nfun\nauxtok\n(\n out: FILEref, tok: token\n) : void =\n(\ncase+\ntok.token_node of\n\/\/\n| T_KWORD _ => ()\n\/\/\n| T_ENDL () => emit_ENDL (out)\n| T_SPACES (cs) => emit_text (out, cs)\n\/\/\n| T_COMMENT_line () =>\n emit_text (out, \"\/\/ COMMENT_line\\n\")\n| T_COMMENT_block () => ((*ignored*))\n\/\/\n| T_INT (_, rep) => emit_text (out, rep)\n\/\/\n| T_STRING (str) => emit_text (out, str)\n\/\/\n| T_IDENT_alp (name) => emit_text (out, name)\n| T_IDENT_srp (name) => emit_text (out, name) \/\/ FIXME?\n\/\/\n| T_IDENT_sym (name) => emit_text (out, name)\n\/\/\n| T_LPAREN () => emit_LPAREN (out)\n| T_RPAREN () => emit_RPAREN (out)\n\/\/\n| T_LBRACKET () => emit_LBRACKET (out)\n| T_RBRACKET () => emit_RBRACKET (out)\n\/\/\n| T_LBRACE () => emit_LBRACE (out)\n| T_RBRACE () => emit_RBRACE (out)\n\/\/\n| T_LT () => emit_text (out, \"<\")\n| T_GT () => emit_text (out, \">\")\n\/\/\n| T_MINUS () => emit_text (out, \"-\")\n\/\/\n| T_COLON () => emit_text (out, \":\")\n\/\/\n| T_COMMA () => emit_text (out, \",\")\n| T_SEMICOLON () => emit_text (out, \";\")\n\/\/\n| T_SLASH () => emit_text (out, \"\/\")\n\/\/\n| _ (*unrecognized*) =>\n {\n val () = fprint! (out, \"TOKERR(\", tok, \")\")\n }\n) (* end of [auxtok] *)\n\/\/\nin\n\/\/\ncase+ toks of\n| list_nil () => ()\n| list_cons (tok, toks) =>\n (\n auxtok (out, tok); emit_extcode (out, toks)\n ) (* end of [list_cons] *)\n\/\/\nend \/\/ end of [emit_extcode]\n\n(* ****** ****** *)\n\/\/\nextern\nfun emit_instrlst\n (out: FILEref, inss: instrlst, labbeg: label, labend: label) : void\n\/\/\nextern\nfun\nemit_s0exp : emit_type (s0exp)\nextern\nfun\nemit_s0explst : emit_type (s0explst)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nemit_s0exp\n (out, s0e) = let\n\/\/\n\/\/\nin\n\/\/\ncase+\ns0e.s0exp_node of\n\/\/\n| S0Eide (id) => emit_symbol (out, id)\n| S0Elist (s0es) => () \/\/ shouldn't happen? marked as \"temp\"\n| S0Eappid (id, s0es) =>\n \/\/ FIXME: what about other types? e.g. array types? struct types?\n () where {\n val () = emit_i0de (out, id)\n val () = emit_LPAREN (out)\n val () = emit_s0explst (out, s0es)\n val () = emit_RPAREN (out)\n }\n\/\/\nend \/\/ end of [emit_s0exp]\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_s0explst\n (out, s0es) = let\n\/\/\nfun\nloop\n(\n out: FILEref, s0es: s0explst, i: int\n) : void =\n(\ncase+ s0es of\n| list_nil () => ()\n| list_cons (s0e, s0es) => let\n val () =\n if i > 0 then emit_text (out, \", \")\n \/\/ end of [val]\n in\n emit_s0exp (out, s0e); loop (out, s0es, i+1)\n end \/\/ end of [list_cons]\n)\n\/\/\nin\n loop (out, s0es, 0)\nend \/\/ end of [emit_s0explst]\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nfunlab_get_index (fl: label): int\nextern\nfun\ntmplab_get_index (lab: label): int\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_f0arglst_get (): f0arglst\nextern\nfun\nthe_f0arglst_set (f0as: f0arglst): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_tmpdeclst_get (): tmpdeclst\nextern\nfun\nthe_tmpdeclst_set (tds: tmpdeclst): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_funbodylst_get (): instrlst\nextern\nfun\nthe_funbodylst_set (inss: instrlst): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_branchlablst_get (): labelist\nextern\nfun\nthe_branchlablst_set (labs: labelist): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_caseofseqlst_get (): instrlst\nextern\nfun\nthe_caseofseqlst_set (inss: instrlst): void\n\/\/\n(* ****** ****** *)\n\nlocal\n\/\/\nval the_f0arglst = ref (list_nil)\nval the_tmpdeclst = ref (list_nil)\n\/\/\nval the_funbodylst = ref (list_nil)\n\/\/\nval the_branchlablst = ref (list_nil)\nval the_caseofseqlst = ref (list_nil)\n\/\/\nin (* in-of-local *)\n\nimplement\nthe_f0arglst_get () = !the_f0arglst\nimplement\nthe_f0arglst_set (xs) = !the_f0arglst := xs\n\nimplement\nthe_tmpdeclst_get () = !the_tmpdeclst\nimplement\nthe_tmpdeclst_set (xs) = !the_tmpdeclst := xs\n\nimplement\nthe_funbodylst_get () = !the_funbodylst\nimplement\nthe_funbodylst_set (xs) = !the_funbodylst := xs\n\nimplement\nthe_branchlablst_get () = !the_branchlablst\nimplement\nthe_branchlablst_set (xs) = !the_branchlablst := xs\n\nimplement\nthe_caseofseqlst_get () = !the_caseofseqlst\nimplement\nthe_caseofseqlst_set (xs) = !the_caseofseqlst := xs\n\nend \/\/ end of [local]\n\n(* ******* ****** *)\n\nlocal\n\nfun\nloop\n(\n out: FILEref, d0es: d0explst, i: int\n) : void =\n(\ncase+ d0es of\n| list_nil () => ()\n| list_cons (d0e, d0es) => let\n val () =\n if i > 0 then emit_newline (out)\n \/\/ end of [val]\n in\n emit_d0exp (out, d0e);\n emit_newline (out);\n loop (out, d0es, i+1)\n end \/\/ end of [list_cons]\n)\n\nin (* in-of-local *)\n\nimplement\nemit_d0explst (out, d0es) = loop (out, d0es, 0)\nimplement\nemit_d0explst_1 (out, d0es) = loop (out, d0es, 1)\n\nend \/\/ end of [local]\n\n(* ******* ****** *)\n\nimplement\nemit_d0exp\n (out, d0e) = let\nin\n\/\/\ncase+\nd0e.d0exp_node of\n\/\/\n| D0Eide (id) =>\n {\n val () =\n if tmpvar_is_arg (id)\n then emit_text (out, \"ldarg\")\n else emit_text (out, \"ldloc\")\n \/\/ end of [val]\n val () = emit_SPACE (out)\n val () = emit_symbol (out, id)\n }\n\/\/\n| D0Eappid (id, d0es) =>\n {\n val () = emit_d0explst (out, d0es)\n val () = emit_text (out, \"call\")\n val () = emit_SPACE (out)\n val () = emit_i0de (out, id) \/\/ FIXME: need also type of [id]!\n }\n\/\/\n\/\/\n| ATSPMVint (tok) =>\n {\n val () = emit_text (out, \"ldc.i4\")\n val () = emit_SPACE (out)\n val () = emit_PMVint (out, tok)\n } (* end of [ATSPMVint] *)\n| ATSPMVi0nt (tok) =>\n {\n val () = emit_text (out, \"ldc.i4\")\n val () = emit_SPACE (out)\n val () = emit_PMVi0nt (out, tok)\n } (* end of [ATSPMVi0nt] *)\n\/\/\n| ATSPMVbool (tfv) =>\n {\n val () = emit_text (out, \"ldc.i4\")\n val () = emit_SPACE (out)\n val () = emit_PMVbool (out, tfv)\n } (* end of [ATSPMVbool] *)\n\/\/\n| ATSPMVstring (tok) =>\n {\n val () = emit_text (out, \"ldstr\")\n val () = emit_SPACE(out)\n val () = emit_PMVstring (out, tok)\n } (* end of [ATSPMVstring] *)\n\/\/\n| ATSPMVf0loat (tok) => emit_text (out, \"ATSPMVf0loat(...)\")\n\/\/\n| _ => ()\n\/\/\nend \/\/ end of [emit_d0exp]\n\n(* ****** ****** *)\n\/\/\nextern\nfun emit_f0arg : emit_type (f0arg)\nextern\nfun emit_f0marg : emit_type (f0marg)\nextern\nfun emit_f0head : emit_type (f0head)\n\/\/\nextern\nfun emit_f0body : emit_type (f0body)\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_f0arg\n (out, f0a) = let\nin\n\/\/\ncase+\nf0a.f0arg_node of\n\/\/\n| F0ARGnone s0e => emit_text (out, \"__NONE__\") \/\/ FIXME: how to emit type decl?\n| F0ARGsome (id, s0e) =>\n {\n val () = emit_s0exp (out, s0e)\n val () = emit_SPACE (out)\n val () = emit_i0de (out, id)\n } (* end of [F0ARGsome] *)\n\/\/\nend \/\/ end of [emit_f0arg]\n\n(* ****** ****** *)\n\nimplement\nemit_f0marg\n (out, f0ma) = let\n\/\/\nfun\nloop\n(\n out: FILEref, f0as: f0arglst, i: int\n) : void =\n(\ncase+ f0as of\n| list_nil () => ()\n| list_cons (f0a, f0as) => let\n val () =\n if i > 0 then emit_text (out, \", \")\n \/\/ end of [val]\n in\n emit_f0arg (out, f0a); loop (out, f0as, i+1)\n end \/\/ end of [list_cons]\n)\n\/\/\nin\n loop (out, f0ma.f0marg_node, 0)\nend \/\/ end of [emit_f0marg]\n\n(* ****** ****** *)\n\nimplement\nemit_f0head\n (out, fhd) = let\n\/\/\nval f0as =\n f0head_get_f0arglst (fhd)\n\/\/\nval () = the_f0arglst_set (f0as)\n\/\/\nin\n\/\/\ncase+\nfhd.f0head_node of\n| F0HEAD\n (id(*name of function*), f0ma(*list of arguments*), res(*result type*)) =>\n {\n val () = emit_s0exp (out, res)\n val () = emit_SPACE (out)\n val () = emit_i0de (out, id)\n val () = emit_LPAREN (out)\n val () = emit_f0marg (out, f0ma)\n val () = emit_RPAREN (out)\n }\n\/\/\nend \/\/ end of [emit_f0head]\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit_tmpdeclst\n (out: FILEref, tds: tmpdeclst): void\n\/\/\nimplement\nemit_tmpdeclst\n (out, tds) = let\n\/\/\nfun auxlst\n(\n out: FILEref, tds: tmpdeclst, i: int\n) : void =\n(\ncase+ tds of\n| list_nil () => ()\n| list_cons (td, tds) =>\n (\n case+ td.tmpdec_node of\n | TMPDECnone\n (tmp) => auxlst (out, tds, i) \/\/ probably ATStmpdec_void()\n | TMPDECsome\n (tmp, s0e) => let\n val () =\n if i > 0 then\n emit_text(out, \", \")\n \/\/ end of [val]\n val () = emit_s0exp (out, s0e)\n val () = emit_SPACE (out)\n val () = emit_i0de (out, tmp)\n val () = emit_newline (out)\n in\n auxlst (out, tds, i+1)\n end \/\/ end of [TMPDECsome]\n ) (* end of [list_cons] *)\n)\n\/\/\nin\n auxlst (out, tds, 0)\nend \/\/ end of [emit_tmpdeclst_initize]\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun emit_instr_0\n (out: FILEref, ins: instr): void\n\/\/\nimplement\nemit_instr_0\n (out, ins0) = let\nin\n\/\/\ncase+\nins0.instr_node of\n\/\/\n| ATSreturn (tmp) =>\n {\n val () =\n if tmpvar_is_arg (tmp.i0de_sym)\n then emit_text (out, \"ldarg\")\n else emit_text (out, \"ldloc\")\n \/\/ end of [val]\n val () = emit_SPACE (out)\n val () = emit_i0de (out, tmp)\n val () = emit_newline (out)\n val () = emit_text (out, \"ret\")\n }\n\/\/\n| ATSreturn_void (tmp) =>\n {\n val () = emit_text (out, \"ret\")\n }\n\/\/\n| _ => emit_text (out, \"**INSTR**\")\n\/\/\nend \/\/ end of [emit_instr_0]\n\/\/\nextern\nfun emit_instr\n (out: FILEref, ins: instr, labthis: label, labnext: label) : void\n\/\/\nimplement\nemit_instr\n (out, ins0, labthis, labnext) = let\nin\n\/\/\ncase+\nins0.instr_node of\n\/\/\n| ATSif\n (\n d0e(*test*), inss(*then*), inssopt(*else*)\n ) =>\n (\n emit_d0exp (out, d0e);\n emit_newline (out);\n \n case+ inssopt of\n | Some (inss2) =>\n {\n val () = emit_text (out, \"brfalse\")\n val () = emit_SPACE (out)\n val L1 = label_for_instrlst (inss2)\n val () = emit_label (out, L1)\n val () = emit_ENDL (out)\n val L0 = label_for_instrlst (inss)\n val brlab = make_label (ins0.instr_loc)\n val () = emit_instrlst (out, inss, L0, brlab)\n val () = emit_label_mark (out, brlab)\n val () = emit_text (out, \"br\")\n val () = emit_SPACE (out)\n val () = emit_label (out, labnext)\n val () = emit_ENDL (out)\n val () = emit_instrlst (out, inss2, L1, labnext)\n }\n | None () =>\n {\n val () = emit_text (out, \"brfalse\")\n val () = emit_SPACE (out)\n val () = emit_label (out, labnext)\n val () = emit_ENDL (out)\n val () = emit_instrlst (out, inss, labthis, labnext)\n }\n )\n\/\/ TODO: ATSifthen, ATSifnthen, ATScaseofseq, ATSbranchseq\n\/\/ TODO: ATSlinepragma\n\/\/\n| ATSreturn (tmp) =>\n {\n val () =\n if tmpvar_is_arg (tmp.i0de_sym)\n then emit_text (out, \"ldarg\")\n else emit_text (out, \"ldloc\")\n \/\/ end of [val]\n val () = emit_SPACE (out)\n val () = emit_i0de (out, tmp)\n val () = emit_newline (out)\n val () = emit_text (out, \"ret\")\n }\n\/\/\n| ATSreturn_void (tmp) =>\n {\n val () = emit_text (out, \"ret\")\n }\n\/\/\n(*\n| ATSlinepragma (line, file) =>\n {\n val () = emit_text (out, \".line\")\n val () = emit_SPACE (out)\n val-T_INT(_, lpos) = line.token_node\n val () = emit_text (out, lpos)\n val () = emit_SPACE (out)\n val-T_STRING(filnam) = file.token_node\n val () = emit_text (out, filnam)\n }\n*)\n\/\/\n(*\n| ATSINSlab (lab) =>\n {\n val () = emit_label_mark (out, lab)\n }\n*)\n\/\/\n| ATSINSgoto (lab) =>\n {\n val () = emit_text (out, \"br\")\n val () = emit_SPACE (out)\n val () = emit_label (out, lab)\n }\n\/\/\n(*\n| ATSINSflab (flab) =>\n {\n val () = emit_label_mark (out, flab)\n }\n*)\n\/\/\n| ATSINSfgoto (flab) =>\n {\n val () = emit_text (out, \"br\")\n val () = emit_SPACE (out)\n val () = emit_label (out, flab)\n }\n\/\/\n| ATSINSmove (tmp, d0e) =>\n {\n val () = emit_d0exp (out, d0e)\n val () = emit_newline (out)\n val () =\n if tmpvar_is_arg (tmp.i0de_sym)\n then emit_text (out, \"starg\")\n else emit_text (out, \"stloc\")\n \/\/ end of [val] \n val () = emit_SPACE (out)\n val () = emit_i0de (out, tmp)\n } (* end of [ATSINSmove] *)\n| ATSINSmove_void (_, d0e) =>\n {\n val () = emit_d0exp (out, d0e)\n } (* end of [ATSINSmove_void] *)\n\/\/ TODO: ATSdynload0, ATSdynload1, ATSdynloadset\n\/\/\n| _ =>\n {\n val () = emit_text (out, \"**INSTR**\")\n }\n\/\/\nend \/\/ end of [emit_instr]\n\n(* ****** ****** *)\nimplement\nemit_instrlst\n(\n out, inss, labthis, lablast\n) = (\n\/\/\ncase+ inss of\n| list_nil () => ()\n| list_cons (ins0, inss) => let\n \/\/\n \/\/\n in\n case+ ins0.instr_node of\n | ATSINSlab (label) =>\n (\n emit_instrlst (out, inss, label, lablast)\n )\n | ATSINSflab (label) =>\n (\n emit_instrlst (out, inss, label, lablast)\n )\n | ATSlinepragma (line, file) =>\n (\n emit_instrlst (out, inss, labthis, lablast)\n )\n | _(*other*) =>\n {\n val () = emit_label_mark (out, labthis)\n val labnext =\n (\n case+ inss of\n | list_nil () => lablast\n | _ => label_for_instrlst (inss)\n ) (* end of [val] *)\n val () = emit_instr (out, ins0, labthis, labnext)\n val () = emit_ENDL (out)\n val () = emit_instrlst (out, inss, labnext, lablast)\n }\n end \/\/ end of [let]\n\/\/\n) (* end of [emit_instrlst] *)\n\n(* ****** ****** *)\n\/\/\nextern\nfun emit_ATSfunbodyseq\n (out: FILEref, ins: instr, labnext: label) : void\n\/\/\nimplement\nemit_ATSfunbodyseq\n (out, ins, labnext) = let\n\/\/\nval-ATSfunbodyseq (inss) = ins.instr_node\nval L1 = label_for_instrlst (inss)\n\/\/\nin\n emit_instrlst (out, inss, L1, labnext)\nend \/\/ end of [emit_ATSfunbodyseq]\n\n(* ****** ****** *)\n\/\/\nextern\nfun emit_f0body_0 : emit_type (f0body)\n\/\/\nimplement\nemit_f0body_0\n (out, fbody) = let\n\/\/\nfun\nauxlst\n(\n out: FILEref, inss: instrlst\n) : void =\n(\ncase+ inss of\n| list_nil () => ()\n| list_cons\n (ins0, inss1) => let\n val-list_cons (ins1, inss2) = inss1\n val labnext = label_for_instrlst (inss1)\n val () = emit_ATSfunbodyseq (out, ins0, labnext)\n val () = emit_label_mark (out, labnext)\n \/\/ FIXME: inss2 is EMPTY! what now?\n val lablast =\n (\n case+ inss2 of\n | list_nil () => i0de_make_string (location_dummy, \"LASTLABEL\")\n | _ => label_for_instrlst (inss2)\n )\n val () = emit_instr (out, ins1, labnext, lablast)\n in\n auxlst (out, inss2)\n end \/\/ end of [list_cons]\n) (* end of [auxlst] *)\n\/\/\nin\n\/\/\ncase+\nfbody.f0body_node of\n\/\/\n| F0BODY (tds, inss) => let\n val () = label_reset ()\n in\n auxlst (out, inss)\n end \/\/ end of [auxlst]\n\/\/\nend \/\/ end of [emit_f0body_0]\n\n(* ****** ****** *)\nimplement\nemit_f0body\n (out, fbody) = let\n\/\/\nval tmpdecs =\n f0body_get_tmpdeclst (fbody)\n\/\/\nval () = the_tmpdeclst_set (tmpdecs)\nval () = emit_LBRACE (out)\nval () = emit_newline (out)\n\/\/ TODO: how to compute maxstack?\nval () = emit_text (out, \".maxstack 16\")\nval () = emit_newline (out)\n\/\/ emit locals\nval () = emit_text (out, \".locals\")\nval () = emit_SPACE (out)\n(*\nval () = emit_text (out, \"init\")\nval () = emit_SPACE (out)\n*)\nval () = emit_LPAREN (out)\nval () = emit_newline (out)\nval () = emit_tmpdeclst (out, tmpdecs)\nval () = emit_RPAREN (out)\nval () = emit_newline (out)\n\nval () = emit_f0body_0 (out, fbody)\nval () = emit_newline (out)\nval () = emit_RBRACE (out)\nin\n\/\/\n\/\/\nend \/\/ end of [emit_f0body]\n\n(* ****** ****** *)\n\nimplement\nemit_f0decl\n (out, fdec) = let\nin\n\/\/\ncase+\nfdec.f0decl_node of\n| F0DECLnone (fhd) =>\n \/\/ does this actually mean function declaration (e.g. forward function decl)?\n ()\n| F0DECLsome (fhd, fbody) =>\n {\n val () = emit_text (out, \".method\")\n val () = emit_SPACE (out)\n val () = emit_text (out, \"static\")\n \/\/ TODO: public\/private?\n \/\/ static -> private\n val () = emit_SPACE (out)\n val () = emit_text (out, \"public\")\n val () = emit_SPACE (out)\n \/\/ FIXME: where is the type of this function??\n \/\/ TODO: use \n val () = emit_f0head (out, fhd)\n val () = emit_SPACE (out) \n val () = emit_text (out, \"cil\")\n val () = emit_SPACE (out)\n val () = emit_text (out, \"managed\")\n val () = emit_newline (out)\n val () = emit_f0body (out, fbody)\n val () = emit_newline (out)\n } (* end of [F0DECLsome] *)\n\/\/\nend \/\/ end of [emit_f0decl]\n\n(* ****** ****** *)\n\n\/\/\nextern\nfun\ntyrec_labsel\n (tyrec: tyrec, lab: symbol): int\n\/\/\nimplement\ntyrec_labsel\n (tyrec, lab) = let\n\/\/\nfun loop\n(\n xs: tyfldlst, i: int\n) : int =\n(\ncase+ xs of\n| list_cons (x, xs) => let\n val TYFLD (id, s0e) = x.tyfld_node\n in\n if lab = id.i0de_sym then i else loop (xs, i+1)\n end \/\/ end of [list_cons\n| list_nil ((*void*)) => ~1(*error*)\n)\n\/\/\nin\n loop (tyrec.tyrec_node, 0)\nend \/\/ end of [tyrec_labsel]\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_SELcon\n (out, d0e) = let\n\/\/\nval-ATSSELcon\n (d0rec, s0e, id) = d0e.d0exp_node\nval-S0Eide (name) = s0e.s0exp_node\nval-~Some_vt (s0rec) = typedef_search_opt (name)\n\/\/\nval index = tyrec_labsel (s0rec, id.i0de_sym)\n\/\/\nval () =\n emit_d0exp (out, d0rec)\n\/\/\nval () = emit_LBRACKET (out)\nval () = emit_int (out, index)\nval () = emit_RBRACKET (out)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit_SELcon]\n\n(* ****** ****** *)\n\nimplement\nemit_SELboxrec\n (out, d0e) = let\n\/\/\nval-ATSSELboxrec\n (d0rec, s0e, id) = d0e.d0exp_node\nval-S0Eide (name) = s0e.s0exp_node\nval-~Some_vt (s0rec) = typedef_search_opt (name)\n\/\/\nval index = tyrec_labsel (s0rec, id.i0de_sym)\n\/\/\nval () =\n emit_d0exp (out, d0rec)\n\/\/\nval () = emit_LBRACKET (out)\nval () = emit_int (out, index)\nval () = emit_RBRACKET (out)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit_SELboxrec]\n\n(* ****** ****** *)\n\/\/\n#define\nATSEXTCODE_BEG \"\/*\\nATSextcode_beg()\\n*\/\"\n#define\nATSEXTCODE_END \"\/*\\nATSextcode_end()\\n*\/\"\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_d0ecl\n (out, d0c) = let\nin\n\/\/\ncase+\nd0c.d0ecl_node of\n\/\/\n| D0Cinclude include =>\n {\n val () = emit_text (out, \"#include\")\n val () = emit_SPACE (out)\n\/\/ val () = emit_text (out, include)\n val () = emit_newline (out)\n }\n\/\/\n| D0Cifdef (i0de, d0eclist) =>\n {\n(* val () = emit_text (out, \"#ifdef\")\n val () = emit_SPACE (out)*)\n val () = emit_newline (out)\n }\n| D0Cifndef (i0de, d0eclist) =>\n {\n(* val () = emit_text (out, \"#ifndef\")\n val () = emit_SPACE (out)*)\n val () = emit_newline (out)\n }\n\/\/\n| D0Ctypedef (id, def) =>\n {\n val () = typedef_insert (id.i0de_sym, def)\n \/\/ TODO: insert type (class) declaration\n } (* end of [D0Ctypedef] *)\n\/\/\n| D0Cdyncst_mac i0de => ()\n| D0Cdyncst_extfun (i0de, s0explst, s0exp) => ()\n| D0Cextcode (toks) =>\n {\n val () = emit_text (out, ATSEXTCODE_BEG)\n val () = emit_extcode (out, toks)\n val () = emit_text (out, ATSEXTCODE_END)\n }\n| D0Cclosurerize (_, _, _, _) => ()\n\/\/\n| D0Cfundecl (fk, f0d) => emit_f0decl (out, f0d)\n\/\/\nend \/\/ end of [emit_d0ecl]\n\n(* ****** ****** *)\n\nimplement\nemit_toplevel\n (out, d0cs) = let\n\/\/\nfun\nloop\n(\n out: FILEref, d0cs: d0eclist\n) : void =\n(\n\/\/\ncase+ d0cs of\n| list_nil () => ()\n| list_cons\n (d0c, d0cs) => let\n in\n emit_d0ecl (out, d0c); loop (out, d0cs)\n end \/\/ end of [list_cons]\n\/\/\n)\n\/\/\nin\n loop (out, d0cs)\nend \/\/ end of [emit_toplevel]\n\n(* ****** ****** *)\n\n(* end of [atsparemit_emit_cil.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"0e1dbc5e8fd73cfd8908fb6618f56e6a97ef06de","subject":"Updating: very minorly","message":"Updating: very minorly\n","repos":"bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib","old_file":"contrib\/libatscc\/libatscc2py3\/DATS\/arrayref.dats","new_file":"contrib\/libatscc\/libatscc2py3\/DATS\/arrayref.dats","new_contents":"(*\n** For writing ATS code\n** that translates into Python\n*)\n\n(* ****** ****** *)\n\n#define ATS_DYNLOADFLAG 0\n\n(* ****** ****** *)\n\/\/\n\/\/ HX-2014-08:\n\/\/ prefix for external names\n\/\/\n#define\nATS_EXTERN_PREFIX \"ats2pypre_\"\n#define\nATS_STATIC_PREFIX \"_ats2pypre_arrayref_\"\n\/\/\n(* ****** ****** *)\n\n%{^\n######\nfrom ats2pypre_basics_cats import *\n######\nfrom ats2pypre_bool_cats import *\nfrom ats2pypre_integer_cats import *\n######\nfrom ats2pypre_PYlist_cats import *\n######\n%} \/\/ end of [%{^]\n\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_define.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\nUN = \"prelude\/SATS\/unsafe.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/..\/basics_py.sats\"\n\/\/\nstaload \".\/..\/SATS\/integer.sats\"\n\/\/\nstaload \".\/..\/SATS\/PYlist.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/..\/SATS\/intrange.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/..\/SATS\/arrayref.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\n#include \"{$LIBATSCC}\/DATS\/arrayref.dats\"\n\/\/\n(* ****** ****** *)\n\/\/\n(*\nassume arrayref(a, n) = PYlist(a)\n*)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\narrayref_make_elt\n {a}{n}(asz, x0) =\n $UN.cast(PYlist_make_elt(asz, x0))\n\/\/\n(* ****** ****** *)\n\nimplement\narrayref_get_at\n {a}(A, i) = let\n val A =\n $UN.cast{PYlist(a)}(A) in PYlist_get_at(A, i)\n \/\/ end of [val]\nend \/\/ end of [arrayref_get_at]\n\n(* ****** ****** *)\n\nimplement\narrayref_set_at\n {a}(A, i, x) = let\n val A =\n $UN.cast{PYlist(a)}(A) in PYlist_set_at(A, i, x)\n \/\/ end of [val]\nend \/\/ end of [arrayref_set_at]\n\n(* ****** ****** *)\n\/\/\n\/\/ Array-with-size\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\narrszref_make_arrayref\n {a}(A, n) =\n(\n $UN.cast{arrszref(a)}(A)\n)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\narrszref_size\n {a}(A) = let\n val A = $UN.cast{PYlist(a)}(A)\nin\n $UN.cast{intGte(0)}(PYlist_length(A))\nend \/\/ end of [arrszref_size]\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\narrszref_get_at\n {a}(A, i) = let\n val A =\n $UN.cast{PYlist(a)}(A) in PYlist_get_at(A, i)\n \/\/ end of [val]\nend \/\/ end of [arrszref_get_at]\n\/\/\nimplement\narrszref_set_at\n {a}(A, i, x) = let\n val A =\n $UN.cast{PYlist(a)}(A) in PYlist_set_at(A, i, x)\n \/\/ end of [val]\nend \/\/ end of [arrszref_set_at]\n\/\/\n(* ****** ****** *)\n\n(* end of [arrayref.dats] *)\n","old_contents":"(*\n** For writing ATS code\n** that translates into Python\n*)\n\n(* ****** ****** *)\n\n#define ATS_DYNLOADFLAG 0\n\n(* ****** ****** *)\n\/\/\n\/\/ HX-2014-08:\n\/\/ prefix for external names\n\/\/\n#define\nATS_EXTERN_PREFIX \"ats2pypre_\"\n#define\nATS_STATIC_PREFIX \"_ats2pypre_arrayref_\"\n\/\/\n(* ****** ****** *)\n\n%{^\n######\nfrom ats2pypre_basics_cats import *\n######\nfrom ats2pypre_bool_cats import *\nfrom ats2pypre_integer_cats import *\n######\nfrom ats2pypre_PYlist_cats import *\n######\n%} \/\/ end of [%{^]\n\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_define.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\nUN = \"prelude\/SATS\/unsafe.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/..\/basics_py.sats\"\n\/\/\nstaload \".\/..\/SATS\/integer.sats\"\n\/\/\nstaload \".\/..\/SATS\/PYlist.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/..\/SATS\/intrange.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/..\/SATS\/arrayref.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\n#include \"{$LIBATSCC}\/DATS\/arrayref.dats\"\n\/\/\n(* ****** ****** *)\n\/\/\n(*\nassume arrayref(a, n) = PYlist(a)\n*)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\narrayref_make_elt\n {a}{n}(asz, x0) =\n $UN.cast{arrayref(a,n)}(PYlist_make_elt(asz, x0))\n\/\/\n(* ****** ****** *)\n\nimplement\narrayref_get_at{a}(A, i) = let\n val A = $UN.cast{PYlist(a)}(A) in PYlist_get_at(A, i)\nend \/\/ end of [arrayref_get_at]\n\n(* ****** ****** *)\n\nimplement\narrayref_set_at{a}(A, i, x) = let\n val A = $UN.cast{PYlist(a)}(A) in PYlist_set_at(A, i, x)\nend \/\/ end of [arrayref_set_at]\n\n(* ****** ****** *)\n\/\/\n\/\/ Array-with-size\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\narrszref_make_arrayref\n {a}(A, n) = $UN.cast{arrszref(a)}(A)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\narrszref_size{a}(A) = let\n val A = $UN.cast{PYlist(a)}(A)\nin\n $UN.cast{intGte(0)}(PYlist_length(A))\nend \/\/ end of [arrszref_size]\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\narrszref_get_at{a}(A, i) = let\n val A = $UN.cast{PYlist(a)}(A) in PYlist_get_at(A, i)\nend \/\/ end of [arrszref_get_at]\n\/\/\nimplement\narrszref_set_at{a}(A, i, x) = let\n val A = $UN.cast{PYlist(a)}(A) in PYlist_set_at(A, i, x)\nend \/\/ end of [arrszref_set_at]\n\/\/\n(* ****** ****** *)\n\n(* end of [arrayref.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"2254a2a63438aecdf5f8e5e7b84de7e1ace59765","subject":"Merging","message":"Merging\n","repos":"githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib","old_file":"contrib\/libatscc\/libatscc2erl\/Session\/SATS\/basis.sats","new_file":"contrib\/libatscc\/libatscc2erl\/Session\/SATS\/basis.sats","new_contents":"(*\n** Atscc2erl:\n** A basis for\n** dyadic session-types\n*)\n\n(* ****** ****** *)\n\/\/\n\/\/ HX-2015-07:\n\/\/ prefix for external names\n\/\/\n#define\nATS_EXTERN_PREFIX \"libats2erl_session_\"\n\/\/\n(* ****** ****** *)\n\/\/\nlocal\n\/\/\n#include \"share\/atspre_define.hats\"\n\/\/\nin\n staload \"{$LIBATSCC2ERL}\/basics_erl.sats\"\nend \/\/ end of [local]\n\/\/\n(* ****** ****** *)\n\/\/\nabstype chsnd(a:vt@ype)\nabstype chrcv(a:vt@ype)\n\/\/\n(* ****** ****** *)\n\nabstype chnil\nabstype chcons(a:type, ss:type)\n\n(* ****** ****** *)\n\/\/\nstadef :: = chcons \/\/ infix oper\n\/\/\n(* ****** ****** *)\n\/\/\nabstype ssnot(ss:type)\n\/\/\nabstype ssdisj(ss:type)\nabstype ssconj(ss:type)\nabstype ssdisj_nil and ssconj_nil\n\/\/\n(* ****** ****** *)\n\/\/\nabsvtype\nchanpos(type) = ptr and channeg(type) = ptr\n\/\/\n(* ****** ****** *)\n\/\/\nprfun\nchanpos_not{ss:type}\n (!chanpos(ssnot(ss)) >> channeg(ss)): void\nprfun\nchanneg_not{ss:type}\n (!channeg(ssnot(ss)) >> chanpos(ss)): void\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nchanpos_send\n {a:vt0p}{ss:type}\n(\n chp: !chanpos(chsnd(a)::ss) >> chanpos(ss), x: a\n) : void = \"mac#%\" \/\/ end-of-function\n\/\/\nfun\nchanneg_recv\n {a:vt0p}{ss:type}\n(\n chn: !channeg(chrcv(a)::ss) >> channeg(ss), x: a\n) : void = \"mac#%\" \/\/ end-of-function\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nchanpos_recv\n {a:vt0p}{ss:type}\n (!chanpos(chrcv(a)::ss) >> chanpos(ss)): a = \"mac#%\"\n\/\/\nfun\nchanneg_send\n {a:vt0p}{ss:type}\n (!channeg(chsnd(a)::ss) >> channeg(ss)): a = \"mac#%\"\n\/\/\n(* ****** ****** *)\n\/\/\nfun chanpos_nil_wait (chp: chanpos(chnil)): void = \"mac#%\"\nfun channeg_nil_close (chn: channeg(chnil)): void = \"mac#%\"\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nchanposneg_link\n {ss:type}(chp: chanpos(ss), chn: channeg(ss)): void = \"mac#%\"\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nchanneg_create{ss:type}\n (fserv: chanpos(ss) - void): channeg(ss) = \"mac#%\"\nfun\nchanneg_createnv\n {env:t0p}{ss:type}\n (fserv: (env, chanpos(ss)) - void, env): channeg(ss) = \"mac#%\"\n\/\/\n(* ****** ****** *)\n\nsymintr channel_send\noverload channel_send with chanpos_send\noverload channel_send with channeg_recv\n\n(* ****** ****** *)\n\nsymintr channel_recv\noverload channel_recv with chanpos_recv\noverload channel_recv with channeg_send\n\n(* ****** ****** *)\n\nsymintr channel_close\noverload channel_close with chanpos_nil_wait\noverload channel_close with channeg_nil_close\n\n(* ****** ****** *)\n\/\/\nmacdef\nchannel_send_close\n (chx, x0) = (\n\/\/\nlet val chx = ,(chx) in channel_send(chx, ,(x0)); channel_close(chx) end\n\/\/\n) (* end of [channel_send_close] *)\n\/\/\n(* ****** ****** *)\n\/\/\nmacdef\nchannel_recv_close(chx) =\nlet val chx = ,(chx); val x0 = channel_recv(chx) in channel_close(chx); x0 end\n\/\/\n(* ****** ****** *)\n\/\/\n\/\/ HX-2015-07:\n\/\/ For persistent service\n\/\/\n(* ****** ****** *)\n\/\/\nabstype\nchansrvc(ss:type) = ptr\nabstype\nchansrvc2(env:vt@ype, ss:type) = ptr\n\/\/\nstadef service = chansrvc\nstadef service = chansrvc2\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nchansrvc_create{ss:type}\n(\n fserv: chanpos(ss) - void\n) : chansrvc(ss) = \"mac#%\" \/\/ end-of-fun\n\/\/\nfun\nchansrvc_request\n {ss:type}\n (chsrv: chansrvc(ss)): channeg(ss) = \"mac#%\"\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nchansrvc2_create\n {env:vt0p}{ss:type}\n(\n fserv: (env, chanpos(ss)) - void\n) : chansrvc2(env, ss) = \"mac#%\" \/\/ end-of-fun\n\/\/\nfun\nchansrvc2_request\n {env:vt0p}{ss:type}\n (env, chansrvc2(env, ss)): channeg(ss) = \"mac#%\"\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nchansrvc_register\n {ss:type}\n (name: atom, chsrv: chansrvc(ss)): void = \"mac#%\"\nfun\nchansrvc2_register\n {env:vt0p}{ss:type}\n (name: atom, chsrv: chansrvc2(env, ss)): void = \"mac#%\"\n\/\/\n(* ****** ****** *)\n\n(* end of [basis.sats] *)\n","old_contents":"(*\n** Atscc2erl:\n** A basis for\n** dyadic session-types\n*)\n\n(* ****** ****** *)\n\/\/\n\/\/ HX-2015-07:\n\/\/ prefix for external names\n\/\/\n#define\nATS_EXTERN_PREFIX \"libats2erl_session_\"\n\/\/\n(* ****** ****** *)\n\/\/\nlocal\n\/\/\n#include \"share\/atspre_define.hats\"\n\/\/\nin\n staload \"{$LIBATSCC2ERL}\/basics_erl.sats\"\nend \/\/ end of [local]\n\/\/\n(* ****** ****** *)\n\/\/\nabstype chsnd(a:vt@ype)\nabstype chrcv(a:vt@ype)\n\/\/\n(* ****** ****** *)\n\nabstype chnil\nabstype chcons(a:type, ss:type)\n\n(* ****** ****** *)\n\/\/\nstadef :: = chcons \/\/ infix oper\n\/\/\n(* ****** ****** *)\n\nabstype ssdisj(ss:type)\nabstype ssconj(ss:type)\nabstype ssdisj_nil and ssconj_nil\n\n(* ****** ****** *)\n\/\/\nabsvtype\nchanpos(type) = ptr and channeg(type) = ptr\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nchanpos_send\n {a:vt0p}{ss:type}\n(\n chp: !chanpos(chsnd(a)::ss) >> chanpos(ss), x: a\n) : void = \"mac#%\" \/\/ end-of-function\n\/\/\nfun\nchanneg_recv\n {a:vt0p}{ss:type}\n(\n chn: !channeg(chrcv(a)::ss) >> channeg(ss), x: a\n) : void = \"mac#%\" \/\/ end-of-function\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nchanpos_recv\n {a:vt0p}{ss:type}\n (!chanpos(chrcv(a)::ss) >> chanpos(ss)): a = \"mac#%\"\n\/\/\nfun\nchanneg_send\n {a:vt0p}{ss:type}\n (!channeg(chsnd(a)::ss) >> channeg(ss)): a = \"mac#%\"\n\/\/\n(* ****** ****** *)\n\/\/\nfun chanpos_nil_wait (chp: chanpos(chnil)): void = \"mac#%\"\nfun channeg_nil_close (chn: channeg(chnil)): void = \"mac#%\"\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nchanposneg_link\n {ss:type}(chp: chanpos(ss), chn: channeg(ss)): void = \"mac#%\"\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nchanneg_create{ss:type}\n (fserv: chanpos(ss) - void): channeg(ss) = \"mac#%\"\nfun\nchanneg_createnv\n {env:t0p}{ss:type}\n (fserv: (env, chanpos(ss)) - void, env): channeg(ss) = \"mac#%\"\n\/\/\n(* ****** ****** *)\n\nsymintr channel_send\noverload channel_send with chanpos_send\noverload channel_send with channeg_recv\n\n(* ****** ****** *)\n\nsymintr channel_recv\noverload channel_recv with chanpos_recv\noverload channel_recv with channeg_send\n\n(* ****** ****** *)\n\nsymintr channel_close\noverload channel_close with chanpos_nil_wait\noverload channel_close with channeg_nil_close\n\n(* ****** ****** *)\n\/\/\nmacdef\nchannel_send_close\n (chx, x0) = (\n\/\/\nlet val chx = ,(chx) in channel_send(chx, ,(x0)); channel_close(chx) end\n\/\/\n) (* end of [channel_send_close] *)\n\/\/\n(* ****** ****** *)\n\/\/\nmacdef\nchannel_recv_close(chx) =\nlet val chx = ,(chx); val x0 = channel_recv(chx) in channel_close(chx); x0 end\n\/\/\n(* ****** ****** *)\n\/\/\n\/\/ HX-2015-07:\n\/\/ For persistent service\n\/\/\n(* ****** ****** *)\n\/\/\nabstype\nchansrvc(ss:type) = ptr\nabstype\nchansrvc2(env:vt@ype, ss:type) = ptr\n\/\/\nstadef service = chansrvc\nstadef service = chansrvc2\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nchansrvc_create{ss:type}\n(\n fserv: chanpos(ss) - void\n) : chansrvc(ss) = \"mac#%\" \/\/ end-of-fun\n\/\/\nfun\nchansrvc_request\n {ss:type}\n (chsrv: chansrvc(ss)): channeg(ss) = \"mac#%\"\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nchansrvc2_create\n {env:vt0p}{ss:type}\n(\n fserv: (env, chanpos(ss)) - void\n) : chansrvc2(env, ss) = \"mac#%\" \/\/ end-of-fun\n\/\/\nfun\nchansrvc2_request\n {env:vt0p}{ss:type}\n (env, chansrvc2(env, ss)): channeg(ss) = \"mac#%\"\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nchansrvc_register\n {ss:type}\n (name: atom, chsrv: chansrvc(ss)): void = \"mac#%\"\nfun\nchansrvc2_register\n {env:vt0p}{ss:type}\n (name: atom, chsrv: chansrvc2(env, ss)): void = \"mac#%\"\n\/\/\n(* ****** ****** *)\n\n(* end of [basis.sats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"9e7ecfc51b153577bb8f11ffee1540b915b32bc2","subject":"Keeping pace with upstream.","message":"Keeping pace with upstream.\n\nAlso, added local\/argument distinction (currently, by analysing\ntmpvar names).\n","repos":"alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib","old_file":"projects\/MEDIUM\/ATS-parse-emit\/CIL\/atsparemit_emit_cil.dats","new_file":"projects\/MEDIUM\/ATS-parse-emit\/CIL\/atsparemit_emit_cil.dats","new_contents":"(* ****** ****** *)\n\/\/\n\/\/ ATS-parse-emit-python\n\/\/\n(* ****** ****** *)\n\/\/\n\/\/ AS-2014-08-17: start\n\/\/\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_staload.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\nUN = \"prelude\/SATS\/unsafe.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/atsparemit.sats\"\nstaload \".\/atsparemit_syntax.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/atsparemit_emit.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/atsparemit_topenv.dats\"\n\/\/\n(* ****** ****** *)\n\nfn\nsymbol_is_arg (x: symbol) :<> bool = let\n val name = g1ofg0_string (symbol_get_name (x))\nin\n if strlen (name) >= 4 then\n string_get_at (name, 0) = 'a' && string_get_at (name, 1) = 'r' && string_get_at (name, 2) = 'g'\n && isdigit (string_get_at (name, 3))\n else false\nend \/\/ end of [symbol_is_arg]\n\n(* ****** ****** *)\n\nimplement\nemit_ENDL (out) = emit_text (out, \"\\n\")\n\n(* ****** ****** *)\n\nimplement\nemit_SPACE (out) = emit_text (out, \" \")\n\n(* ****** ****** *)\n\nimplement\nemit_SHARP (out) = emit_text (out, \"#\")\n\n(* ****** ****** *)\n\nimplement\nemit_LPAREN (out) = emit_text (out, \"(\")\nimplement\nemit_RPAREN (out) = emit_text (out, \")\")\n\n(* ****** ****** *)\n\nimplement\nemit_LBRACE (out) = emit_text (out, \"{\")\nimplement\nemit_RBRACE (out) = emit_text (out, \"}\")\n\n\n(* ****** ****** *)\n\nimplement\nemit_LBRACKET (out) = emit_text (out, \"[\")\nimplement\nemit_RBRACKET (out) = emit_text (out, \"]\")\n\n(* ****** ****** *)\n\nimplement\nemit_flush (out) = fileref_flush (out)\nimplement\nemit_newline (out) = fprint_newline (out)\n\n(* ****** ****** *)\n\/\/\nimplement\nemit_int (out, x) = fprint_int (out, x)\n\/\/\nimplement\nemit_text (out, x) = fprint_string (out, x)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nemit_symbol (out, x) =\n fprint_string (out, symbol_get_name (x))\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_PMVint\n (out, tok) = let\n\/\/\nval-T_INT(base, rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVint]\n\n(* ****** ****** *)\n\nimplement\nemit_PMVi0nt\n (out, tok) = let\n\/\/\nval-T_INT(base, rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVi0nt]\n\n(* ****** ****** *)\n\/\/\nimplement\nemit_PMVbool\n (out, tfv) =\n(\n emit_text (out, if tfv then \"1\" else \"0\")\n) (* end of [emit_PMVbool] *)\n\/\/\n(* ****** ****** *)\nimplement\nemit_PMVstring\n (out, tok) = let\n\/\/\nval-T_STRING(rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVstring]\n\n(* ****** ****** *)\n\/\/\nimplement\nemit_i0de\n (out, id) = emit_symbol (out, id.i0de_sym)\nimplement\nemit_label\n (out, lab) = emit_symbol (out, lab.i0de_sym)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun emit_instrlst\n (out: FILEref, inss: instrlst) : void\n\/\/\nextern\nfun\nemit_s0exp : emit_type (s0exp)\nextern\nfun\nemit_s0explst : emit_type (s0explst)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nemit_s0exp\n (out, s0e) = let\n\/\/\n\/\/\nin\n\/\/\ncase+\ns0e.s0exp_node of\n\/\/\n| S0Eide (id) => emit_symbol (out, id)\n| S0Elist (s0es) => () \/\/ shouldn't happen? marked as \"temp\"\n| S0Eappid (id, s0es) =>\n \/\/ FIXME: what about other types? e.g. array types? struct types?\n () where {\n val () = emit_i0de (out, id)\n val () = emit_LPAREN (out)\n val () = emit_s0explst (out, s0es)\n val () = emit_RPAREN (out)\n }\n\/\/\nend \/\/ end of [emit_s0exp]\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_s0explst\n (out, s0es) = let\n\/\/\nfun\nloop\n(\n out: FILEref, s0es: s0explst, i: int\n) : void =\n(\ncase+ s0es of\n| list_nil () => ()\n| list_cons (s0e, s0es) => let\n val () =\n if i > 0 then emit_text (out, \", \")\n \/\/ end of [val]\n in\n emit_s0exp (out, s0e); loop (out, s0es, i+1)\n end \/\/ end of [list_cons]\n)\n\/\/\nin\n loop (out, s0es, 0)\nend \/\/ end of [emit_s0explst]\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nfunlab_get_index (fl: label): int\nextern\nfun\ntmplab_get_index (lab: label): int\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_f0arglst_get (): f0arglst\nextern\nfun\nthe_f0arglst_set (f0as: f0arglst): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_tmpdeclst_get (): tmpdeclst\nextern\nfun\nthe_tmpdeclst_set (tds: tmpdeclst): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_funbodylst_get (): instrlst\nextern\nfun\nthe_funbodylst_set (inss: instrlst): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_branchlablst_get (): labelist\nextern\nfun\nthe_branchlablst_set (labs: labelist): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_caseofseqlst_get (): instrlst\nextern\nfun\nthe_caseofseqlst_set (inss: instrlst): void\n\/\/\n(* ****** ****** *)\n\nlocal\n\/\/\nval the_f0arglst = ref (list_nil)\nval the_tmpdeclst = ref (list_nil)\n\/\/\nval the_funbodylst = ref (list_nil)\n\/\/\nval the_branchlablst = ref (list_nil)\nval the_caseofseqlst = ref (list_nil)\n\/\/\nin (* in-of-local *)\n\nimplement\nthe_f0arglst_get () = !the_f0arglst\nimplement\nthe_f0arglst_set (xs) = !the_f0arglst := xs\n\nimplement\nthe_tmpdeclst_get () = !the_tmpdeclst\nimplement\nthe_tmpdeclst_set (xs) = !the_tmpdeclst := xs\n\nimplement\nthe_funbodylst_get () = !the_funbodylst\nimplement\nthe_funbodylst_set (xs) = !the_funbodylst := xs\n\nimplement\nthe_branchlablst_get () = !the_branchlablst\nimplement\nthe_branchlablst_set (xs) = !the_branchlablst := xs\n\nimplement\nthe_caseofseqlst_get () = !the_caseofseqlst\nimplement\nthe_caseofseqlst_set (xs) = !the_caseofseqlst := xs\n\nend \/\/ end of [local]\n\n(* ******* ****** *)\n\nlocal\n\nfun\nloop\n(\n out: FILEref, d0es: d0explst, i: int\n) : void =\n(\ncase+ d0es of\n| list_nil () => ()\n| list_cons (d0e, d0es) => let\n val () =\n if i > 0 then emit_newline (out)\n \/\/ end of [val]\n in\n emit_d0exp (out, d0e);\n emit_newline (out);\n loop (out, d0es, i+1)\n end \/\/ end of [list_cons]\n)\n\nin (* in-of-local *)\n\nimplement\nemit_d0explst (out, d0es) = loop (out, d0es, 0)\nimplement\nemit_d0explst_1 (out, d0es) = loop (out, d0es, 1)\n\nend \/\/ end of [local]\n\n(* ******* ****** *)\n\nimplement\nemit_d0exp\n (out, d0e) = let\nin\n\/\/\ncase+\nd0e.d0exp_node of\n\/\/\n| D0Eide (id) =>\n {\n val () =\n if symbol_is_arg (id)\n then emit_text (out, \"ldarg\")\n else emit_text (out, \"ldloc\")\n \/\/ end of [val]\n val () = emit_SPACE (out)\n val () = emit_symbol (out, id)\n }\n\/\/\n| D0Eappid (id, d0es) =>\n {\n val () = emit_d0explst (out, d0es)\n val () = emit_text (out, \"call\")\n val () = emit_SPACE (out)\n val () = emit_i0de (out, id) \/\/ FIXME: need also type of [id]!\n }\n\/\/\n\/\/\n| ATSPMVint (tok) =>\n {\n val () = emit_text (out, \"ldc.i4\")\n val () = emit_SPACE (out)\n val () = emit_PMVint (out, tok)\n } (* end of [ATSPMVint] *)\n| ATSPMVi0nt (tok) =>\n {\n val () = emit_text (out, \"ldc.i4\")\n val () = emit_SPACE (out)\n val () = emit_PMVi0nt (out, tok)\n } (* end of [ATSPMVi0nt] *)\n\/\/\n| ATSPMVbool (tfv) =>\n {\n val () = emit_text (out, \"ldc.i4\")\n val () = emit_SPACE (out)\n val () = emit_PMVbool (out, tfv)\n } (* end of [ATSPMVbool] *)\n\/\/\n| ATSPMVstring (tok) =>\n {\n val () = emit_text (out, \"ldstr\")\n val () = emit_SPACE(out)\n val () = emit_PMVstring (out, tok)\n } (* end of [ATSPMVstring] *)\n\/\/\n| ATSPMVf0loat (tok) => emit_text (out, \"ATSPMVf0loat(...)\")\n\/\/\n| _ => ()\n\/\/\nend \/\/ end of [emit_d0exp]\n\n(* ****** ****** *)\n\/\/\nextern\nfun emit_f0arg : emit_type (f0arg)\nextern\nfun emit_f0marg : emit_type (f0marg)\nextern\nfun emit_f0head : emit_type (f0head)\n\/\/\nextern\nfun emit_f0body : emit_type (f0body)\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_f0arg\n (out, f0a) = let\nin\n\/\/\ncase+\nf0a.f0arg_node of\n\/\/\n| F0ARGnone s0e => emit_text (out, \"__NONE__\") \/\/ FIXME: how to emit type decl?\n| F0ARGsome (id, s0e) =>\n {\n val () = emit_s0exp (out, s0e)\n val () = emit_SPACE (out)\n val () = emit_i0de (out, id)\n } (* end of [F0ARGsome] *)\n\/\/\nend \/\/ end of [emit_f0arg]\n\n(* ****** ****** *)\n\nimplement\nemit_f0marg\n (out, f0ma) = let\n\/\/\nfun\nloop\n(\n out: FILEref, f0as: f0arglst, i: int\n) : void =\n(\ncase+ f0as of\n| list_nil () => ()\n| list_cons (f0a, f0as) => let\n val () =\n if i > 0 then emit_text (out, \", \")\n \/\/ end of [val]\n in\n emit_f0arg (out, f0a); loop (out, f0as, i+1)\n end \/\/ end of [list_cons]\n)\n\/\/\nin\n loop (out, f0ma.f0marg_node, 0)\nend \/\/ end of [emit_f0marg]\n\n(* ****** ****** *)\n\nimplement\nemit_f0head\n (out, fhd) = let\n\/\/\nval f0as =\n f0head_get_f0arglst (fhd)\n\/\/\nval () = the_f0arglst_set (f0as)\n\/\/\nin\n\/\/\ncase+\nfhd.f0head_node of\n| F0HEAD\n (id(*name of function*), f0ma(*list of arguments*), res(*result type*)) =>\n {\n val () = emit_s0exp (out, res)\n val () = emit_SPACE (out)\n val () = emit_i0de (out, id)\n val () = emit_LPAREN (out)\n val () = emit_f0marg (out, f0ma)\n val () = emit_RPAREN (out)\n }\n\/\/\nend \/\/ end of [emit_f0head]\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit_tmpdeclst\n (out: FILEref, tds: tmpdeclst): void\n\/\/\nimplement\nemit_tmpdeclst\n (out, tds) = let\n\/\/\nfun auxlst\n(\n out: FILEref, tds: tmpdeclst, i: int\n) : void =\n(\ncase+ tds of\n| list_nil () => ()\n| list_cons (td, tds) =>\n (\n case+ td.tmpdec_node of\n | TMPDECnone\n (tmp) => auxlst (out, tds, i) \/\/ probably ATStmpdec_void()\n | TMPDECsome\n (tmp, s0e) => let\n val () =\n if i > 0 then\n emit_text(out, \", \")\n \/\/ end of [val]\n val () = emit_s0exp (out, s0e)\n val () = emit_SPACE (out)\n val () = emit_i0de (out, tmp)\n val () = emit_newline (out)\n in\n auxlst (out, tds, i+1)\n end \/\/ end of [TMPDECsome]\n ) (* end of [list_cons] *)\n)\n\/\/\nin\n auxlst (out, tds, 0)\nend \/\/ end of [emit_tmpdeclst_initize]\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun emit_instr\n (out: FILEref, ins: instr) : void\n\/\/\nimplement\nemit_instr\n (out, ins0) = let\nin\n\/\/\ncase+\nins0.instr_node of\n\/\/\n| ATSif\n (\n d0e(*test*), inss(*then*), inssopt(*else*)\n ) =>\n {\n \/\/ TODO: labels must be assigned automatically... but how?\n val () = emit_d0exp (out, d0e)\n val () = emit_newline (out)\n val () = emit_text (out, \"brfalse L1\")\n val () = emit_newline (out)\n val () = emit_instrlst (out, inss)\n val () =\n (\n case+ inssopt of\n | Some(inss) =>\n {\n val () = emit_text (out, \"br L2\")\n val () = emit_newline (out)\n val () = emit_text (out, \"L1:\")\n val () = emit_newline (out)\n val () = emit_instrlst (out, inss)\n }\n | None((*void*)) => ()\n )\n val () = emit_text (out, \"L2:\") \/\/ next instruction, whatever it may be\n val () = emit_newline (out)\n } (* end of [ATSif] *)\n\/\/ TODO: ATSifthen, ATSifnthen, ATScaseofseq, ATSbranchseq\n\/\/ TODO: ATSlinepragma\n\/\/\n| ATSreturn (tmp) =>\n {\n \/\/ FIXME: if tmp is actually funarg, we must use ldarg\n val () = emit_text (out, \"ldloc\")\n val () = emit_SPACE (out)\n val () = emit_i0de (out, tmp)\n val () = emit_newline (out)\n val () = emit_text (out, \"ret\")\n }\n\/\/\n| ATSreturn_void (tmp) =>\n {\n val () = emit_text (out, \"ret\")\n }\n\/\/\n| ATSlinepragma (line, file) =>\n {\n \/\/ skip\n }\n\/\/\n| ATSINSlab (lab) =>\n {\n val () = emit_label (out, lab)\n val () = emit_text (out, \":\")\n }\n\/\/\n| ATSINSgoto (lab) =>\n {\n val () = emit_text (out, \"br\")\n val () = emit_SPACE (out)\n val () = emit_label (out, lab)\n }\n\/\/\n| ATSINSflab (flab) =>\n {\n val () = emit_label (out, flab)\n val () = emit_text (out, \":\")\n }\n\/\/\n| ATSINSfgoto (flab) =>\n {\n val () = emit_text (out, \"br\")\n val () = emit_SPACE (out)\n val () = emit_label (out, flab)\n }\n\/\/\n| ATSINSmove (tmp, d0e) =>\n {\n val () = emit_d0exp (out, d0e)\n val () = emit_newline (out)\n val () =\n if symbol_is_arg (tmp.i0de_sym)\n then emit_text (out, \"starg\")\n else emit_text (out, \"stloc\")\n \/\/ end of [val] \n val () = emit_SPACE (out)\n val () = emit_i0de (out, tmp)\n } (* end of [ATSINSmove] *)\n| ATSINSmove_void (_, d0e) =>\n {\n val () = emit_d0exp (out, d0e)\n } (* end of [ATSINSmove_void] *)\n\/\/ TODO: ATSdynload0, ATSdynload1, ATSdynloadset\n\/\/\n| _ =>\n {\n val () = emit_text (out, \"**INSTR**\")\n }\n\/\/\nend \/\/ end of [emit_instr]\n\n(* ****** ****** *)\nimplement\nemit_instrlst\n(\n out, inss\n) = (\n\/\/\ncase+ inss of\n| list_nil () => ()\n| list_cons (ins, inss) =>\n {\n val () = emit_instr (out, ins)\n val () = emit_ENDL (out)\n val () = emit_instrlst (out, inss)\n }\n\/\/\n) (* end of [emit_instrlst] *)\n\n(* ****** ****** *)\n\/\/\nextern\nfun emit_ATSfunbodyseq\n (out: FILEref, ins: instr) : void\n\/\/\nimplement\nemit_ATSfunbodyseq\n (out, ins) = let\n\/\/\nval-ATSfunbodyseq (inss) = ins.instr_node\n\/\/\nin\n emit_instrlst (out, inss)\nend \/\/ end of [emit_ATSfunbodyseq]\n\n(* ****** ****** *)\n\/\/\nextern\nfun emit_f0body_0 : emit_type (f0body)\n\/\/\nimplement\nemit_f0body_0\n (out, fbody) = let\n\/\/\nfun\nauxlst\n(\n out: FILEref, inss: instrlst\n) : void =\n(\ncase+ inss of\n| list_nil () => ()\n| list_cons\n (ins0, inss1) => let\n val-list_cons (ins1, inss2) = inss1\n val () = emit_ATSfunbodyseq (out, ins0)\n val () = emit_instr (out, ins1)\n in\n auxlst (out, inss2)\n end \/\/ end of [list_cons]\n) (* end of [auxlst] *)\n\/\/\nin\n\/\/\ncase+\nfbody.f0body_node of\n\/\/\n| F0BODY (tds, inss) => auxlst (out, inss)\n\/\/\nend \/\/ end of [emit_f0body_0]\n\n(* ****** ****** *)\nimplement\nemit_f0body\n (out, fbody) = let\n\/\/\nval tmpdecs =\n f0body_get_tmpdeclst (fbody)\n\/\/\nval () = the_tmpdeclst_set (tmpdecs)\nval () = emit_LBRACE (out)\nval () = emit_newline (out)\n\/\/ TODO: how to compute maxstack?\nval () = emit_text (out, \".maxstack 1\")\nval () = emit_newline (out)\n\/\/ emit locals\nval () = emit_text (out, \".locals\")\nval () = emit_SPACE (out)\nval () = emit_text (out, \"init\")\nval () = emit_SPACE (out)\nval () = emit_LPAREN (out)\nval () = emit_newline (out)\nval () = emit_tmpdeclst (out, tmpdecs)\nval () = emit_RPAREN (out)\nval () = emit_newline (out)\n\/\/ .locals init (\n\/\/ class [Mono.Cecil]Mono.Cecil.AssemblyNameDefinition V_0,\n\/\/ int32 V_1\n\/\/ )\nval () = emit_f0body_0 (out, fbody)\nval () = emit_newline (out)\nval () = emit_RBRACE (out)\nin\n\/\/\n\/\/\nend \/\/ end of [emit_f0body]\n\n(* ****** ****** *)\n\nimplement\nemit_f0decl\n (out, fdec) = let\nin\n\/\/\ncase+\nfdec.f0decl_node of\n| F0DECLnone (fhd) =>\n \/\/ does this actually mean function declaration (e.g. forward function decl)?\n ()\n| F0DECLsome (fhd, fbody) =>\n {\n val () = emit_text (out, \".method\")\n val () = emit_SPACE (out)\n val () = emit_text (out, \"static\")\n \/\/ TODO: public\/private?\n val () = emit_SPACE (out)\n val () = emit_text (out, \"public\")\n val () = emit_SPACE (out)\n \/\/ FIXME: where is the type of this function??\n val () = emit_f0head (out, fhd)\n val () = emit_SPACE (out) \n val () = emit_text (out, \"cil\")\n val () = emit_SPACE (out)\n val () = emit_text (out, \"managed\")\n val () = emit_newline (out)\n val () = emit_f0body (out, fbody)\n val () = emit_newline (out)\n } (* end of [F0DECLsome] *)\n\/\/\nend \/\/ end of [emit_f0decl]\n\n(* ****** ****** *)\n\n\/\/\nextern\nfun\ntyrec_labsel\n (tyrec: tyrec, lab: symbol): int\n\/\/\nimplement\ntyrec_labsel\n (tyrec, lab) = let\n\/\/\nfun loop\n(\n xs: tyfldlst, i: int\n) : int =\n(\ncase+ xs of\n| list_cons (x, xs) => let\n val TYFLD (id, s0e) = x.tyfld_node\n in\n if lab = id.i0de_sym then i else loop (xs, i+1)\n end \/\/ end of [list_cons\n| list_nil ((*void*)) => ~1(*error*)\n)\n\/\/\nin\n loop (tyrec.tyrec_node, 0)\nend \/\/ end of [tyrec_labsel]\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_SELcon\n (out, d0e) = let\n\/\/\nval-ATSSELcon\n (d0rec, s0e, id) = d0e.d0exp_node\nval-S0Eide (name) = s0e.s0exp_node\nval-~Some_vt (s0rec) = typedef_search_opt (name)\n\/\/\nval index = tyrec_labsel (s0rec, id.i0de_sym)\n\/\/\nval () =\n emit_d0exp (out, d0rec)\n\/\/\nval () = emit_LBRACKET (out)\nval () = emit_int (out, index)\nval () = emit_RBRACKET (out)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit_SELcon]\n\n(* ****** ****** *)\n\nimplement\nemit_SELboxrec\n (out, d0e) = let\n\/\/\nval-ATSSELboxrec\n (d0rec, s0e, id) = d0e.d0exp_node\nval-S0Eide (name) = s0e.s0exp_node\nval-~Some_vt (s0rec) = typedef_search_opt (name)\n\/\/\nval index = tyrec_labsel (s0rec, id.i0de_sym)\n\/\/\nval () =\n emit_d0exp (out, d0rec)\n\/\/\nval () = emit_LBRACKET (out)\nval () = emit_int (out, index)\nval () = emit_RBRACKET (out)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit_SELboxrec]\n\n(* ****** ****** *)\n\nimplement\nemit_d0ecl\n (out, d0c) = let\nin\n\/\/\ncase+\nd0c.d0ecl_node of\n\/\/\n| D0Cinclude include =>\n {\n val () = emit_text (out, \"#include\")\n val () = emit_SPACE (out)\n\/\/ val () = emit_text (out, include)\n val () = emit_newline (out)\n }\n\/\/\n| D0Cifdef (i0de, d0eclist) =>\n {\n val () = emit_text (out, \"#ifdef\")\n val () = emit_SPACE (out)\n val () = emit_newline (out)\n }\n| D0Cifndef (i0de, d0eclist) =>\n {\n val () = emit_text (out, \"#ifndef\")\n val () = emit_SPACE (out)\n val () = emit_newline (out)\n }\n\/\/\n| D0Ctypedef (id, def) =>\n {\n val () = typedef_insert (id.i0de_sym, def)\n } (* end of [D0Ctypedef] *)\n\/\/\n| D0Cdyncst_mac i0de => ()\n| D0Cdyncst_extfun (i0de, s0explst, s0exp) => ()\n\/\/\n| D0Cfundecl (fk, f0d) => emit_f0decl (out, f0d)\n\/\/\nend \/\/ end of [emit_d0ecl]\n\n(* ****** ****** *)\n\nimplement\nemit_toplevel\n (out, d0cs) = let\n\/\/\nfun\nloop\n(\n out: FILEref, d0cs: d0eclist\n) : void =\n(\n\/\/\ncase+ d0cs of\n| list_nil () => ()\n| list_cons\n (d0c, d0cs) => let\n in\n emit_d0ecl (out, d0c); loop (out, d0cs)\n end \/\/ end of [list_cons]\n\/\/\n)\n\/\/\nin\n loop (out, d0cs)\nend \/\/ end of [emit_toplevel]\n\n(* ****** ****** *)\n\n(* end of [atsparemit_emit_cil.dats] *)\n","old_contents":"(* ****** ****** *)\n\/\/\n\/\/ ATS-parse-emit-python\n\/\/\n(* ****** ****** *)\n\/\/\n\/\/ AS-2014-08-17: start\n\/\/\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_staload.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\nUN = \"prelude\/SATS\/unsafe.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/atsparemit.sats\"\nstaload \".\/atsparemit_syntax.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/atsparemit_emit.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/atsparemit_topenv.dats\"\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_ENDL (out) = emit_text (out, \"\\n\")\n\n(* ****** ****** *)\n\nimplement\nemit_SPACE (out) = emit_text (out, \" \")\n\n(* ****** ****** *)\n\nimplement\nemit_SHARP (out) = emit_text (out, \"#\")\n\n(* ****** ****** *)\n\nimplement\nemit_LPAREN (out) = emit_text (out, \"(\")\nimplement\nemit_RPAREN (out) = emit_text (out, \")\")\n\n(* ****** ****** *)\n\nimplement\nemit_LBRACE (out) = emit_text (out, \"{\")\nimplement\nemit_RBRACE (out) = emit_text (out, \"}\")\n\n\n(* ****** ****** *)\n\nimplement\nemit_LBRACKET (out) = emit_text (out, \"[\")\nimplement\nemit_RBRACKET (out) = emit_text (out, \"]\")\n\n(* ****** ****** *)\n\nimplement\nemit_flush (out) = fileref_flush (out)\nimplement\nemit_newline (out) = fprint_newline (out)\n\n(* ****** ****** *)\n\/\/\nimplement\nemit_int (out, x) = fprint_int (out, x)\n\/\/\nimplement\nemit_text (out, x) = fprint_string (out, x)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nemit_symbol (out, x) =\n fprint_string (out, symbol_get_name (x))\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_PMVint\n (out, tok) = let\n\/\/\nval-T_INT(base, rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVint]\n\n(* ****** ****** *)\n\nimplement\nemit_PMVi0nt\n (out, tok) = let\n\/\/\nval-T_INT(base, rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVi0nt]\n\n(* ****** ****** *)\n\/\/\nimplement\nemit_PMVbool\n (out, tfv) =\n(\n emit_text (out, if tfv then \"1\" else \"0\")\n) (* end of [emit_PMVbool] *)\n\/\/\n(* ****** ****** *)\nimplement\nemit_PMVstring\n (out, tok) = let\n\/\/\nval-T_STRING(rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVstring]\n\n(* ****** ****** *)\n\/\/\nimplement\nemit_i0de\n (out, id) = emit_symbol (out, id.i0de_sym)\nimplement\nemit_label\n (out, lab) = emit_symbol (out, lab.i0de_sym)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun emit_instrlst\n (out: FILEref, inss: instrlst) : void\n\/\/\nextern\nfun\nemit_s0exp : emit_type (s0exp)\nextern\nfun\nemit_s0explst : emit_type (s0explst)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nemit_s0exp\n (out, s0e) = let\n\/\/\n\/\/\nin\n\/\/\ncase+\ns0e.s0exp_node of\n\/\/\n| S0Eide (id) => emit_symbol (out, id)\n| S0Elist (s0es) => () \/\/ shouldn't happen? marked as \"temp\"\n| S0Eappid (id, s0es) =>\n \/\/ FIXME: what about other types? e.g. array types? struct types?\n () where {\n val () = emit_symbol (out, id)\n val () = emit_LPAREN (out)\n val () = emit_s0explst (out, s0es)\n val () = emit_RPAREN (out)\n }\n\/\/\nend \/\/ end of [emit_s0exp]\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_s0explst\n (out, s0es) = let\n\/\/\nfun\nloop\n(\n out: FILEref, s0es: s0explst, i: int\n) : void =\n(\ncase+ s0es of\n| list_nil () => ()\n| list_cons (s0e, s0es) => let\n val () =\n if i > 0 then emit_text (out, \", \")\n \/\/ end of [val]\n in\n emit_s0exp (out, s0e); loop (out, s0es, i+1)\n end \/\/ end of [list_cons]\n)\n\/\/\nin\n loop (out, s0es, 0)\nend \/\/ end of [emit_s0explst]\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nfunlab_get_index (fl: label): int\nextern\nfun\ntmplab_get_index (lab: label): int\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_f0arglst_get (): f0arglst\nextern\nfun\nthe_f0arglst_set (f0as: f0arglst): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_tmpdeclst_get (): tmpdeclst\nextern\nfun\nthe_tmpdeclst_set (tds: tmpdeclst): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_funbodylst_get (): instrlst\nextern\nfun\nthe_funbodylst_set (inss: instrlst): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_branchlablst_get (): labelist\nextern\nfun\nthe_branchlablst_set (labs: labelist): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_caseofseqlst_get (): instrlst\nextern\nfun\nthe_caseofseqlst_set (inss: instrlst): void\n\/\/\n(* ****** ****** *)\n\nlocal\n\/\/\nval the_f0arglst = ref (list_nil)\nval the_tmpdeclst = ref (list_nil)\n\/\/\nval the_funbodylst = ref (list_nil)\n\/\/\nval the_branchlablst = ref (list_nil)\nval the_caseofseqlst = ref (list_nil)\n\/\/\nin (* in-of-local *)\n\nimplement\nthe_f0arglst_get () = !the_f0arglst\nimplement\nthe_f0arglst_set (xs) = !the_f0arglst := xs\n\nimplement\nthe_tmpdeclst_get () = !the_tmpdeclst\nimplement\nthe_tmpdeclst_set (xs) = !the_tmpdeclst := xs\n\nimplement\nthe_funbodylst_get () = !the_funbodylst\nimplement\nthe_funbodylst_set (xs) = !the_funbodylst := xs\n\nimplement\nthe_branchlablst_get () = !the_branchlablst\nimplement\nthe_branchlablst_set (xs) = !the_branchlablst := xs\n\nimplement\nthe_caseofseqlst_get () = !the_caseofseqlst\nimplement\nthe_caseofseqlst_set (xs) = !the_caseofseqlst := xs\n\nend \/\/ end of [local]\n\n(* ******* ****** *)\n\nlocal\n\nfun\nloop\n(\n out: FILEref, d0es: d0explst, i: int\n) : void =\n(\ncase+ d0es of\n| list_nil () => ()\n| list_cons (d0e, d0es) => let\n val () =\n if i > 0 then emit_newline (out)\n \/\/ end of [val]\n in\n emit_d0exp (out, d0e);\n emit_newline (out);\n loop (out, d0es, i+1)\n end \/\/ end of [list_cons]\n)\n\nin (* in-of-local *)\n\nimplement\nemit_d0explst (out, d0es) = loop (out, d0es, 0)\nimplement\nemit_d0explst_1 (out, d0es) = loop (out, d0es, 1)\n\nend \/\/ end of [local]\n\n(* ******* ****** *)\n\nimplement\nemit_d0exp\n (out, d0e) = let\nin\n\/\/\ncase+\nd0e.d0exp_node of\n\/\/\n| D0Eide (id) =>\n {\n val () = emit_text (out, \"ldloc\")\n val () = emit_SPACE (out)\n val () = emit_symbol (out, id)\n }\n\/\/\n| D0Eappid (id, d0es) =>\n {\n val () = emit_d0explst (out, d0es)\n val () = emit_text (out, \"call\")\n val () = emit_SPACE (out)\n val () = emit_symbol (out, id) \/\/ FIXME: need also type of [id]!\n }\n\/\/\n\/\/\n| ATSPMVint (tok) =>\n {\n val () = emit_text (out, \"ldc.i4\")\n val () = emit_SPACE (out)\n val () = emit_PMVint (out, tok)\n } (* end of [ATSPMVint] *)\n| ATSPMVi0nt (tok) =>\n {\n val () = emit_text (out, \"ldc.i4\")\n val () = emit_SPACE (out)\n val () = emit_PMVi0nt (out, tok)\n } (* end of [ATSPMVi0nt] *)\n\/\/\n| ATSPMVbool (tfv) =>\n {\n val () = emit_text (out, \"ldc.i4\")\n val () = emit_SPACE (out)\n val () = emit_PMVbool (out, tfv)\n } (* end of [ATSPMVbool] *)\n\/\/\n| ATSPMVstring (tok) =>\n {\n val () = emit_text (out, \"ldstr\")\n val () = emit_SPACE(out)\n val () = emit_PMVstring (out, tok)\n } (* end of [ATSPMVstring] *)\n\/\/\n| ATSPMVf0loat (tok) => emit_text (out, \"ATSPMVf0loat(...)\")\n\/\/\n| _ => ()\n\/\/\nend \/\/ end of [emit_d0exp]\n\n(* ****** ****** *)\n\/\/\nextern\nfun emit_f0arg : emit_type (f0arg)\nextern\nfun emit_f0marg : emit_type (f0marg)\nextern\nfun emit_f0head : emit_type (f0head)\n\/\/\nextern\nfun emit_f0body : emit_type (f0body)\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_f0arg\n (out, f0a) = let\nin\n\/\/\ncase+\nf0a.f0arg_node of\n\/\/\n| F0ARGnone s0e => emit_text (out, \"__NONE__\") \/\/ FIXME: how to emit type decl?\n| F0ARGsome (id, s0e) =>\n {\n val () = emit_s0exp (out, s0e)\n val () = emit_SPACE (out)\n val () = emit_i0de (out, id)\n } (* end of [F0ARGsome] *)\n\/\/\nend \/\/ end of [emit_f0arg]\n\n(* ****** ****** *)\n\nimplement\nemit_f0marg\n (out, f0ma) = let\n\/\/\nfun\nloop\n(\n out: FILEref, f0as: f0arglst, i: int\n) : void =\n(\ncase+ f0as of\n| list_nil () => ()\n| list_cons (f0a, f0as) => let\n val () =\n if i > 0 then emit_text (out, \", \")\n \/\/ end of [val]\n in\n emit_f0arg (out, f0a); loop (out, f0as, i+1)\n end \/\/ end of [list_cons]\n)\n\/\/\nin\n loop (out, f0ma.f0marg_node, 0)\nend \/\/ end of [emit_f0marg]\n\n(* ****** ****** *)\n\nimplement\nemit_f0head\n (out, fhd) = let\n\/\/\nval f0as =\n f0head_get_f0arglst (fhd)\n\/\/\nval () = the_f0arglst_set (f0as)\n\/\/\nin\n\/\/\ncase+\nfhd.f0head_node of\n| F0HEAD\n (id(*name of function*), f0ma(*list of arguments*), res(*result type*)) =>\n {\n val () = emit_s0exp (out, res)\n val () = emit_SPACE (out)\n val () = emit_i0de (out, id)\n val () = emit_LPAREN (out)\n val () = emit_f0marg (out, f0ma)\n val () = emit_RPAREN (out)\n }\n\/\/\nend \/\/ end of [emit_f0head]\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit_tmpdeclst\n (out: FILEref, tds: tmpdeclst): void\n\/\/\nimplement\nemit_tmpdeclst\n (out, tds) = let\n\/\/\nfun auxlst\n(\n out: FILEref, tds: tmpdeclst, i: int\n) : void =\n(\ncase+ tds of\n| list_nil () => ()\n| list_cons (td, tds) =>\n (\n case+ td.tmpdec_node of\n | TMPDECnone\n (tmp) => auxlst (out, tds, i) \/\/ probably ATStmpdec_void()\n | TMPDECsome\n (tmp, s0e) => let\n val () =\n if i > 0 then\n emit_text(out, \", \")\n \/\/ end of [val]\n val () = emit_s0exp (out, s0e)\n val () = emit_SPACE (out)\n val () = emit_i0de (out, tmp)\n val () = emit_newline (out)\n in\n auxlst (out, tds, i+1)\n end \/\/ end of [TMPDECsome]\n ) (* end of [list_cons] *)\n)\n\/\/\nin\n auxlst (out, tds, 0)\nend \/\/ end of [emit_tmpdeclst_initize]\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun emit_instr\n (out: FILEref, ins: instr) : void\n\/\/\nimplement\nemit_instr\n (out, ins0) = let\nin\n\/\/\ncase+\nins0.instr_node of\n\/\/\n| ATSif\n (\n d0e(*test*), inss(*then*), inssopt(*else*)\n ) =>\n {\n \/\/ TODO: labels must be assigned automatically... but how?\n val () = emit_d0exp (out, d0e)\n val () = emit_newline (out)\n val () = emit_text (out, \"brfalse L1\")\n val () = emit_newline (out)\n val () = emit_instrlst (out, inss)\n val () =\n (\n case+ inssopt of\n | Some(inss) =>\n {\n val () = emit_text (out, \"br L2\")\n val () = emit_newline (out)\n val () = emit_text (out, \"L1:\")\n val () = emit_newline (out)\n val () = emit_instrlst (out, inss)\n }\n | None((*void*)) => ()\n )\n val () = emit_text (out, \"L2:\") \/\/ next instruction, whatever it may be\n val () = emit_newline (out)\n } (* end of [ATSif] *)\n\/\/ TODO: ATSifthen, ATSifnthen, ATScaseofseq, ATSbranchseq\n\/\/ TODO: ATSlinepragma\n\/\/\n| ATSreturn (tmp) =>\n {\n \/\/ FIXME: if tmp is actually funarg, we must use ldarg\n val () = emit_text (out, \"ldloc\")\n val () = emit_SPACE (out)\n val () = emit_i0de (out, tmp)\n val () = emit_newline (out)\n val () = emit_text (out, \"ret\")\n }\n\/\/\n| ATSreturn_void (tmp) =>\n {\n val () = emit_text (out, \"ret\")\n }\n\/\/\n| ATSlinepragma (line, file) =>\n {\n \/\/ skip\n }\n\/\/\n| ATSINSlab (lab) =>\n {\n val () = emit_label (out, lab)\n val () = emit_text (out, \":\")\n }\n\/\/\n| ATSINSgoto (lab) =>\n {\n val () = emit_text (out, \"br\")\n val () = emit_SPACE (out)\n val () = emit_label (out, lab)\n }\n\/\/\n| ATSINSflab (flab) =>\n {\n val () = emit_label (out, flab)\n val () = emit_text (out, \":\")\n }\n\/\/\n| ATSINSfgoto (flab) =>\n {\n val () = emit_text (out, \"br\")\n val () = emit_SPACE (out)\n val () = emit_label (out, flab)\n }\n\/\/\n| ATSINSmove (tmp, d0e) =>\n {\n val () = emit_d0exp (out, d0e)\n val () = emit_newline (out)\n val () = emit_text (out, \"stloc\")\n val () = emit_SPACE (out)\n val () = emit_i0de (out, tmp)\n } (* end of [ATSINSmove] *)\n| ATSINSmove_void (_, d0e) =>\n {\n val () = emit_d0exp (out, d0e)\n } (* end of [ATSINSmove_void] *)\n\/\/ TODO: ATSdynload0, ATSdynload1, ATSdynloadset\n\/\/\n| _ =>\n {\n val () = emit_text (out, \"**INSTR**\")\n }\n\/\/\nend \/\/ end of [emit_instr]\n\n(* ****** ****** *)\nimplement\nemit_instrlst\n(\n out, inss\n) = (\n\/\/\ncase+ inss of\n| list_nil () => ()\n| list_cons (ins, inss) =>\n {\n val () = emit_instr (out, ins)\n val () = emit_ENDL (out)\n val () = emit_instrlst (out, inss)\n }\n\/\/\n) (* end of [emit_instrlst] *)\n\n(* ****** ****** *)\n\/\/\nextern\nfun emit_ATSfunbodyseq\n (out: FILEref, ins: instr) : void\n\/\/\nimplement\nemit_ATSfunbodyseq\n (out, ins) = let\n\/\/\nval-ATSfunbodyseq (inss) = ins.instr_node\n\/\/\nin\n emit_instrlst (out, inss)\nend \/\/ end of [emit_ATSfunbodyseq]\n\n(* ****** ****** *)\n\/\/\nextern\nfun emit_f0body_0 : emit_type (f0body)\n\/\/\nimplement\nemit_f0body_0\n (out, fbody) = let\n\/\/\nfun\nauxlst\n(\n out: FILEref, inss: instrlst\n) : void =\n(\ncase+ inss of\n| list_nil () => ()\n| list_cons\n (ins0, inss1) => let\n val-list_cons (ins1, inss2) = inss1\n val () = emit_ATSfunbodyseq (out, ins0)\n val () = emit_instr (out, ins1)\n in\n auxlst (out, inss2)\n end \/\/ end of [list_cons]\n) (* end of [auxlst] *)\n\/\/\nin\n\/\/\ncase+\nfbody.f0body_node of\n\/\/\n| F0BODY (tds, inss) => auxlst (out, inss)\n\/\/\nend \/\/ end of [emit_f0body_0]\n\n(* ****** ****** *)\nimplement\nemit_f0body\n (out, fbody) = let\n\/\/\nval tmpdecs =\n f0body_get_tmpdeclst (fbody)\n\/\/\nval () = the_tmpdeclst_set (tmpdecs)\nval () = emit_LBRACE (out)\nval () = emit_newline (out)\n\/\/ TODO: how to compute maxstack?\nval () = emit_text (out, \".maxstack 1\")\nval () = emit_newline (out)\n\/\/ emit locals\nval () = emit_text (out, \".locals\")\nval () = emit_SPACE (out)\nval () = emit_text (out, \"init\")\nval () = emit_SPACE (out)\nval () = emit_LPAREN (out)\nval () = emit_newline (out)\nval () = emit_tmpdeclst (out, tmpdecs)\nval () = emit_RPAREN (out)\nval () = emit_newline (out)\n\/\/ .locals init (\n\/\/ class [Mono.Cecil]Mono.Cecil.AssemblyNameDefinition V_0,\n\/\/ int32 V_1\n\/\/ )\nval () = emit_f0body_0 (out, fbody)\nval () = emit_newline (out)\nval () = emit_RBRACE (out)\nin\n\/\/\n\/\/\nend \/\/ end of [emit_f0body]\n\n(* ****** ****** *)\n\nimplement\nemit_f0decl\n (out, fdec) = let\nin\n\/\/\ncase+\nfdec.f0decl_node of\n| F0DECLnone (fhd) =>\n \/\/ does this actually mean function declaration (e.g. forward function decl)?\n ()\n| F0DECLsome (fhd, fbody) =>\n {\n val () = emit_text (out, \".method\")\n val () = emit_SPACE (out)\n val () = emit_text (out, \"static\")\n \/\/ TODO: public\/private?\n val () = emit_SPACE (out)\n val () = emit_text (out, \"public\")\n val () = emit_SPACE (out)\n \/\/ FIXME: where is the type of this function??\n val () = emit_f0head (out, fhd)\n val () = emit_SPACE (out) \n val () = emit_text (out, \"cil\")\n val () = emit_SPACE (out)\n val () = emit_text (out, \"managed\")\n val () = emit_newline (out)\n val () = emit_f0body (out, fbody)\n val () = emit_newline (out)\n } (* end of [F0DECLsome] *)\n\/\/\nend \/\/ end of [emit_f0decl]\n\n(* ****** ****** *)\n\n\/\/\nextern\nfun\ntyrec_labsel\n (tyrec: tyrec, lab: symbol): int\n\/\/\nimplement\ntyrec_labsel\n (tyrec, lab) = let\n\/\/\nfun loop\n(\n xs: tyfldlst, i: int\n) : int =\n(\ncase+ xs of\n| list_cons (x, xs) => let\n val TYFLD (id, s0e) = x.tyfld_node\n in\n if lab = id.i0de_sym then i else loop (xs, i+1)\n end \/\/ end of [list_cons\n| list_nil ((*void*)) => ~1(*error*)\n)\n\/\/\nin\n loop (tyrec.tyrec_node, 0)\nend \/\/ end of [tyrec_labsel]\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_SELcon\n (out, d0e) = let\n\/\/\nval-ATSSELcon\n (d0rec, s0e, id) = d0e.d0exp_node\nval-S0Eide (name) = s0e.s0exp_node\nval-~Some_vt (s0rec) = typedef_search_opt (name)\n\/\/\nval index = tyrec_labsel (s0rec, id.i0de_sym)\n\/\/\nval () =\n emit_d0exp (out, d0rec)\n\/\/\nval () = emit_LBRACKET (out)\nval () = emit_int (out, index)\nval () = emit_RBRACKET (out)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit_SELcon]\n\n(* ****** ****** *)\n\nimplement\nemit_SELboxrec\n (out, d0e) = let\n\/\/\nval-ATSSELboxrec\n (d0rec, s0e, id) = d0e.d0exp_node\nval-S0Eide (name) = s0e.s0exp_node\nval-~Some_vt (s0rec) = typedef_search_opt (name)\n\/\/\nval index = tyrec_labsel (s0rec, id.i0de_sym)\n\/\/\nval () =\n emit_d0exp (out, d0rec)\n\/\/\nval () = emit_LBRACKET (out)\nval () = emit_int (out, index)\nval () = emit_RBRACKET (out)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit_SELboxrec]\n\n(* ****** ****** *)\n\nimplement\nemit_d0ecl\n (out, d0c) = let\nin\n\/\/\ncase+\nd0c.d0ecl_node of\n\/\/\n| D0Cinclude include => ()\n where {\n val () = emit_text (out, \"#include\")\n val () = emit_SPACE (out)\n\/\/ val () = emit_text (out, include)\n val () = emit_newline (out)\n }\n\/\/\n| D0Cifdef (i0de, d0eclist) => ()\n| D0Cifndef (i0de, d0eclist) => ()\n\/\/\n| D0Ctypedef (id, def) =>\n {\n val () = typedef_insert (id.i0de_sym, def)\n } (* end of [D0Ctypedef] *)\n\/\/\n| D0Cdyncst_mac i0de => ()\n| D0Cdyncst_extfun (i0de, s0explst, s0exp) => ()\n\/\/\n| D0Cfundecl (fk, f0d) => emit_f0decl (out, f0d)\n\/\/\nend \/\/ end of [emit_d0ecl]\n\n(* ****** ****** *)\n\nimplement\nemit_toplevel\n (out, d0cs) = let\n\/\/\nfun\nloop\n(\n out: FILEref, d0cs: d0eclist\n) : void =\n(\n\/\/\ncase+ d0cs of\n| list_nil () => ()\n| list_cons\n (d0c, d0cs) => let\n in\n emit_d0ecl (out, d0c); loop (out, d0cs)\n end \/\/ end of [list_cons]\n\/\/\n)\n\/\/\nin\n loop (out, d0cs)\nend \/\/ end of [emit_toplevel]\n\n(* ****** ****** *)\n\n(* end of [atsparemit_emit_cil.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"961e61f8973a08f9a5aa80fef4775022378719ad","subject":"Updating: working more on ATS-extsolve-z3","message":"Updating: working more on ATS-extsolve-z3\n","repos":"githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib","old_file":"projects\/MEDIUM\/ATS-extsolve-z3\/SOLVING\/patsolve_z3_solving_sort.dats","new_file":"projects\/MEDIUM\/ATS-extsolve-z3\/SOLVING\/patsolve_z3_solving_sort.dats","new_contents":"(*\n##\n## ATS-extsolve-z3:\n## Solving ATS-constraints with Z3\n##\n*)\n\n(* ****** ****** *)\n\/\/\n#ifndef\nPATSOLVE_Z3_SOLVING\n#include \".\/myheader.hats\"\n#endif \/\/ end of [ifndef]\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\nUN = \"prelude\/SATS\/unsafe.sats\"\n\/\/\nstaload \".\/patsolve_z3_solving_ctx.dats\"\n\/\/\n(* ****** ****** *)\n\nassume sort_vtype = Z3_sort\n\n(* ****** ****** *)\n\nimplement\nsort_decref\n (ty) = () where\n{\n val (fpf | ctx) =\n the_Z3_context_vget()\n \/\/ end of [val]\n val () = Z3_sort_dec_ref(ctx, ty)\n prval ((*void*)) = fpf(ctx)\n}\n\n(* ****** ****** *)\n\nimplement\nsort_incref\n (ty) = ty2 where\n{\n val (fpf | ctx) =\n the_Z3_context_vget()\n \/\/ end of [val]\n val ty2 = Z3_sort_inc_ref(ctx, ty)\n prval ((*void*)) = fpf(ctx)\n}\n\n(* ****** ****** *)\n\/\/\nimplement \nsort_int () = res where\n{\n val (fpf | ctx) = \n the_Z3_context_vget()\n \/\/ end of [val]\n val res = Z3_mk_int_sort (ctx)\n prval ((*void*)) = fpf (ctx)\n}\n\/\/\n(* ****** ****** *)\n\/\/\nimplement \nsort_bool () = res where\n{\n val (fpf | ctx) = \n the_Z3_context_vget()\n \/\/ end of [val]\n val res = Z3_mk_bool_sort (ctx)\n prval ((*void*)) = fpf (ctx)\n}\n\/\/\n(* ****** ****** *)\n\/\/\nimplement \nsort_real () = res where\n{\n val (fpf | ctx) = \n the_Z3_context_vget()\n \/\/ end of [val]\n val res = Z3_mk_real_sort (ctx)\n prval ((*void*)) = fpf (ctx)\n}\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nsort_mk_type () = sort_mk_abstract(\"type\")\nimplement\nsort_mk_t0ype () = sort_mk_abstract(\"t0ype\")\n\/\/\nimplement\nsort_mk_vtype () = sort_mk_abstract(\"type\")\nimplement\nsort_mk_vt0ype () = sort_mk_abstract(\"t0ype\")\n\/\/\n(* ****** ****** *)\n\/\/\n(*\nimplement\nsort_mk_abstract(name) = sort_int()\n*)\n\/\/\nimplement\nsort_mk_abstract\n (name) = res where\n{\n val (fpf | ctx) = \n the_Z3_context_vget()\n \/\/ end of [val]\n val sym = Z3_mk_string_symbol (ctx, name)\n val res = Z3_mk_uninterpreted_sort (ctx, sym)\n prval ((*void*)) = fpf (ctx)\n}\n\/\/\n(* ****** ****** *)\n\nimplement\nsort_error\n (s2t0) = res where\n{\n\/\/\nval () =\nprerrln!\n (\"sort_error: s2t0 = \", s2t0)\n\/\/\nval () = assertloc(false)\nval res = sort_error(s2t0)\n\/\/\n} (* end of [sort_error] *)\n\n(* ****** ****** *)\n\nimplement\nsort_make_s2rt(s2t0) = let\n\/\/\n(*\nval () =\nprintln! (\"sort_make: s2t0 = \", s2t0)\n*)\n\/\/\nin\n\/\/\ncase+ s2t0 of\n\/\/\n| S2RTint() => sort_int()\n| S2RTaddr() => sort_int()\n| S2RTbool() => sort_bool()\n\/\/\n| S2RTreal() => sort_real()\n(*\n| S2RTstring() => sort_string()\n*)\n\/\/\n| S2RTtype() => sort_mk_type()\n| S2RTt0ype() => sort_mk_t0ype()\n| S2RTvtype() => sort_mk_vtype()\n| S2RTvt0ype() => sort_mk_vt0ype()\n\/\/\n| _(*unrecognized*) => sort_error(s2t0)\n\/\/\nend (* end of [sort_make_s2rt] *)\n\n(* ****** ****** *)\n\n(* end of [patsolve_z3_solving_sort.dats] *)\n","old_contents":"(*\n##\n## ATS-extsolve-z3:\n## Solving ATS-constraints with Z3\n##\n*)\n\n(* ****** ****** *)\n\/\/\n#ifndef\nPATSOLVE_Z3_SOLVING\n#include \".\/myheader.hats\"\n#endif \/\/ end of [ifndef]\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\nUN = \"prelude\/SATS\/unsafe.sats\"\n\/\/\nstaload \".\/patsolve_z3_solving_ctx.dats\"\n\/\/\n(* ****** ****** *)\n\nassume sort_vtype = Z3_sort\n\n(* ****** ****** *)\n\nimplement\nsort_decref\n (ty) = () where\n{\n val (fpf | ctx) =\n the_Z3_context_vget()\n \/\/ end of [val]\n val () = Z3_sort_dec_ref(ctx, ty)\n prval ((*void*)) = fpf(ctx)\n}\n\n(* ****** ****** *)\n\nimplement\nsort_incref\n (ty) = ty2 where\n{\n val (fpf | ctx) =\n the_Z3_context_vget()\n \/\/ end of [val]\n val ty2 = Z3_sort_inc_ref(ctx, ty)\n prval ((*void*)) = fpf(ctx)\n}\n\n(* ****** ****** *)\n\/\/\nimplement \nsort_int () = res where\n{\n val (fpf | ctx) = \n the_Z3_context_vget()\n \/\/ end of [val]\n val res = Z3_mk_int_sort (ctx)\n prval ((*void*)) = fpf (ctx)\n}\n\/\/\n(* ****** ****** *)\n\/\/\nimplement \nsort_bool () = res where\n{\n val (fpf | ctx) = \n the_Z3_context_vget()\n \/\/ end of [val]\n val res = Z3_mk_bool_sort (ctx)\n prval ((*void*)) = fpf (ctx)\n}\n\/\/\n(* ****** ****** *)\n\/\/\nimplement \nsort_real () = res where\n{\n val (fpf | ctx) = \n the_Z3_context_vget()\n \/\/ end of [val]\n val res = Z3_mk_real_sort (ctx)\n prval ((*void*)) = fpf (ctx)\n}\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nsort_mk_type () = sort_mk_abstract(\"type\")\nimplement\nsort_mk_t0ype () = sort_mk_abstract(\"t0ype\")\n\/\/\nimplement\nsort_mk_vtype () = sort_mk_abstract(\"type\")\nimplement\nsort_mk_vt0ype () = sort_mk_abstract(\"t0ype\")\n\/\/\n(* ****** ****** *)\n\/\/\n(*\nimplement\nsort_mk_abstract(name) = sort_int()\n*)\n\/\/\nimplement\nsort_mk_abstract\n (name) = res where\n{\n val (fpf | ctx) = \n the_Z3_context_vget()\n \/\/ end of [val]\n val sym = Z3_mk_string_symbol (ctx, name)\n val res = Z3_mk_uninterpreted_sort (ctx, sym)\n prval ((*void*)) = fpf (ctx)\n}\n\/\/\n(* ****** ****** *)\n\nimplement\nsort_error\n (s2t0) = res where\n{\n\/\/\nval () =\nprerrln!\n (\"sort_error: s2t0 = \", s2t0)\n\/\/\nval () = assertloc(false)\nval res = sort_error(s2t0)\n\/\/\n} (* end of [sort_error] *)\n\n(* ****** ****** *)\n\nimplement\nsort_make_s2rt(s2t0) = let\n\/\/\nval () =\nprintln! (\"sort_make: s2t0 = \", s2t0)\n\/\/\nin\n\/\/\ncase+ s2t0 of\n\/\/\n| S2RTint() => sort_int()\n| S2RTaddr() => sort_int()\n| S2RTbool() => sort_bool()\n\/\/\n| S2RTreal() => sort_real()\n(*\n| S2RTstring() => sort_string()\n*)\n\/\/\n| S2RTtype() => sort_mk_type()\n| S2RTt0ype() => sort_mk_t0ype()\n| S2RTvtype() => sort_mk_vtype()\n| S2RTvt0ype() => sort_mk_vt0ype()\n\/\/\n| _(*unrecognized*) => sort_error(s2t0)\n\/\/\nend (* end of [sort_make_s2rt] *)\n\n(* ****** ****** *)\n\n(* end of [patsolve_z3_solving_sort.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"4cc471ac0f54bb251d1659329cc1a14bb453ed09","subject":"Updating: very minorly tidying-up","message":"Updating: very minorly tidying-up\n","repos":"ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib","old_file":"projects\/MEDIUM\/OOPLATS\/OOPLATS-trial0\/TEST\/test02.dats","new_file":"projects\/MEDIUM\/OOPLATS\/OOPLATS-trial0\/TEST\/test02.dats","new_contents":"(* ****** ****** *)\n\/\/\nstaload\n\"libats\/ML\/SATS\/basis.sats\"\n\/\/\nstaload \".\/..\/OOPLATS.sats\"\n\/\/\n(* ****** ****** *)\n\nabstype symbol(t@ype)\n\n(* ****** ****** *)\n\/\/\nextern\nval\nsymbol$print :\n symbol(cfun(class, value, void))\nextern\nval\nsymbol$fprint :\n symbol(cfun(class, FILEref, value, void))\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nclass_getsym{a:t@ype}(class, symbol(a)): a\n\/\/\n(* ****** ****** *)\n\nfun\nevalmsg$print\n (class, value): void = let\n\/\/\nval\nfprint_mtd =\nclass_getsym (class, symbol$fprint)\n\/\/\nin\n fprint_mtd (class, stdout_ref, value)\nend \/\/ end of [evalmsg$print]\n\n(* ****** ****** *)\n\/\/\nextern\nval\nthe_object_class : class\n\/\/\n(* ****** ****** *)\n\/\/\n(*\nval () =\nclass_setmtd\n (the_object_class, symbol$print, evalmsg$print)\n*)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun tocls_int(x: int): class\nextern\nfun tocls_double(x: double): class\nextern\nfun tocls_string(x: string): class\n\/\/\nsymintr tocls\n\/\/\noverload tocls with tocls_int\noverload tocls with tocls_double\noverload tocls with tocls_string\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nprint_int\n (x: int): void = evalmsg$print(tocls(x), toval(x))\nfun\nprint_double\n (x: double): void = evalmsg$print(tocls(x), toval(x))\nfun\nprint_string\n (x: string): void = evalmsg$print(tocls(x), toval(x))\n\/\/\n(* ****** ****** *)\n\n(* end of [test02.dats] *)\n","old_contents":"(* ****** ****** *)\n\/\/\nstaload\n\"libats\/ML\/SATS\/basis.sats\"\n\/\/\nstaload \".\/..\/OOPLATS.sats\"\n\/\/\n(* ****** ****** *)\n\nabstype symbol(t@ype)\n\n(* ****** ****** *)\n\nextern\nval\nsymbol$print :\n symbol(cfun(class, value, void))\nextern\nval\nsymbol$fprint :\n symbol(cfun(class, FILEref, value, void))\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nclass_getsym{a:t@ype}(class, symbol(a)): a\n\/\/\n(* ****** ****** *)\n\nfun\nevalmsg$print\n (class, value): void = let\n\/\/\nval\nfprint_mtd =\nclass_getsym (class, symbol$fprint)\n\/\/\nin\n fprint_mtd (class, stdout_ref, value)\nend \/\/ end of [evalmsg$print]\n\n(* ****** ****** *)\n\/\/\nextern\nval\nthe_object_class : class\n\/\/\n(* ****** ****** *)\n\/\/\n(*\nval () =\nclass_setmtd\n (the_object_class, symbol$print, evalmsg$print)\n*)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun tocls_int(x: int): class\nextern\nfun tocls_double(x: double): class\nextern\nfun tocls_string(x: string): class\n\/\/\nsymintr tocls\n\/\/\noverload tocls with tocls_int\noverload tocls with tocls_double\noverload tocls with tocls_string\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nprint_int\n (x: int): void = evalmsg$print(tocls(x), toval(x))\nfun\nprint_double\n (x: double): void = evalmsg$print(tocls(x), toval(x))\nfun\nprint_string\n (x: string): void = evalmsg$print(tocls(x), toval(x))\n\/\/\n(* ****** ****** *)\n\n(* end of [test02.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"4bc947be09ed07cf54ba7ff7aea26d13dd52aaa3","subject":"Updating: working more on ATS-extsolve-z3","message":"Updating: working more on ATS-extsolve-z3\n","repos":"githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib","old_file":"projects\/MEDIUM\/ATS-extsolve-z3\/patsolve_z3_solving.dats","new_file":"projects\/MEDIUM\/ATS-extsolve-z3\/patsolve_z3_solving.dats","new_contents":"(*\n##\n## ATS-extsolve-z3:\n## Solving ATS-constraints with Z3\n##\n*)\n\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_define.hats\"\n#include\n\"share\/atspre_staload.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\n#define\nZ3_targetloc\n\"$PATSHOMERELOC\/contrib\/SMT\/Z3\"\n\/\/\n#define\nPATSOLVE_targetloc \".\/.ATS-extsolve\"\n\/\/\n(* ****** ****** *)\n\nstaload \"{$Z3}\/SATS\/z3.sats\"\n\n(* ****** ****** *)\n\/\/\nstaload\n\"{$PATSOLVE}\/patsolve_cnstrnt.sats\"\nstaload\n\"{$PATSOLVE}\/patsolve_parsing.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/patsolve_z3_solving.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nabsview\nsmtenv_push_v\n\/\/\nextern\nfun\nsmtenv_push\n (env: !smtenv): (smtenv_push_v | void)\n\/\/\nextern\nfun\nsmtenv_pop\n (pf: smtenv_push_v | env: !smtenv): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nc3nstr_solve_errmsg\n (c3t: c3nstr, unsolved: uint): int\n\/\/\nimplement \nc3nstr_solve_errmsg\n (c3t, unsolved) = 0 where\n{\n\/\/\nval () = (\n\/\/\nif\nunsolved = 0u\nthen let\n val out = stderr_ref\n val loc = c3t.c3nstr_loc\nin\n fprintln! (out, \"Unsolved constraint @ \", loc, \":\", c3t);\nend \/\/ end of [then]\n\/\/\n) (* end of [val] *)\n\/\/\n} (* end of [c3nstr_solve_errmsg] *)\n\/\/\n(* ****** ****** *)\n\nextern\nfun\nc3nstr_solve_prop\n(\n loc0: loc_t\n, env: !smtenv, s2p: s2exp, nerr: &int >> _\n) : int (*status*) \/\/ end-of-function\n\n(* ****** ****** *)\n\nextern\nfun\nc3nstr_solve_itmlst\n(\n loc0: loc_t, env: !smtenv\n, s3is: s3itmlst, unsolved: &uint >> _, nerr: &int >> _\n) : int(*status*) \/\/ end-of-function\n\n(* ****** ****** *)\n\nextern\nfun\nc3nstr_solve_itmlst_cnstr\n(\n loc0: loc_t, env: !smtenv\n, s3is: s3itmlst, c3t: c3nstr, unsolved: &uint >> _, nerr: &int >> _\n) : int(*status*) \/\/ end-of-function\n\n(* ****** ****** *)\n\nextern fun\nc3nstr_solve_itmlst_disj\n(\n loc0: loc_t, env: !smtenv\n, s3is: s3itmlst, s3iss: s3itmlstlst, unsolved: &uint >> _, nerr: &int >> _\n) : int(*status*) \/\/ end-of-function\n\n(* ****** ****** *)\n\nextern\nfun\nc3nstr_solve_main \n(\n env: !smtenv, c3t: c3nstr, unsolved : &uint >> _, nerr: &int >> _\n) : int(*status*) \/\/ end of [c3nstr_solve_main]\n\n(* ****** ****** *)\n\nimplement\nc3nstr_solve_prop\n(\n loc0, env, s2p, nerr\n) = let\n\/\/\nval s2p =\n formula_make_s2exp (env, s2p)\n\/\/\nval ans =\n smtenv_formula_solve (env, s2p)\n\/\/\nin\n\/\/\nif ans then ~1(*solved*) else 0 (*unsolved*)\n\/\/\nend \/\/ end of [c3nstr_solve_prop]\n\n(* ****** ****** *)\n\nimplement\nc3nstr_solve_itmlst\n(\n loc0, env, s3is, unsolved, nerr\n) = let\n\/\/\nval () =\nprintln!\n (\"c3str_solve_itmlst: s3is = \", s3is)\n\/\/\nin\n\/\/\ncase+ s3is of\n| list_nil\n ((*void*)) => ~1(*solved*)\n \/\/ end of [list_nil]\n| list_cons\n (s3i, s3is) =>\n (\n case+ s3i of\n | S3ITMsvar (s2v) => let\n val () = smtenv_add_s2var (env, s2v)\n in\n c3nstr_solve_itmlst (loc0, env, s3is, unsolved, nerr)\n end \/\/ end of [S3ITMsvar]\n | S3ITMhypo (h3p) => let\n val s2p = s2exp_make_h3ypo (h3p)\n val ((*void*)) = smtenv_add_s2exp (env, s2p)\n in\n c3nstr_solve_itmlst (loc0, env, s3is, unsolved, nerr)\n end \/\/ end of [S3ITMhypo]\n | S3ITMsVar (s2V) =>\n c3nstr_solve_itmlst (loc0, env, s3is, unsolved, nerr)\n | S3ITMcnstr c3t =>\n c3nstr_solve_itmlst_cnstr (loc0, env, s3is, c3t, unsolved, nerr)\n | S3ITMcnstr_ref\n (loc1, ctr) => (\n case+ ctr of\n | Some(c3t) =>\n c3nstr_solve_itmlst_cnstr (loc1, env, s3is, c3t, unsolved, nerr)\n \/\/ end of [Some]\n | None((*void*)) => ~1(*solved*)\n ) (* end of [S3ITMcnstr] *)\n | S3ITMdisj (s3iss_disj) =>\n c3nstr_solve_itmlst_disj (loc0, env, s3is, s3iss_disj, unsolved, nerr)\n \/\/ end of [S3ITMdisj]\n ) \/\/ end of [list_cons]\n\/\/\nend \/\/ end of [c3nstr_solve_itmlst]\n\n(* ****** ****** *)\n\nimplement\nc3nstr_solve_itmlst_cnstr\n(\n loc0, env, s3is, c3t, unsolved, nerr\n) = let\n val (pf|()) = smtenv_push (env)\n val ans1 =\n c3nstr_solve_main (env, c3t, unsolved, nerr)\n \/\/ end of [val]\n val ((*void*)) = smtenv_pop (pf | env)\n val ans2 =\n c3nstr_solve_itmlst (loc0, env, s3is, unsolved, nerr)\n \/\/ end of [val]\nin\n if ans1 >= 0 then 0(*unsolved*) else ans2\nend \/\/ end of [c3nstr_solve_itmlst_cnstr]\n\n(* ****** ****** *)\n\nimplement\nc3nstr_solve_itmlst_disj\n(\n loc0, env\n, s3is0, s3iss(*disj*), unsolved, nerr\n) = let\n(*\nval () = (\n println! (\"c3nstr_solve_itmlst_disj: s3iss = ...\")\n) (* end of [val] *)\n*)\nin\n\/\/\ncase+ s3iss of\n| list_nil\n ((*void*)) => ~1 (*solved*)\n \/\/ end of [list_nil]\n| list_cons\n (s3is, s3iss) => let\n val (pf|()) = smtenv_push (env)\n val s3is1 = list_append (s3is, s3is0)\n val ans = c3nstr_solve_itmlst (loc0, env, s3is1, unsolved, nerr)\n val ((*void*)) = smtenv_pop (pf | env)\n in\n c3nstr_solve_itmlst_disj (loc0, env, s3is0, s3iss, unsolved, nerr)\n end \/\/ end of [list_cons]\n\/\/\nend \/\/ end of [c3nstr_solve_itmlst_disj]\n\n(* ****** ****** *)\n\nimplement\nc3nstr_solve_main\n(\n env, c3t, unsolved, nerr\n) = let\n\/\/\nval loc0 = c3t.c3nstr_loc\n\/\/\nvar status: int =\n(\n\/\/\n\/\/ ~1: solved; 0: unsolved\n\/\/\ncase+\nc3t.c3nstr_node of\n| C3NSTRprop s2p =>\n c3nstr_solve_prop(loc0, env, s2p, nerr)\n \/\/ end of [C3NSTRprop]\n| C3NSTRitmlst s3is =>\n c3nstr_solve_itmlst(loc0, env, s3is, unsolved, nerr)\n \/\/ end of [C3NSTRitmlst]\n\/\/\n) : int \/\/ end of [val]\n\/\/\nval () = (\n\/\/\nif\nstatus >= 0\nthen {\n val iswarn =\n c3nstr_solve_errmsg (c3t, unsolved)\n \/\/ end of [val]\n val () = if iswarn > 0 then (status := ~1)\n} \/\/ end of [then]\n\/\/\n) (* end of [val] *)\n\/\/\nval () =\n if status >= 0 then (unsolved := unsolved + 1u)\n\/\/\nin\n status (* ~1\/0: solved\/unsolved *)\nend \/\/ end of [c3nstr_solve_main]\n\n(* ****** ****** *)\n\nimplement\n{}(*tmp*)\nc3nstr_z3_solve\n (c3t0) = let\n\/\/\nval env = smtenv_create()\n\/\/\nvar unsolved: uint = 0u and err: int = 0\nval _(*ans*) = c3nstr_solve_main (env, c3t0, unsolved, err)\n\/\/\nval ((*void*)) = smtenv_destroy (env)\nin\n\/\/\ncase+ 0 of\n| _ when\n unsolved = 0u => let\n val () = (\n prerrln! \"typechecking is finished successfully!\"\n ) (* end of [val] *)\n in\n \/\/ nothing\n end \/\/ end of [unsolved = 0]\n| _ (* unsolved > 0 *) =>\n {\n val () = prerr \"typechecking has failed\"\n val () =\n if unsolved <= 1u then prerr \": there is one unsolved constraint\"\n val () =\n if unsolved >= 2u then prerr \": there are some unsolved constraints\"\n val () = (\n prerrln! \": please inspect the above reported error message(s) for information.\"\n ) (* end of [val] *)\n } (* end of [_ when unsolved > 0] *)\n\/\/\nend \/\/ end of [c3nstr_z3_solve]\n\n(* ****** ****** *)\n\n#define PATSOLVE_Z3_SOLVING 1\n\n(* ****** ****** *)\n\nlocal\n\/\/\n#include \".\/SOLVING\/patsolve_z3_solving_sort.dats\"\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [local]\n\n(* ****** ****** *)\n\nlocal\n\/\/\n#include \".\/SOLVING\/patsolve_z3_solving_form.dats\"\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [local]\n\n(* ****** ****** *)\n\nlocal\n\/\/\n#include \".\/SOLVING\/patsolve_z3_solving_smtenv.dats\"\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [local]\n\n(* ****** ****** *)\n\n(* end of [patsolve_z3_solving.dats] *)\n","old_contents":"(*\n##\n## ATS-extsolve-z3:\n## Solving ATS-constraints with Z3\n##\n*)\n\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_define.hats\"\n#include\n\"share\/atspre_staload.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\n#define\nPATSOLVE_targetloc \".\/.ATS-extsolve\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\n\"{$PATSOLVE}\/patsolve_cnstrnt.sats\"\nstaload\n\"{$PATSOLVE}\/patsolve_parsing.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/patsolve_z3_solving.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nabsview\nsmtenv_push_v\n\/\/\nextern\nfun\nsmtenv_push\n (env: !smtenv): (smtenv_push_v | void)\n\/\/\nextern\nfun\nsmtenv_pop\n (pf: smtenv_push_v | env: !smtenv): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nc3nstr_solve_errmsg\n (c3t: c3nstr, unsolved: uint): int\n\/\/\nimplement \nc3nstr_solve_errmsg\n (c3t, unsolved) = 0 where\n{\n\/\/\nval () = (\n\/\/\nif\nunsolved = 0u\nthen let\n val out = stderr_ref\n val loc = c3t.c3nstr_loc\nin\n fprintln! (out, \"Unsolved constraint @ \", loc, \":\", c3t);\nend \/\/ end of [then]\n\/\/\n) (* end of [val] *)\n\/\/\n} (* end of [c3nstr_solve_errmsg] *)\n\/\/\n(* ****** ****** *)\n\nextern\nfun\nc3nstr_solve_prop\n(\n loc0: loc_t\n, env: !smtenv, s2p: s2exp, nerr: &int >> _\n) : int (*status*) \/\/ end-of-function\n\n(* ****** ****** *)\n\nextern\nfun\nc3nstr_solve_itmlst\n(\n loc0: loc_t, env: !smtenv\n, s3is: s3itmlst, unsolved: &uint >> _, nerr: &int >> _\n) : int(*status*) \/\/ end-of-function\n\n(* ****** ****** *)\n\nextern\nfun\nc3nstr_solve_itmlst_cnstr\n(\n loc0: loc_t, env: !smtenv\n, s3is: s3itmlst, c3t: c3nstr, unsolved: &uint >> _, nerr: &int >> _\n) : int(*status*) \/\/ end-of-function\n\n(* ****** ****** *)\n\nextern fun\nc3nstr_solve_itmlst_disj\n(\n loc0: loc_t, env: !smtenv\n, s3is: s3itmlst, s3iss: s3itmlstlst, unsolved: &uint >> _, nerr: &int >> _\n) : int(*status*) \/\/ end-of-function\n\n(* ****** ****** *)\n\nextern\nfun\nc3nstr_solve_main \n(\n env: !smtenv, c3t: c3nstr, unsolved : &uint >> _, nerr: &int >> _\n) : int(*status*) \/\/ end of [c3nstr_solve_main]\n\n(* ****** ****** *)\n\nimplement\nc3nstr_solve_prop\n(\n loc0, env, s2p, nerr\n) = let\n\/\/\nval s2p =\n formula_make_s2exp (env, s2p)\n\/\/\nval ans =\n smtenv_formula_solve (env, s2p)\n\/\/\nin\n\/\/\nif ans then ~1(*solved*) else 0 (*unsolved*)\n\/\/\nend \/\/ end of [c3nstr_solve_prop]\n\n(* ****** ****** *)\n\nimplement\nc3nstr_solve_itmlst\n(\n loc0, env, s3is, unsolved, nerr\n) = let\n\/\/\nval () =\nprintln!\n (\"c3str_solve_itmlst: s3is = \", s3is)\n\/\/\nin\n\/\/\ncase+ s3is of\n| list_nil\n ((*void*)) => ~1(*solved*)\n \/\/ end of [list_nil]\n| list_cons\n (s3i, s3is) =>\n (\n case+ s3i of\n | S3ITMsvar (s2v) => let\n val () = smtenv_add_s2var (env, s2v)\n in\n c3nstr_solve_itmlst (loc0, env, s3is, unsolved, nerr)\n end \/\/ end of [S3ITMsvar]\n | S3ITMhypo (h3p) => let\n val s2p = s2exp_make_h3ypo (h3p)\n val ((*void*)) = smtenv_add_s2exp (env, s2p)\n in\n c3nstr_solve_itmlst (loc0, env, s3is, unsolved, nerr)\n end \/\/ end of [S3ITMhypo]\n | S3ITMsVar (s2V) =>\n c3nstr_solve_itmlst (loc0, env, s3is, unsolved, nerr)\n | S3ITMcnstr c3t =>\n c3nstr_solve_itmlst_cnstr (loc0, env, s3is, c3t, unsolved, nerr)\n | S3ITMcnstr_ref\n (loc1, ctr) => (\n case+ ctr of\n | Some(c3t) =>\n c3nstr_solve_itmlst_cnstr (loc1, env, s3is, c3t, unsolved, nerr)\n \/\/ end of [Some]\n | None((*void*)) => ~1(*solved*)\n ) (* end of [S3ITMcnstr] *)\n | S3ITMdisj (s3iss_disj) =>\n c3nstr_solve_itmlst_disj (loc0, env, s3is, s3iss_disj, unsolved, nerr)\n \/\/ end of [S3ITMdisj]\n ) \/\/ end of [list_cons]\n\/\/\nend \/\/ end of [c3nstr_solve_itmlst]\n\n(* ****** ****** *)\n\nimplement\nc3nstr_solve_itmlst_cnstr\n(\n loc0, env, s3is, c3t, unsolved, nerr\n) = let\n val (pf|()) = smtenv_push (env)\n val ans1 =\n c3nstr_solve_main (env, c3t, unsolved, nerr)\n \/\/ end of [val]\n val ((*void*)) = smtenv_pop (pf | env)\n val ans2 =\n c3nstr_solve_itmlst (loc0, env, s3is, unsolved, nerr)\n \/\/ end of [val]\nin\n if ans1 >= 0 then 0(*unsolved*) else ans2\nend \/\/ end of [c3nstr_solve_itmlst_cnstr]\n\n(* ****** ****** *)\n\nimplement\nc3nstr_solve_itmlst_disj\n(\n loc0, env\n, s3is0, s3iss(*disj*), unsolved, nerr\n) = let\n(*\nval () = (\n println! (\"c3nstr_solve_itmlst_disj: s3iss = ...\")\n) (* end of [val] *)\n*)\nin\n\/\/\ncase+ s3iss of\n| list_nil\n ((*void*)) => ~1 (*solved*)\n \/\/ end of [list_nil]\n| list_cons\n (s3is, s3iss) => let\n val (pf|()) = smtenv_push (env)\n val s3is1 = list_append (s3is, s3is0)\n val ans = c3nstr_solve_itmlst (loc0, env, s3is1, unsolved, nerr)\n val ((*void*)) = smtenv_pop (pf | env)\n in\n c3nstr_solve_itmlst_disj (loc0, env, s3is0, s3iss, unsolved, nerr)\n end \/\/ end of [list_cons]\n\/\/\nend \/\/ end of [c3nstr_solve_itmlst_disj]\n\n(* ****** ****** *)\n\nimplement\nc3nstr_solve_main\n(\n env, c3t, unsolved, nerr\n) = let\n\/\/\nval loc0 = c3t.c3nstr_loc\n\/\/\nvar status: int =\n(\n\/\/\n\/\/ ~1: solved; 0: unsolved\n\/\/\ncase+\nc3t.c3nstr_node of\n| C3NSTRprop s2p =>\n c3nstr_solve_prop(loc0, env, s2p, nerr)\n \/\/ end of [C3NSTRprop]\n| C3NSTRitmlst s3is =>\n c3nstr_solve_itmlst(loc0, env, s3is, unsolved, nerr)\n \/\/ end of [C3NSTRitmlst]\n\/\/\n) : int \/\/ end of [val]\n\/\/\nval () = (\n\/\/\nif\nstatus >= 0\nthen {\n val iswarn =\n c3nstr_solve_errmsg (c3t, unsolved)\n \/\/ end of [val]\n val () = if iswarn > 0 then (status := ~1)\n} \/\/ end of [then]\n\/\/\n) (* end of [val] *)\n\/\/\nval () =\n if status >= 0 then (unsolved := unsolved + 1u)\n\/\/\nin\n status (* ~1\/0: solved\/unsolved *)\nend \/\/ end of [c3nstr_solve_main]\n\n(* ****** ****** *)\n\nimplement\n{}(*tmp*)\nc3nstr_z3_solve\n (c3t0) = let\n\/\/\nval env = smtenv_create()\n\/\/\nvar unsolved: uint = 0u and err: int = 0\nval _(*ans*) = c3nstr_solve_main (env, c3t0, unsolved, err)\n\/\/\nval ((*void*)) = smtenv_destroy (env)\nin\n\/\/\ncase+ 0 of\n| _ when\n unsolved = 0u => let\n val () = (\n prerrln! \"typechecking is finished successfully!\"\n ) (* end of [val] *)\n in\n \/\/ nothing\n end \/\/ end of [unsolved = 0]\n| _ (* unsolved > 0 *) =>\n {\n val () = prerr \"typechecking has failed\"\n val () =\n if unsolved <= 1u then prerr \": there is one unsolved constraint\"\n val () =\n if unsolved >= 2u then prerr \": there are some unsolved constraints\"\n val () = (\n prerrln! \": please inspect the above reported error message(s) for information.\"\n ) (* end of [val] *)\n } (* end of [_ when unsolved > 0] *)\n\/\/\nend \/\/ end of [c3nstr_z3_solve]\n\n(* ****** ****** *)\n\n#define PATSOLVE_Z3_SOLVING 1\n\n(* ****** ****** *)\n\nlocal\n\/\/\n#include \".\/SOLVING\/patsolve_z3_solving_sort.dats\"\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [local]\n\n(* ****** ****** *)\n\nlocal\n\/\/\n#include \".\/SOLVING\/patsolve_z3_solving_form.dats\"\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [local]\n\n(* ****** ****** *)\n\nlocal\n\/\/\n#include \".\/SOLVING\/patsolve_z3_solving_smtenv.dats\"\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [local]\n\n(* ****** ****** *)\n\n(* end of [patsolve_z3_solving.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"d1e06fa9f0d59da5583a290dd88ab2c470a85dc2","subject":"Add dependent types into EEPROM API","message":"Add dependent types into EEPROM API\n","repos":"Proclivis\/arduino-ats,Proclivis\/arduino-ats,fpiot\/arduino-ats,fpiot\/arduino-ats","old_file":"SATS\/eeprom.sats","new_file":"SATS\/eeprom.sats","new_contents":"%{#\n#include \n%}\nfun eeprom_read_byte {n:nat} (address: int n): uint8 = \"mac#\"\nfun eeprom_write_byte {n:nat} (address: int n, value: uint8): void = \"mac#\"\n","old_contents":"%{#\n#include \n%}\nfun eeprom_read_byte (address: int): uint8 = \"mac#\"\nfun eeprom_write_byte (address: int, value: uint8): void = \"mac#\"\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"167f866afb8f873fe3943d6ddc81892fc231994d","subject":"Updating: improving atscc2php","message":"Updating: improving atscc2php\n","repos":"alex-ren\/Learn-ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib","old_file":"projects\/MEDIUM\/ATS-parse-emit\/PHP\/atsparemit_emit2_php.dats","new_file":"projects\/MEDIUM\/ATS-parse-emit\/PHP\/atsparemit_emit2_php.dats","new_contents":"(* ****** ****** *)\n\/\/\n\/\/ ATS-parse-emit-php\n\/\/\n(* ****** ****** *)\n\/\/\n\/\/ HX-2014-08-20: start\n\/\/\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_staload.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\nUN = \"prelude\/SATS\/unsafe.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/atsparemit.sats\"\nstaload \".\/atsparemit_syntax.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/atsparemit_emit.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/atsparemit_typedef.dats\"\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit_tmpdeclst_initize\n(\n out: FILEref, tds: tmpdeclst\n) : void \/\/ end-of-fun\n\/\/\nimplement\nemit_tmpdeclst_initize\n (out, tds) = let\n\/\/\nfun auxlst\n(\n out: FILEref, tds: tmpdeclst\n) : void = let\nin\n\/\/\ncase+ tds of\n| list_nil () => ()\n| list_cons (td, tds) =>\n (\n case+ td.tmpdec_node of\n | TMPDECnone\n (tmp) => auxlst (out, tds)\n | TMPDECsome\n (tmp, _) => let\n val () =\n emit_nspc (out, 2(*ind*))\n val () = (\n emit_text (out, \"\/\/ \"); emit_tmpvar (out, tmp); emit_ENDL (out)\n ) (* end of [val] *)\n in\n auxlst (out, tds)\n end \/\/ end of [TMPDECsome]\n ) (* end of [list_cons] *)\n\/\/\nend \/\/ end of [auxlist]\n\/\/\nin\n auxlst (out, tds)\nend \/\/ end of [emit_tmpdeclst_initize]\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_f0arglst_get (): f0arglst\nextern\nfun\nthe_f0arglst_set (f0as: f0arglst): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_tmpdeclst_get (): tmpdeclst\nextern\nfun\nthe_tmpdeclst_set (tds: tmpdeclst): void\n\/\/\n(* ****** ****** *)\n\/\/\nlocal\n\/\/\nval the_f0arglst = ref (list_nil)\nval the_tmpdeclst = ref (list_nil)\n\/\/\nin (* in-of-local *)\n\nimplement\nthe_f0arglst_get () = !the_f0arglst\nimplement\nthe_f0arglst_set (xs) = !the_f0arglst := xs\n\nimplement\nthe_tmpdeclst_get () = !the_tmpdeclst\nimplement\nthe_tmpdeclst_set (xs) = !the_tmpdeclst := xs\n\nend \/\/ end of [local]\n\n(* ****** ****** *)\n\/\/\nextern\nfun emit2_instr\n (out: FILEref, ind: int, ins: instr) : void\n\/\/\nextern\nfun emit2_instr_ln\n (out: FILEref, ind: int, ins: instr) : void\n\/\/\nextern\nfun emit2_instrlst\n (out: FILEref, ind: int, inss: instrlst) : void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun emit2_ATSfunbodyseq\n (out: FILEref, ind: int, ins: instr) : void\n\/\/\nextern\nfun emit2_ATSINSmove_con1\n (out: FILEref, ind: int, ins: instr) : void\nextern\nfun emit2_ATSINSmove_boxrec\n (out: FILEref, ind: int, ins: instr) : void\n\/\/\n(* ****** ****** *)\n\/\/\n\/\/ HX-2014-08:\n\/\/ this one should not be used for\n\/\/ emitting multiple-line instructions\n\/\/\nimplement\nemit_instr\n (out, ins) = emit2_instr (out, 0(*ind*), ins)\n\/\/\n(* ****** ****** *)\n\nimplement\nemit2_instr\n (out, ind, ins0) = let\nin\n\/\/\ncase+\nins0.instr_node of\n\/\/\n| ATSif\n (\n d0e, inss, inssopt\n ) => let\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"if\")\n val () = emit_LPAREN (out)\n val () = emit_d0exp (out, d0e)\n val () = emit_RPAREN (out)\n val () = emit_text (out, \" {\\n\")\n val () = emit2_instrlst (out, ind+2, inss)\n in\n case+ inssopt of\n | None _ =>\n {\n val () = emit_nspc (out, ind)\n val ((*closing*)) = emit_text (out, \"} \/\/ endif\")\n } (* end of [None] *)\n | Some (inss) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"} else {\\n\")\n val () = emit2_instrlst (out, ind+2, inss)\n val () = emit_nspc (out, ind)\n val ((*closing*)) = emit_text (out, \"} \/\/ endif\")\n } (* end of [Some] *)\n end \/\/ end of [ATSif]\n\/\/\n| ATSifthen (d0e, inss) =>\n {\n\/\/\n val-list_cons (ins, _) = inss\n\/\/\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"if(\")\n val () = emit_d0exp (out, d0e)\n val () = emit_text (out, \") \")\n val () = emit_instr (out, ins)\n }\n\/\/\n| ATSifnthen (d0e, inss) =>\n {\n\/\/\n val-list_cons (ins, _) = inss\n\/\/\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"if(!\")\n val () = emit_d0exp (out, d0e)\n val ((*closing*)) = emit_text (out, \") \")\n val () = emit_instr (out, ins)\n }\n\/\/\n| ATSbranchseq (inss) =>\n {\n\/\/\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"\/\/ ATSbranchseq_beg\")\n\/\/\n val () = emit_ENDL (out)\n val () = emit2_instrlst (out, ind, inss)\n\/\/\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"break;\\n\")\n\/\/\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"\/\/ ATSbranchseq_end\")\n\/\/\n } (* end of [ATSbranchseq] *)\n\/\/\n| ATScaseofseq (inss) =>\n {\n\/\/\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"\/\/ ATScaseofseq_beg\")\n val () = emit_ENDL (out)\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"do {\\n\")\n\/\/\n val () = emit2_instrlst (out, ind+2, inss)\n\/\/\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"} while(0);\\n\")\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"\/\/ ATScaseofseq_end\")\n\/\/\n } (* end of [ATScaseofseq] *)\n\/\/\n| ATSreturn (tmp) =>\n {\n val () = emit_nspc (out, ind)\n val () = (\n emit_text (out, \"return \"); emit_tmpvar (out, tmp)\n ) (* end of [val] *)\n val () = emit_SEMICOLON (out)\n }\n| ATSreturn_void (tmp) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"return\/*_void*\/\")\n val () = emit_SEMICOLON (out)\n }\n\/\/\n| ATSINSlab (lab) =>\n {\n val () = emit_nspc (out, ind)\n val () = (\n emit_label (out, lab); emit_COLON (out)\n ) (* end of [val] *)\n } (* end of [ATSINSlab] *)\n\/\/\n| ATSINSgoto (lab) =>\n {\n val () = emit_nspc (out, ind)\n val () = (\n emit_text (out, \"goto \"); emit_label (out, lab)\n ) (* end of [val] *)\n val () = emit_SEMICOLON (out)\n } (* end of [ATSINSgoto] *)\n\/\/\n| ATSINSflab (flab) =>\n {\n val () = emit_nspc (out, ind)\n val () = (\n emit_label (out, flab); emit_COLON (out)\n ) (* end of [val] *)\n } (* end of [ATSINSflab] *)\n\/\/\n| ATSINSfgoto (flab) =>\n {\n val () = emit_nspc (out, ind)\n val () = (\n emit_text (out, \"goto \"); emit_label (out, flab)\n ) (* end of [val] *)\n val () = emit_SEMICOLON (out)\n } (* end of [ATSINSfgoto] *)\n\/\/\n| ATSINSmove (tmp, d0e) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_tmpvar (out, tmp)\n val () = emit_text (out, \" = \")\n val () = emit_d0exp (out, d0e)\n val () = emit_SEMICOLON (out)\n } (* end of [ATSINSmove] *)\n\/\/\n| ATSINSmove_void (tmp, d0e) =>\n {\n val () = emit_nspc (out, ind)\n val () = (\n case+ d0e.d0exp_node of\n | ATSempty _ =>\n emit_text (out, \"\/\/ ATSINSmove_void\")\n \/\/ end of [ATSempty]\n | _ (*non-ATSempty*) => emit_d0exp (out, d0e)\n ) : void \/\/ end of [val]\n val () = emit_SEMICOLON (out)\n } (* end of [ATSINSmove_void] *)\n\/\/\n| ATSINSmove_nil (tmp) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_tmpvar (out, tmp)\n val () = emit_text (out, \" = \")\n val () = emit_text (out, \"null\")\n val () = emit_SEMICOLON (out)\n }\n| ATSINSmove_con0 (tmp, tag) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_tmpvar (out, tmp)\n val () = emit_text (out, \" = \")\n val () = emit_PMVint (out, tag)\n val () = emit_SEMICOLON (out)\n }\n\/\/\n| ATSINSmove_con1 _ =>\n emit2_ATSINSmove_con1 (out, ind, ins0)\n| ATSINSmove_boxrec _ =>\n emit2_ATSINSmove_boxrec (out, ind, ins0)\n\/\/\n| ATStailcalseq (inss) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"\/\/ ATStailcalseq_beg\")\n val () = emit_ENDL (out)\n val () = emit2_instrlst (out, ind, inss)\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"\/\/ ATStailcalseq_end\")\n } (* end of [ATStailcalseq] *)\n\/\/\n| ATSINSmove_tlcal (tmp, d0e) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_tmpvar (out, tmp)\n val () = emit_text (out, \" = \")\n val () = emit_d0exp (out, d0e) \n val () = emit_SEMICOLON (out)\n } (* end of [ATSINSmove_tlcal] *)\n\/\/\n| ATSINSargmove_tlcal (tmp1, tmp2) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_tmpvar (out, tmp1)\n val () = emit_text (out, \" = \")\n val () = emit_tmpvar (out, tmp2)\n val () = emit_SEMICOLON (out)\n } (* end of [ATSINSargmove_tlcal] *)\n\/\/\n| ATSdynload (dummy) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"\/\/ ATSdynload()\")\n }\n\/\/\n| ATSdynload0 (flag) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"var\\n\")\n val () =\n (\n emit_tmpvar (out, flag); emit_text (out, \" = 0 ;\")\n )\n }\n| ATSdynload1 (flag) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"\/\/ ATSdynload1(...)\")\n }\n| ATSdynloadset (flag) =>\n {\n val () = emit_nspc (out, ind)\n val () =\n (\n emit_tmpvar (out, flag); emit_text (out, \" = 1 ; \/\/ flag is set\")\n )\n }\n\/\/\n| _ (*rest-of-instr*) =>\n {\n val () = emit_nspc (out, ind)\n val ((*error*)) = fprint! (out, \"UNRECOGNIZED-INSTRUCTION: \", ins0)\n }\n\/\/\nend \/\/ end of [emit2_instr]\n\n(* ****** ****** *)\n\nimplement\nemit2_instr_ln\n (out, ind, ins) =\n(\n emit2_instr (out, ind, ins); emit_ENDL (out)\n) (* end of [emit2_instr_ln] *)\n\n(* ****** ****** *)\n\nimplement\nemit2_instrlst\n(\n out, ind, inss\n) = (\n\/\/\ncase+ inss of\n| list_nil () => ()\n| list_cons (ins, inss) =>\n {\n val () = emit2_instr_ln (out, ind, ins)\n val () = emit2_instrlst (out, ind, inss)\n }\n\/\/\n) (* end of [emit2_instrlst] *)\n\n(* ****** ****** *)\n\nimplement\nemit2_ATSfunbodyseq\n (out, ind, ins) = let\n\/\/\nval-ATSfunbodyseq (inss) = ins.instr_node\n\/\/\nin\n emit2_instrlst (out, ind, inss)\nend \/\/ end of [emit2_ATS2funbodyseq]\n\n(* ****** ****** *)\n\nimplement\nemit2_ATSINSmove_con1\n (out, ind, ins0) = let\n\/\/\nfun\ngetarglst\n(\n inss: instrlst\n) : d0explst =\n(\ncase+ inss of\n| list_nil () => list_nil ()\n| list_cons (ins, inss) => let\n val-ATSINSstore_con1_ofs (_, _, _, d0e) = ins.instr_node\n val d0es = getarglst (inss)\n in\n list_cons (d0e, d0es)\n end \/\/ end of [list_cons]\n)\n\/\/\nval-ATSINSmove_con1 (inss) = ins0.instr_node\n\/\/\nval-list_cons (ins, inss) = inss\nval-ATSINSmove_con1_new (tmp, _) = ins.instr_node \n\/\/\nvar opt: tokenopt = None()\n\/\/\nval inss =\n(\ncase+ inss of\n| list_nil () => inss\n| list_cons (ins, inss2) =>\n (\n case+ ins.instr_node of\n | ATSINSstore_con1_tag\n (tmp, tag) => let\n val () = opt := Some(tag) in inss2\n end \/\/ end of [ATSINSstore_con1_tag]\n | _ (*non-ATSINSstore_con1_tag*) => inss\n )\n) : instrlst\n\/\/\nval d0es = getarglst (inss)\nval () = emit_nspc (out, ind)\nval () = emit_tmpvar (out, tmp)\nval () = emit_text (out, \" = \")\nval () = emit_LBRACKET (out)\nval () =\n(\ncase+ opt of\n| None () => ()\n| Some (tag) => emit_PMVint (out, tag)\n) : void \/\/ end of [val]\nval () =\n(\ncase+ opt of\n| None _ => emit_d0explst (out, d0es)\n| Some _ => emit_d0explst_1 (out, d0es)\n) : void \/\/ end of [val]\n\/\/\nval () = emit_RBRACKET (out)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit2_ATSINSmove_con1]\n\n(* ****** ****** *)\n\nimplement\nemit2_ATSINSmove_boxrec\n (out, ind, ins0) = let\n\/\/\nfun\ngetarglst\n(\n inss: instrlst\n) : d0explst =\n(\ncase+ inss of\n| list_nil () => list_nil ()\n| list_cons (ins, inss) => let\n val-ATSINSstore_boxrec_ofs (_, _, _, d0e) = ins.instr_node\n val d0es = getarglst (inss)\n in\n list_cons (d0e, d0es)\n end \/\/ end of [list_cons]\n)\n\/\/\nval-ATSINSmove_boxrec (inss) = ins0.instr_node\n\/\/\nval-list_cons (ins, inss) = inss\nval-ATSINSmove_boxrec_new (tmp, _) = ins.instr_node \n\/\/\nval d0es = getarglst (inss)\n\/\/\nval () = emit_nspc (out, ind)\nval () = emit_tmpvar (out, tmp)\nval () = emit_text (out, \" = \")\nval () = emit_LBRACKET (out)\nval () = emit_d0explst (out, d0es)\nval () = emit_RBRACKET (out)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit2_ATSINSmove_boxrec]\n\n(* ****** ****** *)\n\n#define\nATSEXTCODE_BEG \"\/* ATSextcode_beg() *\/\"\n#define\nATSEXTCODE_END \"\/* ATSextcode_end() *\/\"\n\n(* ****** ****** *)\n\nimplement\nemit_d0ecl\n (out, d0c) = let\nin\n\/\/\ncase+\nd0c.d0ecl_node of\n\/\/\n| D0Cinclude _ => ()\n\/\/\n| D0Cifdef _ => ()\n| D0Cifndef _ => ()\n\/\/\n| D0Ctypedef (id, def) =>\n typedef_insert (id.i0de_sym, def)\n \/\/ end of [D0Ctypedef]\n\/\/\n| D0Cdyncst_mac _ => ()\n| D0Cdyncst_extfun _ => ()\n\/\/\n| D0Cextcode (toks) =>\n {\n val () = emit_ENDL (out)\n val () =\n emit_text (out, ATSEXTCODE_BEG)\n val () = emit_extcode (out, toks) \/\/ HX: verbatim output\n val () =\n emit_text (out, ATSEXTCODE_END)\n val ((*void*)) = emit_newline (out)\n } (* end of [D0Cextcode] *)\n\/\/\n| D0Cstatmp\n (tmp, opt) =>\n {\n val () = emit_ENDL (out)\n val () = (\n case+ opt of\n | Some _ => () | None () => emit_text(out, \"\/*\\n\")\n ) (* end of [val] *)\n val () = (\n emit_text (out, \"\/\/ \"); emit_tmpvar (out, tmp); emit_ENDL (out)\n ) (* end of [val] *)\n val () = (\n case+ opt of\n | Some _ => () | None () => emit_text(out, \"*\/\\n\")\n ) (* end of [val] *)\n } (* end of [D0Cstatmp] *)\n\/\/\n| D0Cfundecl\n (fk, f0d) => emit_f0decl (out, f0d)\n\/\/\n| D0Cclosurerize\n (\n fl, env, arg, res\n ) => emit_closurerize (out, fl, env, arg, res)\n\/\/\nend \/\/ end of [emit_d0ecl]\n\n(* ****** ****** *)\n\/\/\nextern\nfun emit_f0arg : emit_type (f0arg)\nextern\nfun emit_f0marg : emit_type (f0marg)\nextern\nfun emit_f0head : emit_type (f0head)\n\/\/\nextern\nfun emit_f0body : emit_type (f0body)\nextern\nfun emit_f0body_0 : emit_type (f0body)\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_f0arg\n (out, f0a) = let\nin\n\/\/\ncase+\nf0a.f0arg_node of\n\/\/\n| F0ARGnone _ => emit_text (out, \"__NONE__\")\n| F0ARGsome (arg, s0e) => emit_tmpvar (out, arg)\n\/\/\nend \/\/ end of [emit_f0arg]\n\n(* ****** ****** *)\n\nimplement\nemit_f0marg\n (out, f0ma) = let\n\/\/\nfun\nloop\n(\n out: FILEref, f0as: f0arglst, i: int\n) : void =\n(\ncase+ f0as of\n| list_nil () => ()\n| list_cons (f0a, f0as) => let\n val () =\n if i > 0 then emit_text (out, \", \")\n \/\/ end of [val]\n in\n emit_f0arg (out, f0a); loop (out, f0as, i+1)\n end \/\/ end of [list_cons]\n)\n\/\/\nin\n loop (out, f0ma.f0marg_node, 0)\nend \/\/ end of [emit_f0marg]\n\n(* ****** ****** *)\n\nimplement\nemit_f0head\n (out, fhd) = let\n\/\/\nval f0as =\n f0head_get_f0arglst (fhd)\n\/\/\nval () = the_f0arglst_set (f0as)\n\/\/\nin\n\/\/\ncase+\nfhd.f0head_node of\n| F0HEAD\n (fid, f0ma, res) =>\n {\n\/\/\n val () = emit_i0de (out, fid)\n\/\/\n val () = emit_LPAREN (out)\n val () = emit_f0marg (out, f0ma)\n val () = emit_RPAREN (out)\n\/\/\n } (* end of [F0HEAD] *)\n\/\/\nend \/\/ end of [emit_f0head]\n\n(* ****** ****** *)\n\nimplement\nemit_f0body\n (out, fbody) = let\n\/\/\nval tmpdecs =\n f0body_get_tmpdeclst (fbody)\nval inss_body =\n f0body_get_bdinstrlst (fbody)\n\/\/\nval () = the_tmpdeclst_set (tmpdecs)\n\/\/\nval () = emit_text (out, \"{\\n\")\n\/\/\nval () = emit_text (out, \"\/*\\n\")\n\/\/\nval () =\n emit_tmpdeclst_initize (out, tmpdecs)\n\/\/\nval () = emit_text (out, \"*\/\\n\")\n\/\/\nval ((*main*)) = emit_f0body_0 (out, fbody)\n\/\/\nval ((*closing*)) =\n emit_text (out, \"} \/\/ end-of-function\\n\")\n\/\/\nin\n \/\/ nothing\nend (* end of [emit_f0body] *)\n\n(* ****** ****** *)\n\nimplement\nemit_f0body_0\n (out, fbody) = let\n\/\/\nfun\nauxlst\n(\n out: FILEref, inss: instrlst, i: int\n) : void =\n(\ncase+ inss of\n\/\/\n| list_nil () => ()\n\/\/\n| list_cons\n (ins0, inss1) => let\n val-list_cons(ins1, inss2) = inss1\n val () = if i > 0 then emit_text (out, \"\/\/\\n\")\n val () = emit2_ATSfunbodyseq (out, 2(*ind*), ins0)\n val ((*return*)) = emit2_instr_ln (out, 2(*ind*), ins1)\n in\n auxlst (out, inss2, i+1)\n end \/\/ end of [list_cons]\n\/\/\n) (* end of [auxlst] *)\n\/\/\nin\n\/\/\ncase+\nfbody.f0body_node of\n\/\/\n| F0BODY (tds, inss) =>\n {\n val () = auxlst (out, inss, 0(*i*))\n }\n\/\/\nend \/\/ end of [emit_f0body_0]\n\n(* ****** ****** *)\n\nimplement\nemit_f0decl\n (out, fdec) = let\nin\n\/\/\ncase+\nfdec.f0decl_node of\n| F0DECLnone (fhd) => () \n| F0DECLsome (fhd, fbody) =>\n {\n val () = emit_ENDL (out)\n val () = emit_text (out, \"function\")\n val () = emit_ENDL (out)\n val () = emit_f0head (out, fhd)\n val () = emit_ENDL (out)\n val () = emit_f0body (out, fbody)\n val () = emit_newline (out)\n } (* end of [F0DECLsome] *)\n\/\/\nend \/\/ end of [emit_f0decl]\n\n(* ****** ****** *)\n\nimplement\nemit_toplevel\n (out, d0cs) = let\n\/\/\nfun\nloop\n(\n out: FILEref, d0cs: d0eclist\n) : void =\n(\n\/\/\ncase+ d0cs of\n| list_nil () => ()\n| list_cons\n (d0c, d0cs) => let\n val () =\n emit_d0ecl (out, d0c)\n \/\/ end of [val]\n in\n loop (out, d0cs)\n end \/\/ end of [list_cons]\n\/\/\n)\n\/\/\nin\n loop (out, d0cs)\nend \/\/ end of [emit_toplevel]\n\n(* ****** ****** *)\n\n(* end of [atsparemit_emit2_php.dats] *)\n","old_contents":"(* ****** ****** *)\n\/\/\n\/\/ ATS-parse-emit-php\n\/\/\n(* ****** ****** *)\n\/\/\n\/\/ HX-2014-08-20: start\n\/\/\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_staload.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\nUN = \"prelude\/SATS\/unsafe.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/atsparemit.sats\"\nstaload \".\/atsparemit_syntax.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/atsparemit_emit.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/atsparemit_typedef.dats\"\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit_tmpdeclst_initize\n (out: FILEref, tds: tmpdeclst): void\n\/\/\nimplement\nemit_tmpdeclst_initize\n (out, tds) = let\n\/\/\nfun auxlst\n(\n out: FILEref, tds: tmpdeclst\n) : void = let\nin\n\/\/\ncase+ tds of\n| list_nil () => ()\n| list_cons (td, tds) =>\n (\n case+ td.tmpdec_node of\n | TMPDECnone\n (tmp) => auxlst (out, tds)\n | TMPDECsome\n (tmp, _) => let\n val () =\n emit_nspc (out, 2(*ind*))\n val () = emit_ENDL (out)\n val () = (\n emit_text (out, \"\/\/ \"); emit_tmpvar (out, tmp);\n ) (* end of [val] *)\n in\n auxlst (out, tds)\n end \/\/ end of [TMPDECsome]\n ) (* end of [list_cons] *)\n\/\/\nend \/\/ end of [auxlist]\n\/\/\nin\n auxlst (out, tds)\nend \/\/ end of [emit_tmpdeclst_initize]\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_f0arglst_get (): f0arglst\nextern\nfun\nthe_f0arglst_set (f0as: f0arglst): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_tmpdeclst_get (): tmpdeclst\nextern\nfun\nthe_tmpdeclst_set (tds: tmpdeclst): void\n\/\/\n(* ****** ****** *)\n\/\/\nlocal\n\/\/\nval the_f0arglst = ref (list_nil)\nval the_tmpdeclst = ref (list_nil)\n\/\/\nin (* in-of-local *)\n\nimplement\nthe_f0arglst_get () = !the_f0arglst\nimplement\nthe_f0arglst_set (xs) = !the_f0arglst := xs\n\nimplement\nthe_tmpdeclst_get () = !the_tmpdeclst\nimplement\nthe_tmpdeclst_set (xs) = !the_tmpdeclst := xs\n\nend \/\/ end of [local]\n\n(* ****** ****** *)\n\/\/\nextern\nfun emit2_instr\n (out: FILEref, ind: int, ins: instr) : void\n\/\/\nextern\nfun emit2_instrlst\n (out: FILEref, ind: int, inss: instrlst) : void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun emit2_ATSfunbodyseq\n (out: FILEref, ind: int, ins: instr) : void\n\/\/\nextern\nfun emit2_ATSINSmove_con1\n (out: FILEref, ind: int, ins: instr) : void\nextern\nfun emit2_ATSINSmove_boxrec\n (out: FILEref, ind: int, ins: instr) : void\n\/\/\n(* ****** ****** *)\n\/\/\n\/\/ HX-2014-08:\n\/\/ this one should not be used for\n\/\/ emitting multiple-line instructions\n\/\/\nimplement\nemit_instr\n (out, ins) = emit2_instr (out, 0(*ind*), ins)\n\/\/\n(* ****** ****** *)\n\nimplement\nemit2_instr\n (out, ind, ins0) = let\nin\n\/\/\ncase+\nins0.instr_node of\n\/\/\n| ATSif\n (\n d0e, inss, inssopt\n ) => let\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"if \")\n val () = emit_LPAREN (out)\n val () = emit_d0exp (out, d0e)\n val () = emit_RPAREN (out)\n val () = emit_text (out, \" {\")\n val () = emit2_instrlst (out, ind+2, inss)\n in\n case+ inssopt of\n | None _ =>\n {\n val () = emit_ENDL (out)\n val () = emit_nspc (out, ind)\n val ((*closing*)) = emit_text (out, \"} \/\/ endif\")\n } (* end of [None] *)\n | Some (inss) =>\n {\n val () = emit_ENDL (out)\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"} else {\")\n val () = emit2_instrlst (out, ind+2, inss)\n val () = emit_ENDL (out)\n val () = emit_nspc (out, ind)\n val ((*closing*)) = emit_text (out, \"} \/\/ endif\")\n } (* end of [Some] *)\n end \/\/ end of [ATSif]\n\/\/\n| ATSifthen (d0e, inss) =>\n {\n\/\/\n val-list_cons (ins, _) = inss\n\/\/\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"if(\")\n val () = emit_d0exp (out, d0e)\n val () = emit_text (out, \") \")\n val () = emit_instr (out, ins)\n }\n\/\/\n| ATSifnthen (d0e, inss) =>\n {\n\/\/\n val-list_cons (ins, _) = inss\n\/\/\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"if(!\")\n val () = emit_d0exp (out, d0e)\n val ((*closing*)) = emit_text (out, \") \")\n val () = emit_instr (out, ins)\n }\n\/\/\n| ATSbranchseq (inss) =>\n {\n\/\/\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"\/\/ ATSbranchseq_beg\")\n\/\/\n val () = emit2_instrlst (out, ind, inss)\n\/\/\n val () = emit_ENDL (out)\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"break;\")\n val () = emit_ENDL (out)\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"\/\/ ATSbranchseq_end\")\n\/\/\n } (* end of [ATSbranchseq] *)\n\/\/\n| ATScaseofseq (inss) =>\n {\n\/\/\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"\/\/ ATScaseofseq_beg\")\n val () = emit_ENDL (out)\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"do {\")\n\/\/\n val () = emit2_instrlst (out, ind+2, inss)\n\/\/\n val () = emit_ENDL (out)\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"} while(0) ;\")\n val () = emit_ENDL (out)\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"\/\/ ATScaseofseq_end\")\n\/\/\n } (* end of [ATScaseofseq] *)\n\/\/\n| ATSreturn (tmp) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"return \")\n val () = emit_tmpvar (out, tmp)\n val () = emit_SEMICOLON (out)\n }\n| ATSreturn_void (tmp) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"return\/*_void*\/\")\n val () = emit_SEMICOLON (out)\n }\n\/\/\n| ATSINSlab (lab) =>\n {\n val () = emit_nspc (out, ind)\n val () = (\n emit_label (out, lab); emit_COLON (out)\n ) (* end of [val] *)\n } (* end of [ATSINSlab] *)\n\/\/\n| ATSINSgoto (lab) =>\n {\n val () = emit_nspc (out, ind)\n val () = (\n emit_text (out, \"goto \"); emit_label (out, lab)\n ) (* end of [val] *)\n val () = emit_SEMICOLON (out)\n } (* end of [ATSINSgoto] *)\n\/\/\n| ATSINSflab (flab) =>\n {\n val () = emit_nspc (out, ind)\n val () = (\n emit_label (out, flab); emit_COLON (out)\n ) (* end of [val] *)\n } (* end of [ATSINSflab] *)\n\/\/\n| ATSINSfgoto (flab) =>\n {\n val () = emit_nspc (out, ind)\n val () = (\n emit_text (out, \"goto \"); emit_label (out, flab)\n ) (* end of [val] *)\n val () = emit_SEMICOLON (out)\n } (* end of [ATSINSfgoto] *)\n\/\/\n| ATSINSmove (tmp, d0e) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_tmpvar (out, tmp)\n val () = emit_text (out, \" = \")\n val () = emit_d0exp (out, d0e)\n val () = emit_SEMICOLON (out)\n } (* end of [ATSINSmove] *)\n\/\/\n| ATSINSmove_void (tmp, d0e) =>\n {\n val () = emit_nspc (out, ind)\n val () = (\n case+ d0e.d0exp_node of\n | ATSempty _ =>\n emit_text (out, \"\/\/ ATSINSmove_void\")\n \/\/ end of [ATSempty]\n | _ (*non-ATSempty*) => emit_d0exp (out, d0e)\n ) : void \/\/ end of [val]\n val () = emit_SEMICOLON (out)\n } (* end of [ATSINSmove_void] *)\n\/\/\n| ATSINSmove_nil (tmp) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_tmpvar (out, tmp)\n val () = emit_text (out, \" = \")\n val () = emit_text (out, \"null\")\n val () = emit_SEMICOLON (out)\n }\n| ATSINSmove_con0 (tmp, tag) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_tmpvar (out, tmp)\n val () = emit_text (out, \" = \")\n val () = emit_PMVint (out, tag)\n val () = emit_SEMICOLON (out)\n }\n\/\/\n| ATSINSmove_con1 _ =>\n emit2_ATSINSmove_con1 (out, ind, ins0)\n| ATSINSmove_boxrec _ =>\n emit2_ATSINSmove_boxrec (out, ind, ins0)\n\/\/\n| ATStailcalseq (inss) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"\/\/ ATStailcalseq_beg\")\n val () = emit2_instrlst (out, ind, inss)\n val () = emit_ENDL (out)\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"\/\/ ATStailcalseq_end\")\n } (* end of [ATStailcalseq] *)\n\/\/\n| ATSINSmove_tlcal (tmp, d0e) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_tmpvar (out, tmp)\n val () = emit_text (out, \" = \")\n val () = emit_d0exp (out, d0e) \n val () = emit_SEMICOLON (out)\n } (* end of [ATSINSmove_tlcal] *)\n\/\/\n| ATSINSargmove_tlcal (tmp1, tmp2) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_tmpvar (out, tmp1)\n val () = emit_text (out, \" = \")\n val () = emit_tmpvar (out, tmp2)\n val () = emit_SEMICOLON (out)\n } (* end of [ATSINSargmove_tlcal] *)\n\/\/\n| ATSdynload (dummy) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"\/\/ ATSdynload()\")\n }\n\/\/\n| ATSdynload0 (flag) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"var\\n\")\n val () =\n (\n emit_tmpvar (out, flag); emit_text (out, \" = 0 ;\")\n )\n }\n| ATSdynload1 (flag) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"\/\/ ATSdynload1(...)\")\n }\n| ATSdynloadset (flag) =>\n {\n val () = emit_nspc (out, ind)\n val () =\n (\n emit_tmpvar (out, flag); emit_text (out, \" = 1 ; \/\/ flag is set\")\n )\n }\n\/\/\n| _ (*rest-of-instr*) =>\n {\n val () = emit_nspc (out, ind)\n val ((*error*)) = fprint! (out, \"UNRECOGNIZED-INSTRUCTION: \", ins0)\n }\n\/\/\nend \/\/ end of [emit2_instr]\n\n(* ****** ****** *)\n\nimplement\nemit2_instrlst\n(\n out, ind, inss\n) = (\n\/\/\ncase+ inss of\n| list_nil () => ()\n| list_cons (ins, inss) =>\n {\n val () = emit_ENDL (out)\n val () = emit2_instr (out, ind, ins)\n val () = emit2_instrlst (out, ind, inss)\n }\n\/\/\n) (* end of [emit2_instrlst] *)\n\n(* ****** ****** *)\n\nimplement\nemit2_ATSfunbodyseq\n (out, ind, ins) = let\n\/\/\nval-ATSfunbodyseq (inss) = ins.instr_node\n\/\/\nin\n emit2_instrlst (out, ind, inss)\nend \/\/ end of [emit2_ATS2funbodyseq]\n\n(* ****** ****** *)\n\nimplement\nemit2_ATSINSmove_con1\n (out, ind, ins0) = let\n\/\/\nfun\ngetarglst\n(\n inss: instrlst\n) : d0explst =\n(\ncase+ inss of\n| list_nil () => list_nil ()\n| list_cons (ins, inss) => let\n val-ATSINSstore_con1_ofs (_, _, _, d0e) = ins.instr_node\n val d0es = getarglst (inss)\n in\n list_cons (d0e, d0es)\n end \/\/ end of [list_cons]\n)\n\/\/\nval-ATSINSmove_con1 (inss) = ins0.instr_node\n\/\/\nval-list_cons (ins, inss) = inss\nval-ATSINSmove_con1_new (tmp, _) = ins.instr_node \n\/\/\nvar opt: tokenopt = None()\n\/\/\nval inss =\n(\ncase+ inss of\n| list_nil () => inss\n| list_cons (ins, inss2) =>\n (\n case+ ins.instr_node of\n | ATSINSstore_con1_tag\n (tmp, tag) => let\n val () = opt := Some(tag) in inss2\n end \/\/ end of [ATSINSstore_con1_tag]\n | _ (*non-ATSINSstore_con1_tag*) => inss\n )\n) : instrlst\n\/\/\nval d0es = getarglst (inss)\nval () = emit_nspc (out, ind)\nval () = emit_tmpvar (out, tmp)\nval () = emit_text (out, \" = \")\nval () = emit_LBRACKET (out)\nval () =\n(\ncase+ opt of\n| None () => ()\n| Some (tag) => emit_PMVint (out, tag)\n) : void \/\/ end of [val]\nval () =\n(\ncase+ opt of\n| None _ => emit_d0explst (out, d0es)\n| Some _ => emit_d0explst_1 (out, d0es)\n) : void \/\/ end of [val]\n\/\/\nval () = emit_RBRACKET (out)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit2_ATSINSmove_con1]\n\n(* ****** ****** *)\n\nimplement\nemit2_ATSINSmove_boxrec\n (out, ind, ins0) = let\n\/\/\nfun\ngetarglst\n(\n inss: instrlst\n) : d0explst =\n(\ncase+ inss of\n| list_nil () => list_nil ()\n| list_cons (ins, inss) => let\n val-ATSINSstore_boxrec_ofs (_, _, _, d0e) = ins.instr_node\n val d0es = getarglst (inss)\n in\n list_cons (d0e, d0es)\n end \/\/ end of [list_cons]\n)\n\/\/\nval-ATSINSmove_boxrec (inss) = ins0.instr_node\n\/\/\nval-list_cons (ins, inss) = inss\nval-ATSINSmove_boxrec_new (tmp, _) = ins.instr_node \n\/\/\nval d0es = getarglst (inss)\n\/\/\nval () = emit_nspc (out, ind)\nval () = emit_tmpvar (out, tmp)\nval () = emit_text (out, \" = \")\nval () = emit_LBRACKET (out)\nval () = emit_d0explst (out, d0es)\nval () = emit_RBRACKET (out)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit2_ATSINSmove_boxrec]\n\n(* ****** ****** *)\n\n#define\nATSEXTCODE_BEG \"\/* ATSextcode_beg() *\/\"\n#define\nATSEXTCODE_END \"\/* ATSextcode_end() *\/\"\n\n(* ****** ****** *)\n\nimplement\nemit_d0ecl\n (out, d0c) = let\nin\n\/\/\ncase+\nd0c.d0ecl_node of\n\/\/\n| D0Cinclude _ => ()\n\/\/\n| D0Cifdef _ => ()\n| D0Cifndef _ => ()\n\/\/\n| D0Ctypedef (id, def) =>\n typedef_insert (id.i0de_sym, def)\n \/\/ end of [D0Ctypedef]\n\/\/\n| D0Cdyncst_mac _ => ()\n| D0Cdyncst_extfun _ => ()\n\/\/\n| D0Cextcode (toks) =>\n {\n val () = emit_ENDL (out)\n val () =\n emit_text (out, ATSEXTCODE_BEG)\n val () = emit_extcode (out, toks) \/\/ HX: verbatim output\n val () =\n emit_text (out, ATSEXTCODE_END)\n val ((*void*)) = emit_newline (out)\n } (* end of [D0Cextcode] *)\n\/\/\n| D0Cstatmp\n (tmp, opt) =>\n {\n val () = emit_ENDL (out)\n val () = (\n case+ opt of\n | Some _ => () | None () => emit_text(out, \"\/*\\n\")\n ) (* end of [val] *)\n val () = (\n emit_text (out, \"\/\/ \"); emit_tmpvar (out, tmp); emit_ENDL (out)\n ) (* end of [val] *)\n val () = (\n case+ opt of\n | Some _ => () | None () => emit_text(out, \"*\/\\n\")\n ) (* end of [val] *)\n } (* end of [D0Cstatmp] *)\n\/\/\n| D0Cfundecl\n (fk, f0d) => emit_f0decl (out, f0d)\n\/\/\n| D0Cclosurerize\n (\n fl, env, arg, res\n ) => emit_closurerize (out, fl, env, arg, res)\n\/\/\nend \/\/ end of [emit_d0ecl]\n\n(* ****** ****** *)\n\/\/\nextern\nfun emit_f0arg : emit_type (f0arg)\nextern\nfun emit_f0marg : emit_type (f0marg)\nextern\nfun emit_f0head : emit_type (f0head)\n\/\/\nextern\nfun emit_f0body : emit_type (f0body)\nextern\nfun emit_f0body_0 : emit_type (f0body)\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_f0arg\n (out, f0a) = let\nin\n\/\/\ncase+\nf0a.f0arg_node of\n\/\/\n| F0ARGnone _ => emit_text (out, \"__NONE__\")\n| F0ARGsome (arg, s0e) => emit_tmpvar (out, arg)\n\/\/\nend \/\/ end of [emit_f0arg]\n\n(* ****** ****** *)\n\nimplement\nemit_f0marg\n (out, f0ma) = let\n\/\/\nfun\nloop\n(\n out: FILEref, f0as: f0arglst, i: int\n) : void =\n(\ncase+ f0as of\n| list_nil () => ()\n| list_cons (f0a, f0as) => let\n val () =\n if i > 0 then emit_text (out, \", \")\n \/\/ end of [val]\n in\n emit_f0arg (out, f0a); loop (out, f0as, i+1)\n end \/\/ end of [list_cons]\n)\n\/\/\nin\n loop (out, f0ma.f0marg_node, 0)\nend \/\/ end of [emit_f0marg]\n\n(* ****** ****** *)\n\nimplement\nemit_f0head\n (out, fhd) = let\n\/\/\nval f0as =\n f0head_get_f0arglst (fhd)\n\/\/\nval () = the_f0arglst_set (f0as)\n\/\/\nin\n\/\/\ncase+\nfhd.f0head_node of\n| F0HEAD\n (fid, f0ma, res) =>\n {\n\/\/\n val () = emit_i0de (out, fid)\n\/\/\n val () = emit_LPAREN (out)\n val () = emit_f0marg (out, f0ma)\n val () = emit_RPAREN (out)\n\/\/\n } (* end of [F0HEAD] *)\n\/\/\nend \/\/ end of [emit_f0head]\n\n(* ****** ****** *)\n\nimplement\nemit_f0body\n (out, fbody) = let\n\/\/\nval tmpdecs =\n f0body_get_tmpdeclst (fbody)\nval inss_body =\n f0body_get_bdinstrlst (fbody)\n\/\/\nval () = the_tmpdeclst_set (tmpdecs)\n\/\/\nval () = emit_text (out, \"{\")\n\/\/\nval () = emit_text (out, \"\\n\/*\")\n\/\/\nval () =\n emit_tmpdeclst_initize (out, tmpdecs)\n\/\/\nval () = emit_text (out, \"\\n*\/\")\n\/\/\nval ((*main*)) = emit_f0body_0 (out, fbody)\n\/\/\nval () = emit_text (out, \"\\n} \/\/ end-of-function\\n\")\n\/\/\nin\n \/\/ nothing\nend (* end of [emit_f0body] *)\n\n(* ****** ****** *)\n\nimplement\nemit_f0body_0\n (out, fbody) = let\n\/\/\nfun\nauxlst\n(\n out: FILEref, inss: instrlst, i: int\n) : void =\n(\ncase+ inss of\n| list_nil () => ()\n| list_cons\n (ins0, inss1) => let\n val-list_cons (ins1, inss2) = inss1\n val () = if i > 0 then emit_ENDL (out)\n val () = emit2_ATSfunbodyseq (out, 2(*ind*), ins0)\n val ((*newline*)) = emit_ENDL (out)\n val ((*ATSreturn*)) = emit2_instr (out, 2(*ind*), ins1)\n in\n auxlst (out, inss2, i+1)\n end \/\/ end of [list_cons]\n\/\/\n) (* end of [auxlst] *)\n\/\/\nin\n\/\/\ncase+\nfbody.f0body_node of\n\/\/\n| F0BODY (tds, inss) =>\n {\n val () = auxlst (out, inss, 0(*i*))\n }\n\/\/\nend \/\/ end of [emit_f0body_0]\n\n(* ****** ****** *)\n\nimplement\nemit_f0decl\n (out, fdec) = let\nin\n\/\/\ncase+\nfdec.f0decl_node of\n| F0DECLnone (fhd) => () \n| F0DECLsome (fhd, fbody) =>\n {\n val () = emit_ENDL (out)\n val () =\n emit_text (out, \"function\\n\")\n val () = emit_f0head (out, fhd)\n val () = emit_newline (out)\n val () = emit_f0body (out, fbody)\n } (* end of [F0DECLsome] *)\n\/\/\nend \/\/ end of [emit_f0decl]\n\n(* ****** ****** *)\n\nimplement\nemit_toplevel\n (out, d0cs) = let\n\/\/\nfun\nloop\n(\n out: FILEref, d0cs: d0eclist\n) : void =\n(\n\/\/\ncase+ d0cs of\n| list_nil () => ()\n| list_cons\n (d0c, d0cs) => let\n val () =\n emit_d0ecl (out, d0c)\n \/\/ end of [val]\n in\n loop (out, d0cs)\n end \/\/ end of [list_cons]\n\/\/\n)\n\/\/\nin\n loop (out, d0cs)\nend \/\/ end of [emit_toplevel]\n\n(* ****** ****** *)\n\n(* end of [atsparemit_emit2_php.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"ddd57ba6472ba727b070f9ba3393dbb4a9f697c6","subject":"Better code format","message":"Better code format\n","repos":"fpiot\/arduino-ats,Proclivis\/arduino-ats,fpiot\/arduino-ats,Proclivis\/arduino-ats","old_file":"demo\/lcd_ats\/DATS\/main.dats","new_file":"demo\/lcd_ats\/DATS\/main.dats","new_contents":"#include \"config.hats\"\n#include \"{$TOP}\/avr_prelude\/kernel_staload.hats\"\n\nstaload \"{$TOP}\/SATS\/arduino.sats\"\nstaload \"{$TOP}\/SATS\/lcd.sats\"\n\n#define MY_DELAY_MS 400.0\n#define LCD_WIDTH 16\n\nval g_str_atsrun = \"\"\nval g_str_message = \" ATS is a statically typed programming language that unifies implementation with formal specification. It is equipped with a highly expressive type system rooted in the framework Applied Type System, which gives the language its name. In particular, both dependent types and linear types are available in ATS. \"\n\nimplement main0 () = {\n fun loop {n:int}{i:nat | i < n}\n (lcd: !LCD, str: string (n), pos: size_t (i)): void = {\n val () = lcd_setCursor (lcd, 1, 0)\n val () = lcd_print (lcd, g_str_atsrun, i2sz 0, length g_str_atsrun)\n val () = lcd_setCursor (lcd, 0, 1)\n val () = lcd_print (lcd, str, pos, i2sz LCD_WIDTH)\n val () = _delay_ms (MY_DELAY_MS)\n val () = if pos + LCD_WIDTH < length str\n then loop (lcd, str, pos + 1)\n }\n fun forever {n:int}{i:nat | i < n}\n (lcd: !LCD, str: string (n), pos: size_t (i)): void = {\n val () = loop (lcd, str, pos)\n val () = forever (lcd, str, pos)\n }\n val lcd = lcd_open (8, 13, 9, 4, 5, 6, 7)\n val () = forever (lcd, g_str_message, i2sz 0)\n val () = lcd_close lcd\n}\n","old_contents":"#include \"config.hats\"\n#include \"{$TOP}\/avr_prelude\/kernel_staload.hats\"\n\nstaload \"{$TOP}\/SATS\/arduino.sats\"\nstaload \"{$TOP}\/SATS\/lcd.sats\"\n\n#define MY_DELAY_MS 400.0\n#define LCD_WIDTH 16\n\nval g_string = \" ATS is a statically typed programming language that unifies implementation with formal specification. It is equipped with a highly expressive type system rooted in the framework Applied Type System, which gives the language its name. In particular, both dependent types and linear types are available in ATS. \"\n\nimplement main0 () = {\n fun loop {n:int}{i:nat | i < n}\n (lcd: !LCD, str: string (n), pos: size_t (i)): void = {\n val () = lcd_setCursor (lcd, 1, 0)\n val () = lcd_print (lcd, \"\", i2sz 0, length \"\")\n val () = lcd_setCursor (lcd, 0, 1)\n val () = lcd_print (lcd, str, pos, i2sz LCD_WIDTH)\n val () = _delay_ms (MY_DELAY_MS)\n val () = if pos + LCD_WIDTH < length str then loop (lcd, str, pos + 1)\n }\n fun forever {n:int}{i:nat | i < n}\n (lcd: !LCD, str: string (n), pos: size_t (i)): void = {\n val () = loop (lcd, str, pos)\n val () = forever (lcd, str, pos)\n }\n val lcd = lcd_open (8, 13, 9, 4, 5, 6, 7)\n val () = forever (lcd, g_string, i2sz 0)\n val () = lcd_close lcd\n}\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"046b50e1dc47a98e8a41749174256e1a9a6444ab","subject":"Updating: minorly improving","message":"Updating: minorly improving\n","repos":"master-q\/ATS-Postiats-contrib,steinwaywhw\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,steinwaywhw\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,steinwaywhw\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,steinwaywhw\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,steinwaywhw\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,steinwaywhw\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib","old_file":"projects\/MEDIUM\/Algorianim\/quicksort\/GTK\/quicksort_anim2.dats","new_file":"projects\/MEDIUM\/Algorianim\/quicksort\/GTK\/quicksort_anim2.dats","new_contents":"\/\/\n\/\/ Animating Quicksort\n\/\/\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_define.hats\"\n#include\n\"share\/atspre_staload.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\nUN = \"prelude\/SATS\/unsafe.sats\"\n\/\/\nstaload \"libats\/ML\/SATS\/basis.sats\"\nstaload \"libats\/ML\/SATS\/list0.sats\"\nstaload \"libats\/ML\/SATS\/array0.sats\"\n\/\/\nstaload _ = \"libats\/ML\/DATS\/list0.dats\"\nstaload _ = \"libats\/ML\/DATS\/array0.dats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \"libats\/SATS\/hashfun.sats\"\nstaload \"libats\/SATS\/hashtbl_chain.sats\"\n\/\/\nstaload _ = \"libats\/DATS\/hashfun.dats\"\nstaload _ = \"libats\/DATS\/hashtbl_chain.dats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\n\"{$LIBATSHWXI}\/testing\/SATS\/randgen.sats\"\nstaload _ =\n\"{$LIBATSHWXI}\/testing\/DATS\/randgen.dats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\n\"{$LIBATSHWXI}\/teaching\/BUCS\/DATS\/BUCS.dats\"\n\/\/\n(* ****** ****** *)\n\n#define MYMAX 100\n\n(* ****** ****** *)\n\ntypedef int2 = (int, int)\n\n(* ****** ****** *)\n\nlocal\n\nval theExchlst =\n ref (list_nil)\n\nin (* in-of-local *)\n\nfun theExchlst_add\n (i1: int, i2: int): void =\n(\n !theExchlst := cons ((i1, i2), !theExchlst)\n)\nfun\ntheExchlst_get_all\n(\n\/\/ argumentlst\n) : List0(int2) = let\n val xys = !theExchlst\n val ((*void*)) = !theExchlst := nil ()\nin\n list_vt2t (list_reverse (xys))\nend \/\/ end of [theExchlst_get_all]\n\nend \/\/ end of [local]\n\n(* ****** ****** *)\n\nextern\nfun{\na:t@ype\n} array0_swap\n (A: array0 (a), i: size_t, j: size_t): void\n\/\/ end of [array0_swap]\n\n(* ****** ****** *)\n \nimplement\n{a}(*tmp*)\narray0_swap\n (A, i, j) =\n{\n val tmp = A[i]\n val () = A[i] := A[j]\n val () = A[j] := tmp\n val () = theExchlst_add (sz2i(i), sz2i(j))\n}\n \n(* ****** ****** *)\n\nextern\nfun{\na:t@ype\n} quicksort (A: array0 (a)): void\n\n(* ****** ****** *)\n\nextern\nfun{\na:t@ype\n} quicksort2\n(\n A: array0 (a), st: size_t, len: size_t\n) : void \/\/ end of [quicksort2]\n\n(* ****** ****** *)\n\nextern\nfun{a:t@ype}\nqsort_partition\n(\n A: array0 (a), st: size_t, len: size_t\n) : size_t \/\/ end of [qsort_partition]\n\n(* ****** ****** *)\n\/\/\nimplement\n{a}(*tmp*)\nquicksort (A) =\n quicksort2 (A, i2sz(0), A.size)\n\/\/\n(* ****** ****** *)\n\nimplement\n{a}(*tmp*)\nquicksort2 (A, st, len) =\n(\nif\nlen >= 2\nthen let\n val len_f = qsort_partition (A, st, len)\n val ((*void*)) = quicksort2 (A, st, len_f)\n val len_r = len - len_f\n val ((*void*)) = quicksort2 (A, succ(st+len_f), pred(len_r))\nin\n \/\/ nothing\nend \/\/ end of [then]\nelse () \/\/ end of [else]\n\/\/\n) (* end of [qsort] *)\n\n(* ****** ****** *)\n\nimplement\n{a}(*tmp*)\nqsort_partition\n (A, st, len) = let\n\/\/\nval len = g1ofg0 (len)\nval () = assertloc (len > 0)\nval last = pred (st + len)\nval pind = st + i2sz(randint(sz2i(len)))\nval () = array0_swap (A, pind, last)\nval pivot = A[last]\n\/\/\nfun loop\n(\n k1: size_t, k2: size_t\n) : size_t =\n if k2 < last then let\n val sgn = gcompare_val (pivot, A[k2])\n in\n if sgn <= 0\n then loop (k1, succ(k2))\n else (array0_swap(A, k1, k2); loop (succ(k1), succ(k2)))\n \/\/ end of [if]\n end else k1 \/\/ end of [loop]\n\/\/\nval k1 = loop (st, st)\nval () = array0_swap (A, k1, last)\n\/\/\nin\n (k1 - st)\nend \/\/ end of [qort_partition]\n\n(* ****** ****** *)\n\nlocal\n\nimplement\nrandgen_val () = randint (MYMAX)\n\nin (* in-of-local *)\n\nfun\ngenScript{n:int}\n(\n out: FILEref, asz: size_t(n)\n) :\n(\n array0 (int), List0(int2)\n) = let\n\/\/\nval A =\nrandgen_arrayref (asz)\n\/\/\nval A = array0 (A, asz)\nval A2 = array0_copy (A)\n\/\/\nval () = quicksort (A2)\n\/\/\n(*\nval () = fprint (out, A, asz)\nval () = fprint_newline (out)\nval () = fprint (out, A2, asz)\nval () = fprint_newline (out)\n*)\n\/\/\nin\n (A, theExchlst_get_all ())\nend (* end of [genScript] *)\n\nend \/\/ end of [local]\n\n(* ****** ****** *)\n\/\/\nstaload \"{$CAIRO}\/SATS\/cairo.sats\"\n\/\/\nstaload \"{$LIBATSHWXI}\/teaching\/mydraw\/SATS\/mydraw.sats\"\nstaload \"{$LIBATSHWXI}\/teaching\/mydraw\/SATS\/mydraw_cairo.sats\"\n\/\/\nstaload \"{$LIBATSHWXI}\/teaching\/mydraw\/DATS\/mydraw_bargraph.dats\"\n\/\/\nstaload _(*anon*) = \"{$LIBATSHWXI}\/teaching\/mydraw\/DATS\/mydraw.dats\"\nstaload _(*anon*) = \"{$LIBATSHWXI}\/teaching\/mydraw\/DATS\/mydraw_cairo.dats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \"{$LIBATSHWXI}\/teaching\/myGTK\/SATS\/gtkcairotimer.sats\"\nstaload \"{$LIBATSHWXI}\/teaching\/myGTK\/DATS\/gtkcairotimer\/gtkcairotimer_toplevel.dats\"\n\/\/\nstaload CP = \"{$LIBATSHWXI}\/teaching\/myGTK\/DATS\/gtkcairotimer\/ControlPanel.dats\"\nstaload DP = \"{$LIBATSHWXI}\/teaching\/myGTK\/DATS\/gtkcairotimer\/DrawingPanel.dats\"\nstaload MAIN = \"{$LIBATSHWXI}\/teaching\/myGTK\/DATS\/gtkcairotimer\/gtkcairotimer_main.dats\"\nstaload TIMER = \"{$LIBATSHWXI}\/teaching\/myGTK\/DATS\/gtkcairotimer\/gtkcairotimer_timer.dats\"\n\/\/\n(* ****** ****** *)\n\ndynload \".\/gtkcairotimer_toplevel.dats\"\n\n(* ****** ****** *)\n\nlocal\n\/\/\nval () = srandom_with_time ()\n\/\/\nval xy0 = ref ((~1, 0))\n\/\/\nval (A0, xys0) =\n genScript (stdout_ref, i2sz(96))\n\/\/\nval theExchlst2 = ref (xys0)\n\/\/\nin (* in-of-local *)\n\nval ASZ = array0_copy (A0)\n\nextern\nfun\nASZ_reset (): void\nimplement\nASZ_reset () = {\n\/\/\nval () = srandom_with_time ()\n\/\/\nvar i: size_t\nval () = !xy0 := ((~1, 0))\nval () = for (i := i2sz(0); i < A0.size; i := succ(i)) ASZ[i] := A0[i]\nval () = !theExchlst2 := xys0\n\/\/\n} (* end of [ASZ_reset] *)\n\nextern\nfun\nASZ_update (): void\nimplement\nASZ_update () = let\n\/\/\n val ij = !xy0\n val xys = !theExchlst2\n\/\/\n val () = (\n case+ xys of\n | nil () => !xy0 := ((~1, 0))\n | cons (xy, xys) => (!xy0 := xy; !theExchlst2 := xys)\n ) (* end of [val] *)\n\/\/\n val i = ij.0 and j = ij.1\n\/\/\nin\n if i >= 0 then array0_interchange (ASZ, g0i2u(i), g0i2u(j))\nend (* end of [ASZ_update] *)\n\nend \/\/ end of [local]\n\n(* ****** ****** *)\n\nimplement\nthe_timer_reset_after<> () = ASZ_reset ()\n\n(* ****** ****** *)\n\nextern\nfun\ncairo_draw_array0\n(\n cr: !cairo_ref1\n, point, point, point, point, array0(int)\n) : void \/\/ end-of-fun\n\n(* ****** ****** *)\n\/\/\nextern\nfun\ncolorgen (x: int): color\n\/\/\nimplement\ncolorgen (x) = let\n\/\/\n val x = $UN.cast{uint32}(x)\n val hval = $extfcall (uint32, \"atslib_inthash_jenkins\", x)\n val hval = $UN.cast{uint}(hval)\n\/\/\n val r = $UN.cast{int}(hval mod 256u)\n val hval = hval \/ 256u\n val g = $UN.cast{int}(hval mod 256u)\n val hval = hval \/ 256u\n val b = $UN.cast{int}(hval mod 256u)\n\/\/\nin\n color_make (r\/256.0, g\/256.0, b\/256.0)\nend \/\/ end of [colorgen]\n\/\/\n(* ****** ****** *)\n\nimplement\ncairo_draw_array0\n(\n cr, p1, p2, p3, p4, ASZ\n) = let\n\/\/\nval p_cr = ptrcast (cr)\n\/\/\nimplement\nmydraw_get0_cairo<> () = let\n\/\/\nextern\ncastfn __cast {l:addr} (ptr(l)): vttakeout (void, cairo_ref(l))\n\/\/\nin\n __cast (p_cr)\nend \/\/ end of [mydraw_get0_cairo]\n\/\/\nimplement\nmydraw_bargraph$color<> (i) = colorgen (ASZ[i])\n\nimplement\nmydraw_bargraph$height<> (i) = 1.0 * (ASZ[i]+1) \/ MYMAX\n\/\/\nval asz = ASZ.size\nval asz = sz2i (asz)\nval asz = ckastloc_gintGt (asz, 0)\n\/\/\nin\n mydraw_bargraph (asz, p1, p2, p3, p4)\nend \/\/ end of [cairo_draw_array0]\n\n(* ****** ****** *)\n\nextern\nfun\nmydraw_clock\n (cr: !cairo_ref1, width: int, height: int) : void\n\/\/ end of [mydraw_clock]\n\n(* ****** ****** *)\n\nimplement\nmydraw_clock\n (cr, W, H) = let\n\/\/\nval W =\ng0int2float_int_double(W)\nand H =\ng0int2float_int_double(H)\n\/\/\nval WH = min (W, H)\n\/\/\nval xm = (W - WH) \/ 2\nval ym = (H - WH) \/ 2\n\/\/\nval v0 = vector_make (xm, ym)\n\/\/\nval p1 = point_make (0. , WH) + v0\nval p2 = point_make (WH , WH) + v0\nval p3 = point_make (WH , 0.) + v0\nval p4 = point_make (0. , 0.) + v0\n\/\/\nval () =\nif the_timer_is_running () then ASZ_update ()\n\/\/\nval (pf | ()) = cairo_save (cr)\nval () = cairo_draw_array0 (cr, p1, p2, p3, p4, ASZ)\nval ((*void*)) = cairo_restore (pf | cr)\n\/\/\nin\n \/\/ nothing\nend \/\/ [mydraw_clock]\n\n(* ****** ****** *)\n\/\/\n%{^\ntypedef char **charptrptr ;\n%} ;\nabstype charptrptr = $extype\"charptrptr\"\n\/\/\n(* ****** ****** *)\n\nimplement\nmain0{n}\n(\n argc, argv\n) = let\n\/\/\nvar argc: int = argc\nvar argv: charptrptr = $UN.castvwtp1{charptrptr}(argv)\n\/\/\nval () = $extfcall (void, \"gtk_init\", addr@(argc), addr@(argv))\n\/\/\nimplement\ngtkcairotimer_title<> () = stropt_some\"InsertionSort\"\nimplement\ngtkcairotimer_timeout_interval<> () = 100U \/\/ millisecs\nimplement\ngtkcairotimer_mydraw<> (cr, width, height) = mydraw_clock (cr, width, height)\n\/\/\nval ((*void*)) = gtkcairotimer_main ((*void*))\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [main0]\n\n(* ****** ****** *)\n\n(* end of [insertsort_anim2.dats] *)\n","old_contents":"\/\/\n\/\/ Animating Quicksort\n\/\/\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_define.hats\"\n#include\n\"share\/atspre_staload.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\nUN = \"prelude\/SATS\/unsafe.sats\"\n\/\/\nstaload \"libats\/ML\/SATS\/basis.sats\"\nstaload \"libats\/ML\/SATS\/list0.sats\"\nstaload \"libats\/ML\/SATS\/array0.sats\"\n\/\/\nstaload _ = \"libats\/ML\/DATS\/list0.dats\"\nstaload _ = \"libats\/ML\/DATS\/array0.dats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \"libats\/SATS\/hashfun.sats\"\nstaload \"libats\/SATS\/hashtbl_chain.sats\"\n\/\/\nstaload _ = \"libats\/DATS\/hashfun.dats\"\nstaload _ = \"libats\/DATS\/hashtbl_chain.dats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\n\"{$LIBATSHWXI}\/testing\/SATS\/randgen.sats\"\nstaload _ =\n\"{$LIBATSHWXI}\/testing\/DATS\/randgen.dats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\n\"{$LIBATSHWXI}\/teaching\/BUCS\/DATS\/BUCS.dats\"\n\/\/\n(* ****** ****** *)\n\n#define MYMAX 100\n\n(* ****** ****** *)\n\ntypedef int2 = (int, int)\n\n(* ****** ****** *)\n\nlocal\n\nval theExchlst =\n ref (list_nil)\n\nin (* in-of-local *)\n\nfun theExchlst_add\n (i1: int, i2: int): void =\n(\n !theExchlst := cons ((i1, i2), !theExchlst)\n)\nfun\ntheExchlst_get_all\n(\n\/\/ argumentlst\n) : List0(int2) = let\n val xys = !theExchlst\n val ((*void*)) = !theExchlst := nil ()\nin\n list_vt2t (list_reverse (xys))\nend \/\/ end of [theExchlst_get_all]\n\nend \/\/ end of [local]\n\n(* ****** ****** *)\n\nextern\nfun{\na:t@ype\n} array0_swap\n (A: array0 (a), i: size_t, j: size_t): void\n\/\/ end of [array0_swap]\n\n(* ****** ****** *)\n \nimplement\n{a}(*tmp*)\narray0_swap\n (A, i, j) =\n{\n val tmp = A[i]\n val () = A[i] := A[j]\n val () = A[j] := tmp\n val () = theExchlst_add (sz2i(i), sz2i(j))\n}\n \n(* ****** ****** *)\n\nextern\nfun{\na:t@ype\n} quicksort (A: array0 (a)): void\n\n(* ****** ****** *)\n\nextern\nfun{\na:t@ype\n} quicksort2\n(\n A: array0 (a), st: size_t, len: size_t\n) : void \/\/ end of [quicksort2]\n\n(* ****** ****** *)\n\nextern\nfun{a:t@ype}\nqsort_partition\n(\n A: array0 (a), st: size_t, len: size_t\n) : size_t \/\/ end of [qsort_partition]\n\n(* ****** ****** *)\n\/\/\nimplement\n{a}(*tmp*)\nquicksort (A) =\n quicksort2 (A, i2sz(0), A.size)\n\/\/\n(* ****** ****** *)\n\nimplement\n{a}(*tmp*)\nquicksort2 (A, st, len) =\n(\nif\nlen >= 2\nthen let\n val len_f = qsort_partition (A, st, len)\n val ((*void*)) = quicksort2 (A, st, len_f)\n val len_r = len - len_f\n val ((*void*)) = quicksort2 (A, succ(st+len_f), pred(len_r))\nin\n \/\/ nothing\nend \/\/ end of [then]\nelse () \/\/ end of [else]\n\/\/\n) (* end of [qsort] *)\n\n(* ****** ****** *)\n\nimplement\n{a}(*tmp*)\nqsort_partition\n (A, st, len) = let\n\/\/\nval last = pred(st+len)\nval pivot = A[last] \/\/ need randomness?\n\/\/\nfun loop\n(\n k1: size_t, k2: size_t\n) : size_t =\n if k2 < last then let\n val sgn = gcompare_val (pivot, A[k2])\n in\n if sgn <= 0\n then loop (k1, succ(k2))\n else (array0_swap(A, k1, k2); loop (succ(k1), succ(k2)))\n \/\/ end of [if]\n end else k1 \/\/ end of [loop]\n\/\/\nval k1 = loop (st, st)\nval () = array0_swap (A, k1, last)\n\/\/\nin\n (k1 - st)\nend \/\/ end of [qort_partition]\n\n(* ****** ****** *)\n\nlocal\n\nimplement\nrandgen_val () = randint (MYMAX)\n\nin (* in-of-local *)\n\nfun\ngenScript{n:int}\n(\n out: FILEref, asz: size_t(n)\n) :\n(\n array0 (int), List0(int2)\n) = let\n\/\/\nval A =\nrandgen_arrayref (asz)\n\/\/\nval A = array0 (A, asz)\nval A2 = array0_copy (A)\n\/\/\nval () = quicksort (A2)\n\/\/\n(*\nval () = fprint (out, A, asz)\nval () = fprint_newline (out)\nval () = fprint (out, A2, asz)\nval () = fprint_newline (out)\n*)\n\/\/\nin\n (A, theExchlst_get_all ())\nend (* end of [genScript] *)\n\nend \/\/ end of [local]\n\n(* ****** ****** *)\n\/\/\nstaload \"{$CAIRO}\/SATS\/cairo.sats\"\n\/\/\nstaload \"{$LIBATSHWXI}\/teaching\/mydraw\/SATS\/mydraw.sats\"\nstaload \"{$LIBATSHWXI}\/teaching\/mydraw\/SATS\/mydraw_cairo.sats\"\n\/\/\nstaload \"{$LIBATSHWXI}\/teaching\/mydraw\/DATS\/mydraw_bargraph.dats\"\n\/\/\nstaload _(*anon*) = \"{$LIBATSHWXI}\/teaching\/mydraw\/DATS\/mydraw.dats\"\nstaload _(*anon*) = \"{$LIBATSHWXI}\/teaching\/mydraw\/DATS\/mydraw_cairo.dats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \"{$LIBATSHWXI}\/teaching\/myGTK\/SATS\/gtkcairotimer.sats\"\nstaload \"{$LIBATSHWXI}\/teaching\/myGTK\/DATS\/gtkcairotimer\/gtkcairotimer_toplevel.dats\"\n\/\/\nstaload CP = \"{$LIBATSHWXI}\/teaching\/myGTK\/DATS\/gtkcairotimer\/ControlPanel.dats\"\nstaload DP = \"{$LIBATSHWXI}\/teaching\/myGTK\/DATS\/gtkcairotimer\/DrawingPanel.dats\"\nstaload MAIN = \"{$LIBATSHWXI}\/teaching\/myGTK\/DATS\/gtkcairotimer\/gtkcairotimer_main.dats\"\nstaload TIMER = \"{$LIBATSHWXI}\/teaching\/myGTK\/DATS\/gtkcairotimer\/gtkcairotimer_timer.dats\"\n\/\/\n(* ****** ****** *)\n\ndynload \".\/gtkcairotimer_toplevel.dats\"\n\n(* ****** ****** *)\n\nlocal\n\/\/\nval xy0 = ref ((0, 0))\n\/\/\nval ((*void*)) = srandom_with_time ()\n\/\/\nval (A0, xys0) =\n genScript (stdout_ref, i2sz(64))\n\/\/\nval theExchlst2 = ref (xys0)\n\/\/\nin (* in-of-local *)\n\nval ASZ = array0_copy (A0)\n\nextern\nfun\nASZ_reset (): void\nimplement\nASZ_reset () = {\n\/\/\nvar i: size_t\nval () = !xy0 := ((0, 0))\nval () = for (i := i2sz(0); i < A0.size; i := succ(i)) ASZ[i] := A0[i]\nval () = !theExchlst2 := xys0\n\/\/\n} (* end of [ASZ_reset] *)\n\nextern\nfun\nASZ_update (): void\nimplement\nASZ_update () = let\n\/\/\n val ij = !xy0\n val xys = !theExchlst2\n\/\/\n val () = (\n case+ xys of\n | nil () => !xy0 := ((0, 0))\n | cons (xy, xys) => (!xy0 := xy; !theExchlst2 := xys)\n ) (* end of [val] *)\n\/\/\n val i = ij.0 and j = ij.1\n\/\/\nin\n if i >= 0 then array0_interchange (ASZ, g0i2u(i), g0i2u(j))\nend (* end of [ASZ_update] *)\n\nend \/\/ end of [local]\n\n(* ****** ****** *)\n\nimplement\nthe_timer_reset_after<> () = ASZ_reset ()\n\n(* ****** ****** *)\n\nextern\nfun\ncairo_draw_array0\n(\n cr: !cairo_ref1\n, point, point, point, point, array0(int)\n) : void \/\/ end-of-fun\n\n(* ****** ****** *)\n\/\/\nextern\nfun\ncolorgen (x: int): color\n\/\/\nimplement\ncolorgen (x) = let\n\/\/\n val x = $UN.cast{uint32}(x)\n val hval = $extfcall (uint32, \"atslib_inthash_jenkins\", x)\n val hval = $UN.cast{uint}(hval)\n\/\/\n val r = $UN.cast{int}(hval mod 256u)\n val hval = hval \/ 256u\n val g = $UN.cast{int}(hval mod 256u)\n val hval = hval \/ 256u\n val b = $UN.cast{int}(hval mod 256u)\n\/\/\nin\n color_make (r\/256.0, g\/256.0, b\/256.0)\nend \/\/ end of [colorgen]\n\/\/\n(* ****** ****** *)\n\nimplement\ncairo_draw_array0\n(\n cr, p1, p2, p3, p4, ASZ\n) = let\n\/\/\nval p_cr = ptrcast (cr)\n\/\/\nimplement\nmydraw_get0_cairo<> () = let\n\/\/\nextern\ncastfn __cast {l:addr} (ptr(l)): vttakeout (void, cairo_ref(l))\n\/\/\nin\n __cast (p_cr)\nend \/\/ end of [mydraw_get0_cairo]\n\/\/\nimplement\nmydraw_bargraph$color<> (i) = colorgen (ASZ[i])\n\nimplement\nmydraw_bargraph$height<> (i) = 1.0 * (ASZ[i]+1) \/ MYMAX\n\/\/\nval asz = ASZ.size\nval asz = sz2i (asz)\nval asz = ckastloc_gintGt (asz, 0)\n\/\/\nin\n mydraw_bargraph (asz, p1, p2, p3, p4)\nend \/\/ end of [cairo_draw_array0]\n\n(* ****** ****** *)\n\nextern\nfun\nmydraw_clock\n (cr: !cairo_ref1, width: int, height: int) : void\n\/\/ end of [mydraw_clock]\n\n(* ****** ****** *)\n\nimplement\nmydraw_clock\n (cr, W, H) = let\n\/\/\nval W =\ng0int2float_int_double(W)\nand H =\ng0int2float_int_double(H)\n\/\/\nval WH = min (W, H)\n\/\/\nval xm = (W - WH) \/ 2\nval ym = (H - WH) \/ 2\n\/\/\nval v0 = vector_make (xm, ym)\n\/\/\nval p1 = point_make (0. , WH) + v0\nval p2 = point_make (WH , WH) + v0\nval p3 = point_make (WH , 0.) + v0\nval p4 = point_make (0. , 0.) + v0\n\/\/\nval () =\nif the_timer_is_running () then ASZ_update ()\n\/\/\nval (pf | ()) = cairo_save (cr)\nval () = cairo_draw_array0 (cr, p1, p2, p3, p4, ASZ)\nval ((*void*)) = cairo_restore (pf | cr)\n\/\/\nin\n \/\/ nothing\nend \/\/ [mydraw_clock]\n\n(* ****** ****** *)\n\/\/\n%{^\ntypedef char **charptrptr ;\n%} ;\nabstype charptrptr = $extype\"charptrptr\"\n\/\/\n(* ****** ****** *)\n\nimplement\nmain0{n}\n(\n argc, argv\n) = let\n\/\/\nvar argc: int = argc\nvar argv: charptrptr = $UN.castvwtp1{charptrptr}(argv)\n\/\/\nval () = $extfcall (void, \"gtk_init\", addr@(argc), addr@(argv))\n\/\/\nimplement\ngtkcairotimer_title<> () = stropt_some\"InsertionSort\"\nimplement\ngtkcairotimer_timeout_interval<> () = 100U \/\/ millisecs\nimplement\ngtkcairotimer_mydraw<> (cr, width, height) = mydraw_clock (cr, width, height)\n\/\/\nval ((*void*)) = gtkcairotimer_main ((*void*))\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [main0]\n\n(* ****** ****** *)\n\n(* end of [insertsort_anim2.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"10a8a5a6e07cc0f6418ee7650ec07bf0593fd9c0","subject":"Updating: very minorly improving","message":"Updating: very minorly improving\n","repos":"bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib","old_file":"projects\/SMALL\/JSmydraw\/Sierpinski_3angle\/Sierpinski_3angle_txt.dats","new_file":"projects\/SMALL\/JSmydraw\/Sierpinski_3angle\/Sierpinski_3angle_txt.dats","new_contents":"(*\n** Poorman's Drawing\n** Sierpinski triangles\n*)\n\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_define.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\n#define\nATS_MAINATSFLAG 1\n\/\/\n#define\nATS_DYNLOADNAME\n\"Sierpinski_3angle_txt__dynload\"\n\/\/\n#define\nATS_STATIC_PREFIX \"Sierpinski_3angle_txt__\"\n\/\/\n(* ****** ****** *)\n\/\/\n#include\n\"{$LIBATSCC2JS}\/staloadall.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\n\"{$LIBATSCC2JS}\/SATS\/print.sats\"\n\/\/\nstaload\n_ = \"{$LIBATSCC2JS}\/DATS\/print.dats\"\n\/\/\n(* ****** ****** *)\n\n#define NROW 48\n#define NCOL 80\n\n(* ****** ****** *)\n\/\/\nval\ntheCanvas =\nmatrixref_make_elt{int}(NROW, NCOL, 0)\n\/\/\n(* ****** ****** *)\n\/\/\nfun\ntheCanvas_clear() =\nmatrixref_foreach_cloref\n (theCanvas, NROW, NCOL, lam(i, j) => (theCanvas[i,NCOL,j] := 0))\n\/\/\n(* ****** ****** *)\n\/\/\nfun\ntheCanvas_print() =\nmatrixref_foreach_cloref\n(\n theCanvas\n, NROW, NCOL\n, lam(i, j) =>\n let\n val x = theCanvas[i,NCOL,j]\n in\n print_string(if x = 0 then \" \" else \"X\"); if j=NCOL-1 then print_newline()\n end \/\/ end of [let]\n) (* end of [matrixref_foreach] *)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\ndraw_point(x: int, y: int): void\n\/\/\nimplement\ndraw_point(x, y) = let\n\/\/\nval x = g1ofg0(x) and y = g1ofg0(y)\n\/\/\n(*\nval () = println! (\"draw_point: x = \", x)\nval () = println! (\"draw_point: y = \", y)\n*)\n\/\/\nin\n if x < 0 then ()\n else if y < 0 then ()\n else if x >= NCOL then ()\n else if y >= NROW then ()\n else (theCanvas[y, NCOL, x] := 1)\nend \/\/ end of [draw_point]\n\/\/\n(* ****** ****** *)\n\ntypedef\npoint = $tup(int, int)\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nmidpoint(p1: point, p2: point): point\n\/\/\n(* ****** ****** *)\n\nimplement\nmidpoint(p1, p2) = $tup((p1.0+p2.0)\/2, (p1.1+p2.1)\/2)\n\n(* ****** ****** *)\n\/\/\nextern\nfun\ndraw_hline\n (x1: int, x2: int, y: int): void\n\/\/\n(* ****** ****** *)\n\nimplement\ndraw_hline\n (x1, x2, y) = let\n\/\/\nfun loop (x1: int): void =\n if x1 <= x2\n then (draw_point(x1, y); loop(x1+1)) else ()\n \/\/ end of [if]\n\/\/\nin\n loop (x1)\nend \/\/ end of [draw_hline]\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\ndraw_triangle_0\n (p1: point, p2: point, p3: point): void\nextern\nfun\ndraw_triangle_1\n (p1: point, p2: point, p3: point): void\n\/\/\n(* ****** ****** *)\n\nimplement\ndraw_triangle_0\n (p1, p2, p3) = let\n\/\/\nval x1 = p1.0 and y1 = p1.1\nval x2 = p2.0 and y2 = p2.1\nval x3 = p3.0 and y3 = p3.1\n\/\/\nval () = assertloc (y2 = y3)\nval () = assertloc (x1 + x1 = x2 + x3)\n\/\/\nval dir =\n (if y1 >= y2 then 1 else ~1): int\n\/\/\nfun\nloop\n(\n x2: int, x3: int, y2: int\n) : void = let\n\/\/\nval () = draw_point(x2, y2)\nval () = draw_point(x3, y2)\n\/\/\nin\n if y1 != y2\n then loop(x2+1, x3-1, y2+dir) else ()\n \/\/ end of [if]\nend \/\/ end of [loop]\n\/\/\nin\n draw_hline(x2+1, x3-1, y2); loop (x2, x3, y2)\nend \/\/ end of [draw_triangle_0]\n\n(* ****** ****** *)\n\nimplement\ndraw_triangle_1\n (p1, p2, p3) = let\n\/\/\nval x1 = p1.0 and y1 = p1.1\nval x2 = p2.0 and y2 = p2.1\nval x3 = p3.0 and y3 = p3.1\n\/\/\nval () = assertloc (y2 = y3)\nval () = assertloc (x1 + x1 = x2 + x3)\n\/\/\nval dir =\n (if y1 >= y2 then 1 else ~1): int\n\/\/\nfun\nloop\n(\n x2: int, x3: int, y2: int\n) : void = let\n\/\/\nval () = draw_hline(x2, x3, y2)\n\/\/\nin\n if y1 != y2 then loop(x2+1, x3-1, y2+dir) else ()\nend \/\/ end of [loop]\n\/\/\nin\n loop (x2, x3, y2)\nend \/\/ end of [draw_triangle_1]\n\n(* ****** ****** *)\n\/\/\nextern\nfun\ndraw_sierpinski\n (p1: point, p2: point, p3: point, n: int): void\nextern\nfun\ndraw_sierpinski_aux\n (p1: point, p2: point, p3: point, n: int): void\n\/\/\n(* ****** ****** *)\n\nimplement\ndraw_sierpinski\n (p1, p2, p3, n) =\n(\n if n > 0\n then draw_sierpinski_aux(p1, p2, p3, n)\n else ()\n \/\/ end of [if]\n) (* end of [draw_sierpinski] *)\n\nimplement\ndraw_sierpinski_aux\n (p1, p2, p3, n) = let\n\/\/\n val p12 = midpoint(p1, p2)\n val p23 = midpoint(p2, p3)\n val p31 = midpoint(p3, p1)\n\/\/\n val () = draw_triangle_1(p23, p12, p31)\n val () = draw_sierpinski(p1, p12, p31, n-1)\n val () = draw_sierpinski(p12, p2, p23, n-1)\n val () = draw_sierpinski(p31, p23, p3, n-1)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [draw_sierpinski_aux]\n\n(* ****** ****** *)\n\/\/\nextern\nfun\ndraw_sierpinski_demo\n (level: int): void = \"mac#\"\n\/\/\n(* ****** ****** *)\n\nimplement\ndraw_sierpinski_demo\n (level) = let\n\/\/\nval p1 = $tup(32, 0 )\nval p2 = $tup(0 , 32)\nval p3 = $tup(64, 32)\n\/\/\nval () = theCanvas_clear()\nval () = draw_triangle_0(p1, p2, p3)\nval () = draw_sierpinski(p1, p2, p3, level)\nval () = theCanvas_print()\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [draw_sierpinski_demo]\n\n(* ****** ****** *)\n\n%{$\n\/\/\nvar theLevel = 0;\nvar theLevelMax = 5;\n\nfunction\ndraw2_sierpinski_demo()\n{\n\/\/\nvar\nlevel = theLevel;\n\/\/\ntheLevel = (level+1)%theLevelMax;\n\/\/\nvar _ =\nats2jspre_the_print_store_clear();\n\/\/\nvar _ = draw_sierpinski_demo(level);\n\/\/\ndocument.getElementById(\"theDrawingString\").innerHTML = ats2jspre_the_print_store_join();\n\/\/\nsetTimeout(draw2_sierpinski_demo, 1000);\n\/\/\nreturn;\n\/\/\n} \/\/ end of [draw2_sierpinski_demo]\n\/\/\njQuery(document).ready(function(){Sierpinski_3angle_txt__dynload(); draw2_sierpinski_demo();});\n\/\/\n%} \/\/ end of [%{$]\n\n(* ****** ****** *)\n\n(* end of [Sierpinski_3angle_txt.dats] *)\n","old_contents":"(*\n**\n*)\n\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_define.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\n#define\nATS_MAINATSFLAG 1\n\/\/\n#define\nATS_DYNLOADNAME\n\"Sierpinski_3angle_txt__dynload\"\n\/\/\n#define\nATS_STATIC_PREFIX \"Sierpinski_3angle_txt__\"\n\/\/\n(* ****** ****** *)\n\/\/\n#include\n\"{$LIBATSCC2JS}\/staloadall.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\n\"{$LIBATSCC2JS}\/SATS\/print.sats\"\n\/\/\nstaload\n_ = \"{$LIBATSCC2JS}\/DATS\/print.dats\"\n\/\/\n(* ****** ****** *)\n\n#define NROW 48\n#define NCOL 80\n\n(* ****** ****** *)\n\/\/\nval\ntheCanvas =\nmatrixref_make_elt{int}(NROW, NCOL, 0)\n\/\/\n(* ****** ****** *)\n\/\/\nfun\ntheCanvas_clear() =\nmatrixref_foreach_cloref\n (theCanvas, NROW, NCOL, lam(i, j) => (theCanvas[i,NCOL,j] := 0))\n\/\/\n(* ****** ****** *)\n\/\/\nfun\ntheCanvas_print() =\nmatrixref_foreach_cloref\n(\n theCanvas\n, NROW, NCOL\n, lam(i, j) =>\n let\n val x = theCanvas[i,NCOL,j]\n in\n print_string(if x = 0 then \" \" else \"X\"); if j=NCOL-1 then print_newline()\n end \/\/ end of [let]\n) (* end of [matrixref_foreach] *)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\ndraw_point(x: int, y: int): void\n\/\/\nimplement\ndraw_point(x, y) = let\n\/\/\nval x = g1ofg0(x) and y = g1ofg0(y)\n\/\/\n(*\nval () = println! (\"draw_point: x = \", x)\nval () = println! (\"draw_point: y = \", y)\n*)\n\/\/\nin\n if x < 0 then ()\n else if y < 0 then ()\n else if x >= NCOL then ()\n else if y >= NROW then ()\n else (theCanvas[y, NCOL, x] := 1)\nend \/\/ end of [draw_point]\n\/\/\n(* ****** ****** *)\n\ntypedef\npoint = $tup(int, int)\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nmidpoint(p1: point, p2: point): point\n\/\/\n(* ****** ****** *)\n\nimplement\nmidpoint(p1, p2) = $tup((p1.0+p2.0)\/2, (p1.1+p2.1)\/2)\n\n(* ****** ****** *)\n\/\/\nextern\nfun\ndraw_hline\n (x1: int, x2: int, y: int): void\n\/\/\n(* ****** ****** *)\n\nimplement\ndraw_hline\n (x1, x2, y) = let\n\/\/\nfun loop (x1: int): void =\n if x1 <= x2\n then (draw_point(x1, y); loop(x1+1)) else ()\n \/\/ end of [if]\n\/\/\nin\n loop (x1)\nend \/\/ end of [draw_hline]\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\ndraw_triangle_0\n (p1: point, p2: point, p3: point): void\nextern\nfun\ndraw_triangle_1\n (p1: point, p2: point, p3: point): void\n\/\/\n(* ****** ****** *)\n\nimplement\ndraw_triangle_0\n (p1, p2, p3) = let\n\/\/\nval x1 = p1.0 and y1 = p1.1\nval x2 = p2.0 and y2 = p2.1\nval x3 = p3.0 and y3 = p3.1\n\/\/\nval () = assertloc (y2 = y3)\nval () = assertloc (x1 + x1 = x2 + x3)\n\/\/\nval dir =\n (if y1 >= y2 then 1 else ~1): int\n\/\/\nfun\nloop\n(\n x2: int, x3: int, y2: int\n) : void = let\n\/\/\nval () = draw_point(x2, y2)\nval () = draw_point(x3, y2)\n\/\/\nin\n if y1 != y2\n then loop(x2+1, x3-1, y2+dir) else ()\n \/\/ end of [if]\nend \/\/ end of [loop]\n\/\/\nin\n draw_hline(x2+1, x3-1, y2); loop (x2, x3, y2)\nend \/\/ end of [draw_triangle_0]\n\n(* ****** ****** *)\n\nimplement\ndraw_triangle_1\n (p1, p2, p3) = let\n\/\/\nval x1 = p1.0 and y1 = p1.1\nval x2 = p2.0 and y2 = p2.1\nval x3 = p3.0 and y3 = p3.1\n\/\/\nval () = assertloc (y2 = y3)\nval () = assertloc (x1 + x1 = x2 + x3)\n\/\/\nval dir =\n (if y1 >= y2 then 1 else ~1): int\n\/\/\nfun\nloop\n(\n x2: int, x3: int, y2: int\n) : void = let\n\/\/\nval () = draw_hline(x2, x3, y2)\n\/\/\nin\n if y1 != y2 then loop(x2+1, x3-1, y2+dir) else ()\nend \/\/ end of [loop]\n\/\/\nin\n loop (x2, x3, y2)\nend \/\/ end of [draw_triangle_1]\n\n(* ****** ****** *)\n\/\/\nextern\nfun\ndraw_sierpinski\n (p1: point, p2: point, p3: point, n: int): void\nextern\nfun\ndraw_sierpinski_aux\n (p1: point, p2: point, p3: point, n: int): void\n\/\/\n(* ****** ****** *)\n\nimplement\ndraw_sierpinski\n (p1, p2, p3, n) =\n(\n if n > 0\n then draw_sierpinski_aux(p1, p2, p3, n)\n else ()\n \/\/ end of [if]\n) (* end of [draw_sierpinski] *)\n\nimplement\ndraw_sierpinski_aux\n (p1, p2, p3, n) = let\n\/\/\n val p12 = midpoint(p1, p2)\n val p23 = midpoint(p2, p3)\n val p31 = midpoint(p3, p1)\n\/\/\n val () = draw_triangle_1(p23, p12, p31)\n val () = draw_sierpinski(p1, p12, p31, n-1)\n val () = draw_sierpinski(p12, p2, p23, n-1)\n val () = draw_sierpinski(p31, p23, p3, n-1)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [draw_sierpinski_aux]\n\n(* ****** ****** *)\n\/\/\nextern\nfun\ndraw_sierpinski_demo\n (level: int): void = \"mac#\"\n\/\/\n(* ****** ****** *)\n\nimplement\ndraw_sierpinski_demo\n (level) = let\n\/\/\nval p1 = $tup(32, 0 )\nval p2 = $tup(0 , 32)\nval p3 = $tup(64, 32)\n\/\/\nval () = theCanvas_clear()\nval () = draw_triangle_0(p1, p2, p3)\nval () = draw_sierpinski(p1, p2, p3, level)\nval () = theCanvas_print()\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [draw_sierpinski_demo]\n\n(* ****** ****** *)\n\n%{$\n\/\/\nvar theLevel = 0;\nvar theLevelMax = 5;\n\nfunction\ndraw2_sierpinski_demo()\n{\n\/\/\nvar\nlevel = theLevel;\n\/\/\ntheLevel = (level+1)%theLevelMax;\n\/\/\nvar _ =\nats2jspre_the_print_store_clear();\n\/\/\nvar _ = draw_sierpinski_demo(level);\n\/\/\ndocument.getElementById(\"theDrawingString\").innerHTML = ats2jspre_the_print_store_join();\n\/\/\nsetTimeout(draw2_sierpinski_demo, 1000);\n\/\/\nreturn;\n\/\/\n} \/\/ end of [draw2_sierpinski_demo]\n\/\/\njQuery(document).ready(function(){Sierpinski_3angle_txt__dynload(); draw2_sierpinski_demo();});\n\/\/\n%} \/\/ end of [%{$]\n\n(* ****** ****** *)\n\n(* end of [Sierpinski_3angle_txt.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"58ff6e164191f6ca8e6f2603a5da3e5d5459c2e9","subject":"Updating: working on chardev-1","message":"Updating: working on chardev-1\n","repos":"ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib","old_file":"projects\/MEDIUM\/LinuxKerneling\/TEST\/mycode\/chardev\/chardev-1.dats","new_file":"projects\/MEDIUM\/LinuxKerneling\/TEST\/mycode\/chardev\/chardev-1.dats","new_contents":"(*\n** A simple char device\n*)\n\n(* ****** ****** *)\n\/\/\n\/\/ HX-2014-10-24:\n\/\/ nothing fancy here;\n\/\/ just trying to get it working\n\/\/\n(* ****** ****** *)\n\/\/\n\/\/ HX-2014-10-21:\n\/\/ no use for dynloading\n\/\/\n#define ATS_DYNLOADFLAG 0\n\/\/\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_define.hats\"\n\/\/\n#include\n\"{$KERNELATS}\/prelude\/staloadall.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\n\"{$LINUX}\/basics.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\n\"{$LINUX}\/SATS\/errno.sats\"\nstaload\n\"{$LINUX}\/SATS\/types.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\n\"{$LINUX}\/SATS\/init.sats\"\nstaload\n\"{$LINUX}\/SATS\/module.sats\"\nstaload\n\"{$LINUX}\/SATS\/kernel.sats\"\nstaload $PRINTK \/\/ HX: opening NS\n\/\/\nstaload \"{$LINUX}\/SATS\/fs.sats\"\n\/\/\n(* ****** ****** *)\n\nstaload\nUN = \"prelude\/SATS\/unsafe.sats\"\n\n(* ****** ****** *)\n\n%{^\nMODULE_LICENSE(\"Dual BSD\/GPL\") ;\n%} \/\/ end of [%{^]\n\n(* ****** ****** *)\n\nstatic\nfun init_module(): interr = \"mac#\"\nstatic\nfun cleanup_module(): void = \"mac#\"\n\n(* ****** ****** *)\n\n%{^\nstatic int Major = 0;\nstatic int Device_open = 0;\nstatic int Device_open_count = 0;\n%} \/\/ end of [%{^]\n\nmacdef\nMajor = $extval(int, \"Major\")\nmacdef\nDevice_open = $extval(int, \"Device_open\")\nmacdef\nDevice_open_count = $extval(int, \"Device_open_count\")\n\n(* ****** ****** *)\n\n%{^\n#define BUFLEN 80 \/\/ Max length of the message from the device\n#define DEVICE_NAME \"chardev-1\" \/* Dev name as it appears in \/proc\/devices *\/\n\/\/\ntypedef\nchar *charptr ;\nchar Message[BUFLEN];\ncharptr Message0_ptr = &Message[0];\ncharptr Message1_ptr = &Message[0];\n\/\/\n%} \/\/ end of [%{^]\n\ntypedef charptr = $extype\"charptr\"\n\nmacdef\nDEVICE_NAME = $extval(string, \"DEVICE_NAME\")\nmacdef\nMessage0_ptr = $extval(charptr, \"Message0_ptr\")\nmacdef\nMessage1_ptr = $extval(charptr, \"Message1_ptr\")\n\n(* ****** ****** *)\n\n%{^\n\/\/\nstatic int device_open(struct inode *, struct file *);\nstatic int device_release(struct inode *, struct file *);\nstatic ssize_t device_read(struct file *, char *, size_t, loff_t *);\nstatic ssize_t device_write(struct file *, const char *, size_t, loff_t *);\n\/\/\n%} \/\/ end of [%{^]\n\n(* ****** ****** *)\n\n%{^\n\nstruct\nfile_operations\nfops = {\n .read = device_read,\n .write = device_write,\n .open = device_open,\n .release = device_release\n} ;\n\nstatic void *fops_ptr = &(fops);\n\n%} \/\/ end of [%{^]\n\nmacdef\nfops_ptr = $extval(fops_ptr1, \"fops_ptr\")\n\n(* ****** ****** *)\n\nimplement\ninit_module\n(\n) = let\n\/\/\nextvar\n\"Major\" =\nregister_chrdev(0u, DEVICE_NAME, fops_ptr)\n\/\/\nval Major = g1ofg0(Major)\n\/\/\nin\n\/\/\nif\n(Major > 0)\nthen let\n\/\/\nval () =\n$extfcall\n(\n void\n, \"printk\", KERN_INFO_\"The assigned major number is: %d\\n\", Major\n) (* end of [val] *)\n\/\/\nin\n 0(*SUCCESS*)\nend \/\/ end of [then]\nelse let\n\/\/\nval () =\n$extfcall\n(\n void\n, \"printk\", KERN_ALERT_\"Registering chardev failed with %d\\n\", Major\n) (* end of [val] *)\n\/\/\nin\n Major\nend \/\/ end of [else]\n\/\/\nend (* end of [init_module] *)\n\n(* ****** ****** *)\n\nimplement\ncleanup_module\n(\n\/\/ argumentless\n) = () where\n{\n\/\/\nval\nMajor =\n(\nif Major > 0\n then g0i2u(Major) else 0u\n\/\/ end of [if]\n) : uint \/\/ end of [val]\n\/\/\nval () = unregister_chrdev(Major, DEVICE_NAME)\n\/\/\n} (* end of [cleanup_module] *)\n\n(* ****** ****** *)\n\/\/\nstatic\nfun device_open_ (inode_ptr1, file_ptr1): interr = \"mac#\"\nstatic\nfun device_release_ (inode_ptr1, file_ptr1): interr = \"mac#\"\n\/\/\n(* ****** ****** *)\n\nimplement\ndevice_open_\n (inx, filp) = let\nin\n\/\/\nif\n(Device_open = 0)\nthen let\n\/\/\nextvar\n\"Device_open\" = Device_open + 1\nextvar\n\"Device_open_count\" = Device_open_count + 1\n\/\/\nval () =\n$extfcall\n(\n void\n, \"sprintf\"\n, Message0_ptr, \"Hello(%d) from the chardev\\n\", Device_open_count\n) : void \/\/ end of [val]\n\/\/\nextvar\n\"Message1_ptr\" = Message0_ptr\n\/\/\nin\n 0(*SUCCESS*)\nend \/\/ end of [then]\nelse ~(EBUSY) \/\/ end of [else]\n\/\/\nend \/\/ end of [device_open_]\n \n(* ****** ****** *)\n\nimplement\ndevice_release_\n (inx, filp) = let\n\/\/\nextvar\n\"Device_open_count\" = Device_open_count - 1\n\/\/\nin\n 0(*SUCCESS*)\nend \/\/ end of [device_release_]\n\n(* ****** ****** *)\n\n%{$\n\/\/\nstatic\ninline\nint\ndevice_open\n(\nstruct inode *p0, struct file *p1\n) { return device_open_(p0, p1) ; }\n\/\/\nstatic\ninline\nint\ndevice_release\n(\nstruct inode *p0, struct file *p1\n) { return device_release_(p0, p1) ; }\n\/\/\n%} \/\/ end of [%{$]\n\n(* ****** ****** *)\n\/\/\nstatic\nfun\ndevice_read_{n:int}\n(\n file_ptr1, buf: &ubytes(n), size_t(n), ofs: &loff_t\n) : ssize_t = \"mac#\" \/\/ end-of-function\nstatic\nfun\ndevice_write_{n:int}\n(\n file_ptr1, buf: &ubytes(n), size_t(n), ofs: &loff_t\n) : ssize_t = \"mac#\" \/\/ end-of-function\n\/\/\n(* ****** ****** *)\n\nimplement\ndevice_read_\n (filp, buf, n, ofs) = let\n\/\/\nval n2 =\nstring_nlength<>\n ($UN.cast{string}(Message1_ptr), n)\n\/\/\nval nread =\n$extfcall\n(\n size_t\n, \"copy_to_user\", addr@buf, Message1_ptr, n2\n) (* end of [val] *)\n\/\/\nextvar\n\"Message1_ptr\" =\nadd_ptr_bsz ($UN.cast{ptr}(Message1_ptr), nread)\n\/\/\nin\n $UN.cast{ssize_t}(nread)\nend \/\/ end of [device_read_]\n\n(* ****** ****** *)\n\nimplement\ndevice_write_\n (filp, buf, n, ofs) = let\n\/\/\nval () =\n$extfcall\n(\n void\n, \"printk\"\n, KERN_ALERT_\"Sorry, this operation isn't supported.\\n\"\n) (* end of [val] *)\n\/\/\nin\n $UN.cast{ssize_t}(~(EINVAL))\nend \/\/ end of [device_write_]\n\n(* ****** ****** *)\n\n%{$\n\/\/\nstatic\ninline\nssize_t\ndevice_read\n(\nstruct file *p0, char *buf, size_t n, loff_t *ofs\n) { return device_read_(p0, buf, n, ofs) ; }\n\/\/\nstatic\ninline\nssize_t\ndevice_write\n(\nstruct file *p0, const char *buf, size_t n, loff_t *ofs\n) { return device_write_(p0, (void*)buf, n, ofs) ; }\n\/\/\n%} \/\/ end of [%{$]\n\n(* ****** ****** *)\n\n(* end of [chardev-1.dats] *)\n","old_contents":"(*\n** A simple char device\n*)\n\n(* ****** ****** *)\n\/\/\n\/\/ HX-2014-10-24:\n\/\/ nothing fancy here;\n\/\/ just trying to get it working\n\/\/\n(* ****** ****** *)\n\/\/\n\/\/ HX-2014-10-21:\n\/\/ no use for dynloading\n\/\/\n#define ATS_DYNLOADFLAG 0\n\/\/\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_define.hats\"\n\/\/\n#include\n\"{$KERNELATS}\/prelude\/staloadall.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\n\"{$LINUX}\/basics.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\n\"{$LINUX}\/SATS\/errno.sats\"\nstaload\n\"{$LINUX}\/SATS\/types.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\n\"{$LINUX}\/SATS\/init.sats\"\nstaload\n\"{$LINUX}\/SATS\/module.sats\"\nstaload\n\"{$LINUX}\/SATS\/kernel.sats\"\nstaload $PRINTK \/\/ HX: opening NS\n\/\/\nstaload \"{$LINUX}\/SATS\/fs.sats\"\n\/\/\n(* ****** ****** *)\n\nstaload\nUN = \"prelude\/SATS\/unsafe.sats\"\n\n(* ****** ****** *)\n\n%{^\nMODULE_LICENSE(\"Dual BSD\/GPL\") ;\n%} \/\/ end of [%{^]\n\n(* ****** ****** *)\n\nstatic\nfun init_module(): interr = \"mac#\"\nstatic\nfun cleanup_module(): void = \"mac#\"\n\n(* ****** ****** *)\n\n%{^\nstatic int Major = 0;\nstatic int Device_open = 0;\nstatic int Device_open_count = 0;\n%} \/\/ end of [%{^]\n\nmacdef\nMajor = $extval(int, \"Major\")\nmacdef\nDevice_open = $extval(int, \"Device_open\")\nmacdef\nDevice_open_count = $extval(int, \"Device_open_count\")\n\n(* ****** ****** *)\n\n%{^\n#define BUFLEN 80 \/\/ Max length of the message from the device\n#define DEVICE_NAME \"chardev-1\" \/* Dev name as it appears in \/proc\/devices *\/\n\/\/\ntypedef\nchar *charptr ;\nchar Message[BUFLEN];\ncharptr Message0_ptr = &Message[0];\ncharptr Message1_ptr = &Message[0];\n\/\/\n%} \/\/ end of [%{^]\n\ntypedef charptr = $extype\"charptr\"\n\nmacdef\nDEVICE_NAME = $extval(string, \"DEVICE_NAME\")\nmacdef\nMessage0_ptr = $extval(charptr, \"Message0_ptr\")\nmacdef\nMessage1_ptr = $extval(charptr, \"Message1_ptr\")\n\n(* ****** ****** *)\n\n%{^\n\/\/\nstatic int device_open(struct inode *, struct file *);\nstatic int device_release(struct inode *, struct file *);\nstatic ssize_t device_read(struct file *, char *, size_t, loff_t *);\nstatic ssize_t device_write(struct file *, const char *, size_t, loff_t *);\n\/\/\n%} \/\/ end of [%{^]\n\n(* ****** ****** *)\n\n%{^\n\nstruct\nfile_operations\nfops = {\n .read = device_read,\n .write = device_write,\n .open = device_open,\n .release = device_release\n} ;\n\nstatic void *fops_ptr = &(fops);\n\n%} \/\/ end of [%{^]\n\nmacdef\nfops_ptr = $extval(fops_ptr1, \"fops_ptr\")\n\n(* ****** ****** *)\n\nimplement\ninit_module\n(\n) = let\n\/\/\nextvar\n\"Major\" =\nregister_chrdev(0u, DEVICE_NAME, fops_ptr)\n\/\/\nval Major = g1ofg0(Major)\n\/\/\nin\n\/\/\nif\n(Major > 0)\nthen let\n\/\/\nval () =\n$extfcall\n(\n void\n, \"printk\", KERN_INFO_\"The assigned major number is: %d\\n\", Major\n) (* end of [val] *)\n\/\/\nin\n 0(*SUCCESS*)\nend \/\/ end of [then]\nelse let\n\/\/\nval () =\n$extfcall\n(\n void\n, \"printk\", KERN_ALERT_\"Registering chardev failed with %d\\n\", Major\n) (* end of [val] *)\n\/\/\nin\n Major\nend \/\/ end of [else]\n\/\/\nend (* end of [init_module] *)\n\n(* ****** ****** *)\n\nimplement\ncleanup_module\n(\n\/\/ argumentless\n) = () where\n{\n\/\/\nval\nMajor =\n(\nif Major > 0\n then g0i2u(Major) else 0u\n\/\/ end of [if]\n) : uint \/\/ end of [val]\n\/\/\nval () = unregister_chrdev(Major, DEVICE_NAME)\n\/\/\n} (* end of [cleanup_module] *)\n\n(* ****** ****** *)\n\/\/\nstatic\nfun device_open_ (inode_ptr1, file_ptr1): interr = \"mac#\"\nstatic\nfun device_release_ (inode_ptr1, file_ptr1): interr = \"mac#\"\n\/\/\n(* ****** ****** *)\n\nimplement\ndevice_open_\n (inx, filp) = let\nin\n\/\/\nif\n(Device_open = 0)\nthen let\n\/\/\nextvar\n\"Device_open\" = Device_open + 1\nextvar\n\"Device_open_count\" = Device_open_count + 1\n\/\/\nval () =\n$extfcall\n(\n void\n, \"sprintf\"\n, Message0_ptr, \"Hello(%d) from the chardev\\n\", Device_open_count\n) : void \/\/ end of [val]\n\/\/\nextvar\n\"Message1_ptr\" = Message0_ptr\n\/\/\nin\n 0(*SUCCESS*)\nend \/\/ end of [then]\nelse ~(EBUSY) \/\/ end of [else]\n\/\/\nend \/\/ end of [device_open_]\n \n(* ****** ****** *)\n\nimplement\ndevice_release_\n (inx, filp) = let\n\/\/\nextvar\n\"Device_open_count\" = Device_open_count - 1\n\/\/\nin\n 0(*SUCCESS*)\nend \/\/ end of [device_release_]\n\n(* ****** ****** *)\n\n%{$\n\/\/\nstatic\ninline\nint\ndevice_open\n(\nstruct inode *p0, struct file *p1\n) { return device_open_(p0, p1) ; }\n\/\/\nstatic\ninline\nint\ndevice_release\n(\nstruct inode *p0, struct file *p1\n) { return device_release_(p0, p1) ; }\n\/\/\n%} \/\/ end of [%{$]\n\n(* ****** ****** *)\n\/\/\nstatic\nfun\ndevice_read_{n:int}\n(\n file_ptr1, buf: &ubytes(n), size_t(n), ofs: &loff_t\n) : ssize_t = \"mac#\" \/\/ end-of-function\nstatic\nfun\ndevice_write_{n:int}\n(\n file_ptr1, buf: &ubytes(n), size_t(n), ofs: &loff_t\n) : ssize_t = \"mac#\" \/\/ end-of-function\n\/\/\n(* ****** ****** *)\n\nimplement\ndevice_read_\n (filp, buf, n, ofs) = let\nin\n g0i2i(0)\nend \/\/ end of [device_read_]\n\n(* ****** ****** *)\n\nimplement\ndevice_write_\n (filp, buf, n, ofs) = let\n\/\/\nval () =\n$extfcall\n(\n void\n, \"printk\"\n, KERN_ALERT_\"Sorry, this operation isn't supported.\\n\"\n) (* end of [val] *)\n\/\/\nin\n $UN.cast{ssize_t}(~(EINVAL))\nend \/\/ end of [device_write_]\n\n(* ****** ****** *)\n\n%{$\n\/\/\nstatic\ninline\nssize_t\ndevice_read\n(\nstruct file *p0, char *buf, size_t n, loff_t *ofs\n) { return device_read_(p0, buf, n, ofs) ; }\n\/\/\nstatic\ninline\nssize_t\ndevice_write\n(\nstruct file *p0, const char *buf, size_t n, loff_t *ofs\n) { return device_write_(p0, (void*)buf, n, ofs) ; }\n\/\/\n%} \/\/ end of [%{$]\n\n(* ****** ****** *)\n\n(* end of [chardev-1.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"dddff799a874838726886f15ec5325e49e90d204","subject":"implement tcp_socket_connection_connect API","message":"implement tcp_socket_connection_connect API\n","repos":"fpiot\/mbed-ats,fpiot\/mbed-ats,fpiot\/mbed-ats,fpiot\/mbed-ats,fpiot\/mbed-ats,fpiot\/mbed-ats","old_file":"demos\/halapi_ats\/libmbedats\/DATS\/net_lwip_Socket_TCPSocketConnection.dats","new_file":"demos\/halapi_ats\/libmbedats\/DATS\/net_lwip_Socket_TCPSocketConnection.dats","new_contents":"#include \"share\/atspre_staload.hats\"\n\nstaload UN = \"prelude\/SATS\/unsafe.sats\"\nstaload \"libmbedats\/SATS\/net_lwip_Socket_Socket.sats\"\nstaload \"libmbedats\/SATS\/net_lwip_Socket_Endpoint.sats\"\nstaload \"libmbedats\/SATS\/net_lwip_Socket_TCPSocketConnection.sats\"\n\nvtypedef TCPSocketConnection_struct = @{\n is_connected= bool\n, sock= Socket\n, endpoint= Endpoint\n}\n\nabsvtype TCPSocketConnection_minus_struct (l:addr)\n\nextern castfn\nTCPSocketConnection_takeout_struct\n(\n tcp: !TCPSocketConnection >> TCPSocketConnection_minus_struct l\n) : #[l:addr] (TCPSocketConnection_struct @ l | ptr l)\n\nextern praxi\nTCPSocketConnection_addback_struct\n {l:addr}\n(\n pfat: TCPSocketConnection_struct @ l\n| tcp: !TCPSocketConnection_minus_struct l >> TCPSocketConnection\n) : void\n\nimplement\ntcp_socket_connection_open () = let\n val (pfgc, pfat | p) = ptr_alloc ()\n val () = p->is_connected := false\n val () = p->sock := socket_open ()\n val () = p->endpoint := endpoint_open ()\nin\n $UN.castvwtp0{TCPSocketConnection}((pfat, pfgc | p))\nend\n\nimplement\ntcp_socket_connection_connect (tcp, host, port) = let\n val (pfat | p) = TCPSocketConnection_takeout_struct (tcp)\n val rs = socket_initsock (p->sock, SOCK_STREAM)\n val ret = if rs = false then false else let\n val re = endpoint_set_address (p->endpoint, host, port)\n in\n if re = false then false else let\n abst@ype socklen_t = $extype\"socklen_t\"\n extern fun lwip_connect: (int, struct_sockaddr_in_p, socklen_t) -> int = \"mac#\"\n val fd = socket_sock_fd (p->sock)\n val rh = endpoint_remoteHost (p->endpoint)\n val rc = lwip_connect (fd, rh, $UN.cast (sizeof))\n in\n if rc < 0 then let\n val _ = socket_finisock (p->sock, true)\n in\n false\n end else let\n val () = p->is_connected := true\n in\n true\n end\n end\n end\n prval () = TCPSocketConnection_addback_struct(pfat | tcp)\nin\n ret\nend\n\nimplement\ntcp_socket_connection_close (tcp) = {\n val (pfat | p) = TCPSocketConnection_takeout_struct (tcp)\n val () = endpoint_close (p->endpoint)\n val () = socket_close (p->sock)\n val () = $UN.castvwtp0((pfat | p))\n val () = __free (tcp) where {\n extern fun __free {vt:vtype} (x: vt): void = \"atspre_mfree_gc\"\n }\n}\n","old_contents":"#include \"share\/atspre_staload.hats\"\n\nstaload UN = \"prelude\/SATS\/unsafe.sats\"\nstaload \"libmbedats\/SATS\/net_lwip_Socket_Socket.sats\"\nstaload \"libmbedats\/SATS\/net_lwip_Socket_Endpoint.sats\"\nstaload \"libmbedats\/SATS\/net_lwip_Socket_TCPSocketConnection.sats\"\n\nvtypedef TCPSocketConnection_struct = @{\n is_connected= bool\n, sock= Socket\n, endpoint= Endpoint\n}\n\nabsvtype TCPSocketConnection_minus_struct (l:addr)\n\nextern castfn\nTCPSocketConnection_takeout_struct\n(\n tcp: !TCPSocketConnection >> TCPSocketConnection_minus_struct l\n) : #[l:addr] (TCPSocketConnection_struct @ l | ptr l)\n\nextern praxi\nTCPSocketConnection_addback_struct\n {l:addr}\n(\n pfat: TCPSocketConnection_struct @ l\n| tcp: !TCPSocketConnection_minus_struct l >> TCPSocketConnection\n) : void\n\nimplement\ntcp_socket_connection_open () = let\n val (pfgc, pfat | p) = ptr_alloc ()\n val () = p->is_connected := false\n val () = p->sock := socket_open ()\n val () = p->endpoint := endpoint_open ()\nin\n $UN.castvwtp0{TCPSocketConnection}((pfat, pfgc | p))\nend\n\nimplement\ntcp_socket_connection_connect (tcp, host, port) = let\n val (pfat | p) = TCPSocketConnection_takeout_struct (tcp)\n val rs = socket_initsock (p->sock, SOCK_STREAM)\n val ret = if rs = false then false else let\n val re = endpoint_set_address (p->endpoint, host, port)\n in\n if re = false then false else let\n in\n true \/\/ xxx\n end\n end\n \/\/ xxx\n prval () = TCPSocketConnection_addback_struct(pfat | tcp)\nin\n ret\nend\n\nimplement\ntcp_socket_connection_close (tcp) = {\n val (pfat | p) = TCPSocketConnection_takeout_struct (tcp)\n val () = endpoint_close (p->endpoint)\n val () = socket_close (p->sock)\n val () = $UN.castvwtp0((pfat | p))\n val () = __free (tcp) where {\n extern fun __free {vt:vtype} (x: vt): void = \"atspre_mfree_gc\"\n }\n}\n","returncode":0,"stderr":"","license":"apache-2.0","lang":"ATS"} {"commit":"250b0d1bf9240995d1f302ae3f2f38e703ea7789","subject":"Updating: very minorly improving","message":"Updating: very minorly improving\n","repos":"bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib","old_file":"projects\/MEDIUM\/CATS-atsccomp\/CATS-atscc2erl\/TEST\/Sessiontype\/TEST2\/queue2.dats","new_file":"projects\/MEDIUM\/CATS-atsccomp\/CATS-atscc2erl\/TEST\/Sessiontype\/TEST2\/queue2.dats","new_contents":"(*\n** A queue of channels\n*)\n(* ****** ****** *)\n\n#define ATS_DYNLOADFLAG 0\n\n(* ****** ****** *)\n\/\/\n(*\n#define ATS_PACKNAME \"queue2\"\n*)\n\/\/\n#define ATS_EXTERN_PREFIX \"queue2_\"\n#define ATS_STATIC_PREFIX \"_queue2_\"\n\/\/\n(* ****** ****** *)\n\n%{^\n%%\n-module(queue2_dats).\n%%\n-export([main0_erl\/0]).\n%%\n-compile(nowarn_unused_vars).\n-compile(nowarn_unused_function).\n%%\n-export([ats2erlpre_cloref1_app\/2]).\n-export([libats2erl_session_chque_server\/0]).\n-export([libats2erl_session_chanpos_server\/2]).\n-export([libats2erl_session_channeg_server\/2]).\n%%\n-include(\".\/libatscc2erl\/libatscc2erl_all.hrl\").\n-include(\".\/libatscc2erl\/Sessiontype_mylibats2erl_all.hrl\").\n%%\n%} \/\/ end of [%{]\n\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_define.hats\"\n\/\/\n#include\n\"{$LIBATSCC2ERL}\/staloadall.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\nUN = \"prelude\/SATS\/unsafe.sats\"\n\/\/\n(* ****** ****** *)\n\nstaload \".\/..\/SATS\/basis.sats\"\nstaload \".\/..\/DATS\/basis_chan2.dats\"\n\n(* ****** ****** *)\n\/\/\n(*\n\/\/\ndatatype\nssque(a:t@ype, int) =\n | ssque_nil(a, 0) of ()\n | {n:pos}\n ssque_deq(a, n) of (snd(a), ssque(a,n-1))\n | {n:pos}\n ssque_top(a, n) of (snd(a), ssque(a,n-0))\n | {n:nat}\n ssque_enq(a, n) of (rcv(a), ssque(a,n+1))\n\/\/\n*)\nabstype ssque(a:t@ype, n:int)\n\/\/\n(* ****** ****** *)\n\/\/\ndatatype\nchanpos_ssque\n (a:t@ype, type, int) =\n | chanpos_ssque_nil(a, nil, 0) of ()\n | {n:pos}\n chanpos_ssque_deq(a,chsnd(a)::ssque(a,n-1),n) of ()\n | {n:pos}\n chanpos_ssque_top(a,chsnd(a)::ssque(a,n-0),n) of ()\n | {n:nat}\n chanpos_ssque_enq(a,chrcv(a)::ssque(a,n+1),n) of ()\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nchanpos_ssque\n {a:t@ype}{n:nat}\n (!chanpos(ssque(a,n)) >> chanpos(ss))\n: #[ss:type] chanpos_ssque(a, ss, n) = \"mac#%\"\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nchanneg_ssque_nil\n {a:t@ype}\n (!channeg(ssque(a,0)) >> channeg(nil)): void = \"mac#%\"\nextern\nfun\nchanneg_ssque_deq\n {a:t@ype}{n:pos}\n (!channeg(ssque(a,n)) >> channeg(chsnd(a)::ssque(a,n-1))): void = \"mac#%\"\nand\nchanneg_ssque_top\n {a:t@ype}{n:pos}\n (!channeg(ssque(a,n)) >> channeg(chsnd(a)::ssque(a,n-0))): void = \"mac#%\"\nand\nchanneg_ssque_enq\n {a:t@ype}{n:nat}\n (!channeg(ssque(a,n)) >> channeg(chrcv(a)::ssque(a,n+1))): void = \"mac#%\"\n\/\/\n(* ****** ****** *)\n \nimplement\nchanpos_ssque\n {a}{n}(chpos) = let\n\/\/\nval\nchpos2 = $UN.castvwtp1{chanpos2}(chpos)\nval tag = chanpos2_recv{natLt(4)}(chpos2)\n\/\/\nprval () = $UN.cast2void(chpos2)\n\/\/\nin\n\/\/\ncase+ tag of\n| 0 => let\n prval () = $UN.prop_assert{n==0}()\n prval () =\n $UN.castview2void(chpos) in chanpos_ssque_nil()\n end \/\/ end of [prval]\n| 1 => let\n prval () = $UN.prop_assert{n > 0}()\n prval () =\n $UN.castview2void(chpos) in chanpos_ssque_deq()\n end \/\/ end of [prval]\n| 2 => let\n prval () = $UN.prop_assert{n > 0}()\n prval () =\n $UN.castview2void(chpos) in chanpos_ssque_top()\n end \/\/ end of [prval]\n| 3 => let\n prval () =\n $UN.castview2void(chpos) in chanpos_ssque_enq()\n end \/\/ end of [prval]\n\/\/\nend \/\/ end of [chanpos_ssque]\n\/\/\n(* ****** ****** *)\n\nimplement\nchanneg_ssque_nil\n (chneg) = () where\n{\n\/\/\nval\nchneg2 =\n$UN.castvwtp1{channeg2}(chneg)\n\/\/\nval () =\n channeg2_recv{int}(chneg2, 0)\n\/\/\nprval () = $UN.cast2void(chneg2)\n\/\/\nprval () = $UN.castview2void(chneg)\n\/\/\n} (* end of [channeg_ssque_nil] *)\n\n(* ****** ****** *)\n\nimplement\nchanneg_ssque_deq\n (chneg) = () where\n{\n\/\/\nval\nchneg2 =\n$UN.castvwtp1{channeg2}(chneg)\n\/\/\nval () =\n channeg2_recv{int}(chneg2, 1)\n\/\/\nprval () = $UN.cast2void(chneg2)\n\/\/\nprval () = $UN.castview2void(chneg)\n\/\/\n} (* end of [channeg_ssque_deq] *)\n\n(* ****** ****** *)\n\nimplement\nchanneg_ssque_top\n (chneg) = () where\n{\n\/\/\nval\nchneg2 =\n$UN.castvwtp1{channeg2}(chneg)\n\/\/\nval () =\n channeg2_recv{int}(chneg2, 2)\n\/\/\nprval () = $UN.cast2void(chneg2)\n\/\/\nprval () = $UN.castview2void(chneg)\n\/\/\n} (* end of [channeg_ssque_top] *)\n\n(* ****** ****** *)\n\nimplement\nchanneg_ssque_enq\n (chneg) = () where\n{\n\/\/\nval\nchneg2 =\n$UN.castvwtp1{channeg2}(chneg)\n\/\/\nval () =\n channeg2_recv{int}(chneg2, 3)\n\/\/\nprval () = $UN.cast2void(chneg2)\n\/\/\nprval () = $UN.castview2void(chneg)\n\/\/\n} (* end of [channeg_ssque_enq] *)\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nqueue_nil{a:t0p}(): channeg(ssque(a, 0)) = \"mac#%\"\n\/\/\nextern\nfun\nqueue_free_nil{a:t0p}(channeg(ssque(a, 0))): void = \"mac#%\"\n\/\/\nextern\nfun\nqueue_deq\n {a:t0p}{n:pos}\n (que: !channeg(ssque(a,n)) >> channeg(ssque(a,n-1))): (a) = \"mac#%\"\n\/\/\nextern\nfun\nqueue_top\n {a:t0p}{n:pos}\n (que: !channeg(ssque(a,n)) >> channeg(ssque(a,n-0))): (a) = \"mac#%\"\n\/\/\nextern\nfun\nqueue_enq\n {a:t0p}{n:nat}\n (que: !channeg(ssque(a,n)) >> channeg(ssque(a,n+1)), x0: a): void = \"mac#%\"\n\/\/\n(* ****** ****** *)\n\nimplement\nqueue_nil\n {a}((*void*)) = let\n\/\/\nfun\nfserv\n(\n chp: chanpos(ssque(a,0))\n) : void = let\n\/\/\nval opt = chanpos_ssque(chp)\n\/\/\nin\n\/\/\ncase+ opt of\n| chanpos_ssque_nil() =>\n chanpos_nil_wait (chp)\n| chanpos_ssque_enq() => let\n val\n x_fst = chanpos_recv{a}(chp)\n in\n fserv2 (x_fst, queue_nil(), chp)\n end \/\/ end of [chanpos_ssque_enq]\n\/\/\nend \/\/ end of [fserv]\n\/\/\nand\nfserv2\n{n:nat}\n(\n x: a\n, chn: channeg(ssque(a,n))\n, chp: chanpos(ssque(a,n+1))\n) : void = let\n\/\/\nval opt = chanpos_ssque(chp)\n\/\/\nin\n\/\/\ncase+ opt of\n| chanpos_ssque_deq() => let\n val () = chanpos_send{a}(chp, x)\n in\n chanposneg_link (chp, chn)\n end \/\/ end of [chanpos_ssque_deq]\n| chanpos_ssque_top() => let\n val () = chanpos_send{a}(chp, x)\n in\n fserv2 (x, chn, chp)\n end \/\/ end of [chanpos_ssque_deq]\n| chanpos_ssque_enq() => let\n val y = chanpos_recv{a}(chp)\n val () = channeg_ssque_enq (chn)\n val () = channeg_recv{a}(chn, y)\n in\n fserv2 (x, chn, chp)\n end \/\/ end of [chanpos_ssque_enq]\n\/\/\nend \/\/ end of [fserv2]\n\/\/\nin\n channeg_create(llam (chp) => fserv (chp))\nend \/\/ end of [queue_nil]\n\n(* ****** ****** *)\n\nimplement\nqueue_free_nil\n {a}(chn) = () where\n{\n\/\/\nval () = channeg_ssque_nil(chn)\nval () = channeg_nil_close(chn)\n\/\/\n} (* end of [queue_free_nil] *)\n\n(* ****** ****** *)\n\nimplement\nqueue_deq\n {a}(chn) =\n(\n channeg_ssque_deq(chn); channeg_send{a}(chn)\n) (* end of [queue_deq] *)\n\n(* ****** ****** *)\n\nimplement\nqueue_top\n {a}(chn) =\n(\n channeg_ssque_top(chn); channeg_send{a}(chn)\n) (* end of [queue_top] *)\n\n(* ****** ****** *)\n\nimplement\nqueue_enq\n {a}(chn, x0) =\n(\n channeg_ssque_enq(chn); channeg_recv{a}(chn, x0)\n) (* end of [queue_enq] *)\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nqueue_map_cloref\n {a:t0p}{b:t0p}{n:nat}\n(\n que: channeg(ssque(a,n)), n: int(n), f: (a) - b\n) : channeg(ssque(b,n)) \/\/ end-of-function\n\/\/\n(* ****** ****** *)\n\nimplement\nqueue_map_cloref\n {a}{b}{n}(que, n, f) = let\n\/\/\nfun\nloop{i,j:nat}\n(\n que: channeg(ssque(a, i))\n, i: int(i), res: channeg(ssque(b, j))\n) : channeg(ssque(b, i+j)) =\n(\n\/\/\nif\ni > 0\nthen let\n val x = queue_deq(que)\n val () = queue_enq(res, f(x))\nin\n loop(que, i-1, res)\nend \/\/ end of [then]\nelse let\n val () = queue_free_nil(que) in res\nend \/\/ end of [else]\n\/\/\n) (* end of [loop] *)\n\/\/\nin\n loop(que, n, queue_nil())\nend \/\/ end of [queue_map_cloref]\n\n(* ****** ****** *)\n\nextern \nfun\nmain0_erl\n(\n\/\/ argumentless\n) : void = \"mac#\"\n\/\/\nimplement\nmain0_erl((*void*)) =\n{\n\/\/\n#define N 100\n\/\/\nval Q0 = queue_nil{int}()\n\/\/\nval () = queue_enq (Q0, 0)\nval () = queue_enq (Q0, 1)\nval () = queue_enq (Q0, 2)\n\/\/\nval x0 = queue_top (Q0)\nval () = println! (\"x0(0) = \", x0)\nval x0 = queue_deq (Q0)\nval () = println! (\"x0(0) = \", x0)\nval x1 = queue_deq (Q0)\nval () = println! (\"x1(1) = \", x1)\n\/\/\nval () = queue_enq (Q0, 3)\nval () = queue_enq (Q0, 4)\n\/\/\nval x2 = queue_top (Q0)\nval () = println! (\"x2(2) = \", x2)\nval x2 = queue_deq (Q0)\nval () = println! (\"x2(2) = \", x2)\nval x3 = queue_deq (Q0)\nval () = println! (\"x3(3) = \", x3)\n\/\/\nval () = queue_enq (Q0, 5)\nval () = queue_enq (Q0, 6)\nval () = queue_enq (Q0, 7)\n\/\/\nval x4 = queue_top (Q0)\nval () = println! (\"x4(4) = \", x4)\nval x4 = queue_deq (Q0)\nval () = println! (\"x4(4) = \", x4)\nval x5 = queue_top (Q0)\nval () = println! (\"x5(5) = \", x5)\nval x5 = queue_deq (Q0)\nval () = println! (\"x5(5) = \", x5)\nval x6 = queue_deq (Q0)\nval () = println! (\"x7(6) = \", x6)\n\/\/\nval () = queue_enq (Q0, 8)\nval Q1 = queue_map_cloref{int}{int}(Q0, 2, lam(x) => 2 * x)\n\/\/\nval x7 = queue_top (Q1)\nval () = println! (\"x7(7) = \", x7)\nval x7 = queue_deq (Q1)\nval () = println! (\"x7(7) = \", x7)\nval x8 = queue_deq (Q1)\nval () = println! (\"x8(8) = \", x8)\n\/\/\nval ((*freed*)) = queue_free_nil{int}(Q1)\n\/\/\n} (* end of [main0] *)\n\n(* ****** ****** *)\n\n(* end of [queue2.dats] *)\n","old_contents":"(*\n** A queue of channels\n*)\n(* ****** ****** *)\n\n#define ATS_DYNLOADFLAG 0\n\n(* ****** ****** *)\n\/\/\n(*\n#define ATS_PACKNAME \"queue2\"\n*)\n\/\/\n#define ATS_EXTERN_PREFIX \"queue2_\"\n#define ATS_STATIC_PREFIX \"_queue2_\"\n\/\/\n(* ****** ****** *)\n\n%{^\n%%\n-module(queue2_dats).\n%%\n-export([main0_erl\/0]).\n%%\n-compile(nowarn_unused_vars).\n-compile(nowarn_unused_function).\n%%\n-export([ats2erlpre_cloref1_app\/2]).\n-export([libats2erl_session_chque_server\/0]).\n-export([libats2erl_session_chanpos_server\/2]).\n-export([libats2erl_session_channeg_server\/2]).\n%%\n-include(\".\/libatscc2erl\/libatscc2erl_all.hrl\").\n-include(\".\/libatscc2erl\/Sessiontype_mylibats2erl_all.hrl\").\n%%\n%} \/\/ end of [%{]\n\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_define.hats\"\n\/\/\n#include\n\"{$LIBATSCC2ERL}\/staloadall.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\nUN = \"prelude\/SATS\/unsafe.sats\"\n\/\/\n(* ****** ****** *)\n\nstaload \".\/..\/SATS\/basis.sats\"\nstaload \".\/..\/DATS\/basis_chan2.dats\"\n\n(* ****** ****** *)\n\/\/\n(*\n\/\/\ndatatype\nssque(a:t@ype, int) =\n | ssque_nil(a, 0) of ()\n | {n:pos}\n ssque_deq(a, n) of (snd(a), ssque(a,n-1))\n | {n:pos}\n ssque_top(a, n) of (snd(a), ssque(a,n-0))\n | {n:nat}\n ssque_enq(a, n) of (rcv(a), ssque(a,n+1))\n\/\/\n*)\nabstype ssque(a:t@ype, n:int)\n\/\/\n(* ****** ****** *)\n\/\/\ndatatype\nchanpos_ssque\n (a:t@ype, type, int) =\n | chanpos_ssque_nil(a, nil, 0) of ()\n | {n:pos}\n chanpos_ssque_deq(a,chsnd(a)::ssque(a,n-1),n) of ()\n | {n:pos}\n chanpos_ssque_top(a,chsnd(a)::ssque(a,n-0),n) of ()\n | {n:nat}\n chanpos_ssque_enq(a,chrcv(a)::ssque(a,n+1),n) of ()\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nchanpos_ssque\n {a:t@ype}{n:nat}\n (!chanpos(ssque(a,n)) >> chanpos(ss))\n: #[ss:type] chanpos_ssque(a, ss, n) = \"mac#%\"\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nchanneg_ssque_nil\n {a:t@ype}\n (!channeg(ssque(a,0)) >> channeg(nil)): void = \"mac#%\"\nextern\nfun\nchanneg_ssque_deq\n {a:t@ype}{n:pos}\n (!channeg(ssque(a,n)) >> channeg(chsnd(a)::ssque(a,n-1))): void = \"mac#%\"\nand\nchanneg_ssque_top\n {a:t@ype}{n:pos}\n (!channeg(ssque(a,n)) >> channeg(chsnd(a)::ssque(a,n-0))): void = \"mac#%\"\nand\nchanneg_ssque_enq\n {a:t@ype}{n:nat}\n (!channeg(ssque(a,n)) >> channeg(chrcv(a)::ssque(a,n+1))): void = \"mac#%\"\n\/\/\n(* ****** ****** *)\n \nimplement\nchanpos_ssque\n {a}{n}(chpos) = let\n\/\/\nval\nchpos2 = $UN.castvwtp1{chanpos2}(chpos)\nval tag = chanpos2_recv{natLt(4)}(chpos2)\n\/\/\nprval () = $UN.cast2void(chpos2)\n\/\/\nin\n\/\/\ncase+ tag of\n| 0 => let\n prval () = $UN.prop_assert{n==0}()\n prval () =\n $UN.castview2void(chpos) in chanpos_ssque_nil()\n end \/\/ end of [prval]\n| 1 => let\n prval () = $UN.prop_assert{n > 0}()\n prval () =\n $UN.castview2void(chpos) in chanpos_ssque_deq()\n end \/\/ end of [prval]\n| 2 => let\n prval () = $UN.prop_assert{n > 0}()\n prval () =\n $UN.castview2void(chpos) in chanpos_ssque_top()\n end \/\/ end of [prval]\n| 3 => let\n prval () =\n $UN.castview2void(chpos) in chanpos_ssque_enq()\n end \/\/ end of [prval]\n\/\/\nend \/\/ end of [chanpos_ssque]\n\/\/\n(* ****** ****** *)\n\nimplement\nchanneg_ssque_nil\n (chneg) = () where\n{\n\/\/\nval\nchneg2 =\n$UN.castvwtp1{channeg2}(chneg)\n\/\/\nval () =\n channeg2_recv{int}(chneg2, 0)\n\/\/\nprval () = $UN.cast2void(chneg2)\n\/\/\nprval () = $UN.castview2void(chneg)\n\/\/\n} (* end of [channeg_ssque_nil] *)\n\n(* ****** ****** *)\n\nimplement\nchanneg_ssque_deq\n (chneg) = () where\n{\n\/\/\nval\nchneg2 =\n$UN.castvwtp1{channeg2}(chneg)\n\/\/\nval () =\n channeg2_recv{int}(chneg2, 1)\n\/\/\nprval () = $UN.cast2void(chneg2)\n\/\/\nprval () = $UN.castview2void(chneg)\n\/\/\n} (* end of [channeg_ssque_deq] *)\n\n(* ****** ****** *)\n\nimplement\nchanneg_ssque_top\n (chneg) = () where\n{\n\/\/\nval\nchneg2 =\n$UN.castvwtp1{channeg2}(chneg)\n\/\/\nval () =\n channeg2_recv{int}(chneg2, 2)\n\/\/\nprval () = $UN.cast2void(chneg2)\n\/\/\nprval () = $UN.castview2void(chneg)\n\/\/\n} (* end of [channeg_ssque_top] *)\n\n(* ****** ****** *)\n\nimplement\nchanneg_ssque_enq\n (chneg) = () where\n{\n\/\/\nval\nchneg2 =\n$UN.castvwtp1{channeg2}(chneg)\n\/\/\nval () =\n channeg2_recv{int}(chneg2, 3)\n\/\/\nprval () = $UN.cast2void(chneg2)\n\/\/\nprval () = $UN.castview2void(chneg)\n\/\/\n} (* end of [channeg_ssque_enq] *)\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nqueue_nil{a:t0p}(): channeg(ssque(a, 0)) = \"mac#%\"\n\/\/\nextern\nfun\nqueue_free_nil{a:t0p}(channeg(ssque(a, 0))): void = \"mac#%\"\n\/\/\nextern\nfun\nqueue_deq\n {a:t0p}{n:pos}\n (que: !channeg(ssque(a,n)) >> channeg(ssque(a,n-1))): (a) = \"mac#%\"\n\/\/\nextern\nfun\nqueue_top\n {a:t0p}{n:pos}\n (que: !channeg(ssque(a,n)) >> channeg(ssque(a,n-0))): (a) = \"mac#%\"\n\/\/\nextern\nfun\nqueue_enq\n {a:t0p}{n:nat}\n (que: !channeg(ssque(a,n)) >> channeg(ssque(a,n+1)), x0: a): void = \"mac#%\"\n\/\/\n(* ****** ****** *)\n\nimplement\nqueue_nil\n {a}((*void*)) = let\n\/\/\nfun\nfserv\n(\n chp: chanpos(ssque(a,0))\n) : void = let\n\/\/\nval opt = chanpos_ssque(chp)\n\/\/\nin\n\/\/\ncase+ opt of\n| chanpos_ssque_nil() =>\n chanpos_nil_wait (chp)\n| chanpos_ssque_enq() => let\n val\n x_fst = chanpos_recv{a}(chp)\n in\n fserv2 (x_fst, queue_nil(), chp)\n end \/\/ end of [chanpos_ssque_enq]\n\/\/\nend \/\/ end of [fserv]\n\/\/\nand\nfserv2\n{n:nat}\n(\n x: a\n, chn: channeg(ssque(a,n))\n, chp: chanpos(ssque(a,n+1))\n) : void = let\n\/\/\nval opt = chanpos_ssque(chp)\n\/\/\nin\n\/\/\ncase+ opt of\n| chanpos_ssque_deq() => let\n val () = chanpos_send{a}(chp, x)\n in\n chanposneg_link (chp, chn)\n end \/\/ end of [chanpos_ssque_deq]\n| chanpos_ssque_top() => let\n val () = chanpos_send{a}(chp, x)\n in\n fserv2 (x, chn, chp)\n end \/\/ end of [chanpos_ssque_deq]\n| chanpos_ssque_enq() => let\n val y = chanpos_recv{a}(chp)\n val () = channeg_ssque_enq (chn)\n val () = channeg_recv{a}(chn, y)\n in\n fserv2 (x, chn, chp)\n end \/\/ end of [chanpos_ssque_enq]\n\/\/\nend \/\/ end of [fserv2]\n\/\/\nin\n channeg_create(llam (chp) => fserv (chp))\nend \/\/ end of [queue_nil]\n\n(* ****** ****** *)\n\nimplement\nqueue_free_nil\n {a}(chn) = () where\n{\n\/\/\nval () = channeg_ssque_nil(chn)\nval () = channeg_nil_close(chn)\n\/\/\n} (* end of [queue_free_nil] *)\n\n(* ****** ****** *)\n\nimplement\nqueue_deq\n {a}(chn) =\n(\n channeg_ssque_deq(chn); channeg_send{a}(chn)\n) (* end of [queue_deq] *)\n\n(* ****** ****** *)\n\nimplement\nqueue_top\n {a}(chn) =\n(\n channeg_ssque_top(chn); channeg_send{a}(chn)\n) (* end of [queue_top] *)\n\n(* ****** ****** *)\n\nimplement\nqueue_enq\n {a}(chn, x0) =\n(\n channeg_ssque_enq(chn); channeg_recv{a}(chn, x0)\n) (* end of [queue_enq] *)\n\n(* ****** ****** *)\n\nextern \nfun\nmain0_erl\n(\n\/\/ argumentless\n) : void = \"mac#\"\n\/\/\nimplement\nmain0_erl((*void*)) =\n{\n\/\/\n#define N 100\n\/\/\nval Q0 = queue_nil{int}()\n\/\/\nval () = queue_enq (Q0, 0)\nval () = queue_enq (Q0, 1)\nval () = queue_enq (Q0, 2)\n\/\/\nval x0 = queue_top (Q0)\nval () = println! (\"x0(0) = \", x0)\nval x0 = queue_deq (Q0)\nval () = println! (\"x0(0) = \", x0)\nval x1 = queue_deq (Q0)\nval () = println! (\"x1(1) = \", x1)\n\/\/\nval () = queue_enq (Q0, 3)\nval () = queue_enq (Q0, 4)\n\/\/\nval x2 = queue_top (Q0)\nval () = println! (\"x2(2) = \", x2)\nval x2 = queue_deq (Q0)\nval () = println! (\"x2(2) = \", x2)\nval x3 = queue_deq (Q0)\nval () = println! (\"x3(3) = \", x3)\n\/\/\nval () = queue_enq (Q0, 5)\nval () = queue_enq (Q0, 6)\nval () = queue_enq (Q0, 7)\n\/\/\nval x4 = queue_top (Q0)\nval () = println! (\"x4(4) = \", x4)\nval x4 = queue_deq (Q0)\nval () = println! (\"x4(4) = \", x4)\nval x5 = queue_top (Q0)\nval () = println! (\"x5(5) = \", x5)\nval x5 = queue_deq (Q0)\nval () = println! (\"x5(5) = \", x5)\nval x6 = queue_deq (Q0)\nval () = println! (\"x7(6) = \", x6)\n\/\/\nval () = queue_enq (Q0, 8)\n\/\/\nval x7 = queue_top (Q0)\nval () = println! (\"x7(7) = \", x7)\nval x7 = queue_deq (Q0)\nval () = println! (\"x7(7) = \", x7)\nval x8 = queue_deq (Q0)\nval () = println! (\"x8(8) = \", x8)\n\/\/\nval ((*freed*)) = queue_free_nil{int}(Q0)\n\/\/\n} (* end of [main0] *)\n\n(* ****** ****** *)\n\n(* end of [queue2.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"5bc2566eec588a9e4ef16fc2cfca3b2a43539d0f","subject":"link to template file in arithmetic","message":"link to template file in arithmetic\n","repos":"raventid\/coursera_learning,raventid\/coursera_learning,raventid\/coursera_learning,raventid\/coursera_learning,raventid\/coursera_learning,raventid\/coursera_learning,raventid\/coursera_learning,raventid\/coursera_learning,raventid\/coursera_learning,raventid\/coursera_learning","old_file":"ats\/introduction_to_programming_in_ats\/simple_arithmetic.dats","new_file":"ats\/introduction_to_programming_in_ats\/simple_arithmetic.dats","new_contents":"\/\/ This is a standard function-pack\n\/\/ strongly recommend to include it everywhere\n\/\/ to avoid very long-time debug sessions.\n\n\/\/ in `template.dats` file in this `dir` you can also find\n\/\/ another template it is as much usefull as the oriiginal one\n\n#include \"share\/atspre_staload.hats\"\n\n\nval _ = println! (\"(1+2)\/(3+4) = \", (1+2)\/(3+4))\n\nval _ = println! (\"-1 = \", x) where {\n val x = ~1\n}\n\nval _ = (\n println! (\"0.123 = \", 0.123);\n println! (\"0.000314 = \", 314E-6);\n)\n\nval _ = (\n println! (\"float is \", x, \" and double is \", y);\n) where {\n val x = 2.0f; \/\/ float\n val y = 2.0; \/\/ double\n}\n\nval+ 3 = op+(1,2)\n\nimplement main0 () = ()","old_contents":"\/\/ This is a standard function-pack\n\/\/ strongly recommend to include it everywhere\n\/\/ to avoid very long-time debug sessions.\n\n#include \"share\/atspre_staload.hats\"\n\n\nval _ = println! (\"(1+2)\/(3+4) = \", (1+2)\/(3+4))\n\nval _ = println! (\"-1 = \", x) where {\n val x = ~1\n}\n\nval _ = (\n println! (\"0.123 = \", 0.123);\n println! (\"0.000314 = \", 314E-6);\n)\n\nval _ = (\n println! (\"float is \", x, \" and double is \", y);\n) where {\n val x = 2.0f; \/\/ float\n val y = 2.0; \/\/ double\n}\n\nval+ 3 = op+(1,2)\n\nimplement main0 () = ()","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"5b214d95bb9408c409c6c1116460b41589c1410a","subject":"Updating: experimenting with multi-party sessions","message":"Updating: experimenting with multi-party sessions\n","repos":"bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib","old_file":"projects\/MEDIUM\/CATS-atsccomp\/CATS-atscc2erl\/TEST\/Sessiontype\/TEST\/multi-party.dats","new_file":"projects\/MEDIUM\/CATS-atsccomp\/CATS-atscc2erl\/TEST\/Sessiontype\/TEST\/multi-party.dats","new_contents":"(* ****** ****** *)\n\/\/\n\/\/ HX-2015-07-11:\n\/\/ let the multi-party begin!\n\/\/\n(* ****** ****** *)\n\nstaload \"libats\/SATS\/ilist_prf.sats\"\n\n(* ****** ****** *)\n\n(*\nBob -> Alice: ::\nBob -> Alice: {\n Time: Alice -> Bob: (uch, x0)\n\/\/\nval ((*returned*)) = $UN.cast2void(uch)\n\/\/\n} (* end of [channel0_send] *)\n\n(* ****** ****** *)\n\nimplement\n{a}(*tmp*)\nchannel0_recv\n (chan0, i, j, x0) = let\n\/\/\nval+CHANNEL0(n, G, chmat) = chan0\n\/\/\nval p0 = ptrcast(chmat)\n\/\/\nval p_ij =\n ptr_add(p0, i*n+j)\n\/\/\nval (pf, fpf | p_ij) =\n $UN.ptr_vtake{uchan(a)}(p_ij)\n\/\/\nval () = (x0 := uchan_remove (!p_ij))\n\/\/\nprval ((*returned*)) = fpf(pf)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [channel0_recv]\n\n(* ****** ****** *)\n\nimplement\n{a}(*tmp*)\nchannel0_recv_val\n (chan0, i, j) = x0 where\n{\n\/\/\nvar x0: a \/\/ uninitized\n\/\/\nval () = channel0_recv(chan0, i, j, x0)\n\/\/\n} (* end of [channel0_recv_val] *)\n\n(* ****** ****** *)\n\n(* end of [basic_channel0.dats] *)\n","old_contents":"(*\n** Channel pairs\n*)\n\n(* ****** ****** *)\n\/\/\nstaload\n\".\/..\/SATS\/basis.sats\"\nstaload\n\".\/..\/SATS\/intset.sats\"\n\/\/\nstaload \".\/basis_uchan.dats\"\n\/\/\n(* ****** ****** *)\n\/\/\nabsvtype\nchannel0_vtype(a:vt@ype, n:int)\n\/\/\nstadef channel0 = channel0_vtype\n\/\/\nextern\npraxi\nlemma_channel0_param\n {a:vt0p}{n:int}(!channel0(a, n)): [n >= 0] void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\n{a:vt0p}\nchannel0_make_pair\n {n:nat}\n(\n n: int(n), capacity: intGt(0)\n) : (channel0(a, n), channel0(a, n))\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\n{a:vt0p}\nchannel0_free\n {n:int}(chan0: channel0(a, n)): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun{a:vt0p}\nchannel0_send\n {n:int}\n(\n !channel0(a, n)\n, i: natLt(n), j: natLt(n), x: a\n) : void \/\/ end-of-function\n\/\/\nextern\nfun{a:vt0p}\nchannel0_recv\n {n:int}\n(\n !channel0(a, n)\n, i: natLt(n), j: natLt(n), x: &a? >> a\n) : void \/\/ end-of-function\nextern\nfun{a:vt0p}\nchannel0_recv_val\n {n:int}\n(\n !channel0(a, n), i: natLt(n), j: natLt(n)\n) : (a) \/\/ end of [channel0_recv_val]\n\/\/\n(* ****** ****** *)\n\/\/\ndatavtype\nchannel0_\n(\n a:vt@ype, n:int\n) =\nCHANNEL0 of\n(\n int(n), intset(n), matrixptr(uchan(a), n, n)\n) (* end of [channel0_] *)\n\/\/\n(* ****** ****** *)\n\/\/\nassume\nchannel0_vtype\n (a:vt0p, n:int) = channel0_(a, n)\n\/\/\n(* ****** ****** *)\n\nimplement\n{a}(*tmp*)\nchannel0_free\n (chan0) = let\n\/\/\nval () =\nlemma_channel0_param(chan0)\n\/\/\nval\n~CHANNEL0(n, G, chmat) = chan0\n\/\/\nimplement\n(elt:vtype)\nmatrix_uninitize$clear\n (i, j, x) = let\n\/\/\nval x = $UN.castvwtp0{ptr}(x)\n\/\/\nin\n\/\/\nif\nisneqz(x)\nthen (\n uchan_unref($UN.castvwtp0{uchan(a)}(x))\n) (* end of [if] *)\n\/\/\nend \/\/ end of [matrix_uninitize$clear]\n\/\/\nval n = i2sz(n)\n\/\/\nval () = matrixptr_freelin(chmat, n, n)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [channel0_free]\n\n(* ****** ****** *)\n\nimplement\n{a}(*tmp*)\nchannel0_send\n (chan0, i, j, x0) =\n{\n\/\/\nval+CHANNEL0(n, G, chmat) = chan0\n\/\/\nval p0 = ptrcast(chmat)\n\/\/\nval uch =\n $UN.ptr0_get_at(p0, i*n+j)\n\/\/\nval ((*void*)) = uchan_insert (uch, x0)\n\/\/\nval ((*returned*)) = $UN.cast2void(uch)\n\/\/\n} (* end of [channel0_send] *)\n\n(* ****** ****** *)\n\nimplement\n{a}(*tmp*)\nchannel0_recv\n (chan0, i, j, x0) = let\n\/\/\nval+CHANNEL0(n, G, chmat) = chan0\n\/\/\nval p0 = ptrcast(chmat)\n\/\/\nval p_ij =\n ptr_add(p0, i*n+j)\n\/\/\nval (pf, fpf | p_ij) =\n $UN.ptr_vtake{uchan(a)}(p_ij)\n\/\/\nval () = (x0 := uchan_remove (!p_ij))\n\/\/\nprval ((*returned*)) = fpf(pf)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [channel0_recv]\n\n(* ****** ****** *)\n\nimplement\n{a}(*tmp*)\nchannel0_recv_val\n (chan0, i, j) = x0 where\n{\n\/\/\nvar x0: a \/\/ uninitized\n\/\/\nval () = channel0_recv(chan0, i, j, x0)\n\/\/\n} (* end of [channel0_recv_val] *)\n\n(* ****** ****** *)\n\n(* end of [basic_channel0.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"9025f88fa3170d3f34d7e4c7450a31065618f557","subject":"Updating: very minorly improving","message":"Updating: very minorly improving\n","repos":"ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib","old_file":"projects\/MEDIUM\/M-Check\/SCRATCH\/ClientServer-1.dats","new_file":"projects\/MEDIUM\/M-Check\/SCRATCH\/ClientServer-1.dats","new_contents":"(* ****** ****** *)\n\/\/\n\/\/ Author: Hongwei Xi\n\/\/ Authoremail: gmhwxiATgmailDOTcom\n\/\/ Start time: February, 2016\n\/\/\n(* ****** ****** *)\n\/\/\n\/\/ Following a Promela-example in\n\/\/ (Spin Model Checker Primer Reference)\n\/\/\n(* ****** ****** *)\n \n(*\nproctype\nAgent(chan listen; chan talk)\n{\n do\n :: talk!hold(listen)\n :: talk!deny(listen) -> break\n :: talk!grant(listen) ->\n wait:\n listen?return0; break\n od;\n server!return0(listen)\n}\n*)\n \n(* ****** ****** *)\n\nabstype channel\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nchannel_recv{a:type}(channel): a\nextern\nfun\nchannel_send{a:type}(channel, a): void\n\/\/\nextern\nfun\nchannel_create(cap: intGte(0)): channel\n\/\/\n(* ****** ****** *)\n\nextern\nfun\nchannel_is_empty : channel -> bool\nextern\nfun\nchannel_isnot_empty : channel -> bool\n\n(* ****** ****** *)\n\/\/\ndatatype\nAgentReply =\n| DENY of ()\n| DENY of (channel)\n| HOLD of (channel)\n| GRANT of (channel)\n\/\/\ndatatype\nClientReply = RETURN0 of ()\n\/\/\ndatatype\nServerOpt =\n | RETURN0 of (channel)\n | REQUEST0 of (channel)\n\/\/\n(* ****** ****** *)\n\/\/\nval\ntheServer = channel_create(0)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nAgent\n(\n agent: channel, client: channel\n) : void \/\/ end of [Agent]\n\/\/\n(* ****** ****** *)\n\nextern val RAND: int\n\n(* ****** ****** *)\n\/\/\nimplement\nAgent(agent, client) = let\n\/\/\nfun\nloop\n( agent: channel\n, client: channel\n) : void = (\n\/\/\ncase RAND of\n| 0 => let\n val () =\n channel_send(client, HOLD(agent))\n in\n loop(agent, client)\n end \/\/ end of [_]\n| 1 =>\n channel_send(client, DENY(agent))\n| _ => let\n val () =\n channel_send(client, GRANT(agent))\n val-RETURN0() =\n channel_recv{ClientReply}(agent)\n \/\/ end of [val]\n in\n \/\/ break\n end \/\/ end of [_]\n\/\/\n) (* end of [loop] *)\n\/\/\nval () = loop(agent, client)\n\/\/\nin\n channel_send(theServer, agent)\nend \/\/ end of [Agent]\n\/\/\n(* ****** ****** *)\n\n(*\n#define M 2\nactive [M] proctype Client()\n{\n chan me = [0] of { mtype, chan };\n chan agent;\nend:\n do\n :: timeout ->\n server!request(me);\n do\n :: me?hold(agent)\n :: me?deny(agent) -> break\n :: me?grant(agent) -> agent!return0; break\n od\n od\n}\n*) \n\n(* ****** ****** *)\n\/\/\nextern\nfun Client(): void\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nClient() = let\n\/\/\nfun\nloop\n(\n client: channel\n) : void =\n(\n\/\/\ncase+ RAND of\n| _ => let\n val () =\n channel_send(theServer, REQUEST0(client))\n in\n loop2(client)\n end \/\/ end of [loop]\n\/\/\n) (* end of [loop] *)\n\/\/\nand\nloop2\n(\n client: channel\n) : void = let\n val opt = channel_recv{AgentReply}(client)\nin\n\/\/\ncase+ opt of\n| DENY() => ()\n| DENY(agent) => ()\n| HOLD(agent) => loop2(client)\n| GRANT(agent) => channel_send(agent, RETURN0())\n\/\/\nend \/\/ end of [loop2]\n\/\/\nin\n loop(channel_create(0))\nend \/\/ end of [Client]\n\n(* ****** ****** *)\n\n(*\nactive\nproctype Server()\n{\n chan agents[N] = [0] of { mtype };\n chan pool = [N] of { chan };\n chan client, agent;\n byte i;\n do\n :: i < N -> pool!agents[i]; i++\n :: else -> break\n od;\n end:\n do\n :: server?request(client) ->\n if\n :: empty(pool) ->\n client!deny(0)\n :: nempty(pool) ->\n pool?agent;\n run Agent(agent,client)\n fi\n :: server?return0(agent) ->\n pool!agent\n od\n}\n*)\n\n(* ****** ****** *)\n\/\/\nextern\nfun Server((*void*)): void\n\/\/\nimplement\nServer() = let\n\/\/\nfun\nloop\n(\n pool: channel\n) : void = let\n\/\/\nval\nopt =\nchannel_recv{ServerOpt}(theServer)\n\/\/\nin\n\/\/\ncase+ opt of\n| RETURN0(agent) => let\n val () =\n channel_send{channel}(pool, agent)\n in\n loop(pool)\n end \/\/ end of [RETURN0]\n| REQUEST0(client) =>\n if channel_isnot_empty(pool)\n then let\n val agent =\n channel_recv{channel}(pool)\n \/\/ end of [val]\n val () = Agent(agent, client)\n in\n loop(pool)\n end \/\/ end of [then]\n else let\n val () =\n channel_send(client, DENY((*void*)))\n in\n loop(pool)\n end \/\/ end of [else]\n\/\/ \nend \/\/ end of [loop]\n\/\/\nval\npool = channel_create(5)\n\/\/\nin\n loop(pool)\nend \/\/ end of [Server]\n\/\/\n(* ****** ****** *)\n\n(* end of [ClientServer-1.dats] *)\n","old_contents":"(* ****** ****** *)\n\/\/\n\/\/ Author: Hongwei Xi\n\/\/ Authoremail: gmhwxiATgmailDOTcom\n\/\/ Start time: February, 2016\n\/\/\n(* ****** ****** *)\n \n(*\nproctype\nAgent(chan listen; chan talk)\n{\n do\n :: talk!hold(listen)\n :: talk!deny(listen) -> break\n :: talk!grant(listen) ->\n wait:\n listen?return0; break\n od;\n server!return0(listen)\n}\n*)\n \n(* ****** ****** *)\n\nabstype channel\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nchannel_recv{a:type}(channel): a\nextern\nfun\nchannel_send{a:type}(channel, a): void\n\/\/\nextern\nfun\nchannel_create(cap: intGte(0)): channel\n\/\/\n(* ****** ****** *)\n\/\/\ndatatype\nAgentReply =\n| DENY of (channel)\n| HOLD of (channel)\n| GRANT of (channel)\n\/\/\ndatatype ClientReply = RETURN0 of ()\ndatatype ClientRequest = REQUEST0 of (channel)\n\/\/\n(* ****** ****** *)\n\/\/\nval\ntheServer = channel_create(0)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nAgent\n(\n agent: channel, client: channel\n) : void \/\/ end of [Agent]\n\/\/\n(* ****** ****** *)\n\nextern val RAND: int\n\n(* ****** ****** *)\n\/\/\nimplement\nAgent(agent, client) = (\n\/\/\ncase RAND of\n| 0 => let\n val () =\n channel_send(client, HOLD(agent))\n in\n Agent(agent, client)\n end \/\/ end of [_]\n| 1 =>\n channel_send(client, DENY(agent))\n| _ => let\n val () =\n channel_send(client, GRANT(agent))\n val-RETURN0() =\n channel_recv{ClientReply}(agent)\n \/\/ end of [val]\n in\n \/\/ break\n end \/\/ end of [_]\n\/\/\n) (* end of [Agent] *)\n\/\/\n(* ****** ****** *)\n\n(*\n#define M 2\nactive [M] proctype Client()\n{\n chan me = [0] of { mtype, chan };\n chan agent;\nend:\n do\n :: timeout ->\n server!request(me);\n do\n :: me?hold(agent)\n :: me?deny(agent) -> break\n :: me?grant(agent) -> agent!return0; break\n od\n od\n}\n*) \n\n(* ****** ****** *)\n\/\/\nextern\nfun Client(): void\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nClient() = let\n\/\/\nfun\nloop\n(\n client: channel\n) : void =\n(\n\/\/\ncase+ RAND of\n| _ => let\n val () =\n channel_send(theServer, REQUEST0(client))\n in\n loop2(client)\n end \/\/ end of [loop]\n\/\/\n) (* end of [loop] *)\n\/\/\nand\nloop2\n(\n client: channel\n) : void = let\n val opt = channel_recv{AgentReply}(client)\nin\n\/\/\ncase+ opt of\n| DENY(agent) => ()\n| HOLD(agent) => loop2(client)\n| GRANT(agent) => channel_send(agent, RETURN0())\n\/\/\nend \/\/ end of [loop2]\n\/\/\nin\n loop(channel_create(0))\nend \/\/ end of [Client]\n\n(* ****** ****** *)\n\n(* end of [ClientServer-1.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"3c319df37a150c80d9a99ec575cf5d7408c76cfd","subject":"Updating: very minorly improving","message":"Updating: very minorly improving\n","repos":"githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib","old_file":"projects\/MEDIUM\/M-Check\/SCRATCH\/ClientServer-2.dats","new_file":"projects\/MEDIUM\/M-Check\/SCRATCH\/ClientServer-2.dats","new_contents":"(* ****** ****** *)\n\/\/\n\/\/ Author: Hongwei Xi\n\/\/ Authoremail: gmhwxiATgmailDOTcom\n\/\/ Start time: February, 2016\n\/\/\n(* ****** ****** *)\n\/\/\n\/\/ Following a Promela-example in\n\/\/ (Spin Model Checker Primer Reference)\n\/\/\n(* ****** ****** *)\n\n(*\nproctype\nAgent(chan listen; chan talk)\n{\n do\n :: talk!hold(listen)\n :: talk!deny(listen) -> break\n :: talk!grant(listen) ->\n wait:\n listen?return0; break\n od;\n server!return0(listen)\n}\n*)\n\n(* ****** ****** *)\n\nabstype chnil\nabstype chcons(x:vt@ype, xs:type)\n\n(* ****** ****** *)\n\nstadef :: = chcons\n\n(* ****** ****** *)\n\nabstype chanref(a:vtype)\n\n(* ****** ****** *)\n\/\/\nabsvtype channel0\n\/\/\nabsvtype chanpos1(ss:vtype)\nabsvtype channeg1(ss:vtype)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nchannel0_create\n (cap: intGte(0)): channel0\n\/\/\nextern\nfun channel0_destroy(channel0): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nchannel0_split{ss:vtype}\n (chan: !channel0 >> chanpos1(ss)): channeg1(ss)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nprfun\nchanneg1_nil_close (channeg1(chnil)): void\nextern\nprfun\nchanpos1_nil_close (!chanpos1(chnil) >> channel0): void\n\/\/\n(* ****** ****** *)\n\nextern\nfun\nchanpos1_recv\n{x:vt@ype}{xs:type}\n(\n chan: !chanpos1(x::xs) >> chanpos1(xs)\n) : x \/\/ end of [chanpos1_recv]\n\n(* ****** ****** *)\n\nextern\nfun\nchanneg1_send\n{x:vt@ype}{xs:type}\n(\n chan: !channeg1(x::xs) >> channeg1(xs), x: (x)\n) : void \/\/ end of [channeg1_send]\n\n(* ****** ****** *)\n\ndatavtype\nss_client =\n | DENY of (chnil)\n | DENY of (channeg1(chnil), chnil)\n | HOLD of (channeg1(chnil), ss_client)\n | GRANT of (channeg1(ss_grant), chnil)\n\/\/\nand ss_grant = RETURN1 of (chnil)\n\/\/\n(* ****** ****** *)\n\/\/\ndatavtype\nClientOpt(ss:vtype) =\n | DENY(chnil) of ()\n | DENY(chnil) of channeg1(chnil)\n | HOLD(ss_client) of channeg1(chnil)\n | GRANT(chnil) of (channeg1(ss_grant))\n\/\/\ndatatype\nAgentGrantOpt(ss:vtype) = RETURN1(chnil) of ()\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nchanref_recv\n {a:vtype}(chan: chanref(a)): (a)\nextern\nfun\nchanref_send\n {a:vtype}(chan: chanref(a), x: (a)): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nchanneg1_client{ss:vtype}\n (chan: !channeg1(ss_client) >> channeg1(ss), x: ClientOpt(ss)): void\nextern\nfun\nchanpos1_client\n (chan: !chanpos1(ss_client) >> chanpos1(ss)): #[ss:vtype] ClientOpt(ss)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nchanneg1_grant{ss:vtype}\n (chan: !channeg1(ss_grant) >> channeg1(ss), x: AgentGrantOpt(ss)): void\nextern\nfun\nchanpos1_grant\n (chan: !chanpos1(ss_grant) >> chanpos1(ss)): #[ss:vtype] AgentGrantOpt(ss)\n\/\/\n(* ****** ****** *)\n\nextern val RANDOM : int\n\n(* ****** ****** *)\n\/\/\ndatavtype\nServerOpt =\n | RETURN0 of (channel0)\n | REQUEST0 of (channeg1(ss_client))\n\/\/\n(* ****** ****** *)\n\nextern\nval\ntheServer : chanref(ServerOpt)\n\n(* ****** ****** *)\n\/\/\nextern\nfun Server((*void*)): void\nextern\nfun Client((*void*)): void\n\/\/\nextern\nfun\nAgent\n(\n agent: channel0\n, client: channeg1(ss_client)\n) : void \/\/ end of [Agent]\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nchanref_create\n {a:vtype}\n (cap: intGte(0)): chanref(a)\n\/\/\nextern\nfun\nchanref_is_empty\n : {a:vtype} chanref(a) -> bool\nextern\nfun\nchanref_isnot_empty\n : {a:vtype} chanref(a) -> bool\n\/\/\n(* ****** ****** *)\n\nimplement\nServer() = let\n\/\/\nfun\nloop\n(\n pool: chanref(channel0)\n) : void = let\n\/\/\nval\nopt = chanref_recv(theServer)\n\/\/\nin\n\/\/\ncase+ opt of\n| ~RETURN0(agent) => let\n val () =\n chanref_send(pool, agent)\n in\n loop(pool)\n end \/\/ end of [RETURN0]\n| ~REQUEST0(client) =>\n if chanref_isnot_empty(pool)\n then let\n val agent =\n chanref_recv(pool)\n \/\/ end of [val]\n val () = Agent(agent, client)\n in\n loop(pool)\n end \/\/ end of [then]\n else let\n val () =\n channeg1_client(client, DENY())\n val () = channeg1_nil_close(client)\n in\n loop(pool)\n end \/\/ end of [else]\n\/\/ \nend \/\/ end of [loop]\n\/\/\nval\npool = chanref_create(5)\n\/\/\nin\n loop(pool)\nend \/\/ end of [Server]\n\/\/\n(* ****** ****** *)\n\nimplement\nAgent(agent, client) = let\n\/\/\nfun\nloop\n( agent: !channel0\n, client: channeg1(ss_client)\n) : void = (\n\/\/\ncase\nRANDOM of\n| 0 => let\n val\n agent2 =\n channel0_split{chnil}(agent)\n val () =\n channeg1_client(client, HOLD(agent2))\n val ((*void*)) = chanpos1_nil_close(agent)\n in\n loop(agent, client)\n end \/\/ end of [_]\n| 1 => let\n val\n agent2 =\n channel0_split{chnil}(agent)\n val () =\n channeg1_client(client, DENY(agent2))\n val ((*void*)) = chanpos1_nil_close(agent)\n val ((*void*)) = channeg1_nil_close(client)\n in\n \/\/ break\n end \/\/ end of [1]\n| _ => let\n val\n agent2 =\n channel0_split{ss_grant}(agent)\n val () =\n channeg1_client(client, GRANT(agent2))\n val+RETURN1() = chanpos1_grant(agent)\n val ((*void*)) = chanpos1_nil_close(agent)\n val ((*void*)) = channeg1_nil_close(client)\n in\n \/\/ break\n end \/\/ end of [_]\n\/\/\n) (* end of [loop] *)\n\/\/\nval () = loop(agent, client)\n\/\/\nin\n chanref_send(theServer, RETURN0(agent))\nend \/\/ end of [Agent]\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nClient() = let\n\/\/\nfun\nloop\n(\n client: channel0\n) : void =\n(\n\/\/\ncase+\nRANDOM\nof \/\/ case\n| _ => let\n val\n client2 =\n channel0_split{ss_client}(client)\n val () =\n chanref_send(theServer, REQUEST0(client2))\n in\n loop2(client)\n end \/\/ end of [loop]\n\/\/\n) (* end of [loop] *)\n\/\/\nand\nloop2\n(\n client: chanpos1(ss_client)\n) : void = let\n\/\/\nval opt = chanpos1_client(client)\n\/\/\nin\n\/\/\ncase+ opt of\n| ~DENY() =>\n {\n val () =\n chanpos1_nil_close(client)\n val () = channel0_destroy(client)\n }\n| ~DENY(agent) =>\n {\n val () =\n channeg1_nil_close(agent)\n val () =\n chanpos1_nil_close(client)\n val () = channel0_destroy(client)\n }\n| ~HOLD(agent) =>\n loop2(client) where\n {\n val () = channeg1_nil_close(agent)\n }\n\/\/\n| ~GRANT(agent) =>\n {\n val () =\n channeg1_grant(agent, RETURN1())\n val () = channeg1_nil_close(agent)\n val () = chanpos1_nil_close(client)\n val () = channel0_destroy(client)\n }\n\/\/\nend \/\/ end of [loop2]\n\/\/\nin\n loop(channel0_create(0))\nend \/\/ end of [Client]\n\n(* ****** ****** *)\n\n(* end of [ClientServer-2.dats] *)\n","old_contents":"(* ****** ****** *)\n\/\/\n\/\/ Author: Hongwei Xi\n\/\/ Authoremail: gmhwxiATgmailDOTcom\n\/\/ Start time: February, 2016\n\/\/\n(* ****** ****** *)\n\/\/\n\/\/ Following a Promela-example in\n\/\/ (Spin Model Checker Primer Reference)\n\/\/\n(* ****** ****** *)\n\n(*\nproctype\nAgent(chan listen; chan talk)\n{\n do\n :: talk!hold(listen)\n :: talk!deny(listen) -> break\n :: talk!grant(listen) ->\n wait:\n listen?return0; break\n od;\n server!return0(listen)\n}\n*)\n\n(* ****** ****** *)\n\nabstype chnil\nabstype chcons(x:vt@ype, xs:type)\n\n(* ****** ****** *)\n\nstadef :: = chcons\n\n(* ****** ****** *)\n\nabstype chanref(a:vtype)\n\n(* ****** ****** *)\n\/\/\nabsvtype channel0\n\/\/\nabsvtype chanpos1(ss:vtype)\nabsvtype channeg1(ss:vtype)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nchannel0_split{ss:vtype}\n (chan: !channel0 >> chanpos1(ss)): channeg1(ss)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nchanneg1_nil_close (channeg1(chnil)): void\nextern\nfun\nchanpos1_nil_close (!chanpos1(chnil) >> channel0): void\n\/\/\n(* ****** ****** *)\n\nextern\nfun\nchanpos1_recv\n{x:vt@ype}{xs:type}\n(\n chan: !chanpos1(x::xs) >> chanpos1(xs)\n) : x \/\/ end of [chanpos1_recv]\n\n(* ****** ****** *)\n\nextern\nfun\nchanneg1_send\n{x:vt@ype}{xs:type}\n(\n chan: !channeg1(x::xs) >> channeg1(xs), x: (x)\n) : void \/\/ end of [channeg1_send]\n\n(* ****** ****** *)\n\ndatavtype\nss_client =\n | DENY of (chnil)\n | DENY of (channeg1(chnil), chnil)\n | HOLD of (channeg1(chnil), ss_client)\n | GRANT of (channeg1(ss_grant), chnil)\n\/\/\nand ss_grant = RETURN1 of (chnil)\n\/\/\n(* ****** ****** *)\n\/\/\ndatavtype\nClientOpt(ss:vtype) =\n | DENY(chnil) of ()\n | DENY(chnil) of channeg1(chnil)\n | HOLD(ss_client) of channeg1(chnil)\n | GRANT(chnil) of (channeg1(ss_grant))\n\/\/\ndatatype\nAgentGrantOpt(ss:vtype) = RETURN1(chnil) of ()\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nchanref_recv\n {a:vtype}(chan: chanref(a)): (a)\nextern\nfun\nchanref_send\n {a:vtype}(chan: chanref(a), x: (a)): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nchanneg1_client{ss:vtype}\n (chan: !channeg1(ss_client) >> channeg1(ss), x: ClientOpt(ss)): void\nextern\nfun\nchanpos1_client\n (chan: !chanpos1(ss_client) >> chanpos1(ss)): #[ss:vtype] ClientOpt(ss)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nchanneg1_grant{ss:vtype}\n (chan: !channeg1(ss_grant) >> channeg1(ss), x: AgentGrantOpt(ss)): void\nextern\nfun\nchanpos1_grant\n (chan: !chanpos1(ss_grant) >> chanpos1(ss)): #[ss:vtype] AgentGrantOpt(ss)\n\/\/\n(* ****** ****** *)\n\nextern val RANDOM : int\n\n(* ****** ****** *)\n\/\/\ndatavtype\nServerOpt =\n | RETURN0 of (channel0)\n | REQUEST of (channeg1(ss_client))\n\/\/\n(* ****** ****** *)\n\nextern val theServer : chanref(ServerOpt)\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nAgent\n(\n agent: channel0\n, client: channeg1(ss_client)\n) : void \/\/ end of [Agent]\n\/\/\n(* ****** ****** *)\n\nimplement\nAgent(agent, client) = let\n\/\/\nfun\nloop\n( agent: !channel0\n, client: channeg1(ss_client)\n) : void = (\n\/\/\ncase\nRANDOM of\n| 0 => let\n val\n agent2 =\n channel0_split{chnil}(agent)\n val () =\n channeg1_client(client, HOLD(agent2))\n val ((*void*)) = chanpos1_nil_close(agent)\n in\n loop(agent, client)\n end \/\/ end of [_]\n| 1 => let\n val\n agent2 =\n channel0_split{chnil}(agent)\n val () =\n channeg1_client(client, DENY(agent2))\n val ((*void*)) = chanpos1_nil_close(agent)\n val ((*void*)) = channeg1_nil_close(client)\n in\n \/\/ break\n end \/\/ end of [1]\n| _ => let\n val\n agent2 =\n channel0_split{ss_grant}(agent)\n val () =\n channeg1_client(client, GRANT(agent2))\n val+RETURN1() = chanpos1_grant(agent)\n val ((*void*)) = chanpos1_nil_close(agent)\n val ((*void*)) = channeg1_nil_close(client)\n in\n \/\/ break\n end \/\/ end of [_]\n\/\/\n) (* end of [loop] *)\n\/\/\nval () = loop(agent, client)\n\/\/\nin\n chanref_send(theServer, RETURN0(agent))\nend \/\/ end of [Agent]\n\/\/\n(* ****** ****** *)\n\n(* end of [ClientServer-2.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"813953dc4061a7bc18bc52bf487a2d34a84e7a39","subject":"Updating: fixing a typo","message":"Updating: fixing a typo\n","repos":"steinwaywhw\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,steinwaywhw\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,steinwaywhw\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,steinwaywhw\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,steinwaywhw\/ATS-Postiats-contrib,steinwaywhw\/ATS-Postiats-contrib","old_file":"contrib\/libats-\/hwxi\/libev\/TEST\/test00-pkgreloc.dats","new_file":"contrib\/libats-\/hwxi\/libev\/TEST\/test00-pkgreloc.dats","new_contents":"\/\/\n\/\/ Some code for testing\n\/\/ the API in ATS for libev\n\/\/\n(* ****** ****** *)\n\/\/\n#define\nPATSCONTRIB \"\\\nhttps:\/\/raw.githubusercontent.com\/\\\ngithwxi\/ATS-Postiats-contrib\/master\/contrib\"\n\/\/\n(*\n\/\/\n\/\/ HX-2014-05-14: this is a backup:\n\/\/\n#define\nPATSCONTRIB \"http:\/\/www.ats-lang.org\/LIBRARY\/contrib\"\n*)\n\/\/\n(* ****** ****** *)\n\/\/\nrequire \"{$PATSCONTRIB}\/libats-\/hwxi\/libev\/SATS\/ev.sats\"\nrequire \"{$PATSCONTRIB}\/libats-\/hwxi\/libev\/DATS\/ev.dats\"\nrequire \"{$PATSCONTRIB}\/libats-\/hwxi\/libev\/CATS\/ev.cats\"\n\/\/\n(* ****** ****** *)\n\nstaload \"{$PATSCONTRIB}\/libats-\/hwxi\/libev\/SATS\/ev.sats\"\n\n(* ****** ****** *)\n\nval () =\n{\n\/\/\nval major = ev_version_major ()\nval minor = ev_version_minor ()\n\/\/\nval () = println! (\"ev_version_major() = \", major)\nval () = println! (\"ev_version_minor() = \", minor)\n\/\/\n} (* end of [val] *)\n\n(* ****** ****** *)\n\nimplement main0 () = ()\n\n(* ****** ****** *)\n\n(* end of [test00-pkgreloc.dats] *)\n","old_contents":"\/\/\n\/\/ Some code for testing\n\/\/ the API in ATS for libev\n\/\/\n(* ****** ****** *)\n\/\/\n#define\nPATSCONTRIB \"\\\nhttps:\/\/raw.githubusercontent.com\/\\\ngithwxi\/ATS-Postiats-contrib\/master\/contrib\"\n\/\/\n(*\n\/\/\n\/\/ HX-2014-05-14: this is a backup:\n\/\/\n#define\nPATSCONTRIB \"http:\/\/www.ats-lang.org\/LIBRARY\/contrib\"\n*)\n\/\/\n(* ****** ****** *)\n\/\/\nrequire \"{$PATSCONTRIB}\/libats-\/hwxi\/libev\/SATS\/ev.sats\"\nrequire \"{$PATSCONTRIB}\/libats-\/hwxi\/libev\/DATS\/ev.dats\"\nrequire \"{$PATSCONTRIB}\/libats-\/hwxi\/libev\/CATS\/ev.cats\"\n\/\/\n(* ****** ****** *)\n\nstaload \"{$PATSCONTRIB}\/libats-\/hwxi\/libev\/SATS\/ev.sats\"\n\n(* ****** ****** *)\n\nval () =\n{\n\/\/\nval major = ev_version_major ()\nval minor = ev_version_minor ()\n\/\/\nval () = println! (\"ev_version_major() = \", major)\nval () = println! (\"ev_version_minor() = \", minor)\n\/\/\n} (* end of [val] *)\n\n(* ****** ****** *)\n\nimplement main0 () = ()\n\n(* ****** ****** *)\n\n(* end of [test00.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"aaf39aa56c35e98099e464b032f1e622412c7cb6","subject":"Updating: adding aruduino\/LCDemoMatrix","message":"Updating: adding aruduino\/LCDemoMatrix\n","repos":"ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib","old_file":"contrib\/arduino\/SATS\/LedControl\/TEST\/LCDemoMatrix.dats","new_file":"contrib\/arduino\/SATS\/LedControl\/TEST\/LCDemoMatrix.dats","new_contents":"(*\n#\n# For testing LedControl\n#\n*)\n(* ****** ****** *)\n\n#define ATS_DYNLOADFLAG 0\n\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_define.hats\"\n#include\n\"{$ARDUINO}\/staloadall.hats\"\n\/\/\n(* ****** ****** *)\n\nstaload \".\/..\/LedControl.sats\"\n\n(* ****** ****** *)\n\n%{^\nLedControl theLC;\n%} \/\/ end of [%{^]\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nsetup (): void = \"mac#\"\n\/\/\nimplement\nsetup () =\n{\n\/\/\nextvar\n\"theLC\" =\nLedControl(12,11,10,1)\n\/\/\nval lc =\n$extval\n (LedControl_ptr, \"theLC\")\n\/\/\nval () = lc.shutdown(0, false)\nval () = lc.setIntensity(0, 8)\nval () = lc.clearDisplay( 0 )\n}\n\/\/\n(* ****** ****** *)\n\/\/\nmacdef DELAY_TIME = 100UL\n\/\/\nmacdef\nB00000000 = $extval(byte, \"0\")\nmacdef\nB10100000 = $extval(byte, \"B10100000\")\n\/\/\n(* ****** ****** *)\n\n(*\nvoid rows() {\n for(int row=0;row<8;row++) {\n delay(delaytime);\n lc.setRow(0,row,B10100000);\n delay(delaytime);\n lc.setRow(0,row,(byte)0);\n for(int i=0;i\n (row, col, env) =\n(\n doWork(row, col); loop_doWork(row, col, 0)\n)\n\/\/\nin\n intrange2_foreach(0, 8, 0, 8)\nend \/\/ end of [loop_single]\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nloop(): void = \"mac#\"\nimplement\nloop() =\n{\n val lc = $extval(LedControl_ptr, \"theLC\")\n val () = $extfcall(void, \"writeArduinoOnMatrix\", lc)\n val () = loop_rows(lc)\n val () = loop_cols(lc)\n val () = loop_single(lc)\n} (* end of [loop] *)\n\/\/\n(* ****** ****** *)\n\n(* end of [LCDemoMatrix.dats] *)\n","old_contents":"(*\n#\n# For testing LedControl\n#\n*)\n(* ****** ****** *)\n\n#define ATS_DYNLOADFLAG 0\n\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_define.hats\"\n#include\n\"{$ARDUINO}\/staloadall.hats\"\n\/\/\n(* ****** ****** *)\n\nstaload \".\/..\/LedControl.sats\"\n\n(* ****** ****** *)\n\n%{^\nLedControl theLC;\n%} \/\/ end of [%{^]\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nsetup (): void = \"mac#\"\n\/\/\nimplement\nsetup () =\n{\n\/\/\nextvar\n\"theLC\" =\nLedControl(12,11,10,1)\n\/\/\nval lc =\n$extval\n (LedControl_ptr, \"theLC\")\n\/\/\nval () = lc.shutdown(0, false)\nval () = lc.setIntensity(0, 8)\nval () = lc.clearDisplay( 0 )\n}\n\/\/\n(* ****** ****** *)\n\/\/\nmacdef DELAY_TIME = 100UL\n\/\/\nmacdef\nB00000000 = $extval(byte, \"0\")\nmacdef\nB10100000 = $extval(byte, \"B10100000\")\n\/\/\n(* ****** ****** *)\n\n(*\nvoid rows() {\n for(int row=0;row<8;row++) {\n delay(delaytime);\n lc.setRow(0,row,B10100000);\n delay(delaytime);\n lc.setRow(0,row,(byte)0);\n for(int i=0;i let\n prval() =\n chanpos_array_nil(chp)\n in\n chanpos_nil_wait (chp)\n end \/\/ end of [nil]\n| list_cons (x, xs) => let\n prval() =\n chanpos_array_cons(chp)\n val () = chanpos_send{a}(chp, x)\n in\n fserv(chp, xs)\n end \/\/ end of [cons]\n) (* end of [fserv] *)\n\/\/\nin\n channeg_create(llam(chp) => fserv(chp, xs))\nend \/\/ end of [list2ssarray]\n\n(* ****** ****** *)\n\nimplement\nlist2ssarray_vt\n {a}(xs) = let\n\/\/\nfun\nfserv{n:int}\n(\n chp: chanpos(ssarray(a, n)), xs: list_vt(a, n)\n) : void =\n(\ncase+ xs of\n| ~nil_vt () => let\n prval() =\n chanpos_array_nil(chp)\n in\n chanpos_nil_wait (chp)\n end \/\/ end of [nil]\n| ~cons_vt (x, xs) => let\n prval() =\n chanpos_array_cons(chp)\n val () = chanpos_send{a}(chp, x)\n in\n fserv(chp, xs)\n end \/\/ end of [cons]\n) (* end of [fserv] *)\n\/\/\nin\n channeg_create(llam(chp) => fserv(chp, xs))\nend \/\/ end of [list2ssarray_vt]\n\n(* ****** ****** *)\n\nimplement\nssarray2list_vt\n {a}{n}(chn, n) = xs where\n{\n\/\/\nprval\n() = $UN.prop_assert{n >= 0}()\n\/\/\nval xs =\nchanneg_array_takeout_list{a}(chn, n)\n\/\/\nprval() = channeg_array_nil (chn)\nval ((*closed*)) = channeg_nil_close (chn)\n\/\/\n} (* end of [ssarray2list_vt] *)\n\n(* ****** ****** *)\n\nimplement\nchanneg_array_takeout_list\n {a}{n}{i}(chn, i) = let\n\/\/\nvtypedef\nchan(n:int) = channeg(ssarray(a, n))\n\/\/\nfun\nrevapp\n{i,j:nat}\n(\n xs: list_vt(a, i)\n, ys: list_vt(a, j)\n) : list_vt(a, i+j) =\n(\ncase+ xs of\n| ~nil_vt() => ys\n| ~cons_vt(x, xs) =>\n revapp(xs, list_vt_cons{a}(x, ys))\n \/\/ end of [cons_vt]\n) (* end of [revapp] *)\n\/\/\nfun\nloop\n{n:int}\n{i,j:nat | i <= n}\n(\n chn:\n !chan(n) >> chan(n-i)\n, i: int(i), res: list_vt(a, j)\n) : list_vt(a, i+j) = (\n\/\/\nif\ni > 0\nthen let\n\/\/\nprval() =\n channeg_array_cons(chn)\n\/\/\nval x0 = channeg_send{a}(chn)\n\/\/\nin\n\/\/\nloop(chn, i-1, list_vt_cons{a}(x0, res))\n\/\/\nend \/\/ end of [then]\nelse res \/\/ end of [else]\n\/\/\n) (* end of [loop] *)\n\/\/\nin\n revapp(loop(chn, i, list_vt_nil), list_vt_nil)\nend \/\/ end of [channeg_array_takeout_list]\n\n(* ****** ****** *)\n\n(* end of [ssarray.dats] *)\n","old_contents":"(*\n** Session Array\n*)\n\n(* ****** ****** *)\n\/\/\n#define ATS_DYNLOADFLAG 0\n\/\/\n(* ****** ****** *)\n\/\/\n#define\nATS_EXTERN_PREFIX \"libats2erl_session_\"\n#define\nATS_STATIC_PREFIX \"_libats2erl_session_ssarray_\"\n\/\/\n(* ****** ****** *)\n\/\/\n#include \"share\/atspre_define.hats\"\n#include \"{$LIBATSCC2ERL}\/staloadall.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\nUN =\n\"prelude\/SATS\/unsafe.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/..\/SATS\/basis.sats\"\nstaload \".\/..\/SATS\/ssarray.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\n\".\/basis_chan0.dats\" \/\/ un-typed channels\n\/\/\n(* ****** ****** *)\n\nimplement\nchanpos_arrsz\n {a}{n}(chp, n) = let\n\/\/\ntypedef\nss = chsnd(int)::ssarray(a,n)\nprval() =\n $UN.castview2void{chanpos(ss)}(chp)\n\/\/\nin\n chanpos_send{int}(chp, n)\nend \/\/ end of [chanpos_arrsz]\n\n(* ****** ****** *)\n\nimplement\nchanneg_arrsz\n {a}(chn) = asz where\n{\n\/\/\nprval\n[n:int](_) = g1ofg0(0)\n\/\/\ntypedef\nss = chsnd(int)::ssarray(a,n)\nprval() =\n $UN.castview2void{channeg(ss)}(chn)\n\/\/\nval\nasz = channeg_send{int}(chn)\n\/\/\nval\n[n:int]\nasz = $UN.cast{intGte(0)}(asz)\n\/\/\nprval() =\n $UN.castview2void{channeg(ssarray(a,n))}(chn)\n\/\/\n} (* end of [channeg_arrsz] *)\n\n(* ****** ****** *)\n\/\/\nimplement\nssarray2list\n {a}(chn, n) =\n list_vt2t(ssarray2list_vt(chn, n))\n\/\/\n(* ****** ****** *)\n\nimplement\nlist2ssarray\n {a}(xs) = let\n\/\/\nfun\nfserv{n:int}\n(\n chp: chanpos(ssarray(a, n)), xs: list(a, n)\n) : void =\n(\ncase+ xs of\n| list_nil () => let\n prval() =\n chanpos_array_nil(chp)\n in\n chanpos_nil_wait (chp)\n end \/\/ end of [nil]\n| list_cons (x, xs) => let\n prval() =\n chanpos_array_cons(chp)\n val () = chanpos_send{a}(chp, x)\n in\n fserv(chp, xs)\n end \/\/ end of [cons]\n) (* end of [fserv] *)\n\/\/\nin\n channeg_create(llam(chp) => fserv(chp, xs))\nend \/\/ end of [list2ssarray]\n\n(* ****** ****** *)\n\nimplement\nlist2ssarray_vt\n {a}(xs) = let\n\/\/\nfun\nfserv{n:int}\n(\n chp: chanpos(ssarray(a, n)), xs: list_vt(a, n)\n) : void =\n(\ncase+ xs of\n| ~nil_vt () => let\n prval() =\n chanpos_array_nil(chp)\n in\n chanpos_nil_wait (chp)\n end \/\/ end of [nil]\n| ~cons_vt (x, xs) => let\n prval() =\n chanpos_array_cons(chp)\n val () = chanpos_send{a}(chp, x)\n in\n fserv(chp, xs)\n end \/\/ end of [cons]\n) (* end of [fserv] *)\n\/\/\nin\n channeg_create(llam(chp) => fserv(chp, xs))\nend \/\/ end of [list2ssarray_vt]\n\n(* ****** ****** *)\n\nimplement\nssarray2list_vt\n {a}{n}(chn, n) = xs where\n{\n\/\/\nprval\n() = $UN.prop_assert{n >= 0}()\n\/\/\nval xs =\nchanneg_array_takeout_list{a}(chn, n)\n\/\/\nprval() = channeg_array_nil (chn)\nval ((*closed*)) = channeg_nil_close (chn)\n\/\/\n} (* end of [ssarray2list_vt] *)\n\n(* ****** ****** *)\n\nimplement\nchanneg_array_takeout_list\n {a}{n}{i}(chn, i) = let\n\/\/\nvtypedef\nchan(n:int) = channeg(ssarray(a, n))\n\/\/\nfun\nrevapp\n{i,j:nat}\n(\n xs: list_vt(a, i)\n, ys: list_vt(a, j)\n) : list_vt(a, i+j) =\n(\ncase+ xs of\n| ~nil_vt() => ys\n| ~cons_vt(x, xs) =>\n revapp(xs, list_vt_cons{a}(x, ys))\n \/\/ end of [cons_vt]\n) (* end of [revapp] *)\n\/\/\nfun\nloop\n{n:int}\n{i,j:nat | i <= n}\n(\n chn:\n !chan(n) >> chan(n-i)\n, i: int(i), res: list_vt(a, j)\n) : list_vt(a, i+j) = (\n\/\/\nif\ni > 0\nthen let\n\/\/\nprval() =\n channeg_array_cons(chn)\n\/\/\nval x0 = channeg_send{a}(chn)\n\/\/\nin\n\/\/\nloop(chn, i-1, list_vt_cons{a}(x0, res))\n\/\/\nend \/\/ end of [then]\nelse res \/\/ end of [else]\n\/\/\n) (* end of [loop] *)\n\/\/\nin\n revapp(loop(chn, i, list_vt_nil), list_vt_nil)\nend \/\/ end of [channeg_array_takeout_list]\n\n(* ****** ****** *)\n\n(* end of [ssarray.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"1692e5e7c938d1d8006dbfd944ef8cf92635d464","subject":"Updating: very minorly improving","message":"Updating: very minorly improving\n","repos":"bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib","old_file":"contrib\/libats-\/hwxi\/teaching\/mysession-g\/TEST\/test03-4p.dats","new_file":"contrib\/libats-\/hwxi\/teaching\/mysession-g\/TEST\/test03-4p.dats","new_contents":"(*\n**\n** For testing g-sessions\n**\n** This example involves 4 parties,\n** passing 4 messages in a ring-like\n** fashion.\n**\n** Author: Hongwei Xi\n** Authoremail: gmhwxiATgmailDOTcom\n** Start time: the 8th of March, 2016\n**\n*)\n\n(* ****** ****** *)\n\n%{^\n\/\/\n#include \n\/\/\n%} \/\/ end of [%{^]\n\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_staload.hats\"\n\/\/\n(* ****** ****** *)\n\nstaload UN = $UNSAFE\n\n(* ****** ****** *)\n\nstaload\nUNISTD = \"libc\/SATS\/unistd.sats\"\n\n(* ****** ****** *)\n\nstaload\n\".\/..\/SATS\/basis_intset.sats\"\nstaload _ =\n\".\/..\/DATS\/basis_intset.dats\"\n\n(* ****** ****** *)\n\/\/\nstaload\n\".\/..\/SATS\/basis_ssntype.sats\"\nstaload\n\".\/..\/SATS\/basis_ssntype2r.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload _ =\n\"libats\/DATS\/deqarray.dats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload _ =\n\"libats\/DATS\/athread.dats\"\nstaload _ =\n\"libats\/DATS\/athread_posix.dats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload _ =\n\".\/..\/DATS\/basis_uchan.dats\"\nstaload _ =\n\".\/..\/DATS\/basis_channel0.dats\"\nstaload _ =\n\".\/..\/DATS\/basis_channel1.dats\"\nstaload _ =\n\".\/..\/DATS\/basis_ssntype2r.dats\"\n\/\/\n(* ****** ****** *)\n\n#define N 4\n\n(* ****** ****** *)\n\/\/\ntypedef\nssn_ring4 =\nmsg(0, 1, string) ::\nmsg(1, 2, string) ::\nmsg(2, 3, string) ::\nmsg(3, 0, string) :: nil\n\/\/\n(* ****** ****** *)\n\/\/\nstadef S0 = iset(0)\nstadef S1 = iset(1)\nstadef S2 = iset(2)\nstadef S3 = iset(3)\n\/\/\nstadef S02 = iset(0,2)\nstadef S13 = iset(1,3)\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nfserv_client0\n(\n chan:\n channel1(S0, N, ssn_ring4)\n) : void =\n{\n\/\/\nprval() =\nlemma_iset_sing_is_member{0}()\nprval() =\nlemma_iset_sing_isnot_member{0,1}()\nprval() =\nlemma_iset_sing_isnot_member{0,2}()\nprval() =\nlemma_iset_sing_isnot_member{0,3}()\n\/\/\nval () =\nchannel1_send\n (chan, 0, 1, \"msg(0, 1)\")\n\/\/\nval () = channel1_skipex(chan)\nval () = channel1_skipex(chan)\n\/\/\nval\nmsg = channel1_recv_val(chan, 3, 0)\nval () = println! (\"client0: msg = \", msg)\n\/\/\nval () = channel1_close(chan)\n\/\/\n} (* end of [fserv_client0] *)\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nfserv_client1\n(\n chan:\n channel1(S1, N, ssn_ring4)\n) : void =\n{\n\/\/\nprval() =\nlemma_iset_sing_is_member{1}()\nprval() =\nlemma_iset_sing_isnot_member{1,0}()\nprval() =\nlemma_iset_sing_isnot_member{1,2}()\nprval() =\nlemma_iset_sing_isnot_member{1,3}()\n\/\/\nval\nmsg =\nchannel1_recv_val(chan, 0, 1)\nval () =\nprintln! (\"client1: msg = \", msg)\n\/\/\nval () =\nchannel1_send(chan, 1, 2, \"msg(1, 2)\")\n\/\/\nval () = channel1_skipex(chan)\nval () = channel1_skipex(chan)\n\/\/\nval () = channel1_close(chan)\n\/\/\n} (* end of [fserv_client1] *)\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nfserv_client2\n(\n chan:\n channel1(S2, N, ssn_ring4)\n) : void =\n{\n\/\/\nprval() =\nlemma_iset_sing_is_member{2}()\nprval() =\nlemma_iset_sing_isnot_member{2,0}()\nprval() =\nlemma_iset_sing_isnot_member{2,1}()\nprval() =\nlemma_iset_sing_isnot_member{2,3}()\n\/\/\nval () =\n channel1_skipex(chan)\n\/\/\nval\nmsg =\nchannel1_recv_val(chan, 1, 2)\nval () =\nprintln! (\"client2: msg = \", msg)\n\/\/\nval () =\nchannel1_send(chan, 2, 3, \"msg(2, 3)\")\n\/\/\nval () = channel1_skipex(chan)\n\/\/\nval () = channel1_close(chan)\n\/\/\n} (* end of [fserv_client2] *)\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nfserv_client3\n(\n chan:\n channel1(S3, N, ssn_ring4)\n) : void =\n{\n\/\/\nprval() =\nlemma_iset_sing_is_member{3}()\nprval() =\nlemma_iset_sing_isnot_member{3,0}()\nprval() =\nlemma_iset_sing_isnot_member{3,1}()\nprval() =\nlemma_iset_sing_isnot_member{3,2}()\n\/\/\nval () =\n channel1_skipex(chan)\nval () =\n channel1_skipex(chan)\n\/\/\nval\nmsg =\nchannel1_recv_val(chan, 2, 3)\nval () =\nprintln!(\"client3: msg = \", msg)\n\/\/\nval () =\nchannel1_send(chan, 3, 0, \"msg(3, 0)\")\n\/\/\nval () = channel1_close(chan)\n\/\/\n} (* end of [fserv_client3] *)\n\/\/\n(* ****** ****** *)\n\nimplement\nmain0\n(\n argc, argv\n) = let\n\/\/\nval S0 = intset_int{N}(0)\nval S1 = intset_int{N}(1)\nval S2 = intset_int{N}(2)\nval S3 = intset_int{N}(3)\n\/\/\nval chn0 =\ncchannel1_create_exn\n(\n N, S0, llam(chp) => fserv_client0(chp)\n) (* end of [val] *)\nval chn2 =\ncchannel1_create_exn\n(\n N, S2, llam(chp) => fserv_client2(chp)\n) (* end of [val] *)\n\/\/\nval chn1 =\ncchannel1_create_exn\n(\n N, S1, llam(chp) => fserv_client1(chp)\n) (* end of [val] *)\nval chn3 =\ncchannel1_create_exn\n(\n N, S3, llam(chp) => fserv_client3(chp)\n) (* end of [val] *)\n\/\/\nval () =\nchannel1_link_elim\n(\n channel1_link(chn0, $UN.castvwtp0(chn2))\n, channel1_link(chn1, $UN.castvwtp0(chn3))\n) (* end of [val] *)\n\/\/\nin\n<<<<<<< HEAD\n ignoret($UNISTD.usleep(250000u)) \/\/ wait until the 4 threads finish\n=======\n ignoret($UNISTD.usleep(250000u))\n>>>>>>> c28772a91c84b274e4949aa92626461b8a513f39\nend \/\/ end of [main0]\n\n(* ****** ****** *)\n\n<<<<<<< HEAD\n(* end of [test03-4p.dats] *)\n=======\n(* end of [test02-3p.dats] *)\n>>>>>>> c28772a91c84b274e4949aa92626461b8a513f39\n","old_contents":"(*\n**\n** For testing g-sessions\n**\n** This example involves 4 parties,\n** passing 4 messages in a ring-like\n** fashion.\n**\n** Author: Hongwei Xi\n** Authoremail: gmhwxiATgmailDOTcom\n** Start time: the 8th of March, 2016\n**\n*)\n\n(* ****** ****** *)\n\n%{^\n\/\/\n#include \n\/\/\n%} \/\/ end of [%{^]\n\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_staload.hats\"\n\/\/\n(* ****** ****** *)\n\nstaload UN = $UNSAFE\n\n(* ****** ****** *)\n\nstaload\nUNISTD = \"libc\/SATS\/unistd.sats\"\n\n(* ****** ****** *)\n\nstaload\n\".\/..\/SATS\/basis_intset.sats\"\nstaload _ =\n\".\/..\/DATS\/basis_intset.dats\"\n\n(* ****** ****** *)\n\/\/\nstaload\n\".\/..\/SATS\/basis_ssntype.sats\"\nstaload\n\".\/..\/SATS\/basis_ssntype2r.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload _ =\n\"libats\/DATS\/deqarray.dats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload _ =\n\"libats\/DATS\/athread.dats\"\nstaload _ =\n\"libats\/DATS\/athread_posix.dats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload _ =\n\".\/..\/DATS\/basis_uchan.dats\"\nstaload _ =\n\".\/..\/DATS\/basis_channel0.dats\"\nstaload _ =\n\".\/..\/DATS\/basis_channel1.dats\"\nstaload _ =\n\".\/..\/DATS\/basis_ssntype2r.dats\"\n\/\/\n(* ****** ****** *)\n\n#define N 4\n\n(* ****** ****** *)\n\/\/\ntypedef\nssn_ring4 =\nmsg(0, 1, string) ::\nmsg(1, 2, string) ::\nmsg(2, 3, string) ::\nmsg(3, 0, string) :: nil\n\/\/\n(* ****** ****** *)\n\/\/\nstadef S0 = iset(0)\nstadef S1 = iset(1)\nstadef S2 = iset(2)\nstadef S3 = iset(3)\n\/\/\nstadef S02 = iset(0,2)\nstadef S13 = iset(1,3)\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nfserv_client0\n(\n chan:\n channel1(S0, N, ssn_ring4)\n) : void =\n{\n\/\/\nprval() =\nlemma_iset_sing_is_member{0}()\nprval() =\nlemma_iset_sing_isnot_member{0,1}()\nprval() =\nlemma_iset_sing_isnot_member{0,2}()\nprval() =\nlemma_iset_sing_isnot_member{0,3}()\n\/\/\nval () =\nchannel1_send\n (chan, 0, 1, \"msg(0, 1)\")\n\/\/\nval () = channel1_skipex(chan)\nval () = channel1_skipex(chan)\n\/\/\nval\nmsg = channel1_recv_val(chan, 3, 0)\nval () = println! (\"client0: msg = \", msg)\n\/\/\nval () = channel1_close(chan)\n\/\/\n} (* end of [fserv_client0] *)\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nfserv_client1\n(\n chan:\n channel1(S1, N, ssn_ring4)\n) : void =\n{\n\/\/\nprval() =\nlemma_iset_sing_is_member{1}()\nprval() =\nlemma_iset_sing_isnot_member{1,0}()\nprval() =\nlemma_iset_sing_isnot_member{1,2}()\nprval() =\nlemma_iset_sing_isnot_member{1,3}()\n\/\/\nval\nmsg =\nchannel1_recv_val(chan, 0, 1)\nval () =\nprintln! (\"client1: msg = \", msg)\n\/\/\nval () =\nchannel1_send(chan, 1, 2, \"msg(1, 2)\")\n\/\/\nval () = channel1_skipex(chan)\nval () = channel1_skipex(chan)\n\/\/\nval () = channel1_close(chan)\n\/\/\n} (* end of [fserv_client1] *)\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nfserv_client2\n(\n chan:\n channel1(S2, N, ssn_ring4)\n) : void =\n{\n\/\/\nprval() =\nlemma_iset_sing_is_member{2}()\nprval() =\nlemma_iset_sing_isnot_member{2,0}()\nprval() =\nlemma_iset_sing_isnot_member{2,1}()\nprval() =\nlemma_iset_sing_isnot_member{2,3}()\n\/\/\nval () =\n channel1_skipex(chan)\n\/\/\nval\nmsg =\nchannel1_recv_val(chan, 1, 2)\nval () =\nprintln! (\"client2: msg = \", msg)\n\/\/\nval () =\nchannel1_send(chan, 2, 3, \"msg(2, 3)\")\n\/\/\nval () = channel1_skipex(chan)\n\/\/\nval () = channel1_close(chan)\n\/\/\n} (* end of [fserv_client2] *)\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nfserv_client3\n(\n chan:\n channel1(S3, N, ssn_ring4)\n) : void =\n{\n\/\/\nprval() =\nlemma_iset_sing_is_member{3}()\nprval() =\nlemma_iset_sing_isnot_member{3,0}()\nprval() =\nlemma_iset_sing_isnot_member{3,1}()\nprval() =\nlemma_iset_sing_isnot_member{3,2}()\n\/\/\nval () =\n channel1_skipex(chan)\nval () =\n channel1_skipex(chan)\n\/\/\nval\nmsg =\nchannel1_recv_val(chan, 2, 3)\nval () =\nprintln!(\"client3: msg = \", msg)\n\/\/\nval () =\nchannel1_send(chan, 3, 0, \"msg(3, 0)\")\n\/\/\nval () = channel1_close(chan)\n\/\/\n} (* end of [fserv_client3] *)\n\/\/\n(* ****** ****** *)\n\nimplement\nmain0\n(\n argc, argv\n) = let\n\/\/\nval S0 = intset_int{N}(0)\nval S1 = intset_int{N}(1)\nval S2 = intset_int{N}(2)\nval S3 = intset_int{N}(3)\n\/\/\nval chn0 =\ncchannel1_create_exn\n(\n N, S0, llam(chp) => fserv_client0(chp)\n) (* end of [val] *)\nval chn2 =\ncchannel1_create_exn\n(\n N, S2, llam(chp) => fserv_client2(chp)\n) (* end of [val] *)\n\/\/\nval chn1 =\ncchannel1_create_exn\n(\n N, S1, llam(chp) => fserv_client1(chp)\n) (* end of [val] *)\nval chn3 =\ncchannel1_create_exn\n(\n N, S3, llam(chp) => fserv_client3(chp)\n) (* end of [val] *)\n\/\/\nval () =\nchannel1_link_elim\n(\n channel1_link(chn0, $UN.castvwtp0(chn2))\n, channel1_link(chn1, $UN.castvwtp0(chn3))\n) (* end of [val] *)\n\/\/\nin\n ignoret($UNISTD.usleep(250000u)) \/\/ wait until the 4 threads finish\nend \/\/ end of [main0]\n\n(* ****** ****** *)\n\n(* end of [test03-4p.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"bb475d8d19941684a559f06f9bda38d7e99d3657","subject":"Updating: very minorly fixing","message":"Updating: very minorly fixing\n","repos":"bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib","old_file":"contrib\/arduino\/TEST\/ArrayQuickSort\/ArrayQuickSort.dats","new_file":"contrib\/arduino\/TEST\/ArrayQuickSort\/ArrayQuickSort.dats","new_contents":"(*\n#\n# ArrayQuickSort\n#\n*)\n(* ****** ****** *)\n\n#define ATS_DYNLOADFLAG 0\n\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_define.hats\"\n#include\n\"{$ARDUINO}\/staloadall.hats\"\n\/\/\n(* ****** ****** *)\n\nstaload UN = \"prelude\/SATS\/unsafe.sats\"\n\n(* ****** ****** *)\n\/\/\n%{^\ntypedef char *charptr;\n%} \/\/ end of [%{^]\n\/\/\nabstype charptr = $extype\"charptr\"\n\/\/\n(* ****** ****** *)\n\/\/\n%{^\n#define N 10\nint theArray[N] =\n{\n 0,1,2,3,4,5,6,7,8,9\n} ;\n%} \/\/ end of [%{^]\n#define N 10\nmacdef theArray =\n $extval(arrayref(int,N),\"theArray\")\n\/\/\n(* ****** ****** *)\n\nmacdef LEDPIN = 13\nmacdef BAUD_RATE = 9600\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nsetup (): void = \"mac#\"\n\/\/\nimplement\nsetup () = () where\n{\n\/\/\nval () = pinMode(LEDPIN, OUTPUT)\nval () = Serial_ptr._begin(BAUD_RATE)\n\/\/\n} (* end of [setup] *)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nfprint_val\n (out, x) = Serial_ptr.print(x)\n\/\/\n(* ****** ****** *)\n\/\/\n(*\nimplement\nfprint_string (out, x) = Serial_ptr.print(x)\n*)\n(* ****** ****** *)\n\/\/\nimplement\nfprint_array$sep<> (out) = ()\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun loop (): void = \"mac#\"\n\/\/\nimplement\nloop () =\nmyloop(0) where\n{\n\/\/\nfun\nmysort{n:nat}\n(\n A: arrayref(int, n)\n, n: int(n)\n) : void = let\n\/\/\nval\n(\n vbox pf | p\n) =\n arrayref_get_viewptr(A)\nin\n array_quicksort (!p, i2sz(n))\nend \/\/ end of [mysort]\n\/\/\nfun\nmyrand{n:int}\n(\n A: arrayref(int, n), n: int(n)\n) : void = let\n\/\/\nval\n(\n vbox pf | p\n) =\n arrayref_get_viewptr(A)\n\/\/\nprval () = lemma_arrayref_param(A)\n\/\/\nimplement\narray_permute$randint<>\n {n}(n) =\n(\n $UN.cast{sizeLt(n)}(random(sz2i(n)))\n) (* end of [array_permute$randint] *)\n\/\/\nin\n $effmask_ref(array_permute (!p, i2sz(n)))\nend \/\/ end of [myrand]\n\/\/\nfun\nmyloop\n(\n bit: int\n) : void = let\n\/\/\nval\nout = $extval (FILEref, \"0\")\n\/\/\n(*\nval () =\nrandomSeed($UN.cast{uint}(millis()))\n*)\n\/\/\nval A = theArray\nval () = fprint_arrayref (out, A, i2sz(N))\nval () = Serial_ptr.println()\n\/\/\nval () =\n(\n if bit = 0 then myrand(A, N) else mysort(A, N)\n) : void \/\/ end of [val]\n\/\/\nval () = digitalWrite(LEDPIN, 1)\nval () = delay(250)\nval () = digitalWrite(LEDPIN, 0)\nval () = delay(1000)\n\/\/\nin\n myloop (1-bit)\nend \/\/ end of [myloop]\n\/\/\n} (* end of [loop] *)\n\/\/\n(* ****** ****** *)\n\n(* end of [ArrayQuickSort.dats] *)\n","old_contents":"(*\n#\n# ArrayQuickSort\n#\n*)\n(* ****** ****** *)\n\n#define ATS_DYNLOADFLAG 0\n\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_define.hats\"\n#include\n\"{$ARDUINO}\/staloadall.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload _ =\n \"prelude\/DATS\/array_quicksort.dats\"\n\/\/\n(* ****** ****** *)\n\nstaload UN = \"prelude\/SATS\/unsafe.sats\"\n\n(* ****** ****** *)\n\/\/\n%{^\ntypedef char *charptr;\n%} \/\/ end of [%{^]\n\/\/\nabstype charptr = $extype\"charptr\"\n\/\/\n(* ****** ****** *)\n\/\/\n%{^\n#define N 10\nint theArray[N] =\n{\n 0,1,2,3,4,5,6,7,8,9\n} ;\n%} \/\/ end of [%{^]\n#define N 10\nmacdef theArray =\n $extval(arrayref(int,N),\"theArray\")\n\/\/\n(* ****** ****** *)\n\nmacdef LEDPIN = 13\nmacdef BAUD_RATE = 9600\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nsetup (): void = \"mac#\"\n\/\/\nimplement\nsetup () = () where\n{\n\/\/\nval () = pinMode(LEDPIN, OUTPUT)\nval () = Serial_ptr._begin(BAUD_RATE)\n\/\/\n} (* end of [setup] *)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nfprint_val\n (out, x) = Serial_ptr.print(x)\n\/\/\n(* ****** ****** *)\n\/\/\n(*\nimplement\nfprint_string (out, x) = Serial_ptr.print(x)\n*)\n(* ****** ****** *)\n\/\/\nimplement\nfprint_array$sep<> (out) = ()\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun loop (): void = \"mac#\"\n\/\/\nimplement\nloop () =\nmyloop(0) where\n{\n\/\/\nfun\nmysort{n:nat}\n(\n A: arrayref(int, n)\n, n: int(n)\n) : void = let\n\/\/\nval\n(\n vbox pf | p\n) =\n arrayref_get_viewptr(A)\nin\n array_quicksort (!p, i2sz(n))\nend \/\/ end of [mysort]\n\/\/\nfun\nmyrand{n:int}\n(\n A: arrayref(int, n), n: int(n)\n) : void = let\n\/\/\nval\n(\n vbox pf | p\n) =\n arrayref_get_viewptr(A)\n\/\/\nprval () = lemma_arrayref_param(A)\n\/\/\nimplement\narray_permute$randint<>\n {n}(n) =\n(\n $UN.cast{sizeLt(n)}(random(sz2i(n)))\n) (* end of [array_permute$randint] *)\n\/\/\nin\n $effmask_ref(array_permute (!p, i2sz(n)))\nend \/\/ end of [myrand]\n\/\/\nfun\nmyloop\n(\n bit: int\n) : void = let\n\/\/\nval\nout = $extval (FILEref, \"0\")\n\/\/\n(*\nval () =\nrandomSeed($UN.cast{uint}(millis()))\n*)\n\/\/\nval A = theArray\nval () = fprint_arrayref (out, A, i2sz(N))\nval () = Serial_ptr.println()\n\/\/\nval () =\n(\n if bit = 0 then myrand(A, N) else mysort(A, N)\n) : void \/\/ end of [val]\n\/\/\nval () = digitalWrite(LEDPIN, 1)\nval () = delay(250)\nval () = digitalWrite(LEDPIN, 0)\nval () = delay(1000)\n\/\/\nin\n myloop (1-bit)\nend \/\/ end of [myloop]\n\/\/\n} (* end of [loop] *)\n\/\/\n(* ****** ****** *)\n\n(* end of [ArrayQuickSort.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"f08edb1fb80b55e0c1f5a2496a1807bddc9af2a3","subject":"Updating: working on chardev-1","message":"Updating: working on chardev-1\n","repos":"bbarker\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib","old_file":"projects\/MEDIUM\/LinuxKerneling\/TEST\/mycode\/chardev\/chardev-1.dats","new_file":"projects\/MEDIUM\/LinuxKerneling\/TEST\/mycode\/chardev\/chardev-1.dats","new_contents":"(*\n** A simple char device\n*)\n\n(* ****** ****** *)\n\/\/\n\/\/ HX-2014-10-24:\n\/\/ nothing fancy here;\n\/\/ just trying to get it working\n\/\/\n(* ****** ****** *)\n\/\/\n\/\/ HX-2014-10-21:\n\/\/ no use for dynloading\n\/\/\n#define ATS_DYNLOADFLAG 0\n\/\/\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_define.hats\"\n\/\/\n#include\n\"{$KERNELATS}\/prelude\/staloadall.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\n\"{$LINUX}\/basics.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\n\"{$LINUX}\/SATS\/errno.sats\"\nstaload\n\"{$LINUX}\/SATS\/types.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\n\"{$LINUX}\/SATS\/init.sats\"\nstaload\n\"{$LINUX}\/SATS\/module.sats\"\nstaload\n\"{$LINUX}\/SATS\/kernel.sats\"\nstaload $PRINTK \/\/ HX: opening NS\n\/\/\nstaload \"{$LINUX}\/SATS\/fs.sats\"\n\/\/\nstaload \"{$LINUX}\/SATS\/asm\/uaccess.sats\"\n\/\/\n(* ****** ****** *)\n\nstaload\nUN = \"prelude\/SATS\/unsafe.sats\"\n\n(* ****** ****** *)\n\n%{^\nMODULE_LICENSE(\"Dual BSD\/GPL\") ;\n%} \/\/ end of [%{^]\n\n(* ****** ****** *)\n\nstatic\nfun init_module(): interr = \"mac#\"\nstatic\nfun cleanup_module(): void = \"mac#\"\n\n(* ****** ****** *)\n\n%{^\nstatic int Major = 0;\nstatic int Device_open = 0;\nstatic int Device_open_count = 0;\n%} \/\/ end of [%{^]\n\nmacdef\nMajor = $extval(int, \"Major\")\nmacdef\nDevice_open = $extval(int, \"Device_open\")\nmacdef\nDevice_open_count = $extval(int, \"Device_open_count\")\n\n(* ****** ****** *)\n\n%{^\n#define BUFLEN 80 \/\/ Max length of the message from the device\n#define DEVICE_NAME \"chardev-1\" \/* Dev name as it appears in \/proc\/devices *\/\n\/\/\ntypedef\nchar *charptr ;\nchar Message[BUFLEN];\ncharptr Message0_ptr = &Message[0];\ncharptr Message1_ptr = &Message[0];\n\/\/\n%} \/\/ end of [%{^]\n\ntypedef charptr = $extype\"charptr\"\n\nmacdef\nDEVICE_NAME = $extval(string, \"DEVICE_NAME\")\nmacdef\nMessage0_ptr = $extval(charptr, \"Message0_ptr\")\nmacdef\nMessage1_ptr = $extval(charptr, \"Message1_ptr\")\n\n(* ****** ****** *)\n\n%{^\n\/\/\nstatic int device_open(struct inode *, struct file *);\nstatic int device_release(struct inode *, struct file *);\nstatic ssize_t device_read(struct file *, char *, size_t, loff_t *);\nstatic ssize_t device_write(struct file *, const char *, size_t, loff_t *);\n\/\/\n%} \/\/ end of [%{^]\n\n(* ****** ****** *)\n\n%{^\n\nstruct\nfile_operations\nfops = {\n .read = device_read,\n .write = device_write,\n .open = device_open,\n .release = device_release\n} ;\n\nstatic void *fops_ptr = &(fops);\n\n%} \/\/ end of [%{^]\n\nmacdef\nfops_ptr = $extval(fops_ptr1, \"fops_ptr\")\n\n(* ****** ****** *)\n\nimplement\ninit_module\n(\n) = let\n\/\/\nextvar\n\"Major\" =\nregister_chrdev(0u, DEVICE_NAME, fops_ptr)\n\/\/\nval Major = g1ofg0(Major)\n\/\/\nin\n\/\/\nif\n(Major > 0)\nthen let\n\/\/\nval () =\n$extfcall\n(\n void\n, \"printk\", KERN_INFO_\"The assigned major number is: %d\\n\", Major\n) (* end of [val] *)\n\/\/\nin\n 0(*SUCCESS*)\nend \/\/ end of [then]\nelse let\n\/\/\nval () =\n$extfcall\n(\n void\n, \"printk\", KERN_ALERT_\"Registering chardev failed with %d\\n\", Major\n) (* end of [val] *)\n\/\/\nin\n Major\nend \/\/ end of [else]\n\/\/\nend (* end of [init_module] *)\n\n(* ****** ****** *)\n\nimplement\ncleanup_module\n(\n\/\/ argumentless\n) = () where\n{\n\/\/\nval\nMajor =\n(\nif Major > 0\n then g0i2u(Major) else 0u\n\/\/ end of [if]\n) : uint \/\/ end of [val]\n\/\/\nval () = unregister_chrdev(Major, DEVICE_NAME)\n\/\/\n} (* end of [cleanup_module] *)\n\n(* ****** ****** *)\n\/\/\nstatic\nfun device_open_ (inode_ptr1, file_ptr1): interr = \"mac#\"\nstatic\nfun device_release_ (inode_ptr1, file_ptr1): interr = \"mac#\"\n\/\/\n(* ****** ****** *)\n\nimplement\ndevice_open_\n (inx, filp) = let\nin\n\/\/\nif\n(Device_open = 0)\nthen let\n\/\/\nextvar\n\"Device_open\" = Device_open + 1\nextvar\n\"Device_open_count\" = Device_open_count + 1\n\/\/\nval () =\n$extfcall\n(\n void\n, \"sprintf\"\n, Message0_ptr, \"Hello(%d) from the chardev\\n\", Device_open_count\n) : void \/\/ end of [val]\n\/\/\nextvar\n\"Message1_ptr\" = Message0_ptr\n\/\/\nin\n 0(*SUCCESS*)\nend \/\/ end of [then]\nelse ~(EBUSY) \/\/ end of [else]\n\/\/\nend \/\/ end of [device_open_]\n \n(* ****** ****** *)\n\nimplement\ndevice_release_\n (inx, filp) = let\n\/\/\nextvar\n\"Device_open\" = Device_open - 1\n\/\/\nin\n 0(*SUCCESS*)\nend \/\/ end of [device_release_]\n\n(* ****** ****** *)\n\n%{$\n\/\/\nstatic\ninline\nint\ndevice_open\n(\nstruct inode *p0, struct file *p1\n) { return device_open_(p0, p1) ; }\n\/\/\nstatic\ninline\nint\ndevice_release\n(\nstruct inode *p0, struct file *p1\n) { return device_release_(p0, p1) ; }\n\/\/\n%} \/\/ end of [%{$]\n\n(* ****** ****** *)\n\/\/\nstatic\nfun\ndevice_read_{n:int}\n(\n file_ptr1, buf: &ubytes(n), size_t(n), ofs: &loff_t\n) : ssize_t = \"mac#\" \/\/ end-of-function\nstatic\nfun\ndevice_write_{n:int}\n(\n file_ptr1, buf: &ubytes(n), size_t(n), ofs: &loff_t\n) : ssize_t = \"mac#\" \/\/ end-of-function\n\/\/\n(* ****** ****** *)\n\nimplement\ndevice_read_\n (filp, buf, n, ofs) = let\n\/\/\nval n2 =\nstring_nlength<>\n ($UN.cast{string}(Message1_ptr), n)\n\/\/\nval\nnread =\n$extfcall\n(\n size_t\n, \"copy_to_user\", addr@buf, Message1_ptr, n2\n) (* end of [val] *)\n\/\/\nextvar\n\"Message1_ptr\" =\nadd_ptr_bsz ($UN.cast{ptr}(Message1_ptr), nread)\n\/\/\nval () =\n$extfcall\n(\n void, \"printk\", KERN_INFO_\"device_read_: n2 = %ld\", n2\n)\nval () =\n$extfcall\n(\n void, \"printk\", KERN_INFO_\"device_read_: nread = %ld\", nread\n)\n\/\/\nin\n $UN.cast{ssize_t}(nread)\nend \/\/ end of [device_read_]\n\n(* ****** ****** *)\n\nimplement\ndevice_write_\n (filp, buf, n, ofs) = let\n\/\/\nval () =\n$extfcall\n(\n void\n, \"printk\"\n, KERN_ALERT_\"Sorry, this operation isn't supported.\\n\"\n) (* end of [val] *)\n\/\/\nin\n $UN.cast{ssize_t}(~(EINVAL))\nend \/\/ end of [device_write_]\n\n(* ****** ****** *)\n\n%{$\n\/\/\nstatic\ninline\nssize_t\ndevice_read\n(\nstruct file *p0, char *buf, size_t n, loff_t *ofs\n) { return device_read_(p0, buf, n, ofs) ; }\n\/\/\nstatic\ninline\nssize_t\ndevice_write\n(\nstruct file *p0, const char *buf, size_t n, loff_t *ofs\n) { return device_write_(p0, (void*)buf, n, ofs) ; }\n\/\/\n%} \/\/ end of [%{$]\n\n(* ****** ****** *)\n\n(* end of [chardev-1.dats] *)\n","old_contents":"(*\n** A simple char device\n*)\n\n(* ****** ****** *)\n\/\/\n\/\/ HX-2014-10-24:\n\/\/ nothing fancy here;\n\/\/ just trying to get it working\n\/\/\n(* ****** ****** *)\n\/\/\n\/\/ HX-2014-10-21:\n\/\/ no use for dynloading\n\/\/\n#define ATS_DYNLOADFLAG 0\n\/\/\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_define.hats\"\n\/\/\n#include\n\"{$KERNELATS}\/prelude\/staloadall.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\n\"{$LINUX}\/basics.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\n\"{$LINUX}\/SATS\/errno.sats\"\nstaload\n\"{$LINUX}\/SATS\/types.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\n\"{$LINUX}\/SATS\/init.sats\"\nstaload\n\"{$LINUX}\/SATS\/module.sats\"\nstaload\n\"{$LINUX}\/SATS\/kernel.sats\"\nstaload $PRINTK \/\/ HX: opening NS\n\/\/\nstaload \"{$LINUX}\/SATS\/fs.sats\"\n\/\/\nstaload \"{$LINUX}\/SATS\/asm\/uaccess.sats\"\n\/\/\n(* ****** ****** *)\n\nstaload\nUN = \"prelude\/SATS\/unsafe.sats\"\n\n(* ****** ****** *)\n\n%{^\nMODULE_LICENSE(\"Dual BSD\/GPL\") ;\n%} \/\/ end of [%{^]\n\n(* ****** ****** *)\n\nstatic\nfun init_module(): interr = \"mac#\"\nstatic\nfun cleanup_module(): void = \"mac#\"\n\n(* ****** ****** *)\n\n%{^\nstatic int Major = 0;\nstatic int Device_open = 0;\nstatic int Device_open_count = 0;\n%} \/\/ end of [%{^]\n\nmacdef\nMajor = $extval(int, \"Major\")\nmacdef\nDevice_open = $extval(int, \"Device_open\")\nmacdef\nDevice_open_count = $extval(int, \"Device_open_count\")\n\n(* ****** ****** *)\n\n%{^\n#define BUFLEN 80 \/\/ Max length of the message from the device\n#define DEVICE_NAME \"chardev-1\" \/* Dev name as it appears in \/proc\/devices *\/\n\/\/\ntypedef\nchar *charptr ;\nchar Message[BUFLEN];\ncharptr Message0_ptr = &Message[0];\ncharptr Message1_ptr = &Message[0];\n\/\/\n%} \/\/ end of [%{^]\n\ntypedef charptr = $extype\"charptr\"\n\nmacdef\nDEVICE_NAME = $extval(string, \"DEVICE_NAME\")\nmacdef\nMessage0_ptr = $extval(charptr, \"Message0_ptr\")\nmacdef\nMessage1_ptr = $extval(charptr, \"Message1_ptr\")\n\n(* ****** ****** *)\n\n%{^\n\/\/\nstatic int device_open(struct inode *, struct file *);\nstatic int device_release(struct inode *, struct file *);\nstatic ssize_t device_read(struct file *, char *, size_t, loff_t *);\nstatic ssize_t device_write(struct file *, const char *, size_t, loff_t *);\n\/\/\n%} \/\/ end of [%{^]\n\n(* ****** ****** *)\n\n%{^\n\nstruct\nfile_operations\nfops = {\n .read = device_read,\n .write = device_write,\n .open = device_open,\n .release = device_release\n} ;\n\nstatic void *fops_ptr = &(fops);\n\n%} \/\/ end of [%{^]\n\nmacdef\nfops_ptr = $extval(fops_ptr1, \"fops_ptr\")\n\n(* ****** ****** *)\n\nimplement\ninit_module\n(\n) = let\n\/\/\nextvar\n\"Major\" =\nregister_chrdev(0u, DEVICE_NAME, fops_ptr)\n\/\/\nval Major = g1ofg0(Major)\n\/\/\nin\n\/\/\nif\n(Major > 0)\nthen let\n\/\/\nval () =\n$extfcall\n(\n void\n, \"printk\", KERN_INFO_\"The assigned major number is: %d\\n\", Major\n) (* end of [val] *)\n\/\/\nin\n 0(*SUCCESS*)\nend \/\/ end of [then]\nelse let\n\/\/\nval () =\n$extfcall\n(\n void\n, \"printk\", KERN_ALERT_\"Registering chardev failed with %d\\n\", Major\n) (* end of [val] *)\n\/\/\nin\n Major\nend \/\/ end of [else]\n\/\/\nend (* end of [init_module] *)\n\n(* ****** ****** *)\n\nimplement\ncleanup_module\n(\n\/\/ argumentless\n) = () where\n{\n\/\/\nval\nMajor =\n(\nif Major > 0\n then g0i2u(Major) else 0u\n\/\/ end of [if]\n) : uint \/\/ end of [val]\n\/\/\nval () = unregister_chrdev(Major, DEVICE_NAME)\n\/\/\n} (* end of [cleanup_module] *)\n\n(* ****** ****** *)\n\/\/\nstatic\nfun device_open_ (inode_ptr1, file_ptr1): interr = \"mac#\"\nstatic\nfun device_release_ (inode_ptr1, file_ptr1): interr = \"mac#\"\n\/\/\n(* ****** ****** *)\n\nimplement\ndevice_open_\n (inx, filp) = let\nin\n\/\/\nif\n(Device_open = 0)\nthen let\n\/\/\nextvar\n\"Device_open\" = Device_open + 1\nextvar\n\"Device_open_count\" = Device_open_count + 1\n\/\/\nval () =\n$extfcall\n(\n void\n, \"sprintf\"\n, Message0_ptr, \"Hello(%d) from the chardev\\n\", Device_open_count\n) : void \/\/ end of [val]\n\/\/\nextvar\n\"Message1_ptr\" = Message0_ptr\n\/\/\nin\n 0(*SUCCESS*)\nend \/\/ end of [then]\nelse ~(EBUSY) \/\/ end of [else]\n\/\/\nend \/\/ end of [device_open_]\n \n(* ****** ****** *)\n\nimplement\ndevice_release_\n (inx, filp) = let\n\/\/\nextvar\n\"Device_open\" = Device_open - 1\n\/\/\nin\n 0(*SUCCESS*)\nend \/\/ end of [device_release_]\n\n(* ****** ****** *)\n\n%{$\n\/\/\nstatic\ninline\nint\ndevice_open\n(\nstruct inode *p0, struct file *p1\n) { return device_open_(p0, p1) ; }\n\/\/\nstatic\ninline\nint\ndevice_release\n(\nstruct inode *p0, struct file *p1\n) { return device_release_(p0, p1) ; }\n\/\/\n%} \/\/ end of [%{$]\n\n(* ****** ****** *)\n\/\/\nstatic\nfun\ndevice_read_{n:int}\n(\n file_ptr1, buf: &ubytes(n), size_t(n), ofs: &loff_t\n) : ssize_t = \"mac#\" \/\/ end-of-function\nstatic\nfun\ndevice_write_{n:int}\n(\n file_ptr1, buf: &ubytes(n), size_t(n), ofs: &loff_t\n) : ssize_t = \"mac#\" \/\/ end-of-function\n\/\/\n(* ****** ****** *)\n\nimplement\ndevice_read_\n (filp, buf, n, ofs) = let\n\/\/\nval n2 =\nstring_nlength<>\n ($UN.cast{string}(Message1_ptr), n)\n\/\/\nval\nnread =\n$extfcall\n(\n size_t\n, \"copy_to_user\", addr@buf, Message1_ptr, n2\n) (* end of [val] *)\n\/\/\nextvar\n\"Message1_ptr\" =\nadd_ptr_bsz ($UN.cast{ptr}(Message1_ptr), nread)\n\/\/\nval () =\n$extfcall\n(\n void, \"printk\", \"device_read_: n2 = %ld\", n2\n)\nval () =\n$extfcall\n(\n void, \"printk\", \"device_read_: nread = %ld\", nread\n)\n\/\/\nin\n $UN.cast{ssize_t}(nread)\nend \/\/ end of [device_read_]\n\n(* ****** ****** *)\n\nimplement\ndevice_write_\n (filp, buf, n, ofs) = let\n\/\/\nval () =\n$extfcall\n(\n void\n, \"printk\"\n, KERN_ALERT_\"Sorry, this operation isn't supported.\\n\"\n) (* end of [val] *)\n\/\/\nin\n $UN.cast{ssize_t}(~(EINVAL))\nend \/\/ end of [device_write_]\n\n(* ****** ****** *)\n\n%{$\n\/\/\nstatic\ninline\nssize_t\ndevice_read\n(\nstruct file *p0, char *buf, size_t n, loff_t *ofs\n) { return device_read_(p0, buf, n, ofs) ; }\n\/\/\nstatic\ninline\nssize_t\ndevice_write\n(\nstruct file *p0, const char *buf, size_t n, loff_t *ofs\n) { return device_write_(p0, (void*)buf, n, ofs) ; }\n\/\/\n%} \/\/ end of [%{$]\n\n(* ****** ****** *)\n\n(* end of [chardev-1.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"0182231ea3d16c5b5aaf261612a8d0836403e5a7","subject":"Updating: very very minorly","message":"Updating: very very minorly\n","repos":"ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib","old_file":"contrib\/libats-\/hwxi\/teaching\/mygrading\/HATS\/mygrading.hats","new_file":"contrib\/libats-\/hwxi\/teaching\/mygrading\/HATS\/mygrading.hats","new_contents":"(*\n** THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\n** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\n** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\n** HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\n** WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n** FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\n** OTHER DEALINGS IN THE SOFTWARE.\n*)\n\n(* ****** ****** *)\n\n(*\n** A library of grading for my own use\n*)\n\n(* ****** ****** *)\n\/\/\n\/\/ Author: Hongwei Xi\n\/\/ Authoremail: gmhwxiATgmailDOTcom\n\/\/ Start time: the first of July, 2016\n\/\/\n(* ****** ****** *)\n\/\/\n#define\nMYGRADING_HATS 1\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\ncsv_parse_line\n(\n line: string\n) : List0_vt(Strptr1)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\ncsv_parse_line_nerr\n(\n line: string, nerr: &int >> _\n) : List0_vt(Strptr1)\n\/\/\n(* ****** ****** *)\n\nimplement\ncsv_parse_line\n (line) = res0 where\n{\n\/\/\nvar nerr: int = 0\nval res0 = csv_parse_line_nerr(line, nerr)\n\/\/\n} (* end of [csv_parse_line] *)\n\n(* ****** ****** *)\n\/\/\nlocal\n\/\/\n#include \".\/csv_parse_line.hats\"\n\/\/\nin (* nothing *) end \/\/ [local]\n\/\/\n(* ****** ****** *)\n\n(* end of [mygrading.hats] *)\n","old_contents":"(*\n** THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\n** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\n** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\n** HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\n** WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n** FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\n** OTHER DEALINGS IN THE SOFTWARE.\n*)\n\n(* ****** ****** *)\n\n(*\n** A library of grading for my own use\n*)\n\n(* ****** ****** *)\n\/\/\n\/\/ Author: Hongwei Xi\n\/\/ Authoremail: gmhwxiATgmailDOTcom\n\/\/ Start time: the first of July, 2016\n\/\/\n(* ****** ****** *)\n\/\/\n#define\nMYGRADING_HATS 1\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\ncsv_parse_line\n(\n line: string\n) : List0_vt(Strptr1)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\ncsv_parse_line_nerr\n(\n line: string, nerr: &int >> _\n) : List0_vt(Strptr1)\n\/\/\n(* ****** ****** *)\n\nimplement\ncsv_parse_line\n (line) = let\n\/\/\nvar nerr: int = 0\nval res0 = csv_parse_line_nerr(line, nerr)\n\/\/\nin\n res0\nend \/\/ end of [csv_parse_line]\n\n(* ****** ****** *)\n\/\/\nlocal\n\/\/\n#include \".\/csv_parse_line.hats\"\n\/\/\nin (* nothing *) end \/\/ [local]\n\/\/\n(* ****** ****** *)\n\n(* end of [mygrading.hats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"3d616cd38aca259d7622ebef39edaeafc200b135","subject":"Updating: very minorly tidying-up","message":"Updating: very minorly tidying-up\n","repos":"githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib","old_file":"contrib\/libatscc\/libatscc2js\/SATS\/Bacon.js\/baconjs.sats","new_file":"contrib\/libatscc\/libatscc2js\/SATS\/Bacon.js\/baconjs.sats","new_contents":"(*\n** For writing ATS code\n** that translates into JavaScript\n*)\n\n(* ****** ****** *)\n\n(*\n** Permission to use, copy, modify, and distribute this software for any\n** purpose with or without fee is hereby granted, provided that the above\n** copyright notice and this permission notice appear in all copies.\n** \n** THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES\n** WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF\n** MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR\n** ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\n** WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN\n** ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF\n** OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n*)\n\n(* ****** ****** *)\n\n(*\n** Author: Hongwei Xi\n** Authoremail: gmhwxi AT gmail DOT com\n** Start Time: April, 2015\n*)\n\n(* ****** ****** *)\n\n#define\nATS_STALOADFLAG 0 \/\/ no staloading at run-time\n#define\nATS_EXTERN_PREFIX \"ats2js_bacon_\" \/\/ prefix for external names\n\n(* ****** ****** *)\n\/\/\nstaload\n\".\/..\/..\/basics_js.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nabstype Event = ptr\nabstype EStream(a:t@ype) = ptr\n\/\/\nabstype Property(a:t@ype) = ptr\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nBacon_once\n {a:t0p}(x: a): EStream(a) = \"mac#%\"\nfun\nBacon_never\n {a:t0p}((*void*)): EStream(a) = \"mac#%\"\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nBacon_delay\n {a:t0p}\n (ms: intGte(0), x: a): EStream(a) = \"mac#%\"\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nBacon_interval\n {a:t0p}\n (ms: intGte(0), x: a): EStream(a) = \"mac#%\"\n\/\/\nfun\nBacon_repeatedly\n {a:t0p}\n (ms: intGte(0), xs: JSarray(a)): EStream(a) = \"mac#%\"\n\/\/\nfun\nBacon_sequentially\n {a:t0p}\n (ms: intGte(0), xs: JSarray(a)): EStream(a) = \"mac#%\"\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nBacon_repeat{a:t0p}\n(\n fopr: cfun(intGte(0), EStream(a))\n) : EStream(a) = \"mac#%\" \/\/ end-of-fun\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nEStream_map\n {a,b:t0p}\n(\n xs: EStream(a), fopr: cfun(a, b)\n) : EStream(b) = \"mac#%\" \/\/ end-of-fun\nfun\nProperty_map\n {a,b:t0p}\n(\n xs: Property(a), fopr: cfun(a, b)\n) : Property(b) = \"mac#%\" \/\/ end-of-fun\n\/\/\noverload map with EStream_map\noverload map with Property_map\noverload .map with EStream_map\noverload .map with Property_map\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nEStream_map_property\n {a,b:t0p}\n(\n xs: EStream(a), ys: Property(b)\n) : EStream(b) = \"mac#%\" \/\/ end-of-fun\n\/\/\noverload map with EStream_map_property\noverload .map with EStream_map_property\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nEStream_filter\n {a:t0p}\n(\n xs: EStream(a), test: cfun(a, bool)\n) : EStream(a) = \"mac#%\" \/\/ end-of-fun\n\/\/\noverload filter with EStream_filter\noverload .filter with EStream_filter\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nEStream_filter_property\n {a:t0p}\n(\n xs: EStream(a), bs: Property(bool)\n) : EStream(a) = \"mac#%\" \/\/ end-of-fun\n\/\/\noverload filter with EStream_filter_property\noverload .filter with EStream_filter_property\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nEStream_scan\n {a,b:t0p}\n(\n xs: EStream(b), ini: a, fopr: cfun(a, b, a)\n) : Property(a) = \"mac#%\" \/\/ end-of-function\n\/\/\noverload scan with EStream_scan\noverload .scan with EStream_scan\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nEStream_merge2\n {a:t0p}\n (EStream(a), EStream(a)): EStream(a) = \"mac#%\"\nfun\nEStream_merge3\n {a:t0p}\n (EStream(a), EStream(a), EStream(a)): EStream(a) = \"mac#%\"\n\/\/\noverload merge with EStream_merge2\noverload merge with EStream_merge3\n\/\/\noverload .merge with EStream_merge2\noverload .merge with EStream_merge3\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nBacon_combineWith2\n {a,b,c:t0p}\n(\n Property(a), Property(b), cfun(a, b, c)\n) : Property(c) = \"mac#%\" \/\/ end-of-function\nfun\nBacon_combineWith3\n {a,b,c,d:t0p}\n(\n Property(a), Property(b), Property(c), cfun(a, b, c, d)\n) : Property(d) = \"mac#%\" \/\/ end-of-function\n\/\/\noverload combineWith with Bacon_combineWith2\noverload combineWith with Bacon_combineWith3\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nEStream_toProperty\n {a:t0p}(EStream(a)): Property(a) = \"mac#%\"\nfun\nEStream_toProperty_init\n {a:t0p}(EStream(a), x0: a): Property(a) = \"mac#%\"\n\/\/\noverload toProperty with EStream_toProperty\noverload toProperty with EStream_toProperty_init\noverload .toProperty with EStream_toProperty\noverload .toProperty with EStream_toProperty_init\n\/\/\nfun\nProperty_toEventStream\n {a:t0p}(Property(a)): EStream(a) = \"mac#%\"\n\/\/\noverload toEventStream with Property_toEventStream\noverload .toEventStream with Property_toEventStream\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nEStream_onValue\n {a:t0p}(EStream(a), cfun(a, void)): void = \"mac#%\"\nfun\nProperty_onValue\n {a:t0p}(Property(a), cfun(a, void)): void = \"mac#%\"\n\/\/\noverload onValue with EStream_onValue\noverload onValue with Property_onValue\noverload .onValue with EStream_onValue\noverload .onValue with Property_onValue\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nEStream_subscribe\n {a:t0p}(EStream(a), cfun(Event, void)): void = \"mac#%\"\nfun\nProperty_subscribe\n {a:t0p}(Property(a), cfun(Event, void)): void = \"mac#%\"\n\/\/\noverload subscribe with EStream_subscribe\noverload subscribe with Property_subscribe\noverload .subscribe with EStream_subscribe\noverload .subscribe with Property_subscribe\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nProperty_startWith\n {a:t0p}(Property(a), a): Property(a) = \"mac#%\"\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nEStream_doAction\n {a:t0p}\n (xs: EStream(a), f: cfun(a, void)): EStream(a) = \"mac#%\"\nfun\nProperty_doAction\n {a:t0p}\n (xs: Property(a), f: cfun(a, void)): Property(a) = \"mac#%\"\n\/\/\noverload doAction with EStream_doAction\noverload doAction with Property_doAction\noverload .doAction with EStream_doAction\noverload .doAction with Property_doAction\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nProperty_sampledBy_estream\n {a,b:t0p}(Property(a), EStream(b)): EStream(a) = \"mac#%\"\nfun\nProperty_sampledBy_property\n {a,b:t0p}(Property(a), Property(b)): Property(a) = \"mac#%\"\n\/\/\noverload sampledBy with Property_sampledBy_estream\noverload sampledBy with Property_sampledBy_property\noverload .sampledBy with Property_sampledBy_estream\noverload .sampledBy with Property_sampledBy_property\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nProperty_sampledBy_estream_cfun\n {a,b:t0p}{c:t0p}\n(\n Property(a), EStream(b), cfun(a, b, c)\n) : EStream(c) = \"mac#%\" \/\/ end-of-function\nfun\nProperty_sampledBy_property_cfun\n {a,b:t0p}{c:t0p}\n(\n Property(a), Property(b), cfun(a, b, c)\n) : Property(c) = \"mac#%\" \/\/ end-of-function\n\/\/\noverload sampledBy with Property_sampledBy_estream_cfun\noverload sampledBy with Property_sampledBy_property_cfun\noverload .sampledBy with Property_sampledBy_estream_cfun\noverload .sampledBy with Property_sampledBy_property_cfun\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nEStream_zip_estream_cfun\n {a,b:t0p}{c:t0p}\n(\n xs: EStream(a), ys: EStream(b), cfun(a, b, c)\n) : EStream(c) = \"mac#%\" \/\/ end-of-function\n\/\/\noverload zip with EStream_zip_estream_cfun\noverload .zip with EStream_zip_estream_cfun\n\/\/\n(* ****** ****** *)\n\n(* end of [baconjs.sats] *)\n","old_contents":"(*\n** For writing ATS code\n** that translates into JavaScript\n*)\n\n(* ****** ****** *)\n\n(*\n** Permission to use, copy, modify, and distribute this software for any\n** purpose with or without fee is hereby granted, provided that the above\n** copyright notice and this permission notice appear in all copies.\n** \n** THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES\n** WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF\n** MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR\n** ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\n** WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN\n** ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF\n** OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n*)\n\n(* ****** ****** *)\n\n(*\n** Author: Hongwei Xi\n** Authoremail: gmhwxi AT gmail DOT com\n** Start Time: April, 2015\n*)\n\n(* ****** ****** *)\n\n#define\nATS_STALOADFLAG 0 \/\/ no staloading at run-time\n#define\nATS_EXTERN_PREFIX \"ats2js_bacon_\" \/\/ prefix for external names\n\n(* ****** ****** *)\n\/\/\nstaload\n\".\/..\/..\/basics_js.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nabstype Event = ptr\nabstype EStream(a:t@ype) = ptr\n\/\/\nabstype Property(a:t@ype) = ptr\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nBacon_once\n {a:t0p}(x: a): EStream(a) = \"mac#%\"\nfun\nBacon_never\n {a:t0p}((*void*)): EStream(a) = \"mac#%\"\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nBacon_delay\n {a:t0p}\n (delay: intGte(0), x: a): EStream(a) = \"mac#%\"\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nBacon_interval\n {a:t0p}(int: intGte(0), x: a): EStream(a) = \"mac#%\"\n\/\/\nfun\nBacon_repeatedly\n {a:t0p}\n (int: intGte(0), xs: JSarray(a)): EStream(a) = \"mac#%\"\n\/\/\nfun\nBacon_sequentially\n {a:t0p}\n (int: intGte(0), xs: JSarray(a)): EStream(a) = \"mac#%\"\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nBacon_repeat{a:t0p}\n (fopr: cfun(intGte(0), EStream(a))): EStream(a) = \"mac#%\"\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nEStream_map\n {a,b:t0p}\n(\n xs: EStream(a), fopr: cfun(a, b)\n) : EStream(b) = \"mac#%\" \/\/ end-of-fun\nfun\nProperty_map\n {a,b:t0p}\n(\n xs: Property(a), fopr: cfun(a, b)\n) : Property(b) = \"mac#%\" \/\/ end-of-fun\n\/\/\noverload map with EStream_map\noverload map with Property_map\noverload .map with EStream_map\noverload .map with Property_map\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nEStream_map_property\n {a,b:t0p}\n(\n xs: EStream(a), ys: Property(b)\n) : EStream(b) = \"mac#%\" \/\/ end-of-fun\n\/\/\noverload map with EStream_map_property\noverload .map with EStream_map_property\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nEStream_filter\n {a:t0p}\n(\n xs: EStream(a), test: cfun(a, bool)\n) : EStream(a) = \"mac#%\" \/\/ end-of-fun\n\/\/\noverload filter with EStream_filter\noverload .filter with EStream_filter\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nEStream_filter_property\n {a:t0p}\n(\n xs: EStream(a), bs: Property(bool)\n) : EStream(a) = \"mac#%\" \/\/ end-of-fun\n\/\/\noverload filter with EStream_filter_property\noverload .filter with EStream_filter_property\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nEStream_scan\n {a,b:t0p}\n(\n xs: EStream(b), ini: a, fopr: cfun(a, b, a)\n) : Property(a) = \"mac#%\" \/\/ end-of-function\n\/\/\noverload scan with EStream_scan\noverload .scan with EStream_scan\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nEStream_merge2\n {a:t0p}\n (EStream(a), EStream(a)): EStream(a) = \"mac#%\"\nfun\nEStream_merge3\n {a:t0p}\n (EStream(a), EStream(a), EStream(a)): EStream(a) = \"mac#%\"\n\/\/\noverload merge with EStream_merge2\noverload merge with EStream_merge3\n\/\/\noverload .merge with EStream_merge2\noverload .merge with EStream_merge3\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nBacon_combineWith2\n {a,b,c:t0p}\n(\n Property(a), Property(b), cfun(a, b, c)\n) : Property(c) = \"mac#%\" \/\/ end-of-function\nfun\nBacon_combineWith3\n {a,b,c,d:t0p}\n(\n Property(a), Property(b), Property(c), cfun(a, b, c, d)\n) : Property(d) = \"mac#%\" \/\/ end-of-function\n\/\/\noverload combineWith with Bacon_combineWith2\noverload combineWith with Bacon_combineWith3\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nEStream_toProperty\n {a:t0p}(EStream(a)): Property(a) = \"mac#%\"\nfun\nEStream_toProperty_init\n {a:t0p}(EStream(a), x0: a): Property(a) = \"mac#%\"\n\/\/\noverload toProperty with EStream_toProperty\noverload toProperty with EStream_toProperty_init\noverload .toProperty with EStream_toProperty\noverload .toProperty with EStream_toProperty_init\n\/\/\nfun\nProperty_toEventStream\n {a:t0p}(Property(a)): EStream(a) = \"mac#%\"\n\/\/\noverload toEventStream with Property_toEventStream\noverload .toEventStream with Property_toEventStream\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nEStream_onValue\n {a:t0p}(EStream(a), cfun(a, void)): void = \"mac#%\"\nfun\nProperty_onValue\n {a:t0p}(Property(a), cfun(a, void)): void = \"mac#%\"\n\/\/\noverload onValue with EStream_onValue\noverload onValue with Property_onValue\noverload .onValue with EStream_onValue\noverload .onValue with Property_onValue\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nEStream_subscribe\n {a:t0p}(EStream(a), cfun(Event, void)): void = \"mac#%\"\nfun\nProperty_subscribe\n {a:t0p}(Property(a), cfun(Event, void)): void = \"mac#%\"\n\/\/\noverload subscribe with EStream_subscribe\noverload subscribe with Property_subscribe\noverload .subscribe with EStream_subscribe\noverload .subscribe with Property_subscribe\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nProperty_startWith\n {a:t0p}(Property(a), a): Property(a) = \"mac#%\"\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nEStream_doAction\n {a:t0p}\n (xs: EStream(a), f: cfun(a, void)): EStream(a) = \"mac#%\"\nfun\nProperty_doAction\n {a:t0p}\n (xs: Property(a), f: cfun(a, void)): Property(a) = \"mac#%\"\n\/\/\noverload doAction with EStream_doAction\noverload doAction with Property_doAction\noverload .doAction with EStream_doAction\noverload .doAction with Property_doAction\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nProperty_sampledBy_estream\n {a,b:t0p}(Property(a), EStream(b)): EStream(a) = \"mac#%\"\nfun\nProperty_sampledBy_property\n {a,b:t0p}(Property(a), Property(b)): Property(a) = \"mac#%\"\n\/\/\noverload sampledBy with Property_sampledBy_estream\noverload sampledBy with Property_sampledBy_property\noverload .sampledBy with Property_sampledBy_estream\noverload .sampledBy with Property_sampledBy_property\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nProperty_sampledBy_estream_cfun\n {a,b:t0p}{c:t0p}\n(\n Property(a), EStream(b), cfun(a, b, c)\n) : EStream(c) = \"mac#%\" \/\/ end-of-function\nfun\nProperty_sampledBy_property_cfun\n {a,b:t0p}{c:t0p}\n(\n Property(a), Property(b), cfun(a, b, c)\n) : Property(c) = \"mac#%\" \/\/ end-of-function\n\/\/\noverload sampledBy with Property_sampledBy_estream_cfun\noverload sampledBy with Property_sampledBy_property_cfun\noverload .sampledBy with Property_sampledBy_estream_cfun\noverload .sampledBy with Property_sampledBy_property_cfun\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nEStream_zip_estream_cfun\n {a,b:t0p}{c:t0p}\n(\n xs: EStream(a), ys: EStream(b), cfun(a, b, c)\n) : EStream(c) = \"mac#%\" \/\/ end-of-function\n\/\/\noverload zip with EStream_zip_estream_cfun\noverload .zip with EStream_zip_estream_cfun\n\/\/\n(* ****** ****** *)\n\n(* end of [baconjs.sats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"7f4fd73cacc27bdeb81e9dc2dba2e358cb9fcd0f","subject":"Updating: very minorly improving","message":"Updating: very minorly improving\n","repos":"githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib","old_file":"contrib\/libats-\/hwxi\/teaching\/mysession-g\/TEST\/bitstr.dats","new_file":"contrib\/libats-\/hwxi\/teaching\/mysession-g\/TEST\/bitstr.dats","new_contents":"(*\n** Bit-strings\n*)\n\n(* ****** ****** *)\n\n%{^\n\/\/\n#include \n\/\/\n%} \/\/ end of [%{^]\n\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_staload.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload UN = $UNSAFE\n\/\/\nstaload\nUNISTD = \"libc\/SATS\/unistd.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\n\".\/..\/SATS\/basis_intset.sats\"\nstaload _ =\n\".\/..\/DATS\/basis_intset.dats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\n\".\/..\/SATS\/basis_ssntype.sats\"\nstaload\n\".\/..\/SATS\/basis_ssntype2r.sats\"\n\/\/\n(* ****** ****** *)\n\nstaload\n_ = \"libats\/DATS\/deqarray.dats\"\n\n(* ****** ****** *)\n\/\/\nstaload\n_ = \"libats\/DATS\/athread.dats\"\nstaload\n_ = \"libats\/DATS\/athread_posix.dats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload _ =\n\".\/..\/DATS\/basis_uchan.dats\"\nstaload CHAN0 =\n\".\/..\/DATS\/basis_channel0.dats\"\nstaload CHAN1 =\n\".\/..\/DATS\/basis_channel1.dats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload _ =\n\".\/..\/DATS\/basis_ssntype2r.dats\"\n\/\/\n(* ****** ****** *)\n\/\/\nabstype\nssn_list(a:vt@ype)\n\/\/\n(* ****** ****** *)\n\/\/\ndatatype\nchan1neg_list\n (a:vt@ype, type) =\n| chan1neg_list_nil(a, nil) of ()\n| chan1neg_list_cons\n (a, snd(a) :: ssn_list(a)) of ()\n \/\/ chan1neg_list_cons\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun{}\nchan1neg_list\n {a:vt@ype}\n(\n chneg:\n !chan1neg(ssn_list(a)) >> chan1neg(ss)\n) : #[ss:type] chan1neg_list(a, ss)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun{}\nchan1pos_list_nil\n {a:vt@ype}\n(\n chpos:\n !chan1pos(ssn_list(a)) >> chan1pos(nil)\n) : void \/\/ end of [chan1pos_list_nil]\nextern\nfun{}\nchan1pos_list_cons\n {a:vt@ype}\n(\n chpos:\n !chan1pos(ssn_list(a)) >> chan1pos(snd(a)::ssn_list(a))\n) : void \/\/ end of [chan1pos_list_cons]\n\/\/\n(* ****** ****** *)\n\nimplement\n{}(*tmp*)\nchan1pos_list_nil\n (chpos) = () where\n{\n\/\/\nvtypedef\nchan0 = $CHAN0.channel0(ptr, 2)\n\/\/\nval\nchan0 = $UN.castvwtp1{chan0}(chpos)\n\/\/\nval () =\n$CHAN0.channel0_send(chan0, 0, 1, $UN.int2ptr(0))\n\/\/\nprval () = $UN.cast2void(chan0)\nprval () = $UN.castview2void(chpos)\n\/\/\n} (* end of [chan1pos_list_nil] *)\n\/\/\n(* ****** ****** *)\n\nimplement\n{}(*tmp*)\nchan1pos_list_cons\n (chpos) = () where\n{\n\/\/\nvtypedef\nchan0 = $CHAN0.channel0(ptr, 2)\n\/\/\nval\nchan0 = $UN.castvwtp1{chan0}(chpos)\n\/\/\nval () =\n$CHAN0.channel0_send(chan0, 0, 1, $UN.int2ptr(1))\n\/\/\nprval () = $UN.cast2void(chan0)\nprval () = $UN.castview2void(chpos)\n\/\/\n} (* end of [chan1pos_list_cons] *)\n\n(* ****** ****** *)\n\nimplement\n{}(*tmp*)\nchan1neg_list\n (chneg) = let\n\/\/\nvtypedef\nchan0 = $CHAN0.channel0(ptr, 2)\nval\nchan0 = $UN.castvwtp1{chan0}(chneg)\n\/\/\nval tag =\n $CHAN0.channel0_recv_val(chan0, 0, 1)\n\/\/\nprval () = $UN.cast2void(chan0)\n\/\/\nin\n\/\/\nif\niseqz(tag)\nthen let\n prval () = $UN.castview2void(chneg) in chan1neg_list_nil()\nend \/\/ end of [then]\nelse let\n prval () = $UN.castview2void(chneg) in chan1neg_list_cons()\nend \/\/ end of [else]\n\/\/\nend \/\/ end of [chan1neg_list]\n\n(* ****** ****** *)\n\/\/\nabst@ype bit = int\n\/\/\nmacdef B0 = $UN.cast{bit}(0)\nmacdef B1 = $UN.cast{bit}(1)\n\/\/\ntypedef bit_ = natLt(2)\n\/\/\nextern castfn bit2bit_(bit): bit_\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nint2bits\n {n:nat}(int(n)): chan1neg(ssn_list(bit))\n\/\/\n(* ****** ****** *)\n\nimplement\nint2bits(n) = let\n\/\/\nfun\nfserv{n:nat}\n(\n n: int(n), chp: chan1pos(ssn_list(bit))\n) : void = (\n\/\/\nif\nn > 0\nthen let\n val n2 = half(n)\n val bit =\n (\n if n = 2*n2 then B0 else B1\n ) : bit \/\/ end of [val]\n val () = chan1pos_list_cons(chp)\n val ((*void*)) = chan1pos_send(chp, bit)\nin\n fserv(n2, chp)\nend \/\/ end of [then]\nelse let\n val () = chan1pos_list_nil(chp) in channel1_close(chp)\nend \/\/ end of [else]\n\/\/\n) (* end of [fserv] *)\n\/\/\nin\n chan1neg_create_exn{ssn_list(bit)}(llam(chp) => fserv(n, chp))\nend \/\/ end of [int2bits]\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nsucc_bits\n(\n chneg:\n chan1neg(ssn_list(bit))\n) : chan1neg(ssn_list(bit))\n\/\/\n(* ****** ****** *)\n\nimplement\nsucc_bits(chn) = let\n\/\/\nfun\nfserv\n(\n chp: chan1pos(ssn_list(bit))\n, chn: chan1neg(ssn_list(bit))\n) : void = let\n\/\/\nval opt = chan1neg_list(chn)\n\/\/\nin\n\/\/\ncase+ opt of\n| chan1neg_list_nil() => let\n val () =\n chan1pos_list_cons(chp)\n val () =\n chan1pos_send(chp, B1)\n val () =\n chan1pos_list_nil(chp)\n \/\/ end of [val]\n val () = channel1_close(chp)\n val () = channel1_close(chn)\n in\n \/\/ nothing\n end \/\/ end of [chan1neg_list_nil]\n| chan1neg_list_cons() => let\n val () =\n chan1pos_list_cons (chp)\n val bit = chan1neg_send_val (chn)\n val bit_ = bit2bit_(bit)\n in\n if bit_ > 0\n then let\n val () =\n chan1pos_send (chp, B0)\n \/\/ end of [val]\n in\n fserv(chp, chn)\n end \/\/ end of [then]\n else let\n val () =\n chan1pos_send (chp, B1)\n \/\/ end of [val]\n in\n chan1posneg_elim(chp, chn)\n end \/\/ end of [else]\n end \/\/ end of [chan1neg_list_cons]\n\/\/\nend \/\/ end of [fserv]\n\/\/\nin\n chan1neg_create_exn{ssn_list(bit)}(llam(chp) => fserv(chp, chn))\nend \/\/ end of [succ_bits]\n \n(* ****** ****** *)\n\nextern\nfun\nadd_bits_bits\n(\n chan1neg(ssn_list(bit))\n, chan1neg(ssn_list(bit))\n) : chan1neg(ssn_list(bit))\n\n(* ****** ****** *)\n\nimplement\nadd_bits_bits\n (chn1, chn2) = let\n\/\/\nfun\nfserv\n(\n chp: chan1pos(ssn_list(bit))\n, chn1: chan1neg(ssn_list(bit))\n, chn2: chan1neg(ssn_list(bit))\n) : void = let\n\/\/\nval opt1 = chan1neg_list (chn1)\n\/\/\nin\n\/\/\ncase+ opt1 of\n| chan1neg_list_nil() => let\n val () = channel1_close(chn1)\n in\n chan1posneg_elim (chp, chn2)\n end \/\/ end of [chan1neg_list_nil]\n| chan1neg_list_cons() => let\n val () =\n chan1pos_list_cons (chp)\n \/\/ end of [val]\n val opt2 = chan1neg_list (chn2)\n in\n case+ opt2 of\n | chan1neg_list_nil() => let\n val () =\n channel1_close(chn2)\n \/\/ end of [val]\n in\n chan1posneg_elim(chp, chn1)\n end \/\/ end of [chan1neg_list_nil]\n | chan1neg_list_cons() => let\n val b1 = chan1neg_send_val(chn1)\n and b2 = chan1neg_send_val(chn2)\n val b1_ = bit2bit_(b1) and b2_ = bit2bit_(b2)\n in\n case+ b1_ of\n | 0 => (\n chan1pos_send(chp, b2); fserv(chp, chn1, chn2)\n ) (* end of [0] *)\n | 1 => (\n case+ b2_ of\n | 0 => (chan1pos_send(chp, B1); fserv(chp, chn1, chn2))\n | 1 => (chan1pos_send(chp, B0); fserv(chp, chn1, succ_bits(chn2)))\n ) (* end of [1] *)\n end \/\/ end of [chan1neg_list_cons]\n end \/\/ end of [chan1neg_list_cons]\n\/\/\nend \/\/ end of [fserv]\n\/\/\nin\n chan1neg_create_exn{ssn_list(bit)}(llam(chp) => fserv(chp, chn1, chn2))\nend \/\/ end of [add_bits_bits]\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nbits2int\n(\n chn: chan1neg(ssn_list(bit))\n) : intGte(0) \/\/ end-of-function\n\/\/\n(* ****** ****** *)\n\nimplement\nbits2int(chn) = let\n\/\/\nfun\nloop\n(\n xs: List0_vt(bit), res: intGte(0)\n) : intGte(0) =\n(\ncase+ xs of\n| ~list_vt_nil() => res\n| ~list_vt_cons(x, xs) =>\n loop (xs, 2*res + bit2bit_(x))\n) (* end of [loop] *)\n\/\/\n\/\/\nfun\nloop2\n(\n chn: chan1neg(ssn_list(bit)), xs: List0_vt(bit)\n) : List0_vt(bit) = let\n\/\/\nval opt = chan1neg_list(chn)\n\/\/\nin\n\/\/\ncase+ opt of\n| chan1neg_list_nil() => let\n val () =\n channel1_close(chn) in xs\n \/\/ end of [val]\n end \/\/ end of [chan1neg_list_nil]\n| chan1neg_list_cons() => let\n val x =\n chan1neg_send_val (chn)\n \/\/ end of [val]\n in\n loop2(chn, list_vt_cons(x, xs))\n end \/\/ end of [chan1neg_list_cons]\n\/\/\nend \/\/ end of [loop2]\n\/\/\nin\n loop(loop2(chn, list_vt_nil(*void*)), 0)\nend \/\/ end of [bits2int]\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nsucc_int(intGte(0)): intGte(0)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nsucc_int(x) =\n bits2int(succ_bits(int2bits(x)))\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nadd_int_int(intGte(0), intGte(0)): intGte(0)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nadd_int_int(x, y) =\n bits2int(add_bits_bits(int2bits(x), int2bits(y)))\n\/\/\n(* ****** ****** *)\n\nimplement\nmain0(argc, argv) =\n{\n\/\/\nval a0 =\n(\nif argc >= 2\n then g0string2int(argv[1]) else 0\n\/\/ end of [if]\n) : int \/\/ end of [val]\n\/\/\nval a1 =\n(\nif argc >= 3\n then g0string2int(argv[2]) else 0\n\/\/ end of [if]\n) : int \/\/ end of [val]\n\/\/\nval a0 = g1ofg0(a0)\nand a1 = g1ofg0(a1)\n\/\/\nval () = assertloc (a0 >= 0)\nval () = assertloc (a1 >= 0)\n\/\/\nval () =\nprintln!\n (a0, \" + \", a1, \" = \", add_int_int(a0, a1))\n\/\/\nval _(*left*) = $UNISTD.usleep(250000u)\n\/\/\n} (* end of [main0] *)\n\n(* ****** ****** *)\n\n(* end of [bitstr.dats] *)\n","old_contents":"(*\n** Bit-strings\n*)\n\n(* ****** ****** *)\n\n%{^\n\/\/\n#include \n\/\/\n%} \/\/ end of [%{^]\n\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_staload.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload UN = $UNSAFE\n\/\/\nstaload\nUNISTD = \"libc\/SATS\/unistd.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\n\".\/..\/SATS\/basis_intset.sats\"\nstaload _ =\n\".\/..\/DATS\/basis_intset.dats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\n\".\/..\/SATS\/basis_ssntype.sats\"\nstaload\n\".\/..\/SATS\/basis_ssntype2r.sats\"\n\/\/\n(* ****** ****** *)\n\nstaload\n_ = \"libats\/DATS\/deqarray.dats\"\n\n(* ****** ****** *)\n\/\/\nstaload\n_ = \"libats\/DATS\/athread.dats\"\nstaload\n_ = \"libats\/DATS\/athread_posix.dats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload _ =\n\".\/..\/DATS\/basis_uchan.dats\"\nstaload CHAN0 =\n\".\/..\/DATS\/basis_channel0.dats\"\nstaload CHAN1 =\n\".\/..\/DATS\/basis_channel1.dats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload _ =\n\".\/..\/DATS\/basis_ssntype2r.dats\"\n\/\/\n(* ****** ****** *)\n\/\/\nabstype\nssn_list(a:vt@ype)\n\/\/\n(* ****** ****** *)\n\/\/\ndatatype\nchan1neg_list\n (a:vt@ype, type) =\n| chan1neg_list_nil(a, nil) of ()\n| chan1neg_list_cons\n (a, snd(a) :: ssn_list(a)) of ()\n \/\/ chan1neg_list_cons\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun{}\nchan1neg_list\n {a:vt@ype}\n(\n chneg:\n !chan1neg(ssn_list(a)) >> chan1neg(ss)\n) : #[ss:type] chan1neg_list(a, ss)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun{}\nchan1pos_list_nil\n {a:vt@ype}\n(\n chpos:\n !chan1pos(ssn_list(a)) >> chan1pos(nil)\n) : void \/\/ end of [chan1pos_list_nil]\nextern\nfun{}\nchan1pos_list_cons\n {a:vt@ype}\n(\n chpos:\n !chan1pos(ssn_list(a)) >> chan1pos(snd(a)::ssn_list(a))\n) : void \/\/ end of [chan1pos_list_cons]\n\/\/\n(* ****** ****** *)\n\nimplement\n{}(*tmp*)\nchan1pos_list_nil\n (chpos) = () where\n{\n\/\/\nvtypedef\nchan0 = $CHAN0.channel0(ptr, 2)\n\/\/\nval\nchan0 = $UN.castvwtp1{chan0}(chpos)\n\/\/\nval () =\n$CHAN0.channel0_send(chan0, 0, 1, $UN.int2ptr(0))\n\/\/\nprval () = $UN.cast2void(chan0)\nprval () = $UN.castview2void(chpos)\n\/\/\n} (* end of [chan1pos_list_nil] *)\n\/\/\n(* ****** ****** *)\n\nimplement\n{}(*tmp*)\nchan1pos_list_cons\n (chpos) = () where\n{\n\/\/\nvtypedef\nchan0 = $CHAN0.channel0(ptr, 2)\n\/\/\nval\nchan0 = $UN.castvwtp1{chan0}(chpos)\n\/\/\nval () =\n$CHAN0.channel0_send(chan0, 0, 1, $UN.int2ptr(1))\n\/\/\nprval () = $UN.cast2void(chan0)\nprval () = $UN.castview2void(chpos)\n\/\/\n} (* end of [chan1pos_list_cons] *)\n\n(* ****** ****** *)\n\nimplement\n{}(*tmp*)\nchan1neg_list\n (chneg) = let\n\/\/\nvtypedef\nchan0 = $CHAN0.channel0(ptr, 2)\nval\nchan0 = $UN.castvwtp1{chan0}(chneg)\n\/\/\nval tag =\n $CHAN0.channel0_recv_val(chan0, 0, 1)\n\/\/\nprval () = $UN.cast2void(chan0)\n\/\/\nin\n\/\/\nif\niseqz(tag)\nthen let\n prval () = $UN.castview2void(chneg) in chan1neg_list_nil()\nend \/\/ end of [then]\nelse let\n prval () = $UN.castview2void(chneg) in chan1neg_list_cons()\nend \/\/ end of [else]\n\/\/\nend \/\/ end of [chan1neg_list]\n\n(* ****** ****** *)\n\/\/\nabst@ype bit = int\n\/\/\nmacdef B0 = $UN.cast{bit}(0)\nmacdef B1 = $UN.cast{bit}(1)\n\/\/\ntypedef bit_ = natLt(2)\n\/\/\nextern castfn bit2bit_(bit): bit_\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nint2bits\n {n:nat}(int(n)): chan1neg(ssn_list(bit))\n\/\/\n(* ****** ****** *)\n\nimplement\nint2bits(n) = let\n\/\/\nfun\nfserv{n:nat}\n(\n n: int(n), chp: chan1pos(ssn_list(bit))\n) : void = (\n\/\/\nif\nn > 0\nthen let\n val n2 = half(n)\n val bit =\n (\n if n = 2*n2 then B0 else B1\n ) : bit \/\/ end of [val]\n val () = chan1pos_list_cons(chp)\n val ((*void*)) = chan1pos_send(chp, bit)\nin\n fserv (n2, chp)\nend \/\/ end of [then]\nelse let\n val () = chan1pos_list_nil(chp) in channel1_close(chp)\nend \/\/ end of [else]\n\/\/\n) (* end of [fserv] *)\n\/\/\nin\n chan1neg_create_exn{ssn_list(bit)}(llam(chp) => fserv (n, chp))\nend \/\/ end of [int2bits]\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nsucc_bits\n(\n chneg:\n chan1neg(ssn_list(bit))\n) : chan1neg(ssn_list(bit))\n\/\/\n(* ****** ****** *)\n\nimplement\nsucc_bits(chn) = let\n\/\/\nfun\nfserv\n(\n chp: chan1pos(ssn_list(bit))\n, chn: chan1neg(ssn_list(bit))\n) : void = let\n\/\/\nval opt = chan1neg_list(chn)\n\/\/\nin\n\/\/\ncase+ opt of\n| chan1neg_list_nil() => let\n val () =\n chan1pos_list_cons(chp)\n val () =\n chan1pos_send(chp, B1)\n val () =\n chan1pos_list_nil(chp)\n \/\/ end of [val]\n val () = channel1_close(chp)\n val () = channel1_close(chn)\n in\n \/\/ nothing\n end \/\/ end of [chan1neg_list_nil]\n| chan1neg_list_cons() => let\n val () =\n chan1pos_list_cons (chp)\n val bit = chan1neg_send_val (chn)\n val bit_ = bit2bit_(bit)\n in\n if bit_ > 0\n then let\n val () =\n chan1pos_send (chp, B0)\n \/\/ end of [val]\n in\n fserv(chp, chn)\n end \/\/ end of [then]\n else let\n val () =\n chan1pos_send (chp, B1)\n \/\/ end of [val]\n in\n chan1posneg_elim(chp, chn)\n end \/\/ end of [else]\n end \/\/ end of [chan1neg_list_cons]\n\/\/\nend \/\/ end of [fserv]\n\/\/\nin\n chan1neg_create_exn{ssn_list(bit)}(llam(chp) => fserv (chp, chn))\nend \/\/ end of [succ_bits]\n \n(* ****** ****** *)\n\nextern\nfun\nadd_bits_bits\n(\n chan1neg(ssn_list(bit))\n, chan1neg(ssn_list(bit))\n) : chan1neg(ssn_list(bit))\n\n(* ****** ****** *)\n\nimplement\nadd_bits_bits\n (chn1, chn2) = let\n\/\/\nfun\nfserv\n(\n chp: chan1pos(ssn_list(bit))\n, chn1: chan1neg(ssn_list(bit))\n, chn2: chan1neg(ssn_list(bit))\n) : void = let\n\/\/\nval opt1 = chan1neg_list (chn1)\n\/\/\nin\n\/\/\ncase+ opt1 of\n| chan1neg_list_nil() => let\n val () = channel1_close(chn1)\n in\n chan1posneg_elim (chp, chn2)\n end \/\/ end of [chan1neg_list_nil]\n| chan1neg_list_cons() => let\n val () =\n chan1pos_list_cons (chp)\n \/\/ end of [val]\n val opt2 = chan1neg_list (chn2)\n in\n case+ opt2 of\n | chan1neg_list_nil() => let\n val () =\n channel1_close(chn2)\n \/\/ end of [val]\n in\n chan1posneg_elim(chp, chn1)\n end \/\/ end of [chan1neg_list_nil]\n | chan1neg_list_cons() => let\n val b1 = chan1neg_send_val(chn1)\n and b2 = chan1neg_send_val(chn2)\n val b1_ = bit2bit_(b1) and b2_ = bit2bit_(b2)\n in\n case+ b1_ of\n | 0 => (\n chan1pos_send(chp, b2); fserv(chp, chn1, chn2)\n ) (* end of [0] *)\n | 1 => (\n case+ b2_ of\n | 0 => (chan1pos_send(chp, B1); fserv(chp, chn1, chn2))\n | 1 => (chan1pos_send(chp, B0); fserv(chp, chn1, succ_bits(chn2)))\n ) (* end of [1] *)\n end \/\/ end of [chan1neg_list_cons]\n end \/\/ end of [chan1neg_list_cons]\n\/\/\nend \/\/ end of [fserv]\n\/\/\nin\n chan1neg_create_exn{ssn_list(bit)}(llam(chp) => fserv (chp, chn1, chn2))\nend \/\/ end of [add_bits_bits]\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nbits2int\n(\n chn: chan1neg(ssn_list(bit))\n) : intGte(0) \/\/ end-of-function\n\/\/\n(* ****** ****** *)\n\nimplement\nbits2int(chn) = let\n\/\/\nfun\nloop\n(\n xs: List0_vt(bit), res: intGte(0)\n) : intGte(0) =\n(\ncase+ xs of\n| ~list_vt_nil() => res\n| ~list_vt_cons(x, xs) =>\n loop (xs, 2*res + bit2bit_(x))\n) (* end of [loop] *)\n\/\/\n\/\/\nfun\nloop2\n(\n chn: chan1neg(ssn_list(bit)), xs: List0_vt(bit)\n) : List0_vt(bit) = let\n\/\/\nval opt = chan1neg_list(chn)\n\/\/\nin\n\/\/\ncase+ opt of\n| chan1neg_list_nil() => let\n val () =\n channel1_close(chn) in xs\n \/\/ end of [val]\n end \/\/ end of [chan1neg_list_nil]\n| chan1neg_list_cons() => let\n val x =\n chan1neg_send_val (chn)\n \/\/ end of [val]\n in\n loop2(chn, list_vt_cons(x, xs))\n end \/\/ end of [chan1neg_list_cons]\n\/\/\nend \/\/ end of [loop2]\n\/\/\nin\n loop(loop2(chn, list_vt_nil(*void*)), 0)\nend \/\/ end of [bits2int]\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nsucc_int(intGte(0)): intGte(0)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nsucc_int(x) =\n bits2int(succ_bits(int2bits(x)))\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nadd_int_int(intGte(0), intGte(0)): intGte(0)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nadd_int_int(x, y) =\n bits2int(add_bits_bits(int2bits(x), int2bits(y)))\n\/\/\n(* ****** ****** *)\n\nimplement\nmain0(argc, argv) =\n{\n\/\/\nval a0 =\n(\nif argc >= 2\n then g0string2int(argv[1]) else 0\n\/\/ end of [if]\n) : int \/\/ end of [val]\n\/\/\nval a1 =\n(\nif argc >= 3\n then g0string2int(argv[2]) else 0\n\/\/ end of [if]\n) : int \/\/ end of [val]\n\/\/\nval a0 = g1ofg0(a0)\nand a1 = g1ofg0(a1)\n\/\/\nval () = assertloc (a0 >= 0)\nval () = assertloc (a1 >= 0)\n\/\/\nval () =\nprintln!\n (a0, \" + \", a1, \" = \", add_int_int(a0, a1))\n\/\/\nval _(*left*) = $UNISTD.usleep(250000u)\n\/\/\n} (* end of [main0] *)\n\n(* ****** ****** *)\n\n(* end of [bitstr.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"4f5ded8a6e05109a3e165d8a90fe0b62dc80783a","subject":"Updating: very very minorly","message":"Updating: very very minorly\n","repos":"githwxi\/ATS-Postiats-frozen,githwxi\/ATS-Postiats-frozen,githwxi\/ATS-Postiats-frozen,githwxi\/ATS-Postiats-frozen,githwxi\/ATS-Postiats-frozen,githwxi\/ATS-Postiats-frozen,githwxi\/ATS-Postiats-frozen,githwxi\/ATS-Postiats-frozen,githwxi\/ATS-Postiats-frozen","old_file":"projects\/SMALL\/openshift-python-2016-07-20\/MYCODE\/hello.dats","new_file":"projects\/SMALL\/openshift-python-2016-07-20\/MYCODE\/hello.dats","new_contents":"(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_define.hats\"\n#include\n\"{$LIBATSCC2PY3}\/staloadall.hats\"\n\/\/\n(* ****** ****** *)\n\n#define ATS_DYNLOADFLAG 0\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nhello(): string = \"mac#\"\n\/\/\nimplement\nhello() =\n\"Hello from [patsopt+atscc2py3]!\"\n\/\/\n(* ****** ****** *)\n%{^\nimport sys\n######\nfrom libatscc2py_all import *\n######\nsys.setrecursionlimit(1000000)\n######\n%} \/\/ end of [%{^]\n\n(* ****** ****** *)\n\n(* end of [hello.dats] *)\n","old_contents":"(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_define.hats\"\n#include\n\"{$LIBATSCC2PY3}\/staloadall.hats\"\n\/\/\n(* ****** ****** *)\n\n#define ATS_DYNLOADFLAG 0\n\n(* ****** ****** *)\n\/\/\nextern\nfun hello(): string = \"mac#\"\n\/\/\nimplement\nhello() = \"Hello from [patsopt+atscc2py3]!\"\n\/\/\n(* ****** ****** *)\n%{^\nimport sys\n######\nfrom libatscc2py_all import *\n######\nsys.setrecursionlimit(1000000)\n######\n%} \/\/ end of [%{^]\n\n(* ****** ****** *)\n\n(* end of [hello.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"5426d1588a94f08c64558579dedf05976b066f37","subject":"Updating: scratching a bit","message":"Updating: scratching a bit\n","repos":"ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib","old_file":"projects\/MEDIUM\/ATS-parse-emit\/Erlang\/SCRATCH\/scratch03.dats","new_file":"projects\/MEDIUM\/ATS-parse-emit\/Erlang\/SCRATCH\/scratch03.dats","new_contents":"(* ****** ****** *)\n\/\/\n\/\/ HX-2014-12-23:\n\/\/ For the purpose of\n\/\/ studying session types\n\/\/\n(* ****** ****** *)\n\n(*\nclient1: send(int) -> recv(int)\nclient2: send(int) -> send(int) -> recv(int)\n*)\n\n(* ****** ****** *)\n\n(*\nserver1: recv(int) -> send(int)\nserver2: recv(int) -> recv(int) -> send(int)\n*)\n\n(* ****** ****** *)\n\ntypedef str = string\n\n(* ****** ****** *)\n\nstadef nil = unit_v\nstadef :: (a:view, b:view) = (a, b)\n\n(* ****** ****** *)\n\/\/\nabsview send_v (a:t@ype)\nabsview recv_v (a:t@ype)\n\/\/\n(* ****** ****** *)\n\/\/\nviewdef \/\/ for accessing a unary service\nclient1_v = send_v(int) :: recv_v(int) :: nil\nviewdef \/\/ for accessing a binary service\nclient2_v = send_v(int) :: send_v(int) :: recv_v(int) :: nil\n\/\/\n(* ****** ****** *)\n\nviewdef \/\/ for providing a unary service\nserver1_v = recv_v(int) :: send_v(int) :: nil\nviewdef \/\/ for providing a binary service\nserver2_v = recv_v(int) :: recv_v(int) :: send_v(int) :: nil\n\n(* ****** ****** *)\n\nabsview\nadisj_v (v1:view, v2: view)\nextern\npraxi adisj_v_left : {v1,v2:view} (v1) -> adisj_v (v1, v2)\nextern\npraxi adisj_v_right : {v1,v2:view} (v2) -> adisj_v (v1, v2)\n\n(* ****** ****** *)\n\nextern\nfun client1 (pf: client1_v | (*void*)): void\nextern\nfun client2 (pf: client2_v | (*void*)): void\n\n(* ****** ****** *)\n\/\/\nabsview\naconj (v1:view, v2:view)\ndatavtype\nadisj_vt (v1:view, v2:view) =\n | adisj_vt_left (v1, v2) of (v1 | (*void*))\n | adisj_vt_right (v1, v2) of (v2 | (*void*))\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun inject_l{v1,v2:view}\n(\n pf: !v1 >> adisj_v (v1, v2) | (*void*)\n) : adisj_vt (v1, v2) \/\/ end of [inject_l]\nextern\nfun inject_r{v1,v2:view}\n(\n pf: !v2 >> adisj_v (v1, v2) | (*void*)\n) : adisj_vt (v1, v2) \/\/ end of [inject_r]\n\/\/\nextern\nfun choose_conj{v1,v2:view}\n (pf: aconj (v1, v2) | (*void*)): adisj_vt (v1, v2)\n\/\/\n(* ****** ****** *)\n\nextern\nfun server1 (pf: server1_v | (*void*)): void\nextern\nfun server2 (pf: server2_v | (*void*)): void\nextern \/\/ [server] combines [server1] and [server2]\nfun server (pf: aconj (server1_v, server2_v) | (*void*)): void\n\n(* ****** ****** *)\n\nimplement\nserver(pf | (*void*)) = let\n val tag = choose_conj (pf | (*void*))\nin\n case+ tag of\n | ~adisj_vt_left (pf1 | ) => server1 (pf1 | (*void*))\n | ~adisj_vt_right (pf2 | ) => server2 (pf2 | (*void*))\nend \/\/ end of [server]\n\n(* ****** ****** *)\n\n(* end of [scratch03.dats] *)\n","old_contents":"(* ****** ****** *)\n\/\/\n\/\/ HX-2014-12-23:\n\/\/ For the purpose of\n\/\/ studying session types\n\/\/\n(* ****** ****** *)\n\n(*\nclient1: send(int) -> recv(int)\nclient2: send(int) -> send(int) -> recv(int)\n*)\n\n(* ****** ****** *)\n\n(*\nserver1: recv(int) -> send(int)\nserver2: recv(int) -> recv(int) -> send(int)\n*)\n\n(* ****** ****** *)\n\ntypedef str = string\n\n(* ****** ****** *)\n\nstadef nil = unit_v\nstadef :: (a:view, b:view) = (a, b)\n\n(* ****** ****** *)\n\/\/\nabsview send_v (a:t@ype)\nabsview recv_v (a:t@ype)\n\/\/\n(* ****** ****** *)\n\nviewdef\nclient1_v = send_v(int) :: recv_v(int) :: nil\nviewdef\nclient2_v = send_v(int) :: send_v(int) :: recv_v(int) :: nil\n\n(* ****** ****** *)\n\nviewdef\nserver1_v = recv_v(int) :: send_v(int) :: nil\nviewdef\nserver2_v = recv_v(int) :: recv_v(int) :: send_v(int) :: nil\n\n(* ****** ****** *)\n\nabsview\nadisj_v (v1:view, v2: view)\nextern\npraxi adisj_v_left : {v1,v2:view} (v1) -> adisj_v (v1, v2)\nextern\npraxi adisj_v_right : {v1,v2:view} (v2) -> adisj_v (v1, v2)\n\n(* ****** ****** *)\n\nextern\nfun client1 (pf: client1_v | (*void*)): void\nextern\nfun client2 (pf: client2_v | (*void*)): void\n\n(* ****** ****** *)\n\/\/\nabsview\naconj (v1:view, v2:view)\ndatavtype\nadisj_vt (v1:view, v2:view) =\n | adisj_vt_left (v1, v2) of (v1 | (*void*))\n | adisj_vt_right (v1, v2) of (v2 | (*void*))\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun inject_l{v1,v2:view}\n(\n pf: !v1 >> adisj_v (v1, v2) | (*void*)\n) : adisj_vt (v1, v2) \/\/ end of [inject_l]\nextern\nfun inject_r{v1,v2:view}\n(\n pf: !v2 >> adisj_v (v1, v2) | (*void*)\n) : adisj_vt (v1, v2) \/\/ end of [inject_r]\n\/\/\nextern\nfun choose_conj{v1,v2:view}\n (pf: aconj (v1, v2) | (*void*)): adisj_vt (v1, v2)\n\/\/\n(* ****** ****** *)\n\nextern\nfun server1 (pf: server1_v | (*void*)): void\nextern\nfun server2 (pf: server2_v | (*void*)): void\nextern\nfun server (pf: aconj (server1_v, server2_v) | (*void*)): void\n\n(* ****** ****** *)\n\nimplement\nserver(pf | (*void*)) = let\n val tag = choose_conj (pf | (*void*))\nin\n case+ tag of\n | ~adisj_vt_left (pf1 | ) => server1 (pf1 | (*void*))\n | ~adisj_vt_right (pf2 | ) => server2 (pf2 | (*void*))\nend \/\/ end of [server]\n\n(* ****** ****** *)\n\n(* end of [scratch03.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"a34685d2d547779c980fc51f1e2710202e8dec87","subject":"Updating: very minorly improving","message":"Updating: very minorly improving\n","repos":"ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib","old_file":"projects\/MEDIUM\/CATS-atsccomp\/CATS-atscc2scm\/atscc2scm_emit.dats","new_file":"projects\/MEDIUM\/CATS-atsccomp\/CATS-atscc2scm\/atscc2scm_emit.dats","new_contents":"(* ****** ****** *)\n\/\/\n\/\/ Atscc2scm:\n\/\/ from ATS to Scheme\n\/\/\n(* ****** ****** *)\n\/\/\n\/\/ HX-2016-05-19: start\n\/\/\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_staload.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\nUN = \"prelude\/SATS\/unsafe.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\n#define\nCATSPARSEMIT_targetloc \".\/.CATS-parsemit\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \"{$CATSPARSEMIT}\/catsparse.sats\"\n\/\/\nstaload \"{$CATSPARSEMIT}\/catsparse_syntax.sats\"\n\/\/\nstaload \"{$CATSPARSEMIT}\/catsparse_emit.sats\"\n\/\/\nstaload \"{$CATSPARSEMIT}\/catsparse_typedef.sats\"\nstaload \"{$CATSPARSEMIT}\/catsparse_fundecl.sats\"\n\/\/\n(* ****** ****** *)\n\nlocal\n\nstaload\nTM = \"libc\/SATS\/time.sats\"\nstadef time_t = $TM.time_t\n\nin (* in-of-local *)\n\nimplement\nemit_time_stamp (out) = let\n\/\/\nvar tm: time_t\nval () = tm := $TM.time_get ()\nval (pfopt | p_tm) = $TM.localtime (tm)\n\/\/\nval () = emit_text (out, \";;;;;;\\n\");\nval () = emit_text (out, \";;\\n\");\nval () = emit_text (out, \";; The Scheme code is generated by atscc2scm\\n\")\nval () = emit_text (out, \";; The starting compilation time is: \")\n\/\/\nval () =\nif\np_tm > 0\nthen let\n prval Some_v @(pf1, fpf1) = pfopt\n val tm_min = $TM.tm_get_min (!p_tm)\n val tm_hour = $TM.tm_get_hour (!p_tm)\n val tm_mday = $TM.tm_get_mday (!p_tm)\n val tm_mon = 1 + $TM.tm_get_mon (!p_tm)\n val tm_year = 1900 + $TM.tm_get_year (!p_tm)\n prval () = fpf1 (pf1)\nin\n $extfcall\n (\n void\n , \"fprintf\"\n , out, \"%i-%i-%i: %2ih:%2im\\n\", tm_year, tm_mon, tm_mday, tm_hour, tm_min\n )\nend \/\/ end of [then]\nelse let\n prval None_v () = pfopt\nin\n emit_text (out, \"**TIME-ERROR**\\n\")\nend \/\/ end of [else]\n\/\/\nval () = emit_text (out, \";;\\n\")\nval () = emit_text (out, \";;;;;;\\n\")\n\/\/\nin\n \/\/ emit_newline (out)\nend \/\/ end of [emit_time_stamp]\n\nend \/\/ end of [local]\n\n(* ****** ****** *)\n\nimplement\nemit_PMVint\n (out, tok) = let\n\/\/\nval-T_INT(base, rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVint]\n\/\/\nimplement\nemit_PMVintrep\n (out, tok) = let\n\/\/\nval-T_INT(base, rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVintrep]\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_PMVbool\n (out, tfv) = (\n\/\/\nemit_text\n( out\n, if tfv then \"true\" else \"false\"\n) (* end of [emit_text] *)\n\/\/\n) (* end of [emit_PMVbool] *)\n\n(* ****** ****** *)\n\nimplement\nemit_PMVstring\n (out, tok) = let\n\/\/\nval-T_STRING(rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVstring]\n\n(* ****** ****** *)\n\nimplement\nemit_PMVfloat\n (out, tok) = let\n\/\/\nval-T_FLOAT(base, rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVfloat]\n\n(* ****** ****** *)\n\nimplement\nemit_PMVi0nt\n (out, tok) = let\n\/\/\nval-T_INT(base, rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVi0nt]\n\n(* ****** ****** *)\n\nimplement\nemit_PMVf0loat\n (out, tok) = let\n\/\/\nval-T_FLOAT(base, rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVf0loat]\n\n(* ****** ****** *)\n\/\/\nimplement\nemit_PMVempty\n (out, _) = emit_text (out, \"null\")\n\/\/ \nimplement\nemit_PMVextval\n (out, toks) = emit_tokenlst (out, toks)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nf0ide_get_arity (fid: i0de): int\n\/\/\nimplement\nf0ide_get_arity\n (fid) = let\n\/\/\nval\nopt =\nf0head_search_opt(fid.i0dex_sym)\n\/\/\nin\n\/\/\ncase+ opt of\n| ~None_vt() => ~1\n| ~Some_vt(fhd) =>\n (\n case+\n fhd.f0head_node\n of \/\/ case+\n | F0HEAD(fid, fma, _) =>\n list_length (fma.f0marg_node)\n \/\/ end of [F0HEAD]\n ) (* end of [Some_vt] *)\n\/\/\nend \/\/ end of [f0ide_get_arity]\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit_f0ide\n : emit_type (i0de) = \"ext#atscc2scm_emit_f0ide\"\nextern\nfun\nemit_flabel\n : emit_type (label) = \"ext#atscc2scm_emit_flabel\"\n\/\/\nimplement\nemit_f0ide\n (out, fid) = let\n\/\/\nval sym = fid.i0dex_sym\nval name = symbol_get_name(sym)\n\/\/\nval c0 =\n $UN.ptr0_get (string2ptr(name))\n\/\/\nval () = if c0 = '_' then emit_text(out, \"f\")\n\/\/\nin\n emit_symbol(out, sym)\nend \/\/ end of [emit_f0ide]\n\/\/\nimplement\nemit_flabel\n (out, flab) = emit_f0ide (out, flab)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nemit_PMVfunlab\n (out, flab) =\n{\n\/\/\nval n0 = f0ide_get_arity(flab)\n\/\/\nval () = emit_text(out, \"fun \")\nval () = emit_flabel (out, flab)\nval () = (emit_text(out, \"\/\"); emit_int(out, n0))\n\/\/\n} (* end of [emit_PMVfunlab] *)\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_PMVcfunlab\n (out, flab, d0es_env) =\n{\n\/\/\nval () = emit_LPAREN (out)\n\/\/\nval () =\n emit_flabel (out, flab)\nval () =\n emit_text (out, \"__closurerize\")\n\/\/\nval () = emit_d0explst_1 (out, d0es_env)\nval () = emit_RPAREN (out)\n\/\/\n} (* end of [emit_PMVcfunlab] *)\n\n(* ****** ****** *)\n\nimplement\nemit_CSTSPmyloc\n (out, tok) = let\n\/\/\nval-T_STRING(rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_CSTSPmyloc]\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit_fname_d0exp\n : (FILEref, string, d0exp) -> void\nextern\nfun\nemit_fname_d0exp2\n : (FILEref, string, d0exp, d0exp) -> void\nextern\nfun\nemit_fname_d0exp_int\n : (FILEref, string, d0exp, int(*ctag*)) -> void\n\/\/\nimplement\nemit_fname_d0exp\n (out, fname, d0e) =\n{\n\/\/\nval () = emit_LPAREN (out)\n\/\/\nval () = (\n emit_text (out, fname); emit_SPACE (out); emit_d0exp (out, d0e)\n) (* end of [val] *)\n\/\/\nval () = emit_RPAREN (out)\n\/\/\n} (* end of [emit_fname_d0exp] *)\n\/\/\nimplement\nemit_fname_d0exp2\n (out, fname, d0e1, d0e2) =\n{\n\/\/\nval () = emit_LPAREN (out)\nval () =\n(\n emit_text (out, fname); emit_SPACE (out); \n emit_d0exp (out, d0e1); emit_SPACE (out); emit_d0exp (out, d0e2)\n)\nval () = emit_RPAREN (out)\n\/\/\n} (* end of [emit_fname_d0exp2] *)\n\/\/\nimplement\nemit_fname_d0exp_int\n (out, fname, d0e, ctag) =\n{\n\/\/\nval () = emit_LPAREN (out)\nval () =\n(\n emit_text (out, fname); emit_SPACE (out); \n emit_d0exp (out, d0e); emit_SPACE (out); emit_int (out, ctag)\n)\nval () = emit_RPAREN (out)\n\/\/\n} (* end of [emit_fname_d0exp_int] *)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nemit_ATSCKiseqz(out, d0e) =\n emit_fname_d0exp(out, \"ATSCKiseqz\", d0e)\nimplement\nemit_ATSCKisneqz(out, d0e) =\n emit_fname_d0exp(out, \"ATSCKisneqz\", d0e)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nemit_ATSCKptriscons(out, d0e) =\n emit_fname_d0exp(out, \"ATSCKptriscons\", d0e)\nimplement\nemit_ATSCKptrisnull(out, d0e) =\n emit_fname_d0exp(out, \"ATSCKptrisnull\", d0e)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nemit_ATSCKpat_int\n (out, d0e, i0) =\n emit_fname_d0exp2 (out, \"ATSCKpat_int\", d0e, i0)\nimplement\nemit_ATSCKpat_bool\n (out, d0e, b0) =\n emit_fname_d0exp2 (out, \"ATSCKpat_bool\", d0e, b0)\nimplement\nemit_ATSCKpat_string\n (out, d0e, s0) =\n emit_fname_d0exp2 (out, \"ATSCKpat_string\", d0e, s0)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nemit_ATSCKpat_con0\n (out, d0e, ctag) =\n emit_fname_d0exp_int (out, \"ATSCKpat_con0\", d0e, ctag)\nimplement\nemit_ATSCKpat_con1\n (out, d0e, ctag) =\n emit_fname_d0exp_int (out, \"ATSCKpat_con1\", d0e, ctag)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nemit_tmpvar\n (out, tmp) = let\n\/\/\nval\nsym = tmp.i0dex_sym\nval\nname =\ng1ofg0(symbol_get_name(sym))\n\/\/\nin\n\/\/\nif\nisneqz(name)\nthen (\n emit_text(out, name)\n) (* end of [then] *)\nelse () \/\/ end of [else]\n\/\/\nend \/\/ end of [emit_tmpvar]\n\/\/\n(* ****** ****** *)\n\nfun\ns0exp_get_arity\n (s0e: s0exp): int =\n(\ncase+\ns0e.s0exp_node\nof \/\/ case+\n| S0Elist(s0es) => list_length(s0es) | _ => ~1\n) (* end of [s0exp_get_arity] *)\n\n(* ****** ****** *)\n\nimplement\nemit_d0exp\n (out, d0e0) = let\nin\n\/\/\ncase+\nd0e0.d0exp_node of\n\/\/\n| D0Eide (tmp) => \n {\n val () = emit_tmpvar (out, tmp)\n }\n\/\/\n| D0Eappid (fid, d0es) =>\n {\n val () = emit_LPAREN (out)\n val () = emit_f0ide (out, fid)\n val () = emit_d0explst_1 (out, d0es)\n val () = emit_RPAREN (out)\n }\n| D0Eappexp (d0e, d0es) =>\n {\n val () = emit_LPAREN (out)\n val () = emit_d0exp (out, d0e)\n val () = emit_d0explst_1 (out, d0es)\n val () = emit_RPAREN (out)\n }\n\/\/\n| D0Elist (d0es) =>\n {\n val () = emit_LPAREN (out)\n val () = emit_text (out, \"D0Elist\")\n val () = emit_d0explst_1 (out, d0es)\n val () = emit_RPAREN (out)\n }\n\/\/\n| ATSPMVint (int) => emit_PMVint (out, int)\n| ATSPMVintrep (int) => emit_PMVintrep (out, int)\n\/\/\n| ATSPMVbool (tfv) => emit_PMVbool (out, tfv)\n\/\/\n| ATSPMVfloat (flt) => emit_PMVfloat (out, flt)\n\/\/\n| ATSPMVstring (str) => emit_PMVstring (out, str)\n\/\/\n| ATSPMVi0nt (int) => emit_PMVi0nt (out, int)\n| ATSPMVf0loat (flt) => emit_PMVf0loat (out, flt)\n\/\/\n| ATSPMVempty (dummy) => emit_PMVempty (out, 0)\n| ATSPMVextval (toklst) => emit_PMVextval (out, toklst)\n\/\/\n| ATSPMVrefarg0 (d0e) => emit_d0exp (out, d0e)\n| ATSPMVrefarg1 (d0e) => emit_d0exp (out, d0e)\n\/\/\n| ATSPMVfunlab (fl) => emit_PMVfunlab (out, fl)\n| ATSPMVcfunlab\n (_(*knd*), fl, d0es) => emit_PMVcfunlab (out, fl, d0es)\n \/\/ end of [ATSPMVcfunlab]\n\/\/\n| ATSPMVcastfn\n (_(*fid*), _(*s0e*), arg) => emit_d0exp (out, arg)\n\/\/\n| ATSCSTSPmyloc (tok) => emit_CSTSPmyloc (out, tok)\n\/\/\n\/\/\n| ATSCKiseqz(d0e) => emit_ATSCKiseqz (out, d0e)\n| ATSCKisneqz(d0e) => emit_ATSCKisneqz (out, d0e)\n| ATSCKptriscons(d0e) => emit_ATSCKptriscons (out, d0e)\n| ATSCKptrisnull(d0e) => emit_ATSCKptrisnull (out, d0e)\n\/\/\n| ATSCKpat_int\n (d0e, int) => emit_ATSCKpat_int (out, d0e, int)\n| ATSCKpat_bool\n (d0e, bool) => emit_ATSCKpat_bool (out, d0e, bool)\n| ATSCKpat_string\n (d0e, string) => emit_ATSCKpat_string (out, d0e, string)\n\/\/\n| ATSCKpat_con0\n (d0e, ctag) => emit_ATSCKpat_con0 (out, d0e, ctag)\n| ATSCKpat_con1\n (d0e, ctag) => emit_ATSCKpat_con1 (out, d0e, ctag)\n\/\/\n| ATSSELcon _ => emit_SELcon (out, d0e0)\n| ATSSELrecsin _ => emit_SELrecsin (out, d0e0)\n| ATSSELboxrec _ => emit_SELboxrec (out, d0e0)\n| ATSSELfltrec _ => emit_text (out, \"ATSSELfltrec(...)\")\n\/\/\n| ATSextfcall\n (_fun, _arg) => {\n val () = emit_i0de (out, _fun)\n val () = emit_d0exparg (out, _arg)\n } (* end of [ATSextfcall] *)\n| ATSextmcall\n (_obj, _mtd, _arg) => {\n\/\/\n val () = emit_d0exp (out, _obj)\n val () = emit_DOT (out)\n val () = emit_d0exp (out, _mtd)\n\/\/\n val () = emit_d0exparg (out, _arg)\n\/\/\n } (* end of [ATSextmcall] *)\n\/\/\n| ATSfunclo_fun\n (\n d0e_fun, s0e_arg, _(*res*)\n ) =>\n {\n val () =\n emit_text\n (out, \"?ATSfunclo_fun\")\n \/\/ end of [val]\n val () =\n (\n emit_LPAREN (out); emit_d0exp (out, d0e_fun); emit_RPAREN (out)\n ) (* end of [val] *)\n } (* end of [ATSfunclo_fun] *)\n\/\/\n| ATSfunclo_clo\n (\n d0e_fun, _(*arg*), _(*res*)\n ) =>\n {\n val () =\n emit_text(out, \"?ATSfunclo_clo\")\n val () =\n (\n emit_LPAREN (out); emit_d0exp (out, d0e_fun); emit_RPAREN (out)\n ) (* end of [val] *)\n } (* end of [ATSfunclo_clo] *)\n\/\/\nend \/\/ end of [emit_d0exp]\n\n(* ****** ****** *)\n\nlocal\n\nfun\nloop\n(\n out: FILEref, d0es: d0explst, i: int\n) : void =\n(\ncase+ d0es of\n| list_nil () => ()\n| list_cons (d0e, d0es) => let\n val () =\n if i > 0 then emit_SPACE(out)\n \/\/ end of [val]\n in\n emit_d0exp (out, d0e); loop (out, d0es, i+1)\n end \/\/ end of [list_cons]\n)\n\nin (* in-of-local *)\n\nimplement\nemit_d0explst (out, d0es) = loop (out, d0es, 0)\nimplement\nemit_d0explst_1 (out, d0es) = loop (out, d0es, 1)\n\nend \/\/ end of [local]\n\n(* ****** ****** *)\n\nimplement\nemit_d0exparg\n (out, d0es) = \n{\n\/\/\nval () = emit_LPAREN (out)\nval () = emit_d0explst (out, d0es)\nval () = emit_RPAREN (out)\n\/\/\n} (* end of [emit_d0exparg] *)\n\n(* ****** ****** *)\n\/\/\nextern\nfun\ntyrec_labsel\n (tyrec: tyrec, lab: symbol): int\n\/\/\nimplement\ntyrec_labsel\n (tyrec, lab) = let\n\/\/\nfun loop\n(\n xs: tyfldlst, i: int\n) : int =\n(\ncase+ xs of\n| list_cons (x, xs) => let\n val TYFLD (id, s0e) = x.tyfld_node\n in\n if lab = id.i0dex_sym then i else loop (xs, i+1)\n end \/\/ end of [list_cons\n| list_nil ((*void*)) => ~1(*error*)\n)\n\/\/\nin\n loop (tyrec.tyrec_node, 0)\nend \/\/ end of [tyrec_labsel]\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_SELcon\n (out, d0e) = let\n\/\/\nval-\nATSSELcon\n (d0rec, s0e, id) = d0e.d0exp_node\n\/\/\nval-S0Eide(name) = s0e.s0exp_node\nval-~Some_vt(s0rec) = typedef_search_opt(name)\n\/\/\nval tupi = tyrec_labsel(s0rec, id.i0dex_sym)\n\/\/\nval () =\nemit_text\n (out, \"(ATSSELcon \")\n\/\/\nval () =\n(\n emit_d0exp (out, d0rec); emit_SPACE(out); emit_int (out, tupi)\n) (* end of [val] *)\n\/\/\nval () = emit_RPAREN (out)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit_SELcon]\n\n(* ****** ****** *)\n\nimplement\nemit_SELrecsin\n (out, d0e) = let\n\/\/\nval-\nATSSELrecsin\n (d0rec, s0e, id) = d0e.d0exp_node\n\/\/\nin\n emit_d0exp (out, d0rec)\nend \/\/ end of [emit_SELrecsin]\n\n(* ****** ****** *)\n\nimplement\nemit_SELboxrec\n (out, d0e) = let\n\/\/\nval-\nATSSELboxrec\n (d0rec, s0e, id) = d0e.d0exp_node\n\/\/\nval-S0Eide(name) = s0e.s0exp_node\nval-~Some_vt(s0rec) = typedef_search_opt(name)\n\/\/\nval tupi = tyrec_labsel(s0rec, id.i0dex_sym)\n\/\/\nval () =\nemit_text\n (out, \"(ATSSELboxrec \")\n\/\/\n\/\/\nval () =\n(\n emit_d0exp (out, d0rec); emit_SPACE(out); emit_int (out, tupi)\n) (* end of [val] *)\n\/\/\nval () = emit_RPAREN (out)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit_SELboxrec]\n\n(* ****** ****** *)\n\/\/\nimplement\nemit_COMMENT_line\n (out, tok) = let\n\/\/\nval-\nT_COMMENT_line\n (str) = tok.token_node\n\/\/\nin\n emit_text (out, str)\nend \/\/ end of [emit_COMMENT_line]\n\/\/\nimplement\nemit_COMMENT_block\n (out, tok) = let\n\/\/\nval-\nT_COMMENT_block\n (str) = tok.token_node\n\/\/\nin\n emit_text (out, str)\nend \/\/ end of [emit_COMMENT_block]\n\/\/\n(* ****** ****** *)\n\nlocal\n\nfun\naux0_cenv\n(\n out: FILEref\n, s0es: s0explst\n) : void = let\n\/\/\nfun\nauxlst\n(\n i: int, s0es: s0explst\n) : void =\n(\ncase+ s0es of\n| list_nil() => ()\n| list_cons\n (_, s0es) => let\n val () =\n emit_text(out, \", \")\n val () =\n (\n emit_text(out, \"Cenv\"); emit_int(out, i)\n )\n in\n auxlst(i+1, s0es)\n end \/\/ end of [auxlst]\n)\n\/\/\nval () = emit_LBRACE(out)\nval () = (emit_text(out, \"_\"); auxlst(1, s0es))\nval () = emit_RBRACE(out)\n\/\/\nin\n \/\/ nothing\nend (* end of [aux0_cenv] *)\n\nfun\naux0_arglst\n(\n out: FILEref\n, s0es: s0explst\n, n0: int, i: int\n) : void = (\n\/\/\ncase+ s0es of\n| list_nil\n ((*void*)) => ()\n| list_cons\n (s0e, s0es) => let\n val () =\n if n0+i > 0\n then emit_text (out, \", \")\n \/\/ end of [val]\n val () =\n (\n emit_text (out, \"XArg\"); emit_int (out, i)\n ) (* end of [val] *)\n in\n aux0_arglst (out, s0es, n0, i+1)\n end \/\/ end of [list_cons]\n\/\/\n) (* end of [aux0_arglst] *)\n\nfun\naux0_envlst\n(\n out: FILEref\n, s0es: s0explst\n, n0: int, i: int\n) : void = (\n\/\/\ncase+ s0es of\n| list_nil () => ()\n| list_cons\n (s0e, s0es) => let\n val () =\n if n0+i > 0\n then emit_text (out, \", \")\n \/\/ end of [val]\n val () =\n (\n emit_text (out, \"XEnv\"); emit_int (out, i)\n ) (* end of [val] *)\n in\n aux0_envlst (out, s0es, n0, i+1)\n end \/\/ end of [list_cons]\n\/\/\n) (* end of [aux0_envlst] *)\n\nfun\naux1_envlst\n(\n out: FILEref\n, s0es: s0explst, i: int\n) : int =\n(\ncase+ s0es of\n| list_nil\n ((*void*)) => (i)\n| list_cons\n (s0e, s0es) => let\n val () =\n if i > 0\n then emit_text (out, \", \")\n \/\/ end of [val]\n val () =\n (\n emit_text (out, \"Cenv\"); emit_int (out, i+1)\n ) (* end of [val] *)\n in\n aux1_envlst (out, s0es, i+1)\n end \/\/ end of [list_cons]\n) (* end of [aux1_envlst] *)\n\nin (* in-of-local *)\n\nimplement\nemit_closurerize\n(\n out, flab, env, arg, res\n) = let\n\/\/\nval-S0Elist(s0es_env) = env.s0exp_node\nval-S0Elist(s0es_arg) = arg.s0exp_node\n\/\/\nval () = emit_ENDL (out)\n\/\/\n(*\nval () =\nemit_text (out, \";;fun;;\\n\")\n*)\nval () = emit_flabel (out, flab)\nval () =\nemit_text (out, \"__closurerize(\")\nval () = aux0_envlst (out, s0es_env, 0, 0)\nval ((*closing*)) = emit_text (out, \") -> \\n\")\n\/\/\nval ((*opening*)) = emit_text (out, \"%{\\n\")\n\/\/\nval () = emit_nspc (out, 2)\nval () = emit_text (out, \"{\")\nval () = emit_text (out, \"fun(\")\n\/\/\nval () = aux0_cenv (out, s0es_env)\nval () = aux0_arglst (out, s0es_arg, 1, 0)\n\/\/\nval () = emit_text (out, \") -> \")\n\/\/\nval () = emit_flabel (out, flab)\n\/\/\nval () = emit_LPAREN (out)\nval n0 = aux1_envlst (out, s0es_env, 0)\nval () = aux0_arglst (out, s0es_arg, n0, 0)\nval () = emit_RPAREN (out)\n\/\/\nval () = emit_text (out, \" end\")\n\/\/\nval () = aux0_envlst (out, s0es_env, 1, 0)\nval ((*closing*)) = emit_text (out, \"}.\\n%}\\n\")\n\/\/\nval ((*flushing*)) = emit_newline (out)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit_closurerize]\n\nend \/\/ end of [local]\n\n(* ****** ****** *)\n\n(* end of [atscc2scm_emit.dats] *)\n","old_contents":"(* ****** ****** *)\n\/\/\n\/\/ Atscc2scm:\n\/\/ from ATS to Scheme\n\/\/\n(* ****** ****** *)\n\/\/\n\/\/ HX-2016-05-19: start\n\/\/\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_staload.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\nUN = \"prelude\/SATS\/unsafe.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\n#define\nCATSPARSEMIT_targetloc \".\/.CATS-parsemit\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \"{$CATSPARSEMIT}\/catsparse.sats\"\n\/\/\nstaload \"{$CATSPARSEMIT}\/catsparse_syntax.sats\"\n\/\/\nstaload \"{$CATSPARSEMIT}\/catsparse_emit.sats\"\n\/\/\nstaload \"{$CATSPARSEMIT}\/catsparse_typedef.sats\"\nstaload \"{$CATSPARSEMIT}\/catsparse_fundecl.sats\"\n\/\/\n(* ****** ****** *)\n\nlocal\n\nstaload\nTM = \"libc\/SATS\/time.sats\"\nstadef time_t = $TM.time_t\n\nin (* in-of-local *)\n\nimplement\nemit_time_stamp (out) = let\n\/\/\nvar tm: time_t\nval () = tm := $TM.time_get ()\nval (pfopt | p_tm) = $TM.localtime (tm)\n\/\/\nval () = emit_text (out, \";;;;;;\\n\");\nval () = emit_text (out, \";;\\n\");\nval () = emit_text (out, \";; The Scheme code is generated by atscc2scm\\n\")\nval () = emit_text (out, \";; The starting compilation time is: \")\n\/\/\nval () =\nif\np_tm > 0\nthen let\n prval Some_v @(pf1, fpf1) = pfopt\n val tm_min = $TM.tm_get_min (!p_tm)\n val tm_hour = $TM.tm_get_hour (!p_tm)\n val tm_mday = $TM.tm_get_mday (!p_tm)\n val tm_mon = 1 + $TM.tm_get_mon (!p_tm)\n val tm_year = 1900 + $TM.tm_get_year (!p_tm)\n prval () = fpf1 (pf1)\nin\n $extfcall\n (\n void\n , \"fprintf\"\n , out, \"%i-%i-%i: %2ih:%2im\\n\", tm_year, tm_mon, tm_mday, tm_hour, tm_min\n )\nend \/\/ end of [then]\nelse let\n prval None_v () = pfopt\nin\n emit_text (out, \"**TIME-ERROR**\\n\")\nend \/\/ end of [else]\n\/\/\nval () = emit_text (out, \";;\\n\")\nval () = emit_text (out, \";;;;;;\\n\")\n\/\/\nin\n \/\/ emit_newline (out)\nend \/\/ end of [emit_time_stamp]\n\nend \/\/ end of [local]\n\n(* ****** ****** *)\n\nimplement\nemit_PMVint\n (out, tok) = let\n\/\/\nval-T_INT(base, rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVint]\n\/\/\nimplement\nemit_PMVintrep\n (out, tok) = let\n\/\/\nval-T_INT(base, rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVintrep]\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_PMVbool\n (out, tfv) = (\n\/\/\nemit_text\n( out\n, if tfv then \"true\" else \"false\"\n) (* end of [emit_text] *)\n\/\/\n) (* end of [emit_PMVbool] *)\n\n(* ****** ****** *)\n\nimplement\nemit_PMVstring\n (out, tok) = let\n\/\/\nval-T_STRING(rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVstring]\n\n(* ****** ****** *)\n\nimplement\nemit_PMVfloat\n (out, tok) = let\n\/\/\nval-T_FLOAT(base, rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVfloat]\n\n(* ****** ****** *)\n\nimplement\nemit_PMVi0nt\n (out, tok) = let\n\/\/\nval-T_INT(base, rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVi0nt]\n\n(* ****** ****** *)\n\nimplement\nemit_PMVf0loat\n (out, tok) = let\n\/\/\nval-T_FLOAT(base, rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVf0loat]\n\n(* ****** ****** *)\n\/\/\nimplement\nemit_PMVempty\n (out, _) = emit_text (out, \"null\")\n\/\/ \nimplement\nemit_PMVextval\n (out, toks) = emit_tokenlst (out, toks)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nf0ide_get_arity (fid: i0de): int\n\/\/\nimplement\nf0ide_get_arity\n (fid) = let\n\/\/\nval\nopt =\nf0head_search_opt(fid.i0dex_sym)\n\/\/\nin\n\/\/\ncase+ opt of\n| ~None_vt() => ~1\n| ~Some_vt(fhd) =>\n (\n case+\n fhd.f0head_node\n of \/\/ case+\n | F0HEAD(fid, fma, _) =>\n list_length (fma.f0marg_node)\n \/\/ end of [F0HEAD]\n ) (* end of [Some_vt] *)\n\/\/\nend \/\/ end of [f0ide_get_arity]\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit_f0ide\n : emit_type (i0de) = \"ext#atscc2scm_emit_f0ide\"\nextern\nfun\nemit_flabel\n : emit_type (label) = \"ext#atscc2scm_emit_flabel\"\n\/\/\nimplement\nemit_f0ide\n (out, fid) = let\n\/\/\nval sym = fid.i0dex_sym\nval name = symbol_get_name(sym)\n\/\/\nval c0 =\n $UN.ptr0_get (string2ptr(name))\n\/\/\nval () = if c0 = '_' then emit_text(out, \"f\")\n\/\/\nin\n emit_symbol(out, sym)\nend \/\/ end of [emit_f0ide]\n\/\/\nimplement\nemit_flabel\n (out, flab) = emit_f0ide (out, flab)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nemit_PMVfunlab\n (out, flab) =\n{\n\/\/\nval n0 = f0ide_get_arity(flab)\n\/\/\nval () = emit_text(out, \"fun \")\nval () = emit_flabel (out, flab)\nval () = (emit_text(out, \"\/\"); emit_int(out, n0))\n\/\/\n} (* end of [emit_PMVfunlab] *)\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_PMVcfunlab\n (out, flab, d0es_env) =\n{\n\/\/\nval () = emit_LPAREN (out)\n\/\/\nval () =\n emit_flabel (out, flab)\nval () =\n emit_text (out, \"__closurerize\")\n\/\/\nval () = emit_d0explst_1 (out, d0es_env)\nval () = emit_RPAREN (out)\n\/\/\n} (* end of [emit_PMVcfunlab] *)\n\n(* ****** ****** *)\n\nimplement\nemit_CSTSPmyloc\n (out, tok) = let\n\/\/\nval-T_STRING(rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_CSTSPmyloc]\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit_fname_d0exp\n : (FILEref, string, d0exp) -> void\nextern\nfun\nemit_fname_d0exp2\n : (FILEref, string, d0exp, d0exp) -> void\nextern\nfun\nemit_fname_d0exp_int\n : (FILEref, string, d0exp, int(*ctag*)) -> void\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nemit_ATSCKiseqz(out, d0e) =\n emit_fname_d0exp(out, \"ATSCKiseqz\", d0e)\nimplement\nemit_ATSCKisneqz(out, d0e) =\n emit_fname_d0exp(out, \"ATSCKisneqz\", d0e)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nemit_ATSCKptriscons(out, d0e) =\n emit_fname_d0exp(out, \"ATSCKptriscons\", d0e)\nimplement\nemit_ATSCKptrisnull(out, d0e) =\n emit_fname_d0exp(out, \"ATSCKptrisnull\", d0e)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nemit_ATSCKpat_int\n (out, d0e, i0) =\n emit_fname_d0exp2 (out, \"ATSCKpat_int\", d0e, i0)\nimplement\nemit_ATSCKpat_bool\n (out, d0e, b0) =\n emit_fname_d0exp2 (out, \"ATSCKpat_bool\", d0e, b0)\nimplement\nemit_ATSCKpat_string\n (out, d0e, s0) =\n emit_fname_d0exp2 (out, \"ATSCKpat_string\", d0e, s0)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nemit_ATSCKpat_con0\n (out, d0e, ctag) =\n emit_fname_d0exp_int (out, \"ATSCKpat_con0\", d0e, ctag)\nimplement\nemit_ATSCKpat_con1\n (out, d0e, ctag) =\n emit_fname_d0exp_int (out, \"ATSCKpat_con1\", d0e, ctag)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nemit_tmpvar\n (out, tmp) = let\n\/\/\nval\nsym = tmp.i0dex_sym\nval\nname =\ng1ofg0(symbol_get_name(sym))\n\/\/\nin\n\/\/\nif\nisneqz(name)\nthen (\n emit_text(out, name)\n) (* end of [then] *)\nelse () \/\/ end of [else]\n\/\/\nend \/\/ end of [emit_tmpvar]\n\/\/\n(* ****** ****** *)\n\nfun\ns0exp_get_arity\n (s0e: s0exp): int =\n(\ncase+\ns0e.s0exp_node\nof \/\/ case+\n| S0Elist(s0es) => list_length(s0es) | _ => ~1\n) (* end of [s0exp_get_arity] *)\n\n(* ****** ****** *)\n\nimplement\nemit_d0exp\n (out, d0e0) = let\nin\n\/\/\ncase+\nd0e0.d0exp_node of\n\/\/\n| D0Eide (tmp) => \n {\n val () = emit_tmpvar (out, tmp)\n }\n\/\/\n| D0Eappid (fid, d0es) =>\n {\n val () = emit_LPAREN (out)\n val () = emit_f0ide (out, fid)\n val () = emit_d0explst_1 (out, d0es)\n val () = emit_RPAREN (out)\n }\n| D0Eappexp (d0e, d0es) =>\n {\n val () = emit_LPAREN (out)\n val () = emit_d0exp (out, d0e)\n val () = emit_d0explst_1 (out, d0es)\n val () = emit_RPAREN (out)\n }\n\/\/\n| D0Elist (d0es) =>\n {\n val () = emit_LPAREN (out)\n val () = emit_text (out, \"D0Elist\")\n val () = emit_d0explst_1 (out, d0es)\n val () = emit_RPAREN (out)\n }\n\/\/\n| ATSPMVint (int) => emit_PMVint (out, int)\n| ATSPMVintrep (int) => emit_PMVintrep (out, int)\n\/\/\n| ATSPMVbool (tfv) => emit_PMVbool (out, tfv)\n\/\/\n| ATSPMVfloat (flt) => emit_PMVfloat (out, flt)\n\/\/\n| ATSPMVstring (str) => emit_PMVstring (out, str)\n\/\/\n| ATSPMVi0nt (int) => emit_PMVi0nt (out, int)\n| ATSPMVf0loat (flt) => emit_PMVf0loat (out, flt)\n\/\/\n| ATSPMVempty (dummy) => emit_PMVempty (out, 0)\n| ATSPMVextval (toklst) => emit_PMVextval (out, toklst)\n\/\/\n| ATSPMVrefarg0 (d0e) => emit_d0exp (out, d0e)\n| ATSPMVrefarg1 (d0e) => emit_d0exp (out, d0e)\n\/\/\n| ATSPMVfunlab (fl) => emit_PMVfunlab (out, fl)\n| ATSPMVcfunlab\n (_(*knd*), fl, d0es) => emit_PMVcfunlab (out, fl, d0es)\n \/\/ end of [ATSPMVcfunlab]\n\/\/\n| ATSPMVcastfn\n (_(*fid*), _(*s0e*), arg) => emit_d0exp (out, arg)\n\/\/\n| ATSCSTSPmyloc (tok) => emit_CSTSPmyloc (out, tok)\n\/\/\n\/\/\n| ATSCKiseqz(d0e) => emit_ATSCKiseqz (out, d0e)\n| ATSCKisneqz(d0e) => emit_ATSCKisneqz (out, d0e)\n| ATSCKptriscons(d0e) => emit_ATSCKptriscons (out, d0e)\n| ATSCKptrisnull(d0e) => emit_ATSCKptrisnull (out, d0e)\n\/\/\n| ATSCKpat_int\n (d0e, int) => emit_ATSCKpat_int (out, d0e, int)\n| ATSCKpat_bool\n (d0e, bool) => emit_ATSCKpat_bool (out, d0e, bool)\n| ATSCKpat_string\n (d0e, string) => emit_ATSCKpat_string (out, d0e, string)\n\/\/\n| ATSCKpat_con0\n (d0e, ctag) => emit_ATSCKpat_con0 (out, d0e, ctag)\n| ATSCKpat_con1\n (d0e, ctag) => emit_ATSCKpat_con1 (out, d0e, ctag)\n\/\/\n| ATSSELcon _ => emit_SELcon (out, d0e0)\n| ATSSELrecsin _ => emit_SELrecsin (out, d0e0)\n| ATSSELboxrec _ => emit_SELboxrec (out, d0e0)\n| ATSSELfltrec _ => emit_text (out, \"ATSSELfltrec(...)\")\n\/\/\n| ATSextfcall\n (_fun, _arg) => {\n val () = emit_i0de (out, _fun)\n val () = emit_d0exparg (out, _arg)\n } (* end of [ATSextfcall] *)\n| ATSextmcall\n (_obj, _mtd, _arg) => {\n\/\/\n val () = emit_d0exp (out, _obj)\n val () = emit_DOT (out)\n val () = emit_d0exp (out, _mtd)\n\/\/\n val () = emit_d0exparg (out, _arg)\n\/\/\n } (* end of [ATSextmcall] *)\n\/\/\n| ATSfunclo_fun\n (\n d0e_fun, s0e_arg, _(*res*)\n ) =>\n {\n val () =\n emit_text\n (out, \"?ATSfunclo_fun\")\n \/\/ end of [val]\n val () =\n (\n emit_LPAREN (out); emit_d0exp (out, d0e_fun); emit_RPAREN (out)\n ) (* end of [val] *)\n } (* end of [ATSfunclo_fun] *)\n\/\/\n| ATSfunclo_clo\n (\n d0e_fun, _(*arg*), _(*res*)\n ) =>\n {\n val () =\n emit_text(out, \"?ATSfunclo_clo\")\n val () =\n (\n emit_LPAREN (out); emit_d0exp (out, d0e_fun); emit_RPAREN (out)\n ) (* end of [val] *)\n } (* end of [ATSfunclo_clo] *)\n\/\/\nend \/\/ end of [emit_d0exp]\n\n(* ****** ****** *)\n\nlocal\n\nfun\nloop\n(\n out: FILEref, d0es: d0explst, i: int\n) : void =\n(\ncase+ d0es of\n| list_nil () => ()\n| list_cons (d0e, d0es) => let\n val () =\n if i > 0 then emit_SPACE(out)\n \/\/ end of [val]\n in\n emit_d0exp (out, d0e); loop (out, d0es, i+1)\n end \/\/ end of [list_cons]\n)\n\nin (* in-of-local *)\n\nimplement\nemit_d0explst (out, d0es) = loop (out, d0es, 0)\nimplement\nemit_d0explst_1 (out, d0es) = loop (out, d0es, 1)\n\nend \/\/ end of [local]\n\n(* ****** ****** *)\n\nimplement\nemit_d0exparg\n (out, d0es) = \n{\n\/\/\nval () = emit_LPAREN (out)\nval () = emit_d0explst (out, d0es)\nval () = emit_RPAREN (out)\n\/\/\n} (* end of [emit_d0exparg] *)\n\n(* ****** ****** *)\n\/\/\nextern\nfun\ntyrec_labsel\n (tyrec: tyrec, lab: symbol): int\n\/\/\nimplement\ntyrec_labsel\n (tyrec, lab) = let\n\/\/\nfun loop\n(\n xs: tyfldlst, i: int\n) : int =\n(\ncase+ xs of\n| list_cons (x, xs) => let\n val TYFLD (id, s0e) = x.tyfld_node\n in\n if lab = id.i0dex_sym then i else loop (xs, i+1)\n end \/\/ end of [list_cons\n| list_nil ((*void*)) => ~1(*error*)\n)\n\/\/\nin\n loop (tyrec.tyrec_node, 0)\nend \/\/ end of [tyrec_labsel]\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_SELcon\n (out, d0e) = let\n\/\/\nval-\nATSSELcon\n (d0rec, s0e, id) = d0e.d0exp_node\n\/\/\nval-S0Eide(name) = s0e.s0exp_node\nval-~Some_vt(s0rec) = typedef_search_opt(name)\n\/\/\nval tupi = tyrec_labsel(s0rec, id.i0dex_sym)\n\/\/\nval () =\nemit_text\n (out, \"(ATSSELcon \")\n\/\/\nval () =\n(\n emit_d0exp (out, d0rec); emit_SPACE(out); emit_int (out, tupi)\n) (* end of [val] *)\n\/\/\nval () = emit_RPAREN (out)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit_SELcon]\n\n(* ****** ****** *)\n\nimplement\nemit_SELrecsin\n (out, d0e) = let\n\/\/\nval-\nATSSELrecsin\n (d0rec, s0e, id) = d0e.d0exp_node\n\/\/\nin\n emit_d0exp (out, d0rec)\nend \/\/ end of [emit_SELrecsin]\n\n(* ****** ****** *)\n\nimplement\nemit_SELboxrec\n (out, d0e) = let\n\/\/\nval-\nATSSELboxrec\n (d0rec, s0e, id) = d0e.d0exp_node\n\/\/\nval-S0Eide(name) = s0e.s0exp_node\nval-~Some_vt(s0rec) = typedef_search_opt(name)\n\/\/\nval tupi = tyrec_labsel(s0rec, id.i0dex_sym)\n\/\/\nval () =\nemit_text\n (out, \"(ATSSELboxrec \")\n\/\/\n\/\/\nval () =\n(\n emit_d0exp (out, d0rec); emit_SPACE(out); emit_int (out, tupi)\n) (* end of [val] *)\n\/\/\nval () = emit_RPAREN (out)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit_SELboxrec]\n\n(* ****** ****** *)\n\/\/\nimplement\nemit_COMMENT_line\n (out, tok) = let\n\/\/\nval-\nT_COMMENT_line\n (str) = tok.token_node\n\/\/\nin\n emit_text (out, str)\nend \/\/ end of [emit_COMMENT_line]\n\/\/\nimplement\nemit_COMMENT_block\n (out, tok) = let\n\/\/\nval-\nT_COMMENT_block\n (str) = tok.token_node\n\/\/\nin\n emit_text (out, str)\nend \/\/ end of [emit_COMMENT_block]\n\/\/\n(* ****** ****** *)\n\nlocal\n\nfun\naux0_cenv\n(\n out: FILEref\n, s0es: s0explst\n) : void = let\n\/\/\nfun\nauxlst\n(\n i: int, s0es: s0explst\n) : void =\n(\ncase+ s0es of\n| list_nil() => ()\n| list_cons\n (_, s0es) => let\n val () =\n emit_text(out, \", \")\n val () =\n (\n emit_text(out, \"Cenv\"); emit_int(out, i)\n )\n in\n auxlst(i+1, s0es)\n end \/\/ end of [auxlst]\n)\n\/\/\nval () = emit_LBRACE(out)\nval () = (emit_text(out, \"_\"); auxlst(1, s0es))\nval () = emit_RBRACE(out)\n\/\/\nin\n \/\/ nothing\nend (* end of [aux0_cenv] *)\n\nfun\naux0_arglst\n(\n out: FILEref\n, s0es: s0explst\n, n0: int, i: int\n) : void = (\n\/\/\ncase+ s0es of\n| list_nil\n ((*void*)) => ()\n| list_cons\n (s0e, s0es) => let\n val () =\n if n0+i > 0\n then emit_text (out, \", \")\n \/\/ end of [val]\n val () =\n (\n emit_text (out, \"XArg\"); emit_int (out, i)\n ) (* end of [val] *)\n in\n aux0_arglst (out, s0es, n0, i+1)\n end \/\/ end of [list_cons]\n\/\/\n) (* end of [aux0_arglst] *)\n\nfun\naux0_envlst\n(\n out: FILEref\n, s0es: s0explst\n, n0: int, i: int\n) : void = (\n\/\/\ncase+ s0es of\n| list_nil () => ()\n| list_cons\n (s0e, s0es) => let\n val () =\n if n0+i > 0\n then emit_text (out, \", \")\n \/\/ end of [val]\n val () =\n (\n emit_text (out, \"XEnv\"); emit_int (out, i)\n ) (* end of [val] *)\n in\n aux0_envlst (out, s0es, n0, i+1)\n end \/\/ end of [list_cons]\n\/\/\n) (* end of [aux0_envlst] *)\n\nfun\naux1_envlst\n(\n out: FILEref\n, s0es: s0explst, i: int\n) : int =\n(\ncase+ s0es of\n| list_nil\n ((*void*)) => (i)\n| list_cons\n (s0e, s0es) => let\n val () =\n if i > 0\n then emit_text (out, \", \")\n \/\/ end of [val]\n val () =\n (\n emit_text (out, \"Cenv\"); emit_int (out, i+1)\n ) (* end of [val] *)\n in\n aux1_envlst (out, s0es, i+1)\n end \/\/ end of [list_cons]\n) (* end of [aux1_envlst] *)\n\nin (* in-of-local *)\n\nimplement\nemit_closurerize\n(\n out, flab, env, arg, res\n) = let\n\/\/\nval-S0Elist(s0es_env) = env.s0exp_node\nval-S0Elist(s0es_arg) = arg.s0exp_node\n\/\/\nval () = emit_ENDL (out)\n\/\/\n(*\nval () =\nemit_text (out, \";;fun;;\\n\")\n*)\nval () = emit_flabel (out, flab)\nval () =\nemit_text (out, \"__closurerize(\")\nval () = aux0_envlst (out, s0es_env, 0, 0)\nval ((*closing*)) = emit_text (out, \") -> \\n\")\n\/\/\nval ((*opening*)) = emit_text (out, \"%{\\n\")\n\/\/\nval () = emit_nspc (out, 2)\nval () = emit_text (out, \"{\")\nval () = emit_text (out, \"fun(\")\n\/\/\nval () = aux0_cenv (out, s0es_env)\nval () = aux0_arglst (out, s0es_arg, 1, 0)\n\/\/\nval () = emit_text (out, \") -> \")\n\/\/\nval () = emit_flabel (out, flab)\n\/\/\nval () = emit_LPAREN (out)\nval n0 = aux1_envlst (out, s0es_env, 0)\nval () = aux0_arglst (out, s0es_arg, n0, 0)\nval () = emit_RPAREN (out)\n\/\/\nval () = emit_text (out, \" end\")\n\/\/\nval () = aux0_envlst (out, s0es_env, 1, 0)\nval ((*closing*)) = emit_text (out, \"}.\\n%}\\n\")\n\/\/\nval ((*flushing*)) = emit_newline (out)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit_closurerize]\n\nend \/\/ end of [local]\n\n(* ****** ****** *)\n\n(* end of [atscc2scm_emit.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"19e73e740f07456457ecb9bbd358f1d846fc2c8e","subject":"Add termination metrics","message":"Add termination metrics\n","repos":"Proclivis\/arduino-ats,fpiot\/arduino-ats,fpiot\/arduino-ats,Proclivis\/arduino-ats","old_file":"demo\/lcd_greeting\/DATS\/main.dats","new_file":"demo\/lcd_greeting\/DATS\/main.dats","new_contents":"#include \"config.hats\"\n#include \"{$TOP}\/avr_prelude\/kernel_staload.hats\"\n\nstaload \"{$TOP}\/SATS\/arduino.sats\"\nstaload \"{$TOP}\/SATS\/lcd.sats\"\n\n#define MY_DELAY_MS 400.0\n#define LCD_WIDTH 16\n\nval g_str_atsrun = \"\"\nval g_str_message = \" ATS is a statically typed programming language that unifies implementation with formal specification. It is equipped with a highly expressive type system rooted in the framework Applied Type System, which gives the language its name. In particular, both dependent types and linear types are available in ATS. \"\n\nimplement main () = {\n fun loop {n:int}{i:nat | i < n} ..\n (lcd: !lcd_t, str: string (n), pos: size_t (i)): void = {\n val () = if pos + i2sz LCD_WIDTH <= length str then {\n val () = (lcd_setCursor (lcd, 1, 0); lcd_print (lcd, g_str_atsrun, i2sz 0, length g_str_atsrun))\n val () = (lcd_setCursor (lcd, 0, 1); lcd_print (lcd, str, pos, i2sz LCD_WIDTH))\n val () = delay_ms (MY_DELAY_MS)\n val () = loop (lcd, str, pos + 1)\n }\n }\n fun forever {n:int}{i:nat | i < n}\n (lcd: !lcd_t, str: string (n), pos: size_t (i)): void = {\n val () = loop (lcd, str, pos)\n val () = forever (lcd, str, pos)\n }\n val lcd = lcd_open (8, 13, 9, 4, 5, 6, 7)\n val () = forever (lcd, g_str_message, i2sz 0)\n val () = lcd_close lcd\n}\n","old_contents":"#include \"config.hats\"\n#include \"{$TOP}\/avr_prelude\/kernel_staload.hats\"\n\nstaload \"{$TOP}\/SATS\/arduino.sats\"\nstaload \"{$TOP}\/SATS\/lcd.sats\"\n\n#define MY_DELAY_MS 400.0\n#define LCD_WIDTH 16\n\nval g_str_atsrun = \"\"\nval g_str_message = \" ATS is a statically typed programming language that unifies implementation with formal specification. It is equipped with a highly expressive type system rooted in the framework Applied Type System, which gives the language its name. In particular, both dependent types and linear types are available in ATS. \"\n\nimplement main () = {\n fun loop {n:int}{i:nat | i < n}\n (lcd: !lcd_t, str: string (n), pos: size_t (i)): void = {\n val () = if pos + i2sz LCD_WIDTH <= length str then {\n val () = (lcd_setCursor (lcd, 1, 0); lcd_print (lcd, g_str_atsrun, i2sz 0, length g_str_atsrun))\n val () = (lcd_setCursor (lcd, 0, 1); lcd_print (lcd, str, pos, i2sz LCD_WIDTH))\n val () = delay_ms (MY_DELAY_MS)\n val () = loop (lcd, str, pos + 1)\n }\n }\n fun forever {n:int}{i:nat | i < n}\n (lcd: !lcd_t, str: string (n), pos: size_t (i)): void = {\n val () = loop (lcd, str, pos)\n val () = forever (lcd, str, pos)\n }\n val lcd = lcd_open (8, 13, 9, 4, 5, 6, 7)\n val () = forever (lcd, g_str_message, i2sz 0)\n val () = lcd_close lcd\n}\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"8b2076e2bc0fc4a6ecf114942b4f5009e1a4e940","subject":"Updating: very minorly improving","message":"Updating: very minorly improving\n","repos":"bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib","old_file":"projects\/MEDIUM\/CATS-atsccomp\/CATS-atscc2js\/atscc2js_emit.dats","new_file":"projects\/MEDIUM\/CATS-atsccomp\/CATS-atscc2js\/atscc2js_emit.dats","new_contents":"(* ****** ****** *)\n\/\/\n\/\/ Atscc2js:\n\/\/ from ATS to JavaScript\n\/\/\n(* ****** ****** *)\n\/\/\n\/\/ HX-2014-08-20: start\n\/\/ HX-2015-05-21: restructure\n\/\/\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_staload.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\nUN = \"prelude\/SATS\/unsafe.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\n#define\nCATSPARSEMIT_targetloc \".\/.CATS-parsemit\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \"{$CATSPARSEMIT}\/catsparse.sats\"\n\/\/\nstaload \"{$CATSPARSEMIT}\/catsparse_syntax.sats\"\n\/\/\nstaload \"{$CATSPARSEMIT}\/catsparse_emit.sats\"\n\/\/\nstaload \"{$CATSPARSEMIT}\/catsparse_typedef.sats\"\n\/\/\n(* ****** ****** *)\n\nlocal\n\nstaload\nTM = \"libc\/SATS\/time.sats\"\nstadef time_t = $TM.time_t\n\nin (* in-of-local *)\n\nimplement\nemit_time_stamp (out) = let\n\/\/\nvar tm: time_t\nval () = tm := $TM.time_get ()\nval (pfopt | p_tm) = $TM.localtime (tm)\n\/\/\nval () = emit_text (out, \"\/*\\n\");\nval () = emit_text (out, \"**\\n\");\nval () = emit_text (out, \"** The JavaScript code is generated by atscc2js\\n\")\nval () = emit_text (out, \"** The starting compilation time is: \")\n\/\/\nval () =\nif\np_tm > 0\nthen let\n prval Some_v @(pf1, fpf1) = pfopt\n val tm_min = $TM.tm_get_min (!p_tm)\n val tm_hour = $TM.tm_get_hour (!p_tm)\n val tm_mday = $TM.tm_get_mday (!p_tm)\n val tm_mon = 1 + $TM.tm_get_mon (!p_tm)\n val tm_year = 1900 + $TM.tm_get_year (!p_tm)\n prval () = fpf1 (pf1)\nin\n $extfcall\n (\n void\n , \"fprintf\"\n , out, \"%i-%i-%i: %2ih:%2im\\n\", tm_year, tm_mon, tm_mday, tm_hour, tm_min\n )\nend \/\/ end of [then]\nelse let\n prval None_v () = pfopt\nin\n emit_text (out, \"**TIME-ERROR**\\n\")\nend \/\/ end of [else]\n\/\/\nval () = emit_text (out, \"**\\n\")\nval () = emit_text (out, \"*\/\\n\")\n\/\/\nin\n \/\/ emit_newline (out)\nend \/\/ end of [emit_time_stamp]\n\nend \/\/ end of [local]\n\n(* ****** ****** *)\n\nimplement\nemit_PMVint\n (out, tok) = let\n\/\/\nval-T_INT(base, rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVint]\n\/\/\nimplement\nemit_PMVintrep\n (out, tok) = let\n\/\/\nval-T_INT(base, rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVintrep]\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_PMVbool\n (out, tfv) =\n(\n emit_text (out, if tfv then \"true\" else \"false\")\n) (* end of [emit_PMVbool] *)\n\n(* ****** ****** *)\n\nimplement\nemit_PMVstring\n (out, tok) = let\n\/\/\nval-T_STRING(rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVstring]\n\n(* ****** ****** *)\n\nimplement\nemit_PMVfloat\n (out, tok) = let\n\/\/\nval-T_FLOAT(base, rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVfloat]\n\n(* ****** ****** *)\n\nimplement\nemit_PMVi0nt\n (out, tok) = let\n\/\/\nval-T_INT(base, rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVi0nt]\n\n(* ****** ****** *)\n\nimplement\nemit_PMVf0loat\n (out, tok) = let\n\/\/\nval-T_FLOAT(base, rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVf0loat]\n\n(* ****** ****** *)\n\/\/\nimplement\nemit_PMVempty\n (out, _) = emit_text (out, \"null\")\n\/\/ \nimplement\nemit_PMVextval\n (out, toks) = emit_tokenlst (out, toks)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nemit_PMVfunlab\n (out, flab) = emit_label (out, flab)\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_PMVcfunlab\n (out, fl, d0es) =\n{\n\/\/\nval () =\n emit_label (out, fl)\nval () =\n emit_text (out, \"__closurerize\")\n\/\/\nval () = emit_LPAREN (out)\nval () = emit_d0explst (out, d0es)\nval () = emit_RPAREN (out)\n\/\/\n} (* end of [emit_PMVcfunlab] *)\n\n(* ****** ****** *)\n\nimplement\nemit_CSTSPmyloc\n (out, tok) = let\n\/\/\nval-T_STRING(rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_CSTSPmyloc]\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit_fname_d0exp\n : (FILEref, string, d0exp) -> void\nextern\nfun\nemit_fname_d0exp2\n : (FILEref, string, d0exp, d0exp) -> void\n\/\/\nimplement\nemit_fname_d0exp\n (out, fname, d0e) =\n{\n\/\/\nval () =\n emit_text (out, fname)\nval () = emit_LPAREN (out)\nval () = emit_d0exp (out, d0e)\nval () = emit_RPAREN (out)\n\/\/\n} (* end of [emit_fname_d0exp] *)\n\/\/\nimplement\nemit_fname_d0exp2\n (out, fname, d0e1, d0e2) =\n{\n\/\/\nval () =\n emit_text (out, fname)\n\/\/\nval () = emit_LPAREN (out)\nval () =\n(\n emit_d0exp (out, d0e1); emit_text (out, \", \"); emit_d0exp (out, d0e2)\n)\nval () = emit_RPAREN (out)\n\/\/\n} (* end of [emit_fname_d0exp2] *)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nemit_ATSCKiseqz(out, d0e) =\n emit_fname_d0exp(out, \"ATSCKiseqz\", d0e)\nimplement\nemit_ATSCKisneqz(out, d0e) =\n emit_fname_d0exp(out, \"ATSCKisneqz\", d0e)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nemit_ATSCKptriscons(out, d0e) =\n emit_fname_d0exp(out, \"ATSCKptriscons\", d0e)\nimplement\nemit_ATSCKptrisnull(out, d0e) =\n emit_fname_d0exp(out, \"ATSCKptrisnull\", d0e)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nemit_ATSCKpat_int\n (out, d0e, i0) =\n emit_fname_d0exp2 (out, \"ATSCKpat_int\", d0e, i0)\nimplement\nemit_ATSCKpat_bool\n (out, d0e, b0) =\n emit_fname_d0exp2 (out, \"ATSCKpat_bool\", d0e, b0)\nimplement\nemit_ATSCKpat_string\n (out, d0e, s0) =\n emit_fname_d0exp2 (out, \"ATSCKpat_string\", d0e, s0)\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_ATSCKpat_con0\n (out, d0e, ctag) =\n{\n val () =\n emit_text (out, \"ATSCKpat_con0(\")\n val () = (\n emit_d0exp (out, d0e);\n emit_text (out, \", \"); emit_int (out, ctag); emit_RPAREN (out)\n ) (* end of [val] *)\n} (* end of [emit_ATSCKpat_con0] *)\n\nimplement\nemit_ATSCKpat_con1\n (out, d0e, ctag) =\n{\n val () =\n emit_text (out, \"ATSCKpat_con1(\")\n val () = (\n emit_d0exp (out, d0e);\n emit_text (out, \", \"); emit_int (out, ctag); emit_RPAREN (out)\n ) (* end of [val] *)\n} (* end of [emit_ATSCKpat_con1] *)\n\n(* ****** ****** *)\n\/\/\nimplement\nemit_tmpvar\n (out, tmp) = emit_i0de (out, tmp)\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_d0exp\n (out, d0e0) = let\nin\n\/\/\ncase+\nd0e0.d0exp_node of\n\/\/\n| D0Eide (tmp) => \n {\n val () = emit_tmpvar (out, tmp)\n }\n\/\/\n| D0Eappid (fid, d0es) =>\n {\n val () = emit_i0de (out, fid)\n val () = emit_LPAREN (out)\n val () = emit_d0explst (out, d0es)\n val () = emit_RPAREN (out)\n }\n| D0Eappexp (d0e, d0es) =>\n {\n val () = emit_d0exp (out, d0e)\n val () = emit_LPAREN (out)\n val () = emit_d0explst (out, d0es)\n val () = emit_RPAREN (out)\n }\n\/\/\n| D0Elist (d0es) =>\n {\n val () = emit_text (out, \"D0Elist\")\n val () = emit_LPAREN (out)\n val () = emit_d0explst (out, d0es)\n val () = emit_RPAREN (out)\n }\n\/\/\n| ATSPMVint (int) => emit_PMVint (out, int)\n| ATSPMVintrep (int) => emit_PMVintrep (out, int)\n\/\/\n| ATSPMVbool (tfv) => emit_PMVbool (out, tfv)\n\/\/\n| ATSPMVfloat (flt) => emit_PMVfloat (out, flt)\n\/\/\n| ATSPMVstring (str) => emit_PMVstring (out, str)\n\/\/\n| ATSPMVi0nt (int) => emit_PMVi0nt (out, int)\n| ATSPMVf0loat (flt) => emit_PMVf0loat (out, flt)\n\/\/\n| ATSPMVempty (dummy) => emit_PMVempty (out, 0)\n| ATSPMVextval (toklst) => emit_PMVextval (out, toklst)\n\/\/\n| ATSPMVrefarg0 (d0e) => emit_d0exp (out, d0e)\n| ATSPMVrefarg1 (d0e) => emit_d0exp (out, d0e)\n\/\/\n| ATSPMVfunlab (fl) => emit_PMVfunlab (out, fl)\n| ATSPMVcfunlab\n (_(*knd*), fl, d0es) => emit_PMVcfunlab (out, fl, d0es)\n \/\/ end of [ATSPMVcfunlab]\n\/\/\n| ATSPMVcastfn\n (_(*fid*), _(*s0e*), arg) => emit_d0exp (out, arg)\n\/\/\n| ATSCSTSPmyloc (tok) => emit_CSTSPmyloc (out, tok)\n\/\/\n| ATSCKiseqz(d0e) => emit_ATSCKiseqz (out, d0e)\n| ATSCKisneqz(d0e) => emit_ATSCKisneqz (out, d0e)\n| ATSCKptriscons(d0e) => emit_ATSCKptriscons (out, d0e)\n| ATSCKptrisnull(d0e) => emit_ATSCKptrisnull (out, d0e)\n\/\/\n| ATSCKpat_int\n (d0e, int) => emit_ATSCKpat_int (out, d0e, int)\n| ATSCKpat_bool\n (d0e, bool) => emit_ATSCKpat_bool (out, d0e, bool)\n| ATSCKpat_string\n (d0e, string) => emit_ATSCKpat_bool (out, d0e, string)\n\/\/\n| ATSCKpat_con0\n (d0e, ctag) => emit_ATSCKpat_con0 (out, d0e, ctag)\n| ATSCKpat_con1\n (d0e, ctag) => emit_ATSCKpat_con1 (out, d0e, ctag)\n\/\/\n| ATSSELcon _ => emit_SELcon (out, d0e0)\n| ATSSELrecsin _ => emit_SELrecsin (out, d0e0)\n| ATSSELboxrec _ => emit_SELboxrec (out, d0e0)\n| ATSSELfltrec _ => emit_text (out, \"ATSSELfltrec(...)\")\n\/\/\n| ATSextfcall\n (_fun, _arg) => {\n val () = emit_i0de (out, _fun)\n val () = emit_d0exparg (out, _arg)\n } (* end of [ATSextfcall] *)\n| ATSextmcall\n (_obj, _mtd, _arg) => {\n\/\/\n val () = emit_d0exp (out, _obj)\n val () = emit_DOT (out)\n val () = emit_d0exp (out, _mtd)\n\/\/\n val () = emit_d0exparg (out, _arg)\n\/\/\n } (* end of [ATSextmcall] *)\n\/\/\n| ATSfunclo_fun\n (d0e, _(*arg*), _(*res*)) => emit_d0exp (out, d0e)\n| ATSfunclo_clo\n (d0e, _(*arg*), _(*res*)) =>\n (\n emit_d0exp (out, d0e);\n emit_LBRACKET (out); emit_int (out, 0); emit_RBRACKET (out)\n ) (* end of [ATSfunclo_clo] *)\n\/\/\nend \/\/ end of [emit_d0exp]\n\n(* ****** ****** *)\n\nlocal\n\nfun\nloop\n(\n out: FILEref, d0es: d0explst, i: int\n) : void =\n(\ncase+ d0es of\n| list_nil () => ()\n| list_cons (d0e, d0es) => let\n val () =\n if i > 0 then emit_text (out, \", \")\n \/\/ end of [val]\n in\n emit_d0exp (out, d0e); loop (out, d0es, i+1)\n end \/\/ end of [list_cons]\n)\n\nin (* in-of-local *)\n\nimplement\nemit_d0explst (out, d0es) = loop (out, d0es, 0)\nimplement\nemit_d0explst_1 (out, d0es) = loop (out, d0es, 1)\n\nend \/\/ end of [local]\n\n(* ****** ****** *)\n\nimplement\nemit_d0exparg\n (out, d0es) = \n{\n\/\/\nval () = emit_LPAREN (out)\nval () = emit_d0explst (out, d0es)\nval () = emit_RPAREN (out)\n\/\/\n} (* end of [emit_d0exparg] *)\n\n(* ****** ****** *)\n\/\/\nextern\nfun\ntyrec_labsel\n (tyrec: tyrec, lab: symbol): int\n\/\/\nimplement\ntyrec_labsel\n (tyrec, lab) = let\n\/\/\nfun loop\n(\n xs: tyfldlst, i: int\n) : int =\n(\ncase+ xs of\n| list_cons (x, xs) => let\n val TYFLD (id, s0e) = x.tyfld_node\n in\n if lab = id.i0dex_sym then i else loop (xs, i+1)\n end \/\/ end of [list_cons\n| list_nil ((*void*)) => ~1(*error*)\n)\n\/\/\nin\n loop (tyrec.tyrec_node, 0)\nend \/\/ end of [tyrec_labsel]\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_SELcon\n (out, d0e) = let\n\/\/\nval-\nATSSELcon\n(d0rec, s0e, id) = d0e.d0exp_node\n\/\/\nval-S0Eide (name) = s0e.s0exp_node\nval-~Some_vt (s0rec) = typedef_search_opt (name)\n\/\/\nval index = tyrec_labsel (s0rec, id.i0dex_sym)\n\/\/\nval () =\n emit_d0exp (out, d0rec)\n\/\/\nval () = emit_LBRACKET (out)\nval () = emit_int (out, index)\nval () = emit_RBRACKET (out)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit_SELcon]\n\n(* ****** ****** *)\n\nimplement\nemit_SELrecsin\n (out, d0e) = let\n\/\/\nval-\nATSSELrecsin\n(d0rec, s0e, id) = d0e.d0exp_node\n\/\/\nin\n emit_d0exp (out, d0rec)\nend \/\/ end of [emit_SELrecsin]\n\n(* ****** ****** *)\n\nimplement\nemit_SELboxrec\n (out, d0e) = let\n\/\/\nval-\nATSSELboxrec\n(d0rec, s0e, id) = d0e.d0exp_node\n\/\/\nval-S0Eide (name) = s0e.s0exp_node\nval-~Some_vt (s0rec) = typedef_search_opt (name)\n\/\/\nval index = tyrec_labsel (s0rec, id.i0dex_sym)\n\/\/\nval () =\n emit_d0exp (out, d0rec)\n\/\/\nval () = emit_LBRACKET (out)\nval () = emit_int (out, index)\nval () = emit_RBRACKET (out)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit_SELboxrec]\n\n(* ****** ****** *)\n\/\/\nimplement\nemit_COMMENT_line\n (out, tok) = let\n\/\/\nval-\nT_COMMENT_line\n (str) = tok.token_node\n\/\/\nin\n emit_text (out, str)\nend \/\/ end of [emit_COMMENT_line]\n\/\/\nimplement\nemit_COMMENT_block\n (out, tok) = let\n\/\/\nval-\nT_COMMENT_block\n (str) = tok.token_node\n\/\/\nin\n emit_text (out, str)\nend \/\/ end of [emit_COMMENT_block]\n\/\/\n(* ****** ****** *)\n\nlocal\n\nfun\naux0_arglst\n(\n out: FILEref\n, s0es: s0explst\n, n0: int, i: int\n) : void =\n(\ncase+ s0es of\n| list_nil () => ()\n| list_cons\n (s0e, s0es) => let\n val () =\n if n0+i > 0 then emit_text (out, \", \")\n val () =\n (\n emit_text (out, \"arg\"); emit_int (out, i)\n ) (* end of [val] *)\n in\n aux0_arglst (out, s0es, n0, i+1)\n end \/\/ end of [list_cons]\n) (* end of [aux0_arglst] *)\n\nfun\naux0_envlst\n(\n out: FILEref\n, s0es: s0explst\n, n0: int, i: int\n) : void =\n(\ncase+ s0es of\n| list_nil () => ()\n| list_cons\n (s0e, s0es) => let\n val () =\n if n0+i > 0 then emit_text (out, \", \")\n val () =\n (\n emit_text (out, \"env\"); emit_int (out, i)\n ) (* end of [val] *)\n in\n aux0_envlst (out, s0es, n0, i+1)\n end \/\/ end of [list_cons]\n) (* end of [aux0_envlst] *)\n\nfun\naux1_envlst\n(\n out: FILEref\n, s0es: s0explst, i: int\n) : int =\n(\ncase+ s0es of\n| list_nil\n ((*void*)) => (i)\n| list_cons\n (s0e, s0es) => let\n val () =\n if i > 0\n then emit_text (out, \", \")\n \/\/ end of [if]\n val () =\n (\n emit_text (out, \"cenv\");\n emit_LBRACKET (out); emit_int (out, i+1); emit_RBRACKET (out)\n ) (* end of [val] *)\n in\n aux1_envlst (out, s0es, i+1)\n end \/\/ end of [list_cons]\n) (* end of [aux1_envlst] *)\n\nin (* in-of-local *)\n\nimplement\nemit_closurerize\n(\n out, fl, env, arg, res\n) = let\n\/\/\nval-S0Elist(s0es_env) = env.s0exp_node\nval-S0Elist(s0es_arg) = arg.s0exp_node\n\/\/\nval () = emit_ENDL (out)\n\/\/\nval () =\nemit_text (out, \"function\\n\")\nval () = emit_label (out, fl)\nval () =\nemit_text (out, \"__closurerize(\")\nval () = aux0_envlst (out, s0es_env, 0, 0)\nval ((*closing*)) = emit_text (out, \")\\n\")\n\/\/\nval ((*opening*)) = emit_text (out, \"{\\n\")\n\/\/\nval () = emit_nspc (out, 2)\nval () = emit_text (out, \"return [\")\nval () = emit_text (out, \"function(\")\n\/\/\nval () = emit_text (out, \"cenv\")\nval () = aux0_arglst (out, s0es_arg, 1, 0)\n\/\/\nval () = emit_text (out, \") { return \")\n\/\/\nval () = emit_label (out, fl)\nval () = emit_LPAREN (out)\nval n0 = aux1_envlst (out, s0es_env, 0)\nval () = aux0_arglst (out, s0es_arg, n0, 0)\nval () = emit_RPAREN (out)\n\/\/\nval ((*closing*)) = emit_text (out, \"; }\")\n\/\/\nval () = aux0_envlst (out, s0es_env, 1, 0)\nval ((*closing*)) = emit_text (out, \"];\\n}\\n\")\n\/\/\nval ((*flushing*)) = emit_newline (out)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit_closurerize]\n\nend \/\/ end of [local]\n\n(* ****** ****** *)\n\n(* end of [atscc2js_emit.dats] *)\n","old_contents":"(* ****** ****** *)\n\/\/\n\/\/ Atscc2js:\n\/\/ from ATS to JavaScript\n\/\/\n(* ****** ****** *)\n\/\/\n\/\/ HX-2014-08-20: start\n\/\/ HX-2015-05-21: restructure\n\/\/\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_staload.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\nUN = \"prelude\/SATS\/unsafe.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\n#define\nCATSPARSEMIT_targetloc \".\/.CATS-parsemit\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \"{$CATSPARSEMIT}\/catsparse.sats\"\n\/\/\nstaload \"{$CATSPARSEMIT}\/catsparse_syntax.sats\"\n\/\/\nstaload \"{$CATSPARSEMIT}\/catsparse_emit.sats\"\n\/\/\nstaload \"{$CATSPARSEMIT}\/catsparse_typedef.sats\"\n\/\/\n(* ****** ****** *)\n\nlocal\n\nstaload\nTM = \"libc\/SATS\/time.sats\"\nstadef time_t = $TM.time_t\n\nin (* in-of-local *)\n\nimplement\nemit_time_stamp (out) = let\n\/\/\nvar tm: time_t\nval () = tm := $TM.time_get ()\nval (pfopt | p_tm) = $TM.localtime (tm)\n\/\/\nval () = emit_text (out, \"\/*\\n\");\nval () = emit_text (out, \"**\\n\");\nval () = emit_text (out, \"** The JavaScript code is generated by atscc2js\\n\")\nval () = emit_text (out, \"** The starting compilation time is: \")\n\/\/\nval () =\nif\np_tm > 0\nthen let\n prval Some_v @(pf1, fpf1) = pfopt\n val tm_min = $TM.tm_get_min (!p_tm)\n val tm_hour = $TM.tm_get_hour (!p_tm)\n val tm_mday = $TM.tm_get_mday (!p_tm)\n val tm_mon = 1 + $TM.tm_get_mon (!p_tm)\n val tm_year = 1900 + $TM.tm_get_year (!p_tm)\n prval () = fpf1 (pf1)\nin\n $extfcall\n (\n void\n , \"fprintf\"\n , out, \"%i-%i-%i: %2ih:%2im\\n\", tm_year, tm_mon, tm_mday, tm_hour, tm_min\n )\nend \/\/ end of [then]\nelse let\n prval None_v () = pfopt\nin\n emit_text (out, \"**TIME-ERROR**\\n\")\nend \/\/ end of [else]\n\/\/\nval () = emit_text (out, \"**\\n\")\nval () = emit_text (out, \"*\/\\n\")\n\/\/\nin\n \/\/ emit_newline (out)\nend \/\/ end of [emit_time_stamp]\n\nend \/\/ end of [local]\n\n(* ****** ****** *)\n\nimplement\nemit_PMVint\n (out, tok) = let\n\/\/\nval-T_INT(base, rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVint]\n\/\/\nimplement\nemit_PMVintrep\n (out, tok) = let\n\/\/\nval-T_INT(base, rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVintrep]\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_PMVbool\n (out, tfv) =\n(\n emit_text (out, if tfv then \"true\" else \"false\")\n) (* end of [emit_PMVbool] *)\n\n(* ****** ****** *)\n\nimplement\nemit_PMVstring\n (out, tok) = let\n\/\/\nval-T_STRING(rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVstring]\n\n(* ****** ****** *)\n\nimplement\nemit_PMVfloat\n (out, tok) = let\n\/\/\nval-T_FLOAT(base, rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVfloat]\n\n(* ****** ****** *)\n\nimplement\nemit_PMVi0nt\n (out, tok) = let\n\/\/\nval-T_INT(base, rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVi0nt]\n\n(* ****** ****** *)\n\nimplement\nemit_PMVf0loat\n (out, tok) = let\n\/\/\nval-T_FLOAT(base, rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVf0loat]\n\n(* ****** ****** *)\n\/\/\nimplement\nemit_PMVempty\n (out, _) = emit_text (out, \"null\")\n\/\/ \nimplement\nemit_PMVextval\n (out, toks) = emit_tokenlst (out, toks)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nemit_PMVfunlab\n (out, flab) = emit_label (out, flab)\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_PMVcfunlab\n (out, fl, d0es) =\n{\n\/\/\nval () =\n emit_label (out, fl)\nval () =\n emit_text (out, \"__closurerize\")\n\/\/\nval () = emit_LPAREN (out)\nval () = emit_d0explst (out, d0es)\nval () = emit_RPAREN (out)\n\/\/\n} (* end of [emit_PMVcfunlab] *)\n\n(* ****** ****** *)\n\nimplement\nemit_CSTSPmyloc\n (out, tok) = let\n\/\/\nval-T_STRING(rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_CSTSPmyloc]\n\n(* ****** ****** *)\n\nimplement\nemit_ATSCKiseqz\n (out, d0e) =\n{\n\/\/\nval () = emit_text (out, \"ATSCKiseqz(\")\nval () = (emit_d0exp (out, d0e); emit_RPAREN (out))\n\/\/\n} (* end of [emit_ATSCKiseqz] *)\n\nimplement\nemit_ATSCKisneqz\n (out, d0e) =\n{\n\/\/\nval () = emit_text (out, \"ATSCKisneqz(\")\nval () = (emit_d0exp (out, d0e); emit_RPAREN (out))\n\/\/\n} (* end of [emit_ATSCKisneqz] *)\n\n(* ****** ****** *)\n\nimplement\nemit_ATSCKptriscons\n (out, d0e) =\n{\n\/\/\nval () = emit_text (out, \"ATSCKptriscons(\")\nval () = (emit_d0exp (out, d0e); emit_RPAREN (out))\n\/\/\n} (* end of [emit_ATSCKptriscons] *)\n\nimplement\nemit_ATSCKptrisnull\n (out, d0e) =\n{\n\/\/\nval () = emit_text (out, \"ATSCKptrisnull(\")\nval () = (emit_d0exp (out, d0e); emit_RPAREN (out))\n\/\/\n} (* end of [emit_ATSCKptrisnull] *)\n\n(* ****** ****** *)\n\nimplement\nemit_ATSCKpat_int\n (out, d0e, i0) =\n{\n val () =\n emit_text (out, \"ATSCKpat_int(\")\n val () = (\n emit_d0exp (out, d0e);\n emit_text (out, \", \"); emit_d0exp (out, i0); emit_RPAREN (out)\n ) (* end of [val] *)\n} (* end of [emit_ATSCKpat_int] *)\n\nimplement\nemit_ATSCKpat_bool\n (out, d0e, b0) =\n{\n val () =\n emit_text (out, \"ATSCKpat_bool(\")\n val () = (\n emit_d0exp (out, d0e);\n emit_text (out, \", \"); emit_d0exp (out, b0); emit_RPAREN (out)\n ) (* end of [val] *)\n} (* end of [emit_ATSCKpat_bool] *)\n\nimplement\nemit_ATSCKpat_string\n (out, d0e, s0) =\n{\n val () =\n emit_text (out, \"ATSCKpat_string(\")\n val () = (\n emit_d0exp (out, d0e);\n emit_text (out, \", \"); emit_d0exp (out, s0); emit_RPAREN (out)\n ) (* end of [val] *)\n} (* end of [emit_ATSCKpat_string] *)\n\n(* ****** ****** *)\n\nimplement\nemit_ATSCKpat_con0\n (out, d0e, ctag) =\n{\n val () =\n emit_text (out, \"ATSCKpat_con0(\")\n val () = (\n emit_d0exp (out, d0e);\n emit_text (out, \", \"); emit_int (out, ctag); emit_RPAREN (out)\n ) (* end of [val] *)\n} (* end of [emit_ATSCKpat_con0] *)\n\nimplement\nemit_ATSCKpat_con1\n (out, d0e, ctag) =\n{\n val () =\n emit_text (out, \"ATSCKpat_con1(\")\n val () = (\n emit_d0exp (out, d0e);\n emit_text (out, \", \"); emit_int (out, ctag); emit_RPAREN (out)\n ) (* end of [val] *)\n} (* end of [emit_ATSCKpat_con1] *)\n\n(* ****** ****** *)\n\/\/\nimplement\nemit_tmpvar\n (out, tmp) = emit_i0de (out, tmp)\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_d0exp\n (out, d0e0) = let\nin\n\/\/\ncase+\nd0e0.d0exp_node of\n\/\/\n| D0Eide (tmp) => \n {\n val () = emit_tmpvar (out, tmp)\n }\n\/\/\n| D0Eappid (fid, d0es) =>\n {\n val () = emit_i0de (out, fid)\n val () = emit_LPAREN (out)\n val () = emit_d0explst (out, d0es)\n val () = emit_RPAREN (out)\n }\n| D0Eappexp (d0e, d0es) =>\n {\n val () = emit_d0exp (out, d0e)\n val () = emit_LPAREN (out)\n val () = emit_d0explst (out, d0es)\n val () = emit_RPAREN (out)\n }\n\/\/\n| D0Elist (d0es) =>\n {\n val () = emit_text (out, \"D0Elist\")\n val () = emit_LPAREN (out)\n val () = emit_d0explst (out, d0es)\n val () = emit_RPAREN (out)\n }\n\/\/\n| ATSPMVint (int) => emit_PMVint (out, int)\n| ATSPMVintrep (int) => emit_PMVintrep (out, int)\n\/\/\n| ATSPMVbool (tfv) => emit_PMVbool (out, tfv)\n\/\/\n| ATSPMVfloat (flt) => emit_PMVfloat (out, flt)\n\/\/\n| ATSPMVstring (str) => emit_PMVstring (out, str)\n\/\/\n| ATSPMVi0nt (int) => emit_PMVi0nt (out, int)\n| ATSPMVf0loat (flt) => emit_PMVf0loat (out, flt)\n\/\/\n| ATSPMVempty (dummy) => emit_PMVempty (out, 0)\n| ATSPMVextval (toklst) => emit_PMVextval (out, toklst)\n\/\/\n| ATSPMVrefarg0 (d0e) => emit_d0exp (out, d0e)\n| ATSPMVrefarg1 (d0e) => emit_d0exp (out, d0e)\n\/\/\n| ATSPMVfunlab (fl) => emit_PMVfunlab (out, fl)\n| ATSPMVcfunlab\n (_(*knd*), fl, d0es) => emit_PMVcfunlab (out, fl, d0es)\n \/\/ end of [ATSPMVcfunlab]\n\/\/\n| ATSPMVcastfn\n (_(*fid*), _(*s0e*), arg) => emit_d0exp (out, arg)\n\/\/\n| ATSCSTSPmyloc (tok) => emit_CSTSPmyloc (out, tok)\n\/\/\n| ATSCKiseqz(d0e) => emit_ATSCKiseqz (out, d0e)\n| ATSCKisneqz(d0e) => emit_ATSCKisneqz (out, d0e)\n| ATSCKptriscons(d0e) => emit_ATSCKptriscons (out, d0e)\n| ATSCKptrisnull(d0e) => emit_ATSCKptrisnull (out, d0e)\n\/\/\n| ATSCKpat_int\n (d0e, int) => emit_ATSCKpat_int (out, d0e, int)\n| ATSCKpat_bool\n (d0e, bool) => emit_ATSCKpat_bool (out, d0e, bool)\n| ATSCKpat_string\n (d0e, string) => emit_ATSCKpat_bool (out, d0e, string)\n\/\/\n| ATSCKpat_con0\n (d0e, ctag) => emit_ATSCKpat_con0 (out, d0e, ctag)\n| ATSCKpat_con1\n (d0e, ctag) => emit_ATSCKpat_con1 (out, d0e, ctag)\n\/\/\n| ATSSELcon _ => emit_SELcon (out, d0e0)\n| ATSSELrecsin _ => emit_SELrecsin (out, d0e0)\n| ATSSELboxrec _ => emit_SELboxrec (out, d0e0)\n| ATSSELfltrec _ => emit_text (out, \"ATSSELfltrec(...)\")\n\/\/\n| ATSextfcall\n (_fun, _arg) => {\n val () = emit_i0de (out, _fun)\n val () = emit_d0exparg (out, _arg)\n } (* end of [ATSextfcall] *)\n| ATSextmcall\n (_obj, _mtd, _arg) => {\n\/\/\n val () = emit_d0exp (out, _obj)\n val () = emit_DOT (out)\n val () = emit_d0exp (out, _mtd)\n\/\/\n val () = emit_d0exparg (out, _arg)\n\/\/\n } (* end of [ATSextmcall] *)\n\/\/\n| ATSfunclo_fun\n (d0e, _(*arg*), _(*res*)) => emit_d0exp (out, d0e)\n| ATSfunclo_clo\n (d0e, _(*arg*), _(*res*)) =>\n (\n emit_d0exp (out, d0e);\n emit_LBRACKET (out); emit_int (out, 0); emit_RBRACKET (out)\n ) (* end of [ATSfunclo_clo] *)\n\/\/\nend \/\/ end of [emit_d0exp]\n\n(* ****** ****** *)\n\nlocal\n\nfun\nloop\n(\n out: FILEref, d0es: d0explst, i: int\n) : void =\n(\ncase+ d0es of\n| list_nil () => ()\n| list_cons (d0e, d0es) => let\n val () =\n if i > 0 then emit_text (out, \", \")\n \/\/ end of [val]\n in\n emit_d0exp (out, d0e); loop (out, d0es, i+1)\n end \/\/ end of [list_cons]\n)\n\nin (* in-of-local *)\n\nimplement\nemit_d0explst (out, d0es) = loop (out, d0es, 0)\nimplement\nemit_d0explst_1 (out, d0es) = loop (out, d0es, 1)\n\nend \/\/ end of [local]\n\n(* ****** ****** *)\n\nimplement\nemit_d0exparg\n (out, d0es) = \n{\n\/\/\nval () = emit_LPAREN (out)\nval () = emit_d0explst (out, d0es)\nval () = emit_RPAREN (out)\n\/\/\n} (* end of [emit_d0exparg] *)\n\n(* ****** ****** *)\n\/\/\nextern\nfun\ntyrec_labsel\n (tyrec: tyrec, lab: symbol): int\n\/\/\nimplement\ntyrec_labsel\n (tyrec, lab) = let\n\/\/\nfun loop\n(\n xs: tyfldlst, i: int\n) : int =\n(\ncase+ xs of\n| list_cons (x, xs) => let\n val TYFLD (id, s0e) = x.tyfld_node\n in\n if lab = id.i0dex_sym then i else loop (xs, i+1)\n end \/\/ end of [list_cons\n| list_nil ((*void*)) => ~1(*error*)\n)\n\/\/\nin\n loop (tyrec.tyrec_node, 0)\nend \/\/ end of [tyrec_labsel]\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_SELcon\n (out, d0e) = let\n\/\/\nval-\nATSSELcon\n(d0rec, s0e, id) = d0e.d0exp_node\n\/\/\nval-S0Eide (name) = s0e.s0exp_node\nval-~Some_vt (s0rec) = typedef_search_opt (name)\n\/\/\nval index = tyrec_labsel (s0rec, id.i0dex_sym)\n\/\/\nval () =\n emit_d0exp (out, d0rec)\n\/\/\nval () = emit_LBRACKET (out)\nval () = emit_int (out, index)\nval () = emit_RBRACKET (out)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit_SELcon]\n\n(* ****** ****** *)\n\nimplement\nemit_SELrecsin\n (out, d0e) = let\n\/\/\nval-\nATSSELrecsin\n(d0rec, s0e, id) = d0e.d0exp_node\n\/\/\nin\n emit_d0exp (out, d0rec)\nend \/\/ end of [emit_SELrecsin]\n\n(* ****** ****** *)\n\nimplement\nemit_SELboxrec\n (out, d0e) = let\n\/\/\nval-\nATSSELboxrec\n(d0rec, s0e, id) = d0e.d0exp_node\n\/\/\nval-S0Eide (name) = s0e.s0exp_node\nval-~Some_vt (s0rec) = typedef_search_opt (name)\n\/\/\nval index = tyrec_labsel (s0rec, id.i0dex_sym)\n\/\/\nval () =\n emit_d0exp (out, d0rec)\n\/\/\nval () = emit_LBRACKET (out)\nval () = emit_int (out, index)\nval () = emit_RBRACKET (out)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit_SELboxrec]\n\n(* ****** ****** *)\n\/\/\nimplement\nemit_COMMENT_line\n (out, tok) = let\n\/\/\nval-\nT_COMMENT_line\n (str) = tok.token_node\n\/\/\nin\n emit_text (out, str)\nend \/\/ end of [emit_COMMENT_line]\n\/\/\nimplement\nemit_COMMENT_block\n (out, tok) = let\n\/\/\nval-\nT_COMMENT_block\n (str) = tok.token_node\n\/\/\nin\n emit_text (out, str)\nend \/\/ end of [emit_COMMENT_block]\n\/\/\n(* ****** ****** *)\n\nlocal\n\nfun\naux0_arglst\n(\n out: FILEref\n, s0es: s0explst\n, n0: int, i: int\n) : void =\n(\ncase+ s0es of\n| list_nil () => ()\n| list_cons\n (s0e, s0es) => let\n val () =\n if n0+i > 0 then emit_text (out, \", \")\n val () =\n (\n emit_text (out, \"arg\"); emit_int (out, i)\n ) (* end of [val] *)\n in\n aux0_arglst (out, s0es, n0, i+1)\n end \/\/ end of [list_cons]\n) (* end of [aux0_arglst] *)\n\nfun\naux0_envlst\n(\n out: FILEref\n, s0es: s0explst\n, n0: int, i: int\n) : void =\n(\ncase+ s0es of\n| list_nil () => ()\n| list_cons\n (s0e, s0es) => let\n val () =\n if n0+i > 0 then emit_text (out, \", \")\n val () =\n (\n emit_text (out, \"env\"); emit_int (out, i)\n ) (* end of [val] *)\n in\n aux0_envlst (out, s0es, n0, i+1)\n end \/\/ end of [list_cons]\n) (* end of [aux0_envlst] *)\n\nfun\naux1_envlst\n(\n out: FILEref\n, s0es: s0explst, i: int\n) : int =\n(\ncase+ s0es of\n| list_nil\n ((*void*)) => (i)\n| list_cons\n (s0e, s0es) => let\n val () =\n if i > 0\n then emit_text (out, \", \")\n \/\/ end of [if]\n val () =\n (\n emit_text (out, \"cenv\");\n emit_LBRACKET (out); emit_int (out, i+1); emit_RBRACKET (out)\n ) (* end of [val] *)\n in\n aux1_envlst (out, s0es, i+1)\n end \/\/ end of [list_cons]\n) (* end of [aux1_envlst] *)\n\nin (* in-of-local *)\n\nimplement\nemit_closurerize\n(\n out, fl, env, arg, res\n) = let\n\/\/\nval-S0Elist(s0es_env) = env.s0exp_node\nval-S0Elist(s0es_arg) = arg.s0exp_node\n\/\/\nval () = emit_ENDL (out)\n\/\/\nval () =\nemit_text (out, \"function\\n\")\nval () = emit_label (out, fl)\nval () =\nemit_text (out, \"__closurerize(\")\nval () = aux0_envlst (out, s0es_env, 0, 0)\nval ((*closing*)) = emit_text (out, \")\\n\")\n\/\/\nval ((*opening*)) = emit_text (out, \"{\\n\")\n\/\/\nval () = emit_nspc (out, 2)\nval () = emit_text (out, \"return [\")\nval () = emit_text (out, \"function(\")\n\/\/\nval () = emit_text (out, \"cenv\")\nval () = aux0_arglst (out, s0es_arg, 1, 0)\n\/\/\nval () = emit_text (out, \") { return \")\n\/\/\nval () = emit_label (out, fl)\nval () = emit_LPAREN (out)\nval n0 = aux1_envlst (out, s0es_env, 0)\nval () = aux0_arglst (out, s0es_arg, n0, 0)\nval () = emit_RPAREN (out)\n\/\/\nval ((*closing*)) = emit_text (out, \"; }\")\n\/\/\nval () = aux0_envlst (out, s0es_env, 1, 0)\nval ((*closing*)) = emit_text (out, \"];\\n}\\n\")\n\/\/\nval ((*flushing*)) = emit_newline (out)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit_closurerize]\n\nend \/\/ end of [local]\n\n(* ****** ****** *)\n\n(* end of [atscc2js_emit.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"f1f946736289546759c6656058ba3ce44e2134e5","subject":"updating z3 location","message":"updating z3 location\n","repos":"wdblair\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib","old_file":"contrib\/libats-\/wdblair\/SMT\/Z3\/SATS\/z3.sats","new_file":"contrib\/libats-\/wdblair\/SMT\/Z3\/SATS\/z3.sats","new_contents":"(***********************************************************************)\n(* *)\n(* Applied Type System *)\n(* *)\n(***********************************************************************)\n\n(*\n** ATS\/Postiats - Unleashing the Potential of Types!\n** Copyright (C) 2011-2013 Hongwei Xi, ATS Trustful Software, Inc.\n** All rights reserved\n**\n** ATS is free software; you can redistribute it and\/or modify it under\n** the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by the\n** Free Software Foundation; either version 2.1, or (at your option) any\n** later version.\n**\n** ATS is distributed in the hope that it will be useful, but WITHOUT ANY\n** WARRANTY; without even the implied warranty of MERCHANTABILITY or\n** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License\n** for more details.\n**\n** You should have received a copy of the GNU General Public License\n** along with ATS; see the file COPYING. If not, please write to the\n** Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA\n** 02110-1301, USA.\n*)\n\n(* ****** ****** *)\n\n(*\n** Start Time: April, 2013\n**\n** Author: William Blair \n** Authoremail: wdblair AT bu DOT edu\n**\n** Author: Hongwei Xi\n** Authoremail: gmhwxi AT gmail DOT com\n*)\n\n(* ****** ****** *)\n\n%{#\n#include \"libats-\/wdblair\/SMT\/Z3\/CATS\/z3.cats\"\n%} \/\/ end of [%{#]\n\n(* ****** ****** *)\n\n#define ATS_PACKNAME \"ATSCNTRB.libats-wdblair.Z3\"\n#define ATS_STALOADFLAG 0 \/\/ no static loading at run-time\n#define ATS_EXTERN_PREFIX \"atscntrb_\" \/\/ prefix for external names\n\n(* ****** ****** *)\n\n#define\nATSCNTRB_SML_Z3_Z3_HEADER\n#include \".\/z3_header.sats\"\n\n(* ****** ****** *)\n\n(*\nZ3_config Z3_mk_config ()\nCreate a configuration.\n*)\nfun Z3_mk_config (): Z3_config = \"mac#%\"\n\n(* \nvoid Z3_del_config (__in Z3_config c)\nDelete the given configuration object.\n*)\nfun Z3_del_config (cfg: Z3_config): void = \"mac#%\"\n\n(*\nvoid Z3_set_param_value\n(\n __in Z3_config c, __in Z3_string param_id, __in Z3_string param_value\n)\nSet a configuration parameter.\n*)\nfun Z3_set_param_value\n(\n cfg: !Z3_config, p_id: Z3_string, p_val: Z3_string\n) : void = \"mac#%\" \/\/ end of [Z3_set_param_value]\n \n(* ****** ****** *)\n\n(*\nZ3_context Z3_mk_context (__in Z3_config c)\nCreate a context using the given configuration.\n*)\n(*\nfun Z3_mk_context (cfg: !Z3_config): Z3_context = \"mac#%\"\n*)\n\n(* \nZ3_context Z3_mk_context_rc (__in Z3_config c)\nCreate a context using the given configuration. This function is similar to\nZ3_mk_context. However, in the context returned by this function, the user\nis responsible for managing Z3_ast reference counters. Managing reference\ncounters is a burden and error-prone, but allows the user to use the memory\nmore efficiently. The user must invoke Z3_inc_ref for any Z3_ast returned\nby Z3, and Z3_dec_ref whenever the Z3_ast is not needed anymore. This idiom\nis similar to the one used in BDD (binary decision diagrams) packages such\nas CUDD.\n*)\n\nfun Z3_mk_context_rc (cfg: !Z3_config): Z3_context = \"mac#%\"\n\n(* ****** ****** *)\n\n(*\nvoid\nZ3_del_context (__in Z3_context c)\nDelete the given logical context.\n*)\nfun Z3_del_context (ctx: Z3_context): void = \"mac#%\"\n \n(* ****** ****** *)\n\n(*\nvoid Z3_inc_ref (__in Z3_context c, __in Z3_ast a)\nIncrement the reference counter of the given AST. The context c should\nhave been created using Z3_mk_context_rc. This function is a NOOP if c\nwas created using Z3_mk_context.\n*)\nfun Z3_inc_ref{l:addr}\n (ctx: !Z3_context, a: !Z3_ast l): Z3_ast (l) = \"mac#%\"\n\/\/ end of [Z3_inc_ref]\n \n(*\nvoid\nZ3_dec_ref (__in Z3_context c, __in Z3_ast a)\nDecrement the reference counter of the given AST. The context c should\nhave been created using Z3_mk_context_rc. This function is a NOOP if c\nwas created using Z3_mk_context.\n*)\nfun Z3_dec_ref (ctx: !Z3_context, a: Z3_ast): void = \"mac#%\"\n\n(* ****** ****** *)\n\n(*\nZ3_bool\nZ3_get_param_value\n(\n __in Z3_context c\n, __in Z3_string param_id, __out Z3_string_ptr param_value\n)\n*)\nfun Z3_get_param_value\n(\n ctx: !Z3_context, p_id: Z3_string, p_val: &ptr? >> opt (Z3_string, b)\n) : #[b:bool] bool (b) = \"mac#%\"\n \n(*\nvoid\nZ3_update_param_value\n(__in Z3_context c, __in Z3_string param_id, __in Z3_string param_value)\n*)\nfun Z3_update_param_value\n (ctx: !Z3_context, p_id: Z3_string, p_val: Z3_string): void = \"mac#%\"\n\/\/ end of [Z3_update_param_value]\n\n(* ****** ****** *)\n\n(*\nvoid\nZ3_interrupt (__in Z3_context c)\nInterrupt the execution of a Z3 procedure. This procedure can be used to\ninterrupt: solvers, simplifiers and tactics.\n*) \nfun Z3_interrupt (ctx: !Z3_context): void = \"mac#%\"\n\n(* ****** ****** *)\n\n#include \".\/z3_accessor.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_params.sats\"\n#include \".\/z3_params_descrs.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_symbol.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_sort.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_constapp.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_propeq.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_arithmetic.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_bitvector.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_numerals.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_array.sats\"\n\n(*\n#include \".\/z3_quantifier.sats\"\n*)\n\n(* ****** ****** *)\n\n#include \".\/z3_accessor.sats\"\n#include \".\/z3_modifier.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_model.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_parser.sats\"\n\n(* ****** ****** *)\n\n(*\n#include \".\/z3_interlog.sats\"\n*)\n\n(* ****** ****** *)\n\n#include \".\/z3_quantifier.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_stringconv.sats\"\n\n(* ****** ****** *)\n\n(*\n#include \".\/z3_parserint.sats\"\n#include \".\/z3_errhandle.sats\"\n*)\n\n(* ****** ****** *)\n\n#include \".\/z3_fixedpoint.sats\"\n\n(* ****** ****** *)\n\n(*\n#include \".\/z3_ast_map\"\n#include \".\/z3_ast_vector\"\n*)\n\n(* ****** ****** *)\n\n#include \".\/z3_goal.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_tactic_probe.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_solver.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_stats.sats\"\n\n(* ****** ****** *)\n\n(* end of [z3.sats] *)\n","old_contents":"(***********************************************************************)\n(* *)\n(* Applied Type System *)\n(* *)\n(***********************************************************************)\n\n(*\n** ATS\/Postiats - Unleashing the Potential of Types!\n** Copyright (C) 2011-2013 Hongwei Xi, ATS Trustful Software, Inc.\n** All rights reserved\n**\n** ATS is free software; you can redistribute it and\/or modify it under\n** the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by the\n** Free Software Foundation; either version 2.1, or (at your option) any\n** later version.\n**\n** ATS is distributed in the hope that it will be useful, but WITHOUT ANY\n** WARRANTY; without even the implied warranty of MERCHANTABILITY or\n** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License\n** for more details.\n**\n** You should have received a copy of the GNU General Public License\n** along with ATS; see the file COPYING. If not, please write to the\n** Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA\n** 02110-1301, USA.\n*)\n\n(* ****** ****** *)\n\n(*\n** Start Time: April, 2013\n**\n** Author: William Blair \n** Authoremail: wdblair AT bu DOT edu\n**\n** Author: Hongwei Xi\n** Authoremail: gmhwxi AT gmail DOT com\n*)\n\n(* ****** ****** *)\n\n%{#\n#include \"contrib\/libats-\/wdblair\/SMT\/Z3\/CATS\/z3.cats\"\n%} \/\/ end of [%{#]\n\n(* ****** ****** *)\n\n#define ATS_PACKNAME \"ATSCNTRB.libats-wdblair.Z3\"\n#define ATS_STALOADFLAG 0 \/\/ no static loading at run-time\n#define ATS_EXTERN_PREFIX \"atscntrb_\" \/\/ prefix for external names\n\n(* ****** ****** *)\n\n#define\nATSCNTRB_SML_Z3_Z3_HEADER\n#include \".\/z3_header.sats\"\n\n(* ****** ****** *)\n\n(*\nZ3_config Z3_mk_config ()\nCreate a configuration.\n*)\nfun Z3_mk_config (): Z3_config = \"mac#%\"\n\n(* \nvoid Z3_del_config (__in Z3_config c)\nDelete the given configuration object.\n*)\nfun Z3_del_config (cfg: Z3_config): void = \"mac#%\"\n\n(*\nvoid Z3_set_param_value\n(\n __in Z3_config c, __in Z3_string param_id, __in Z3_string param_value\n)\nSet a configuration parameter.\n*)\nfun Z3_set_param_value\n(\n cfg: !Z3_config, p_id: Z3_string, p_val: Z3_string\n) : void = \"mac#%\" \/\/ end of [Z3_set_param_value]\n \n(* ****** ****** *)\n\n(*\nZ3_context Z3_mk_context (__in Z3_config c)\nCreate a context using the given configuration.\n*)\n(*\nfun Z3_mk_context (cfg: !Z3_config): Z3_context = \"mac#%\"\n*)\n\n(* \nZ3_context Z3_mk_context_rc (__in Z3_config c)\nCreate a context using the given configuration. This function is similar to\nZ3_mk_context. However, in the context returned by this function, the user\nis responsible for managing Z3_ast reference counters. Managing reference\ncounters is a burden and error-prone, but allows the user to use the memory\nmore efficiently. The user must invoke Z3_inc_ref for any Z3_ast returned\nby Z3, and Z3_dec_ref whenever the Z3_ast is not needed anymore. This idiom\nis similar to the one used in BDD (binary decision diagrams) packages such\nas CUDD.\n*)\n\nfun Z3_mk_context_rc (cfg: !Z3_config): Z3_context = \"mac#%\"\n\n(* ****** ****** *)\n\n(*\nvoid\nZ3_del_context (__in Z3_context c)\nDelete the given logical context.\n*)\nfun Z3_del_context (ctx: Z3_context): void = \"mac#%\"\n \n(* ****** ****** *)\n\n(*\nvoid Z3_inc_ref (__in Z3_context c, __in Z3_ast a)\nIncrement the reference counter of the given AST. The context c should\nhave been created using Z3_mk_context_rc. This function is a NOOP if c\nwas created using Z3_mk_context.\n*)\nfun Z3_inc_ref{l:addr}\n (ctx: !Z3_context, a: !Z3_ast l): Z3_ast (l) = \"mac#%\"\n\/\/ end of [Z3_inc_ref]\n \n(*\nvoid\nZ3_dec_ref (__in Z3_context c, __in Z3_ast a)\nDecrement the reference counter of the given AST. The context c should\nhave been created using Z3_mk_context_rc. This function is a NOOP if c\nwas created using Z3_mk_context.\n*)\nfun Z3_dec_ref (ctx: !Z3_context, a: Z3_ast): void = \"mac#%\"\n\n(* ****** ****** *)\n\n(*\nZ3_bool\nZ3_get_param_value\n(\n __in Z3_context c\n, __in Z3_string param_id, __out Z3_string_ptr param_value\n)\n*)\nfun Z3_get_param_value\n(\n ctx: !Z3_context, p_id: Z3_string, p_val: &ptr? >> opt (Z3_string, b)\n) : #[b:bool] bool (b) = \"mac#%\"\n \n(*\nvoid\nZ3_update_param_value\n(__in Z3_context c, __in Z3_string param_id, __in Z3_string param_value)\n*)\nfun Z3_update_param_value\n (ctx: !Z3_context, p_id: Z3_string, p_val: Z3_string): void = \"mac#%\"\n\/\/ end of [Z3_update_param_value]\n\n(* ****** ****** *)\n\n(*\nvoid\nZ3_interrupt (__in Z3_context c)\nInterrupt the execution of a Z3 procedure. This procedure can be used to\ninterrupt: solvers, simplifiers and tactics.\n*) \nfun Z3_interrupt (ctx: !Z3_context): void = \"mac#%\"\n\n(* ****** ****** *)\n\n#include \".\/z3_accessor.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_params.sats\"\n#include \".\/z3_params_descrs.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_symbol.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_sort.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_constapp.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_propeq.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_arithmetic.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_bitvector.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_numerals.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_array.sats\"\n\n(*\n#include \".\/z3_quantifier.sats\"\n*)\n\n(* ****** ****** *)\n\n#include \".\/z3_accessor.sats\"\n#include \".\/z3_modifier.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_model.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_parser.sats\"\n\n(* ****** ****** *)\n\n(*\n#include \".\/z3_interlog.sats\"\n*)\n\n(* ****** ****** *)\n\n#include \".\/z3_quantifier.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_stringconv.sats\"\n\n(* ****** ****** *)\n\n(*\n#include \".\/z3_parserint.sats\"\n#include \".\/z3_errhandle.sats\"\n*)\n\n(* ****** ****** *)\n\n#include \".\/z3_fixedpoint.sats\"\n\n(* ****** ****** *)\n\n(*\n#include \".\/z3_ast_map\"\n#include \".\/z3_ast_vector\"\n*)\n\n(* ****** ****** *)\n\n#include \".\/z3_goal.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_tactic_probe.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_solver.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_stats.sats\"\n\n(* ****** ****** *)\n\n(* end of [z3.sats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"39f8c04fc4301f007dcfd6bc68488027484f5eb6","subject":"Modify Pin.sats.","message":"Modify Pin.sats.\n","repos":"fujiik102\/ats-rx-drivers","old_file":"Pin.sats","new_file":"Pin.sats","new_contents":"\n\/\/ Pin control drivers\n\nstaload \"Bit.sats\"\n\ndatasort IOPort =\n | Port0 of () | Port1 of () | Port2 of () | Port3 of ()\n | Port4 of () | Port5 of () | Port6 of () | Port7 of ()\n | Port8 of () | Port9 of () | PortA of () | PortB of ()\n | PortC of () | PortD of () | PortE of () | PortF of ()\n | PortG of () | PortH of () | PortI of () | PortJ of ()\n\nstadef IOPort2int (p:IOPort):int =\n ifint (p==Port0, 0, ifint (p==Port1, 1,\n ifint (p==Port2, 2, ifint (p==Port3, 3,\n ifint (p==Port4, 4, ifint (p==Port5, 5,\n ifint (p==Port6, 6, ifint (p==Port7, 7,\n ifint (p==Port8, 8, ifint (p==Port9, 9,\n ifint (p==PortA,10, ifint (p==PortB,11,\n ifint (p==PortC,12, ifint (p==PortD,13,\n ifint (p==PortE,14, ifint (p==PortF,15,\n ifint (p==PortG,16, ifint (p==PortH,17,\n ifint (p==PortI,18, ifint (p==PortJ,19,\n ~1))))))))))))))))))))\n\ntypedef ioport_uint_t (p:IOPort) = uint (IOPort2int p)\n\ndatasort Pin = Pin of (IOPort,int)\n\ntypedef pin_uint_t (p:IOPort,n:int) = @(ioport_uint_t p, uint n)\n\n\nstadef P0 (n:int):Pin = Pin (Port0,n)\nstadef P1 (n:int):Pin = Pin (Port1,n)\nstadef P2 (n:int):Pin = Pin (Port2,n)\nstadef P3 (n:int):Pin = Pin (Port3,n)\nstadef P4 (n:int):Pin = Pin (Port4,n)\nstadef P5 (n:int):Pin = Pin (Port5,n)\nstadef P6 (n:int):Pin = Pin (Port6,n)\nstadef P7 (n:int):Pin = Pin (Port7,n)\nstadef P8 (n:int):Pin = Pin (Port8,n)\nstadef P9 (n:int):Pin = Pin (Port9,n)\nstadef PA (n:int):Pin = Pin (PortA,n)\nstadef PB (n:int):Pin = Pin (PortB,n)\nstadef PC (n:int):Pin = Pin (PortC,n)\nstadef PD (n:int):Pin = Pin (PortD,n)\nstadef PE (n:int):Pin = Pin (PortE,n)\nstadef PF (n:int):Pin = Pin (PortF,n)\nstadef PG (n:int):Pin = Pin (PortG,n)\nstadef PH (n:int):Pin = Pin (PortH,n)\nstadef PI (n:int):Pin = Pin (PortI,n)\nstadef PJ (n:int):Pin = Pin (PortJ,n)\n\n\n\/\/ Special form of fractional (n\/2^m only)\ndatasort bisectional = bisectional of (int,int)\n\nstadef bisect1 = bisectional (0,1)\n\ndataprop EQBISECTIONAL (bisectional, bisectional) = {r:bisectional} EQBISECTIONAL (r, r)\npraxi eqbisectional_make {r,s:bisectional | r == s} () : EQBISECTIONAL (r,s)\npraxi bisectional_eq_refl {r:bisectional} () : [r == r] void\npraxi bisectional_eq_reduce {n,m:int | n <= INTMAX_HALF} ():\n [bisectional (n,m) == bisectional (n+n,m+1)] void\n\nstacst bisectional_add_b : (bisectional,bisectional,bisectional) -> bool\n\npraxi {n1,n2,m:int} bisectional_add_axi ():\n [bisectional_add_b (bisectional (n1,m),bisectional (n2,m),bisectional (n1+n2,m))] unit_p\n\nstacst bisectional_half_b : (bisectional,bisectional) -> bool\n\npraxi {n,m:int} bisectional_half_axi ():\n [bisectional_half_b (bisectional (n,m),bisectional (n,m+1))] unit_p\n\n\/\/ PMR\n\nabsview PMR_BIT_V (Pin,bit,bisectional)\n\npraxi {p:Pin}{b:bit} divide_pmr_bit_v {r,s:bisectional | bisectional_half_b (r,s)}\n (PMR_BIT_V (p,b,r)) : (PMR_BIT_V (p,b,s),PMR_BIT_V (p,b,s))\n\npraxi {p:Pin}{b:bit} merge_pmr_bit_v {r,s,t:bisectional | bisectional_add_b (r,s,t)}\n (PMR_BIT_V (p,b,r), PMR_BIT_V (p,b,s)):(PMR_BIT_V (p,b,t))\n\n\nstadef PMR_BIT_IOPORT = O\nstadef PMR_BIT_PERIPHERAL = I\n\ndataview PMR_V (IOPort,bits) =\n {p:IOPort}{b7,b6,b5,b4,b3,b2,b1,b0:bit}\n PMR_V (p,Bits8 (b7,b6,b5,b4,b3,b2,b1,b0)) of\n (PMR_BIT_V (Pin (p,7),b0,bisect1), PMR_BIT_V (Pin (p,6),b1,bisect1),\n PMR_BIT_V (Pin (p,5),b2,bisect1), PMR_BIT_V (Pin (p,4),b3,bisect1),\n PMR_BIT_V (Pin (p,3),b4,bisect1), PMR_BIT_V (Pin (p,2),b5,bisect1),\n PMR_BIT_V (Pin (p,1),b6,bisect1), PMR_BIT_V (Pin (p,0),b7,bisect1))\n\nabsprop PMR_PERMISSION (IOPort,bit_permissions)\n\npropdef PMR_PERMIT (p:IOPort,bs:bits) =\n [perms:bit_permissions]\n (PMR_PERMISSION (p,perms),BITS_PERMIT_CERTIFICATE (8,perms,bs))\n\nfn {bs,cs:bits}{p:IOPort}\n writePMR (PMR_V (p,bs), PMR_PERMIT (p,cs) | ioport_uint_t p, bits_uint_t (8,cs))\n :(PMR_V (p,cs) | void)\n\nfn {bs,cs:bits}{p:IOPort}{b:bit}\n changePMRBit {bn:int | bn < 8}\n (CHANGE_BIT_BITS (8,bs,bn,b,cs),\n !PMR_V (p,bs) >> PMR_V (p,cs),\n PMR_PERMIT (p,cs)\n | pin_uint_t (p,bn), bit_uint_t b):void\n\nfn {bs:bits}{p:IOPort}\n readPMR (!PMR_V (p,bs) | p:ioport_uint_t p)\n :bits_uint_t (8,bs)\n\nfn {p:IOPort}{n:int}{b:bit}{r:bisectional}\n readPMRbit (!PMR_BIT_V (Pin (p,n),b,r) | pin:pin_uint_t (p,n))\n :bool (b==I)\n\n\/\/ The PFS function is postponed.\n\/\/ Define only PFS_V so that other functions can acquire the state of the initial value\n(*\n\/\/ PWPR\n\nabsview PWPR_V (bits)\n\nfn writePWPR {\n pfswe,b0wi,PFSWE,B0WI:bit\n | (pfswe==PFSWE) || (b0wi==O && B0WI==O)\n }(\n !PWPR_V (Bits8 (b0wi,pfswe,O,O,O,O,O,O)) >>\n PWPR_V (Bits8 (B0WI,PFSWE,O,O,O,O,O,O)) |\n bits8int_t (B0WI,PFSWE,O,O,O,O,O,O)\n ):void\n\nfn {pfswe,b0wi:bit}\n readPWPR (!PWPR_V (Bits8 (b0wi,pfswe,O,O,O,O,O,O)))\n :bits8int_t (b0wi,pfswe,O,O,O,O,O,O)\n*)\n\n\/\/ PFS\n\nabsview PFS_V (Pin,bits)\n(*\nfn {p:IOPort}{pnum:int}\n {b0wi,asel,isel,psel4,psel3,psel2,psel1,psel0:bit}\n writePFS (\n !PWPR_V (Bits8 (O,O,O,O,O,O,I,b0wi)),\n !PFS_V (Pin (p,pnum),Bits8 (asel,isel,O,psel4,psel3,psel2,psel1,psel0)) >>\n PFS_V (Pin (p,pnum),Bits8 (O,O,O,O,O,O,O,O)),\n !PMR_BIT_V (Pin (p,pnum), O)\n | pin_uint_t (p,pnum),\n bits8int_t (O,O,O,O,O,O,O,O)\n )\n :void\n\nfn {p:IOPort}{pnum:int}{asel,isel,psel4,psel3,psel2,psel1,psel0:bit}\n readPFS (\n !PFS_V (Pin (p,pnum),Bits8 (asel,isel,O,psel4,psel3,psel2,psel1,psel0))\n | pin_uint_t (p, pnum)\n )\n :bits8int_t (asel,isel,O,psel4,psel3,psel2,psel1,psel0)\n*)\n\n\/\/ TODO Create duplicate prohibited view of peripheral devices.\n\/\/ Issues view with no device assignment pins first.\n\/\/ Propriety of writing \/ disabling per pins is required.\n\n\n\/\/ PDR\n\nstadef PDR_BIT_WRITABLE = I\nstadef PDR_BIT_READ_ONLY = O\n\nabsview PDR_BIT_V (Pin,bit,bisectional)\n\npraxi {p:Pin}{b:bit} divide_pdr_bit_v {r,s:bisectional | bisectional_half_b (r,s)}\n (PDR_BIT_V (p,b,r)) : (PDR_BIT_V (p,b,s),PDR_BIT_V (p,b,s))\n\npraxi {p:Pin}{b:bit} merge_pdr_bit_v {r,s,t:bisectional | bisectional_add_b (r,s,t)}\n (PDR_BIT_V (p,b,r), PDR_BIT_V (p,b,s)):(PDR_BIT_V (p,b,t))\n\n\ndataview PDR_V (p:IOPort,bits) =\n {p:IOPort}{b7,b6,b5,b4,b3,b2,b1,b0:bit}\n PDR_V (p,Bits8 (b7,b6,b5,b4,b3,b2,b1,b0)) of\n (PDR_BIT_V (Pin (p,7),b0,bisect1), PDR_BIT_V (Pin (p,6),b1,bisect1),\n PDR_BIT_V (Pin (p,5),b2,bisect1), PDR_BIT_V (Pin (p,4),b3,bisect1),\n PDR_BIT_V (Pin (p,3),b4,bisect1), PDR_BIT_V (Pin (p,2),b5,bisect1),\n PDR_BIT_V (Pin (p,1),b6,bisect1), PDR_BIT_V (Pin (p,0),b7,bisect1))\n\nabsprop PDR_PERMISSION (IOPort,bit_permissions)\n\npropdef PDR_PERMIT (p:IOPort,bs:bits) =\n [perms:bit_permissions]\n (PDR_PERMISSION (p,perms),BITS_PERMIT_CERTIFICATE (8,perms,bs))\n\nfn {p:IOPort}{bs,cs:bits}{v: int}\n writePDR (PDR_PERMIT (p,cs),\n !PDR_V (p,bs) >> PDR_V (p,cs) |\n ioport_uint_t p,bits_uint_t (8,cs)):void\n\nfn {p:IOPort}{bs:bits}\n readPDR (!PDR_V (p,bs) | ioport_uint_t p)\n : bits_uint_t (8,bs)\n\nfn {p:IOPort}{n:int}{b:bit}{r:bisectional}\n readPDRbit (!PDR_BIT_V (Pin (p,n),b,r) | pin:pin_uint_t (p,n))\n :bool (b==I)\n\n\/\/ PODR\n\nstadef PODR_BIT_HIGH = I\nstadef PODR_BIT_GROUND = O\n\nabsview PODR_BIT_V (Pin,bit,bisectional)\n\npraxi {p:Pin}{b:bit} divide_podr_bit_v {r,s:bisectional | bisectional_half_b (r,s)}\n (PODR_BIT_V (p,b,r)) : (PODR_BIT_V (p,b,s),PODR_BIT_V (p,b,s))\n\npraxi {p:Pin}{b:bit} merge_podr_bit_v {r,s,t:bisectional | bisectional_add_b (r,s,t)}\n (PODR_BIT_V (p,b,r), PODR_BIT_V (p,b,s)):(PODR_BIT_V (p,b,t))\n\n\ndataview PODR_V (p:IOPort,bits) =\n {p:IOPort}{b7,b6,b5,b4,b3,b2,b1,b0:bit}\n PODR_V (p,Bits8 (b7,b6,b5,b4,b3,b2,b1,b0)) of\n (PODR_BIT_V (Pin (p,7),b0,bisect1), PODR_BIT_V (Pin (p,6),b1,bisect1),\n PODR_BIT_V (Pin (p,5),b2,bisect1), PODR_BIT_V (Pin (p,4),b3,bisect1),\n PODR_BIT_V (Pin (p,3),b4,bisect1), PODR_BIT_V (Pin (p,2),b5,bisect1),\n PODR_BIT_V (Pin (p,1),b6,bisect1), PODR_BIT_V (Pin (p,0),b7,bisect1))\n\nabsprop PODR_PERMISSION (IOPort,bit_permissions)\n\npropdef PODR_PERMIT (p:IOPort,bs:bits) =\n [perms:bit_permissions]\n (PODR_PERMISSION (p,perms),BITS_PERMIT_CERTIFICATE (8,perms,bs))\n\nfn {p:IOPort}{bs,cs:bits}\n writePODR (PODR_PERMIT (p,cs),\n !PODR_V (p,bs) >> PODR_V (p,cs) |\n ioport_uint_t p, bits_uint_t (8,cs)):void\n\nfn {p:IOPort}{bs:bits}\n readPODR (PODR_V (p,bs) | ioport_uint_t p)\n :bits_uint_t (8,bs)\n\nfn {p:IOPort}{n:int}{b:bit}{r:bisectional}\n readPODRbit (!PODR_BIT_V (Pin (p,n),b,r) | pin:pin_uint_t (p,n))\n :bool (b==I)\n\n\/\/ PIDR\n\nabsprop PIDR_BIT_P (Pin,bit)\ndataprop PIDR_P (p:IOPort,bits) =\n {p:IOPort}{b7,b6,b5,b4,b3,b2,b1,b0:bit}\n PIDR_P (p,Bits8 (b7,b6,b5,b4,b3,b2,b1,b0)) of\n (PIDR_BIT_P (Pin (p,7),b0), PIDR_BIT_P (Pin (p,6),b1),\n PIDR_BIT_P (Pin (p,5),b2), PIDR_BIT_P (Pin (p,4),b3),\n PIDR_BIT_P (Pin (p,3),b4), PIDR_BIT_P (Pin (p,2),b5),\n PIDR_BIT_P (Pin (p,1),b6), PIDR_BIT_P (Pin (p,0),b7))\n\nfn {p:IOPort} readPIDR (ioport_uint_t p)\n :[bs:bits] (PIDR_P (p,bs) | bits_uint_t (8,bs))\n\n\/\/ GPIO\n\nviewdef PinOutputView (p:Pin,output:bit) =\n [isel:bit][s,r,t:bisectional]\n (PFS_V (p,Bits8 (O,isel,O,O,O,O,O,O)),\n PMR_BIT_V (p,O,s),PDR_BIT_V (p,I,r),PODR_BIT_V (p,output,t))\n\n\nabsprop PinInput (Pin,bit)\n\nfn readPinInput {p:IOPort}{n:int}{isel:bit}{s,r:bisectional}\n (PFS_V (Pin (p,n),Bits8 (O,isel,O,O,O,O,O,O)),\n !PMR_BIT_V (Pin (p,n),O,s),!PDR_BIT_V (Pin (p,n),O,r) | pin_uint_t (p,n))\n : [input:bit] (PinInput (Pin (p,n),input) | bool (input==I))\n\n\/\/\/\/\n\n\/\/ TODO Make a view expressing the setting of output voltage and open drain etc.\n(*\nfn getInitialPinViews () : \/\/\n (GPIOView (P0 0,O,I),\n GPIOView (P0 1,I,O),\n GPIOView (P1 0,O,O),\n GPIOView (P1 1,I,I)\n | void)\n*)\n\n\/\/ TODO make initial absprops.\n\/\/\/\/\nfn rx110_64pins_initial_views (): (\n PODR_PERMISSION (Port0,BitPermissions8 (Permit,Permit,Permit,Permit,Permit,Permit,Permit,Permit)),\n PODR_V (Port0,Bits8(O,O,O,O,O,O,O,O)),\n \n)\n\n\n","old_contents":"\/\/ \u7aef\u5b50\u5236\u5fa1\u30c9\u30e9\u30a4\u30d0\u5b9a\u7fa9\n\nstaload \"Bit.sats\"\n\ndatasort IOPort =\n | Port0 of () | Port1 of () | Port2 of () | Port3 of ()\n | Port4 of () | Port5 of () | Port6 of () | Port7 of ()\n | Port8 of () | Port9 of () | PortA of () | PortB of ()\n | PortC of () | PortD of () | PortE of () | PortF of ()\n | PortG of () | PortH of () | PortI of () | PortJ of ()\n\nstadef IOPort2int (p:IOPort):int =\n ifint (p==Port0, 0, ifint (p==Port1, 1,\n ifint (p==Port2, 2, ifint (p==Port3, 3,\n ifint (p==Port4, 4, ifint (p==Port5, 5,\n ifint (p==Port6, 6, ifint (p==Port7, 7,\n ifint (p==Port8, 8, ifint (p==Port9, 9,\n ifint (p==PortA,10, ifint (p==PortB,11,\n ifint (p==PortC,12, ifint (p==PortD,13,\n ifint (p==PortE,14, ifint (p==PortF,15,\n ifint (p==PortG,16, ifint (p==PortH,17,\n ifint (p==PortI,18, ifint (p==PortJ,19,\n ~1))))))))))))))))))))\n\ntypedef ioport_t (p:IOPort) = int (IOPort2int p)\n\ndatasort Pin = Pin of (IOPort, int)\n\ntypedef pin_t (p:IOPort, n:int) = @(ioport_t p, int n)\n\n\n\/\/ PMR\n\nabsview PMR_BIT_V (Pin, bit)\n\nstadef PMR_BIT_IOPORT = O\nstadef PMR_BIT_PERIPHERAL = I\n\ndataview PMR_V (IOPort,bits) =\n {p:IOPort}{b7,b6,b5,b4,b3,b2,b1,b0:bit}\n PMR_V (p, Bits8 (b7,b6,b5,b4,b3,b2,b1,b0)) of\n (PMR_BIT_V (Pin (p,0), b0), PMR_BIT_V (Pin (p,1), b1),\n PMR_BIT_V (Pin (p,2), b2), PMR_BIT_V (Pin (p,3), b3),\n PMR_BIT_V (Pin (p,4), b4), PMR_BIT_V (Pin (p,5), b5),\n PMR_BIT_V (Pin (p,6), b6), PMR_BIT_V (Pin (p,7), b7))\n\nfn {bs,cs:bits}{p:IOPort}\n writePMR (PMR_V (p,bs) | ioport_t p, bits_uint_t (8,cs))\n :(PMR_V (p,cs) | void)\n\nfn {bs,cs:bits}{p:IOPort}{b:bit}\n changePMRBit {bn:int | bn < 8}\n (CHANGE_BIT_BITS (8,bs,bn,b,cs),\n !PMR_V (p,bs) >> PMR_V (p,cs)\n | pin_t (p,bn), bit_uint_t b):void\n\nfn {bs:bits}{p:IOPort}\n readPMR (!PMR_V (p,bs) | p:ioport_t p)\n :bits_uint_t (8,bs)\n\n\/\/ PFS\u95a2\u6570\u306f\u5ef6\u671f\u3002PFS_V\u306e\u307f\u5b9a\u7fa9\u3057\u3066\u3001\u521d\u671f\u5024\u306e\u72b6\u614b\u306e\u307f\u53d6\u5f97\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\u3002\n(*\n\/\/ PWPR\n\nabsview PWPR_V (bits)\n\nfn writePWPR {\n pfswe,b0wi,PFSWE,B0WI:bit\n | (pfswe==PFSWE) || (b0wi==O && B0WI==O)\n }(\n !PWPR_V (Bits8 (b0wi,pfswe,O,O,O,O,O,O)) >>\n PWPR_V (Bits8 (B0WI,PFSWE,O,O,O,O,O,O)) |\n bits8int_t (B0WI,PFSWE,O,O,O,O,O,O)\n ):void\n\nfn {pfswe,b0wi:bit}\n readPWPR (!PWPR_V (Bits8 (b0wi,pfswe,O,O,O,O,O,O)))\n :bits8int_t (b0wi,pfswe,O,O,O,O,O,O)\n*)\n\n\/\/ PFS\n\nabsview PFS_V (Pin,bits)\n(*\nfn {p:IOPort}{pnum:int}\n {b0wi,asel,isel,psel4,psel3,psel2,psel1,psel0:bit}\n writePFS (\n !PWPR_V (Bits8 (O,O,O,O,O,O,I,b0wi)),\n !PFS_V (Pin (p,pnum),Bits8 (asel,isel,O,psel4,psel3,psel2,psel1,psel0)) >>\n PFS_V (Pin (p,pnum),Bits8 (O,O,O,O,O,O,O,O)),\n !PMR_BIT_V (Pin (p,pnum), O)\n | pin_t (p,pnum),\n bits8int_t (O,O,O,O,O,O,O,O)\n )\n :void\n\nfn {p:IOPort}{pnum:int}{asel,isel,psel4,psel3,psel2,psel1,psel0:bit}\n readPFS (\n !PFS_V (Pin (p,pnum),Bits8 (asel,isel,O,psel4,psel3,psel2,psel1,psel0))\n | pin_t (p, pnum)\n )\n :bits8int_t (asel,isel,O,psel4,psel3,psel2,psel1,psel0)\n*)\n\n\/\/ TODO \u5468\u8fba\u6a5f\u5668\u306e\u91cd\u8907\u7981\u6b62\u30d3\u30e5\u30fc\n\/\/ \u6700\u521d\u306b\u6a5f\u5668\u5272\u308a\u5f53\u3066\u7aef\u5b50\u306a\u3057\u306e\u89b3\u3092\u767a\u884c\u3059\u308b\u3002\n\/\/ \u7aef\u5b50\u3054\u3068\u306e\u66f8\u304d\u8fbc\u307f\u8a31\u53ef\/\u7981\u6b62\u306eprop\u304c\u5fc5\u8981\u3002\n\n\n\/\/ PDR\n\nstadef PDR_BIT_WRITABLE = I\nstadef PDR_BIT_READ_ONLY = O\n\nabsview PDR_BIT_V (Pin, bit)\ndataview PDR_V (IOPort,bits) =\n {p:IOPort}{b7,b6,b5,b4,b3,b2,b1,b0:bit}\n PDR_V (p, Bits8 (b0,b1,b2,b3,b4,b5,b6,b7)) of\n (PDR_BIT_V (Pin (p,0),b0), PDR_BIT_V (Pin (p,1),b1),\n PDR_BIT_V (Pin (p,2),b2), PDR_BIT_V (Pin (p,3),b3),\n PDR_BIT_V (Pin (p,4),b4), PDR_BIT_V (Pin (p,5),b5),\n PDR_BIT_V (Pin (p,6),b6), PDR_BIT_V (Pin (p,7),b7))\n\nabsprop PDR_PERMISSION (IOPort,bit_permissions)\n\ndataprop PDR_PERMIT (IOPort,bits) =\n | {p:IOPort}{perms:bit_permissions}{bs:bits}{v:int}\n PDR_PERMIT (p,bs)\n of (PDR_PERMISSION (p,perms),BITS_PERMIT_CERTIFICATE (8,perms,bs))\n\nfn {p:IOPort}{bs,cs:bits}{v: int}\n writePDR (PDR_PERMIT (p,cs),\n !PDR_V (p,bs) >> PDR_V (p,cs) |\n ioport_t p,bits_uint_t (8,cs)):void\n\nfn {p:IOPort}{bs:bits}\n readPDR (!PDR_V (p,bs) | ioport_t p)\n : bits_uint_t (8,bs)\n\n\n\/\/ PODR\n\nstadef PODR_BIT_HIGH = I\nstadef PODR_BIT_GROUND = O\n\nabsview PODR_BIT_V (Pin,bit)\ndataview PODR_V (IOPort,bits) =\n {p:IOPort}{b7,b6,b5,b4,b3,b2,b1,b0:bit}\n PODR_V (p,Bits8 (b0,b1,b2,b3,b4,b5,b6,b7)) of\n (PODR_BIT_V (Pin (p,0),b0), PODR_BIT_V (Pin (p,1),b1),\n PODR_BIT_V (Pin (p,2),b2), PODR_BIT_V (Pin (p,3),b3),\n PODR_BIT_V (Pin (p,4),b4), PODR_BIT_V (Pin (p,5),b5),\n PODR_BIT_V (Pin (p,6),b6), PODR_BIT_V (Pin (p,7),b7))\n\nabsprop PODR_PERMISSION (IOPort,bit_permissions)\n\ndataprop PODR_PERMIT (IOPort,bits) =\n | {p:IOPort}{perms:bit_permissions}{bs:bits}{v:int}\n PODR_PERMIT (p,bs)\n of (PODR_PERMISSION (p,perms),BITS_PERMIT_CERTIFICATE (8,perms,bs))\n\nfn {p:IOPort}{bs,cs:bits}\n writePODR (PODR_PERMIT (p,cs),\n !PODR_V (p,bs) >> PODR_V (p,cs) |\n ioport_t p, bits_uint_t (8,cs)):void\n\nfn {p:IOPort}{bs:bits}\n readPODR (PODR_V (p,bs) | ioport_t p)\n :bits_uint_t (8,bs)\n\n\/\/ GPIO\n\nviewdef GPIOView (p:Pin,writable:bit,out:bit) =\n (PMR_BIT_V (p, O), PDR_BIT_V (p, writable), PODR_BIT_V (p, out))\n\nstadef P0 (n:int):Pin = Pin (Port0,n)\nstadef P1 (n:int):Pin = Pin (Port1,n)\nstadef P2 (n:int):Pin = Pin (Port2,n)\nstadef P3 (n:int):Pin = Pin (Port3,n)\nstadef P4 (n:int):Pin = Pin (Port4,n)\nstadef P5 (n:int):Pin = Pin (Port5,n)\nstadef P6 (n:int):Pin = Pin (Port6,n)\nstadef P7 (n:int):Pin = Pin (Port7,n)\nstadef P8 (n:int):Pin = Pin (Port8,n)\nstadef P9 (n:int):Pin = Pin (Port9,n)\nstadef PA (n:int):Pin = Pin (PortA,n)\nstadef PB (n:int):Pin = Pin (PortB,n)\nstadef PC (n:int):Pin = Pin (PortC,n)\nstadef PD (n:int):Pin = Pin (PortD,n)\nstadef PE (n:int):Pin = Pin (PortE,n)\nstadef PF (n:int):Pin = Pin (PortF,n)\nstadef PG (n:int):Pin = Pin (PortG,n)\nstadef PH (n:int):Pin = Pin (PortH,n)\nstadef PI (n:int):Pin = Pin (PortI,n)\nstadef PJ (n:int):Pin = Pin (PortJ,n)\n\n\/\/ TODO \u51fa\u529b\u96fb\u5727\u3084\u30aa\u30fc\u30d7\u30f3\u30c9\u30ec\u30a4\u30f3\u306a\u3069\u306e\u8a2d\u5b9a\u3092\u8868\u3059\u89b3\u3092\u4f5c\u308b\u3002\n\/\/ TODO lin\u30bf\u30b0\u3092\u5fa9\u6d3b\u3055\u305b\u308b\u3002\n(*\nfn getInitialPinViews () : \/\/\n (GPIOView (P0 0,O,I),\n GPIOView (P0 1,I,O),\n GPIOView (P1 0,O,O),\n GPIOView (P1 1,I,I)\n | void)\n*)\n\nfn {p:IOPort}{n:int}{rw,outv,before_rw:bit} configIOPin\n (!GPIOView (Pin (p,n),before_rw,outv) >> GPIOView (Pin (p,n),rw,outv)\n | pin:pin_t (p,n), rw:bit_uint_t rw)\n : void\n\nfn {p:IOPort}{n:int}{outv,before_out:bit} putIO\n (!GPIOView (Pin (p,n),I,before_out) >> GPIOView (Pin (p,n),I,outv)\n | pin:pin_t (p,n), bit_uint_t outv)\n : void\n\nfn {p:IOPort}{n:int}{rw,outv:bit} readIO\n (!GPIOView (Pin (p,n),rw,outv) | pin:pin_t (p,n))\n : bit_uint_t outv\n\n(*\n \u8d77\u52d5\u304b\u3089\u306e\u51fa\u529b\u5c65\u6b74\u3092\u578b\u306b\u542b\u307e\u305b\u308b\u3002\n \u5f8c\u304b\u3089\u542b\u307e\u305b\u308b\u3053\u3068\u306f\u3067\u304d\u308b\uff1f\n \u5225\u306e\u30b9\u30bf\u30f3\u30d7\u5316\u3057\u305f\u578b\u3092\u4f5c\u3063\u3066\u3001\u95a2\u4fc2\u3059\u308b\u95a2\u6570\u306b\u578b\u3092\u8ffd\u52a0\u3059\u308c\u3070\u826f\u3044\uff1f\n \u305d\u308c\u3067\u3082\u624b\u9593\u304c\u591a\u3044\uff1f\n \u3059\u3079\u3066\u306ePinView\u306b\u8ffd\u52a0\u3059\u308b\u3088\u308a\u306f\u30de\u30b7\uff1f\n \u8ffd\u52a0\u3059\u308b\u306b\u306f\u3001\u8d77\u52d5\u304b\u3089\u306e\u6642\u9593\u3092\u7ba1\u7406\u3059\u308b\u4ed5\u7d44\u307f\u304c\u5fc5\u8981\n \u53d6\u308a\u6562\u3048\u305a\u9762\u5012\u304f\u3055\u3044\u304b\u3089\u8ae6\u3081\u308b\u3002\n \u5468\u8fba\u6a5f\u5668\u306b\u8a2d\u5b9a\u3059\u308b\u3068\u5c65\u6b74\u304c\u53d6\u308c\u306a\u304f\u306a\u308b\uff1f\n \u5468\u8fba\u6a5f\u5668\u306b\u8a2d\u5b9a\u3057\u305f\u3053\u3068\u3092\u5c65\u6b74\u306b\u6b8b\u3057\u3066\u304a\u3051\u3070\u826f\u3044\u3002\n*)\n\n\/\/ TODO \u30d1\u30c3\u30b1\u30fc\u30b8\u6bce\u306e\u5dee\u7570\u306b\u5bfe\u5fdc\u3059\u308b\u305f\u3081\u306e\u521d\u671fabsprop\n\/\/\/\/\nfn rx110_64pins_initial_views (): (\n PODR_PERMISSION (Port0,BitPermissions8 (Permit,Permit,Permit,Permit,Permit,Permit,Permit,Permit)),\n PODR_V (Port0,Bits8(O,O,O,O,O,O,O,O)),\n \n)\n\n\/\/\n\/\/ \u5b9f\u88c5\n\/\/\n\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"ATS"} {"commit":"b3000185bcd34e07324d52a7b07f3050d021c0d5","subject":"Updating: very minorly","message":"Updating: very minorly\n","repos":"githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib","old_file":"projects\/MEDIUM\/ATS-extsolve\/ATS-extsolve-smt2\/patsolve_smt2_commarg.dats","new_file":"projects\/MEDIUM\/ATS-extsolve\/ATS-extsolve-smt2\/patsolve_smt2_commarg.dats","new_contents":"(*\n##\n## ATS-extsolve-smt2:\n## Outputing ATS-constraints\n## in the format of smt-lib2\n##\n*)\n\n(* ****** ****** *)\n\n(*\n\/\/\n** Author: Hongwei Xi\n** Authoremail: gmhwxiATgmailDOTcom\n** Start time: June, 2016\n\/\/\n** Author: William Blair\n** Authoremail: wdblairATgmailDOTcom\n** Start time: Some time in 2015\n\/\/\n*)\n\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_staload.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\nSTDIO = \"libc\/SATS\/stdio.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\n#define\nPATSOLVE_targetloc \".\/.ATS-extsolve\"\n\/\/\nstaload \"{$PATSOLVE}\/patsolve_cnstrnt.sats\"\nstaload \"{$PATSOLVE}\/patsolve_parsing.sats\"\n\/\/\n(* ****** ****** *)\n\nstaload \".\/patsolve_smt2_commarg.sats\"\nstaload \".\/patsolve_smt2_solving.sats\"\n\n(* ****** ****** *)\n\nimplement\nfprint_commarg(out, ca) = (\n\/\/\ncase+ ca of\n\/\/\n| CAhelp(str) =>\n fprint! (out, \"CAhelp(\", str, \")\")\n\/\/\n| CAgitem(str) =>\n fprint! (out, \"CAgitem(\", str, \")\")\n\/\/\n| CAinput(str) =>\n fprint! (out, \"CAinput(\", str, \")\")\n\/\/\n| CAoutput(knd, str) =>\n fprint! (out, \"CAoutput(\", knd, \", \", str, \")\")\n\/\/\n| CAprintln(str) =>\n fprint! (out, \"CAprintln(\", str, \")\")\n| CAprintfile(str) =>\n fprint! (out, \"CAprintfile(\", str, \")\")\n\/\/\n| CAargend((*void*)) => fprint! (out, \"CAargend(\", \")\")\n\/\/\n) (* end of [fprint_commarg] *)\n\n(* ****** ****** *)\n\nfun{\n} argv_getopt_at\n {n:int}{i:nat}\n(\n n: int n, argv: !argv(n), i: int i\n) : stropt =\n(\n\/\/\nif i < n\n then stropt_some (argv[i]) else stropt_none ()\n\/\/ end of [if]\n\/\/\n) (* end of [argv_getopt_at] *)\n\n(* ****** ****** *)\n\nimplement\npatsolve_smt2_cmdline\n (argc, argv) = let\n\/\/\nvtypedef\nres_vt = commarglst_vt\n\/\/\nfun\naux\n{n:int}\n{i:nat | i <= n}\n(\n argc: int n\n, argv: !argv(n)\n, i: int i, res0: res_vt\n) : res_vt = let\nin\n\/\/\nif\ni < argc\nthen let\n\/\/\nval arg = argv[i]\n\/\/\nin\n\/\/\ncase+ arg of\n\/\/\n| \"-h\" => let\n val ca =\n CAhelp(arg)\n val res0 =\n cons_vt(ca, res0)\n \/\/ end of [val]\n in\n aux(argc, argv, i+1, res0)\n end \/\/ end of ...\n| \"--help\" => let\n val ca =\n CAhelp(arg)\n val res0 =\n cons_vt(ca, res0)\n \/\/ end of [val]\n in\n aux(argc, argv, i+1, res0)\n end \/\/ end of ...\n\/\/\n| \"-i\" => let\n val ca =\n CAinput(arg)\n val res0 =\n cons_vt(ca, res0)\n \/\/ end of [val]\n in\n aux2(argc, argv, i+1, res0)\n end \/\/ end of ...\n| \"--input\" => let\n val ca =\n CAinput(arg)\n val res0 =\n cons_vt(ca, res0)\n \/\/ end of [val]\n in\n aux2(argc, argv, i+1, res0)\n end \/\/ end of ...\n\/\/\n| \"-o\" => let\n val ca =\n CAoutput(0, arg)\n val res0 =\n cons_vt(ca, res0)\n \/\/ end of [val]\n in\n aux2(argc, argv, i+1, res0)\n end \/\/ end of ...\n| \"--output\" => let\n val ca =\n CAoutput(0, arg)\n val res0 =\n cons_vt(ca, res0)\n \/\/ end of [val]\n in\n aux2(argc, argv, i+1, res0)\n end \/\/ end of ...\n| \"--output-w\" => let\n val ca =\n CAoutput(1, arg)\n val res0 =\n cons_vt(ca, res0)\n \/\/ end of [val]\n in\n aux2(argc, argv, i+1, res0)\n end \/\/ end of ...\n| \"--output-a\" => let\n val ca =\n CAoutput(2, arg)\n val res0 =\n cons_vt(ca, res0)\n \/\/ end of [val]\n in\n aux2(argc, argv, i+1, res0)\n end \/\/ end of ...\n\/\/\n| \"--println\" => let\n val ca =\n CAprintln(arg)\n val res0 =\n cons_vt(ca, res0)\n \/\/ end of [val]\n in\n aux2(argc, argv, i+1, res0)\n end \/\/ end of ...\n\/\/\n| \"--printfile\" => let\n val ca =\n CAprintfile(arg)\n val res0 =\n cons_vt(ca, res0)\n \/\/ end of [val]\n in\n aux2(argc, argv, i+1, res0)\n end \/\/ end of ...\n\/\/\n| _ (*rest*) => let\n val ca =\n CAgitem(arg)\n val res0 =\n cons_vt(ca, res0)\n \/\/ end of [val]\n in\n aux(argc, argv, i+1, res0)\n end \/\/ end of [...]\n\/\/\nend \/\/ end of [then]\nelse res0 \/\/ end of [else]\n\/\/\nend \/\/ end of [aux]\n\/\/\nand\naux2\n{n:int}\n{i:nat | i <= n}\n(\n argc: int n\n, argv: !argv(n)\n, i: int i, res0: res_vt\n) : res_vt = let\nin\nif\ni < argc\nthen let\n\/\/\nval arg = argv[i]\n\/\/\nval ca =\n CAgitem(arg)\nval res0 =\n cons_vt(ca, res0)\n\/\/ end of [val]\nin\n aux(argc, argv, i+1, res0)\nend \/\/ end of [then]\nelse res0 \/\/ end of [else]\n\/\/\nend \/\/ end of [aux2]\n\/\/\nval args = aux(argc, argv, 0, nil_vt)\n\/\/\nin\n\/\/\nlist_vt_reverse(list_vt_cons(CAargend(), args))\n\/\/\nend \/\/ end of [patsolve_smt2_cmdline]\n\n(* ****** ****** *)\n\/\/\nextern fun patsolve_smt2_help(): void\n\/\/\nextern fun patsolve_smt2_gitem(string): void\n\/\/\nextern fun patsolve_smt2_input((*void*)): void\nextern fun patsolve_smt2_input_arg(string): void\n\/\/\nextern fun patsolve_smt2_output(knd: int): void\nextern fun patsolve_smt2_output_arg(string): void\n\/\/\nextern fun patsolve_smt2_println(): void\nextern fun patsolve_smt2_printfile(): void\nextern fun patsolve_smt2_printfile_arg(string): void\n\/\/\nextern fun patsolve_smt2_argend((*void*)): void\n\/\/\nextern fun patsolve_smt2_commarglst_finalize(): void\n\/\/\n(* ****** ****** *)\n\ntypedef\nstate_struct =\n@{\n\/\/\n nerr= int\n\/\/\n, input= int\n\/\/\n, ninput= int\n\/\/\n, inpfil_ref= FILEref\n\/\/\n, output= int\n\/\/\n, fopen_out= int\n, outfil_ref= FILEref\n, outfil_mod= file_mode\n\/\/\n, println= int\n, printfile= int\n\/\/\n, constraint_real= int\n\/\/\n} (* end of [state_struct] *)\n\n(* ****** ****** *)\n\nlocal\n\/\/\nvar\nthe_state: state_struct?\n\/\/\nval () = the_state.nerr := 0\n\/\/\nval () = the_state.input := 0\nval () = the_state.ninput := 0\n\/\/\nval () = the_state.inpfil_ref := stdin_ref\n\/\/\nval () = the_state.output := 0\n\/\/\nval () = the_state.fopen_out := 0\nval () = the_state.outfil_ref := stdout_ref\nval () = the_state.outfil_mod := file_mode_w\n\/\/\nval () = the_state.println := 0\nval () = the_state.printfile := 0\n\/\/\nval () = the_state.constraint_real := 0\n\/\/\nin (* in-of-local *)\n\/\/\nval\nthe_state\n : ref(state_struct) =\n ref_make_viewptr(view@the_state | addr@the_state)\n\/\/\nend \/\/ end of [local]\n\n(* ****** ****** *)\n\/\/\nimplement\nthe_constraint_real\n ((*void*)) = !the_state.constraint_real\n\/\/\n(* ****** ****** *)\n\nfun\nprocess_arg\n (x: commarg): void = let\n\/\/\n(*\nval () =\nfprintln!\n(\n stdout_ref\n, \"patsolve_smt2_commarglst: process_arg: x = \", x\n) (* end of [val] *)\n*)\n\/\/\nin\n\/\/\ncase+ x of\n\/\/\n| CAhelp _ => patsolve_smt2_help()\n\/\/\n| CAgitem\n (str) => patsolve_smt2_gitem(str)\n \/\/ CAgitem\n\/\/\n| CAinput _ => patsolve_smt2_input()\n\/\/\n| CAoutput\n (knd, _) => patsolve_smt2_output(knd)\n \/\/ CAoutput\n\/\/\n| CAprintln _ => patsolve_smt2_println()\n| CAprintfile _ => patsolve_smt2_printfile()\n\/\/\n| CAargend((*void*)) => patsolve_smt2_argend()\n\/\/\nend \/\/ end of [process_arg]\n\n(* ****** ****** *)\n\nimplement\npatsolve_smt2_commarglst\n (xs) = let\n(*\nval () = println! (\"patsolve_smt2_commarglst\")\n*)\nin\n\/\/\ncase+ xs of\n| ~list_vt_cons\n (x, xs) => let\n val () = process_arg(x)\n in\n patsolve_smt2_commarglst (xs)\n end \/\/ end of [list_vt_cons]\n\/\/\n| ~list_vt_nil\n ((*void*)) => patsolve_smt2_commarglst_finalize ()\n \/\/ end of [list_vt_nil]\n\/\/\nend \/\/ end of [patsolve_smt2_commarglst]\n\n(* ****** ****** *)\n\nimplement\npatsolve_smt2_help() = let\n\/\/\nval out = stdout_ref\nval cmdname = \"patsolve_smt2\"\n\/\/\nin\n\/\/\nfprintln!\n (out, \"Usage: \", cmdname, \" ... \\n\");\nfprintln!\n (out, \"where a is of one of the following forms:\\n\");\n\/\/\nfprintln! (out, \" -h (for printing out this help usage)\");\nfprintln! (out, \" -i (input from )\");\nfprintln! (out, \" -o (output into )\");\n\/\/\nfprintln! (out);\n\/\/\nfprintln! (out, \" --help (for printing out this help usage)\");\n\/\/\nfprintln! (out, \" --input (input from )\");\n\/\/\nfprintln! (out, \" --output (output into )\");\nfprintln! (out, \" --output-w (output-write into )\");\nfprintln! (out, \" --output-a (output-append into )\");\n\/\/\nfprintln! (out, \" --println (print +newline)\");\nfprintln! (out, \" --printfile (print the content of )\");\n\/\/\nfprintln! (out);\n\/\/\nend (* end of [patsolve_smt2_help] *)\n\n(* ****** ****** *)\n\nimplement\npatsolve_smt2_input() =\n{\n\/\/\n(*\nval () =\nprintln!\n (\"patsolve_smt2_input: ...\")\n*)\n\/\/\nval () = !the_state.input := 1\nval () = !the_state.println := 0\nval () = !the_state.printfile := 0\n\/\/\n} (* end of [patsolve_smt2_input] *)\n\n(* ****** ****** *)\n\nimplement\npatsolve_smt2_output\n (knd) =\n{\n\/\/\n(*\nval () =\nprintln!\n (\"patsolve_smt2_output: ...\")\n*)\n\/\/\nval () = !the_state.input := 0\nval () = !the_state.output := 1\nval () = !the_state.println := 0\nval () = !the_state.printfile := 0\n\/\/\nval () =\n(\n ifcase\n | knd = 1 => !the_state.outfil_mod := file_mode_w\n | knd = 2 => !the_state.outfil_mod := file_mode_a\n | _(* else *) => ()\n) : void \/\/ end of [val]\n\/\/\n} (* end of [patsolve_smt2_output] *)\n\n(* ****** ****** *)\n\nimplement\npatsolve_smt2_println\n ((*void*)) =\n{\n\/\/\n(*\nval () =\nprintln!\n (\"patsolve_smt2_print: ...\")\n*)\n\/\/\nval () = !the_state.input := 0\nval () = !the_state.println := 1\nval () = !the_state.printfile := 0\n\/\/\n} (* end of [patsolve_smt2_print] *)\n\n(* ****** ****** *)\n\nimplement\npatsolve_smt2_printfile\n ((*void*)) =\n{\n\/\/\n(*\nval () =\nprintln!\n (\"patsolve_smt2_print: ...\")\n*)\n\/\/\nval () = !the_state.input := 0\nval () = !the_state.println := 0\nval () = !the_state.printfile := 1\n\/\/\n} (* end of [patsolve_smt2_print] *)\n\n(* ****** ****** *)\n\nimplement\npatsolve_smt2_gitem(arg) = let\n\/\/\n(*\nval () =\nprintln!\n(\n \"patsolve_smt2_gitem: arg = \", arg\n) (* println! *)\n*)\n\/\/\nmacdef\ninput() = (!the_state.input > 0)\nmacdef\noutput() = (!the_state.output > 0)\nmacdef\nprintln() = (!the_state.println > 0)\nmacdef\nprintfile() = (!the_state.printfile > 0)\n\/\/\nin\n\/\/\ncase+ 0 of\n\/\/\n| _ when input() =>\n {\n val () = patsolve_smt2_input_arg(arg)\n val () =\n (\n !the_state.ninput := !the_state.ninput+1\n )\n } (* input() *)\n| _ when output() =>\n {\n val () = !the_state.output := 0\n val () = patsolve_smt2_output_arg(arg)\n } (* input() *)\n\/\/\n| _ when println() =>\n {\n val () =\n fprintln! (!the_state.outfil_ref, arg)\n \/\/ end of [val]\n } (* input() *)\n\/\/\n| _ when printfile() =>\n {\n val () = patsolve_smt2_printfile_arg(arg)\n } (* input() *)\n\/\/\n| _ when\n arg = \"--real-on\" =>\n {\n val () = !the_state.constraint_real := 1\n }\n| _ when\n arg = \"--real-off\" =>\n {\n val () = !the_state.constraint_real := 0\n }\n\/\/\n| _ (* unrecognized *) => ((*void*))\n\/\/\nend (* end of [patsolve_smt2_gitem] *)\n\n(* ****** ****** *)\n\nlocal\n\nfun\nauxmain\n (path: string): void = let\n\/\/\nval\nopt =\nfileref_open_opt(path, file_mode_r)\n\/\/\nin\n\/\/\ncase+ opt of\n| ~Some_vt(filr) =>\n {\n\/\/\n val c3t0 =\n parse_fileref_constraints(filr)\n \/\/ end of [val]\n val ((*void*)) = fileref_close(filr)\n\/\/\n(*\n val () =\n fprint! (\n stdout_ref\n , \"patsolve_smt2_input_arg: c3t0 =\\n\"\n ) (* end of [fprint] *)\n val () =\n fpprint_c3nstr(stdout_ref, c3t0)\n \/\/ end of [val]\n val () = fprint_newline (stdout_ref)\n*)\n\/\/\n val out = !the_state.outfil_ref\n val ((*void*)) = c3nstr_smt2_solve(out, c3t0)\n\/\/\n } (* end of [Some_vt] *)\n\/\/\n| ~None_vt((*void*)) =>\n {\n\/\/\n(*\n val () = !the_state.inpfil_ref := stdin_ref\n*)\n\/\/\n val () =\n prerrln!\n (\"The file [\", path, \"] cannot be opened for read!\")\n \/\/ end of [val]\n\/\/\n } (* end of [None_vt] *)\n\/\/\nend \/\/ end of [auxmain]\n\nin (* in-of-local *)\n\/\/\nimplement\npatsolve_smt2_input_arg\n (path) =\n(\n\/\/\ncase+\npath of\n| \"-\" =>\n {\n val inp = stdin_ref\n val out = !the_state.outfil_ref\n val c3t0 = parse_fileref_constraints(inp)\n val ((*void*)) = c3nstr_smt2_solve(out, c3t0)\n }\n| _(* ... *) => auxmain(path)\n\/\/\n) (* end of [patsolve_smt2_input_arg] *)\n\/\/\nend \/\/ end of [local]\n\n(* ****** ****** *)\n\nimplement\npatsolve_smt2_output_arg\n (path) = let\n\/\/\nval n1 = !the_state.fopen_out\nval f1 = !the_state.outfil_ref\nval () = if n1 > 0 then fileref_close(f1)\n\/\/\nval fm = !the_state.outfil_mod\nval opt = fileref_open_opt(path, fm)\n\/\/\nin\n\/\/\ncase+ opt of\n| ~Some_vt(filr) =>\n {\n\/\/\n val () = !the_state.fopen_out := 1\n val () = !the_state.outfil_ref := filr\n\/\/\n } (* end of [Some_vt] *)\n\/\/\n| ~None_vt((*void*)) =>\n {\n\/\/\n val () = !the_state.fopen_out := 0\n val () = !the_state.outfil_ref := stderr_ref\n\/\/\n val () =\n prerrln!\n (\"The file [\", path, \"] cannot be opened for write!\")\n \/\/ end of [val]\n\/\/\n } (* end of [None_vt] *)\n\/\/\nend \/\/ end of [patsolve_smt2_output_arg]\n\n(* ****** ****** *)\n\nimplement\npatsolve_smt2_printfile_arg\n (path) = let\n\/\/\nval fm = file_mode_r\nval opt =\n fileref_open_opt(path, fm)\n\/\/\nval out = !the_state.outfil_ref\n\/\/\nfun\nfcopy\n(\n inp: FILEref, out: FILEref\n) : void = let\n\/\/\nval iseof = fileref_is_eof(inp)\n\/\/\nin\n\/\/\nif\niseof\nthen\n fileref_close(inp)\nelse let\n\/\/\nval str =\n fileref_get_line_string(inp)\n\/\/ end of [va]\nval ((*void*)) = fprintln! (out, str)\nval ((*freed*)) = strptr_free(str)\n\/\/\nin\n fcopy(inp, out)\nend (* end of [else] *)\n\/\/\nend \/\/ end of [fcopy]\n\/\/\nin\n\/\/\ncase+ opt of\n| ~Some_vt(inp) =>\n fcopy(inp, out)\n \/\/ end of [Some_vt]\n| ~None_vt((*void*)) =>\n (\n fprintln! (out, \"(the-file-[\", path, \"]-cannot-open-for-read)\")\n ) (* end of [None_vt] *)\n\/\/\nend \/\/ end of [patsolve_smt2_printfile_arg]\n\n(* ****** ****** *)\n\nimplement\npatsolve_smt2_argend\n ((*void*)) = let\n\/\/\nmacdef test() =\n (!the_state.input > 0 && !the_state.ninput = 0)\n\/\/\nin\n\/\/\ncase+ 0 of\n| _ when test() =>\n {\n\/\/\n val inp = stdin_ref\n val out = !the_state.outfil_ref\n val c3t0 = parse_fileref_constraints(inp)\n val ((*void*)) = c3nstr_smt2_solve(out, c3t0)\n\/\/\n } (* end of [test] *)\n| _ (*rest*) => ((*ignored*))\n\/\/\nend (* end of [patsolve_smt2_argend] *)\n\n(* ****** ****** *)\n\nimplement\npatsolve_smt2_commarglst_finalize\n ((*void*)) =\n{\n\/\/\n val n1 = !the_state.fopen_out\n val f1 = !the_state.outfil_ref\n val () = if n1 > 0 then fileref_close(f1)\n\/\/\n} (* end of [patsolve_smt2_commarglst_finalize] *)\n\n(* ****** ****** *)\n\n(* end of [patsolve_smt2_commarg.dats] *)\n","old_contents":"(*\n##\n## ATS-extsolve-smt2:\n## Outputing ATS-constraints\n## in the format of smt-lib2\n##\n*)\n\n(* ****** ****** *)\n\n(*\n\/\/\n** Author: Hongwei Xi\n** Authoremail: gmhwxiATgmailDOTcom\n** Start time: June, 2016\n\/\/\n** Author: William Blair\n** Authoremail: wdblairATgmailDOTcom\n** Start time: Some time in 2015\n\/\/\n*)\n\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_staload.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\nSTDIO = \"libc\/SATS\/stdio.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\n#define\nPATSOLVE_targetloc \".\/.ATS-extsolve\"\n\/\/\nstaload \"{$PATSOLVE}\/patsolve_cnstrnt.sats\"\nstaload \"{$PATSOLVE}\/patsolve_parsing.sats\"\n\/\/\n(* ****** ****** *)\n\nstaload \".\/patsolve_smt2_commarg.sats\"\nstaload \".\/patsolve_smt2_solving.sats\"\n\n(* ****** ****** *)\n\nimplement\nfprint_commarg(out, ca) = (\n\/\/\ncase+ ca of\n\/\/\n| CAhelp(str) =>\n fprint! (out, \"CAhelp(\", str, \")\")\n\/\/\n| CAgitem(str) =>\n fprint! (out, \"CAgitem(\", str, \")\")\n\/\/\n| CAinput(str) =>\n fprint! (out, \"CAinput(\", str, \")\")\n\/\/\n| CAoutput(knd, str) =>\n fprint! (out, \"CAoutput(\", knd, \", \", str, \")\")\n\/\/\n| CAprintln(str) =>\n fprint! (out, \"CAprintln(\", str, \")\")\n| CAprintfile(str) =>\n fprint! (out, \"CAprintfile(\", str, \")\")\n\/\/\n| CAargend((*void*)) => fprint! (out, \"CAargend(\", \")\")\n\/\/\n) (* end of [fprint_commarg] *)\n\n(* ****** ****** *)\n\nfun{\n} argv_getopt_at\n {n:int}{i:nat}\n(\n n: int n, argv: !argv(n), i: int i\n) : stropt =\n(\n\/\/\nif i < n\n then stropt_some (argv[i]) else stropt_none ()\n\/\/ end of [if]\n\/\/\n) (* end of [argv_getopt_at] *)\n\n(* ****** ****** *)\n\nimplement\npatsolve_smt2_cmdline\n (argc, argv) = let\n\/\/\nvtypedef\nres_vt = commarglst_vt\n\/\/\nfun\naux\n{n:int}\n{i:nat | i <= n}\n(\n argc: int n\n, argv: !argv(n)\n, i: int i, res0: res_vt\n) : res_vt = let\nin\n\/\/\nif\ni < argc\nthen let\n\/\/\nval arg = argv[i]\n\/\/\nin\n\/\/\ncase+ arg of\n\/\/\n| \"-h\" => let\n val ca =\n CAhelp(arg)\n val res0 =\n cons_vt(ca, res0)\n \/\/ end of [val]\n in\n aux(argc, argv, i+1, res0)\n end \/\/ end of ...\n| \"--help\" => let\n val ca =\n CAhelp(arg)\n val res0 =\n cons_vt(ca, res0)\n \/\/ end of [val]\n in\n aux(argc, argv, i+1, res0)\n end \/\/ end of ...\n\/\/\n| \"-i\" => let\n val ca =\n CAinput(arg)\n val res0 =\n cons_vt(ca, res0)\n \/\/ end of [val]\n in\n aux2(argc, argv, i+1, res0)\n end \/\/ end of ...\n| \"--input\" => let\n val ca =\n CAinput(arg)\n val res0 =\n cons_vt(ca, res0)\n \/\/ end of [val]\n in\n aux2(argc, argv, i+1, res0)\n end \/\/ end of ...\n\/\/\n| \"-o\" => let\n val ca =\n CAoutput(0, arg)\n val res0 =\n cons_vt(ca, res0)\n \/\/ end of [val]\n in\n aux2(argc, argv, i+1, res0)\n end \/\/ end of ...\n| \"--output\" => let\n val ca =\n CAoutput(0, arg)\n val res0 =\n cons_vt(ca, res0)\n \/\/ end of [val]\n in\n aux2(argc, argv, i+1, res0)\n end \/\/ end of ...\n| \"--output-w\" => let\n val ca =\n CAoutput(1, arg)\n val res0 =\n cons_vt(ca, res0)\n \/\/ end of [val]\n in\n aux2(argc, argv, i+1, res0)\n end \/\/ end of ...\n| \"--output-a\" => let\n val ca =\n CAoutput(2, arg)\n val res0 =\n cons_vt(ca, res0)\n \/\/ end of [val]\n in\n aux2(argc, argv, i+1, res0)\n end \/\/ end of ...\n\/\/\n| \"--println\" => let\n val ca =\n CAprintln(arg)\n val res0 =\n cons_vt(ca, res0)\n \/\/ end of [val]\n in\n aux2(argc, argv, i+1, res0)\n end \/\/ end of ...\n\/\/\n| \"--printfile\" => let\n val ca =\n CAprintfile(arg)\n val res0 =\n cons_vt(ca, res0)\n \/\/ end of [val]\n in\n aux2(argc, argv, i+1, res0)\n end \/\/ end of ...\n\/\/\n| _ (*rest*) => let\n val ca =\n CAgitem(arg)\n val res0 =\n cons_vt(ca, res0)\n \/\/ end of [val]\n in\n aux(argc, argv, i+1, res0)\n end \/\/ end of [...]\n\/\/\nend \/\/ end of [then]\nelse res0 \/\/ end of [else]\n\/\/\nend \/\/ end of [aux]\n\/\/\nand\naux2\n{n:int}\n{i:nat | i <= n}\n(\n argc: int n\n, argv: !argv(n)\n, i: int i, res0: res_vt\n) : res_vt = let\nin\nif\ni < argc\nthen let\n\/\/\nval arg = argv[i]\n\/\/\nval ca =\n CAgitem(arg)\nval res0 =\n cons_vt(ca, res0)\n\/\/ end of [val]\nin\n aux(argc, argv, i+1, res0)\nend \/\/ end of [then]\nelse res0 \/\/ end of [else]\n\/\/\nend \/\/ end of [aux2]\n\/\/\nval args = aux(argc, argv, 0, nil_vt)\n\/\/\nin\n\/\/\nlist_vt_reverse(list_vt_cons(CAargend(), args))\n\/\/\nend \/\/ end of [patsolve_smt2_cmdline]\n\n(* ****** ****** *)\n\/\/\nextern fun patsolve_smt2_help(): void\n\/\/\nextern fun patsolve_smt2_gitem(string): void\n\/\/\nextern fun patsolve_smt2_input((*void*)): void\nextern fun patsolve_smt2_input_arg(string): void\n\/\/\nextern fun patsolve_smt2_output(knd: int): void\nextern fun patsolve_smt2_output_arg(string): void\n\/\/\nextern fun patsolve_smt2_println(): void\nextern fun patsolve_smt2_printfile(): void\nextern fun patsolve_smt2_printfile_arg(string): void\n\/\/\nextern fun patsolve_smt2_argend((*void*)): void\n\/\/\nextern fun patsolve_smt2_commarglst_finalize(): void\n\/\/\n(* ****** ****** *)\n\ntypedef\nstate_struct =\n@{\n\/\/\n nerr= int\n\/\/\n, input= int\n\/\/\n, ninput= int\n\/\/\n, inpfil_ref= FILEref\n\/\/\n, output= int\n\/\/\n, fopen_out= int\n, outfil_ref= FILEref\n, outfil_mod= file_mode\n\/\/\n, println= int\n, printfile= int\n\/\/\n, constraint_real= int\n\/\/\n} (* end of [state_struct] *)\n\n(* ****** ****** *)\n\nlocal\n\/\/\nvar\nthe_state: state_struct?\n\/\/\nval () = the_state.nerr := 0\n\/\/\nval () = the_state.input := 0\nval () = the_state.ninput := 0\n\/\/\nval () = the_state.inpfil_ref := stdin_ref\n\/\/\nval () = the_state.output := 0\n\/\/\nval () = the_state.fopen_out := 0\nval () = the_state.outfil_ref := stdout_ref\nval () = the_state.outfil_mod := file_mode_w\n\/\/\nval () = the_state.println := 0\nval () = the_state.printfile := 0\n\/\/\nval () = the_state.constraint_real := 0\n\/\/\nin (* in-of-local *)\n\/\/\nval\nthe_state\n : ref(state_struct) =\n ref_make_viewptr(view@the_state | addr@the_state)\n\/\/\nend \/\/ end of [local]\n\n(* ****** ****** *)\n\/\/\nimplement\nthe_constraint_real\n ((*void*)) = !the_state.constraint_real\n\/\/\n(* ****** ****** *)\n\nfun\nprocess_arg\n (x: commarg): void = let\n\/\/\n(*\nval () =\nfprintln!\n(\n stdout_ref\n, \"patsolve_smt2_commarglst: process_arg: x = \", x\n) (* end of [val] *)\n*)\n\/\/\nin\n\/\/\ncase+ x of\n\/\/\n| CAhelp _ => patsolve_smt2_help()\n\/\/\n| CAgitem\n (str) => patsolve_smt2_gitem(str)\n \/\/ CAgitem\n\/\/\n| CAinput _ => patsolve_smt2_input()\n\/\/\n| CAoutput\n (knd, _) => patsolve_smt2_output(knd)\n \/\/ CAoutput\n\/\/\n| CAprintln _ => patsolve_smt2_println()\n| CAprintfile _ => patsolve_smt2_printfile()\n\/\/\n| CAargend((*void*)) => patsolve_smt2_argend()\n\/\/\nend \/\/ end of [process_arg]\n\n(* ****** ****** *)\n\nimplement\npatsolve_smt2_commarglst\n (xs) = let\n(*\nval () = println! (\"patsolve_smt2_commarglst\")\n*)\nin\n\/\/\ncase+ xs of\n| ~list_vt_cons\n (x, xs) => let\n val () = process_arg(x)\n in\n patsolve_smt2_commarglst (xs)\n end \/\/ end of [list_vt_cons]\n\/\/\n| ~list_vt_nil\n ((*void*)) => patsolve_smt2_commarglst_finalize ()\n \/\/ end of [list_vt_nil]\n\/\/\nend \/\/ end of [patsolve_smt2_commarglst]\n\n(* ****** ****** *)\n\nimplement\npatsolve_smt2_help() = let\n\/\/\nval out = stdout_ref\nval cmdname = \"patsolve_smt2\"\n\/\/\nin\n\/\/\nfprintln!\n (out, \"Usage: \", cmdname, \" ... \\n\");\nfprintln!\n (out, \"where a is of one of the following forms:\\n\");\n\/\/\nfprintln! (out, \" -h (for printing out this help usage)\");\nfprintln! (out, \" -i (input from )\");\nfprintln! (out, \" -o (output into )\");\n\/\/\nfprintln! (out);\n\/\/\nfprintln! (out, \" --help (for printing out this help usage)\");\n\/\/\nfprintln! (out, \" --print (print +newline)\");\n\/\/\nfprintln! (out, \" --input (input from )\");\n\/\/\nfprintln! (out, \" --output (output into )\");\nfprintln! (out, \" --output-w (output-write into )\");\nfprintln! (out, \" --output-a (output-append into )\");\n\/\/\nfprintln! (out);\n\/\/\nend (* end of [patsolve_smt2_help] *)\n\n(* ****** ****** *)\n\nimplement\npatsolve_smt2_input() =\n{\n\/\/\n(*\nval () =\nprintln!\n (\"patsolve_smt2_input: ...\")\n*)\n\/\/\nval () = !the_state.input := 1\nval () = !the_state.println := 0\nval () = !the_state.printfile := 0\n\/\/\n} (* end of [patsolve_smt2_input] *)\n\n(* ****** ****** *)\n\nimplement\npatsolve_smt2_output\n (knd) =\n{\n\/\/\n(*\nval () =\nprintln!\n (\"patsolve_smt2_output: ...\")\n*)\n\/\/\nval () = !the_state.input := 0\nval () = !the_state.output := 1\nval () = !the_state.println := 0\nval () = !the_state.printfile := 0\n\/\/\nval () =\n(\n ifcase\n | knd = 1 => !the_state.outfil_mod := file_mode_w\n | knd = 2 => !the_state.outfil_mod := file_mode_a\n | _(* else *) => ()\n) : void \/\/ end of [val]\n\/\/\n} (* end of [patsolve_smt2_output] *)\n\n(* ****** ****** *)\n\nimplement\npatsolve_smt2_println\n ((*void*)) =\n{\n\/\/\n(*\nval () =\nprintln!\n (\"patsolve_smt2_print: ...\")\n*)\n\/\/\nval () = !the_state.input := 0\nval () = !the_state.println := 1\nval () = !the_state.printfile := 0\n\/\/\n} (* end of [patsolve_smt2_print] *)\n\n(* ****** ****** *)\n\nimplement\npatsolve_smt2_printfile\n ((*void*)) =\n{\n\/\/\n(*\nval () =\nprintln!\n (\"patsolve_smt2_print: ...\")\n*)\n\/\/\nval () = !the_state.input := 0\nval () = !the_state.println := 0\nval () = !the_state.printfile := 1\n\/\/\n} (* end of [patsolve_smt2_print] *)\n\n(* ****** ****** *)\n\nimplement\npatsolve_smt2_gitem(arg) = let\n\/\/\n(*\nval () =\nprintln!\n(\n \"patsolve_smt2_gitem: arg = \", arg\n) (* println! *)\n*)\n\/\/\nmacdef\ninput() = (!the_state.input > 0)\nmacdef\noutput() = (!the_state.output > 0)\nmacdef\nprintln() = (!the_state.println > 0)\nmacdef\nprintfile() = (!the_state.printfile > 0)\n\/\/\nin\n\/\/\ncase+ 0 of\n\/\/\n| _ when input() =>\n {\n val () = patsolve_smt2_input_arg(arg)\n val () =\n (\n !the_state.ninput := !the_state.ninput+1\n )\n } (* input() *)\n| _ when output() =>\n {\n val () = !the_state.output := 0\n val () = patsolve_smt2_output_arg(arg)\n } (* input() *)\n\/\/\n| _ when println() =>\n {\n val () =\n fprintln! (!the_state.outfil_ref, arg)\n \/\/ end of [val]\n } (* input() *)\n\/\/\n| _ when printfile() =>\n {\n val () = patsolve_smt2_printfile_arg(arg)\n } (* input() *)\n\/\/\n| _ when\n arg = \"--real-on\" =>\n {\n val () = !the_state.constraint_real := 1\n }\n| _ when\n arg = \"--real-off\" =>\n {\n val () = !the_state.constraint_real := 0\n }\n\/\/\n| _ (* unrecognized *) => ((*void*))\n\/\/\nend (* end of [patsolve_smt2_gitem] *)\n\n(* ****** ****** *)\n\nlocal\n\nfun\nauxmain\n (path: string): void = let\n\/\/\nval\nopt =\nfileref_open_opt(path, file_mode_r)\n\/\/\nin\n\/\/\ncase+ opt of\n| ~Some_vt(filr) =>\n {\n\/\/\n val c3t0 =\n parse_fileref_constraints(filr)\n \/\/ end of [val]\n val ((*void*)) = fileref_close(filr)\n\/\/\n(*\n val () =\n fprint! (\n stdout_ref\n , \"patsolve_smt2_input_arg: c3t0 =\\n\"\n ) (* end of [fprint] *)\n val () =\n fpprint_c3nstr(stdout_ref, c3t0)\n \/\/ end of [val]\n val () = fprint_newline (stdout_ref)\n*)\n\/\/\n val out = !the_state.outfil_ref\n val ((*void*)) = c3nstr_smt2_solve(out, c3t0)\n\/\/\n } (* end of [Some_vt] *)\n\/\/\n| ~None_vt((*void*)) =>\n {\n\/\/\n(*\n val () = !the_state.inpfil_ref := stdin_ref\n*)\n\/\/\n val () =\n prerrln!\n (\"The file [\", path, \"] cannot be opened for read!\")\n \/\/ end of [val]\n\/\/\n } (* end of [None_vt] *)\n\/\/\nend \/\/ end of [auxmain]\n\nin (* in-of-local *)\n\/\/\nimplement\npatsolve_smt2_input_arg\n (path) =\n(\n\/\/\ncase+\npath of\n| \"-\" =>\n {\n val inp = stdin_ref\n val out = !the_state.outfil_ref\n val c3t0 = parse_fileref_constraints(inp)\n val ((*void*)) = c3nstr_smt2_solve(out, c3t0)\n }\n| _(* ... *) => auxmain(path)\n\/\/\n) (* end of [patsolve_smt2_input_arg] *)\n\/\/\nend \/\/ end of [local]\n\n(* ****** ****** *)\n\nimplement\npatsolve_smt2_output_arg\n (path) = let\n\/\/\nval n1 = !the_state.fopen_out\nval f1 = !the_state.outfil_ref\nval () = if n1 > 0 then fileref_close(f1)\n\/\/\nval fm = !the_state.outfil_mod\nval opt = fileref_open_opt(path, fm)\n\/\/\nin\n\/\/\ncase+ opt of\n| ~Some_vt(filr) =>\n {\n\/\/\n val () = !the_state.fopen_out := 1\n val () = !the_state.outfil_ref := filr\n\/\/\n } (* end of [Some_vt] *)\n\/\/\n| ~None_vt((*void*)) =>\n {\n\/\/\n val () = !the_state.fopen_out := 0\n val () = !the_state.outfil_ref := stderr_ref\n\/\/\n val () =\n prerrln!\n (\"The file [\", path, \"] cannot be opened for write!\")\n \/\/ end of [val]\n\/\/\n } (* end of [None_vt] *)\n\/\/\nend \/\/ end of [patsolve_smt2_output_arg]\n\n(* ****** ****** *)\n\nimplement\npatsolve_smt2_printfile_arg\n (path) = let\n\/\/\nval fm = file_mode_r\nval opt =\n fileref_open_opt(path, fm)\n\/\/\nval out = !the_state.outfil_ref\n\/\/\nfun\nfcopy\n(\n inp: FILEref, out: FILEref\n) : void = let\n\/\/\nval iseof = fileref_is_eof(inp)\n\/\/\nin\n\/\/\nif\niseof\nthen\n fileref_close(inp)\nelse let\n\/\/\nval str =\n fileref_get_line_string(inp)\n\/\/ end of [va]\nval ((*void*)) = fprintln! (out, str)\nval ((*freed*)) = strptr_free(str)\n\/\/\nin\n fcopy(inp, out)\nend (* end of [else] *)\n\/\/\nend \/\/ end of [fcopy]\n\/\/\nin\n\/\/\ncase+ opt of\n| ~Some_vt(inp) =>\n fcopy(inp, out)\n \/\/ end of [Some_vt]\n| ~None_vt((*void*)) =>\n (\n fprintln! (out, \"(the-file-[\", path, \"]-cannot-open-for-read)\")\n ) (* end of [None_vt] *)\n\/\/\nend \/\/ end of [patsolve_smt2_printfile_arg]\n\n(* ****** ****** *)\n\nimplement\npatsolve_smt2_argend\n ((*void*)) = let\n\/\/\nmacdef test() =\n (!the_state.input > 0 && !the_state.ninput = 0)\n\/\/\nin\n\/\/\ncase+ 0 of\n| _ when test() =>\n {\n\/\/\n val inp = stdin_ref\n val out = !the_state.outfil_ref\n val c3t0 = parse_fileref_constraints(inp)\n val ((*void*)) = c3nstr_smt2_solve(out, c3t0)\n\/\/\n } (* end of [test] *)\n| _ (*rest*) => ((*ignored*))\n\/\/\nend (* end of [patsolve_smt2_argend] *)\n\n(* ****** ****** *)\n\nimplement\npatsolve_smt2_commarglst_finalize\n ((*void*)) =\n{\n\/\/\n val n1 = !the_state.fopen_out\n val f1 = !the_state.outfil_ref\n val () = if n1 > 0 then fileref_close(f1)\n\/\/\n} (* end of [patsolve_smt2_commarglst_finalize] *)\n\n(* ****** ****** *)\n\n(* end of [patsolve_smt2_commarg.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"f0bdd5c2677277ee01ffea90609ec349bba0f999","subject":"Use case with new compiler","message":"Use case with new compiler\n","repos":"Proclivis\/arduino-ats,fpiot\/arduino-ats,fpiot\/arduino-ats,Proclivis\/arduino-ats","old_file":"demo\/pwm_button_ats\/DATS\/main.dats","new_file":"demo\/pwm_button_ats\/DATS\/main.dats","new_contents":"#include \"config.hats\"\n#include \"{$TOP}\/avr_prelude\/kernel_staload.hats\"\n\nstaload \"{$TOP}\/SATS\/arduino.sats\"\nstaload UN = \"prelude\/SATS\/unsafe.sats\"\n\n#define LED 9\n#define BUTTON 7\n#define DELAY_MS 10.0\n\ntypedef state_dat = @{ state= natLt(2), brightness= natLt(256), start_time= ulint }\n#define STATE_LEDOFF 0\n#define STATE_LEDON 1\n\nfun state_transition (sd:state_dat):state_dat = @{ state= state, brightness= br, start_time= start } where {\n val state = case+ sd.state of\n | STATE_LEDOFF => STATE_LEDON\n | STATE_LEDON => STATE_LEDOFF\n val br = sd.brightness\n val start = millis ()\n}\n\nfun state_helddown (sd:state_dat):state_dat = @{ state= state, brightness= br, start_time= start } where {\n val state = sd.state\n val start = sd.start_time\n val t = if (state = STATE_LEDON) && (millis () - sd.start_time > $UN.cast 500)\n then sd.brightness + 1\n else sd.brightness\n val br = if gt_g0int_int (t, 255) then 0 else $UN.cast t\n}\n\nfun do_state (b: natLt(2), old_b:natLt(2), sd:state_dat): state_dat =\n case+ (b, old_b) of\n | (HIGH, LOW) => state_transition sd\n | (HIGH, HIGH) => state_helddown sd\n | (_, _) => sd\n\nfun do_action (sd:state_dat): void =\n case+ sd.state of\n | STATE_LEDON => analogWrite(LED, sd.brightness)\n | STATE_LEDOFF => analogWrite(LED, 0)\n\nimplement main () = {\n fun loop (old_b:natLt(2), sd:state_dat) = {\n val b = digitalRead (BUTTON)\n val nsd = do_state (b, old_b, sd)\n val () = delay_ms (DELAY_MS)\n val () = do_action nsd\n val () = loop (b, nsd)\n }\n val () = pinMode (LED, OUTPUT)\n val () = pinMode (BUTTON, INPUT)\n val () = loop (LOW, @{ state= STATE_LEDOFF, brightness= 128, start_time= $UN.cast 0 })\n}\n","old_contents":"#include \"config.hats\"\n#include \"{$TOP}\/avr_prelude\/kernel_staload.hats\"\n\nstaload \"{$TOP}\/SATS\/arduino.sats\"\nstaload UN = \"prelude\/SATS\/unsafe.sats\"\n\n#define LED 9\n#define BUTTON 7\n#define DELAY_MS 10.0\n\ntypedef state_dat = @{ state= natLt(2), brightness= natLt(256), start_time= ulint }\n#define STATE_LEDOFF 0\n#define STATE_LEDON 1\n\nfun state_transition (sd:state_dat):state_dat = @{ state= state, brightness= br, start_time= start } where {\n val state = case+ sd.state of\n | STATE_LEDOFF => STATE_LEDON\n | STATE_LEDON => STATE_LEDOFF\n val br = sd.brightness\n val start = millis ()\n}\n\nfun state_helddown (sd:state_dat):state_dat = @{ state= state, brightness= br, start_time= start } where {\n val state = sd.state\n val start = sd.start_time\n val t = if (state = STATE_LEDON) && (millis () - sd.start_time > $UN.cast 500)\n then sd.brightness + 1\n else sd.brightness\n val br = if gt_g0int_int (t, 255) then 0 else $UN.cast t\n}\n\nfun do_state (b: natLt(2), old_b:natLt(2), sd:state_dat): state_dat =\n if b = HIGH && old_b = LOW then state_transition sd\n else if b = HIGH && old_b = HIGH then state_helddown sd\n else sd\n\nfun do_action (sd:state_dat): void =\n case+ sd.state of\n | STATE_LEDON => analogWrite(LED, sd.brightness)\n | STATE_LEDOFF => analogWrite(LED, 0)\n\nimplement main () = {\n fun loop (old_b:natLt(2), sd:state_dat) = {\n val b = digitalRead (BUTTON)\n val nsd = do_state (b, old_b, sd)\n val () = delay_ms (DELAY_MS)\n val () = do_action nsd\n val () = loop (b, nsd)\n }\n val () = pinMode (LED, OUTPUT)\n val () = pinMode (BUTTON, INPUT)\n val () = loop (LOW, @{ state= STATE_LEDOFF, brightness= 128, start_time= $UN.cast 0 })\n}\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"20ee68b7285a5589f3abda98e993a1f7df3f83af","subject":"Updating: very minorly tidying-up","message":"Updating: very minorly tidying-up\n","repos":"bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib","old_file":"contrib\/libats-\/hwxi\/globals\/HATS\/gdeqarray.hats","new_file":"contrib\/libats-\/hwxi\/globals\/HATS\/gdeqarray.hats","new_contents":"(***********************************************************************)\n(* *)\n(* ATS\/contrib\/atshwxi *)\n(* *)\n(***********************************************************************)\n\n(*\n** Copyright (C) 2014 Hongwei Xi, ATS Trustful Software, Inc.\n**\n** Permission is hereby granted, free of charge, to any person obtaining a\n** copy of this software and associated documentation files (the \"Software\"),\n** to deal in the Software without restriction, including without limitation\n** the rights to use, copy, modify, merge, publish, distribute, sublicense,\n** and\/or sell copies of the Software, and to permit persons to whom the\n** Software is furnished to do so, subject to the following stated conditions:\n** \n** The above copyright notice and this permission notice shall be included in\n** all copies or substantial portions of the Software.\n** \n** THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n** OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n** THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n** FROM OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n** IN THE SOFTWARE.\n*)\n\n(* ****** ****** *)\n\n(*\nabsvt@ype T\n#define CAPACITY1 (= CAPACITY + 1)\n*)\n\n(* ****** ****** *)\n\nextern fun get_size ():<> size_t\nextern fun get_capacity ():<> size_t\n\n(* ****** ****** *)\n\nextern fun is_nil ():<> bool\nextern fun isnot_nil ():<> bool\nextern fun is_full ():<> bool\nextern fun isnot_full ():<> bool\n\n(* ****** ****** *)\n\/\/\nexception\nGDEQARRAYinsert of ()\n\/\/\nextern\nfun\ninsert_atbeg\n(\n x0: T, res: &T? >> opt (T, b)\n) : #[b:bool] bool(b) \/\/ endfun\n\/\/\nextern\nfun insert_atbeg_exn (x0: T): void\nextern\nfun insert_atbeg_opt (x0: T): Option_vt (T)\n\/\/\nextern\nfun\ninsert_atend\n(\n x0: T, res: &T? >> opt (T, b)\n) : #[b:bool] bool(b) \/\/ endfun\n\/\/\nextern\nfun insert_atend_exn (x0: T): void\nextern\nfun insert_atend_opt (x0: T): Option_vt (T)\n\/\/\n(* ****** ****** *)\n\/\/\nexception\nGDEQARRAYtakeout of ()\n\/\/\nextern\nfun\ntakeout_atbeg\n(\n x0: &T? >> opt (T, b)\n) : #[b:bool] bool (b) \/\/ endfun\n\/\/\nextern\nfun takeout_atbeg_exn ((*void*)): T\nextern\nfun takeout_atbeg_opt ((*void*)): Option_vt (T)\n\/\/\nextern\nfun\ntakeout_atend\n(\n x0: &T? >> opt (T, b)\n) : #[b:bool] bool (b) \/\/ endfun\n\/\/\nextern\nfun takeout_atend_exn ((*void*)): T\nextern\nfun takeout_atend_opt ((*void*)): Option_vt (T)\n\/\/\n(* ****** ****** *)\n\nlocal\n\/\/\nstaload\nUN = \"prelude\/SATS\/unsafe.sats\"\n\/\/\nstaload \"libats\/SATS\/deqarray.sats\"\nstaload _ = \"libats\/DATS\/deqarray.dats\"\n\/\/\n#define\nCAPACITY (CAPACITY1-1)\n\/\/\nlocal\n\/\/\nvar\n_array_ =\n@[T][CAPACITY1]()\n\/\/\nin(*in-of-local*)\nval\ntheArrayptr =\n$UN.castvwtp0{arrayptr(T?,CAPACITY1)}((view@_array_ | addr@_array_))\nend \/\/ end of [local]\n\/\/\nlocal\nval\ncap = CAPACITY\nvar\n_struct_\n: deqarray_tsize (*uninitized*)\n\/\/\nin (*in-of-local*)\nval\n(pfngc|theDQA0) =\ndeqarray_make_ngc__tsz{T}(view@_struct_ | addr@_struct_, theArrayptr, i2sz(cap), sizeof)\nend \/\/ end of [local]\n\/\/\nvtypedef\nDQA = [n:nat] deqarray(T, CAPACITY, n)\n\/\/\nval theDQA0_ptr = $UN.castvwtp0{ptr}((pfngc | theDQA0))\n\/\/\nin (* in-of-local *)\n\nimplement\nget_size () = res where\n{\n\/\/\nval dqa =\n$UN.castvwtp0{DQA}(theDQA0_ptr)\nval res = deqarray_get_size (dqa)\nprval ((*void*)) = $UN.cast2void (dqa)\n\/\/\n} (* end of [get_size] *)\n\nimplement\nget_capacity () = res where\n{\n\/\/\nval dqa =\n$UN.castvwtp0{DQA}(theDQA0_ptr)\nval res = deqarray_get_capacity (dqa)\nprval ((*void*)) = $UN.cast2void (dqa)\n\/\/\n} (* end of [get_capacity] *)\n\n(* ****** ****** *)\n\nimplement\nis_nil () = res where\n{\n\/\/\nval dqa =\n$UN.castvwtp0{DQA}(theDQA0_ptr)\nval res = deqarray_is_nil (dqa)\nprval ((*void*)) = $UN.cast2void (dqa)\n\/\/\n} (* end of [is_nil] *)\n\nimplement\nisnot_nil () = res where\n{\n\/\/\nval dqa =\n$UN.castvwtp0{DQA}(theDQA0_ptr)\nval res = deqarray_isnot_nil (dqa)\nprval ((*void*)) = $UN.cast2void (dqa)\n\/\/\n} (* end of [isnot_nil] *)\n\n(* ****** ****** *)\n\nimplement\nis_full () = res where\n{\n\/\/\nval dqa =\n$UN.castvwtp0{DQA}(theDQA0_ptr)\nval res = deqarray_is_full (dqa)\nprval ((*void*)) = $UN.cast2void (dqa)\n\/\/\n} (* end of [is_full] *)\n\nimplement\nisnot_full () = res where\n{\n\/\/\nval dqa =\n$UN.castvwtp0{DQA}(theDQA0_ptr)\nval res = deqarray_isnot_full (dqa)\nprval ((*void*)) = $UN.cast2void (dqa)\n\/\/\n} (* end of [isnot_full] *)\n\n(* ****** ****** *)\n\nimplement\ninsert_atbeg\n (x0, res) = let\n\/\/\nval dqa =\n$UN.castvwtp0{DQA}(theDQA0_ptr)\nval isnot = deqarray_isnot_full (dqa)\n\/\/\nin\n\/\/\nif isnot\n then let\n val () = deqarray_insert_atbeg (dqa, x0)\n prval ((*void*)) = opt_none (res)\n prval ((*void*)) = $UN.cast2void (dqa)\n in\n false\n end \/\/ end of [then]\n else let\n val () = res := x0\n prval ((*void*)) = opt_some (res)\n prval ((*void*)) = $UN.cast2void (dqa)\n in\n true\n end \/\/ end of [else]\n\/\/ end of [if]\n\/\/\nend \/\/ end of [insert_atbeg]\n\n(* ****** ****** *)\n\nimplement\ninsert_atbeg_exn(x0) = () where\n{\n\/\/\nval dqa =\n$UN.castvwtp0{DQA}(theDQA0_ptr)\n\/\/\nval ((*void*)) = (\n\/\/\nif\ndeqarray_isnot_full (dqa)\nthen deqarray_insert_atbeg (dqa, x0)\nelse $raise GDEQARRAYinsert((*void*))\n\/\/\n) : void \/\/ end of [val]\n\/\/\nprval ((*void*)) = $UN.cast2void (dqa)\n\/\/\n} (* end of [insert_atbeg_exn] *)\n\nimplement\ninsert_atbeg_opt(x0) = res where\n{\n\/\/\nval dqa =\n$UN.castvwtp0{DQA}(theDQA0_ptr)\nval res = deqarray_insert_atbeg_opt (dqa, x0)\nprval ((*void*)) = $UN.cast2void (dqa)\n\/\/\n} (* end of [insert_atbeg_opt] *)\n\n(* ****** ****** *)\n\nimplement\ninsert_atend\n (x0, res) = let\n\/\/\nval dqa =\n$UN.castvwtp0{DQA}(theDQA0_ptr)\nval isnot = deqarray_isnot_full (dqa)\n\/\/\nin\n\/\/\nif isnot\n then let\n val () = deqarray_insert_atend (dqa, x0)\n prval ((*void*)) = opt_none (res)\n prval ((*void*)) = $UN.cast2void (dqa)\n in\n false\n end \/\/ end of [then]\n else let\n val () = res := x0\n prval ((*void*)) = opt_some (res)\n prval ((*void*)) = $UN.cast2void (dqa)\n in\n true\n end \/\/ end of [else]\n\/\/ end of [if]\n\/\/\nend \/\/ end of [insert_atend]\n\n(* ****** ****** *)\n\nimplement\ninsert_atend_exn(x0) = () where\n{\n\/\/\nval dqa =\n$UN.castvwtp0{DQA}(theDQA0_ptr)\n\/\/\nval ((*void*)) = (\n\/\/\nif\ndeqarray_isnot_full (dqa)\nthen deqarray_insert_atend (dqa, x0)\nelse $raise GDEQARRAYinsert((*void*))\n\/\/\n) : void \/\/ end of [val]\n\/\/\nprval ((*void*)) = $UN.cast2void (dqa)\n\/\/\n} (* end of [insert_atend_exn] *)\n\nimplement\ninsert_atend_opt(x0) = res where\n{\n\/\/\nval dqa =\n$UN.castvwtp0{DQA}(theDQA0_ptr)\nval res = deqarray_insert_atend_opt (dqa, x0)\nprval ((*void*)) = $UN.cast2void (dqa)\n\/\/\n} (* end of [insert_atend_opt] *)\n\n(* ****** ****** *)\n\nimplement\ntakeout_atbeg(x0) = let\n\/\/\nval dqa =\n$UN.castvwtp0{DQA}(theDQA0_ptr)\nval isnot = deqarray_isnot_nil (dqa)\n\/\/\nin\n\/\/\nif isnot\n then let\n val () =\n x0 := deqarray_takeout_atbeg (dqa)\n prval () = opt_some{T}(x0)\n prval ((*void*)) = $UN.cast2void (dqa)\n in\n true\n end \/\/ end of [then]\n else let\n prval () = opt_none{T}(x0)\n prval ((*void*)) = $UN.cast2void (dqa)\n in\n false\n end \/\/ end of [else]\n\/\/ end of [if]\n\/\/\nend \/\/ end of [takeout_atbeg]\n\n(* ****** ****** *)\n\nimplement\ntakeout_atbeg_exn() = res where\n{\n\/\/\nval dqa =\n$UN.castvwtp0{DQA}(theDQA0_ptr)\n\/\/\nval res = (\n\/\/\nif\ndeqarray_isnot_nil(dqa)\nthen deqarray_takeout_atbeg (dqa)\nelse $raise GDEQARRAYtakeout((*void*))\n\/\/\n) : T \/\/ end of [val]\n\/\/\nprval ((*void*)) = $UN.cast2void (dqa)\n\/\/\n} (* end of [takeout_atbeg_exn] *)\n\nimplement\ntakeout_atbeg_opt() = res where\n{\n\/\/\nval dqa =\n$UN.castvwtp0{DQA}(theDQA0_ptr)\nval res = deqarray_takeout_atbeg_opt (dqa)\nprval ((*void*)) = $UN.cast2void (dqa)\n\/\/\n} (* end of [takeout_atbeg_opt] *)\n\n(* ****** ****** *)\n\nimplement\ntakeout_atend(x0) = let\n\/\/\nval dqa =\n$UN.castvwtp0{DQA}(theDQA0_ptr)\nval isnot = deqarray_isnot_nil (dqa)\n\/\/\nin\n\/\/\nif isnot\n then let\n val () =\n x0 := deqarray_takeout_atend (dqa)\n prval ((*void*)) = opt_some{T}(x0)\n prval ((*void*)) = $UN.cast2void (dqa)\n in\n true\n end \/\/ end of [then]\n else let\n prval ((*void*)) = opt_none{T}(x0)\n prval ((*void*)) = $UN.cast2void(dqa)\n in\n false\n end \/\/ end of [else]\n\/\/ end of [if]\n\/\/\nend \/\/ end of [takeout_atend]\n\n(* ****** ****** *)\n\nimplement\ntakeout_atend_exn() = res where\n{\n\/\/\nval dqa =\n$UN.castvwtp0{DQA}(theDQA0_ptr)\n\/\/\nval res = (\n\/\/\nif\ndeqarray_isnot_nil(dqa)\nthen deqarray_takeout_atend(dqa)\nelse $raise GDEQARRAYtakeout((*void*))\n\/\/\n) : T \/\/ end of [val]\n\/\/\nprval ((*void*)) = $UN.cast2void (dqa)\n\/\/\n} (* end of [takeout_atend_exn] *)\n\nimplement\ntakeout_atend_opt() = res where\n{\n\/\/\nval dqa =\n $UN.castvwtp0{DQA}(theDQA0_ptr)\n\/\/\nval res =\n deqarray_takeout_atend_opt (dqa)\n\/\/\nprval ((*void*)) = $UN.cast2void (dqa)\n\/\/\n} (* end of [takeout_atend_opt] *)\n\n(* ****** ****** *)\n\nend \/\/ end of [local]\n\n(* ****** ****** *)\n\n(* end of [gdeqarray.hats] *)\n","old_contents":"(***********************************************************************)\n(* *)\n(* ATS\/contrib\/atshwxi *)\n(* *)\n(***********************************************************************)\n\n(*\n** Copyright (C) 2014 Hongwei Xi, ATS Trustful Software, Inc.\n**\n** Permission is hereby granted, free of charge, to any person obtaining a\n** copy of this software and associated documentation files (the \"Software\"),\n** to deal in the Software without restriction, including without limitation\n** the rights to use, copy, modify, merge, publish, distribute, sublicense,\n** and\/or sell copies of the Software, and to permit persons to whom the\n** Software is furnished to do so, subject to the following stated conditions:\n** \n** The above copyright notice and this permission notice shall be included in\n** all copies or substantial portions of the Software.\n** \n** THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n** OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n** THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n** FROM OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n** IN THE SOFTWARE.\n*)\n\n(* ****** ****** *)\n\n(*\nabsvt@ype T\n#define CAPACITY1 (= CAPACITY + 1)\n*)\n\n(* ****** ****** *)\n\nextern fun get_size ():<> size_t\nextern fun get_capacity ():<> size_t\n\n(* ****** ****** *)\n\nextern fun is_nil ():<> bool\nextern fun isnot_nil ():<> bool\nextern fun is_full ():<> bool\nextern fun isnot_full ():<> bool\n\n(* ****** ****** *)\n\/\/\nexception\nGDEQARRAYinsert of ()\n\/\/\nextern\nfun\ninsert_atbeg\n(\n x0: T, res: &T? >> opt (T, b)\n) : #[b:bool] bool(b) \/\/ endfun\n\/\/\nextern\nfun insert_atbeg_exn (x0: T): void\nextern\nfun insert_atbeg_opt (x0: T): Option_vt (T)\n\/\/\nextern\nfun\ninsert_atend\n(\n x0: T, res: &T? >> opt (T, b)\n) : #[b:bool] bool(b) \/\/ endfun\n\/\/\nextern\nfun insert_atend_exn (x0: T): void\nextern\nfun insert_atend_opt (x0: T): Option_vt (T)\n\/\/\n(* ****** ****** *)\n\/\/\nexception\nGDEQARRAYtakeout of ()\n\/\/\nextern\nfun\ntakeout_atbeg\n(\n x0: &T? >> opt (T, b)\n) : #[b:bool] bool (b) \/\/ endfun\n\/\/\nextern\nfun takeout_atbeg_exn ((*void*)): T\nextern\nfun takeout_atbeg_opt ((*void*)): Option_vt (T)\n\/\/\nextern\nfun\ntakeout_atend\n(\n x0: &T? >> opt (T, b)\n) : #[b:bool] bool (b) \/\/ endfun\n\/\/\nextern\nfun takeout_atend_exn ((*void*)): T\nextern\nfun takeout_atend_opt ((*void*)): Option_vt (T)\n\/\/\n(* ****** ****** *)\n\nlocal\n\/\/\nstaload \"libats\/SATS\/deqarray.sats\"\nstaload _ = \"libats\/DATS\/deqarray.dats\"\n\/\/\nstaload UN = \"prelude\/SATS\/unsafe.sats\"\n\/\/\n#define\nCAPACITY (CAPACITY1-1)\n\/\/\nlocal\nvar _array = @[T][CAPACITY1]()\nin (*in-of-local*)\nval the_arrayptr =\n$UN.castvwtp0{arrayptr(T?,CAPACITY1)}((view@_array | addr@_array))\nend \/\/ end of [local]\n\/\/\nlocal\nval cap = CAPACITY\nvar _struct: deqarray_tsize \/\/ uninitized\nin (*in-of-local*)\nval (pfngc | the_deqarray) =\ndeqarray_make_ngc__tsz{T}(view@_struct | addr@_struct, the_arrayptr, i2sz(cap), sizeof)\nend \/\/ end of [local]\n\/\/\nvtypedef DQA = [n:nat] deqarray(T, CAPACITY, n)\nval the_deqarray_ptr = $UN.castvwtp0{ptr}((pfngc | the_deqarray))\n\/\/\nin (* in-of-local *)\n\nimplement\nget_size () = res where\n{\n\/\/\nval dqa =\n$UN.castvwtp0{DQA}(the_deqarray_ptr)\nval res = deqarray_get_size (dqa)\nprval ((*void*)) = $UN.cast2void (dqa)\n\/\/\n} (* end of [get_size] *)\n\nimplement\nget_capacity () = res where\n{\n\/\/\nval dqa =\n$UN.castvwtp0{DQA}(the_deqarray_ptr)\nval res = deqarray_get_capacity (dqa)\nprval ((*void*)) = $UN.cast2void (dqa)\n\/\/\n} (* end of [get_capacity] *)\n\n(* ****** ****** *)\n\nimplement\nis_nil () = res where\n{\n\/\/\nval dqa =\n$UN.castvwtp0{DQA}(the_deqarray_ptr)\nval res = deqarray_is_nil (dqa)\nprval ((*void*)) = $UN.cast2void (dqa)\n\/\/\n} (* end of [is_nil] *)\n\nimplement\nisnot_nil () = res where\n{\n\/\/\nval dqa =\n$UN.castvwtp0{DQA}(the_deqarray_ptr)\nval res = deqarray_isnot_nil (dqa)\nprval ((*void*)) = $UN.cast2void (dqa)\n\/\/\n} (* end of [isnot_nil] *)\n\n(* ****** ****** *)\n\nimplement\nis_full () = res where\n{\n\/\/\nval dqa =\n$UN.castvwtp0{DQA}(the_deqarray_ptr)\nval res = deqarray_is_full (dqa)\nprval ((*void*)) = $UN.cast2void (dqa)\n\/\/\n} (* end of [is_full] *)\n\nimplement\nisnot_full () = res where\n{\n\/\/\nval dqa =\n$UN.castvwtp0{DQA}(the_deqarray_ptr)\nval res = deqarray_isnot_full (dqa)\nprval ((*void*)) = $UN.cast2void (dqa)\n\/\/\n} (* end of [isnot_full] *)\n\n(* ****** ****** *)\n\nimplement\ninsert_atbeg\n (x0, res) = let\n\/\/\nval dqa =\n$UN.castvwtp0{DQA}(the_deqarray_ptr)\nval isnot = deqarray_isnot_full (dqa)\n\/\/\nin\n\/\/\nif isnot\n then let\n val () = deqarray_insert_atbeg (dqa, x0)\n prval ((*void*)) = opt_none (res)\n prval ((*void*)) = $UN.cast2void (dqa)\n in\n false\n end \/\/ end of [then]\n else let\n val () = res := x0\n prval ((*void*)) = opt_some (res)\n prval ((*void*)) = $UN.cast2void (dqa)\n in\n true\n end \/\/ end of [else]\n\/\/ end of [if]\n\/\/\nend \/\/ end of [insert_atbeg]\n\n(* ****** ****** *)\n\nimplement\ninsert_atbeg_exn(x0) = () where\n{\n\/\/\nval dqa =\n$UN.castvwtp0{DQA}(the_deqarray_ptr)\n\/\/\nval ((*void*)) = (\n\/\/\nif\ndeqarray_isnot_full (dqa)\nthen deqarray_insert_atbeg (dqa, x0)\nelse $raise GDEQARRAYinsert((*void*))\n\/\/\n) : void \/\/ end of [val]\n\/\/\nprval ((*void*)) = $UN.cast2void (dqa)\n\/\/\n} (* end of [insert_atbeg_exn] *)\n\nimplement\ninsert_atbeg_opt(x0) = res where\n{\n\/\/\nval dqa =\n$UN.castvwtp0{DQA}(the_deqarray_ptr)\nval res = deqarray_insert_atbeg_opt (dqa, x0)\nprval ((*void*)) = $UN.cast2void (dqa)\n\/\/\n} (* end of [insert_atbeg_opt] *)\n\n(* ****** ****** *)\n\nimplement\ninsert_atend\n (x0, res) = let\n\/\/\nval dqa =\n$UN.castvwtp0{DQA}(the_deqarray_ptr)\nval isnot = deqarray_isnot_full (dqa)\n\/\/\nin\n\/\/\nif isnot\n then let\n val () = deqarray_insert_atend (dqa, x0)\n prval ((*void*)) = opt_none (res)\n prval ((*void*)) = $UN.cast2void (dqa)\n in\n false\n end \/\/ end of [then]\n else let\n val () = res := x0\n prval ((*void*)) = opt_some (res)\n prval ((*void*)) = $UN.cast2void (dqa)\n in\n true\n end \/\/ end of [else]\n\/\/ end of [if]\n\/\/\nend \/\/ end of [insert_atend]\n\n(* ****** ****** *)\n\nimplement\ninsert_atend_exn(x0) = () where\n{\n\/\/\nval dqa =\n$UN.castvwtp0{DQA}(the_deqarray_ptr)\n\/\/\nval ((*void*)) = (\n\/\/\nif\ndeqarray_isnot_full (dqa)\nthen deqarray_insert_atend (dqa, x0)\nelse $raise GDEQARRAYinsert((*void*))\n\/\/\n) : void \/\/ end of [val]\n\/\/\nprval ((*void*)) = $UN.cast2void (dqa)\n\/\/\n} (* end of [insert_atend_exn] *)\n\nimplement\ninsert_atend_opt(x0) = res where\n{\n\/\/\nval dqa =\n$UN.castvwtp0{DQA}(the_deqarray_ptr)\nval res = deqarray_insert_atend_opt (dqa, x0)\nprval ((*void*)) = $UN.cast2void (dqa)\n\/\/\n} (* end of [insert_atend_opt] *)\n\n(* ****** ****** *)\n\nimplement\ntakeout_atbeg(x0) = let\n\/\/\nval dqa =\n$UN.castvwtp0{DQA}(the_deqarray_ptr)\nval isnot = deqarray_isnot_nil (dqa)\n\/\/\nin\n\/\/\nif isnot\n then let\n val () =\n x0 := deqarray_takeout_atbeg (dqa)\n prval () = opt_some{T}(x0)\n prval ((*void*)) = $UN.cast2void (dqa)\n in\n true\n end \/\/ end of [then]\n else let\n prval () = opt_none{T}(x0)\n prval ((*void*)) = $UN.cast2void (dqa)\n in\n false\n end \/\/ end of [else]\n\/\/ end of [if]\n\/\/\nend \/\/ end of [takeout_atbeg]\n\n(* ****** ****** *)\n\nimplement\ntakeout_atbeg_exn() = res where\n{\n\/\/\nval dqa =\n$UN.castvwtp0{DQA}(the_deqarray_ptr)\n\/\/\nval res = (\n\/\/\nif\ndeqarray_isnot_nil(dqa)\nthen deqarray_takeout_atbeg (dqa)\nelse $raise GDEQARRAYtakeout((*void*))\n\/\/\n) : T \/\/ end of [val]\n\/\/\nprval ((*void*)) = $UN.cast2void (dqa)\n\/\/\n} (* end of [takeout_atbeg_exn] *)\n\nimplement\ntakeout_atbeg_opt() = res where\n{\nval dqa =\n$UN.castvwtp0{DQA}(the_deqarray_ptr)\nval res = deqarray_takeout_atbeg_opt (dqa)\nprval ((*void*)) = $UN.cast2void (dqa)\n} (* end of [takeout_atbeg_opt] *)\n\n(* ****** ****** *)\n\nimplement\ntakeout_atend(x0) = let\n\/\/\nval dqa =\n$UN.castvwtp0{DQA}(the_deqarray_ptr)\nval isnot = deqarray_isnot_nil (dqa)\n\/\/\nin\n\/\/\nif isnot\n then let\n val () =\n x0 := deqarray_takeout_atend (dqa)\n prval ((*void*)) = opt_some{T}(x0)\n prval ((*void*)) = $UN.cast2void (dqa)\n in\n true\n end \/\/ end of [then]\n else let\n prval ((*void*)) = opt_none{T}(x0)\n prval ((*void*)) = $UN.cast2void (dqa)\n in\n false\n end \/\/ end of [else]\n\/\/ end of [if]\n\/\/\nend \/\/ end of [takeout_atend]\n\n(* ****** ****** *)\n\nimplement\ntakeout_atend_exn() = res where\n{\n\/\/\nval dqa =\n$UN.castvwtp0{DQA}(the_deqarray_ptr)\n\/\/\nval res = (\n\/\/\nif\ndeqarray_isnot_nil(dqa)\nthen deqarray_takeout_atend (dqa)\nelse $raise GDEQARRAYtakeout((*void*))\n\/\/\n) : T \/\/ end of [val]\n\/\/\nprval ((*void*)) = $UN.cast2void (dqa)\n\/\/\n} (* end of [takeout_atend_exn] *)\n\nimplement\ntakeout_atend_opt() = res where\n{\n\/\/\nval dqa =\n $UN.castvwtp0{DQA}(the_deqarray_ptr)\n\/\/\nval res = deqarray_takeout_atend_opt (dqa)\nprval ((*void*)) = $UN.cast2void (dqa)\n\/\/\n} (* end of [takeout_atend_opt] *)\n\n(* ****** ****** *)\n\nend \/\/ end of [local]\n\n(* ****** ****** *)\n\n(* end of [gdeqarray.hats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"7a72338b3043f629e5090858a08404030621c109","subject":"Updating: very minorly improving","message":"Updating: very minorly improving\n","repos":"alex-ren\/Learn-ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib","old_file":"projects\/MEDIUM\/ATS-parse-emit\/Erlang\/SCRATCH\/scratch08.dats","new_file":"projects\/MEDIUM\/ATS-parse-emit\/Erlang\/SCRATCH\/scratch08.dats","new_contents":"(* ****** ****** *)\n\/\/\n\/\/ HX-2014-12-25:\n\/\/ For the purpose of\n\/\/ studying session types\n\/\/\n(* ****** ****** *)\n\/\/\nabstype send (a:vt@ype)\nabstype recv (a:vt@ype)\n\/\/\n(* ****** ****** *)\n\nabstype\nchseq (a:type, b:type)\n\n(* ****** ****** *)\n\nstadef nil = unit\nstadef :: (a:type, b:type) = chseq (a, b)\n\n(* ****** ****** *)\n\/\/\nabsvtype chpos(type)\nabsvtype chneg(type)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun{a:vt0p}\nchpos_send{ss:type}\n (ch: !chpos(send(a) :: ss) >> chpos(ss), x: a): void\nextern\nfun{a:vt0p}\nchpos_recv{ss:type}\n (ch: !chpos(recv(a) :: ss) >> chpos(ss), x: &a? >> _): void\nextern\nfun{a:vt0p}\nchpos_recv_val{ss:type}(ch: !chpos(recv(a) :: ss) >> chpos(ss)): a\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun{a:vt0p}\nchneg_recv{ss:type}\n (ch: !chneg(recv(a) :: ss) >> chneg(ss), x: a): void\nextern\nfun{a:vt0p}\nchneg_send{ss:type}\n (ch: !chneg(send(a) :: ss) >> chneg(ss), x: &a? >> _): void\nextern\nfun{a:vt0p}\nchneg_send_val{ss:type}(ch: !chneg(send(a) :: ss) >> chneg(ss)): a\n\/\/\n(* ****** ****** *)\n\nextern\nfun chpos_recv_close (ch: chpos(nil)): void\nextern\nfun chneg_send_close (ch: chneg(nil)): void\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nchpos_chneg_connect{ss:type} (ch1: chpos(ss), ch2: chneg(ss)): void\n\/\/\n(* ****** ****** *)\n\/\/\ndatatype\nsslist (a:t@ype) =\n| sslist_nil of (nil)\n| sslist_cons of (send(a) :: sslist(a))\n\/\/\n(*\ndatavtype\nchpos_sslist (a:t@ype) =\n| chpos_sslist_nil of ()\n| chpos_sslist_cons of (chpos(send(a) :: sslist(a)))\n*)\n\/\/\ndatavtype\nchneg_sslist (a:t@ype) =\n| chneg_sslist_nil of ()\n| chneg_sslist_cons of (chneg(send(a) :: sslist(a)))\n\/\/\n(* ****** ****** *)\n\/\/\n(*\nextern\nfun\nchpos_sslist\n {a:t0p}(chpos(sslist(a))): chpos_sslist(a)\nextern\nfun\nchneg_sslist_nil{a:t0p}(chneg(sslist(a))): void\nand\nchneg_sslist_cons\n {a:t0p}(chneg(sslist(a))): chneg(send(a) :: sslist(a))\n*)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nchneg_sslist\n {a:t0p}(chneg(sslist(a))): chneg_sslist(a)\nextern\nfun\nchpos_sslist_nil{a:t0p}(chpos(sslist(a))): void\nand\nchpos_sslist_cons\n {a:t0p}(chpos(sslist(a))): chpos(send(a) :: sslist(a))\n\/\/\n(* ****** ****** *)\n\nstaload\nUN = \"prelude\/SATS\/unsafe.sats\"\n\n(* ****** ****** *)\n\/\/\nabst@ype bit = int\n\/\/\nmacdef B0 = $UN.cast{bit}(0)\nmacdef B1 = $UN.cast{bit}(1)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nchneg_create{ss:type}\n (f: chpos(ss) - void): chneg(ss)\n\/\/\n(* ****** ****** *)\n\nextern\nfun int2bits{n:nat} (int(n)): chneg(sslist(bit))\n\n(* ****** ****** *)\n\nimplement\nint2bits(n) = let\n\/\/\nfun\nfserv{n:nat}\n(\n n: int(n), ch: chpos(sslist(bit))\n) : void = (\n\/\/\nif\nn > 0\nthen let\n val n2 = half(n)\n val bit =\n (\n if n = 2*n2 then B0 else B1\n ) : bit \/\/ end of [val]\n val ch = chpos_sslist_cons (ch)\n val ((*void*)) = chpos_send (ch, bit)\nin\n fserv (n2, ch)\nend \/\/ end of [then]\nelse chpos_sslist_nil (ch)\n\/\/\n) (* end of [fserv] *)\n\/\/\nin\n chneg_create{sslist(bit)}(llam (ch) => fserv (n, ch))\nend \/\/ end of [int2bits]\n\n(* ****** ****** *)\n\/\/\nextern\nfun succ_bits (chneg(sslist(bit))): chneg(sslist(bit))\nextern\nfun add_bits_bits (chneg(sslist(bit)), chneg(sslist(bit))): chneg(sslist(bit))\n\/\/\n(* ****** ****** *)\n\ntypedef bit_ = natLt(2)\n\n(* ****** ****** *)\n\nimplement\nsucc_bits(ch1) = let\n\/\/\nfun\nfserv\n(\n ch: chpos(sslist(bit))\n, ch1: chneg(sslist(bit))\n) : void = let\n\/\/\nval opt = chneg_sslist (ch1)\n\/\/\nin\n\/\/\ncase+ opt of\n| ~chneg_sslist_nil () => let\n val ch = chpos_sslist_cons (ch)\n val ((*void*)) = chpos_send (ch, B1)\n val ((*void*)) = chpos_sslist_nil (ch)\n in\n \/\/ nothing\n end \/\/ end of [chneg_sslist_nil]\n| ~chneg_sslist_cons (ch1) => let\n val bit = chneg_send_val (ch1)\n val bit_ = $UN.cast{bit_}(bit)\n val ch = chpos_sslist_cons (ch)\n in\n if bit_ = 0\n then let\n val () = chpos_send (ch, B1)\n in\n chpos_chneg_connect (ch, ch1)\n end \/\/ end of [then]\n else let\n val () = chpos_send (ch, B0)\n in\n fserv (ch, ch1)\n end \/\/ end of [else]\n end \/\/ end of [chneg_sslist_cons]\n\/\/\nend \/\/ end of [fserv]\n\/\/\nin\n chneg_create{sslist(bit)}(llam (ch) => fserv (ch, ch1))\nend \/\/ end of [succ_bits]\n \n(* ****** ****** *)\n\nimplement\nadd_bits_bits\n (ch1, ch2) = let\n\/\/\nfun\nfserv\n(\n ch: chpos(sslist(bit))\n, ch1: chneg(sslist(bit))\n, ch2: chneg(sslist(bit))\n) : void = let\n\/\/\nval opt1 = chneg_sslist (ch1)\n\/\/\nin\n\/\/\ncase+ opt1 of\n| ~chneg_sslist_nil () =>\n chpos_chneg_connect (ch, ch2)\n| ~chneg_sslist_cons (ch1) => let\n val opt2 = chneg_sslist (ch2)\n in\n case+ opt2 of\n | ~chneg_sslist_nil () => let\n val ch = chpos_sslist_cons (ch)\n in\n chpos_chneg_connect (ch, ch1)\n end \/\/ end of [chneg_sslist_nil]\n | ~chneg_sslist_cons (ch2) => let\n val b1 = chneg_send_val (ch1)\n and b2 = chneg_send_val (ch2)\n val b1_ = $UN.cast{natLt(2)}(b1)\n and b2_ = $UN.cast{natLt(2)}(b2)\n val ch = chpos_sslist_cons (ch)\n in\n case+ b1_ of\n | 0 => (chpos_send (ch, b2); fserv (ch, ch1, ch2))\n | 1 => (\n case+ b2_ of\n | 0 => (chpos_send (ch, B1); fserv (ch, ch1, ch2))\n | 1 => (chpos_send (ch, B0); fserv (ch, ch1, succ_bits(ch2)))\n ) (* end of [1] *)\n end \/\/ end of [chneg_sslist_cons]\n end \/\/ end of [chneg_sslist_cons]\n\/\/\nend \/\/ end of [fserv]\n\/\/\nin\n chneg_create{sslist(bit)}(llam (ch) => fserv (ch, ch1, ch2))\nend \/\/ end of [add_bits_bits]\n\n(* ****** ****** *)\n\n(* end of [scratch08.dats] *)\n","old_contents":"(* ****** ****** *)\n\/\/\n\/\/ HX-2014-12-25:\n\/\/ For the purpose of\n\/\/ studying session types\n\/\/\n(* ****** ****** *)\n\/\/\nabstype send (a:vt@ype)\nabstype recv (a:vt@ype)\n\/\/\n(* ****** ****** *)\n\nabstype\nchseq (a:type, b:type)\n\n(* ****** ****** *)\n\nstadef nil = unit\nstadef :: (a:type, b:type) = chseq (a, b)\n\n(* ****** ****** *)\n\/\/\nabsvtype chpos(type)\nabsvtype chneg(type)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun{a:vt0p}\nchpos_send{ss:type}\n (ch: !chpos(send(a) :: ss) >> chpos(ss), x: a): void\nextern\nfun{a:vt0p}\nchpos_recv{ss:type}\n (ch: !chpos(recv(a) :: ss) >> chpos(ss), x: &a? >> _): void\nextern\nfun{a:vt0p}\nchpos_recv_val{ss:type}(ch: !chpos(recv(a) :: ss) >> chpos(ss)): a\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun{a:vt0p}\nchneg_recv{ss:type}\n (ch: !chneg(recv(a) :: ss) >> chneg(ss), x: a): void\nextern\nfun{a:vt0p}\nchneg_send{ss:type}\n (ch: !chneg(send(a) :: ss) >> chneg(ss), x: &a? >> _): void\nextern\nfun{a:vt0p}\nchneg_send_val{ss:type}(ch: !chneg(send(a) :: ss) >> chneg(ss)): a\n\/\/\n(* ****** ****** *)\n\nextern\nfun chpos_recv_close (ch: chpos(nil)): void\nextern\nfun chneg_send_close (ch: chneg(nil)): void\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nchpos_chneg_connect{ss:type} (ch1: chpos(ss), ch2: chneg(ss)): void\n\/\/\n(* ****** ****** *)\n\/\/\ndatatype\nsslist (a:t@ype) =\n| sslist_nil of (nil)\n| sslist_cons of (send(a) :: sslist(a))\n\/\/\n(*\ndatavtype\nchpos_sslist (a:t@ype) =\n| chpos_sslist_nil of ()\n| chpos_sslist_cons of (chpos(send(a) :: sslist(a)))\n*)\n\/\/\ndatavtype\nchneg_sslist (a:t@ype) =\n| chneg_sslist_nil of ()\n| chneg_sslist_cons of (chneg(send(a) :: sslist(a)))\n\/\/\n(* ****** ****** *)\n\/\/\n(*\nextern\nfun\nchpos_sslist\n {a:t0p}(chpos(sslist(a))): chpos_sslist(a)\nextern\nfun\nchneg_sslist_nil{a:t0p}(chneg(sslist(a))): void\nand\nchneg_sslist_cons\n {a:t0p}(chneg(sslist(a))): chneg(send(a) :: sslist(a))\n*)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nchneg_sslist\n {a:t0p}(chneg(sslist(a))): chneg_sslist(a)\nextern\nfun\nchpos_sslist_nil{a:t0p}(chpos(sslist(a))): void\nand\nchpos_sslist_cons\n {a:t0p}(chpos(sslist(a))): chpos(send(a) :: sslist(a))\n\/\/\n(* ****** ****** *)\n\nstaload\nUN = \"prelude\/SATS\/unsafe.sats\"\n\n(* ****** ****** *)\n\/\/\nabst@ype bit = natLt(2)\n\/\/\nmacdef B0 = $UN.cast{bit}(0)\nmacdef B1 = $UN.cast{bit}(1)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nchneg_create{ss:type}\n (f: chpos(ss) - void): chneg(ss)\n\/\/\n(* ****** ****** *)\n\nextern\nfun int2bits{n:nat} (int(n)): chneg(sslist(bit))\n\n(* ****** ****** *)\n\nimplement\nint2bits (n) = let\n\/\/\nfun\nfserv{n:nat}\n(\n n: int(n), ch: chpos(sslist(bit))\n) : void = (\n\/\/\nif\nn > 0\nthen let\n val n2 = half(n)\n val bit = (if n = 2*n2 then 0 else 1): natLt(2)\n val bit = $UN.cast{bit}(bit)\n val ch = chpos_sslist_cons (ch)\n val ((*void*)) = chpos_send (ch, bit)\nin\n fserv (n2, ch)\nend \/\/ end of [then]\nelse chpos_sslist_nil (ch)\n\/\/\n) (* end of [fserv] *)\n\/\/\nin\n chneg_create{sslist(bit)}(llam (ch) => fserv (n, ch))\nend \/\/ end of [int2bits]\n\n(* ****** ****** *)\n\/\/\nextern\nfun succ_bits (chneg(sslist(bit))): chneg(sslist(bit))\nextern\nfun add_bits_bits (chneg(sslist(bit)), chneg(sslist(bit))): chneg(sslist(bit))\n\/\/\n(* ****** ****** *)\n\nimplement\nsucc_bits (ch1) = let\n\/\/\nfun\nfserv\n(\n ch: chpos(sslist(bit))\n, ch1: chneg(sslist(bit))\n) : void = let\n\/\/\nval opt = chneg_sslist (ch1)\n\/\/\nin\n\/\/\ncase+ opt of\n| ~chneg_sslist_nil () => let\n val ch = chpos_sslist_cons (ch)\n val ((*void*)) = chpos_send (ch, B1)\n val ((*void*)) = chpos_sslist_nil (ch)\n in\n \/\/ nothing\n end \/\/ end of [chneg_sslist_nil]\n| ~chneg_sslist_cons (ch1) => let\n val ch = chpos_sslist_cons (ch)\n val bit = chneg_send_val (ch1)\n val bit = $UN.cast{natLt(0)}(bit)\n in\n if bit = 0\n then let\n val ((*void*)) = chpos_send (ch, B1)\n in\n chpos_chneg_connect (ch, ch1)\n end \/\/ end of [then]\n else let\n val ((*void*)) = chpos_send (ch, B0)\n in\n fserv (ch, ch1)\n end \/\/ end of [else]\n end \/\/ end of [chneg_sslist_cons]\n\/\/\nend \/\/ end of [fserv]\n\/\/\nin\n chneg_create{sslist(bit)}(llam (ch) => fserv (ch, ch1))\nend \/\/ end of [succ_bits]\n \n(* ****** ****** *)\n\nimplement\nadd_bits_bits\n (ch1, ch2) = let\n\/\/\nfun\nfserv\n(\n ch: chpos(sslist(bit))\n, ch1: chneg(sslist(bit))\n, ch2: chneg(sslist(bit))\n) : void = let\n\/\/\nval opt1 = chneg_sslist (ch1)\n\/\/\nin\n\/\/\ncase+ opt1 of\n| ~chneg_sslist_nil () =>\n chpos_chneg_connect (ch, ch2)\n| ~chneg_sslist_cons (ch1) => let\n val opt2 = chneg_sslist (ch2)\n in\n case+ opt2 of\n | ~chneg_sslist_nil () => let\n val ch = chpos_sslist_cons (ch)\n in\n chpos_chneg_connect (ch, ch1)\n end \/\/ end of [chneg_sslist_nil]\n | ~chneg_sslist_cons (ch2) => let\n val b1 = chneg_send_val (ch1)\n and b2 = chneg_send_val (ch2)\n val b1_ = $UN.cast{natLt(2)}(b1)\n and b2_ = $UN.cast{natLt(2)}(b2)\n val ch = chpos_sslist_cons (ch)\n in\n case+ b1_ of\n | 0 => (chpos_send (ch, b2); fserv (ch, ch1, ch2))\n | 1 => (\n case+ b2_ of\n | 0 => (chpos_send (ch, B1); fserv (ch, ch1, ch2))\n | 1 => (chpos_send (ch, B0); fserv (ch, ch1, succ_bits(ch2)))\n ) (* end of [1] *)\n end \/\/ end of [chneg_sslist_cons]\n end \/\/ end of [chneg_sslist_cons]\n\/\/\nend \/\/ end of [fserv]\n\/\/\nin\n chneg_create{sslist(bit)}(llam (ch) => fserv (ch, ch1, ch2))\nend \/\/ end of [add_bits_bits]\n\n(* ****** ****** *)\n\n(* end of [scratch08.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"bffcf9fe3e40199951773d1b926b3ca7817274a1","subject":"Updating: adding PEULER\/P16","message":"Updating: adding PEULER\/P16\n","repos":"bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib","old_file":"projects\/MEDIUM\/PEULER\/P16\/P16.sats","new_file":"projects\/MEDIUM\/PEULER\/P16\/P16.sats","new_contents":"(*\n** Project Euler: P16\n** See https:\/\/projecteuler.net\n*)\n(* ****** ****** *)\n\/\/\n\/\/ Author: Hongwei Xi\n\/\/ Authoremail: gmhwxiATgmailDOTcom\n\/\/ Start time: January 14, 2015\n\/\/\n(* ****** ****** *)\n\/\/\n#include \"share\/atspre_define.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\n\"{$LIBATSHWXI}\/PEULER\/SATS\/peuler.sats\"\n\/\/\n(* ****** ****** *)\n\n#define BASE 10\n\n(* ****** ****** *)\n\/\/\ndatatype\ndlist(int) =\n | dlist_nil(0) of ()\n | {d:nat | d < BASE}{n:nat}\n dlist_cons(d+n*BASE) of (int(d), dlist(n))\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nadd_dlist_dlist\n {m,n:nat}(m: dlist(m), n: dlist(n)): dlist(m+n)\n\/\/\n(* ****** ****** *)\n\/\/\nfun\ndlist_gen_exp2\n {n:nat}(n: int(n)): [r:int] (EXP2(n, r) | dlist(r))\n\/\/\n(* ****** ****** *)\n\nfun dlist_tally{n:nat}(ds: dlist(n)): int\n\n(* ****** ****** *)\n\n(* end of [P16.sats] *)\n","old_contents":"(*\n** Project Euler: P16\n** See https:\/\/projecteuler.net\n*)\n(* ****** ****** *)\n\/\/\n\/\/ Author: Hongwei Xi\n\/\/ Authoremail: gmhwxiATgmailDOTcom\n\/\/ Start time: January 14, 2015\n\/\/\n(* ****** ****** *)\n\/\/\n#include \"share\/atspre_define.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\n\"{$LIBATSHWXI}\/PEULER\/SATS\/peuler.sats\"\n\/\/\n(* ****** ****** *)\n\n#define BASE 10\n\n(* ****** ****** *)\n\/\/\ndatatype\ndlist(int) =\n | dlist_nil(0) of ()\n | {d:nat | d < BASE}{n:nat}\n dlist_cons(d+n*BASE) of (int(d), dlist(n))\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nadd_dlist_dlist\n {m,n:nat}\n (m: dlist(m), n: dlist(n)): dlist(m+n)\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nexp2{n:nat}\n (int(n)): [r:int] (EXP2(n, r) | dlist(r))\n\/\/\n(* ****** ****** *)\n\nfun dlist_sum{n:nat}(ds: dlist(n)): int\n\n(* ****** ****** *)\n\n(* end of [P16.sats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"e7add5477f4f355a8858b674208469f10c5b328e","subject":"Error handling","message":"Error handling\n","repos":"shlevy\/socket-activate","old_file":"dynamic\/socket-activate.dats","new_file":"dynamic\/socket-activate.dats","new_contents":"%{^\n#include \"include\/common.h\"\n%}\n\n#include \"share\/atspre_staload.hats\"\n\n#define ATS_DYNLOADFLAG 0\n\nstaload \"static\/fd.sats\"\nstaload \"static\/error.sats\"\n\nimplement main () = let\n extern fn perror(string_type): void = \"mac#perror\"\n\n val (pf | fd) = socket(AF_UNIX, SOCK_STREAM | ATS_AF_UNIX, ATS_SOCK_STREAM)\nin (if fd >= 0 then let\n prval Some_v pf = pf\n\n val (pf | res) = close(pf | fd)\nin (if res = ~1 then let\n prval Some_v e_obl = pf\n val _ = perror \"Closing socket\"\n prval _ = discharge_error_obligation e_obl\nin 2 end\nelse let\n prval None_v () = pf\nin 0 end): int end\nelse let\n prval None_v () = pf\n val _ = perror \"Creating socket\"\nin 1 end): int end\n","old_contents":"%{^\n#include \"include\/common.h\"\n%}\n\n#include \"share\/atspre_staload.hats\"\n\n#define ATS_DYNLOADFLAG 0\n\nstaload \"static\/fd.sats\"\nstaload \"static\/error.sats\"\n\nimplement main () = let\n val (pf | fd) = socket(AF_UNIX, SOCK_STREAM | ATS_AF_UNIX, ATS_SOCK_STREAM)\nin (if fd >= 0 then let\n prval Some_v pf = pf\n\n val (pf | res) = close(pf | fd)\nin (if res = ~1 then let\n prval Some_v e_obl = pf\n prval _ = discharge_error_obligation e_obl\nin 2 end\nelse let\n prval None_v () = pf\nin 0 end): int end\nelse let\n prval None_v () = pf\nin 1 end): int end\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"dc16c78f5da333d0ca2e139f3d825b8f07b86584","subject":"Updating: very minorly","message":"Updating: very minorly\n","repos":"bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib","old_file":"contrib\/arduino\/TEST\/QueenPuzzle\/QueenPuzzle.dats","new_file":"contrib\/arduino\/TEST\/QueenPuzzle\/QueenPuzzle.dats","new_contents":"(*\n#\n# QueenPuzzle\n#\n*)\n(* ****** ****** *)\n\n#define ATS_DYNLOADFLAG 0\n\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_define.hats\"\n#include\n\"{$ARDUINO}\/staloadall.hats\"\n\/\/\n(* ****** ****** *)\n\nstaload UN = \"prelude\/SATS\/unsafe.sats\"\n\n(* ****** ****** *)\n\/\/\n%{^\ntypedef char *charptr;\n%} \/\/ end of [%{^]\n\/\/\nabstype charptr = $extype\"charptr\"\n\/\/\n(* ****** ****** *)\n\/\/\n%{^\n#define N 8\nint theArray[N] =\n{\n 0,0,0,0,0,0,0,0\n} ;\n%} \/\/ end of [%{^]\n#define N 8\nmacdef theArray =\n $extval(arrayref(int,N),\"theArray\")\n\/\/\n(* ****** ****** *)\n\/\/\nfnx\nfind_next\n {n:pos}\n(\n A: arrayref(int, n), n: int(n)\n) : bool = let\n\/\/\nfun\nloop\n(\n i: natLte(n)\n) : natLte(n) =\n(\nif\ni < n\nthen\n if A[i] > 0 then loop (i+1) else i\nelse n\n) (* end of [loop] *)\n\/\/\nval i0 = loop (0)\n\/\/\nin\n\/\/\nif\ni0 < n\nthen\n(\n A[i0] := 1; find2_next (A, n, i0)\n) (* end of [then] *)\nelse\n(\n A[n-1] := A[n-1] + 1; find2_next (A, n, n-1)\n) (* end of [else] *)\n\/\/\nend \/\/ end of [find_next]\n\nand\nfind2_next\n {n:pos}\n(\n A: arrayref(int, n), n: int(n), i: natLt(n)\n) : bool = let\n\/\/\nfun\ntest\n(\n A: arrayref(int, n), i: natLt(n), j: intGte(0)\n) : bool =\n(\nif\nj >= i\nthen true\nelse\n(\nif\nA[i] = A[j]\nthen false\nelse (if (i-j=abs(A[i]-A[j])) then false else test(A, i, j+1))\n) (* end of [else] *)\n) (* end of [test] *)\n\/\/\nin\n\/\/\nif\nA[i] <= n\nthen let\nin\n\/\/\nif\ntest(A, i, 0)\nthen\n(\n if i+1=n then true else find_next(A, n)\n) (* end of [then] *)\nelse (A[i] := A[i]+1; find2_next(A, n, i))\n\/\/\nend \/\/ end of [then]\nelse let\n val () = A[i] := 0\nin\n if i > 0 then (A[i-1] := A[i-1]+1; find2_next (A, n, i-1)) else false\nend \/\/ end of [else]\n\/\/\nend \/\/ end of [find2_next]\n\n(* ****** ****** *)\n\nmacdef LEDPIN = 13\nmacdef BAUD_RATE = 9600\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nsetup (): void = \"mac#\"\n\/\/\nimplement\nsetup () = () where\n{\n\/\/\nval () = pinMode(LEDPIN, OUTPUT)\nval () = Serial_ptr._begin(BAUD_RATE)\n\/\/\n} (* end of [setup] *)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nfprint_val\n (out, x) = let\n\/\/\nfun\nndot(n: int): void =\nif n > 0 then\n(\n Serial_ptr.print(\". \"); ndot(n-1)\n) (* end of [if] *)\n\/\/\nval () = ndot(x-1)\nval () = Serial_ptr.print(\"Q \")\nval () = ndot(N-x)\nval () = Serial_ptr.println((*void*))\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [fprint_val]\n\n(* ****** ****** *)\n\/\/\nimplement\nfprint_string (out, x) = Serial_ptr.print(x)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nfprint_array$sep<> (out) = ()\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun loop (): void = \"mac#\"\n\/\/\nimplement\nloop () =\nmyloop() where\n{\nfun\nmyloop(): void = let\n\/\/\nval\nout = $extval (FILEref, \"0\")\n\/\/\n(*\nval () =\nrandomSeed($UN.cast{uint}(millis()))\n*)\n\/\/\nval A = theArray\nval found = find_next (A, N)\n\/\/\nval () =\nif found then\n{\n val () =\n fprint_arrayref (out, A, i2sz(N))\n val () = Serial_ptr.println()\n} (* end of [then] *)\n\/\/\nval () =\nif ~found then\n{\n\/\/\n val () =\n fprint_string (out, \"All solutions are found!\")\n val () = Serial_ptr.println()\n\/\/\n} (* end of [then] *)\n\/\/\nval () = digitalWrite(LEDPIN, 1)\nval () = delay(250)\nval () = digitalWrite(LEDPIN, 0)\nval () = delay(1000)\n\/\/\nin\n myloop ()\nend \/\/ end of [myloop]\n\/\/\n} (* end of [loop] *)\n\/\/\n(* ****** ****** *)\n\n(* end of [QueenPuzzle.dats] *)\n","old_contents":"(*\n#\n# QueenPuzzle\n#\n*)\n(* ****** ****** *)\n\n#define ATS_DYNLOADFLAG 0\n\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_define.hats\"\n#include\n\"{$ARDUINO}\/staloadall.hats\"\n\/\/\n(* ****** ****** *)\n\nstaload UN = \"prelude\/SATS\/unsafe.sats\"\n\n(* ****** ****** *)\n\/\/\n%{^\ntypedef char *charptr;\n%} \/\/ end of [%{^]\n\/\/\nabstype charptr = $extype\"charptr\"\n\/\/\n(* ****** ****** *)\n\/\/\n%{^\n#define N 8\nint theArray[N] =\n{\n 0,0,0,0,0,0,0,0\n} ;\n%} \/\/ end of [%{^]\n#define N 8\nmacdef theArray =\n $extval(arrayref(int,N),\"theArray\")\n\/\/\n(* ****** ****** *)\n\/\/\nfnx\nfind_next\n {n:pos}\n(\n A: arrayref(int, n), n: int(n)\n) : bool = let\n\/\/\nfun\nloop\n(\n i: natLte(n)\n) : natLte(n) =\n(\nif\ni < n\nthen\n if A[i] > 0 then loop (i+1) else i\nelse n\n) (* end of [loop] *)\n\/\/\nval i0 = loop (0)\n\/\/\nin\n\/\/\nif\ni0 < n\nthen\n(\n A[i0] := 1; find2_next (A, n, i0)\n) (* end of [then] *)\nelse\n(\n A[n-1] := A[n-1] + 1; find2_next (A, n, n-1)\n) (* end of [else] *)\n\/\/\nend \/\/ end of [find_next]\n\nand\nfind2_next\n {n:pos}\n(\n A: arrayref(int, n), n: int(n), i: natLt(n)\n) : bool = let\n\/\/\nfun\ntest\n(\n A: arrayref(int, n), i: natLt(n), j: intGte(0)\n) : bool =\n(\nif j >= i then true else\n (if A[i] = A[j] then false else if (i-j=abs(A[i]-A[j])) then false else test (A, i, j+1))\n) (* end of [test] *)\n\/\/\nin\n\/\/\nif\nA[i] <= n\nthen let\nin\n\/\/\nif test(A, i, 0)\n then\n (if i+1=n then true else find_next(A, n))\n else (A[i] := A[i]+1; find2_next(A, n, i))\n\/\/\nend \/\/ end of [then]\nelse let\n val () = A[i] := 0\nin\n if i > 0 then (A[i-1] := A[i-1]+1; find2_next (A, n, i-1)) else false\nend \/\/ end of [else]\n\/\/\nend \/\/ end of [find2_next]\n\n(* ****** ****** *)\n\nmacdef LEDPIN = 13\nmacdef BAUD_RATE = 9600\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nsetup (): void = \"mac#\"\n\/\/\nimplement\nsetup () = () where\n{\n\/\/\nval () = pinMode(LEDPIN, OUTPUT)\nval () = Serial_ptr._begin(BAUD_RATE)\n\/\/\n} (* end of [setup] *)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nfprint_val\n (out, x) = let\n\/\/\nfun\nndot(n: int): void =\nif n > 0 then\n(\n Serial_ptr.print(\". \"); ndot(n-1)\n) (* end of [if] *)\n\/\/\nval () = ndot(x-1)\nval () = Serial_ptr.print(\"Q \")\nval () = ndot(N-x)\nval () = Serial_ptr.println((*void*))\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [fprint_val]\n\n(* ****** ****** *)\n\/\/\nimplement\nfprint_string (out, x) = Serial_ptr.print(x)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nfprint_array$sep<> (out) = ()\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun loop (): void = \"mac#\"\n\/\/\nimplement\nloop () =\nmyloop() where\n{\nfun\nmyloop(): void = let\n\/\/\nval\nout = $extval (FILEref, \"0\")\n\/\/\n(*\nval () =\nrandomSeed($UN.cast{uint}(millis()))\n*)\n\/\/\nval A = theArray\nval found = find_next (A, N)\n\/\/\nval () =\nif found then\n{\n val () =\n fprint_arrayref (out, A, i2sz(N))\n val () = Serial_ptr.println()\n} (* end of [then] *)\n\/\/\nval () =\nif ~found then\n{\n\/\/\n val () =\n fprint_string (out, \"All solutions are found!\")\n val () = Serial_ptr.println()\n\/\/\n} (* end of [then] *)\n\/\/\nval () = digitalWrite(LEDPIN, 1)\nval () = delay(250)\nval () = digitalWrite(LEDPIN, 0)\nval () = delay(1000)\n\/\/\nin\n myloop ()\nend \/\/ end of [myloop]\n\/\/\n} (* end of [loop] *)\n\/\/\n(* ****** ****** *)\n\n(* end of [QueenPuzzle.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"1b93610caeb0cffb4c53af14b63f75515b99c1b8","subject":"Updating: minorly tidying-up","message":"Updating: minorly tidying-up\n","repos":"master-q\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib","old_file":"contrib\/libats-\/hwxi\/SIMD\/SATS\/v2df.sats","new_file":"contrib\/libats-\/hwxi\/SIMD\/SATS\/v2df.sats","new_contents":"(***********************************************************************)\n(* *)\n(* ATS\/contrib\/libats-hwxi *)\n(* *)\n(***********************************************************************)\n\n(*\n** Copyright (C) 2014 Hongwei Xi, ATS Trustful Software, Inc.\n**\n** Permission is hereby granted, free of charge, to any person obtaining a\n** copy of this software and associated documentation files (the \"Software\"),\n** to deal in the Software without restriction, including without limitation\n** the rights to use, copy, modify, merge, publish, distribute, sublicense,\n** and\/or sell copies of the Software, and to permit persons to whom the\n** Software is furnished to do so, subject to the following stated conditions:\n** \n** The above copyright notice and this permission notice shall be included in\n** all copies or substantial portions of the Software.\n** \n** THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n** OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n** THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n** FROM OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n** IN THE SOFTWARE.\n*)\n\n(* ****** ****** *)\n\/\/\n\/\/ HX-2014-06-04: ported from ATS1\n\/\/\n(* ****** ****** *)\n\/\/\n\/\/ for supporting SIMD on vectors of 2 doubles\n\/\/\n(* ****** ****** *)\n\n%{#\n\/\/\n#include \"SIMD\/CATS\/v2df.cats\"\n\/\/\n%} \/\/ end of [%{#]\n\n(* ****** ****** *)\n\n#define\nATS_PACKNAME \"ATSCNTRB.libats-hwxi.SIMD\"\n#define\nATS_EXTERN_PREFIX \"atscntrb_libatshwxi_SIMD_\"\n\n(* ****** ****** *)\n\/\/\nabst@ype v2df =\n$extype\"atscntrb_v2df_type\"\n\/\/\n(* ****** ****** *)\n\nval v2df_0_0: v2df = \"mac#%\"\nval v2df_1_1: v2df = \"mac#%\"\n\n(* ****** ****** *)\n\/\/\nfun v2df_get_fst (dd: v2df): double = \"mac#%\"\nfun v2df_get_snd (dd: v2df): double = \"mac#%\"\n\/\/\n(* ****** ****** *)\n\/\/\nsymintr v2df_make\n\/\/\nfun\nv2df_make_int_int\n (i0: int, i1: int): v2df = \"mac#%\"\nfun\nv2df_make_double_double\n (d0: double, d1: double): v2df = \"mac#%\"\n\/\/\noverload v2df_make with v2df_make_int_int\noverload v2df_make with v2df_make_double_double\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nadd_v2df_v2df\n (dd0: v2df, dd1: v2df): v2df = \"mac#%\"\nfun\nsub_v2df_v2df\n (dd0: v2df, dd1: v2df): v2df = \"mac#%\"\nfun\nmul_v2df_v2df\n (dd0: v2df, dd1: v2df): v2df = \"mac#%\"\nfun\ndiv_v2df_v2df\n (dd0: v2df, dd1: v2df): v2df = \"mac#%\"\n\/\/\noverload + with add_v2df_v2df of 0\noverload - with sub_v2df_v2df of 0\noverload * with mul_v2df_v2df of 0\noverload \/ with div_v2df_v2df of 0\n\/\/\n(* ****** ****** *)\n\n(* end of [v2df.sats] *)\n","old_contents":"(***********************************************************************)\n(* *)\n(* ATS\/contrib\/libats-hwxi *)\n(* *)\n(***********************************************************************)\n\n(*\n** Copyright (C) 2014 Hongwei Xi, ATS Trustful Software, Inc.\n**\n** Permission is hereby granted, free of charge, to any person obtaining a\n** copy of this software and associated documentation files (the \"Software\"),\n** to deal in the Software without restriction, including without limitation\n** the rights to use, copy, modify, merge, publish, distribute, sublicense,\n** and\/or sell copies of the Software, and to permit persons to whom the\n** Software is furnished to do so, subject to the following stated conditions:\n** \n** The above copyright notice and this permission notice shall be included in\n** all copies or substantial portions of the Software.\n** \n** THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n** OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n** THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n** FROM OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n** IN THE SOFTWARE.\n*)\n\n(* ****** ****** *)\n\/\/\n\/\/ HX-2014-06-04: ported from ATS1\n\/\/\n(* ****** ****** *)\n\/\/\n\/\/ for supporting SIMD on vectors of 2 doubles\n\/\/\n(* ****** ****** *)\n\n%{#\n\/\/\n#include \"SIMD\/CATS\/v2df.cats\"\n\/\/\n%} \/\/ end of [%{#]\n\n(* ****** ****** *)\n\n#define\nATS_PACKNAME \"ATSCNTRB.libats-hwxi.SIMD\"\n#define\nATS_EXTERN_PREFIX \"atscntrb_libatshwxi_SIMD_\"\n\n(* ****** ****** *)\n\/\/\nabst@ype v2df =\n$extype\"atscntrb_v2df_type\"\n\/\/\n(* ****** ****** *)\n\nval v2df_0_0: v2df = \"mac#%\"\nval v2df_1_1: v2df = \"mac#%\"\n\n(* ****** ****** *)\n\/\/\nfun v2df_get_fst (dd: v2df): double = \"mac#%\"\nfun v2df_get_snd (dd: v2df): double = \"mac#%\"\n\/\/\n(* ****** ****** *)\n\/\/\nsymintr v2df_make\n\/\/\nfun v2df_make_int_int\n (i0: int, i1: int): v2df = \"mac#%\"\nfun v2df_make_double_double\n (d0: double, d1: double): v2df = \"mac#%\"\n\/\/\noverload v2df_make with v2df_make_int_int\noverload v2df_make with v2df_make_double_double\n\/\/\n(* ****** ****** *)\n\/\/\nfun add_v2df_v2df\n (dd0: v2df, dd1: v2df): v2df = \"mac#%\"\nfun sub_v2df_v2df\n (dd0: v2df, dd1: v2df): v2df = \"mac#%\"\nfun mul_v2df_v2df\n (dd0: v2df, dd1: v2df): v2df = \"mac#%\"\nfun div_v2df_v2df\n (dd0: v2df, dd1: v2df): v2df = \"mac#%\"\n\/\/\noverload + with add_v2df_v2df of 0\noverload - with sub_v2df_v2df of 0\noverload * with mul_v2df_v2df of 0\noverload \/ with div_v2df_v2df of 0\n\/\/\n(* ****** ****** *)\n\n(* end of [v2df.sats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"fa429ecff29d7ea765b87d88889c81370c0b2a12","subject":"Cleaned up the insertion sort example a bit.","message":"Cleaned up the insertion sort example a bit.\n","repos":"githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib","old_file":"contrib\/libats-\/wdblair\/prelude\/TEST\/array_insort.dats","new_file":"contrib\/libats-\/wdblair\/prelude\/TEST\/array_insort.dats","new_contents":"\/\/ staload _ = \"prelude\/DATS\/integer.dats\"\n\n(* ****** ****** *)\n\nstaload \"contrib\/libats-\/wdblair\/prelude\/SATS\/array.sats\"\nstaload \"contrib\/libats-\/wdblair\/patsolve\/SATS\/stampseq.sats\"\n\n(* ****** ****** *)\n\n\/\/ assume T(a:t@ype, xs:stamp) = a\n\n(* ****** ****** *)\n\ntypedef cmp_fn(a:t@ype) = {l1,l2:addr} {x1,x2:stamp} (\n !T(a, x1) @ l1, !T(a, x2) @ l2 | \n ptr (l1), ptr (l2)) -> int (sgn(x1-x2))\n\n(* ****** ****** *)\n\nextern\npraxi array_sorted_len_lemma \n {a:t@ype} {l:addr} {xs:stmsq | ordered(xs)} {n:nat} (\n pf: !array_v (a, l, xs, n)\n): [sorted(xs, n)] void\n\nextern\npraxi array_ordered_lemma\n {a:t@ype} {l:addr} {n:nat} {xs:stmsq | sorted(xs, n)} (\n pf: !array_v (a, l, xs, n)\n): [ordered(xs)] void\n\n(* ****** ****** *)\n\n(**\n Shorthand to make the example more readable\n*)\n\n#define :: array_v_cons\n#define nil array_v_nil\n\nmacdef offset = ptr_offset\nmacdef swap = array_ptrswap\nmacdef split = array_v_split\nmacdef join = array_v_unsplit\n\n\n(* ****** ****** *)\n\nfn\nsort {a:t@ype} {l:addr} {xs:stmsq} {n:nat} .. (\n pf: array_v (a, l, xs, n) | \n p: ptr l, n: size_t n, sz: size_t (sizeof(a)), cmp: cmp_fn(a)\n): [ys:stmsq | ordered(ys)] (\n array_v (a, l, ys, n) | void\n) = let\n \n (**\n Short hand to abstract sz, which stays the same for the whole\n function.\n *)\n macdef ptrsucc(p) = add_ptr_bsz(,(p), sz)\n macdef ptrpred(p) = sub_ptr_bsz(,(p), sz)\n \n fun \n loop {m:nat | m <= n}\n {ys:stmsq | ordered(ys)} .. (\n pfsorted: array_v (a, l, ys, m), \n pfrem: array_v (a, l+m*sizeof(a), drop(xs, m), n-m) |\n ps: ptr l, pr: ptr (l+m*sizeof(a)), m: size_t (m)\n ): [zs:stmsq | ordered(zs)] (\n array_v (a, l, zs, n) | void\n ) =\n if m = n then let\n prval nil () = pfrem\n in \n (pfsorted | ())\n end\n else let\n \n fn\n insert {n:nat} {l:addr}\n {x:stamp} {xs:stmsq | ordered(xs)} .. (\n pfxs: array_v (a, l, xs, n), pfx: T(a, x) @ l + n*sizeof(a) | \n p: ptr l, px: ptr (l + n *sizeof(a)), n: size_t n\n ): [ys:stmsq | ordered(ys)] (\n array_v (a, l, ys, n+1) | void\n ) = let\n prval () = array_sorted_len_lemma (pfxs)\n prval pfxsx = array_v_extend (pfxs, pfx)\n \n fun\n loop {i:nat | i <= n} {x:stamp}\n {xs:stmsq | sorted(xs, n) ; lte(x, xs, i, n)} .. (\n pf: array_v (a, l, insert(xs, i, x), n+1) | px: ptr (l+i*sizeof(a))\n ): [j:nat | sorted(insert(xs, j, x), n+1)] (\n array_v (a, l, insert(xs, j, x), n+1) | void\n ) = \n if p = px then let\n prval () = equal_ptr_lemma {a} {l} {0,i} (p, px)\n in\n #[0 | (pf | ())]\n end\n else let \n val py = ptrpred(px)\n \n prval (front, last) = split (pf, offset{a}{l}{i}(p, px, sz))\n prval pfx :: pfxs = last\n prval (sortedfront, pfys) = split (front, offset{a}{l}{i-1}(p, py, sz))\n prval pfy :: pfyss = pfys\n\n val sgn = cmp (pfy, pfx | py, px)\n \n prval front = join (sortedfront, pfy :: pfyss)\n prval last = pfx :: pfxs\n prval () = pf := join (front, last)\n in\n if sgn <= 0 then\n (** \n Found our final position\n *) \n #[i | (pf | ())]\n else let\n (**\n py > px, swap and try again\n *)\n val () = swap {a}{l}{n+1}{i-1, i} (pf | py, px, sz)\n val [i':int] (pfins | ()) = loop {i-1} {x} {xs} (pf | py)\n in\n #[i' | (pfins | ())]\n end\n end\n \n val (pfins | ()) = loop {n}{x}{xs} (pfxsx | px)\n \n prval () = array_ordered_lemma (pfins)\n in\n (pfins | ())\n end\n \n prval array_v_cons (pfr, pfrss) = pfrem\n \n val (pfinserted | ()) = insert (pfsorted, pfr | ps, pr, m)\n in\n loop (pfinserted, pfrss | ps, ptrsucc(pr), succ(m))\n end\n \nin\n loop (array_v_nil(), pf | p, p, u2sz(0u))\nend\n\n\n \n\n \n\n\n \n","old_contents":"\/\/ staload _ = \"prelude\/DATS\/integer.dats\"\n\n(* ****** ****** *)\n\nstaload \"contrib\/libats-\/wdblair\/prelude\/SATS\/array.sats\"\nstaload \"contrib\/libats-\/wdblair\/patsolve\/SATS\/stampseq.sats\"\n\n(* ****** ****** *)\n\n\/\/ assume T(a:t@ype, xs:stamp) = a\n\n(* ****** ****** *)\n\ntypedef cmp_fn(a:t@ype) = {l1,l2:addr} {x1,x2:stamp} (\n !T(a, x1) @ l1, !T(a, x2) @ l2 | \n ptr (l1), ptr (l2)) -> int (sgn(x1-x2))\n\n(* ****** ****** *)\n\nextern\npraxi array_sorted_len_lemma \n {a:t@ype} {l:addr} {xs:stmsq | ordered(xs)} {n:nat} (\n pf: !array_v (a, l, xs, n)\n): [sorted(xs, n)] void\n\nextern\npraxi array_ordered_lemma\n {a:t@ype} {l:addr} {n:nat} {xs:stmsq | sorted(xs, n)} (\n pf: !array_v (a, l, xs, n)\n): [ordered(xs)] void\n\n(* ****** ****** *)\n\n#define :: array_v_cons\n\nfn\nsort {a:t@ype} {l:addr} {xs:stmsq} {n:nat} .. (\n pf: array_v (a, l, xs, n) | \n p: ptr l, n: size_t n, sz: size_t (sizeof(a)), cmp: cmp_fn(a)\n): [ys:stmsq | ordered(ys)] (\n array_v (a, l, ys, n) | void\n) = let\n\n fun \n loop {m:nat | m <= n}\n {ys:stmsq | ordered(ys)} .. (\n pfsorted: array_v (a, l, ys, m), \n pfrem: array_v (a, l+m*sizeof(a), drop(xs, m), n-m) |\n ps: ptr l, pr: ptr (l+m*sizeof(a)), m: size_t (m)\n ): [zs:stmsq | ordered(zs)] (\n array_v (a, l, zs, n) | void\n ) =\n if m = n then let\n prval array_v_nil () = pfrem\n in \n (pfsorted | ())\n end\n else let\n \n fn\n insert {n:nat} {l:addr}\n {x:stamp} {xs:stmsq | ordered(xs)} .. (\n pfxs: array_v (a, l, xs, n), pfx: T(a, x) @ l + n*sizeof(a) | \n p: ptr l, px: ptr (l + n *sizeof(a)), n: size_t n\n ): [ys:stmsq | ordered(ys)] (\n array_v (a, l, ys, n+1) | void\n ) = let\n prval () = array_sorted_len_lemma (pfxs)\n prval pfxsx = array_v_extend (pfxs, pfx)\n \n fun\n loop {i:nat | i <= n} {x:stamp}\n {xs:stmsq | sorted(xs, n) ; lte(x, xs, i, n)} .. (\n pf: array_v (a, l, insert(xs, i, x), n+1) | pi: ptr (l+i*sizeof(a))\n ): [j:nat | sorted(insert(xs, j, x), n+1)] (\n array_v (a, l, insert(xs, j, x), n+1) | void\n ) = \n if p = pi then let\n prval () = equal_ptr_lemma {a} {l} {0,i} (p, pi)\n in\n #[0 | (pf | ())]\n end\n else let \n val q = sub_ptr_bsz(pi, sz)\n \n prval (front, last) = array_v_split (pf, ptr_offset{a}{l}{i}(p, pi, sz))\n prval pfx :: pfxs = last\n prval (pff, pfis) = \n array_v_split (front, ptr_offset{a}{l}{i-1}(p, q, sz))\n prval pfi1 :: pfiss = pfis\n\n val sgn = cmp (pfi1, pfx | q, pi)\n \n prval front = array_v_unsplit (pff, pfi1 :: pfiss)\n prval last = pfx :: pfxs\n prval () = pf := array_v_unsplit (front, last)\n in\n if sgn < 0 then\n (** \n Found our final position\n *) \n #[i | (pf | ())]\n else let\n (**\n pi-1 > pi, swap and try again\n *)\n val () = array_ptrswap {a}{l}{n+1}{i-1, i} (pf | q, pi, sz)\n val [i':int] (pfins | ()) = loop {i-1} {x} {xs} (pf | q)\n in\n #[i' | (pfins | ())]\n end\n end\n \n val (pfins | ()) = loop {n}{x}{xs} (pfxsx | px)\n \n prval () = array_ordered_lemma (pfins)\n in\n (pfins | ())\n end\n \n prval array_v_cons (pfr, pfrss) = pfrem\n \n val (pfinserted | ()) = insert (pfsorted, pfr | ps, pr, m)\n in\n loop (pfinserted, pfrss | ps, add_ptr_bsz(pr, sz), succ(m))\n end\n \nin\n loop (array_v_nil(), pf | p, p, u2sz(0u))\nend\n\n\n \n\n \n\n\n \n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"d730d2679f5765f83c7016a469df4d9ef3835714","subject":"Updating: improving JSclock","message":"Updating: improving JSclock\n","repos":"alex-ren\/Learn-ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib","old_file":"projects\/SMALL\/JSclock\/myclock1-2.dats","new_file":"projects\/SMALL\/JSclock\/myclock1-2.dats","new_contents":"(*\n\/\/\nAn example of atscc2js: Wall Clock\n\/\/\nAuthor: Hongwei Xi\nAuthoremail: hwxi AT cs DOT bu DOT edu\nStart Time: September, 2014\n\/\/\nThis example is essentially translated from\nthe JS code at the following site:\n\/\/\nhttp:\/\/www.neilwallis.com\/projects\/html5\/clock\/\n\/\/\n*)\n\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_define.hats\"\n#include\n\"share\/atspre_staload.hats\"\n\/\/\n(* ****** ****** *)\n\n#define ATS_DYNLOADFLAG 0\n\n(* ****** ****** *)\n\/\/\nstaload\nUN = \"prelude\/SATS\/unsafe.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\n#include\n\"{$LIBATSCC2JS}\/staloadall.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\n\"{$LIBATSCC2JS}\/SATS\/HTML\/canvas-2d\/canvas2d.sats\"\n\/\/\n(* ****** ****** *)\n\nmacdef PI = JSmath_PI\nmacdef sin = JSmath_sin and cos = JSmath_cos\n\n(* ****** ****** *)\n\nfun\ndraw_mark\n(\n ctx: canvas2d, i: int\n) : void = {\n\/\/\nval a = PI\/30*i\nval sa = sin(a)\nval ca = cos(a)\nval sx = 110 * sa\nval sy = 110 * ca\nval ex = 120 * sa\nval ey = 120 * ca\n\/\/\nval () = ctx.lineWidth(2)\n\/\/\nval () = ctx.beginPath()\nval () = ctx.moveTo(sx, sy)\nval () = ctx.lineTo(ex, ey)\nval () = ctx.closePath()\n\/\/\nval () = ctx.stroke()\n\/\/\n} (* end of [draw_mark] *)\n\n(* ****** ****** *)\n\nfun\ndraw_mark2\n(\n ctx: canvas2d, i: int\n) : void = {\n\/\/\nval a = PI\/30*i\nval sa = sin(a)\nval ca = cos(a)\nval sx = 95 * sa\nval sy = ~95 * ca\nval ex = 120 * sa\nval ey = ~120 * ca\nval nx = 80 * sa\nval ny = ~80 * ca\n\/\/\nval () = ctx.fillText(toString(i\/5), nx, ny)\n\/\/\nval () = ctx.lineWidth(8)\n\/\/\nval () = ctx.beginPath()\nval () = ctx.moveTo(sx, sy)\nval () = ctx.lineTo(ex, ey)\nval () = ctx.closePath()\n\/\/\nval () = ctx.stroke()\n\/\/\n} (* end of [draw_mark2] *)\n\n(* ****** ****** *)\n\/\/\nextern\nfun\ndraw_clock\n(\n ctx: canvas2d\n, nhr: double, nmin: double, nsec: double\n) : void = \"mac#\" \/\/ end-of-fun\n\/\/\nimplement\ndraw_clock\n(\n ctx, nhr, nmin, nsec\n) = () where {\n\/\/\nval () = ctx.clearRect(0.0, 0.0, 300.0, 300.0)\n\/\/\n\/\/ Define gradients for 3D-shadow effect\n\/\/\nval g1 = ctx.createLinearGradient(0.0, 0.0, 300.0, 300.0)\nval () = g1.addColorStop(0.0, \"#D83040\")\nval () = g1.addColorStop(1.0, \"#801020\")\n\/\/\nval g2 = ctx.createLinearGradient(0.0, 0.0, 300.0, 300.0)\nval () = g2.addColorStop(0.0, \"#801020\")\nval () = g2.addColorStop(1.0, \"#D83040\")\n\/\/\nval () = ctx.font(\"bold 20px arial\")\nval () = ctx.textAlign(\"center\")\nval () = ctx.textBaseline(\"middle\")\nval () = ctx.lineWidth(1)\n\/\/\nval () = ctx.strokeStyle_gradient(g1)\nval () = ctx.lineWidth(10)\n\/\/\nval pf = ctx.save()\nval () = ctx.beginPath()\nval () = ctx.arc(150.0, 150.0, 138.0, 0.0, 2*PI, true)\nval () = ctx.closePath()\nval () = ctx.shadowBlur(6)\nval () = ctx.shadowOffsetX(4)\nval () = ctx.shadowOffsetY(4)\nval () = ctx.shadowColor(\"rgba(0,0,0,0.6)\")\nval () = ctx.stroke()\nval () = ctx.restore(pf.0 | (*none*))\n\/\/\nval () = ctx.strokeStyle_gradient(g2)\nval () = ctx.lineWidth(10)\n\/\/\nval pf = ctx.save()\nval () = ctx.beginPath()\nval () = ctx.arc(150.0, 150.0, 129.0, 0.0, 2*PI, true);\nval () = ctx.closePath()\nval () = ctx.stroke()\nval () = ctx.restore(pf.0 | (*none*))\n\/\/\nval () = ctx.strokeStyle(\"#222\")\n\/\/\nval pf = ctx.save()\n\/\/\nval () = ctx.translate(150.0, 150.0)\n\/\/\nval () = let\n\/\/\nfun loop\n(\n ctx: canvas2d, i: int\n) : void =\n(\nif\ni <= 60\nthen let\n val () =\n (\n if i % 5 != 0\n then draw_mark (ctx, i) else draw_mark2 (ctx, i)\n \/\/ end of [if]\n ) : void \/\/ end of [val]\nin\n loop (ctx, i+1)\nend \/\/ end of [then]\nelse () \/\/ end of [else]\n) (* end of [loop] *)\n\/\/\nin\n loop (ctx, 1)\nend \/\/ end of [val]\n\/\/\nval ampm =\n (if (nhr < 12.0) then \"AM\" else \"PM\"): string\n\/\/\nval () = ctx.strokeStyle(\"#000\")\nval () = ctx.lineWidth(1)\nval () = ctx.strokeRect(21.0, ~14.0, 44.0, 27.0)\nval () = ctx.fillText(ampm, 43.0, 0.0)\nval () = ctx.lineWidth(6)\n\/\/\nval () =\n{\n val pf = ctx.save()\n val () = ctx.rotate(nhr*PI\/6)\n val () = ctx.beginPath()\n val () = ctx.moveTo(0.0, 10.0)\n val () = ctx.lineTo(0.0, ~60.0)\n val () = ctx.closePath()\n val () = ctx.stroke()\n val () = ctx.restore(pf.0 | (*none*))\n} (* end of [val] *)\n\/\/\nval () =\n{\n val pf = ctx.save()\n val () = ctx.rotate(nmin*PI\/30)\n val () = ctx.beginPath()\n val () = ctx.moveTo(0.0, 20.0)\n val () = ctx.lineTo(0.0, ~110.0)\n val () = ctx.closePath()\n val () = ctx.stroke()\n val () = ctx.restore(pf.0 | (*none*))\n} (* end of [val] *)\n\/\/\nval () = ctx.lineWidth (3)\nval () = ctx.strokeStyle(\"#E33\")\n\/\/\nval () =\n{\n val pf = ctx.save()\n val () = ctx.rotate(nsec*PI\/30)\n val () = ctx.beginPath()\n val () = ctx.moveTo(0.0, 20.0)\n val () = ctx.lineTo(0.0, ~110.0)\n val () = ctx.closePath()\n val () = ctx.stroke()\n val () = ctx.restore(pf.0 | (*none*))\n} (* end of [val] *)\n\/\/\nval () = ctx.fillStyle(\"#000\")\n\/\/\nval () =\n{\n val pf = ctx.save()\n val () = ctx.beginPath()\n val () = ctx.arc(0.0, 0.0, 6.5, 0.0, 2*PI, true)\n val () = ctx.closePath()\n val () = ctx.fill()\n val () = ctx.restore(pf.0 | (*none*))\n} (* end of [val] *)\n\/\/\nval () = ctx.restore (pf.0 | (*none*))\n\/\/\n} (* end of [where] *) \/\/ [draw_clock]\n\/\/\n(* ****** ****** *)\n\n%{$\n\/\/\nvar\ncanvas =\ndocument.getElementById(\"Patsoptaas-Evaluate-Canvas\");\nvar context = canvas.getContext( '2d' );\n\/\/\nvar w = canvas.width\nvar h = canvas.height\nvar xc = w \/ 2\nvar yc = h \/ 2\nvar wh = Math.min (w, h)\nvar alpha = wh \/ 300\n\/\/\nfunction\ndraw2_clock()\n{\nvar date = new Date() ;\nvar secs = date.getSeconds()\nvar mins = date.getMinutes()\nvar mins = mins + secs \/ 60.0\nvar hours = date.getHours()\nvar hours = hours + mins \/ 60.0\n\/\/\ncontext.save();\ncontext.translate(xc-wh\/2, yc-wh\/2);\ncontext.scale (alpha, alpha);\ndraw_clock(context, hours, mins, secs);\ncontext.restore();\n\/\/\nsetTimeout(draw2_clock, 500);\n\/\/\nreturn;\n\/\/\n} \/\/ end of [draw2_clock]\n\/\/\njQuery(document).ready(function(){draw2_clock();});\n\/\/\n%} \/\/ end of [%{$]\n\n(* ****** ****** *)\n\n(* end of [myclock1-2.dats] *)\n","old_contents":"(*\n\/\/\nAn example of atscc2js: Wall Clock\n\/\/\nAuthor: Hongwei Xi\nAuthoremail: hwxi AT cs DOT bu DOT edu\nStart Time: September, 2014\n\/\/\nThis example is essentially translated from\nthe JS code at the following site:\n\/\/\nhttp:\/\/www.neilwallis.com\/projects\/html5\/clock\/\n\/\/\n*)\n\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_define.hats\"\n#include\n\"share\/atspre_staload.hats\"\n\/\/\n(* ****** ****** *)\n\n#define ATS_DYNLOADFLAG 0\n\n(* ****** ****** *)\n\/\/\nstaload\nUN = \"prelude\/SATS\/unsafe.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\n#include\n\"{$LIBATSCC2JS}\/staloadall.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\n\"{$LIBATSCC2JS}\/SATS\/HTML\/canvas-2d\/canvas2d.sats\"\n\/\/\n(* ****** ****** *)\n\nmacdef PI = JSmath_PI\nmacdef sin = JSmath_sin and cos = JSmath_cos\n\n(* ****** ****** *)\n\nfun\ndraw_mark\n(\n ctx: canvas2d, i: int\n) : void = {\n\/\/\nval a = PI\/30*i\nval sa = sin(a)\nval ca = cos(a)\nval sx = 110 * sa\nval sy = 110 * ca\nval ex = 120 * sa\nval ey = 120 * ca\n\/\/\nval () = ctx.lineWidth(2)\n\/\/\nval () = ctx.beginPath()\nval () = ctx.moveTo(sx, sy)\nval () = ctx.lineTo(ex, ey)\nval () = ctx.closePath()\n\/\/\nval () = ctx.stroke()\n\/\/\n} (* end of [draw_mark] *)\n\n(* ****** ****** *)\n\nfun\ndraw_mark2\n(\n ctx: canvas2d, i: int\n) : void = {\n\/\/\nval a = PI\/30*i\nval sa = sin(a)\nval ca = cos(a)\nval sx = 95 * sa\nval sy = ~95 * ca\nval ex = 120 * sa\nval ey = ~120 * ca\nval nx = 80 * sa\nval ny = ~80 * ca\n\/\/\nval () = ctx.fillText(toString(i\/5), nx, ny)\n\/\/\nval () = ctx.lineWidth(8)\n\/\/\nval () = ctx.beginPath()\nval () = ctx.moveTo(sx, sy)\nval () = ctx.lineTo(ex, ey)\nval () = ctx.closePath()\n\/\/\nval () = ctx.stroke()\n\/\/\n} (* end of [draw_mark2] *)\n\n(* ****** ****** *)\n\/\/\nextern\nfun\ndraw_clock\n(\n ctx: canvas2d\n, nhr: double, nmin: double, nsec: double\n) : void = \"mac#\" \/\/ end-of-fun\n\/\/\nimplement\ndraw_clock\n(\n ctx, nhr, nmin, nsec\n) = () where {\n\/\/\nval () = ctx.clearRect(0.0, 0.0, 300.0, 300.0)\n\/\/\n\/\/ Define gradients for 3D-shadow effect\n\/\/\nval g1 = ctx.createLinearGradient(0.0, 0.0, 300.0, 300.0)\nval () = g1.addColorStop(0.0, \"#D83040\")\nval () = g1.addColorStop(1.0, \"#801020\")\n\/\/\nval g2 = ctx.createLinearGradient(0.0, 0.0, 300.0, 300.0)\nval () = g2.addColorStop(0.0, \"#801020\")\nval () = g2.addColorStop(1.0, \"#D83040\")\n\/\/\nval () = ctx.font(\"bold 20px arial\")\nval () = ctx.textAlign(\"center\")\nval () = ctx.textBaseline(\"middle\")\nval () = ctx.lineWidth(1)\n\/\/\nval () = ctx.strokeStyle_gradient(g1)\nval () = ctx.lineWidth(10)\n\/\/\nval pf = ctx.save()\nval () = ctx.beginPath()\nval () = ctx.arc(150.0, 150.0, 138.0, 0.0, 2*PI, true)\nval () = ctx.closePath()\nval () = ctx.shadowBlur(6)\nval () = ctx.shadowOffsetX(4)\nval () = ctx.shadowOffsetY(4)\nval () = ctx.shadowColor(\"rgba(0,0,0,0.6)\")\nval () = ctx.stroke()\nval () = ctx.restore(pf.0 | (*none*))\n\/\/\nval () = ctx.strokeStyle_gradient(g2)\nval () = ctx.lineWidth(10)\n\/\/\nval pf = ctx.save()\nval () = ctx.beginPath()\nval () = ctx.arc(150.0, 150.0, 129.0, 0.0, 2*PI, true);\nval () = ctx.closePath()\nval () = ctx.stroke()\nval () = ctx.restore(pf.0 | (*none*))\n\/\/\nval () = ctx.strokeStyle(\"#222\")\n\/\/\nval pf = ctx.save()\n\/\/\nval () = ctx.translate(150.0, 150.0)\n\/\/\nval () = let\n\/\/\nfun loop\n(\n ctx: canvas2d, i: int\n) : void =\n(\nif\ni <= 60\nthen let\n val () =\n (\n if i % 5 != 0\n then draw_mark (ctx, i) else draw_mark2 (ctx, i)\n \/\/ end of [if]\n ) : void \/\/ end of [val]\nin\n loop (ctx, i+1)\nend \/\/ end of [then]\nelse () \/\/ end of [else]\n) (* end of [loop] *)\n\/\/\nin\n loop (ctx, 1)\nend \/\/ end of [val]\n\/\/\nval ampm =\n (if (nhr < 12.0) then \"AM\" else \"PM\"): string\n\/\/\nval () = ctx.strokeStyle(\"#000\")\nval () = ctx.lineWidth(1)\nval () = ctx.strokeRect(21.0, ~14.0, 44.0, 27.0)\nval () = ctx.fillText(ampm, 43.0, 0.0)\nval () = ctx.lineWidth(6)\n\/\/\nval () =\n{\n val pf = ctx.save()\n val () = ctx.rotate(nhr*PI\/6)\n val () = ctx.beginPath()\n val () = ctx.moveTo(0.0, 10.0)\n val () = ctx.lineTo(0.0, ~60.0)\n val () = ctx.closePath()\n val () = ctx.stroke()\n val () = ctx.restore(pf.0 | (*none*))\n} (* end of [val] *)\n\/\/\nval () =\n{\n val pf = ctx.save()\n val () = ctx.rotate(nmin*PI\/30)\n val () = ctx.beginPath()\n val () = ctx.moveTo(0.0, 20.0)\n val () = ctx.lineTo(0.0, ~110.0)\n val () = ctx.closePath()\n val () = ctx.stroke()\n val () = ctx.restore(pf.0 | (*none*))\n} (* end of [val] *)\n\/\/\nval () = ctx.lineWidth (3)\nval () = ctx.strokeStyle(\"#E33\")\n\/\/\nval () =\n{\n val pf = ctx.save()\n val () = ctx.rotate(nsec*PI\/30)\n val () = ctx.beginPath()\n val () = ctx.moveTo(0.0, 20.0)\n val () = ctx.lineTo(0.0, ~110.0)\n val () = ctx.closePath()\n val () = ctx.stroke()\n val () = ctx.restore(pf.0 | (*none*))\n} (* end of [val] *)\n\/\/\nval () = ctx.fillStyle(\"#000\")\n\/\/\nval () =\n{\n val pf = ctx.save()\n val () = ctx.beginPath()\n val () = ctx.arc(0.0, 0.0, 6.5, 0.0, 2*PI, true)\n val () = ctx.closePath()\n val () = ctx.fill()\n val () = ctx.restore(pf.0 | (*none*))\n} (* end of [val] *)\n\/\/\nval () = ctx.restore (pf.0 | (*none*))\n\/\/\n} (* end of [where] *) \/\/ [draw_clock]\n\/\/\n(* ****** ****** *)\n\n%{$\n\/\/\nvar\ncanvas =\ndocument.getElementById(\"Patsoptaas-Evaluate-Canvas\");\nvar context = canvas.getContext( '2d' );\n\/\/\nvar w = canvas.w\nvar h = canvas.h\nvar xc = w \/ 2\nvar yc = h \/ 2\nvar wh = Math.min (w, h)\nvar alpha = wh \/ 300\n\/\/\nfunction\ndraw2_clock()\n{\nvar date = new Date() ;\nvar secs = date.getSeconds()\nvar mins = date.getMinutes()\nvar mins = mins + secs \/ 60.0\nvar hours = date.getHours()\nvar hours = hours + mins \/ 60.0\n\/\/\ncontext.save();\ncontext.translate(xc-wh\/2, yc-wh\/2);\ncontext.scale (alpha, alpha);\ndraw_clock(context, hours, mins, secs);\ncontext.restore();\n\/\/\nsetTimeout(draw2_clock, 500);\n\/\/\nreturn;\n\/\/\n} \/\/ end of [draw2_clock]\n\/\/\njQuery(document).ready(function(){draw2_clock();});\n\/\/\n%} \/\/ end of [%{$]\n\n(* ****** ****** *)\n\n(* end of [myclock1-2.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"5e00a1e57931d2f39ac6dbc8f486ebcf2e5767e1","subject":"Use array","message":"Use array\n","repos":"Proclivis\/arduino-ats,Proclivis\/arduino-ats,fpiot\/arduino-ats,fpiot\/arduino-ats","old_file":"lcd_ats\/DATS\/lcd.dats","new_file":"lcd_ats\/DATS\/lcd.dats","new_contents":"(*\n * For LinkSprite 16X2 LCD Keypad Shield for Arduino\n * http:\/\/store.linksprite.com\/linksprite-16x2-lcd-keypad-shield-for-arduino-version-b\/\n * http:\/\/www.linksprite.com\/wiki\/index.php5?title=16_X_2_LCD_Keypad_Shield_for_Arduino\n *)\n#define ATS_DYNLOADFLAG 0 \/\/ no dynloading at run-time\n#include \"share\/atspre_define.hats\"\n#include \"share\/atspre_staload.hats\"\nstaload \"SATS\/arduino.sats\"\nstaload \"SATS\/lcd.sats\"\nstaload UN = \"prelude\/SATS\/unsafe.sats\"\n\n%{\ninline uint8_t atspre_uint8_bit_or(uint8_t a, uint8_t b) { return (a | b); }\ninline uint8_t atspre_uint8_bit_and(uint8_t a, uint8_t b) { return (a & b); }\n%}\nextern fun uint8_bit_or: (uint8, uint8) -> uint8 = \"mac#atspre_uint8_bit_or\"\nextern fun uint8_bit_and: (uint8, uint8) -> uint8 = \"mac#atspre_uint8_bit_and\"\n\n(* Private struct *)\nvtypedef LCD_struct = @{\n rs_pin = uint8 \/\/ LOW: command. HIGH: character.\n, rw_pin = uint8 \/\/ LOW: write to LCD. HIGH: read from LCD.\n, enable_pin = uint8 \/\/ activated by a HIGH pulse.\n, displayfunction = uint8\n, displaycontrol = uint8\n, displaymode = uint8\n, numlines = uint8\n, currline = uint8\n, data_pins = @[uint8][4]\n}\nabsvtype LCD_minus_struct (l:addr)\nextern castfn\nLCD_takeout_struct (* xxx Should lock *)\n(\n tcp: !LCD >> LCD_minus_struct l\n) : #[l:addr] (LCD_struct @ l | ptr l)\nextern praxi\nLCD_addback_struct (* xxx Should unlock *)\n {l:addr}\n(\n pfat: LCD_struct @ l\n| tcp: !LCD_minus_struct l >> LCD\n) : void\n\n(* Low level functions *)\nextern fun lcd_display: {l:addr} (!LCD_struct @ l | ptr l) -> void\nextern fun lcd_command: {l:addr} (!LCD_struct @ l | ptr l, uint8) -> void\nextern fun lcd_send: {l:addr} (!LCD_struct @ l | ptr l, uint8, HIGHLOW) -> void\nextern fun lcd_pulseEnable: {l:addr} (!LCD_struct @ l | ptr l) -> void\nextern fun lcd_write4bits: {l:addr} (!LCD_struct @ l | ptr l, uint8) -> void\n\nlocal\n var _global_lcd_struct: LCD_struct\nin\n implement lcd_open (rs, rw, enable, d0, d1, d2, d3) = let\n val lcd = $UN.castvwtp0 (addr@_global_lcd_struct)\n val (pfat | p) = LCD_takeout_struct (lcd)\n val () = p->rs_pin := rs\n val () = p->rw_pin := rw\n val () = p->enable_pin := enable\n val () = p->data_pins.[0] := d0\n val () = p->data_pins.[1] := d1\n val () = p->data_pins.[2] := d2\n val () = p->data_pins.[3] := d3\n val () = pinMode (p->rs_pin, OUTPUT)\n val () = pinMode (p->rw_pin, OUTPUT)\n val () = pinMode (p->enable_pin, OUTPUT)\n val LCD_4BITMODE = $UN.cast 0x00\n val LCD_2LINE = $UN.cast 0x08\n val LCD_5x8DOTS = $UN.cast 0x00\n val () = p->displayfunction := uint8_bit_or (LCD_4BITMODE, uint8_bit_or (LCD_2LINE, LCD_5x8DOTS))\n prval () = LCD_addback_struct(pfat | lcd)\n fun lcd_begin (lcd: !LCD, lines: uint8): void = {\n val (pfat | p) = LCD_takeout_struct (lcd)\n val () = p->numlines := lines\n val () = p->currline := $UN.cast 0\n val () = _delay_us 50000.0\n val () = digitalWrite (p->rs_pin, LOW)\n val () = digitalWrite (p->enable_pin, LOW)\n val () = digitalWrite (p->rw_pin, LOW)\n val displayfunction = p->displayfunction\n \/\/ this is according to the hitachi HD44780 datasheet \/ figure 24, pg 46\n \/\/ we start in 8bit mode, try to set 4 bit mode\n val () = lcd_write4bits (pfat | p, $UN.cast 0x03)\n val () = _delay_us 4500.0\n val () = lcd_write4bits (pfat | p, $UN.cast 0x03) \/\/ second try\n val () = _delay_us 4500.0\n val () = lcd_write4bits (pfat | p, $UN.cast 0x03) \/\/ third go!\n val () = _delay_us 150.0\n val () = lcd_write4bits (pfat | p, $UN.cast 0x02) \/\/ finally, set to 4-bit interface\n \/\/ finally, set # lines, font size, etc.\n val LCD_FUNCTIONSET = $UN.cast 0x20\n val () = lcd_command (pfat | p, uint8_bit_or (LCD_FUNCTIONSET, displayfunction))\n \/\/ turn the display on with no cursor or blinking default\n val LCD_DISPLAYON = $UN.cast 0x04\n val LCD_CURSOROFF = $UN.cast 0x00\n val LCD_BLINKOFF = $UN.cast 0x00\n val () = p->displaycontrol := uint8_bit_or (LCD_DISPLAYON, uint8_bit_or (LCD_CURSOROFF, LCD_BLINKOFF))\n val () = lcd_display (pfat | p)\n \/\/ Initialize to default text direction (for romance languages)\n val LCD_ENTRYLEFT = $UN.cast 0x02\n val LCD_ENTRYSHIFTDECREMENT = $UN.cast 0x00\n val () = p->displaymode := uint8_bit_or (LCD_ENTRYLEFT, LCD_ENTRYSHIFTDECREMENT)\n val displaymode = p->displaymode\n \/\/ set the entry mode\n val LCD_ENTRYMODESET = $UN.cast 0x04\n val () = lcd_command (pfat | p, uint8_bit_or (LCD_ENTRYMODESET, displaymode))\n prval () = LCD_addback_struct(pfat | lcd)\n \/\/ clear it off\n val () = lcd_clear lcd\n }\n val () = lcd_begin (lcd, $UN.cast 2)\n in\n lcd\n end\nend\n\nimplement lcd_close (lcd) = {\n val () = $UN.castvwtp0(lcd) (* Consume lcd *)\n}\n\nimplement lcd_clear (lcd) = {\n val LCD_CLEARDISPLAY = $UN.cast 0x01\n val (pfat | p) = LCD_takeout_struct (lcd)\n val () = lcd_command (pfat | p, LCD_CLEARDISPLAY) \/\/ clear display, set cursor position to zero\n prval () = LCD_addback_struct(pfat | lcd)\n val () = _delay_us 2000.0 \/\/ this command takes a long time!\n}\n\nimplement lcd_setCursor (lcd, col, row) = {\n val LCD_SETDDRAMADDR = $UN.cast 0x80\n val row_ofs = if row > 0 then 0x40 else 0x00\n val (pfat | p) = LCD_takeout_struct (lcd)\n val () = lcd_command(pfat | p, uint8_bit_or (LCD_SETDDRAMADDR, col + $UN.cast row_ofs))\n prval () = LCD_addback_struct(pfat | lcd)\n}\n\nimplement lcd_print (lcd, str, start, len) = {\n fun w (lcd: !LCD, p: ptr): void = {\n val c = $UN.ptr0_get (p)\n val () = lcd_write (lcd, c)\n }\n fun loop (lcd: !LCD, p: ptr, r: int): void = {\n val () = if r > 0 then (w (lcd, p); loop (lcd, ptr_succ (p), r - 1))\n }\n val p0 = string2ptr (str)\n val p0 = ptr_add (p0, start)\n val () = loop (lcd, p0, len)\n}\n\nimplement lcd_write (lcd, value) = {\n val (pfat | p) = LCD_takeout_struct (lcd)\n val () = lcd_send (pfat | p, value, HIGH)\n prval () = LCD_addback_struct(pfat | lcd)\n}\n\nimplement lcd_display (pfat | p) = {\n val LCD_DISPLAYON = $UN.cast 0x04\n val () = p->displaycontrol := LCD_DISPLAYON\n val displaycontrol = p->displaycontrol\n val LCD_DISPLAYCONTROL = $UN.cast 0x08\n val () = lcd_command (pfat | p, uint8_bit_or (LCD_DISPLAYCONTROL, displaycontrol))\n}\n\nimplement lcd_command (pfat | p, value) = {\n val () = lcd_send (pfat | p, value, LOW)\n}\n\nimplement lcd_send (pfat | p, value, mode) = {\n val () = digitalWrite (p->rs_pin, mode)\n val () = digitalWrite (p->rw_pin, LOW)\n val () = lcd_write4bits (pfat | p, value >> 4)\n val () = lcd_write4bits (pfat | p, value)\n}\n\nimplement lcd_pulseEnable (pfat | p) = {\n val () = digitalWrite (p->enable_pin, LOW)\n val () = _delay_us 1.0\n val () = digitalWrite (p->enable_pin, HIGH)\n val () = _delay_us 1.0 \/\/ enable pulse must be >450ns\n val () = digitalWrite (p->enable_pin, LOW)\n val () = _delay_us 100.0 \/\/ commands need > 37us to settle\n}\n\nimplement lcd_write4bits (pfat | p, value) = {\n fun uint8_to_highlow (v: uint8): HIGHLOW = $UN.cast (uint8_bit_and (v, $UN.cast 0x01))\n val () = pinMode (p->data_pins.[0], OUTPUT)\n val () = digitalWrite (p->data_pins.[0], uint8_to_highlow (value >> 0))\n val () = pinMode (p->data_pins.[1], OUTPUT)\n val () = digitalWrite (p->data_pins.[1], uint8_to_highlow (value >> 1))\n val () = pinMode (p->data_pins.[2], OUTPUT)\n val () = digitalWrite (p->data_pins.[2], uint8_to_highlow (value >> 2))\n val () = pinMode (p->data_pins.[3], OUTPUT)\n val () = digitalWrite (p->data_pins.[3], uint8_to_highlow (value >> 3))\n val () = lcd_pulseEnable (pfat | p)\n}\n","old_contents":"(*\n * For LinkSprite 16X2 LCD Keypad Shield for Arduino\n * http:\/\/store.linksprite.com\/linksprite-16x2-lcd-keypad-shield-for-arduino-version-b\/\n * http:\/\/www.linksprite.com\/wiki\/index.php5?title=16_X_2_LCD_Keypad_Shield_for_Arduino\n *)\n#define ATS_DYNLOADFLAG 0 \/\/ no dynloading at run-time\n#include \"share\/atspre_define.hats\"\n#include \"share\/atspre_staload.hats\"\nstaload \"SATS\/arduino.sats\"\nstaload \"SATS\/lcd.sats\"\nstaload UN = \"prelude\/SATS\/unsafe.sats\"\n\n%{\ninline uint8_t atspre_uint8_bit_or(uint8_t a, uint8_t b) { return (a | b); }\ninline uint8_t atspre_uint8_bit_and(uint8_t a, uint8_t b) { return (a & b); }\n%}\nextern fun uint8_bit_or: (uint8, uint8) -> uint8 = \"mac#atspre_uint8_bit_or\"\nextern fun uint8_bit_and: (uint8, uint8) -> uint8 = \"mac#atspre_uint8_bit_and\"\n\n(* Private struct *)\nvtypedef LCD_struct = @{\n rs_pin = uint8 \/\/ LOW: command. HIGH: character.\n, rw_pin = uint8 \/\/ LOW: write to LCD. HIGH: read from LCD.\n, enable_pin = uint8 \/\/ activated by a HIGH pulse.\n, data_pins = @(uint8, uint8, uint8, uint8)\n, displayfunction = uint8\n, displaycontrol = uint8\n, displaymode = uint8\n, numlines = uint8\n, currline = uint8\n}\nabsvtype LCD_minus_struct (l:addr)\nextern castfn\nLCD_takeout_struct (* xxx Should lock *)\n(\n tcp: !LCD >> LCD_minus_struct l\n) : #[l:addr] (LCD_struct @ l | ptr l)\nextern praxi\nLCD_addback_struct (* xxx Should unlock *)\n {l:addr}\n(\n pfat: LCD_struct @ l\n| tcp: !LCD_minus_struct l >> LCD\n) : void\n\n(* Low level functions *)\nextern fun lcd_display: {l:addr} (!LCD_struct @ l | ptr l) -> void\nextern fun lcd_command: {l:addr} (!LCD_struct @ l | ptr l, uint8) -> void\nextern fun lcd_send: {l:addr} (!LCD_struct @ l | ptr l, uint8, HIGHLOW) -> void\nextern fun lcd_pulseEnable: {l:addr} (!LCD_struct @ l | ptr l) -> void\nextern fun lcd_write4bits: {l:addr} (!LCD_struct @ l | ptr l, uint8) -> void\n\nlocal\n var _global_lcd_struct: LCD_struct\nin\n implement lcd_open (rs, rw, enable, d0, d1, d2, d3) = let\n val lcd = $UN.castvwtp0 (addr@_global_lcd_struct)\n val (pfat | p) = LCD_takeout_struct (lcd)\n val () = p->rs_pin := rs\n val () = p->rw_pin := rw\n val () = p->enable_pin := enable\n val () = p->data_pins := @(d0, d1, d2, d3)\n val () = pinMode (p->rs_pin, OUTPUT)\n val () = pinMode (p->rw_pin, OUTPUT)\n val () = pinMode (p->enable_pin, OUTPUT)\n val LCD_4BITMODE = $UN.cast 0x00\n val LCD_2LINE = $UN.cast 0x08\n val LCD_5x8DOTS = $UN.cast 0x00\n val () = p->displayfunction := uint8_bit_or (LCD_4BITMODE, uint8_bit_or (LCD_2LINE, LCD_5x8DOTS))\n prval () = LCD_addback_struct(pfat | lcd)\n fun lcd_begin (lcd: !LCD, lines: uint8): void = {\n val (pfat | p) = LCD_takeout_struct (lcd)\n val () = p->numlines := lines\n val () = p->currline := $UN.cast 0\n val () = _delay_us 50000.0\n val () = digitalWrite (p->rs_pin, LOW)\n val () = digitalWrite (p->enable_pin, LOW)\n val () = digitalWrite (p->rw_pin, LOW)\n val displayfunction = p->displayfunction\n \/\/ this is according to the hitachi HD44780 datasheet \/ figure 24, pg 46\n \/\/ we start in 8bit mode, try to set 4 bit mode\n val () = lcd_write4bits (pfat | p, $UN.cast 0x03)\n val () = _delay_us 4500.0\n val () = lcd_write4bits (pfat | p, $UN.cast 0x03) \/\/ second try\n val () = _delay_us 4500.0\n val () = lcd_write4bits (pfat | p, $UN.cast 0x03) \/\/ third go!\n val () = _delay_us 150.0\n val () = lcd_write4bits (pfat | p, $UN.cast 0x02) \/\/ finally, set to 4-bit interface\n \/\/ finally, set # lines, font size, etc.\n val LCD_FUNCTIONSET = $UN.cast 0x20\n val () = lcd_command (pfat | p, uint8_bit_or (LCD_FUNCTIONSET, displayfunction))\n \/\/ turn the display on with no cursor or blinking default\n val LCD_DISPLAYON = $UN.cast 0x04\n val LCD_CURSOROFF = $UN.cast 0x00\n val LCD_BLINKOFF = $UN.cast 0x00\n val () = p->displaycontrol := uint8_bit_or (LCD_DISPLAYON, uint8_bit_or (LCD_CURSOROFF, LCD_BLINKOFF))\n val () = lcd_display (pfat | p)\n \/\/ Initialize to default text direction (for romance languages)\n val LCD_ENTRYLEFT = $UN.cast 0x02\n val LCD_ENTRYSHIFTDECREMENT = $UN.cast 0x00\n val () = p->displaymode := uint8_bit_or (LCD_ENTRYLEFT, LCD_ENTRYSHIFTDECREMENT)\n val displaymode = p->displaymode\n \/\/ set the entry mode\n val LCD_ENTRYMODESET = $UN.cast 0x04\n val () = lcd_command (pfat | p, uint8_bit_or (LCD_ENTRYMODESET, displaymode))\n prval () = LCD_addback_struct(pfat | lcd)\n \/\/ clear it off\n val () = lcd_clear lcd\n }\n val () = lcd_begin (lcd, $UN.cast 2)\n in\n lcd\n end\nend\n\nimplement lcd_close (lcd) = {\n val () = $UN.castvwtp0(lcd) (* Consume lcd *)\n}\n\nimplement lcd_clear (lcd) = {\n val LCD_CLEARDISPLAY = $UN.cast 0x01\n val (pfat | p) = LCD_takeout_struct (lcd)\n val () = lcd_command (pfat | p, LCD_CLEARDISPLAY) \/\/ clear display, set cursor position to zero\n prval () = LCD_addback_struct(pfat | lcd)\n val () = _delay_us 2000.0 \/\/ this command takes a long time!\n}\n\nimplement lcd_setCursor (lcd, col, row) = {\n val LCD_SETDDRAMADDR = $UN.cast 0x80\n val row_ofs = if row > 0 then 0x40 else 0x00\n val (pfat | p) = LCD_takeout_struct (lcd)\n val () = lcd_command(pfat | p, uint8_bit_or (LCD_SETDDRAMADDR, col + $UN.cast row_ofs))\n prval () = LCD_addback_struct(pfat | lcd)\n}\n\nimplement lcd_print (lcd, str, start, len) = {\n fun w (lcd: !LCD, p: ptr): void = {\n val c = $UN.ptr0_get (p)\n val () = lcd_write (lcd, c)\n }\n fun loop (lcd: !LCD, p: ptr, r: int): void = {\n val () = if r > 0 then (w (lcd, p); loop (lcd, ptr_succ (p), r - 1))\n }\n val p0 = string2ptr (str)\n val p0 = ptr_add (p0, start)\n val () = loop (lcd, p0, len)\n}\n\nimplement lcd_write (lcd, value) = {\n val (pfat | p) = LCD_takeout_struct (lcd)\n val () = lcd_send (pfat | p, value, HIGH)\n prval () = LCD_addback_struct(pfat | lcd)\n}\n\nimplement lcd_display (pfat | p) = {\n val LCD_DISPLAYON = $UN.cast 0x04\n val () = p->displaycontrol := LCD_DISPLAYON\n val displaycontrol = p->displaycontrol\n val LCD_DISPLAYCONTROL = $UN.cast 0x08\n val () = lcd_command (pfat | p, uint8_bit_or (LCD_DISPLAYCONTROL, displaycontrol))\n}\n\nimplement lcd_command (pfat | p, value) = {\n val () = lcd_send (pfat | p, value, LOW)\n}\n\nimplement lcd_send (pfat | p, value, mode) = {\n val () = digitalWrite (p->rs_pin, mode)\n val () = digitalWrite (p->rw_pin, LOW)\n val () = lcd_write4bits (pfat | p, value >> 4)\n val () = lcd_write4bits (pfat | p, value)\n}\n\nimplement lcd_pulseEnable (pfat | p) = {\n val () = digitalWrite (p->enable_pin, LOW)\n val () = _delay_us 1.0\n val () = digitalWrite (p->enable_pin, HIGH)\n val () = _delay_us 1.0 \/\/ enable pulse must be >450ns\n val () = digitalWrite (p->enable_pin, LOW)\n val () = _delay_us 100.0 \/\/ commands need > 37us to settle\n}\n\nimplement lcd_write4bits (pfat | p, value) = {\n fun uint8_to_highlow (v: uint8): HIGHLOW = $UN.cast (uint8_bit_and (v, $UN.cast 0x01))\n val () = pinMode (p->data_pins.0, OUTPUT)\n val () = digitalWrite (p->data_pins.0, uint8_to_highlow (value >> 0))\n val () = pinMode (p->data_pins.1, OUTPUT)\n val () = digitalWrite (p->data_pins.1, uint8_to_highlow (value >> 1))\n val () = pinMode (p->data_pins.2, OUTPUT)\n val () = digitalWrite (p->data_pins.2, uint8_to_highlow (value >> 2))\n val () = pinMode (p->data_pins.3, OUTPUT)\n val () = digitalWrite (p->data_pins.3, uint8_to_highlow (value >> 3))\n val () = lcd_pulseEnable (pfat | p)\n}\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"5f08f496f1fadb35773e6b8f111ea3c8f50956b8","subject":"Write lcd_begin (cont.)","message":"Write lcd_begin (cont.)\n","repos":"fpiot\/arduino-ats,fpiot\/arduino-ats,Proclivis\/arduino-ats,Proclivis\/arduino-ats","old_file":"lcd_ats\/DATS\/lcd.dats","new_file":"lcd_ats\/DATS\/lcd.dats","new_contents":"#define ATS_DYNLOADFLAG 0 \/\/ no dynloading at run-time\nstaload \"SATS\/arduino.sats\"\nstaload \"SATS\/lcd.sats\"\nstaload UN = \"prelude\/SATS\/unsafe.sats\"\n\n%{\ninline uint8_t atspre_uint8_bit_or(uint8_t a, uint8_t b) {\n return (a | b);\n}\n%}\nextern fun uint8_bit_or: (uint8, uint8) -> uint8 = \"mac#atspre_uint8_bit_or\"\n\n(* Private struct *)\nvtypedef LCD_struct = @{\n rs_pin = uint8 \/\/ LOW: command. HIGH: character.\n, rw_pin = uint8 \/\/ LOW: write to LCD. HIGH: read from LCD.\n, enable_pin = uint8 \/\/ activated by a HIGH pulse.\n, data_pins = @(uint8, uint8, uint8, uint8)\n, displayfunction = uint8\n, displaycontrol = uint8\n, displaymode = uint8\n, numlines = uint8\n, currline = uint8\n}\nabsvtype LCD_minus_struct (l:addr)\nextern castfn\nLCD_takeout_struct\n(\n tcp: !LCD >> LCD_minus_struct l\n) : #[l:addr] (LCD_struct @ l | ptr l)\nextern praxi\nLCD_addback_struct\n {l:addr}\n(\n pfat: LCD_struct @ l\n| tcp: !LCD_minus_struct l >> LCD\n) : void\n\nlocal\n var _global_lcd_struct: LCD_struct\nin\n implement lcd_open (rs, rw, enable, d0, d1, d2, d3) = let\n val lcd = $UN.castvwtp0 (addr@_global_lcd_struct)\n val (pfat | p) = LCD_takeout_struct (lcd)\n val () = p->rs_pin := rs\n val () = p->rw_pin := rw\n val () = p->enable_pin := enable\n val () = p->data_pins := @(d0, d1, d2, d3)\n val () = pinMode (p->rs_pin, OUTPUT)\n val () = pinMode (p->rw_pin, OUTPUT)\n val () = pinMode (p->enable_pin, OUTPUT)\n val LCD_4BITMODE = $UN.cast 0x00\n val LCD_1LINE = $UN.cast 0x00\n val LCD_5x8DOTS = $UN.cast 0x00\n val () = p->displayfunction := uint8_bit_or (LCD_4BITMODE, uint8_bit_or (LCD_1LINE, LCD_5x8DOTS))\n prval () = LCD_addback_struct(pfat | lcd)\n fun lcd_begin (lcd: !LCD, lines: uint8): void = {\n val (pfat | p) = LCD_takeout_struct (lcd)\n val () = p->numlines := lines\n val () = p->currline := $UN.cast 0\n val () = _delay_ms 50000.0\n val () = digitalWrite (p->rs_pin, LOW)\n val () = digitalWrite (p->enable_pin, LOW)\n val () = digitalWrite (p->rw_pin, LOW)\n prval () = LCD_addback_struct(pfat | lcd)\n \/\/ this is according to the hitachi HD44780 datasheet \/ figure 24, pg 46\n \/\/ we start in 8bit mode, try to set 4 bit mode\n val () = lcd_write4bits (lcd, $UN.cast 0x03)\n val () = _delay_ms 4500.0\n val () = lcd_write4bits (lcd, $UN.cast 0x03) \/\/ second try\n val () = _delay_ms 4500.0\n val () = lcd_write4bits (lcd, $UN.cast 0x03) \/\/ third go!\n val () = _delay_ms 150.0\n val () = lcd_write4bits (lcd, $UN.cast 0x02) \/\/ finally, set to 4-bit interface\n \/\/ xxx\n }\n val () = lcd_begin (lcd, $UN.cast 1)\n in\n lcd\n end\nend\n\nimplement lcd_close (lcd) = {\n val () = $UN.castvwtp0(lcd) (* Consume lcd *)\n}\n\nimplement lcd_write4bits (lcd, value) = {\n val (pfat | p) = LCD_takeout_struct (lcd)\n \/\/ xxx\n prval () = LCD_addback_struct(pfat | lcd)\n}\n","old_contents":"#define ATS_DYNLOADFLAG 0 \/\/ no dynloading at run-time\nstaload \"SATS\/arduino.sats\"\nstaload \"SATS\/lcd.sats\"\nstaload UN = \"prelude\/SATS\/unsafe.sats\"\n\n%{\ninline uint8_t atspre_uint8_bit_or(uint8_t a, uint8_t b) {\n return (a | b);\n}\n%}\nextern fun uint8_bit_or: (uint8, uint8) -> uint8 = \"mac#atspre_uint8_bit_or\"\n\n(* Private struct *)\nvtypedef LCD_struct = @{\n rs_pin = uint8 \/\/ LOW: command. HIGH: character.\n, rw_pin = uint8 \/\/ LOW: write to LCD. HIGH: read from LCD.\n, enable_pin = uint8 \/\/ activated by a HIGH pulse.\n, data_pins = @(uint8, uint8, uint8, uint8)\n, displayfunction = uint8\n, displaycontrol = uint8\n, displaymode = uint8\n, numlines = uint8\n, currline = uint8\n}\nabsvtype LCD_minus_struct (l:addr)\nextern castfn\nLCD_takeout_struct\n(\n tcp: !LCD >> LCD_minus_struct l\n) : #[l:addr] (LCD_struct @ l | ptr l)\nextern praxi\nLCD_addback_struct\n {l:addr}\n(\n pfat: LCD_struct @ l\n| tcp: !LCD_minus_struct l >> LCD\n) : void\n\nlocal\n var _global_lcd_struct: LCD_struct\nin\n implement lcd_open (rs, rw, enable, d0, d1, d2, d3) = let\n val lcd = $UN.castvwtp0 (addr@_global_lcd_struct)\n val (pfat | p) = LCD_takeout_struct (lcd)\n val () = p->rs_pin := rs\n val () = p->rw_pin := rw\n val () = p->enable_pin := enable\n val () = p->data_pins := @(d0, d1, d2, d3)\n val () = pinMode (p->rs_pin, OUTPUT)\n val () = pinMode (p->rw_pin, OUTPUT)\n val () = pinMode (p->enable_pin, OUTPUT)\n val LCD_4BITMODE = $UN.cast 0x00\n val LCD_1LINE = $UN.cast 0x00\n val LCD_5x8DOTS = $UN.cast 0x00\n val () = p->displayfunction := uint8_bit_or (LCD_4BITMODE, uint8_bit_or (LCD_1LINE, LCD_5x8DOTS))\n \/\/ xxx\n prval () = LCD_addback_struct(pfat | lcd)\n in\n lcd\n end\nend\n\nimplement lcd_close (lcd) = {\n val () = $UN.castvwtp0(lcd) (* Consume lcd *)\n}\n\nimplement lcd_write4bits (lcd, value) = {\n val (pfat | p) = LCD_takeout_struct (lcd)\n \/\/ xxx\n prval () = LCD_addback_struct(pfat | lcd)\n}\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"2594ed015b6609eb56618cfdd4cccc1678c944c8","subject":"Add more opcodes","message":"Add more opcodes\n","repos":"RyanTKing\/ats-chip8,RyanTKing\/ats-chip8","old_file":"DATS\/chip8-loop.dats","new_file":"DATS\/chip8-loop.dats","new_contents":"(* ****** ****** *)\n\/\/\n\/\/ chip8-loop.dats\n\/\/ Implementation of functions that handle the main emulation loop.\n\/\/\n(* ****** ****** *)\n\n#ifndef CHIP8_MAIN\n#include \".\/..\/staloadall.hats\"\n#endif\n\nstaload STDLIB = \"libats\/libc\/SATS\/stdlib.sats\"\n\n(* ****** ****** *)\n\nlocal\n assume opcode_type = '{\n p = byte,\n Vx = breg,\n Vy = breg,\n n = byte,\n kk = byte,\n nnn = word\n }\n\n val interrupted = ref(false)\n\n fun fetch(): word = opc where {\n val b_hi = Mem(w2imem(PC.get()))\n val () = PC.incr(w_0x1)\n val b_lo = Mem(w2imem(PC.get()))\n val () = PC.incr(w_0x1)\n val opc = (b2w(b_hi) lsl 0x8) lor b2w(b_lo)\n }\n\n fun decode(opc: word): opcode = '{\n p = w2b((opc lsr 0xC) land w_0xF),\n Vx = V((opc lsr 0x8) land w_0xF),\n Vy = V((opc lsr 0x4) land w_0xF),\n n = w2b(opc land w_0xF),\n kk = w2b(opc land w_0xFF),\n nnn = opc land w_0xFFF\n }\n\n fun execute(opc: opcode): void =\n let\n fun check_p(p: byte): bool = opc.p = p\n fun check_pn(p: byte, n: byte): bool = opc.p = p && opc.n = n\n fun check_pkk(p: byte, kk: byte): bool = opc.p = p && opc.kk = kk\n fun check_pnnn(p: byte, nnn: word): bool = opc.p = p && opc.nnn = nnn\n fun get_Vx(): byte = (opc.Vx).get()\n fun set_Vx(b: byte): void = (opc.Vx).set(b)\n fun get_Vy(): byte = (opc.Vy).get()\n fun set_Vy(b: byte): void = (opc.Vy).set(b)\n fun set_Vf(test: bool): void =\n if test then (V(w_0xF)).set(b_0x1) else (V(w_0xF)).set(b_0x0)\n\n overload Vx with get_Vx\n overload Vx with set_Vx\n overload Vy with get_Vy\n overload Vy with set_Vy\n overload Vf with set_Vf\n in\n ifcase\n | check_pkk(b_0x0, i2b(0xE0)) => clear_screen()\n | check_pkk(b_0x0, i2b(0xEE)) => PC.set(stack_pop())\n | check_p(b_0x1) => PC.set(opc.nnn)\n | check_p(b_0x2) => (stack_push(PC.get()); PC.set(opc.nnn))\n | check_p(b_0x3) => if (Vx() = opc.kk) then PC.incr(w_0x2)\n | check_p(b_0x4) => if (Vx() != opc.kk) then PC.incr(w_0x2)\n | check_p(b_0x5) => if (Vx() = Vy()) then PC.incr(w_0x2)\n | check_p(b_0x6) => Vx(opc.kk)\n | check_p(b_0x7) => Vx(Vx() + opc.kk)\n | check_pn(b_0x8, b_0x0) => Vx(Vy())\n | check_pn(b_0x8, b_0x1) => Vx(Vx() lor Vy())\n | check_pn(b_0x8, b_0x2) => Vx(Vx() land Vy())\n | check_pn(b_0x8, b_0x3) => Vx(Vx() lxor Vy())\n | check_pn(b_0x8, b_0x4) => (Vf(Vx() > (b_0xFF - Vy())); Vx(Vx() + Vy()))\n | check_pn(b_0x8, b_0x5) => (Vf(Vx() > Vy()); Vx(Vx() - Vy()))\n | check_pn(b_0x8, b_0x6) => (Vf((Vx() land b_0x1) = b_0x1); Vx(Vx() lsr 1))\n | check_pn(b_0x8, b_0x7) => (Vf(Vy() > Vx()); Vx(Vy() - Vx()))\n | check_pn(b_0x8, b_0xE) => (Vf((Vx() lsr 7) = b_0x1); Vx(Vx() lsl 1))\n | check_pn(b_0x9, b_0x0) => if (Vx() != Vy()) then PC.incr(w_0x2)\n | check_p(b_0xA) => I.set(opc.nnn)\n | check_p(b_0xB) => PC.set(b2w((V(w_0x0)).get()) + opc.nnn)\n | check_p(b_0xC) => Vx(i2b($STDLIB.rand() % 256) land opc.kk)\n | check_p(b_0xD) => draw_y(0) where {\n val () = (V(0xF)).set(b_0x0)\n val x = b2i(Vx.get())\n val y = b2i(Vy.get())\n val height = w2i(n)\n\n fun draw_x(row: byte, x_off: int, y_off: int): void =\n if x_off < SPR_WIDTH && x + x_off < SCR_WIDTH then\n let\n val _x = $UN.cast{natLt(SCR_WIDTH)}(x + x_off)\n val _y = $UN.cast{natLt(SCR_HEIGHT)}(y + y_off)\n val pix = (row lsr (SPR_WIDTH - 1 - x_off)) land b_0x1\n val () = if pix = b_0x1 then (\n if Scr(_x, _y) = b_0x1 then (\n (V(0xF)).set(b_0x1);\n Scr(_x, _y, b_0x0)\n ) else Scr(_x, _y, b_0x1)\n )\n in\n draw_x(row, succ(x_off), y_off)\n end\n\n fun draw_y(y_off: int): void = (\n if y_off < height && y + y_off < SCR_HEIGHT then (\n draw_x(Mem($UN.cast{imem}(I.get() + y_off)), 0, y_off);\n draw_y(succ(y_off))\n )\n )\n }\n\n | _ => $raise UnknownOpcode((b2w(opc.p) lsl 0xC) lor opc.nnn)\n end\n\n\n fun exec_insns(): void =\n if has_time() then execute(opc) where {\n val opc = fetch()\n val opc = decode(opc)\n }\n\nin\n implement quit() = !interrupted := true\n\n implement game_loop(dpy) =\n let\n val () = exec_insns()\n val () = poll_kb()\n val () = if sync_clock() then update_display(dpy)\n in\n if not !interrupted then game_loop(dpy)\n end\nend\n\n(* End of chip8-loop.dats *)","old_contents":"(* ****** ****** *)\n\/\/\n\/\/ chip8-loop.dats\n\/\/ Implementation of functions that handle the main emulation loop.\n\/\/\n(* ****** ****** *)\n\n#ifndef CHIP8_MAIN\n#include \".\/..\/staloadall.hats\"\n#endif\n\nstaload STDLIB = \"libats\/libc\/SATS\/stdlib.sats\"\n\n(* ****** ****** *)\n\nlocal\n assume opcode_type = '{\n p = byte,\n Vx = breg,\n Vy = breg,\n n = byte,\n kk = byte,\n nnn = word\n }\n\n val interrupted = ref(false)\n\n fun fetch(): word = opc where {\n val b_hi = Mem(w2imem(PC.get()))\n val () = PC.incr(w_0x1)\n val b_lo = Mem(w2imem(PC.get()))\n val () = PC.incr(w_0x1)\n val opc = (b2w(b_hi) lsl 0x8) lor b2w(b_lo)\n }\n\n fun decode(opc: word): opcode = '{\n p = w2b((opc lsr 0xC) land w_0xF),\n Vx = V((opc lsr 0x8) land w_0xF),\n Vy = V((opc lsr 0x4) land w_0xF),\n n = w2b(opc land w_0xF),\n kk = w2b(opc land w_0xFF),\n nnn = opc land w_0xFFF\n }\n\n fun execute(opc: opcode): void =\n let\n fun check_p(p: byte): bool = opc.p = p\n fun check_pn(p: byte, n: byte): bool = opc.p = p && opc.n = n\n fun check_pkk(p: byte, kk: byte): bool = opc.p = p && opc.kk = kk\n fun check_pnnn(p: byte, nnn: word): bool = opc.p = p && opc.nnn = nnn\n fun get_Vx(): byte = (opc.Vx).get()\n fun set_Vx(b: byte): void = (opc.Vx).set(b)\n fun get_Vy(): byte = (opc.Vy).get()\n fun set_Vy(b: byte): void = (opc.Vy).set(b)\n fun set_Vf(test: bool): void =\n if test then (V(w_0xF)).set(b_0x1) else (V(w_0xF)).set(b_0x0)\n\n overload Vx with get_Vx\n overload Vx with set_Vx\n overload Vy with get_Vy\n overload Vy with set_Vy\n overload Vf with set_Vf\n in\n ifcase\n | check_pkk(b_0x0, i2b(0xE0)) => clear_screen()\n | check_pkk(b_0x0, i2b(0xEE)) => PC.set(stack_pop())\n | check_p(b_0x1) => PC.set(opc.nnn)\n | check_p(b_0x2) => (stack_push(PC.get()); PC.set(opc.nnn))\n | check_p(b_0x3) => if (Vx() = opc.kk) then PC.incr(w_0x2)\n | check_p(b_0x4) => if (Vx() != opc.kk) then PC.incr(w_0x2)\n | check_p(b_0x5) => if (Vx() = Vy()) then PC.incr(w_0x2)\n | check_p(b_0x6) => Vx(opc.kk)\n | check_p(b_0x7) => Vx(Vx() + opc.kk)\n | check_pn(b_0x8, b_0x0) => Vx(Vy())\n | check_pn(b_0x8, b_0x1) => Vx(Vx() lor Vy())\n | check_pn(b_0x8, b_0x2) => Vx(Vx() land Vy())\n | check_pn(b_0x8, b_0x3) => Vx(Vx() lxor Vy())\n | check_pn(b_0x8, b_0x4) => (Vf(Vx() > (b_0xFF - Vy())); Vx(Vx() + Vy()))\n | check_pn(b_0x8, b_0x5) => (Vf(Vx() > Vy()); Vx(Vx() - Vy()))\n | check_pn(b_0x8, b_0x6) => (Vf((Vx() land b_0x1) = b_0x1); Vx(Vx() lsr 1))\n | check_pn(b_0x8, b_0x7) => (Vf(Vy() > Vx()); Vx(Vy() - Vx()))\n | check_pn(b_0x8, b_0xE) => (Vf((Vx() lsr 7) = b_0x1); Vx(Vx() lsl 1))\n | check_pn(b_0x9, b_0x0) => if (Vx() != Vy()) then PC.incr(w_0x2)\n | check_p(b_0xA) => I.set(opc.nnn)\n | check_p(b_0xB) => PC.set(b2w((V(0)).get()) + opc.nnn)\n | check_p(b_0xC) => Vx(i2b($STDLIB.rand() % 256) land opc.kk)\n | _ => $raise UnknownOpcode((b2w(opc.p) lsl 0xC) lor opc.nnn)\n end\n\n\n fun exec_insns(): void =\n if has_time() then execute(opc) where {\n val opc = fetch()\n val opc = decode(opc)\n }\n\nin\n implement quit() = !interrupted := true\n\n implement game_loop(dpy) =\n let\n val () = exec_insns()\n val () = poll_kb()\n val () = if sync_clock() then update_display(dpy)\n in\n if not !interrupted then game_loop(dpy)\n end\nend\n\n(* End of chip8-loop.dats *)","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"eb83b3503fd97e98309879f55cea01aeccb61a34","subject":"Some fix","message":"Some fix\n","repos":"fpiot\/arduino-ats,fpiot\/arduino-ats,Proclivis\/arduino-ats,Proclivis\/arduino-ats","old_file":"demo\/06a_analoginput_blink\/DATS\/main.dats","new_file":"demo\/06a_analoginput_blink\/DATS\/main.dats","new_contents":"#include \"config.hats\"\n#include \"{$TOP}\/avr_prelude\/kernel_staload.hats\"\n\nstaload \"{$TOP}\/SATS\/arduino.sats\"\nstaload UN = \"prelude\/SATS\/unsafe.sats\"\n\n#define LED 13\n#define SENSOR 0\n\nimplement main () = {\n fun loop () = {\n val w = analogRead (SENSOR)\n val () = digitalWrite (LED, HIGH)\n val () = delay ($UN.cast w)\n val () = digitalWrite (LED, LOW)\n val () = delay ($UN.cast w)\n val () = loop ()\n }\n val () = pinMode (LED, OUTPUT)\n val () = loop ()\n}\n","old_contents":"#include \"config.hats\"\n#include \"{$TOP}\/avr_prelude\/kernel_staload.hats\"\n\nstaload \"{$TOP}\/SATS\/arduino.sats\"\nstaload UN = \"prelude\/SATS\/unsafe.sats\"\n\n#define LED 13\n#define SENSOR 0\n#define BLINK_DELAY_MS 500.0\n\nimplement main () = {\n fun loop () = {\n val w = analogRead(SENSOR)\n val () = digitalWrite (LED, HIGH)\n val () = delay ($UN.cast w)\n val () = digitalWrite (LED, LOW)\n val () = delay ($UN.cast w)\n val () = loop ()\n }\n val () = pinMode (LED, OUTPUT)\n val () = loop ()\n}\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"e63cbc9db5e53b8a2ce48654e3b67396531dad87","subject":"Updating: very minorly tidying-up","message":"Updating: very minorly tidying-up\n","repos":"bbarker\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib","old_file":"contrib\/libats-\/wdblair\/SMT\/Z3\/SATS\/z3.sats","new_file":"contrib\/libats-\/wdblair\/SMT\/Z3\/SATS\/z3.sats","new_contents":"(***********************************************************************)\n(* *)\n(* Applied Type System *)\n(* *)\n(***********************************************************************)\n\n(*\n** ATS\/Postiats - Unleashing the Potential of Types!\n** Copyright (C) 2011-2013 Hongwei Xi, ATS Trustful Software, Inc.\n** All rights reserved\n**\n** ATS is free software; you can redistribute it and\/or modify it under\n** the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by the\n** Free Software Foundation; either version 2.1, or (at your option) any\n** later version.\n**\n** ATS is distributed in the hope that it will be useful, but WITHOUT ANY\n** WARRANTY; without even the implied warranty of MERCHANTABILITY or\n** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License\n** for more details.\n**\n** You should have received a copy of the GNU General Public License\n** along with ATS; see the file COPYING. If not, please write to the\n** Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA\n** 02110-1301, USA.\n*)\n\n(* ****** ****** *)\n\n(*\n** Start Time: April, 2013\n**\n** Author: William Blair \n** Authoremail: wdblair AT bu DOT edu\n**\n** Author: Hongwei Xi\n** Authoremail: gmhwxi AT gmail DOT com\n*)\n\n(* ****** ****** *)\n\n%{#\n#include \"libats-\/wdblair\/SMT\/Z3\/CATS\/z3.cats\"\n%} \/\/ end of [%{#]\n\n(* ****** ****** *)\n\n#define ATS_PACKNAME \"ATSCNTRB.libats-wdblair.Z3\"\n#define ATS_STALOADFLAG 0 \/\/ no static loading at run-time\n#define ATS_EXTERN_PREFIX \"atscntrb_\" \/\/ prefix for external names\n\n(* ****** ****** *)\n\n#define\nATSCNTRB_SML_Z3_Z3_HEADER\n#include \".\/z3_header.sats\"\n\n(* ****** ****** *)\n\n(*\nZ3_config Z3_mk_config ()\nCreate a configuration.\n*)\nfun Z3_mk_config (): Z3_config = \"mac#%\"\n\n(* \nvoid Z3_del_config (__in Z3_config c)\nDelete the given configuration object.\n*)\nfun Z3_del_config (cfg: Z3_config): void = \"mac#%\"\n\n(*\nvoid Z3_set_param_value\n(\n __in Z3_config c, __in Z3_string param_id, __in Z3_string param_value\n)\nSet a configuration parameter.\n*)\nfun Z3_set_param_value\n(\n cfg: !Z3_config, p_id: Z3_string, p_val: Z3_string\n) : void = \"mac#%\" \/\/ end of [Z3_set_param_value]\n \n(* ****** ****** *)\n\n(*\nZ3_context Z3_mk_context (__in Z3_config c)\nCreate a context using the given configuration.\n*)\n(*\nfun Z3_mk_context (cfg: !Z3_config): Z3_context = \"mac#%\"\n*)\n\n(* \nZ3_context Z3_mk_context_rc (__in Z3_config c)\nCreate a context using the given configuration. This function is similar to\nZ3_mk_context. However, in the context returned by this function, the user\nis responsible for managing Z3_ast reference counters. Managing reference\ncounters is a burden and error-prone, but allows the user to use the memory\nmore efficiently. The user must invoke Z3_inc_ref for any Z3_ast returned\nby Z3, and Z3_dec_ref whenever the Z3_ast is not needed anymore. This idiom\nis similar to the one used in BDD (binary decision diagrams) packages such\nas CUDD.\n*)\n\nfun Z3_mk_context_rc (cfg: !Z3_config): Z3_context = \"mac#%\"\n\n(* ****** ****** *)\n\n(*\nvoid\nZ3_del_context (__in Z3_context c)\nDelete the given logical context.\n*)\nfun Z3_del_context (ctx: Z3_context): void = \"mac#%\"\n \n(* ****** ****** *)\n\n(*\nvoid Z3_inc_ref (__in Z3_context c, __in Z3_ast a)\nIncrement the reference counter of the given AST. The context c should\nhave been created using Z3_mk_context_rc. This function is a NOOP if c\nwas created using Z3_mk_context.\n*)\nfun Z3_inc_ref{l:addr}\n (ctx: !Z3_context, a: !Z3_ast l): Z3_ast (l) = \"mac#%\"\n\/\/ end of [Z3_inc_ref]\n \n(*\nvoid\nZ3_dec_ref (__in Z3_context c, __in Z3_ast a)\nDecrement the reference counter of the given AST. The context c should\nhave been created using Z3_mk_context_rc. This function is a NOOP if c\nwas created using Z3_mk_context.\n*)\nfun Z3_dec_ref (ctx: !Z3_context, a: Z3_ast): void = \"mac#%\"\n\n(* ****** ****** *)\n\n(*\nZ3_bool\nZ3_get_param_value\n(\n __in Z3_context c\n, __in Z3_string param_id, __out Z3_string_ptr param_value\n)\n*)\nfun Z3_get_param_value\n(\n ctx: !Z3_context, p_id: Z3_string, p_val: &ptr? >> opt (Z3_string, b)\n) : #[b:bool] bool (b) = \"mac#%\"\n \n(*\nvoid\nZ3_update_param_value\n(__in Z3_context c, __in Z3_string param_id, __in Z3_string param_value)\n*)\nfun Z3_update_param_value\n (ctx: !Z3_context, p_id: Z3_string, p_val: Z3_string): void = \"mac#%\"\n\/\/ end of [Z3_update_param_value]\n\n(* ****** ****** *)\n\n(*\nvoid\nZ3_interrupt (__in Z3_context c)\nInterrupt the execution of a Z3 procedure. This procedure can be used to\ninterrupt: solvers, simplifiers and tactics.\n*) \nfun Z3_interrupt (ctx: !Z3_context): void = \"mac#%\"\n\n(* ****** ****** *)\n\n#include \".\/z3_accessor.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_params.sats\"\n#include \".\/z3_params_descrs.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_symbol.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_sort.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_constapp.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_propeq.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_arithmetic.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_bitvector.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_numerals.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_array.sats\"\n\n(*\n#include \".\/z3_quantifier.sats\"\n*)\n\n(* ****** ****** *)\n\n#include \".\/z3_accessor.sats\"\n#include \".\/z3_modifier.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_model.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_parser.sats\"\n\n(* ****** ****** *)\n\n(*\n#include \".\/z3_interlog.sats\"\n*)\n\n(* ****** ****** *)\n\n#include \".\/z3_quantifier.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_stringconv.sats\"\n\n(* ****** ****** *)\n\n(*\n#include \".\/z3_parserint.sats\"\n#include \".\/z3_errhandle.sats\"\n*)\n\n(* ****** ****** *)\n\n#include \".\/z3_fixedpoint.sats\"\n\n(* ****** ****** *)\n\n(*\n#include \".\/z3_ast_map\"\n#include \".\/z3_ast_vector\"\n*)\n\n(* ****** ****** *)\n\n#include \".\/z3_goal.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_tactic_probe.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_solver.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_stats.sats\"\n\n(* ****** ****** *)\n\n(* end of [z3.sats] *)\n","old_contents":"(***********************************************************************)\n(* *)\n(* Applied Type System *)\n(* *)\n(***********************************************************************)\n\n(*\n** ATS\/Postiats - Unleashing the Potential of Types!\n** Copyright (C) 2011-2013 Hongwei Xi, ATS Trustful Software, Inc.\n** All rights reserved\n**\n** ATS is free software; you can redistribute it and\/or modify it under\n** the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by the\n** Free Software Foundation; either version 2.1, or (at your option) any\n** later version.\n**\n** ATS is distributed in the hope that it will be useful, but WITHOUT ANY\n** WARRANTY; without even the implied warranty of MERCHANTABILITY or\n** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License\n** for more details.\n**\n** You should have received a copy of the GNU General Public License\n** along with ATS; see the file COPYING. If not, please write to the\n** Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA\n** 02110-1301, USA.\n*)\n\n(* ****** ****** *)\n\n(*\n** Start Time: April, 2013\n**\n** Author: William Blair \n** Authoremail: wdblair AT bu DOT edu\n**\n** Author: Hongwei Xi\n** Authoremail: gmhwxi AT gmail DOT com\n*)\n\n(* ****** ****** *)\n\n%{#\n#include \"contrib\/libats-\/wdblair\/SMT\/Z3\/CATS\/z3.cats\"\n%} \/\/ end of [%{#]\n\n(* ****** ****** *)\n\n#define ATS_PACKNAME \"ATSCNTRB.libats-wdblair.Z3\"\n#define ATS_STALOADFLAG 0 \/\/ no static loading at run-time\n#define ATS_EXTERN_PREFIX \"atscntrb_\" \/\/ prefix for external names\n\n(* ****** ****** *)\n\n#define\nATSCNTRB_SML_Z3_Z3_HEADER\n#include \".\/z3_header.sats\"\n\n(* ****** ****** *)\n\n(*\nZ3_config Z3_mk_config ()\nCreate a configuration.\n*)\nfun Z3_mk_config (): Z3_config = \"mac#%\"\n\n(* \nvoid Z3_del_config (__in Z3_config c)\nDelete the given configuration object.\n*)\nfun Z3_del_config (cfg: Z3_config): void = \"mac#%\"\n\n(*\nvoid Z3_set_param_value\n(\n __in Z3_config c, __in Z3_string param_id, __in Z3_string param_value\n)\nSet a configuration parameter.\n*)\nfun Z3_set_param_value\n(\n cfg: !Z3_config, p_id: Z3_string, p_val: Z3_string\n) : void = \"mac#%\" \/\/ end of [Z3_set_param_value]\n \n(* ****** ****** *)\n\n(*\nZ3_context Z3_mk_context (__in Z3_config c)\nCreate a context using the given configuration.\n*)\n(*\nfun Z3_mk_context (cfg: !Z3_config): Z3_context = \"mac#%\"\n*)\n\n(* \nZ3_context Z3_mk_context_rc (__in Z3_config c)\nCreate a context using the given configuration. This function is similar to\nZ3_mk_context. However, in the context returned by this function, the user\nis responsible for managing Z3_ast reference counters. Managing reference\ncounters is a burden and error-prone, but allows the user to use the memory\nmore efficiently. The user must invoke Z3_inc_ref for any Z3_ast returned\nby Z3, and Z3_dec_ref whenever the Z3_ast is not needed anymore. This idiom\nis similar to the one used in BDD (binary decision diagrams) packages such\nas CUDD.\n*)\n\nfun Z3_mk_context_rc (cfg: !Z3_config): Z3_context = \"mac#%\"\n\n(* ****** ****** *)\n\n(*\nvoid\nZ3_del_context (__in Z3_context c)\nDelete the given logical context.\n*)\nfun Z3_del_context (ctx: Z3_context): void = \"mac#%\"\n \n(* ****** ****** *)\n\n(*\nvoid Z3_inc_ref (__in Z3_context c, __in Z3_ast a)\nIncrement the reference counter of the given AST. The context c should\nhave been created using Z3_mk_context_rc. This function is a NOOP if c\nwas created using Z3_mk_context.\n*)\nfun Z3_inc_ref{l:addr}\n (ctx: !Z3_context, a: !Z3_ast l): Z3_ast (l) = \"mac#%\"\n\/\/ end of [Z3_inc_ref]\n \n(*\nvoid\nZ3_dec_ref (__in Z3_context c, __in Z3_ast a)\nDecrement the reference counter of the given AST. The context c should\nhave been created using Z3_mk_context_rc. This function is a NOOP if c\nwas created using Z3_mk_context.\n*)\nfun Z3_dec_ref (ctx: !Z3_context, a: Z3_ast): void = \"mac#%\"\n\n(* ****** ****** *)\n\n(*\nZ3_bool\nZ3_get_param_value\n(\n __in Z3_context c\n, __in Z3_string param_id, __out Z3_string_ptr param_value\n)\n*)\nfun Z3_get_param_value\n(\n ctx: !Z3_context, p_id: Z3_string, p_val: &ptr? >> opt (Z3_string, b)\n) : #[b:bool] bool (b) = \"mac#%\"\n \n(*\nvoid\nZ3_update_param_value\n(__in Z3_context c, __in Z3_string param_id, __in Z3_string param_value)\n*)\nfun Z3_update_param_value\n (ctx: !Z3_context, p_id: Z3_string, p_val: Z3_string): void = \"mac#%\"\n\/\/ end of [Z3_update_param_value]\n\n(* ****** ****** *)\n\n(*\nvoid\nZ3_interrupt (__in Z3_context c)\nInterrupt the execution of a Z3 procedure. This procedure can be used to\ninterrupt: solvers, simplifiers and tactics.\n*) \nfun Z3_interrupt (ctx: !Z3_context): void = \"mac#%\"\n\n(* ****** ****** *)\n\n#include \".\/z3_accessor.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_params.sats\"\n#include \".\/z3_params_descrs.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_symbol.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_sort.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_constapp.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_propeq.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_arithmetic.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_bitvector.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_numerals.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_array.sats\"\n\n(*\n#include \".\/z3_quantifier.sats\"\n*)\n\n(* ****** ****** *)\n\n#include \".\/z3_accessor.sats\"\n#include \".\/z3_modifier.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_model.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_parser.sats\"\n\n(* ****** ****** *)\n\n(*\n#include \".\/z3_interlog.sats\"\n*)\n\n(* ****** ****** *)\n\n#include \".\/z3_quantifier.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_stringconv.sats\"\n\n(* ****** ****** *)\n\n(*\n#include \".\/z3_parserint.sats\"\n#include \".\/z3_errhandle.sats\"\n*)\n\n(* ****** ****** *)\n\n#include \".\/z3_fixedpoint.sats\"\n\n(* ****** ****** *)\n\n(*\n#include \".\/z3_ast_map\"\n#include \".\/z3_ast_vector\"\n*)\n\n(* ****** ****** *)\n\n#include \".\/z3_goal.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_tactic_probe.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_solver.sats\"\n\n(* ****** ****** *)\n\n#include \".\/z3_stats.sats\"\n\n(* ****** ****** *)\n\n(* end of [z3.sats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"c6682f1241c699c220145eda2f41c3aa864f877d","subject":"Snatch tcp_socket_connection_receive","message":"Snatch tcp_socket_connection_receive\n","repos":"fpiot\/mbed-ats,fpiot\/mbed-ats,fpiot\/mbed-ats,fpiot\/mbed-ats,fpiot\/mbed-ats,fpiot\/mbed-ats","old_file":"demos\/halapi_ats\/libmbedats\/DATS\/net_lwip_Socket_TCPSocketConnection.dats","new_file":"demos\/halapi_ats\/libmbedats\/DATS\/net_lwip_Socket_TCPSocketConnection.dats","new_contents":"#include \"share\/atspre_staload.hats\"\n\nstaload UN = \"prelude\/SATS\/unsafe.sats\"\nstaload \"libmbedats\/SATS\/net_lwip_Socket_Socket.sats\"\nstaload \"libmbedats\/SATS\/net_lwip_Socket_Endpoint.sats\"\nstaload \"libmbedats\/SATS\/net_lwip_Socket_TCPSocketConnection.sats\"\n\nvtypedef TCPSocketConnection_struct = @{\n is_connected= bool\n, sock= Socket\n, endpoint= Endpoint\n}\n\nabsvtype TCPSocketConnection_minus_struct (l:addr)\n\nextern castfn\nTCPSocketConnection_takeout_struct\n(\n tcp: !TCPSocketConnection >> TCPSocketConnection_minus_struct l\n) : #[l:addr] (TCPSocketConnection_struct @ l | ptr l)\n\nextern praxi\nTCPSocketConnection_addback_struct\n {l:addr}\n(\n pfat: TCPSocketConnection_struct @ l\n| tcp: !TCPSocketConnection_minus_struct l >> TCPSocketConnection\n) : void\n\nimplement\ntcp_socket_connection_open () = let\n val (pfgc, pfat | p) = ptr_alloc ()\n val () = p->is_connected := false\n val () = p->sock := socket_open ()\n val () = p->endpoint := endpoint_open ()\nin\n $UN.castvwtp0{TCPSocketConnection}((pfat, pfgc | p))\nend\n\nimplement\ntcp_socket_connection_is_connected (tcp) = let\n val (pfat | p) = TCPSocketConnection_takeout_struct (tcp)\n val r = p->is_connected\n prval () = TCPSocketConnection_addback_struct(pfat | tcp)\nin\n r\nend\n\nimplement\ntcp_socket_connection_connect (tcp, host, port) = let\n val (pfat | p) = TCPSocketConnection_takeout_struct (tcp)\n val rs = socket_initsock (p->sock, SOCK_STREAM)\n val ret = if rs = false then false else let\n val re = endpoint_set_address (p->endpoint, host, port)\n in\n if re = false then false else let\n abst@ype socklen_t = $extype\"socklen_t\"\n extern fun lwip_connect: (int, struct_sockaddr_in_p, socklen_t) -> int = \"mac#\"\n val fd = socket_sock_fd (p->sock)\n val rh = endpoint_remoteHost (p->endpoint)\n val rc = lwip_connect (fd, rh, $UN.cast (sizeof))\n in\n if rc < 0 then let\n val _ = socket_finisock (p->sock, true)\n in\n false\n end else let\n val () = p->is_connected := true\n in\n true\n end\n end\n end\n prval () = TCPSocketConnection_addback_struct(pfat | tcp)\nin\n ret\nend\n\nimplement\ntcp_socket_connection_receive (tcp) = let\n val is_connected = tcp_socket_connection_is_connected (tcp)\n val (pfat | p) = TCPSocketConnection_takeout_struct (tcp)\n val fd = socket_sock_fd (p->sock)\n val blocking = socket_blocking (p->sock)\n prval () = TCPSocketConnection_addback_struct(pfat | tcp)\nin\n if (fd < 0) orelse (not is_connected) then None_vt () else let\n val b = if blocking then true else let\n val (pfat | p) = TCPSocketConnection_takeout_struct (tcp)\n val tout = socket_timeout (p->sock)\n val r = socket_wait_readable (p->sock, tout)\n prval () = TCPSocketConnection_addback_struct(pfat | tcp)\n in\n r\n end\n in\n if b then let\n extern fun lwip_recv: (int, ptr, size_t, int) -> int = \"mac#\"\n #define N 127\n #define CNUL '\\000'\n val N1 = succ(N)\n val (pf, pfgc | p) = malloc_gc (i2sz N1)\n val n = lwip_recv (fd, p, i2sz N, 0)\n val () = $UN.ptr0_set(ptr_add(p, n), CNUL)\n val s = $UN.castvwtp0{strptr}((pf, pfgc | p))\n in\n Some_vt (s)\n end else None_vt ()\n end\nend\n\nimplement\ntcp_socket_connection_close (tcp) = {\n val (pfat | p) = TCPSocketConnection_takeout_struct (tcp)\n val () = endpoint_close (p->endpoint)\n val () = socket_close (p->sock)\n val () = $UN.castvwtp0((pfat | p))\n val () = __free (tcp) where {\n extern fun __free {vt:vtype} (x: vt): void = \"atspre_mfree_gc\"\n }\n}\n","old_contents":"#include \"share\/atspre_staload.hats\"\n\nstaload UN = \"prelude\/SATS\/unsafe.sats\"\nstaload \"libmbedats\/SATS\/net_lwip_Socket_Socket.sats\"\nstaload \"libmbedats\/SATS\/net_lwip_Socket_Endpoint.sats\"\nstaload \"libmbedats\/SATS\/net_lwip_Socket_TCPSocketConnection.sats\"\n\nvtypedef TCPSocketConnection_struct = @{\n is_connected= bool\n, sock= Socket\n, endpoint= Endpoint\n}\n\nabsvtype TCPSocketConnection_minus_struct (l:addr)\n\nextern castfn\nTCPSocketConnection_takeout_struct\n(\n tcp: !TCPSocketConnection >> TCPSocketConnection_minus_struct l\n) : #[l:addr] (TCPSocketConnection_struct @ l | ptr l)\n\nextern praxi\nTCPSocketConnection_addback_struct\n {l:addr}\n(\n pfat: TCPSocketConnection_struct @ l\n| tcp: !TCPSocketConnection_minus_struct l >> TCPSocketConnection\n) : void\n\nimplement\ntcp_socket_connection_open () = let\n val (pfgc, pfat | p) = ptr_alloc ()\n val () = p->is_connected := false\n val () = p->sock := socket_open ()\n val () = p->endpoint := endpoint_open ()\nin\n $UN.castvwtp0{TCPSocketConnection}((pfat, pfgc | p))\nend\n\nimplement\ntcp_socket_connection_is_connected (tcp) = let\n val (pfat | p) = TCPSocketConnection_takeout_struct (tcp)\n val r = p->is_connected\n prval () = TCPSocketConnection_addback_struct(pfat | tcp)\nin\n r\nend\n\nimplement\ntcp_socket_connection_connect (tcp, host, port) = let\n val (pfat | p) = TCPSocketConnection_takeout_struct (tcp)\n val rs = socket_initsock (p->sock, SOCK_STREAM)\n val ret = if rs = false then false else let\n val re = endpoint_set_address (p->endpoint, host, port)\n in\n if re = false then false else let\n abst@ype socklen_t = $extype\"socklen_t\"\n extern fun lwip_connect: (int, struct_sockaddr_in_p, socklen_t) -> int = \"mac#\"\n val fd = socket_sock_fd (p->sock)\n val rh = endpoint_remoteHost (p->endpoint)\n val rc = lwip_connect (fd, rh, $UN.cast (sizeof))\n in\n if rc < 0 then let\n val _ = socket_finisock (p->sock, true)\n in\n false\n end else let\n val () = p->is_connected := true\n in\n true\n end\n end\n end\n prval () = TCPSocketConnection_addback_struct(pfat | tcp)\nin\n ret\nend\n\nimplement\ntcp_socket_connection_receive (tcp) = let\n val is_connected = tcp_socket_connection_is_connected (tcp)\n val (pfat | p) = TCPSocketConnection_takeout_struct (tcp)\n val fd = socket_sock_fd (p->sock)\n val blocking = socket_blocking (p->sock)\n prval () = TCPSocketConnection_addback_struct(pfat | tcp)\nin\n if (fd < 0) orelse (not is_connected) then None_vt () else let\n val b = if blocking then true else let\n val (pfat | p) = TCPSocketConnection_takeout_struct (tcp)\n val tout = socket_timeout (p->sock)\n val r = socket_wait_readable (p->sock, tout)\n prval () = TCPSocketConnection_addback_struct(pfat | tcp)\n in\n r\n end\n in\n None_vt () \/\/ xxx\n end\nend\n\nimplement\ntcp_socket_connection_close (tcp) = {\n val (pfat | p) = TCPSocketConnection_takeout_struct (tcp)\n val () = endpoint_close (p->endpoint)\n val () = socket_close (p->sock)\n val () = $UN.castvwtp0((pfat | p))\n val () = __free (tcp) where {\n extern fun __free {vt:vtype} (x: vt): void = \"atspre_mfree_gc\"\n }\n}\n","returncode":0,"stderr":"","license":"apache-2.0","lang":"ATS"} {"commit":"e4155516c4d86ee1b6af9944e5d6a083aab49778","subject":"More strong type","message":"More strong type\n","repos":"fpiot\/arduino-ats,Proclivis\/arduino-ats,Proclivis\/arduino-ats,fpiot\/arduino-ats","old_file":"demo\/04_pwm_closure\/DATS\/main.dats","new_file":"demo\/04_pwm_closure\/DATS\/main.dats","new_contents":"#include \"config.hats\"\n#include \"{$TOP}\/avr_prelude\/kernel_staload.hats\"\n\nstaload \"{$TOP}\/SATS\/arduino.sats\"\nstaload UN = \"prelude\/SATS\/unsafe.sats\"\n\n#define LED 9\n#define DELAY_MS 10.0\n\nfun int_foreach_clo\n (n: natLt(256), f: &natLt(256) - void): void = {\n val () = f n\n val () = if n > 0 then int_foreach_clo (n - 1, f)\n}\n\nimplement main () = {\n fun fadein() = let\n var fwork = lam@ (n: natLt(256)) => {\n val () = analogWrite (LED, $UN.cast n)\n val () = delay_ms(DELAY_MS)\n }\n in\n int_foreach_clo(255, fwork)\n end \/\/ end of [fadein]\n val () = pinMode (LED, OUTPUT)\n val () = (fix f(): void => (fadein(); f()))()\n}\n","old_contents":"#include \"config.hats\"\n#include \"{$TOP}\/avr_prelude\/kernel_staload.hats\"\n\nstaload \"{$TOP}\/SATS\/arduino.sats\"\nstaload UN = \"prelude\/SATS\/unsafe.sats\"\n\n#define LED 9\n#define DELAY_MS 10.0\n\nfun int_foreach_clo\n (n: int, f: &int - void): void = {\n val () = f n\n val () = int_foreach_clo (n - 1, f)\n}\n\nimplement main () = {\n fun fadein() = let\n var fwork = lam@ (n: int) => {\n val () = analogWrite (LED, $UN.cast n)\n val () = delay_ms(DELAY_MS)\n }\n in\n int_foreach_clo(256, fwork)\n end \/\/ end of [fadein]\n val () = pinMode (LED, OUTPUT)\n val () = (fix f(): void => (fadein(); f()))()\n}\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"320f5593a359dcbe8b969aa199f524eb53d5909a","subject":"Updating: very minorly improving","message":"Updating: very minorly improving\n","repos":"githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib","old_file":"contrib\/libats-\/hwxi\/teaching\/mysession-g\/DATS\/intset.dats","new_file":"contrib\/libats-\/hwxi\/teaching\/mysession-g\/DATS\/intset.dats","new_contents":"(*\n** integer sets\n*)\n\n(* ****** ****** *)\n\/\/\nstaload\n\".\/..\/SATS\/intset.sats\"\n\/\/\n(* ****** ****** *)\n\nassume\nintset(n:int, xs:iset) = List0(int)\n\n(* ****** ****** *)\n\/\/\nimplement\n{}(*tmp*)\nintset_nil() = list_nil()\n\/\/\nimplement\n{}(*tmp*)\nintset_int(x) = list_sing(x)\n\/\/\nimplement\n{}(*tmp*)\nintset_int2(x1, x2) = $list{int}(x1, x2)\n\/\/\nimplement\n{}(*tmp*)\nintset_int3(x1, x2, x3) = $list{int}(x1, x2, x3)\n\/\/\n(* ****** ****** *)\n\nimplement\n{}(*tmp*)\nintset_ncomplement\n (xs, n) = let\n\/\/\nfun\naux1\n(\n i: int\n, res: List0_vt(int)\n) : List0_vt(int) =\n(\n\/\/\nif (i < n)\n then aux1(i+1, cons_vt(i, res)) else res\n\/\/\n) (* end of [aux1] *)\n\/\/\nand\naux2\n(\n i: int\n, x0: int\n, xs: List0(int)\n, res: List0_vt(int)\n) : List0_vt(int) = (\n\/\/\nif\n(i < x0)\nthen (\n aux2(i+1, x0, xs, cons_vt(i, res))\n) else (\n case+ xs of\n | list_nil() => aux1(i+1, res)\n | list_cons(x, xs) => aux2(i+1, x, xs, res)\n) (* end of [else] *)\n\/\/\n) (* end of [aux2] *)\n\/\/\nval ys = (\n\/\/\ncase+ xs of\n| list_nil() => aux1(0, nil_vt)\n| list_cons(x, xs) => aux2(0, x, xs, nil_vt)\n\/\/\n) : List0_vt(int)\n\/\/\nin\n list_vt2t(list_vt_reverse(ys))\nend \/\/ end of [intset_ncomplement]\n\n(* ****** ****** *)\n\nimplement\nfprint_intset(out, xs) = fprint_list_sep(out, xs, \"->\")\n\n(* ****** ****** *)\n\n(* end of [intset.dats] *)\n","old_contents":"(*\n** integer sets\n*)\n\n(* ****** ****** *)\n\/\/\nstaload\n\".\/..\/SATS\/intset.sats\"\n\/\/\n(* ****** ****** *)\n\nassume\nintset(n:int, xs:iset) = List0(int)\n\n(* ****** ****** *)\n\/\/\nimplement\n{}(*tmp*)\nintset_nil() = list_nil()\n\/\/\nimplement\n{}(*tmp*)\nintset_int(x) = list_sing(x)\n\/\/\nimplement\n{}(*tmp*)\nintset_int2(x1, x2) = $list{int}(x1, x2)\n\/\/\nimplement\n{}(*tmp*)\nintset_int3(x1, x2, x3) = $list{int}(x1, x2, x3)\n\/\/\n(* ****** ****** *)\n\nimplement\n{}(*tmp*)\nintset_ncomplement\n (xs, n) = let\n\/\/\nfun\naux1\n(\n i: int\n, res: List0_vt(int)\n) : List0_vt(int) =\n(\n\/\/\nif (i < n)\n then aux1(i+1, cons_vt(i, res)) else res\n\/\/\n) (* end of [aux1] *)\n\/\/\nand\naux2\n(\n i: int\n, x0: int\n, xs: List0(int)\n, res: List0_vt(int)\n) : List0_vt(int) = (\n\/\/\nif\n(i < x0)\nthen (\n aux2(i+1, x0, xs, cons_vt(i, res))\n) else (\n case+ xs of\n | list_nil() => aux1(i+1, res)\n | list_cons(x, xs) => aux2(i+1, x, xs, res)\n) (* end of [else] *)\n\/\/\n) (* end of [aux2] *)\n\/\/\nin\n\/\/\ncase+ xs of\n| list_nil() =>\n list_vt2t(list_vt_reverse(aux1(0, nil_vt)))\n| list_cons(x, xs) =>\n list_vt2t(list_vt_reverse(aux2(0, x, xs, nil_vt)))\n\/\/\nend \/\/ end of [intset_ncomplement]\n\n(* ****** ****** *)\n\nimplement\nfprint_intset(out, xs) = fprint_list_sep(out, xs, \"->\")\n\n(* ****** ****** *)\n\n(* end of [intset.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"b7e270d764ba8f741a8d0c49b664d76b043c8c3c","subject":"Updating location of jsmn.dats","message":"Updating location of jsmn.dats\n","repos":"wdblair\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib","old_file":"projects\/MEDIUM\/ATS-extsolve\/parsing\/parsing_mylib.dats","new_file":"projects\/MEDIUM\/ATS-extsolve\/parsing\/parsing_mylib.dats","new_contents":"(*\n** Parsing constraints in JSON format\n*)\n\n(* ****** ****** *)\n\n#include\n\"share\/atspre_define.hats\"\n#include\n\"share\/atspre_staload.hats\"\n\n(* ****** ****** *)\n\n#define ATS_DYNLOADFLAG 0 (* no run-time dynloading *)\n\n(* ****** ****** *)\n\nlocal\nin\n%{\n#define JSMN_STRICT 1\n\n#include \"jsmn.c\"\n%}\nend\n\n\nlocal\nin\n#include \"libats-\/wdblair\/jsmn\/DATS\/jsmn.dats\"\nend\n\n(* ****** ****** *)\n\n(* end of [parsing_mylib.dats] *)\n","old_contents":"(*\n** Parsing constraints in JSON format\n*)\n\n(* ****** ****** *)\n\n#include\n\"share\/atspre_define.hats\"\n#include\n\"share\/atspre_staload.hats\"\n\n(* ****** ****** *)\n\n#define ATS_DYNLOADFLAG 0 (* no run-time dynloading *)\n\n(* ****** ****** *)\n\nlocal\nin\n%{\n#define JSMN_STRICT 1\n\n#include \"jsmn.c\"\n%}\nend\n\n\nlocal\nin\n#include \"contrib\/libats-\/wdblair\/jsmn\/DATS\/jsmn.dats\"\nend\n\n(* ****** ****** *)\n\n(* end of [parsing_mylib.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"40edf773f92681608b780714ef8a6a0dbae74a9a","subject":"Updating: minorly improving","message":"Updating: minorly improving\n","repos":"wdblair\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,steinwaywhw\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,steinwaywhw\/ATS-Postiats-contrib,steinwaywhw\/ATS-Postiats-contrib,steinwaywhw\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,steinwaywhw\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,steinwaywhw\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib","old_file":"projects\/SMALL\/M-N-K-game\/Part1\/game_board.dats","new_file":"projects\/SMALL\/M-N-K-game\/Part1\/game_board.dats","new_contents":"(*\n** The M-N-K-game\n*)\n\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_staload.hats\"\n\/\/\n(* ****** ****** *)\n\nstaload \".\/game.sats\"\n\n(* ****** ****** *)\n\nassume\nboard_type = mtrxszref (int)\n\n(* ****** ****** *)\n\/\/\nimplement\nboard_make (m, n) =\n mtrxszref_make_elt (i2sz(m), i2sz(n), 0)\n\/\/\n(* ****** ****** *)\n\nfun\npid2char (id: int): char =\n(\ncase+ id of\n| 0 => ' ' | 1 => 'X' | 2 => 'O' | _ => '#'\n) (* end of [pid2char] *)\n\n(* ****** ****** *)\n\/\/\nimplement\nfprint_board (out, board) =\n fprint_mtrxszref_sep (out, board, \"|\", \"\\n\")\n\/\/\n(* ****** ****** *)\n\n\/\/ (*\nval () = \/\/ testing code\n{\n\/\/\nval () =\nprintln! (\"TESTING(game_board):\")\n\/\/\nval () =\nprintln! (\"TESTING(fprint_board): beg\")\nval board = board_make (3, 3)\nval ((*void*)) = fprint_board (stdout_ref, board)\nval ((*void*)) = fprint_newline (stdout_ref)\nval () =\nprintln! (\"TESTING(fprint_board): end\")\n} (* end of [val] *)\n\/\/ *)\n\n(* ****** ****** *)\n\n(* end of [game_board.dats] *)\n","old_contents":"(*\n** The M-N-K-game\n*)\n\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_staload.hats\"\n\/\/\n(* ****** ****** *)\n\nstaload \".\/game.sats\"\n\n(* ****** ****** *)\n\nassume\nboard_type = mtrxszref (int)\n\n(* ****** ****** *)\n\/\/\nimplement\nboard_make (m, n) =\n mtrxszref_make_elt (i2sz(m), i2sz(n), 0)\n\/\/\n(* ****** ****** *)\n\n(* end of [game_board.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"4465869d80fa2d255bb3fff0f0323da1ed3123d2","subject":"Updating: very minorly improving","message":"Updating: very minorly improving\n","repos":"bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib","old_file":"contrib\/libatscc\/libatscc2py\/TEST\/PYgame\/test01.dats","new_file":"contrib\/libatscc\/libatscc2py\/TEST\/PYgame\/test01.dats","new_contents":"(* ****** ****** *)\n\/\/\n\/\/ Trying libatscc2py\/PYgame\n\/\/\n\/\/ Author: Hongwei Xi\n\/\/ Authoremail: gmhwxiATgmailDOTcom\n\/\/ Starting time: May 23, 2016\n\/\/\n(* ****** ****** *)\n\/\/\n(*\n#include\n\"share\/atspre_define.hats\"\n*)\n\/\/\n#include\".\/..\/..\/staloadall.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/..\/..\/SATS\/PYgame\/pygame.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\ntest01_main\n(\n\/\/ argless\n) : void = \"mac#\"\n\/\/\nimplement\ntest01_main() =\n{\n\/\/\nval npnf = pygame_init_ret()\nval ((*void*)) = println! (\"np = \", npnf.0)\nval ((*void*)) = println! (\"nf = \", npnf.1)\n\/\/\nval res = $tup(500,500)\nval screen = display_set_mode(res)\nval _(*Rect*) = screen.fill(Color(0, 0, 0))\n\/\/\nval screen2 = Surface(screen.get_size(), SRCALPHA, 32)\n\/\/\n(*\nval () = println! (\"screen2_width = \", screen2.get_width())\nval () = println! (\"screen2_height = \", screen2.get_height())\n*)\n\/\/\nval c1 = Color(200, 200, 200)\n\/\/\nval r0 = Rect(100, 100, 300, 300)\n\/\/\nval _rect_ = screen2.fill(c1, r0, 0)\n\/\/\nval _rect_ =\n draw_circle(screen2, Color(0,0,0), $tup(250,250), 100)\n\/\/\nval _rect_ =\n screen.blit(screen2, $tup(0, 0))\n\/\/\nval ((*void*)) = display_flip((*void*))\n\/\/\nval () = loop() where\n{\n fun\n loop(): void = let\n val e = event_wait()\n val t = e.type()\n in\n ifcase\n | t = QUIT => ()\n | t = KEYDOWN => ()\n | _(*else*) => loop()\n end \/\/ end of [loop]\n}\n\/\/\nval ((*void*)) = pygame_quit((*void*))\n\/\/\n} (* end of [test01_main] *)\n\/\/\n(* ****** ****** *)\n\n%{^\n######\nfrom libatscc2py_all import *\n######\nfrom ats2py_PYgame_pyame_cats import *\n######\nsys.setrecursionlimit(1000000)\n######\n%} \/\/ end of [%{^]\n\n(* ****** ****** *)\n\n%{$\nif __name__ == '__main__': test01_main()\n%} \/\/ end of [%{$]\n\n(* ****** ****** *)\n\n(* end of [test01.dats] *)\n","old_contents":"(* ****** ****** *)\n\/\/\n\/\/ Trying libatscc2py\/Pygame\n\/\/\n(* ****** ****** *)\n\/\/\n(*\n#include\n\"share\/atspre_define.hats\"\n*)\n\/\/\n#include\".\/..\/..\/staloadall.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/..\/..\/SATS\/PYgame\/pygame.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\ntest01_main\n(\n\/\/ argless\n) : void = \"mac#\"\n\/\/\nimplement\ntest01_main() =\n{\n\/\/\nval npnf = pygame_init_ret()\nval ((*void*)) = println! (\"np = \", npnf.0)\nval ((*void*)) = println! (\"nf = \", npnf.1)\n\/\/\nval res = $tup(500,500)\nval screen = display_set_mode(res)\nval _(*Rect*) = screen.fill(Color(0, 0, 0))\n\/\/\nval screen2 = Surface(screen.get_size(), SRCALPHA, 32)\n\/\/\n(*\nval () = println! (\"screen2_width = \", screen2.get_width())\nval () = println! (\"screen2_height = \", screen2.get_height())\n*)\n\/\/\nval c1 = Color(200, 200, 200)\n\/\/\nval r0 = Rect(100, 100, 300, 300)\n\/\/\nval _rect_ = screen2.fill(c1, r0, 0)\n\/\/\nval _rect_ =\n draw_circle(screen2, Color(0,0,0), $tup(250,250), 100)\n\/\/\nval _rect_ =\n screen.blit(screen2, $tup(0, 0))\n\/\/\nval ((*void*)) = display_flip((*void*))\n\/\/\nval () = loop() where\n{\n fun\n loop(): void = let\n val e = event_wait()\n val t = e.type()\n in\n ifcase\n | t = QUIT => ()\n | t = KEYDOWN => ()\n | _(*else*) => loop()\n end \/\/ end of [loop]\n}\n\/\/\nval ((*void*)) = pygame_quit((*void*))\n\/\/\n} (* end of [test01_main] *)\n\/\/\n(* ****** ****** *)\n\n%{^\n######\nfrom libatscc2py_all import *\n######\nfrom ats2py_PYgame_pyame_cats import *\n######\nsys.setrecursionlimit(1000000)\n######\n%} \/\/ end of [%{^]\n\n(* ****** ****** *)\n\n%{$\nif __name__ == '__main__': test01_main()\n%} \/\/ end of [%{$]\n\n(* ****** ****** *)\n\n(* end of [test01.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"90898105c5301124e608d1370fdd39c01a2a7ffa","subject":"Updating: initiating ATS-Python3","message":"Updating: initiating ATS-Python3\n","repos":"steinwaywhw\/ATS-Python3","old_file":"DATS\/atscc2py3_emit2.dats","new_file":"DATS\/atscc2py3_emit2.dats","new_contents":"(* ****** ****** *)\n\/\/\n\/\/ Atscc2py3:\n\/\/ from ATS to Python3\n\/\/\n(* ****** ****** *)\n\/\/\n\/\/ HX-2014-08-04: start\n\/\/ HX-2015-05-23: restructure\n\/\/\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_staload.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\nUN = \"prelude\/SATS\/unsafe.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\n#if\ndefined\n(\nCATSPARSEMIT_targetloc\n)\n#then\n#else\n\/\/\n#define\nCATSPARSEMIT_targetloc\n\".\/..\/CATS-parsemit\"\n\/\/\n#endif \/\/ end of [ifdef]\n\/\/\n(* ****** ****** *)\n\/\/\n#staload\n\"{$CATSPARSEMIT}\/SATS\/catsparse.sats\"\n#staload\n\"{$CATSPARSEMIT}\/SATS\/catsparse_emit.sats\"\n#staload\n\"{$CATSPARSEMIT}\/SATS\/catsparse_syntax.sats\"\n#staload\n\"{$CATSPARSEMIT}\/SATS\/catsparse_typedef.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_statmpdeclst_get(): d0eclist\nextern\nfun\nthe_statmpdeclst_insert(d0ecl): void\n\/\/\n(* ****** ****** *)\n\nlocal\n\/\/\nval the_statmps =\n ref (list_nil(*void*))\n\/\/\nin (* in-of-local *)\n\/\/\nimplement\nthe_statmpdeclst_get() =\n list_vt2t(list_reverse(!the_statmps))\n\/\/\nimplement\nthe_statmpdeclst_insert(d0c) = let\n val d0cs = !the_statmps in !the_statmps := list_cons (d0c, d0cs)\nend \/\/ end of [the_statmpdeclst_insert]\n\/\/\nend \/\/ end of [local]\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit_the_statmpdeclst\n(\nout: FILEref, ind: int\n) : void \/\/ end-of-fun\n\/\/\nimplement\nemit_the_statmpdeclst\n (out, ind) = let\n\/\/\nfun auxlst\n(\n out: FILEref, xs: d0eclist\n) : void =\n(\ncase+ xs of\n| list_nil () => ()\n| list_cons (x, xs) => let\n val-\n D0Cstatmp\n (tmp, opt) = x.d0ecl_node\n \/\/ end of [val]\n in\n case+ opt of\n | None _ =>\n (\n auxlst(out, xs)\n ) (* None *)\n | Some _ => let\n val () = emit_ENDL(out)\n val () = emit_nspc(out, ind)\n val () =\n (\n emit_text(out, \"global \"); emit_tmpvar(out, tmp)\n ) (* end of [val] *)\n in\n auxlst (out, xs)\n end \/\/ end of [Some]\n end \/\/ end of [list_cons]\n) (* end of [auxlst] *)\n\/\/\nin\n auxlst (out, the_statmpdeclst_get())\nend \/\/ end of [emit_the_statmpdeclst]\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit_f0arglst_nonlocal\n(\nout: FILEref\n,\nf0as: f0arglst ): void\n\/\/\nimplement\nemit_f0arglst_nonlocal\n (out, f0as) = let\n\/\/\nfun\nauxlst\n(\n out: FILEref, f0as: f0arglst, i: int\n) : void =\n(\ncase+ f0as of\n| list_nil() => ()\n| list_cons(f0a, f0as) =>\n (\n case-\n f0a.f0arg_node\n of (* case- *)\n | F0ARGsome (arg, _) => let\n val () =\n if i > 0\n then emit_text (out, \", \")\n \/\/ end of [if]\n val () = emit_tmpvar (out, arg)\n in\n auxlst (out, f0as, i+1)\n end \/\/ end of [F0ARGsome]\n ) (* end of [list_cons] *)\n)\n\/\/\nin\n\/\/\ncase+ f0as of\n| list_nil() =>\n {\n \/\/ nothing\n } (* list_nil *)\n| list_cons _ =>\n {\n val () =\n emit_nspc (out, 4(*ind*))\n val () =\n emit_text (out, \"nonlocal \")\n val () = auxlst (out, f0as, 0(*i*))\n val () = emit_ENDL (out)\n } (* list_cons *)\n\/\/\nend \/\/ end of [emit_f0arglst_nonlocal]\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit_tmpdeclst_initize\n (out: FILEref, tds: tmpdeclst): void\n\/\/\nimplement\nemit_tmpdeclst_initize\n (out, tds) = let\n\/\/\nfun auxlst\n(\n out: FILEref, tds: tmpdeclst\n) : void =\n(\ncase+ tds of\n| list_nil () => ()\n| list_cons (td, tds) =>\n (\n case+\n td.tmpdec_node\n of (* case+ *)\n | TMPDECnone\n (tmp) => auxlst (out, tds)\n \/\/ end of [TMPDECnone]\n | TMPDECsome\n (tmp, _) => let\n val () = emit_nspc (out, 2(*ind*))\n val () = emit_tmpvar (out, tmp)\n val () = emit_text (out, \" = None\\n\")\n in\n auxlst (out, tds)\n end \/\/ end of [TMPDECsome]\n ) (* end of [list_cons] *)\n)\n\/\/\nin\n auxlst (out, tds)\nend \/\/ end of [emit_tmpdeclst_initize]\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit_tmpdeclst_nonlocal\n (out: FILEref, tds: tmpdeclst): void\n\/\/\nimplement\nemit_tmpdeclst_nonlocal\n (out, tds) = let\n\/\/\nfun auxlst\n(\n out: FILEref, tds: tmpdeclst, i: int\n) : void =\n(\ncase+ tds of\n| list_nil () => ()\n| list_cons (td, tds) =>\n (\n case+\n td.tmpdec_node\n of (* case+ *)\n | TMPDECnone\n (tmp) =>\n (\n auxlst(out, tds, i)\n ) (* TMPDECnone *)\n | TMPDECsome\n (tmp, _) => let\n val () =\n if i > 0 then\n emit_text (out, \", \")\n \/\/ end of [if]\n val () = emit_tmpvar (out, tmp)\n in\n auxlst (out, tds, i+1)\n end \/\/ end of [TMPDECsome]\n ) (* end of [list_cons] *)\n)\n\/\/\nin\n\/\/\ncase+ tds of\n| list_nil () => ()\n| list_cons _ =>\n {\n val () =\n emit_nspc (out, 4(*ind*))\n val () =\n emit_text (out, \"nonlocal\")\n val () = emit_SPACE (out)\n val () = auxlst (out, tds, 0)\n val () = emit_newline (out)\n } (* end of [list_cons] *)\n\/\/\nend \/\/ end of [emit_tmpdeclst_nonlocal]\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit_mbranchlst_initize\n(out: FILEref, inss: instrlst): void\n\/\/\nimplement\nemit_mbranchlst_initize\n (out, inss) = let\n\/\/\nfun auxlst\n(\n out: FILEref, inss: instrlst, i: int\n) : void =\n(\n\/\/\ncase+ inss of\n| list_nil() => ()\n| list_cons(_, inss) =>\n {\n val () =\n emit_nspc (out, 2(*ind*))\n \/\/ end of [val]\n val () =\n (\n emit_text (out, \"mbranch_\");\n emit_int (out, i); emit_text (out, \" = None\\n\")\n )\n val () = auxlst (out, inss, i+1)\n } (* end of [list_cons] *)\n\/\/\n) (* end of [auxlst] *)\n\/\/\nin\n auxlst (out, inss, 1(*i*))\nend \/\/ end of [emit_mbranchlst_initize]\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit_mbranchlst_nonlocal\n (out: FILEref, inss: instrlst): void\n\/\/\nimplement\nemit_mbranchlst_nonlocal\n (out, inss) = let\n\/\/\nfun auxlst\n(\n out: FILEref, inss: instrlst, i: int\n) : void =\n(\ncase+ inss of\n| list_nil() => ()\n| list_cons(_, inss) => let\n val () =\n if i >= 2 then emit_text (out, \", \")\n val () =\n (\n emit_text (out, \"mbranch_\"); emit_int (out, i)\n ) (* end of [val] *)\n in\n auxlst (out, inss, i+1)\n end \/\/ end of [list_cons]\n\/\/\n) (* end of [auxlst] *)\n\/\/\nin\n\/\/\ncase+ inss of\n| list_nil () => ()\n| list_cons _ =>\n {\n val () =\n emit_nspc (out, 4(*ind*))\n val () =\n emit_text (out, \"nonlocal \")\n val () = auxlst (out, inss, 1(*i*))\n val () = emit_ENDL (out)\n } (* end of [list_cons] *)\n\/\/\nend \/\/ end of [emit_mbranchlst_nonlocal]\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nfunlab_get_index(fl: label): int\nextern\nfun\ntmplab_get_index(lab: label): int\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_f0arglst_get(): f0arglst\nextern\nfun\nthe_f0arglst_set(f0as: f0arglst): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_tmpdeclst_get(): tmpdeclst\nextern\nfun\nthe_tmpdeclst_set(tds: tmpdeclst): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_funbodylst_get(): instrlst\nextern\nfun\nthe_funbodylst_set(inss: instrlst): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_branchlablst_get(): labelist\nextern\nfun\nthe_branchlablst_set(tls: labelist): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_caseofseqlst_get(): instrlst\nextern\nfun\nthe_caseofseqlst_set(inss: instrlst): void\n\/\/\n(* ****** ****** *)\n\nlocal\n\/\/\nval the_f0arglst = ref (list_nil)\nval the_tmpdeclst = ref (list_nil)\n\/\/\nval the_funbodylst = ref (list_nil)\n\/\/\nval the_branchlablst = ref (list_nil)\nval the_caseofseqlst = ref (list_nil)\n\/\/\nin (* in-of-local *)\n\nimplement\nthe_f0arglst_get() = !the_f0arglst\nimplement\nthe_f0arglst_set(xs) = !the_f0arglst := xs\n\nimplement\nthe_tmpdeclst_get() = !the_tmpdeclst\nimplement\nthe_tmpdeclst_set(xs) = !the_tmpdeclst := xs\n\nimplement\nthe_funbodylst_get() = !the_funbodylst\nimplement\nthe_funbodylst_set(xs) = !the_funbodylst := xs\n\nimplement\nthe_branchlablst_get() = !the_branchlablst\nimplement\nthe_branchlablst_set(tls) = !the_branchlablst := tls\n\nimplement\nthe_caseofseqlst_get() = !the_caseofseqlst\nimplement\nthe_caseofseqlst_set(xs) = !the_caseofseqlst := xs\n\nend \/\/ end of [local]\n\n(* ****** ****** *)\n\nimplement\nfunlab_get_index\n (fl0) = let\n\/\/\nval n0 = fl0.i0dex_sym\n\/\/\nfun\nauxlst\n(\nxs: instrlst, i: int\n) : int = (\n\/\/\ncase+ xs of\n| list_nil () => ~1(*error*)\n| list_cons (x, xs) =>\n (\n case+ x.instr_node of\n | ATSfunbodyseq _ => let\n val fl = funbodyseq_get_funlab (x)\n in\n if n0 = fl.i0dex_sym then i else auxlst (xs, i+1)\n end \/\/ end of [ATSfunbodyseq]\n | _ (*non-ATSfunbody*) => auxlst (xs, i)\n ) (* end of [list_cons] *)\n\/\/\n) (* end of [auxlst] *)\n\/\/\nin\n auxlst (the_funbodylst_get(), 1)\nend \/\/ end of [funlab_get_index]\n\n(* ****** ****** *)\n\nimplement\ntmplab_get_index\n (lab0) = let\n\/\/\nval n0 = lab0.i0dex_sym\n\/\/\nfun\nauxlst\n(\n xs: labelist, i: int\n) : int =\n(\ncase+ xs of\n| list_nil () => ~1(*error*)\n| list_cons (x, xs) =>\n if n0 = x.i0dex_sym then i else auxlst (xs, i+1)\n \/\/ end of [list_cons]\n)\n\/\/\nin\n\/\/\nauxlst(the_branchlablst_get(), 1)\n\/\/\nend \/\/ end of [tmplab_get_index]\n\n(* ****** ****** *)\n\/\/\nfun\nemit_funlab_index\n (out: FILEref, fl: label): void =\n emit_int(out, funlab_get_index(fl))\n\/\/\nfun\nemit_tmplab_index\n (out: FILEref, lab: label): void =\n emit_int(out, tmplab_get_index(lab))\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nbranchmap_get_index\n (ins: instr): int\n\/\/\nimplement\nbranchmap_get_index\n (x0) = let\n\/\/\nval p0 = $UN.cast2ptr(x0)\n\/\/\nfun\nauxlst\n(\nxs: instrlst, i: int\n) : int =\n(\ncase xs of\n| list_nil() => ~1(*error*)\n| list_cons(x, xs) =>\n if $UN.cast2ptr(x) = p0 then i else auxlst(xs, i+1)\n \/\/ end of [list_cons]\n)\n\/\/\nin\n auxlst(the_caseofseqlst_get(), 1)\nend \/\/ end of [branchmap_get_index]\n\n(* ****** ****** *)\n\/\/\nfun\nemit_branchmap_index\n (out: FILEref, ins: instr): void =\n emit_int (out, branchmap_get_index(ins))\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nemit_branchmap\n(\n out: FILEref, ins0: instr\n) : void = let\n\/\/\nfun auxlst\n(\n out: FILEref, xs: instrlst, i: int\n) : int =\n(\ncase+ xs of\n| list_nil() => i\n| list_cons(x, xs) =>\n (\n case+ x.instr_node of\n | ATSINSlab (lab) => let\n val ((*void*)) =\n if i >= 2 then emit_text(out, \", \")\n \/\/ end of [val]\n val () = emit_int (out, i)\n val () = emit_text (out, \": \")\n val () = emit_label (out, lab)\n in\n auxlst (out, xs, i+1)\n end \/\/ end of [ATSINSlab]\n | _(*non-ATSINSlab*) => auxlst (out, xs, i)\n ) (* list_cons *)\n) (* end of [auxlst] *)\n\/\/\nfun auxlst2\n(\n out: FILEref, xs: instrlst, i: int\n) : void =\n(\ncase+ xs of\n| list_nil() => ()\n| list_cons(x, xs) => let\n val-ATSbranchseq(inss) = x.instr_node\n in\n auxlst2 (out, xs, auxlst (out, inss, i))\n end \/\/ end of [list_cons]\n) (* end of [auxlst2] *)\n\/\/\nval-ATScaseofseq(inss) = ins0.instr_node\n\/\/\nval () = emit_nspc (out, 2(*ind*))\nval () = emit_text (out, \"mbranch_\")\nval () = emit_branchmap_index (out, ins0)\nval () = emit_text (out, \" = \")\nval ((*opening*)) = emit_text (out, \"{ \")\nval () = auxlst2 (out, inss, 1(*first*))\nval ((*closing*)) = emit_text (out, \" }\\n\")\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit_branchmap]\n\/\/\n(* ****** ****** *)\n\nfun\nemit_branchmaplst\n(\n out: FILEref, inss: instrlst\n) : void =\n(\ncase+ inss of\n| list_nil () => ()\n| list_cons (ins, inss) =>\n {\n val () = emit_branchmap (out, ins)\n val () = emit_branchmaplst (out, inss)\n }\n) (* end of [emit_branchmaplst] *)\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nf0body_collect_caseof\n (fbody: f0body): instrlst(*list-of-caseofseq*)\n\/\/\nextern\nfun\ninstrlst_collect_caseof\n (inss: instrlst): instrlst(*list-of-caseofseq*)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nf0body_collect_caseof\n (fbody) = let\nin\n\/\/\ncase+\nfbody.f0body_node\nof \/\/ case+\n| F0BODY(tds, inss) => instrlst_collect_caseof(inss)\n\/\/\nend \/\/ end of [f0body_collect_caseof]\n\/\/\nimplement\ninstrlst_collect_caseof\n (inss) = let\n\/\/\nvtypedef res = instrlst_vt\n\/\/\nfun\naux\n(\n ins: instr, res: res\n) : res =\n(\ncase+\nins.instr_node of\n\/\/\n| ATScaseofseq\n (inss) =>\n (\n auxlst(inss, cons_vt(ins, res))\n ) (* end of [ATScaseofseq] *)\n| ATSbranchseq(inss) => auxlst(inss, res)\n\/\/\n| ATSif (\n d0e, inss, inssopt\n ) => let\n val res = auxlst(inss, res)\n in\n case+ inssopt of\n | None((*void*)) => res | Some(inss) => auxlst(inss, res)\n end \/\/ end of [ATSif]\n\/\/\n| ATSifthen(d0e, inss) => auxlst(inss, res)\n| ATSifnthen(d0e, inss) => auxlst(inss, res)\n\/\/\n| ATSfunbodyseq(inss) => auxlst(inss, res)\n\/\/\n| _ (*rest-of-instr*) => res\n\/\/\n) (* end of [aux] *)\n\/\/\nand\nauxlst\n(\n inss: instrlst, res: res\n) : res =\n(\ncase+ inss of\n| list_cons\n (ins, inss) => let\n val res = aux (ins, res) in auxlst(inss, res)\n end \/\/ end of [list_cons]\n| list_nil((*void*)) => res\n)\n\/\/\nval res = auxlst(inss, list_vt_nil)\n\/\/\nin\n list_vt2t(list_vt_reverse(res))\nend \/\/ end of [instrlst_collect_caseof]\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit2_instr\n(out: FILEref, ind: int, ins: instr) : void\nextern\nfun\nemit2_instr_ln\n(out: FILEref, ind: int, ins: instr) : void\nextern\nfun\nemit2_instr_newline\n(out: FILEref, ind: int, ins: instr) : void\nextern\nfun\nemit2_instrlst\n(out: FILEref, ind: int, inss: instrlst) : void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit2_ATSfunbodyseq\n(out: FILEref, ind: int, ins: instr) : void\n\/\/\nextern\nfun\nemit2_ATSINSmove_con1\n(out: FILEref, ind: int, ins: instr) : void\n\/\/\nextern\nfun\nemit2_ATSINSmove_boxrec\n(out: FILEref, ind: int, ins: instr) : void\n\/\/\nextern\nfun\nemit2_ATSINSmove_delay\n(out: FILEref, ind: int, ins: instr) : void\nextern\nfun\nemit2_ATSINSmove_lazyeval\n(out: FILEref, ind: int, ins: instr) : void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit2_ATSINSmove_ldelay\n(out: FILEref, ind: int, ins: instr) : void\nextern\nfun\nemit2_ATSINSmove_llazyeval\n(out: FILEref, ind: int, ins: instr) : void\n\/\/\n(* ****** ****** *)\n\/\/\n\/\/ HX-2014-08:\n\/\/ this one should not be used for\n\/\/ emitting multiple-line instructions\n\/\/\nimplement\nemit_instr\n (out, ins) = emit2_instr (out, 0(*ind*), ins)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nemit2_instr\n (out, ind, ins0) = let\nin\n\/\/\ncase+\nins0.instr_node of\n\/\/\n| ATSif\n (\n d0e, inss, inssopt\n ) =>\n {\n\/\/\n val () = emit_nspc (out, ind)\n\/\/\n val () = emit_text (out, \"if \")\n val () = emit_LPAREN (out)\n val () = emit_d0exp (out, d0e)\n val () = emit_RPAREN (out)\n val () = emit_text (out, \":\\n\")\n\/\/\n val () = emit2_instrlst (out, ind+2, inss)\n\/\/\n val () =\n (\n case+\n inssopt\n of (*case+*)\n | None() => ()\n | Some(inss) =>\n (\n case+ inss of\n | list_nil _ => ()\n | list_cons _ => {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"else:\\n\")\n val () = emit2_instrlst (out, ind+2, inss)\n } (* end of [list_cons] *)\n ) (* end of [Some] *)\n )\n\/\/\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"#endif\")\n\/\/\n } (* end of [ATSif] *)\n\/\/\n| ATSifthen (d0e, inss) =>\n {\n\/\/\n val-list_sing(ins) = inss\n\/\/\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"if(\")\n val () = emit_d0exp (out, d0e)\n val ((*closing*)) = emit_text (out, \"): \")\n val () = emit_instr (out, ins)\n }\n| ATSifnthen (d0e, inss) =>\n {\n\/\/\n val-list_sing(ins) = inss\n\/\/\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"if not(\")\n val () = emit_d0exp (out, d0e)\n val ((*closing*)) = emit_text (out, \"): \")\n val () = emit_instr (out, ins)\n }\n\/\/\n| ATSbranchseq (inss) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"#ATSbranch\")\n }\n\/\/\n| ATScaseofseq (inss) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"#ATScaseofseq_beg\")\n val () = emit_ENDL (out)\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"tmplab_py = 1\\n\")\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"while(1):\\n\")\n val () = emit_nspc (out, ind+2)\n val () = emit_text (out, \"mbranch_\")\n val () = emit_branchmap_index (out, ins0)\n val () = emit_text (out, \".get(tmplab_py)()\\n\")\n val () = emit_nspc (out, ind+2)\n val () = emit_text (out, \"if (tmplab_py == 0): break\\n\")\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"#ATScaseofseq_end\")\n }\n\/\/\n| ATSreturn (tmp) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"return \")\n val () = emit_tmpvar (out, tmp)\n }\n| ATSreturn_void (tmp) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"return#_void\")\n }\n\/\/\n| ATSlinepragma (line, file) =>\n {\n val () = emit_text (out, \"#line \")\n val () = emit_PMVint (out, line)\n val () = emit_SPACE (out)\n val () = emit_PMVstring (out, file)\n }\n\/\/\n| ATSINSlab (lab) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"#\")\n val () = emit_label (out, lab)\n }\n| ATSINSgoto (lab) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"tmplab_py = \")\n val () = emit_tmplab_index (out, lab)\n val () =\n (\n emit_SPACE (out);\n emit_text (out, \"; return\");\n emit_SHARP (out); emit_label (out, lab)\n ) (* end of [val] *)\n }\n\/\/\n| ATSINSflab (flab) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_SHARP (out)\n val () = emit_label (out, flab)\n }\n| ATSINSfgoto (flab) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"funlab_py = \")\n val () = emit_funlab_index (out, flab)\n val () =\n (\n emit_SPACE (out);\n emit_SHARP (out); emit_label (out, flab)\n ) (* end of [val] *)\n }\n\/\/\n| ATSINSfreeclo (d0e) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"#ATSINSfreeclo\")\n val () = emit_LPAREN (out)\n val () = emit_d0exp (out, d0e)\n val () = emit_RPAREN (out)\n val () = emit_SEMICOLON (out)\n }\n| ATSINSfreecon (d0e) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"#ATSINSfreecon\")\n val () = emit_LPAREN (out)\n val () = emit_d0exp (out, d0e)\n val () = emit_RPAREN (out)\n val () = emit_SEMICOLON (out)\n }\n\/\/\n| ATSINSmove (tmp, d0e) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_tmpvar (out, tmp)\n val () = (\n emit_text (out, \" = \"); emit_d0exp (out, d0e)\n ) (* end of [val] *)\n } (* end of [ATSINSmove] *)\n\/\/\n| ATSINSmove_void (tmp, d0e) =>\n {\n val () = emit_nspc (out, ind)\n val () = (\n case+ d0e.d0exp_node of\n | ATSPMVempty _ =>\n emit_text (out, \"None#ATSINSmove_void\")\n \/\/ end of [ATSPMVempty]\n | _ (*non-ATSPMVempty*) => emit_d0exp (out, d0e)\n ) : void \/\/ end of [val]\n } (* end of [ATSINSmove_void] *)\n\/\/\n| ATSINSmove_nil (tmp) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_tmpvar (out, tmp)\n val () = emit_text (out, \" = \")\n val () = emit_text (out, \"None\")\n }\n\/\/\n| ATSINSmove_con0 (tmp, tag) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_tmpvar (out, tmp)\n val () = (\n emit_text (out, \" = \"); emit_PMVint (out, tag)\n ) (* end of [val] *)\n }\n\/\/\n| ATSINSmove_con1 _ =>\n emit2_ATSINSmove_con1 (out, ind, ins0)\n\/\/\n| ATSINSmove_boxrec _ =>\n emit2_ATSINSmove_boxrec (out, ind, ins0)\n\/\/\n| ATSINSmove_delay _ =>\n emit2_ATSINSmove_delay (out, ind, ins0)\n| ATSINSmove_lazyeval _ =>\n emit2_ATSINSmove_lazyeval (out, ind, ins0)\n\/\/\n| ATSINSmove_ldelay _ =>\n emit2_ATSINSmove_ldelay (out, ind, ins0)\n| ATSINSmove_llazyeval _ =>\n emit2_ATSINSmove_llazyeval (out, ind, ins0)\n\/\/\n| ATStailcalseq (inss) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"#ATStailcalseq_beg\")\n val () = emit_ENDL (out)\n val () = emit2_instrlst (out, ind, inss)\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"#ATStailcalseq_end\")\n \n } (* end of [ATStailcalseq] *)\n\/\/\n| ATSINSmove_tlcal (tmp, d0e) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_tmpvar (out, tmp)\n val () = emit_text (out, \" = \")\n val () = emit_d0exp (out, d0e) \n } (* end of [ATSINSmove_tlcal] *)\n\/\/\n| ATSINSargmove_tlcal (tmp1, tmp2) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_tmpvar (out, tmp1)\n val () = emit_text (out, \" = \")\n val () = emit_tmpvar (out, tmp2)\n } (* end of [ATSINSargmove_tlcal] *)\n\/\/\n| ATSINSextvar_assign (ext, d0e_r) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_d0exp (out, ext)\n val () = emit_text (out, \" = \")\n val () = emit_d0exp (out, d0e_r)\n val () = emit_SEMICOLON (out)\n }\n| ATSINSdyncst_valbind (d2c, d0e_r) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_i0de (out, d2c)\n val () = emit_text (out, \" = \")\n val () = emit_d0exp (out, d0e_r)\n val () = emit_SEMICOLON (out)\n }\n\/\/\n| ATSINScaseof_fail (errmsg) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"ATSINScaseof_fail\")\n val () = emit_LPAREN (out)\n val () = emit_PMVstring (out, errmsg)\n val () = emit_RPAREN (out)\n val () = emit_SEMICOLON (out)\n }\n| ATSINSdeadcode_fail (__tok__) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"ATSINSdeadcode_fail()\")\n val () = emit_SEMICOLON (out)\n }\n\/\/\n| ATSdynload (dummy) =>\n {\n val () = emit_nspc (out, ind) \n val () = emit_text (out, \"#ATSdynload()\")\n val () = emit_the_statmpdeclst (out, ind)\n }\n\/\/\n| ATSdynloadset (flag) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"#ATSdynloadset\\n\")\n val () = emit_nspc (out, ind)\n val () = (\n emit_tmpvar (out, flag); emit_text (out, \" = 1\")\n ) (* end of [val] *)\n }\n\/\/\n| ATSdynloadfcall (fcall) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"#ATSdynloadfcall\\n\")\n val () = emit_nspc (out, ind)\n val () =\n (emit_tmpvar (out, fcall); emit_text (out, \"()\"))\n \/\/ end of [val]\n }\n\/\/\n| ATSdynloadflag_sta (flag) =>\n {\n val () = emit_nspc (out, ind) \n val () = emit_text (out, \"#ATSdynloadflag_sta\\n\")\n val () = emit_nspc (out, ind) \n val () = (\n emit_text (out, \"global \"); emit_tmpvar (out, flag)\n ) (* end of [val] *)\n }\n\/\/\n| ATSdynloadflag_ext (flag) =>\n {\n val () = emit_nspc (out, ind) \n val () = emit_text (out, \"#ATSdynloadflag_ext\\n\")\n val () = emit_nspc (out, ind) \n val () = (\n emit_text (out, \"global \"); emit_tmpvar (out, flag)\n ) (* end of [val] *)\n }\n\/\/\n| _ (*rest-of-instr*) =>\n {\n val () = emit_nspc (out, ind)\n val ((*error*)) = fprint! (out, \"UNRECOGNIZED-INSTRUCTION: \", ins0)\n }\n\/\/\nend \/\/ end of [emit2_instr]\n\n(* ****** ****** *)\n\nimplement\nemit2_instr_ln\n (out, ind, ins) =\n(\n emit2_instr (out, ind, ins); emit_ENDL (out)\n) (* end of [emit2_instr_ln] *)\n\n(* ****** ****** *)\n\nimplement\nemit2_instr_newline\n (out, ind, ins) =\n(\n emit2_instr (out, ind, ins); emit_newline (out)\n) (* end of [emit2_instr_newline] *)\n\n(* ****** ****** *)\n\nimplement\nemit2_instrlst\n(\n out, ind, inss\n) = (\n\/\/\ncase+ inss of\n| list_nil () => ()\n| list_cons\n (ins, inss) => let\n val () = emit2_instr (out, ind, ins)\n in\n emit_ENDL (out); emit2_instrlst (out, ind, inss)\n end \/\/ end of [list_cons]\n\/\/\n) (* end of [emit2_instrlst] *)\n\n(* ****** ****** *)\n\nimplement\nemit2_ATSfunbodyseq\n (out, ind, ins) = let\n\/\/\nval-ATSfunbodyseq (inss) = ins.instr_node\n\/\/\nin\n emit2_instrlst (out, ind, inss)\nend \/\/ end of [emit2_ATS2funbodyseq]\n\n(* ****** ****** *)\n\nimplement\nemit2_ATSINSmove_con1\n (out, ind, ins0) = let\n\/\/\nfun\ngetarglst\n(\n inss: instrlst\n) : d0explst =\n(\ncase+ inss of\n| list_nil () => list_nil ()\n| list_cons (ins, inss) => let\n val-ATSINSstore_con1_ofs (_, _, _, d0e) = ins.instr_node\n val d0es = getarglst (inss)\n in\n list_cons (d0e, d0es)\n end \/\/ end of [list_cons]\n)\n\/\/\nval-ATSINSmove_con1 (inss) = ins0.instr_node\n\/\/\nval-list_cons (ins, inss) = inss\nval-ATSINSmove_con1_new (tmp, _) = ins.instr_node \n\/\/\nvar opt: tokenopt = None()\n\/\/\nval inss =\n(\ncase+ inss of\n| list_nil () => inss\n| list_cons (ins, inss2) =>\n (\n case+ ins.instr_node of\n | ATSINSstore_con1_tag\n (tmp, tag) => let\n val () = opt := Some(tag) in inss2\n end \/\/ end of [ATSINSstore_con1_tag]\n | _ (*non-ATSINSstore_con1_tag*) => inss\n )\n) : instrlst\n\/\/\nval d0es = getarglst (inss)\nval () = emit_nspc (out, ind)\nval () = emit_tmpvar (out, tmp)\nval () = emit_text (out, \" = \")\nval () = emit_LPAREN (out)\nval () =\n(\ncase+ opt of\n| None () => ()\n| Some (tag) => emit_PMVint (out, tag)\n) : void \/\/ end of [val]\nval () =\n(\ncase+ opt of\n| None _ => emit_d0explst (out, d0es)\n| Some _ => emit_d0explst_1 (out, d0es)\n) : void \/\/ end of [val]\n\/\/\nval ntup =\n(\ncase+ opt of\n| None _ => list_length(d0es)\n| Some _ => list_length(d0es) + 1\n) : int (* end of [val] *)\n\/\/\nval () =\nif ntup = 1\n then emit_text(out, \", )\") else emit_RPAREN(out)\n\/\/ end of [if]\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit2_ATSINSmove_con1]\n\n(* ****** ****** *)\n\nimplement\nemit2_ATSINSmove_boxrec\n (out, ind, ins0) = let\n\/\/\nfun\ngetarglst\n(\n inss: instrlst\n) : d0explst =\n(\ncase+ inss of\n\/\/\n| list_nil() => list_nil ()\n\/\/\n| list_cons(ins, inss) => let\n val-ATSINSstore_boxrec_ofs(_, _, _, d0e) = ins.instr_node\n val d0es = getarglst(inss)\n in\n list_cons (d0e, d0es)\n end \/\/ end of [list_cons]\n\/\/\n) (* end of [getarglst] *)\n\/\/\nval-\nATSINSmove_boxrec(inss) = ins0.instr_node\n\/\/\nval-\nlist_cons(ins, inss) = inss\nval-\nATSINSmove_boxrec_new(tmp, _) = ins.instr_node \n\/\/\nval d0es = getarglst (inss)\n\/\/\nval () = emit_nspc (out, ind)\nval () = emit_tmpvar (out, tmp)\nval () = emit_text (out, \" = \")\nval () = emit_LPAREN (out)\nval () = emit_d0explst (out, d0es)\n\/\/\nval () =\n(\nif list_is_sing(d0es)\n then emit_text(out, \", )\") else emit_RPAREN (out)\n\/\/ end of [if]\n) (* end of [val] *)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit2_ATSINSmove_boxrec]\n\n(* ****** ****** *)\n\nimplement\nemit2_ATSINSmove_delay\n (out, ind, ins0) = let\n\/\/\nval-ATSINSmove_delay(tmp, s0e, thunk) = ins0.instr_node\n\/\/\nval () =\n emit_nspc(out, ind)\nval () =\n emit_tmpvar(out, tmp)\n\/\/\nval () = emit_text(out, \" = [\")\n\/\/\nval () = (\n emit_int(out, 0); emit_text(out, \", \"); emit_d0exp(out, thunk)\n) (* end of [val] *)\nval ((*closing*)) = emit_text(out, \"]\")\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit2_ATSINSmove_delay]\n\n(* ****** ****** *)\n\nimplement\nemit2_ATSINSmove_lazyeval\n (out, ind, ins0) = let\n\/\/\nval-\nATSINSmove_lazyeval\n (tmp, s0e, lazyval) = ins0.instr_node\n\/\/\nval () = emit_nspc(out, ind)\n\/\/\nval () =\n(\n emit_tmpvar(out, tmp); emit_text(out, \" = \")\n) (* end of [val] *)\nval () =\n(\n emit_text(out, \"ATSPMVlazyval_eval(\");\n emit_d0exp(out, lazyval); emit_text(out, \"); \")\n) (* end of [val] *)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit2_ATSINSmove_lazyeval]\n\n(* ****** ****** *)\n\nimplement\nemit2_ATSINSmove_ldelay\n (out, ind, ins0) = let\n\/\/\nval-\nATSINSmove_ldelay\n (tmp, s0e, thunk) = ins0.instr_node\n\/\/\nval () = emit_nspc (out, ind)\n\/\/\nval () =\n(\n emit_tmpvar(out, tmp); emit_text(out, \" = \"); emit_d0exp(out, thunk)\n) (* end of [val] *)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit2_ATSINSmove_ldelay]\n\n(* ****** ****** *)\n\nimplement\nemit2_ATSINSmove_llazyeval\n (out, ind, ins0) = let\n\/\/\nval-\nATSINSmove_llazyeval\n (tmp, s0e, lazyval) = ins0.instr_node\n\/\/\nval () =\n emit_nspc(out, ind)\n\/\/\nval () =\n(\n emit_tmpvar(out, tmp); emit_text(out, \" = \")\n) (* end of [val] *)\n\/\/\nval () =\n(\n emit_text(out, \"ATSPMVllazyval_eval(\");\n emit_d0exp (out, lazyval); emit_text (out, \")\")\n) (* end of [val] *)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit2_ATSINSmove_llazyeval]\n\n(* ****** ****** *)\n\/\/\n#define\nATSEXTCODE_BEG \"######\\n#ATSextcode_beg()\\n######\"\n#define\nATSEXTCODE_END \"######\\n#ATSextcode_end()\\n######\"\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_d0ecl\n (out, d0c0) = let\nin\n\/\/\ncase+\nd0c0.d0ecl_node of\n\/\/\n| D0Cinclude _ => ()\n\/\/\n| D0Cifdef _ => ()\n| D0Cifndef _ => ()\n\/\/\n| D0Ctypedef (id, def) =>\n typedef_insert (id.i0dex_sym, def)\n\/\/\n| D0Cassume (id) =>\n {\n val () = emit_ENDL (out)\n val () =\n emit_text (out, \"#ATSassume(\")\n val () = (\n emit_i0de (out, id); emit_text (out, \")\\n\")\n ) (* end of [val] *)\n }\n\/\/\n| D0Cdyncst_mac _ => ()\n| D0Cdyncst_extfun _ => ()\n| D0Cdyncst_valdec _ => ()\n| D0Cdyncst_valimp _ => ()\n\/\/\n| D0Cstatmp\n (tmp, opt) =>\n {\n val () = emit_ENDL (out)\n val () = the_statmpdeclst_insert (d0c0)\n val () = (\n case+ opt of\n | Some _ => () | None () => emit_text(out, \"#\")\n ) (* end of [val] *)\n val () = (\n emit_tmpvar (out, tmp); emit_text (out, \" = None\\n\")\n ) (* end of [val] *)\n } (* end of [D0Cstatmp] *)\n\/\/\n| D0Cextcode (toks) =>\n {\n val () = emit_ENDL (out)\n val () =\n emit_text (out, ATSEXTCODE_BEG)\n val () = emit_extcode (out, toks) \/\/ HX: verbatim output\n val () =\n emit_text (out, ATSEXTCODE_END)\n val ((*void*)) = emit_newline (out)\n } (* end of [D0Cextcode] *)\n\/\/\n| D0Cfundecl\n (fk, f0d) => emit_f0decl (out, f0d)\n\/\/\n| D0Cclosurerize\n (\n fl, env, arg, res\n ) => emit_closurerize (out, fl, env, arg, res)\n\/\/\n| D0Cdynloadflag_init\n (flag) => (\n\/\/\n\/\/ HX-2015-05-22:\n\/\/ it is skipped as Python does not have a link-time!\n\/\/ \n ) (* end of [D0Cdynloadflag_init] *)\n| D0Cdynloadflag_minit\n (flag) => {\n val () = emit_ENDL (out)\n val () = (\n emit_tmpvar (out, flag); emit_text (out, \" = 0\\n\")\n ) (* end of [val] *)\n } (* end of [D0Cdynloadflag_minit] *)\n\/\/\n| D0Cdynexn_dec(idexn) =>\n (\n emit_text(out, \"## dynexn_dec(\"); emit_i0de(out, idexn); emit_text(out, \")\\n\")\n ) (* end of [D0Cdynexn_dec] *)\n| D0Cdynexn_extdec(idexn) =>\n (\n emit_text(out, \"## dynexn_extdec(\"); emit_i0de(out, idexn); emit_text(out, \")\\n\")\n ) (* end of [D0Cdynexn_extdec] *)\n| D0Cdynexn_initize(idexn, fullname) =>\n (\n emit_text(out, \"## dynexn_initize(\"); emit_i0de(out, idexn); emit_text(out, \")\\n\")\n ) (* end of [D0Cdynexn_initize] *)\n\/\/\nend \/\/ end of [emit_d0ecl]\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit2_tmpdec\n(out: FILEref, ind: int, td: tmpdec) : void\nextern\nfun\nemit2_tmpdeclst\n(out: FILEref, ind: int, tds: tmpdeclst) : void\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_tmpdec\n (out, td) = emit2_tmpdec(out, 0(*ind*), td)\n\/\/\nimplement\nemit2_tmpdec\n (out, ind, td) = let\nin\n\/\/\ncase+\ntd.tmpdec_node of\n\/\/\n| TMPDECnone(tmp) =>\n {\n val () = emit_nspc(out, ind)\n val () = (emit_SHARP(out); emit_tmpvar(out, tmp))\n }\n| TMPDECsome(tmp, s0e) =>\n {\n val () = emit_nspc(out, ind)\n val () = (emit_tmpvar(out, tmp); emit_text(out, \" = None\"))\n }\nend \/\/ end of [emit2_tmpdec]\n\/\/\n(* ****** ****** *)\n\nimplement\nemit2_tmpdeclst\n(\n out, ind, tds\n) = (\n\/\/\ncase+ tds of\n| list_nil() => ()\n| list_cons(td, tds) =>\n {\n val () =\n (\n emit2_tmpdec\n (\n out, ind, td\n ) ; emit_ENDL(out)\n )\n val () = emit2_tmpdeclst(out, ind, tds)\n }\n\/\/\n) (* end of [emit2_tmpdeclst] *)\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit_branchseq\n (out: FILEref, ins0: instr): void\nextern\nfun\nemit_branchseqlst\n (out: FILEref, inss: instrlst): void\n\/\/\nextern\nfun\nemit_fundef_nonlocal(out: FILEref): void\n\/\/\n(* ****** ****** *)\n\nlocal\n\nfun\nauxlst\n(\n out: FILEref, inss: instrlst\n) : void = let\n\/\/\nval inss =\ninstrlst_skip_linepragma(inss)\n\/\/\nval-list_cons(ins, inss) = inss\nval-ATSINSlab(lab) = ins.instr_node\n\/\/\nval () = emit_nspc(out, 2)\nval () = emit_text(out, \"def\")\nval () = emit_SPACE(out)\nval () = emit_label(out, lab)\nval () = emit_text(out, \"():\\n\")\n\/\/\nval () = emit_fundef_nonlocal (out)\n\/\/\nval () = emit_nspc(out, 4)\nval () = emit_text(out, \"tmplab_py = 0\\n\")\n\/\/\nin\n auxlst2( out, lab, inss )\nend (* end of [auxlst] *)\n\nand\nauxlst2\n(\n out: FILEref, lab: label, inss: instrlst\n) : void = let\nin\n\/\/\ncase+ inss of\n\/\/\n| list_nil\n ((*none*)) =>\n {\n val () = emit_nspc(out, 4)\n val () = emit_text(out, \"return\\n\") \n } (* end of [list_nil] *)\n\/\/\n| list_cons\n (ins1, inss2) =>\n (\n case+\n ins1.instr_node\n of (* case+ *)\n | ATSINSlab(lab) =>\n auxlst(out, inss) where\n {\n\/\/\n val () = emit_nspc(out, 4)\n val () = emit_label(out, lab)\n val () = emit_text(out, \"()\\n\")\n val () = emit_nspc(out, 4)\n val () = emit_text(out, \"return\\n\")\n\/\/\n } (* ATSINSlab *)\n | _ (*non-ATSINSlab*) =>\n auxlst2(out, lab, inss2) where\n {\n val () =\n (\n emit2_instr(out, 4, ins1); emit_ENDL(out)\n ) (* end of [val] *)\n } (* end of [non-ATSINSlab] *)\n ) (* end of [list_cons] *)\n\/\/\nend \/\/ (* end of [auxlst2] *)\n\nin (* in-of-local *)\n\nimplement\nemit_branchseq\n (out, ins0) = let\n\/\/\nval-ATSbranchseq (inss) = ins0.instr_node\n\/\/\nin\n auxlst (out, inss)\nend \/\/ end of [emit_branchseq]\n\nend \/\/ end of [local]\n\n(* ****** ****** *)\n\nfun\nemit_branchseqlst\n(\n out: FILEref, inss: instrlst\n) : void =\n(\ncase+ inss of\n| list_nil() => ()\n| list_cons(ins, inss) =>\n {\n val () = emit_branchseq(out, ins)\n val () = emit_branchseqlst(out, inss)\n }\n) (* end of [emit_branchseqlst] *)\n\n(* ****** ****** *)\n\nimplement\nemit_fundef_nonlocal\n (out) = () where\n{\n\/\/\nval f0as = the_f0arglst_get()\nval () = emit_f0arglst_nonlocal(out, f0as)\n\/\/\nval tmpdecs = the_tmpdeclst_get()\nval () = emit_tmpdeclst_nonlocal(out, tmpdecs)\n\/\/\nval () =\nemit_nspc(out, 4(*ind*))\nval () =\nemit_text(out, \"nonlocal funlab_py, tmplab_py\\n\")\n\/\/\nval inss_caseof = the_caseofseqlst_get()\nval () = emit_mbranchlst_nonlocal(out, inss_caseof)\n\/\/\n} \/\/ end of [emit_fundef_nonlocal]\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit_caseofseq\n (out: FILEref, ins0: instr): void\nextern\nfun\nemit_caseofseqlst\n (out: FILEref, inss: instrlst): void\n\/\/\n(* ****** ****** *)\n\nfun\nemit_caseofseq\n(\n out: FILEref, ins0: instr\n) : void = let\n\/\/\nval-\nATScaseofseq(inss) = ins0.instr_node\n\/\/\nval tls = caseofseq_get_tmplablst(ins0)\nval ((*update*)) = the_branchlablst_set(tls)\n\/\/\nin\n emit_branchseqlst(out, inss)\nend \/\/ end of [emit_caseofseq]\n\n(* ****** ****** *)\n\nfun\nemit_caseofseqlst\n(\n out: FILEref, inss: instrlst\n) : void =\n(\ncase+ inss of\n| list_nil() => ()\n| list_cons(ins, inss) =>\n {\n val () = emit_caseofseq(out, ins)\n val () = emit_caseofseqlst(out, inss)\n }\n) (* end of [emit_caseofseqlst] *)\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit_f0arg : emit_type (f0arg)\nand\nemit_f0marg : emit_type (f0marg)\nand\nemit_f0head : emit_type (f0head)\n\/\/\nextern\nfun\nemit_f0body : emit_type (f0body)\nand\nemit_f0body_0 : emit_type (f0body)\nand\nemit_f0body_tlcal : emit_type (f0body)\nand\nemit_f0body_tlcal2 : emit_type (f0body)\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_f0arg\n (out, f0a) = let\nin\n\/\/\ncase+\nf0a.f0arg_node of\n\/\/\n| F0ARGnone _ => emit_text(out, \"__NONE__\")\n| F0ARGsome(arg, s0e) => emit_tmpvar(out, arg)\n\/\/\nend \/\/ end of [emit_f0arg]\n\n(* ****** ****** *)\n\nimplement\nemit_f0marg\n (out, f0ma) = let\n\/\/\nfun\nloop\n(\n out: FILEref, f0as: f0arglst, i: int\n) : void =\n(\ncase+ f0as of\n| list_nil() => ()\n| list_cons(f0a, f0as) => let\n val () =\n if i > 0 then emit_text(out, \", \")\n \/\/ end of [val]\n in\n emit_f0arg(out, f0a); loop(out, f0as, i+1)\n end \/\/ end of [list_cons]\n)\n\/\/\nin\n loop(out, f0ma.f0marg_node, 0)\nend \/\/ end of [emit_f0marg]\n\n(* ****** ****** *)\n\nimplement\nemit_f0head\n (out, fhd) = let\n\/\/\nval\nf0as =\nf0head_get_f0arglst(fhd)\n\/\/\nval () = the_f0arglst_set(f0as)\n\/\/\nin\n\/\/\ncase+\nfhd.f0head_node of\n| F0HEAD\n (fid, f0ma, res) =>\n {\n val () =\n emit_tmpvar(out, fid)\n\/\/\n val () = emit_LPAREN(out)\n val () = emit_f0marg(out, f0ma)\n val () = emit_RPAREN(out)\n\/\/\n val () = emit_text(out, \":\")\n\/\/\n } (* end of [F0HEAD] *)\n\/\/\nend \/\/ end of [emit_f0head]\n\n(* ****** ****** *)\n\nimplement\nemit_f0body\n (out, fbody) = let\n\/\/\nval knd = f0body_classify (fbody)\n(*\nval () = println! (\"emit_f0body: knd = \", knd)\n*)\n\/\/\nval tmpdecs =\n f0body_get_tmpdeclst(fbody)\nval inss_body =\n f0body_get_bdinstrlst(fbody)\nval inss_caseof =\n f0body_collect_caseof(fbody)\n\/\/\nval () = the_tmpdeclst_set(tmpdecs)\nval () = the_funbodylst_set(inss_body)\nval () = the_caseofseqlst_set(inss_caseof)\n\/\/\nval () = emit_tmpdeclst_initize(out, tmpdecs)\n\/\/\nval () = emit_nspc(out, 2(*ind*))\nval () = emit_text(out, \"funlab_py = None\\n\")\nval () = emit_nspc(out, 2(*ind*))\nval () = emit_text(out, \"tmplab_py = None\\n\")\n\/\/\nval () = emit_mbranchlst_initize(out, inss_caseof)\n\/\/\nval () = emit_caseofseqlst (out, inss_caseof)\nval () = emit_branchmaplst (out, inss_caseof)\n\/\/\nin\n\/\/\ncase+ knd of\n| 0 => emit_f0body_0(out, fbody)\n| 1 => emit_f0body_tlcal(out, fbody)\n| 2 => emit_f0body_tlcal2(out, fbody)\n| _ => let val () = assertloc(false) in (*nothing*) end\n\/\/\nend \/\/ end of [emit_f0body]\n\n(* ****** ****** *)\n\nimplement\nemit_f0body_0\n (out, fbody) = let\n\/\/\nfun\nauxlst\n(\n out: FILEref, inss: instrlst\n) : void =\n(\ncase+ inss of\n| list_nil () => ()\n| list_cons\n (ins0, inss1) => let\n\/\/\n val-list_cons(ins1, inss2) = inss1\n\/\/\n val () =\n emit2_ATSfunbodyseq(out, 2(*ind*), ins0)\n val () = emit2_instr_ln(out, 2(*ind*), ins1)\n\/\/\n in\n auxlst(out, inss2)\n end \/\/ end of [list_cons]\n\/\/\n) (* end of [auxlst] *)\n\/\/\nin\n\/\/\ncase+\nfbody.f0body_node of\n\/\/\n| F0BODY (tds, inss) => auxlst (out, inss)\n\/\/\nend \/\/ end of [emit_f0body_0]\n\n(* ****** ****** *)\n\nimplement\nemit_f0body_tlcal\n (out, fbody) = let\n\/\/\nfun\nauxlst\n(\n out: FILEref, inss: instrlst\n) : void =\n(\ncase+ inss of\n| list_nil() => ()\n| list_cons\n (ins0, inss1) => let\n\/\/\n val-\n list_cons(ins1, inss2) = inss1\n\/\/\n val () =\n emit2_ATSfunbodyseq(out, 4(*ind*), ins0)\n\/\/\n val () = emit_nspc(out, 4(*ind*))\n val () = emit_text(out, \"if (funlab_py == 0): break\\n\")\n val () = emit2_instr_ln(out, 2(*ind*), ins1)\n\/\/\n in\n auxlst (out, inss2)\n end \/\/ end of [list_cons]\n\/\/\n) (* end of [auxlst] *)\n\/\/\nval () = emit_nspc(out, 2(*ind*))\nval () = emit_text(out, \"while(1):\\n\")\nval () = emit_nspc(out, 4(*ind*))\nval () = emit_text(out, \"funlab_py = 0\\n\")\n\/\/\nval () =\n(\ncase+\nfbody.f0body_node\nof (* case+ *)\n\/\/\n| F0BODY(tds, inss) => auxlst(out, inss)\n\/\/\n)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit_f0body_tlcal]\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit_mfundef_initize\n(\nout: FILEref\n,\ninss: instrlst): void\n\/\/\nimplement\nemit_mfundef_initize\n (out, inss) = let\n\/\/\nfun auxlst\n(\n out: FILEref, xs: instrlst, i: int\n) : void =\n(\ncase+ xs of\n| list_nil() => ()\n| list_cons(x, xs) => let\n\/\/\n val fl =\n funbodyseq_get_funlab(x)\n\/\/\n val () =\n if i >= 2\n then emit_text(out, \", \")\n \/\/ end of [if]\n val () = emit_int(out, i)\n val () = emit_text(out, \": \")\n val () = emit_label(out, fl)\n\/\/ \n in\n let\n val-list_cons(_, xs) = xs in auxlst(out, xs, i+1)\n end \/\/ end of [let]\n end \/\/ end of [list_cons]\n)\n\/\/\nval () =\nemit_nspc(out, 2(*ind*))\nval () =\nemit_text(out, \"mfundef = { \")\n\/\/\nval () = auxlst (out, inss, 1)\nval () = emit_text (out, \" }\\n\")\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit_mfundef_initize]\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit_the_funbodylst\n(\nout: FILEref): void\n\/\/\nimplement\nemit_the_funbodylst\n (out) = let\n\/\/\nfun\nauxfun\n(\n out: FILEref, ins0: instr\n) : void = let\n\/\/\nval-\nATSfunbodyseq\n (inss) = ins0.instr_node\n\/\/\nval-list_cons(ins1, inss) = inss\nval-ATSINSflab(fl) = ins1.instr_node\n\/\/\nval () = emit_nspc(out, 2)\nval () = emit_text(out, \"def\")\nval () = emit_SPACE(out)\nval () = emit_label(out, fl)\nval () = emit_text(out, \"():\\n\")\n\/\/\nval () = emit_fundef_nonlocal(out)\n\/\/\nval () = emit_nspc(out, 4)\nval () = emit_text(out, \"funlab_py = 0\\n\")\nval () = emit2_instrlst(out, 4(*ind*), inss)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [auxfun]\n\/\/\nfun auxlst\n(\n out: FILEref, inss: instrlst\n) : void =\n(\ncase+ inss of\n| list_nil () => ()\n| list_cons _ => let\n\/\/\n val-\n list_cons(ins0, inss) = inss\n val-\n list_cons(ins1, inss) = inss\n\/\/\n val () = auxfun(out, ins0)\n val () = emit2_instr_newline(out, 4(*ind*), ins1)\n\/\/\n in\n auxlst(out, inss)\n end \/\/ end of [auxlst]\n) (* end of [auxlst] *)\n\/\/\nval inss_body = the_funbodylst_get()\n\/\/\nval () = auxlst(out, inss_body)\nval () = emit_mfundef_initize(out, inss_body)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit_the_funbodylst]\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_f0body_tlcal2\n (out, fbody) = let\n\/\/\nval () = emit_nspc(out, 2(*ind*))\nval () = emit_text(out, \"tmpret_py = None\\n\")\n\/\/\nval () = emit_the_funbodylst(out)\n\/\/\nval () = emit_nspc(out, 2(*ind*))\nval () = emit_text(out, \"funlab_py = 1\\n\")\nval () = emit_nspc(out, 2(*ind*))\nval () = emit_text(out, \"while(1):\\n\")\nval () = emit_nspc(out, 4(*ind*))\nval () = emit_text(out, \"tmpret_py = mfundef.get(funlab_py)()\\n\")\nval () = emit_nspc(out, 4(*ind*))\nval () = emit_text(out, \"if (funlab_py == 0): break\\n\")\nval () = emit_nspc(out, 2(*ind*))\nval () = emit_text(out, \"return tmpret_py\\n\")\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit_f0body_tlcal2]\n\n(* ****** ****** *)\n\nimplement\nemit_f0decl\n (out, fdec) = let\nin\n\/\/\ncase+\nfdec.f0decl_node\nof (* case+ *)\n| F0DECLnone\n (fhd) => () \n \/\/ F0DECLnone\n| F0DECLsome\n (fhd, fbody) =>\n {\n val () = emit_ENDL (out)\n val () = emit_text (out, \"def\")\n val () = emit_SPACE (out)\n val () = emit_f0head (out, fhd)\n val () = emit_ENDL (out)\n val () = emit_f0body (out, fbody)\n val () = emit_newline (out)\n } (* end of [F0DECLsome] *)\n\/\/\nend \/\/ end of [emit_f0decl]\n\n(* ****** ****** *)\n\nimplement\nemit_toplevel\n (out, d0cs) = let\n\/\/\nfun\nloop\n(\n out: FILEref, d0cs: d0eclist\n) : void =\n(\n\/\/\ncase+ d0cs of\n| list_nil\n ((*void*)) => ()\n \/\/ list_nil\n| list_cons\n (d0c, d0cs) => let\n val () =\n emit_d0ecl (out, d0c)\n \/\/ end of [val]\n in\n loop(out, d0cs)\n end \/\/ end of [list_cons]\n\/\/\n) (* end of [loop] *)\n\/\/\nin\n loop(out, d0cs)\nend \/\/ end of [emit_toplevel]\n\n(* ****** ****** *)\n\n(* end of [atscc2py3_emit2.dats] *)\n","old_contents":"(* ****** ****** *)\n\/\/\n\/\/ Atscc2py3:\n\/\/ from ATS to Python3\n\/\/\n(* ****** ****** *)\n\/\/\n\/\/ HX-2014-08-04: start\n\/\/ HX-2015-05-23: restructure\n\/\/\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_staload.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\nUN = \"prelude\/SATS\/unsafe.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\n#if\ndefined\n(\nCATSPARSEMIT_targetloc\n)\n#then\n#else\n\/\/\n#define\nCATSPARSEMIT_targetloc\n\".\/..\/CATS-parsemit\"\n\/\/\n#endif \/\/ end of [ifdef]\n\/\/\n(* ****** ****** *)\n\/\/\n#staload\n\"{$CATSPARSEMIT}\/SATS\/catsparse.sats\"\n#staload\n\"{$CATSPARSEMIT}\/SATS\/catsparse_emit.sats\"\n#staload\n\"{$CATSPARSEMIT}\/SATS\/catsparse_syntax.sats\"\n#staload\n\"{$CATSPARSEMIT}\/SATS\/catsparse_typedef.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_statmpdeclst_get(): d0eclist\nextern\nfun\nthe_statmpdeclst_insert(d0ecl): void\n\/\/\n(* ****** ****** *)\n\nlocal\n\/\/\nval the_statmps =\n ref (list_nil(*void*))\n\/\/\nin (* in-of-local *)\n\/\/\nimplement\nthe_statmpdeclst_get() =\n list_vt2t(list_reverse(!the_statmps))\n\/\/\nimplement\nthe_statmpdeclst_insert(d0c) = let\n val d0cs = !the_statmps in !the_statmps := list_cons (d0c, d0cs)\nend \/\/ end of [the_statmpdeclst_insert]\n\/\/\nend \/\/ end of [local]\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit_the_statmpdeclst\n(\nout: FILEref, ind: int\n) : void \/\/ end-of-fun\n\/\/\nimplement\nemit_the_statmpdeclst\n (out, ind) = let\n\/\/\nfun auxlst\n(\n out: FILEref, xs: d0eclist\n) : void =\n(\ncase+ xs of\n| list_nil () => ()\n| list_cons (x, xs) => let\n val-\n D0Cstatmp\n (tmp, opt) = x.d0ecl_node\n \/\/ end of [val]\n in\n case+ opt of\n | None _ =>\n (\n auxlst(out, xs)\n ) (* None *)\n | Some _ => let\n val () = emit_ENDL(out)\n val () = emit_nspc(out, ind)\n val () =\n (\n emit_text(out, \"global \"); emit_tmpvar(out, tmp)\n ) (* end of [val] *)\n in\n auxlst (out, xs)\n end \/\/ end of [Some]\n end \/\/ end of [list_cons]\n) (* end of [auxlst] *)\n\/\/\nin\n auxlst (out, the_statmpdeclst_get())\nend \/\/ end of [emit_the_statmpdeclst]\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit_f0arglst_nonlocal\n(\nout: FILEref\n,\nf0as: f0arglst ): void\n\/\/\nimplement\nemit_f0arglst_nonlocal\n (out, f0as) = let\n\/\/\nfun\nauxlst\n(\n out: FILEref, f0as: f0arglst, i: int\n) : void =\n(\ncase+ f0as of\n| list_nil() => ()\n| list_cons(f0a, f0as) =>\n (\n case-\n f0a.f0arg_node\n of (* case- *)\n | F0ARGsome (arg, _) => let\n val () =\n if i > 0\n then emit_text (out, \", \")\n \/\/ end of [if]\n val () = emit_tmpvar (out, arg)\n in\n auxlst (out, f0as, i+1)\n end \/\/ end of [F0ARGsome]\n ) (* end of [list_cons] *)\n)\n\/\/\nin\n\/\/\ncase+ f0as of\n| list_nil() =>\n {\n \/\/ nothing\n } (* list_nil *)\n| list_cons _ =>\n {\n val () =\n emit_nspc (out, 4(*ind*))\n val () =\n emit_text (out, \"nonlocal \")\n val () = auxlst (out, f0as, 0(*i*))\n val () = emit_ENDL (out)\n } (* list_cons *)\n\/\/\nend \/\/ end of [emit_f0arglst_nonlocal]\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit_tmpdeclst_initize\n (out: FILEref, tds: tmpdeclst): void\n\/\/\nimplement\nemit_tmpdeclst_initize\n (out, tds) = let\n\/\/\nfun auxlst\n(\n out: FILEref, tds: tmpdeclst\n) : void =\n(\ncase+ tds of\n| list_nil () => ()\n| list_cons (td, tds) =>\n (\n case+\n td.tmpdec_node\n of (* case+ *)\n | TMPDECnone\n (tmp) => auxlst (out, tds)\n \/\/ end of [TMPDECnone]\n | TMPDECsome\n (tmp, _) => let\n val () = emit_nspc (out, 2(*ind*))\n val () = emit_tmpvar (out, tmp)\n val () = emit_text (out, \" = None\\n\")\n in\n auxlst (out, tds)\n end \/\/ end of [TMPDECsome]\n ) (* end of [list_cons] *)\n)\n\/\/\nin\n auxlst (out, tds)\nend \/\/ end of [emit_tmpdeclst_initize]\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit_tmpdeclst_nonlocal\n (out: FILEref, tds: tmpdeclst): void\n\/\/\nimplement\nemit_tmpdeclst_nonlocal\n (out, tds) = let\n\/\/\nfun auxlst\n(\n out: FILEref, tds: tmpdeclst, i: int\n) : void =\n(\ncase+ tds of\n| list_nil () => ()\n| list_cons (td, tds) =>\n (\n case+\n td.tmpdec_node\n of (* case+ *)\n | TMPDECnone\n (tmp) =>\n (\n auxlst(out, tds, i)\n ) (* TMPDECnone *)\n | TMPDECsome\n (tmp, _) => let\n val () =\n if i > 0 then\n emit_text (out, \", \")\n \/\/ end of [if]\n val () = emit_tmpvar (out, tmp)\n in\n auxlst (out, tds, i+1)\n end \/\/ end of [TMPDECsome]\n ) (* end of [list_cons] *)\n)\n\/\/\nin\n\/\/\ncase+ tds of\n| list_nil () => ()\n| list_cons _ =>\n {\n val () =\n emit_nspc (out, 4(*ind*))\n val () =\n emit_text (out, \"nonlocal\")\n val () = emit_SPACE (out)\n val () = auxlst (out, tds, 0)\n val () = emit_newline (out)\n } (* end of [list_cons] *)\n\/\/\nend \/\/ end of [emit_tmpdeclst_nonlocal]\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit_mbranchlst_initize\n(out: FILEref, inss: instrlst): void\n\/\/\nimplement\nemit_mbranchlst_initize\n (out, inss) = let\n\/\/\nfun auxlst\n(\n out: FILEref, inss: instrlst, i: int\n) : void =\n(\n\/\/\ncase+ inss of\n| list_nil() => ()\n| list_cons(_, inss) =>\n {\n val () =\n emit_nspc (out, 2(*ind*))\n \/\/ end of [val]\n val () =\n (\n emit_text (out, \"mbranch_\");\n emit_int (out, i); emit_text (out, \" = None\\n\")\n )\n val () = auxlst (out, inss, i+1)\n } (* end of [list_cons] *)\n\/\/\n) (* end of [auxlst] *)\n\/\/\nin\n auxlst (out, inss, 1(*i*))\nend \/\/ end of [emit_mbranchlst_initize]\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit_mbranchlst_nonlocal\n (out: FILEref, inss: instrlst): void\n\/\/\nimplement\nemit_mbranchlst_nonlocal\n (out, inss) = let\n\/\/\nfun auxlst\n(\n out: FILEref, inss: instrlst, i: int\n) : void =\n(\ncase+ inss of\n| list_nil() => ()\n| list_cons(_, inss) => let\n val () =\n if i >= 2 then emit_text (out, \", \")\n val () =\n (\n emit_text (out, \"mbranch_\"); emit_int (out, i)\n ) (* end of [val] *)\n in\n auxlst (out, inss, i+1)\n end \/\/ end of [list_cons]\n\/\/\n) (* end of [auxlst] *)\n\/\/\nin\n\/\/\ncase+ inss of\n| list_nil () => ()\n| list_cons _ =>\n {\n val () =\n emit_nspc (out, 4(*ind*))\n val () =\n emit_text (out, \"nonlocal \")\n val () = auxlst (out, inss, 1(*i*))\n val () = emit_ENDL (out)\n } (* end of [list_cons] *)\n\/\/\nend \/\/ end of [emit_mbranchlst_nonlocal]\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nfunlab_get_index (fl: label): int\nextern\nfun\ntmplab_get_index (lab: label): int\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_f0arglst_get (): f0arglst\nextern\nfun\nthe_f0arglst_set (f0as: f0arglst): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_tmpdeclst_get (): tmpdeclst\nextern\nfun\nthe_tmpdeclst_set (tds: tmpdeclst): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_funbodylst_get (): instrlst\nextern\nfun\nthe_funbodylst_set (inss: instrlst): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_branchlablst_get (): labelist\nextern\nfun\nthe_branchlablst_set (tls: labelist): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_caseofseqlst_get (): instrlst\nextern\nfun\nthe_caseofseqlst_set (inss: instrlst): void\n\/\/\n(* ****** ****** *)\n\nlocal\n\/\/\nval the_f0arglst = ref (list_nil)\nval the_tmpdeclst = ref (list_nil)\n\/\/\nval the_funbodylst = ref (list_nil)\n\/\/\nval the_branchlablst = ref (list_nil)\nval the_caseofseqlst = ref (list_nil)\n\/\/\nin (* in-of-local *)\n\nimplement\nthe_f0arglst_get () = !the_f0arglst\nimplement\nthe_f0arglst_set (xs) = !the_f0arglst := xs\n\nimplement\nthe_tmpdeclst_get () = !the_tmpdeclst\nimplement\nthe_tmpdeclst_set (xs) = !the_tmpdeclst := xs\n\nimplement\nthe_funbodylst_get () = !the_funbodylst\nimplement\nthe_funbodylst_set (xs) = !the_funbodylst := xs\n\nimplement\nthe_branchlablst_get () = !the_branchlablst\nimplement\nthe_branchlablst_set (tls) = !the_branchlablst := tls\n\nimplement\nthe_caseofseqlst_get () = !the_caseofseqlst\nimplement\nthe_caseofseqlst_set (xs) = !the_caseofseqlst := xs\n\nend \/\/ end of [local]\n\n(* ****** ****** *)\n\nimplement\nfunlab_get_index\n (fl0) = let\n\/\/\nval n0 = fl0.i0dex_sym\n\/\/\nfun\nauxlst\n(\n xs: instrlst, i: int\n) : int = (\n\/\/\ncase+ xs of\n| list_nil () => ~1(*error*)\n| list_cons (x, xs) =>\n (\n case+ x.instr_node of\n | ATSfunbodyseq _ => let\n val fl = funbodyseq_get_funlab (x)\n in\n if n0 = fl.i0dex_sym then i else auxlst (xs, i+1)\n end \/\/ end of [ATSfunbodyseq]\n | _ (*non-ATSfunbody*) => auxlst (xs, i)\n ) (* end of [list_cons] *)\n\/\/\n) (* end of [auxlst] *)\n\/\/\nin\n auxlst (the_funbodylst_get(), 1)\nend \/\/ end of [funlab_get_index]\n\n(* ****** ****** *)\n\nimplement\ntmplab_get_index\n (lab0) = let\n\/\/\nval n0 = lab0.i0dex_sym\n\/\/\nfun\nauxlst\n(\n xs: labelist, i: int\n) : int =\n(\ncase+ xs of\n| list_nil () => ~1(*error*)\n| list_cons (x, xs) =>\n if n0 = x.i0dex_sym then i else auxlst (xs, i+1)\n \/\/ end of [list_cons]\n)\n\/\/\nin\n\/\/\nauxlst(the_branchlablst_get(), 1)\n\/\/\nend \/\/ end of [tmplab_get_index]\n\n(* ****** ****** *)\n\/\/\nfun\nemit_funlab_index\n (out: FILEref, fl: label): void =\n emit_int(out, funlab_get_index(fl))\n\/\/\nfun\nemit_tmplab_index\n (out: FILEref, lab: label): void =\n emit_int(out, tmplab_get_index(lab))\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nbranchmap_get_index\n (ins: instr): int\n\/\/\nimplement\nbranchmap_get_index\n (x0) = let\n\/\/\nval p0 = $UN.cast2ptr(x0)\n\/\/\nfun auxlst\n(\n xs: instrlst, i: int\n) : int =\n(\ncase xs of\n| list_nil() => ~1(*error*)\n| list_cons(x, xs) =>\n if $UN.cast2ptr(x) = p0 then i else auxlst (xs, i+1)\n \/\/ end of [list_cons]\n)\n\/\/\nin\n auxlst(the_caseofseqlst_get(), 1)\nend \/\/ end of [branchmap_get_index]\n\n(* ****** ****** *)\n\/\/\nfun\nemit_branchmap_index\n (out: FILEref, ins: instr): void =\n emit_int (out, branchmap_get_index(ins))\n\/\/\n(* ****** ****** *)\n\/\/\nfun\nemit_branchmap\n(\n out: FILEref, ins0: instr\n) : void = let\n\/\/\nfun auxlst\n(\n out: FILEref, xs: instrlst, i: int\n) : int =\n(\ncase+ xs of\n| list_nil() => i\n| list_cons(x, xs) =>\n (\n case+ x.instr_node of\n | ATSINSlab (lab) => let\n val ((*void*)) =\n if i >= 2 then emit_text(out, \", \")\n \/\/ end of [val]\n val () = emit_int (out, i)\n val () = emit_text (out, \": \")\n val () = emit_label (out, lab)\n in\n auxlst (out, xs, i+1)\n end \/\/ end of [ATSINSlab]\n | _(*non-ATSINSlab*) => auxlst (out, xs, i)\n ) (* list_cons *)\n) (* end of [auxlst] *)\n\/\/\nfun auxlst2\n(\n out: FILEref, xs: instrlst, i: int\n) : void =\n(\ncase+ xs of\n| list_nil() => ()\n| list_cons(x, xs) => let\n val-ATSbranchseq(inss) = x.instr_node\n in\n auxlst2 (out, xs, auxlst (out, inss, i))\n end \/\/ end of [list_cons]\n) (* end of [auxlst2] *)\n\/\/\nval-ATScaseofseq(inss) = ins0.instr_node\n\/\/\nval () = emit_nspc (out, 2(*ind*))\nval () = emit_text (out, \"mbranch_\")\nval () = emit_branchmap_index (out, ins0)\nval () = emit_text (out, \" = \")\nval ((*opening*)) = emit_text (out, \"{ \")\nval () = auxlst2 (out, inss, 1(*first*))\nval ((*closing*)) = emit_text (out, \" }\\n\")\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit_branchmap]\n\/\/\n(* ****** ****** *)\n\nfun\nemit_branchmaplst\n(\n out: FILEref, inss: instrlst\n) : void =\n(\ncase+ inss of\n| list_nil () => ()\n| list_cons (ins, inss) =>\n {\n val () = emit_branchmap (out, ins)\n val () = emit_branchmaplst (out, inss)\n }\n) (* end of [emit_branchmaplst] *)\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nf0body_collect_caseof\n (fbody: f0body): instrlst(*list-of-caseofseq*)\n\/\/\nextern\nfun\ninstrlst_collect_caseof\n (inss: instrlst): instrlst(*list-of-caseofseq*)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nf0body_collect_caseof\n (fbody) = let\nin\n\/\/\ncase+\nfbody.f0body_node\nof \/\/ case+\n| F0BODY(tds, inss) => instrlst_collect_caseof(inss)\n\/\/\nend \/\/ end of [f0body_collect_caseof]\n\/\/\nimplement\ninstrlst_collect_caseof\n (inss) = let\n\/\/\nvtypedef res = instrlst_vt\n\/\/\nfun\naux\n(\n ins: instr, res: res\n) : res =\n(\ncase+\nins.instr_node of\n\/\/\n| ATScaseofseq\n (inss) => (\n auxlst(inss, cons_vt(ins, res))\n ) (* end of [ATScaseofseq] *)\n| ATSbranchseq(inss) => auxlst(inss, res)\n\/\/\n| ATSif (\n d0e, inss, inssopt\n ) => let\n val res = auxlst(inss, res)\n in\n case+ inssopt of\n | None((*void*)) => res | Some(inss) => auxlst(inss, res)\n end \/\/ end of [ATSif]\n\/\/\n| ATSifthen(d0e, inss) => auxlst(inss, res)\n| ATSifnthen(d0e, inss) => auxlst(inss, res)\n\/\/\n| ATSfunbodyseq(inss) => auxlst(inss, res)\n\/\/\n| _ (*rest-of-instr*) => res\n\/\/\n) (* end of [aux] *)\n\/\/\nand\nauxlst\n(\n inss: instrlst, res: res\n) : res =\n(\ncase+ inss of\n| list_cons\n (ins, inss) => let\n val res = aux (ins, res) in auxlst (inss, res)\n end \/\/ end of [list_cons]\n| list_nil ((*void*)) => res\n)\n\/\/\nval res = auxlst(inss, list_vt_nil)\n\/\/\nin\n list_vt2t(list_vt_reverse(res))\nend \/\/ end of [instrlst_collect_caseof]\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun emit2_instr\n (out: FILEref, ind: int, ins: instr) : void\nextern\nfun emit2_instr_ln\n (out: FILEref, ind: int, ins: instr) : void\nextern\nfun emit2_instr_newline\n (out: FILEref, ind: int, ins: instr) : void\nextern\nfun emit2_instrlst\n (out: FILEref, ind: int, inss: instrlst) : void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun emit2_ATSfunbodyseq\n (out: FILEref, ind: int, ins: instr) : void\n\/\/\nextern\nfun emit2_ATSINSmove_con1\n (out: FILEref, ind: int, ins: instr) : void\n\/\/\nextern\nfun emit2_ATSINSmove_boxrec\n (out: FILEref, ind: int, ins: instr) : void\n\/\/\nextern\nfun emit2_ATSINSmove_delay\n (out: FILEref, ind: int, ins: instr) : void\nextern\nfun emit2_ATSINSmove_lazyeval\n (out: FILEref, ind: int, ins: instr) : void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun emit2_ATSINSmove_ldelay\n (out: FILEref, ind: int, ins: instr) : void\nextern\nfun emit2_ATSINSmove_llazyeval\n (out: FILEref, ind: int, ins: instr) : void\n\/\/\n(* ****** ****** *)\n\/\/\n\/\/ HX-2014-08:\n\/\/ this one should not be used for\n\/\/ emitting multiple-line instructions\n\/\/\nimplement\nemit_instr\n (out, ins) = emit2_instr (out, 0(*ind*), ins)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nemit2_instr\n (out, ind, ins0) = let\nin\n\/\/\ncase+\nins0.instr_node of\n\/\/\n| ATSif\n (\n d0e, inss, inssopt\n ) =>\n {\n\/\/\n val () = emit_nspc (out, ind)\n\/\/\n val () = emit_text (out, \"if \")\n val () = emit_LPAREN (out)\n val () = emit_d0exp (out, d0e)\n val () = emit_RPAREN (out)\n val () = emit_text (out, \":\\n\")\n\/\/\n val () = emit2_instrlst (out, ind+2, inss)\n\/\/\n val () =\n (\n case+\n inssopt\n of (*case+*)\n | None() => ()\n | Some(inss) =>\n (\n case+ inss of\n | list_nil _ => ()\n | list_cons _ => {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"else:\\n\")\n val () = emit2_instrlst (out, ind+2, inss)\n } (* end of [list_cons] *)\n ) (* end of [Some] *)\n )\n\/\/\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"#endif\")\n\/\/\n } (* end of [ATSif] *)\n\/\/\n| ATSifthen (d0e, inss) =>\n {\n\/\/\n val-list_sing(ins) = inss\n\/\/\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"if(\")\n val () = emit_d0exp (out, d0e)\n val ((*closing*)) = emit_text (out, \"): \")\n val () = emit_instr (out, ins)\n }\n| ATSifnthen (d0e, inss) =>\n {\n\/\/\n val-list_sing(ins) = inss\n\/\/\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"if not(\")\n val () = emit_d0exp (out, d0e)\n val ((*closing*)) = emit_text (out, \"): \")\n val () = emit_instr (out, ins)\n }\n\/\/\n| ATSbranchseq (inss) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"#ATSbranch\")\n }\n\/\/\n| ATScaseofseq (inss) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"#ATScaseofseq_beg\")\n val () = emit_ENDL (out)\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"tmplab_py = 1\\n\")\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"while(1):\\n\")\n val () = emit_nspc (out, ind+2)\n val () = emit_text (out, \"mbranch_\")\n val () = emit_branchmap_index (out, ins0)\n val () = emit_text (out, \".get(tmplab_py)()\\n\")\n val () = emit_nspc (out, ind+2)\n val () = emit_text (out, \"if (tmplab_py == 0): break\\n\")\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"#ATScaseofseq_end\")\n }\n\/\/\n| ATSreturn (tmp) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"return \")\n val () = emit_tmpvar (out, tmp)\n }\n| ATSreturn_void (tmp) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"return#_void\")\n }\n\/\/\n| ATSlinepragma (line, file) =>\n {\n val () = emit_text (out, \"#line \")\n val () = emit_PMVint (out, line)\n val () = emit_SPACE (out)\n val () = emit_PMVstring (out, file)\n }\n\/\/\n| ATSINSlab (lab) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"#\")\n val () = emit_label (out, lab)\n }\n| ATSINSgoto (lab) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"tmplab_py = \")\n val () = emit_tmplab_index (out, lab)\n val () =\n (\n emit_SPACE (out);\n emit_text (out, \"; return\");\n emit_SHARP (out); emit_label (out, lab)\n ) (* end of [val] *)\n }\n\/\/\n| ATSINSflab (flab) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_SHARP (out)\n val () = emit_label (out, flab)\n }\n| ATSINSfgoto (flab) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"funlab_py = \")\n val () = emit_funlab_index (out, flab)\n val () =\n (\n emit_SPACE (out);\n emit_SHARP (out); emit_label (out, flab)\n ) (* end of [val] *)\n }\n\/\/\n| ATSINSfreeclo (d0e) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"#ATSINSfreeclo\")\n val () = emit_LPAREN (out)\n val () = emit_d0exp (out, d0e)\n val () = emit_RPAREN (out)\n val () = emit_SEMICOLON (out)\n }\n| ATSINSfreecon (d0e) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"#ATSINSfreecon\")\n val () = emit_LPAREN (out)\n val () = emit_d0exp (out, d0e)\n val () = emit_RPAREN (out)\n val () = emit_SEMICOLON (out)\n }\n\/\/\n| ATSINSmove (tmp, d0e) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_tmpvar (out, tmp)\n val () = (\n emit_text (out, \" = \"); emit_d0exp (out, d0e)\n ) (* end of [val] *)\n } (* end of [ATSINSmove] *)\n\/\/\n| ATSINSmove_void (tmp, d0e) =>\n {\n val () = emit_nspc (out, ind)\n val () = (\n case+ d0e.d0exp_node of\n | ATSPMVempty _ =>\n emit_text (out, \"None#ATSINSmove_void\")\n \/\/ end of [ATSPMVempty]\n | _ (*non-ATSPMVempty*) => emit_d0exp (out, d0e)\n ) : void \/\/ end of [val]\n } (* end of [ATSINSmove_void] *)\n\/\/\n| ATSINSmove_nil (tmp) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_tmpvar (out, tmp)\n val () = emit_text (out, \" = \")\n val () = emit_text (out, \"None\")\n }\n\/\/\n| ATSINSmove_con0 (tmp, tag) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_tmpvar (out, tmp)\n val () = (\n emit_text (out, \" = \"); emit_PMVint (out, tag)\n ) (* end of [val] *)\n }\n\/\/\n| ATSINSmove_con1 _ =>\n emit2_ATSINSmove_con1 (out, ind, ins0)\n\/\/\n| ATSINSmove_boxrec _ =>\n emit2_ATSINSmove_boxrec (out, ind, ins0)\n\/\/\n| ATSINSmove_delay _ =>\n emit2_ATSINSmove_delay (out, ind, ins0)\n| ATSINSmove_lazyeval _ =>\n emit2_ATSINSmove_lazyeval (out, ind, ins0)\n\/\/\n| ATSINSmove_ldelay _ =>\n emit2_ATSINSmove_ldelay (out, ind, ins0)\n| ATSINSmove_llazyeval _ =>\n emit2_ATSINSmove_llazyeval (out, ind, ins0)\n\/\/\n| ATStailcalseq (inss) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"#ATStailcalseq_beg\")\n val () = emit_ENDL (out)\n val () = emit2_instrlst (out, ind, inss)\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"#ATStailcalseq_end\")\n \n } (* end of [ATStailcalseq] *)\n\/\/\n| ATSINSmove_tlcal (tmp, d0e) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_tmpvar (out, tmp)\n val () = emit_text (out, \" = \")\n val () = emit_d0exp (out, d0e) \n } (* end of [ATSINSmove_tlcal] *)\n\/\/\n| ATSINSargmove_tlcal (tmp1, tmp2) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_tmpvar (out, tmp1)\n val () = emit_text (out, \" = \")\n val () = emit_tmpvar (out, tmp2)\n } (* end of [ATSINSargmove_tlcal] *)\n\/\/\n| ATSINSextvar_assign (ext, d0e_r) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_d0exp (out, ext)\n val () = emit_text (out, \" = \")\n val () = emit_d0exp (out, d0e_r)\n val () = emit_SEMICOLON (out)\n }\n| ATSINSdyncst_valbind (d2c, d0e_r) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_i0de (out, d2c)\n val () = emit_text (out, \" = \")\n val () = emit_d0exp (out, d0e_r)\n val () = emit_SEMICOLON (out)\n }\n\/\/\n| ATSINScaseof_fail (errmsg) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"ATSINScaseof_fail\")\n val () = emit_LPAREN (out)\n val () = emit_PMVstring (out, errmsg)\n val () = emit_RPAREN (out)\n val () = emit_SEMICOLON (out)\n }\n| ATSINSdeadcode_fail (__tok__) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"ATSINSdeadcode_fail()\")\n val () = emit_SEMICOLON (out)\n }\n\/\/\n| ATSdynload (dummy) =>\n {\n val () = emit_nspc (out, ind) \n val () = emit_text (out, \"#ATSdynload()\")\n val () = emit_the_statmpdeclst (out, ind)\n }\n\/\/\n| ATSdynloadset (flag) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"#ATSdynloadset\\n\")\n val () = emit_nspc (out, ind)\n val () = (\n emit_tmpvar (out, flag); emit_text (out, \" = 1\")\n ) (* end of [val] *)\n }\n\/\/\n| ATSdynloadfcall (fcall) =>\n {\n val () = emit_nspc (out, ind)\n val () = emit_text (out, \"#ATSdynloadfcall\\n\")\n val () = emit_nspc (out, ind)\n val () =\n (emit_tmpvar (out, fcall); emit_text (out, \"()\"))\n \/\/ end of [val]\n }\n\/\/\n| ATSdynloadflag_sta (flag) =>\n {\n val () = emit_nspc (out, ind) \n val () = emit_text (out, \"#ATSdynloadflag_sta\\n\")\n val () = emit_nspc (out, ind) \n val () = (\n emit_text (out, \"global \"); emit_tmpvar (out, flag)\n ) (* end of [val] *)\n }\n\/\/\n| ATSdynloadflag_ext (flag) =>\n {\n val () = emit_nspc (out, ind) \n val () = emit_text (out, \"#ATSdynloadflag_ext\\n\")\n val () = emit_nspc (out, ind) \n val () = (\n emit_text (out, \"global \"); emit_tmpvar (out, flag)\n ) (* end of [val] *)\n }\n\/\/\n| _ (*rest-of-instr*) =>\n {\n val () = emit_nspc (out, ind)\n val ((*error*)) = fprint! (out, \"UNRECOGNIZED-INSTRUCTION: \", ins0)\n }\n\/\/\nend \/\/ end of [emit2_instr]\n\n(* ****** ****** *)\n\nimplement\nemit2_instr_ln\n (out, ind, ins) =\n(\n emit2_instr (out, ind, ins); emit_ENDL (out)\n) (* end of [emit2_instr_ln] *)\n\n(* ****** ****** *)\n\nimplement\nemit2_instr_newline\n (out, ind, ins) =\n(\n emit2_instr (out, ind, ins); emit_newline (out)\n) (* end of [emit2_instr_newline] *)\n\n(* ****** ****** *)\n\nimplement\nemit2_instrlst\n(\n out, ind, inss\n) = (\n\/\/\ncase+ inss of\n| list_nil () => ()\n| list_cons\n (ins, inss) => let\n val () = emit2_instr (out, ind, ins)\n in\n emit_ENDL (out); emit2_instrlst (out, ind, inss)\n end \/\/ end of [list_cons]\n\/\/\n) (* end of [emit2_instrlst] *)\n\n(* ****** ****** *)\n\nimplement\nemit2_ATSfunbodyseq\n (out, ind, ins) = let\n\/\/\nval-ATSfunbodyseq (inss) = ins.instr_node\n\/\/\nin\n emit2_instrlst (out, ind, inss)\nend \/\/ end of [emit2_ATS2funbodyseq]\n\n(* ****** ****** *)\n\nimplement\nemit2_ATSINSmove_con1\n (out, ind, ins0) = let\n\/\/\nfun\ngetarglst\n(\n inss: instrlst\n) : d0explst =\n(\ncase+ inss of\n| list_nil () => list_nil ()\n| list_cons (ins, inss) => let\n val-ATSINSstore_con1_ofs (_, _, _, d0e) = ins.instr_node\n val d0es = getarglst (inss)\n in\n list_cons (d0e, d0es)\n end \/\/ end of [list_cons]\n)\n\/\/\nval-ATSINSmove_con1 (inss) = ins0.instr_node\n\/\/\nval-list_cons (ins, inss) = inss\nval-ATSINSmove_con1_new (tmp, _) = ins.instr_node \n\/\/\nvar opt: tokenopt = None()\n\/\/\nval inss =\n(\ncase+ inss of\n| list_nil () => inss\n| list_cons (ins, inss2) =>\n (\n case+ ins.instr_node of\n | ATSINSstore_con1_tag\n (tmp, tag) => let\n val () = opt := Some(tag) in inss2\n end \/\/ end of [ATSINSstore_con1_tag]\n | _ (*non-ATSINSstore_con1_tag*) => inss\n )\n) : instrlst\n\/\/\nval d0es = getarglst (inss)\nval () = emit_nspc (out, ind)\nval () = emit_tmpvar (out, tmp)\nval () = emit_text (out, \" = \")\nval () = emit_LPAREN (out)\nval () =\n(\ncase+ opt of\n| None () => ()\n| Some (tag) => emit_PMVint (out, tag)\n) : void \/\/ end of [val]\nval () =\n(\ncase+ opt of\n| None _ => emit_d0explst (out, d0es)\n| Some _ => emit_d0explst_1 (out, d0es)\n) : void \/\/ end of [val]\n\/\/\nval ntup =\n(\ncase+ opt of\n| None _ => list_length(d0es)\n| Some _ => list_length(d0es) + 1\n) : int (* end of [val] *)\n\/\/\nval () =\nif ntup = 1\n then emit_text(out, \", )\") else emit_RPAREN(out)\n\/\/ end of [if]\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit2_ATSINSmove_con1]\n\n(* ****** ****** *)\n\nimplement\nemit2_ATSINSmove_boxrec\n (out, ind, ins0) = let\n\/\/\nfun\ngetarglst\n(\n inss: instrlst\n) : d0explst =\n(\ncase+ inss of\n\/\/\n| list_nil() => list_nil ()\n\/\/\n| list_cons(ins, inss) => let\n val-ATSINSstore_boxrec_ofs(_, _, _, d0e) = ins.instr_node\n val d0es = getarglst(inss)\n in\n list_cons (d0e, d0es)\n end \/\/ end of [list_cons]\n\/\/\n) (* end of [getarglst] *)\n\/\/\nval-\nATSINSmove_boxrec(inss) = ins0.instr_node\n\/\/\nval-\nlist_cons(ins, inss) = inss\nval-\nATSINSmove_boxrec_new(tmp, _) = ins.instr_node \n\/\/\nval d0es = getarglst (inss)\n\/\/\nval () = emit_nspc (out, ind)\nval () = emit_tmpvar (out, tmp)\nval () = emit_text (out, \" = \")\nval () = emit_LPAREN (out)\nval () = emit_d0explst (out, d0es)\n\/\/\nval () =\n(\nif list_is_sing(d0es)\n then emit_text(out, \", )\") else emit_RPAREN (out)\n\/\/ end of [if]\n) (* end of [val] *)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit2_ATSINSmove_boxrec]\n\n(* ****** ****** *)\n\nimplement\nemit2_ATSINSmove_delay\n (out, ind, ins0) = let\n\/\/\nval-ATSINSmove_delay(tmp, s0e, thunk) = ins0.instr_node\n\/\/\nval () =\n emit_nspc(out, ind)\nval () =\n emit_tmpvar(out, tmp)\n\/\/\nval () = emit_text(out, \" = [\")\n\/\/\nval () = (\n emit_int(out, 0); emit_text(out, \", \"); emit_d0exp(out, thunk)\n) (* end of [val] *)\nval ((*closing*)) = emit_text(out, \"]\")\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit2_ATSINSmove_delay]\n\n(* ****** ****** *)\n\nimplement\nemit2_ATSINSmove_lazyeval\n (out, ind, ins0) = let\n\/\/\nval-\nATSINSmove_lazyeval\n (tmp, s0e, lazyval) = ins0.instr_node\n\/\/\nval () = emit_nspc(out, ind)\n\/\/\nval () =\n(\n emit_tmpvar(out, tmp); emit_text(out, \" = \")\n) (* end of [val] *)\nval () =\n(\n emit_text(out, \"ATSPMVlazyval_eval(\");\n emit_d0exp(out, lazyval); emit_text(out, \"); \")\n) (* end of [val] *)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit2_ATSINSmove_lazyeval]\n\n(* ****** ****** *)\n\nimplement\nemit2_ATSINSmove_ldelay\n (out, ind, ins0) = let\n\/\/\nval-\nATSINSmove_ldelay\n (tmp, s0e, thunk) = ins0.instr_node\n\/\/\nval () = emit_nspc (out, ind)\n\/\/\nval () =\n(\n emit_tmpvar(out, tmp); emit_text(out, \" = \"); emit_d0exp(out, thunk)\n) (* end of [val] *)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit2_ATSINSmove_ldelay]\n\n(* ****** ****** *)\n\nimplement\nemit2_ATSINSmove_llazyeval\n (out, ind, ins0) = let\n\/\/\nval-\nATSINSmove_llazyeval\n (tmp, s0e, lazyval) = ins0.instr_node\n\/\/\nval () =\n emit_nspc(out, ind)\n\/\/\nval () =\n(\n emit_tmpvar(out, tmp); emit_text(out, \" = \")\n) (* end of [val] *)\n\/\/\nval () =\n(\n emit_text(out, \"ATSPMVllazyval_eval(\");\n emit_d0exp (out, lazyval); emit_text (out, \")\")\n) (* end of [val] *)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit2_ATSINSmove_llazyeval]\n\n(* ****** ****** *)\n\/\/\n#define\nATSEXTCODE_BEG \"######\\n#ATSextcode_beg()\\n######\"\n#define\nATSEXTCODE_END \"######\\n#ATSextcode_end()\\n######\"\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_d0ecl\n (out, d0c0) = let\nin\n\/\/\ncase+\nd0c0.d0ecl_node of\n\/\/\n| D0Cinclude _ => ()\n\/\/\n| D0Cifdef _ => ()\n| D0Cifndef _ => ()\n\/\/\n| D0Ctypedef (id, def) =>\n typedef_insert (id.i0dex_sym, def)\n\/\/\n| D0Cassume (id) =>\n {\n val () = emit_ENDL (out)\n val () =\n emit_text (out, \"#ATSassume(\")\n val () = (\n emit_i0de (out, id); emit_text (out, \")\\n\")\n ) (* end of [val] *)\n }\n\/\/\n| D0Cdyncst_mac _ => ()\n| D0Cdyncst_extfun _ => ()\n| D0Cdyncst_valdec _ => ()\n| D0Cdyncst_valimp _ => ()\n\/\/\n| D0Cstatmp\n (tmp, opt) =>\n {\n val () = emit_ENDL (out)\n val () = the_statmpdeclst_insert (d0c0)\n val () = (\n case+ opt of\n | Some _ => () | None () => emit_text(out, \"#\")\n ) (* end of [val] *)\n val () = (\n emit_tmpvar (out, tmp); emit_text (out, \" = None\\n\")\n ) (* end of [val] *)\n } (* end of [D0Cstatmp] *)\n\/\/\n| D0Cextcode (toks) =>\n {\n val () = emit_ENDL (out)\n val () =\n emit_text (out, ATSEXTCODE_BEG)\n val () = emit_extcode (out, toks) \/\/ HX: verbatim output\n val () =\n emit_text (out, ATSEXTCODE_END)\n val ((*void*)) = emit_newline (out)\n } (* end of [D0Cextcode] *)\n\/\/\n| D0Cfundecl\n (fk, f0d) => emit_f0decl (out, f0d)\n\/\/\n| D0Cclosurerize\n (\n fl, env, arg, res\n ) => emit_closurerize (out, fl, env, arg, res)\n\/\/\n| D0Cdynloadflag_init\n (flag) => (\n\/\/\n\/\/ HX-2015-05-22:\n\/\/ it is skipped as Python does not have a link-time!\n\/\/ \n ) (* end of [D0Cdynloadflag_init] *)\n| D0Cdynloadflag_minit\n (flag) => {\n val () = emit_ENDL (out)\n val () = (\n emit_tmpvar (out, flag); emit_text (out, \" = 0\\n\")\n ) (* end of [val] *)\n } (* end of [D0Cdynloadflag_minit] *)\n\/\/\n| D0Cdynexn_dec(idexn) =>\n (\n emit_text(out, \"## dynexn_dec(\"); emit_i0de(out, idexn); emit_text(out, \")\\n\")\n ) (* end of [D0Cdynexn_dec] *)\n| D0Cdynexn_extdec(idexn) =>\n (\n emit_text(out, \"## dynexn_extdec(\"); emit_i0de(out, idexn); emit_text(out, \")\\n\")\n ) (* end of [D0Cdynexn_extdec] *)\n| D0Cdynexn_initize(idexn, fullname) =>\n (\n emit_text(out, \"## dynexn_initize(\"); emit_i0de(out, idexn); emit_text(out, \")\\n\")\n ) (* end of [D0Cdynexn_initize] *)\n\/\/\nend \/\/ end of [emit_d0ecl]\n\n(* ****** ****** *)\n\/\/\nextern\nfun emit2_tmpdec\n (out: FILEref, ind: int, td: tmpdec) : void\nextern\nfun emit2_tmpdeclst\n (out: FILEref, ind: int, tds: tmpdeclst) : void\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_tmpdec\n (out, td) = emit2_tmpdec (out, 0(*ind*), td)\n\/\/\nimplement\nemit2_tmpdec\n (out, ind, td) = let\nin\n\/\/\ncase+\ntd.tmpdec_node of\n\/\/\n| TMPDECnone (tmp) =>\n {\n val () = emit_nspc (out, ind)\n val () = (emit_SHARP (out); emit_tmpvar (out, tmp))\n }\n| TMPDECsome (tmp, s0e) =>\n {\n val () = emit_nspc (out, ind)\n val () = (emit_tmpvar (out, tmp); emit_text (out, \" = None\"))\n }\nend \/\/ end of [emit2_tmpdec]\n\/\/\n(* ****** ****** *)\n\nimplement\nemit2_tmpdeclst\n(\n out, ind, tds\n) = (\n\/\/\ncase+ tds of\n| list_nil () => ()\n| list_cons (td, tds) =>\n {\n val () = emit2_tmpdec (out, ind, td)\n val () = emit_ENDL (out)\n val () = emit2_tmpdeclst (out, ind, tds)\n }\n\/\/\n) (* end of [emit2_tmpdeclst] *)\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit_branchseq\n (out: FILEref, ins0: instr): void\nextern\nfun\nemit_branchseqlst\n (out: FILEref, inss: instrlst): void\n\/\/\nextern\nfun\nemit_fundef_nonlocal (out: FILEref): void\n\/\/\n(* ****** ****** *)\n\nlocal\n\nfun auxlst\n(\n out: FILEref, inss: instrlst\n) : void = let\n\/\/\nval inss =\ninstrlst_skip_linepragma (inss)\n\/\/\nval-list_cons (ins, inss) = inss\nval-ATSINSlab (lab) = ins.instr_node\n\/\/\nval () = emit_nspc (out, 2)\nval () = emit_text (out, \"def\")\nval () = emit_SPACE (out)\nval () = emit_label (out, lab)\nval () = emit_text (out, \"():\\n\")\n\/\/\nval () = emit_fundef_nonlocal (out)\n\/\/\nval () = emit_nspc (out, 4)\nval () = emit_text (out, \"tmplab_py = 0\\n\")\n\/\/\nin\n auxlst2 (out, lab, inss)\nend (* end of [auxlst] *)\n\nand auxlst2\n(\n out: FILEref, lab: label, inss: instrlst\n) : void = let\nin\n\/\/\ncase+ inss of\n\/\/\n| list_nil ((*none*)) =>\n {\n val () = emit_nspc (out, 4)\n val () = emit_text (out, \"return\\n\") \n } (* end of [list_nil] *)\n\/\/\n| list_cons\n (ins1, inss2) =>\n (\n case ins1.instr_node of\n | ATSINSlab (lab) =>\n {\n val () = emit_nspc (out, 4)\n val () = emit_label (out, lab)\n val () = emit_text (out, \"()\\n\")\n val () = emit_nspc (out, 4)\n val () = emit_text (out, \"return\\n\")\n val () = auxlst (out, inss)\n }\n | _ (*non-ATSINSlab*) =>\n {\n val () = (\n emit2_instr (out, 4, ins1); emit_ENDL (out)\n ) (* end of [val] *)\n val () = auxlst2 (out, lab, inss2)\n } (* end of [non-ATSINSlab] *)\n ) (* end of [list_cons] *)\n\/\/\nend \/\/ (* end of [auxlst2] *)\n\nin (* in-of-local *)\n\nimplement\nemit_branchseq\n (out, ins0) = let\n\/\/\nval-ATSbranchseq (inss) = ins0.instr_node\n\/\/\nin\n auxlst (out, inss)\nend \/\/ end of [emit_branchseq]\n\nend \/\/ end of [local]\n\n(* ****** ****** *)\n\nfun\nemit_branchseqlst\n(\n out: FILEref, inss: instrlst\n) : void =\n(\ncase+ inss of\n| list_nil () => ()\n| list_cons (ins, inss) =>\n {\n val () = emit_branchseq (out, ins)\n val () = emit_branchseqlst (out, inss)\n }\n) (* end of [emit_branchseqlst] *)\n\n(* ****** ****** *)\n\nimplement\nemit_fundef_nonlocal\n (out) = () where\n{\n\/\/\nval f0as = the_f0arglst_get ()\nval () = emit_f0arglst_nonlocal (out, f0as)\n\/\/\nval tmpdecs = the_tmpdeclst_get ()\nval () = emit_tmpdeclst_nonlocal (out, tmpdecs)\n\/\/\nval () =\nemit_nspc (out, 4(*ind*))\nval () =\nemit_text (out, \"nonlocal funlab_py, tmplab_py\\n\")\n\/\/\nval inss_caseof = the_caseofseqlst_get ()\nval () = emit_mbranchlst_nonlocal(out, inss_caseof)\n\/\/\n} \/\/ end of [emit_fundef_nonlocal]\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit_caseofseq\n (out: FILEref, ins0: instr): void\nextern\nfun\nemit_caseofseqlst\n (out: FILEref, inss: instrlst): void\n\/\/\n(* ****** ****** *)\n\nfun\nemit_caseofseq\n(\n out: FILEref, ins0: instr\n) : void = let\n\/\/\nval-ATScaseofseq(inss) = ins0.instr_node\n\/\/\nval tls = caseofseq_get_tmplablst (ins0)\nval ((*update*)) = the_branchlablst_set (tls)\n\/\/\nin\n emit_branchseqlst (out, inss)\nend \/\/ end of [emit_caseofseq]\n\n(* ****** ****** *)\n\nfun\nemit_caseofseqlst\n(\n out: FILEref, inss: instrlst\n) : void =\n(\ncase+ inss of\n| list_nil () => ()\n| list_cons (ins, inss) =>\n {\n val () = emit_caseofseq (out, ins)\n val () = emit_caseofseqlst (out, inss)\n }\n) (* end of [emit_caseofseqlst] *)\n\n(* ****** ****** *)\n\/\/\nextern\nfun emit_f0arg : emit_type (f0arg)\nextern\nfun emit_f0marg : emit_type (f0marg)\nextern\nfun emit_f0head : emit_type (f0head)\n\/\/\nextern\nfun emit_f0body : emit_type (f0body)\nextern\nfun emit_f0body_0 : emit_type (f0body)\nextern\nfun emit_f0body_tlcal : emit_type (f0body)\nextern\nfun emit_f0body_tlcal2 : emit_type (f0body)\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_f0arg\n (out, f0a) = let\nin\n\/\/\ncase+\nf0a.f0arg_node of\n\/\/\n| F0ARGnone _ => emit_text (out, \"__NONE__\")\n| F0ARGsome (arg, s0e) => emit_tmpvar (out, arg)\n\/\/\nend \/\/ end of [emit_f0arg]\n\n(* ****** ****** *)\n\nimplement\nemit_f0marg\n (out, f0ma) = let\n\/\/\nfun\nloop\n(\n out: FILEref, f0as: f0arglst, i: int\n) : void =\n(\ncase+ f0as of\n| list_nil () => ()\n| list_cons (f0a, f0as) => let\n val () =\n if i > 0 then emit_text (out, \", \")\n \/\/ end of [val]\n in\n emit_f0arg (out, f0a); loop (out, f0as, i+1)\n end \/\/ end of [list_cons]\n)\n\/\/\nin\n loop (out, f0ma.f0marg_node, 0)\nend \/\/ end of [emit_f0marg]\n\n(* ****** ****** *)\n\nimplement\nemit_f0head\n (out, fhd) = let\n\/\/\nval f0as =\n f0head_get_f0arglst (fhd)\n\/\/\nval () = the_f0arglst_set (f0as)\n\/\/\nin\n\/\/\ncase+\nfhd.f0head_node of\n| F0HEAD\n (fid, f0ma, res) =>\n {\n val () = emit_tmpvar (out, fid)\n val () = emit_LPAREN (out)\n val () = emit_f0marg (out, f0ma)\n val () = emit_RPAREN (out)\n val () = emit_text (out, \":\")\n }\n\/\/\nend \/\/ end of [emit_f0head]\n\n(* ****** ****** *)\n\nimplement\nemit_f0body\n (out, fbody) = let\n\/\/\nval knd = f0body_classify (fbody)\n(*\nval () = println! (\"emit_f0body: knd = \", knd)\n*)\n\/\/\nval tmpdecs =\n f0body_get_tmpdeclst(fbody)\nval inss_body =\n f0body_get_bdinstrlst(fbody)\nval inss_caseof =\n f0body_collect_caseof(fbody)\n\/\/\nval () = the_tmpdeclst_set (tmpdecs)\nval () = the_funbodylst_set (inss_body)\nval () = the_caseofseqlst_set (inss_caseof)\n\/\/\nval () = emit_tmpdeclst_initize (out, tmpdecs)\n\/\/\nval () = emit_nspc (out, 2(*ind*))\nval () = emit_text (out, \"funlab_py = None\\n\")\nval () = emit_nspc (out, 2(*ind*))\nval () = emit_text (out, \"tmplab_py = None\\n\")\n\/\/\nval () = emit_mbranchlst_initize(out, inss_caseof)\n\/\/\nval () = emit_caseofseqlst (out, inss_caseof)\nval () = emit_branchmaplst (out, inss_caseof)\n\/\/\nin\n\/\/\ncase+ knd of\n| 0 => emit_f0body_0 (out, fbody)\n| 1 => emit_f0body_tlcal (out, fbody)\n| 2 => emit_f0body_tlcal2 (out, fbody)\n| _ => let val () = assertloc(false) in (*nothing*) end\n\/\/\nend \/\/ end of [emit_f0body]\n\n(* ****** ****** *)\n\nimplement\nemit_f0body_0\n (out, fbody) = let\n\/\/\nfun\nauxlst\n(\n out: FILEref, inss: instrlst\n) : void =\n(\ncase+ inss of\n| list_nil () => ()\n| list_cons\n (ins0, inss1) => let\n val-list_cons (ins1, inss2) = inss1\n val () = emit2_ATSfunbodyseq (out, 2(*ind*), ins0)\n val () = emit2_instr_ln (out, 2(*ind*), ins1)\n in\n auxlst (out, inss2)\n end \/\/ end of [list_cons]\n\/\/\n) (* end of [auxlst] *)\n\/\/\nin\n\/\/\ncase+\nfbody.f0body_node of\n\/\/\n| F0BODY (tds, inss) => auxlst (out, inss)\n\/\/\nend \/\/ end of [emit_f0body_0]\n\n(* ****** ****** *)\n\nimplement\nemit_f0body_tlcal\n (out, fbody) = let\n\/\/\nfun\nauxlst\n(\n out: FILEref, inss: instrlst\n) : void =\n(\ncase+ inss of\n| list_nil () => ()\n| list_cons\n (ins0, inss1) => let\n val-list_cons (ins1, inss2) = inss1\n val () = emit2_ATSfunbodyseq (out, 4(*ind*), ins0)\n val () = emit_nspc (out, 4(*ind*))\n val () = emit_text (out, \"if (funlab_py == 0): break\\n\")\n val () = emit2_instr_ln (out, 2(*ind*), ins1)\n in\n auxlst (out, inss2)\n end \/\/ end of [list_cons]\n\/\/\n) (* end of [auxlst] *)\n\/\/\nval () = emit_nspc (out, 2(*ind*))\nval () = emit_text (out, \"while(1):\\n\")\nval () = emit_nspc (out, 4(*ind*))\nval () = emit_text (out, \"funlab_py = 0\\n\")\n\/\/\nval () =\n(\ncase+\nfbody.f0body_node of\n\/\/\n| F0BODY (tds, inss) => auxlst (out, inss)\n\/\/\n)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit_f0body_tlcal]\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit_mfundef_initize\n (out: FILEref, inss: instrlst): void\n\/\/\nimplement\nemit_mfundef_initize\n (out, inss) = let\n\/\/\nfun auxlst\n(\n out: FILEref, xs: instrlst, i: int\n) : void =\n(\ncase+ xs of\n| list_nil () => ()\n| list_cons (x, xs) => let\n val fl =\n funbodyseq_get_funlab (x)\n val () =\n if i >= 2\n then emit_text (out, \", \")\n \/\/ end of [if]\n val () = emit_int (out, i)\n val () = emit_text (out, \": \")\n val () = emit_label (out, fl)\n val-list_cons (_, xs) = xs\n in\n auxlst (out, xs, i+1)\n end \/\/ end of [list_cons]\n)\n\/\/\nval () =\nemit_nspc (out, 2(*ind*))\nval () =\nemit_text (out, \"mfundef = { \")\nval () = auxlst (out, inss, 1)\nval () = emit_text (out, \" }\\n\")\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit_mfundef_initize]\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit_the_funbodylst (out: FILEref): void\n\/\/\nimplement\nemit_the_funbodylst\n (out) = let\n\/\/\nfun auxfun\n(\n out: FILEref, ins0: instr\n) : void = let\n\/\/\nval-ATSfunbodyseq(inss) = ins0.instr_node\n\/\/\nval-list_cons (ins1, inss) = inss\nval-ATSINSflab (fl) = ins1.instr_node\n\/\/\nval () = emit_nspc (out, 2)\nval () = emit_text (out, \"def\")\nval () = emit_SPACE (out)\nval () = emit_label (out, fl)\nval () = emit_text (out, \"():\\n\")\n\/\/\nval () = emit_fundef_nonlocal (out)\n\/\/\nval () = emit_nspc (out, 4)\nval () = emit_text (out, \"funlab_py = 0\\n\")\nval () = emit2_instrlst (out, 4(*ind*), inss)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [auxfun]\n\/\/\nfun auxlst\n(\n out: FILEref, inss: instrlst\n) : void =\n(\ncase+ inss of\n| list_nil () => ()\n| list_cons _ => let\n val-list_cons (ins0, inss) = inss\n val-list_cons (ins1, inss) = inss\n val () = auxfun (out, ins0)\n val () = emit2_instr_newline (out, 4(*ind*), ins1)\n in\n auxlst (out, inss)\n end \/\/ end of [auxlst]\n) (* end of [auxlst] *)\n\/\/\nval inss_body = the_funbodylst_get()\n\/\/\nval () = auxlst (out, inss_body)\nval () = emit_mfundef_initize (out, inss_body)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit_the_funbodylst]\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_f0body_tlcal2\n (out, fbody) = let\n\/\/\nval () = emit_nspc (out, 2(*ind*))\nval () = emit_text (out, \"tmpret_py = None\\n\")\n\/\/\nval () = emit_the_funbodylst (out)\n\/\/\nval () = emit_nspc (out, 2(*ind*))\nval () = emit_text (out, \"funlab_py = 1\\n\")\nval () = emit_nspc (out, 2(*ind*))\nval () = emit_text (out, \"while(1):\\n\")\nval () = emit_nspc (out, 4(*ind*))\nval () = emit_text (out, \"tmpret_py = mfundef.get(funlab_py)()\\n\")\nval () = emit_nspc (out, 4(*ind*))\nval () = emit_text (out, \"if (funlab_py == 0): break\\n\")\nval () = emit_nspc (out, 2(*ind*))\nval () = emit_text (out, \"return tmpret_py\\n\")\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit_f0body_tlcal2]\n\n(* ****** ****** *)\n\nimplement\nemit_f0decl\n (out, fdec) = let\nin\n\/\/\ncase+\nfdec.f0decl_node of\n| F0DECLnone (fhd) => () \n| F0DECLsome (fhd, fbody) =>\n {\n val () = emit_ENDL (out)\n val () = emit_text (out, \"def\")\n val () = emit_SPACE (out)\n val () = emit_f0head (out, fhd)\n val () = emit_ENDL (out)\n val () = emit_f0body (out, fbody)\n val () = emit_newline (out)\n } (* end of [F0DECLsome] *)\n\/\/\nend \/\/ end of [emit_f0decl]\n\n(* ****** ****** *)\n\nimplement\nemit_toplevel\n (out, d0cs) = let\n\/\/\nfun\nloop\n(\n out: FILEref, d0cs: d0eclist\n) : void =\n(\n\/\/\ncase+ d0cs of\n| list_nil () => ()\n| list_cons\n (d0c, d0cs) => let\n val () =\n emit_d0ecl (out, d0c)\n \/\/ end of [val]\n in\n loop (out, d0cs)\n end \/\/ end of [list_cons]\n\/\/\n) (* end of [loop] *)\n\/\/\nin\n loop (out, d0cs)\nend \/\/ end of [emit_toplevel]\n\n(* ****** ****** *)\n\n(* end of [atscc2py3_emit2.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"e166b467e126eb99323689d5b57d5d93b3eca27e","subject":"Small fix to make ATS-parse-emit-CIL compilable.","message":"Small fix to make ATS-parse-emit-CIL compilable.\n","repos":"bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib","old_file":"projects\/MEDIUM\/ATS-parse-emit\/CIL\/atsparemit_emit_cil.dats","new_file":"projects\/MEDIUM\/ATS-parse-emit\/CIL\/atsparemit_emit_cil.dats","new_contents":"(* ****** ****** *)\n\/\/\n\/\/ ATS-parse-emit-python\n\/\/\n(* ****** ****** *)\n\/\/\n\/\/ AS-2014-08-17: start\n\/\/\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_staload.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\nUN = \"prelude\/SATS\/unsafe.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/atsparemit.sats\"\nstaload \".\/atsparemit_cil.sats\"\nstaload \".\/atsparemit_syntax.sats\"\nstaload \".\/atsparemit_syntax_cil.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/atsparemit_emit.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/atsparemit_typedef.dats\"\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_ENDL (out) = emit_text (out, \"\\n\")\n\n(* ****** ****** *)\n\nimplement\nemit_SPACE (out) = emit_text (out, \" \")\n\n(* ****** ****** *)\n\nimplement\nemit_SHARP (out) = emit_text (out, \"#\")\n\n(* ****** ****** *)\n\nimplement\nemit_COLON (out) = emit_text (out, \":\")\n\n(* ****** ****** *)\n\nimplement\nemit_LPAREN (out) = emit_text (out, \"(\")\nimplement\nemit_RPAREN (out) = emit_text (out, \")\")\n\n(* ****** ****** *)\n\nimplement\nemit_LBRACE (out) = emit_text (out, \"{\")\nimplement\nemit_RBRACE (out) = emit_text (out, \"}\")\n\n\n(* ****** ****** *)\n\nimplement\nemit_LBRACKET (out) = emit_text (out, \"[\")\nimplement\nemit_RBRACKET (out) = emit_text (out, \"]\")\n\n(* ****** ****** *)\n\nimplement\nemit_flush (out) = fileref_flush (out)\nimplement\nemit_newline (out) = fprint_newline (out)\n\n(* ****** ****** *)\n\/\/\nimplement\nemit_int (out, x) = fprint_int (out, x)\n\/\/\nimplement\nemit_text (out, x) = fprint_string (out, x)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nemit_symbol (out, x) =\n fprint_string (out, symbol_get_name (x))\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_PMVint\n (out, tok) = let\n\/\/\nval-T_INT(base, rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVint]\n\n(* ****** ****** *)\n\nimplement\nemit_PMVi0nt\n (out, tok) = let\n\/\/\nval-T_INT(base, rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVi0nt]\n\n(* ****** ****** *)\n\/\/\nimplement\nemit_PMVbool\n (out, tfv) =\n(\n emit_text (out, if tfv then \"1\" else \"0\")\n) (* end of [emit_PMVbool] *)\n\/\/\n(* ****** ****** *)\nimplement\nemit_PMVstring\n (out, tok) = let\n\/\/\nval-T_STRING(rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVstring]\n\n(* ****** ****** *)\n\/\/\nimplement\nemit_i0de\n (out, id) = emit_symbol (out, id.i0de_sym)\nimplement\nemit_label\n (out, lab) = emit_symbol (out, lab.i0de_sym)\nfun\nemit_label_mark\n (out, lab) =\n {\n val () = emit_label (out, lab)\n val () = emit_COLON (out)\n val () = emit_ENDL (out)\n }\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_extcode\n (out, toks) = let\n\/\/\nfun\nauxtok\n(\n out: FILEref, tok: token\n) : void =\n(\ncase+\ntok.token_node of\n\/\/\n| T_KWORD _ => ()\n\/\/\n| T_ENDL () => emit_ENDL (out)\n| T_SPACES (cs) => emit_text (out, cs)\n\/\/\n| T_COMMENT_line () =>\n emit_text (out, \"\/\/ COMMENT_line\\n\")\n| T_COMMENT_block () => ((*ignored*))\n\/\/\n| T_INT (_, rep) => emit_text (out, rep)\n\/\/\n| T_STRING (str) => emit_text (out, str)\n\/\/\n| T_IDENT_alp (name) => emit_text (out, name)\n| T_IDENT_srp (name) => emit_text (out, name) \/\/ FIXME?\n\/\/\n| T_IDENT_sym (name) => emit_text (out, name)\n\/\/\n| T_LPAREN () => emit_LPAREN (out)\n| T_RPAREN () => emit_RPAREN (out)\n\/\/\n| T_LBRACKET () => emit_LBRACKET (out)\n| T_RBRACKET () => emit_RBRACKET (out)\n\/\/\n| T_LBRACE () => emit_LBRACE (out)\n| T_RBRACE () => emit_RBRACE (out)\n\/\/\n| T_LT () => emit_text (out, \"<\")\n| T_GT () => emit_text (out, \">\")\n\/\/\n| T_MINUS () => emit_text (out, \"-\")\n\/\/\n| T_COLON () => emit_text (out, \":\")\n\/\/\n| T_COMMA () => emit_text (out, \",\")\n| T_SEMICOLON () => emit_text (out, \";\")\n\/\/\n| T_SLASH () => emit_text (out, \"\/\")\n\/\/\n| _ (*unrecognized*) =>\n {\n val () = fprint! (out, \"TOKERR(\", tok, \")\")\n }\n) (* end of [auxtok] *)\n\/\/\nin\n\/\/\ncase+ toks of\n| list_nil () => ()\n| list_cons (tok, toks) =>\n (\n auxtok (out, tok); emit_extcode (out, toks)\n ) (* end of [list_cons] *)\n\/\/\nend \/\/ end of [emit_extcode]\n\n(* ****** ****** *)\n\/\/\nextern\nfun emit_tmpvar_ld (out: FILEref, tmp: i0de): void\n\/\/\nextern\nfun emit_tmpvar_st (out: FILEref, tmp: i0de): void\n\/\/\nimplement\n emit_tmpvar_ld (out, tmp) =\n {\n val () =\n if tmpvar_is_arg (tmp.i0de_sym)\n then emit_text (out, \"ldarg\")\n else emit_text (out, \"ldloc\")\n val () = emit_SPACE (out)\n val () = emit_i0de (out, tmp)\n } \/\/ end of [emit_tmpvar_ld]\n\/\/\nimplement\n emit_tmpvar_st\n (out, tmp) =\n {\n val () =\n if tmpvar_is_arg (tmp.i0de_sym)\n then emit_text (out, \"starg\")\n else emit_text (out, \"stloc\")\n val () = emit_SPACE (out)\n val () = emit_i0de (out, tmp)\n } \/\/ end of [emit_tmpvar_st]\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun emit_MODCLSNAME (out: FILEref, fname: string): void\n\/\/\nimplement\n emit_MODCLSNAME (out, fname) = {\n val () = emit_text (out, \"\\'\")\n \/\/ TODO: sanitize?\n val () = emit_text (out, fname)\n val () = emit_text (out, \"\\'\")\n} (* end of [emit_MODCLSNAME] *)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit_branchseqlst\n (out: FILEref, inss: instrlst, labthis: label, labnext: label): void\n\/\/\nextern\nfun\nemit_instrlst\n (out: FILEref, inss: instrlst, labbeg: label, labend: label) : void\n\/\/\nextern\nfun\nemit_s0exp : emit_type (s0exp)\nextern\nfun\nemit_s0explst : emit_type (s0explst)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nemit_s0exp\n (out, s0e) = let\n\/\/\n\/\/\nin\n\/\/\ncase+\ns0e.s0exp_node of\n\/\/\n| S0Eide (id) =>\n(\n case+ symbol_get_name (id) of\n | \"atsvoid_t0ype\" => emit_text (out, \"void\")\n | \"atstype_void\" => emit_text (out, \"void\")\n | _ => emit_symbol (out, id)\n) (* end of [S0Eide] *)\n| S0Elist (s0es) => () \/\/ shouldn't happen? marked as \"temp\"\n| S0Eappid (id, s0es) =>\n \/\/ FIXME: what about other types? e.g. array types? struct types?\n(\n case+ symbol_get_name (id.i0de_sym) of\n | \"atstkind_t0ype\" => let\n \/\/ unboxed type, of sort t@ype in ATS\n val-list_cons (s0e, list_nil ()) = s0es\n val-S0Eide (id) = s0e.s0exp_node\n in\n case+ symbol_get_name (id) of\n | \"atstype_sint\" => emit_text (out, \"int16\")\n | \"atstype_usint\" =>\n {\n val () = emit_text (out, \"unsigned\")\n val () = emit_SPACE (out)\n val () = emit_text (out, \"int16\")\n }\n | \"atstype_int\" => emit_text (out, \"int32\")\n | \"atstype_uint\" =>\n {\n val () = emit_text (out, \"unsigned\")\n val () = emit_SPACE (out)\n val () = emit_text (out, \"int\")\n }\n | \"atstype_lint\" => emit_text (out, \"int64\")\n | \"atstype_ulint\" =>\n {\n val () = emit_text (out, \"unsigned\")\n val () = emit_SPACE (out)\n val () = emit_text (out, \"int64\")\n }\n | \"atstype_bool\" => emit_text (out, \"bool\")\n | \"atstype_byte\" =>\n {\n val () = emit_text (out, \"unsigned\")\n val () = emit_SPACE (out)\n val () = emit_text (out, \"int8\")\n }\n \/\/ TODO: atstype_char, atstype_schar, atstype_uchar\n | \"atstype_string\" => emit_text (out, \"string\")\n | \"atstype_stropt\" => emit_text (out, \"string\")\n | \"atstype_strptr\" => emit_text (out, \"string\")\n | _ => emit_symbol (out, id)\n end \/\/ end of [let]\n | _ =>\n {\n val () = emit_i0de (out, id)\n val () = emit_LPAREN (out)\n val () = emit_s0explst (out, s0es)\n val () = emit_RPAREN (out)\n } \/\/ end of [_]\n)\n\/\/\nend \/\/ end of [emit_s0exp]\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_s0explst\n (out, s0es) = let\n\/\/\nfun\nloop\n(\n out: FILEref, s0es: s0explst, i: int\n) : void =\n(\ncase+ s0es of\n| list_nil () => ()\n| list_cons (s0e, s0es) => let\n val () =\n if i > 0 then emit_text (out, \", \")\n \/\/ end of [val]\n in\n emit_s0exp (out, s0e); loop (out, s0es, i+1)\n end \/\/ end of [list_cons]\n)\n\/\/\nin\n loop (out, s0es, 0)\nend \/\/ end of [emit_s0explst]\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nfunlab_get_index (fl: label): int\nextern\nfun\ntmplab_get_index (lab: label): int\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_f0arglst_get (): f0arglst\nextern\nfun\nthe_f0arglst_set (f0as: f0arglst): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_tmpdeclst_get (): tmpdeclst\nextern\nfun\nthe_tmpdeclst_set (tds: tmpdeclst): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_funbodylst_get (): instrlst\nextern\nfun\nthe_funbodylst_set (inss: instrlst): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_branchlablst_get (): labelist\nextern\nfun\nthe_branchlablst_set (labs: labelist): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_caseofseqlst_get (): instrlst\nextern\nfun\nthe_caseofseqlst_set (inss: instrlst): void\n\/\/\n(* ****** ****** *)\n\nlocal\n\/\/\nval the_f0arglst = ref (list_nil)\nval the_tmpdeclst = ref (list_nil)\n\/\/\nval the_funbodylst = ref (list_nil)\n\/\/\nval the_branchlablst = ref (list_nil)\nval the_caseofseqlst = ref (list_nil)\n\/\/\nin (* in-of-local *)\n\nimplement\nthe_f0arglst_get () = !the_f0arglst\nimplement\nthe_f0arglst_set (xs) = !the_f0arglst := xs\n\nimplement\nthe_tmpdeclst_get () = !the_tmpdeclst\nimplement\nthe_tmpdeclst_set (xs) = !the_tmpdeclst := xs\n\nimplement\nthe_funbodylst_get () = !the_funbodylst\nimplement\nthe_funbodylst_set (xs) = !the_funbodylst := xs\n\nimplement\nthe_branchlablst_get () = !the_branchlablst\nimplement\nthe_branchlablst_set (xs) = !the_branchlablst := xs\n\nimplement\nthe_caseofseqlst_get () = !the_caseofseqlst\nimplement\nthe_caseofseqlst_set (xs) = !the_caseofseqlst := xs\n\nend \/\/ end of [local]\n\n(* ******* ****** *)\n\nlocal\n\nfun\nloop\n(\n out: FILEref, d0es: d0explst, i: int\n) : void =\n(\ncase+ d0es of\n| list_nil () => ()\n| list_cons (d0e, d0es) => let\n val () =\n if i > 0 then emit_newline (out)\n \/\/ end of [val]\n in\n emit_d0exp (out, d0e);\n emit_newline (out);\n loop (out, d0es, i+1)\n end \/\/ end of [list_cons]\n)\n\nin (* in-of-local *)\n\nimplement\nemit_d0explst (out, d0es) = loop (out, d0es, 0)\nimplement\nemit_d0explst_1 (out, d0es) = loop (out, d0es, 1)\n\nend \/\/ end of [local]\n\n(* ******* ****** *)\n\/\/\nextern\nfun emit_f0arg : emit_type (f0arg)\nextern\nfun emit_f0marg : emit_type (f0marg)\nextern\nfun emit_f0head : emit_type (f0head)\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_d0exp\n (out, d0e) = let\nin\n\/\/\ncase+\nd0e.d0exp_node of\n\/\/\n| D0Eide (id) =>\n {\n val () = emit_tmpvar_ld (out, id)\n }\n\/\/\n| D0Eappid (id, d0es) => let\n val () = emit_d0explst (out, d0es)\n\n \/\/ need type for [id]\n \/\/ what is [tyrec] type for?\n \/\/ val-~Some_vt (s0rec) = typedef_search_opt (id.i0de_sym)\n \n val f0head_opt = f0head_search_opt (id.i0de_sym)\n in\n case+ f0head_opt of\n | ~None_vt() =>\n {\n val () =\n (\n case+ symbol_get_name (id.i0de_sym) of\n \/\/ many more functions\n \/\/ atspre_g1int_add_int\n \/\/ atspre_g0int_sub_int\n \/\/ atspre_g0int_mul_int\n \/\/ atspre_g0int2int_int_int\n \/\/ atspre_g0int_lte_int\n \/\/ atspre_g0int_sub_int\n \/\/ - some of these are just macros (map to other functions)\n \/\/ - we still have to figure out the type signatures\n | \"atspre_print_newline\" =>\n {\n val () = emit_text (out, \"call\")\n val () = emit_SPACE (out)\n val () = emit_text (out, \"void [mscorlib]System.Console::WriteLine()\")\n }\n | \"atspre_print_string\" =>\n {\n val () = emit_text (out, \"call\")\n val () = emit_SPACE (out)\n val () = emit_text (out, \"void [mscorlib]System.Console::WriteLine(string)\")\n }\n | \"atspre_print_int\" =>\n {\n val () = emit_text (out, \"call\")\n val () = emit_SPACE (out)\n val () = emit_text (out, \"void [mscorlib]System.Console::Write(int32)\")\n }\n \/\/\n | \"ATSCKpat_int\" => emit_text (out, \"ceq\")\n | \"ATSCKpat_bool\" => emit_text (out, \"ceq\")\n | \"ATSCKpat_char\" => emit_text (out, \"ceq\")\n | \"ATSCKpat_float\" => emit_text (out, \"ceq\")\n | \"ATSCKpat_string\" =>\n {\n val () = emit_text (out, \"call\")\n val () = emit_SPACE (out)\n val () = emit_text (out, \"bool [mscorlib]System.String::Equals(string,string)\")\n }\n \/\/ TODO: ATSCKpat_(con*|exn*)\n \/\/\n | _ =>\n {\n val () = emit_text (out, \"call\")\n val () = emit_SPACE (out)\n val () = emit_i0de (out, id) \/\/ FIXME: need also type of [id]!\n }\n ) (* end of [val] *)\n }\n | ~Some_vt(fhd) =>\n {\n val () = emit_text (out, \"call\")\n val () = emit_SPACE (out)\n val () = emit_f0head (out, fhd)\n }\n end \/\/ end of [D0Eappid]\n\/\/\n\/\/ TODO: D0Elist\n\/\/\n| ATSempty (x) => emit_text (out, \"ldnull\")\n\/\/\n| ATSPMVint (tok) =>\n {\n val () = emit_text (out, \"ldc.i4\")\n val () = emit_SPACE (out)\n val () = emit_PMVint (out, tok)\n } (* end of [ATSPMVint] *)\n| ATSPMVi0nt (tok) =>\n {\n val-T_INT(base, rep) = tok.token_node\n val () = emit_text (out, \"ldc.i4\")\n val () = emit_SPACE (out)\n val () = emit_text (out, rep)\n } (* end of [ATSPMVi0nt] *)\n\/\/\n| ATSPMVbool (tfv) =>\n {\n val () = emit_text (out, \"ldc.i4\")\n val () = emit_SPACE (out)\n val () = emit_PMVbool (out, tfv)\n } (* end of [ATSPMVbool] *)\n\/\/\n| ATSPMVstring (tok) =>\n {\n val () = emit_text (out, \"ldstr\")\n val () = emit_SPACE(out)\n val () = emit_PMVstring (out, tok)\n } (* end of [ATSPMVstring] *)\n\/\/\n| ATSPMVf0loat (tok) =>\n {\n val-T_FLOAT(base, rep) = tok.token_node\n val () = emit_text (out, rep)\n }\n\/\/\n| _ => emit_text (out, \"**D0EXP**\")\n\/\/\nend \/\/ end of [emit_d0exp]\n\n(* ****** ****** *)\n\/\/\nextern\nfun emit_f0body : emit_type (f0body)\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_f0arg\n (out, f0a) = let\nin\n\/\/\ncase+\nf0a.f0arg_node of\n\/\/\n| F0ARGnone s0e => emit_s0exp (out, s0e)\n| F0ARGsome (id, s0e) =>\n {\n val () = emit_s0exp (out, s0e)\n val () = emit_SPACE (out)\n val () = emit_i0de (out, id)\n } (* end of [F0ARGsome] *)\n\/\/\nend \/\/ end of [emit_f0arg]\n\n(* ****** ****** *)\n\nimplement\nemit_f0marg\n (out, f0ma) = let\n\/\/\nfun\nloop\n(\n out: FILEref, f0as: f0arglst, i: int\n) : void =\n(\ncase+ f0as of\n| list_nil () => ()\n| list_cons (f0a, f0as) => let\n val () =\n if i > 0 then emit_text (out, \", \")\n \/\/ end of [val]\n in\n emit_f0arg (out, f0a); loop (out, f0as, i+1)\n end \/\/ end of [list_cons]\n)\n\/\/\nin\n loop (out, f0ma.f0marg_node, 0)\nend \/\/ end of [emit_f0marg]\n\n(* ****** ****** *)\n\nimplement\nemit_f0head\n (out, fhd) = let\n\/\/\nval f0as =\n f0head_get_f0arglst (fhd)\n\/\/\nval () = the_f0arglst_set (f0as)\n\/\/\nin\n\/\/\ncase+\nfhd.f0head_node of\n| F0HEAD\n (id(*name of function*), f0ma(*list of arguments*), res(*result type*)) =>\n {\n val () = emit_s0exp (out, res)\n val () = emit_SPACE (out)\n val () = emit_i0de (out, id)\n val () = emit_LPAREN (out)\n val () = emit_f0marg (out, f0ma)\n val () = emit_RPAREN (out)\n }\n\/\/\nend \/\/ end of [emit_f0head]\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit_tmpdeclst\n (out: FILEref, tds: tmpdeclst): void\n\/\/\nimplement\nemit_tmpdeclst\n (out, tds) = let\n\/\/\nfun auxlst\n(\n out: FILEref, tds: tmpdeclst, i: int\n) : void =\n(\ncase+ tds of\n| list_nil () => ()\n| list_cons (td, tds) =>\n (\n case+ td.tmpdec_node of\n | TMPDECnone\n (tmp) => auxlst (out, tds, i) \/\/ probably ATStmpdec_void()\n | TMPDECsome\n (tmp, s0e) => let\n val () =\n if i > 0 then\n emit_text(out, \", \")\n \/\/ end of [val]\n val () = emit_s0exp (out, s0e)\n val () = emit_SPACE (out)\n val () = emit_i0de (out, tmp)\n val () = emit_newline (out)\n in\n auxlst (out, tds, i+1)\n end \/\/ end of [TMPDECsome]\n ) (* end of [list_cons] *)\n)\n\/\/\nin\n auxlst (out, tds, 0)\nend \/\/ end of [emit_tmpdeclst_initize]\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun emit_instr_0\n (out: FILEref, ins: instr): void\n\/\/\nimplement\nemit_instr_0\n (out, ins0) = let\nin\n\/\/\ncase+\nins0.instr_node of\n\/\/\n| ATSreturn (tmp) =>\n {\n val () = emit_tmpvar_ld (out, tmp)\n val () = emit_newline (out)\n val () = emit_text (out, \"ret\")\n }\n\/\/\n| ATSreturn_void (tmp) =>\n {\n val () = emit_text (out, \"ret\")\n }\n\/\/\n| _ => emit_text (out, \"**INSTR**\")\n\/\/\nend \/\/ end of [emit_instr_0]\n\/\/\nextern\nfun emit_instr\n (out: FILEref, ins: instr, labthis: label, labnext: label) : void\n\/\/\nimplement\nemit_instr\n (out, ins0, labthis, labnext) = let\nin\n\/\/\ncase+\nins0.instr_node of\n\/\/\n| ATSif\n (\n d0e(*test*), inss(*then*), inssopt(*else*)\n ) =>\n (\n emit_d0exp (out, d0e);\n emit_newline (out);\n \n case+ inssopt of\n | Some (inss2) =>\n {\n val () = emit_text (out, \"brfalse\")\n val () = emit_SPACE (out)\n val L1 = label_for_instrlst (inss2)\n val () = emit_label (out, L1)\n val () = emit_ENDL (out)\n val L0 = label_for_instrlst (inss)\n val brlab = make_label (ins0.instr_loc)\n val () = emit_instrlst (out, inss, L0, brlab)\n val () = emit_label_mark (out, brlab)\n val () = emit_text (out, \"br\")\n val () = emit_SPACE (out)\n val () = emit_label (out, labnext)\n val () = emit_ENDL (out)\n val () = emit_instrlst (out, inss2, L1, labnext)\n }\n | None () =>\n {\n val () = emit_text (out, \"brfalse\")\n val () = emit_SPACE (out)\n val () = emit_label (out, labnext)\n val () = emit_ENDL (out)\n val () = emit_instrlst (out, inss, labthis, labnext)\n }\n )\n\/\/\n| ATSifthen (d0e, inss) =>\n {\n\/\/\n val-list_cons (ins, _) = inss\n\/\/\n val () = emit_d0exp (out, d0e)\n val () = emit_ENDL (out)\n val () = emit_text (out, \"brfalse\")\n val () = emit_SPACE (out)\n val () = emit_label (out, labnext)\n val () = emit_ENDL (out)\n val () = emit_instr (out, ins, labthis, labnext)\n }\n| ATSifnthen (d0e, inss) =>\n {\n\/\/\n val-list_cons (ins, _) = inss\n\/\/\n val () = emit_d0exp (out, d0e)\n val () = emit_ENDL (out)\n val () = emit_text (out, \"brtrue\")\n val () = emit_SPACE (out)\n val () = emit_label (out, labnext)\n val () = emit_ENDL (out)\n val () = emit_instr (out, ins, labthis, labnext)\n }\n\/\/\n| ATSbranchseq (inss) =>\n {\n val () = emit_text (out, \"\/* ATSbranch *\/\")\n }\n\/\/\n| ATScaseofseq (inss) =>\n {\n val () = emit_text (out, \"\/* ATScaseofseq_beg *\/\\n\")\n val () = emit_branchseqlst (out, inss, labthis, labnext)\n val () = emit_text (out, \"\/* ATScaseofseq_end *\/\\n\")\n }\n\/\/\n\/\/ TODO: ATSlinepragma\n\/\/\n| ATSreturn (tmp) =>\n {\n val () =\n if tmpvar_is_arg (tmp.i0de_sym)\n then emit_text (out, \"ldarg\")\n else emit_text (out, \"ldloc\")\n \/\/ end of [val]\n val () = emit_SPACE (out)\n val () = emit_i0de (out, tmp)\n val () = emit_newline (out)\n val () = emit_text (out, \"ret\")\n }\n\/\/\n| ATSreturn_void (tmp) =>\n {\n val () = emit_text (out, \"ret\")\n }\n\/\/\n(*\n| ATSlinepragma (line, file) =>\n {\n val () = emit_text (out, \".line\")\n val () = emit_SPACE (out)\n val-T_INT(_, lpos) = line.token_node\n val () = emit_text (out, lpos)\n val () = emit_SPACE (out)\n val-T_STRING(filnam) = file.token_node\n val () = emit_text (out, filnam)\n }\n*)\n\/\/\n(*\n| ATSINSlab (lab) =>\n {\n val () = emit_label_mark (out, lab)\n }\n*)\n\/\/\n| ATSINSgoto (lab) =>\n {\n val () = emit_text (out, \"br\")\n val () = emit_SPACE (out)\n val () = emit_label (out, lab)\n }\n\/\/\n(*\n| ATSINSflab (flab) =>\n {\n val () = emit_label_mark (out, flab)\n }\n*)\n\/\/\n| ATSINSfgoto (flab) =>\n {\n val () = emit_text (out, \"br\")\n val () = emit_SPACE (out)\n val () = emit_label (out, flab)\n }\n\/\/\n| ATSINSmove (tmp, d0e) =>\n {\n val () = emit_d0exp (out, d0e)\n val () = emit_newline (out)\n val () = emit_tmpvar_st (out, tmp)\n } (* end of [ATSINSmove] *)\n| ATSINSmove_void (_, d0e) =>\n {\n val () = emit_d0exp (out, d0e)\n } (* end of [ATSINSmove_void] *)\n\/\/ TODO: ATSdynload0, ATSdynload1, ATSdynloadset\n\/\/\n| ATStailcalseq (inss) =>\n {\n val () = emit_text (out, \"\/\/ ATStailcalseq_beg\")\n val () = emit_ENDL (out)\n val () = emit_instrlst (out, inss, labthis, labnext)\n val () = emit_text (out, \"\/\/ ATStailcalseq_end\")\n } (* end of [ATStailcalseq] *)\n\/\/\n| ATSINSmove_tlcal (tmp, d0e) =>\n {\n val () = emit_d0exp (out, d0e)\n val () = emit_ENDL (out)\n val () = emit_tmpvar_st (out, tmp)\n } (* end of [ATSINSmove_tlcal] *)\n\/\/\n| ATSINSargmove_tlcal (tmp1, tmp2) =>\n {\n val () = emit_tmpvar_ld (out, tmp2)\n val () = emit_ENDL (out)\n val () = emit_tmpvar_st (out, tmp1) \n } (* end of [ATSINSargmove_tlcal] *)\n\/\/\n| _ =>\n {\n val ((*error*)) = fprint! (out, \"UNRECOGNIZED-INSTRUCTION: \", ins0)\n }\n\/\/\nend \/\/ end of [emit_instr]\n\n(* ****** ****** *)\n\nimplement\nemit_branchseqlst\n (out, inss, labthis, lablast) = let\n\/\/\nfun auxseq\n(\n out: FILEref\n, ins0: instr\n, labthis: label\n, labnext: label\n) : void = let\nin\n\/\/\ncase-\nins0.instr_node of\n\/\/\n| ATSbranchseq\n (inss) =>\n {\n val () = emit_text (out, \"\/* ATSbranch_beg *\/\\n\")\n val () = emit_instrlst (out, inss, labthis, labnext)\n val () = emit_text (out, \"\/* ATSbranch_end *\/\\n\")\n } \/\/ end of [ATSbranchseq]\n\/\/\nend (* end of [auxseq] *)\n\/\/\nfun auxseqlst\n(\n out: FILEref\n, inss: instrlst\n, labnext: label\n, lablast: label\n) : void = let\nin\n\/\/\ncase+ inss of\n| list_nil () => ()\n| list_cons\n (ins, inss) => let\n\/\/\n val labnext =\n (\n case+ inss of\n | list_nil () => lablast\n | _ => label_for_instrlst (inss)\n ) (* end of [val] *)\n\/\/\n val () = auxseq (out, ins, labnext, lablast)\n\/\/\n val () = emit_text (out, \"br\")\n val () = emit_SPACE (out)\n val () = emit_label (out, lablast)\n val () = emit_ENDL (out)\n\/\/\n in\n auxseqlst (out, inss, labnext, lablast)\n end (* end of [list_cons] *)\n\/\/\nend (* end of [auxseqlst] *)\n\/\/\n val labthis =\n (\n case+ inss of\n | list_nil () => lablast\n | _ => label_for_instrlst (inss)\n ) (* end of [val] *)\n\/\/\nin\n auxseqlst (out, inss, labthis, lablast);\nend \/\/ end of [emit_branchseqlst]\n\n(* ****** ****** *)\n\nimplement\nemit_instrlst\n(\n out, inss, labthis, lablast\n) = (\n\/\/\ncase+ inss of\n| list_nil () => ()\n| list_cons (ins0, inss) => let\n \/\/\n \/\/\n in\n case+ ins0.instr_node of\n | ATSINSlab (label) =>\n (\n emit_instrlst (out, inss, label, lablast)\n )\n | ATSINSflab (label) =>\n (\n emit_instrlst (out, inss, label, lablast)\n )\n | ATSlinepragma (line, file) =>\n {\n val () = emit_text (out, \".line\")\n val () = emit_SPACE (out)\n val-T_INT(_, lpos) = line.token_node\n val () = emit_text (out, lpos)\n val () = emit_SPACE (out)\n val-T_STRING(filnam) = file.token_node\n val filnam = g1ofg0 (filnam)\n \/\/ double quotes -> single quotes\n val () = emit_text (out, \"'\")\n \/\/ FIXME: very involved\n val-true = string_isnot_empty filnam\n val len = pred (length filnam)\n val-true = len > g1int2uint(0)\n val () = fprint_substring (out, filnam, g1int2uint(1), pred (len))\n val () = emit_text (out, \"'\")\n val () = emit_ENDL (out)\n val () = emit_instrlst (out, inss, labthis, lablast)\n }\n | _(*other*) =>\n {\n val () = emit_label_mark (out, labthis)\n val labnext =\n (\n case+ inss of\n | list_nil () => lablast\n | _ => label_for_instrlst (inss)\n ) (* end of [val] *)\n val () = emit_instr (out, ins0, labthis, labnext)\n val () = emit_ENDL (out)\n val () = emit_instrlst (out, inss, labnext, lablast)\n }\n end \/\/ end of [let]\n\/\/\n) (* end of [emit_instrlst] *)\n\n(* ****** ****** *)\n\/\/\nextern\nfun emit_ATSfunbodyseq\n (out: FILEref, ins: instr, labnext: label) : void\n\/\/\nimplement\nemit_ATSfunbodyseq\n (out, ins, labnext) = let\n\/\/\nval-ATSfunbodyseq (inss) = ins.instr_node\nval L1 = label_for_instrlst (inss)\n\/\/\nin\n emit_instrlst (out, inss, L1, labnext)\nend \/\/ end of [emit_ATSfunbodyseq]\n\n(* ****** ****** *)\n\/\/\nextern\nfun emit_f0body_0 : emit_type (f0body)\n\/\/\nimplement\nemit_f0body_0\n (out, fbody) = let\n\/\/\nfun\nauxlst\n(\n out: FILEref, inss: instrlst\n) : void =\n(\ncase+ inss of\n| list_nil () => ()\n| list_cons\n (ins0, inss1) => let\n val-list_cons (ins1, inss2) = inss1\n val labnext = label_for_instrlst (inss1)\n val () = emit_ATSfunbodyseq (out, ins0, labnext)\n val () = emit_label_mark (out, labnext)\n \/\/ FIXME: inss2 is EMPTY! what now?\n val lablast =\n (\n case+ inss2 of\n | list_nil () => i0de_make_string (location_dummy, \"LASTLABEL\")\n | _ => label_for_instrlst (inss2)\n )\n val () = emit_instr (out, ins1, labnext, lablast)\n in\n auxlst (out, inss2)\n end \/\/ end of [list_cons]\n) (* end of [auxlst] *)\n\/\/\nin\n\/\/\ncase+\nfbody.f0body_node of\n\/\/\n| F0BODY (tds, inss) => let\n val () = label_reset ()\n in\n auxlst (out, inss)\n end \/\/ end of [auxlst]\n\/\/\nend \/\/ end of [emit_f0body_0]\n\n(* ****** ****** *)\nimplement\nemit_f0body\n (out, fbody) = let\n\/\/\nval tmpdecs =\n f0body_get_tmpdeclst (fbody)\n\/\/\nval () = the_tmpdeclst_set (tmpdecs)\nval () = emit_LBRACE (out)\nval () = emit_newline (out)\n\/\/ TODO: how to compute maxstack?\nval () = emit_text (out, \".maxstack 16\")\nval () = emit_newline (out)\n\/\/ emit locals\nval () = emit_text (out, \".locals\")\nval () = emit_SPACE (out)\n(*\nval () = emit_text (out, \"init\")\nval () = emit_SPACE (out)\n*)\nval () = emit_LPAREN (out)\nval () = emit_newline (out)\nval () = emit_tmpdeclst (out, tmpdecs)\nval () = emit_RPAREN (out)\nval () = emit_newline (out)\n\nval () = emit_f0body_0 (out, fbody)\nval () = emit_newline (out)\nval () = emit_RBRACE (out)\nin\n\/\/\n\/\/\nend \/\/ end of [emit_f0body]\n\n(* ****** ****** *)\n\nimplement\nemit_f0decl\n (out, fdec) = let\nin\n\/\/\ncase+\nfdec.f0decl_node of\n| F0DECLnone (fhd) =>\n \/\/ does this actually mean function declaration (e.g. forward function decl)?\n {\n val-F0HEAD(id, _, _) = fhd.f0head_node\n val () = f0head_insert (id.i0de_sym, fhd)\n }\n| F0DECLsome (fhd, fbody) =>\n {\n val () = emit_text (out, \".method\")\n val () = emit_SPACE (out)\n val () = emit_text (out, \"static\")\n \/\/ TODO: public\/private?\n \/\/ static -> private\n val () = emit_SPACE (out)\n val () = emit_text (out, \"public\")\n val () = emit_SPACE (out)\n val-F0HEAD(id, _, _) = fhd.f0head_node\n val () = f0head_insert (id.i0de_sym, fhd)\n val () = emit_f0head (out, fhd)\n val () = emit_SPACE (out) \n val () = emit_text (out, \"cil\")\n val () = emit_SPACE (out)\n val () = emit_text (out, \"managed\")\n val () = emit_newline (out)\n val () = emit_f0body (out, fbody)\n val () = emit_newline (out)\n } (* end of [F0DECLsome] *)\n\/\/\nend \/\/ end of [emit_f0decl]\n\n(* ****** ****** *)\n\n\/\/\nextern\nfun\ntyrec_labsel\n (tyrec: tyrec, lab: symbol): int\n\/\/\nimplement\ntyrec_labsel\n (tyrec, lab) = let\n\/\/\nfun loop\n(\n xs: tyfldlst, i: int\n) : int =\n(\ncase+ xs of\n| list_cons (x, xs) => let\n val TYFLD (id, s0e) = x.tyfld_node\n in\n if lab = id.i0de_sym then i else loop (xs, i+1)\n end \/\/ end of [list_cons\n| list_nil ((*void*)) => ~1(*error*)\n)\n\/\/\nin\n loop (tyrec.tyrec_node, 0)\nend \/\/ end of [tyrec_labsel]\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_SELcon\n (out, d0e) = let\n\/\/\nval-ATSSELcon\n (d0rec, s0e, id) = d0e.d0exp_node\nval-S0Eide (name) = s0e.s0exp_node\nval-~Some_vt (s0rec) = typedef_search_opt (name)\n\/\/\nval index = tyrec_labsel (s0rec, id.i0de_sym)\n\/\/\nval () =\n emit_d0exp (out, d0rec)\n\/\/\nval () = emit_LBRACKET (out)\nval () = emit_int (out, index)\nval () = emit_RBRACKET (out)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit_SELcon]\n\n(* ****** ****** *)\n\nimplement\nemit_SELboxrec\n (out, d0e) = let\n\/\/\nval-ATSSELboxrec\n (d0rec, s0e, id) = d0e.d0exp_node\nval-S0Eide (name) = s0e.s0exp_node\nval-~Some_vt (s0rec) = typedef_search_opt (name)\n\/\/\nval index = tyrec_labsel (s0rec, id.i0de_sym)\n\/\/\nval () =\n emit_d0exp (out, d0rec)\n\/\/\nval () = emit_LBRACKET (out)\nval () = emit_int (out, index)\nval () = emit_RBRACKET (out)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit_SELboxrec]\n\n(* ****** ****** *)\n\/\/\n#define\nATSEXTCODE_BEG \"\/*\\nATSextcode_beg()\\n*\/\"\n#define\nATSEXTCODE_END \"\/*\\nATSextcode_end()\\n*\/\"\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_d0ecl\n (out, d0c) = let\nin\n\/\/\ncase+\nd0c.d0ecl_node of\n\/\/\n| D0Cinclude include =>\n {\n val () = emit_text (out, \"#include\")\n val () = emit_SPACE (out)\n val-T_STRING(filnam) = include.token_node\n val () = emit_text (out, filnam)\n val () = emit_newline (out)\n }\n\/\/\n| D0Cifdef (i0de, d0eclist) =>\n {\n val () = emit_text (out, \"#ifdef\")\n val () = emit_SPACE (out)\n val () = emit_i0de (out, i0de)\n val () = emit_newline (out)\n val () = emit_text (out, \"#endif\")\n val () = emit_newline (out)\n }\n| D0Cifndef (i0de, d0eclist) =>\n {\n val () = emit_text (out, \"#ifndef\")\n val () = emit_SPACE (out)\n val () = emit_i0de (out, i0de)\n val () = emit_newline (out)\n val () = emit_text (out, \"#endif\")\n val () = emit_newline (out)\n }\n\/\/\n| D0Ctypedef (id, def) =>\n {\n val () = typedef_insert (id.i0de_sym, def)\n \/\/ TODO: insert type (class) declaration\n } (* end of [D0Ctypedef] *)\n\/\/\n| D0Cassume (id) =>\n {\n val () = emit_text (out, \"\/* ATSassume(\")\n val () = emit_i0de (out, id)\n val () = emit_text (out, \") *\/\\n\")\n }\n\/\/\n| D0Cdyncst_mac ide =>\n \/\/ [ide] is the identifier for a dynamic constant which is implemented as a macro\n ()\n (*\n {\n val () = emit_text (out, \"dyncst_mac\")\n val () = emit_SPACE (out)\n val filnam = ide.i0de_sym\n val () = emit_symbol (out, filnam)\n val () = emit_ENDL (out)\n }*)\n| D0Cdyncst_extfun (i0de, s0explst, s0exp) =>\n {\n }\n\/\/\n| D0Cstatmp\n (tmp, opt) =>\n {\n val () = (\n case+ opt of\n | Some _ => () | None () => emit_text (out, \"\/\/\")\n ) (* end of [val] *)\n val () = (\n emit_i0de (out, tmp)\n ) (* end of [val] *)\n } (* end of [D0Cstatmp] *)\n\/\/\n| D0Cextcode (toks) =>\n {\n val () = emit_text (out, ATSEXTCODE_BEG)\n val () = emit_extcode (out, toks)\n val () = emit_text (out, ATSEXTCODE_END)\n }\n| D0Cclosurerize (_, _, _, _) => ()\n\/\/\n| D0Cfundecl (fk, f0d) => emit_f0decl (out, f0d)\n\/\/\n| D0Cdynloadflag_init (flag) =>\n (\n emit_text (out, \"\/\/ dynloadflag_init\\n\");\n (* TODO\n emit_global (out, flag); emit_text (out, \" = 0;\\n\")\n *)\n )\n\/\/\nend \/\/ end of [emit_d0ecl]\n\n(* ****** ****** *)\n\nimplement\nemit2_toplevel\n (out, d0cs, fname, namespace) = let\n\/\/\nfun\nloop\n(\n out: FILEref, d0cs: d0eclist\n) : void =\n(\n\/\/\ncase+ d0cs of\n| list_nil () => ()\n| list_cons\n (d0c, d0cs) => let\n in\n emit_d0ecl (out, d0c); loop (out, d0cs)\n end \/\/ end of [list_cons]\n\/\/\n)\n\/\/\n\/\/ TODO: for the main file, emit assembly manifest (assembly references, etc.)\n\/\/ TODO: for all modules, emit .module extern for other modules?\n\/\/ TODO: handle entry point\n\/\/\nval () = emit_text (out, \".module\")\nval () = emit_SPACE (out)\nval () = emit_text (out, \"'\")\nval () = emit_text (out, fname)\nval () = emit_text (out, \"'\")\nval () = emit_ENDL (out)\n\/\/\nval () = emit_text (out, \".namespace\")\nval () = emit_SPACE (out)\nval () = emit_text (out, namespace)\nval () = emit_SPACE (out)\nval () = emit_LBRACE (out)\nval () = emit_ENDL (out)\n\/\/\nval () = emit_text (out, \".class\")\nval () = emit_SPACE (out)\nval () = emit_MODCLSNAME (out, fname)\nval () = emit_SPACE (out)\nval () = emit_LBRACE (out)\nval () = emit_ENDL (out)\nval () = loop (out, d0cs)\nval () = emit_RBRACE (out) (* end of [class] definition *)\nval () = emit_text (out, \"\/* end of class *\/\")\n\/\/\nval () = emit_ENDL (out)\nval () = emit_RBRACE (out) (* end of [namespace] definition *)\nval () = emit_text (out, \"\/* end of namespace *\/\")\n\/\/\nin\n (*empty*)\nend \/\/ end of [emit2_toplevel]\n\n(* ****** ****** *)\n\n(* end of [atsparemit_emit_cil.dats] *)\n","old_contents":"(* ****** ****** *)\n\/\/\n\/\/ ATS-parse-emit-python\n\/\/\n(* ****** ****** *)\n\/\/\n\/\/ AS-2014-08-17: start\n\/\/\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_staload.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\nUN = \"prelude\/SATS\/unsafe.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/atsparemit.sats\"\nstaload \".\/atsparemit_cil.sats\"\nstaload \".\/atsparemit_syntax.sats\"\nstaload \".\/atsparemit_syntax_cil.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/atsparemit_emit.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/atsparemit_typedef.dats\"\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_ENDL (out) = emit_text (out, \"\\n\")\n\n(* ****** ****** *)\n\nimplement\nemit_SPACE (out) = emit_text (out, \" \")\n\n(* ****** ****** *)\n\nimplement\nemit_SHARP (out) = emit_text (out, \"#\")\n\n(* ****** ****** *)\n\nimplement\nemit_COLON (out) = emit_text (out, \":\")\n\n(* ****** ****** *)\n\nimplement\nemit_LPAREN (out) = emit_text (out, \"(\")\nimplement\nemit_RPAREN (out) = emit_text (out, \")\")\n\n(* ****** ****** *)\n\nimplement\nemit_LBRACE (out) = emit_text (out, \"{\")\nimplement\nemit_RBRACE (out) = emit_text (out, \"}\")\n\n\n(* ****** ****** *)\n\nimplement\nemit_LBRACKET (out) = emit_text (out, \"[\")\nimplement\nemit_RBRACKET (out) = emit_text (out, \"]\")\n\n(* ****** ****** *)\n\nimplement\nemit_flush (out) = fileref_flush (out)\nimplement\nemit_newline (out) = fprint_newline (out)\n\n(* ****** ****** *)\n\/\/\nimplement\nemit_int (out, x) = fprint_int (out, x)\n\/\/\nimplement\nemit_text (out, x) = fprint_string (out, x)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nemit_symbol (out, x) =\n fprint_string (out, symbol_get_name (x))\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_PMVint\n (out, tok) = let\n\/\/\nval-T_INT(base, rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVint]\n\n(* ****** ****** *)\n\nimplement\nemit_PMVi0nt\n (out, tok) = let\n\/\/\nval-T_INT(base, rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVi0nt]\n\n(* ****** ****** *)\n\/\/\nimplement\nemit_PMVbool\n (out, tfv) =\n(\n emit_text (out, if tfv then \"1\" else \"0\")\n) (* end of [emit_PMVbool] *)\n\/\/\n(* ****** ****** *)\nimplement\nemit_PMVstring\n (out, tok) = let\n\/\/\nval-T_STRING(rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVstring]\n\n(* ****** ****** *)\n\/\/\nimplement\nemit_i0de\n (out, id) = emit_symbol (out, id.i0de_sym)\nimplement\nemit_label\n (out, lab) = emit_symbol (out, lab.i0de_sym)\nfun\nemit_label_mark\n (out, lab) =\n {\n val () = emit_label (out, lab)\n val () = emit_COLON (out)\n val () = emit_ENDL (out)\n }\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_extcode\n (out, toks) = let\n\/\/\nfun\nauxtok\n(\n out: FILEref, tok: token\n) : void =\n(\ncase+\ntok.token_node of\n\/\/\n| T_KWORD _ => ()\n\/\/\n| T_ENDL () => emit_ENDL (out)\n| T_SPACES (cs) => emit_text (out, cs)\n\/\/\n| T_COMMENT_line () =>\n emit_text (out, \"\/\/ COMMENT_line\\n\")\n| T_COMMENT_block () => ((*ignored*))\n\/\/\n| T_INT (_, rep) => emit_text (out, rep)\n\/\/\n| T_STRING (str) => emit_text (out, str)\n\/\/\n| T_IDENT_alp (name) => emit_text (out, name)\n| T_IDENT_srp (name) => emit_text (out, name) \/\/ FIXME?\n\/\/\n| T_IDENT_sym (name) => emit_text (out, name)\n\/\/\n| T_LPAREN () => emit_LPAREN (out)\n| T_RPAREN () => emit_RPAREN (out)\n\/\/\n| T_LBRACKET () => emit_LBRACKET (out)\n| T_RBRACKET () => emit_RBRACKET (out)\n\/\/\n| T_LBRACE () => emit_LBRACE (out)\n| T_RBRACE () => emit_RBRACE (out)\n\/\/\n| T_LT () => emit_text (out, \"<\")\n| T_GT () => emit_text (out, \">\")\n\/\/\n| T_MINUS () => emit_text (out, \"-\")\n\/\/\n| T_COLON () => emit_text (out, \":\")\n\/\/\n| T_COMMA () => emit_text (out, \",\")\n| T_SEMICOLON () => emit_text (out, \";\")\n\/\/\n| T_SLASH () => emit_text (out, \"\/\")\n\/\/\n| _ (*unrecognized*) =>\n {\n val () = fprint! (out, \"TOKERR(\", tok, \")\")\n }\n) (* end of [auxtok] *)\n\/\/\nin\n\/\/\ncase+ toks of\n| list_nil () => ()\n| list_cons (tok, toks) =>\n (\n auxtok (out, tok); emit_extcode (out, toks)\n ) (* end of [list_cons] *)\n\/\/\nend \/\/ end of [emit_extcode]\n\n(* ****** ****** *)\n\/\/\nextern\nfun emit_tmpvar_ld (out: FILEref, tmp: i0de): void\n\/\/\nextern\nfun emit_tmpvar_st (out: FILEref, tmp: i0de): void\n\/\/\nimplement\n emit_tmpvar_ld (out, tmp) =\n {\n val () =\n if tmpvar_is_arg (tmp.i0de_sym)\n then emit_text (out, \"ldarg\")\n else emit_text (out, \"ldloc\")\n val () = emit_SPACE (out)\n val () = emit_i0de (out, tmp)\n } \/\/ end of [emit_tmpvar_ld]\n\/\/\nimplement\n emit_tmpvar_st\n (out, tmp) =\n {\n val () =\n if tmpvar_is_arg (tmp.i0de_sym)\n then emit_text (out, \"starg\")\n else emit_text (out, \"stloc\")\n val () = emit_SPACE (out)\n val () = emit_i0de (out, tmp)\n } \/\/ end of [emit_tmpvar_st]\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun emit_MODCLSNAME (out: FILEref, fname: string): void\n\/\/\nimplement\n emit_MODCLSNAME (out, fname) = {\n val () = emit_text (out, \"\\'\")\n \/\/ TODO: sanitize?\n val () = emit_text (out, fname)\n val () = emit_text (out, \"\\'\")\n} (* end of [emit_MODCLSNAME] *)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit_branchseqlst\n (out: FILEref, inss: instrlst, labthis: label, labnext: label): void\n\/\/\nextern\nfun\nemit_instrlst\n (out: FILEref, inss: instrlst, labbeg: label, labend: label) : void\n\/\/\nextern\nfun\nemit_s0exp : emit_type (s0exp)\nextern\nfun\nemit_s0explst : emit_type (s0explst)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nemit_s0exp\n (out, s0e) = let\n\/\/\n\/\/\nin\n\/\/\ncase+\ns0e.s0exp_node of\n\/\/\n| S0Eide (id) =>\n(\n case+ symbol_get_name (id) of\n | \"atsvoid_t0ype\" => emit_text (out, \"void\")\n | \"atstype_void\" => emit_text (out, \"void\")\n | _ => emit_symbol (out, id)\n) (* end of [S0Eide] *)\n| S0Elist (s0es) => () \/\/ shouldn't happen? marked as \"temp\"\n| S0Eappid (id, s0es) =>\n \/\/ FIXME: what about other types? e.g. array types? struct types?\n(\n case+ symbol_get_name (id.i0de_sym) of\n | \"atstkind_t0ype\" => let\n \/\/ unboxed type, of sort t@ype in ATS\n val-list_cons (s0e, list_nil ()) = s0es\n val-S0Eide (id) = s0e.s0exp_node\n in\n case+ symbol_get_name (id) of\n | \"atstype_sint\" => emit_text (out, \"int16\")\n | \"atstype_usint\" =>\n {\n val () = emit_text (out, \"unsigned\")\n val () = emit_SPACE (out)\n val () = emit_text (out, \"int16\")\n }\n | \"atstype_int\" => emit_text (out, \"int32\")\n | \"atstype_uint\" =>\n {\n val () = emit_text (out, \"unsigned\")\n val () = emit_SPACE (out)\n val () = emit_text (out, \"int\")\n }\n | \"atstype_lint\" => emit_text (out, \"int64\")\n | \"atstype_ulint\" =>\n {\n val () = emit_text (out, \"unsigned\")\n val () = emit_SPACE (out)\n val () = emit_text (out, \"int64\")\n }\n | \"atstype_bool\" => emit_text (out, \"bool\")\n | \"atstype_byte\" =>\n {\n val () = emit_text (out, \"unsigned\")\n val () = emit_SPACE (out)\n val () = emit_text (out, \"int8\")\n }\n \/\/ TODO: atstype_char, atstype_schar, atstype_uchar\n | \"atstype_string\" => emit_text (out, \"string\")\n | \"atstype_stropt\" => emit_text (out, \"string\")\n | \"atstype_strptr\" => emit_text (out, \"string\")\n | _ => emit_symbol (out, id)\n end \/\/ end of [let]\n | _ =>\n {\n val () = emit_i0de (out, id)\n val () = emit_LPAREN (out)\n val () = emit_s0explst (out, s0es)\n val () = emit_RPAREN (out)\n } \/\/ end of [_]\n)\n\/\/\nend \/\/ end of [emit_s0exp]\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_s0explst\n (out, s0es) = let\n\/\/\nfun\nloop\n(\n out: FILEref, s0es: s0explst, i: int\n) : void =\n(\ncase+ s0es of\n| list_nil () => ()\n| list_cons (s0e, s0es) => let\n val () =\n if i > 0 then emit_text (out, \", \")\n \/\/ end of [val]\n in\n emit_s0exp (out, s0e); loop (out, s0es, i+1)\n end \/\/ end of [list_cons]\n)\n\/\/\nin\n loop (out, s0es, 0)\nend \/\/ end of [emit_s0explst]\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nfunlab_get_index (fl: label): int\nextern\nfun\ntmplab_get_index (lab: label): int\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_f0arglst_get (): f0arglst\nextern\nfun\nthe_f0arglst_set (f0as: f0arglst): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_tmpdeclst_get (): tmpdeclst\nextern\nfun\nthe_tmpdeclst_set (tds: tmpdeclst): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_funbodylst_get (): instrlst\nextern\nfun\nthe_funbodylst_set (inss: instrlst): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_branchlablst_get (): labelist\nextern\nfun\nthe_branchlablst_set (labs: labelist): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_caseofseqlst_get (): instrlst\nextern\nfun\nthe_caseofseqlst_set (inss: instrlst): void\n\/\/\n(* ****** ****** *)\n\nlocal\n\/\/\nval the_f0arglst = ref (list_nil)\nval the_tmpdeclst = ref (list_nil)\n\/\/\nval the_funbodylst = ref (list_nil)\n\/\/\nval the_branchlablst = ref (list_nil)\nval the_caseofseqlst = ref (list_nil)\n\/\/\nin (* in-of-local *)\n\nimplement\nthe_f0arglst_get () = !the_f0arglst\nimplement\nthe_f0arglst_set (xs) = !the_f0arglst := xs\n\nimplement\nthe_tmpdeclst_get () = !the_tmpdeclst\nimplement\nthe_tmpdeclst_set (xs) = !the_tmpdeclst := xs\n\nimplement\nthe_funbodylst_get () = !the_funbodylst\nimplement\nthe_funbodylst_set (xs) = !the_funbodylst := xs\n\nimplement\nthe_branchlablst_get () = !the_branchlablst\nimplement\nthe_branchlablst_set (xs) = !the_branchlablst := xs\n\nimplement\nthe_caseofseqlst_get () = !the_caseofseqlst\nimplement\nthe_caseofseqlst_set (xs) = !the_caseofseqlst := xs\n\nend \/\/ end of [local]\n\n(* ******* ****** *)\n\nlocal\n\nfun\nloop\n(\n out: FILEref, d0es: d0explst, i: int\n) : void =\n(\ncase+ d0es of\n| list_nil () => ()\n| list_cons (d0e, d0es) => let\n val () =\n if i > 0 then emit_newline (out)\n \/\/ end of [val]\n in\n emit_d0exp (out, d0e);\n emit_newline (out);\n loop (out, d0es, i+1)\n end \/\/ end of [list_cons]\n)\n\nin (* in-of-local *)\n\nimplement\nemit_d0explst (out, d0es) = loop (out, d0es, 0)\nimplement\nemit_d0explst_1 (out, d0es) = loop (out, d0es, 1)\n\nend \/\/ end of [local]\n\n(* ******* ****** *)\n\/\/\nextern\nfun emit_f0arg : emit_type (f0arg)\nextern\nfun emit_f0marg : emit_type (f0marg)\nextern\nfun emit_f0head : emit_type (f0head)\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_d0exp\n (out, d0e) = let\nin\n\/\/\ncase+\nd0e.d0exp_node of\n\/\/\n| D0Eide (id) =>\n {\n val () = emit_tmpvar_ld (out, id)\n }\n\/\/\n| D0Eappid (id, d0es) => let\n val () = emit_d0explst (out, d0es)\n\n \/\/ need type for [id]\n \/\/ what is [tyrec] type for?\n \/\/ val-~Some_vt (s0rec) = typedef_search_opt (id.i0de_sym)\n \n val f0head_opt = f0head_search_opt (id.i0de_sym)\n in\n case+ f0head_opt of\n | ~None_vt() =>\n {\n val () =\n (\n case+ symbol_get_name (id.i0de_sym) of\n \/\/ many more functions\n \/\/ atspre_g1int_add_int\n \/\/ atspre_g0int_sub_int\n \/\/ atspre_g0int_mul_int\n \/\/ atspre_g0int2int_int_int\n \/\/ atspre_g0int_lte_int\n \/\/ atspre_g0int_sub_int\n \/\/ - some of these are just macros (map to other functions)\n \/\/ - we still have to figure out the type signatures\n | \"atspre_print_newline\" =>\n {\n val () = emit_text (out, \"call\")\n val () = emit_SPACE (out)\n val () = emit_text (out, \"void [mscorlib]System.Console::WriteLine()\")\n }\n | \"atspre_print_string\" =>\n {\n val () = emit_text (out, \"call\")\n val () = emit_SPACE (out)\n val () = emit_text (out, \"void [mscorlib]System.Console::WriteLine(string)\")\n }\n | \"atspre_print_int\" =>\n {\n val () = emit_text (out, \"call\")\n val () = emit_SPACE (out)\n val () = emit_text (out, \"void [mscorlib]System.Console::Write(int32)\")\n }\n \/\/\n | \"ATSCKpat_int\" => emit_text (out, \"ceq\")\n | \"ATSCKpat_bool\" => emit_text (out, \"ceq\")\n | \"ATSCKpat_char\" => emit_text (out, \"ceq\")\n | \"ATSCKpat_float\" => emit_text (out, \"ceq\")\n | \"ATSCKpat_string\" =>\n {\n val () = emit_text (out, \"call\")\n val () = emit_SPACE (out)\n val () = emit_text (out, \"bool [mscorlib]System.String::Equals(string,string)\")\n }\n \/\/ TODO: ATSCKpat_(con*|exn*)\n \/\/\n | _ =>\n {\n val () = emit_text (out, \"call\")\n val () = emit_SPACE (out)\n val () = emit_i0de (out, id) \/\/ FIXME: need also type of [id]!\n }\n ) (* end of [val] *)\n }\n | ~Some_vt(fhd) =>\n {\n val () = emit_text (out, \"call\")\n val () = emit_SPACE (out)\n val () = emit_f0head (out, fhd)\n }\n end \/\/ end of [D0Eappid]\n\/\/\n\/\/ TODO: D0Elist\n\/\/\n| ATSempty (x) => emit_text (out, \"ldnull\")\n\/\/\n| ATSPMVint (tok) =>\n {\n val () = emit_text (out, \"ldc.i4\")\n val () = emit_SPACE (out)\n val () = emit_PMVint (out, tok)\n } (* end of [ATSPMVint] *)\n| ATSPMVi0nt (tok) =>\n {\n val-T_INT(base, rep) = tok.token_node\n val () = emit_text (out, \"ldc.i4\")\n val () = emit_SPACE (out)\n val () = emit_text (out, rep)\n } (* end of [ATSPMVi0nt] *)\n\/\/\n| ATSPMVbool (tfv) =>\n {\n val () = emit_text (out, \"ldc.i4\")\n val () = emit_SPACE (out)\n val () = emit_PMVbool (out, tfv)\n } (* end of [ATSPMVbool] *)\n\/\/\n| ATSPMVstring (tok) =>\n {\n val () = emit_text (out, \"ldstr\")\n val () = emit_SPACE(out)\n val () = emit_PMVstring (out, tok)\n } (* end of [ATSPMVstring] *)\n\/\/\n| ATSPMVf0loat (tok) =>\n {\n val-T_FLOAT(base, rep) = tok.token_node\n val () = emit_text (out, rep)\n }\n\/\/\n| _ => emit_text (out, \"**D0EXP**\")\n\/\/\nend \/\/ end of [emit_d0exp]\n\n(* ****** ****** *)\n\/\/\nextern\nfun emit_f0body : emit_type (f0body)\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_f0arg\n (out, f0a) = let\nin\n\/\/\ncase+\nf0a.f0arg_node of\n\/\/\n| F0ARGnone s0e => emit_s0exp (out, s0e)\n| F0ARGsome (id, s0e) =>\n {\n val () = emit_s0exp (out, s0e)\n val () = emit_SPACE (out)\n val () = emit_i0de (out, id)\n } (* end of [F0ARGsome] *)\n\/\/\nend \/\/ end of [emit_f0arg]\n\n(* ****** ****** *)\n\nimplement\nemit_f0marg\n (out, f0ma) = let\n\/\/\nfun\nloop\n(\n out: FILEref, f0as: f0arglst, i: int\n) : void =\n(\ncase+ f0as of\n| list_nil () => ()\n| list_cons (f0a, f0as) => let\n val () =\n if i > 0 then emit_text (out, \", \")\n \/\/ end of [val]\n in\n emit_f0arg (out, f0a); loop (out, f0as, i+1)\n end \/\/ end of [list_cons]\n)\n\/\/\nin\n loop (out, f0ma.f0marg_node, 0)\nend \/\/ end of [emit_f0marg]\n\n(* ****** ****** *)\n\nimplement\nemit_f0head\n (out, fhd) = let\n\/\/\nval f0as =\n f0head_get_f0arglst (fhd)\n\/\/\nval () = the_f0arglst_set (f0as)\n\/\/\nin\n\/\/\ncase+\nfhd.f0head_node of\n| F0HEAD\n (id(*name of function*), f0ma(*list of arguments*), res(*result type*)) =>\n {\n val () = emit_s0exp (out, res)\n val () = emit_SPACE (out)\n val () = emit_i0de (out, id)\n val () = emit_LPAREN (out)\n val () = emit_f0marg (out, f0ma)\n val () = emit_RPAREN (out)\n }\n\/\/\nend \/\/ end of [emit_f0head]\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit_tmpdeclst\n (out: FILEref, tds: tmpdeclst): void\n\/\/\nimplement\nemit_tmpdeclst\n (out, tds) = let\n\/\/\nfun auxlst\n(\n out: FILEref, tds: tmpdeclst, i: int\n) : void =\n(\ncase+ tds of\n| list_nil () => ()\n| list_cons (td, tds) =>\n (\n case+ td.tmpdec_node of\n | TMPDECnone\n (tmp) => auxlst (out, tds, i) \/\/ probably ATStmpdec_void()\n | TMPDECsome\n (tmp, s0e) => let\n val () =\n if i > 0 then\n emit_text(out, \", \")\n \/\/ end of [val]\n val () = emit_s0exp (out, s0e)\n val () = emit_SPACE (out)\n val () = emit_i0de (out, tmp)\n val () = emit_newline (out)\n in\n auxlst (out, tds, i+1)\n end \/\/ end of [TMPDECsome]\n ) (* end of [list_cons] *)\n)\n\/\/\nin\n auxlst (out, tds, 0)\nend \/\/ end of [emit_tmpdeclst_initize]\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun emit_instr_0\n (out: FILEref, ins: instr): void\n\/\/\nimplement\nemit_instr_0\n (out, ins0) = let\nin\n\/\/\ncase+\nins0.instr_node of\n\/\/\n| ATSreturn (tmp) =>\n {\n val () = emit_tmpvar_ld (out, tmp)\n val () = emit_newline (out)\n val () = emit_text (out, \"ret\")\n }\n\/\/\n| ATSreturn_void (tmp) =>\n {\n val () = emit_text (out, \"ret\")\n }\n\/\/\n| _ => emit_text (out, \"**INSTR**\")\n\/\/\nend \/\/ end of [emit_instr_0]\n\/\/\nextern\nfun emit_instr\n (out: FILEref, ins: instr, labthis: label, labnext: label) : void\n\/\/\nimplement\nemit_instr\n (out, ins0, labthis, labnext) = let\nin\n\/\/\ncase+\nins0.instr_node of\n\/\/\n| ATSif\n (\n d0e(*test*), inss(*then*), inssopt(*else*)\n ) =>\n (\n emit_d0exp (out, d0e);\n emit_newline (out);\n \n case+ inssopt of\n | Some (inss2) =>\n {\n val () = emit_text (out, \"brfalse\")\n val () = emit_SPACE (out)\n val L1 = label_for_instrlst (inss2)\n val () = emit_label (out, L1)\n val () = emit_ENDL (out)\n val L0 = label_for_instrlst (inss)\n val brlab = make_label (ins0.instr_loc)\n val () = emit_instrlst (out, inss, L0, brlab)\n val () = emit_label_mark (out, brlab)\n val () = emit_text (out, \"br\")\n val () = emit_SPACE (out)\n val () = emit_label (out, labnext)\n val () = emit_ENDL (out)\n val () = emit_instrlst (out, inss2, L1, labnext)\n }\n | None () =>\n {\n val () = emit_text (out, \"brfalse\")\n val () = emit_SPACE (out)\n val () = emit_label (out, labnext)\n val () = emit_ENDL (out)\n val () = emit_instrlst (out, inss, labthis, labnext)\n }\n )\n\/\/\n| ATSifthen (d0e, inss) =>\n {\n\/\/\n val-list_cons (ins, _) = inss\n\/\/\n val () = emit_d0exp (out, d0e)\n val () = emit_ENDL (out)\n val () = emit_text (out, \"brfalse\")\n val () = emit_SPACE (out)\n val () = emit_label (out, labnext)\n val () = emit_ENDL (out)\n val () = emit_instr (out, ins, labthis, labnext)\n }\n| ATSifnthen (d0e, inss) =>\n {\n\/\/\n val-list_cons (ins, _) = inss\n\/\/\n val () = emit_d0exp (out, d0e)\n val () = emit_ENDL (out)\n val () = emit_text (out, \"brtrue\")\n val () = emit_SPACE (out)\n val () = emit_label (out, labnext)\n val () = emit_ENDL (out)\n val () = emit_instr (out, ins, labthis, labnext)\n }\n\/\/\n| ATSbranchseq (inss) =>\n {\n val () = emit_text (out, \"\/* ATSbranch *\/\")\n }\n\/\/\n| ATScaseofseq (inss) =>\n {\n val () = emit_text (out, \"\/* ATScaseofseq_beg *\/\\n\")\n val () = emit_branchseqlst (out, inss, labthis, labnext)\n val () = emit_text (out, \"\/* ATScaseofseq_end *\/\\n\")\n }\n\/\/\n\/\/ TODO: ATSlinepragma\n\/\/\n| ATSreturn (tmp) =>\n {\n val () =\n if tmpvar_is_arg (tmp.i0de_sym)\n then emit_text (out, \"ldarg\")\n else emit_text (out, \"ldloc\")\n \/\/ end of [val]\n val () = emit_SPACE (out)\n val () = emit_i0de (out, tmp)\n val () = emit_newline (out)\n val () = emit_text (out, \"ret\")\n }\n\/\/\n| ATSreturn_void (tmp) =>\n {\n val () = emit_text (out, \"ret\")\n }\n\/\/\n(*\n| ATSlinepragma (line, file) =>\n {\n val () = emit_text (out, \".line\")\n val () = emit_SPACE (out)\n val-T_INT(_, lpos) = line.token_node\n val () = emit_text (out, lpos)\n val () = emit_SPACE (out)\n val-T_STRING(filnam) = file.token_node\n val () = emit_text (out, filnam)\n }\n*)\n\/\/\n(*\n| ATSINSlab (lab) =>\n {\n val () = emit_label_mark (out, lab)\n }\n*)\n\/\/\n| ATSINSgoto (lab) =>\n {\n val () = emit_text (out, \"br\")\n val () = emit_SPACE (out)\n val () = emit_label (out, lab)\n }\n\/\/\n(*\n| ATSINSflab (flab) =>\n {\n val () = emit_label_mark (out, flab)\n }\n*)\n\/\/\n| ATSINSfgoto (flab) =>\n {\n val () = emit_text (out, \"br\")\n val () = emit_SPACE (out)\n val () = emit_label (out, flab)\n }\n\/\/\n| ATSINSmove (tmp, d0e) =>\n {\n val () = emit_d0exp (out, d0e)\n val () = emit_newline (out)\n val () = emit_tmpvar_st (out, tmp)\n } (* end of [ATSINSmove] *)\n| ATSINSmove_void (_, d0e) =>\n {\n val () = emit_d0exp (out, d0e)\n } (* end of [ATSINSmove_void] *)\n\/\/ TODO: ATSdynload0, ATSdynload1, ATSdynloadset\n\/\/\n| ATStailcalseq (inss) =>\n {\n val () = emit_text (out, \"\/\/ ATStailcalseq_beg\")\n val () = emit_ENDL (out)\n val () = emit_instrlst (out, inss, labthis, labnext)\n val () = emit_text (out, \"\/\/ ATStailcalseq_end\")\n } (* end of [ATStailcalseq] *)\n\/\/\n| ATSINSmove_tlcal (tmp, d0e) =>\n {\n val () = emit_d0exp (out, d0e)\n val () = emit_ENDL (out)\n val () = emit_tmpvar_st (out, tmp)\n } (* end of [ATSINSmove_tlcal] *)\n\/\/\n| ATSINSargmove_tlcal (tmp1, tmp2) =>\n {\n val () = emit_tmpvar_ld (out, tmp2)\n val () = emit_ENDL (out)\n val () = emit_tmpvar_st (out, tmp1) \n } (* end of [ATSINSargmove_tlcal] *)\n\/\/\n| _ =>\n {\n val ((*error*)) = fprint! (out, \"UNRECOGNIZED-INSTRUCTION: \", ins0)\n }\n\/\/\nend \/\/ end of [emit_instr]\n\n(* ****** ****** *)\n\nimplement\nemit_branchseqlst\n (out, inss, labthis, lablast) = let\n\/\/\nfun auxseq\n(\n out: FILEref\n, ins0: instr\n, labthis: label\n, labnext: label\n) : void = let\nin\n\/\/\ncase-\nins0.instr_node of\n\/\/\n| ATSbranchseq\n (inss) =>\n {\n val () = emit_text (out, \"\/* ATSbranch_beg *\/\\n\")\n val () = emit_instrlst (out, inss, labthis, labnext)\n val () = emit_text (out, \"\/* ATSbranch_end *\/\\n\")\n } \/\/ end of [ATSbranchseq]\n\/\/\nend (* end of [auxseq] *)\n\/\/\nfun auxseqlst\n(\n out: FILEref\n, inss: instrlst\n, labnext: label\n, lablast: label\n) : void = let\nin\n\/\/\ncase+ inss of\n| list_nil () => ()\n| list_cons\n (ins, inss) => let\n\/\/\n val labnext =\n (\n case+ inss of\n | list_nil () => lablast\n | _ => label_for_instrlst (inss)\n ) (* end of [val] *)\n\/\/\n val () = auxseq (out, ins, labnext, lablast)\n\/\/\n val () = emit_text (out, \"br\")\n val () = emit_SPACE (out)\n val () = emit_label (out, lablast)\n val () = emit_ENDL (out)\n\/\/\n in\n auxseqlst (out, inss, labnext, lablast)\n end (* end of [list_cons] *)\n\/\/\nend (* end of [auxseqlst] *)\n\/\/\n val labthis =\n (\n case+ inss of\n | list_nil () => lablast\n | _ => label_for_instrlst (inss)\n ) (* end of [val] *)\n\/\/\nin\n auxseqlst (out, inss, labthis, lablast);\nend \/\/ end of [emit_branchseqlst]\n\n(* ****** ****** *)\n\nimplement\nemit_instrlst\n(\n out, inss, labthis, lablast\n) = (\n\/\/\ncase+ inss of\n| list_nil () => ()\n| list_cons (ins0, inss) => let\n \/\/\n \/\/\n in\n case+ ins0.instr_node of\n | ATSINSlab (label) =>\n (\n emit_instrlst (out, inss, label, lablast)\n )\n | ATSINSflab (label) =>\n (\n emit_instrlst (out, inss, label, lablast)\n )\n | ATSlinepragma (line, file) =>\n {\n val () = emit_text (out, \".line\")\n val () = emit_SPACE (out)\n val-T_INT(_, lpos) = line.token_node\n val () = emit_text (out, lpos)\n val () = emit_SPACE (out)\n val-T_STRING(filnam) = file.token_node\n val filnam = g1ofg0 (filnam)\n \/\/ double quotes -> single quotes\n val () = emit_text (out, \"'\")\n \/\/ FIXME: very involved\n val-true = string_isnot_empty filnam\n val len = pred (length filnam)\n val-true = len > g1int2uint(0)\n val () = fprint_substring (out, filnam, g1int2uint(1), pred (len))\n val () = emit_text (out, \"'\")\n val () = emit_ENDL (out)\n val () = emit_instrlst (out, inss, labthis, lablast)\n }\n | _(*other*) =>\n {\n val () = emit_label_mark (out, labthis)\n val labnext =\n (\n case+ inss of\n | list_nil () => lablast\n | _ => label_for_instrlst (inss)\n ) (* end of [val] *)\n val () = emit_instr (out, ins0, labthis, labnext)\n val () = emit_ENDL (out)\n val () = emit_instrlst (out, inss, labnext, lablast)\n }\n end \/\/ end of [let]\n\/\/\n) (* end of [emit_instrlst] *)\n\n(* ****** ****** *)\n\/\/\nextern\nfun emit_ATSfunbodyseq\n (out: FILEref, ins: instr, labnext: label) : void\n\/\/\nimplement\nemit_ATSfunbodyseq\n (out, ins, labnext) = let\n\/\/\nval-ATSfunbodyseq (inss) = ins.instr_node\nval L1 = label_for_instrlst (inss)\n\/\/\nin\n emit_instrlst (out, inss, L1, labnext)\nend \/\/ end of [emit_ATSfunbodyseq]\n\n(* ****** ****** *)\n\/\/\nextern\nfun emit_f0body_0 : emit_type (f0body)\n\/\/\nimplement\nemit_f0body_0\n (out, fbody) = let\n\/\/\nfun\nauxlst\n(\n out: FILEref, inss: instrlst\n) : void =\n(\ncase+ inss of\n| list_nil () => ()\n| list_cons\n (ins0, inss1) => let\n val-list_cons (ins1, inss2) = inss1\n val labnext = label_for_instrlst (inss1)\n val () = emit_ATSfunbodyseq (out, ins0, labnext)\n val () = emit_label_mark (out, labnext)\n \/\/ FIXME: inss2 is EMPTY! what now?\n val lablast =\n (\n case+ inss2 of\n | list_nil () => i0de_make_string (location_dummy, \"LASTLABEL\")\n | _ => label_for_instrlst (inss2)\n )\n val () = emit_instr (out, ins1, labnext, lablast)\n in\n auxlst (out, inss2)\n end \/\/ end of [list_cons]\n) (* end of [auxlst] *)\n\/\/\nin\n\/\/\ncase+\nfbody.f0body_node of\n\/\/\n| F0BODY (tds, inss) => let\n val () = label_reset ()\n in\n auxlst (out, inss)\n end \/\/ end of [auxlst]\n\/\/\nend \/\/ end of [emit_f0body_0]\n\n(* ****** ****** *)\nimplement\nemit_f0body\n (out, fbody) = let\n\/\/\nval tmpdecs =\n f0body_get_tmpdeclst (fbody)\n\/\/\nval () = the_tmpdeclst_set (tmpdecs)\nval () = emit_LBRACE (out)\nval () = emit_newline (out)\n\/\/ TODO: how to compute maxstack?\nval () = emit_text (out, \".maxstack 16\")\nval () = emit_newline (out)\n\/\/ emit locals\nval () = emit_text (out, \".locals\")\nval () = emit_SPACE (out)\n(*\nval () = emit_text (out, \"init\")\nval () = emit_SPACE (out)\n*)\nval () = emit_LPAREN (out)\nval () = emit_newline (out)\nval () = emit_tmpdeclst (out, tmpdecs)\nval () = emit_RPAREN (out)\nval () = emit_newline (out)\n\nval () = emit_f0body_0 (out, fbody)\nval () = emit_newline (out)\nval () = emit_RBRACE (out)\nin\n\/\/\n\/\/\nend \/\/ end of [emit_f0body]\n\n(* ****** ****** *)\n\nimplement\nemit_f0decl\n (out, fdec) = let\nin\n\/\/\ncase+\nfdec.f0decl_node of\n| F0DECLnone (fhd) =>\n \/\/ does this actually mean function declaration (e.g. forward function decl)?\n {\n val-F0HEAD(id, _, _) = fhd.f0head_node\n val () = f0head_insert (id.i0de_sym, fhd)\n }\n| F0DECLsome (fhd, fbody) =>\n {\n val () = emit_text (out, \".method\")\n val () = emit_SPACE (out)\n val () = emit_text (out, \"static\")\n \/\/ TODO: public\/private?\n \/\/ static -> private\n val () = emit_SPACE (out)\n val () = emit_text (out, \"public\")\n val () = emit_SPACE (out)\n val-F0HEAD(id, _, _) = fhd.f0head_node\n val () = f0head_insert (id.i0de_sym, fhd)\n val () = emit_f0head (out, fhd)\n val () = emit_SPACE (out) \n val () = emit_text (out, \"cil\")\n val () = emit_SPACE (out)\n val () = emit_text (out, \"managed\")\n val () = emit_newline (out)\n val () = emit_f0body (out, fbody)\n val () = emit_newline (out)\n } (* end of [F0DECLsome] *)\n\/\/\nend \/\/ end of [emit_f0decl]\n\n(* ****** ****** *)\n\n\/\/\nextern\nfun\ntyrec_labsel\n (tyrec: tyrec, lab: symbol): int\n\/\/\nimplement\ntyrec_labsel\n (tyrec, lab) = let\n\/\/\nfun loop\n(\n xs: tyfldlst, i: int\n) : int =\n(\ncase+ xs of\n| list_cons (x, xs) => let\n val TYFLD (id, s0e) = x.tyfld_node\n in\n if lab = id.i0de_sym then i else loop (xs, i+1)\n end \/\/ end of [list_cons\n| list_nil ((*void*)) => ~1(*error*)\n)\n\/\/\nin\n loop (tyrec.tyrec_node, 0)\nend \/\/ end of [tyrec_labsel]\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_SELcon\n (out, d0e) = let\n\/\/\nval-ATSSELcon\n (d0rec, s0e, id) = d0e.d0exp_node\nval-S0Eide (name) = s0e.s0exp_node\nval-~Some_vt (s0rec) = typedef_search_opt (name)\n\/\/\nval index = tyrec_labsel (s0rec, id.i0de_sym)\n\/\/\nval () =\n emit_d0exp (out, d0rec)\n\/\/\nval () = emit_LBRACKET (out)\nval () = emit_int (out, index)\nval () = emit_RBRACKET (out)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit_SELcon]\n\n(* ****** ****** *)\n\nimplement\nemit_SELboxrec\n (out, d0e) = let\n\/\/\nval-ATSSELboxrec\n (d0rec, s0e, id) = d0e.d0exp_node\nval-S0Eide (name) = s0e.s0exp_node\nval-~Some_vt (s0rec) = typedef_search_opt (name)\n\/\/\nval index = tyrec_labsel (s0rec, id.i0de_sym)\n\/\/\nval () =\n emit_d0exp (out, d0rec)\n\/\/\nval () = emit_LBRACKET (out)\nval () = emit_int (out, index)\nval () = emit_RBRACKET (out)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit_SELboxrec]\n\n(* ****** ****** *)\n\/\/\n#define\nATSEXTCODE_BEG \"\/*\\nATSextcode_beg()\\n*\/\"\n#define\nATSEXTCODE_END \"\/*\\nATSextcode_end()\\n*\/\"\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_d0ecl\n (out, d0c) = let\nin\n\/\/\ncase+\nd0c.d0ecl_node of\n\/\/\n| D0Cinclude include =>\n {\n val () = emit_text (out, \"#include\")\n val () = emit_SPACE (out)\n val-T_STRING(filnam) = include.token_node\n val () = emit_text (out, filnam)\n val () = emit_newline (out)\n }\n\/\/\n| D0Cifdef (i0de, d0eclist) =>\n {\n val () = emit_text (out, \"#ifdef\")\n val () = emit_SPACE (out)\n val () = emit_i0de (out, i0de)\n val () = emit_newline (out)\n val () = emit_text (out, \"#endif\")\n val () = emit_newline (out)\n }\n| D0Cifndef (i0de, d0eclist) =>\n {\n val () = emit_text (out, \"#ifndef\")\n val () = emit_SPACE (out)\n val () = emit_i0de (out, i0de)\n val () = emit_newline (out)\n val () = emit_text (out, \"#endif\")\n val () = emit_newline (out)\n }\n\/\/\n| D0Ctypedef (id, def) =>\n {\n val () = typedef_insert (id.i0de_sym, def)\n \/\/ TODO: insert type (class) declaration\n } (* end of [D0Ctypedef] *)\n\/\/\n| D0Cassume (id) =>\n {\n val () = emit_text (out, \"\/* ATSassume(\")\n val () = emit_i0de (out, id)\n val () = emit_text (out, \") *\/\\n\")\n }\n\/\/\n| D0Cdyncst_mac ide =>\n \/\/ [ide] is the identifier for a dynamic constant which is implemented as a macro\n ()\n (*\n {\n val () = emit_text (out, \"dyncst_mac\")\n val () = emit_SPACE (out)\n val filnam = ide.i0de_sym\n val () = emit_symbol (out, filnam)\n val () = emit_ENDL (out)\n }*)\n| D0Cdyncst_extfun (i0de, s0explst, s0exp) =>\n {\n }\n\/\/\n| D0Cstatmp\n (tmp, opt) =>\n {\n val () = (\n case+ opt of\n | Some _ => () | None () => emit_text (out, \"\/\/\")\n ) (* end of [val] *)\n val () = (\n emit_i0de (out, tmp)\n ) (* end of [val] *)\n } (* end of [D0Cstatmp] *)\n\/\/\n| D0Cextcode (toks) =>\n {\n val () = emit_text (out, ATSEXTCODE_BEG)\n val () = emit_extcode (out, toks)\n val () = emit_text (out, ATSEXTCODE_END)\n }\n| D0Cclosurerize (_, _, _, _) => ()\n\/\/\n| D0Cfundecl (fk, f0d) => emit_f0decl (out, f0d)\n\/\/\nend \/\/ end of [emit_d0ecl]\n\n(* ****** ****** *)\n\nimplement\nemit2_toplevel\n (out, d0cs, fname, namespace) = let\n\/\/\nfun\nloop\n(\n out: FILEref, d0cs: d0eclist\n) : void =\n(\n\/\/\ncase+ d0cs of\n| list_nil () => ()\n| list_cons\n (d0c, d0cs) => let\n in\n emit_d0ecl (out, d0c); loop (out, d0cs)\n end \/\/ end of [list_cons]\n\/\/\n)\n\/\/\n\/\/ TODO: for the main file, emit assembly manifest (assembly references, etc.)\n\/\/ TODO: for all modules, emit .module extern for other modules?\n\/\/ TODO: handle entry point\n\/\/\nval () = emit_text (out, \".module\")\nval () = emit_SPACE (out)\nval () = emit_text (out, \"'\")\nval () = emit_text (out, fname)\nval () = emit_text (out, \"'\")\nval () = emit_ENDL (out)\n\/\/\nval () = emit_text (out, \".namespace\")\nval () = emit_SPACE (out)\nval () = emit_text (out, namespace)\nval () = emit_SPACE (out)\nval () = emit_LBRACE (out)\nval () = emit_ENDL (out)\n\/\/\nval () = emit_text (out, \".class\")\nval () = emit_SPACE (out)\nval () = emit_MODCLSNAME (out, fname)\nval () = emit_SPACE (out)\nval () = emit_LBRACE (out)\nval () = emit_ENDL (out)\nval () = loop (out, d0cs)\nval () = emit_RBRACE (out) (* end of [class] definition *)\nval () = emit_text (out, \"\/* end of class *\/\")\n\/\/\nval () = emit_ENDL (out)\nval () = emit_RBRACE (out) (* end of [namespace] definition *)\nval () = emit_text (out, \"\/* end of namespace *\/\")\n\/\/\nin\n (*empty*)\nend \/\/ end of [emit2_toplevel]\n\n(* ****** ****** *)\n\n(* end of [atsparemit_emit_cil.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"7db874dd94024febecb259b8a205531342e25d4a","subject":"Updating: very minorly improving","message":"Updating: very minorly improving\n","repos":"githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib","old_file":"contrib\/libatscc\/libatscc2py\/TEST\/PYgame\/test01.dats","new_file":"contrib\/libatscc\/libatscc2py\/TEST\/PYgame\/test01.dats","new_contents":"(* ****** ****** *)\n\/\/\n\/\/ Trying libatscc2py\/Pygame\n\/\/\n(* ****** ****** *)\n\/\/\n(*\n#include\n\"share\/atspre_define.hats\"\n*)\n\/\/\n#include\".\/..\/..\/staloadall.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/..\/..\/SATS\/PYgame\/pygame.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\ntest01_main\n(\n\/\/ argless\n) : void = \"mac#\"\n\/\/\nimplement\ntest01_main() =\n{\n\/\/\nval npnf = pygame_init_ret()\nval ((*void*)) = println! (\"np = \", npnf.0)\nval ((*void*)) = println! (\"nf = \", npnf.1)\n\/\/\nval res = $tup(500,500)\nval screen = display_set_mode(res)\nval _(*Rect*) = screen.fill(Color(0, 0, 0))\n\/\/\nval screen2 = Surface(screen.get_size(), SRCALPHA, 32)\n\/\/\n(*\nval () = println! (\"screen2_width = \", screen2.get_width())\nval () = println! (\"screen2_height = \", screen2.get_height())\n*)\n\/\/\nval c1 = Color(200, 200, 200)\n\/\/\nval r0 = Rect(100, 100, 300, 300)\n\/\/\nval _rect_ = screen2.fill(c1, r0, 0)\n\/\/\nval _rect_ =\n draw_circle(screen2, Color(0,0,0), $tup(250,250), 100)\n\/\/\nval _rect_ =\n screen.blit(screen2, $tup(0, 0))\n\/\/\nval ((*void*)) = display_flip((*void*))\n\/\/\nval () = loop() where\n{\n fun\n loop(): void = let\n val e = event_wait()\n val t = e.type()\n in\n ifcase\n | t = QUIT => ()\n | t = KEYDOWN => ()\n | _(*else*) => loop()\n end \/\/ end of [loop]\n}\n\/\/\nval ((*void*)) = pygame_quit((*void*))\n\/\/\n} (* end of [test01_main] *)\n\/\/\n(* ****** ****** *)\n\n%{^\n######\nfrom libatscc2py_all import *\n######\nfrom ats2py_PYgame_pyame_cats import *\n######\nsys.setrecursionlimit(1000000)\n######\n%} \/\/ end of [%{^]\n\n(* ****** ****** *)\n\n%{$\nif __name__ == '__main__': test01_main()\n%} \/\/ end of [%{$]\n\n(* ****** ****** *)\n\n(* end of [test01.dats] *)\n","old_contents":"(* ****** ****** *)\n\/\/\n\/\/ Trying libatscc2py\/Pygame\n\/\/\n(* ****** ****** *)\n\/\/\n(*\n#include\n\"share\/atspre_define.hats\"\n*)\n\/\/\n#include\".\/..\/..\/staloadall.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/..\/..\/SATS\/PYgame\/pygame.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\ntest01_main\n(\n\/\/ argless\n) : void = \"mac#\"\n\/\/\nimplement\ntest01_main() =\n{\n\/\/\nval npnf = pygame_init_ret()\nval ((*void*)) = println! (\"np = \", npnf.0)\nval ((*void*)) = println! (\"nf = \", npnf.1)\n\/\/\nval res = $tup(500,500)\nval screen = display_set_mode(res)\nval _(*Rect*) = screen.fill(Color(0, 0, 0))\n\/\/\nval screen2 = Surface(screen.get_size(), SRCALPHA, 32)\n\/\/\n(*\nval () = println! (\"screen2_width = \", screen2.get_width())\nval () = println! (\"screen2_height = \", screen2.get_height())\n*)\n\/\/\nval _rect_ =\n draw_rect(screen2, Color(200, 200, 200), Rect(100, 100, 300, 300), 1)\n\/\/\nval _rect_ =\n screen.blit(screen2, $tup(0, 0))\n\/\/\nval ((*void*)) = display_flip((*void*))\n\/\/\nval () = loop() where\n{\n fun\n loop(): void = let\n val e = event_wait()\n val t = e.type()\n in\n ifcase\n | t = QUIT => ()\n | t = KEYDOWN => ()\n | _(*else*) => loop()\n end \/\/ end of [loop]\n}\n\/\/\nval ((*void*)) = pygame_quit((*void*))\n\/\/\n} (* end of [test01_main] *)\n\/\/\n(* ****** ****** *)\n\n%{^\n######\nfrom libatscc2py_all import *\n######\nfrom ats2py_PYgame_pyame_cats import *\n######\nsys.setrecursionlimit(1000000)\n######\n%} \/\/ end of [%{^]\n\n(* ****** ****** *)\n\n%{$\nif __name__ == '__main__': test01_main()\n%} \/\/ end of [%{$]\n\n(* ****** ****** *)\n\n(* end of [test01.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"6f6321f1d3db55f5a39383587e1dce76df60191a","subject":"Updating: very minorly improving","message":"Updating: very minorly improving\n","repos":"githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib","old_file":"projects\/MEDIUM\/M-Check\/SCRATCH\/ClientServer-1.dats","new_file":"projects\/MEDIUM\/M-Check\/SCRATCH\/ClientServer-1.dats","new_contents":"(* ****** ****** *)\n\/\/\n\/\/ Author: Hongwei Xi\n\/\/ Authoremail: gmhwxiATgmailDOTcom\n\/\/ Start time: February, 2016\n\/\/\n(* ****** ****** *)\n\/\/\n\/\/ Following a Promela-example in\n\/\/ (Spin Model Checker Primer Reference)\n\/\/\n(* ****** ****** *)\n \n(*\nproctype\nAgent(chan listen; chan talk)\n{\n do\n :: talk!hold(listen)\n :: talk!deny(listen) -> break\n :: talk!grant(listen) ->\n wait:\n listen?return0; break\n od;\n server!return0(listen)\n}\n*)\n \n(* ****** ****** *)\n\nabstype channel\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nchannel_recv{a:type}(channel): a\nextern\nfun\nchannel_send{a:type}(channel, a): void\n\/\/\nextern\nfun\nchannel_create(cap: intGte(0)): channel\n\/\/\n(* ****** ****** *)\n\nextern\nfun\nchannel_is_empty : channel -> bool\nextern\nfun\nchannel_isnot_empty : channel -> bool\n\n(* ****** ****** *)\n\/\/\ndatatype\nClientOpt =\n| DENY of ()\n| DENY of (channel)\n| HOLD of (channel)\n| GRANT of (channel)\n\/\/\ndatatype\nClientReply = RETURN0 of ()\n\/\/\ndatatype\nServerOpt =\n | RETURN0 of (channel)\n | REQUEST0 of (channel)\n\/\/\n(* ****** ****** *)\n\/\/\nval\ntheServer = channel_create(0)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nAgent\n(\n agent: channel, client: channel\n) : void \/\/ end of [Agent]\n\/\/\n(* ****** ****** *)\n\nextern val RAND: int\n\n(* ****** ****** *)\n\/\/\nimplement\nAgent(agent, client) = let\n\/\/\nfun\nloop\n( agent: channel\n, client: channel\n) : void = (\n\/\/\ncase RAND of\n| 0 => let\n val () =\n channel_send(client, HOLD(agent))\n in\n loop(agent, client)\n end \/\/ end of [_]\n| 1 =>\n channel_send(client, DENY(agent))\n| _ => let\n val () =\n channel_send(client, GRANT(agent))\n val-RETURN0() =\n channel_recv{ClientReply}(agent)\n \/\/ end of [val]\n in\n \/\/ break\n end \/\/ end of [_]\n\/\/\n) (* end of [loop] *)\n\/\/\nval () = loop(agent, client)\n\/\/\nin\n channel_send(theServer, agent)\nend \/\/ end of [Agent]\n\/\/\n(* ****** ****** *)\n\n(*\n#define M 2\nactive [M] proctype Client()\n{\n chan me = [0] of { mtype, chan };\n chan agent;\nend:\n do\n :: timeout ->\n server!request(me);\n do\n :: me?hold(agent)\n :: me?deny(agent) -> break\n :: me?grant(agent) -> agent!return0; break\n od\n od\n}\n*) \n\n(* ****** ****** *)\n\/\/\nextern\nfun Client(): void\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nClient() = let\n\/\/\nfun\nloop\n(\n client: channel\n) : void =\n(\n\/\/\ncase+ RAND of\n| _ => let\n val () =\n channel_send(theServer, REQUEST0(client))\n in\n loop2(client)\n end \/\/ end of [loop]\n\/\/\n) (* end of [loop] *)\n\/\/\nand\nloop2\n(\n client: channel\n) : void = let\n val opt = channel_recv{ClientOpt}(client)\nin\n\/\/\ncase+ opt of\n| DENY() => ()\n| DENY(agent) => ()\n| HOLD(agent) => loop2(client)\n| GRANT(agent) => channel_send(agent, RETURN0())\n\/\/\nend \/\/ end of [loop2]\n\/\/\nin\n loop(channel_create(0))\nend \/\/ end of [Client]\n\n(* ****** ****** *)\n\n(*\nactive\nproctype Server()\n{\n chan agents[N] = [0] of { mtype };\n chan pool = [N] of { chan };\n chan client, agent;\n byte i;\n do\n :: i < N -> pool!agents[i]; i++\n :: else -> break\n od;\n end:\n do\n :: server?request(client) ->\n if\n :: empty(pool) ->\n client!deny(0)\n :: nempty(pool) ->\n pool?agent;\n run Agent(agent,client)\n fi\n :: server?return0(agent) ->\n pool!agent\n od\n}\n*)\n\n(* ****** ****** *)\n\/\/\nextern\nfun Server((*void*)): void\n\/\/\nimplement\nServer() = let\n\/\/\nfun\nloop\n(\n pool: channel\n) : void = let\n\/\/\nval\nopt =\nchannel_recv{ServerOpt}(theServer)\n\/\/\nin\n\/\/\ncase+ opt of\n| RETURN0(agent) => let\n val () =\n channel_send{channel}(pool, agent)\n in\n loop(pool)\n end \/\/ end of [RETURN0]\n| REQUEST0(client) =>\n if channel_isnot_empty(pool)\n then let\n val agent =\n channel_recv{channel}(pool)\n \/\/ end of [val]\n val () = Agent(agent, client)\n in\n loop(pool)\n end \/\/ end of [then]\n else let\n val () =\n channel_send(client, DENY((*void*)))\n in\n loop(pool)\n end \/\/ end of [else]\n\/\/ \nend \/\/ end of [loop]\n\/\/\nval\npool = channel_create(5)\n\/\/\nin\n loop(pool)\nend \/\/ end of [Server]\n\/\/\n(* ****** ****** *)\n\n(* end of [ClientServer-1.dats] *)\n","old_contents":"(* ****** ****** *)\n\/\/\n\/\/ Author: Hongwei Xi\n\/\/ Authoremail: gmhwxiATgmailDOTcom\n\/\/ Start time: February, 2016\n\/\/\n(* ****** ****** *)\n\/\/\n\/\/ Following a Promela-example in\n\/\/ (Spin Model Checker Primer Reference)\n\/\/\n(* ****** ****** *)\n \n(*\nproctype\nAgent(chan listen; chan talk)\n{\n do\n :: talk!hold(listen)\n :: talk!deny(listen) -> break\n :: talk!grant(listen) ->\n wait:\n listen?return0; break\n od;\n server!return0(listen)\n}\n*)\n \n(* ****** ****** *)\n\nabstype channel\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nchannel_recv{a:type}(channel): a\nextern\nfun\nchannel_send{a:type}(channel, a): void\n\/\/\nextern\nfun\nchannel_create(cap: intGte(0)): channel\n\/\/\n(* ****** ****** *)\n\nextern\nfun\nchannel_is_empty : channel -> bool\nextern\nfun\nchannel_isnot_empty : channel -> bool\n\n(* ****** ****** *)\n\/\/\ndatatype\nAgentReply =\n| DENY of ()\n| DENY of (channel)\n| HOLD of (channel)\n| GRANT of (channel)\n\/\/\ndatatype\nClientReply = RETURN0 of ()\n\/\/\ndatatype\nServerOpt =\n | RETURN0 of (channel)\n | REQUEST0 of (channel)\n\/\/\n(* ****** ****** *)\n\/\/\nval\ntheServer = channel_create(0)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nAgent\n(\n agent: channel, client: channel\n) : void \/\/ end of [Agent]\n\/\/\n(* ****** ****** *)\n\nextern val RAND: int\n\n(* ****** ****** *)\n\/\/\nimplement\nAgent(agent, client) = let\n\/\/\nfun\nloop\n( agent: channel\n, client: channel\n) : void = (\n\/\/\ncase RAND of\n| 0 => let\n val () =\n channel_send(client, HOLD(agent))\n in\n loop(agent, client)\n end \/\/ end of [_]\n| 1 =>\n channel_send(client, DENY(agent))\n| _ => let\n val () =\n channel_send(client, GRANT(agent))\n val-RETURN0() =\n channel_recv{ClientReply}(agent)\n \/\/ end of [val]\n in\n \/\/ break\n end \/\/ end of [_]\n\/\/\n) (* end of [loop] *)\n\/\/\nval () = loop(agent, client)\n\/\/\nin\n channel_send(theServer, agent)\nend \/\/ end of [Agent]\n\/\/\n(* ****** ****** *)\n\n(*\n#define M 2\nactive [M] proctype Client()\n{\n chan me = [0] of { mtype, chan };\n chan agent;\nend:\n do\n :: timeout ->\n server!request(me);\n do\n :: me?hold(agent)\n :: me?deny(agent) -> break\n :: me?grant(agent) -> agent!return0; break\n od\n od\n}\n*) \n\n(* ****** ****** *)\n\/\/\nextern\nfun Client(): void\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nClient() = let\n\/\/\nfun\nloop\n(\n client: channel\n) : void =\n(\n\/\/\ncase+ RAND of\n| _ => let\n val () =\n channel_send(theServer, REQUEST0(client))\n in\n loop2(client)\n end \/\/ end of [loop]\n\/\/\n) (* end of [loop] *)\n\/\/\nand\nloop2\n(\n client: channel\n) : void = let\n val opt = channel_recv{AgentReply}(client)\nin\n\/\/\ncase+ opt of\n| DENY() => ()\n| DENY(agent) => ()\n| HOLD(agent) => loop2(client)\n| GRANT(agent) => channel_send(agent, RETURN0())\n\/\/\nend \/\/ end of [loop2]\n\/\/\nin\n loop(channel_create(0))\nend \/\/ end of [Client]\n\n(* ****** ****** *)\n\n(*\nactive\nproctype Server()\n{\n chan agents[N] = [0] of { mtype };\n chan pool = [N] of { chan };\n chan client, agent;\n byte i;\n do\n :: i < N -> pool!agents[i]; i++\n :: else -> break\n od;\n end:\n do\n :: server?request(client) ->\n if\n :: empty(pool) ->\n client!deny(0)\n :: nempty(pool) ->\n pool?agent;\n run Agent(agent,client)\n fi\n :: server?return0(agent) ->\n pool!agent\n od\n}\n*)\n\n(* ****** ****** *)\n\/\/\nextern\nfun Server((*void*)): void\n\/\/\nimplement\nServer() = let\n\/\/\nfun\nloop\n(\n pool: channel\n) : void = let\n\/\/\nval\nopt =\nchannel_recv{ServerOpt}(theServer)\n\/\/\nin\n\/\/\ncase+ opt of\n| RETURN0(agent) => let\n val () =\n channel_send{channel}(pool, agent)\n in\n loop(pool)\n end \/\/ end of [RETURN0]\n| REQUEST0(client) =>\n if channel_isnot_empty(pool)\n then let\n val agent =\n channel_recv{channel}(pool)\n \/\/ end of [val]\n val () = Agent(agent, client)\n in\n loop(pool)\n end \/\/ end of [then]\n else let\n val () =\n channel_send(client, DENY((*void*)))\n in\n loop(pool)\n end \/\/ end of [else]\n\/\/ \nend \/\/ end of [loop]\n\/\/\nval\npool = channel_create(5)\n\/\/\nin\n loop(pool)\nend \/\/ end of [Server]\n\/\/\n(* ****** ****** *)\n\n(* end of [ClientServer-1.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"be381b010d95d0c33380d40c78eb25ade1962d0e","subject":"Updating: very minorly improving","message":"Updating: very minorly improving\n","repos":"ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib","old_file":"contrib\/libatscc\/libatscc2js\/TEST\/Worker\/test3_client.dats","new_file":"contrib\/libatscc\/libatscc2js\/TEST\/Worker\/test3_client.dats","new_contents":"(* ****** ****** *)\n\/\/\n\/\/ Testing WebWorker\n\/\/\n(* ****** ****** *)\n\n#define ATS_DYNLOADFLAG 0\n\n(* ****** ****** *)\n \n#include\n\"share\/atspre_define.hats\"\n#include\n\"{$LIBATSCC2JS}\/staloadall.hats\"\n \n(* ****** ****** *)\n\nstaload \"libats\/ML\/SATS\/basis.sats\"\n\n(* ****** ****** *)\n\nstaload\nUN = \"prelude\/SATS\/unsafe.sats\"\n\n(* ****** ****** *)\n\/\/\nstaload\n\"{$LIBATSCC2JS}\/SATS\/Worker\/channel.sats\"\nstaload\n\"{$LIBATSCC2JS}\/DATS\/Worker\/channel.dats\"\n#include\n\"{$LIBATSCC2JS}\/DATS\/Worker\/channeg.dats\"\n\/\/\n(* ****** ****** *)\n\n%{^\n\/\/\nfunction\ntheArg1_set(a1)\n{\n document.getElementById('theArg1').value = a1;\n}\nfunction\ntheArg2_set(a2)\n{\n document.getElementById('theArg2').value = a2;\n}\nfunction\ntheResult_get()\n{\n return parseInt(document.getElementById('theResult').value);\n}\nfunction\ntheResult_set(value)\n{\n document.getElementById('theResult').value = value;\n}\n\/\/\nfunction\ntheArg1Arg2Result_clear()\n{\n document.getElementById('theArg1').value = \"\";\n document.getElementById('theArg2').value = \"\";\n document.getElementById('theResult').value = \"\";\n}\n\/\/\n%} \/\/ end of [%{^]\n\n(* ****** ****** *)\n\n%{^\n\/\/\nvar\nStarted = false;\n\/\/\nfunction\nStart_onclick()\n{\n if (!Started)\n {\n Started = true; return StartIt();\n } else\n {\n alert ('The session is in progress!'); return;\n }\n}\n\/\/\nvar\nAnswerIt = 0;\nvar\nAnswerIt_do = 0;\n\/\/\nfunction\nAnswerIt_onclick()\n{\n if (AnswerIt)\n {\n AnswerIt = 0;\n return ats2jspre_cloref0_app(AnswerIt_do);\n } else {\n alert('The AnswerIt button is not ready yet!'); return;\n } \/\/ end of [if]\n}\n\/\/\nfunction\nAnswerIt_do_set(fclo)\n { AnswerIt = 1; AnswerIt_do = fclo; return; }\n\/\/\n%} \/\/ end of [%{^]\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\nPROTOCOL = \".\/test3_prot.sats\"\n\/\/\ntypedef sstest1 = $PROTOCOL.sstest1\ntypedef sstest2 = $PROTOCOL.sstest2\ntypedef sstest3 = $PROTOCOL.sstest3\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nStartIt(): void = \"mac#\"\n\/\/\nextern\nfun\nPostRep\n(\n channeg(chnil), k0: chncont0_nil, n: int, yn: bool\n) : void = \"mac#\" \/\/ end-of-fun\nextern\nfun\nReplyIt\n(\n channeg(sstest1), k0: chncont0_nil, n: int, a1: int, a2: int\n) : void = \"mac#\" \/\/ end-of-fun\nextern\nfun\nReplyIt_repeat\n(\n channeg(ssdisj(ssrepeat(sstest1))), k0: chncont0_nil, a1: int, a2: int\n) : void = \"mac#\" \/\/ end-of-fun\n\/\/\nextern\nfun\nStartIt_aft\n (chn: channeg(ssdisj(ssrepeat(sstest2)))): void\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nStartIt() = let\n\/\/\nval\nchn =\nchanneg0_new_file(\".\/test3_server_dats_.js\")\n\/\/\nval\nchn = $UN.castvwtp0{channeg(sstest3)}(chn)\n\/\/\nin\n\/\/\nchanneg1_recv(chn, 0, lam(chn) => StartIt_aft(chn))\n\/\/\nend \/\/ end of [Start_onclick]\n\n(* ****** ****** *)\n\nimplement\nStartIt_aft\n (chn) = let\n\/\/\nval k0 =\nlam(chn: channeg_nil) =\n let extvar \"Started\" = false in channeg1_close(chn) end\n\/\/\nimplement\nchanneg1_repeat_disj$fwork_tag<>\n (tag) =\n(\n if tag = 0 then\n {\n val () =\n $extfcall(void, \"theArg1Arg2Result_clear\")\n val () = alert(\"The session of multiplcation test is over!\")\n }\n)\n\/\/\nin\n\/\/\nchanneg1_repeat_disj\n(\n chn, k0\n, lam(chn, k0) =>\n channeg1_send\n ( chn\n , lam(chn, a1) =>\n channeg1_send\n ( chn\n , lam(chn, a2) =>\n ReplyIt_repeat(chn, k0, chmsg_parse(a1), chmsg_parse(a2))\n )\n )\n)\n\/\/\nend \/\/ end of [StartIt_aft]\n\n(* ****** ****** *)\n\nimplement\nReplyIt\n (chn, k0, n, a1, a2) = let\n\/\/\nval () =\n $extfcall(void, \"theArg1_set\", a1)\nval () =\n $extfcall(void, \"theArg2_set\", a2)\n\/\/\nval () =\n $extfcall(void, \"theResult_set\", \"\")\n\/\/\nval\nReplyIt_do =\nllam() = let\n val res = $extfcall(int, \"theResult_get\")\nin\n\/\/\nchanneg1_recv\n( chn, res\n, lam(chn) =>\n channeg1_send\n ( chn\n , lam(chn, yn) => PostRep(chn, k0, n, chmsg_parse(yn))\n )\n)\n\/\/\nend \/\/ end of [ReplyIt_do]\n\/\/\nin\n\/\/\n$extfcall\n(\n void , \"AnswerIt_do_set\", $UN.castvwtp0{JSobj}(ReplyIt_do)\n)\n\/\/\nend \/\/ end of [ReplyIt]\n\n(* ****** ****** *)\n\nimplement\nPostRep(chn, k0, n, yn) = let\n\/\/\n val () = k0(chn)\n\/\/\nin\n if yn\n then alert(\"The replied answer is right :)\")\n else (if n >= 3 then alert(\"The replied answer is wrong :(\"))\n \/\/ end of [if]\nend \/\/ end of [PostRep]\n\n(* ****** ****** *)\n\nimplement\nReplyIt_repeat\n (chn, k0, a1, a2) = let\n\/\/\nval N = ref{int}(0)\n\/\/\nimplement\nchanneg1_repeat_disj$fwork_tag<>\n (tag) = let\n val n = N[]\n val () = N[] := n + 1\nin\n case+ tag of\n | 0 => ()\n | _ => if n > 0 then alert(\"Please try again!\")\nend \/\/ end of ...\n\/\/\nin\n\/\/\nchanneg1_repeat_disj\n(\n chn, k0, lam(chn, k0) => ReplyIt(chn, k0, N[], a1, a2)\n)\n\/\/\nend (* end of [ReplyIt_repeat] *)\n\n(* ****** ****** *)\n\n(* end of [test3_client.dats] *)\n","old_contents":"(* ****** ****** *)\n\/\/\n\/\/ Testing WebWorker\n\/\/\n(* ****** ****** *)\n\n#define ATS_DYNLOADFLAG 0\n\n(* ****** ****** *)\n \n#include\n\"share\/atspre_define.hats\"\n#include\n\"{$LIBATSCC2JS}\/staloadall.hats\"\n \n(* ****** ****** *)\n\nstaload \"libats\/ML\/SATS\/basis.sats\"\n\n(* ****** ****** *)\n\nstaload\nUN = \"prelude\/SATS\/unsafe.sats\"\n\n(* ****** ****** *)\n\/\/\nstaload\n\"{$LIBATSCC2JS}\/SATS\/Worker\/channel.sats\"\nstaload\n\"{$LIBATSCC2JS}\/DATS\/Worker\/channel.dats\"\n#include\n\"{$LIBATSCC2JS}\/DATS\/Worker\/channeg.dats\"\n\/\/\n(* ****** ****** *)\n\n%{^\n\/\/\nfunction\ntheArg1_set(a1)\n{\n document.getElementById('theArg1').value = a1;\n}\nfunction\ntheArg2_set(a2)\n{\n document.getElementById('theArg2').value = a2;\n}\nfunction\ntheResult_get()\n{\n return parseInt(document.getElementById('theResult').value);\n}\nfunction\ntheResult_set(value)\n{\n document.getElementById('theResult').value = value;\n}\n\/\/\nfunction\ntheArg1Arg2Result_clear()\n{\n document.getElementById('theArg1').value = \"\";\n document.getElementById('theArg2').value = \"\";\n document.getElementById('theResult').value = \"\";\n}\n\/\/\n%} \/\/ end of [%{^]\n\n(* ****** ****** *)\n\n%{^\n\/\/\nvar\nStarted = false;\n\/\/\nfunction\nStart_onclick()\n{\n if (!Started)\n {\n Started = true; return StartIt();\n } else\n {\n alert ('The session is in progress!'); return;\n }\n}\n\/\/\nvar\nAnswerIt = 0;\nvar\nAnswerIt_do = 0;\n\/\/\nfunction\nAnswerIt_onclick()\n{\n if (AnswerIt)\n {\n AnswerIt = 0;\n return ats2jspre_cloref0_app(AnswerIt_do);\n } else {\n alert('The AnswerIt button is not ready yet!'); return;\n } \/\/ end of [if]\n}\n\/\/\nfunction\nAnswerIt_do_set(fclo)\n { AnswerIt = 1; AnswerIt_do = fclo; return; }\n\/\/\n%} \/\/ end of [%{^]\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\nPROTOCOL = \".\/test3_prot.sats\"\n\/\/\ntypedef sstest1 = $PROTOCOL.sstest1\ntypedef sstest2 = $PROTOCOL.sstest2\ntypedef sstest3 = $PROTOCOL.sstest3\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nStartIt(): void = \"mac#\"\n\/\/\nextern\nfun\nPostRep\n(\n channeg(chnil), k0: chncont0_nil, n: int, yn: bool\n) : void = \"mac#\" \/\/ end-of-fun\nextern\nfun\nReplyIt\n(\n channeg(sstest1), k0: chncont0_nil, n: int, a1: int, a2: int\n) : void = \"mac#\" \/\/ end-of-fun\nextern\nfun\nReplyIt_repeat\n(\n channeg(ssdisj(ssrepeat(sstest1))), k0: chncont0_nil, a1: int, a2: int\n) : void = \"mac#\" \/\/ end-of-fun\n\/\/\nextern\nfun\nStartIt_aft\n (chn: channeg(ssdisj(ssrepeat(sstest2)))): void\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nStartIt() = let\n\/\/\nval\nchn =\nchanneg0_new_file(\".\/test3_server_dats_.js\")\n\/\/\nval\nchn = $UN.castvwtp0{channeg(sstest3)}(chn)\n\/\/\nin\n\/\/\nchanneg1_recv(chn, 0, lam(chn) => StartIt_aft(chn))\n\/\/\nend \/\/ end of [Start_onclick]\n\n(* ****** ****** *)\n\nimplement\nStartIt_aft\n (chn) = let\n\/\/\nval k0 =\nlam(chn: channeg_nil) =\n let extvar \"Started\" = false in channeg1_close(chn) end\n\/\/\nimplement\nchanneg1_repeat_disj$fwork_tag<>\n (tag) =\n(\n if tag = 0 then\n {\n val () =\n $extfcall(void, \"theArg1Arg2Result_clear\")\n val () = alert(\"The session of multiplcation test is over!\")\n }\n)\n\/\/\nin\n\/\/\nchanneg1_repeat_disj\n(\n chn, k0\n, lam(chn, k0) =>\n channeg1_send\n ( chn\n , lam(chn, a1) =>\n channeg1_send\n ( chn\n , lam(chn, a2) =>\n ReplyIt_repeat(chn, k0, chmsg_parse(a1), chmsg_parse(a2))\n )\n )\n)\n\/\/\nend \/\/ end of [StartIt_aft]\n\n(* ****** ****** *)\n\nimplement\nReplyIt\n (chn, k0, n, a1, a2) = let\n\/\/\nval () =\n $extfcall(void, \"theArg1_set\", a1)\nval () =\n $extfcall(void, \"theArg2_set\", a2)\n\/\/\nval () =\n $extfcall(void, \"theResult_set\", \"\")\n\/\/\nval\nReplyIt_do =\nllam() = let\n val res = $extfcall(int, \"theResult_get\")\nin\n\/\/\nchanneg1_recv\n( chn, res\n, lam(chn) =>\n channeg1_send\n ( chn\n , lam(chn, yn) => PostRep(chn, k0, n, chmsg_parse(yn))\n )\n)\n\/\/\nend \/\/ end of [ReplyIt_do]\n\/\/\nin\n\/\/\n$extfcall\n(\n void , \"AnswerIt_do_set\", $UN.castvwtp0{JSobj}(ReplyIt_do)\n)\n\/\/\nend \/\/ end of [ReplyIt]\n\n(* ****** ****** *)\n\nimplement\nPostRep(chn, k0, n, yn) = let\n\/\/\n val () = k0(chn)\n\/\/\nin\n if yn\n then alert(\"The replied answer is right :)\")\n else (if n >= 3 then alert(\"The replied answer is wrong :(\"))\n \/\/ end of [if]\nend \/\/ end of [PostRep]\n\n(* ****** ****** *)\n\nimplement\nReplyIt_repeat\n (chn, k0, a1, a2) = let\n\/\/\nval N = ref{int}(0)\n\/\/\nimplement\nchanneg1_repeat_disj$fwork_tag<>\n (tag) = let\n val n = N[]\n val () = N[] := n + 1\nin\n case+ tag of\n | 0 => ()\n | _ => if n > 0 then alert(\"Please try gain!\")\nend \/\/ end of ...\n\/\/\nin\n\/\/\nchanneg1_repeat_disj\n(\n chn, k0, lam(chn, k0) => ReplyIt(chn, k0, N[], a1, a2)\n)\n\/\/\nend (* end of [ReplyIt_repeat] *)\n\n(* ****** ****** *)\n\n(* end of [test3_client.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"aa7d3d7c5625cd8944a413a2b56bf9bff67d37f3","subject":"Various improvements to atsparemit-CIL. Still untested.","message":"Various improvements to atsparemit-CIL.\nStill untested.\n","repos":"ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,master-q\/ATS-Postiats-contrib","old_file":"projects\/MEDIUM\/ATS-parse-emit\/CIL\/atsparemit_emit_cil.dats","new_file":"projects\/MEDIUM\/ATS-parse-emit\/CIL\/atsparemit_emit_cil.dats","new_contents":"(* ****** ****** *)\n\/\/\n\/\/ ATS-parse-emit-python\n\/\/\n(* ****** ****** *)\n\/\/\n\/\/ AS-2014-08-17: start\n\/\/\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_staload.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\nUN = \"prelude\/SATS\/unsafe.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/atsparemit.sats\"\nstaload \".\/atsparemit_syntax.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/atsparemit_emit.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/atsparemit_topenv.dats\"\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_ENDL (out) = emit_text (out, \"\\n\")\n\n(* ****** ****** *)\n\nimplement\nemit_SPACE (out) = emit_text (out, \" \")\n\n(* ****** ****** *)\n\nimplement\nemit_SHARP (out) = emit_text (out, \"#\")\n\n(* ****** ****** *)\n\nimplement\nemit_LPAREN (out) = emit_text (out, \"(\")\nimplement\nemit_RPAREN (out) = emit_text (out, \")\")\n\n(* ****** ****** *)\n\nimplement\nemit_LBRACE (out) = emit_text (out, \"{\")\nimplement\nemit_RBRACE (out) = emit_text (out, \"}\")\n\n\n(* ****** ****** *)\n\nimplement\nemit_LBRACKET (out) = emit_text (out, \"[\")\nimplement\nemit_RBRACKET (out) = emit_text (out, \"]\")\n\n(* ****** ****** *)\n\nimplement\nemit_flush (out) = fileref_flush (out)\nimplement\nemit_newline (out) = fprint_newline (out)\n\n(* ****** ****** *)\n\/\/\nimplement\nemit_int (out, x) = fprint_int (out, x)\n\/\/\nimplement\nemit_text (out, x) = fprint_string (out, x)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nemit_symbol (out, x) =\n fprint_string (out, symbol_get_name (x))\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_PMVint\n (out, tok) = let\n\/\/\nval-T_INT(base, rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVint]\n\n(* ****** ****** *)\n\nimplement\nemit_PMVi0nt\n (out, tok) = let\n\/\/\nval-T_INT(base, rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVi0nt]\n\n(* ****** ****** *)\n\/\/\nimplement\nemit_PMVbool\n (out, tfv) =\n(\n emit_text (out, if tfv then \"1\" else \"0\")\n) (* end of [emit_PMVbool] *)\n\/\/\n(* ****** ****** *)\nimplement\nemit_PMVstring\n (out, tok) = let\n\/\/\nval-T_STRING(rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVstring]\n\n(* ****** ****** *)\n\/\/\nimplement\nemit_i0de\n (out, id) = emit_symbol (out, id.i0de_sym)\nimplement\nemit_label\n (out, lab) = emit_symbol (out, lab.i0de_sym)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun emit_instrlst\n (out: FILEref, inss: instrlst) : void\n\/\/\nextern\nfun\nemit_s0exp : emit_type (s0exp)\nextern\nfun\nemit_s0explst : emit_type (s0explst)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nemit_s0exp\n (out, s0e) = let\n\/\/\n\/\/\nin\n\/\/\ncase+\ns0e.s0exp_node of\n\/\/\n| S0Eide (id) => emit_symbol (out, id)\n| S0Elist (s0es) => () \/\/ shouldn't happen? marked as \"temp\"\n| S0Eappid (id, s0es) =>\n \/\/ FIXME: what about other types? e.g. array types? struct types?\n () where {\n val () = emit_symbol (out, id)\n val () = emit_LPAREN (out)\n val () = emit_s0explst (out, s0es)\n val () = emit_RPAREN (out)\n }\n\/\/\nend \/\/ end of [emit_s0exp]\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_s0explst\n (out, s0es) = let\n\/\/\nfun\nloop\n(\n out: FILEref, s0es: s0explst, i: int\n) : void =\n(\ncase+ s0es of\n| list_nil () => ()\n| list_cons (s0e, s0es) => let\n val () =\n if i > 0 then emit_text (out, \", \")\n \/\/ end of [val]\n in\n emit_s0exp (out, s0e); loop (out, s0es, i+1)\n end \/\/ end of [list_cons]\n)\n\/\/\nin\n loop (out, s0es, 0)\nend \/\/ end of [emit_s0explst]\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nfunlab_get_index (fl: label): int\nextern\nfun\ntmplab_get_index (lab: label): int\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_f0arglst_get (): f0arglst\nextern\nfun\nthe_f0arglst_set (f0as: f0arglst): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_tmpdeclst_get (): tmpdeclst\nextern\nfun\nthe_tmpdeclst_set (tds: tmpdeclst): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_funbodylst_get (): instrlst\nextern\nfun\nthe_funbodylst_set (inss: instrlst): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_branchlablst_get (): labelist\nextern\nfun\nthe_branchlablst_set (labs: labelist): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_caseofseqlst_get (): instrlst\nextern\nfun\nthe_caseofseqlst_set (inss: instrlst): void\n\/\/\n(* ****** ****** *)\n\nlocal\n\/\/\nval the_f0arglst = ref (list_nil)\nval the_tmpdeclst = ref (list_nil)\n\/\/\nval the_funbodylst = ref (list_nil)\n\/\/\nval the_branchlablst = ref (list_nil)\nval the_caseofseqlst = ref (list_nil)\n\/\/\nin (* in-of-local *)\n\nimplement\nthe_f0arglst_get () = !the_f0arglst\nimplement\nthe_f0arglst_set (xs) = !the_f0arglst := xs\n\nimplement\nthe_tmpdeclst_get () = !the_tmpdeclst\nimplement\nthe_tmpdeclst_set (xs) = !the_tmpdeclst := xs\n\nimplement\nthe_funbodylst_get () = !the_funbodylst\nimplement\nthe_funbodylst_set (xs) = !the_funbodylst := xs\n\nimplement\nthe_branchlablst_get () = !the_branchlablst\nimplement\nthe_branchlablst_set (xs) = !the_branchlablst := xs\n\nimplement\nthe_caseofseqlst_get () = !the_caseofseqlst\nimplement\nthe_caseofseqlst_set (xs) = !the_caseofseqlst := xs\n\nend \/\/ end of [local]\n\n(* ******* ****** *)\n\nlocal\n\nfun\nloop\n(\n out: FILEref, d0es: d0explst, i: int\n) : void =\n(\ncase+ d0es of\n| list_nil () => ()\n| list_cons (d0e, d0es) => let\n val () =\n if i > 0 then emit_newline (out)\n \/\/ end of [val]\n in\n emit_d0exp (out, d0e);\n emit_newline (out);\n loop (out, d0es, i+1)\n end \/\/ end of [list_cons]\n)\n\nin (* in-of-local *)\n\nimplement\nemit_d0explst (out, d0es) = loop (out, d0es, 0)\nimplement\nemit_d0explst_1 (out, d0es) = loop (out, d0es, 1)\n\nend \/\/ end of [local]\n\n(* ******* ****** *)\n\nimplement\nemit_d0exp\n (out, d0e) = let\nin\n\/\/\ncase+\nd0e.d0exp_node of\n\/\/\n| D0Eide (id) =>\n {\n val () = emit_text (out, \"ldloc\")\n val () = emit_SPACE (out)\n val () = emit_symbol (out, id)\n }\n\/\/\n| D0Eappid (id, d0es) =>\n {\n val () = emit_d0explst (out, d0es)\n val () = emit_text (out, \"call\")\n val () = emit_SPACE (out)\n val () = emit_symbol (out, id) \/\/ FIXME: need also type of [id]!\n }\n\/\/\n\/\/\n| ATSPMVint (tok) =>\n {\n val () = emit_text (out, \"ldc.i4\")\n val () = emit_SPACE (out)\n val () = emit_PMVint (out, tok)\n } (* end of [ATSPMVint] *)\n| ATSPMVi0nt (tok) =>\n {\n val () = emit_text (out, \"ldc.i4\")\n val () = emit_SPACE (out)\n val () = emit_PMVi0nt (out, tok)\n } (* end of [ATSPMVi0nt] *)\n\/\/\n| ATSPMVbool (tfv) =>\n {\n val () = emit_text (out, \"ldc.i4\")\n val () = emit_SPACE (out)\n val () = emit_PMVbool (out, tfv)\n } (* end of [ATSPMVbool] *)\n\/\/\n| ATSPMVstring (tok) =>\n {\n val () = emit_text (out, \"ldstr\")\n val () = emit_SPACE(out)\n val () = emit_PMVstring (out, tok)\n } (* end of [ATSPMVstring] *)\n\/\/\n| ATSPMVf0loat (tok) => emit_text (out, \"ATSPMVf0loat(...)\")\n\/\/\n| _ => ()\n\/\/\nend \/\/ end of [emit_d0exp]\n\n(* ****** ****** *)\n\/\/\nextern\nfun emit_f0arg : emit_type (f0arg)\nextern\nfun emit_f0marg : emit_type (f0marg)\nextern\nfun emit_f0head : emit_type (f0head)\n\/\/\nextern\nfun emit_f0body : emit_type (f0body)\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_f0arg\n (out, f0a) = let\nin\n\/\/\ncase+\nf0a.f0arg_node of\n\/\/\n| F0ARGnone s0e => emit_text (out, \"__NONE__\") \/\/ FIXME: how to emit type decl?\n| F0ARGsome (id, s0e) =>\n {\n val () = emit_s0exp (out, s0e)\n val () = emit_SPACE (out)\n val () = emit_i0de (out, id)\n } (* end of [F0ARGsome] *)\n\/\/\nend \/\/ end of [emit_f0arg]\n\n(* ****** ****** *)\n\nimplement\nemit_f0marg\n (out, f0ma) = let\n\/\/\nfun\nloop\n(\n out: FILEref, f0as: f0arglst, i: int\n) : void =\n(\ncase+ f0as of\n| list_nil () => ()\n| list_cons (f0a, f0as) => let\n val () =\n if i > 0 then emit_text (out, \", \")\n \/\/ end of [val]\n in\n emit_f0arg (out, f0a); loop (out, f0as, i+1)\n end \/\/ end of [list_cons]\n)\n\/\/\nin\n loop (out, f0ma.f0marg_node, 0)\nend \/\/ end of [emit_f0marg]\n\n(* ****** ****** *)\n\nimplement\nemit_f0head\n (out, fhd) = let\n\/\/\nval f0as =\n f0head_get_f0arglst (fhd)\n\/\/\nval () = the_f0arglst_set (f0as)\n\/\/\nin\n\/\/\ncase+\nfhd.f0head_node of\n| F0HEAD\n (id(*name of function*), f0ma(*list of arguments*), res(*result type*)) =>\n {\n val () = emit_s0exp (out, res)\n val () = emit_SPACE (out)\n val () = emit_i0de (out, id)\n val () = emit_LPAREN (out)\n val () = emit_f0marg (out, f0ma)\n val () = emit_RPAREN (out)\n }\n\/\/\nend \/\/ end of [emit_f0head]\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit_tmpdeclst\n (out: FILEref, tds: tmpdeclst): void\n\/\/\nimplement\nemit_tmpdeclst\n (out, tds) = let\n\/\/\nfun auxlst\n(\n out: FILEref, tds: tmpdeclst, i: int\n) : void =\n(\ncase+ tds of\n| list_nil () => ()\n| list_cons (td, tds) =>\n (\n case+ td.tmpdec_node of\n | TMPDECnone\n (tmp) => auxlst (out, tds, i) \/\/ probably ATStmpdec_void()\n | TMPDECsome\n (tmp, s0e) => let\n val () =\n if i > 0 then\n emit_text(out, \", \")\n \/\/ end of [val]\n val () = emit_s0exp (out, s0e)\n val () = emit_SPACE (out)\n val () = emit_i0de (out, tmp)\n val () = emit_newline (out)\n in\n auxlst (out, tds, i+1)\n end \/\/ end of [TMPDECsome]\n ) (* end of [list_cons] *)\n)\n\/\/\nin\n auxlst (out, tds, 0)\nend \/\/ end of [emit_tmpdeclst_initize]\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun emit_instr\n (out: FILEref, ins: instr) : void\n\/\/\nimplement\nemit_instr\n (out, ins0) = let\nin\n\/\/\ncase+\nins0.instr_node of\n\/\/\n| ATSif\n (\n d0e(*test*), inss(*then*), inssopt(*else*)\n ) =>\n {\n \/\/ TODO: labels must be assigned automatically... but how?\n val () = emit_d0exp (out, d0e)\n val () = emit_newline (out)\n val () = emit_text (out, \"brfalse L1\")\n val () = emit_newline (out)\n val () = emit_instrlst (out, inss)\n val () =\n (\n case+ inssopt of\n | Some(inss) =>\n {\n val () = emit_text (out, \"br L2\")\n val () = emit_newline (out)\n val () = emit_text (out, \"L1:\")\n val () = emit_newline (out)\n val () = emit_instrlst (out, inss)\n }\n | None((*void*)) => ()\n )\n val () = emit_text (out, \"L2:\") \/\/ next instruction, whatever it may be\n val () = emit_newline (out)\n } (* end of [ATSif] *)\n\/\/ TODO: ATSifthen, ATSifnthen, ATScaseofseq, ATSbranchseq\n\/\/ TODO: ATSlinepragma\n\/\/\n| ATSreturn (tmp) =>\n {\n \/\/ FIXME: if tmp is actually funarg, we must use ldarg\n val () = emit_text (out, \"ldloc\")\n val () = emit_SPACE (out)\n val () = emit_i0de (out, tmp)\n val () = emit_newline (out)\n val () = emit_text (out, \"ret\")\n }\n\/\/\n| ATSreturn_void (tmp) =>\n {\n val () = emit_text (out, \"ret\")\n }\n\/\/\n| ATSlinepragma (line, file) =>\n {\n \/\/ skip\n }\n\/\/\n| ATSINSlab (lab) =>\n {\n val () = emit_label (out, lab)\n val () = emit_text (out, \":\")\n }\n\/\/\n| ATSINSgoto (lab) =>\n {\n val () = emit_text (out, \"br\")\n val () = emit_SPACE (out)\n val () = emit_label (out, lab)\n }\n\/\/\n| ATSINSflab (flab) =>\n {\n val () = emit_label (out, flab)\n val () = emit_text (out, \":\")\n }\n\/\/\n| ATSINSfgoto (flab) =>\n {\n val () = emit_text (out, \"br\")\n val () = emit_SPACE (out)\n val () = emit_label (out, flab)\n }\n\/\/\n| ATSINSmove (tmp, d0e) =>\n {\n val () = emit_d0exp (out, d0e)\n val () = emit_newline (out)\n val () = emit_text (out, \"stloc\")\n val () = emit_SPACE (out)\n val () = emit_i0de (out, tmp)\n } (* end of [ATSINSmove] *)\n| ATSINSmove_void (_, d0e) =>\n {\n val () = emit_d0exp (out, d0e)\n } (* end of [ATSINSmove_void] *)\n\/\/ TODO: ATSdynload0, ATSdynload1, ATSdynloadset\n\/\/\n| _ =>\n {\n val () = emit_text (out, \"**INSTR**\")\n }\n\/\/\nend \/\/ end of [emit_instr]\n\n(* ****** ****** *)\nimplement\nemit_instrlst\n(\n out, inss\n) = (\n\/\/\ncase+ inss of\n| list_nil () => ()\n| list_cons (ins, inss) =>\n {\n val () = emit_instr (out, ins)\n val () = emit_ENDL (out)\n val () = emit_instrlst (out, inss)\n }\n\/\/\n) (* end of [emit_instrlst] *)\n\n(* ****** ****** *)\n\/\/\nextern\nfun emit_ATSfunbodyseq\n (out: FILEref, ins: instr) : void\n\/\/\nimplement\nemit_ATSfunbodyseq\n (out, ins) = let\n\/\/\nval-ATSfunbodyseq (inss) = ins.instr_node\n\/\/\nin\n emit_instrlst (out, inss)\nend \/\/ end of [emit_ATSfunbodyseq]\n\n(* ****** ****** *)\n\/\/\nextern\nfun emit_f0body_0 : emit_type (f0body)\n\/\/\nimplement\nemit_f0body_0\n (out, fbody) = let\n\/\/\nfun\nauxlst\n(\n out: FILEref, inss: instrlst\n) : void =\n(\ncase+ inss of\n| list_nil () => ()\n| list_cons\n (ins0, inss1) => let\n val-list_cons (ins1, inss2) = inss1\n val () = emit_ATSfunbodyseq (out, ins0)\n val () = emit_instr (out, ins1)\n in\n auxlst (out, inss2)\n end \/\/ end of [list_cons]\n) (* end of [auxlst] *)\n\/\/\nin\n\/\/\ncase+\nfbody.f0body_node of\n\/\/\n| F0BODY (tds, inss) => auxlst (out, inss)\n\/\/\nend \/\/ end of [emit_f0body_0]\n\n(* ****** ****** *)\nimplement\nemit_f0body\n (out, fbody) = let\n\/\/\nval tmpdecs =\n f0body_get_tmpdeclst (fbody)\n\/\/\nval () = the_tmpdeclst_set (tmpdecs)\nval () = emit_LBRACE (out)\nval () = emit_newline (out)\n\/\/ TODO: how to compute maxstack?\nval () = emit_text (out, \".maxstack 1\")\nval () = emit_newline (out)\n\/\/ emit locals\nval () = emit_text (out, \".locals\")\nval () = emit_SPACE (out)\nval () = emit_text (out, \"init\")\nval () = emit_SPACE (out)\nval () = emit_LPAREN (out)\nval () = emit_newline (out)\nval () = emit_tmpdeclst (out, tmpdecs)\nval () = emit_RPAREN (out)\nval () = emit_newline (out)\n\/\/ .locals init (\n\/\/ class [Mono.Cecil]Mono.Cecil.AssemblyNameDefinition V_0,\n\/\/ int32 V_1\n\/\/ )\nval () = emit_f0body_0 (out, fbody)\nval () = emit_newline (out)\nval () = emit_RBRACE (out)\nin\n\/\/\n\/\/\nend \/\/ end of [emit_f0body]\n\n(* ****** ****** *)\n\nimplement\nemit_f0decl\n (out, fdec) = let\nin\n\/\/\ncase+\nfdec.f0decl_node of\n| F0DECLnone (fhd) =>\n \/\/ does this actually mean function declaration (e.g. forward function decl)?\n ()\n| F0DECLsome (fhd, fbody) =>\n {\n val () = emit_text (out, \".method\")\n val () = emit_SPACE (out)\n val () = emit_text (out, \"static\")\n \/\/ TODO: public\/private?\n val () = emit_SPACE (out)\n val () = emit_text (out, \"public\")\n val () = emit_SPACE (out)\n \/\/ FIXME: where is the type of this function??\n val () = emit_f0head (out, fhd)\n val () = emit_SPACE (out) \n val () = emit_text (out, \"cil\")\n val () = emit_SPACE (out)\n val () = emit_text (out, \"managed\")\n val () = emit_newline (out)\n val () = emit_f0body (out, fbody)\n val () = emit_newline (out)\n } (* end of [F0DECLsome] *)\n\/\/\nend \/\/ end of [emit_f0decl]\n\n(* ****** ****** *)\n\n\/\/\nextern\nfun\ntyrec_labsel\n (tyrec: tyrec, lab: symbol): int\n\/\/\nimplement\ntyrec_labsel\n (tyrec, lab) = let\n\/\/\nfun loop\n(\n xs: tyfldlst, i: int\n) : int =\n(\ncase+ xs of\n| list_cons (x, xs) => let\n val TYFLD (id, s0e) = x.tyfld_node\n in\n if lab = id.i0de_sym then i else loop (xs, i+1)\n end \/\/ end of [list_cons\n| list_nil ((*void*)) => ~1(*error*)\n)\n\/\/\nin\n loop (tyrec.tyrec_node, 0)\nend \/\/ end of [tyrec_labsel]\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_SELcon\n (out, d0e) = let\n\/\/\nval-ATSSELcon\n (d0rec, s0e, id) = d0e.d0exp_node\nval-S0Eide (name) = s0e.s0exp_node\nval-~Some_vt (s0rec) = typedef_search_opt (name)\n\/\/\nval index = tyrec_labsel (s0rec, id.i0de_sym)\n\/\/\nval () =\n emit_d0exp (out, d0rec)\n\/\/\nval () = emit_LBRACKET (out)\nval () = emit_int (out, index)\nval () = emit_RBRACKET (out)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit_SELcon]\n\n(* ****** ****** *)\n\nimplement\nemit_SELboxrec\n (out, d0e) = let\n\/\/\nval-ATSSELboxrec\n (d0rec, s0e, id) = d0e.d0exp_node\nval-S0Eide (name) = s0e.s0exp_node\nval-~Some_vt (s0rec) = typedef_search_opt (name)\n\/\/\nval index = tyrec_labsel (s0rec, id.i0de_sym)\n\/\/\nval () =\n emit_d0exp (out, d0rec)\n\/\/\nval () = emit_LBRACKET (out)\nval () = emit_int (out, index)\nval () = emit_RBRACKET (out)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit_SELboxrec]\n\n(* ****** ****** *)\n\nimplement\nemit_d0ecl\n (out, d0c) = let\nin\n\/\/\ncase+\nd0c.d0ecl_node of\n\/\/\n| D0Cinclude include => ()\n where {\n val () = emit_text (out, \"#include\")\n val () = emit_SPACE (out)\n\/\/ val () = emit_text (out, include)\n val () = emit_newline (out)\n }\n\/\/\n| D0Cifdef (i0de, d0eclist) => ()\n| D0Cifndef (i0de, d0eclist) => ()\n\/\/\n| D0Ctypedef (id, def) =>\n {\n val () = typedef_insert (id.i0de_sym, def)\n } (* end of [D0Ctypedef] *)\n\/\/\n| D0Cdyncst_mac i0de => ()\n| D0Cdyncst_extfun (i0de, s0explst, s0exp) => ()\n\/\/\n| D0Cfundecl (fk, f0d) => emit_f0decl (out, f0d)\n\/\/\nend \/\/ end of [emit_d0ecl]\n\n(* ****** ****** *)\n\nimplement\nemit_toplevel\n (out, d0cs) = let\n\/\/\nfun\nloop\n(\n out: FILEref, d0cs: d0eclist\n) : void =\n(\n\/\/\ncase+ d0cs of\n| list_nil () => ()\n| list_cons\n (d0c, d0cs) => let\n in\n emit_d0ecl (out, d0c); loop (out, d0cs)\n end \/\/ end of [list_cons]\n\/\/\n)\n\/\/\nin\n loop (out, d0cs)\nend \/\/ end of [emit_toplevel]\n\n(* ****** ****** *)\n\n(* end of [atsparemit_emit_cil.dats] *)\n","old_contents":"(* ****** ****** *)\n\/\/\n\/\/ ATS-parse-emit-python\n\/\/\n(* ****** ****** *)\n\/\/\n\/\/ AS-2014-08-17: start\n\/\/\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_staload.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\nUN = \"prelude\/SATS\/unsafe.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/atsparemit.sats\"\nstaload \".\/atsparemit_syntax.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/atsparemit_emit.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \".\/atsparemit_topenv.dats\"\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_ENDL (out) = emit_text (out, \"\\n\")\n\n(* ****** ****** *)\n\nimplement\nemit_SPACE (out) = emit_text (out, \" \")\n\n(* ****** ****** *)\n\nimplement\nemit_SHARP (out) = emit_text (out, \"#\")\n\n(* ****** ****** *)\n\nimplement\nemit_LPAREN (out) = emit_text (out, \"(\")\nimplement\nemit_RPAREN (out) = emit_text (out, \")\")\n\n(* ****** ****** *)\n\nimplement\nemit_LBRACE (out) = emit_text (out, \"{\")\nimplement\nemit_RBRACE (out) = emit_text (out, \"}\")\n\n\n(* ****** ****** *)\n\nimplement\nemit_LBRACKET (out) = emit_text (out, \"[\")\nimplement\nemit_RBRACKET (out) = emit_text (out, \"]\")\n\n(* ****** ****** *)\n\nimplement\nemit_flush (out) = fileref_flush (out)\nimplement\nemit_newline (out) = fprint_newline (out)\n\n(* ****** ****** *)\n\/\/\nimplement\nemit_int (out, x) = fprint_int (out, x)\n\/\/\nimplement\nemit_text (out, x) = fprint_string (out, x)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nemit_symbol (out, x) =\n fprint_string (out, symbol_get_name (x))\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_PMVint\n (out, tok) = let\n\/\/\nval-T_INT(base, rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVint]\n\n(* ****** ****** *)\n\nimplement\nemit_PMVi0nt\n (out, tok) = let\n\/\/\nval-T_INT(base, rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVi0nt]\n\n(* ****** ****** *)\n\/\/\nimplement\nemit_PMVbool\n (out, tfv) =\n(\n emit_text (out, if tfv then \"1\" else \"0\")\n) (* end of [emit_PMVbool] *)\n\/\/\n(* ****** ****** *)\nimplement\nemit_PMVstring\n (out, tok) = let\n\/\/\nval-T_STRING(rep) = tok.token_node\n\/\/\nin\n emit_text (out, rep)\nend \/\/ end of [emit_PMVstring]\n\n(* ****** ****** *)\n\/\/\nimplement\nemit_i0de\n (out, id) = emit_symbol (out, id.i0de_sym)\nimplement\nemit_label\n (out, lab) = emit_symbol (out, lab.i0de_sym)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit_s0exp : emit_type (s0exp)\nextern\nfun\nemit_s0explst : emit_type (s0explst)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nemit_s0exp\n (out, s0e) = let\n\/\/\n\/\/\nin\n\/\/\ncase+\ns0e.s0exp_node of\n\/\/\n| S0Eide (id) => emit_symbol (out, id)\n| S0Elist (s0es) => () \/\/ shouldn't happen? marked as \"temp\"\n| S0Eappid (id, s0es) =>\n \/\/ FIXME: what about other types? e.g. array types? struct types?\n () where {\n val () = emit_symbol (out, id)\n val () = emit_LPAREN (out)\n val () = emit_s0explst (out, s0es)\n val () = emit_RPAREN (out)\n }\n\/\/\nend \/\/ end of [emit_s0exp]\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_s0explst\n (out, s0es) = let\n\/\/\nfun\nloop\n(\n out: FILEref, s0es: s0explst, i: int\n) : void =\n(\ncase+ s0es of\n| list_nil () => ()\n| list_cons (s0e, s0es) => let\n val () =\n if i > 0 then emit_text (out, \", \")\n \/\/ end of [val]\n in\n emit_s0exp (out, s0e); loop (out, s0es, i+1)\n end \/\/ end of [list_cons]\n)\n\/\/\nin\n loop (out, s0es, 0)\nend \/\/ end of [emit_s0explst]\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nfunlab_get_index (fl: label): int\nextern\nfun\ntmplab_get_index (lab: label): int\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_f0arglst_get (): f0arglst\nextern\nfun\nthe_f0arglst_set (f0as: f0arglst): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_tmpdeclst_get (): tmpdeclst\nextern\nfun\nthe_tmpdeclst_set (tds: tmpdeclst): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_funbodylst_get (): instrlst\nextern\nfun\nthe_funbodylst_set (inss: instrlst): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_branchlablst_get (): labelist\nextern\nfun\nthe_branchlablst_set (labs: labelist): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nthe_caseofseqlst_get (): instrlst\nextern\nfun\nthe_caseofseqlst_set (inss: instrlst): void\n\/\/\n(* ****** ****** *)\n\nlocal\n\/\/\nval the_f0arglst = ref (list_nil)\nval the_tmpdeclst = ref (list_nil)\n\/\/\nval the_funbodylst = ref (list_nil)\n\/\/\nval the_branchlablst = ref (list_nil)\nval the_caseofseqlst = ref (list_nil)\n\/\/\nin (* in-of-local *)\n\nimplement\nthe_f0arglst_get () = !the_f0arglst\nimplement\nthe_f0arglst_set (xs) = !the_f0arglst := xs\n\nimplement\nthe_tmpdeclst_get () = !the_tmpdeclst\nimplement\nthe_tmpdeclst_set (xs) = !the_tmpdeclst := xs\n\nimplement\nthe_funbodylst_get () = !the_funbodylst\nimplement\nthe_funbodylst_set (xs) = !the_funbodylst := xs\n\nimplement\nthe_branchlablst_get () = !the_branchlablst\nimplement\nthe_branchlablst_set (xs) = !the_branchlablst := xs\n\nimplement\nthe_caseofseqlst_get () = !the_caseofseqlst\nimplement\nthe_caseofseqlst_set (xs) = !the_caseofseqlst := xs\n\nend \/\/ end of [local]\n\n(* ******* ****** *)\n\nimplement\nemit_d0exp\n (out, d0e) = let\nin\n\/\/\ncase+\nd0e.d0exp_node of\n\/\/\n| _ => ()\n\/\/\nend \/\/ end of [emit_d0exp]\n\n(* ****** ****** *)\n\/\/\nextern\nfun emit_f0arg : emit_type (f0arg)\nextern\nfun emit_f0marg : emit_type (f0marg)\nextern\nfun emit_f0head : emit_type (f0head)\n\/\/\nextern\nfun emit_f0body : emit_type (f0body)\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_f0arg\n (out, f0a) = let\nin\n\/\/\ncase+\nf0a.f0arg_node of\n\/\/\n| F0ARGnone s0e => emit_text (out, \"__NONE__\") \/\/ FIXME: how to emit type decl?\n| F0ARGsome (id, s0e) => emit_i0de (out, id) \/\/ FIXME: how to emit type decl?\n\/\/\nend \/\/ end of [emit_f0arg]\n\n(* ****** ****** *)\n\nimplement\nemit_f0marg\n (out, f0ma) = let\n\/\/\nfun\nloop\n(\n out: FILEref, f0as: f0arglst, i: int\n) : void =\n(\ncase+ f0as of\n| list_nil () => ()\n| list_cons (f0a, f0as) => let\n val () =\n if i > 0 then emit_text (out, \", \")\n \/\/ end of [val]\n in\n emit_f0arg (out, f0a); loop (out, f0as, i+1)\n end \/\/ end of [list_cons]\n)\n\/\/\nin\n loop (out, f0ma.f0marg_node, 0)\nend \/\/ end of [emit_f0marg]\n\n(* ****** ****** *)\n\nimplement\nemit_f0head\n (out, fhd) = let\n\/\/\nval f0as =\n f0head_get_f0arglst (fhd)\n\/\/\nval () = the_f0arglst_set (f0as)\n\/\/\nin\n\/\/\ncase+\nfhd.f0head_node of\n| F0HEAD\n (id(*name of function*), f0ma(*list of arguments*), res(*result type*)) =>\n {\n val () = emit_s0exp (out, res)\n val () = emit_SPACE (out)\n val () = emit_i0de (out, id)\n val () = emit_LPAREN (out)\n val () = emit_f0marg (out, f0ma)\n val () = emit_RPAREN (out)\n }\n\/\/\nend \/\/ end of [emit_f0head]\n\n(* ****** ****** *)\n\/\/\nextern\nfun\nemit_tmpdeclst\n (out: FILEref, tds: tmpdeclst): void\n\/\/\nimplement\nemit_tmpdeclst\n (out, tds) = let\n\/\/\nfun auxlst\n(\n out: FILEref, tds: tmpdeclst, i: int\n) : void =\n(\ncase+ tds of\n| list_nil () => ()\n| list_cons (td, tds) =>\n (\n case+ td.tmpdec_node of\n | TMPDECnone\n (tmp) => auxlst (out, tds, i) \/\/ probably ATStmpdec_void()\n | TMPDECsome\n (tmp, s0e) => let\n val () =\n if i > 0 then\n emit_text(out, \", \")\n \/\/ end of [val]\n val () = emit_s0exp (out, s0e)\n val () = emit_SPACE (out)\n val () = emit_i0de (out, tmp)\n val () = emit_newline (out)\n in\n auxlst (out, tds, i+1)\n end \/\/ end of [TMPDECsome]\n ) (* end of [list_cons] *)\n)\n\/\/\nin\n auxlst (out, tds, 0)\nend \/\/ end of [emit_tmpdeclst_initize]\n\/\/\n(* ****** ****** *)\nimplement\nemit_f0body\n (out, fbody) = let\n\/\/\nval tmpdecs =\n f0body_get_tmpdeclst (fbody)\nval inss_body =\n f0body_get_bdinstrlst (fbody)\n\/\/\nval () = the_tmpdeclst_set (tmpdecs)\nval () = the_funbodylst_set (inss_body)\nval () = emit_LBRACE (out)\n\/\/ TODO: insert body\nval () = emit_newline (out)\nval () = emit_text (out, \".maxstack 1\")\n\/\/ emit locals\nval () = emit_text (out, \".locals\")\nval () = emit_SPACE (out)\nval () = emit_text (out, \"init\")\nval () = emit_SPACE (out)\nval () = emit_LPAREN (out)\nval () = emit_newline (out)\nval () = emit_tmpdeclst (out, tmpdecs)\nval () = emit_RPAREN (out)\nval () = emit_newline (out)\n\/\/ .locals init (\n\/\/ class [Mono.Cecil]Mono.Cecil.AssemblyNameDefinition V_0,\n\/\/ int32 V_1\n\/\/ )\nval () = emit_text (out, \"IL_0000: ret\")\nval () = emit_newline (out)\nval () = emit_RBRACE (out)\nin\n\/\/\n\/\/\nend \/\/ end of [emit_f0body]\n\n(* ****** ****** *)\n\nimplement\nemit_f0decl\n (out, fdec) = let\nin\n\/\/\ncase+\nfdec.f0decl_node of\n| F0DECLnone (fhd) =>\n \/\/ does this actually mean function declaration (e.g. forward function decl)?\n ()\n| F0DECLsome (fhd, fbody) =>\n {\n val () = emit_text (out, \".method\")\n val () = emit_SPACE (out)\n val () = emit_text (out, \"static\")\n \/\/ TODO: public\/private?\n val () = emit_SPACE (out)\n val () = emit_text (out, \"public\")\n val () = emit_SPACE (out)\n \/\/ FIXME: where is the type of this function??\n val () = emit_f0head (out, fhd)\n val () = emit_SPACE (out) \n val () = emit_text (out, \"cil\")\n val () = emit_SPACE (out)\n val () = emit_text (out, \"managed\")\n val () = emit_newline (out)\n val () = emit_f0body (out, fbody)\n val () = emit_newline (out)\n } (* end of [F0DECLsome] *)\n\/\/\nend \/\/ end of [emit_f0decl]\n\n(* ****** ****** *)\n\nlocal\n\nfun\nloop\n(\n out: FILEref, d0es: d0explst, i: int\n) : void =\n(\ncase+ d0es of\n| list_nil () => ()\n| list_cons (d0e, d0es) => let\n val () =\n if i > 0 then emit_text (out, \", \")\n \/\/ end of [val]\n in\n emit_d0exp (out, d0e); loop (out, d0es, i+1)\n end \/\/ end of [list_cons]\n)\n\nin (* in-of-local *)\n\nimplement\nemit_d0explst (out, d0es) = loop (out, d0es, 0)\nimplement\nemit_d0explst_1 (out, d0es) = loop (out, d0es, 1)\n\nend \/\/ end of [local]\n\n(* ****** ****** *)\n\n\/\/\nextern\nfun\ntyrec_labsel\n (tyrec: tyrec, lab: symbol): int\n\/\/\nimplement\ntyrec_labsel\n (tyrec, lab) = let\n\/\/\nfun loop\n(\n xs: tyfldlst, i: int\n) : int =\n(\ncase+ xs of\n| list_cons (x, xs) => let\n val TYFLD (id, s0e) = x.tyfld_node\n in\n if lab = id.i0de_sym then i else loop (xs, i+1)\n end \/\/ end of [list_cons\n| list_nil ((*void*)) => ~1(*error*)\n)\n\/\/\nin\n loop (tyrec.tyrec_node, 0)\nend \/\/ end of [tyrec_labsel]\n\/\/\n(* ****** ****** *)\n\nimplement\nemit_SELcon\n (out, d0e) = let\n\/\/\nval-ATSSELcon\n (d0rec, s0e, id) = d0e.d0exp_node\nval-S0Eide (name) = s0e.s0exp_node\nval-~Some_vt (s0rec) = typedef_search_opt (name)\n\/\/\nval index = tyrec_labsel (s0rec, id.i0de_sym)\n\/\/\nval () =\n emit_d0exp (out, d0rec)\n\/\/\nval () = emit_LBRACKET (out)\nval () = emit_int (out, index)\nval () = emit_RBRACKET (out)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit_SELcon]\n\n(* ****** ****** *)\n\nimplement\nemit_SELboxrec\n (out, d0e) = let\n\/\/\nval-ATSSELboxrec\n (d0rec, s0e, id) = d0e.d0exp_node\nval-S0Eide (name) = s0e.s0exp_node\nval-~Some_vt (s0rec) = typedef_search_opt (name)\n\/\/\nval index = tyrec_labsel (s0rec, id.i0de_sym)\n\/\/\nval () =\n emit_d0exp (out, d0rec)\n\/\/\nval () = emit_LBRACKET (out)\nval () = emit_int (out, index)\nval () = emit_RBRACKET (out)\n\/\/\nin\n \/\/ nothing\nend \/\/ end of [emit_SELboxrec]\n\n(* ****** ****** *)\n\nimplement\nemit_d0ecl\n (out, d0c) = let\nin\n\/\/\ncase+\nd0c.d0ecl_node of\n\/\/\n| D0Cinclude include => ()\n where {\n val () = emit_text (out, \"#include\")\n val () = emit_SPACE (out)\n\/\/ val () = emit_text (out, include)\n val () = emit_newline (out)\n }\n\/\/\n| D0Cifdef (i0de, d0eclist) => ()\n| D0Cifndef (i0de, d0eclist) => ()\n\/\/\n| D0Ctypedef (id, def) =>\n {\n val () = typedef_insert (id.i0de_sym, def)\n } (* end of [D0Ctypedef] *)\n\/\/\n| D0Cdyncst_mac i0de => ()\n| D0Cdyncst_extfun (i0de, s0explst, s0exp) => ()\n\/\/\n| D0Cfundecl (fk, f0d) => emit_f0decl (out, f0d)\n\/\/\nend \/\/ end of [emit_d0ecl]\n\n(* ****** ****** *)\n\nimplement\nemit_toplevel\n (out, d0cs) = let\n\/\/\nfun\nloop\n(\n out: FILEref, d0cs: d0eclist\n) : void =\n(\n\/\/\ncase+ d0cs of\n| list_nil () => ()\n| list_cons\n (d0c, d0cs) => let\n in\n emit_d0ecl (out, d0c); loop (out, d0cs)\n end \/\/ end of [list_cons]\n\/\/\n)\n\/\/\nin\n loop (out, d0cs)\nend \/\/ end of [emit_toplevel]\n\n(* ****** ****** *)\n\n(* end of [atsparemit_emit_cil.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"1c323484506a96d8cb2ce15dec5620a3553399f2","subject":"Updating: very minorly fixing","message":"Updating: very minorly fixing\n","repos":"githwxi\/ATS-Postiats-frozen,githwxi\/ATS-Postiats-frozen,githwxi\/ATS-Postiats-frozen,githwxi\/ATS-Postiats-frozen,githwxi\/ATS-Postiats-frozen,githwxi\/ATS-Postiats-frozen,githwxi\/ATS-Postiats-frozen,githwxi\/ATS-Postiats-frozen,githwxi\/ATS-Postiats-frozen","old_file":"projects\/SMALL\/html2pats-2016-01-13\/html2pats.dats","new_file":"projects\/SMALL\/html2pats-2016-01-13\/html2pats.dats","new_contents":"(*\n** HTML2ATS\/Postiats\n**\n** For simplifying the task of writing HTML-producing functions\n** in ATS\/Postiats.\n*)\n\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_staload.hats\"\n\/\/\n#define\nLIBXML2_targetloc\n\"$PATSHOMERELOC\/contrib\/libxml2\/libxml\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \"{$LIBXML2}\/SATS\/xml0.sats\"\nstaload _ = \"{$LIBXML2}\/DATS\/xml0.dats\"\n\/\/\n(* ****** ****** *)\n\nstaload \"{$LIBXML2}\/SATS\/tree.sats\"\nstaload \"{$LIBXML2}\/SATS\/parser.sats\"\nstaload \"{$LIBXML2}\/SATS\/HTMLparser.sats\"\n\n(* ****** ****** *)\n\n#define ATS_DYNARGS_TOP \"ats-dynargs\"\n#define ATS_CALL \"ats-call\"\n#define ATS_IMPL \"ats-impl\"\n#define ATS_TMP \"tmp\"\n#define ATS_FUN \"fun\"\n#define ATS_TMPARGS \"tmpargs\"\n#define ATS_GENARGS \"genargs\"\n#define ATS_DYNARGS \"dynargs\"\n#define ATS_DLR \"$\"\n#define ATS_LBRACE \"{\"\n#define ATS_RBRACE \"}\"\n#define ATS_ESCAPE \"\\\\\"\n\n(* ****** ****** *)\n\/\/\n\/\/ Parsing of embedded variables and expressions\n\/\/\n\n%{^\nATSinline()\natstype_bool\nATSPRELUDE_STRNPTR_IS_ATEND(atstype_strptr s, atstype_size i) {\n return (s[i]) == '\\000'? atsbool_true : atsbool_false;\n}\nATSinline()\natstype_void\nATSPRELUDE_STRBUF_INIT(atstype_ptrk sbf) {\n ((atstype_char*)sbf)[0] = '\\000';\n}\nATSinline()\natstype_size\nATSPRELUDE_STRBUF_PUT(atstype_ptrk sbf, atstype_size i, atstype_char c) {\n ((atstype_char*)sbf)[i] = c;\n return i+1;\n}\nATSinline()\natstype_void\nATSPRELUDE_STRBUF_FIN(atstype_ptrk sbf, atstype_size i) {\n ((atstype_char*)sbf)[i] = '\\000';\n}\nATSinline()\natstype_char\nATSPRELUDE_STRBUF_GET_AT(atstype_ptrk sbf, atstype_size i) {\n return ((atstype_char*)sbf)[i];\n}\n%}\n\nextern\nfun\nstrnptr_is_atend\n {l:agz}{n:int}{i:nat | i <= n}\n (s: !strnptr (l, n), i: size_t (i)):<> bool (i==n) = \"mac#ATSPRELUDE_STRNPTR_IS_ATEND\"\n\nextern\nfun\nstrbuf_is_atend\n {m,n,i:int | i <= n}\n (s: &strbuf (m, n), i: size_t (i)):<> bool (i==n) = \"mac#ATSPRELUDE_STRNPTR_IS_ATEND\"\nextern\nfun\nstrbuf_get_at\n {m,n,i:int | i < n}\n (s: &strbuf (m, n), i: size_t (i)):<> charNZ = \"mac#ATSPRELUDE_STRBUF_GET_AT\"\n\n\/\/ \"extended\" (for lack of better word)\nabst@ype estrbuf (m:int, n:int) \/\/ size same as strbuf (m, n)\n\nextern\ncastfn\nstrbuf_init {m:int | m > 0} (\n &b0ytes(m) >> estrbuf (m, 0)\n): void = \"mac#ATSPRELUDE_STRBUF_INIT\"\nextern\ncastfn\nstrbuf_clear {m,n:int} (\n !estrbuf (m, n) >> estrbuf (m, 0)\n): void\nextern\nfun\nstrbuf_reset {m,n:int | m > 0} (\n &strbuf (m, n) >> estrbuf (m, 0)\n): void = \"mac#ATSPRELUDE_STRBUF_INIT\"\nextern\nfun\nstrbuf_extend {m,n:int; n+1 < m} (\n sbf: &estrbuf (m, n) >> estrbuf (m, n+1), size_t n, c: charNZ\n): size_t (n+1) = \"mac#ATSPRELUDE_STRBUF_PUT\"\nextern\nfun\nstrbuf_finalize {m,n:int; n < m} (\n sbf: &estrbuf (m, n) >> strbuf (m, n), size_t n\n): void = \"mac#ATSPRELUDE_STRBUF_FIN\"\n\ndatatype TOKTYPE =\n | TT_TEXT\n | TT_VAR\n | TT_EXPR\ndatatype ERRTYPE =\n | ET_INVALID_CHARACTER\n | ET_PREMATURE_EOF\n | ET_OVERFLOW \/\/ buffer overflowed\n\nextern\nfun\nfprint_TOKTYPE (FILEref, TOKTYPE): void\noverload fprint with fprint_TOKTYPE\n\nextern\nfun\nprint_TOKTYPE (TOKTYPE): void\noverload print with print_TOKTYPE\n\nextern\nfun\nfprint_ERRTYPE (FILEref, ERRTYPE): void\noverload fprint with fprint_ERRTYPE\nextern\nfun\nprint_ERRTYPE (ERRTYPE): void\noverload print with print_ERRTYPE\n\nextern\nfun{env:vt@ype}\nparemit$fwork {m,n:int} (\n TOKTYPE, &strbuf (m, n), &(env) >> _\n): void\nextern\nfun{env:vt@ype}\nparemit$err {l:agz}{n,i:int | i <= n} (\n ERRTYPE\n, !strnptr (l, n), size_t i, &(env) >> _\n, string(*message*)\n): void\n\nextern\nfun{env:vt@ype}\nparemit_env {l:agz} {n:int} (\n !strnptr (l, n)\n, env: &(env) >> _\n): void\n\nimplement\nfprint_TOKTYPE (out, tp) =\n case+ tp of\n | TT_TEXT () => fprint_string (out, \"text\")\n | TT_VAR () => fprint_string (out, \"variable\")\n | TT_EXPR () => fprint_string (out, \"expression\")\nimplement\nprint_TOKTYPE (tp) = fprint_TOKTYPE (stdout_ref, tp)\n\nimplement\nfprint_ERRTYPE (out, et) =\n case+ et of\n | ET_INVALID_CHARACTER () => fprint_string (out, \"invalid character\")\n | ET_PREMATURE_EOF () => fprint_string (out, \"premature EOF\")\n | ET_OVERFLOW () => fprint_string (out, \"buffer overflow\")\nimplement\nprint_ERRTYPE (et) = fprint_ERRTYPE (stdout_ref, et)\n\nimplement{env}\nparemit_env {l} {n} (str, env) = let\n\/\/\n #define BUFSIZ 16384\n typedef Sbuf (k:int) = estrbuf (BUFSIZ, k)\n\/\/\n fun\n aux {n,j,k1:nat | j <= n; k1+1 <= BUFSIZ} (\n str: !strnptr (l, n)\n , j: size_t j\n , k: size_t k1\n , sbf: &Sbuf (k1) >> Sbuf (k2)\n , env: &(env) >> _\n ): #[k2:int | k2+1 <= BUFSIZ] size_t k2 =\n if strnptr_is_atend (str, j) then let\n \/\/ flush the text, if any\n val () =\n if :(sbf: Sbuf (0)) => k > (i2sz)0 then let\n val () = strbuf_finalize (sbf, k)\n val () = paremit$fwork (TT_TEXT, sbf, env) in\n strbuf_reset (sbf)\n end\n \/\/ end of [val]\n in\n (i2sz)0\n end else let\n val j0 = j\n val c = strnptr_get_at (str, j)\n in\n case+ c of\n | '\\\\' => let\n val j = succ(j)\n in\n if strnptr_is_atend (str, j) then let\n val () = paremit$err (ET_PREMATURE_EOF, str, j, env, \"looking for {, }, \\\\ or $\")\n in\n k\n end else let\n val c1 = strnptr_get_at (str, j)\n in\n case+ 0 of\n | _ when c1 = '$' || c1 = '\\{' || c1 = '}' || c1 = '\\\\' =>\n \/\/ okay to overflow here, just emit the existing TEXT you got so far\n if succ(k) < BUFSIZ then let\n val k = strbuf_extend (sbf, k, c1)\n in\n aux (str, succ(j), k, sbf, env)\n end else let\n val () = strbuf_finalize (sbf, k)\n val () = paremit$fwork (TT_TEXT, sbf, env)\n val () = strbuf_reset (sbf)\n val k = (i2sz)0\n val k1 = strbuf_extend (sbf, k, c1)\n in\n aux (str, succ(j), k1, sbf, env)\n end \/\/ end of [if]\n | _ => let\n val () = paremit$err (ET_INVALID_CHARACTER, str, j, env, \"looking for {, }, \\\\ or $\")\n in\n k\n end \/\/ end of [let]\n end \/\/ end of [if]\n end \/\/ end of [let]\n | '$' => let\n \/\/ flush the text, if any\n val () =\n if :(sbf: Sbuf (0)) => k > (i2sz)0 then let\n val () = strbuf_finalize (sbf, k)\n val () = paremit$fwork (TT_TEXT, sbf, env) in\n strbuf_reset (sbf)\n end\n \/\/ end of [val]\n val k = (i2sz)0\n val j = succ(j)\n in\n if strnptr_is_atend (str, j) then let\n val () = paremit$err (ET_PREMATURE_EOF, str, j, env, \"looking for alphabetic symbol or {\")\n in\n k\n end else let\n val c = strnptr_get_at (str, j)\n in\n case+ 0 of\n | _ when c = '\\{' => block (str, succ(j), k, sbf, env, 1)\n | _ when c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' =>\n if succ(k) < BUFSIZ then let\n val k = strbuf_extend (sbf, k, c)\n in\n ident (str, succ(j), k, sbf, env)\n end else let\n val () = strbuf_finalize (sbf, j)\n val () = paremit$err (ET_OVERFLOW, str, j, env, \"error\")\n val () = strbuf_reset (sbf)\n val k = (i2sz)0\n in\n k\n end \/\/ end of [if]\n | _ => let\n val () = paremit$err (ET_INVALID_CHARACTER, str, j, env, \"looking for alphabetic symbol or {\")\n in\n k\n end\n end \/\/ end of [if]\n end \/\/ end of [let]\n | _ =>\n \/\/ okay to overflow here, just emit the TEXT you got so far\n if succ(k) < BUFSIZ then let\n val k = strbuf_extend (sbf, k, c)\n in\n aux (str, succ(j), k, sbf, env)\n end else let\n val () = strbuf_finalize (sbf, k)\n val () = paremit$fwork (TT_TEXT, sbf, env)\n val () = strbuf_reset (sbf)\n val k = (i2sz)0\n val k = strbuf_extend (sbf, k, c)\n in\n aux (str, succ(j), k, sbf, env)\n end \/\/ end of [if]\n end \/\/ end of [aux]\n\n and\n block {n,j,k1:nat | j <= n; k1+1 <= BUFSIZ} (\n str: !strnptr (l, n), j: size_t j\n , k: size_t k1, sbf: &Sbuf (k1) >> Sbuf (k2)\n , env: &(env) >> _\n , count: int \/\/ brace count\n ): #[k2:nat | k2+1 <= BUFSIZ] size_t (k2) =\n if strnptr_is_atend (str, j) then let\n val () = paremit$err (ET_PREMATURE_EOF, str, j, env, \"looking for }\")\n in\n k\n end else let\n val c = strnptr_get_at (str, j)\n in\n case+ c of\n | '\\\\' => let\n val j = succ(j)\n in\n if strnptr_is_atend (str, j) then let\n val () = paremit$err (ET_PREMATURE_EOF, str, j, env, \"looking for {, }, \\\\ or $\")\n in\n k\n end else let\n val c1 = strnptr_get_at (str, j)\n in\n case+ 0 of\n | _ when c1 = '$' || c1 = '\\{' || c1 = '}' =>\n if succ(k) < BUFSIZ then let\n val k = strbuf_extend (sbf, k, c1)\n in\n block (str, succ(j), k, sbf, env, count)\n end else let\n val () = strbuf_finalize (sbf, k)\n val () = paremit$err (ET_OVERFLOW, str, j, env, \"error\")\n val k = (i2sz)0\n val () = strbuf_reset (sbf)\n in\n k\n end \/\/ end of [if]\n | _ => let\n val () = paremit$err (ET_INVALID_CHARACTER, str, j, env, \"looking for {, }, \\\\ or $\")\n in\n k\n end \/\/ end of [let]\n end \/\/ end of [if]\n end \/\/ end of [let]\n | '}' => let\n val count = pred(count)\n in\n if count = 0 then let\n \/\/ flush the text, if any\n val () =\n if :(sbf: Sbuf (0)) => k > (i2sz)0 then let\n val () = strbuf_finalize (sbf, k)\n val () = paremit$fwork (TT_EXPR, sbf, env) in\n strbuf_reset (sbf)\n end\n val k = (i2sz)0\n val j = succ(j)\n val k2 = aux (str, j, k, sbf, env)\n prval () = lemma_g1uint_param (k2)\n in\n k2\n end else let\n val j = succ(j)\n in\n if succ(k) < BUFSIZ then let\n val k = strbuf_extend (sbf, k, c)\n in\n block (str, j, k, sbf, env, count)\n end else let\n val () = paremit$err (ET_OVERFLOW, str, j, env, \"error\")\n val k = (i2sz)0\n val () = strbuf_clear (sbf)\n in\n k\n end \/\/ end of [if]\n end \/\/ end of [if]\n end \/\/ end of [let]\n | _ => let\n val j = succ(j)\n val count = if c = '\\{' then succ(count) else count\n in\n if succ(k) < BUFSIZ then let\n val k = strbuf_extend (sbf, k, c)\n in\n block (str, j, k, sbf, env, count)\n end else let\n val () = paremit$err (ET_OVERFLOW, str, j, env, \"error\")\n val k = (i2sz)0\n val () = strbuf_clear (sbf)\n in\n k\n end \/\/ end of [if]\n end \/\/ end of [let]\n end \/\/ end of [if]\n \/\/ end of [block]\n\n and\n ident {n,k1,j:nat | j <= n; k1+1 <= BUFSIZ} (\n str: !strnptr (l, n)\n , j: size_t j\n , k: size_t k1, sbf: &Sbuf (k1) >> Sbuf (k2)\n , env: &(env) >> _\n ): #[k2:nat | k2+1 <= BUFSIZ] size_t (k2) =\n if strnptr_is_atend (str, j) then (\n \/\/ flush the text, if any\n if :(sbf: Sbuf (0)) => k > (i2sz)0 then let\n val () = strbuf_finalize (sbf, k)\n val () = paremit$fwork (TT_VAR, sbf, env)\n val () = strbuf_reset (sbf) in\n (i2sz)0\n end else k\n ) else let\n val c = strnptr_get_at (str, j)\n in\n case+ 0 of\n | _ when c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' =>\n if succ(k) < BUFSIZ then let\n val k = strbuf_extend (sbf, k, c)\n in\n ident (str, succ(j), k, sbf, env)\n end else let\n val () = paremit$err (ET_OVERFLOW, str, j, env, \"error\")\n val k = (i2sz)0\n val () = strbuf_clear (sbf)\n in\n k\n end \/\/ end of [if]\n | _ => let\n val () =\n if :(sbf: Sbuf (0)) => k > (i2sz)0 then let\n val () = strbuf_finalize (sbf, k)\n val () = paremit$fwork (TT_VAR, sbf, env) in\n strbuf_reset (sbf)\n end\n \/\/ end of [val]\n val k = (i2sz)0\n val k = strbuf_extend (sbf, k, c)\n val k2 = aux (str, succ(j), k, sbf, env)\n prval () = lemma_g1uint_param (k2)\n in\n k2\n end \/\/ end of [let]\n end \/\/ end of [if]\n \/\/ end of [ident]\n prval () = lemma_strnptr_param (str)\n var sbuf = @[byte][BUFSIZ]()\n val () = strbuf_init (sbuf)\n val _ = aux (str, (i2sz)0, (i2sz)0, sbuf, env)\n val () = strbuf_clear (sbuf)\n val () = strbuf_finalize (sbuf, (i2sz)0)\n prval () = strbuf2bytes (sbuf)\nin\nend \/\/ end of [paremit_env]\n\n(* ****** ****** *)\n\/\/\nfun indent\n(\n out: FILEref, n: int\n) : void =\n if n > 0 then (fprint (out, ' '); indent (out, n-1))\n\/\/ end of [indent]\n\nextern\nfun\nemit_tmpargs {l:addr}{n:int} (out: FILEref, gen: bool, tmpargs: !strnptr (l, n)): void\nimplement\nemit_tmpargs {l}{n} (out, gen, args) = let\n fun\n aux0 {l:agz}{i,n:nat | i <= n} (dynargs: !strnptr (l, n), i: size_t (i), append: bool, gen: bool): void =\n if strnptr_is_atend (dynargs, i) then fprint! (out, (if gen then \")\" else \">\"):string)\n else let\n val c = strnptr_get_at (dynargs, i)\n in\n case+ 0 of\n | _ when c = ' ' || c = '\\n' || c = '\\r' || c = '\\t' || c = ';' => aux0 (dynargs, succ(i), append, gen)\n | _ => let\n val () = if append then fprint! (out, (if gen then \")(\" else \"><\"):string)\n in\n aux1 (dynargs, i, (i2sz)0, append, gen)\n end \/\/ end of [let]\n \/\/ end of [case]\n end \/\/ end of [if]\n \/\/ end of [aux]\n \n and\n aux1 {l:agz}{i,j,n:nat | i < n; i+j <= n} (dynargs: !strnptr (l, n), i: size_t (i), j: size_t (j), fst: bool, gen: bool): void =\n if strnptr_is_atend (dynargs, i+j) then fprint! (out, (if gen then \")\" else \">\"):string)\n else let\n val c = strnptr_get_at (dynargs, i+j)\n in\n case+ 0 of\n | _ when c = ' ' || c = '\\n' || c = '\\r' || c = '\\t' || c = ';' => aux0 (dynargs, succ(i+j), true, gen)\n | _ => let\n val () = fprint! (out, c)\n in\n aux1 (dynargs, i, succ(j), false, gen)\n end \/\/ end of [let]\n \/\/ end of [case]\n end \/\/ end of [if]\n \/\/ end of [aux1]\nin\n if strnptr_isnot_null (args) then let \n prval () = lemma_strnptr_param (args)\n val i = (i2sz)0\n val () = fprint! (out, (if gen then \"(\" else \"<\"): string)\n in\n if strnptr_is_atend (args, i) then fprint! (out, (if gen then \")\" else \">\"):string)\n else aux0 (args, i, false, gen)\n end \/\/ end of [if]\nend \/\/ end of [emit_tmpargs]\n\nextern\nfun\nemit_dynargs {l:addr}{n:int} (out: FILEref, dynargs: !strnptr (l, n), append: bool): void\nimplement\nemit_dynargs {n} (out, dynargs, append) = let\n fun\n aux0 {l:agz}{i,n:nat | i <= n} (dynargs: !strnptr (l, n), i: size_t (i), append: bool): void =\n if strnptr_is_atend (dynargs, i) then fprint! (out, \")\")\n else let\n val c = strnptr_get_at (dynargs, i)\n in\n case+ 0 of\n | _ when c = ' ' || c = '\\n' || c = '\\r' || c = '\\t' || c = ',' => aux0 (dynargs, succ(i), append)\n | _ => let\n val () = if append then fprint! (out, \", \")\n in\n aux1 (dynargs, i, (i2sz)0, append)\n end \/\/ end of [let]\n \/\/ end of [case]\n end \/\/ end of [if]\n \/\/ end of [aux]\n \n and\n aux1 {l:agz}{i,j,n:nat | i < n; i+j <= n} (dynargs: !strnptr (l, n), i: size_t (i), j: size_t (j), fst: bool): void =\n if strnptr_is_atend (dynargs, i+j) then fprint! (out, \")\")\n else let\n val c = strnptr_get_at (dynargs, i+j)\n in\n case+ 0 of\n | _ when c = ' ' || c = '\\n' || c = '\\r' || c = '\\t' || c = ',' => aux0 (dynargs, succ(i+j), true)\n | _ => let\n val () = fprint! (out, c)\n in\n aux1 (dynargs, i, succ(j), false)\n end \/\/ end of [let]\n \/\/ end of [case]\n end \/\/ end of [if]\n \/\/ end of [aux1]\nin\n if strnptr_isnot_null (dynargs) then let \n prval () = lemma_strnptr_param (dynargs)\n val i = (i2sz)0\n val () = if ~append then fprint! (out, \"(\")\n in\n if strnptr_is_atend (dynargs, i) then fprint! (out, \")\")\n else aux0 (dynargs, i, append)\n end \/\/ end of [if]\nend \/\/ end of [emit_dynargs]\n\n\/\/\nextern\nfun\nemit_fun_impl (out: FILEref, filename: string, dynargs: Strptr0): void\n\nimplement\nemit_fun_impl (out, filename, dynargs) = {\n\/\/\nval (fpf_filename_base | filename_base) = filename_get_base (filename)\nval () = fprint!(out, \"implement \")\nval base = strptr2strnptr (filename_base)\nprval [l:addr] EQADDR () = eqaddr_make_ptr (strnptr2ptr(base))\nprval [n:int] EQINT () = lemma_strnptr_eqint (base) where {\n extern\n praxi\n lemma_strnptr_eqint {l:addr}{n:int} (!strnptr (l, n)) : [m:int] EQINT (n, m)\n}\nprval () = lemma_strnptr_param (base)\nval () =\n\/\/\nif :(base: strnptr(l,n)) => strnptr_isnot_null (base) then let\n implement{env}\n strnptr_foreach$cont (c, env) = (c <> '.')\n implement{env}\n strnptr_foreach$fwork (c, env) = fprint!(out, c)\n prval () = lemma_strnptr_param (base)\n val _ = strnptr_foreach (base)\nin\n (*empty*)\nend \/\/ end of [if]\nval () = fprint!(out, \" (out\")\nval dynargs = strptr2strnptr (dynargs)\nval () = emit_dynargs (out, dynargs, true)\nval () = strnptr_free (dynargs)\nval () = fprintln!(out, \" = \")\nval bas = strnptr2strptr {l}{n} (base)\nprval () = fpf_filename_base (bas)\n\/\/\n} (* end of [emit_fun_impl] *)\n\n(* ****** ****** *)\n\nextern\nfun\nfprint_strbuf_pats_esc {m,n:int} (out: FILEref, sbf: &strbuf (m, n)): void\nimplement\nfprint_strbuf_pats_esc {m,n} (out, sbf) = let\n fun\n aux {i,n:nat | i <= n} (out: FILEref, sbf: &strbuf (m, n), i: size_t (i)): void =\n if strbuf_is_atend (sbf, i) then ()\n else let\n val c = strbuf_get_at (sbf, i)\n val i = succ(i)\n in\n (\n case+ c of\n | '\\n' => fprint! (out, \"\\\\n\")\n | '\\r' => fprint! (out, \"\\\\r\")\n | '\\t' => fprint! (out, \"\\\\t\")\n | '\\f' => fprint! (out, \"\\\\f\")\n | '\\v' => fprint! (out, \"\\\\v\")\n | '\\b' => fprint! (out, \"\\\\b\")\n | '\\\\' => fprint! (out, \"\\\\\\\\\")\n | '\"' => fprint! (out, \"\\\\\\\"\")\n | _ => fprint! (out, c)\n );\n aux (out, sbf, i)\n end \/\/ end of [if]\n \/\/ end of [aux]\n prval () = lemma_strbuf_param (sbf)\n prval () = __trustme (sbf) where {\n extern\n prfun\n __trustme {m,n:int} (!strbuf (m, n)): [m > 0;n>=0] void\n } (* end of [prval] *)\nin\n aux (out, sbf, (i2sz)0)\nend \/\/ end of [fprint_strbuf_pats_esc]\n\nextern\nfun\nfprint_strptr_pats_esc (out: FILEref, s: !Strptr0): void\nimplement\nfprint_strptr_pats_esc (out, s) =\n if strptr_isnot_null (s) then {\n val p = strptr2ptr (s)\n prval (pf_at, fpf) = __trustme (s) where {\n extern\n prfun\n __trustme {l:agz} (\n !strptr (l) >> ptr (l)\n ): #[m,n:int] (strbuf_v (l, m, n), (strbuf_v (l, m, n), ptr (l)) - strptr (l))\n }\n val () = fprint_strbuf_pats_esc (out, !s)\n prval () = s := fpf (pf_at, p)\n } (* end of [if] *)\n\/\/ end of [fprint_strptr_pats_esc] *)\n\n(* ****** ****** *)\n\/\/\nextern\nfun treeWalk\n(out: FILEref, !xmlDocPtr1, !xmlNodePtr0): void\n\/\/\nimplement\ntreeWalk (out, doc, node) = let\n\/\/\nfun auxNode\n(\n out: FILEref\n, doc: !xmlDocPtr1\n, node: !xmlNodePtr0\n, nspace: int\n) : void = let\n\/\/\nval p_node = ptrcast (node)\n\/\/\nin\n\/\/\nif p_node > 0 then let\n val nodetype = xmlNode_get_type (node)\nin\n if nodetype = XML_ELEMENT_NODE then let\n \/\/ if node is one of special tags? otherwise, carry on\n \/\/ - if special: e.g. call, impl\n \/\/ - otherwise: just print it\n \/\/ - look out for text nodes, these might contain what we want to use\n \/\/ - similarly to attribute values, these might contain stuff we want to use\n val name = node.name()\n val name = xmlString2string (name)\n in\n case+ 0 of\n | _ when name = ATS_CALL => let\n \/\/ @fun (name of function to call)\n val attr_fun = xmlGetProp (node, ATS_FUN)\n val attr_fun = xmlStrptr2strptr (attr_fun)\n \/\/ @tmpargs (comma-\/semicolon-separated list of identifiers for specific template arguments)\n val tmpargs = xmlGetProp (node, ATS_TMPARGS)\n val tmpargs = xmlStrptr2strptr (tmpargs)\n \/\/ @dynargs (comma-separated list of identifiers for dynamic arguments)\n val dynargs = xmlGetProp (node, ATS_DYNARGS)\n val dynargs = xmlStrptr2strptr (dynargs)\n val () = indent (out, nspace)\n val () = fprint! (out, \"val () = \", attr_fun)\n val tmpargs = strptr2strnptr (tmpargs)\n val () = emit_tmpargs (out, false, tmpargs)\n val dynargs = strptr2strnptr (dynargs)\n val () = emit_dynargs (out, dynargs, false)\n val () = fprintln! (out, \" where {\")\n \/\/ recur\n val (fpf | nodelst) = node.children()\n val () = auxNode (out, doc, nodelst, nspace+2)\n prval () = minus_addback (fpf, nodelst | node)\n \/\/ end\n val () = indent (out, nspace)\n val () = fprintln! (out, \"}\")\n val () = strptr_free (attr_fun)\n val () = strnptr_free (tmpargs)\n val () = strnptr_free (dynargs)\n \/\/ ... stands for something else (e.g. the children of CALL)\n in\n end \/\/ end of [let]\n | _ when name = ATS_IMPL => let\n \/\/ @tmp (name of function template to implement)\n val tmp = xmlGetProp (node, ATS_TMP)\n val tmp = xmlStrptr2strptr (tmp)\n \/\/ @genargs (comma-\/semicolon-separated list of identifiers for generic template arguments)\n val genargs = xmlGetProp (node, ATS_GENARGS)\n val genargs = xmlStrptr2strptr (genargs)\n val genargs = strptr2strnptr (genargs)\n \/\/ @tmpargs (comma-\/semicolon-separated list of identifiers for template arguments)\n val tmpargs = xmlGetProp (node, ATS_TMPARGS)\n val tmpargs = xmlStrptr2strptr (tmpargs)\n val tmpargs = strptr2strnptr (tmpargs)\n \/\/ @dynargs (comma-separated list of identifiers for dynamic arguments)\n val dynargs = xmlGetProp (node, ATS_DYNARGS)\n val dynargs = xmlStrptr2strptr (dynargs)\n val dynargs = strptr2strnptr (dynargs)\n \/\/ implement tmp (dynargs) = ...\n \/\/ ... stands for something else (e.g. the children of IMPL)\n val () = indent (out, nspace)\n val () = fprint! (out, \"implement\")\n val () = emit_tmpargs (out, true, genargs)\n val () = fprintln! (out)\n val () = indent (out, nspace)\n val () = fprint! (out, tmp)\n val () = emit_tmpargs (out, false, tmpargs)\n val () = emit_dynargs (out, dynargs, false)\n val () = fprintln! (out, \" = {\")\n val () = strptr_free (tmp)\n val () = strnptr_free (genargs)\n val () = strnptr_free (tmpargs)\n val () = strnptr_free (dynargs)\n \/\/ recur\n val (fpf | nodelst) = node.children()\n val () = auxNode (out, doc, nodelst, nspace+2)\n prval () = minus_addback (fpf, nodelst | node)\n \/\/ end\n val () = indent (out, nspace)\n val () = fprintln! (out, \"}\") \n in\n end \/\/ end of [let]\n | _ => {\n val () = indent (out, nspace)\n val () = fprintln! (out, \"val () = htmlprint_tagname (out, \\\"\", name, \"\\\")\")\n \/\/\n val (fpf | proplst) = node.properties()\n val () = auxAttr (out, doc, proplst, nspace)\n prval () = minus_addback (fpf, proplst | node)\n \/\/\n val () = indent (out, nspace)\n val () = fprintln! (out, \"val () = htmlprint_chardata (out)\")\n \/\/\n val () = indent (out, nspace)\n val () = fprintln!(out, \"val () = {\")\n val (fpf | nodelst) = node.children()\n val () = auxNode (out, doc, nodelst, nspace+2)\n prval () = minus_addback (fpf, nodelst | node)\n val () = indent (out, nspace)\n val () = fprintln!(out, \"} (* end of [\", name, \"] *)\")\n \/\/\n val () = indent (out, nspace)\n val () = fprintln! (out, \"val () = htmlprint_tagend (out, \\\"\", name, \"\\\")\")\n \/\/\n val (fpf | node_next) = node.next()\n val () = auxNode (out, doc, node_next, nspace)\n prval () = minus_addback (fpf, node_next | node)\n \/\/\n } (* end of [_] *)\n end else if nodetype = XML_TEXT_NODE || nodetype = XML_CDATA_SECTION_NODE then let\n val text = xmlNodeGetContent (node)\n val text = xmlStrptr2strptr (text)\n val text = strptr2strnptr (text)\n local\n implement{env}\n paremit$fwork (toktype, sbf, env) = let\n val () = indent (out, nspace)\n in\n case+ toktype of\n | TT_TEXT () => {\n val () = fprint! (out, \"val () = htmlprint_string (out, \\\"\")\n val () = fprint_strbuf_pats_esc (out, sbf)\n val () = fprintln! (out, \"\\\")\")\n } (* end of [TT_TEXT] *)\n | TT_VAR () => fprintln! (out, \"val () = htmlprint_mac (out, \", sbf, \")\")\n | TT_EXPR () => fprintln! (out, \"val () = htmlprint_mac (out, \", sbf, \")\")\n end \/\/ end of [paremit$fwork]\n implement{env}\n paremit$err {l}{n,i} (errtype, str, i, env, msg) =\n {\n val () = fprintln!(out, \"error (\", errtype, \"): i: \", i, \":\", msg)\n } (* end of [paremit$err] *)\n in \/\/ in-of-local\n var env = (g0ofg1)0\n val () = if ptrcast(text) > 0 then paremit_env (text, env)\n end \/\/ end-of-local\n \/\/ what other parsing do we have to do?\n \/\/ list of whatever(identifiers) separated by , and ; \/\/ for dynargs, tmpargs, ats-dynargs\n val () = strnptr_free (text)\n val () = fprintln!(out)\n val (fpf | node_next) = node.next()\n val () = auxNode (out, doc, node_next, nspace)\n prval () = minus_addback (fpf, node_next | node)\n in\n end else if nodetype = XML_COMMENT_NODE then let\n val text = xmlNodeGetContent (node)\n val text = xmlStrptr2strptr (text)\n val () = indent (out, nspace)\n val () = fprintln!(out, \"val () = htmlprint_combeg (out)\")\n val () = indent (out, nspace)\n val () = fprint!(out, \"val () = htmlprint_string (out, \\\"\")\n val () = fprint_strptr_pats_esc (out, text)\n val () = fprintln!(out, \"\\\")\")\n val () = strptr_free (text)\n val () = indent (out, nspace)\n val () = fprintln!(out, \"val () = htmlprint_comend (out)\")\n val (fpf | node_next) = node.next()\n val () = auxNode (out, doc, node_next, nspace)\n prval () = minus_addback (fpf, node_next | node)\n in\n end else let\n \/\/ otherwise, skip!\n val () = fprintln!(out, \"unknown node type!\")\n val () = fprintln!(out, $UNSAFE.castvwtp0{int}(nodetype))\n val (fpf | node_next) = node.next()\n val () = auxNode (out, doc, node_next, nspace)\n prval () = minus_addback (fpf, node_next | node)\n in\n \/\/ nothing\n end\nend else () \/\/ end of [if]\n\/\/\nend \/\/ end of [auxNode]\n\nand auxAttr {l0:agz;l1:agez}\n(\n out: FILEref\n, doc: !xmlDocPtr(l0)\n, attr: !xmlAttrPtr(l1)\n, nspace: int\n) : void = let\n val p_attr = ptrcast (attr)\nin\n\/\/\nif p_attr > 0 then let\n val name = attr.name()\n val name = xmlString2string (name)\n\/\/\n val () =\n case+ :(doc: xmlDocPtr(l0), attr: xmlAttrPtr(l1)) => 0 of\n | _ when name = ATS_DYNARGS_TOP => ()\n | _ => {\n \/\/ NOTE: some special attributes should not be parsed this way!\n val (fpf_children | children) = attr.children()\n val value = xmlNodeListGetString (doc, children, 1)\n val value = xmlStrptr2strptr (value)\n val value = strptr2strnptr (value)\n val p_value = ptrcast (value)\n val () = indent (out, nspace)\n val () = fprintln! (out, \"val () = htmlprint_attrib (out, \\\"\", name, \"\\\")\")\n local\n implement{env}\n paremit$fwork (toktype, sbf, env) = let\n val () = indent (out, nspace)\n in\n case+ toktype of\n | TT_TEXT () => {\n val () = fprint! (out, \"val () = htmlprint_string (out, \\\"\")\n val () = fprint_strbuf_pats_esc (out, sbf)\n val () = fprintln! (out, \"\\\")\")\n } (* end of [TT_TEXT] *)\n | TT_VAR () => fprintln! (out, \"val () = htmlprint_mac (out, \", sbf, \")\")\n | TT_EXPR () => fprintln! (out, \"val () = htmlprint_mac (out, \", sbf, \")\")\n end \/\/ end of [paremit$fwork]\n implement{env}\n paremit$err {l}{n,i} (errtype, str, i, env, msg) = {\n val () = fprintln!(out, \"error (\", errtype, \"): i: \", i, \":\", msg)\n } (* end of [paremit$err] *)\n in \/\/ in-of-local\n var env = (g0ofg1)0\n val () = if ptrcast (value) > 0 then paremit_env (value, env)\n end \/\/ end-of-local\n val () = strnptr_free (value)\n prval () = minus_addback (fpf_children, children | attr)\n }\n\/\/\n val (fpf | attr2) = attr.next()\n val () = auxAttr (out, doc, attr2, nspace)\n prval () = minus_addback (fpf, attr2 | attr)\nin\n \/\/ nothing\nend else () \/\/ end of [if]\n\/\/\nend \/\/ end of [auxAttr]\n\/\/\nin\n auxNode (out, doc, node, 0)\nend \/\/ end of [treeWalk]\n\n(* ****** ****** *)\n\nimplement\nmain0 (argc, argv) = (\n\/\/\nif argc >= 3 then let\n\/\/\nval filename = argv[1]\nval outfile = argv[2]\n\/\/\nval encoding = stropt_none((*void*))\n\/\/\nval doc = htmlParseFile (filename, encoding)\n\/\/\nin\n\/\/\nif ptrcast (doc) > 0 then {\n\/\/\nval () = println! (\"The file [\", filename, \"] has been parsed successfully!\")\n\/\/\nval out = fileref_open_exn (outfile, file_mode_w)\nval (fpf | root) = xmlDocGetRootElement (doc)\nval root_dynargs =\n (if ptrcast (root) > 0 then let\n val root_params = xmlGetProp (root, ATS_DYNARGS_TOP)\n val root_params = xmlStrptr2strptr (root_params)\n in\n root_params\n end else strptr_null ()): Strptr0\nval () = emit_fun_impl (out, filename, root_dynargs)\nval () = fprintln!(out, \"{\")\nval () = fprintln! (out, \"val () = htmlprint_prolog (out)\")\nval () = treeWalk (out, doc, root)\nval () = fprintln!(out, \"} (* end of code for [\", filename, \"] *)\")\nprval ((*void*)) = minus_addback (fpf, root | doc)\n\/\/\nval () = xmlFreeDoc (doc)\n\/\/\nval () = xmlCleanupParser ((*void*))\n\/\/\nval () = fileref_close (out)\n\/\/\n} else {\n\/\/\nval () = prerrln!(\"parsing failed!\")\nval () = xmlFreeDoc (doc)\n\/\/\n} (* end of [if] *)\n\/\/\nend else println!(\"Usage: \")\n\/\/\n) (* end of [main] *)\n\n(* ****** ****** *)\n\n(* end of [html2pats.dats] *)\n","old_contents":"(*\n** HTML 2 ATS\/Postiats\n**\n** For simplifying the task of writing HTML-producing functions\n** in ATS\/Postiats.\n*)\n\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_staload.hats\"\n\/\/\n#define\nLIBXML2_targetloc \"$PATSHOMERELOC\/contrib\/libxml2\/libxml\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \"{$LIBXML2}\/SATS\/xml0.sats\"\nstaload _ = \"{$LIBXML2}\/DATS\/xml0.dats\"\n\/\/\n(* ****** ****** *)\n\nstaload \"{$LIBXML2}\/SATS\/tree.sats\"\nstaload \"{$LIBXML2}\/SATS\/parser.sats\"\nstaload \"{$LIBXML2}\/SATS\/HTMLparser.sats\"\n\n(* ****** ****** *)\n\n#define ATS_DYNARGS_TOP \"ats-dynargs\"\n#define ATS_CALL \"ats-call\"\n#define ATS_IMPL \"ats-impl\"\n#define ATS_TMP \"tmp\"\n#define ATS_FUN \"fun\"\n#define ATS_TMPARGS \"tmpargs\"\n#define ATS_GENARGS \"genargs\"\n#define ATS_DYNARGS \"dynargs\"\n#define ATS_DLR \"$\"\n#define ATS_LBRACE \"{\"\n#define ATS_RBRACE \"}\"\n#define ATS_ESCAPE \"\\\\\"\n\n(* ****** ****** *)\n\/\/\n\/\/ Parsing of embedded variables and expressions\n\/\/\n\n%{^\nATSinline()\natstype_bool\nATSPRELUDE_STRNPTR_IS_ATEND(atstype_strptr s, atstype_size i) {\n return (s[i]) == '\\000'? atsbool_true : atsbool_false;\n}\nATSinline()\natstype_void\nATSPRELUDE_STRBUF_INIT(atstype_ptrk sbf) {\n ((atstype_char*)sbf)[0] = '\\000';\n}\nATSinline()\natstype_size\nATSPRELUDE_STRBUF_PUT(atstype_ptrk sbf, atstype_size i, atstype_char c) {\n ((atstype_char*)sbf)[i] = c;\n return i+1;\n}\nATSinline()\natstype_void\nATSPRELUDE_STRBUF_FIN(atstype_ptrk sbf, atstype_size i) {\n ((atstype_char*)sbf)[i] = '\\000';\n}\nATSinline()\natstype_char\nATSPRELUDE_STRBUF_GET_AT(atstype_ptrk sbf, atstype_size i) {\n return ((atstype_char*)sbf)[i];\n}\n%}\n\nextern\nfun\nstrnptr_is_atend\n {l:agz}{n:int}{i:nat | i <= n}\n (s: !strnptr (l, n), i: size_t (i)):<> bool (i==n) = \"mac#ATSPRELUDE_STRNPTR_IS_ATEND\"\n\nextern\nfun\nstrbuf_is_atend\n {m,n,i:int | i <= n}\n (s: &strbuf (m, n), i: size_t (i)):<> bool (i==n) = \"mac#ATSPRELUDE_STRNPTR_IS_ATEND\"\nextern\nfun\nstrbuf_get_at\n {m,n,i:int | i < n}\n (s: &strbuf (m, n), i: size_t (i)):<> charNZ = \"mac#ATSPRELUDE_STRBUF_GET_AT\"\n\n\/\/ \"extended\" (for lack of better word)\nabst@ype estrbuf (m:int, n:int) \/\/ size same as strbuf (m, n)\n\nextern\ncastfn\nstrbuf_init {m:int | m > 0} (\n &b0ytes(m) >> estrbuf (m, 0)\n): void = \"mac#ATSPRELUDE_STRBUF_INIT\"\nextern\ncastfn\nstrbuf_clear {m,n:int} (\n !estrbuf (m, n) >> estrbuf (m, 0)\n): void\nextern\nfun\nstrbuf_reset {m,n:int | m > 0} (\n &strbuf (m, n) >> estrbuf (m, 0)\n): void = \"mac#ATSPRELUDE_STRBUF_INIT\"\nextern\nfun\nstrbuf_extend {m,n:int; n+1 < m} (\n sbf: &estrbuf (m, n) >> estrbuf (m, n+1), size_t n, c: charNZ\n): size_t (n+1) = \"mac#ATSPRELUDE_STRBUF_PUT\"\nextern\nfun\nstrbuf_finalize {m,n:int; n < m} (\n sbf: &estrbuf (m, n) >> strbuf (m, n), size_t n\n): void = \"mac#ATSPRELUDE_STRBUF_FIN\"\n\ndatatype TOKTYPE =\n | TT_TEXT\n | TT_VAR\n | TT_EXPR\ndatatype ERRTYPE =\n | ET_INVALID_CHARACTER\n | ET_PREMATURE_EOF\n | ET_OVERFLOW \/\/ buffer overflowed\n\nextern\nfun\nfprint_TOKTYPE (FILEref, TOKTYPE): void\noverload fprint with fprint_TOKTYPE\n\nextern\nfun\nprint_TOKTYPE (TOKTYPE): void\noverload print with print_TOKTYPE\n\nextern\nfun\nfprint_ERRTYPE (FILEref, ERRTYPE): void\noverload fprint with fprint_ERRTYPE\nextern\nfun\nprint_ERRTYPE (ERRTYPE): void\noverload print with print_ERRTYPE\n\nextern\nfun{env:vt@ype}\nparemit$fwork {m,n:int} (\n TOKTYPE, &strbuf (m, n), &(env) >> _\n): void\nextern\nfun{env:vt@ype}\nparemit$err {l:agz}{n,i:int | i <= n} (\n ERRTYPE\n, !strnptr (l, n), size_t i, &(env) >> _\n, string(*message*)\n): void\n\nextern\nfun{env:vt@ype}\nparemit_env {l:agz} {n:int} (\n !strnptr (l, n)\n, env: &(env) >> _\n): void\n\nimplement\nfprint_TOKTYPE (out, tp) =\n case+ tp of\n | TT_TEXT () => fprint_string (out, \"text\")\n | TT_VAR () => fprint_string (out, \"variable\")\n | TT_EXPR () => fprint_string (out, \"expression\")\nimplement\nprint_TOKTYPE (tp) = fprint_TOKTYPE (stdout_ref, tp)\n\nimplement\nfprint_ERRTYPE (out, et) =\n case+ et of\n | ET_INVALID_CHARACTER () => fprint_string (out, \"invalid character\")\n | ET_PREMATURE_EOF () => fprint_string (out, \"premature EOF\")\n | ET_OVERFLOW () => fprint_string (out, \"buffer overflow\")\nimplement\nprint_ERRTYPE (et) = fprint_ERRTYPE (stdout_ref, et)\n\nimplement{env}\nparemit_env {l} {n} (str, env) = let\n\/\/\n #define BUFSIZ 16384\n typedef Sbuf (k:int) = estrbuf (BUFSIZ, k)\n\/\/\n fun\n aux {n,j,k1:nat | j <= n; k1+1 <= BUFSIZ} (\n str: !strnptr (l, n)\n , j: size_t j\n , k: size_t k1\n , sbf: &Sbuf (k1) >> Sbuf (k2)\n , env: &(env) >> _\n ): #[k2:int | k2+1 <= BUFSIZ] size_t k2 =\n if strnptr_is_atend (str, j) then let\n \/\/ flush the text, if any\n val () =\n if :(sbf: Sbuf (0)) => k > (i2sz)0 then let\n val () = strbuf_finalize (sbf, k)\n val () = paremit$fwork (TT_TEXT, sbf, env) in\n strbuf_reset (sbf)\n end\n \/\/ end of [val]\n in\n (i2sz)0\n end else let\n val j0 = j\n val c = strnptr_get_at (str, j)\n in\n case+ c of\n | '\\\\' => let\n val j = succ(j)\n in\n if strnptr_is_atend (str, j) then let\n val () = paremit$err (ET_PREMATURE_EOF, str, j, env, \"looking for {, }, \\\\ or $\")\n in\n k\n end else let\n val c1 = strnptr_get_at (str, j)\n in\n case+ 0 of\n | _ when c1 = '$' || c1 = '\\{' || c1 = '}' || c1 = '\\\\' =>\n \/\/ okay to overflow here, just emit the existing TEXT you got so far\n if succ(k) < BUFSIZ then let\n val k = strbuf_extend (sbf, k, c1)\n in\n aux (str, succ(j), k, sbf, env)\n end else let\n val () = strbuf_finalize (sbf, k)\n val () = paremit$fwork (TT_TEXT, sbf, env)\n val () = strbuf_reset (sbf)\n val k = (i2sz)0\n val k1 = strbuf_extend (sbf, k, c1)\n in\n aux (str, succ(j), k1, sbf, env)\n end \/\/ end of [if]\n | _ => let\n val () = paremit$err (ET_INVALID_CHARACTER, str, j, env, \"looking for {, }, \\\\ or $\")\n in\n k\n end \/\/ end of [let]\n end \/\/ end of [if]\n end \/\/ end of [let]\n | '$' => let\n \/\/ flush the text, if any\n val () =\n if :(sbf: Sbuf (0)) => k > (i2sz)0 then let\n val () = strbuf_finalize (sbf, k)\n val () = paremit$fwork (TT_TEXT, sbf, env) in\n strbuf_reset (sbf)\n end\n \/\/ end of [val]\n val k = (i2sz)0\n val j = succ(j)\n in\n if strnptr_is_atend (str, j) then let\n val () = paremit$err (ET_PREMATURE_EOF, str, j, env, \"looking for alphabetic symbol or {\")\n in\n k\n end else let\n val c = strnptr_get_at (str, j)\n in\n case+ 0 of\n | _ when c = '\\{' => block (str, succ(j), k, sbf, env, 1)\n | _ when c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' =>\n if succ(k) < BUFSIZ then let\n val k = strbuf_extend (sbf, k, c)\n in\n ident (str, succ(j), k, sbf, env)\n end else let\n val () = strbuf_finalize (sbf, j)\n val () = paremit$err (ET_OVERFLOW, str, j, env, \"error\")\n val () = strbuf_reset (sbf)\n val k = (i2sz)0\n in\n k\n end \/\/ end of [if]\n | _ => let\n val () = paremit$err (ET_INVALID_CHARACTER, str, j, env, \"looking for alphabetic symbol or {\")\n in\n k\n end\n end \/\/ end of [if]\n end \/\/ end of [let]\n | _ =>\n \/\/ okay to overflow here, just emit the TEXT you got so far\n if succ(k) < BUFSIZ then let\n val k = strbuf_extend (sbf, k, c)\n in\n aux (str, succ(j), k, sbf, env)\n end else let\n val () = strbuf_finalize (sbf, k)\n val () = paremit$fwork (TT_TEXT, sbf, env)\n val () = strbuf_reset (sbf)\n val k = (i2sz)0\n val k = strbuf_extend (sbf, k, c)\n in\n aux (str, succ(j), k, sbf, env)\n end \/\/ end of [if]\n end \/\/ end of [aux]\n\n and\n block {n,j,k1:nat | j <= n; k1+1 <= BUFSIZ} (\n str: !strnptr (l, n), j: size_t j\n , k: size_t k1, sbf: &Sbuf (k1) >> Sbuf (k2)\n , env: &(env) >> _\n , count: int \/\/ brace count\n ): #[k2:nat | k2+1 <= BUFSIZ] size_t (k2) =\n if strnptr_is_atend (str, j) then let\n val () = paremit$err (ET_PREMATURE_EOF, str, j, env, \"looking for }\")\n in\n k\n end else let\n val c = strnptr_get_at (str, j)\n in\n case+ c of\n | '\\\\' => let\n val j = succ(j)\n in\n if strnptr_is_atend (str, j) then let\n val () = paremit$err (ET_PREMATURE_EOF, str, j, env, \"looking for {, }, \\\\ or $\")\n in\n k\n end else let\n val c1 = strnptr_get_at (str, j)\n in\n case+ 0 of\n | _ when c1 = '$' || c1 = '\\{' || c1 = '}' =>\n if succ(k) < BUFSIZ then let\n val k = strbuf_extend (sbf, k, c1)\n in\n block (str, succ(j), k, sbf, env, count)\n end else let\n val () = strbuf_finalize (sbf, k)\n val () = paremit$err (ET_OVERFLOW, str, j, env, \"error\")\n val k = (i2sz)0\n val () = strbuf_reset (sbf)\n in\n k\n end \/\/ end of [if]\n | _ => let\n val () = paremit$err (ET_INVALID_CHARACTER, str, j, env, \"looking for {, }, \\\\ or $\")\n in\n k\n end \/\/ end of [let]\n end \/\/ end of [if]\n end \/\/ end of [let]\n | '}' => let\n val count = pred(count)\n in\n if count = 0 then let\n \/\/ flush the text, if any\n val () =\n if :(sbf: Sbuf (0)) => k > (i2sz)0 then let\n val () = strbuf_finalize (sbf, k)\n val () = paremit$fwork (TT_EXPR, sbf, env) in\n strbuf_reset (sbf)\n end\n val k = (i2sz)0\n val j = succ(j)\n val k2 = aux (str, j, k, sbf, env)\n prval () = lemma_g1uint_param (k2)\n in\n k2\n end else let\n val j = succ(j)\n in\n if succ(k) < BUFSIZ then let\n val k = strbuf_extend (sbf, k, c)\n in\n block (str, j, k, sbf, env, count)\n end else let\n val () = paremit$err (ET_OVERFLOW, str, j, env, \"error\")\n val k = (i2sz)0\n val () = strbuf_clear (sbf)\n in\n k\n end \/\/ end of [if]\n end \/\/ end of [if]\n end \/\/ end of [let]\n | _ => let\n val j = succ(j)\n val count = if c = '\\{' then succ(count) else count\n in\n if succ(k) < BUFSIZ then let\n val k = strbuf_extend (sbf, k, c)\n in\n block (str, j, k, sbf, env, count)\n end else let\n val () = paremit$err (ET_OVERFLOW, str, j, env, \"error\")\n val k = (i2sz)0\n val () = strbuf_clear (sbf)\n in\n k\n end \/\/ end of [if]\n end \/\/ end of [let]\n end \/\/ end of [if]\n \/\/ end of [block]\n\n and\n ident {n,k1,j:nat | j <= n; k1+1 <= BUFSIZ} (\n str: !strnptr (l, n)\n , j: size_t j\n , k: size_t k1, sbf: &Sbuf (k1) >> Sbuf (k2)\n , env: &(env) >> _\n ): #[k2:nat | k2+1 <= BUFSIZ] size_t (k2) =\n if strnptr_is_atend (str, j) then (\n \/\/ flush the text, if any\n if :(sbf: Sbuf (0)) => k > (i2sz)0 then let\n val () = strbuf_finalize (sbf, k)\n val () = paremit$fwork (TT_VAR, sbf, env)\n val () = strbuf_reset (sbf) in\n (i2sz)0\n end else k\n ) else let\n val c = strnptr_get_at (str, j)\n in\n case+ 0 of\n | _ when c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' =>\n if succ(k) < BUFSIZ then let\n val k = strbuf_extend (sbf, k, c)\n in\n ident (str, succ(j), k, sbf, env)\n end else let\n val () = paremit$err (ET_OVERFLOW, str, j, env, \"error\")\n val k = (i2sz)0\n val () = strbuf_clear (sbf)\n in\n k\n end \/\/ end of [if]\n | _ => let\n val () =\n if :(sbf: Sbuf (0)) => k > (i2sz)0 then let\n val () = strbuf_finalize (sbf, k)\n val () = paremit$fwork (TT_VAR, sbf, env) in\n strbuf_reset (sbf)\n end\n \/\/ end of [val]\n val k = (i2sz)0\n val k = strbuf_extend (sbf, k, c)\n val k2 = aux (str, succ(j), k, sbf, env)\n prval () = lemma_g1uint_param (k2)\n in\n k2\n end \/\/ end of [let]\n end \/\/ end of [if]\n \/\/ end of [ident]\n prval () = lemma_strnptr_param (str)\n var sbuf = @[byte][BUFSIZ]()\n val () = strbuf_init (sbuf)\n val _ = aux (str, (i2sz)0, (i2sz)0, sbuf, env)\n val () = strbuf_clear (sbuf)\n val () = strbuf_finalize (sbuf, (i2sz)0)\n prval () = strbuf2bytes (sbuf)\nin\nend \/\/ end of [paremit_env]\n\n(* ****** ****** *)\n\/\/\nfun indent\n(\n out: FILEref, n: int\n) : void =\n if n > 0 then (fprint (out, ' '); indent (out, n-1))\n\/\/ end of [indent]\n\nextern\nfun\nemit_tmpargs {l:addr}{n:int} (out: FILEref, gen: bool, tmpargs: !strnptr (l, n)): void\nimplement\nemit_tmpargs {l}{n} (out, gen, args) = let\n fun\n aux0 {l:agz}{i,n:nat | i <= n} (dynargs: !strnptr (l, n), i: size_t (i), append: bool, gen: bool): void =\n if strnptr_is_atend (dynargs, i) then fprint! (out, (if gen then \")\" else \">\"):string)\n else let\n val c = strnptr_get_at (dynargs, i)\n in\n case+ 0 of\n | _ when c = ' ' || c = '\\n' || c = '\\r' || c = '\\t' || c = ';' => aux0 (dynargs, succ(i), append, gen)\n | _ => let\n val () = if append then fprint! (out, (if gen then \")(\" else \"><\"):string)\n in\n aux1 (dynargs, i, (i2sz)0, append, gen)\n end \/\/ end of [let]\n \/\/ end of [case]\n end \/\/ end of [if]\n \/\/ end of [aux]\n \n and\n aux1 {l:agz}{i,j,n:nat | i < n; i+j <= n} (dynargs: !strnptr (l, n), i: size_t (i), j: size_t (j), fst: bool, gen: bool): void =\n if strnptr_is_atend (dynargs, i+j) then fprint! (out, (if gen then \")\" else \">\"):string)\n else let\n val c = strnptr_get_at (dynargs, i+j)\n in\n case+ 0 of\n | _ when c = ' ' || c = '\\n' || c = '\\r' || c = '\\t' || c = ';' => aux0 (dynargs, succ(i+j), true, gen)\n | _ => let\n val () = fprint! (out, c)\n in\n aux1 (dynargs, i, succ(j), false, gen)\n end \/\/ end of [let]\n \/\/ end of [case]\n end \/\/ end of [if]\n \/\/ end of [aux1]\nin\n if strnptr_isnot_null (args) then let \n prval () = lemma_strnptr_param (args)\n val i = (i2sz)0\n val () = fprint! (out, (if gen then \"(\" else \"<\"): string)\n in\n if strnptr_is_atend (args, i) then fprint! (out, (if gen then \")\" else \">\"):string)\n else aux0 (args, i, false, gen)\n end \/\/ end of [if]\nend \/\/ end of [emit_tmpargs]\n\nextern\nfun\nemit_dynargs {l:addr}{n:int} (out: FILEref, dynargs: !strnptr (l, n), append: bool): void\nimplement\nemit_dynargs {n} (out, dynargs, append) = let\n fun\n aux0 {l:agz}{i,n:nat | i <= n} (dynargs: !strnptr (l, n), i: size_t (i), append: bool): void =\n if strnptr_is_atend (dynargs, i) then fprint! (out, \")\")\n else let\n val c = strnptr_get_at (dynargs, i)\n in\n case+ 0 of\n | _ when c = ' ' || c = '\\n' || c = '\\r' || c = '\\t' || c = ',' => aux0 (dynargs, succ(i), append)\n | _ => let\n val () = if append then fprint! (out, \", \")\n in\n aux1 (dynargs, i, (i2sz)0, append)\n end \/\/ end of [let]\n \/\/ end of [case]\n end \/\/ end of [if]\n \/\/ end of [aux]\n \n and\n aux1 {l:agz}{i,j,n:nat | i < n; i+j <= n} (dynargs: !strnptr (l, n), i: size_t (i), j: size_t (j), fst: bool): void =\n if strnptr_is_atend (dynargs, i+j) then fprint! (out, \")\")\n else let\n val c = strnptr_get_at (dynargs, i+j)\n in\n case+ 0 of\n | _ when c = ' ' || c = '\\n' || c = '\\r' || c = '\\t' || c = ',' => aux0 (dynargs, succ(i+j), true)\n | _ => let\n val () = fprint! (out, c)\n in\n aux1 (dynargs, i, succ(j), false)\n end \/\/ end of [let]\n \/\/ end of [case]\n end \/\/ end of [if]\n \/\/ end of [aux1]\nin\n if strnptr_isnot_null (dynargs) then let \n prval () = lemma_strnptr_param (dynargs)\n val i = (i2sz)0\n val () = if ~append then fprint! (out, \"(\")\n in\n if strnptr_is_atend (dynargs, i) then fprint! (out, \")\")\n else aux0 (dynargs, i, append)\n end \/\/ end of [if]\nend \/\/ end of [emit_dynargs]\n\n\/\/\nextern\nfun\nemit_fun_impl (out: FILEref, filename: string, dynargs: Strptr0): void\n\nimplement\nemit_fun_impl (out, filename, dynargs) = {\n\/\/\nval (fpf_filename_base | filename_base) = filename_get_base (filename)\nval () = fprint!(out, \"implement \")\nval base = strptr2strnptr (filename_base)\nprval [l:addr] EQADDR () = eqaddr_make_ptr (strnptr2ptr(base))\nprval [n:int] EQINT () = lemma_strnptr_eqint (base) where {\n extern\n praxi\n lemma_strnptr_eqint {l:addr}{n:int} (!strnptr (l, n)) : [m:int] EQINT (n, m)\n}\nprval () = lemma_strnptr_param (base)\nval () =\n\/\/\nif :(base: strnptr(l,n)) => strnptr_isnot_null (base) then let\n implement{env}\n strnptr_foreach$cont (c, env) = (c <> '.')\n implement{env}\n strnptr_foreach$fwork (c, env) = fprint!(out, c)\n prval () = lemma_strnptr_param (base)\n val _ = strnptr_foreach (base)\nin\n (*empty*)\nend \/\/ end of [if]\nval () = fprint!(out, \" (out\")\nval dynargs = strptr2strnptr (dynargs)\nval () = emit_dynargs (out, dynargs, true)\nval () = strnptr_free (dynargs)\nval () = fprintln!(out, \" = \")\nval bas = strnptr2strptr {l}{n} (base)\nprval () = fpf_filename_base (bas)\n\/\/\n} (* end of [emit_fun_impl] *)\n\n(* ****** ****** *)\n\nextern\nfun\nfprint_strbuf_pats_esc {m,n:int} (out: FILEref, sbf: &strbuf (m, n)): void\nimplement\nfprint_strbuf_pats_esc {m,n} (out, sbf) = let\n fun\n aux {i,n:nat | i <= n} (out: FILEref, sbf: &strbuf (m, n), i: size_t (i)): void =\n if strbuf_is_atend (sbf, i) then ()\n else let\n val c = strbuf_get_at (sbf, i)\n val i = succ(i)\n in\n (\n case+ c of\n | '\\n' => fprint! (out, \"\\\\n\")\n | '\\r' => fprint! (out, \"\\\\r\")\n | '\\t' => fprint! (out, \"\\\\t\")\n | '\\f' => fprint! (out, \"\\\\f\")\n | '\\v' => fprint! (out, \"\\\\v\")\n | '\\b' => fprint! (out, \"\\\\b\")\n | '\\\\' => fprint! (out, \"\\\\\\\\\")\n | '\"' => fprint! (out, \"\\\\\\\"\")\n | _ => fprint! (out, c)\n );\n aux (out, sbf, i)\n end \/\/ end of [if]\n \/\/ end of [aux]\n prval () = lemma_strbuf_param (sbf)\n prval () = __trustme (sbf) where {\n extern\n prfun\n __trustme {m,n:int} (!strbuf (m, n)): [m > 0;n>=0] void\n } (* end of [prval] *)\nin\n aux (out, sbf, (i2sz)0)\nend \/\/ end of [fprint_strbuf_pats_esc]\n\nextern\nfun\nfprint_strptr_pats_esc (out: FILEref, s: !Strptr0): void\nimplement\nfprint_strptr_pats_esc (out, s) =\n if strptr_isnot_null (s) then {\n val p = strptr2ptr (s)\n prval (pf_at, fpf) = __trustme (s) where {\n extern\n prfun\n __trustme {l:agz} (\n !strptr (l) >> ptr (l)\n ): #[m,n:int] (strbuf_v (l, m, n), (strbuf_v (l, m, n), ptr (l)) - strptr (l))\n }\n val () = fprint_strbuf_pats_esc (out, !s)\n prval () = s := fpf (pf_at, p)\n } (* end of [if] *)\n\/\/ end of [fprint_strptr_pats_esc] *)\n\n(* ****** ****** *)\n\/\/\nextern\nfun treeWalk\n(out: FILEref, !xmlDocPtr1, !xmlNodePtr0): void\n\/\/\nimplement\ntreeWalk (out, doc, node) = let\n\/\/\nfun auxNode\n(\n out: FILEref\n, doc: !xmlDocPtr1\n, node: !xmlNodePtr0\n, nspace: int\n) : void = let\n\/\/\nval p_node = ptrcast (node)\n\/\/\nin\n\/\/\nif p_node > 0 then let\n val nodetype = xmlNode_get_type (node)\nin\n if nodetype = XML_ELEMENT_NODE then let\n \/\/ if node is one of special tags? otherwise, carry on\n \/\/ - if special: e.g. call, impl\n \/\/ - otherwise: just print it\n \/\/ - look out for text nodes, these might contain what we want to use\n \/\/ - similarly to attribute values, these might contain stuff we want to use\n val name = __name (node)\n val name = xmlString2string (name)\n in\n case+ 0 of\n | _ when name = ATS_CALL => let\n \/\/ @fun (name of function to call)\n val attr_fun = xmlGetProp (node, ATS_FUN)\n val attr_fun = xmlStrptr2strptr (attr_fun)\n \/\/ @tmpargs (comma-\/semicolon-separated list of identifiers for specific template arguments)\n val tmpargs = xmlGetProp (node, ATS_TMPARGS)\n val tmpargs = xmlStrptr2strptr (tmpargs)\n \/\/ @dynargs (comma-separated list of identifiers for dynamic arguments)\n val dynargs = xmlGetProp (node, ATS_DYNARGS)\n val dynargs = xmlStrptr2strptr (dynargs)\n val () = indent (out, nspace)\n val () = fprint! (out, \"val () = \", attr_fun)\n val tmpargs = strptr2strnptr (tmpargs)\n val () = emit_tmpargs (out, false, tmpargs)\n val dynargs = strptr2strnptr (dynargs)\n val () = emit_dynargs (out, dynargs, false)\n val () = fprintln! (out, \" where {\")\n \/\/ recur\n val (fpf | nodelst) = __children (node)\n val () = auxNode (out, doc, nodelst, nspace+2)\n prval () = minus_addback (fpf, nodelst | node)\n \/\/ end\n val () = indent (out, nspace)\n val () = fprintln! (out, \"}\")\n val () = strptr_free (attr_fun)\n val () = strnptr_free (tmpargs)\n val () = strnptr_free (dynargs)\n \/\/ ... stands for something else (e.g. the children of CALL)\n in\n end \/\/ end of [let]\n | _ when name = ATS_IMPL => let\n \/\/ @tmp (name of function template to implement)\n val tmp = xmlGetProp (node, ATS_TMP)\n val tmp = xmlStrptr2strptr (tmp)\n \/\/ @genargs (comma-\/semicolon-separated list of identifiers for generic template arguments)\n val genargs = xmlGetProp (node, ATS_GENARGS)\n val genargs = xmlStrptr2strptr (genargs)\n val genargs = strptr2strnptr (genargs)\n \/\/ @tmpargs (comma-\/semicolon-separated list of identifiers for template arguments)\n val tmpargs = xmlGetProp (node, ATS_TMPARGS)\n val tmpargs = xmlStrptr2strptr (tmpargs)\n val tmpargs = strptr2strnptr (tmpargs)\n \/\/ @dynargs (comma-separated list of identifiers for dynamic arguments)\n val dynargs = xmlGetProp (node, ATS_DYNARGS)\n val dynargs = xmlStrptr2strptr (dynargs)\n val dynargs = strptr2strnptr (dynargs)\n \/\/ implement tmp (dynargs) = ...\n \/\/ ... stands for something else (e.g. the children of IMPL)\n val () = indent (out, nspace)\n val () = fprint! (out, \"implement\")\n val () = emit_tmpargs (out, true, genargs)\n val () = fprintln! (out)\n val () = indent (out, nspace)\n val () = fprint! (out, tmp)\n val () = emit_tmpargs (out, false, tmpargs)\n val () = emit_dynargs (out, dynargs, false)\n val () = fprintln! (out, \" = {\")\n val () = strptr_free (tmp)\n val () = strnptr_free (genargs)\n val () = strnptr_free (tmpargs)\n val () = strnptr_free (dynargs)\n \/\/ recur\n val (fpf | nodelst) = __children (node)\n val () = auxNode (out, doc, nodelst, nspace+2)\n prval () = minus_addback (fpf, nodelst | node)\n \/\/ end\n val () = indent (out, nspace)\n val () = fprintln! (out, \"}\") \n in\n end \/\/ end of [let]\n | _ => {\n val () = indent (out, nspace)\n val () = fprintln! (out, \"val () = htmlprint_tagname (out, \\\"\", name, \"\\\")\")\n \/\/\n val (fpf | proplst) = __properties (node)\n val () = auxAttr (out, doc, proplst, nspace)\n prval () = minus_addback (fpf, proplst | node)\n \/\/\n val () = indent (out, nspace)\n val () = fprintln! (out, \"val () = htmlprint_chardata (out)\")\n \/\/\n val () = indent (out, nspace)\n val () = fprintln!(out, \"val () = {\")\n val (fpf | nodelst) = __children (node)\n val () = auxNode (out, doc, nodelst, nspace+2)\n prval () = minus_addback (fpf, nodelst | node)\n val () = indent (out, nspace)\n val () = fprintln!(out, \"} (* end of [\", name, \"] *)\")\n \/\/\n val () = indent (out, nspace)\n val () = fprintln! (out, \"val () = htmlprint_tagend (out, \\\"\", name, \"\\\")\")\n \/\/\n val (fpf | node_next) = __next (node)\n val () = auxNode (out, doc, node_next, nspace)\n prval () = minus_addback (fpf, node_next | node)\n \/\/\n } (* end of [_] *)\n end else if nodetype = XML_TEXT_NODE || nodetype = XML_CDATA_SECTION_NODE then let\n val text = xmlNodeGetContent (node)\n val text = xmlStrptr2strptr (text)\n val text = strptr2strnptr (text)\n local\n implement{env}\n paremit$fwork (toktype, sbf, env) = let\n val () = indent (out, nspace)\n in\n case+ toktype of\n | TT_TEXT () => {\n val () = fprint! (out, \"val () = htmlprint_string (out, \\\"\")\n val () = fprint_strbuf_pats_esc (out, sbf)\n val () = fprintln! (out, \"\\\")\")\n } (* end of [TT_TEXT] *)\n | TT_VAR () => fprintln! (out, \"val () = htmlprint_mac (out, \", sbf, \")\")\n | TT_EXPR () => fprintln! (out, \"val () = htmlprint_mac (out, \", sbf, \")\")\n end \/\/ end of [paremit$fwork]\n implement{env}\n paremit$err {l}{n,i} (errtype, str, i, env, msg) =\n {\n val () = fprintln!(out, \"error (\", errtype, \"): i: \", i, \":\", msg)\n } (* end of [paremit$err] *)\n in \/\/ in-of-local\n var env = (g0ofg1)0\n val () = if ptrcast(text) > 0 then paremit_env (text, env)\n end \/\/ end-of-local\n \/\/ what other parsing do we have to do?\n \/\/ list of whatever(identifiers) separated by , and ; \/\/ for dynargs, tmpargs, ats-dynargs\n val () = strnptr_free (text)\n val () = fprintln!(out)\n val (fpf | node_next) = __next (node)\n val () = auxNode (out, doc, node_next, nspace)\n prval () = minus_addback (fpf, node_next | node)\n in\n end else if nodetype = XML_COMMENT_NODE then let\n val text = xmlNodeGetContent (node)\n val text = xmlStrptr2strptr (text)\n val () = indent (out, nspace)\n val () = fprintln!(out, \"val () = htmlprint_combeg (out)\")\n val () = indent (out, nspace)\n val () = fprint!(out, \"val () = htmlprint_string (out, \\\"\")\n val () = fprint_strptr_pats_esc (out, text)\n val () = fprintln!(out, \"\\\")\")\n val () = strptr_free (text)\n val () = indent (out, nspace)\n val () = fprintln!(out, \"val () = htmlprint_comend (out)\")\n val (fpf | node_next) = __next (node)\n val () = auxNode (out, doc, node_next, nspace)\n prval () = minus_addback (fpf, node_next | node)\n in\n end else let\n \/\/ otherwise, skip!\n val () = fprintln!(out, \"unknown node type!\")\n val () = fprintln!(out, $UNSAFE.castvwtp0{int}(nodetype))\n val (fpf | node_next) = __next (node)\n val () = auxNode (out, doc, node_next, nspace)\n prval () = minus_addback (fpf, node_next | node)\n in\n \/\/ nothing\n end\nend else () \/\/ end of [if]\n\/\/\nend \/\/ end of [auxNode]\n\nand auxAttr {l0:agz;l1:agez}\n(\n out: FILEref\n, doc: !xmlDocPtr(l0)\n, attr: !xmlAttrPtr(l1)\n, nspace: int\n) : void = let\n val p_attr = ptrcast (attr)\nin\n\/\/\nif p_attr > 0 then let\n val name = __name (attr)\n val name = xmlString2string (name)\n\/\/\n val () =\n case+ :(doc: xmlDocPtr(l0), attr: xmlAttrPtr(l1)) => 0 of\n | _ when name = ATS_DYNARGS_TOP => ()\n | _ => {\n \/\/ NOTE: some special attributes should not be parsed this way!\n val (fpf_children | children) = __children (attr)\n val value = xmlNodeListGetString (doc, children, 1)\n val value = xmlStrptr2strptr (value)\n val value = strptr2strnptr (value)\n val p_value = ptrcast (value)\n val () = indent (out, nspace)\n val () = fprintln! (out, \"val () = htmlprint_attrib (out, \\\"\", name, \"\\\")\")\n local\n implement{env}\n paremit$fwork (toktype, sbf, env) = let\n val () = indent (out, nspace)\n in\n case+ toktype of\n | TT_TEXT () => {\n val () = fprint! (out, \"val () = htmlprint_string (out, \\\"\")\n val () = fprint_strbuf_pats_esc (out, sbf)\n val () = fprintln! (out, \"\\\")\")\n } (* end of [TT_TEXT] *)\n | TT_VAR () => fprintln! (out, \"val () = htmlprint_mac (out, \", sbf, \")\")\n | TT_EXPR () => fprintln! (out, \"val () = htmlprint_mac (out, \", sbf, \")\")\n end \/\/ end of [paremit$fwork]\n implement{env}\n paremit$err {l}{n,i} (errtype, str, i, env, msg) = {\n val () = fprintln!(out, \"error (\", errtype, \"): i: \", i, \":\", msg)\n } (* end of [paremit$err] *)\n in \/\/ in-of-local\n var env = (g0ofg1)0\n val () = if ptrcast (value) > 0 then paremit_env (value, env)\n end \/\/ end-of-local\n val () = strnptr_free (value)\n prval () = minus_addback (fpf_children, children | attr)\n }\n\/\/\n val (fpf | attr2) = __next (attr)\n val () = auxAttr (out, doc, attr2, nspace)\n prval () = minus_addback (fpf, attr2 | attr)\nin\n \/\/ nothing\nend else () \/\/ end of [if]\n\/\/\nend \/\/ end of [auxAttr]\n\/\/\nin\n auxNode (out, doc, node, 0)\nend \/\/ end of [treeWalk]\n\n(* ****** ****** *)\n\nimplement\nmain0 (argc, argv) = (\n\/\/\nif argc >= 3 then let\n\/\/\nval filename = argv[1]\nval outfile = argv[2]\n\/\/\nval encoding = stropt_none((*void*))\n\/\/\nval doc = htmlParseFile (filename, encoding)\n\/\/\nin\n\/\/\nif ptrcast (doc) > 0 then {\n\/\/\nval () = println! (\"The file [\", filename, \"] has been parsed successfully!\")\n\/\/\nval out = fileref_open_exn (outfile, file_mode_w)\nval (fpf | root) = xmlDocGetRootElement (doc)\nval root_dynargs =\n (if ptrcast (root) > 0 then let\n val root_params = xmlGetProp (root, ATS_DYNARGS_TOP)\n val root_params = xmlStrptr2strptr (root_params)\n in\n root_params\n end else strptr_null ()): Strptr0\nval () = emit_fun_impl (out, filename, root_dynargs)\nval () = fprintln!(out, \"{\")\nval () = fprintln! (out, \"val () = htmlprint_prolog (out)\")\nval () = treeWalk (out, doc, root)\nval () = fprintln!(out, \"} (* end of code for [\", filename, \"] *)\")\nprval ((*void*)) = minus_addback (fpf, root | doc)\n\/\/\nval () = xmlFreeDoc (doc)\n\/\/\nval () = xmlCleanupParser ((*void*))\n\/\/\nval () = fileref_close (out)\n\/\/\n} else {\n\/\/\nval () = prerrln!(\"parsing failed!\")\nval () = xmlFreeDoc (doc)\n\/\/\n} (* end of [if] *)\n\/\/\nend else println!(\"Usage: \")\n\/\/\n) (* end of [main] *)\n\n(* ****** ****** *)\n\n(* end of [html2pats.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"638bdc9ed5f5198367cf3d5d11ef3bbf5a883aeb","subject":"Updating: fixing a typo","message":"Updating: fixing a typo\n","repos":"ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib","old_file":"projects\/MEDIUM\/ATS-extsolve\/ATS-extsolve-z3\/TEST\/fact2.dats","new_file":"projects\/MEDIUM\/ATS-extsolve\/ATS-extsolve-z3\/TEST\/fact2.dats","new_contents":"(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_staload.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstacst fact: int -> int\n\/\/\n(* ****** ****** *)\n\/\/\nextern\npraxi\nfact_bas(): [fact(0)==1] unit_p\nextern\npraxi\nfact_ind{n:pos}(): [fact(n)==n*fact(n-1)] unit_p\n\/\/\n(* ****** ****** *)\n\n(*\n\/\/\n\/\/ HX:\n\/\/ it works with Z3-4.3.?\n\/\/ it does not work with Z3-4.4.0\n\/\/\nfun\nfact\n{n:nat}\n(\n n: int(n)\n) : int(fact(n)) = let\n\/\/\nprval() = $solver_assert(fact_bas)\nprval() = $solver_assert(fact_ind)\n\/\/\nfun\nloop\n{n:nat}\n{r:int} ..\n(\n n: int(n), r: int(r)\n) : int(fact(n)*r) = (\n\/\/\nif n = 0 then (r) else loop(n-1, n*r)\n\/\/\n) (* end of [loop] *)\n\/\/\nin\n loop(n, 1)\nend \/\/ end of [fact]\n*)\n\n(* ****** ****** *)\n\nfun\nfact\n{n:nat}\n(\n n: int(n)\n) : int(fact(n)) = let\n\/\/\nprval() = $solver_assert(fact_bas)\nprval() = $solver_assert(fact_ind)\n\/\/\nfun\nloop\n{ i:nat\n| i <= n\n} ..\n(\n i: int(i), r: int(fact(i))\n) : int(fact(n)) = (\n\/\/\nif i < n then loop(i+1, (i+1)*r) else r\n\/\/\n) (* end of [loop] *)\n\/\/\nin\n loop(0, 1)\nend \/\/ end of [fact]\n\n(* ****** ****** *)\n\nimplement\nmain0(argc, argv) =\n{\n\/\/\nval n =\n(\nif (argc >= 2)\n then g0string2int(argv[1]) else 10\n\/\/ end of [if]\n) : int \/\/ end of [val]\n\/\/\nval n = g1ofg0(n)\nval n = (if n >= 0 then n else 0): intGte(0)\n\/\/\nval () = println! (\"fact(\", n, \") = \", fact(n))\n\/\/\n} (* end of [main0] *)\n\n(* ****** ****** *)\n\n(* end of [fact2.dats] *)\n","old_contents":"(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_staload.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstacst fact: int -> int\n\/\/\n(* ****** ****** *)\n\/\/\nextern\npraxi\nfact_bas(): [fact(0)==1] unit_p\nextern\npraxi\nfact_ind{n:pos}(): [fact(n)==n*fact(n-1)] unit_p\n\/\/\n(* ****** ****** *)\n\n(*\n\/\/\n\/\/ HX:\n\/\/ it works with Z3-4.4.0\n\/\/ it does not work with Z3-4.4.0\n\/\/\nfun\nfact\n{n:nat}\n(\n n: int(n)\n) : int(fact(n)) = let\n\/\/\nprval() = $solver_assert(fact_bas)\nprval() = $solver_assert(fact_ind)\n\/\/\nfun\nloop\n{n:nat}\n{r:int} ..\n(\n n: int(n), r: int(r)\n) : int(fact(n)*r) = (\n\/\/\nif n = 0 then (r) else loop(n-1, n*r)\n\/\/\n) (* end of [loop] *)\n\/\/\nin\n loop(n, 1)\nend \/\/ end of [fact]\n*)\n\n(* ****** ****** *)\n\nfun\nfact\n{n:nat}\n(\n n: int(n)\n) : int(fact(n)) = let\n\/\/\nprval() = $solver_assert(fact_bas)\nprval() = $solver_assert(fact_ind)\n\/\/\nfun\nloop\n{ i:nat\n| i <= n\n} ..\n(\n i: int(i), r: int(fact(i))\n) : int(fact(n)) = (\n\/\/\nif i < n then loop(i+1, (i+1)*r) else r\n\/\/\n) (* end of [loop] *)\n\/\/\nin\n loop(0, 1)\nend \/\/ end of [fact]\n\n(* ****** ****** *)\n\nimplement\nmain0(argc, argv) =\n{\n\/\/\nval n =\n(\nif (argc >= 2)\n then g0string2int(argv[1]) else 10\n\/\/ end of [if]\n) : int \/\/ end of [val]\n\/\/\nval n = g1ofg0(n)\nval n = (if n >= 0 then n else 0): intGte(0)\n\/\/\nval () = println! (\"fact(\", n, \") = \", fact(n))\n\/\/\n} (* end of [main0] *)\n\n(* ****** ****** *)\n\n(* end of [fact2.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"67a0b6c6d7bb08f198f51a119e2de4fa1600f2ed","subject":"fix bug with S2EVar","message":"fix bug with S2EVar\n","repos":"alex-ren\/Learn-ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,alex-ren\/Learn-ATS-Postiats-contrib,wdblair\/ATS-Postiats-contrib","old_file":"projects\/MEDIUM\/ATS-extsolve\/parsing\/parsing_s2exp.dats","new_file":"projects\/MEDIUM\/ATS-extsolve\/parsing\/parsing_s2exp.dats","new_contents":"(*\n** Parsing constraints in JSON format\n*)\n\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_define.hats\"\n#include\n\"share\/atspre_staload.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \"constraint\/constraint.sats\"\n\/\/\n(* ****** ****** *)\n\nstaload \"parsing\/jsonval.sats\"\n\n(* ****** ****** *)\n\nstaload \"parsing\/parsing.sats\"\n\n(* ****** ****** *)\n\nextern\nfun{}\nparse_s2exp_node (jsonval): s2exp_node\n\n(* ****** ****** *)\n\nimplement{}\nparse_s2exp\n (jsv0) = let\n\/\/\nval jsv = jsv0[\"s2exp_srt\"]\nval s2t = parse_s2rt (jsv)\nval jsv = jsv0[\"s2exp_node\"]\nval node = parse_s2exp_node (jsv)\n\/\/\nin\n s2exp_make_node (s2t, node)\nend \/\/ end of [parse_s2exp]\n\n(* ****** ****** *)\n\nimplement{}\nparse_s2explst \n (jsv0) = let\n \n implement\n jsonval_parse (jsv) = parse_s2exp (jsv)\n \nin\n parse_list (jsv0)\nend\n\n(* ****** ****** *)\n\nimplement{}\nparse_s2exp_node\n (jsv0) = let\n(*\nval (\n) = fprintln!\n (stdout_ref, \"parse_s2exp_node: jsv0 = \", jsv0)\n*)\nin\n if jsv0.has_key(\"S2Eint\") then\n parse_S2Eint (jsv0[\"S2Eint\"])\n \n else if jsv0.has_key(\"S2Eintinf\") then\n parse_S2Eintinf (jsv0[\"S2Eintinf\"])\n \n else if jsv0.has_key(\"S2Ecst\") then\n parse_S2Ecst (jsv0[\"S2Ecst\"])\n \n else if jsv0.has_key(\"S2Evar\") then\n parse_S2Evar (jsv0[\"S2Evar\"])\n \n else if jsv0.has_key(\"S2EVar\") then\n parse_S2EVar (jsv0[\"S2EVar\"])\n \n else if jsv0.has_key(\"S2Eeqeq\") then\n parse_S2Eeqeq (jsv0[\"S2Eeqeq\"])\n \n else if jsv0.has_key(\"S2Eapp\") then\n parse_S2Eapp (jsv0[\"S2Eapp\"])\n \n else if jsv0.has_key(\"S2Emetdec\") then\n parse_S2Emetdec (jsv0[\"S2Emetdec\"])\n \n else if jsv0.has_key( \"S2Esizeof\" ) then\n parse_S2Esizeof (jsv0[\"S2Esizeof\" ])\n \n else if jsv0.has_key(\"S2Etop\") then\n parse_S2Etop (jsv0[\"S2Etop\"])\n \n else let\n (**\n val () =\n prerrln! (\"warning(ATS): [parse_s2exp]: name = \", name)\n *)\n in\n parse_S2Eignored (jsv0)\n end\nend where {\n\nfun\nparse_S2Eint\n (jsv0:jsonval): s2exp_node = let\n\nval () = assertloc (jsv0.size >= 1)\n\nin\n S2Eint (parse_int (jsv0[0]))\nend \/\/ end of [parse_S2Eint]\n\nfun\nparse_S2Eintinf\n (jsv0:jsonval): s2exp_node = let\n\nval () = assertloc (jsv0.size >= 1)\n\nin\n S2Eintinf (parse_string (jsv0[0]))\nend \/\/ end of [parse_S2Eintinf]\n\nfun\nparse_S2Ecst\n (jsv0:jsonval): s2exp_node = let\n\nval () = assertloc (jsv0.size >= 1)\nval s2c = parse_s2cst (jsv0[0])\n\nin\n S2Ecst (s2c)\nend \/\/ end of [parse_S2Ecst]\n\nfun\nparse_S2Evar\n (jsv0:jsonval): s2exp_node = let\n\nval () = assertloc (jsv0.size >= 1)\nval s2v = parse_s2var (jsv0[0])\n\nin\n S2Evar (s2v)\nend \/\/ end of [parse_S2Evar]\n\nfun\nparse_S2EVar\n (jsv0:jsonval): s2exp_node = let\n\nval () = assertloc (jsv0.size >= 1)\nval s2V = parse_s2Var (jsv0[0])\n\nin\n S2EVar (s2V)\nend \/\/ end of [parse_S2EVar]\n\nfun\nparse_S2Eeqeq\n (jsv0:jsonval): s2exp_node = let\n\nval () = assertloc (jsv0.size >= 2)\nval l = parse_s2exp (jsv0[0])\nval r = parse_s2exp (jsv0[1])\n\nin\n S2Eeqeq (l, r)\nend \/\/ end of [parse_S2EVar]\n\nfun\nparse_S2Eapp\n (jsv0: jsonval): s2exp_node = let\n\nval () = assertloc (jsv0.size >= 2)\nval s2e_fun = parse_s2exp (jsv0[0])\nval s2es_arg = parse_s2explst (jsv0[1])\n\nin\n S2Eapp (s2e_fun, s2es_arg)\nend \/\/ end of [parse_S2Eapp]\n\nfun\nparse_S2Emetdec\n (jsv0:jsonval): s2exp_node = let\n\nval () = assertloc (jsv0.size >= 2)\nval met = parse_s2explst (jsv0[0])\nval bound = parse_s2explst (jsv0[1])\n\nin\n S2Emetdec (met, bound)\nend \/\/ end of [parse_S2Emetdec]\n\nfun\nparse_S2Esizeof\n (jsv0:jsonval): s2exp_node = let\n\nval () = assertloc (jsv0.size >= 1)\nval s2e = parse_s2exp (jsv0[0])\n\nin\n S2Esizeof (s2e)\nend \/\/ end of [parse_S2Esizeof]\n\nfun\nparse_S2Etop\n (jsv0:jsonval): s2exp_node = let\n\nval () = assertloc (jsv0.size >= 2)\nval knd = parse_int (jsv0[0])\nval s2e = parse_s2exp (jsv0[1])\n\nin\n S2Etop (knd, s2e)\nend \/\/ end of [parse_S2Esizeof]\n\nfun\nparse_S2Eignored \n (jsv: jsonval): s2exp_node = S2Eignored ((*void*))\n\n} \/\/ end of [parse_s2exp_node]\n\n(* ****** ****** *)\n\n(* end of [parsing_s2exp] *)\n","old_contents":"(*\n** Parsing constraints in JSON format\n*)\n\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_define.hats\"\n#include\n\"share\/atspre_staload.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload \"constraint\/constraint.sats\"\n\/\/\n(* ****** ****** *)\n\nstaload \"parsing\/jsonval.sats\"\n\n(* ****** ****** *)\n\nstaload \"parsing\/parsing.sats\"\n\n(* ****** ****** *)\n\nextern\nfun{}\nparse_s2exp_node (jsonval): s2exp_node\n\n(* ****** ****** *)\n\nimplement{}\nparse_s2exp\n (jsv0) = let\n\/\/\nval jsv = jsv0[\"s2exp_srt\"]\nval s2t = parse_s2rt (jsv)\nval jsv = jsv0[\"s2exp_node\"]\nval node = parse_s2exp_node (jsv)\n\/\/\nin\n s2exp_make_node (s2t, node)\nend \/\/ end of [parse_s2exp]\n\n(* ****** ****** *)\n\nimplement{}\nparse_s2explst \n (jsv0) = let\n \n implement\n jsonval_parse (jsv) = parse_s2exp (jsv)\n \nin\n parse_list (jsv0)\nend\n\n(* ****** ****** *)\n\nimplement{}\nparse_s2exp_node\n (jsv0) = let\n(*\nval (\n) = fprintln!\n (stdout_ref, \"parse_s2exp_node: jsv0 = \", jsv0)\n*)\nin\n if jsv0.has_key(\"S2Eint\") then\n parse_S2Eint (jsv0[\"S2Eint\"])\n \n else if jsv0.has_key(\"S2Eintinf\") then\n parse_S2Eintinf (jsv0[\"S2Eintinf\"])\n \n else if jsv0.has_key(\"S2Ecst\") then\n parse_S2Ecst (jsv0[\"S2Ecst\"])\n \n else if jsv0.has_key(\"S2Evar\") then\n parse_S2Evar (jsv0[\"S2Evar\"])\n \n else if jsv0.has_key(\"S2EVar\") then\n parse_S2EVar (jsv0[\"S2Evar\"])\n \n else if jsv0.has_key(\"S2Eeqeq\") then\n parse_S2Eeqeq (jsv0[\"S2Eeqeq\"])\n \n else if jsv0.has_key(\"S2Eapp\") then\n parse_S2Eapp (jsv0[\"S2Eapp\"])\n \n else if jsv0.has_key(\"S2Emetdec\") then\n parse_S2Emetdec (jsv0[\"S2Emetdec\"])\n \n else if jsv0.has_key( \"S2Esizeof\" ) then\n parse_S2Esizeof (jsv0[\"S2Esizeof\" ])\n \n else if jsv0.has_key(\"S2Etop\") then\n parse_S2Etop (jsv0[\"S2Etop\"])\n \n else let\n (**\n val () =\n prerrln! (\"warning(ATS): [parse_s2exp]: name = \", name)\n *)\n in\n parse_S2Eignored (jsv0)\n end\nend where {\n\nfun\nparse_S2Eint\n (jsv0:jsonval): s2exp_node = let\n\nval () = assertloc (jsv0.size >= 1)\n\nin\n S2Eint (parse_int (jsv0[0]))\nend \/\/ end of [parse_S2Eint]\n\nfun\nparse_S2Eintinf\n (jsv0:jsonval): s2exp_node = let\n\nval () = assertloc (jsv0.size >= 1)\n\nin\n S2Eintinf (parse_string (jsv0[0]))\nend \/\/ end of [parse_S2Eintinf]\n\nfun\nparse_S2Ecst\n (jsv0:jsonval): s2exp_node = let\n\nval () = assertloc (jsv0.size >= 1)\nval s2c = parse_s2cst (jsv0[0])\n\nin\n S2Ecst (s2c)\nend \/\/ end of [parse_S2Ecst]\n\nfun\nparse_S2Evar\n (jsv0:jsonval): s2exp_node = let\n\nval () = assertloc (jsv0.size >= 1)\nval s2v = parse_s2var (jsv0[0])\n\nin\n S2Evar (s2v)\nend \/\/ end of [parse_S2Evar]\n\nfun\nparse_S2EVar\n (jsv0:jsonval): s2exp_node = let\n\nval () = assertloc (jsv0.size >= 1)\nval s2V = parse_s2Var (jsv0[0])\n\nin\n S2EVar (s2V)\nend \/\/ end of [parse_S2EVar]\n\nfun\nparse_S2Eeqeq\n (jsv0:jsonval): s2exp_node = let\n\nval () = assertloc (jsv0.size >= 2)\nval l = parse_s2exp (jsv0[0])\nval r = parse_s2exp (jsv0[1])\n\nin\n S2Eeqeq (l, r)\nend \/\/ end of [parse_S2EVar]\n\nfun\nparse_S2Eapp\n (jsv0: jsonval): s2exp_node = let\n\nval () = assertloc (jsv0.size >= 2)\nval s2e_fun = parse_s2exp (jsv0[0])\nval s2es_arg = parse_s2explst (jsv0[1])\n\nin\n S2Eapp (s2e_fun, s2es_arg)\nend \/\/ end of [parse_S2Eapp]\n\nfun\nparse_S2Emetdec\n (jsv0:jsonval): s2exp_node = let\n\nval () = assertloc (jsv0.size >= 2)\nval met = parse_s2explst (jsv0[0])\nval bound = parse_s2explst (jsv0[1])\n\nin\n S2Emetdec (met, bound)\nend \/\/ end of [parse_S2Emetdec]\n\nfun\nparse_S2Esizeof\n (jsv0:jsonval): s2exp_node = let\n\nval () = assertloc (jsv0.size >= 1)\nval s2e = parse_s2exp (jsv0[0])\n\nin\n S2Esizeof (s2e)\nend \/\/ end of [parse_S2Esizeof]\n\nfun\nparse_S2Etop\n (jsv0:jsonval): s2exp_node = let\n\nval () = assertloc (jsv0.size >= 2)\nval knd = parse_int (jsv0[0])\nval s2e = parse_s2exp (jsv0[1])\n\nin\n S2Etop (knd, s2e)\nend \/\/ end of [parse_S2Esizeof]\n\nfun\nparse_S2Eignored \n (jsv: jsonval): s2exp_node = S2Eignored ((*void*))\n\n} \/\/ end of [parse_s2exp_node]\n\n(* ****** ****** *)\n\n(* end of [parsing_s2exp] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"0c7cf67e6cb96a035bdeac56b5c55f877fdb0f86","subject":"Updating: very minorly","message":"Updating: very minorly\n","repos":"githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib","old_file":"projects\/MEDIUM\/ATS-extsolve-z3\/TEST\/quadratic.dats","new_file":"projects\/MEDIUM\/ATS-extsolve-z3\/TEST\/quadratic.dats","new_contents":"(*\n** Testing some operations on reals\n*)\n\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_staload.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\n\"libats\/SATS\/Number\/real.sats\"\n\/\/\nstaload\n\"libats\/DATS\/Number\/real_double.dats\"\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nquadratic_solve1\n {A,B,C:real | A > 0}\n(\n A: real(A), B: real(B), C: real(C)\n) : [x:real | A*x*x+B*x+C==i2r(0)] real(x)\n\/\/\nextern\nfun\nquadratic_solve2\n {A,B,C:real | A > 0}\n(\n A: real(A), B: real(B), C: real(C)\n) : [x:real | A*x*x+B*x+C==i2r(0)] real(x)\n\/\/\n(* ****** ****** *)\n\n#define i2r(x) int2real(x)\n\n(* ****** ****** *)\n\/\/\nimplement\nquadratic_solve1\n (A, B, C) = let\n\/\/\nval Delta = B*B-4*A*C\n\/\/\nprval () =\n $solver_assert(lemma_sqrt_def)\n\/\/\nval ((*void*)) = assert(Delta >= 0)\n\/\/\nin\n (~B+sqrt(Delta))\/(2*A)\nend \/\/ end of [quadratic_solve1]\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nquadratic_solve2\n (A, B, C) = let\n\/\/\nval Delta = B*B-4*A*C\n\/\/\nprval () =\n $solver_assert(lemma_sqrt_def)\n\/\/\nval ((*void*)) = assert(Delta >= 0)\n\/\/\nin\n (~B-sqrt(Delta))\/(2*A)\nend \/\/ end of [quadratic_solve2]\n\/\/\n(* ****** ****** *)\n\nval root1 =\n quadratic_solve1(i2r(1), i2r(1), i2r(~1))\nval root2 =\n quadratic_solve2(i2r(1), i2r(1), i2r(~1))\n\n(* ****** ****** *)\n\nval () = println! (\"root1 = \", root1)\nval () = println! (\"root2 = \", root2)\n\n(* ****** ****** *)\n\nimplement\nmain0() = () where\n{\n\/\/\nval () =\nprintln! (\"Hello from [quadratic]\")\n\/\/\n} (* end of [main0] *)\n\n(* ****** ****** *)\n\n(* end of [quadratic.dats] *)\n","old_contents":"(*\n** Testing some operations on reals\n*)\n\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_staload.hats\"\n\/\/\n(* ****** ****** *)\n\/\/\nstaload\n\"libats\/SATS\/Number\/real.sats\"\n\/\/\nstaload\n\"libats\/DATS\/Number\/real_double.dats\"\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun\nquadratic_solve1\n {A,B,C:real}\n(\n A: real(A), B: real(B), C: real(C)\n) : [x:real | A*x*x+B*x+C==i2r(0)] real(x)\n\/\/\nextern\nfun\nquadratic_solve2\n {A,B,C:real}\n(\n A: real(A), B: real(B), C: real(C)\n) : [x:real | A*x*x+B*x+C==i2r(0)] real(x)\n\/\/\n(* ****** ****** *)\n\n#define i2r(x) int2real(x)\n\n(* ****** ****** *)\n\/\/\nimplement\nquadratic_solve1\n (A, B, C) = let\n\/\/\nval Delta = B*B-4*A*C\n\/\/\nval ((*void*)) = assert(A > 0)\nval ((*void*)) = assert(Delta >= 0)\n\/\/\nprval () =\n $solver_assert(lemma_sqrt_def)\n\/\/\nin\n (~B+sqrt(Delta))\/(2*A)\nend \/\/ end of [quadratic_solve1]\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\nquadratic_solve2\n (A, B, C) = let\n\/\/\nval Delta = B*B-4*A*C\n\/\/\nval ((*void*)) = assert(A > 0)\nval ((*void*)) = assert(Delta >= 0)\n\/\/\nprval () =\n $solver_assert(lemma_sqrt_def)\n\/\/\nin\n (~B-sqrt(Delta))\/(2*A)\nend \/\/ end of [quadratic_solve2]\n\/\/\n(* ****** ****** *)\n\nval root1 =\n quadratic_solve1(i2r(1), i2r(1), i2r(~1))\nval root2 =\n quadratic_solve2(i2r(1), i2r(1), i2r(~1))\n\n(* ****** ****** *)\n\nval () = println! (\"root1 = \", root1)\nval () = println! (\"root2 = \", root2)\n\n(* ****** ****** *)\n\nimplement\nmain0() = () where\n{\n\/\/\nval () =\nprintln! (\"Hello from [quadratic]\")\n\/\/\n} (* end of [main0] *)\n\n(* ****** ****** *)\n\n(* end of [quadratic.dats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"366e0554c9dc73a670c74668ad5335a601e4be83","subject":"Updating: very minorly improving","message":"Updating: very minorly improving\n","repos":"githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib","old_file":"contrib\/libats-\/hwxi\/teaching\/mysession-g\/SATS\/basis_ssntype.sats","new_file":"contrib\/libats-\/hwxi\/teaching\/mysession-g\/SATS\/basis_ssntype.sats","new_contents":"(*\n** Basis for g-session types\n*)\n\n(* ****** ****** *)\n\/\/\nstaload\n\".\/basis_intset.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nfun{}\nchannel_cap(): intGte(1) \n\/\/\n(* ****** ****** *)\n\/\/\nabstype\nsession_msg\n (i:int, j:int, a:vt@ype)\n\/\/\n(* ****** ****** *)\n\nabstype ssession_nil\nabstype ssession_cons(a:type, ssn:type)\n\n(* ****** ****** *)\n\/\/\nstadef msg = session_msg\n\/\/\nstadef nil = ssession_nil\n\/\/\nstadef :: = ssession_cons\nstadef cons = ssession_cons\n\/\/\n(* ****** ****** *)\n\/\/\nabstype\nsession_choose\n(\n i:int, ssn1:type, ssn2:type\n) (* session_choose *)\n\/\/\nstadef choose = session_choose\n\/\/\n(* ****** ****** *)\n\/\/\nabsvtype\nchannel1_vtype\n (G:iset, n:int, ssn:type) = ptr\n\/\/\nvtypedef\nchannel1\n (G:iset, n:int, ssn:type) = channel1_vtype(G, n, ssn)\n\/\/\nvtypedef\ncchannel1\n (G:iset, n:int, ssn:type) = channel1_vtype(ncomp(n, G), n, ssn)\n\/\/\n(* ****** ****** *)\n\/\/\nfun{}\nchannel1_get_nrole\n {n:int}{ssn:type}{G:iset}\n (chan: !channel1(G, n, ssn)): int(n)\n\/\/\nfun{}\nchannel1_get_group\n {n:int}{ssn:type}{G:iset}\n (chan: !channel1(G, n, ssn)): intset(n,G)\n\/\/\n(* ****** ****** *)\n\/\/\nfun\n{a:vt0p}\nchannel1_close\n {n:int}{ssn:type}{G:iset}(chan: channel1(G, n, nil)): void\n\/\/\n(* ****** ****** *)\n\/\/\nfun{}\nchannel1_skipin\n {a:vt0p}\n {n:int}{ssn:type}{G:iset}\n {i,j:nat | ismbr(G, i); ismbr(G, j)}\n(\n !channel1(G, n, msg(i, j, a)::ssn) >> channel1(G, n, ssn)\n) : void \/\/ end-of-function\npraxi\nlemma_channel1_skipin\n {a:vt0p}\n {n:int}{ssn:type}{G:iset}\n {i,j:nat | ismbr(G, i); ismbr(G, j)}\n(\n !channel1(G, n, msg(i, j, a)::ssn) >> channel1(G, n, ssn)\n) : void \/\/ lemma_channel1_skipin\n\/\/\nfun{}\nchannel1_skipex\n {a:vt0p}\n {n:int}{ssn:type}{G:iset}\n {i,j:nat | ~ismbr(G, i); ~ismbr(G, j)}\n(\n !channel1(G, n, msg(i, j, a)::ssn) >> channel1(G, n, ssn)\n) : void \/\/ end-of-function\npraxi\nlemma_channel1_skipex\n {a:vt0p}\n {n:int}{ssn:type}{G:iset}\n {i,j:nat | ~ismbr(G, i); ~ismbr(G, j)}\n(\n !channel1(G, n, msg(i, j, a)::ssn) >> channel1(G, n, ssn)\n) : void \/\/ lemma_channel1_skipex\n\/\/\n(* ****** ****** *)\n\/\/\nfun\n{a:vt0p}\nchannel1_send\n {n:int}{ssn:type}{G:iset}\n {i,j:nat | i < n; j < n; ismbr(G, i); ~ismbr(G, j)}\n(\n !channel1(G, n, msg(i, j, a)::ssn) >> channel1(G, n, ssn), int(i), int(j), a\n) : void \/\/ end of [channel1_send]\n\/\/\nfun\n{a:vt0p}\nchannel1_recv\n {n:int}{ssn:type}{G:iset}\n {i,j:nat | i < n; j < n; ~ismbr(G, i); ismbr(G, j)}\n(\n !channel1(G, n, msg(i, j, a)::ssn) >> channel1(G, n, ssn), int(i), int(j), &a? >> a\n) : void \/\/ end of [channel1_recv]\n\/\/\nfun\n{a:vt0p}\nchannel1_recv_val\n {n:int}{ssn:type}{G:iset}\n {i,j:nat | i < n; j < n; ~ismbr(G, i); ismbr(G, j)}\n (!channel1(G, n, msg(i, j, a)::ssn) >> channel1(G, n, ssn), int(i), int(j)): (a)\n\/\/\n(* ****** ****** *)\n\/\/\ndatatype\nchoosetag\n(\n a:type, b:type, c:type\n) =\n | choosetag_l(a, b, a) of ()\n | choosetag_r(a, b, b) of ()\n\/\/\n(* ****** ****** *)\n\nfun{}\nchannel1_choose_l\n {n:int}\n {ssn1,ssn2:type}\n {G:iset}\n {i:nat | i < n; ismbr(G, i)}\n(\n !channel1(G, n, choose(i,ssn1,ssn2)) >> channel1(G, n, ssn1), i: int(i)\n) : void \/\/ end of [channel1_choose_l]\nfun{}\nchannel1_choose_r\n {n:int}\n {ssn1,ssn2:type}\n {G:iset}\n {i:nat | i < n; ismbr(G, i)}\n(\n !channel1(G, n, choose(i,ssn1,ssn2)) >> channel1(G, n, ssn2), i: int(i)\n) : void \/\/ end of [channel1_choose_r]\n\n(* ****** ****** *)\n\nfun{}\nchannel1_choosetag\n {n:int}\n {ssn1,ssn2:type}\n {G:iset}\n {i:nat | i < n; ~isnil(G); ~ismbr(G, i)}\n(\n !channel1(G, n, choose(i,ssn1,ssn2)) >> channel1(G, n, ssn), i: int(i)\n) : #[ssn:type] choosetag(ssn1, ssn2, ssn)\n\n(* ****** ****** *)\n\/\/\n(*\n\/\/\n\/\/ HX-2015-03-06:\n\/\/ This one does not work with sschoose!!!\n\/\/\nfun{}\nchannel1_link\n {n:int}{ssn:type}\n {G1,G2:iset | isnil(G1*G2)}\n (channel1(G1, n, ssn), channel1(G2, n, ssn)): channel1(G1+G2, n, ssn)\n*)\n\/\/\nfun{}\nchannel1_link\n {n:int}{ssn:type}\n {G1,G2:iset | isful(G1+G2,n)}\n (channel1(G1, n, ssn), channel1(G2, n, ssn)): channel1(G1*G2, n, ssn)\n\/\/\n(* ****** ****** *)\n\/\/\nfun{}\nchannel1_link_elim\n {n:int}{ssn:type}{G:iset}(channel1(G, n, ssn), cchannel1(G, n, ssn)): void\n\/\/\n(* ****** ****** *)\n\/\/\nfun{}\ncchannel1_create_exn\n {n:nat}{ssn:type}{G:iset}\n(\n nrole: int(n), G: intset(n), fserv: channel1(G, n, ssn) - void\n) : cchannel1(G, n, ssn) \/\/ end of [cchannel1_create_exn]\n\/\/\n(* ****** ****** *)\n\n(* end of [basis_ssntype.sats] *)\n","old_contents":"(*\n** Basis for g-session types\n*)\n\n(* ****** ****** *)\n\/\/\nstaload\n\".\/basis_intset.sats\"\n\/\/\n(* ****** ****** *)\n\/\/\nfun{}\nchannel_cap(): intGte(1) \n\/\/\n(* ****** ****** *)\n\/\/\nabstype\nsession_msg\n (i:int, j:int, a:vt@ype)\n\/\/\n(* ****** ****** *)\n\nabstype ssession_nil\nabstype ssession_cons(a:type, ssn:type)\n\n(* ****** ****** *)\n\/\/\nstadef msg = session_msg\n\/\/\nstadef nil = ssession_nil\n\/\/\nstadef :: = ssession_cons\nstadef cons = ssession_cons\n\/\/\n(* ****** ****** *)\n\/\/\nabstype\nsession_choose\n(\n i:int, ssn1:type, ssn2:type\n) (* session_choose *)\n\/\/\nstadef choose = session_choose\n\/\/\n(* ****** ****** *)\n\/\/\nabsvtype\nchannel1_vtype\n (G:iset, n:int, ssn:type) = ptr\n\/\/\nvtypedef\nchannel1\n (G:iset, n:int, ssn:type) = channel1_vtype(G, n, ssn)\n\/\/\nvtypedef\ncchannel1\n (G:iset, n:int, ssn:type) = channel1_vtype(ncomp(n, G), n, ssn)\n\/\/\n(* ****** ****** *)\n\/\/\nfun{}\nchannel1_get_nrole\n {n:int}{ssn:type}{G:iset}\n (chan: !channel1(G, n, ssn)): int(n)\n\/\/\nfun{}\nchannel1_get_group\n {n:int}{ssn:type}{G:iset}\n (chan: !channel1(G, n, ssn)): intset(n,G)\n\/\/\n(* ****** ****** *)\n\/\/\nfun\n{a:vt0p}\nchannel1_close\n {n:int}{ssn:type}{G:iset}(chan: channel1(G, n, nil)): void\n\/\/\n(* ****** ****** *)\n\/\/\nfun{}\nchannel1_skipin\n {a:vt0p}\n {n:int}{ssn:type}{G:iset}\n {i,j:nat | ismbr(G, i); ismbr(G, j)}\n(\n !channel1(G, n, msg(i, j, a)::ssn) >> channel1(G, n, ssn)\n) : void \/\/ end-of-function\npraxi\nlemma_channel1_skipin\n {a:vt0p}\n {n:int}{ssn:type}{G:iset}\n {i,j:nat | ismbr(G, i); ismbr(G, j)}\n(\n !channel1(G, n, msg(i, j, a)::ssn) >> channel1(G, n, ssn)\n) : void \/\/ lemma_channel1_skipin\n\/\/\nfun{}\nchannel1_skipex\n {a:vt0p}\n {n:int}{ssn:type}{G:iset}\n {i,j:nat | ~ismbr(G, i); ~ismbr(G, j)}\n(\n !channel1(G, n, msg(i, j, a)::ssn) >> channel1(G, n, ssn)\n) : void \/\/ end-of-function\npraxi\nlemma_channel1_skipex\n {a:vt0p}\n {n:int}{ssn:type}{G:iset}\n {i,j:nat | ~ismbr(G, i); ~ismbr(G, j)}\n(\n !channel1(G, n, msg(i, j, a)::ssn) >> channel1(G, n, ssn)\n) : void \/\/ lemma_channel1_skipex\n\/\/\n(* ****** ****** *)\n\/\/\nfun\n{a:vt0p}\nchannel1_send\n {n:int}{ssn:type}{G:iset}\n {i,j:nat | i < n; j < n; ismbr(G, i); ~ismbr(G, j)}\n(\n !channel1(G, n, msg(i, j, a)::ssn) >> channel1(G, n, ssn), int(i), int(j), a\n) : void \/\/ end of [channel1_send]\n\/\/\nfun\n{a:vt0p}\nchannel1_recv\n {n:int}{ssn:type}{G:iset}\n {i,j:nat | i < n; j < n; ~ismbr(G, i); ismbr(G, j)}\n(\n !channel1(G, n, msg(i, j, a)::ssn) >> channel1(G, n, ssn), int(i), int(j), &a? >> a\n) : void \/\/ end of [channel1_recv]\n\/\/\nfun\n{a:vt0p}\nchannel1_recv_val\n {n:int}{ssn:type}{G:iset}\n {i,j:nat | i < n; j < n; ~ismbr(G, i); ismbr(G, j)}\n (!channel1(G, n, msg(i, j, a)::ssn) >> channel1(G, n, ssn), int(i), int(j)): (a)\n\/\/\n(* ****** ****** *)\n\/\/\ndatatype\nchoosetag\n(\n a:type, b:type, c:type\n) =\n | choosetag_l(a, b, a) of ()\n | choosetag_r(a, b, b) of ()\n\/\/\n(* ****** ****** *)\n\nfun{}\nchannel1_choose_l\n {n:int}\n {ssn1,ssn2:type}\n {G:iset}\n {i:nat | i < n; ismbr(G, i)}\n(\n !channel1(G, n, choose(i,ssn1,ssn2)) >> channel1(G, n, ssn1), i: int(i)\n) : void \/\/ end of [channel1_choose_l]\nfun{}\nchannel1_choose_r\n {n:int}\n {ssn1,ssn2:type}\n {G:iset}\n {i:nat | i < n; ismbr(G, i)}\n(\n !channel1(G, n, choose(i,ssn1,ssn2)) >> channel1(G, n, ssn2), i: int(i)\n) : void \/\/ end of [channel1_choose_r]\n\n(* ****** ****** *)\n\nfun{}\nchannel1_choosetag\n {n:int}\n {ssn1,ssn2:type}\n {G:iset}\n {i:nat | i < n; ~isnil(G); ~ismbr(G, i)}\n(\n !channel1(G, n, choose(i,ssn1,ssn2)) >> channel1(G, n, ssn), i: int(i)\n) : #[ssn:type] choosetag(ssn1, ssn2, ssn)\n\n(* ****** ****** *)\n\/\/\n(*\n\/\/\n\/\/ HX-2015-03-06:\n\/\/ This one does not work with sschoose!!!\n\/\/\nfun{}\nchannel1_link\n {n:int}{ssn:type}\n {G1,G2:iset | isnil(G1*G2)}\n (channel1(G1, n, ssn), channel1(G2, n, ssn)): channel1(G1+G2, n, ssn)\n*)\n\/\/\nfun{}\nchannel1_link\n {n:int}{ssn:type}\n {G1,G2:iset | isful(G1+G2,n)}\n (channel1(G1, n, ssn), channel1(G2, n, ssn)): channel1(G1*G2, n, ssn)\n\/\/\n(* ****** ****** *)\n\/\/\nfun{}\nchannel1_link_elim\n {n:int}{ssn:type}{G:iset}(channel1(G, n, ssn), cchannel1(G, n, ssn)): void\n\/\/\n(* ****** ****** *)\n\/\/\nfun{}\ncchannel1_create_exn\n {n:nat}{ssn:type}{G:iset}\n(\n nrole: int(n), G: intset(n), fserv: channel1(G, n, ssn) - void\n) : cchannel1(G, n, ssn) \/\/ end of [cchannel1_create_exn]\n\/\/\n(* ****** ****** *)\n\n(* end of [basis.sats] *)\n\/\/\ntypedef\nsession_snd(a:vt@ype) = session_msg(0, 1, a)\ntypedef\nsession_rcv(a:vt@ype) = session_msg(1, 0, a)\n\/\/\nstadef snd = session_snd\nstadef rcv = session_rcv\n\/\/\nvtypedef\nchan1pos(ssn:type) = channel1(iset(0), 2, ssn)\nvtypedef\nchan1neg(ssn:type) = channel1(iset(1), 2, ssn)\n\/\/\nfun\n{a:vt0p}\nchan1pos_send{ssn:type}\n (!chan1pos(snd(a)::ssn) >> chan1pos(ssn), a): void\n\/\/\nfun\n{a:vt0p}\nchan1pos_recv{ssn:type}\n(\n !chan1pos(rcv(a)::ssn) >> chan1pos(ssn), &a? >> a\n) : void \/\/ end-of-function\nfun\n{a:vt0p}\nchan1pos_recv_val{ssn:type}\n (chp: !chan1pos(rcv(a)::ssn) >> chan1pos(ssn)): (a)\n\/\/\nfun\n{a:vt0p}\nchan1neg_recv{ssn:type}\n (!chan1neg(rcv(a)::ssn) >> chan1neg(ssn), a): void\n\/\/\nfun\n{a:vt0p}\nchan1neg_send{ssn:type}\n(\n !chan1neg(snd(a)::ssn) >> chan1neg(ssn), &a? >> a\n) : void \/\/ end-of-function\nfun\n{a:vt0p}\nchan1neg_send_val{ssn:type}\n (chn: !chan1neg(snd(a)::ssn) >> chan1neg(ssn)): (a)\n\/\/\n(* ****** ****** *)\n\/\/\nfun{}\nchan1neg_create_exn\n {ssn:type}(fserv: chan1pos(ssn) - void): chan1neg(ssn)\n\/\/\n(* ****** ****** *)\n\n(* end of [basis_ssntype.sats] *)\n","returncode":0,"stderr":"","license":"mit","lang":"ATS"} {"commit":"b8f208d0048c1f129028170599aec3d6f0e940f4","subject":"Updating: very very minorly","message":"Updating: very very minorly\n","repos":"githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib,githwxi\/ATS-Postiats-contrib,bbarker\/ATS-Postiats-contrib,ashalkhakov\/ATS-Postiats-contrib","old_file":"projects\/LARGE\/TUTORIATS\/BUCASCS320\/PAGEN-assign.dats","new_file":"projects\/LARGE\/TUTORIATS\/BUCASCS320\/PAGEN-assign.dats","new_contents":"(* ****** ****** *)\n\/\/\n\/\/ HX: 2016-08-03:\n\/\/ Some PAGEN-functions\n\/\/ for creating assignments \n\/\/ \n(* ****** ****** *)\n\n#define ATS_DYNLOADFLAG 0\n\n(* ****** ****** *)\n\/\/\n#include\n\"share\/atspre_define.hats\"\n#include\n\"{$LIBATSCC2PY3}\/staloadall.hats\"\n\/\/\nstaload\n\"{$LIBATSCC2PY3}\/SATS\/PYLIBC\/random.sats\"\nstaload\n\"{$LIBATSCC2PY3}\/SATS\/PYLIBC\/datetime.sats\"\n\/\/\n(* ****** ****** *)\n\nstaload UN = \"prelude\/SATS\/unsafe.sats\"\n\n(* ****** ****** *)\n\/\/\nextern\nfun{}\npatsopt_tc_button(key: string): void\nextern\nfun{}\npatsopt_cc_button(key: string): void\nextern\nfun{}\npatsopt_cc2js_button(key: string): void\n\/\/\nextern\nfun{} pats2xhtml_button(key: string): void\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\n{}(*tmp*)\npatsopt_tc_button(key) =\n{\n\/\/\nval () =\ngprintln!(\"\\\npatsopt_tc<\/button>\\\n\") (* gprintln! *)\n\/\/\n} (* end of [patsopt_tc_button] *)\n\/\/\nimplement\n{}(*tmp*)\npatsopt_cc_button(key) =\n{\n\/\/\nval () =\ngprintln!(\"\\\npatsopt_cc<\/button>\\\n\") (* gprintln! *)\n\/\/\n} (* end of [patsopt_cc_button] *)\n\/\/\nimplement\n{}(*tmp*)\npatsopt_cc2js_button(key) =\n{\n\/\/\nval () =\ngprintln!(\"\\\npatsopt_cc2js<\/button>\\\n\") (* gprintln! *)\n\/\/\n} (* end of [patsopt_cc2js_button] *)\n\/\/\nimplement\n{}(*tmp*)\npats2xhtml_button(key) =\n{\n\/\/\nval () =\ngprintln! (\"\\\npats2xhtml-toggle<\/button>\\\n\") (* gprintln! *)\n\/\/\n} (* pats2xhtml_button *)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun{}\npatssrc_saveAs_button(key: string): void\nextern\nfun{}\npatssrc_saveAs_input0(key: string): void\nextern\nfun{}\npatsout_saveAs_button(key: string): void\nextern\nfun{}\npatsout_saveAs_input0(key: string): void\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\n{}(*tmp*)\npatssrc_saveAs_button(key) =\n{\n\/\/\nval () =\ngprintln! (\"\\\nsaveAs<\/button>\\\n\") (* gprintln! *)\n\/\/\n} (* patssrc_saveAs_button *)\n\nimplement\n{}(*tmp*)\npatssrc_saveAs_input0(key) =\n{\n\/\/\nval () =\ngprintln! (\"\\\n<\/input>\\\n\") (* gprintln! *)\n\/\/\n} (* patssrc_saveAs_input0 *)\n\/\/\nimplement\n{}(*tmp*)\npatsout_saveAs_button(key) =\n{\n\/\/\nval () =\ngprintln! (\"\\\nsaveAs<\/button>\\\n\") (* gprintln! *)\n\/\/\n} (* patsout_saveAs_button *)\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun{}\nPAGENassign_html(key: string): void\n\/\/\nextern\nfun{}\nPAGENassign_head(key: string): void\n\/\/\nextern\nfun{}\nPAGENassign_body(key: string): void\n\/\/\nextern\nfun{}\nPAGENassign_title(key: string): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun{}\nPAGENassign_descript(key: string): void\nextern\nfun{}\nPAGENassign_descript2(key: string): void\n\/\/\n(* ****** ****** *)\n\/\/\nextern\nfun{}\nPAGENassign_body_top(key: string): void\nextern\nfun{}\nPAGENassign_body_bottom(key: string): void\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\n{}(*tmp*)\nPAGENassign_html\n (key) =\n{\n\/\/\nval () =\ngprintln!\n(\n\"\"\n) (* gprintln! *)\n\/\/\nval () =\ngprintln! (\"\")\n\/\/\nval () =\nPAGENassign_head(key)\n\/\/\nval () =\nPAGENassign_body(key)\n\/\/\nval () =\ngprintln! (\"<\/html>\")\n\/\/\n} (* end of [PAGENassign_html] *)\n\/\/\n(* ****** ****** *)\n\/\/\nimplement\n{}(*tmp*)\nPAGENassign_head\n (key) =\n{\n\/\/\nval () =\ngprintln! (\"\")\n\/\/\nval () =\nPAGENassign_title(key)\n\/\/\nval () =\ngprintln! (\"\\\n\\\n\") (* end of [val] *)\n\/\/\nval () =\ngprintln! (\"\\\n