Mercurial Hosting > luan
annotate src/luan/LuanClosure.java @ 1809:90187946d1a4
minor
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 12 May 2024 17:15:33 -0600 |
parents | c922446f53aa |
children |
rev | line source |
---|---|
1330 | 1 package luan; |
21
c93d8c781853
add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
2 |
1330 | 3 import luan.impl.Pointer; |
21
c93d8c781853
add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
4 |
c93d8c781853
add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
5 |
1578 | 6 public abstract class LuanClosure extends LuanFunction implements LuanMutable { |
1330 | 7 public Pointer[] upValues; |
8 public boolean javaOk; | |
9 public final String sourceName; | |
1578 | 10 private boolean immutable = false; |
21
c93d8c781853
add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
11 |
1563
8fbcc4747091
remove LuanFunction.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
1561
diff
changeset
|
12 public LuanClosure(Pointer[] upValues,boolean javaOk,String sourceName) throws LuanException { |
1400
221eedb0f54e
fix inner class gc bug
Franklin Schmidt <fschmidt@gmail.com>
parents:
1347
diff
changeset
|
13 this.upValues = upValues; |
1133 | 14 this.javaOk = javaOk; |
1330 | 15 this.sourceName = sourceName; |
21
c93d8c781853
add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
16 } |
c93d8c781853
add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
17 |
1578 | 18 @Override public final boolean isImmutable() { |
19 return immutable; | |
1563
8fbcc4747091
remove LuanFunction.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
1561
diff
changeset
|
20 } |
8fbcc4747091
remove LuanFunction.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
1561
diff
changeset
|
21 |
1578 | 22 @Override public final void makeImmutable() { |
23 if(immutable) | |
1563
8fbcc4747091
remove LuanFunction.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
1561
diff
changeset
|
24 return; |
1578 | 25 immutable = true; |
26 LuanMutable.makeImmutable(upValues); | |
1563
8fbcc4747091
remove LuanFunction.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
1561
diff
changeset
|
27 } |
8fbcc4747091
remove LuanFunction.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
1561
diff
changeset
|
28 |
8fbcc4747091
remove LuanFunction.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
1561
diff
changeset
|
29 @Override public final Object call(Luan luan,Object... args) throws LuanException { |
1330 | 30 luan.push(this); |
659
f1150518c467
remove tail recursion
Franklin Schmidt <fschmidt@gmail.com>
parents:
646
diff
changeset
|
31 try { |
670
58ebfec6178b
all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents:
668
diff
changeset
|
32 return doCall(luan,args); |
681 | 33 } catch(StackOverflowError e) { |
1347
643cf1c37723
move webserver to lib and bug fixes
Franklin Schmidt <fschmidt@gmail.com>
parents:
1335
diff
changeset
|
34 throw new LuanException( "stack overflow", e ); |
659
f1150518c467
remove tail recursion
Franklin Schmidt <fschmidt@gmail.com>
parents:
646
diff
changeset
|
35 } finally { |
1330 | 36 luan.pop(); |
670
58ebfec6178b
all luan now compiles
Franklin Schmidt <fschmidt@gmail.com>
parents:
668
diff
changeset
|
37 } |
21
c93d8c781853
add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
38 } |
c93d8c781853
add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
39 |
1578 | 40 @Override public final String toString() { |
1335 | 41 return super.toString()+"="+sourceName; |
42 } | |
43 | |
1333
25746915a241
merge Luan and LuanState
Franklin Schmidt <fschmidt@gmail.com>
parents:
1330
diff
changeset
|
44 public abstract Object doCall(Luan luan,Object[] args) throws LuanException; |
21
c93d8c781853
add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff
changeset
|
45 } |