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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1330
f41919741100 fix security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1159
diff changeset
1 package luan;
21
c93d8c781853 add functions
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2
1330
f41919741100 fix security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1159
diff changeset
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
c922446f53aa immutable threading
Franklin Schmidt <fschmidt@gmail.com>
parents: 1563
diff changeset
6 public abstract class LuanClosure extends LuanFunction implements LuanMutable {
1330
f41919741100 fix security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1159
diff changeset
7 public Pointer[] upValues;
f41919741100 fix security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1159
diff changeset
8 public boolean javaOk;
f41919741100 fix security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1159
diff changeset
9 public final String sourceName;
1578
c922446f53aa immutable threading
Franklin Schmidt <fschmidt@gmail.com>
parents: 1563
diff changeset
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
ba4daf107e07 fix security bug
Franklin Schmidt <fschmidt@gmail.com>
parents: 787
diff changeset
14 this.javaOk = javaOk;
1330
f41919741100 fix security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1159
diff changeset
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
c922446f53aa immutable threading
Franklin Schmidt <fschmidt@gmail.com>
parents: 1563
diff changeset
18 @Override public final boolean isImmutable() {
c922446f53aa immutable threading
Franklin Schmidt <fschmidt@gmail.com>
parents: 1563
diff changeset
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
c922446f53aa immutable threading
Franklin Schmidt <fschmidt@gmail.com>
parents: 1563
diff changeset
22 @Override public final void makeImmutable() {
c922446f53aa immutable threading
Franklin Schmidt <fschmidt@gmail.com>
parents: 1563
diff changeset
23 if(immutable)
1563
8fbcc4747091 remove LuanFunction.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 1561
diff changeset
24 return;
1578
c922446f53aa immutable threading
Franklin Schmidt <fschmidt@gmail.com>
parents: 1563
diff changeset
25 immutable = true;
c922446f53aa immutable threading
Franklin Schmidt <fschmidt@gmail.com>
parents: 1563
diff changeset
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
f41919741100 fix security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1159
diff changeset
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
f1c935be546d improve stack trace
Franklin Schmidt <fschmidt@gmail.com>
parents: 672
diff changeset
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
f41919741100 fix security
Franklin Schmidt <fschmidt@gmail.com>
parents: 1159
diff changeset
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
c922446f53aa immutable threading
Franklin Schmidt <fschmidt@gmail.com>
parents: 1563
diff changeset
40 @Override public final String toString() {
1335
e0cf0d108a77 major cleanup
Franklin Schmidt <fschmidt@gmail.com>
parents: 1333
diff changeset
41 return super.toString()+"="+sourceName;
e0cf0d108a77 major cleanup
Franklin Schmidt <fschmidt@gmail.com>
parents: 1333
diff changeset
42 }
e0cf0d108a77 major cleanup
Franklin Schmidt <fschmidt@gmail.com>
parents: 1333
diff changeset
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 }