~ubuntu-branches/ubuntu/vivid/nqp/vivid-proposed

« back to all changes in this revision

Viewing changes to src/vm/jvm/runtime/org/perl6/nqp/sixmodel/reprs/ContextRefInstance.java

  • Committer: Package Import Robot
  • Author(s): Alessandro Ghedini
  • Date: 2013-11-01 12:09:18 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20131101120918-kx51sl0sxl3exsxi
Tags: 2013.10-1
* New upstream release
* Bump versioned (Build-)Depends on parrot
* Update patches
* Install new README.pod
* Fix vcs-field-not-canonical
* Do not install rubyish examples
* Do not Depends on parrot-devel anymore
* Add 07_disable-serialization-tests.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.perl6.nqp.sixmodel.reprs;
 
2
 
 
3
import org.perl6.nqp.runtime.CallFrame;
 
4
import org.perl6.nqp.runtime.ExceptionHandling;
 
5
import org.perl6.nqp.runtime.StaticCodeInfo;
 
6
import org.perl6.nqp.runtime.ThreadContext;
 
7
import org.perl6.nqp.sixmodel.SixModelObject;
 
8
 
 
9
public class ContextRefInstance extends SixModelObject {
 
10
    public CallFrame context;
 
11
    
 
12
    public SixModelObject at_key_boxed(ThreadContext tc, String key) {
 
13
        Integer idx = context.codeRef.staticInfo.oTryGetLexicalIdx(key);
 
14
        return idx == null ? null : context.oLex[idx];
 
15
    }
 
16
    
 
17
    public void at_key_native(ThreadContext tc, String key) {
 
18
        Integer idx = context.codeRef.staticInfo.iTryGetLexicalIdx(key);
 
19
        if (idx != null) {
 
20
            tc.native_i = context.iLex[idx];
 
21
            tc.native_type = ThreadContext.NATIVE_INT;
 
22
            return;
 
23
        }
 
24
        idx = context.codeRef.staticInfo.nTryGetLexicalIdx(key);
 
25
        if (idx != null) {
 
26
            tc.native_n = context.nLex[idx];
 
27
            tc.native_type = ThreadContext.NATIVE_NUM;
 
28
            return;
 
29
        }
 
30
        idx = context.codeRef.staticInfo.sTryGetLexicalIdx(key);
 
31
        if (idx != null) {
 
32
            tc.native_s = context.sLex[idx];
 
33
            tc.native_type = ThreadContext.NATIVE_STR;
 
34
            return;
 
35
        }
 
36
        throw ExceptionHandling.dieInternal(tc, "No lexical " + key + " in this lexpad");
 
37
    }
 
38
    
 
39
    public void bind_key_boxed(ThreadContext tc, String key, SixModelObject value) {
 
40
        Integer idx = context.codeRef.staticInfo.oTryGetLexicalIdx(key);
 
41
        if (idx == null)
 
42
            throw ExceptionHandling.dieInternal(tc, "No lexical " + key + " in this lexpad");
 
43
        context.oLex[idx] = value;
 
44
    }
 
45
    
 
46
    public void bind_key_native(ThreadContext tc, String key) {
 
47
        Integer idx = context.codeRef.staticInfo.iTryGetLexicalIdx(key);
 
48
        if (idx != null) {
 
49
            context.iLex[idx] = tc.native_i;
 
50
            tc.native_type = ThreadContext.NATIVE_INT;
 
51
            return;
 
52
        }
 
53
        idx = context.codeRef.staticInfo.nTryGetLexicalIdx(key);
 
54
        if (idx != null) {
 
55
            context.nLex[idx] = tc.native_n;
 
56
            tc.native_type = ThreadContext.NATIVE_NUM;
 
57
            return;
 
58
        }
 
59
        idx = context.codeRef.staticInfo.sTryGetLexicalIdx(key);
 
60
        if (idx != null) {
 
61
            context.sLex[idx] = tc.native_s;
 
62
            tc.native_type = ThreadContext.NATIVE_STR;
 
63
            return;
 
64
        }
 
65
        throw ExceptionHandling.dieInternal(tc, "No lexical " + key + " in this lexpad");
 
66
    }
 
67
    
 
68
    public long exists_key(ThreadContext tc, String key) {
 
69
        StaticCodeInfo sci = context.codeRef.staticInfo;
 
70
        return sci.oTryGetLexicalIdx(key) != null ||
 
71
               sci.iTryGetLexicalIdx(key) != null ||
 
72
               sci.nTryGetLexicalIdx(key) != null ||
 
73
               sci.sTryGetLexicalIdx(key) != null
 
74
               ? 1 : 0;
 
75
    }
 
76
}