Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Stub in the binder.
Doesn't actually do anything yet, this just gets the op and some of
the constants in place.
  • Loading branch information
jnthn committed May 10, 2013
1 parent 39ea92e commit 7bf40c1
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 3 deletions.
13 changes: 12 additions & 1 deletion src/vm/jvm/Perl6/Ops.nqp
Expand Up @@ -7,15 +7,18 @@ my $TYPE_P6OPS := 'Lorg/perl6/rakudo/Ops;';

# Other types we'll refer to.
my $TYPE_OPS := 'Lorg/perl6/nqp/runtime/Ops;';
my $TYPE_CSD := 'Lorg/perl6/nqp/runtime/CallSiteDescriptor;';
my $TYPE_SMO := 'Lorg/perl6/nqp/sixmodel/SixModelObject;';
my $TYPE_TC := 'Lorg/perl6/nqp/runtime/ThreadContext;';
my $TYPE_STR := 'Ljava/lang/String;';
my $TYPE_OBJ := 'Ljava/lang/Object;';

# Opcode types.
my $RT_OBJ := 0;
my $RT_INT := 1;
my $RT_NUM := 2;
my $RT_STR := 3;
my $RT_VOID := -1;

# Perl 6 opcode specific mappings.
$ops.map_classlib_hll_op('perl6', 'p6box_i', $TYPE_P6OPS, 'p6box_i', [$RT_INT], $RT_OBJ, :tc);
Expand All @@ -31,7 +34,15 @@ $ops.map_classlib_hll_op('perl6', 'p6store', $TYPE_P6OPS, 'p6store', [$RT_OBJ, $
$ops.map_classlib_hll_op('perl6', 'p6var', $TYPE_P6OPS, 'p6var', [$RT_OBJ], $RT_OBJ, :tc);
$ops.map_classlib_hll_op('perl6', 'p6reprname', $TYPE_P6OPS, 'p6reprname', [$RT_OBJ], $RT_OBJ, :tc);
$ops.map_classlib_hll_op('perl6', 'p6definite', $TYPE_P6OPS, 'p6definite', [$RT_OBJ], $RT_OBJ, :tc);
$ops.map_classlib_hll_op('perl6', 'p6bindsig', $TYPE_P6OPS, 'p6bindsig', [], $RT_OBJ, :tc);
$ops.add_hll_op('perl6', 'p6bindsig', -> $qastcomp, $op {
my $il := JAST::InstructionList.new();
$il.append(JAST::Instruction.new( :op('aload_1') ));
$il.append(JAST::Instruction.new( :op('aload'), 'csd' ));
$il.append(JAST::Instruction.new( :op('aload'), '__args' ));
$il.append(JAST::Instruction.new( :op('invokestatic'), $TYPE_P6OPS,
"p6bindsig", 'V', $TYPE_TC, $TYPE_CSD, "[$TYPE_OBJ" ));
$ops.result($il, $RT_VOID);
});
$ops.map_classlib_hll_op('perl6', 'p6isbindable', $TYPE_P6OPS, 'p6isbindable', [$RT_OBJ, $RT_OBJ], $RT_INT, :tc);
$ops.map_classlib_hll_op('perl6', 'p6bindcaptosig', $TYPE_P6OPS, 'p6bindcaptosig', [$RT_OBJ, $RT_OBJ], $RT_OBJ, :tc);
$ops.map_classlib_hll_op('perl6', 'p6trialbind', $TYPE_P6OPS, 'p6trialbind', [$RT_OBJ, $RT_OBJ, $RT_OBJ], $RT_INT, :tc);
Expand Down
62 changes: 62 additions & 0 deletions src/vm/jvm/runtime/org/perl6/rakudo/Binder.java
@@ -0,0 +1,62 @@
package org.perl6.rakudo;

import java.util.*;

import org.perl6.nqp.runtime.*;
import org.perl6.nqp.sixmodel.*;

public final class Binder {
/* Possible results of binding. */
public static final int BIND_RESULT_OK = 0;
public static final int BIND_RESULT_FAIL = 1;
public static final int BIND_RESULT_JUNCTION = 2;

/* Compile time trial binding result indicators. */
public static final int TRIAL_BIND_NOT_SURE = 0; /* Plausible, but need to check at runtime. */
public static final int TRIAL_BIND_OK = 1; /* Bind will always work out. */
public static final int TRIAL_BIND_NO_WAY = -1; /* Bind could never work out. */

/* Flags. */
private static final int SIG_ELEM_BIND_CAPTURE = 1;
private static final int SIG_ELEM_BIND_PRIVATE_ATTR = 2;
private static final int SIG_ELEM_BIND_PUBLIC_ATTR = 4;
private static final int SIG_ELEM_BIND_ATTRIBUTIVE = (SIG_ELEM_BIND_PRIVATE_ATTR | SIG_ELEM_BIND_PUBLIC_ATTR);
private static final int SIG_ELEM_SLURPY_POS = 8;
private static final int SIG_ELEM_SLURPY_NAMED = 16;
private static final int SIG_ELEM_SLURPY_LOL = 32;
private static final int SIG_ELEM_SLURPY = (SIG_ELEM_SLURPY_POS | SIG_ELEM_SLURPY_NAMED | SIG_ELEM_SLURPY_LOL);
private static final int SIG_ELEM_INVOCANT = 64;
private static final int SIG_ELEM_MULTI_INVOCANT = 128;
private static final int SIG_ELEM_IS_RW = 256;
private static final int SIG_ELEM_IS_COPY = 512;
private static final int SIG_ELEM_IS_PARCEL = 1024;
private static final int SIG_ELEM_IS_OPTIONAL = 2048;
private static final int SIG_ELEM_ARRAY_SIGIL = 4096;
private static final int SIG_ELEM_HASH_SIGIL = 8192;
private static final int SIG_ELEM_DEFAULT_FROM_OUTER = 16384;
private static final int SIG_ELEM_IS_CAPTURE = 32768;
private static final int SIG_ELEM_UNDEFINED_ONLY = 65536;
private static final int SIG_ELEM_DEFINED_ONLY = 131072;
private static final int SIG_ELEM_DEFINEDNES_CHECK = (SIG_ELEM_UNDEFINED_ONLY | SIG_ELEM_DEFINED_ONLY);
private static final int SIG_ELEM_NOMINAL_GENERIC = 524288;
private static final int SIG_ELEM_DEFAULT_IS_LITERAL = 1048576;
private static final int SIG_ELEM_NATIVE_INT_VALUE = 2097152;
private static final int SIG_ELEM_NATIVE_NUM_VALUE = 4194304;
private static final int SIG_ELEM_NATIVE_STR_VALUE = 8388608;
private static final int SIG_ELEM_NATIVE_VALUE = (SIG_ELEM_NATIVE_INT_VALUE | SIG_ELEM_NATIVE_NUM_VALUE | SIG_ELEM_NATIVE_STR_VALUE);

/* Last error, per thread. */
public static HashMap<ThreadContext, String> lastErrors = new HashMap<ThreadContext, String>();

public static int bind(ThreadContext tc, CallFrame ctx, SixModelObject params,
CallSiteDescriptor csd, Object[] args,
boolean noNomTypeCheck, boolean needError) {
/* XXX TODO. */
System.err.println("p6bindsig NYI");
return BIND_RESULT_OK;
}

public static String lastError(ThreadContext tc) {
return lastErrors.get(tc);
}
}
41 changes: 39 additions & 2 deletions src/vm/jvm/runtime/org/perl6/rakudo/Ops.java
@@ -1,16 +1,24 @@
package org.perl6.rakudo;

import org.perl6.nqp.runtime.ThreadContext;
import org.perl6.nqp.sixmodel.SixModelObject;
import org.perl6.nqp.runtime.*;
import org.perl6.nqp.sixmodel.*;

/**
* Contains implementation of nqp:: ops specific to Rakudo Perl 6.
*/
public final class Ops {
private static SixModelObject Code;
private static SixModelObject Signature;
private static SixModelObject Parameter;
private static SixModelObject False;
private static SixModelObject True;
private static boolean initialized = false;

/* Parameter hints for fast lookups. */
private static final int HINT_CODE_DO = 0;
private static final int HINT_CODE_SIG = 1;
private static final int HINT_SIG_PARAMS = 0;

public static SixModelObject p6init(ThreadContext tc) {
if (!initialized) {
tc.gc.contConfigs.put("rakudo_scalar", new RakudoContainerConfigurer());
Expand All @@ -20,6 +28,9 @@ public static SixModelObject p6init(ThreadContext tc) {
}

public static SixModelObject p6settypes(SixModelObject conf, ThreadContext tc) {
Code = conf.at_key_boxed(tc, "Code");
Signature = conf.at_key_boxed(tc, "Signature");
Parameter = conf.at_key_boxed(tc, "Parameter");
False = conf.at_key_boxed(tc, "False");
True = conf.at_key_boxed(tc, "True");
return conf;
Expand All @@ -28,4 +39,30 @@ public static SixModelObject p6settypes(SixModelObject conf, ThreadContext tc) {
public static SixModelObject booleanize(int x) {
return x == 0 ? False : True;
}

public static void p6bindsig(ThreadContext tc, CallSiteDescriptor csd, Object[] args) {
/* Do any flattening before processing begins. */
CallFrame cf = tc.curFrame;
if (csd.hasFlattening) {
csd = csd.explodeFlattening(cf, args);
args = tc.flatArgs;
}
else {
tc.flatArgs = args;
}

/* Look up parameters to bind. */
SixModelObject sig = cf.codeRef.codeObject
.get_attribute_boxed(tc, Code, "$!signature", HINT_CODE_SIG);
SixModelObject params = sig
.get_attribute_boxed(tc, Signature, "$!params", HINT_SIG_PARAMS);

/* Run binder, and handle any errors. */
switch (Binder.bind(tc, cf, params, csd, args, false, true)) {
case Binder.BIND_RESULT_FAIL:
throw ExceptionHandling.dieInternal(tc, Binder.lastError(tc));
case Binder.BIND_RESULT_JUNCTION:
throw ExceptionHandling.dieInternal(tc, "Junction re-dispatch NYI");
}
}
}

0 comments on commit 7bf40c1

Please sign in to comment.