Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement islist and ishash.
  • Loading branch information
jnthn committed Jan 6, 2013
1 parent d70c951 commit ccd0d69
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/QAST/JASTCompiler.nqp
Expand Up @@ -732,6 +732,8 @@ QAST::OperationsJAST.map_classlib_core_op('push', $TYPE_OPS, 'push', [$RT_OBJ, $
QAST::OperationsJAST.map_classlib_core_op('pop', $TYPE_OPS, 'pop', [$RT_OBJ], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('unshift', $TYPE_OPS, 'unshift', [$RT_OBJ, $RT_OBJ], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('shift', $TYPE_OPS, 'shift', [$RT_OBJ], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('islist', $TYPE_OPS, 'islist', [$RT_OBJ], $RT_INT, :tc);
QAST::OperationsJAST.map_classlib_core_op('ishash', $TYPE_OPS, 'ishash', [$RT_OBJ], $RT_INT, :tc);

# object opcodes
QAST::OperationsJAST.map_jvm_core_op('null', 'aconst_null', [], $RT_OBJ);
Expand Down
8 changes: 8 additions & 0 deletions src/org/perl6/nqp/runtime/Ops.java
Expand Up @@ -3,6 +3,8 @@
import java.math.BigInteger;

import org.perl6.nqp.sixmodel.*;
import org.perl6.nqp.sixmodel.reprs.VMArray;
import org.perl6.nqp.sixmodel.reprs.VMHash;

/**
* Contains complex operations that are more involved that the simple ops that the
Expand Down Expand Up @@ -590,6 +592,12 @@ public static SixModelObject deletekey(SixModelObject hash, String key, ThreadCo
public static long elems(SixModelObject agg, ThreadContext tc) {
return agg.elems(tc);
}
public static long islist(SixModelObject obj, ThreadContext tc) {
return obj.st.REPR instanceof VMArray ? 1 : 0;
}
public static long ishash(SixModelObject obj, ThreadContext tc) {
return obj.st.REPR instanceof VMHash ? 1 : 0;
}

/* Math operations. */
public static double sec_n(double val) {
Expand Down

0 comments on commit ccd0d69

Please sign in to comment.