Advertisement
snake5

new lang: func resolution, storage classes

Jan 28th, 2015
569
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 2.48 KB | None | 0 0
  1. //// NewLang CODE ////
  2. class twoint
  3. {
  4.     var first : int32;
  5.     var second : uint32;
  6. }
  7.  
  8. extern func dump( v : int32 );
  9. extern func dump( v : float64 );
  10.  
  11. static var gval : int32 = 1;
  12.  
  13. func _test( a : int32 ) : int32
  14. {
  15.     var v : int8 = -5;
  16.     while( v < 0 )
  17.     {
  18.         dump( v + a );
  19.         v += 1;
  20.         break 1;
  21.     }
  22.     return 0s8 + a + v;
  23. }
  24.  
  25. func main()
  26. {
  27.     var ii : twoint;
  28.     ii.first = 5;
  29.     dump( ii.first );
  30.     gval += 123;
  31.     gval += 456;
  32.     dump( gval );
  33.     dump( sizeof( uint16 ) );
  34.     dump( sizeof( 0s8 ) );
  35.     var dbl : float64;
  36.     dump( sizeof( dbl ) );
  37.    
  38.     dump( _test( 1 ) );
  39.     dump( 1.2 );
  40. }
  41.  
  42. //// C CODE ////
  43. #include <inttypes.h>
  44.  
  45. typedef uint8_t Ibool;
  46. typedef int8_t Iint8;
  47. typedef uint8_t Iuint8;
  48. typedef int16_t Iint16;
  49. typedef uint16_t Iuint16;
  50. typedef int32_t Iint32;
  51. typedef uint32_t Iuint32;
  52. typedef int64_t Iint64;
  53. typedef uint64_t Iuint64;
  54. typedef float Ifloat32;
  55. typedef double Ifloat64;
  56.  
  57. typedef struct Itwoint
  58. {
  59.     Iint32 Ifirst;
  60.     Iuint32 Isecond;
  61. }
  62. Itwoint;
  63.  
  64. Iint32 Igval = 1;
  65.  
  66. extern void Idump_IPint32( Iint32 Iv );
  67. extern void Idump_IPfloat64( Ifloat64 Iv );
  68. Iint32 _Itest_IPint32( Iint32 Ia );
  69. void Imain();
  70.  
  71. Iint32 _Itest_IPint32( Iint32 Ia )
  72. {
  73.     Iint8 Iv;
  74.     const Iuint8 I0 = 5;
  75.     Iint32 I1 = -I0;
  76.     Iv = I1;
  77. lbl_0:;
  78.     const Iuint8 I2 = 0;
  79.     Ibool I3 = Iv < I2;
  80.     if( !I3 ) goto lbl_1;
  81.     Iint32 I4 = Iv + Ia;
  82.     Idump_IPint32( I4 );
  83.     const Iuint8 I5 = 1;
  84.     Iv = Iv + I5;
  85.     Iv = Iv;
  86.     goto lbl_1;
  87.     goto lbl_0;
  88. lbl_1:;
  89.     const Iint8 I6 = 0;
  90.     Iint32 I7 = I6 + Ia;
  91.     Iint32 I8 = I7 + Iv;
  92.     return I8;
  93. }
  94.  
  95. void Imain()
  96. {
  97.     Ifloat64 Idbl;
  98.     Itwoint Iii;
  99.     const Iuint32 I0 = 0;
  100.     char* I1 = (char*) &Iii;
  101.     char* I2 = I1 + I0;
  102.     const Iuint8 I3 = 5;
  103.     *(Iint32*) I2 = I3;
  104.     const Iuint32 I4 = 0;
  105.     char* I5 = (char*) &Iii;
  106.     char* I6 = I5 + I4;
  107.     Iint32 I7 = *I6;
  108.     Idump_IPint32( I7 );
  109.     const Iuint8 I8 = 123;
  110.     Iint32 I9 = Igval;
  111.     Iint32 I10 = I9 + I8;
  112.     Igval = I10;
  113.     const Iuint16 I11 = 456;
  114.     Iint32 I12 = Igval;
  115.     Iint32 I13 = I12 + I11;
  116.     Igval = I13;
  117.     Iint32 I14 = Igval;
  118.     Idump_IPint32( I14 );
  119.     const Iint32 I15 = 2;
  120.     Idump_IPint32( I15 );
  121.     const Iint8 I16 = 0;
  122.     const Iint32 I17 = 1;
  123.     Idump_IPint32( I17 );
  124.     const Iint32 I18 = 8;
  125.     Idump_IPint32( I18 );
  126.     const Iuint8 I19 = 1;
  127.     Iint32 I20 = _Itest_IPint32( I19 );
  128.     Idump_IPint32( I20 );
  129.     const Ifloat64 I21 = 1.2;
  130.     Idump_IPfloat64( I21 );
  131. }
  132.  
  133. int main()
  134. {
  135.     Imain();
  136.     return 0;
  137. }
  138.  
  139. //// OUTPUT ////
  140. int32 (5)
  141. int32 (580)
  142. int32 (2)
  143. int32 (1)
  144. int32 (8)
  145. int32 (-4)
  146. int32 (-3)
  147. float64 (1.2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement