comparison src/luan/impl/Closure.java @ 775:1a68fc55a80c

simplify dir structure
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 26 Aug 2016 14:36:40 -0600
parents core/src/luan/impl/Closure.java@f1c935be546d
children fbbdd369a13a
comparison
equal deleted inserted replaced
774:3e30cf310e56 775:1a68fc55a80c
1 package luan.impl;
2
3 import luan.Luan;
4 import luan.LuanFunction;
5 import luan.LuanState;
6 import luan.LuanException;
7 import luan.DeepCloner;
8 import luan.DeepCloneable;
9 import luan.LuanJava;
10
11
12 public abstract class Closure extends LuanFunction implements DeepCloneable, Cloneable {
13 public Pointer[] upValues;
14 public LuanJava java;
15
16 public Closure(int nUpValues,LuanJava java) throws LuanException {
17 this.upValues = new Pointer[nUpValues];
18 this.java = java;
19 }
20
21 @Override public Closure shallowClone() {
22 try {
23 return (Closure)clone();
24 } catch(CloneNotSupportedException e) {
25 throw new RuntimeException(e);
26 }
27 }
28
29 @Override public void deepenClone(DeepCloneable dc,DeepCloner cloner) {
30 Closure clone = (Closure)dc;
31 clone.upValues = (Pointer[])cloner.deepClone(upValues);
32 clone.java = (LuanJava)cloner.deepClone(java);
33 }
34
35 @Override public final Object call(LuanState luan,Object[] args) throws LuanException {
36 LuanJava old = luan.java;
37 luan.java = java;
38 try {
39 return doCall(luan,args);
40 } catch(StackOverflowError e) {
41 throw new LuanException( "stack overflow" );
42 } finally {
43 luan.java = old;
44 }
45 }
46
47 public abstract Object doCall(LuanState luan,Object[] args) throws LuanException;
48 }