view src/luan/LuanClosure.java @ 1626:cf9dfead83a3

use Config.postgres
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 07 Dec 2021 18:30:02 -0700
parents c922446f53aa
children
line wrap: on
line source

package luan;

import luan.impl.Pointer;


public abstract class LuanClosure extends LuanFunction implements LuanMutable {
	public Pointer[] upValues;
	public boolean javaOk;
	public final String sourceName;
	private boolean immutable = false;

	public LuanClosure(Pointer[] upValues,boolean javaOk,String sourceName) throws LuanException {
		this.upValues = upValues;
		this.javaOk = javaOk;
		this.sourceName = sourceName;
	}

	@Override public final boolean isImmutable() {
		return immutable;
	}

	@Override public final void makeImmutable() {
		if(immutable)
			return;
		immutable = true;
		LuanMutable.makeImmutable(upValues);
	}

	@Override public final Object call(Luan luan,Object... args) throws LuanException {
		luan.push(this);
		try {
			return doCall(luan,args);
		} catch(StackOverflowError e) {
			throw new LuanException( "stack overflow", e );
		} finally {
			luan.pop();
		}	
	}

	@Override public final String toString() {
		return super.toString()+"="+sourceName;
	}

	public abstract Object doCall(Luan luan,Object[] args) throws LuanException;
}