Hex Artifact Content
Not logged in

Artifact 6911dbe2567441865774ec99b4c01d1958b3b51c:


0000: 0d 0a 2f 2a 2a 0a 20 2a 20 41 75 74 68 6f 72 73  ../**. * Authors
0010: 3a 20 6b 2e 69 6e 61 62 61 0a 20 2a 20 4c 69 63  : k.inaba. * Lic
0020: 65 6e 73 65 3a 20 4e 59 53 4c 20 30 2e 39 39 38  ense: NYSL 0.998
0030: 32 20 68 74 74 70 3a 2f 2f 77 77 77 2e 6b 6d 6f  2 http://www.kmo
0040: 6e 6f 73 2e 6e 65 74 2f 6e 79 73 6c 2f 0a 20 2a  nos.net/nysl/. *
0050: 0a 20 2a 20 52 75 6e 74 69 6d 65 20 6c 69 62 72  . * Runtime libr
0060: 61 72 79 20 66 6f 72 20 50 6f 6c 65 6d 79 20 70  ary for Polemy p
0070: 72 6f 67 72 61 6d 6d 69 6e 67 20 6c 61 6e 67 75  rogramming langu
0080: 61 67 65 2e 0a 20 2a 2f 0a 6d 6f 64 75 6c 65 20  age.. */.module 
0090: 70 6f 6c 65 6d 79 2e 72 75 6e 74 69 6d 65 3b 0a  polemy.runtime;.
00a0: 69 6d 70 6f 72 74 20 70 6f 6c 65 6d 79 2e 5f 63  import polemy._c
00b0: 6f 6d 6d 6f 6e 3b 0a 69 6d 70 6f 72 74 20 70 6f  ommon;.import po
00c0: 6c 65 6d 79 2e 6c 61 79 65 72 3b 0d 0a 69 6d 70  lemy.layer;..imp
00d0: 6f 72 74 20 70 6f 6c 65 6d 79 2e 66 61 69 6c 75  ort polemy.failu
00e0: 72 65 3b 0d 0a 69 6d 70 6f 72 74 20 70 6f 6c 65  re;..import pole
00f0: 6d 79 2e 66 72 65 73 68 3b 0d 0a 69 6d 70 6f 72  my.fresh;..impor
0100: 74 20 70 6f 6c 65 6d 79 2e 76 61 6c 75 65 3b 0d  t polemy.value;.
0110: 0a 69 6d 70 6f 72 74 20 70 6f 6c 65 6d 79 2e 65  .import polemy.e
0120: 76 61 6c 3b 0a 69 6d 70 6f 72 74 20 73 74 64 2e  val;.import std.
0130: 73 74 64 69 6f 3b 0a 69 6d 70 6f 72 74 20 73 74  stdio;.import st
0140: 64 2e 72 61 6e 64 6f 6d 3b 0d 0a 0d 0a 2f 2f 2f  d.random;....///
0150: 20 65 6e 72 6f 6c 6c 20 74 68 65 20 6e 61 74 69   enroll the nati
0160: 76 65 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f  ve implementatio
0170: 6e 73 20 6f 66 20 70 72 69 6d 69 74 69 76 65 20  ns of primitive 
0180: 66 75 6e 63 74 69 6f 6e 73 0d 0a 0d 0a 76 6f 69  functions....voi
0190: 64 20 65 6e 72 6f 6c 6c 52 75 6e 74 69 6d 65 4c  d enrollRuntimeL
01a0: 69 62 72 61 72 79 28 20 45 76 61 6c 75 61 74 6f  ibrary( Evaluato
01b0: 72 20 65 20 29 0d 0a 7b 0d 0a 09 2f 2f 20 61 72  r e )..{...// ar
01c0: 69 74 68 6d 65 74 69 63 20 6f 70 65 72 61 74 69  ithmetic operati
01d0: 6f 6e 73 0d 0a 09 65 2e 61 64 64 50 72 69 6d 69  ons...e.addPrimi
01e0: 74 69 76 65 28 22 2b 22 2c 20 20 56 61 6c 75 65  tive("+",  Value
01f0: 4c 61 79 65 72 2c 0d 0a 09 09 28 49 6e 74 56 61  Layer,....(IntVa
0200: 6c 75 65 20 6c 68 73 2c 20 49 6e 74 56 61 6c 75  lue lhs, IntValu
0210: 65 20 72 68 73 29 7b 72 65 74 75 72 6e 20 6e 65  e rhs){return ne
0220: 77 20 49 6e 74 56 61 6c 75 65 28 6c 68 73 2e 64  w IntValue(lhs.d
0230: 61 74 61 20 2b 20 72 68 73 2e 64 61 74 61 29 3b  ata + rhs.data);
0240: 7d 20 29 3b 0d 0a 09 65 2e 61 64 64 50 72 69 6d  } );...e.addPrim
0250: 69 74 69 76 65 28 22 2d 22 2c 20 20 56 61 6c 75  itive("-",  Valu
0260: 65 4c 61 79 65 72 2c 0d 0a 09 09 28 49 6e 74 56  eLayer,....(IntV
0270: 61 6c 75 65 20 6c 68 73 2c 20 49 6e 74 56 61 6c  alue lhs, IntVal
0280: 75 65 20 72 68 73 29 7b 72 65 74 75 72 6e 20 6e  ue rhs){return n
0290: 65 77 20 49 6e 74 56 61 6c 75 65 28 6c 68 73 2e  ew IntValue(lhs.
02a0: 64 61 74 61 20 2d 20 72 68 73 2e 64 61 74 61 29  data - rhs.data)
02b0: 3b 7d 20 29 3b 0d 0a 09 65 2e 61 64 64 50 72 69  ;} );...e.addPri
02c0: 6d 69 74 69 76 65 28 22 2a 22 2c 20 20 56 61 6c  mitive("*",  Val
02d0: 75 65 4c 61 79 65 72 2c 0d 0a 09 09 28 49 6e 74  ueLayer,....(Int
02e0: 56 61 6c 75 65 20 6c 68 73 2c 20 49 6e 74 56 61  Value lhs, IntVa
02f0: 6c 75 65 20 72 68 73 29 7b 72 65 74 75 72 6e 20  lue rhs){return 
0300: 6e 65 77 20 49 6e 74 56 61 6c 75 65 28 6c 68 73  new IntValue(lhs
0310: 2e 64 61 74 61 20 2a 20 72 68 73 2e 64 61 74 61  .data * rhs.data
0320: 29 3b 7d 20 29 3b 0d 0a 09 65 2e 61 64 64 50 72  );} );...e.addPr
0330: 69 6d 69 74 69 76 65 28 22 2f 22 2c 20 20 56 61  imitive("/",  Va
0340: 6c 75 65 4c 61 79 65 72 2c 0d 0a 09 09 28 49 6e  lueLayer,....(In
0350: 74 56 61 6c 75 65 20 6c 68 73 2c 20 49 6e 74 56  tValue lhs, IntV
0360: 61 6c 75 65 20 72 68 73 29 7b 0d 0a 09 09 09 69  alue rhs){.....i
0370: 66 28 20 72 68 73 2e 64 61 74 61 20 3d 3d 20 30  f( rhs.data == 0
0380: 20 29 0d 0a 09 09 09 09 74 68 72 6f 77 20 67 65   )......throw ge
0390: 6e 65 78 21 52 75 6e 74 69 6d 65 45 78 63 65 70  nex!RuntimeExcep
03a0: 74 69 6f 6e 28 22 64 69 76 69 73 69 6f 6e 20 62  tion("division b
03b0: 79 20 30 22 29 3b 0d 0a 09 09 09 72 65 74 75 72  y 0");.....retur
03c0: 6e 20 6e 65 77 20 49 6e 74 56 61 6c 75 65 28 6c  n new IntValue(l
03d0: 68 73 2e 64 61 74 61 20 2f 20 72 68 73 2e 64 61  hs.data / rhs.da
03e0: 74 61 29 3b 0d 0a 09 09 7d 29 3b 0d 0a 09 65 2e  ta);....});...e.
03f0: 61 64 64 50 72 69 6d 69 74 69 76 65 28 22 25 22  addPrimitive("%"
0400: 2c 20 20 56 61 6c 75 65 4c 61 79 65 72 2c 0d 0a  ,  ValueLayer,..
0410: 09 09 28 49 6e 74 56 61 6c 75 65 20 6c 68 73 2c  ..(IntValue lhs,
0420: 20 49 6e 74 56 61 6c 75 65 20 72 68 73 29 7b 72   IntValue rhs){r
0430: 65 74 75 72 6e 20 6e 65 77 20 49 6e 74 56 61 6c  eturn new IntVal
0440: 75 65 28 6c 68 73 2e 64 61 74 61 20 25 20 72 68  ue(lhs.data % rh
0450: 73 2e 64 61 74 61 29 3b 7d 20 29 3b 0d 0a 09 65  s.data);} );...e
0460: 2e 61 64 64 50 72 69 6d 69 74 69 76 65 28 22 7c  .addPrimitive("|
0470: 7c 22 2c 20 56 61 6c 75 65 4c 61 79 65 72 2c 0d  |", ValueLayer,.
0480: 0a 09 09 28 49 6e 74 56 61 6c 75 65 20 6c 68 73  ...(IntValue lhs
0490: 2c 20 49 6e 74 56 61 6c 75 65 20 72 68 73 29 7b  , IntValue rhs){
04a0: 72 65 74 75 72 6e 20 6e 65 77 20 49 6e 74 56 61  return new IntVa
04b0: 6c 75 65 28 6c 68 73 2e 64 61 74 61 21 3d 30 20  lue(lhs.data!=0 
04c0: 7c 7c 20 72 68 73 2e 64 61 74 61 21 3d 30 29 3b  || rhs.data!=0);
04d0: 7d 20 29 3b 0d 0a 09 65 2e 61 64 64 50 72 69 6d  } );...e.addPrim
04e0: 69 74 69 76 65 28 22 26 26 22 2c 20 56 61 6c 75  itive("&&", Valu
04f0: 65 4c 61 79 65 72 2c 0d 0a 09 09 28 49 6e 74 56  eLayer,....(IntV
0500: 61 6c 75 65 20 6c 68 73 2c 20 49 6e 74 56 61 6c  alue lhs, IntVal
0510: 75 65 20 72 68 73 29 7b 72 65 74 75 72 6e 20 6e  ue rhs){return n
0520: 65 77 20 49 6e 74 56 61 6c 75 65 28 6c 68 73 2e  ew IntValue(lhs.
0530: 64 61 74 61 21 3d 30 20 26 26 20 72 68 73 2e 64  data!=0 && rhs.d
0540: 61 74 61 21 3d 30 29 3b 7d 20 29 3b 0d 0a 09 2f  ata!=0);} );.../
0550: 2f 20 73 74 72 69 6e 67 20 6f 70 65 72 61 74 69  / string operati
0560: 6f 6e 28 73 29 0d 0a 09 65 2e 61 64 64 50 72 69  on(s)...e.addPri
0570: 6d 69 74 69 76 65 28 22 7e 22 2c 20 20 56 61 6c  mitive("~",  Val
0580: 75 65 4c 61 79 65 72 2c 0d 0a 09 09 28 56 61 6c  ueLayer,....(Val
0590: 75 65 20 6c 68 73 2c 20 56 61 6c 75 65 20 72 68  ue lhs, Value rh
05a0: 73 29 7b 72 65 74 75 72 6e 20 6e 65 77 20 53 74  s){return new St
05b0: 72 56 61 6c 75 65 28 6c 68 73 2e 74 6f 53 74 72  rValue(lhs.toStr
05c0: 69 6e 67 20 7e 20 72 68 73 2e 74 6f 53 74 72 69  ing ~ rhs.toStri
05d0: 6e 67 29 3b 7d 20 29 3b 0d 0a 09 2f 2f 20 63 6f  ng);} );...// co
05e0: 6d 70 61 72 69 73 6f 6e 0d 0a 09 65 2e 61 64 64  mparison...e.add
05f0: 50 72 69 6d 69 74 69 76 65 28 22 3c 22 2c 20 20  Primitive("<",  
0600: 56 61 6c 75 65 4c 61 79 65 72 2c 20 28 56 61 6c  ValueLayer, (Val
0610: 75 65 20 6c 68 73 2c 20 56 61 6c 75 65 20 72 68  ue lhs, Value rh
0620: 73 29 7b 72 65 74 75 72 6e 20 6e 65 77 20 49 6e  s){return new In
0630: 74 56 61 6c 75 65 28 6c 68 73 20 3c 20 72 68 73  tValue(lhs < rhs
0640: 29 3b 7d 20 29 3b 0d 0a 09 65 2e 61 64 64 50 72  );} );...e.addPr
0650: 69 6d 69 74 69 76 65 28 22 3e 22 2c 20 20 56 61  imitive(">",  Va
0660: 6c 75 65 4c 61 79 65 72 2c 20 28 56 61 6c 75 65  lueLayer, (Value
0670: 20 6c 68 73 2c 20 56 61 6c 75 65 20 72 68 73 29   lhs, Value rhs)
0680: 7b 72 65 74 75 72 6e 20 6e 65 77 20 49 6e 74 56  {return new IntV
0690: 61 6c 75 65 28 6c 68 73 20 3e 20 72 68 73 29 3b  alue(lhs > rhs);
06a0: 7d 20 29 3b 0d 0a 09 65 2e 61 64 64 50 72 69 6d  } );...e.addPrim
06b0: 69 74 69 76 65 28 22 3c 3d 22 2c 20 56 61 6c 75  itive("<=", Valu
06c0: 65 4c 61 79 65 72 2c 20 28 56 61 6c 75 65 20 6c  eLayer, (Value l
06d0: 68 73 2c 20 56 61 6c 75 65 20 72 68 73 29 7b 72  hs, Value rhs){r
06e0: 65 74 75 72 6e 20 6e 65 77 20 49 6e 74 56 61 6c  eturn new IntVal
06f0: 75 65 28 6c 68 73 20 3c 3d 20 72 68 73 29 3b 7d  ue(lhs <= rhs);}
0700: 20 29 3b 0d 0a 09 65 2e 61 64 64 50 72 69 6d 69   );...e.addPrimi
0710: 74 69 76 65 28 22 3e 3d 22 2c 20 56 61 6c 75 65  tive(">=", Value
0720: 4c 61 79 65 72 2c 20 28 56 61 6c 75 65 20 6c 68  Layer, (Value lh
0730: 73 2c 20 56 61 6c 75 65 20 72 68 73 29 7b 72 65  s, Value rhs){re
0740: 74 75 72 6e 20 6e 65 77 20 49 6e 74 56 61 6c 75  turn new IntValu
0750: 65 28 6c 68 73 20 3e 3d 20 72 68 73 29 3b 7d 20  e(lhs >= rhs);} 
0760: 29 3b 0d 0a 09 65 2e 61 64 64 50 72 69 6d 69 74  );...e.addPrimit
0770: 69 76 65 28 22 3d 3d 22 2c 20 56 61 6c 75 65 4c  ive("==", ValueL
0780: 61 79 65 72 2c 20 28 56 61 6c 75 65 20 6c 68 73  ayer, (Value lhs
0790: 2c 20 56 61 6c 75 65 20 72 68 73 29 7b 72 65 74  , Value rhs){ret
07a0: 75 72 6e 20 6e 65 77 20 49 6e 74 56 61 6c 75 65  urn new IntValue
07b0: 28 6c 68 73 20 3d 3d 20 72 68 73 29 3b 7d 20 29  (lhs == rhs);} )
07c0: 3b 0d 0a 09 65 2e 61 64 64 50 72 69 6d 69 74 69  ;...e.addPrimiti
07d0: 76 65 28 22 21 3d 22 2c 20 56 61 6c 75 65 4c 61  ve("!=", ValueLa
07e0: 79 65 72 2c 20 28 56 61 6c 75 65 20 6c 68 73 2c  yer, (Value lhs,
07f0: 20 56 61 6c 75 65 20 72 68 73 29 7b 72 65 74 75   Value rhs){retu
0800: 72 6e 20 6e 65 77 20 49 6e 74 56 61 6c 75 65 28  rn new IntValue(
0810: 6c 68 73 20 21 3d 20 72 68 73 29 3b 7d 20 29 3b  lhs != rhs);} );
0820: 0d 0a 09 2f 2f 20 63 6f 6e 74 72 6f 6c 20 66 6c  ...// control fl
0830: 6f 77 0d 0a 09 65 2e 61 64 64 50 72 69 6d 69 74  ow...e.addPrimit
0840: 69 76 65 28 22 69 66 22 2c 20 56 61 6c 75 65 4c  ive("if", ValueL
0850: 61 79 65 72 2c 20 28 49 6e 74 56 61 6c 75 65 20  ayer, (IntValue 
0860: 78 2c 20 46 75 6e 56 61 6c 75 65 20 66 74 2c 20  x, FunValue ft, 
0870: 46 75 6e 56 61 6c 75 65 20 66 65 29 7b 0d 0a 09  FunValue fe){...
0880: 09 61 75 74 6f 20 74 6f 52 75 6e 20 3d 20 28 78  .auto toRun = (x
0890: 2e 64 61 74 61 3d 3d 30 20 3f 20 66 65 20 3a 20  .data==0 ? fe : 
08a0: 66 74 29 3b 0d 0a 09 09 72 65 74 75 72 6e 20 74  ft);....return t
08b0: 6f 52 75 6e 2e 69 6e 76 6f 6b 65 28 56 61 6c 75  oRun.invoke(Valu
08c0: 65 4c 61 79 65 72 2c 20 74 6f 52 75 6e 2e 64 65  eLayer, toRun.de
08d0: 66 69 6e 69 74 69 6f 6e 43 6f 6e 74 65 78 74 28  finitionContext(
08e0: 29 2c 20 6e 75 6c 6c 29 3b 0d 0a 09 7d 29 3b 0d  ), null);...});.
08f0: 0a 09 2f 2f 20 74 79 70 65 20 74 65 73 74 0d 0a  ..// type test..
0900: 09 65 2e 61 64 64 50 72 69 6d 69 74 69 76 65 28  .e.addPrimitive(
0910: 22 5f 69 73 69 6e 74 22 2c 20 56 61 6c 75 65 4c  "_isint", ValueL
0920: 61 79 65 72 2c 0d 0a 09 09 28 56 61 6c 75 65 20  ayer,....(Value 
0930: 76 29 7b 72 65 74 75 72 6e 20 6e 65 77 20 49 6e  v){return new In
0940: 74 56 61 6c 75 65 28 63 61 73 74 28 49 6e 74 56  tValue(cast(IntV
0950: 61 6c 75 65 29 76 20 21 69 73 20 6e 75 6c 6c 29  alue)v !is null)
0960: 3b 7d 20 29 3b 0d 0a 09 65 2e 61 64 64 50 72 69  ;} );...e.addPri
0970: 6d 69 74 69 76 65 28 22 5f 69 73 73 74 72 22 2c  mitive("_isstr",
0980: 20 56 61 6c 75 65 4c 61 79 65 72 2c 0d 0a 09 09   ValueLayer,....
0990: 28 56 61 6c 75 65 20 76 29 7b 72 65 74 75 72 6e  (Value v){return
09a0: 20 6e 65 77 20 49 6e 74 56 61 6c 75 65 28 63 61   new IntValue(ca
09b0: 73 74 28 53 74 72 56 61 6c 75 65 29 76 20 21 69  st(StrValue)v !i
09c0: 73 20 6e 75 6c 6c 29 3b 7d 20 29 3b 0d 0a 09 65  s null);} );...e
09d0: 2e 61 64 64 50 72 69 6d 69 74 69 76 65 28 22 5f  .addPrimitive("_
09e0: 69 73 66 75 6e 22 2c 20 56 61 6c 75 65 4c 61 79  isfun", ValueLay
09f0: 65 72 2c 0d 0a 09 09 28 56 61 6c 75 65 20 76 29  er,....(Value v)
0a00: 7b 72 65 74 75 72 6e 20 6e 65 77 20 49 6e 74 56  {return new IntV
0a10: 61 6c 75 65 28 63 61 73 74 28 46 75 6e 56 61 6c  alue(cast(FunVal
0a20: 75 65 29 76 20 21 69 73 20 6e 75 6c 6c 29 3b 7d  ue)v !is null);}
0a30: 20 29 3b 0d 0a 09 65 2e 61 64 64 50 72 69 6d 69   );...e.addPrimi
0a40: 74 69 76 65 28 22 5f 69 73 75 6e 64 65 66 69 6e  tive("_isundefin
0a50: 65 64 22 2c 20 56 61 6c 75 65 4c 61 79 65 72 2c  ed", ValueLayer,
0a60: 0d 0a 09 09 28 56 61 6c 75 65 20 76 29 7b 72 65  ....(Value v){re
0a70: 74 75 72 6e 20 6e 65 77 20 49 6e 74 56 61 6c 75  turn new IntValu
0a80: 65 28 63 61 73 74 28 55 6e 64 65 66 69 6e 65 64  e(cast(Undefined
0a90: 56 61 6c 75 65 29 76 20 21 69 73 20 6e 75 6c 6c  Value)v !is null
0aa0: 29 3b 7d 20 29 3b 0d 0a 09 65 2e 61 64 64 50 72  );} );...e.addPr
0ab0: 69 6d 69 74 69 76 65 28 22 5f 69 73 74 61 62 6c  imitive("_istabl
0ac0: 65 22 2c 20 56 61 6c 75 65 4c 61 79 65 72 2c 0d  e", ValueLayer,.
0ad0: 0a 09 09 28 56 61 6c 75 65 20 76 29 7b 72 65 74  ...(Value v){ret
0ae0: 75 72 6e 20 6e 65 77 20 49 6e 74 56 61 6c 75 65  urn new IntValue
0af0: 28 63 61 73 74 28 54 61 62 6c 65 29 76 20 21 69  (cast(Table)v !i
0b00: 73 20 6e 75 6c 6c 29 3b 7d 20 29 3b 0d 0a 09 2f  s null);} );.../
0b10: 2f 20 74 61 62 6c 65 0d 0a 09 65 2e 61 64 64 50  / table...e.addP
0b20: 72 69 6d 69 74 69 76 65 28 22 2e 22 2c 20 56 61  rimitive(".", Va
0b30: 6c 75 65 4c 61 79 65 72 2c 20 28 54 61 62 6c 65  lueLayer, (Table
0b40: 20 74 2c 20 53 74 72 56 61 6c 75 65 20 73 29 7b   t, StrValue s){
0b50: 0d 0a 09 09 69 66 28 20 74 2e 68 61 73 28 73 2e  ....if( t.has(s.
0b60: 64 61 74 61 2c 20 56 61 6c 75 65 4c 61 79 65 72  data, ValueLayer
0b70: 29 20 29 0d 0a 09 09 09 72 65 74 75 72 6e 20 74  ) ).....return t
0b80: 2e 67 65 74 28 73 2e 64 61 74 61 2c 20 56 61 6c  .get(s.data, Val
0b90: 75 65 4c 61 79 65 72 29 3b 0d 0a 09 09 74 68 72  ueLayer);....thr
0ba0: 6f 77 20 67 65 6e 65 78 21 52 75 6e 74 69 6d 65  ow genex!Runtime
0bb0: 45 78 63 65 70 74 69 6f 6e 28 74 65 78 74 28 22  Exception(text("
0bc0: 74 61 62 6c 65 20 64 6f 20 6e 6f 74 20 68 61 76  table do not hav
0bd0: 65 20 74 68 65 20 66 69 65 6c 64 20 22 2c 73 29  e the field ",s)
0be0: 29 3b 0d 0a 09 7d 29 3b 0d 0a 09 65 2e 61 64 64  );...});...e.add
0bf0: 50 72 69 6d 69 74 69 76 65 28 22 2e 3f 22 2c 20  Primitive(".?", 
0c00: 56 61 6c 75 65 4c 61 79 65 72 2c 20 28 54 61 62  ValueLayer, (Tab
0c10: 6c 65 20 74 2c 20 53 74 72 56 61 6c 75 65 20 73  le t, StrValue s
0c20: 29 7b 0d 0a 09 09 72 65 74 75 72 6e 20 6e 65 77  ){....return new
0c30: 20 49 6e 74 56 61 6c 75 65 28 74 2e 68 61 73 28   IntValue(t.has(
0c40: 73 2e 64 61 74 61 2c 20 56 61 6c 75 65 4c 61 79  s.data, ValueLay
0c50: 65 72 29 29 3b 0d 0a 09 7d 29 3b 0d 0a 09 65 2e  er));...});...e.
0c60: 61 64 64 50 72 69 6d 69 74 69 76 65 28 22 2e 3d  addPrimitive(".=
0c70: 22 2c 20 56 61 6c 75 65 4c 61 79 65 72 2c 20 28  ", ValueLayer, (
0c80: 54 61 62 6c 65 20 74 2c 20 53 74 72 56 61 6c 75  Table t, StrValu
0c90: 65 20 73 2c 20 56 61 6c 75 65 20 76 29 7b 0d 0a  e s, Value v){..
0ca0: 09 09 61 75 74 6f 20 74 32 20 3d 20 6e 65 77 20  ..auto t2 = new 
0cb0: 54 61 62 6c 65 28 74 2c 20 54 61 62 6c 65 2e 4b  Table(t, Table.K
0cc0: 69 6e 64 2e 4e 6f 74 50 72 6f 70 61 67 61 74 65  ind.NotPropagate
0cd0: 53 65 74 29 3b 0d 0a 09 09 74 32 2e 73 65 74 28  Set);....t2.set(
0ce0: 73 2e 64 61 74 61 2c 20 56 61 6c 75 65 4c 61 79  s.data, ValueLay
0cf0: 65 72 2c 20 76 29 3b 0d 0a 09 09 72 65 74 75 72  er, v);....retur
0d00: 6e 20 74 32 3b 0d 0a 09 7d 29 3b 0d 0a 09 65 2e  n t2;...});...e.
0d10: 61 64 64 50 72 69 6d 69 74 69 76 65 28 22 7b 7d  addPrimitive("{}
0d20: 22 2c 20 56 61 6c 75 65 4c 61 79 65 72 2c 20 28  ", ValueLayer, (
0d30: 29 7b 0d 0a 09 09 72 65 74 75 72 6e 20 6e 65 77  ){....return new
0d40: 20 54 61 62 6c 65 3b 0d 0a 09 7d 29 3b 0d 0a 09   Table;...});...
0d50: 2f 2f 20 49 4f 20 61 6e 64 20 6f 74 68 65 72 73  // IO and others
0d60: 0d 0a 09 65 2e 61 64 64 50 72 69 6d 69 74 69 76  ...e.addPrimitiv
0d70: 65 28 22 70 72 69 6e 74 22 2c 20 56 61 6c 75 65  e("print", Value
0d80: 4c 61 79 65 72 2c 20 28 56 61 6c 75 65 20 61 29  Layer, (Value a)
0d90: 7b 20 77 72 69 74 65 6c 6e 28 61 29 3b 20 72 65  { writeln(a); re
0da0: 74 75 72 6e 20 6e 65 77 20 49 6e 74 56 61 6c 75  turn new IntValu
0db0: 65 28 30 29 3b 20 7d 29 3b 0d 0a 09 65 2e 61 64  e(0); });...e.ad
0dc0: 64 50 72 69 6d 69 74 69 76 65 28 22 67 65 6e 73  dPrimitive("gens
0dd0: 79 6d 22 2c 20 56 61 6c 75 65 4c 61 79 65 72 2c  ym", ValueLayer,
0de0: 20 28 29 7b 20 72 65 74 75 72 6e 20 6e 65 77 20   (){ return new 
0df0: 53 74 72 56 61 6c 75 65 28 66 72 65 73 68 56 61  StrValue(freshVa
0e00: 72 4e 61 6d 65 28 29 29 3b 20 7d 29 3b 0d 0a 09  rName()); });...
0e10: 61 75 74 6f 20 72 61 6e 64 20 3d 20 4d 74 31 39  auto rand = Mt19
0e20: 39 33 37 28 75 6e 70 72 65 64 69 63 74 61 62 6c  937(unpredictabl
0e30: 65 53 65 65 64 29 3b 0d 0a 09 65 2e 61 64 64 50  eSeed);...e.addP
0e40: 72 69 6d 69 74 69 76 65 28 22 72 61 6e 64 22 2c  rimitive("rand",
0e50: 20 56 61 6c 75 65 4c 61 79 65 72 2c 20 28 49 6e   ValueLayer, (In
0e60: 74 56 61 6c 75 65 20 6e 29 7b 0d 0a 09 09 72 65  tValue n){....re
0e70: 74 75 72 6e 20 6e 65 77 20 49 6e 74 56 61 6c 75  turn new IntValu
0e80: 65 28 20 75 6e 69 66 6f 72 6d 28 30 2c 63 61 73  e( uniform(0,cas
0e90: 74 28 69 6e 74 29 6e 2e 64 61 74 61 2e 74 6f 49  t(int)n.data.toI
0ea0: 6e 74 28 29 2c 72 61 6e 64 29 20 29 3b 0d 0a 09  nt(),rand) );...
0eb0: 7d 29 3b 0d 0a 7d 0d 0a                          });..}..