default.txt 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. package my.package;
  2. #if js
  3. import js.Browser;
  4. #elseif sys
  5. import Sys;
  6. #else
  7. import Date;
  8. #end
  9. import Lambda;
  10. using Main.IntExtender;
  11. extern class Math {
  12. static var PI(default,null) : Float;
  13. static function floor(v:Float):Int;
  14. }
  15. /**
  16. * Abstract forwarding
  17. */
  18. abstract MyAbstract(Int) from Int to Int {
  19. inline function new(i:Int) {
  20. this = i;
  21. }
  22. @:op(A * B)
  23. public function multiply(rhs:MyAbstract) {
  24. return this * rhs;
  25. }
  26. }
  27. // an enum
  28. enum Color {
  29. Red;
  30. Green;
  31. Blue;
  32. Rgb(r:Int, g:Int, b:Int);
  33. }
  34. @:generic
  35. class Gen<T> {
  36. var v:T;
  37. public function new(v:T) {
  38. this.v = v;
  39. }
  40. public var x(get, set):T;
  41. private inline function get_x():T
  42. return v;
  43. private inline function set_x(x:T):T
  44. return v = x;
  45. }
  46. class Main extends BaseClass implements SomeFunctionality {
  47. var callback:Void->Void = null;
  48. var myArray:Array<Float> = new Array<Float>();
  49. var arr = [4,8,0,3,9,1,5,2,6,7];
  50. public function new(x) {
  51. super(x);
  52. }
  53. public static function main() {
  54. trace('What\'s up?');
  55. trace('Hi, ${name}!');
  56. // switch statements!
  57. var c:Color = Color.Green;
  58. var x:Int = switch(c) {
  59. case Red: 0;
  60. case Green: 1;
  61. case Blue: 2;
  62. case Rgb(r, g, b): 3;
  63. case _: -1;
  64. }
  65. for(i in 0...3) {
  66. trace(i);
  67. continue;
  68. break;
  69. }
  70. do {
  71. trace("Hey-o!");
  72. } while(false);
  73. var done:Bool = false;
  74. while(!done) {
  75. done = true;
  76. }
  77. var H:Int = cast new MyAbstract(42);
  78. var h:Int = cast(new MyAbstract(31), Int);
  79. try {
  80. throw "error";
  81. }
  82. catch(err:String) {
  83. trace(err);
  84. }
  85. var map = new haxe.ds.IntMap<String>();
  86. var f = map.set.bind(_, "12");
  87. }
  88. function nothing():Void
  89. trace("nothing!");
  90. private inline function func(a:Int, b:Float, ?c:String, d:Bool=false):Dynamic {
  91. return {
  92. x: 0,
  93. y: true,
  94. z: false,
  95. a: 1.53,
  96. b: 5e10,
  97. c: -12,
  98. h: null
  99. };
  100. }
  101. override function quicksort( lo : Int, hi : Int ) : Void {
  102. var i = lo;
  103. var j = hi;
  104. var buf = arr;
  105. var p = buf[(lo+hi)>>1];
  106. while( i <= j ) {
  107. while( arr[i] > p ) i++;
  108. while( arr[j] < p ) j--;
  109. if( i <= j ) {
  110. var t = buf[i];
  111. buf[i++] = buf[j];
  112. buf[j--] = t;
  113. }
  114. }
  115. if( lo < j ) quicksort( lo, j );
  116. if( i < hi ) quicksort( i, hi );
  117. }
  118. }