diff src/luan/interp/LuanParser.java @ 86:6db8f286fa6c

_ENV is per module, not global git-svn-id: https://luan-java.googlecode.com/svn/trunk@87 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Wed, 27 Feb 2013 08:03:51 +0000
parents b84f66704026
children d03022acea47
line wrap: on
line diff
--- a/src/luan/interp/LuanParser.java	Mon Feb 25 03:53:54 2013 +0000
+++ b/src/luan/interp/LuanParser.java	Wed Feb 27 08:03:51 2013 +0000
@@ -24,14 +24,6 @@
 
 class LuanParser extends BaseParser<Object> {
 
-	LuanSource source;
-
-	LuanSource.Element se(int start) {
-		return new LuanSource.Element(source,start,currentIndex());
-	}
-
-	static final String _ENV = "_ENV";
-
 	static final class Frame {
 		final Frame parent;
 		final List<String> symbols = new ArrayList<String>();
@@ -41,14 +33,16 @@
 		final List<String> upValueSymbols = new ArrayList<String>();
 		final List<UpValue.Getter> upValueGetters = new ArrayList<UpValue.Getter>();
 
-		Frame() {
+		Frame(UpValue.Getter envGetter) {
 			this.parent = null;
 			upValueSymbols.add(_ENV);
-			upValueGetters.add(UpValue.globalGetter);
+			upValueGetters.add(envGetter);
 		}
 
 		Frame(Frame parent) {
 			this.parent = parent;
+			if( upValueIndex(_ENV) != 0 )
+				throw new RuntimeException();
 		}
 
 		int stackIndex(String name) {
@@ -82,10 +76,22 @@
 		}
 	}
 
+	static final String _ENV = "_ENV";
 	static final UpValue.Getter[] NO_UP_VALUE_GETTERS = new UpValue.Getter[0];
 
+//	UpValue.Getter envGetter = new UpValue.EnvGetter();
+	final LuanSource source;
+	Frame frame;
 	int nEquals;
-	Frame frame = new Frame();
+
+	LuanParser(LuanSource source,UpValue.Getter envGetter) {
+		this.source = source;
+		this.frame = new Frame(envGetter);
+	}
+
+	LuanSource.Element se(int start) {
+		return new LuanSource.Element(source,start,currentIndex());
+	}
 
 	boolean nEquals(int n) {
 		nEquals = n;
@@ -140,8 +146,8 @@
 		return true;
 	}
 
-	Chunk newChunk(int start) {
-		return new Chunk( se(start), (Stmt)pop(), frame.stackSize, symbolsSize(), frame.isVarArg, frame.upValueGetters.toArray(NO_UP_VALUE_GETTERS) );
+	FnDef newFnDef(int start) {
+		return new FnDef( se(start), (Stmt)pop(), frame.stackSize, symbolsSize(), frame.isVarArg, frame.upValueGetters.toArray(NO_UP_VALUE_GETTERS) );
 	}
 
 	Rule Target() {
@@ -153,13 +159,13 @@
 				Sequence(
 					ExpList(false),
 					push( new ReturnStmt( se(start.get()), (Expressions)pop() ) ),
-					push( newChunk(start.get()) ),
+					push( newFnDef(start.get()) ),
 					EOI
 				),
 				Sequence(
 					action( frame.isVarArg = true ),
 					Block(),
-					push( newChunk(start.get()) ),
+					push( newFnDef(start.get()) ),
 					EOI
 				)
 			)
@@ -648,7 +654,7 @@
 				)
 			),
 			')', Spaces(inParens), Block(), Keyword("end",inParens),
-			push( newChunk(start.get()) ),
+			push( newFnDef(start.get()) ),
 			action( frame = frame.parent )
 		);
 	}