changeset 661:1bbb08c0d8f1

compile LocalFunctionStmt
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 06 Apr 2016 21:19:30 -0600
parents e064377994b2
children ee00a619eec1
files core/src/luan/impl/LuanParser.java
diffstat 1 files changed, 7 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/core/src/luan/impl/LuanParser.java	Wed Apr 06 21:06:29 2016 -0600
+++ b/core/src/luan/impl/LuanParser.java	Wed Apr 06 21:19:30 2016 -0600
@@ -249,7 +249,7 @@
 		StmtString stmt;
 		if( (stmt=ReturnStmt()) != null
 			|| (stmt=FunctionStmt()) != null
-			|| (stmt=stmtStr(LocalFunctionStmt())) != null
+			|| (stmt=LocalFunctionStmt()) != null
 			|| (stmt=BreakStmt()) != null
 			|| (stmt=ForStmt()) != null
 			|| (stmt=DoStmt()) != null
@@ -357,14 +357,16 @@
 		return parser.success( var.set(new ExpString(fnDef)) );
 	}
 
-	private Stmt LocalFunctionStmt() throws ParseException {
+	private StmtString LocalFunctionStmt() throws ParseException {
 		parser.begin();
 		if( !(Keyword("local",In.NOTHING) && Keyword("function",In.NOTHING)) )
 			return parser.failure(null);
 		String name = RequiredName(In.NOTHING);
 		addSymbol( name );
 		FnDef fnDef = RequiredFunction(In.NOTHING);
-		return parser.success( new SetStmt( new SetLocalVar(symbolsSize()-1), fnDef ) );
+		Settable s = new SetLocalVar(symbolsSize()-1);
+		String code = new SettableString(s).code + ".set(luan," + new ExpString(fnDef).code + ");\n";
+		return parser.success( new StmtString(code) );
 	}
 
 	private StmtString BreakStmt() throws ParseException {
@@ -1563,13 +1565,13 @@
 
 	private static class StmtString {
 		final String code;
-
+/*
 		StmtString(Stmt stmt) {
 			if( stmt==null )  throw new NullPointerException();
 			int i = LuanImpl.addStmt(stmt);
 			code = "LuanImpl.getStmt(" + i + ").eval(luan);\n";
 		}
-
+*/
 		StmtString(String code) {
 			this.code = code;
 			if( code.contains("LuanParser") )  throw new RuntimeException("\n"+code);
@@ -1611,10 +1613,6 @@
 		return stmtStr==null ? null : stmtStr.toStmt();
 	}
 
-	private static StmtString stmtStr(Stmt stmt) {
-		return stmt==null ? null : new StmtString(stmt);
-	}
-
 
 	private static class SettableString {
 		final String code;