Advertisement
snake5

new lang: break, globals

Jan 18th, 2015
564
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.95 KB | None | 0 0
  1. /// CODE ///
  2. extern func dump( v : int64 );
  3.  
  4. static var gval : int32 = 1;
  5.  
  6. func _test( a : int32 ) : int32
  7. {
  8.     var v : int8 = -5;
  9.     while( v < 0 )
  10.     {
  11.         dump( v + a );
  12.         v += 1;
  13.         break 1;
  14.     }
  15.     return 0s8 + a + v;
  16. }
  17.  
  18. func main()
  19. {
  20.     gval += 123;
  21.     gval += 456;
  22.     dump( gval );
  23.     dump( sizeof( uint16 ) );
  24.     dump( sizeof( 0s8 ) );
  25.     var dbl : float64;
  26.     dump( sizeof( dbl ) );
  27.    
  28.     dump( _test( 1 ) );
  29. }
  30. /// BYTECODE ///
  31. FUNC (struct=6 op=30 opsub=0 tt=75)
  32. {
  33.   name = '_test'
  34.   bytecode:
  35.     DECLARG <int32> a [7]
  36.     DECLVAR <int8> v [2]
  37.     CONST <uint8> 0 [15] : 05
  38.     NEGATE <int32> 1 [17] <= 0 [15]
  39.     COPY <int8> v [2] <= 1 [17]
  40.     LABEL: lbl_0
  41.     CONST <uint8> 2 [20] : 00
  42.     LT <bool> 3 [23] <= v [2], 2 [20]
  43.     JUMP_NIF: 3 ?~! lbl_1 [19]
  44.     ADD <int32> 4 [24] <= v [2], a [7]
  45.     FCALL <>  [0] <= func:dump [1] args(1): 4 [24]
  46.     CONST <uint8> 5 [25] : 01
  47.     ADD <int32> v [2] <= v [2], 5 [25]
  48.     JUMP: lbl_1
  49.     JUMP: lbl_0
  50.     LABEL: lbl_1
  51.     CONST <int8> 6 [27] : 00
  52.     ADD <int32> 7 [28] <= 6 [27], a [7]
  53.     ADD <int32> 8 [29] <= 7 [28], v [2]
  54.     RETURN 8 [29]
  55. }
  56. FUNC (struct=6 op=30 opsub=0 tt=75)
  57. {
  58.   name = 'main'
  59.   bytecode:
  60.     DECLVAR <float64> dbl [12]
  61.     CONST <uint8> 0 [15] : 7b
  62.     GLOBGET <int32> 1 [17] <= gval
  63.     ADD <int32> 2 [20] <= 1 [17], 0 [15]
  64.     GLOBSET gval <= 2 [20]
  65.     CONST <uint16> 3 [23] : ffffffc801
  66.     GLOBGET <int32> 4 [24] <= gval
  67.     ADD <int32> 5 [25] <= 4 [24], 3 [23]
  68.     GLOBSET gval <= 5 [25]
  69.     FCALL <>  [0] <= func:dump [1] args(1): gval [4]
  70.     CONST <int32> 6 [27] : 02000000
  71.     FCALL <>  [0] <= func:dump [1] args(1): 6 [27]
  72.     CONST <int8> 7 [28] : 00
  73.     CONST <int32> 8 [29] : 01000000
  74.     FCALL <>  [0] <= func:dump [1] args(1): 8 [29]
  75.     CONST <int32> 9 [34] : 08000000
  76.     FCALL <>  [0] <= func:dump [1] args(1): 9 [34]
  77.     CONST <uint8> 10 [36] : 01
  78.     FCALL <int32> 11 [37] <= func:_test [6] args(1): 10 [36]
  79.     FCALL <>  [0] <= func:dump [1] args(1): 11 [37]
  80. }
  81. /// GENERATED C CODE ///
  82. Iint32 Igval = 1;
  83.  
  84. extern void Idump( Iint64 Iv );
  85. Iint32 _Itest( Iint32 Ia );
  86. void Imain();
  87.  
  88. Iint32 _Itest( Iint32 Ia )
  89. {
  90.     Iint8 Iv;
  91.     const Iuint8 I0 = 5;
  92.     Iint32 I1 = -I0;
  93.     Iv = I1;
  94. lbl_0:;
  95.     const Iuint8 I2 = 0;
  96.     Ibool I3 = Iv < I2;
  97.     if( !I3 ) goto lbl_1;
  98.     Iint32 I4 = Iv + Ia;
  99.     Idump( I4 );
  100.     const Iuint8 I5 = 1;
  101.     Iv = Iv + I5;
  102.     goto lbl_1;
  103.     goto lbl_0;
  104. lbl_1:;
  105.     const Iint8 I6 = 0;
  106.     Iint32 I7 = I6 + Ia;
  107.     Iint32 I8 = I7 + Iv;
  108.     return I8;
  109. }
  110.  
  111. void Imain()
  112. {
  113.     Ifloat64 Idbl;
  114.     const Iuint8 I0 = 123;
  115.     Iint32 I1 = Igval;
  116.     Iint32 I2 = I1 + I0;
  117.     Igval = I2;
  118.     const Iuint16 I3 = 456;
  119.     Iint32 I4 = Igval;
  120.     Iint32 I5 = I4 + I3;
  121.     Igval = I5;
  122.     Idump( Igval );
  123.     const Iint32 I6 = 2;
  124.     Idump( I6 );
  125.     const Iint8 I7 = 0;
  126.     const Iint32 I8 = 1;
  127.     Idump( I8 );
  128.     const Iint32 I9 = 8;
  129.     Idump( I9 );
  130.     const Iuint8 I10 = 1;
  131.     Iint32 I11 = _Itest( I10 );
  132.     Idump( I11 );
  133. }
  134. /// OUTPUT ///
  135. int (580)
  136. int (2)
  137. int (1)
  138. int (8)
  139. int (-4)
  140. int (-3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement