-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.fastj
195 lines (131 loc) · 2.69 KB
/
example.fastj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/**
define Filter in java
package net.fastj;
public interface Filter<T> {
boolean isSatisfied(T obj);
}
*/
var filter = [net.fastj.Filter](s)=> s.contains("hai");
println(filter("lichanghai"));
println(filter.isSatisfied("hello world"));
class Filter2{
def dispatch(dispatcher){
println(dispatcher);
if(dispatcher.isInvoke()){
return true;
}
return false;
}
def isSatisfied( obj){
return obj.contains("li");
}
}
import("net.fastj.Filter");
var filter = createProxy(new Filter2(), Filter.class);
println("filter.isSatisfied: " +filter.isSatisfied("lichanghai"));
jLabel: for(j = 0;j<1;j++){
iLabel: for(var i=0;i<10;i++) {
println("j=" + j + ", i=" + i);
if(i >4) break jLabel;
}
}
def loopFun(){
for(var i=0;i<10;i++)
yield i*20;
}
println(loopFun());
class Int{
var value = 0;
def Int(){
}
def Int(v){
this.value = v;
}
def + (v){
return new Int(this.value +v);
}
def toString(){
return this.value;
}
def ()(k){
return k+10;
}
def [](k){
return k+11;
}
}
var xx = new Int(10);
println(new Int(40) + 20);
println("--------------"+xx(20));
println("--------------"+xx[20]);
println(new String("lichanghai"));
var x = [java.util.concurrent.Callable.call]()=> 10;
println(x());
def fun(a, v0, v1){
return a(v0, v1);
}
var k = (a,b) => a+b;
println(fun((a,b) => a+b, 123, 234));
// class
class S0{
var s0=20;
def S0(){
this.s0 = 100000000;
}
def add(d){
return d + this.s0;
}
}
println(new S0().add(10) );
class S1{
var s1=11;
def sub(d){
return d - this.s1;
}
}
println(new S1().sub(10) );
class C0 : S0, S1 {
def C0(x){
this.s1 = x;
}
}
var c0 = new C0(2000);
println(c0.add(c0.sub(20)));
println( __LINE__ );
println(toStr("25")+20);
for(var i=0;i<1;i++){
println( @'@Operators(ops = { "()" })');
var code = "public Object fun(";
for(var j=0;j<i;j++){
if(j!=0){
code = code + " , ";
}
code = code + "Object obj"+j;
}
println(code +"){");
code = "return this.invoke(";
for(var j=0;j<i;j++){
if(j!=0){
code = code + " , ";
}
code = code + "obj"+j;
}
println(code + ");");
println("}");
println();
}
println(true);
println(String.class);
println(now());
println("----------------------------------------------------------------------------");
println("----------------------------------------------------------------------------");
if(defined(__FILE__))
{
var count=0;
for(var line : readfile(__FILE__)){
println(line);
if( (count++) > 10){
break;
}
}
}