14514f5e3Sopenharmony_ci/* 24514f5e3Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License. 54514f5e3Sopenharmony_ci * You may obtain a copy of the License at 64514f5e3Sopenharmony_ci * 74514f5e3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 84514f5e3Sopenharmony_ci * 94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and 134514f5e3Sopenharmony_ci * limitations under the License. 144514f5e3Sopenharmony_ci */ 154514f5e3Sopenharmony_cideclare function print(arg:any, arg1?:any):string; 164514f5e3Sopenharmony_ci 174514f5e3Sopenharmony_ciclass cpu { 184514f5e3Sopenharmony_ci public mode: number = 1; 194514f5e3Sopenharmony_ci constructor() { 204514f5e3Sopenharmony_ci this.mode = 4; 214514f5e3Sopenharmony_ci } 224514f5e3Sopenharmony_ci public static add(a: number, b: number): number { 234514f5e3Sopenharmony_ci print(a); 244514f5e3Sopenharmony_ci cpu.sub(a, b); 254514f5e3Sopenharmony_ci var out : number = a + b; 264514f5e3Sopenharmony_ci return out; 274514f5e3Sopenharmony_ci } 284514f5e3Sopenharmony_ci get kind() { 294514f5e3Sopenharmony_ci print(this.mode); 304514f5e3Sopenharmony_ci return this.mode; 314514f5e3Sopenharmony_ci } 324514f5e3Sopenharmony_ci public static sub(a: number, b: number): number { 334514f5e3Sopenharmony_ci print(b); 344514f5e3Sopenharmony_ci var out : number = a + b; 354514f5e3Sopenharmony_ci return out; 364514f5e3Sopenharmony_ci } 374514f5e3Sopenharmony_ci 384514f5e3Sopenharmony_ci static Constant = 1; 394514f5e3Sopenharmony_ci static Curve = 2; 404514f5e3Sopenharmony_ci static TwoC = 3; 414514f5e3Sopenharmony_ci static TwoCC = 4; 424514f5e3Sopenharmony_ci static test1 = 1; 434514f5e3Sopenharmony_ci static test2 = 2; 444514f5e3Sopenharmony_ci static test3 = 3; 454514f5e3Sopenharmony_ci static test4 = 4; 464514f5e3Sopenharmony_ci static test5 = 1; 474514f5e3Sopenharmony_ci static test6 = 2; 484514f5e3Sopenharmony_ci static test7 = 3; 494514f5e3Sopenharmony_ci static test8 = 4; 504514f5e3Sopenharmony_ci static test9 = 1; 514514f5e3Sopenharmony_ci static test10 = 2; 524514f5e3Sopenharmony_ci static test11 = 3; 534514f5e3Sopenharmony_ci static test12 = 4; 544514f5e3Sopenharmony_ci static test13 = 1; 554514f5e3Sopenharmony_ci static test14 = 2; 564514f5e3Sopenharmony_ci static test14 = 3; 574514f5e3Sopenharmony_ci static test15 = 4; 584514f5e3Sopenharmony_ci static test16 = 1; 594514f5e3Sopenharmony_ci static test17 = 2; 604514f5e3Sopenharmony_ci static test18 = 3; 614514f5e3Sopenharmony_ci static test19 = 4; 624514f5e3Sopenharmony_ci static test20 = 1; 634514f5e3Sopenharmony_ci static test21 = 2; 644514f5e3Sopenharmony_ci static test22 = 3; 654514f5e3Sopenharmony_ci static test23 = 4; 664514f5e3Sopenharmony_ci static test24 = 1; 674514f5e3Sopenharmony_ci static test25 = 2; 684514f5e3Sopenharmony_ci static test26 = 3; 694514f5e3Sopenharmony_ci static test27 = 4; 704514f5e3Sopenharmony_ci static test28 = 2; 714514f5e3Sopenharmony_ci static test29 = 3; 724514f5e3Sopenharmony_ci static test30 = 1; 734514f5e3Sopenharmony_ci static test31 = 2; 744514f5e3Sopenharmony_ci static test32 = 3; 754514f5e3Sopenharmony_ci static test33 = 4; 764514f5e3Sopenharmony_ci static test34 = 1; 774514f5e3Sopenharmony_ci static test35 = 2; 784514f5e3Sopenharmony_ci static test36 = 3; 794514f5e3Sopenharmony_ci static test37 = 4; 804514f5e3Sopenharmony_ci static test38 = 2; 814514f5e3Sopenharmony_ci static test39 = 3; 824514f5e3Sopenharmony_ci static test40 = 1; 834514f5e3Sopenharmony_ci static test41 = 2; 844514f5e3Sopenharmony_ci static test42 = 3; 854514f5e3Sopenharmony_ci static test43 = 4; 864514f5e3Sopenharmony_ci static test44 = 1; 874514f5e3Sopenharmony_ci static test45 = 2; 884514f5e3Sopenharmony_ci static test46 = 3; 894514f5e3Sopenharmony_ci static test47 = 4; 904514f5e3Sopenharmony_ci static test48 = 2; 914514f5e3Sopenharmony_ci static test49 = 3; 924514f5e3Sopenharmony_ci static test50 = 1; 934514f5e3Sopenharmony_ci static test51 = 2; 944514f5e3Sopenharmony_ci static test52 = 3; 954514f5e3Sopenharmony_ci static test53 = 4; 964514f5e3Sopenharmony_ci static test54 = 1; 974514f5e3Sopenharmony_ci static test55 = 2; 984514f5e3Sopenharmony_ci static test56 = 3; 994514f5e3Sopenharmony_ci static test57 = 4; 1004514f5e3Sopenharmony_ci static test58 = 2; 1014514f5e3Sopenharmony_ci static test59 = 3; 1024514f5e3Sopenharmony_ci static test60 = 1; 1034514f5e3Sopenharmony_ci static test61 = 2; 1044514f5e3Sopenharmony_ci static test62 = 3; 1054514f5e3Sopenharmony_ci static test63 = 4; 1064514f5e3Sopenharmony_ci static test64 = 1; 1074514f5e3Sopenharmony_ci static test65 = 2; 1084514f5e3Sopenharmony_ci static test66 = 3; 1094514f5e3Sopenharmony_ci static test67 = 4; 1104514f5e3Sopenharmony_ci static test68 = 2; 1114514f5e3Sopenharmony_ci static test69 = 3; 1124514f5e3Sopenharmony_ci static test70 = 1; 1134514f5e3Sopenharmony_ci static test71 = 2; 1144514f5e3Sopenharmony_ci static test72 = 3; 1154514f5e3Sopenharmony_ci static test73 = 4; 1164514f5e3Sopenharmony_ci static test74 = 1; 1174514f5e3Sopenharmony_ci static test75 = 2; 1184514f5e3Sopenharmony_ci static test76 = 3; 1194514f5e3Sopenharmony_ci static test77 = 4; 1204514f5e3Sopenharmony_ci static test78 = 2; 1214514f5e3Sopenharmony_ci static test79 = 3; 1224514f5e3Sopenharmony_ci static test80 = 1; 1234514f5e3Sopenharmony_ci static test81 = 2; 1244514f5e3Sopenharmony_ci static test82 = 3; 1254514f5e3Sopenharmony_ci static test83 = 4; 1264514f5e3Sopenharmony_ci static test84 = 1; 1274514f5e3Sopenharmony_ci static test85 = 2; 1284514f5e3Sopenharmony_ci static test86 = 3; 1294514f5e3Sopenharmony_ci static test87 = 4; 1304514f5e3Sopenharmony_ci static test88 = 2; 1314514f5e3Sopenharmony_ci static test89 = 3; 1324514f5e3Sopenharmony_ci static test90 = 1; 1334514f5e3Sopenharmony_ci static test91 = 2; 1344514f5e3Sopenharmony_ci static test92 = 3; 1354514f5e3Sopenharmony_ci static test93 = 4; 1364514f5e3Sopenharmony_ci static test94 = 1; 1374514f5e3Sopenharmony_ci static test95 = 2; 1384514f5e3Sopenharmony_ci static test96 = 3; 1394514f5e3Sopenharmony_ci static test97 = 4; 1404514f5e3Sopenharmony_ci static test98 = 2; 1414514f5e3Sopenharmony_ci static test99 = 3; 1424514f5e3Sopenharmony_ci static test100 = 2; 1434514f5e3Sopenharmony_ci static test101 = 3; 1444514f5e3Sopenharmony_ci static test102 = 4; 1454514f5e3Sopenharmony_ci static test103 = 1; 1464514f5e3Sopenharmony_ci static test104 = 2; 1474514f5e3Sopenharmony_ci static test104 = 3; 1484514f5e3Sopenharmony_ci static test105 = 4; 1494514f5e3Sopenharmony_ci static test106 = 1; 1504514f5e3Sopenharmony_ci static test107 = 2; 1514514f5e3Sopenharmony_ci static test108 = 3; 1524514f5e3Sopenharmony_ci static test109 = 4; 1534514f5e3Sopenharmony_ci static test110 = 2; 1544514f5e3Sopenharmony_ci static test111 = 3; 1554514f5e3Sopenharmony_ci static test112 = 4; 1564514f5e3Sopenharmony_ci static test113 = 1; 1574514f5e3Sopenharmony_ci static test114 = 2; 1584514f5e3Sopenharmony_ci static test114 = 3; 1594514f5e3Sopenharmony_ci static test115 = 4; 1604514f5e3Sopenharmony_ci static test116 = 1; 1614514f5e3Sopenharmony_ci static test117 = 2; 1624514f5e3Sopenharmony_ci static test118 = 3; 1634514f5e3Sopenharmony_ci static test119 = 4; 1644514f5e3Sopenharmony_ci} 1654514f5e3Sopenharmony_ciclass cpu1 { 1664514f5e3Sopenharmony_ci public mode: number = 1; 1674514f5e3Sopenharmony_ci constructor() { 1684514f5e3Sopenharmony_ci this.mode = 4; 1694514f5e3Sopenharmony_ci } 1704514f5e3Sopenharmony_ci 1714514f5e3Sopenharmony_ci public static color1(op: number): number { 1724514f5e3Sopenharmony_ci return op; 1734514f5e3Sopenharmony_ci } 1744514f5e3Sopenharmony_ci 1754514f5e3Sopenharmony_ci public static color(color1:string, op: number): number; 1764514f5e3Sopenharmony_ci 1774514f5e3Sopenharmony_ci public static color(color1:number, op: number): number; 1784514f5e3Sopenharmony_ci 1794514f5e3Sopenharmony_ci public static color(color1: string | number, op: number): void { 1804514f5e3Sopenharmony_ci print("method is ok"); 1814514f5e3Sopenharmony_ci } 1824514f5e3Sopenharmony_ci 1834514f5e3Sopenharmony_ci public static color2(op: number): number { 1844514f5e3Sopenharmony_ci return op; 1854514f5e3Sopenharmony_ci } 1864514f5e3Sopenharmony_ci 1874514f5e3Sopenharmony_ci get kind() { 1884514f5e3Sopenharmony_ci print(this.mode); 1894514f5e3Sopenharmony_ci return this.mode; 1904514f5e3Sopenharmony_ci } 1914514f5e3Sopenharmony_ci static Constant = 1; 1924514f5e3Sopenharmony_ci static Curve = 2; 1934514f5e3Sopenharmony_ci static TwoC = 3; 1944514f5e3Sopenharmony_ci static TwoCC = 4; 1954514f5e3Sopenharmony_ci} 1964514f5e3Sopenharmony_cifunction foo():number { 1974514f5e3Sopenharmony_ci return cpu.Curve; 1984514f5e3Sopenharmony_ci} 1994514f5e3Sopenharmony_ciprint(foo()); 2004514f5e3Sopenharmony_cicpu.add(1, 3); 2014514f5e3Sopenharmony_civar systems: cpu = new cpu(); 2024514f5e3Sopenharmony_ciprint(systems.kind); 2034514f5e3Sopenharmony_cicpu.sub(1, 4); 2044514f5e3Sopenharmony_ciprint(cpu1.TwoC); 2054514f5e3Sopenharmony_ciprint(cpu1.length); 2064514f5e3Sopenharmony_cicpu1.color(); 2074514f5e3Sopenharmony_ci 2084514f5e3Sopenharmony_citry { 2094514f5e3Sopenharmony_ci cpu1.length = 4; 2104514f5e3Sopenharmony_ci} catch (e) { 2114514f5e3Sopenharmony_ci print(e) 2124514f5e3Sopenharmony_ci} 2134514f5e3Sopenharmony_ci 2144514f5e3Sopenharmony_ciclass Info { 2154514f5e3Sopenharmony_ci isHit: boolean = false; 2164514f5e3Sopenharmony_ci hitCount: int = 0; 2174514f5e3Sopenharmony_ci distance: number; 2184514f5e3Sopenharmony_ci 2194514f5e3Sopenharmony_ci constructor() { 2204514f5e3Sopenharmony_ci this.distance = 0; 2214514f5e3Sopenharmony_ci } 2224514f5e3Sopenharmony_ci 2234514f5e3Sopenharmony_ci toString() :string { 2244514f5e3Sopenharmony_ci return 'Intersection [' + this.distance + ']'; 2254514f5e3Sopenharmony_ci } 2264514f5e3Sopenharmony_ci} 2274514f5e3Sopenharmony_ci 2284514f5e3Sopenharmony_ciclass Shape { 2294514f5e3Sopenharmony_ci intersect(ray: number) : Info { 2304514f5e3Sopenharmony_ci return undefined; 2314514f5e3Sopenharmony_ci } 2324514f5e3Sopenharmony_ci func1(a:any,...A:any) : void { 2334514f5e3Sopenharmony_ci for (let p in A) { 2344514f5e3Sopenharmony_ci print(A[p]); 2354514f5e3Sopenharmony_ci } 2364514f5e3Sopenharmony_ci } 2374514f5e3Sopenharmony_ci} 2384514f5e3Sopenharmony_ci 2394514f5e3Sopenharmony_ciclass Scene { 2404514f5e3Sopenharmony_ci shapes : Shape[]; 2414514f5e3Sopenharmony_ci constructor() { 2424514f5e3Sopenharmony_ci this.shapes = new Array(); 2434514f5e3Sopenharmony_ci } 2444514f5e3Sopenharmony_ci} 2454514f5e3Sopenharmony_ci 2464514f5e3Sopenharmony_ciclass Sphere extends Shape { 2474514f5e3Sopenharmony_ci radius: number; 2484514f5e3Sopenharmony_ci 2494514f5e3Sopenharmony_ci constructor(radius: number) { 2504514f5e3Sopenharmony_ci super(); 2514514f5e3Sopenharmony_ci this.radius = radius; 2524514f5e3Sopenharmony_ci } 2534514f5e3Sopenharmony_ci 2544514f5e3Sopenharmony_ci intersect(ray: number) : Info { 2554514f5e3Sopenharmony_ci var info = new Info(); 2564514f5e3Sopenharmony_ci print("intersect"); 2574514f5e3Sopenharmony_ci return info; 2584514f5e3Sopenharmony_ci } 2594514f5e3Sopenharmony_ci 2604514f5e3Sopenharmony_ci func1() : void { 2614514f5e3Sopenharmony_ci print("func1") 2624514f5e3Sopenharmony_ci } 2634514f5e3Sopenharmony_ci} 2644514f5e3Sopenharmony_ci 2654514f5e3Sopenharmony_cifunction testIntersection(scene: Scene): number { 2664514f5e3Sopenharmony_ci var hits = 0; 2674514f5e3Sopenharmony_ci for(var i= 0; i<scene.shapes.length; i++){ 2684514f5e3Sopenharmony_ci var shape = scene.shapes[i]; 2694514f5e3Sopenharmony_ci var info = shape.intersect(hits); 2704514f5e3Sopenharmony_ci shape.func1(hits); 2714514f5e3Sopenharmony_ci } 2724514f5e3Sopenharmony_ci return hits; 2734514f5e3Sopenharmony_ci} 2744514f5e3Sopenharmony_ci 2754514f5e3Sopenharmony_cifunction renderScene(){ 2764514f5e3Sopenharmony_ci var scene = new Scene(); 2774514f5e3Sopenharmony_ci 2784514f5e3Sopenharmony_ci var sphere = new Sphere(3); 2794514f5e3Sopenharmony_ci 2804514f5e3Sopenharmony_ci var sphere1 = new Sphere(4); 2814514f5e3Sopenharmony_ci 2824514f5e3Sopenharmony_ci scene.shapes.push(sphere); 2834514f5e3Sopenharmony_ci scene.shapes.push(sphere1); 2844514f5e3Sopenharmony_ci 2854514f5e3Sopenharmony_ci testIntersection(scene); 2864514f5e3Sopenharmony_ci} 2874514f5e3Sopenharmony_cirenderScene(); 2884514f5e3Sopenharmony_cilet sh = new Shape(); 2894514f5e3Sopenharmony_cish.func1(1, 2); 2904514f5e3Sopenharmony_ci 2914514f5e3Sopenharmony_ciclass Node{ 2924514f5e3Sopenharmony_ci public map : string; 2934514f5e3Sopenharmony_ci public nodeType : number; 2944514f5e3Sopenharmony_ci public parentNode : Node; 2954514f5e3Sopenharmony_ci public childNode : Node; 2964514f5e3Sopenharmony_ci 2974514f5e3Sopenharmony_ci constructor(radius: number) { 2984514f5e3Sopenharmony_ci this.map = "hh"; 2994514f5e3Sopenharmony_ci this.nodeType = 1; 3004514f5e3Sopenharmony_ci this.parentNode = null; 3014514f5e3Sopenharmony_ci this.childNode = null; 3024514f5e3Sopenharmony_ci } 3034514f5e3Sopenharmony_ci 3044514f5e3Sopenharmony_ci public lookup(names: string) : void { 3054514f5e3Sopenharmony_ci var el = this; 3064514f5e3Sopenharmony_ci while (el) { 3074514f5e3Sopenharmony_ci var map = el.map; 3084514f5e3Sopenharmony_ci if (map == names) { 3094514f5e3Sopenharmony_ci print(map) 3104514f5e3Sopenharmony_ci } 3114514f5e3Sopenharmony_ci el = el.nodeType == 1 ? el.childNode : el.parentNode; 3124514f5e3Sopenharmony_ci const tmp = Node.Constant; 3134514f5e3Sopenharmony_ci print(el); 3144514f5e3Sopenharmony_ci } 3154514f5e3Sopenharmony_ci } 3164514f5e3Sopenharmony_ci 3174514f5e3Sopenharmony_ci static Constant = 1; 3184514f5e3Sopenharmony_ci static Curve = 2; 3194514f5e3Sopenharmony_ci static TwoC = 3; 3204514f5e3Sopenharmony_ci} 3214514f5e3Sopenharmony_ciObject.defineProperty(Node, "property1", { 3224514f5e3Sopenharmony_ci value: 32, 3234514f5e3Sopenharmony_ci writable: false 3244514f5e3Sopenharmony_ci}); 3254514f5e3Sopenharmony_cilet obj = new Node(); 3264514f5e3Sopenharmony_ciobj.lookup("hh");