1/* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15declare function print(arg:any, arg1?:any):string; 16 17class cpu { 18 public mode: number = 1; 19 constructor() { 20 this.mode = 4; 21 } 22 public static add(a: number, b: number): number { 23 print(a); 24 cpu.sub(a, b); 25 var out : number = a + b; 26 return out; 27 } 28 get kind() { 29 print(this.mode); 30 return this.mode; 31 } 32 public static sub(a: number, b: number): number { 33 print(b); 34 var out : number = a + b; 35 return out; 36 } 37 38 static Constant = 1; 39 static Curve = 2; 40 static TwoC = 3; 41 static TwoCC = 4; 42 static test1 = 1; 43 static test2 = 2; 44 static test3 = 3; 45 static test4 = 4; 46 static test5 = 1; 47 static test6 = 2; 48 static test7 = 3; 49 static test8 = 4; 50 static test9 = 1; 51 static test10 = 2; 52 static test11 = 3; 53 static test12 = 4; 54 static test13 = 1; 55 static test14 = 2; 56 static test14 = 3; 57 static test15 = 4; 58 static test16 = 1; 59 static test17 = 2; 60 static test18 = 3; 61 static test19 = 4; 62 static test20 = 1; 63 static test21 = 2; 64 static test22 = 3; 65 static test23 = 4; 66 static test24 = 1; 67 static test25 = 2; 68 static test26 = 3; 69 static test27 = 4; 70 static test28 = 2; 71 static test29 = 3; 72 static test30 = 1; 73 static test31 = 2; 74 static test32 = 3; 75 static test33 = 4; 76 static test34 = 1; 77 static test35 = 2; 78 static test36 = 3; 79 static test37 = 4; 80 static test38 = 2; 81 static test39 = 3; 82 static test40 = 1; 83 static test41 = 2; 84 static test42 = 3; 85 static test43 = 4; 86 static test44 = 1; 87 static test45 = 2; 88 static test46 = 3; 89 static test47 = 4; 90 static test48 = 2; 91 static test49 = 3; 92 static test50 = 1; 93 static test51 = 2; 94 static test52 = 3; 95 static test53 = 4; 96 static test54 = 1; 97 static test55 = 2; 98 static test56 = 3; 99 static test57 = 4; 100 static test58 = 2; 101 static test59 = 3; 102 static test60 = 1; 103 static test61 = 2; 104 static test62 = 3; 105 static test63 = 4; 106 static test64 = 1; 107 static test65 = 2; 108 static test66 = 3; 109 static test67 = 4; 110 static test68 = 2; 111 static test69 = 3; 112 static test70 = 1; 113 static test71 = 2; 114 static test72 = 3; 115 static test73 = 4; 116 static test74 = 1; 117 static test75 = 2; 118 static test76 = 3; 119 static test77 = 4; 120 static test78 = 2; 121 static test79 = 3; 122 static test80 = 1; 123 static test81 = 2; 124 static test82 = 3; 125 static test83 = 4; 126 static test84 = 1; 127 static test85 = 2; 128 static test86 = 3; 129 static test87 = 4; 130 static test88 = 2; 131 static test89 = 3; 132 static test90 = 1; 133 static test91 = 2; 134 static test92 = 3; 135 static test93 = 4; 136 static test94 = 1; 137 static test95 = 2; 138 static test96 = 3; 139 static test97 = 4; 140 static test98 = 2; 141 static test99 = 3; 142 static test100 = 2; 143 static test101 = 3; 144 static test102 = 4; 145 static test103 = 1; 146 static test104 = 2; 147 static test104 = 3; 148 static test105 = 4; 149 static test106 = 1; 150 static test107 = 2; 151 static test108 = 3; 152 static test109 = 4; 153 static test110 = 2; 154 static test111 = 3; 155 static test112 = 4; 156 static test113 = 1; 157 static test114 = 2; 158 static test114 = 3; 159 static test115 = 4; 160 static test116 = 1; 161 static test117 = 2; 162 static test118 = 3; 163 static test119 = 4; 164} 165class cpu1 { 166 public mode: number = 1; 167 constructor() { 168 this.mode = 4; 169 } 170 171 public static color1(op: number): number { 172 return op; 173 } 174 175 public static color(color1:string, op: number): number; 176 177 public static color(color1:number, op: number): number; 178 179 public static color(color1: string | number, op: number): void { 180 print("method is ok"); 181 } 182 183 public static color2(op: number): number { 184 return op; 185 } 186 187 get kind() { 188 print(this.mode); 189 return this.mode; 190 } 191 static Constant = 1; 192 static Curve = 2; 193 static TwoC = 3; 194 static TwoCC = 4; 195} 196function foo():number { 197 return cpu.Curve; 198} 199print(foo()); 200cpu.add(1, 3); 201var systems: cpu = new cpu(); 202print(systems.kind); 203cpu.sub(1, 4); 204print(cpu1.TwoC); 205print(cpu1.length); 206cpu1.color(); 207 208try { 209 cpu1.length = 4; 210} catch (e) { 211 print(e) 212} 213 214class Info { 215 isHit: boolean = false; 216 hitCount: int = 0; 217 distance: number; 218 219 constructor() { 220 this.distance = 0; 221 } 222 223 toString() :string { 224 return 'Intersection [' + this.distance + ']'; 225 } 226} 227 228class Shape { 229 intersect(ray: number) : Info { 230 return undefined; 231 } 232 func1(a:any,...A:any) : void { 233 for (let p in A) { 234 print(A[p]); 235 } 236 } 237} 238 239class Scene { 240 shapes : Shape[]; 241 constructor() { 242 this.shapes = new Array(); 243 } 244} 245 246class Sphere extends Shape { 247 radius: number; 248 249 constructor(radius: number) { 250 super(); 251 this.radius = radius; 252 } 253 254 intersect(ray: number) : Info { 255 var info = new Info(); 256 print("intersect"); 257 return info; 258 } 259 260 func1() : void { 261 print("func1") 262 } 263} 264 265function testIntersection(scene: Scene): number { 266 var hits = 0; 267 for(var i= 0; i<scene.shapes.length; i++){ 268 var shape = scene.shapes[i]; 269 var info = shape.intersect(hits); 270 shape.func1(hits); 271 } 272 return hits; 273} 274 275function renderScene(){ 276 var scene = new Scene(); 277 278 var sphere = new Sphere(3); 279 280 var sphere1 = new Sphere(4); 281 282 scene.shapes.push(sphere); 283 scene.shapes.push(sphere1); 284 285 testIntersection(scene); 286} 287renderScene(); 288let sh = new Shape(); 289sh.func1(1, 2); 290 291class Node{ 292 public map : string; 293 public nodeType : number; 294 public parentNode : Node; 295 public childNode : Node; 296 297 constructor(radius: number) { 298 this.map = "hh"; 299 this.nodeType = 1; 300 this.parentNode = null; 301 this.childNode = null; 302 } 303 304 public lookup(names: string) : void { 305 var el = this; 306 while (el) { 307 var map = el.map; 308 if (map == names) { 309 print(map) 310 } 311 el = el.nodeType == 1 ? el.childNode : el.parentNode; 312 const tmp = Node.Constant; 313 print(el); 314 } 315 } 316 317 static Constant = 1; 318 static Curve = 2; 319 static TwoC = 3; 320} 321Object.defineProperty(Node, "property1", { 322 value: 32, 323 writable: false 324}); 325let obj = new Node(); 326obj.lookup("hh");