Skip to content

Commit

Permalink
Add variants of compilejast and compilejasttofile that accept array o…
Browse files Browse the repository at this point in the history
…f strings.
  • Loading branch information
donaldh committed Sep 25, 2013
1 parent 7b02322 commit 130c815
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/vm/jvm/QAST/Compiler.nqp
Expand Up @@ -2446,6 +2446,8 @@ QAST::OperationsJAST.map_classlib_core_op('getpid', $TYPE_OPS, 'getpid', [], $RT
QAST::OperationsJAST.map_classlib_core_op('jvmgetproperties', $TYPE_OPS, 'jvmgetproperties', [], $RT_OBJ, :tc);

# JVM-specific ops for compilation unit handling
QAST::OperationsJAST.map_classlib_core_op('compilejastlines', $TYPE_OPS, 'compilejastlines', [$RT_OBJ], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('compilejastlinestofile', $TYPE_OPS, 'compilejastlinestofile', [$RT_OBJ, $RT_STR], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('compilejast', $TYPE_OPS, 'compilejast', [$RT_STR], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('compilejasttofile', $TYPE_OPS, 'compilejasttofile', [$RT_STR, $RT_STR], $RT_STR, :tc);
QAST::OperationsJAST.map_classlib_core_op('loadcompunit', $TYPE_OPS, 'loadcompunit', [$RT_OBJ, $RT_INT], $RT_OBJ, :tc);
Expand Down
31 changes: 31 additions & 0 deletions src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java
Expand Up @@ -26,6 +26,7 @@
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
Expand Down Expand Up @@ -641,6 +642,7 @@ public static SixModelObject slurpasync(SixModelObject obj, SixModelObject resul
return obj;
}

@SuppressWarnings({ "unchecked", "rawtypes" })
public static SixModelObject linesasync(SixModelObject obj, SixModelObject resultType,
long chomp, SixModelObject queue, SixModelObject done, SixModelObject error,
ThreadContext tc) {
Expand Down Expand Up @@ -5093,11 +5095,40 @@ public static SixModelObject bitshiftr_I(SixModelObject a, long b, SixModelObjec
}

/* Evaluation of code; JVM-specific ops. */
public static SixModelObject compilejastlines(SixModelObject dump, ThreadContext tc) {
if (dump instanceof VMArrayInstance) {
VMArrayInstance array = (VMArrayInstance) dump;
List<String> lines = new LinkedList<String>();
for (int index = 0; index < array.elems; index++) {
lines.add(array.at_pos_boxed(tc, index).get_str(tc));
}
EvalResult res = new EvalResult();
res.jc = JASTToJVMBytecode.buildClassFromString(lines, false);
return res;
} else {
throw ExceptionHandling.dieInternal(tc,
"compilejastlines requires an array with the VMArrayInstance REPR");
}
}
public static SixModelObject compilejast(String dump, ThreadContext tc) {
EvalResult res = new EvalResult();
res.jc = JASTToJVMBytecode.buildClassFromString(dump, false);
return res;
}
public static SixModelObject compilejastlinestofile(SixModelObject dump, String filename, ThreadContext tc) {
if (dump instanceof VMArrayInstance) {
VMArrayInstance array = (VMArrayInstance) dump;
List<String> lines = new LinkedList<String>();
for (int index = 0; index < array.elems; index++) {
lines.add(array.at_pos_boxed(tc, index).get_str(tc));
}
JASTToJVMBytecode.writeClassFromString(lines, filename);
return dump;
} else {
throw ExceptionHandling.dieInternal(tc,
"compilejastlines requires an array with the VMArrayInstance REPR");
}
}
public static String compilejasttofile(String dump, String filename, ThreadContext tc) {
JASTToJVMBytecode.writeClassFromString(dump, filename);
return dump;
Expand Down

0 comments on commit 130c815

Please sign in to comment.