Mercurial Hosting > luan
changeset 658:e038905512d3
compile ReturnStmt
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 05 Apr 2016 18:38:29 -0600 |
parents | 8081713bf7d9 |
children | f1150518c467 |
files | core/src/luan/impl/LuanJavaCompiler.java core/src/luan/impl/LuanParser.java core/src/luan/impl/LuanStateImpl.java |
diffstat | 3 files changed, 11 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
diff -r 8081713bf7d9 -r e038905512d3 core/src/luan/impl/LuanJavaCompiler.java --- a/core/src/luan/impl/LuanJavaCompiler.java Tue Apr 05 17:37:54 2016 -0600 +++ b/core/src/luan/impl/LuanJavaCompiler.java Tue Apr 05 18:38:29 2016 -0600 @@ -52,7 +52,7 @@ boolean b = compiler.getTask(out, fjfm, null, null, null, Collections.singletonList(sourceFile)).call(); if( !b ) throw new RuntimeException("\n"+out+"\ncode:\n"+code+"\n"); - byte[] byteCode = baos.toByteArray(); + final byte[] byteCode = baos.toByteArray(); int max = byteCode.length-len-3; outer: for( int i=0; true; i++ ) {
diff -r 8081713bf7d9 -r e038905512d3 core/src/luan/impl/LuanParser.java --- a/core/src/luan/impl/LuanParser.java Tue Apr 05 17:37:54 2016 -0600 +++ b/core/src/luan/impl/LuanParser.java Tue Apr 05 18:38:29 2016 -0600 @@ -181,9 +181,10 @@ FnDef Expression() throws ParseException { Spaces(In.NOTHING); int start = parser.begin(); - Expressions expr = exp(ExprZ(In.NOTHING)); + ExpString expr = ExprZ(In.NOTHING); if( expr != null && parser.endOfInput() ) { - Stmt stmt = new ReturnStmt( expr ); + String code = "luan.returnValues = " + expr.code + ";\n"; + Stmt stmt = stmt( new StmtString(code) ); return parser.success(newFnDef(start,stmt)); } return parser.failure(null); @@ -246,7 +247,7 @@ if( LocalStmt(stmts) ) return; StmtString stmt; - if( (stmt=stmtStr(ReturnStmt())) != null + if( (stmt=ReturnStmt()) != null || (stmt=stmtStr(FunctionStmt())) != null || (stmt=stmtStr(LocalFunctionStmt())) != null || (stmt=BreakStmt()) != null @@ -327,14 +328,14 @@ } } - private Stmt ReturnStmt() throws ParseException { + private StmtString ReturnStmt() throws ParseException { parser.begin(); if( !Keyword("return",In.NOTHING) ) return parser.failure(null); - Expressions exprs = exp(ExpStringList(In.NOTHING)); - if( exprs==null ) - exprs = ExpList.emptyExpList; - return parser.success( new ReturnStmt(exprs) ); + ExpString exprs = ExpStringList(In.NOTHING); + String code = "luan.returnValues = " + (exprs!=null ? exprs.code : "LuanFunction.NOTHING") + ";\n" + +"return;\n"; + return parser.success( new StmtString(code) ); } private Stmt FunctionStmt() throws ParseException {
diff -r 8081713bf7d9 -r e038905512d3 core/src/luan/impl/LuanStateImpl.java --- a/core/src/luan/impl/LuanStateImpl.java Tue Apr 05 17:37:54 2016 -0600 +++ b/core/src/luan/impl/LuanStateImpl.java Tue Apr 05 18:38:29 2016 -0600 @@ -53,7 +53,7 @@ } private Frame frame = null; - Object returnValues; + public Object returnValues; Closure tailFn; LuanStateImpl() {}