Hex Artifact Content
Not logged in

Artifact bd983db748e0ad6a74109f93391c25ff423173d9:


0000: ef bb bf 2f 2a 2a 0d 0a 20 2a 20 41 75 74 68 6f  .../**.. * Autho
0010: 72 73 3a 20 6b 2e 69 6e 61 62 61 0d 0a 20 2a 20  rs: k.inaba.. * 
0020: 4c 69 63 65 6e 73 65 3a 20 4e 59 53 4c 20 30 2e  License: NYSL 0.
0030: 39 39 38 32 20 68 74 74 70 3a 2f 2f 77 77 77 2e  9982 http://www.
0040: 6b 6d 6f 6e 6f 73 2e 6e 65 74 2f 6e 79 73 6c 2f  kmonos.net/nysl/
0050: 0d 0a 20 2a 0d 0a 20 2a 20 44 65 66 69 6e 69 74  .. *.. * Definit
0060: 69 6f 6e 20 6f 66 20 63 6f 6e 73 74 61 6e 74 73  ion of constants
0070: 20 72 65 6c 61 74 65 64 20 74 6f 20 74 68 65 20   related to the 
0080: 6c 61 79 65 72 73 2e 0d 0a 20 2a 2f 0d 0a 6d 6f  layers... */..mo
0090: 64 75 6c 65 20 70 6f 6c 65 6d 79 2e 6c 61 79 65  dule polemy.laye
00a0: 72 3b 0d 0a 69 6d 70 6f 72 74 20 70 6f 6c 65 6d  r;..import polem
00b0: 79 2e 5f 63 6f 6d 6d 6f 6e 3b 0d 0a 0d 0a 2f 2f  y._common;....//
00c0: 2f 20 54 79 70 65 20 66 6f 72 20 74 68 65 20 6c  / Type for the l
00d0: 61 79 65 72 20 49 44 0d 0a 0d 0a 61 6c 69 61 73  ayer ID....alias
00e0: 20 73 74 72 69 6e 67 20 4c 61 79 65 72 3b 0d 0a   string Layer;..
00f0: 0d 0a 65 6e 75 6d 20 3a 20 4c 61 79 65 72 0d 0a  ..enum : Layer..
0100: 7b 0d 0a 09 53 79 73 74 65 6d 4c 61 79 65 72 20  {...SystemLayer 
0110: 20 20 3d 20 22 28 73 79 73 74 65 6d 29 22 2c 20    = "(system)", 
0120: 20 20 2f 2f 2f 20 50 72 65 64 65 66 69 6e 65 64    /// Predefined
0130: 20 6c 61 79 65 72 20 66 6f 72 20 69 6e 74 65 72   layer for inter
0140: 6e 61 6c 20 64 61 74 61 0d 0a 09 56 61 6c 75 65  nal data...Value
0150: 4c 61 79 65 72 20 20 20 20 3d 20 22 40 76 61 6c  Layer    = "@val
0160: 75 65 22 2c 20 20 20 20 20 2f 2f 2f 20 50 72 65  ue",     /// Pre
0170: 64 65 66 69 6e 65 64 20 6c 61 79 65 72 20 66 6f  defined layer fo
0180: 72 20 6e 6f 72 6d 61 6c 20 72 75 6e 0d 0a 09 4d  r normal run...M
0190: 61 63 72 6f 4c 61 79 65 72 20 20 20 20 3d 20 22  acroLayer    = "
01a0: 40 6d 61 63 72 6f 22 2c 20 20 20 20 20 2f 2f 2f  @macro",     ///
01b0: 20 50 72 65 64 65 66 69 6e 65 64 20 6c 61 79 65   Predefined laye
01c0: 72 20 66 6f 72 20 6d 61 63 72 6f 20 72 75 6e 20  r for macro run 
01d0: 28 40 6c 61 79 28 29 20 63 68 61 6e 67 65 73 20  (@lay() changes 
01e0: 6c 61 79 65 72 29 0d 0a 09 52 61 77 4d 61 63 72  layer)...RawMacr
01f0: 6f 4c 61 79 65 72 20 3d 20 22 28 72 61 77 6d 61  oLayer = "(rawma
0200: 63 72 6f 29 22 2c 20 2f 2f 2f 20 50 72 65 64 65  cro)", /// Prede
0210: 66 69 6e 65 64 20 6c 61 79 65 72 20 66 6f 72 20  fined layer for 
0220: 6d 61 63 72 6f 20 72 75 6e 20 28 40 6c 61 79 28  macro run (@lay(
0230: 29 20 62 65 63 6f 6d 65 73 20 41 53 54 29 0d 0a  ) becomes AST)..
0240: 09 41 73 74 4c 61 79 65 72 20 20 20 20 20 20 3d  .AstLayer      =
0250: 20 22 28 61 73 74 29 22 2c 20 20 20 20 20 20 2f   "(ast)",      /
0260: 2f 2f 20 50 72 65 64 65 66 69 6e 65 64 20 6c 61  // Predefined la
0270: 79 65 72 20 66 6f 72 20 6d 61 63 72 6f 20 72 75  yer for macro ru
0280: 6e 20 28 6e 65 76 65 72 20 69 6e 76 6f 6b 65 20  n (never invoke 
0290: 6d 61 63 72 6f 29 0d 0a 7d 0d 0a 0d 0a 2f 2f 2f  macro)..}....///
02a0: 20 54 72 75 65 20 69 66 20 69 74 20 69 73 20 6d   True if it is m
02b0: 61 63 72 6f 2d 6c 69 6b 65 20 6c 61 79 65 72 20  acro-like layer 
02c0: 74 68 61 74 20 62 61 73 69 63 61 6c 6c 79 20 67  that basically g
02d0: 65 6e 65 72 61 74 65 73 20 73 79 6e 74 61 78 20  enerates syntax 
02e0: 74 72 65 65 0d 0a 0d 0a 62 6f 6f 6c 20 69 73 41  tree....bool isA
02f0: 53 54 4c 61 79 65 72 28 20 4c 61 79 65 72 20 6c  STLayer( Layer l
0300: 61 79 20 29 0d 0a 7b 0d 0a 09 72 65 74 75 72 6e  ay )..{...return
0310: 20 6c 61 79 3d 3d 4d 61 63 72 6f 4c 61 79 65 72   lay==MacroLayer
0320: 20 7c 7c 20 6c 61 79 3d 3d 52 61 77 4d 61 63 72   || lay==RawMacr
0330: 6f 4c 61 79 65 72 20 7c 7c 20 6c 61 79 3d 3d 41  oLayer || lay==A
0340: 73 74 4c 61 79 65 72 3b 0d 0a 7d 0d 0a 0d 0a 75  stLayer;..}....u
0350: 6e 69 74 74 65 73 74 0d 0a 7b 0d 0a 09 61 73 73  nittest..{...ass
0360: 65 72 74 28 20 21 69 73 41 53 54 4c 61 79 65 72  ert( !isASTLayer
0370: 28 53 79 73 74 65 6d 4c 61 79 65 72 29 20 29 3b  (SystemLayer) );
0380: 0d 0a 09 61 73 73 65 72 74 28 20 21 69 73 41 53  ...assert( !isAS
0390: 54 4c 61 79 65 72 28 56 61 6c 75 65 4c 61 79 65  TLayer(ValueLaye
03a0: 72 29 20 29 3b 0d 0a 09 61 73 73 65 72 74 28 20  r) );...assert( 
03b0: 69 73 41 53 54 4c 61 79 65 72 28 4d 61 63 72 6f  isASTLayer(Macro
03c0: 4c 61 79 65 72 29 20 29 3b 0d 0a 09 61 73 73 65  Layer) );...asse
03d0: 72 74 28 20 69 73 41 53 54 4c 61 79 65 72 28 52  rt( isASTLayer(R
03e0: 61 77 4d 61 63 72 6f 4c 61 79 65 72 29 20 29 3b  awMacroLayer) );
03f0: 0d 0a 09 61 73 73 65 72 74 28 20 69 73 41 53 54  ...assert( isAST
0400: 4c 61 79 65 72 28 41 73 74 4c 61 79 65 72 29 20  Layer(AstLayer) 
0410: 29 3b 0d 0a 7d 0d 0a 0d 0a 2f 2f 2f 20 54 72 75  );..}..../// Tru
0420: 65 20 69 66 20 69 6e 20 74 68 65 20 73 70 65 63  e if in the spec
0430: 69 66 69 65 64 20 6c 61 79 65 72 20 40 6c 61 79  ified layer @lay
0440: 28 2e 2e 2e 29 20 68 61 73 20 6e 6f 20 65 66 66  (...) has no eff
0450: 65 63 74 20 61 6e 64 20 6d 65 72 65 6c 79 20 70  ect and merely p
0460: 72 6f 64 75 63 65 73 20 61 20 73 79 6e 74 61 78  roduces a syntax
0470: 20 74 72 65 65 0d 0a 0d 0a 62 6f 6f 6c 20 69 73   tree....bool is
0480: 4e 6f 4c 61 79 65 72 43 68 61 6e 67 65 4c 61 79  NoLayerChangeLay
0490: 65 72 28 20 4c 61 79 65 72 20 6c 61 79 20 29 0d  er( Layer lay ).
04a0: 0a 7b 0d 0a 09 72 65 74 75 72 6e 20 6c 61 79 3d  .{...return lay=
04b0: 3d 52 61 77 4d 61 63 72 6f 4c 61 79 65 72 20 7c  =RawMacroLayer |
04c0: 7c 20 6c 61 79 3d 3d 41 73 74 4c 61 79 65 72 3b  | lay==AstLayer;
04d0: 0d 0a 7d 0d 0a 0d 0a 75 6e 69 74 74 65 73 74 0d  ..}....unittest.
04e0: 0a 7b 0d 0a 09 61 73 73 65 72 74 28 20 21 69 73  .{...assert( !is
04f0: 4e 6f 4c 61 79 65 72 43 68 61 6e 67 65 4c 61 79  NoLayerChangeLay
0500: 65 72 28 53 79 73 74 65 6d 4c 61 79 65 72 29 20  er(SystemLayer) 
0510: 29 3b 0d 0a 09 61 73 73 65 72 74 28 20 21 69 73  );...assert( !is
0520: 4e 6f 4c 61 79 65 72 43 68 61 6e 67 65 4c 61 79  NoLayerChangeLay
0530: 65 72 28 56 61 6c 75 65 4c 61 79 65 72 29 20 29  er(ValueLayer) )
0540: 3b 0d 0a 09 61 73 73 65 72 74 28 20 21 69 73 4e  ;...assert( !isN
0550: 6f 4c 61 79 65 72 43 68 61 6e 67 65 4c 61 79 65  oLayerChangeLaye
0560: 72 28 4d 61 63 72 6f 4c 61 79 65 72 29 20 29 3b  r(MacroLayer) );
0570: 0d 0a 09 61 73 73 65 72 74 28 20 69 73 4e 6f 4c  ...assert( isNoL
0580: 61 79 65 72 43 68 61 6e 67 65 4c 61 79 65 72 28  ayerChangeLayer(
0590: 52 61 77 4d 61 63 72 6f 4c 61 79 65 72 29 20 29  RawMacroLayer) )
05a0: 3b 0d 0a 09 61 73 73 65 72 74 28 20 69 73 4e 6f  ;...assert( isNo
05b0: 4c 61 79 65 72 43 68 61 6e 67 65 4c 61 79 65 72  LayerChangeLayer
05c0: 28 41 73 74 4c 61 79 65 72 29 20 29 3b 0d 0a 7d  (AstLayer) );..}
05d0: 0d 0a 0d 0a 2f 2f 2f 20 54 72 75 65 20 69 66 20  ..../// True if 
05e0: 64 6f 20 6d 61 63 72 6f 20 65 78 70 61 6e 73 74  do macro expanst
05f0: 69 6f 6e 0d 0a 0d 0a 62 6f 6f 6c 20 69 73 4d 61  ion....bool isMa
0600: 63 72 6f 4c 61 79 65 72 28 20 4c 61 79 65 72 20  croLayer( Layer 
0610: 6c 61 79 20 29 0d 0a 7b 0d 0a 09 72 65 74 75 72  lay )..{...retur
0620: 6e 20 6c 61 79 3d 3d 4d 61 63 72 6f 4c 61 79 65  n lay==MacroLaye
0630: 72 20 7c 7c 20 6c 61 79 3d 3d 52 61 77 4d 61 63  r || lay==RawMac
0640: 72 6f 4c 61 79 65 72 3b 0d 0a 7d 0d 0a 0d 0a 75  roLayer;..}....u
0650: 6e 69 74 74 65 73 74 0d 0a 7b 0d 0a 09 61 73 73  nittest..{...ass
0660: 65 72 74 28 20 21 69 73 4d 61 63 72 6f 4c 61 79  ert( !isMacroLay
0670: 65 72 28 53 79 73 74 65 6d 4c 61 79 65 72 29 20  er(SystemLayer) 
0680: 29 3b 0d 0a 09 61 73 73 65 72 74 28 20 21 69 73  );...assert( !is
0690: 4d 61 63 72 6f 4c 61 79 65 72 28 56 61 6c 75 65  MacroLayer(Value
06a0: 4c 61 79 65 72 29 20 29 3b 0d 0a 09 61 73 73 65  Layer) );...asse
06b0: 72 74 28 20 69 73 4d 61 63 72 6f 4c 61 79 65 72  rt( isMacroLayer
06c0: 28 4d 61 63 72 6f 4c 61 79 65 72 29 20 29 3b 0d  (MacroLayer) );.
06d0: 0a 09 61 73 73 65 72 74 28 20 69 73 4d 61 63 72  ..assert( isMacr
06e0: 6f 4c 61 79 65 72 28 52 61 77 4d 61 63 72 6f 4c  oLayer(RawMacroL
06f0: 61 79 65 72 29 20 29 3b 0d 0a 09 61 73 73 65 72  ayer) );...asser
0700: 74 28 20 21 69 73 4d 61 63 72 6f 4c 61 79 65 72  t( !isMacroLayer
0710: 28 41 73 74 4c 61 79 65 72 29 20 29 3b 0d 0a 7d  (AstLayer) );..}
0720: 0d 0a                                            ..